Clip drawing in wxRendererGeneric::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 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
451 // draw the plus or minus sign
452 void
453 wxRendererGeneric::DrawTreeItemButton(wxWindow * WXUNUSED(win),
454 wxDC& dc,
455 const wxRect& rect,
456 int flags)
457 {
458 // store settings
459 wxDCPenChanger penChanger(dc, *wxGREY_PEN);
460 wxDCBrushChanger brushChanger(dc, *wxWHITE_BRUSH);
461
462 dc.DrawRectangle(rect);
463
464 // black lines
465 const wxCoord xMiddle = rect.x + rect.width/2;
466 const wxCoord yMiddle = rect.y + rect.height/2;
467
468 // half of the length of the horz lines in "-" and "+"
469 const wxCoord halfWidth = rect.width/2 - 2;
470 dc.SetPen(*wxBLACK_PEN);
471 dc.DrawLine(xMiddle - halfWidth, yMiddle,
472 xMiddle + halfWidth + 1, yMiddle);
473
474 if ( !(flags & wxCONTROL_EXPANDED) )
475 {
476 // turn "-" into "+"
477 const wxCoord halfHeight = rect.height/2 - 2;
478 dc.DrawLine(xMiddle, yMiddle - halfHeight,
479 xMiddle, yMiddle + halfHeight + 1);
480 }
481 }
482
483 // ----------------------------------------------------------------------------
484 // sash drawing
485 // ----------------------------------------------------------------------------
486
487 wxSplitterRenderParams
488 wxRendererGeneric::GetSplitterParams(const wxWindow *win)
489 {
490 // see below
491 wxCoord sashWidth,
492 border;
493
494 if ( win->HasFlag(wxSP_3DSASH) )
495 sashWidth = 7;
496 else if ( win->HasFlag(wxSP_NOSASH) )
497 sashWidth = 0;
498 else // no 3D effect
499 sashWidth = 3;
500
501 if ( win->HasFlag(wxSP_3DBORDER) )
502 border = 2;
503 else // no 3D effect
504 border = 0;
505
506 return wxSplitterRenderParams(sashWidth, border, false);
507 }
508
509 void
510 wxRendererGeneric::DrawSplitterBorder(wxWindow *win,
511 wxDC& dc,
512 const wxRect& rectOrig,
513 int WXUNUSED(falgs))
514 {
515 if ( win->HasFlag(wxSP_3DBORDER) )
516 {
517 wxRect rect = rectOrig;
518 DrawShadedRect(dc, &rect, m_penDarkGrey, m_penHighlight);
519 DrawShadedRect(dc, &rect, m_penBlack, m_penLightGrey);
520 }
521 }
522
523 void
524 wxRendererGeneric::DrawSplitterSash(wxWindow *win,
525 wxDC& dcReal,
526 const wxSize& sizeReal,
527 wxCoord position,
528 wxOrientation orient,
529 int WXUNUSED(flags))
530 {
531 // to avoid duplicating the same code for horizontal and vertical sashes,
532 // simply mirror the DC instead if needed (i.e. if horz splitter)
533 wxMirrorDC dc(dcReal, orient != wxVERTICAL);
534 wxSize size = dc.Reflect(sizeReal);
535
536
537 // we draw a Win32-like grey sash with possible 3D border here:
538 //
539 // ---- this is position
540 // /
541 // v
542 // dWGGGDd
543 // GWGGGDB
544 // GWGGGDB where G is light grey (face)
545 // GWGGGDB W white (light)
546 // GWGGGDB D dark grey (shadow)
547 // GWGGGDB B black (dark shadow)
548 // GWGGGDB
549 // GWGGGDB and lower letters are our border (already drawn)
550 // GWGGGDB
551 // wWGGGDd
552 //
553 // only the middle 3 columns are drawn unless wxSP_3D is specified
554
555 const wxCoord h = size.y;
556 wxCoord offset = 0;
557
558 // If we're drawing the border, draw the sash 3d lines shorter
559 if ( win->HasFlag(wxSP_3DBORDER) )
560 {
561 offset = 1;
562 }
563
564 dc.SetPen(*wxTRANSPARENT_PEN);
565 dc.SetBrush(wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE)));
566
567 if ( win->HasFlag(wxSP_3DSASH) )
568 {
569 // Draw the 3D sash
570 dc.DrawRectangle(position + 2, 0, 3, h);
571
572 dc.SetPen(m_penLightGrey);
573 dc.DrawLine(position, offset, position, h - offset);
574
575 dc.SetPen(m_penHighlight);
576 dc.DrawLine(position + 1, 0, position + 1, h);
577
578 dc.SetPen(m_penDarkGrey);
579 dc.DrawLine(position + 5, 0, position + 5, h);
580
581 dc.SetPen(m_penBlack);
582 dc.DrawLine(position + 6, offset, position + 6, h - offset);
583 }
584 else
585 {
586 // Draw a flat sash
587 dc.DrawRectangle(position, 0, 3, h);
588 }
589 }
590
591 // ----------------------------------------------------------------------------
592 // button drawing
593 // ----------------------------------------------------------------------------
594
595 void
596 wxRendererGeneric::DrawComboBoxDropButton(wxWindow *win,
597 wxDC& dc,
598 const wxRect& rect,
599 int flags)
600 {
601 DrawPushButton(win,dc,rect,flags);
602 DrawDropArrow(win,dc,rect,flags);
603 }
604
605 void
606 wxRendererGeneric::DrawDropArrow(wxWindow *win,
607 wxDC& dc,
608 const wxRect& rect,
609 int WXUNUSED(flags))
610 {
611 // This generic implementation should be good
612 // enough for Windows platforms (including XP).
613
614 int arrowHalf = rect.width/5;
615 int rectMid = rect.width / 2;
616 int arrowTopY = (rect.height/2) - (arrowHalf/2);
617
618 // This should always result in arrow with odd width.
619 wxPoint pt[] =
620 {
621 wxPoint(rectMid - arrowHalf, arrowTopY),
622 wxPoint(rectMid + arrowHalf, arrowTopY),
623 wxPoint(rectMid, arrowTopY + arrowHalf)
624 };
625 dc.SetBrush(wxBrush(win->GetForegroundColour()));
626 dc.SetPen(wxPen(win->GetForegroundColour()));
627 dc.DrawPolygon(WXSIZEOF(pt), pt, rect.x, rect.y);
628 }
629
630 void
631 wxRendererGeneric::DrawCheckBox(wxWindow *WXUNUSED(win),
632 wxDC& dc,
633 const wxRect& rect,
634 int flags)
635 {
636 dc.SetPen(*(flags & wxCONTROL_DISABLED ? wxGREY_PEN : wxBLACK_PEN));
637 dc.SetBrush( *wxTRANSPARENT_BRUSH );
638 dc.DrawRectangle(rect);
639
640 if ( flags & wxCONTROL_CHECKED )
641 {
642 dc.DrawCheckMark(rect.Deflate(2, 2));
643 }
644 }
645
646 wxSize wxRendererGeneric::GetCheckBoxSize(wxWindow *WXUNUSED(win))
647 {
648 return wxSize(16, 16);
649 }
650
651 void
652 wxRendererGeneric::DrawPushButton(wxWindow *win,
653 wxDC& dc,
654 const wxRect& rect,
655 int flags)
656 {
657 // Don't try anything too fancy. It'll just turn out looking
658 // out-of-place on most platforms.
659 wxColour bgCol = flags & wxCONTROL_DISABLED ?
660 wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE) :
661 win->GetBackgroundColour();
662 dc.SetBrush(wxBrush(bgCol));
663 dc.SetPen(wxPen(bgCol));
664 dc.DrawRectangle(rect);
665 }
666
667 void
668 wxRendererGeneric::DrawItemSelectionRect(wxWindow * win,
669 wxDC& dc,
670 const wxRect& rect,
671 int flags)
672 {
673 wxBrush brush;
674 if ( flags & wxCONTROL_SELECTED )
675 {
676 if ( flags & wxCONTROL_FOCUSED )
677 {
678 brush = wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT));
679 }
680 else // !focused
681 {
682 brush = wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNSHADOW));
683 }
684 }
685 else // !selected
686 {
687 brush = *wxTRANSPARENT_BRUSH;
688 }
689
690 dc.SetBrush(brush);
691 if ((flags & wxCONTROL_CURRENT) && (flags & wxCONTROL_FOCUSED)
692 #if defined( __WXMAC__ ) && !defined(__WXUNIVERSAL__) && wxOSX_USE_CARBON
693 && IsControlActive( (ControlRef)win->GetHandle() )
694 #endif
695 )
696 dc.SetPen( *wxBLACK_PEN );
697 else
698 dc.SetPen( *wxTRANSPARENT_PEN );
699
700 dc.DrawRectangle( rect );
701
702 // it's unused everywhere except in wxOSX/Carbon
703 wxUnusedVar(win);
704 }
705
706 void
707 wxRendererGeneric::DrawFocusRect(wxWindow* WXUNUSED(win), wxDC& dc, const wxRect& rect, int WXUNUSED(flags))
708 {
709 // draw the pixels manually because the "dots" in wxPen with wxDOT style
710 // may be short traits and not really dots
711 //
712 // note that to behave in the same manner as DrawRect(), we must exclude
713 // the bottom and right borders from the rectangle
714 wxCoord x1 = rect.GetLeft(),
715 y1 = rect.GetTop(),
716 x2 = rect.GetRight(),
717 y2 = rect.GetBottom();
718
719 dc.SetPen(m_penBlack);
720
721 #ifdef __WXMAC__
722 dc.SetLogicalFunction(wxCOPY);
723 #else
724 // this seems to be closer than what Windows does than wxINVERT although
725 // I'm still not sure if it's correct
726 dc.SetLogicalFunction(wxAND_REVERSE);
727 #endif
728
729 wxCoord z;
730 for ( z = x1 + 1; z < x2; z += 2 )
731 dc.DrawPoint(z, rect.GetTop());
732
733 wxCoord shift = z == x2 ? 0 : 1;
734 for ( z = y1 + shift; z < y2; z += 2 )
735 dc.DrawPoint(x2, z);
736
737 shift = z == y2 ? 0 : 1;
738 for ( z = x2 - shift; z > x1; z -= 2 )
739 dc.DrawPoint(z, y2);
740
741 shift = z == x1 ? 0 : 1;
742 for ( z = y2 - shift; z > y1; z -= 2 )
743 dc.DrawPoint(x1, z);
744
745 dc.SetLogicalFunction(wxCOPY);
746 }
747
748 void wxRendererGeneric::DrawChoice(wxWindow* WXUNUSED(win), wxDC& WXUNUSED(dc),
749 const wxRect& WXUNUSED(rect), int WXUNUSED(flags))
750 {
751 wxFAIL_MSG("UNIMPLEMENTED: wxRendererGeneric::DrawChoice");
752 }
753
754 void wxRendererGeneric::DrawComboBox(wxWindow* WXUNUSED(win), wxDC& WXUNUSED(dc),
755 const wxRect& WXUNUSED(rect), int WXUNUSED(flags))
756 {
757 wxFAIL_MSG("UNIMPLEMENTED: wxRendererGeneric::DrawComboBox");
758 }
759
760 void wxRendererGeneric::DrawRadioBitmap(wxWindow* WXUNUSED(win), wxDC& WXUNUSED(dc),
761 const wxRect& WXUNUSED(rect), int WXUNUSED(flags))
762 {
763 wxFAIL_MSG("UNIMPLEMENTED: wxRendererGeneric::DrawRadioBitmap");
764 }
765
766 void wxRendererGeneric::DrawTextCtrl(wxWindow* WXUNUSED(win), wxDC& WXUNUSED(dc),
767 const wxRect& WXUNUSED(rect), int WXUNUSED(flags))
768 {
769 wxFAIL_MSG("UNIMPLEMENTED: wxRendererGeneric::DrawTextCtrl");
770 }
771
772 #ifdef wxHAS_DRAW_TITLE_BAR_BITMAP
773
774 void wxRendererGeneric::DrawTitleBarBitmap(wxWindow * WXUNUSED(win),
775 wxDC& WXUNUSED(dc),
776 const wxRect& WXUNUSED(rect),
777 wxTitleBarButton WXUNUSED(button),
778 int WXUNUSED(flags))
779 {
780 // no need to fail here, if wxHAS_DRAW_TITLE_BAR_BITMAP is defined this
781 // will be implemented in the native renderer and this version is never
782 // going to be used -- but we still need to define it to allow
783 // instantiation of this class (which would have been pure virtual
784 // otherwise)
785 }
786
787 #endif // wxHAS_DRAW_TITLE_BAR_BITMAP
788
789
790 // ----------------------------------------------------------------------------
791 // A module to allow cleanup of generic renderer.
792 // ----------------------------------------------------------------------------
793
794 class wxGenericRendererModule: public wxModule
795 {
796 DECLARE_DYNAMIC_CLASS(wxGenericRendererModule)
797 public:
798 wxGenericRendererModule() {}
799 bool OnInit() { return true; }
800 void OnExit() { wxRendererGeneric::Cleanup(); }
801 };
802
803 IMPLEMENT_DYNAMIC_CLASS(wxGenericRendererModule, wxModule)