]>
Commit | Line | Data |
---|---|---|
891d0563 DE |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: src/cocoa/dcclient.mm | |
938156b2 | 3 | // Purpose: wxWindowDCImpl, wxPaintDCImpl, and wxClientDCImpl classes |
891d0563 DE |
4 | // Author: David Elliott |
5 | // Modified by: | |
6 | // Created: 2003/04/01 | |
891d0563 | 7 | // Copyright: (c) 2003 David Elliott |
526954c5 | 8 | // Licence: wxWindows licence |
891d0563 DE |
9 | ///////////////////////////////////////////////////////////////////////////// |
10 | ||
449c5673 DE |
11 | #include "wx/wxprec.h" |
12 | #ifndef WX_PRECOMP | |
13 | #include "wx/log.h" | |
14 | #include "wx/window.h" | |
449c5673 | 15 | #endif //WX_PRECOMP |
891d0563 | 16 | |
938156b2 DE |
17 | #include "wx/cocoa/dcclient.h" |
18 | ||
891d0563 DE |
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 | /* | |
938156b2 | 27 | * wxWindowDCImpl |
891d0563 | 28 | */ |
938156b2 | 29 | IMPLEMENT_ABSTRACT_CLASS(wxWindowDCImpl, wxCocoaDCImpl) |
891d0563 | 30 | |
938156b2 DE |
31 | wxWindowDCImpl::wxWindowDCImpl(wxDC *owner) |
32 | : wxCocoaDCImpl(owner) | |
33 | , m_window(NULL) | |
b66e9853 | 34 | , m_lockedNSView(NULL) |
891d0563 DE |
35 | { |
36 | }; | |
37 | ||
938156b2 DE |
38 | wxWindowDCImpl::wxWindowDCImpl(wxDC *owner, wxWindow *window) |
39 | : wxCocoaDCImpl(owner) | |
40 | , m_window(window) | |
b66e9853 | 41 | , m_lockedNSView(NULL) |
891d0563 | 42 | { |
2b030203 | 43 | wxLogDebug(wxT("non-client window DC's are not supported, oh well")); |
891d0563 DE |
44 | }; |
45 | ||
938156b2 | 46 | wxWindowDCImpl::~wxWindowDCImpl(void) |
891d0563 | 47 | { |
b66e9853 | 48 | CocoaUnwindStackAndLoseFocus(); |
891d0563 DE |
49 | }; |
50 | ||
938156b2 | 51 | bool wxWindowDCImpl::CocoaLockFocusOnNSView(WX_NSView nsview) |
b66e9853 DE |
52 | { |
53 | if([nsview lockFocusIfCanDraw]) | |
54 | { | |
55 | sm_cocoaDCStack.Insert(this); | |
b66e9853 DE |
56 | CocoaApplyTransformations(); |
57 | m_lockedNSView = nsview; | |
58 | return true; | |
59 | } | |
2b030203 | 60 | wxLogDebug(wxT("focus lock failed!")); |
b66e9853 DE |
61 | return false; |
62 | } | |
63 | ||
938156b2 | 64 | bool wxWindowDCImpl::CocoaUnlockFocusOnNSView() |
b66e9853 DE |
65 | { |
66 | [[m_lockedNSView window] flushWindow]; | |
67 | [m_lockedNSView unlockFocus]; | |
68 | m_lockedNSView = NULL; | |
69 | return true; | |
70 | } | |
71 | ||
938156b2 | 72 | bool wxWindowDCImpl::CocoaLockFocus() |
b66e9853 | 73 | { |
938156b2 | 74 | wxLogTrace(wxTRACE_COCOA,wxT("Locking focus on wxWindowDCImpl=%p, NSView=%p"),this, m_window->GetNonClientNSView()); |
1a1e9ff1 DE |
75 | NSAffineTransform *newTransform = CocoaGetWxToBoundsTransform([m_window->GetNonClientNSView() isFlipped], [m_window->GetNonClientNSView() bounds].size.height); |
76 | [newTransform retain]; | |
77 | [m_cocoaWxToBoundsTransform release]; | |
78 | m_cocoaWxToBoundsTransform = newTransform; | |
b66e9853 DE |
79 | return CocoaLockFocusOnNSView(m_window->GetNonClientNSView()); |
80 | } | |
81 | ||
938156b2 | 82 | bool wxWindowDCImpl::CocoaUnlockFocus() |
b66e9853 | 83 | { |
938156b2 | 84 | wxLogTrace(wxTRACE_COCOA,wxT("Unlocking focus on wxWindowDCImpl=%p, NSView=%p"),this, m_window->GetNonClientNSView()); |
b66e9853 DE |
85 | return CocoaUnlockFocusOnNSView(); |
86 | } | |
87 | ||
938156b2 | 88 | bool wxWindowDCImpl::CocoaGetBounds(void *rectData) |
9d180f3a | 89 | { |
3e21fc05 DE |
90 | if(!rectData) |
91 | return false; | |
92 | if(!m_lockedNSView) | |
93 | return false; | |
94 | NSRect *pRect = (NSRect*)rectData; | |
95 | *pRect = [m_lockedNSView bounds]; | |
96 | return true; | |
9d180f3a DE |
97 | } |
98 | ||
891d0563 | 99 | /* |
938156b2 | 100 | * wxClientDCImpl |
891d0563 | 101 | */ |
938156b2 | 102 | IMPLEMENT_ABSTRACT_CLASS(wxClientDCImpl, wxWindowDCImpl) |
891d0563 | 103 | |
938156b2 DE |
104 | wxClientDCImpl::wxClientDCImpl(wxDC *owner) |
105 | : wxWindowDCImpl(owner) | |
891d0563 DE |
106 | { |
107 | }; | |
108 | ||
938156b2 DE |
109 | wxClientDCImpl::wxClientDCImpl(wxDC *owner, wxWindow *window) |
110 | : wxWindowDCImpl(owner) | |
891d0563 | 111 | { |
d630f41d | 112 | m_window = window; |
891d0563 DE |
113 | }; |
114 | ||
938156b2 | 115 | wxClientDCImpl::~wxClientDCImpl(void) |
891d0563 | 116 | { |
fe8f7943 | 117 | CocoaUnwindStackAndLoseFocus(); |
891d0563 DE |
118 | }; |
119 | ||
938156b2 | 120 | bool wxClientDCImpl::CocoaLockFocus() |
fe8f7943 | 121 | { |
938156b2 | 122 | wxLogTrace(wxTRACE_COCOA,wxT("Locking focus on wxClientDCImpl=%p, NSView=%p"),this, m_window->GetNSView()); |
1a1e9ff1 DE |
123 | NSAffineTransform *newTransform = m_window->CocoaGetWxToBoundsTransform(); |
124 | [newTransform retain]; | |
125 | [m_cocoaWxToBoundsTransform release]; | |
126 | m_cocoaWxToBoundsTransform = newTransform; | |
b66e9853 | 127 | return CocoaLockFocusOnNSView(m_window->GetNSView()); |
fe8f7943 DE |
128 | } |
129 | ||
938156b2 | 130 | bool wxClientDCImpl::CocoaUnlockFocus() |
fe8f7943 | 131 | { |
938156b2 | 132 | wxLogTrace(wxTRACE_COCOA,wxT("Unlocking focus on wxClientDCImpl=%p, NSView=%p"),this, m_window->GetNSView()); |
b66e9853 | 133 | return CocoaUnlockFocusOnNSView(); |
fe8f7943 DE |
134 | } |
135 | ||
891d0563 | 136 | /* |
938156b2 | 137 | * wxPaintDCImpl |
891d0563 | 138 | */ |
938156b2 | 139 | IMPLEMENT_ABSTRACT_CLASS(wxPaintDCImpl, wxWindowDCImpl) |
891d0563 | 140 | |
938156b2 DE |
141 | wxPaintDCImpl::wxPaintDCImpl(wxDC *owner) |
142 | : wxWindowDCImpl(owner) | |
891d0563 DE |
143 | { |
144 | }; | |
145 | ||
938156b2 DE |
146 | wxPaintDCImpl::wxPaintDCImpl(wxDC *owner, wxWindow *window) |
147 | : wxWindowDCImpl(owner) | |
891d0563 | 148 | { |
d630f41d | 149 | m_window = window; |
938156b2 | 150 | wxASSERT_MSG([NSView focusView]==window->GetNSView(), wxT("PaintDC's NSView does not have focus. Please use wxPaintDCImpl only as the first DC created in a paint handler")); |
fe8f7943 | 151 | sm_cocoaDCStack.Insert(this); |
b66e9853 | 152 | m_lockedNSView = window->GetNSView(); |
1a1e9ff1 DE |
153 | NSAffineTransform *newTransform = window->CocoaGetWxToBoundsTransform(); |
154 | [newTransform retain]; | |
155 | [m_cocoaWxToBoundsTransform release]; | |
156 | m_cocoaWxToBoundsTransform = newTransform; | |
fe8f7943 | 157 | CocoaApplyTransformations(); |
891d0563 DE |
158 | }; |
159 | ||
938156b2 | 160 | wxPaintDCImpl::~wxPaintDCImpl(void) |
891d0563 | 161 | { |
fe8f7943 | 162 | CocoaUnwindStackAndLoseFocus(); |
891d0563 DE |
163 | }; |
164 | ||
938156b2 | 165 | bool wxPaintDCImpl::CocoaLockFocus() |
fe8f7943 | 166 | { |
938156b2 | 167 | wxFAIL_MSG(wxT("wxPaintDCImpl cannot be asked to lock focus!")); |
fe8f7943 DE |
168 | return false; |
169 | } | |
170 | ||
938156b2 | 171 | bool wxPaintDCImpl::CocoaUnlockFocus() |
fe8f7943 | 172 | { |
938156b2 | 173 | // wxPaintDCImpl focus can never be unlocked. |
fe8f7943 DE |
174 | return false; |
175 | } | |
176 |