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