]>
Commit | Line | Data |
---|---|---|
9c7f49f5 | 1 | /////////////////////////////////////////////////////////////////////////////// |
5c1f6b27 | 2 | // Name: src/generic/renderg.cpp |
38c4cb6a | 3 | // Purpose: generic implementation of wxRendererNative (for any platform) |
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> | |
0a53b9b8 | 9 | // License: wxWindows license |
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 | ||
da80ae71 WS |
27 | #include "wx/renderer.h" |
28 | ||
9c7f49f5 VZ |
29 | #ifndef WX_PRECOMP |
30 | #include "wx/string.h" | |
da80ae71 | 31 | #include "wx/dc.h" |
9eddec69 | 32 | #include "wx/settings.h" |
dd05139a | 33 | #include "wx/gdicmn.h" |
02761f6c | 34 | #include "wx/module.h" |
9c7f49f5 VZ |
35 | #endif //WX_PRECOMP |
36 | ||
52c14774 | 37 | #include "wx/splitter.h" |
62dc9cb4 | 38 | #include "wx/dcmirror.h" |
9c7f49f5 | 39 | |
ce0cf2b8 | 40 | #ifdef __WXMAC__ |
33ddeaba | 41 | #include "wx/osx/private.h" |
ce0cf2b8 RR |
42 | #endif |
43 | ||
9c7f49f5 | 44 | // ---------------------------------------------------------------------------- |
38c4cb6a | 45 | // wxRendererGeneric: our wxRendererNative implementation |
9c7f49f5 VZ |
46 | // ---------------------------------------------------------------------------- |
47 | ||
38c4cb6a | 48 | class WXDLLEXPORT wxRendererGeneric : public wxRendererNative |
9c7f49f5 VZ |
49 | { |
50 | public: | |
b3208e11 VZ |
51 | wxRendererGeneric(); |
52 | ||
c97c9952 | 53 | virtual int DrawHeaderButton(wxWindow *win, |
9c7f49f5 VZ |
54 | wxDC& dc, |
55 | const wxRect& rect, | |
4b94ddc4 | 56 | int flags = 0, |
9c97f006 | 57 | wxHeaderSortIconType sortArrow = wxHDR_SORT_ICON_NONE, |
4b94ddc4 RD |
58 | wxHeaderButtonParams* params = NULL); |
59 | ||
c97c9952 | 60 | virtual int DrawHeaderButtonContents(wxWindow *win, |
4b94ddc4 RD |
61 | wxDC& dc, |
62 | const wxRect& rect, | |
63 | int flags = 0, | |
9c97f006 | 64 | wxHeaderSortIconType sortArrow = wxHDR_SORT_ICON_NONE, |
4b94ddc4 RD |
65 | wxHeaderButtonParams* params = NULL); |
66 | ||
67 | virtual int GetHeaderButtonHeight(wxWindow *win); | |
9c7f49f5 | 68 | |
9c7f49f5 VZ |
69 | virtual void DrawTreeItemButton(wxWindow *win, |
70 | wxDC& dc, | |
71 | const wxRect& rect, | |
72 | int flags = 0); | |
b3208e11 VZ |
73 | |
74 | virtual void DrawSplitterBorder(wxWindow *win, | |
75 | wxDC& dc, | |
af99040c VZ |
76 | const wxRect& rect, |
77 | int flags = 0); | |
b3208e11 VZ |
78 | |
79 | virtual void DrawSplitterSash(wxWindow *win, | |
80 | wxDC& dc, | |
81 | const wxSize& size, | |
62dc9cb4 | 82 | wxCoord position, |
af99040c VZ |
83 | wxOrientation orient, |
84 | int flags = 0); | |
b3208e11 | 85 | |
f33cef9f VZ |
86 | virtual void DrawComboBoxDropButton(wxWindow *win, |
87 | wxDC& dc, | |
88 | const wxRect& rect, | |
89 | int flags = 0); | |
90 | ||
4c85ab75 VZ |
91 | virtual void DrawDropArrow(wxWindow *win, |
92 | wxDC& dc, | |
93 | const wxRect& rect, | |
94 | int flags = 0); | |
b3208e11 | 95 | |
90b903c2 WS |
96 | virtual void DrawCheckBox(wxWindow *win, |
97 | wxDC& dc, | |
98 | const wxRect& rect, | |
99 | int flags = 0); | |
2209baae | 100 | |
e8759560 VZ |
101 | virtual wxSize GetCheckBoxSize(wxWindow *win); |
102 | ||
2209baae RR |
103 | virtual void DrawPushButton(wxWindow *win, |
104 | wxDC& dc, | |
105 | const wxRect& rect, | |
106 | int flags = 0); | |
107 | ||
daebb44c RR |
108 | virtual void DrawItemSelectionRect(wxWindow *win, |
109 | wxDC& dc, | |
110 | const wxRect& rect, | |
111 | int flags = 0); | |
784d2408 | 112 | |
6d789987 JS |
113 | virtual void DrawFocusRect(wxWindow* win, wxDC& dc, const wxRect& rect, int flags = 0); |
114 | ||
af99040c | 115 | virtual wxSplitterRenderParams GetSplitterParams(const wxWindow *win); |
b3208e11 | 116 | |
04857cb7 VZ |
117 | virtual wxRendererVersion GetVersion() const |
118 | { | |
119 | return wxRendererVersion(wxRendererVersion::Current_Version, | |
120 | wxRendererVersion::Current_Age); | |
121 | } | |
122 | ||
123 | ||
0872a451 JS |
124 | // Cleanup by deleting standard renderer |
125 | static void Cleanup(); | |
126 | ||
127 | // Get the generic object | |
128 | static wxRendererGeneric* DoGetGeneric(); | |
b3208e11 VZ |
129 | |
130 | protected: | |
131 | // draw the rectange using the first pen for the left and top sides and | |
132 | // the second one for the bottom and right ones | |
133 | void DrawShadedRect(wxDC& dc, wxRect *rect, | |
134 | const wxPen& pen1, const wxPen& pen2); | |
135 | ||
136 | // the standard pens | |
137 | wxPen m_penBlack, | |
138 | m_penDarkGrey, | |
139 | m_penLightGrey, | |
140 | m_penHighlight; | |
0872a451 JS |
141 | |
142 | static wxRendererGeneric* sm_rendererGeneric; | |
9c7f49f5 VZ |
143 | }; |
144 | ||
145 | // ============================================================================ | |
b3208e11 | 146 | // wxRendererGeneric implementation |
9c7f49f5 VZ |
147 | // ============================================================================ |
148 | ||
0872a451 JS |
149 | // Get the generic object |
150 | wxRendererGeneric* wxRendererGeneric::DoGetGeneric() | |
151 | { | |
152 | if (!sm_rendererGeneric) | |
153 | sm_rendererGeneric = new wxRendererGeneric; | |
154 | return sm_rendererGeneric; | |
155 | } | |
156 | ||
9c7f49f5 VZ |
157 | // ---------------------------------------------------------------------------- |
158 | // wxRendererGeneric creation | |
159 | // ---------------------------------------------------------------------------- | |
160 | ||
161 | /* static */ | |
38c4cb6a | 162 | wxRendererNative& wxRendererNative::GetGeneric() |
9c7f49f5 | 163 | { |
0872a451 JS |
164 | return * wxRendererGeneric::DoGetGeneric(); |
165 | } | |
9c7f49f5 | 166 | |
0872a451 JS |
167 | void wxRendererGeneric::Cleanup() |
168 | { | |
169 | if (sm_rendererGeneric) | |
170 | delete sm_rendererGeneric; | |
ca65c044 | 171 | |
0872a451 | 172 | sm_rendererGeneric = NULL; |
9c7f49f5 VZ |
173 | } |
174 | ||
0872a451 JS |
175 | wxRendererGeneric* wxRendererGeneric::sm_rendererGeneric = NULL; |
176 | ||
b3208e11 VZ |
177 | wxRendererGeneric::wxRendererGeneric() |
178 | : m_penBlack(wxSystemSettings::GetColour(wxSYS_COLOUR_3DDKSHADOW)), | |
179 | m_penDarkGrey(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW)), | |
180 | m_penLightGrey(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE)), | |
181 | m_penHighlight(wxSystemSettings::GetColour(wxSYS_COLOUR_3DHIGHLIGHT)) | |
182 | { | |
183 | } | |
184 | ||
9c7f49f5 | 185 | // ---------------------------------------------------------------------------- |
b3208e11 VZ |
186 | // wxRendererGeneric helpers |
187 | // ---------------------------------------------------------------------------- | |
188 | ||
189 | void | |
190 | wxRendererGeneric::DrawShadedRect(wxDC& dc, | |
191 | wxRect *rect, | |
192 | const wxPen& pen1, | |
193 | const wxPen& pen2) | |
194 | { | |
195 | // draw the rectangle | |
196 | dc.SetPen(pen1); | |
197 | dc.DrawLine(rect->GetLeft(), rect->GetTop(), | |
198 | rect->GetLeft(), rect->GetBottom()); | |
199 | dc.DrawLine(rect->GetLeft() + 1, rect->GetTop(), | |
200 | rect->GetRight(), rect->GetTop()); | |
201 | dc.SetPen(pen2); | |
202 | dc.DrawLine(rect->GetRight(), rect->GetTop(), | |
203 | rect->GetRight(), rect->GetBottom()); | |
204 | dc.DrawLine(rect->GetLeft(), rect->GetBottom(), | |
205 | rect->GetRight() + 1, rect->GetBottom()); | |
206 | ||
207 | // adjust the rect | |
208 | rect->Inflate(-1); | |
209 | } | |
210 | ||
211 | // ---------------------------------------------------------------------------- | |
212 | // tree/list ctrl drawing | |
9c7f49f5 VZ |
213 | // ---------------------------------------------------------------------------- |
214 | ||
c97c9952 | 215 | int |
4b94ddc4 | 216 | wxRendererGeneric::DrawHeaderButton(wxWindow* win, |
9c7f49f5 VZ |
217 | wxDC& dc, |
218 | const wxRect& rect, | |
4b94ddc4 | 219 | int flags, |
80752b57 | 220 | wxHeaderSortIconType sortArrow, |
4b94ddc4 | 221 | wxHeaderButtonParams* params) |
9c7f49f5 | 222 | { |
38c4cb6a VZ |
223 | const wxCoord x = rect.x, |
224 | y = rect.y, | |
225 | w = rect.width, | |
226 | h = rect.height; | |
9c7f49f5 | 227 | |
4b94ddc4 RD |
228 | dc.SetBrush(wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE))); |
229 | dc.SetPen(*wxTRANSPARENT_PEN); | |
230 | dc.DrawRectangle(rect); | |
6d789987 | 231 | |
b3208e11 | 232 | dc.SetBrush(*wxTRANSPARENT_BRUSH); |
9c7f49f5 | 233 | |
b3208e11 | 234 | dc.SetPen(m_penBlack); |
cae618d1 VZ |
235 | dc.DrawLine( x+w-1, y, x+w-1, y+h ); // right (outer) |
236 | dc.DrawLine( x, y+h-1, x+w, y+h-1 ); // bottom (outer) | |
9c7f49f5 | 237 | |
b3208e11 | 238 | dc.SetPen(m_penDarkGrey); |
cae618d1 VZ |
239 | dc.DrawLine( x+w-2, y+1, x+w-2, y+h-1 ); // right (inner) |
240 | dc.DrawLine( x+1, y+h-2, x+w-1, y+h-2 ); // bottom (inner) | |
9c7f49f5 | 241 | |
b3208e11 | 242 | dc.SetPen(m_penHighlight); |
cae618d1 VZ |
243 | dc.DrawLine( x, y, x, y+h-1 ); // left (outer) |
244 | dc.DrawLine( x, y, x+w-1, y ); // top (outer) | |
4b94ddc4 | 245 | |
c97c9952 | 246 | return DrawHeaderButtonContents(win, dc, rect, flags, sortArrow, params); |
9c7f49f5 VZ |
247 | } |
248 | ||
80752b57 | 249 | |
c97c9952 | 250 | int |
4b94ddc4 RD |
251 | wxRendererGeneric::DrawHeaderButtonContents(wxWindow *win, |
252 | wxDC& dc, | |
253 | const wxRect& rect, | |
254 | int flags, | |
80752b57 | 255 | wxHeaderSortIconType sortArrow, |
4b94ddc4 RD |
256 | wxHeaderButtonParams* params) |
257 | { | |
c97c9952 | 258 | int labelWidth = 0; |
6d789987 | 259 | |
4b94ddc4 RD |
260 | // Mark this item as selected. For the generic version we'll just draw an |
261 | // underline | |
262 | if ( flags & wxCONTROL_SELECTED ) | |
263 | { | |
264 | // draw a line at the bottom of the header button, overlaying the | |
265 | // native hot-tracking line (on XP) | |
266 | const int penwidth = 3; | |
267 | int y = rect.y + rect.height + 1 - penwidth; | |
268 | wxColour c = (params && params->m_selectionColour.Ok()) ? | |
269 | params->m_selectionColour : wxColour(0x66, 0x66, 0x66); | |
270 | wxPen pen(c, penwidth); | |
271 | pen.SetCap(wxCAP_BUTT); | |
272 | dc.SetPen(pen); | |
273 | dc.DrawLine(rect.x, y, rect.x + rect.width, y); | |
274 | } | |
275 | ||
276 | // Draw an up or down arrow | |
277 | int arrowSpace = 0; | |
80752b57 | 278 | if (sortArrow != wxHDR_SORT_ICON_NONE ) |
4b94ddc4 RD |
279 | { |
280 | wxRect ar = rect; | |
281 | ||
282 | // make a rect for the arrow | |
283 | ar.height = 4; | |
284 | ar.width = 8; | |
285 | ar.y += (rect.height - ar.height)/2; | |
286 | ar.x = ar.x + rect.width - 3*ar.width/2; | |
287 | arrowSpace = 3*ar.width/2; // space to preserve when drawing the label | |
6d789987 | 288 | |
4b94ddc4 | 289 | wxPoint triPt[3]; |
80752b57 | 290 | if ( sortArrow & wxHDR_SORT_ICON_UP ) |
4b94ddc4 RD |
291 | { |
292 | triPt[0].x = ar.width / 2; | |
293 | triPt[0].y = 0; | |
294 | triPt[1].x = ar.width; | |
295 | triPt[1].y = ar.height; | |
296 | triPt[2].x = 0; | |
297 | triPt[2].y = ar.height; | |
298 | } | |
299 | else | |
300 | { | |
301 | triPt[0].x = 0; | |
302 | triPt[0].y = 0; | |
303 | triPt[1].x = ar.width; | |
304 | triPt[1].y = 0; | |
305 | triPt[2].x = ar.width / 2; | |
306 | triPt[2].y = ar.height; | |
307 | } | |
308 | ||
309 | wxColour c = (params && params->m_arrowColour.Ok()) ? | |
310 | params->m_arrowColour : wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW); | |
311 | dc.SetPen(wxPen(c)); | |
312 | dc.SetBrush(wxBrush(c)); | |
6d789987 | 313 | dc.DrawPolygon( 3, triPt, ar.x, ar.y); |
4b94ddc4 | 314 | } |
c97c9952 | 315 | labelWidth += arrowSpace; |
6d789987 | 316 | |
4b94ddc4 RD |
317 | const int margin = 5; // number of pixels to reserve on either side of the label |
318 | int bmpWidth = 0; | |
319 | int txtEnd = 0; | |
6d789987 | 320 | |
4b94ddc4 RD |
321 | if ( params && params->m_labelBitmap.Ok() ) |
322 | bmpWidth = params->m_labelBitmap.GetWidth() + 2; | |
c97c9952 RD |
323 | |
324 | labelWidth += bmpWidth + 2*margin; | |
6d789987 | 325 | |
4b94ddc4 RD |
326 | // Draw a label if one is given |
327 | if ( params && !params->m_labelText.empty() ) | |
328 | { | |
329 | wxFont font = params->m_labelFont.Ok() ? | |
330 | params->m_labelFont : win->GetFont(); | |
331 | wxColour clr = params->m_labelColour.Ok() ? | |
332 | params->m_labelColour : win->GetForegroundColour(); | |
333 | ||
334 | wxString label( params->m_labelText ); | |
6d789987 | 335 | |
4b94ddc4 RD |
336 | dc.SetFont(font); |
337 | dc.SetTextForeground(clr); | |
04ee05f9 | 338 | dc.SetBackgroundMode(wxBRUSHSTYLE_TRANSPARENT); |
4b94ddc4 RD |
339 | |
340 | int tw, th, td, x, y; | |
341 | dc.GetTextExtent( label, &tw, &th, &td); | |
c97c9952 | 342 | labelWidth += tw; |
4b94ddc4 | 343 | y = rect.y + wxMax(0, (rect.height - (th+td)) / 2); |
6d789987 | 344 | |
4b94ddc4 RD |
345 | // truncate and add an ellipsis (...) if the text is too wide. |
346 | int targetWidth = rect.width - arrowSpace - bmpWidth - 2*margin; | |
6d789987 | 347 | if ( tw > targetWidth ) |
4b94ddc4 RD |
348 | { |
349 | int ellipsisWidth; | |
350 | dc.GetTextExtent( wxT("..."), &ellipsisWidth, NULL); | |
351 | do { | |
352 | label.Truncate( label.length() - 1 ); | |
353 | dc.GetTextExtent( label, &tw, &th); | |
354 | } while (tw + ellipsisWidth > targetWidth && label.length() ); | |
355 | label.append( wxT("...") ); | |
356 | tw += ellipsisWidth; | |
357 | } | |
6d789987 | 358 | |
4b94ddc4 RD |
359 | switch (params->m_labelAlignment) |
360 | { | |
361 | default: | |
362 | case wxALIGN_LEFT: | |
363 | x = rect.x + margin; | |
364 | break; | |
365 | case wxALIGN_CENTER: | |
366 | x = rect.x + wxMax(0, (rect.width - arrowSpace - tw - bmpWidth)/2); | |
367 | break; | |
368 | case wxALIGN_RIGHT: | |
369 | x = rect.x + wxMax(0, rect.width - arrowSpace - margin - tw - bmpWidth); | |
370 | break; | |
371 | } | |
372 | ||
373 | dc.DrawText(label, x, y); | |
374 | txtEnd = x + tw + 2; | |
375 | } | |
376 | ||
377 | // draw the bitmap if there is one | |
378 | if ( params && params->m_labelBitmap.Ok() ) | |
379 | { | |
380 | int w, h, x, y; | |
381 | w = params->m_labelBitmap.GetWidth(); | |
382 | h = params->m_labelBitmap.GetHeight(); | |
383 | ||
384 | y = rect.y + wxMax(1, (rect.height - h) / 2); | |
385 | ||
386 | // if there is a text label, then put the bitmap at the end of the label | |
387 | if ( txtEnd != 0 ) | |
388 | { | |
389 | x = txtEnd; | |
390 | } | |
391 | // otherwise use the alignment flags | |
392 | else | |
393 | { | |
394 | switch (params->m_labelAlignment) | |
395 | { | |
396 | default: | |
397 | case wxALIGN_LEFT: | |
398 | x = rect.x + margin; | |
399 | break; | |
400 | case wxALIGN_CENTER: | |
401 | x = rect.x + wxMax(1, (rect.width - arrowSpace - w)/2); | |
402 | break; | |
403 | case wxALIGN_RIGHT: | |
404 | x = rect.x + wxMax(1, rect.width - arrowSpace - margin - w); | |
405 | break; | |
406 | } | |
407 | } | |
408 | dc.DrawBitmap(params->m_labelBitmap, x, y, true); | |
409 | } | |
c97c9952 | 410 | return labelWidth; |
4b94ddc4 RD |
411 | } |
412 | ||
413 | ||
414 | int wxRendererGeneric::GetHeaderButtonHeight(wxWindow *win) | |
415 | { | |
416 | // Copied and adapted from src/generic/listctrl.cpp | |
417 | const int HEADER_OFFSET_Y = 1; | |
418 | const int EXTRA_HEIGHT = 4; | |
419 | ||
420 | int w=0, h=14, d=0; | |
421 | if (win) | |
422 | win->GetTextExtent(wxT("Hg"), &w, &h, &d); | |
423 | ||
424 | return h + d + 2 * HEADER_OFFSET_Y + EXTRA_HEIGHT; | |
425 | } | |
426 | ||
427 | ||
9c7f49f5 VZ |
428 | // draw the plus or minus sign |
429 | void | |
2eb10e2a | 430 | wxRendererGeneric::DrawTreeItemButton(wxWindow * WXUNUSED(win), |
9c7f49f5 VZ |
431 | wxDC& dc, |
432 | const wxRect& rect, | |
433 | int flags) | |
434 | { | |
75d6ba56 | 435 | // store settings |
0164f8eb WS |
436 | wxDCPenChanger penChanger(dc, *wxGREY_PEN); |
437 | wxDCBrushChanger brushChanger(dc, *wxWHITE_BRUSH); | |
4660e6ac | 438 | |
0e7761fa | 439 | dc.DrawRectangle(rect); |
9c7f49f5 VZ |
440 | |
441 | // black lines | |
442 | const wxCoord xMiddle = rect.x + rect.width/2; | |
443 | const wxCoord yMiddle = rect.y + rect.height/2; | |
444 | ||
0e7761fa VZ |
445 | // half of the length of the horz lines in "-" and "+" |
446 | const wxCoord halfWidth = rect.width/2 - 2; | |
9c7f49f5 | 447 | dc.SetPen(*wxBLACK_PEN); |
429ef4bc VZ |
448 | dc.DrawLine(xMiddle - halfWidth, yMiddle, |
449 | xMiddle + halfWidth + 1, yMiddle); | |
450 | ||
e8448b79 | 451 | if ( !(flags & wxCONTROL_EXPANDED) ) |
9c7f49f5 VZ |
452 | { |
453 | // turn "-" into "+" | |
0e7761fa VZ |
454 | const wxCoord halfHeight = rect.height/2 - 2; |
455 | dc.DrawLine(xMiddle, yMiddle - halfHeight, | |
429ef4bc | 456 | xMiddle, yMiddle + halfHeight + 1); |
9c7f49f5 VZ |
457 | } |
458 | } | |
459 | ||
b3208e11 VZ |
460 | // ---------------------------------------------------------------------------- |
461 | // sash drawing | |
462 | // ---------------------------------------------------------------------------- | |
463 | ||
af99040c VZ |
464 | wxSplitterRenderParams |
465 | wxRendererGeneric::GetSplitterParams(const wxWindow *win) | |
b3208e11 VZ |
466 | { |
467 | // see below | |
af99040c VZ |
468 | wxCoord sashWidth, |
469 | border; | |
470 | ||
4666bb5f | 471 | if ( win->HasFlag(wxSP_3DSASH) ) |
af99040c | 472 | sashWidth = 7; |
4666bb5f JS |
473 | else if ( win->HasFlag(wxSP_NOSASH) ) |
474 | sashWidth = 0; | |
af99040c | 475 | else // no 3D effect |
28f9eac4 | 476 | sashWidth = 3; |
4666bb5f JS |
477 | |
478 | if ( win->HasFlag(wxSP_3DBORDER) ) | |
479 | border = 2; | |
480 | else // no 3D effect | |
af99040c | 481 | border = 0; |
af99040c VZ |
482 | |
483 | return wxSplitterRenderParams(sashWidth, border, false); | |
b3208e11 VZ |
484 | } |
485 | ||
486 | void | |
52c14774 | 487 | wxRendererGeneric::DrawSplitterBorder(wxWindow *win, |
b3208e11 | 488 | wxDC& dc, |
af99040c VZ |
489 | const wxRect& rectOrig, |
490 | int WXUNUSED(falgs)) | |
b3208e11 | 491 | { |
4666bb5f | 492 | if ( win->HasFlag(wxSP_3DBORDER) ) |
52c14774 VZ |
493 | { |
494 | wxRect rect = rectOrig; | |
495 | DrawShadedRect(dc, &rect, m_penDarkGrey, m_penHighlight); | |
496 | DrawShadedRect(dc, &rect, m_penBlack, m_penLightGrey); | |
497 | } | |
b3208e11 VZ |
498 | } |
499 | ||
500 | void | |
52c14774 | 501 | wxRendererGeneric::DrawSplitterSash(wxWindow *win, |
62dc9cb4 VZ |
502 | wxDC& dcReal, |
503 | const wxSize& sizeReal, | |
504 | wxCoord position, | |
af99040c VZ |
505 | wxOrientation orient, |
506 | int WXUNUSED(flags)) | |
b3208e11 | 507 | { |
62dc9cb4 VZ |
508 | // to avoid duplicating the same code for horizontal and vertical sashes, |
509 | // simply mirror the DC instead if needed (i.e. if horz splitter) | |
510 | wxMirrorDC dc(dcReal, orient != wxVERTICAL); | |
511 | wxSize size = dc.Reflect(sizeReal); | |
512 | ||
513 | ||
52c14774 | 514 | // we draw a Win32-like grey sash with possible 3D border here: |
b3208e11 VZ |
515 | // |
516 | // ---- this is position | |
517 | // / | |
518 | // v | |
519 | // dWGGGDd | |
520 | // GWGGGDB | |
521 | // GWGGGDB where G is light grey (face) | |
522 | // GWGGGDB W white (light) | |
523 | // GWGGGDB D dark grey (shadow) | |
524 | // GWGGGDB B black (dark shadow) | |
525 | // GWGGGDB | |
526 | // GWGGGDB and lower letters are our border (already drawn) | |
527 | // GWGGGDB | |
528 | // wWGGGDd | |
52c14774 VZ |
529 | // |
530 | // only the middle 3 columns are drawn unless wxSP_3D is specified | |
b3208e11 VZ |
531 | |
532 | const wxCoord h = size.y; | |
8aa528db | 533 | wxCoord offset = 0; |
ca65c044 | 534 | |
4666bb5f JS |
535 | // If we're drawing the border, draw the sash 3d lines shorter |
536 | if ( win->HasFlag(wxSP_3DBORDER) ) | |
8aa528db | 537 | { |
4666bb5f | 538 | offset = 1; |
8aa528db | 539 | } |
b3208e11 | 540 | |
4666bb5f | 541 | dc.SetPen(*wxTRANSPARENT_PEN); |
ca65c044 WS |
542 | dc.SetBrush(wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE))); |
543 | ||
4666bb5f | 544 | if ( win->HasFlag(wxSP_3DSASH) ) |
52c14774 | 545 | { |
4666bb5f JS |
546 | // Draw the 3D sash |
547 | dc.DrawRectangle(position + 2, 0, 3, h); | |
548 | ||
52c14774 | 549 | dc.SetPen(m_penLightGrey); |
4666bb5f | 550 | dc.DrawLine(position, offset, position, h - offset); |
b3208e11 | 551 | |
52c14774 | 552 | dc.SetPen(m_penHighlight); |
4666bb5f | 553 | dc.DrawLine(position + 1, 0, position + 1, h); |
b3208e11 | 554 | |
52c14774 | 555 | dc.SetPen(m_penDarkGrey); |
4666bb5f | 556 | dc.DrawLine(position + 5, 0, position + 5, h); |
b3208e11 | 557 | |
52c14774 | 558 | dc.SetPen(m_penBlack); |
4666bb5f JS |
559 | dc.DrawLine(position + 6, offset, position + 6, h - offset); |
560 | } | |
561 | else | |
562 | { | |
563 | // Draw a flat sash | |
564 | dc.DrawRectangle(position, 0, 3, h); | |
52c14774 | 565 | } |
b3208e11 | 566 | } |
9c7f49f5 | 567 | |
4c85ab75 VZ |
568 | // ---------------------------------------------------------------------------- |
569 | // button drawing | |
570 | // ---------------------------------------------------------------------------- | |
571 | ||
f33cef9f VZ |
572 | void |
573 | wxRendererGeneric::DrawComboBoxDropButton(wxWindow *win, | |
574 | wxDC& dc, | |
575 | const wxRect& rect, | |
2209baae | 576 | int flags) |
f33cef9f | 577 | { |
2209baae RR |
578 | DrawPushButton(win,dc,rect,flags); |
579 | DrawDropArrow(win,dc,rect,flags); | |
4c85ab75 VZ |
580 | } |
581 | ||
4c85ab75 VZ |
582 | void |
583 | wxRendererGeneric::DrawDropArrow(wxWindow *win, | |
584 | wxDC& dc, | |
585 | const wxRect& rect, | |
586 | int WXUNUSED(flags)) | |
587 | { | |
588 | // This generic implementation should be good | |
589 | // enough for Windows platforms (including XP). | |
590 | ||
591 | int arrowHalf = rect.width/5; | |
592 | int rectMid = rect.width / 2; | |
593 | int arrowTopY = (rect.height/2) - (arrowHalf/2); | |
594 | ||
595 | // This should always result in arrow with odd width. | |
106a7999 | 596 | wxPoint pt[] = |
f33cef9f | 597 | { |
4c85ab75 VZ |
598 | wxPoint(rectMid - arrowHalf, arrowTopY), |
599 | wxPoint(rectMid + arrowHalf, arrowTopY), | |
600 | wxPoint(rectMid, arrowTopY + arrowHalf) | |
f33cef9f VZ |
601 | }; |
602 | dc.SetBrush(wxBrush(win->GetForegroundColour())); | |
603 | dc.SetPen(wxPen(win->GetForegroundColour())); | |
106a7999 | 604 | dc.DrawPolygon(WXSIZEOF(pt), pt, rect.x, rect.y); |
f33cef9f VZ |
605 | } |
606 | ||
784d2408 | 607 | void |
90b903c2 WS |
608 | wxRendererGeneric::DrawCheckBox(wxWindow *WXUNUSED(win), |
609 | wxDC& dc, | |
610 | const wxRect& rect, | |
611 | int flags) | |
862d8041 | 612 | { |
3061e2fb | 613 | dc.SetPen(*(flags & wxCONTROL_DISABLED ? wxGREY_PEN : wxBLACK_PEN)); |
862d8041 | 614 | dc.SetBrush( *wxTRANSPARENT_BRUSH ); |
3061e2fb VZ |
615 | dc.DrawRectangle(rect); |
616 | ||
617 | if ( flags & wxCONTROL_CHECKED ) | |
862d8041 | 618 | { |
3061e2fb | 619 | dc.DrawCheckMark(rect.Deflate(2, 2)); |
862d8041 RR |
620 | } |
621 | } | |
622 | ||
e8759560 VZ |
623 | wxSize wxRendererGeneric::GetCheckBoxSize(wxWindow *WXUNUSED(win)) |
624 | { | |
625 | return wxSize(16, 16); | |
626 | } | |
627 | ||
2209baae RR |
628 | void |
629 | wxRendererGeneric::DrawPushButton(wxWindow *win, | |
630 | wxDC& dc, | |
631 | const wxRect& rect, | |
632 | int flags) | |
633 | { | |
634 | // Don't try anything too fancy. It'll just turn out looking | |
635 | // out-of-place on most platforms. | |
636 | wxColour bgCol = flags & wxCONTROL_DISABLED ? | |
637 | wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE) : | |
638 | win->GetBackgroundColour(); | |
639 | dc.SetBrush(wxBrush(bgCol)); | |
640 | dc.SetPen(wxPen(bgCol)); | |
641 | dc.DrawRectangle(rect); | |
642 | } | |
643 | ||
784d2408 | 644 | void |
ce0cf2b8 RR |
645 | #ifdef __WXMAC__ |
646 | wxRendererGeneric::DrawItemSelectionRect(wxWindow * win, | |
647 | wxDC& dc, | |
648 | const wxRect& rect, | |
649 | int flags) | |
650 | #else | |
784d2408 VZ |
651 | wxRendererGeneric::DrawItemSelectionRect(wxWindow * WXUNUSED(win), |
652 | wxDC& dc, | |
653 | const wxRect& rect, | |
654 | int flags) | |
ce0cf2b8 | 655 | #endif |
daebb44c | 656 | { |
784d2408 VZ |
657 | wxBrush brush; |
658 | if ( flags & wxCONTROL_SELECTED ) | |
daebb44c | 659 | { |
784d2408 | 660 | if ( flags & wxCONTROL_FOCUSED ) |
daebb44c | 661 | { |
784d2408 | 662 | brush = wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT)); |
daebb44c | 663 | } |
784d2408 | 664 | else // !focused |
daebb44c | 665 | { |
784d2408 | 666 | brush = wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNSHADOW)); |
daebb44c RR |
667 | } |
668 | } | |
784d2408 | 669 | else // !selected |
daebb44c | 670 | { |
784d2408 | 671 | brush = *wxTRANSPARENT_BRUSH; |
daebb44c | 672 | } |
784d2408 VZ |
673 | |
674 | dc.SetBrush(brush); | |
ce0cf2b8 | 675 | if ((flags & wxCONTROL_CURRENT) && (flags & wxCONTROL_FOCUSED) |
530a427a | 676 | #if defined( __WXMAC__ ) && !defined(__WXUNIVERSAL__) && wxOSX_USE_CARBON |
ce0cf2b8 RR |
677 | && IsControlActive( (ControlRef)win->GetHandle() ) |
678 | #endif | |
679 | ) | |
680 | dc.SetPen( *wxBLACK_PEN ); | |
681 | else | |
682 | dc.SetPen( *wxTRANSPARENT_PEN ); | |
784d2408 VZ |
683 | |
684 | dc.DrawRectangle( rect ); | |
daebb44c RR |
685 | } |
686 | ||
6d789987 JS |
687 | void |
688 | wxRendererGeneric::DrawFocusRect(wxWindow* WXUNUSED(win), wxDC& dc, const wxRect& rect, int WXUNUSED(flags)) | |
689 | { | |
690 | // draw the pixels manually because the "dots" in wxPen with wxDOT style | |
691 | // may be short traits and not really dots | |
692 | // | |
693 | // note that to behave in the same manner as DrawRect(), we must exclude | |
694 | // the bottom and right borders from the rectangle | |
695 | wxCoord x1 = rect.GetLeft(), | |
696 | y1 = rect.GetTop(), | |
697 | x2 = rect.GetRight(), | |
698 | y2 = rect.GetBottom(); | |
699 | ||
700 | dc.SetPen(m_penBlack); | |
701 | ||
e2125bdc JS |
702 | #ifdef __WXMAC__ |
703 | dc.SetLogicalFunction(wxCOPY); | |
704 | #else | |
6d789987 JS |
705 | // this seems to be closer than what Windows does than wxINVERT although |
706 | // I'm still not sure if it's correct | |
707 | dc.SetLogicalFunction(wxAND_REVERSE); | |
e2125bdc | 708 | #endif |
6d789987 JS |
709 | |
710 | wxCoord z; | |
711 | for ( z = x1 + 1; z < x2; z += 2 ) | |
712 | dc.DrawPoint(z, rect.GetTop()); | |
713 | ||
714 | wxCoord shift = z == x2 ? 0 : 1; | |
715 | for ( z = y1 + shift; z < y2; z += 2 ) | |
716 | dc.DrawPoint(x2, z); | |
717 | ||
718 | shift = z == y2 ? 0 : 1; | |
719 | for ( z = x2 - shift; z > x1; z -= 2 ) | |
720 | dc.DrawPoint(z, y2); | |
721 | ||
722 | shift = z == x1 ? 0 : 1; | |
723 | for ( z = y2 - shift; z > y1; z -= 2 ) | |
724 | dc.DrawPoint(x1, z); | |
725 | ||
726 | dc.SetLogicalFunction(wxCOPY); | |
727 | } | |
daebb44c | 728 | |
f33cef9f | 729 | // ---------------------------------------------------------------------------- |
0872a451 | 730 | // A module to allow cleanup of generic renderer. |
f33cef9f VZ |
731 | // ---------------------------------------------------------------------------- |
732 | ||
0872a451 JS |
733 | class wxGenericRendererModule: public wxModule |
734 | { | |
735 | DECLARE_DYNAMIC_CLASS(wxGenericRendererModule) | |
736 | public: | |
737 | wxGenericRendererModule() {} | |
47b378bd VS |
738 | bool OnInit() { return true; } |
739 | void OnExit() { wxRendererGeneric::Cleanup(); } | |
0872a451 JS |
740 | }; |
741 | ||
742 | IMPLEMENT_DYNAMIC_CLASS(wxGenericRendererModule, wxModule) |