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