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