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