]> git.saurik.com Git - wxWidgets.git/blame - src/cocoa/dcclient.mm
Use function table instead of direct references to GSocket functions.
[wxWidgets.git] / src / cocoa / dcclient.mm
CommitLineData
891d0563
DE
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/cocoa/dcclient.mm
3// Purpose: wxWindowDC, wxPaintDC, and wxClientDC classes
4// Author: David Elliott
5// Modified by:
6// Created: 2003/04/01
7// RCS-ID: $Id$
8// Copyright: (c) 2003 David Elliott
9// Licence: wxWindows license
10/////////////////////////////////////////////////////////////////////////////
11
449c5673
DE
12#include "wx/wxprec.h"
13#ifndef WX_PRECOMP
14 #include "wx/log.h"
15 #include "wx/window.h"
16 #include "wx/dcclient.h"
17#endif //WX_PRECOMP
891d0563
DE
18
19#import <AppKit/NSView.h>
20#import <AppKit/NSAffineTransform.h>
9d180f3a
DE
21#import <AppKit/NSColor.h>
22#import <AppKit/NSGraphicsContext.h>
23#import <AppKit/NSBezierPath.h>
fe8f7943 24#import <AppKit/NSWindow.h>
891d0563
DE
25
26/*
27 * wxWindowDC
28 */
29IMPLEMENT_DYNAMIC_CLASS(wxWindowDC, wxDC)
30
31wxWindowDC::wxWindowDC(void)
fcc9de54 32: m_window(NULL)
891d0563
DE
33{
34};
35
36wxWindowDC::wxWindowDC( wxWindow *window )
fcc9de54 37: m_window(window)
891d0563
DE
38{
39 wxFAIL_MSG("non-client window DC's are not supported");
40};
41
42wxWindowDC::~wxWindowDC(void)
43{
44};
45
9d180f3a
DE
46void wxWindowDC::Clear()
47{
48 wxASSERT(m_window);
49
50 NSGraphicsContext *context = [NSGraphicsContext currentContext];
51 [context saveGraphicsState];
52
53 [m_backgroundBrush.GetNSColor() set];
54 [NSBezierPath fillRect:[m_window->GetNSView() bounds]];
55
56 [context restoreGraphicsState];
57}
58
891d0563
DE
59/*
60 * wxClientDC
61 */
62IMPLEMENT_DYNAMIC_CLASS(wxClientDC, wxWindowDC)
63
64wxClientDC::wxClientDC(void)
65{
66};
67
68wxClientDC::wxClientDC( wxWindow *window )
69{
d630f41d 70 m_window = window;
891d0563
DE
71};
72
73wxClientDC::~wxClientDC(void)
74{
fe8f7943 75 CocoaUnwindStackAndLoseFocus();
891d0563
DE
76};
77
fe8f7943
DE
78bool wxClientDC::CocoaLockFocus()
79{
80 wxLogDebug("Locking focus on wxClientDC=%p, NSView=%p",this, m_window->GetNSView());
81 if([m_window->GetNSView() lockFocusIfCanDraw])
82 {
83 sm_cocoaDCStack.Insert(this);
84 m_cocoaFlipped = [m_window->GetNSView() isFlipped];
85 m_cocoaHeight = [m_window->GetNSView() bounds].size.height;
86 CocoaApplyTransformations();
87 return true;
88 }
89 wxLogDebug("focus lock failed!");
90 return false;
91}
92
93bool wxClientDC::CocoaUnlockFocus()
94{
95 wxLogDebug("Unlocking focus on wxClientDC=%p, NSView=%p",this, m_window->GetNSView());
96 [[m_window->GetNSView() window] flushWindow];
97 [m_window->GetNSView() unlockFocus];
98 return true;
99}
100
891d0563
DE
101/*
102 * wxPaintDC
103 */
104IMPLEMENT_DYNAMIC_CLASS(wxPaintDC, wxWindowDC)
105
106wxPaintDC::wxPaintDC(void)
107{
108};
109
110wxPaintDC::wxPaintDC( wxWindow *window )
111{
d630f41d 112 m_window = window;
891d0563 113 wxASSERT_MSG([NSView focusView]==window->GetNSView(), "PaintDC's NSView does not have focus. Please use wxPaintDC only as the first DC created in a paint handler");
fe8f7943
DE
114 sm_cocoaDCStack.Insert(this);
115 m_cocoaFlipped = [window->GetNSView() isFlipped];
116 m_cocoaHeight = [window->GetNSView() bounds].size.height;
117 CocoaApplyTransformations();
891d0563
DE
118};
119
120wxPaintDC::~wxPaintDC(void)
121{
fe8f7943 122 CocoaUnwindStackAndLoseFocus();
891d0563
DE
123};
124
fe8f7943
DE
125bool wxPaintDC::CocoaLockFocus()
126{
127 wxFAIL_MSG("wxPaintDC cannot be asked to lock focus!");
128 return false;
129}
130
131bool wxPaintDC::CocoaUnlockFocus()
132{
133 // wxPaintDC focus can never be unlocked.
134 return false;
135}
136