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