]>
Commit | Line | Data |
---|---|---|
9c7f49f5 VZ |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Name: mac/renderer.cpp | |
38c4cb6a | 3 | // Purpose: implementation of wxRendererNative for Mac |
9c7f49f5 VZ |
4 | // Author: Vadim Zeitlin |
5 | // Modified by: | |
6 | // Created: 20.07.2003 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwindows.org> | |
65571936 | 9 | // License: wxWindows licence |
9c7f49f5 VZ |
10 | /////////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | // ============================================================================ | |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
20 | // for compilers that support precompilation, includes "wx.h". | |
21 | #include "wx/wxprec.h" | |
22 | ||
23 | #ifdef __BORLANDC__ | |
24 | #pragma hdrstop | |
25 | #endif | |
26 | ||
27 | #ifndef WX_PRECOMP | |
28 | #include "wx/string.h" | |
4c948343 VZ |
29 | #include "wx/dc.h" |
30 | #include "wx/bitmap.h" | |
31 | #include "wx/settings.h" | |
9c7f49f5 VZ |
32 | #endif //WX_PRECOMP |
33 | ||
34 | #include "wx/renderer.h" | |
5d91a088 GD |
35 | #include "wx/toplevel.h" |
36 | #include "wx/dcclient.h" | |
547aafd2 | 37 | #include "wx/mac/uma.h" |
9c7f49f5 VZ |
38 | |
39 | // ---------------------------------------------------------------------------- | |
38c4cb6a | 40 | // wxRendererMac: our wxRendererNative implementation |
9c7f49f5 VZ |
41 | // ---------------------------------------------------------------------------- |
42 | ||
5cb80ad2 | 43 | class WXDLLEXPORT wxRendererMac : public wxDelegateRendererNative |
9c7f49f5 VZ |
44 | { |
45 | public: | |
46 | // draw the header control button (used by wxListCtrl) | |
47 | virtual void DrawHeaderButton(wxWindow *win, | |
48 | wxDC& dc, | |
49 | const wxRect& rect, | |
50 | int flags = 0); | |
51 | ||
52 | // draw the expanded/collapsed icon for a tree control item | |
53 | virtual void DrawTreeItemButton(wxWindow *win, | |
54 | wxDC& dc, | |
55 | const wxRect& rect, | |
56 | int flags = 0); | |
57 | ||
b3208e11 VZ |
58 | // draw a (vertical) sash |
59 | virtual void DrawSplitterSash(wxWindow *win, | |
60 | wxDC& dc, | |
61 | const wxSize& size, | |
62dc9cb4 | 62 | wxCoord position, |
af99040c VZ |
63 | wxOrientation orient, |
64 | int flags = 0); | |
b3208e11 | 65 | |
9c7f49f5 VZ |
66 | private: |
67 | // the tree buttons | |
68 | wxBitmap m_bmpTreeExpanded, | |
69 | m_bmpTreeCollapsed; | |
70 | }; | |
71 | ||
72 | // ---------------------------------------------------------------------------- | |
73 | // Aqua arrows | |
74 | // ---------------------------------------------------------------------------- | |
75 | ||
76 | /* XPM */ | |
77 | static const char *aqua_arrow_right_xpm[] = { | |
78 | /* columns rows colors chars-per-pixel */ | |
79 | "13 11 4 1", | |
80 | " c None", | |
81 | "b c #C0C0C0", | |
82 | "c c #707070", | |
83 | "d c #A0A0A0", | |
84 | /* pixels */ | |
85 | " b ", | |
86 | " ddb ", | |
87 | " cccdb ", | |
88 | " cccccd ", | |
89 | " ccccccdb ", | |
90 | " ccccccccd", | |
91 | " ccccccdb ", | |
92 | " cccccb ", | |
93 | " cccdb ", | |
94 | " ddb ", | |
95 | " b " | |
96 | }; | |
97 | ||
98 | /* XPM */ | |
99 | static const char *aqua_arrow_down_xpm[] = { | |
100 | /* columns rows colors chars-per-pixel */ | |
101 | "13 11 4 1", | |
102 | " c None", | |
103 | "b c #C0C0C0", | |
104 | "c c #707070", | |
105 | "d c #A0A0A0", | |
106 | /* pixels */ | |
107 | " ", | |
108 | " ", | |
109 | " bdcccccccdb ", | |
110 | " dcccccccd ", | |
111 | " bcccccccb ", | |
112 | " dcccccd ", | |
113 | " bcccccb ", | |
114 | " bcccd ", | |
115 | " dcd ", | |
116 | " bcb ", | |
117 | " d " | |
118 | }; | |
119 | ||
120 | // ============================================================================ | |
121 | // implementation | |
122 | // ============================================================================ | |
123 | ||
124 | /* static */ | |
f0244295 | 125 | wxRendererNative& wxRendererNative::GetDefault() |
9c7f49f5 VZ |
126 | { |
127 | static wxRendererMac s_rendererMac; | |
128 | ||
129 | return s_rendererMac; | |
130 | } | |
131 | ||
132 | void | |
133 | wxRendererMac::DrawHeaderButton(wxWindow *win, | |
134 | wxDC& dc, | |
135 | const wxRect& rect, | |
69342052 | 136 | int flags) |
9c7f49f5 | 137 | { |
6fe1627c SC |
138 | const wxCoord x = dc.XLOG2DEV(rect.x-1), |
139 | y = dc.YLOG2DEV(rect.y-1), | |
140 | w = dc.XLOG2DEVREL(rect.width), | |
141 | h = dc.YLOG2DEVREL(rect.height); | |
9c7f49f5 | 142 | |
11d1adbf SC |
143 | int major,minor; |
144 | wxGetOsVersion( &major, &minor ); | |
9c7f49f5 | 145 | |
11d1adbf | 146 | dc.SetBrush( *wxTRANSPARENT_BRUSH ); |
9c7f49f5 | 147 | |
2480cf88 SC |
148 | #if defined(__WXMAC_OSX__) && ( MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3 ) |
149 | if ( HIThemeDrawButton != 0 ) | |
150 | { | |
151 | HIRect headerRect = CGRectMake( x , y , w , h ); | |
152 | if ( dc.IsKindOf( CLASSINFO( wxPaintDC ) ) == false ) | |
153 | { | |
154 | Rect r = { (short) headerRect.origin.y , (short) headerRect.origin.x , | |
155 | (short) (headerRect.origin.y + headerRect.size.height) , (short) (headerRect.origin.x + headerRect.size.width) } ; | |
156 | RgnHandle updateRgn = NewRgn() ; | |
157 | RectRgn( updateRgn , &r ) ; | |
158 | HIViewSetNeedsDisplayInRegion( (HIViewRef) win->GetHandle() , updateRgn , true ) ; | |
159 | DisposeRgn( updateRgn ) ; | |
160 | } | |
161 | else | |
162 | { | |
163 | CGContextRef cgContext ; | |
164 | #if wxMAC_USE_CORE_GRAPHICS | |
1b144125 | 165 | cgContext = ((wxMacCGContext*)(dc.GetGraphicContext()))->GetNativeContext() ; |
2480cf88 SC |
166 | #else |
167 | Rect bounds ; | |
168 | GetPortBounds( (CGrafPtr) dc.m_macPort , &bounds ) ; | |
169 | QDBeginCGContext( (CGrafPtr) dc.m_macPort , &cgContext ) ; | |
170 | CGContextTranslateCTM( cgContext , 0 , bounds.bottom - bounds.top ) ; | |
171 | CGContextScaleCTM( cgContext , 1 , -1 ) ; | |
6fe1627c SC |
172 | HIShapeReplacePathInCGContext( HIShapeCreateWithQDRgn( (RgnHandle) dc.m_macCurrentClipRgn ) , cgContext ) ; |
173 | CGContextClip( cgContext ) ; | |
69342052 | 174 | HIViewConvertRect( &headerRect , (HIViewRef) win->GetHandle() , (HIViewRef) win->MacGetTopLevelWindow()->GetHandle() ) ; |
2480cf88 SC |
175 | #endif |
176 | { | |
177 | HIThemeButtonDrawInfo drawInfo ; | |
178 | HIRect labelRect ; | |
179 | memset( &drawInfo , 0 , sizeof(drawInfo) ) ; | |
180 | drawInfo.version = 0 ; | |
69342052 | 181 | drawInfo.state = ( flags & wxCONTROL_DISABLED ) ? kThemeStateInactive : kThemeStateActive ; |
2480cf88 SC |
182 | drawInfo.kind = kThemeListHeaderButton ; |
183 | drawInfo.value = 0 ; | |
184 | drawInfo.adornment = kThemeAdornmentNone ; | |
185 | HIThemeDrawButton( &headerRect , &drawInfo , cgContext , kHIThemeOrientationNormal , &labelRect ) ; | |
186 | } | |
187 | #if wxMAC_USE_CORE_GRAPHICS | |
188 | #else | |
189 | QDEndCGContext( (CGrafPtr) dc.m_macPort , &cgContext ) ; | |
190 | #endif | |
191 | } | |
192 | } | |
193 | else | |
194 | #endif | |
11d1adbf | 195 | { |
69342052 SC |
196 | wxMacWindowClipper clipper(win) ; |
197 | Rect rect = { y , x , y + h , x + w } ; | |
198 | wxPoint origin = win->GetClientAreaOrigin() ; | |
199 | int dx , dy ; | |
200 | dx = origin.x ; | |
201 | dy = origin.y ; | |
202 | win->MacWindowToRootWindow( &dx , &dy ) ; | |
203 | OffsetRect( &rect , dx , dy ) ; | |
204 | ||
205 | ThemeButtonDrawInfo drawInfo ; | |
206 | memset( &drawInfo , 0 , sizeof(drawInfo) ) ; | |
207 | drawInfo.state = ( flags & wxCONTROL_DISABLED ) ? kThemeStateInactive : kThemeStateActive ; | |
208 | drawInfo.value = 0 ; | |
209 | drawInfo.adornment = kThemeAdornmentNone ; | |
210 | DrawThemeButton( &rect , kThemeListHeaderButton , &drawInfo , NULL , NULL , NULL , 0 ) ; | |
11d1adbf | 211 | } |
9c7f49f5 VZ |
212 | } |
213 | ||
214 | void | |
215 | wxRendererMac::DrawTreeItemButton(wxWindow *win, | |
216 | wxDC& dc, | |
217 | const wxRect& rect, | |
218 | int flags) | |
219 | { | |
220 | // init the buttons on demand | |
221 | if ( !m_bmpTreeExpanded.Ok() ) | |
222 | { | |
223 | m_bmpTreeExpanded = wxBitmap(aqua_arrow_down_xpm); | |
224 | m_bmpTreeCollapsed = wxBitmap(aqua_arrow_right_xpm); | |
225 | } | |
226 | ||
227 | // draw them | |
228 | ||
229 | // VZ: this is the old code from treectlg.cpp which apparently doesn't work | |
230 | // but I kept it here just in case it is needed -- if not, please | |
231 | // remove it | |
232 | #if 0 // def __WXMAC__ | |
233 | wxMacPortSetter helper(&dc) ; | |
234 | wxMacWindowClipper clipper(this) ; | |
235 | wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ; | |
236 | ||
237 | int loc_x = x - 5 ; | |
238 | int loc_y = y_mid - 6 ; | |
239 | MacWindowToRootWindow( & loc_x , & loc_y ) ; | |
240 | Rect bounds = { loc_y , loc_x , loc_y + 18 , loc_x + 12 } ; | |
241 | ThemeButtonDrawInfo info = { kThemeStateActive , item->IsExpanded() ? kThemeDisclosureDown : kThemeDisclosureRight , | |
242 | kThemeAdornmentNone }; | |
243 | DrawThemeButton( &bounds, kThemeDisclosureButton , | |
244 | &info , NULL , NULL , NULL , NULL ) ; | |
245 | #else // 1 | |
246 | dc.DrawBitmap(flags & wxCONTROL_EXPANDED ? m_bmpTreeExpanded | |
247 | : m_bmpTreeCollapsed, | |
248 | rect.x, rect.y, true /* use mask */); | |
249 | #endif // 0/1 | |
250 | } | |
251 | ||
b3208e11 | 252 | void |
e356d469 VZ |
253 | wxRendererMac::DrawSplitterSash(wxWindow *win, |
254 | wxDC& dc, | |
255 | const wxSize& size, | |
62dc9cb4 | 256 | wxCoord position, |
af99040c VZ |
257 | wxOrientation orient, |
258 | int WXUNUSED(flags)) | |
b3208e11 | 259 | { |
2480cf88 SC |
260 | #if defined(__WXMAC_OSX__) && ( MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3 ) |
261 | if ( HIThemeDrawPaneSplitter != 0 ) | |
eef4e26c | 262 | { |
547aafd2 SC |
263 | bool hasMetal = win->MacGetTopLevelWindow()->MacGetMetalAppearance() ; |
264 | SInt32 height ; | |
265 | GetThemeMetric( kThemeMetricSmallPaneSplitterHeight , &height ) ; | |
266 | HIRect splitterRect ; | |
267 | if ( orient == wxVERTICAL ) | |
268 | splitterRect = CGRectMake( position , 0 , height, size.y); | |
269 | else | |
270 | splitterRect = CGRectMake( 0 , position , size.x , height ); | |
2480cf88 | 271 | #if !wxMAC_USE_CORE_GRAPHICS |
547aafd2 | 272 | HIViewConvertRect( &splitterRect , (HIViewRef) win->GetHandle() , (HIViewRef) win->MacGetTopLevelWindow()->GetHandle() ) ; |
2480cf88 | 273 | #endif |
547aafd2 SC |
274 | |
275 | // under compositing we should only draw when called by the OS, otherwise just issue a redraw command | |
276 | // strange redraw errors occur if we don't do this | |
277 | ||
278 | if ( dc.IsKindOf( CLASSINFO( wxPaintDC ) ) == false ) | |
eef4e26c | 279 | { |
36168292 DS |
280 | Rect r = { (short) splitterRect.origin.y , (short) splitterRect.origin.x , |
281 | (short) (splitterRect.origin.y + splitterRect.size.height) , (short) (splitterRect.origin.x + splitterRect.size.width) } ; | |
547aafd2 SC |
282 | RgnHandle updateRgn = NewRgn() ; |
283 | RectRgn( updateRgn , &r ) ; | |
284 | HIViewSetNeedsDisplayInRegion( (HIViewRef) win->GetHandle() , updateRgn , true ) ; | |
285 | DisposeRgn( updateRgn ) ; | |
286 | } | |
287 | else | |
288 | { | |
2480cf88 | 289 | CGContextRef cgContext ; |
20b69855 | 290 | #if wxMAC_USE_CORE_GRAPHICS |
1b144125 | 291 | cgContext = ((wxMacCGContext*)(dc.GetGraphicContext()))->GetNativeContext() ; |
20b69855 | 292 | #else |
547aafd2 SC |
293 | Rect bounds ; |
294 | GetPortBounds( (CGrafPtr) dc.m_macPort , &bounds ) ; | |
295 | QDBeginCGContext( (CGrafPtr) dc.m_macPort , &cgContext ) ; | |
296 | CGContextTranslateCTM( cgContext , 0 , bounds.bottom - bounds.top ) ; | |
297 | CGContextScaleCTM( cgContext , 1 , -1 ) ; | |
2480cf88 | 298 | #endif |
547aafd2 | 299 | |
2480cf88 SC |
300 | HIThemeSplitterDrawInfo drawInfo ; |
301 | drawInfo.version = 0 ; | |
302 | drawInfo.state = kThemeStateActive ; | |
303 | drawInfo.adornment = hasMetal ? kHIThemeSplitterAdornmentMetal : kHIThemeSplitterAdornmentNone ; | |
304 | HIThemeDrawPaneSplitter( &splitterRect , &drawInfo , cgContext , kHIThemeOrientationNormal ) ; | |
305 | ||
306 | #if wxMAC_USE_CORE_GRAPHICS | |
307 | #else | |
547aafd2 | 308 | QDEndCGContext( (CGrafPtr) dc.m_macPort , &cgContext ) ; |
20b69855 | 309 | #endif |
eef4e26c RR |
310 | } |
311 | } | |
312 | else | |
547aafd2 | 313 | #endif |
eef4e26c | 314 | { |
547aafd2 SC |
315 | // Do the gradient fill: |
316 | static int grayValues[] = | |
eef4e26c | 317 | { |
547aafd2 SC |
318 | 0xA0, 0xF6, 0xED, 0xE4, 0xE2, 0xD0, 0xA0 |
319 | }; | |
320 | dc.SetBrush( *wxTRANSPARENT_BRUSH ); | |
321 | if ( orient == wxVERTICAL ) | |
322 | { | |
323 | int i; | |
324 | for (i=0; i < (int)WXSIZEOF(grayValues); i++) | |
325 | { | |
326 | dc.SetPen( wxPen( wxColour( grayValues[i] , grayValues[i] , grayValues[i] ), | |
327 | 1 , wxSOLID ) ); | |
328 | dc.DrawRectangle( position+i, 0, 1, size.y ); | |
329 | } | |
330 | } | |
331 | else | |
332 | { | |
333 | int i; | |
334 | for (i=0; i < (int)WXSIZEOF(grayValues); i++) | |
335 | { | |
336 | dc.SetPen( wxPen( wxColour( grayValues[i] , grayValues[i] , grayValues[i] ), | |
337 | 1 , wxSOLID ) ); | |
338 | dc.DrawRectangle( 0, position+i, size.x, 1 ); | |
339 | } | |
eef4e26c | 340 | } |
547aafd2 | 341 | } |
b3208e11 VZ |
342 | } |
343 |