]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/renderer.cpp
mark all dtors which are virtual because base class dtor is virtual explicitly virtua...
[wxWidgets.git] / src / mac / carbon / renderer.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/renderer.cpp
3 // Purpose: implementation of wxRendererNative for Mac
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>
9 // License: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
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"
21 #include "wx/dc.h"
22 #include "wx/bitmap.h"
23 #include "wx/settings.h"
24 #include "wx/dcclient.h"
25 #include "wx/toplevel.h"
26 #endif
27
28 #include "wx/renderer.h"
29 #include "wx/mac/uma.h"
30
31
32 class WXDLLEXPORT wxRendererMac : public wxDelegateRendererNative
33 {
34 public:
35 // draw the header control button (used by wxListCtrl)
36 virtual void DrawHeaderButton( wxWindow *win,
37 wxDC& dc,
38 const wxRect& rect,
39 int flags = 0 );
40
41 // draw the expanded/collapsed icon for a tree control item
42 virtual void DrawTreeItemButton( wxWindow *win,
43 wxDC& dc,
44 const wxRect& rect,
45 int flags = 0 );
46
47 // draw a (vertical) sash
48 virtual void DrawSplitterSash( wxWindow *win,
49 wxDC& dc,
50 const wxSize& size,
51 wxCoord position,
52 wxOrientation orient,
53 int flags = 0 );
54
55 private:
56 // the tree buttons
57 wxBitmap m_bmpTreeExpanded;
58 wxBitmap m_bmpTreeCollapsed;
59 };
60
61 // ----------------------------------------------------------------------------
62 // Aqua arrows
63 // ----------------------------------------------------------------------------
64
65 /* XPM */
66 static const char *aqua_arrow_right_xpm[] =
67 {
68 // columns rows colors chars-per-pixel
69 "13 11 4 1",
70 " c None",
71 "b c #C0C0C0",
72 "c c #707070",
73 "d c #A0A0A0",
74
75 // pixels
76 " b ",
77 " ddb ",
78 " cccdb ",
79 " cccccd ",
80 " ccccccdb ",
81 " ccccccccd",
82 " ccccccdb ",
83 " cccccb ",
84 " cccdb ",
85 " ddb ",
86 " b "
87 };
88
89 /* XPM */
90 static const char *aqua_arrow_down_xpm[] =
91 {
92 // columns rows colors chars-per-pixel
93 "13 11 4 1",
94 " c None",
95 "b c #C0C0C0",
96 "c c #707070",
97 "d c #A0A0A0",
98
99 // pixels
100 " ",
101 " ",
102 " bdcccccccdb ",
103 " dcccccccd ",
104 " bcccccccb ",
105 " dcccccd ",
106 " bcccccb ",
107 " bcccd ",
108 " dcd ",
109 " bcb ",
110 " d "
111 };
112
113 // ============================================================================
114 // implementation
115 // ============================================================================
116
117 // static
118 wxRendererNative& wxRendererNative::GetDefault()
119 {
120 static wxRendererMac s_rendererMac;
121
122 return s_rendererMac;
123 }
124
125 void wxRendererMac::DrawHeaderButton( wxWindow *win,
126 wxDC& dc,
127 const wxRect& rect,
128 int flags )
129 {
130 int major, minor;
131
132 wxGetOsVersion( &major, &minor );
133
134 const wxCoord x = dc.XLOG2DEV(rect.x - 1);
135 const wxCoord y = dc.YLOG2DEV(rect.y - 1);
136 const wxCoord w = dc.XLOG2DEVREL(rect.width);
137 const wxCoord h = dc.YLOG2DEVREL(rect.height);
138
139 dc.SetBrush( *wxTRANSPARENT_BRUSH );
140
141 HIRect headerRect = CGRectMake( x, y, w, h );
142 if ( !dc.IsKindOf( CLASSINFO( wxPaintDC ) ) )
143 {
144 Rect r =
145 {
146 (short) headerRect.origin.y, (short) headerRect.origin.x,
147 (short) (headerRect.origin.y + headerRect.size.height),
148 (short) (headerRect.origin.x + headerRect.size.width)
149 };
150
151 RgnHandle updateRgn = NewRgn();
152 RectRgn( updateRgn, &r );
153 HIViewSetNeedsDisplayInRegion( (HIViewRef) win->GetHandle(), updateRgn, true );
154 DisposeRgn( updateRgn );
155 }
156 else
157 {
158 CGContextRef cgContext;
159
160 #if wxMAC_USE_CORE_GRAPHICS
161 cgContext = ((wxMacCGContext*)(dc.GetGraphicContext()))->GetNativeContext();
162 #else
163 Rect bounds;
164
165 GetPortBounds( (CGrafPtr) dc.m_macPort, &bounds );
166 QDBeginCGContext( (CGrafPtr) dc.m_macPort, &cgContext );
167
168 CGContextTranslateCTM( cgContext, 0, bounds.bottom - bounds.top );
169 CGContextScaleCTM( cgContext, 1, -1 );
170
171 HIShapeReplacePathInCGContext( HIShapeCreateWithQDRgn( (RgnHandle) dc.m_macCurrentClipRgn ), cgContext );
172 CGContextClip( cgContext );
173 HIViewConvertRect( &headerRect, (HIViewRef) win->GetHandle(), (HIViewRef) win->MacGetTopLevelWindow()->GetHandle() );
174 #endif
175
176 {
177 HIThemeButtonDrawInfo drawInfo;
178 HIRect labelRect;
179
180 memset( &drawInfo, 0, sizeof(drawInfo) );
181 drawInfo.version = 0;
182 drawInfo.state = (flags & wxCONTROL_DISABLED) ? kThemeStateInactive : kThemeStateActive;
183 drawInfo.kind = kThemeListHeaderButton;
184 drawInfo.value = 0;
185 drawInfo.adornment = kThemeAdornmentNone;
186 HIThemeDrawButton( &headerRect, &drawInfo, cgContext, kHIThemeOrientationNormal, &labelRect );
187 }
188
189 #if wxMAC_USE_CORE_GRAPHICS
190 #else
191 QDEndCGContext( (CGrafPtr) dc.m_macPort, &cgContext );
192 #endif
193 }
194 }
195
196 void wxRendererMac::DrawTreeItemButton( wxWindow *win,
197 wxDC& dc,
198 const wxRect& rect,
199 int flags )
200 {
201 // init the buttons on demand
202 if ( !m_bmpTreeExpanded.Ok() )
203 {
204 m_bmpTreeExpanded = wxBitmap(aqua_arrow_down_xpm);
205 m_bmpTreeCollapsed = wxBitmap(aqua_arrow_right_xpm);
206 }
207
208 // draw them
209
210 // VZ: this is the old code from treectlg.cpp which apparently doesn't work
211 // but I kept it here just in case it is needed -- if not, please
212 // remove it
213
214 #if 0 // def __WXMAC__
215 wxMacPortSetter helper(&dc);
216 wxMacWindowClipper clipper(this);
217 wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() );
218
219 int loc_x = x - 5;
220 int loc_y = y_mid - 6;
221 MacWindowToRootWindow( &loc_x, &loc_y );
222 Rect bounds = { loc_y, loc_x, loc_y + 18, loc_x + 12 };
223 ThemeButtonDrawInfo info =
224 {
225 kThemeStateActive,
226 item->IsExpanded() ? kThemeDisclosureDown : kThemeDisclosureRight,
227 kThemeAdornmentNone
228 };
229
230 DrawThemeButton( &bounds, kThemeDisclosureButton, &info, NULL, NULL, NULL, NULL );
231 #else // 1
232 dc.DrawBitmap(
233 flags & wxCONTROL_EXPANDED
234 ? m_bmpTreeExpanded
235 : m_bmpTreeCollapsed,
236 rect.x, rect.y, true /* use mask */);
237 #endif
238 }
239
240 void wxRendererMac::DrawSplitterSash( wxWindow *win,
241 wxDC& dc,
242 const wxSize& size,
243 wxCoord position,
244 wxOrientation orient,
245 int WXUNUSED(flags) )
246 {
247 bool hasMetal = win->MacGetTopLevelWindow()->MacGetMetalAppearance();
248 SInt32 height;
249 GetThemeMetric( kThemeMetricSmallPaneSplitterHeight, &height );
250 HIRect splitterRect;
251 if (orient == wxVERTICAL)
252 splitterRect = CGRectMake( position, 0, height, size.y );
253 else
254 splitterRect = CGRectMake( 0, position, size.x, height );
255
256 #if !wxMAC_USE_CORE_GRAPHICS
257 HIViewConvertRect(
258 &splitterRect,
259 (HIViewRef) win->GetHandle(),
260 (HIViewRef) win->MacGetTopLevelWindow()->GetHandle() );
261 #endif
262
263 // under compositing we should only draw when called by the OS, otherwise just issue a redraw command
264 // strange redraw errors occur if we don't do this
265
266 if ( !dc.IsKindOf( CLASSINFO( wxPaintDC ) ) )
267 {
268 Rect r =
269 {
270 (short) splitterRect.origin.y,
271 (short) splitterRect.origin.x,
272 (short) (splitterRect.origin.y + splitterRect.size.height),
273 (short) (splitterRect.origin.x + splitterRect.size.width)
274 };
275
276 RgnHandle updateRgn = NewRgn();
277 RectRgn( updateRgn, &r );
278 HIViewSetNeedsDisplayInRegion( (HIViewRef) win->GetHandle(), updateRgn, true );
279 DisposeRgn( updateRgn );
280 }
281 else
282 {
283 CGContextRef cgContext;
284
285 #if wxMAC_USE_CORE_GRAPHICS
286 cgContext = ((wxMacCGContext*)(dc.GetGraphicContext()))->GetNativeContext();
287 #else
288 Rect bounds;
289 GetPortBounds( (CGrafPtr) dc.m_macPort, &bounds );
290 QDBeginCGContext( (CGrafPtr) dc.m_macPort, &cgContext );
291 CGContextTranslateCTM( cgContext, 0, bounds.bottom - bounds.top );
292 CGContextScaleCTM( cgContext, 1, -1 );
293 #endif
294
295 HIThemeSplitterDrawInfo drawInfo;
296 drawInfo.version = 0;
297 drawInfo.state = kThemeStateActive;
298 drawInfo.adornment = hasMetal ? kHIThemeSplitterAdornmentMetal : kHIThemeSplitterAdornmentNone;
299 HIThemeDrawPaneSplitter( &splitterRect, &drawInfo, cgContext, kHIThemeOrientationNormal );
300
301 #if wxMAC_USE_CORE_GRAPHICS
302 #else
303 QDEndCGContext( (CGrafPtr) dc.m_macPort, &cgContext );
304 #endif
305 }
306 }