]>
Commit | Line | Data |
---|---|---|
e9576ca5 SC |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: dcclient.cpp | |
3 | // Purpose: wxClientDC class | |
a31a5f85 | 4 | // Author: Stefan Csomor |
e9576ca5 SC |
5 | // Modified by: |
6 | // Created: 01/02/97 | |
7 | // RCS-ID: $Id$ | |
a31a5f85 | 8 | // Copyright: (c) Stefan Csomor |
65571936 | 9 | // Licence: wxWindows licence |
e9576ca5 SC |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
3d1a4878 | 12 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
e9576ca5 SC |
13 | #pragma implementation "dcclient.h" |
14 | #endif | |
15 | ||
3d1a4878 SC |
16 | #include "wx/wxprec.h" |
17 | ||
e9576ca5 SC |
18 | #include "wx/dcclient.h" |
19 | #include "wx/dcmemory.h" | |
20 | #include "wx/region.h" | |
03e11df5 | 21 | #include "wx/window.h" |
456c94e1 | 22 | #include "wx/toplevel.h" |
5f5f809d | 23 | #include "wx/settings.h" |
463c4d71 | 24 | #include "wx/math.h" |
76a5e5d2 | 25 | #include "wx/mac/private.h" |
e9576ca5 SC |
26 | |
27 | //----------------------------------------------------------------------------- | |
28 | // constants | |
29 | //----------------------------------------------------------------------------- | |
30 | ||
31 | #define RAD2DEG 57.2957795131 | |
32 | ||
33 | //----------------------------------------------------------------------------- | |
34 | // wxPaintDC | |
35 | //----------------------------------------------------------------------------- | |
36 | ||
2f1ae414 | 37 | #if !USE_SHARED_LIBRARY |
e9576ca5 SC |
38 | IMPLEMENT_DYNAMIC_CLASS(wxWindowDC, wxDC) |
39 | IMPLEMENT_DYNAMIC_CLASS(wxClientDC, wxWindowDC) | |
40 | IMPLEMENT_DYNAMIC_CLASS(wxPaintDC, wxWindowDC) | |
2f1ae414 | 41 | #endif |
e9576ca5 SC |
42 | |
43 | /* | |
44 | * wxWindowDC | |
45 | */ | |
46 | ||
d497dca4 | 47 | #include "wx/mac/uma.h" |
be346c26 SC |
48 | #include "wx/notebook.h" |
49 | #include "wx/tabctrl.h" | |
50 | ||
51 | ||
52 | static wxBrush MacGetBackgroundBrush( wxWindow* window ) | |
53 | { | |
54 | wxBrush bkdBrush = window->MacGetBackgroundBrush() ; | |
55 | #if !TARGET_API_MAC_OSX | |
56 | // transparency cannot be handled by the OS when not using composited windows | |
57 | wxWindow* parent = window->GetParent() ; | |
58 | // if we have some 'pseudo' transparency | |
59 | if ( ! bkdBrush.Ok() || bkdBrush.GetStyle() == wxTRANSPARENT || window->GetBackgroundColour() == wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE ) ) | |
60 | { | |
61 | // walk up until we find something | |
62 | while( parent != NULL ) | |
63 | { | |
64 | if ( parent->GetBackgroundColour() != wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE ) ) | |
65 | { | |
66 | // if we have any other colours in the hierarchy | |
67 | bkdBrush.SetColour( parent->GetBackgroundColour() ) ; | |
68 | break ; | |
69 | } | |
70 | if ( parent->IsKindOf( CLASSINFO(wxTopLevelWindow) ) ) | |
71 | { | |
72 | bkdBrush = parent->MacGetBackgroundBrush() ; | |
73 | break ; | |
74 | } | |
75 | if ( parent->IsKindOf( CLASSINFO( wxNotebook ) ) || parent->IsKindOf( CLASSINFO( wxTabCtrl ) ) ) | |
76 | { | |
77 | Rect extent = { 0 , 0 , 0 , 0 } ; | |
78 | int x , y ; | |
79 | x = y = 0 ; | |
80 | wxSize size = parent->GetSize() ; | |
81 | parent->MacClientToRootWindow( &x , &y ) ; | |
82 | extent.left = x ; | |
83 | extent.top = y ; | |
84 | extent.top-- ; | |
85 | extent.right = x + size.x ; | |
86 | extent.bottom = y + size.y ; | |
87 | bkdBrush.MacSetThemeBackground( kThemeBackgroundTabPane , (WXRECTPTR) &extent ) ; | |
88 | break ; | |
89 | } | |
90 | ||
91 | parent = parent->GetParent() ; | |
92 | } | |
93 | } | |
94 | if ( !bkdBrush.Ok() || bkdBrush.GetStyle() == wxTRANSPARENT ) | |
95 | { | |
96 | // if we did not find something, use a default | |
97 | bkdBrush.MacSetTheme( kThemeBrushDialogBackgroundActive ) ; | |
98 | } | |
99 | #endif | |
100 | return bkdBrush ; | |
101 | } | |
102 | ||
519cb848 | 103 | |
2f1ae414 | 104 | wxWindowDC::wxWindowDC() |
e9576ca5 | 105 | { |
1be0560e | 106 | m_window = NULL ; |
519cb848 | 107 | } |
e9576ca5 | 108 | |
1be0560e | 109 | wxWindowDC::wxWindowDC(wxWindow *window) |
519cb848 | 110 | { |
1be0560e SC |
111 | m_window = window ; |
112 | wxTopLevelWindowMac* rootwindow = window->MacGetTopLevelWindow() ; | |
e40298d5 JS |
113 | WindowRef windowref = (WindowRef) rootwindow->MacGetWindowRef() ; |
114 | ||
115 | int x , y ; | |
116 | x = y = 0 ; | |
1be0560e | 117 | window->MacWindowToRootWindow( &x , &y ) ; |
e40298d5 JS |
118 | m_macLocalOrigin.x = x ; |
119 | m_macLocalOrigin.y = y ; | |
cf9d0f93 | 120 | CopyRgn( (RgnHandle) window->MacGetVisibleRegion(true).GetWXHRGN() , (RgnHandle) m_macBoundaryClipRgn ) ; |
e40298d5 JS |
121 | OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , m_macLocalOrigin.x , m_macLocalOrigin.y ) ; |
122 | CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ; | |
123 | m_macPort = UMAGetWindowPort( windowref ) ; | |
1be0560e | 124 | m_ok = TRUE ; |
613a24f7 | 125 | MacSetupGraphicContext() ; |
be346c26 | 126 | SetBackground(MacGetBackgroundBrush(window)); |
519cb848 | 127 | } |
e9576ca5 | 128 | |
2f1ae414 | 129 | wxWindowDC::~wxWindowDC() |
e9576ca5 | 130 | { |
519cb848 | 131 | } |
e9576ca5 | 132 | |
1be0560e SC |
133 | void wxWindowDC::DoGetSize( int* width, int* height ) const |
134 | { | |
135 | wxCHECK_RET( m_window, _T("GetSize() doesn't work without window") ); | |
136 | ||
137 | m_window->GetSize(width, height); | |
138 | } | |
139 | ||
519cb848 SC |
140 | /* |
141 | * wxClientDC | |
142 | */ | |
e9576ca5 | 143 | |
2f1ae414 | 144 | wxClientDC::wxClientDC() |
e9576ca5 | 145 | { |
1be0560e | 146 | m_window = NULL ; |
e9576ca5 SC |
147 | } |
148 | ||
519cb848 | 149 | wxClientDC::wxClientDC(wxWindow *window) |
e9576ca5 | 150 | { |
1be0560e | 151 | m_window = window ; |
e40298d5 JS |
152 | wxTopLevelWindowMac* rootwindow = window->MacGetTopLevelWindow() ; |
153 | if (!rootwindow) | |
154 | return; | |
155 | WindowRef windowref = (WindowRef) rootwindow->MacGetWindowRef() ; | |
156 | wxPoint origin = window->GetClientAreaOrigin() ; | |
157 | wxSize size = window->GetClientSize() ; | |
158 | int x , y ; | |
159 | x = origin.x ; | |
160 | y = origin.y ; | |
161 | window->MacWindowToRootWindow( &x , &y ) ; | |
162 | m_macLocalOrigin.x = x ; | |
163 | m_macLocalOrigin.y = y ; | |
164 | SetRectRgn( (RgnHandle) m_macBoundaryClipRgn , origin.x , origin.y , origin.x + size.x , origin.y + size.y ) ; | |
165 | SectRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) window->MacGetVisibleRegion().GetWXHRGN() , (RgnHandle) m_macBoundaryClipRgn ) ; | |
166 | OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , -origin.x , -origin.y ) ; | |
167 | OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , m_macLocalOrigin.x , m_macLocalOrigin.y ) ; | |
168 | CopyRgn( (RgnHandle) m_macBoundaryClipRgn ,(RgnHandle) m_macCurrentClipRgn ) ; | |
169 | m_macPort = UMAGetWindowPort( windowref ) ; | |
1be0560e | 170 | |
e40298d5 | 171 | m_ok = TRUE ; |
613a24f7 | 172 | MacSetupGraphicContext() ; |
be346c26 | 173 | SetBackground(MacGetBackgroundBrush(window)); |
e40298d5 | 174 | SetFont( window->GetFont() ) ; |
e9576ca5 SC |
175 | } |
176 | ||
2f1ae414 | 177 | wxClientDC::~wxClientDC() |
e9576ca5 | 178 | { |
e9576ca5 SC |
179 | } |
180 | ||
1be0560e SC |
181 | void wxClientDC::DoGetSize(int *width, int *height) const |
182 | { | |
183 | wxCHECK_RET( m_window, _T("GetSize() doesn't work without window") ); | |
184 | ||
185 | m_window->GetClientSize( width, height ); | |
186 | } | |
187 | ||
188 | ||
519cb848 SC |
189 | /* |
190 | * wxPaintDC | |
191 | */ | |
e9576ca5 | 192 | |
2f1ae414 | 193 | wxPaintDC::wxPaintDC() |
e9576ca5 | 194 | { |
1be0560e | 195 | m_window = NULL ; |
e9576ca5 SC |
196 | } |
197 | ||
519cb848 | 198 | wxPaintDC::wxPaintDC(wxWindow *window) |
e9576ca5 | 199 | { |
1be0560e | 200 | m_window = window ; |
e40298d5 JS |
201 | wxTopLevelWindowMac* rootwindow = window->MacGetTopLevelWindow() ; |
202 | WindowRef windowref = (WindowRef) rootwindow->MacGetWindowRef() ; | |
203 | wxPoint origin = window->GetClientAreaOrigin() ; | |
204 | wxSize size = window->GetClientSize() ; | |
205 | int x , y ; | |
206 | x = origin.x ; | |
207 | y = origin.y ; | |
208 | window->MacWindowToRootWindow( &x , &y ) ; | |
209 | m_macLocalOrigin.x = x ; | |
210 | m_macLocalOrigin.y = y ; | |
211 | SetRectRgn( (RgnHandle) m_macBoundaryClipRgn , origin.x , origin.y , origin.x + size.x , origin.y + size.y ) ; | |
212 | SectRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) window->MacGetVisibleRegion().GetWXHRGN() , (RgnHandle) m_macBoundaryClipRgn ) ; | |
213 | OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , -origin.x , -origin.y ) ; | |
214 | SectRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) window->GetUpdateRegion().GetWXHRGN() , (RgnHandle) m_macBoundaryClipRgn ) ; | |
215 | OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , m_macLocalOrigin.x , m_macLocalOrigin.y ) ; | |
216 | CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ; | |
217 | m_macPort = UMAGetWindowPort( windowref ) ; | |
1be0560e | 218 | |
e40298d5 | 219 | m_ok = TRUE ; |
613a24f7 | 220 | MacSetupGraphicContext() ; |
be346c26 | 221 | SetBackground(MacGetBackgroundBrush(window)); |
e40298d5 | 222 | SetFont( window->GetFont() ) ; |
e9576ca5 SC |
223 | } |
224 | ||
519cb848 | 225 | wxPaintDC::~wxPaintDC() |
e9576ca5 | 226 | { |
519cb848 | 227 | } |
1be0560e SC |
228 | |
229 | void wxPaintDC::DoGetSize(int *width, int *height) const | |
230 | { | |
231 | wxCHECK_RET( m_window, _T("GetSize() doesn't work without window") ); | |
232 | ||
233 | m_window->GetClientSize( width, height ); | |
234 | } | |
235 | ||
236 |