Don't change the current pen and brush in DrawHeaderButtonContents().
[wxWidgets.git] / src / generic / renderg.cpp
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 // License: wxWindows license
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 #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 void DrawTreeItemButton(wxWindow *win,
70 wxDC& dc,
71 const wxRect& rect,
72 int flags = 0);
73
74 virtual void DrawSplitterBorder(wxWindow *win,
75 wxDC& dc,
76 const wxRect& rect,
77 int flags = 0);
78
79 virtual void DrawSplitterSash(wxWindow *win,
80 wxDC& dc,
81 const wxSize& size,
82 wxCoord position,
83 wxOrientation orient,
84 int flags = 0);
85
86 virtual void DrawComboBoxDropButton(wxWindow *win,
87 wxDC& dc,
88 const wxRect& rect,
89 int flags = 0);
90
91 virtual void DrawDropArrow(wxWindow *win,
92 wxDC& dc,
93 const wxRect& rect,
94 int flags = 0);
95
96 virtual void DrawCheckBox(wxWindow *win,
97 wxDC& dc,
98 const wxRect& rect,
99 int flags = 0);
100
101 virtual wxSize GetCheckBoxSize(wxWindow *win);
102
103 virtual void DrawPushButton(wxWindow *win,
104 wxDC& dc,
105 const wxRect& rect,
106 int flags = 0);
107
108 virtual void DrawItemSelectionRect(wxWindow *win,
109 wxDC& dc,
110 const wxRect& rect,
111 int flags = 0);
112
113 virtual void DrawFocusRect(wxWindow* win, wxDC& dc, const wxRect& rect, int flags = 0);
114
115 virtual void DrawChoice(wxWindow* win, wxDC& dc, const wxRect& rect, int flags=0);
116
117 virtual void DrawComboBox(wxWindow* win, wxDC& dc, const wxRect& rect, int flags=0);
118
119 virtual void DrawTextCtrl(wxWindow* win, wxDC& dc, const wxRect& rect, int flags=0);
120
121 virtual void DrawRadioBitmap(wxWindow* win, wxDC& dc, const wxRect& rect, int flags=0);
122
123 #ifdef wxHAS_DRAW_TITLE_BAR_BITMAP
124 virtual void DrawTitleBarBitmap(wxWindow *win,
125 wxDC& dc,
126 const wxRect& rect,
127 wxTitleBarButton button,
128 int flags = 0);
129 #endif // wxHAS_DRAW_TITLE_BAR_BITMAP
130
131 virtual wxSplitterRenderParams GetSplitterParams(const wxWindow *win);
132
133 virtual wxRendererVersion GetVersion() const
134 {
135 return wxRendererVersion(wxRendererVersion::Current_Version,
136 wxRendererVersion::Current_Age);
137 }
138
139
140 // Cleanup by deleting standard renderer
141 static void Cleanup();
142
143 // Get the generic object
144 static wxRendererGeneric* DoGetGeneric();
145
146 protected:
147 // draw the rectange using the first pen for the left and top sides and
148 // the second one for the bottom and right ones
149 void DrawShadedRect(wxDC& dc, wxRect *rect,
150 const wxPen& pen1, const wxPen& pen2);
151
152 // the standard pens
153 wxPen m_penBlack,
154 m_penDarkGrey,
155 m_penLightGrey,
156 m_penHighlight;
157
158 static wxRendererGeneric* sm_rendererGeneric;
159 };
160
161 // ============================================================================
162 // wxRendererGeneric implementation
163 // ============================================================================
164
165 // Get the generic object
166 wxRendererGeneric* wxRendererGeneric::DoGetGeneric()
167 {
168 if (!sm_rendererGeneric)
169 sm_rendererGeneric = new wxRendererGeneric;
170 return sm_rendererGeneric;
171 }
172
173 // ----------------------------------------------------------------------------
174 // wxRendererGeneric creation
175 // ----------------------------------------------------------------------------
176
177 /* static */
178 wxRendererNative& wxRendererNative::GetGeneric()
179 {
180 return * wxRendererGeneric::DoGetGeneric();
181 }
182
183 void wxRendererGeneric::Cleanup()
184 {
185 if (sm_rendererGeneric)
186 delete sm_rendererGeneric;
187
188 sm_rendererGeneric = NULL;
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 dc.DrawPolygon( 3, triPt, ar.x, ar.y);
332 }
333 labelWidth += arrowSpace;
334
335 const int margin = 5; // number of pixels to reserve on either side of the label
336 int bmpWidth = 0;
337
338 if ( params && params->m_labelBitmap.Ok() )
339 bmpWidth = params->m_labelBitmap.GetWidth() + 2;
340
341 labelWidth += bmpWidth + 2*margin;
342
343 // draw the bitmap if there is one
344 if ( params && params->m_labelBitmap.Ok() )
345 {
346 int w, h, x, y;
347 w = params->m_labelBitmap.GetWidth();
348 h = params->m_labelBitmap.GetHeight();
349
350 x = margin + rect.x;
351 y = rect.y + wxMax(1, (rect.height - h) / 2);
352
353 if (params->m_labelText.empty())
354 {
355 // use the alignment flags
356 switch (params->m_labelAlignment)
357 {
358 default:
359 case wxALIGN_LEFT:
360 x = rect.x + margin;
361 break;
362 case wxALIGN_CENTER:
363 x = rect.x + wxMax(1, (rect.width - arrowSpace - w)/2);
364 break;
365 case wxALIGN_RIGHT:
366 x = rect.x + wxMax(1, rect.width - arrowSpace - margin - w);
367 break;
368 }
369 }
370 dc.DrawBitmap(params->m_labelBitmap, x, y, true);
371 }
372
373 // Draw a label if one is given
374 if ( params && !params->m_labelText.empty() )
375 {
376 wxFont font = params->m_labelFont.Ok() ?
377 params->m_labelFont : win->GetFont();
378 wxColour clr = params->m_labelColour.Ok() ?
379 params->m_labelColour : win->GetForegroundColour();
380
381 wxString label( params->m_labelText );
382
383 dc.SetFont(font);
384 dc.SetTextForeground(clr);
385 dc.SetBackgroundMode(wxBRUSHSTYLE_TRANSPARENT);
386
387 int tw, th, td, x, y;
388 dc.GetTextExtent( label, &tw, &th, &td);
389 labelWidth += tw;
390 y = rect.y + wxMax(0, (rect.height - (th+td)) / 2);
391
392 // truncate and add an ellipsis (...) if the text is too wide.
393 int targetWidth = rect.width - arrowSpace - bmpWidth - 2*margin;
394 if ( tw > targetWidth )
395 {
396 int ellipsisWidth;
397 dc.GetTextExtent( wxT("..."), &ellipsisWidth, NULL);
398 do {
399 label.Truncate( label.length() - 1 );
400 dc.GetTextExtent( label, &tw, &th);
401 } while (tw + ellipsisWidth > targetWidth && label.length() );
402 label.append( wxT("...") );
403 tw += ellipsisWidth;
404 }
405
406 switch (params->m_labelAlignment)
407 {
408 default:
409 case wxALIGN_LEFT:
410 x = rect.x + margin;
411 break;
412 case wxALIGN_CENTER:
413 x = rect.x + wxMax(0, (rect.width - arrowSpace - tw - bmpWidth)/2);
414 break;
415 case wxALIGN_RIGHT:
416 x = rect.x + wxMax(0, rect.width - arrowSpace - margin - tw - bmpWidth);
417 break;
418 }
419
420 dc.DrawText(label, x + bmpWidth, y);
421 }
422 return labelWidth;
423 }
424
425
426 int wxRendererGeneric::GetHeaderButtonHeight(wxWindow *win)
427 {
428 // Copied and adapted from src/generic/listctrl.cpp
429 const int HEADER_OFFSET_Y = 1;
430 const int EXTRA_HEIGHT = 4;
431
432 int w=0, h=14, d=0;
433 if (win)
434 win->GetTextExtent(wxT("Hg"), &w, &h, &d);
435
436 return h + d + 2 * HEADER_OFFSET_Y + EXTRA_HEIGHT;
437 }
438
439
440 // draw the plus or minus sign
441 void
442 wxRendererGeneric::DrawTreeItemButton(wxWindow * WXUNUSED(win),
443 wxDC& dc,
444 const wxRect& rect,
445 int flags)
446 {
447 // store settings
448 wxDCPenChanger penChanger(dc, *wxGREY_PEN);
449 wxDCBrushChanger brushChanger(dc, *wxWHITE_BRUSH);
450
451 dc.DrawRectangle(rect);
452
453 // black lines
454 const wxCoord xMiddle = rect.x + rect.width/2;
455 const wxCoord yMiddle = rect.y + rect.height/2;
456
457 // half of the length of the horz lines in "-" and "+"
458 const wxCoord halfWidth = rect.width/2 - 2;
459 dc.SetPen(*wxBLACK_PEN);
460 dc.DrawLine(xMiddle - halfWidth, yMiddle,
461 xMiddle + halfWidth + 1, yMiddle);
462
463 if ( !(flags & wxCONTROL_EXPANDED) )
464 {
465 // turn "-" into "+"
466 const wxCoord halfHeight = rect.height/2 - 2;
467 dc.DrawLine(xMiddle, yMiddle - halfHeight,
468 xMiddle, yMiddle + halfHeight + 1);
469 }
470 }
471
472 // ----------------------------------------------------------------------------
473 // sash drawing
474 // ----------------------------------------------------------------------------
475
476 wxSplitterRenderParams
477 wxRendererGeneric::GetSplitterParams(const wxWindow *win)
478 {
479 // see below
480 wxCoord sashWidth,
481 border;
482
483 if ( win->HasFlag(wxSP_3DSASH) )
484 sashWidth = 7;
485 else if ( win->HasFlag(wxSP_NOSASH) )
486 sashWidth = 0;
487 else // no 3D effect
488 sashWidth = 3;
489
490 if ( win->HasFlag(wxSP_3DBORDER) )
491 border = 2;
492 else // no 3D effect
493 border = 0;
494
495 return wxSplitterRenderParams(sashWidth, border, false);
496 }
497
498 void
499 wxRendererGeneric::DrawSplitterBorder(wxWindow *win,
500 wxDC& dc,
501 const wxRect& rectOrig,
502 int WXUNUSED(falgs))
503 {
504 if ( win->HasFlag(wxSP_3DBORDER) )
505 {
506 wxRect rect = rectOrig;
507 DrawShadedRect(dc, &rect, m_penDarkGrey, m_penHighlight);
508 DrawShadedRect(dc, &rect, m_penBlack, m_penLightGrey);
509 }
510 }
511
512 void
513 wxRendererGeneric::DrawSplitterSash(wxWindow *win,
514 wxDC& dcReal,
515 const wxSize& sizeReal,
516 wxCoord position,
517 wxOrientation orient,
518 int WXUNUSED(flags))
519 {
520 // to avoid duplicating the same code for horizontal and vertical sashes,
521 // simply mirror the DC instead if needed (i.e. if horz splitter)
522 wxMirrorDC dc(dcReal, orient != wxVERTICAL);
523 wxSize size = dc.Reflect(sizeReal);
524
525
526 // we draw a Win32-like grey sash with possible 3D border here:
527 //
528 // ---- this is position
529 // /
530 // v
531 // dWGGGDd
532 // GWGGGDB
533 // GWGGGDB where G is light grey (face)
534 // GWGGGDB W white (light)
535 // GWGGGDB D dark grey (shadow)
536 // GWGGGDB B black (dark shadow)
537 // GWGGGDB
538 // GWGGGDB and lower letters are our border (already drawn)
539 // GWGGGDB
540 // wWGGGDd
541 //
542 // only the middle 3 columns are drawn unless wxSP_3D is specified
543
544 const wxCoord h = size.y;
545 wxCoord offset = 0;
546
547 // If we're drawing the border, draw the sash 3d lines shorter
548 if ( win->HasFlag(wxSP_3DBORDER) )
549 {
550 offset = 1;
551 }
552
553 dc.SetPen(*wxTRANSPARENT_PEN);
554 dc.SetBrush(wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE)));
555
556 if ( win->HasFlag(wxSP_3DSASH) )
557 {
558 // Draw the 3D sash
559 dc.DrawRectangle(position + 2, 0, 3, h);
560
561 dc.SetPen(m_penLightGrey);
562 dc.DrawLine(position, offset, position, h - offset);
563
564 dc.SetPen(m_penHighlight);
565 dc.DrawLine(position + 1, 0, position + 1, h);
566
567 dc.SetPen(m_penDarkGrey);
568 dc.DrawLine(position + 5, 0, position + 5, h);
569
570 dc.SetPen(m_penBlack);
571 dc.DrawLine(position + 6, offset, position + 6, h - offset);
572 }
573 else
574 {
575 // Draw a flat sash
576 dc.DrawRectangle(position, 0, 3, h);
577 }
578 }
579
580 // ----------------------------------------------------------------------------
581 // button drawing
582 // ----------------------------------------------------------------------------
583
584 void
585 wxRendererGeneric::DrawComboBoxDropButton(wxWindow *win,
586 wxDC& dc,
587 const wxRect& rect,
588 int flags)
589 {
590 DrawPushButton(win,dc,rect,flags);
591 DrawDropArrow(win,dc,rect,flags);
592 }
593
594 void
595 wxRendererGeneric::DrawDropArrow(wxWindow *win,
596 wxDC& dc,
597 const wxRect& rect,
598 int WXUNUSED(flags))
599 {
600 // This generic implementation should be good
601 // enough for Windows platforms (including XP).
602
603 int arrowHalf = rect.width/5;
604 int rectMid = rect.width / 2;
605 int arrowTopY = (rect.height/2) - (arrowHalf/2);
606
607 // This should always result in arrow with odd width.
608 wxPoint pt[] =
609 {
610 wxPoint(rectMid - arrowHalf, arrowTopY),
611 wxPoint(rectMid + arrowHalf, arrowTopY),
612 wxPoint(rectMid, arrowTopY + arrowHalf)
613 };
614 dc.SetBrush(wxBrush(win->GetForegroundColour()));
615 dc.SetPen(wxPen(win->GetForegroundColour()));
616 dc.DrawPolygon(WXSIZEOF(pt), pt, rect.x, rect.y);
617 }
618
619 void
620 wxRendererGeneric::DrawCheckBox(wxWindow *WXUNUSED(win),
621 wxDC& dc,
622 const wxRect& rect,
623 int flags)
624 {
625 dc.SetPen(*(flags & wxCONTROL_DISABLED ? wxGREY_PEN : wxBLACK_PEN));
626 dc.SetBrush( *wxTRANSPARENT_BRUSH );
627 dc.DrawRectangle(rect);
628
629 if ( flags & wxCONTROL_CHECKED )
630 {
631 dc.DrawCheckMark(rect.Deflate(2, 2));
632 }
633 }
634
635 wxSize wxRendererGeneric::GetCheckBoxSize(wxWindow *WXUNUSED(win))
636 {
637 return wxSize(16, 16);
638 }
639
640 void
641 wxRendererGeneric::DrawPushButton(wxWindow *win,
642 wxDC& dc,
643 const wxRect& rect,
644 int flags)
645 {
646 // Don't try anything too fancy. It'll just turn out looking
647 // out-of-place on most platforms.
648 wxColour bgCol = flags & wxCONTROL_DISABLED ?
649 wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE) :
650 win->GetBackgroundColour();
651 dc.SetBrush(wxBrush(bgCol));
652 dc.SetPen(wxPen(bgCol));
653 dc.DrawRectangle(rect);
654 }
655
656 void
657 wxRendererGeneric::DrawItemSelectionRect(wxWindow * win,
658 wxDC& dc,
659 const wxRect& rect,
660 int flags)
661 {
662 wxBrush brush;
663 if ( flags & wxCONTROL_SELECTED )
664 {
665 if ( flags & wxCONTROL_FOCUSED )
666 {
667 brush = wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT));
668 }
669 else // !focused
670 {
671 brush = wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNSHADOW));
672 }
673 }
674 else // !selected
675 {
676 brush = *wxTRANSPARENT_BRUSH;
677 }
678
679 dc.SetBrush(brush);
680 if ((flags & wxCONTROL_CURRENT) && (flags & wxCONTROL_FOCUSED)
681 #if defined( __WXMAC__ ) && !defined(__WXUNIVERSAL__) && wxOSX_USE_CARBON
682 && IsControlActive( (ControlRef)win->GetHandle() )
683 #endif
684 )
685 dc.SetPen( *wxBLACK_PEN );
686 else
687 dc.SetPen( *wxTRANSPARENT_PEN );
688
689 dc.DrawRectangle( rect );
690
691 // it's unused everywhere except in wxOSX/Carbon
692 wxUnusedVar(win);
693 }
694
695 void
696 wxRendererGeneric::DrawFocusRect(wxWindow* WXUNUSED(win), wxDC& dc, const wxRect& rect, int WXUNUSED(flags))
697 {
698 // draw the pixels manually because the "dots" in wxPen with wxDOT style
699 // may be short traits and not really dots
700 //
701 // note that to behave in the same manner as DrawRect(), we must exclude
702 // the bottom and right borders from the rectangle
703 wxCoord x1 = rect.GetLeft(),
704 y1 = rect.GetTop(),
705 x2 = rect.GetRight(),
706 y2 = rect.GetBottom();
707
708 dc.SetPen(m_penBlack);
709
710 #ifdef __WXMAC__
711 dc.SetLogicalFunction(wxCOPY);
712 #else
713 // this seems to be closer than what Windows does than wxINVERT although
714 // I'm still not sure if it's correct
715 dc.SetLogicalFunction(wxAND_REVERSE);
716 #endif
717
718 wxCoord z;
719 for ( z = x1 + 1; z < x2; z += 2 )
720 dc.DrawPoint(z, rect.GetTop());
721
722 wxCoord shift = z == x2 ? 0 : 1;
723 for ( z = y1 + shift; z < y2; z += 2 )
724 dc.DrawPoint(x2, z);
725
726 shift = z == y2 ? 0 : 1;
727 for ( z = x2 - shift; z > x1; z -= 2 )
728 dc.DrawPoint(z, y2);
729
730 shift = z == x1 ? 0 : 1;
731 for ( z = y2 - shift; z > y1; z -= 2 )
732 dc.DrawPoint(x1, z);
733
734 dc.SetLogicalFunction(wxCOPY);
735 }
736
737 void wxRendererGeneric::DrawChoice(wxWindow* WXUNUSED(win), wxDC& WXUNUSED(dc),
738 const wxRect& WXUNUSED(rect), int WXUNUSED(flags))
739 {
740 wxFAIL_MSG("UNIMPLEMENTED: wxRendererGeneric::DrawChoice");
741 }
742
743 void wxRendererGeneric::DrawComboBox(wxWindow* WXUNUSED(win), wxDC& WXUNUSED(dc),
744 const wxRect& WXUNUSED(rect), int WXUNUSED(flags))
745 {
746 wxFAIL_MSG("UNIMPLEMENTED: wxRendererGeneric::DrawComboBox");
747 }
748
749 void wxRendererGeneric::DrawRadioBitmap(wxWindow* WXUNUSED(win), wxDC& WXUNUSED(dc),
750 const wxRect& WXUNUSED(rect), int WXUNUSED(flags))
751 {
752 wxFAIL_MSG("UNIMPLEMENTED: wxRendererGeneric::DrawRadioBitmap");
753 }
754
755 void wxRendererGeneric::DrawTextCtrl(wxWindow* WXUNUSED(win), wxDC& WXUNUSED(dc),
756 const wxRect& WXUNUSED(rect), int WXUNUSED(flags))
757 {
758 wxFAIL_MSG("UNIMPLEMENTED: wxRendererGeneric::DrawTextCtrl");
759 }
760
761 #ifdef wxHAS_DRAW_TITLE_BAR_BITMAP
762
763 void wxRendererGeneric::DrawTitleBarBitmap(wxWindow * WXUNUSED(win),
764 wxDC& WXUNUSED(dc),
765 const wxRect& WXUNUSED(rect),
766 wxTitleBarButton WXUNUSED(button),
767 int WXUNUSED(flags))
768 {
769 // no need to fail here, if wxHAS_DRAW_TITLE_BAR_BITMAP is defined this
770 // will be implemented in the native renderer and this version is never
771 // going to be used -- but we still need to define it to allow
772 // instantiation of this class (which would have been pure virtual
773 // otherwise)
774 }
775
776 #endif // wxHAS_DRAW_TITLE_BAR_BITMAP
777
778
779 // ----------------------------------------------------------------------------
780 // A module to allow cleanup of generic renderer.
781 // ----------------------------------------------------------------------------
782
783 class wxGenericRendererModule: public wxModule
784 {
785 DECLARE_DYNAMIC_CLASS(wxGenericRendererModule)
786 public:
787 wxGenericRendererModule() {}
788 bool OnInit() { return true; }
789 void OnExit() { wxRendererGeneric::Cleanup(); }
790 };
791
792 IMPLEMENT_DYNAMIC_CLASS(wxGenericRendererModule, wxModule)