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