]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/renderer.cpp
porting forward scrolling fix
[wxWidgets.git] / src / mac / carbon / renderer.cpp
CommitLineData
9c7f49f5 1///////////////////////////////////////////////////////////////////////////////
7af14d71 2// Name: src/mac/carbon/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
9c7f49f5
VZ
12// for compilers that support precompilation, includes "wx.h".
13#include "wx/wxprec.h"
14
15#ifdef __BORLANDC__
16 #pragma hdrstop
17#endif
18
19#ifndef WX_PRECOMP
20 #include "wx/string.h"
4c948343
VZ
21 #include "wx/dc.h"
22 #include "wx/bitmap.h"
23 #include "wx/settings.h"
ed4b0fdc 24 #include "wx/dcclient.h"
1832043f 25 #include "wx/toplevel.h"
7af14d71 26#endif
9c7f49f5
VZ
27
28#include "wx/renderer.h"
8acd14d1 29#include "wx/graphics.h"
547aafd2 30#include "wx/mac/uma.h"
9c7f49f5 31
9c7f49f5 32
5cb80ad2 33class WXDLLEXPORT wxRendererMac : public wxDelegateRendererNative
9c7f49f5
VZ
34{
35public:
36 // draw the header control button (used by wxListCtrl)
c97c9952 37 virtual int DrawHeaderButton( wxWindow *win,
7af14d71
DS
38 wxDC& dc,
39 const wxRect& rect,
4b94ddc4 40 int flags = 0,
80752b57 41 wxHeaderSortIconType sortArrow = wxHDR_SORT_ICON_NONE,
4b94ddc4 42 wxHeaderButtonParams* params = NULL );
9c7f49f5 43
4b94ddc4 44 virtual int GetHeaderButtonHeight(wxWindow *win);
a61c9122 45
9c7f49f5 46 // draw the expanded/collapsed icon for a tree control item
7af14d71
DS
47 virtual void DrawTreeItemButton( wxWindow *win,
48 wxDC& dc,
49 const wxRect& rect,
50 int flags = 0 );
9c7f49f5 51
b3208e11 52 // draw a (vertical) sash
7af14d71
DS
53 virtual void DrawSplitterSash( wxWindow *win,
54 wxDC& dc,
55 const wxSize& size,
56 wxCoord position,
57 wxOrientation orient,
58 int flags = 0 );
cf511e87 59
6239ee05
SC
60 virtual void DrawCheckBox(wxWindow *win,
61 wxDC& dc,
62 const wxRect& rect,
63 int flags = 0);
64
cf511e87
RD
65 virtual void DrawComboBoxDropButton(wxWindow *win,
66 wxDC& dc,
67 const wxRect& rect,
68 int flags = 0);
a61c9122 69
cf511e87
RD
70 virtual void DrawPushButton(wxWindow *win,
71 wxDC& dc,
72 const wxRect& rect,
73 int flags = 0);
a61c9122 74
a4609ab8
KO
75 virtual void DrawItemSelectionRect(wxWindow *win,
76 wxDC& dc,
77 const wxRect& rect,
78 int flags = 0);
b3208e11 79
688a201a
JS
80 virtual void DrawFocusRect(wxWindow* win, wxDC& dc, const wxRect& rect, int flags = 0);
81
9c7f49f5 82private:
cf511e87
RD
83 void DrawMacThemeButton(wxWindow *win,
84 wxDC& dc,
85 const wxRect& rect,
86 int flags,
87 int kind,
88 int adornment);
a61c9122 89
9c7f49f5 90 // the tree buttons
7af14d71
DS
91 wxBitmap m_bmpTreeExpanded;
92 wxBitmap m_bmpTreeCollapsed;
9c7f49f5
VZ
93};
94
9c7f49f5
VZ
95// ============================================================================
96// implementation
97// ============================================================================
98
7af14d71 99// static
f0244295 100wxRendererNative& wxRendererNative::GetDefault()
9c7f49f5
VZ
101{
102 static wxRendererMac s_rendererMac;
103
104 return s_rendererMac;
105}
106
c97c9952 107int wxRendererMac::DrawHeaderButton( wxWindow *win,
7af14d71
DS
108 wxDC& dc,
109 const wxRect& rect,
4b94ddc4 110 int flags,
80752b57 111 wxHeaderSortIconType sortArrow,
4b94ddc4 112 wxHeaderButtonParams* params )
9c7f49f5 113{
1c5decd0
SC
114 const wxCoord x = rect.x;
115 const wxCoord y = rect.y;
116 const wxCoord w = rect.width;
117 const wxCoord h = rect.height;
7af14d71 118
11d1adbf 119 dc.SetBrush( *wxTRANSPARENT_BRUSH );
9c7f49f5 120
a62f32af
SC
121 HIRect headerRect = CGRectMake( x, y, w, h );
122 if ( !dc.IsKindOf( CLASSINFO( wxPaintDC ) ) )
2480cf88 123 {
f968da28 124 win->Refresh( &rect );
a62f32af
SC
125 }
126 else
127 {
128 CGContextRef cgContext;
7af14d71 129
be01a403 130 cgContext = (CGContextRef) dc.GetGraphicsContext()->GetNativeContext();
7af14d71 131
a62f32af
SC
132 {
133 HIThemeButtonDrawInfo drawInfo;
134 HIRect labelRect;
7af14d71 135
a62f32af
SC
136 memset( &drawInfo, 0, sizeof(drawInfo) );
137 drawInfo.version = 0;
a62f32af 138 drawInfo.kind = kThemeListHeaderButton;
4b94ddc4
RD
139 drawInfo.state = (flags & wxCONTROL_DISABLED) ? kThemeStateInactive : kThemeStateActive;
140 drawInfo.value = (flags & wxCONTROL_SELECTED) ? kThemeButtonOn : kThemeButtonOff;
a62f32af 141 drawInfo.adornment = kThemeAdornmentNone;
4b94ddc4
RD
142
143 // The down arrow is drawn automatically, change it to an up arrow if needed.
80752b57 144 if ( sortArrow == wxHDR_SORT_ICON_UP )
4b94ddc4 145 drawInfo.adornment = kThemeAdornmentHeaderButtonSortUp;
a61c9122 146
a62f32af 147 HIThemeDrawButton( &headerRect, &drawInfo, cgContext, kHIThemeOrientationNormal, &labelRect );
4b94ddc4
RD
148
149 // If we don't want any arrows we need to draw over the one already there
80752b57 150 if ( (flags & wxCONTROL_SELECTED) && (sortArrow == wxHDR_SORT_ICON_NONE) )
4b94ddc4
RD
151 {
152 // clip to the header rectangle
153 CGContextSaveGState( cgContext );
154 CGContextClipToRect( cgContext, headerRect );
155 // but draw bigger than that so the arrow will get clipped off
156 headerRect.size.width += 25;
157 HIThemeDrawButton( &headerRect, &drawInfo, cgContext, kHIThemeOrientationNormal, &labelRect );
158 CGContextRestoreGState( cgContext );
a61c9122 159 }
a62f32af 160 }
11d1adbf 161 }
4b94ddc4
RD
162
163 // Reserve room for the arrows before writing the label, and turn off the
164 // flags we've already handled
165 wxRect newRect(rect);
80752b57 166 if ( (flags & wxCONTROL_SELECTED) && (sortArrow != wxHDR_SORT_ICON_NONE) )
4b94ddc4
RD
167 {
168 newRect.width -= 12;
80752b57 169 sortArrow = wxHDR_SORT_ICON_NONE;
4b94ddc4 170 }
80752b57 171 flags &= ~wxCONTROL_SELECTED;
4b94ddc4 172
c97c9952 173 return DrawHeaderButtonContents(win, dc, newRect, flags, sortArrow, params);
4b94ddc4
RD
174}
175
176
177int wxRendererMac::GetHeaderButtonHeight(wxWindow* WXUNUSED(win))
178{
688a201a
JS
179 SInt32 standardHeight;
180 OSStatus errStatus;
4b94ddc4
RD
181
182 errStatus = GetThemeMetric( kThemeMetricListHeaderHeight, &standardHeight );
183 if (errStatus == noErr)
184 {
185 return standardHeight;
186 }
187 return -1;
9c7f49f5
VZ
188}
189
7af14d71
DS
190void wxRendererMac::DrawTreeItemButton( wxWindow *win,
191 wxDC& dc,
192 const wxRect& rect,
193 int flags )
9c7f49f5 194{
1c5decd0 195 // now the wxGCDC is using native transformations
f3d0a750
RD
196 const wxCoord x = rect.x;
197 const wxCoord y = rect.y;
198 const wxCoord w = rect.width;
199 const wxCoord h = rect.height;
1c5decd0 200
46b59ead
KO
201 dc.SetBrush( *wxTRANSPARENT_BRUSH );
202
203 HIRect headerRect = CGRectMake( x, y, w, h );
204 if ( !dc.IsKindOf( CLASSINFO( wxPaintDC ) ) )
205 {
f968da28 206 win->Refresh( &rect );
9c7f49f5 207 }
46b59ead
KO
208 else
209 {
210 CGContextRef cgContext;
9c7f49f5 211
46b59ead 212 cgContext = (CGContextRef) dc.GetGraphicsContext()->GetNativeContext();
7af14d71 213
e1673e52
SC
214 HIThemeButtonDrawInfo drawInfo;
215 HIRect labelRect;
46b59ead 216
e1673e52
SC
217 memset( &drawInfo, 0, sizeof(drawInfo) );
218 drawInfo.version = 0;
219 drawInfo.kind = kThemeDisclosureButton;
220 drawInfo.state = (flags & wxCONTROL_DISABLED) ? kThemeStateInactive : kThemeStateActive;
221 // Apple mailing list posts say to use the arrow adornment constants, but those don't work.
222 // We need to set the value using the 'old' DrawThemeButton constants instead.
223 drawInfo.value = (flags & wxCONTROL_EXPANDED) ? kThemeDisclosureDown : kThemeDisclosureRight;
224 drawInfo.adornment = kThemeAdornmentNone;
225
226 HIThemeDrawButton( &headerRect, &drawInfo, cgContext, kHIThemeOrientationNormal, &labelRect );
46b59ead 227 }
9c7f49f5
VZ
228}
229
7af14d71
DS
230void wxRendererMac::DrawSplitterSash( wxWindow *win,
231 wxDC& dc,
232 const wxSize& size,
233 wxCoord position,
234 wxOrientation orient,
235 int WXUNUSED(flags) )
b3208e11 236{
a62f32af
SC
237 bool hasMetal = win->MacGetTopLevelWindow()->MacGetMetalAppearance();
238 SInt32 height;
239 GetThemeMetric( kThemeMetricSmallPaneSplitterHeight, &height );
240 HIRect splitterRect;
241 if (orient == wxVERTICAL)
242 splitterRect = CGRectMake( position, 0, height, size.y );
243 else
244 splitterRect = CGRectMake( 0, position, size.x, height );
7af14d71 245
a62f32af
SC
246 // under compositing we should only draw when called by the OS, otherwise just issue a redraw command
247 // strange redraw errors occur if we don't do this
547aafd2 248
a62f32af
SC
249 if ( !dc.IsKindOf( CLASSINFO( wxPaintDC ) ) )
250 {
65108179
SC
251 wxRect rect( (int) splitterRect.origin.x, (int) splitterRect.origin.y, (int) splitterRect.size.width,
252 (int) splitterRect.size.height );
f968da28
SC
253 win->Refresh( &rect );
254 }
a62f32af
SC
255 else
256 {
257 CGContextRef cgContext;
7af14d71 258
be01a403 259 cgContext = (CGContextRef) dc.GetGraphicsContext()->GetNativeContext();
547aafd2 260
a62f32af
SC
261 HIThemeSplitterDrawInfo drawInfo;
262 drawInfo.version = 0;
263 drawInfo.state = kThemeStateActive;
264 drawInfo.adornment = hasMetal ? kHIThemeSplitterAdornmentMetal : kHIThemeSplitterAdornmentNone;
265 HIThemeDrawPaneSplitter( &splitterRect, &drawInfo, cgContext, kHIThemeOrientationNormal );
547aafd2 266 }
b3208e11 267}
a4609ab8
KO
268
269void
270wxRendererMac::DrawItemSelectionRect(wxWindow *win,
271 wxDC& dc,
272 const wxRect& rect,
273 int flags )
274{
055de350
VZ
275 if ( !(flags & wxCONTROL_SELECTED) )
276 return;
65108179
SC
277
278 wxColour col( wxMacCreateCGColorFromHITheme( (flags & wxCONTROL_FOCUSED) ?
279 kThemeBrushAlternatePrimaryHighlightColor
280 : kThemeBrushSecondaryHighlightColor ) );
281 wxBrush selBrush( col );
282
a4609ab8
KO
283 dc.SetPen( *wxTRANSPARENT_PEN );
284 dc.SetBrush( selBrush );
285 dc.DrawRectangle( rect );
286}
cf511e87
RD
287
288
289void
290wxRendererMac::DrawMacThemeButton(wxWindow *win,
291 wxDC& dc,
292 const wxRect& rect,
293 int flags,
294 int kind,
295 int adornment)
296{
cf511e87
RD
297 // now the wxGCDC is using native transformations
298 const wxCoord x = rect.x;
299 const wxCoord y = rect.y;
300 const wxCoord w = rect.width;
301 const wxCoord h = rect.height;
cf511e87
RD
302
303 dc.SetBrush( *wxTRANSPARENT_BRUSH );
304
305 HIRect headerRect = CGRectMake( x, y, w, h );
306 if ( !dc.IsKindOf( CLASSINFO( wxPaintDC ) ) )
307 {
f968da28 308 win->Refresh( &rect );
cf511e87
RD
309 }
310 else
311 {
312 CGContextRef cgContext;
cf511e87 313 cgContext = (CGContextRef) dc.GetGraphicsContext()->GetNativeContext();
cf511e87 314
e1673e52
SC
315 HIThemeButtonDrawInfo drawInfo;
316 HIRect labelRect;
cf511e87 317
e1673e52
SC
318 memset( &drawInfo, 0, sizeof(drawInfo) );
319 drawInfo.version = 0;
320 drawInfo.kind = kind;
321 drawInfo.state = (flags & wxCONTROL_DISABLED) ? kThemeStateInactive : kThemeStateActive;
322 drawInfo.value = (flags & wxCONTROL_SELECTED) ? kThemeButtonOn : kThemeButtonOff;
323 if (flags & wxCONTROL_UNDETERMINED)
324 drawInfo.value = kThemeButtonMixed;
325 drawInfo.adornment = adornment;
326
327 HIThemeDrawButton( &headerRect, &drawInfo, cgContext, kHIThemeOrientationNormal, &labelRect );
cf511e87
RD
328 }
329}
330
6239ee05
SC
331void
332wxRendererMac::DrawCheckBox(wxWindow *win,
333 wxDC& dc,
334 const wxRect& rect,
335 int flags)
336{
337 if (flags & wxCONTROL_CHECKED)
338 flags |= wxCONTROL_SELECTED;
339
340 DrawMacThemeButton(win, dc, rect, flags,
341 kThemeCheckBox, kThemeAdornmentNone);
342}
cf511e87
RD
343
344void
345wxRendererMac::DrawComboBoxDropButton(wxWindow *win,
346 wxDC& dc,
347 const wxRect& rect,
348 int flags)
349{
f8e1a81f 350 int kind;
a61c9122 351 if (win->GetWindowVariant() == wxWINDOW_VARIANT_SMALL || (win->GetParent() && win->GetParent()->GetWindowVariant() == wxWINDOW_VARIANT_SMALL))
f8e1a81f 352 kind = kThemeArrowButtonSmall;
a61c9122 353 else if (win->GetWindowVariant() == wxWINDOW_VARIANT_MINI || (win->GetParent() && win->GetParent()->GetWindowVariant() == wxWINDOW_VARIANT_MINI))
f8e1a81f
JS
354 kind = kThemeArrowButtonMini;
355 else
356 kind = kThemeArrowButton;
a61c9122 357
cf511e87 358 DrawMacThemeButton(win, dc, rect, flags,
f8e1a81f 359 kind, kThemeAdornmentArrowDownArrow);
cf511e87 360}
a61c9122 361
cf511e87
RD
362void
363wxRendererMac::DrawPushButton(wxWindow *win,
364 wxDC& dc,
365 const wxRect& rect,
366 int flags)
367{
f8e1a81f 368 int kind;
a61c9122
JS
369 if (win->GetWindowVariant() == wxWINDOW_VARIANT_SMALL || (win->GetParent() && win->GetParent()->GetWindowVariant() == wxWINDOW_VARIANT_SMALL))
370 kind = kThemeBevelButtonSmall;
371 // There is no kThemeBevelButtonMini, but in this case, use Small
372 else if (win->GetWindowVariant() == wxWINDOW_VARIANT_MINI || (win->GetParent() && win->GetParent()->GetWindowVariant() == wxWINDOW_VARIANT_MINI))
f8e1a81f
JS
373 kind = kThemeBevelButtonSmall;
374 else
375 kind = kThemeBevelButton;
376
cf511e87 377 DrawMacThemeButton(win, dc, rect, flags,
f8e1a81f 378 kind, kThemeAdornmentNone);
cf511e87 379}
a61c9122 380
688a201a
JS
381void
382wxRendererMac::DrawFocusRect(wxWindow* win, wxDC& dc, const wxRect& rect, int flags)
383{
384 if (!win)
385 {
386 wxDelegateRendererNative::DrawFocusRect(win, dc, rect, flags);
387 return;
388 }
389
e1673e52 390 CGRect cgrect = CGRectMake( rect.x , rect.y , rect.width, rect.height ) ;
688a201a 391
e1673e52
SC
392 HIThemeFrameDrawInfo info ;
393 memset( &info, 0 , sizeof(info) ) ;
688a201a 394
e1673e52
SC
395 info.version = 0 ;
396 info.kind = 0 ;
397 info.state = kThemeStateActive;
398 info.isFocused = true ;
688a201a 399
e1673e52
SC
400 CGContextRef cgContext = (CGContextRef) win->MacGetCGContextRef() ;
401 wxASSERT( cgContext ) ;
688a201a 402
e1673e52 403 HIThemeDrawFocusRect( &cgrect , true , cgContext , kHIThemeOrientationNormal ) ;
688a201a
JS
404}
405