]> git.saurik.com Git - wxWidgets.git/blob - src/cocoa/dcclient.mm
moving constructors to .cpp
[wxWidgets.git] / src / cocoa / dcclient.mm
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: wxWidgets licence
10 /////////////////////////////////////////////////////////////////////////////
11
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
18
19 #import <AppKit/NSView.h>
20 #import <AppKit/NSAffineTransform.h>
21 #import <AppKit/NSColor.h>
22 #import <AppKit/NSGraphicsContext.h>
23 #import <AppKit/NSBezierPath.h>
24 #import <AppKit/NSWindow.h>
25
26 /*
27 * wxWindowDC
28 */
29 IMPLEMENT_DYNAMIC_CLASS(wxWindowDC, wxDC)
30
31 wxWindowDC::wxWindowDC(void)
32 : m_window(NULL)
33 , m_lockedNSView(NULL)
34 {
35 };
36
37 wxWindowDC::wxWindowDC( wxWindow *window )
38 : m_window(window)
39 , m_lockedNSView(NULL)
40 {
41 wxLogDebug(wxT("non-client window DC's are not supported, oh well"));
42 };
43
44 wxWindowDC::~wxWindowDC(void)
45 {
46 CocoaUnwindStackAndLoseFocus();
47 };
48
49 bool wxWindowDC::CocoaLockFocusOnNSView(WX_NSView nsview)
50 {
51 if([nsview lockFocusIfCanDraw])
52 {
53 sm_cocoaDCStack.Insert(this);
54 m_cocoaFlipped = [nsview isFlipped];
55 m_cocoaHeight = [nsview bounds].size.height;
56 CocoaApplyTransformations();
57 m_lockedNSView = nsview;
58 return true;
59 }
60 wxLogDebug(wxT("focus lock failed!"));
61 return false;
62 }
63
64 bool wxWindowDC::CocoaUnlockFocusOnNSView()
65 {
66 [[m_lockedNSView window] flushWindow];
67 [m_lockedNSView unlockFocus];
68 m_lockedNSView = NULL;
69 return true;
70 }
71
72 bool wxWindowDC::CocoaLockFocus()
73 {
74 wxLogTrace(wxTRACE_COCOA,wxT("Locking focus on wxWindowDC=%p, NSView=%p"),this, m_window->GetNonClientNSView());
75 return CocoaLockFocusOnNSView(m_window->GetNonClientNSView());
76 }
77
78 bool wxWindowDC::CocoaUnlockFocus()
79 {
80 wxLogTrace(wxTRACE_COCOA,wxT("Unlocking focus on wxWindowDC=%p, NSView=%p"),this, m_window->GetNonClientNSView());
81 return CocoaUnlockFocusOnNSView();
82 }
83
84 void wxWindowDC::Clear()
85 {
86 if(!CocoaTakeFocus()) return;
87
88 NSGraphicsContext *context = [NSGraphicsContext currentContext];
89 [context saveGraphicsState];
90
91 [m_backgroundBrush.GetNSColor() set];
92 [NSBezierPath fillRect:[m_lockedNSView bounds]];
93
94 [context restoreGraphicsState];
95 }
96
97 /*
98 * wxClientDC
99 */
100 IMPLEMENT_DYNAMIC_CLASS(wxClientDC, wxWindowDC)
101
102 wxClientDC::wxClientDC(void)
103 {
104 };
105
106 wxClientDC::wxClientDC( wxWindow *window )
107 {
108 m_window = window;
109 };
110
111 wxClientDC::~wxClientDC(void)
112 {
113 CocoaUnwindStackAndLoseFocus();
114 };
115
116 bool wxClientDC::CocoaLockFocus()
117 {
118 wxLogTrace(wxTRACE_COCOA,wxT("Locking focus on wxClientDC=%p, NSView=%p"),this, m_window->GetNSView());
119 return CocoaLockFocusOnNSView(m_window->GetNSView());
120 }
121
122 bool wxClientDC::CocoaUnlockFocus()
123 {
124 wxLogTrace(wxTRACE_COCOA,wxT("Unlocking focus on wxClientDC=%p, NSView=%p"),this, m_window->GetNSView());
125 return CocoaUnlockFocusOnNSView();
126 }
127
128 /*
129 * wxPaintDC
130 */
131 IMPLEMENT_DYNAMIC_CLASS(wxPaintDC, wxWindowDC)
132
133 wxPaintDC::wxPaintDC(void)
134 {
135 };
136
137 wxPaintDC::wxPaintDC( wxWindow *window )
138 {
139 m_window = window;
140 wxASSERT_MSG([NSView focusView]==window->GetNSView(), wxT("PaintDC's NSView does not have focus. Please use wxPaintDC only as the first DC created in a paint handler"));
141 sm_cocoaDCStack.Insert(this);
142 m_lockedNSView = window->GetNSView();
143 m_cocoaFlipped = [window->GetNSView() isFlipped];
144 m_cocoaHeight = [window->GetNSView() bounds].size.height;
145 CocoaApplyTransformations();
146 };
147
148 wxPaintDC::~wxPaintDC(void)
149 {
150 CocoaUnwindStackAndLoseFocus();
151 };
152
153 bool wxPaintDC::CocoaLockFocus()
154 {
155 wxFAIL_MSG(wxT("wxPaintDC cannot be asked to lock focus!"));
156 return false;
157 }
158
159 bool wxPaintDC::CocoaUnlockFocus()
160 {
161 // wxPaintDC focus can never be unlocked.
162 return false;
163 }
164