]> git.saurik.com Git - wxWidgets.git/blame - src/msw/renderer.cpp
Output the extracted number from wxString::ToXXX() even if it returns false.
[wxWidgets.git] / src / msw / renderer.cpp
CommitLineData
9c7f49f5 1///////////////////////////////////////////////////////////////////////////////
90b903c2 2// Name: src/msw/renderer.cpp
38c4cb6a 3// Purpose: implementation of wxRendererNative for Windows
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>
65571936 9// License: 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
27#ifndef WX_PRECOMP
28 #include "wx/string.h"
85b657c7
VS
29 #include "wx/window.h"
30 #include "wx/dc.h"
9eddec69 31 #include "wx/settings.h"
9c7f49f5
VZ
32#endif //WX_PRECOMP
33
51c42fc5 34#include "wx/scopeguard.h"
3c2544bb 35#include "wx/splitter.h"
9c7f49f5 36#include "wx/renderer.h"
03f01e63 37#include "wx/msw/private.h"
025f7d77 38#include "wx/msw/dc.h"
4614c8e5 39#include "wx/msw/uxtheme.h"
8b97949e 40
e4131985
KO
41#if wxUSE_GRAPHICS_CONTEXT
42// TODO remove this dependency (gdiplus needs the macros)
43#ifndef max
44#define max(a,b) (((a) > (b)) ? (a) : (b))
45#endif
46
47#ifndef min
48#define min(a,b) (((a) < (b)) ? (a) : (b))
49#endif
50
7280c828 51#include "wx/dcgraph.h"
e4131985
KO
52#include "gdiplus.h"
53using namespace Gdiplus;
7280c828 54#endif // wxUSE_GRAPHICS_CONTEXT
e4131985 55
7cf3223a
VZ
56// tmschema.h is in Win32 Platform SDK and might not be available with earlier
57// compilers
58#ifndef CP_DROPDOWNBUTTON
2209baae 59 #define BP_PUSHBUTTON 1
e4131985 60 #define BP_RADIOBUTTON 2
9f93b45e 61 #define BP_CHECKBOX 3
e4131985
KO
62 #define RBS_UNCHECKEDNORMAL 1
63 #define RBS_CHECKEDNORMAL (RBS_UNCHECKEDNORMAL + 4)
64 #define RBS_MIXEDNORMAL (RBS_CHECKEDNORMAL + 4)
9f93b45e
VZ
65 #define CBS_UNCHECKEDNORMAL 1
66 #define CBS_CHECKEDNORMAL (CBS_UNCHECKEDNORMAL + 4)
67 #define CBS_MIXEDNORMAL (CBS_CHECKEDNORMAL + 4)
68
2209baae
RR
69 #define PBS_NORMAL 1
70 #define PBS_HOT 2
71 #define PBS_PRESSED 3
72 #define PBS_DISABLED 4
73 #define PBS_DEFAULTED 5
74
7cf3223a
VZ
75 #define CP_DROPDOWNBUTTON 1
76
77 #define CBXS_NORMAL 1
78 #define CBXS_HOT 2
79 #define CBXS_PRESSED 3
80 #define CBXS_DISABLED 4
a9d9e2f2 81
9f93b45e
VZ
82 #define TVP_GLYPH 2
83
84 #define GLPS_CLOSED 1
a9d9e2f2
JS
85 #define GLPS_OPENED 2
86
87 #define HP_HEADERITEM 1
88
89 #define HIS_NORMAL 1
90 #define HIS_HOT 2
91 #define HIS_PRESSED 3
4b94ddc4
RD
92
93 #define TMT_HEIGHT 2417
94
95 #define HP_HEADERSORTARROW 4
96 #define HSAS_SORTEDUP 1
97 #define HSAS_SORTEDDOWN 2
e4131985
KO
98
99 #define EP_EDITTEXT 1
100 #define ETS_NORMAL 1
101 #define ETS_HOT 2
102 #define ETS_SELECTED 3
103 #define ETS_DISABLED 4
104 #define ETS_FOCUSED 5
105 #define ETS_READONLY 6
106 #define ETS_ASSIST 7
107 #define TMT_FILLCOLOR 3802
108 #define TMT_TEXTCOLOR 3803
109 #define TMT_BORDERCOLOR 3801
110 #define TMT_EDGEFILLCOLOR 3808
7cf3223a
VZ
111#endif
112
e4131985
KO
113
114// ----------------------------------------------------------------------------
115// If the DC is a wxGCDC then pull out the HDC from the GraphicsContext when
116// it is needed, and handle the Release when done.
117
118class GraphicsHDC
119{
120public:
121 GraphicsHDC(wxDC* dc)
122 {
123#if wxUSE_GRAPHICS_CONTEXT
124 m_graphics = NULL;
125 wxGCDC* gcdc = wxDynamicCast(dc, wxGCDC);
126 if (gcdc) {
127 m_graphics = (Graphics*)gcdc->GetGraphicsContext()->GetNativeContext();
128 m_hdc = m_graphics->GetHDC();
129 }
130 else
131#endif
97bd2a50 132 m_hdc = GetHdcOf(*((wxMSWDCImpl*)dc->GetImpl()));
e4131985
KO
133 }
134
135 ~GraphicsHDC()
136 {
137#if wxUSE_GRAPHICS_CONTEXT
138 if (m_graphics)
139 m_graphics->ReleaseHDC(m_hdc);
140#endif
141 }
7280c828 142
e4131985
KO
143 operator HDC() const { return m_hdc; }
144
145private:
146 HDC m_hdc;
147#if wxUSE_GRAPHICS_CONTEXT
148 Graphics* m_graphics;
149#endif
150};
151
d6f2a891
VZ
152#if defined(__WXWINCE__)
153 #ifndef DFCS_FLAT
154 #define DFCS_FLAT 0
155 #endif
156 #ifndef DFCS_MONO
157 #define DFCS_MONO 0
158 #endif
9f93b45e
VZ
159#endif
160
59ee63e9
VZ
161#ifndef DFCS_HOT
162 #define DFCS_HOT 0x1000
163#endif
164
de4bf0b3
FM
165// ----------------------------------------------------------------------------
166// methods common to wxRendererMSW and wxRendererXP
167// ----------------------------------------------------------------------------
168
169class wxRendererMSWBase : public wxDelegateRendererNative
170{
171public:
172 wxRendererMSWBase() { }
173 wxRendererMSWBase(wxRendererNative& rendererNative)
174 : wxDelegateRendererNative(rendererNative) { }
175
176 void DrawFocusRect(wxWindow * win,
177 wxDC& dc,
178 const wxRect& rect,
179 int flags = 0);
180
181 void DrawItemSelectionRect(wxWindow *win,
182 wxDC& dc,
183 const wxRect& rect,
184 int flags = 0);
185};
186
9c7f49f5 187// ----------------------------------------------------------------------------
8b97949e 188// wxRendererMSW: wxRendererNative implementation for "old" Win32 systems
9c7f49f5
VZ
189// ----------------------------------------------------------------------------
190
5aac6f3f 191class wxRendererMSW : public wxRendererMSWBase
9c7f49f5 192{
2eb10e2a
VZ
193public:
194 wxRendererMSW() { }
195
8b97949e
VZ
196 static wxRendererNative& Get();
197
7402677a
VZ
198 virtual void DrawComboBoxDropButton(wxWindow *win,
199 wxDC& dc,
200 const wxRect& rect,
201 int flags = 0);
202
59ee63e9
VZ
203 virtual void DrawCheckBox(wxWindow *win,
204 wxDC& dc,
205 const wxRect& rect,
206 int flags = 0);
207
2209baae
RR
208 virtual void DrawPushButton(wxWindow *win,
209 wxDC& dc,
210 const wxRect& rect,
211 int flags = 0);
212
7280c828
VZ
213 virtual void DrawChoice(wxWindow* win,
214 wxDC& dc,
215 const wxRect& rect,
e4131985
KO
216 int flags=0);
217
7280c828
VZ
218 virtual void DrawComboBox(wxWindow* win,
219 wxDC& dc,
220 const wxRect& rect,
e4131985
KO
221 int flags=0);
222
7280c828
VZ
223 virtual void DrawTextCtrl(wxWindow* win,
224 wxDC& dc,
225 const wxRect& rect,
e4131985
KO
226 int flags=0);
227
6e6b532c 228 virtual void DrawRadioBitmap(wxWindow* win,
7280c828
VZ
229 wxDC& dc,
230 const wxRect& rect,
e4131985
KO
231 int flags=0);
232
191e43fd 233 virtual wxSize GetCheckBoxSize(wxWindow *win);
e8759560 234
51c42fc5
VZ
235 virtual int GetHeaderButtonHeight(wxWindow *win);
236
2eb10e2a 237private:
c0c133e1 238 wxDECLARE_NO_COPY_CLASS(wxRendererMSW);
9c7f49f5
VZ
239};
240
8b97949e
VZ
241// ----------------------------------------------------------------------------
242// wxRendererXP: wxRendererNative implementation for Windows XP and later
243// ----------------------------------------------------------------------------
244
7cf3223a
VZ
245#if wxUSE_UXTHEME
246
5aac6f3f 247class wxRendererXP : public wxRendererMSWBase
8b97949e
VZ
248{
249public:
de4bf0b3 250 wxRendererXP() : wxRendererMSWBase(wxRendererMSW::Get()) { }
8b97949e
VZ
251
252 static wxRendererNative& Get();
253
c97c9952 254 virtual int DrawHeaderButton(wxWindow *win,
4b94ddc4
RD
255 wxDC& dc,
256 const wxRect& rect,
257 int flags = 0,
80752b57 258 wxHeaderSortIconType sortArrow = wxHDR_SORT_ICON_NONE,
4b94ddc4 259 wxHeaderButtonParams* params = NULL);
f4322df6 260
9f93b45e
VZ
261 virtual void DrawTreeItemButton(wxWindow *win,
262 wxDC& dc,
263 const wxRect& rect,
264 int flags = 0);
8b97949e
VZ
265 virtual void DrawSplitterBorder(wxWindow *win,
266 wxDC& dc,
c4e6c15e
VZ
267 const wxRect& rect,
268 int flags = 0);
8b97949e
VZ
269 virtual void DrawSplitterSash(wxWindow *win,
270 wxDC& dc,
271 const wxSize& size,
272 wxCoord position,
c4e6c15e
VZ
273 wxOrientation orient,
274 int flags = 0);
7cf3223a
VZ
275 virtual void DrawComboBoxDropButton(wxWindow *win,
276 wxDC& dc,
277 const wxRect& rect,
278 int flags = 0);
90b903c2
WS
279 virtual void DrawCheckBox(wxWindow *win,
280 wxDC& dc,
281 const wxRect& rect,
282 int flags = 0);
9f93b45e 283
2209baae
RR
284 virtual void DrawPushButton(wxWindow *win,
285 wxDC& dc,
286 const wxRect& rect,
287 int flags = 0);
288
9f93b45e 289 virtual wxSplitterRenderParams GetSplitterParams(const wxWindow *win);
8b97949e 290private:
c0c133e1 291 wxDECLARE_NO_COPY_CLASS(wxRendererXP);
8b97949e
VZ
292};
293
7cf3223a
VZ
294#endif // wxUSE_UXTHEME
295
de4bf0b3
FM
296
297// ============================================================================
298// wxRendererMSWBase implementation
299// ============================================================================
300
301void wxRendererMSWBase::DrawFocusRect(wxWindow * WXUNUSED(win),
302 wxDC& dc,
303 const wxRect& rect,
304 int WXUNUSED(flags))
305{
306 RECT rc;
307 wxCopyRectToRECT(rect, rc);
308
309 ::DrawFocusRect(GraphicsHDC(&dc), &rc);
310}
311
312void wxRendererMSWBase::DrawItemSelectionRect(wxWindow *win,
313 wxDC& dc,
314 const wxRect& rect,
315 int flags)
316{
317 wxBrush brush;
318 if ( flags & wxCONTROL_SELECTED )
319 {
320 if ( flags & wxCONTROL_FOCUSED )
321 {
322 brush = wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT));
323 }
324 else // !focused
325 {
326 brush = wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE));
327 }
328 }
329 else // !selected
330 {
331 brush = *wxTRANSPARENT_BRUSH;
332 }
333
334 dc.SetBrush(brush);
335 dc.SetPen(*wxTRANSPARENT_PEN);
336 dc.DrawRectangle( rect );
337
338 if ((flags & wxCONTROL_FOCUSED) && (flags & wxCONTROL_CURRENT))
339 DrawFocusRect( win, dc, rect, flags );
340}
341
342
9c7f49f5 343// ============================================================================
8b97949e 344// wxRendererNative and wxRendererMSW implementation
9c7f49f5
VZ
345// ============================================================================
346
347/* static */
f0244295 348wxRendererNative& wxRendererNative::GetDefault()
8b97949e 349{
7cf3223a 350#if wxUSE_UXTHEME
8b97949e 351 wxUxThemeEngine *themeEngine = wxUxThemeEngine::Get();
7cf3223a
VZ
352 if ( themeEngine && themeEngine->IsAppThemed() )
353 return wxRendererXP::Get();
354#endif // wxUSE_UXTHEME
355
356 return wxRendererMSW::Get();
8b97949e
VZ
357}
358
359/* static */
360wxRendererNative& wxRendererMSW::Get()
9c7f49f5
VZ
361{
362 static wxRendererMSW s_rendererMSW;
363
364 return s_rendererMSW;
365}
366
7402677a
VZ
367void
368wxRendererMSW::DrawComboBoxDropButton(wxWindow * WXUNUSED(win),
369 wxDC& dc,
370 const wxRect& rect,
371 int flags)
372{
373 RECT r;
46bd1978 374 wxCopyRectToRECT(rect, r);
7402677a
VZ
375
376 int style = DFCS_SCROLLCOMBOBOX;
377 if ( flags & wxCONTROL_DISABLED )
378 style |= DFCS_INACTIVE;
379 if ( flags & wxCONTROL_PRESSED )
7cf3223a 380 style |= DFCS_PUSHED | DFCS_FLAT;
7402677a 381
97bd2a50 382 ::DrawFrameControl(GraphicsHDC(&dc), &r, DFC_SCROLL, style);
7402677a
VZ
383}
384
59ee63e9
VZ
385void
386wxRendererMSW::DrawCheckBox(wxWindow * WXUNUSED(win),
387 wxDC& dc,
388 const wxRect& rect,
389 int flags)
390{
391 RECT r;
392 wxCopyRectToRECT(rect, r);
393
394 int style = DFCS_BUTTONCHECK;
395 if ( flags & wxCONTROL_CHECKED )
396 style |= DFCS_CHECKED;
397 if ( flags & wxCONTROL_DISABLED )
398 style |= DFCS_INACTIVE;
8a461249
VZ
399 if ( flags & wxCONTROL_FLAT )
400 style |= DFCS_MONO;
59ee63e9
VZ
401 if ( flags & wxCONTROL_PRESSED )
402 style |= DFCS_PUSHED;
403 if ( flags & wxCONTROL_CURRENT )
404 style |= DFCS_HOT;
405
97bd2a50 406 ::DrawFrameControl(GraphicsHDC(&dc), &r, DFC_BUTTON, style);
59ee63e9
VZ
407}
408
2209baae
RR
409void
410wxRendererMSW::DrawPushButton(wxWindow * WXUNUSED(win),
411 wxDC& dc,
f2ea4255 412 const wxRect& rectOrig,
2209baae
RR
413 int flags)
414{
f2ea4255 415 wxRect rect(rectOrig);
2209baae
RR
416
417 int style = DFCS_BUTTONPUSH;
418 if ( flags & wxCONTROL_DISABLED )
419 style |= DFCS_INACTIVE;
420 if ( flags & wxCONTROL_PRESSED )
421 style |= DFCS_PUSHED | DFCS_FLAT;
f2ea4255
VZ
422 if ( flags & wxCONTROL_ISDEFAULT )
423 {
424 // DrawFrameControl() doesn't seem to support default buttons so we
425 // have to draw the border ourselves
426 wxDCPenChanger pen(dc, *wxBLACK_PEN);
427 wxDCBrushChanger brush(dc, *wxTRANSPARENT_BRUSH);
428 dc.DrawRectangle(rect);
844b9f5f 429 rect.Deflate(1);
f2ea4255
VZ
430 }
431
432 RECT rc;
433 wxCopyRectToRECT(rect, rc);
434
97bd2a50 435 ::DrawFrameControl(GraphicsHDC(&dc), &rc, DFC_BUTTON, style);
2209baae
RR
436}
437
191e43fd 438wxSize wxRendererMSW::GetCheckBoxSize(wxWindow * WXUNUSED(win))
e8759560
VZ
439{
440 return wxSize(::GetSystemMetrics(SM_CXMENUCHECK),
441 ::GetSystemMetrics(SM_CYMENUCHECK));
442}
443
51c42fc5
VZ
444int wxRendererMSW::GetHeaderButtonHeight(wxWindow * WXUNUSED(win))
445{
446 // some "reasonable" value returned in case of error, it doesn't really
447 // correspond to anything but it's better than returning 0
448 static const int DEFAULT_HEIGHT = 20;
449
450
451 // create a temporary header window just to get its geometry
a268f4b7 452 HWND hwndHeader = ::CreateWindow(WC_HEADER, NULL, 0,
51c42fc5
VZ
453 0, 0, 0, 0, NULL, NULL, NULL, NULL);
454 if ( !hwndHeader )
455 return DEFAULT_HEIGHT;
456
457 wxON_BLOCK_EXIT1( ::DestroyWindow, hwndHeader );
458
459 // initialize the struct filled with the values by Header_Layout()
460 RECT parentRect = { 0, 0, 100, 100 };
11fa6e63 461 WINDOWPOS wp = { 0, 0, 0, 0, 0, 0, 0 };
51c42fc5
VZ
462 HDLAYOUT hdl = { &parentRect, &wp };
463
464 return Header_Layout(hwndHeader, &hdl) ? wp.cy : DEFAULT_HEIGHT;
465}
466
e4131985
KO
467// Uses the theme to draw the border and fill for something like a wxTextCtrl
468void wxRendererMSW::DrawTextCtrl(wxWindow* win, wxDC& dc, const wxRect& rect, int flags)
469{
470 wxColour fill;
471 wxColour bdr;
472 COLORREF cref;
7280c828 473
e4131985
KO
474#if wxUSE_UXTHEME
475 wxUxThemeHandle hTheme(win, L"EDIT");
476 if (hTheme)
477 {
478 wxUxThemeEngine::Get()->GetThemeColor(hTheme, EP_EDITTEXT,
479 ETS_NORMAL, TMT_FILLCOLOR, &cref);
480 fill = wxRGBToColour(cref);
481
482 int etsState;
483 if ( flags & wxCONTROL_DISABLED )
484 etsState = ETS_DISABLED;
485 else
486 etsState = ETS_NORMAL;
7280c828 487
e4131985
KO
488 wxUxThemeEngine::Get()->GetThemeColor(hTheme, EP_EDITTEXT,
489 etsState, TMT_BORDERCOLOR, &cref);
7280c828 490 bdr = wxRGBToColour(cref);
e4131985
KO
491 }
492 else
493#endif
494 {
495 fill = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
496 bdr = *wxBLACK;
497 }
7280c828 498
e4131985
KO
499 dc.SetPen( bdr );
500 dc.SetBrush( fill );
501 dc.DrawRectangle(rect);
502}
503
504
505// Draw the equivallent of a wxComboBox
506void wxRendererMSW::DrawComboBox(wxWindow* win, wxDC& dc, const wxRect& rect, int flags)
507{
508 // Draw the main part of the control same as TextCtrl
7280c828
VZ
509 DrawTextCtrl(win, dc, rect, flags);
510
e4131985
KO
511 // Draw the button inside the border, on the right side
512 wxRect br(rect);
513 br.height -= 2;
514 br.x += br.width - br.height - 1;
515 br.width = br.height;
516 br.y += 1;
517
518 DrawComboBoxDropButton(win, dc, br, flags);
519}
520
521
522void wxRendererMSW::DrawChoice(wxWindow* win, wxDC& dc,
523 const wxRect& rect, int flags)
524{
525 DrawComboBox(win, dc, rect, flags);
526}
527
7280c828 528
e4131985 529// Draw a themed radio button
6e6b532c 530void wxRendererMSW::DrawRadioBitmap(wxWindow* win, wxDC& dc, const wxRect& rect, int flags)
e4131985
KO
531{
532#if wxUSE_UXTHEME
533 wxUxThemeHandle hTheme(win, L"BUTTON");
534 if ( !hTheme )
535#endif
536 {
537 // ??? m_rendererNative.DrawRadioButton(win, dc, rect, flags);
538 return;
539 }
540
541#if wxUSE_UXTHEME
542 RECT r;
543 wxCopyRectToRECT(rect, r);
544
545 int state;
546 if ( flags & wxCONTROL_CHECKED )
547 state = RBS_CHECKEDNORMAL;
548 else if ( flags & wxCONTROL_UNDETERMINED )
549 state = RBS_MIXEDNORMAL;
550 else
551 state = RBS_UNCHECKEDNORMAL;
552
553 // RBS_XXX is followed by RBX_XXXGOT, then RBS_XXXPRESSED and DISABLED
554 if ( flags & wxCONTROL_CURRENT )
555 state += 1;
556 else if ( flags & wxCONTROL_PRESSED )
557 state += 2;
558 else if ( flags & wxCONTROL_DISABLED )
559 state += 3;
560
561 wxUxThemeEngine::Get()->DrawThemeBackground
562 (
563 hTheme,
cc9370b7 564 GraphicsHDC(&dc),
e4131985
KO
565 BP_RADIOBUTTON,
566 state,
567 &r,
568 NULL
569 );
570#endif
571}
572
8b97949e
VZ
573// ============================================================================
574// wxRendererXP implementation
575// ============================================================================
576
7cf3223a
VZ
577#if wxUSE_UXTHEME
578
8b97949e
VZ
579/* static */
580wxRendererNative& wxRendererXP::Get()
581{
582 static wxRendererXP s_rendererXP;
583
584 return s_rendererXP;
585}
586
7cf3223a
VZ
587// NOTE: There is no guarantee that the button drawn fills the entire rect (XP
588// default theme, for example), so the caller should have cleared button's
589// background before this call. This is quite likely a wxMSW-specific thing.
590void
591wxRendererXP::DrawComboBoxDropButton(wxWindow * win,
592 wxDC& dc,
593 const wxRect& rect,
594 int flags)
595{
596 wxUxThemeHandle hTheme(win, L"COMBOBOX");
9f93b45e 597 if ( !hTheme )
7cf3223a 598 {
9f93b45e
VZ
599 m_rendererNative.DrawComboBoxDropButton(win, dc, rect, flags);
600 return;
601 }
602
603 RECT r;
604 wxCopyRectToRECT(rect, r);
7cf3223a 605
9f93b45e
VZ
606 int state;
607 if ( flags & wxCONTROL_PRESSED )
608 state = CBXS_PRESSED;
609 else if ( flags & wxCONTROL_CURRENT )
610 state = CBXS_HOT;
611 else if ( flags & wxCONTROL_DISABLED )
612 state = CBXS_DISABLED;
613 else
614 state = CBXS_NORMAL;
615
616 wxUxThemeEngine::Get()->DrawThemeBackground
617 (
618 hTheme,
888dde65 619 GetHdcOf(*((wxMSWDCImpl*)dc.GetImpl())),
9f93b45e
VZ
620 CP_DROPDOWNBUTTON,
621 state,
622 &r,
623 NULL
624 );
625
626}
627
c97c9952 628int
9f93b45e
VZ
629wxRendererXP::DrawHeaderButton(wxWindow *win,
630 wxDC& dc,
631 const wxRect& rect,
4b94ddc4 632 int flags,
80752b57 633 wxHeaderSortIconType sortArrow,
4b94ddc4 634 wxHeaderButtonParams* params)
9f93b45e
VZ
635{
636 wxUxThemeHandle hTheme(win, L"HEADER");
637 if ( !hTheme )
638 {
c97c9952 639 return m_rendererNative.DrawHeaderButton(win, dc, rect, flags, sortArrow, params);
7cf3223a 640 }
9f93b45e
VZ
641
642 RECT r;
643 wxCopyRectToRECT(rect, r);
644
645 int state;
646 if ( flags & wxCONTROL_PRESSED )
647 state = HIS_PRESSED;
648 else if ( flags & wxCONTROL_CURRENT )
649 state = HIS_HOT;
650 else
651 state = HIS_NORMAL;
652 wxUxThemeEngine::Get()->DrawThemeBackground
653 (
654 hTheme,
888dde65 655 GetHdcOf(*((wxMSWDCImpl*)dc.GetImpl())),
9f93b45e
VZ
656 HP_HEADERITEM,
657 state,
658 &r,
659 NULL
660 );
4b94ddc4
RD
661
662 // NOTE: Using the theme to draw HP_HEADERSORTARROW doesn't do anything.
663 // Why? If this can be fixed then draw the sort arrows using the theme
664 // and then clear those flags before calling DrawHeaderButtonContents.
f4322df6 665
4b94ddc4 666 // Add any extras that are specified in flags and params
c97c9952 667 return DrawHeaderButtonContents(win, dc, rect, flags, sortArrow, params);
9f93b45e
VZ
668}
669
4b94ddc4 670
9f93b45e
VZ
671void
672wxRendererXP::DrawTreeItemButton(wxWindow *win,
673 wxDC& dc,
674 const wxRect& rect,
675 int flags)
676{
677 wxUxThemeHandle hTheme(win, L"TREEVIEW");
678 if ( !hTheme )
679 {
680 m_rendererNative.DrawTreeItemButton(win, dc, rect, flags);
681 return;
682 }
683
684 RECT r;
685 wxCopyRectToRECT(rect, r);
686
687 int state = flags & wxCONTROL_EXPANDED ? GLPS_OPENED : GLPS_CLOSED;
688 wxUxThemeEngine::Get()->DrawThemeBackground
689 (
690 hTheme,
888dde65 691 GetHdcOf(*((wxMSWDCImpl*)dc.GetImpl())),
9f93b45e
VZ
692 TVP_GLYPH,
693 state,
694 &r,
695 NULL
696 );
697}
698
e4131985
KO
699
700
9f93b45e 701void
90b903c2
WS
702wxRendererXP::DrawCheckBox(wxWindow *win,
703 wxDC& dc,
704 const wxRect& rect,
705 int flags)
9f93b45e
VZ
706{
707 wxUxThemeHandle hTheme(win, L"BUTTON");
708 if ( !hTheme )
709 {
90b903c2 710 m_rendererNative.DrawCheckBox(win, dc, rect, flags);
9f93b45e
VZ
711 return;
712 }
713
714 RECT r;
715 wxCopyRectToRECT(rect, r);
716
717 int state;
718 if ( flags & wxCONTROL_CHECKED )
719 state = CBS_CHECKEDNORMAL;
720 else if ( flags & wxCONTROL_UNDETERMINED )
721 state = CBS_MIXEDNORMAL;
722 else
723 state = CBS_UNCHECKEDNORMAL;
724
59ee63e9
VZ
725 // CBS_XXX is followed by CBX_XXXHOT, then CBS_XXXPRESSED and DISABLED
726 enum
727 {
728 CBS_HOT_OFFSET = 1,
729 CBS_PRESSED_OFFSET = 2,
730 CBS_DISABLED_OFFSET = 3
731 };
732
733 if ( flags & wxCONTROL_DISABLED )
734 state += CBS_DISABLED_OFFSET;
9f93b45e 735 else if ( flags & wxCONTROL_PRESSED )
59ee63e9
VZ
736 state += CBS_PRESSED_OFFSET;
737 else if ( flags & wxCONTROL_CURRENT )
738 state += CBS_HOT_OFFSET;
9f93b45e
VZ
739
740 wxUxThemeEngine::Get()->DrawThemeBackground
741 (
742 hTheme,
888dde65 743 GetHdcOf(*((wxMSWDCImpl*)dc.GetImpl())),
9f93b45e
VZ
744 BP_CHECKBOX,
745 state,
746 &r,
747 NULL
748 );
7cf3223a
VZ
749}
750
2209baae
RR
751void
752wxRendererXP::DrawPushButton(wxWindow * win,
753 wxDC& dc,
754 const wxRect& rect,
755 int flags)
756{
757 wxUxThemeHandle hTheme(win, L"BUTTON");
758 if ( !hTheme )
759 {
760 m_rendererNative.DrawPushButton(win, dc, rect, flags);
761 return;
762 }
763
764 RECT r;
765 wxCopyRectToRECT(rect, r);
766
767 int state;
768 if ( flags & wxCONTROL_PRESSED )
769 state = PBS_PRESSED;
770 else if ( flags & wxCONTROL_CURRENT )
771 state = PBS_HOT;
772 else if ( flags & wxCONTROL_DISABLED )
773 state = PBS_DISABLED;
774 else if ( flags & wxCONTROL_ISDEFAULT )
775 state = PBS_DEFAULTED;
776 else
777 state = PBS_NORMAL;
778
779 wxUxThemeEngine::Get()->DrawThemeBackground
780 (
781 hTheme,
888dde65 782 GetHdcOf(*((wxMSWDCImpl*)dc.GetImpl())),
2209baae
RR
783 BP_PUSHBUTTON,
784 state,
785 &r,
786 NULL
787 );
2209baae
RR
788}
789
a9fdf824 790
8b97949e
VZ
791// ----------------------------------------------------------------------------
792// splitter drawing
793// ----------------------------------------------------------------------------
794
795// the width of the sash: this is the same as used by Explorer...
796static const wxCoord SASH_WIDTH = 4;
797
c4e6c15e 798wxSplitterRenderParams
3c2544bb 799wxRendererXP::GetSplitterParams(const wxWindow * win)
8b97949e 800{
9f93b45e 801 if ( win->HasFlag(wxSP_NO_XP_THEME) )
3c2544bb
JS
802 return m_rendererNative.GetSplitterParams(win);
803 else
804 return wxSplitterRenderParams(SASH_WIDTH, 0, false);
8b97949e
VZ
805}
806
807void
3c2544bb
JS
808wxRendererXP::DrawSplitterBorder(wxWindow * win,
809 wxDC& dc,
810 const wxRect& rect,
811 int flags)
8b97949e 812{
9f93b45e 813 if ( win->HasFlag(wxSP_NO_XP_THEME) )
3c2544bb
JS
814 {
815 m_rendererNative.DrawSplitterBorder(win, dc, rect, flags);
816 }
8b97949e
VZ
817}
818
819void
820wxRendererXP::DrawSplitterSash(wxWindow *win,
821 wxDC& dc,
822 const wxSize& size,
823 wxCoord position,
c4e6c15e 824 wxOrientation orient,
3c2544bb 825 int flags)
8b97949e 826{
6421119d 827 if ( !win->HasFlag(wxSP_NO_XP_THEME) )
8b97949e 828 {
fe404d1a
JS
829 dc.SetPen(*wxTRANSPARENT_PEN);
830 dc.SetBrush(wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE)));
831 if ( orient == wxVERTICAL )
8b97949e 832 {
fe404d1a 833 dc.DrawRectangle(position, 0, SASH_WIDTH, size.y);
8b97949e 834 }
fe404d1a
JS
835 else // wxHORIZONTAL
836 {
837 dc.DrawRectangle(0, position, size.x, SASH_WIDTH);
838 }
839
840 return;
8b97949e 841 }
6421119d
VZ
842
843 m_rendererNative.DrawSplitterSash(win, dc, size, position, orient, flags);
8b97949e
VZ
844}
845
7cf3223a 846#endif // wxUSE_UXTHEME