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