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