]>
Commit | Line | Data |
---|---|---|
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 | ||
12 | #include "wx/dcclient.h" | |
13 | #include "wx/window.h" | |
fe8f7943 | 14 | #include "wx/log.h" |
891d0563 DE |
15 | |
16 | #import <AppKit/NSView.h> | |
17 | #import <AppKit/NSAffineTransform.h> | |
9d180f3a DE |
18 | #import <AppKit/NSColor.h> |
19 | #import <AppKit/NSGraphicsContext.h> | |
20 | #import <AppKit/NSBezierPath.h> | |
fe8f7943 | 21 | #import <AppKit/NSWindow.h> |
891d0563 DE |
22 | |
23 | /* | |
24 | * wxWindowDC | |
25 | */ | |
26 | IMPLEMENT_DYNAMIC_CLASS(wxWindowDC, wxDC) | |
27 | ||
28 | wxWindowDC::wxWindowDC(void) | |
fcc9de54 | 29 | : m_window(NULL) |
891d0563 DE |
30 | { |
31 | }; | |
32 | ||
33 | wxWindowDC::wxWindowDC( wxWindow *window ) | |
fcc9de54 | 34 | : m_window(window) |
891d0563 DE |
35 | { |
36 | wxFAIL_MSG("non-client window DC's are not supported"); | |
37 | }; | |
38 | ||
39 | wxWindowDC::~wxWindowDC(void) | |
40 | { | |
41 | }; | |
42 | ||
9d180f3a DE |
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 | ||
891d0563 DE |
56 | /* |
57 | * wxClientDC | |
58 | */ | |
59 | IMPLEMENT_DYNAMIC_CLASS(wxClientDC, wxWindowDC) | |
60 | ||
61 | wxClientDC::wxClientDC(void) | |
62 | { | |
63 | }; | |
64 | ||
65 | wxClientDC::wxClientDC( wxWindow *window ) | |
66 | { | |
d630f41d | 67 | m_window = window; |
891d0563 DE |
68 | }; |
69 | ||
70 | wxClientDC::~wxClientDC(void) | |
71 | { | |
fe8f7943 | 72 | CocoaUnwindStackAndLoseFocus(); |
891d0563 DE |
73 | }; |
74 | ||
fe8f7943 DE |
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 | ||
891d0563 DE |
98 | /* |
99 | * wxPaintDC | |
100 | */ | |
101 | IMPLEMENT_DYNAMIC_CLASS(wxPaintDC, wxWindowDC) | |
102 | ||
103 | wxPaintDC::wxPaintDC(void) | |
104 | { | |
105 | }; | |
106 | ||
107 | wxPaintDC::wxPaintDC( wxWindow *window ) | |
108 | { | |
d630f41d | 109 | m_window = window; |
891d0563 | 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"); |
fe8f7943 DE |
111 | sm_cocoaDCStack.Insert(this); |
112 | m_cocoaFlipped = [window->GetNSView() isFlipped]; | |
113 | m_cocoaHeight = [window->GetNSView() bounds].size.height; | |
114 | CocoaApplyTransformations(); | |
891d0563 DE |
115 | }; |
116 | ||
117 | wxPaintDC::~wxPaintDC(void) | |
118 | { | |
fe8f7943 | 119 | CocoaUnwindStackAndLoseFocus(); |
891d0563 DE |
120 | }; |
121 | ||
fe8f7943 DE |
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 |