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