]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/renderer.cpp
Deal with a zero to-page
[wxWidgets.git] / src / mac / carbon / renderer.cpp
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>
9 // License: wxWindows license
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
40 class WXDLLEXPORT wxRendererMac : public wxDelegateRendererNative
41 {
42 public:
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
61 private:
62 // the tree buttons
63 wxBitmap m_bmpTreeExpanded,
64 m_bmpTreeCollapsed;
65 };
66
67 // ----------------------------------------------------------------------------
68 // Aqua arrows
69 // ----------------------------------------------------------------------------
70
71 /* XPM */
72 static const char *aqua_arrow_right_xpm[] = {
73 /* columns rows colors chars-per-pixel */
74 "13 11 4 1",
75 " c None",
76 "b c #C0C0C0",
77 "c c #707070",
78 "d c #A0A0A0",
79 /* pixels */
80 " b ",
81 " ddb ",
82 " cccdb ",
83 " cccccd ",
84 " ccccccdb ",
85 " ccccccccd",
86 " ccccccdb ",
87 " cccccb ",
88 " cccdb ",
89 " ddb ",
90 " b "
91 };
92
93 /* XPM */
94 static const char *aqua_arrow_down_xpm[] = {
95 /* columns rows colors chars-per-pixel */
96 "13 11 4 1",
97 " c None",
98 "b c #C0C0C0",
99 "c c #707070",
100 "d c #A0A0A0",
101 /* pixels */
102 " ",
103 " ",
104 " bdcccccccdb ",
105 " dcccccccd ",
106 " bcccccccb ",
107 " dcccccd ",
108 " bcccccb ",
109 " bcccd ",
110 " dcd ",
111 " bcb ",
112 " d "
113 };
114
115 // ============================================================================
116 // implementation
117 // ============================================================================
118
119 /* static */
120 wxRendererNative& wxRendererNative::Get()
121 {
122 static wxRendererMac s_rendererMac;
123
124 return s_rendererMac;
125 }
126
127 void
128 wxRendererMac::DrawHeaderButton(wxWindow *win,
129 wxDC& dc,
130 const wxRect& rect,
131 int WXUNUSED(flags))
132 {
133 const int CORNER = 1;
134
135 const wxCoord x = rect.x,
136 y = rect.y,
137 w = rect.width,
138 h = rect.height;
139
140 dc.SetBrush( *wxTRANSPARENT_BRUSH );
141
142 dc.SetPen( wxPen( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNSHADOW ) , 1 , wxSOLID ) );
143 dc.DrawLine( x+w-CORNER+1, y, x+w, y+h ); // right (outer)
144 dc.DrawRectangle( x, y+h, w+1, 1 ); // bottom (outer)
145
146 wxPen pen( wxColour( 0x88 , 0x88 , 0x88 ), 1, wxSOLID );
147
148 dc.SetPen( pen );
149 dc.DrawLine( x+w-CORNER, y, x+w-1, y+h ); // right (inner)
150 dc.DrawRectangle( x+1, y+h-1, w-2, 1 ); // bottom (inner)
151
152 dc.SetPen( *wxWHITE_PEN );
153 dc.DrawRectangle( x, y, w-CORNER+1, 1 ); // top (outer)
154 dc.DrawRectangle( x, y, 1, h ); // left (outer)
155 dc.DrawLine( x, y+h-1, x+1, y+h-1 );
156 dc.DrawLine( x+w-1, y, x+w-1, y+1 );
157 }
158
159 void
160 wxRendererMac::DrawTreeItemButton(wxWindow *win,
161 wxDC& dc,
162 const wxRect& rect,
163 int flags)
164 {
165 // init the buttons on demand
166 if ( !m_bmpTreeExpanded.Ok() )
167 {
168 m_bmpTreeExpanded = wxBitmap(aqua_arrow_down_xpm);
169 m_bmpTreeCollapsed = wxBitmap(aqua_arrow_right_xpm);
170 }
171
172 // draw them
173
174 // VZ: this is the old code from treectlg.cpp which apparently doesn't work
175 // but I kept it here just in case it is needed -- if not, please
176 // remove it
177 #if 0 // def __WXMAC__
178 wxMacPortSetter helper(&dc) ;
179 wxMacWindowClipper clipper(this) ;
180 wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ;
181
182 int loc_x = x - 5 ;
183 int loc_y = y_mid - 6 ;
184 MacWindowToRootWindow( & loc_x , & loc_y ) ;
185 Rect bounds = { loc_y , loc_x , loc_y + 18 , loc_x + 12 } ;
186 ThemeButtonDrawInfo info = { kThemeStateActive , item->IsExpanded() ? kThemeDisclosureDown : kThemeDisclosureRight ,
187 kThemeAdornmentNone };
188 DrawThemeButton( &bounds, kThemeDisclosureButton ,
189 &info , NULL , NULL , NULL , NULL ) ;
190 #else // 1
191 dc.DrawBitmap(flags & wxCONTROL_EXPANDED ? m_bmpTreeExpanded
192 : m_bmpTreeCollapsed,
193 rect.x, rect.y, true /* use mask */);
194 #endif // 0/1
195 }
196
197 void
198 wxRendererMac::DrawSplitterSash(wxWindow *win,
199 wxDC& dc,
200 const wxSize& size,
201 wxCoord position)
202 {
203 // VZ: we have to somehow determine if we're drawing a normal sash or
204 // a brushed metal one as they look quite differently... this is
205 // completely bogus anyhow, of course (TODO)
206
207 const wxCoord h = size.y;
208
209 dc.SetPen(*wxLIGHT_GREY_PEN);
210 dc.SetBrush(*wxWHITE_BRUSH);
211 dc.DrawRectangle(position, 0, 7, h);
212 }
213