]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/renderer.cpp
removing non-compositing code, adding individual transparency
[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"
547aafd2 29#include "wx/mac/uma.h"
9c7f49f5 30
9c7f49f5 31
5cb80ad2 32class WXDLLEXPORT wxRendererMac : public wxDelegateRendererNative
9c7f49f5
VZ
33{
34public:
35 // draw the header control button (used by wxListCtrl)
7af14d71
DS
36 virtual void DrawHeaderButton( wxWindow *win,
37 wxDC& dc,
38 const wxRect& rect,
39 int flags = 0 );
9c7f49f5
VZ
40
41 // draw the expanded/collapsed icon for a tree control item
7af14d71
DS
42 virtual void DrawTreeItemButton( wxWindow *win,
43 wxDC& dc,
44 const wxRect& rect,
45 int flags = 0 );
9c7f49f5 46
b3208e11 47 // draw a (vertical) sash
7af14d71
DS
48 virtual void DrawSplitterSash( wxWindow *win,
49 wxDC& dc,
50 const wxSize& size,
51 wxCoord position,
52 wxOrientation orient,
53 int flags = 0 );
b3208e11 54
9c7f49f5
VZ
55private:
56 // the tree buttons
7af14d71
DS
57 wxBitmap m_bmpTreeExpanded;
58 wxBitmap m_bmpTreeCollapsed;
9c7f49f5
VZ
59};
60
61// ----------------------------------------------------------------------------
62// Aqua arrows
63// ----------------------------------------------------------------------------
64
65/* XPM */
7af14d71
DS
66static const char *aqua_arrow_right_xpm[] =
67{
68// columns rows colors chars-per-pixel
9c7f49f5
VZ
69"13 11 4 1",
70" c None",
71"b c #C0C0C0",
72"c c #707070",
73"d c #A0A0A0",
7af14d71
DS
74
75// pixels
9c7f49f5
VZ
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 */
7af14d71
DS
90static const char *aqua_arrow_down_xpm[] =
91{
92// columns rows colors chars-per-pixel
9c7f49f5
VZ
93"13 11 4 1",
94" c None",
95"b c #C0C0C0",
96"c c #707070",
97"d c #A0A0A0",
7af14d71
DS
98
99// pixels
9c7f49f5
VZ
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
7af14d71 117// static
f0244295 118wxRendererNative& wxRendererNative::GetDefault()
9c7f49f5
VZ
119{
120 static wxRendererMac s_rendererMac;
121
122 return s_rendererMac;
123}
124
7af14d71
DS
125void wxRendererMac::DrawHeaderButton( wxWindow *win,
126 wxDC& dc,
127 const wxRect& rect,
128 int flags )
9c7f49f5 129{
7af14d71 130 int major, minor;
9c7f49f5 131
11d1adbf 132 wxGetOsVersion( &major, &minor );
9c7f49f5 133
7af14d71
DS
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
11d1adbf 139 dc.SetBrush( *wxTRANSPARENT_BRUSH );
9c7f49f5 140
a62f32af
SC
141 HIRect headerRect = CGRectMake( x, y, w, h );
142 if ( !dc.IsKindOf( CLASSINFO( wxPaintDC ) ) )
2480cf88 143 {
a62f32af 144 Rect r =
2480cf88 145 {
a62f32af
SC
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;
7af14d71 159
2480cf88 160#if wxMAC_USE_CORE_GRAPHICS
a62f32af 161 cgContext = ((wxMacCGContext*)(dc.GetGraphicContext()))->GetNativeContext();
2480cf88 162#else
a62f32af 163 Rect bounds;
7af14d71 164
a62f32af
SC
165 GetPortBounds( (CGrafPtr) dc.m_macPort, &bounds );
166 QDBeginCGContext( (CGrafPtr) dc.m_macPort, &cgContext );
7af14d71 167
a62f32af
SC
168 CGContextTranslateCTM( cgContext, 0, bounds.bottom - bounds.top );
169 CGContextScaleCTM( cgContext, 1, -1 );
7af14d71 170
a62f32af
SC
171 HIShapeReplacePathInCGContext( HIShapeCreateWithQDRgn( (RgnHandle) dc.m_macCurrentClipRgn ), cgContext );
172 CGContextClip( cgContext );
173 HIViewConvertRect( &headerRect, (HIViewRef) win->GetHandle(), (HIViewRef) win->MacGetTopLevelWindow()->GetHandle() );
2480cf88 174#endif
7af14d71 175
a62f32af
SC
176 {
177 HIThemeButtonDrawInfo drawInfo;
178 HIRect labelRect;
7af14d71 179
a62f32af
SC
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 }
7af14d71 188
2480cf88
SC
189#if wxMAC_USE_CORE_GRAPHICS
190#else
a62f32af 191 QDEndCGContext( (CGrafPtr) dc.m_macPort, &cgContext );
2480cf88 192#endif
11d1adbf 193 }
9c7f49f5
VZ
194}
195
7af14d71
DS
196void wxRendererMac::DrawTreeItemButton( wxWindow *win,
197 wxDC& dc,
198 const wxRect& rect,
199 int flags )
9c7f49f5
VZ
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
7af14d71 213
9c7f49f5 214#if 0 // def __WXMAC__
7af14d71
DS
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 );
9c7f49f5 231#else // 1
7af14d71
DS
232 dc.DrawBitmap(
233 flags & wxCONTROL_EXPANDED
234 ? m_bmpTreeExpanded
235 : m_bmpTreeCollapsed,
236 rect.x, rect.y, true /* use mask */);
237#endif
9c7f49f5
VZ
238}
239
7af14d71
DS
240void wxRendererMac::DrawSplitterSash( wxWindow *win,
241 wxDC& dc,
242 const wxSize& size,
243 wxCoord position,
244 wxOrientation orient,
245 int WXUNUSED(flags) )
b3208e11 246{
a62f32af
SC
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 );
7af14d71 255
2480cf88 256#if !wxMAC_USE_CORE_GRAPHICS
a62f32af
SC
257 HIViewConvertRect(
258 &splitterRect,
259 (HIViewRef) win->GetHandle(),
260 (HIViewRef) win->MacGetTopLevelWindow()->GetHandle() );
2480cf88 261#endif
547aafd2 262
a62f32af
SC
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
547aafd2 265
a62f32af
SC
266 if ( !dc.IsKindOf( CLASSINFO( wxPaintDC ) ) )
267 {
268 Rect r =
547aafd2 269 {
a62f32af
SC
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;
7af14d71 284
20b69855 285#if wxMAC_USE_CORE_GRAPHICS
a62f32af 286 cgContext = ((wxMacCGContext*)(dc.GetGraphicContext()))->GetNativeContext();
20b69855 287#else
a62f32af
SC
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 );
2480cf88 293#endif
547aafd2 294
a62f32af
SC
295 HIThemeSplitterDrawInfo drawInfo;
296 drawInfo.version = 0;
297 drawInfo.state = kThemeStateActive;
298 drawInfo.adornment = hasMetal ? kHIThemeSplitterAdornmentMetal : kHIThemeSplitterAdornmentNone;
299 HIThemeDrawPaneSplitter( &splitterRect, &drawInfo, cgContext, kHIThemeOrientationNormal );
2480cf88
SC
300
301#if wxMAC_USE_CORE_GRAPHICS
302#else
a62f32af 303 QDEndCGContext( (CGrafPtr) dc.m_macPort, &cgContext );
20b69855 304#endif
547aafd2 305 }
b3208e11 306}