]>
Commit | Line | Data |
---|---|---|
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" | |
547aafd2 | 35 | #include "wx/mac/uma.h" |
9c7f49f5 VZ |
36 | |
37 | // ---------------------------------------------------------------------------- | |
38c4cb6a | 38 | // wxRendererMac: our wxRendererNative implementation |
9c7f49f5 VZ |
39 | // ---------------------------------------------------------------------------- |
40 | ||
5cb80ad2 | 41 | class WXDLLEXPORT wxRendererMac : public wxDelegateRendererNative |
9c7f49f5 VZ |
42 | { |
43 | public: | |
44 | // draw the header control button (used by wxListCtrl) | |
45 | virtual void DrawHeaderButton(wxWindow *win, | |
46 | wxDC& dc, | |
47 | const wxRect& rect, | |
48 | int flags = 0); | |
49 | ||
50 | // draw the expanded/collapsed icon for a tree control item | |
51 | virtual void DrawTreeItemButton(wxWindow *win, | |
52 | wxDC& dc, | |
53 | const wxRect& rect, | |
54 | int flags = 0); | |
55 | ||
b3208e11 VZ |
56 | // draw a (vertical) sash |
57 | virtual void DrawSplitterSash(wxWindow *win, | |
58 | wxDC& dc, | |
59 | const wxSize& size, | |
62dc9cb4 | 60 | wxCoord position, |
af99040c VZ |
61 | wxOrientation orient, |
62 | int flags = 0); | |
b3208e11 | 63 | |
9c7f49f5 VZ |
64 | private: |
65 | // the tree buttons | |
66 | wxBitmap m_bmpTreeExpanded, | |
67 | m_bmpTreeCollapsed; | |
68 | }; | |
69 | ||
70 | // ---------------------------------------------------------------------------- | |
71 | // Aqua arrows | |
72 | // ---------------------------------------------------------------------------- | |
73 | ||
74 | /* XPM */ | |
75 | static const char *aqua_arrow_right_xpm[] = { | |
76 | /* columns rows colors chars-per-pixel */ | |
77 | "13 11 4 1", | |
78 | " c None", | |
79 | "b c #C0C0C0", | |
80 | "c c #707070", | |
81 | "d c #A0A0A0", | |
82 | /* pixels */ | |
83 | " b ", | |
84 | " ddb ", | |
85 | " cccdb ", | |
86 | " cccccd ", | |
87 | " ccccccdb ", | |
88 | " ccccccccd", | |
89 | " ccccccdb ", | |
90 | " cccccb ", | |
91 | " cccdb ", | |
92 | " ddb ", | |
93 | " b " | |
94 | }; | |
95 | ||
96 | /* XPM */ | |
97 | static const char *aqua_arrow_down_xpm[] = { | |
98 | /* columns rows colors chars-per-pixel */ | |
99 | "13 11 4 1", | |
100 | " c None", | |
101 | "b c #C0C0C0", | |
102 | "c c #707070", | |
103 | "d c #A0A0A0", | |
104 | /* pixels */ | |
105 | " ", | |
106 | " ", | |
107 | " bdcccccccdb ", | |
108 | " dcccccccd ", | |
109 | " bcccccccb ", | |
110 | " dcccccd ", | |
111 | " bcccccb ", | |
112 | " bcccd ", | |
113 | " dcd ", | |
114 | " bcb ", | |
115 | " d " | |
116 | }; | |
117 | ||
118 | // ============================================================================ | |
119 | // implementation | |
120 | // ============================================================================ | |
121 | ||
122 | /* static */ | |
f0244295 | 123 | wxRendererNative& wxRendererNative::GetDefault() |
9c7f49f5 VZ |
124 | { |
125 | static wxRendererMac s_rendererMac; | |
126 | ||
127 | return s_rendererMac; | |
128 | } | |
129 | ||
130 | void | |
131 | wxRendererMac::DrawHeaderButton(wxWindow *win, | |
132 | wxDC& dc, | |
133 | const wxRect& rect, | |
134 | int WXUNUSED(flags)) | |
135 | { | |
136 | const int CORNER = 1; | |
137 | ||
48fbb521 RR |
138 | const wxCoord x = rect.x-1, |
139 | y = rect.y-1, | |
9c7f49f5 VZ |
140 | w = rect.width, |
141 | h = rect.height; | |
142 | ||
11d1adbf SC |
143 | int major,minor; |
144 | wxGetOsVersion( &major, &minor ); | |
9c7f49f5 | 145 | |
11d1adbf | 146 | dc.SetBrush( *wxTRANSPARENT_BRUSH ); |
9c7f49f5 | 147 | |
11d1adbf SC |
148 | if (major >= 10) |
149 | { | |
150 | dc.SetPen( wxPen( wxColour( 0xC5 , 0xC5 , 0xC5 ) , 1 , wxSOLID ) ); | |
151 | dc.DrawRectangle( x, y+CORNER, 1, h-CORNER ); // left | |
152 | // The right border is overdrawn by the left border of the right neighbouring | |
153 | // header (to maintain a proper single pixel border). Except for the | |
154 | // rightmost header of the listctrl. | |
155 | dc.DrawRectangle( x+w+(CORNER*2), y+CORNER, 1, h-CORNER ); // right | |
156 | dc.SetPen( wxPen( wxColour( 0xB1 , 0xB1 , 0xB1 ) , 1 , wxSOLID ) ); | |
157 | dc.DrawRectangle( x, y+h, w+(CORNER*3), 1 ); // bottom | |
158 | dc.DrawRectangle( x, y, w+(CORNER*3), 1 ); // top | |
159 | ||
160 | // Do a fill of the interior for background: | |
161 | dc.SetPen( wxPen( wxColour( 0xF6 , 0xF6 , 0xF6 ) , 1 , wxSOLID ) ); | |
162 | dc.DrawRectangle( x+CORNER, y+CORNER, w+CORNER, h-CORNER ); | |
163 | ||
164 | // Do the gradient fill: | |
165 | static int grayValues[] = | |
166 | { | |
167 | 0xF6, 0xF2, 0xEF, 0xED, 0xED, 0xEB, 0xEA, 0xEA, 0xE8, | |
168 | 0xE8, 0xE2, 0xE5, 0xE8, 0xEB, 0xEF, 0xF2, 0xFD | |
169 | }; | |
170 | int i; | |
171 | for (i=0; i < h && i < (int)WXSIZEOF(grayValues); i++) | |
172 | { | |
173 | dc.SetPen( wxPen( wxColour( grayValues[i] , grayValues[i] , grayValues[i] ), | |
174 | 1 , wxSOLID ) ); | |
175 | dc.DrawRectangle( x+CORNER, y+CORNER+i, w+CORNER, 1 ); | |
176 | } | |
177 | } | |
178 | else | |
179 | { | |
180 | dc.SetPen( wxPen( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNSHADOW ) , 1 , wxSOLID ) ); | |
181 | dc.DrawLine( x+w-CORNER+1, y, x+w, y+h ); // right (outer) | |
182 | dc.DrawRectangle( x, y+h, w+1, 1 ); // bottom (outer) | |
183 | ||
184 | wxPen pen( wxColour( 0x88 , 0x88 , 0x88 ), 1, wxSOLID ); | |
185 | ||
186 | dc.SetPen( pen ); | |
187 | dc.DrawLine( x+w-CORNER, y, x+w-1, y+h ); // right (inner) | |
188 | dc.DrawRectangle( x+1, y+h-1, w-2, 1 ); // bottom (inner) | |
189 | ||
190 | dc.SetPen( *wxWHITE_PEN ); | |
191 | dc.DrawRectangle( x, y, w-CORNER+1, 1 ); // top (outer) | |
192 | dc.DrawRectangle( x, y, 1, h ); // left (outer) | |
193 | dc.DrawLine( x, y+h-1, x+1, y+h-1 ); | |
194 | dc.DrawLine( x+w-1, y, x+w-1, y+1 ); | |
195 | } | |
9c7f49f5 VZ |
196 | } |
197 | ||
198 | void | |
199 | wxRendererMac::DrawTreeItemButton(wxWindow *win, | |
200 | wxDC& dc, | |
201 | const wxRect& rect, | |
202 | int flags) | |
203 | { | |
204 | // init the buttons on demand | |
205 | if ( !m_bmpTreeExpanded.Ok() ) | |
206 | { | |
207 | m_bmpTreeExpanded = wxBitmap(aqua_arrow_down_xpm); | |
208 | m_bmpTreeCollapsed = wxBitmap(aqua_arrow_right_xpm); | |
209 | } | |
210 | ||
211 | // draw them | |
212 | ||
213 | // VZ: this is the old code from treectlg.cpp which apparently doesn't work | |
214 | // but I kept it here just in case it is needed -- if not, please | |
215 | // remove it | |
216 | #if 0 // def __WXMAC__ | |
217 | wxMacPortSetter helper(&dc) ; | |
218 | wxMacWindowClipper clipper(this) ; | |
219 | wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ; | |
220 | ||
221 | int loc_x = x - 5 ; | |
222 | int loc_y = y_mid - 6 ; | |
223 | MacWindowToRootWindow( & loc_x , & loc_y ) ; | |
224 | Rect bounds = { loc_y , loc_x , loc_y + 18 , loc_x + 12 } ; | |
225 | ThemeButtonDrawInfo info = { kThemeStateActive , item->IsExpanded() ? kThemeDisclosureDown : kThemeDisclosureRight , | |
226 | kThemeAdornmentNone }; | |
227 | DrawThemeButton( &bounds, kThemeDisclosureButton , | |
228 | &info , NULL , NULL , NULL , NULL ) ; | |
229 | #else // 1 | |
230 | dc.DrawBitmap(flags & wxCONTROL_EXPANDED ? m_bmpTreeExpanded | |
231 | : m_bmpTreeCollapsed, | |
232 | rect.x, rect.y, true /* use mask */); | |
233 | #endif // 0/1 | |
234 | } | |
235 | ||
b3208e11 | 236 | void |
e356d469 VZ |
237 | wxRendererMac::DrawSplitterSash(wxWindow *win, |
238 | wxDC& dc, | |
239 | const wxSize& size, | |
62dc9cb4 | 240 | wxCoord position, |
af99040c VZ |
241 | wxOrientation orient, |
242 | int WXUNUSED(flags)) | |
b3208e11 | 243 | { |
547aafd2 SC |
244 | #if ( TARGET_API_MAC_OSX == 1 ) && ( MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_3 ) |
245 | if ( UMAGetSystemVersion() >= 0x1030 ) | |
eef4e26c | 246 | { |
547aafd2 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 ); | |
255 | HIViewConvertRect( &splitterRect , (HIViewRef) win->GetHandle() , (HIViewRef) win->MacGetTopLevelWindow()->GetHandle() ) ; | |
256 | ||
257 | // under compositing we should only draw when called by the OS, otherwise just issue a redraw command | |
258 | // strange redraw errors occur if we don't do this | |
259 | ||
260 | if ( dc.IsKindOf( CLASSINFO( wxPaintDC ) ) == false ) | |
eef4e26c | 261 | { |
36168292 DS |
262 | Rect r = { (short) splitterRect.origin.y , (short) splitterRect.origin.x , |
263 | (short) (splitterRect.origin.y + splitterRect.size.height) , (short) (splitterRect.origin.x + splitterRect.size.width) } ; | |
547aafd2 SC |
264 | RgnHandle updateRgn = NewRgn() ; |
265 | RectRgn( updateRgn , &r ) ; | |
266 | HIViewSetNeedsDisplayInRegion( (HIViewRef) win->GetHandle() , updateRgn , true ) ; | |
267 | DisposeRgn( updateRgn ) ; | |
268 | } | |
269 | else | |
270 | { | |
271 | CGContextRef cgContext ; | |
272 | Rect bounds ; | |
273 | GetPortBounds( (CGrafPtr) dc.m_macPort , &bounds ) ; | |
274 | QDBeginCGContext( (CGrafPtr) dc.m_macPort , &cgContext ) ; | |
275 | CGContextTranslateCTM( cgContext , 0 , bounds.bottom - bounds.top ) ; | |
276 | CGContextScaleCTM( cgContext , 1 , -1 ) ; | |
277 | ||
278 | { | |
279 | HIThemeSplitterDrawInfo drawInfo ; | |
280 | drawInfo.version = 0 ; | |
281 | drawInfo.state = kThemeStateActive ; | |
282 | drawInfo.adornment = hasMetal ? kHIThemeSplitterAdornmentMetal : kHIThemeSplitterAdornmentNone ; | |
283 | HIThemeDrawPaneSplitter( &splitterRect , &drawInfo , cgContext , kHIThemeOrientationNormal ) ; | |
284 | } | |
285 | QDEndCGContext( (CGrafPtr) dc.m_macPort , &cgContext ) ; | |
eef4e26c RR |
286 | } |
287 | } | |
288 | else | |
547aafd2 | 289 | #endif |
eef4e26c | 290 | { |
547aafd2 SC |
291 | #if 0 |
292 | dc.SetPen(*wxLIGHT_GREY_PEN); | |
293 | dc.SetBrush(*wxWHITE_BRUSH); | |
294 | if ( orient == wxVERTICAL ) | |
295 | dc.DrawRectangle(position, 0, 7, size.y); | |
296 | else | |
297 | dc.DrawRectangle(0, position, size.x, 7); | |
298 | #else | |
299 | // Do the gradient fill: | |
300 | static int grayValues[] = | |
eef4e26c | 301 | { |
547aafd2 SC |
302 | 0xA0, 0xF6, 0xED, 0xE4, 0xE2, 0xD0, 0xA0 |
303 | }; | |
304 | dc.SetBrush( *wxTRANSPARENT_BRUSH ); | |
305 | if ( orient == wxVERTICAL ) | |
306 | { | |
307 | int i; | |
308 | for (i=0; i < (int)WXSIZEOF(grayValues); i++) | |
309 | { | |
310 | dc.SetPen( wxPen( wxColour( grayValues[i] , grayValues[i] , grayValues[i] ), | |
311 | 1 , wxSOLID ) ); | |
312 | dc.DrawRectangle( position+i, 0, 1, size.y ); | |
313 | } | |
314 | } | |
315 | else | |
316 | { | |
317 | int i; | |
318 | for (i=0; i < (int)WXSIZEOF(grayValues); i++) | |
319 | { | |
320 | dc.SetPen( wxPen( wxColour( grayValues[i] , grayValues[i] , grayValues[i] ), | |
321 | 1 , wxSOLID ) ); | |
322 | dc.DrawRectangle( 0, position+i, size.x, 1 ); | |
323 | } | |
eef4e26c | 324 | } |
eef4e26c | 325 | #endif |
547aafd2 | 326 | } |
b3208e11 VZ |
327 | } |
328 |