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