]> git.saurik.com Git - wxWidgets.git/blame - src/mac/carbon/renderer.cpp
corrected GetPosition and extended erasing to include the entire update rgn passed
[wxWidgets.git] / src / mac / carbon / renderer.cpp
CommitLineData
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 43class WXDLLEXPORT wxRendererMac : public wxDelegateRendererNative
9c7f49f5
VZ
44{
45public:
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
66private:
67 // the tree buttons
68 wxBitmap m_bmpTreeExpanded,
69 m_bmpTreeCollapsed;
70};
71
72// ----------------------------------------------------------------------------
73// Aqua arrows
74// ----------------------------------------------------------------------------
75
76/* XPM */
77static 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 */
99static 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 125wxRendererNative& wxRendererNative::GetDefault()
9c7f49f5
VZ
126{
127 static wxRendererMac s_rendererMac;
128
129 return s_rendererMac;
130}
131
132void
133wxRendererMac::DrawHeaderButton(wxWindow *win,
134 wxDC& dc,
135 const wxRect& rect,
136 int WXUNUSED(flags))
137{
138 const int CORNER = 1;
139
48fbb521
RR
140 const wxCoord x = rect.x-1,
141 y = rect.y-1,
9c7f49f5
VZ
142 w = rect.width,
143 h = rect.height;
144
11d1adbf
SC
145 int major,minor;
146 wxGetOsVersion( &major, &minor );
9c7f49f5 147
11d1adbf 148 dc.SetBrush( *wxTRANSPARENT_BRUSH );
9c7f49f5 149
11d1adbf
SC
150 if (major >= 10)
151 {
152 dc.SetPen( wxPen( wxColour( 0xC5 , 0xC5 , 0xC5 ) , 1 , wxSOLID ) );
153 dc.DrawRectangle( x, y+CORNER, 1, h-CORNER ); // left
154 // The right border is overdrawn by the left border of the right neighbouring
155 // header (to maintain a proper single pixel border). Except for the
156 // rightmost header of the listctrl.
157 dc.DrawRectangle( x+w+(CORNER*2), y+CORNER, 1, h-CORNER ); // right
158 dc.SetPen( wxPen( wxColour( 0xB1 , 0xB1 , 0xB1 ) , 1 , wxSOLID ) );
159 dc.DrawRectangle( x, y+h, w+(CORNER*3), 1 ); // bottom
160 dc.DrawRectangle( x, y, w+(CORNER*3), 1 ); // top
161
162 // Do a fill of the interior for background:
163 dc.SetPen( wxPen( wxColour( 0xF6 , 0xF6 , 0xF6 ) , 1 , wxSOLID ) );
164 dc.DrawRectangle( x+CORNER, y+CORNER, w+CORNER, h-CORNER );
165
166 // Do the gradient fill:
167 static int grayValues[] =
168 {
169 0xF6, 0xF2, 0xEF, 0xED, 0xED, 0xEB, 0xEA, 0xEA, 0xE8,
170 0xE8, 0xE2, 0xE5, 0xE8, 0xEB, 0xEF, 0xF2, 0xFD
171 };
172 int i;
173 for (i=0; i < h && i < (int)WXSIZEOF(grayValues); i++)
174 {
175 dc.SetPen( wxPen( wxColour( grayValues[i] , grayValues[i] , grayValues[i] ),
176 1 , wxSOLID ) );
177 dc.DrawRectangle( x+CORNER, y+CORNER+i, w+CORNER, 1 );
178 }
179 }
180 else
181 {
182 dc.SetPen( wxPen( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNSHADOW ) , 1 , wxSOLID ) );
183 dc.DrawLine( x+w-CORNER+1, y, x+w, y+h ); // right (outer)
184 dc.DrawRectangle( x, y+h, w+1, 1 ); // bottom (outer)
185
186 wxPen pen( wxColour( 0x88 , 0x88 , 0x88 ), 1, wxSOLID );
187
188 dc.SetPen( pen );
189 dc.DrawLine( x+w-CORNER, y, x+w-1, y+h ); // right (inner)
190 dc.DrawRectangle( x+1, y+h-1, w-2, 1 ); // bottom (inner)
191
192 dc.SetPen( *wxWHITE_PEN );
193 dc.DrawRectangle( x, y, w-CORNER+1, 1 ); // top (outer)
194 dc.DrawRectangle( x, y, 1, h ); // left (outer)
195 dc.DrawLine( x, y+h-1, x+1, y+h-1 );
196 dc.DrawLine( x+w-1, y, x+w-1, y+1 );
197 }
9c7f49f5
VZ
198}
199
200void
201wxRendererMac::DrawTreeItemButton(wxWindow *win,
202 wxDC& dc,
203 const wxRect& rect,
204 int flags)
205{
206 // init the buttons on demand
207 if ( !m_bmpTreeExpanded.Ok() )
208 {
209 m_bmpTreeExpanded = wxBitmap(aqua_arrow_down_xpm);
210 m_bmpTreeCollapsed = wxBitmap(aqua_arrow_right_xpm);
211 }
212
213 // draw them
214
215 // VZ: this is the old code from treectlg.cpp which apparently doesn't work
216 // but I kept it here just in case it is needed -- if not, please
217 // remove it
218#if 0 // def __WXMAC__
219 wxMacPortSetter helper(&dc) ;
220 wxMacWindowClipper clipper(this) ;
221 wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ;
222
223 int loc_x = x - 5 ;
224 int loc_y = y_mid - 6 ;
225 MacWindowToRootWindow( & loc_x , & loc_y ) ;
226 Rect bounds = { loc_y , loc_x , loc_y + 18 , loc_x + 12 } ;
227 ThemeButtonDrawInfo info = { kThemeStateActive , item->IsExpanded() ? kThemeDisclosureDown : kThemeDisclosureRight ,
228 kThemeAdornmentNone };
229 DrawThemeButton( &bounds, kThemeDisclosureButton ,
230 &info , NULL , NULL , NULL , NULL ) ;
231#else // 1
232 dc.DrawBitmap(flags & wxCONTROL_EXPANDED ? m_bmpTreeExpanded
233 : m_bmpTreeCollapsed,
234 rect.x, rect.y, true /* use mask */);
235#endif // 0/1
236}
237
b3208e11 238void
e356d469
VZ
239wxRendererMac::DrawSplitterSash(wxWindow *win,
240 wxDC& dc,
241 const wxSize& size,
62dc9cb4 242 wxCoord position,
af99040c
VZ
243 wxOrientation orient,
244 int WXUNUSED(flags))
b3208e11 245{
547aafd2
SC
246#if ( TARGET_API_MAC_OSX == 1 ) && ( MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3 )
247 if ( UMAGetSystemVersion() >= 0x1030 )
eef4e26c 248 {
547aafd2
SC
249 bool hasMetal = win->MacGetTopLevelWindow()->MacGetMetalAppearance() ;
250 SInt32 height ;
251 GetThemeMetric( kThemeMetricSmallPaneSplitterHeight , &height ) ;
252 HIRect splitterRect ;
253 if ( orient == wxVERTICAL )
254 splitterRect = CGRectMake( position , 0 , height, size.y);
255 else
256 splitterRect = CGRectMake( 0 , position , size.x , height );
257 HIViewConvertRect( &splitterRect , (HIViewRef) win->GetHandle() , (HIViewRef) win->MacGetTopLevelWindow()->GetHandle() ) ;
258
259 // under compositing we should only draw when called by the OS, otherwise just issue a redraw command
260 // strange redraw errors occur if we don't do this
261
262 if ( dc.IsKindOf( CLASSINFO( wxPaintDC ) ) == false )
eef4e26c 263 {
36168292
DS
264 Rect r = { (short) splitterRect.origin.y , (short) splitterRect.origin.x ,
265 (short) (splitterRect.origin.y + splitterRect.size.height) , (short) (splitterRect.origin.x + splitterRect.size.width) } ;
547aafd2
SC
266 RgnHandle updateRgn = NewRgn() ;
267 RectRgn( updateRgn , &r ) ;
268 HIViewSetNeedsDisplayInRegion( (HIViewRef) win->GetHandle() , updateRgn , true ) ;
269 DisposeRgn( updateRgn ) ;
270 }
271 else
272 {
273 CGContextRef cgContext ;
274 Rect bounds ;
275 GetPortBounds( (CGrafPtr) dc.m_macPort , &bounds ) ;
276 QDBeginCGContext( (CGrafPtr) dc.m_macPort , &cgContext ) ;
277 CGContextTranslateCTM( cgContext , 0 , bounds.bottom - bounds.top ) ;
278 CGContextScaleCTM( cgContext , 1 , -1 ) ;
279
280 {
281 HIThemeSplitterDrawInfo drawInfo ;
282 drawInfo.version = 0 ;
283 drawInfo.state = kThemeStateActive ;
284 drawInfo.adornment = hasMetal ? kHIThemeSplitterAdornmentMetal : kHIThemeSplitterAdornmentNone ;
285 HIThemeDrawPaneSplitter( &splitterRect , &drawInfo , cgContext , kHIThemeOrientationNormal ) ;
286 }
287 QDEndCGContext( (CGrafPtr) dc.m_macPort , &cgContext ) ;
eef4e26c
RR
288 }
289 }
290 else
547aafd2 291#endif
eef4e26c 292 {
547aafd2
SC
293#if 0
294 dc.SetPen(*wxLIGHT_GREY_PEN);
295 dc.SetBrush(*wxWHITE_BRUSH);
296 if ( orient == wxVERTICAL )
297 dc.DrawRectangle(position, 0, 7, size.y);
298 else
299 dc.DrawRectangle(0, position, size.x, 7);
300#else
301 // Do the gradient fill:
302 static int grayValues[] =
eef4e26c 303 {
547aafd2
SC
304 0xA0, 0xF6, 0xED, 0xE4, 0xE2, 0xD0, 0xA0
305 };
306 dc.SetBrush( *wxTRANSPARENT_BRUSH );
307 if ( orient == wxVERTICAL )
308 {
309 int i;
310 for (i=0; i < (int)WXSIZEOF(grayValues); i++)
311 {
312 dc.SetPen( wxPen( wxColour( grayValues[i] , grayValues[i] , grayValues[i] ),
313 1 , wxSOLID ) );
314 dc.DrawRectangle( position+i, 0, 1, size.y );
315 }
316 }
317 else
318 {
319 int i;
320 for (i=0; i < (int)WXSIZEOF(grayValues); i++)
321 {
322 dc.SetPen( wxPen( wxColour( grayValues[i] , grayValues[i] , grayValues[i] ),
323 1 , wxSOLID ) );
324 dc.DrawRectangle( 0, position+i, size.x, 1 );
325 }
eef4e26c 326 }
eef4e26c 327#endif
547aafd2 328 }
b3208e11
VZ
329}
330