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