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