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