]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/dcclient.cpp
FixMath fix
[wxWidgets.git] / src / mac / carbon / dcclient.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: dcclient.cpp
3 // Purpose: wxClientDC class
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 01/02/97
7 // RCS-ID: $Id$
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "dcclient.h"
14 #endif
15
16 #include "wx/wxprec.h"
17
18 #include "wx/dcclient.h"
19 #include "wx/dcmemory.h"
20 #include "wx/region.h"
21 #include "wx/window.h"
22 #include "wx/toplevel.h"
23 #include "wx/settings.h"
24 #include "wx/math.h"
25 #include "wx/mac/private.h"
26
27 //-----------------------------------------------------------------------------
28 // constants
29 //-----------------------------------------------------------------------------
30
31 #define RAD2DEG 57.2957795131
32
33 //-----------------------------------------------------------------------------
34 // wxPaintDC
35 //-----------------------------------------------------------------------------
36
37 #if !USE_SHARED_LIBRARY
38 IMPLEMENT_DYNAMIC_CLASS(wxWindowDC, wxDC)
39 IMPLEMENT_DYNAMIC_CLASS(wxClientDC, wxWindowDC)
40 IMPLEMENT_DYNAMIC_CLASS(wxPaintDC, wxWindowDC)
41 #endif
42
43 /*
44 * wxWindowDC
45 */
46
47 #include "wx/mac/uma.h"
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
103
104 wxWindowDC::wxWindowDC()
105 {
106 m_window = NULL ;
107 }
108
109 wxWindowDC::wxWindowDC(wxWindow *window)
110 {
111 m_window = window ;
112 wxTopLevelWindowMac* rootwindow = window->MacGetTopLevelWindow() ;
113 WindowRef windowref = (WindowRef) rootwindow->MacGetWindowRef() ;
114
115 int x , y ;
116 x = y = 0 ;
117 window->MacWindowToRootWindow( &x , &y ) ;
118 m_macLocalOrigin.x = x ;
119 m_macLocalOrigin.y = y ;
120 CopyRgn( (RgnHandle) window->MacGetVisibleRegion(true).GetWXHRGN() , (RgnHandle) m_macBoundaryClipRgn ) ;
121 OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , m_macLocalOrigin.x , m_macLocalOrigin.y ) ;
122 CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
123 m_macPort = UMAGetWindowPort( windowref ) ;
124 m_ok = TRUE ;
125 SetBackground(MacGetBackgroundBrush(window));
126 }
127
128 wxWindowDC::~wxWindowDC()
129 {
130 }
131
132 void wxWindowDC::DoGetSize( int* width, int* height ) const
133 {
134 wxCHECK_RET( m_window, _T("GetSize() doesn't work without window") );
135
136 m_window->GetSize(width, height);
137 }
138
139 /*
140 * wxClientDC
141 */
142
143 wxClientDC::wxClientDC()
144 {
145 m_window = NULL ;
146 }
147
148 wxClientDC::wxClientDC(wxWindow *window)
149 {
150 m_window = window ;
151 wxTopLevelWindowMac* rootwindow = window->MacGetTopLevelWindow() ;
152 if (!rootwindow)
153 return;
154 WindowRef windowref = (WindowRef) rootwindow->MacGetWindowRef() ;
155 wxPoint origin = window->GetClientAreaOrigin() ;
156 wxSize size = window->GetClientSize() ;
157 int x , y ;
158 x = origin.x ;
159 y = origin.y ;
160 window->MacWindowToRootWindow( &x , &y ) ;
161 m_macLocalOrigin.x = x ;
162 m_macLocalOrigin.y = y ;
163 SetRectRgn( (RgnHandle) m_macBoundaryClipRgn , origin.x , origin.y , origin.x + size.x , origin.y + size.y ) ;
164 SectRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) window->MacGetVisibleRegion().GetWXHRGN() , (RgnHandle) m_macBoundaryClipRgn ) ;
165 OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , -origin.x , -origin.y ) ;
166 OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , m_macLocalOrigin.x , m_macLocalOrigin.y ) ;
167 CopyRgn( (RgnHandle) m_macBoundaryClipRgn ,(RgnHandle) m_macCurrentClipRgn ) ;
168 m_macPort = UMAGetWindowPort( windowref ) ;
169
170 m_ok = TRUE ;
171 SetBackground(MacGetBackgroundBrush(window));
172 SetFont( window->GetFont() ) ;
173 }
174
175 wxClientDC::~wxClientDC()
176 {
177 }
178
179 void wxClientDC::DoGetSize(int *width, int *height) const
180 {
181 wxCHECK_RET( m_window, _T("GetSize() doesn't work without window") );
182
183 m_window->GetClientSize( width, height );
184 }
185
186
187 /*
188 * wxPaintDC
189 */
190
191 wxPaintDC::wxPaintDC()
192 {
193 m_window = NULL ;
194 }
195
196 wxPaintDC::wxPaintDC(wxWindow *window)
197 {
198 m_window = window ;
199 wxTopLevelWindowMac* rootwindow = window->MacGetTopLevelWindow() ;
200 WindowRef windowref = (WindowRef) rootwindow->MacGetWindowRef() ;
201 wxPoint origin = window->GetClientAreaOrigin() ;
202 wxSize size = window->GetClientSize() ;
203 int x , y ;
204 x = origin.x ;
205 y = origin.y ;
206 window->MacWindowToRootWindow( &x , &y ) ;
207 m_macLocalOrigin.x = x ;
208 m_macLocalOrigin.y = y ;
209 SetRectRgn( (RgnHandle) m_macBoundaryClipRgn , origin.x , origin.y , origin.x + size.x , origin.y + size.y ) ;
210 SectRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) window->MacGetVisibleRegion().GetWXHRGN() , (RgnHandle) m_macBoundaryClipRgn ) ;
211 OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , -origin.x , -origin.y ) ;
212 SectRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) window->GetUpdateRegion().GetWXHRGN() , (RgnHandle) m_macBoundaryClipRgn ) ;
213 OffsetRgn( (RgnHandle) m_macBoundaryClipRgn , m_macLocalOrigin.x , m_macLocalOrigin.y ) ;
214 CopyRgn( (RgnHandle) m_macBoundaryClipRgn , (RgnHandle) m_macCurrentClipRgn ) ;
215 m_macPort = UMAGetWindowPort( windowref ) ;
216
217 m_ok = TRUE ;
218 SetBackground(MacGetBackgroundBrush(window));
219 SetFont( window->GetFont() ) ;
220 }
221
222 wxPaintDC::~wxPaintDC()
223 {
224 }
225
226 void wxPaintDC::DoGetSize(int *width, int *height) const
227 {
228 wxCHECK_RET( m_window, _T("GetSize() doesn't work without window") );
229
230 m_window->GetClientSize( width, height );
231 }
232
233