]> git.saurik.com Git - wxWidgets.git/blob - src/cocoa/dcclient.mm
unicode compilation fix
[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: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 #include "wx/dcclient.h"
13 #include "wx/window.h"
14 #include "wx/log.h"
15
16 #import <AppKit/NSView.h>
17 #import <AppKit/NSAffineTransform.h>
18 #import <AppKit/NSColor.h>
19 #import <AppKit/NSGraphicsContext.h>
20 #import <AppKit/NSBezierPath.h>
21 #import <AppKit/NSWindow.h>
22
23 /*
24 * wxWindowDC
25 */
26 IMPLEMENT_DYNAMIC_CLASS(wxWindowDC, wxDC)
27
28 wxWindowDC::wxWindowDC(void)
29 : m_window(NULL)
30 {
31 };
32
33 wxWindowDC::wxWindowDC( wxWindow *window )
34 : m_window(window)
35 {
36 wxFAIL_MSG("non-client window DC's are not supported");
37 };
38
39 wxWindowDC::~wxWindowDC(void)
40 {
41 };
42
43 void wxWindowDC::Clear()
44 {
45 wxASSERT(m_window);
46
47 NSGraphicsContext *context = [NSGraphicsContext currentContext];
48 [context saveGraphicsState];
49
50 [m_backgroundBrush.GetNSColor() set];
51 [NSBezierPath fillRect:[m_window->GetNSView() bounds]];
52
53 [context restoreGraphicsState];
54 }
55
56 /*
57 * wxClientDC
58 */
59 IMPLEMENT_DYNAMIC_CLASS(wxClientDC, wxWindowDC)
60
61 wxClientDC::wxClientDC(void)
62 {
63 };
64
65 wxClientDC::wxClientDC( wxWindow *window )
66 {
67 m_window = window;
68 };
69
70 wxClientDC::~wxClientDC(void)
71 {
72 CocoaUnwindStackAndLoseFocus();
73 };
74
75 bool wxClientDC::CocoaLockFocus()
76 {
77 wxLogDebug("Locking focus on wxClientDC=%p, NSView=%p",this, m_window->GetNSView());
78 if([m_window->GetNSView() lockFocusIfCanDraw])
79 {
80 sm_cocoaDCStack.Insert(this);
81 m_cocoaFlipped = [m_window->GetNSView() isFlipped];
82 m_cocoaHeight = [m_window->GetNSView() bounds].size.height;
83 CocoaApplyTransformations();
84 return true;
85 }
86 wxLogDebug("focus lock failed!");
87 return false;
88 }
89
90 bool wxClientDC::CocoaUnlockFocus()
91 {
92 wxLogDebug("Unlocking focus on wxClientDC=%p, NSView=%p",this, m_window->GetNSView());
93 [[m_window->GetNSView() window] flushWindow];
94 [m_window->GetNSView() unlockFocus];
95 return true;
96 }
97
98 /*
99 * wxPaintDC
100 */
101 IMPLEMENT_DYNAMIC_CLASS(wxPaintDC, wxWindowDC)
102
103 wxPaintDC::wxPaintDC(void)
104 {
105 };
106
107 wxPaintDC::wxPaintDC( wxWindow *window )
108 {
109 m_window = window;
110 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");
111 sm_cocoaDCStack.Insert(this);
112 m_cocoaFlipped = [window->GetNSView() isFlipped];
113 m_cocoaHeight = [window->GetNSView() bounds].size.height;
114 CocoaApplyTransformations();
115 };
116
117 wxPaintDC::~wxPaintDC(void)
118 {
119 CocoaUnwindStackAndLoseFocus();
120 };
121
122 bool wxPaintDC::CocoaLockFocus()
123 {
124 wxFAIL_MSG("wxPaintDC cannot be asked to lock focus!");
125 return false;
126 }
127
128 bool wxPaintDC::CocoaUnlockFocus()
129 {
130 // wxPaintDC focus can never be unlocked.
131 return false;
132 }
133