]> git.saurik.com Git - wxWidgets.git/blob - src/msw/renderer.cpp
Ignore WM_CLOSE generated by wxMSW edit control when Escape is pressed.
[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
441 ::DrawFrameControl(GetHdcOf(dc.GetTempHDC()), &r, type, style);
442 }
443
444 void
445 wxRendererMSW::DrawPushButton(wxWindow *win,
446 wxDC& dc,
447 const wxRect& rectOrig,
448 int flags)
449 {
450 wxRect rect(rectOrig);
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);
458 rect.Deflate(1);
459 }
460
461 DoDrawButton(DFCS_BUTTONPUSH, win, dc, rect, flags);
462 }
463
464 void
465 wxRendererMSW::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
502 wxSize wxRendererMSW::GetCheckBoxSize(wxWindow * WXUNUSED(win))
503 {
504 return wxSize(::GetSystemMetrics(SM_CXMENUCHECK),
505 ::GetSystemMetrics(SM_CYMENUCHECK));
506 }
507
508 int 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
516 HWND hwndHeader = ::CreateWindow(WC_HEADER, NULL, 0,
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 };
525 WINDOWPOS wp = { 0, 0, 0, 0, 0, 0, 0 };
526 HDLAYOUT hdl = { &parentRect, &wp };
527
528 return Header_Layout(hwndHeader, &hdl) ? wp.cy : DEFAULT_HEIGHT;
529 }
530
531 int wxRendererMSW::GetHeaderButtonMargin(wxWindow *WXUNUSED(win))
532 {
533 return 10;
534 }
535
536 // Uses the theme to draw the border and fill for something like a wxTextCtrl
537 void wxRendererMSW::DrawTextCtrl(wxWindow* win, wxDC& dc, const wxRect& rect, int flags)
538 {
539 wxColour fill;
540 wxColour bdr;
541 COLORREF cref;
542
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;
556
557 wxUxThemeEngine::Get()->GetThemeColor(hTheme, EP_EDITTEXT,
558 etsState, TMT_BORDERCOLOR, &cref);
559 bdr = wxRGBToColour(cref);
560 }
561 else
562 #endif
563 {
564 fill = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
565 bdr = *wxBLACK;
566 }
567
568 dc.SetPen( bdr );
569 dc.SetBrush( fill );
570 dc.DrawRectangle(rect);
571 }
572
573
574 // Draw the equivalent of a wxComboBox
575 void wxRendererMSW::DrawComboBox(wxWindow* win, wxDC& dc, const wxRect& rect, int flags)
576 {
577 // Draw the main part of the control same as TextCtrl
578 DrawTextCtrl(win, dc, rect, flags);
579
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
591 void wxRendererMSW::DrawChoice(wxWindow* win, wxDC& dc,
592 const wxRect& rect, int flags)
593 {
594 DrawComboBox(win, dc, rect, flags);
595 }
596
597 // ============================================================================
598 // wxRendererXP implementation
599 // ============================================================================
600
601 #if wxUSE_UXTHEME
602
603 /* static */
604 wxRendererNative& wxRendererXP::Get()
605 {
606 static wxRendererXP s_rendererXP;
607
608 return s_rendererXP;
609 }
610
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.
614 void
615 wxRendererXP::DrawComboBoxDropButton(wxWindow * win,
616 wxDC& dc,
617 const wxRect& rect,
618 int flags)
619 {
620 wxUxThemeHandle hTheme(win, L"COMBOBOX");
621 if ( !hTheme )
622 {
623 m_rendererNative.DrawComboBoxDropButton(win, dc, rect, flags);
624 return;
625 }
626
627 wxCHECK_RET( dc.GetImpl(), wxT("Invalid wxDC") );
628
629 wxRect adjustedRect = dc.GetImpl()->MSWApplyGDIPlusTransform(rect);
630
631 RECT r;
632 wxCopyRectToRECT(adjustedRect, r);
633
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,
647 GetHdcOf(dc.GetTempHDC()),
648 CP_DROPDOWNBUTTON,
649 state,
650 &r,
651 NULL
652 );
653
654 }
655
656 int
657 wxRendererXP::DrawHeaderButton(wxWindow *win,
658 wxDC& dc,
659 const wxRect& rect,
660 int flags,
661 wxHeaderSortIconType sortArrow,
662 wxHeaderButtonParams* params)
663 {
664 wxUxThemeHandle hTheme(win, L"HEADER");
665 if ( !hTheme )
666 {
667 return m_rendererNative.DrawHeaderButton(win, dc, rect, flags, sortArrow, params);
668 }
669
670 wxCHECK_MSG( dc.GetImpl(), -1, wxT("Invalid wxDC") );
671
672 wxRect adjustedRect = dc.GetImpl()->MSWApplyGDIPlusTransform(rect);
673
674 RECT r;
675 wxCopyRectToRECT(adjustedRect, r);
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,
687 GetHdcOf(dc.GetTempHDC()),
688 HP_HEADERITEM,
689 state,
690 &r,
691 NULL
692 );
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.
697
698 // Add any extras that are specified in flags and params
699 return DrawHeaderButtonContents(win, dc, rect, flags, sortArrow, params);
700 }
701
702
703 void
704 wxRendererXP::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
716 wxCHECK_RET( dc.GetImpl(), wxT("Invalid wxDC") );
717
718 wxRect adjustedRect = dc.GetImpl()->MSWApplyGDIPlusTransform(rect);
719
720 RECT r;
721 wxCopyRectToRECT(adjustedRect, r);
722
723 int state = flags & wxCONTROL_EXPANDED ? GLPS_OPENED : GLPS_CLOSED;
724 wxUxThemeEngine::Get()->DrawThemeBackground
725 (
726 hTheme,
727 GetHdcOf(dc.GetTempHDC()),
728 TVP_GLYPH,
729 state,
730 &r,
731 NULL
732 );
733 }
734
735 bool
736 wxRendererXP::DoDrawXPButton(int kind,
737 wxWindow *win,
738 wxDC& dc,
739 const wxRect& rect,
740 int flags)
741 {
742 wxUxThemeHandle hTheme(win, L"BUTTON");
743 if ( !hTheme )
744 return false;
745
746 DoDrawButtonLike(hTheme, kind, dc, rect, flags);
747
748 return true;
749 }
750
751 void
752 wxRendererXP::DoDrawButtonLike(HTHEME htheme,
753 int part,
754 wxDC& dc,
755 const wxRect& rect,
756 int flags)
757 {
758 wxCHECK_RET( dc.GetImpl(), wxT("Invalid wxDC") );
759
760 wxRect adjustedRect = dc.GetImpl()->MSWApplyGDIPlusTransform(rect);
761
762 RECT r;
763 wxCopyRectToRECT(adjustedRect, r);
764
765 // the base state is always 1, whether it is PBS_NORMAL,
766 // {CBS,RBS}_UNCHECKEDNORMAL or CBS_NORMAL
767 int state = 1;
768
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 };
778
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
782 if ( flags & wxCONTROL_CHECKED )
783 state += STATES_COUNT;
784 else if ( flags & wxCONTROL_UNDETERMINED )
785 state += 2*STATES_COUNT;
786
787 if ( flags & wxCONTROL_DISABLED )
788 state += DISABLED_OFFSET;
789 else if ( flags & wxCONTROL_PRESSED )
790 state += PRESSED_OFFSET;
791 else if ( flags & wxCONTROL_CURRENT )
792 state += HOT_OFFSET;
793 // wxCONTROL_ISDEFAULT flag is only valid for push buttons
794 else if ( part == BP_PUSHBUTTON && (flags & wxCONTROL_ISDEFAULT) )
795 state = PBS_DEFAULTED;
796
797 wxUxThemeEngine::Get()->DrawThemeBackground
798 (
799 htheme,
800 GetHdcOf(dc.GetTempHDC()),
801 part,
802 state,
803 &r,
804 NULL
805 );
806 }
807
808 void
809 wxRendererXP::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);
851 }
852
853 // ----------------------------------------------------------------------------
854 // splitter drawing
855 // ----------------------------------------------------------------------------
856
857 // the width of the sash: this is the same as used by Explorer...
858 static const wxCoord SASH_WIDTH = 4;
859
860 wxSplitterRenderParams
861 wxRendererXP::GetSplitterParams(const wxWindow * win)
862 {
863 if ( win->HasFlag(wxSP_NO_XP_THEME) )
864 return m_rendererNative.GetSplitterParams(win);
865 else
866 return wxSplitterRenderParams(SASH_WIDTH, 0, false);
867 }
868
869 void
870 wxRendererXP::DrawSplitterBorder(wxWindow * win,
871 wxDC& dc,
872 const wxRect& rect,
873 int flags)
874 {
875 if ( win->HasFlag(wxSP_NO_XP_THEME) )
876 {
877 m_rendererNative.DrawSplitterBorder(win, dc, rect, flags);
878 }
879 }
880
881 void
882 wxRendererXP::DrawSplitterSash(wxWindow *win,
883 wxDC& dc,
884 const wxSize& size,
885 wxCoord position,
886 wxOrientation orient,
887 int flags)
888 {
889 if ( !win->HasFlag(wxSP_NO_XP_THEME) )
890 {
891 dc.SetPen(*wxTRANSPARENT_PEN);
892 dc.SetBrush(wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE)));
893 if ( orient == wxVERTICAL )
894 {
895 dc.DrawRectangle(position, 0, SASH_WIDTH, size.y);
896 }
897 else // wxHORIZONTAL
898 {
899 dc.DrawRectangle(0, position, size.x, SASH_WIDTH);
900 }
901
902 return;
903 }
904
905 m_rendererNative.DrawSplitterSash(win, dc, size, position, orient, flags);
906 }
907
908 #endif // wxUSE_UXTHEME