]> git.saurik.com Git - wxWidgets.git/blame - src/mac/classic/renderer.cpp
Hopefully fixed library names generated by wx-config for OS/2's PM port.
[wxWidgets.git] / src / mac / classic / renderer.cpp
CommitLineData
2646f485
SC
1///////////////////////////////////////////////////////////////////////////////
2// Name: mac/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>
65571936 9// License: wxWindows licence
2646f485
SC
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"
29 #include "wx/dc.h"
30 #include "wx/bitmap.h"
31 #include "wx/settings.h"
32#endif //WX_PRECOMP
33
34#include "wx/renderer.h"
35
36// ----------------------------------------------------------------------------
37// wxRendererMac: our wxRendererNative implementation
38// ----------------------------------------------------------------------------
39
40class WXDLLEXPORT wxRendererMac : public wxDelegateRendererNative
41{
42public:
43 // draw the header control button (used by wxListCtrl)
44 virtual void DrawHeaderButton(wxWindow *win,
45 wxDC& dc,
46 const wxRect& rect,
47 int flags = 0);
48
49 // draw the expanded/collapsed icon for a tree control item
50 virtual void DrawTreeItemButton(wxWindow *win,
51 wxDC& dc,
52 const wxRect& rect,
53 int flags = 0);
54
55 // draw a (vertical) sash
56 virtual void DrawSplitterSash(wxWindow *win,
57 wxDC& dc,
58 const wxSize& size,
59 wxCoord position,
60 wxOrientation orient,
61 int flags = 0);
62
63private:
64 // the tree buttons
65 wxBitmap m_bmpTreeExpanded,
66 m_bmpTreeCollapsed;
67};
68
69// ----------------------------------------------------------------------------
70// Aqua arrows
71// ----------------------------------------------------------------------------
72
73/* XPM */
74static const char *aqua_arrow_right_xpm[] = {
75/* columns rows colors chars-per-pixel */
76"13 11 4 1",
77" c None",
78"b c #C0C0C0",
79"c c #707070",
80"d c #A0A0A0",
81/* pixels */
82" b ",
83" ddb ",
84" cccdb ",
85" cccccd ",
86" ccccccdb ",
87" ccccccccd",
88" ccccccdb ",
89" cccccb ",
90" cccdb ",
91" ddb ",
92" b "
93};
94
95/* XPM */
96static const char *aqua_arrow_down_xpm[] = {
97/* columns rows colors chars-per-pixel */
98"13 11 4 1",
99" c None",
100"b c #C0C0C0",
101"c c #707070",
102"d c #A0A0A0",
103/* pixels */
104" ",
105" ",
106" bdcccccccdb ",
107" dcccccccd ",
108" bcccccccb ",
109" dcccccd ",
110" bcccccb ",
111" bcccd ",
112" dcd ",
113" bcb ",
114" d "
115};
116
117// ============================================================================
118// implementation
119// ============================================================================
120
121/* static */
122wxRendererNative& wxRendererNative::GetDefault()
123{
124 static wxRendererMac s_rendererMac;
125
126 return s_rendererMac;
127}
128
129void
130wxRendererMac::DrawHeaderButton(wxWindow *win,
131 wxDC& dc,
132 const wxRect& rect,
133 int WXUNUSED(flags))
134{
135 const int CORNER = 1;
136
137 const wxCoord x = rect.x-1,
138 y = rect.y-1,
139 w = rect.width,
140 h = rect.height;
141
142 int major,minor;
143 wxGetOsVersion( &major, &minor );
144
145 dc.SetBrush( *wxTRANSPARENT_BRUSH );
146
147 if (major >= 10)
148 {
149 dc.SetPen( wxPen( wxColour( 0xC5 , 0xC5 , 0xC5 ) , 1 , wxSOLID ) );
150 dc.DrawRectangle( x, y+CORNER, 1, h-CORNER ); // left
151 // The right border is overdrawn by the left border of the right neighbouring
152 // header (to maintain a proper single pixel border). Except for the
153 // rightmost header of the listctrl.
154 dc.DrawRectangle( x+w+(CORNER*2), y+CORNER, 1, h-CORNER ); // right
155 dc.SetPen( wxPen( wxColour( 0xB1 , 0xB1 , 0xB1 ) , 1 , wxSOLID ) );
156 dc.DrawRectangle( x, y+h, w+(CORNER*3), 1 ); // bottom
157 dc.DrawRectangle( x, y, w+(CORNER*3), 1 ); // top
158
159 // Do a fill of the interior for background:
160 dc.SetPen( wxPen( wxColour( 0xF6 , 0xF6 , 0xF6 ) , 1 , wxSOLID ) );
161 dc.DrawRectangle( x+CORNER, y+CORNER, w+CORNER, h-CORNER );
162
163 // Do the gradient fill:
164 static int grayValues[] =
165 {
166 0xF6, 0xF2, 0xEF, 0xED, 0xED, 0xEB, 0xEA, 0xEA, 0xE8,
167 0xE8, 0xE2, 0xE5, 0xE8, 0xEB, 0xEF, 0xF2, 0xFD
168 };
169 int i;
170 for (i=0; i < h && i < (int)WXSIZEOF(grayValues); i++)
171 {
172 dc.SetPen( wxPen( wxColour( grayValues[i] , grayValues[i] , grayValues[i] ),
173 1 , wxSOLID ) );
174 dc.DrawRectangle( x+CORNER, y+CORNER+i, w+CORNER, 1 );
175 }
176 }
177 else
178 {
179 dc.SetPen( wxPen( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNSHADOW ) , 1 , wxSOLID ) );
180 dc.DrawLine( x+w-CORNER+1, y, x+w, y+h ); // right (outer)
181 dc.DrawRectangle( x, y+h, w+1, 1 ); // bottom (outer)
182
183 wxPen pen( wxColour( 0x88 , 0x88 , 0x88 ), 1, wxSOLID );
184
185 dc.SetPen( pen );
186 dc.DrawLine( x+w-CORNER, y, x+w-1, y+h ); // right (inner)
187 dc.DrawRectangle( x+1, y+h-1, w-2, 1 ); // bottom (inner)
188
189 dc.SetPen( *wxWHITE_PEN );
190 dc.DrawRectangle( x, y, w-CORNER+1, 1 ); // top (outer)
191 dc.DrawRectangle( x, y, 1, h ); // left (outer)
192 dc.DrawLine( x, y+h-1, x+1, y+h-1 );
193 dc.DrawLine( x+w-1, y, x+w-1, y+1 );
194 }
195}
196
197void
198wxRendererMac::DrawTreeItemButton(wxWindow *win,
199 wxDC& dc,
200 const wxRect& rect,
201 int flags)
202{
203 // init the buttons on demand
204 if ( !m_bmpTreeExpanded.Ok() )
205 {
206 m_bmpTreeExpanded = wxBitmap(aqua_arrow_down_xpm);
207 m_bmpTreeCollapsed = wxBitmap(aqua_arrow_right_xpm);
208 }
209
210 // draw them
211
212 // VZ: this is the old code from treectlg.cpp which apparently doesn't work
213 // but I kept it here just in case it is needed -- if not, please
214 // remove it
215#if 0 // def __WXMAC__
216 wxMacPortSetter helper(&dc) ;
217 wxMacWindowClipper clipper(this) ;
218 wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ;
219
220 int loc_x = x - 5 ;
221 int loc_y = y_mid - 6 ;
222 MacWindowToRootWindow( & loc_x , & loc_y ) ;
223 Rect bounds = { loc_y , loc_x , loc_y + 18 , loc_x + 12 } ;
224 ThemeButtonDrawInfo info = { kThemeStateActive , item->IsExpanded() ? kThemeDisclosureDown : kThemeDisclosureRight ,
225 kThemeAdornmentNone };
226 DrawThemeButton( &bounds, kThemeDisclosureButton ,
227 &info , NULL , NULL , NULL , NULL ) ;
228#else // 1
229 dc.DrawBitmap(flags & wxCONTROL_EXPANDED ? m_bmpTreeExpanded
230 : m_bmpTreeCollapsed,
231 rect.x, rect.y, true /* use mask */);
232#endif // 0/1
233}
234
235void
236wxRendererMac::DrawSplitterSash(wxWindow *win,
237 wxDC& dc,
238 const wxSize& size,
239 wxCoord position,
240 wxOrientation orient,
241 int WXUNUSED(flags))
242{
243 // VZ: we have to somehow determine if we're drawing a normal sash or
244 // a brushed metal one as they look quite differently... this is
245 // completely bogus anyhow, of course (TODO)
246
247#if 0
248 dc.SetPen(*wxLIGHT_GREY_PEN);
249 dc.SetBrush(*wxWHITE_BRUSH);
250 if ( orient == wxVERTICAL )
251 dc.DrawRectangle(position, 0, 7, size.y);
252 else
253 dc.DrawRectangle(0, position, size.x, 7);
254#else
255 // Do the gradient fill:
256 static int grayValues[] =
257 {
258 0xA0, 0xF6, 0xED, 0xE4, 0xE2, 0xD0, 0xA0
259 };
260 dc.SetBrush( *wxTRANSPARENT_BRUSH );
261 if ( orient == wxVERTICAL )
262 {
263 int i;
264 for (i=0; i < (int)WXSIZEOF(grayValues); i++)
265 {
266 dc.SetPen( wxPen( wxColour( grayValues[i] , grayValues[i] , grayValues[i] ),
267 1 , wxSOLID ) );
268 dc.DrawRectangle( position+i, 0, 1, size.y );
269 }
270 }
271 else
272 {
273 int i;
274 for (i=0; i < (int)WXSIZEOF(grayValues); i++)
275 {
276 dc.SetPen( wxPen( wxColour( grayValues[i] , grayValues[i] , grayValues[i] ),
277 1 , wxSOLID ) );
278 dc.DrawRectangle( 0, position+i, size.x, 1 );
279 }
280 }
281#endif
282}
283