]> git.saurik.com Git - wxWidgets.git/blob - src/msw/renderer.cpp
Gracefully disconnect clients in wxDDEServer dtor.
[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 // License: 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/scopeguard.h"
35 #include "wx/splitter.h"
36 #include "wx/renderer.h"
37 #include "wx/msw/private.h"
38 #include "wx/msw/uxtheme.h"
39
40 // tmschema.h is in Win32 Platform SDK and might not be available with earlier
41 // compilers
42 #ifndef CP_DROPDOWNBUTTON
43 #define BP_PUSHBUTTON 1
44 #define BP_RADIOBUTTON 2
45 #define BP_CHECKBOX 3
46 #define RBS_UNCHECKEDNORMAL 1
47 #define RBS_CHECKEDNORMAL (RBS_UNCHECKEDNORMAL + 4)
48 #define RBS_MIXEDNORMAL (RBS_CHECKEDNORMAL + 4)
49 #define CBS_UNCHECKEDNORMAL 1
50 #define CBS_CHECKEDNORMAL (CBS_UNCHECKEDNORMAL + 4)
51 #define CBS_MIXEDNORMAL (CBS_CHECKEDNORMAL + 4)
52
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
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
65
66 #define TVP_GLYPH 2
67
68 #define GLPS_CLOSED 1
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
76
77 #define TMT_HEIGHT 2417
78
79 #define HP_HEADERSORTARROW 4
80 #define HSAS_SORTEDUP 1
81 #define HSAS_SORTEDDOWN 2
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
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
101 #endif
102
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
110 #endif
111
112 #ifndef DFCS_HOT
113 #define DFCS_HOT 0x1000
114 #endif
115
116 // ----------------------------------------------------------------------------
117 // methods common to wxRendererMSW and wxRendererXP
118 // ----------------------------------------------------------------------------
119
120 class wxRendererMSWBase : public wxDelegateRendererNative
121 {
122 public:
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
138 // ----------------------------------------------------------------------------
139 // wxRendererMSW: wxRendererNative implementation for "old" Win32 systems
140 // ----------------------------------------------------------------------------
141
142 class wxRendererMSW : public wxRendererMSWBase
143 {
144 public:
145 wxRendererMSW() { }
146
147 static wxRendererNative& Get();
148
149 virtual void DrawComboBoxDropButton(wxWindow *win,
150 wxDC& dc,
151 const wxRect& rect,
152 int flags = 0);
153
154 virtual void DrawCheckBox(wxWindow *win,
155 wxDC& dc,
156 const wxRect& rect,
157 int flags = 0)
158 {
159 DoDrawButton(DFCS_BUTTONCHECK, win, dc, rect, flags);
160 }
161
162 virtual void DrawPushButton(wxWindow *win,
163 wxDC& dc,
164 const wxRect& rect,
165 int flags = 0);
166
167 virtual void DrawChoice(wxWindow* win,
168 wxDC& dc,
169 const wxRect& rect,
170 int flags = 0);
171
172 virtual void DrawComboBox(wxWindow* win,
173 wxDC& dc,
174 const wxRect& rect,
175 int flags = 0);
176
177 virtual void DrawTextCtrl(wxWindow* win,
178 wxDC& dc,
179 const wxRect& rect,
180 int flags = 0);
181
182 virtual void DrawRadioBitmap(wxWindow* win,
183 wxDC& dc,
184 const wxRect& rect,
185 int flags = 0)
186 {
187 DoDrawButton(DFCS_BUTTONRADIO, win, dc, rect, flags);
188 }
189
190 virtual void DrawTitleBarBitmap(wxWindow *win,
191 wxDC& dc,
192 const wxRect& rect,
193 wxTitleBarButton button,
194 int flags = 0);
195
196 virtual wxSize GetCheckBoxSize(wxWindow *win);
197
198 virtual int GetHeaderButtonHeight(wxWindow *win);
199
200 private:
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
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,
215 int flags)
216 {
217 DoDrawFrameControl(DFC_BUTTON, kind, win, dc, rect, flags);
218 }
219
220 wxDECLARE_NO_COPY_CLASS(wxRendererMSW);
221 };
222
223 // ----------------------------------------------------------------------------
224 // wxRendererXP: wxRendererNative implementation for Windows XP and later
225 // ----------------------------------------------------------------------------
226
227 #if wxUSE_UXTHEME
228
229 class wxRendererXP : public wxRendererMSWBase
230 {
231 public:
232 wxRendererXP() : wxRendererMSWBase(wxRendererMSW::Get()) { }
233
234 static wxRendererNative& Get();
235
236 virtual int DrawHeaderButton(wxWindow *win,
237 wxDC& dc,
238 const wxRect& rect,
239 int flags = 0,
240 wxHeaderSortIconType sortArrow = wxHDR_SORT_ICON_NONE,
241 wxHeaderButtonParams* params = NULL);
242
243 virtual void DrawTreeItemButton(wxWindow *win,
244 wxDC& dc,
245 const wxRect& rect,
246 int flags = 0);
247 virtual void DrawSplitterBorder(wxWindow *win,
248 wxDC& dc,
249 const wxRect& rect,
250 int flags = 0);
251 virtual void DrawSplitterSash(wxWindow *win,
252 wxDC& dc,
253 const wxSize& size,
254 wxCoord position,
255 wxOrientation orient,
256 int flags = 0);
257 virtual void DrawComboBoxDropButton(wxWindow *win,
258 wxDC& dc,
259 const wxRect& rect,
260 int flags = 0);
261 virtual void DrawCheckBox(wxWindow *win,
262 wxDC& dc,
263 const wxRect& rect,
264 int flags = 0)
265 {
266 if ( !DoDrawXPButton(BP_CHECKBOX, win, dc, rect, flags) )
267 m_rendererNative.DrawCheckBox(win, dc, rect, flags);
268 }
269
270 virtual void DrawPushButton(wxWindow *win,
271 wxDC& dc,
272 const wxRect& rect,
273 int flags = 0)
274 {
275 if ( !DoDrawXPButton(BP_PUSHBUTTON, win, dc, rect, flags) )
276 m_rendererNative.DrawPushButton(win, dc, rect, flags);
277 }
278
279 virtual void DrawRadioBitmap(wxWindow *win,
280 wxDC& dc,
281 const wxRect& rect,
282 int flags = 0)
283 {
284 if ( !DoDrawXPButton(BP_RADIOBUTTON, win, dc, rect, flags) )
285 m_rendererNative.DrawRadioBitmap(win, dc, rect, flags);
286 }
287
288 virtual void DrawTitleBarBitmap(wxWindow *win,
289 wxDC& dc,
290 const wxRect& rect,
291 wxTitleBarButton button,
292 int flags = 0);
293
294 virtual wxSplitterRenderParams GetSplitterParams(const wxWindow *win);
295
296 private:
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
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
313 wxDECLARE_NO_COPY_CLASS(wxRendererXP);
314 };
315
316 #endif // wxUSE_UXTHEME
317
318
319 // ============================================================================
320 // wxRendererMSWBase implementation
321 // ============================================================================
322
323 void 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
331 ::DrawFocusRect(GetHdcOf(dc.GetTempHDC()), &rc);
332 }
333
334 void 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
365 // ============================================================================
366 // wxRendererNative and wxRendererMSW implementation
367 // ============================================================================
368
369 /* static */
370 wxRendererNative& wxRendererNative::GetDefault()
371 {
372 #if wxUSE_UXTHEME
373 wxUxThemeEngine *themeEngine = wxUxThemeEngine::Get();
374 if ( themeEngine && themeEngine->IsAppThemed() )
375 return wxRendererXP::Get();
376 #endif // wxUSE_UXTHEME
377
378 return wxRendererMSW::Get();
379 }
380
381 /* static */
382 wxRendererNative& wxRendererMSW::Get()
383 {
384 static wxRendererMSW s_rendererMSW;
385
386 return s_rendererMSW;
387 }
388
389 void
390 wxRendererMSW::DrawComboBoxDropButton(wxWindow * WXUNUSED(win),
391 wxDC& dc,
392 const wxRect& rect,
393 int flags)
394 {
395 RECT r;
396 wxCopyRectToRECT(rect, r);
397
398 int style = DFCS_SCROLLCOMBOBOX;
399 if ( flags & wxCONTROL_DISABLED )
400 style |= DFCS_INACTIVE;
401 if ( flags & wxCONTROL_PRESSED )
402 style |= DFCS_PUSHED | DFCS_FLAT;
403
404 ::DrawFrameControl(GetHdcOf(dc.GetTempHDC()), &r, DFC_SCROLL, style);
405 }
406
407 void
408 wxRendererMSW::DoDrawFrameControl(UINT type,
409 UINT kind,
410 wxWindow * WXUNUSED(win),
411 wxDC& dc,
412 const wxRect& rect,
413 int flags)
414 {
415 RECT r;
416 wxCopyRectToRECT(rect, r);
417
418 int style = kind;
419 if ( flags & wxCONTROL_CHECKED )
420 style |= DFCS_CHECKED;
421 if ( flags & wxCONTROL_DISABLED )
422 style |= DFCS_INACTIVE;
423 if ( flags & wxCONTROL_FLAT )
424 style |= DFCS_MONO;
425 if ( flags & wxCONTROL_PRESSED )
426 style |= DFCS_PUSHED;
427 if ( flags & wxCONTROL_CURRENT )
428 style |= DFCS_HOT;
429
430 ::DrawFrameControl(GetHdcOf(dc.GetTempHDC()), &r, type, style);
431 }
432
433 void
434 wxRendererMSW::DrawPushButton(wxWindow *win,
435 wxDC& dc,
436 const wxRect& rectOrig,
437 int flags)
438 {
439 wxRect rect(rectOrig);
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);
447 rect.Deflate(1);
448 }
449
450 DoDrawButton(DFCS_BUTTONPUSH, win, dc, rect, flags);
451 }
452
453 void
454 wxRendererMSW::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
491 wxSize wxRendererMSW::GetCheckBoxSize(wxWindow * WXUNUSED(win))
492 {
493 return wxSize(::GetSystemMetrics(SM_CXMENUCHECK),
494 ::GetSystemMetrics(SM_CYMENUCHECK));
495 }
496
497 int 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
505 HWND hwndHeader = ::CreateWindow(WC_HEADER, NULL, 0,
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 };
514 WINDOWPOS wp = { 0, 0, 0, 0, 0, 0, 0 };
515 HDLAYOUT hdl = { &parentRect, &wp };
516
517 return Header_Layout(hwndHeader, &hdl) ? wp.cy : DEFAULT_HEIGHT;
518 }
519
520 // Uses the theme to draw the border and fill for something like a wxTextCtrl
521 void wxRendererMSW::DrawTextCtrl(wxWindow* win, wxDC& dc, const wxRect& rect, int flags)
522 {
523 wxColour fill;
524 wxColour bdr;
525 COLORREF cref;
526
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;
540
541 wxUxThemeEngine::Get()->GetThemeColor(hTheme, EP_EDITTEXT,
542 etsState, TMT_BORDERCOLOR, &cref);
543 bdr = wxRGBToColour(cref);
544 }
545 else
546 #endif
547 {
548 fill = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
549 bdr = *wxBLACK;
550 }
551
552 dc.SetPen( bdr );
553 dc.SetBrush( fill );
554 dc.DrawRectangle(rect);
555 }
556
557
558 // Draw the equivalent of a wxComboBox
559 void wxRendererMSW::DrawComboBox(wxWindow* win, wxDC& dc, const wxRect& rect, int flags)
560 {
561 // Draw the main part of the control same as TextCtrl
562 DrawTextCtrl(win, dc, rect, flags);
563
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
575 void wxRendererMSW::DrawChoice(wxWindow* win, wxDC& dc,
576 const wxRect& rect, int flags)
577 {
578 DrawComboBox(win, dc, rect, flags);
579 }
580
581 // ============================================================================
582 // wxRendererXP implementation
583 // ============================================================================
584
585 #if wxUSE_UXTHEME
586
587 /* static */
588 wxRendererNative& wxRendererXP::Get()
589 {
590 static wxRendererXP s_rendererXP;
591
592 return s_rendererXP;
593 }
594
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.
598 void
599 wxRendererXP::DrawComboBoxDropButton(wxWindow * win,
600 wxDC& dc,
601 const wxRect& rect,
602 int flags)
603 {
604 wxUxThemeHandle hTheme(win, L"COMBOBOX");
605 if ( !hTheme )
606 {
607 m_rendererNative.DrawComboBoxDropButton(win, dc, rect, flags);
608 return;
609 }
610
611 RECT r;
612 wxCopyRectToRECT(rect, r);
613
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,
627 GetHdcOf(dc.GetTempHDC()),
628 CP_DROPDOWNBUTTON,
629 state,
630 &r,
631 NULL
632 );
633
634 }
635
636 int
637 wxRendererXP::DrawHeaderButton(wxWindow *win,
638 wxDC& dc,
639 const wxRect& rect,
640 int flags,
641 wxHeaderSortIconType sortArrow,
642 wxHeaderButtonParams* params)
643 {
644 wxUxThemeHandle hTheme(win, L"HEADER");
645 if ( !hTheme )
646 {
647 return m_rendererNative.DrawHeaderButton(win, dc, rect, flags, sortArrow, params);
648 }
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,
663 GetHdcOf(dc.GetTempHDC()),
664 HP_HEADERITEM,
665 state,
666 &r,
667 NULL
668 );
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.
673
674 // Add any extras that are specified in flags and params
675 return DrawHeaderButtonContents(win, dc, rect, flags, sortArrow, params);
676 }
677
678
679 void
680 wxRendererXP::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,
699 GetHdcOf(dc.GetTempHDC()),
700 TVP_GLYPH,
701 state,
702 &r,
703 NULL
704 );
705 }
706
707 bool
708 wxRendererXP::DoDrawXPButton(int kind,
709 wxWindow *win,
710 wxDC& dc,
711 const wxRect& rect,
712 int flags)
713 {
714 wxUxThemeHandle hTheme(win, L"BUTTON");
715 if ( !hTheme )
716 return false;
717
718 DoDrawButtonLike(hTheme, kind, dc, rect, flags);
719
720 return true;
721 }
722
723 void
724 wxRendererXP::DoDrawButtonLike(HTHEME htheme,
725 int part,
726 wxDC& dc,
727 const wxRect& rect,
728 int flags)
729 {
730 RECT r;
731 wxCopyRectToRECT(rect, r);
732
733 // the base state is always 1, whether it is PBS_NORMAL,
734 // {CBS,RBS}_UNCHECKEDNORMAL or CBS_NORMAL
735 int state = 1;
736
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 };
746
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
750 if ( flags & wxCONTROL_CHECKED )
751 state += STATES_COUNT;
752 else if ( flags & wxCONTROL_UNDETERMINED )
753 state += 2*STATES_COUNT;
754
755 if ( flags & wxCONTROL_DISABLED )
756 state += DISABLED_OFFSET;
757 else if ( flags & wxCONTROL_PRESSED )
758 state += PRESSED_OFFSET;
759 else if ( flags & wxCONTROL_CURRENT )
760 state += HOT_OFFSET;
761 // wxCONTROL_ISDEFAULT flag is only valid for push buttons
762 else if ( part == BP_PUSHBUTTON && (flags & wxCONTROL_ISDEFAULT) )
763 state = PBS_DEFAULTED;
764
765 wxUxThemeEngine::Get()->DrawThemeBackground
766 (
767 htheme,
768 GetHdcOf(dc.GetTempHDC()),
769 part,
770 state,
771 &r,
772 NULL
773 );
774 }
775
776 void
777 wxRendererXP::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);
819 }
820
821 // ----------------------------------------------------------------------------
822 // splitter drawing
823 // ----------------------------------------------------------------------------
824
825 // the width of the sash: this is the same as used by Explorer...
826 static const wxCoord SASH_WIDTH = 4;
827
828 wxSplitterRenderParams
829 wxRendererXP::GetSplitterParams(const wxWindow * win)
830 {
831 if ( win->HasFlag(wxSP_NO_XP_THEME) )
832 return m_rendererNative.GetSplitterParams(win);
833 else
834 return wxSplitterRenderParams(SASH_WIDTH, 0, false);
835 }
836
837 void
838 wxRendererXP::DrawSplitterBorder(wxWindow * win,
839 wxDC& dc,
840 const wxRect& rect,
841 int flags)
842 {
843 if ( win->HasFlag(wxSP_NO_XP_THEME) )
844 {
845 m_rendererNative.DrawSplitterBorder(win, dc, rect, flags);
846 }
847 }
848
849 void
850 wxRendererXP::DrawSplitterSash(wxWindow *win,
851 wxDC& dc,
852 const wxSize& size,
853 wxCoord position,
854 wxOrientation orient,
855 int flags)
856 {
857 if ( !win->HasFlag(wxSP_NO_XP_THEME) )
858 {
859 dc.SetPen(*wxTRANSPARENT_PEN);
860 dc.SetBrush(wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE)));
861 if ( orient == wxVERTICAL )
862 {
863 dc.DrawRectangle(position, 0, SASH_WIDTH, size.y);
864 }
865 else // wxHORIZONTAL
866 {
867 dc.DrawRectangle(0, position, size.x, SASH_WIDTH);
868 }
869
870 return;
871 }
872
873 m_rendererNative.DrawSplitterSash(win, dc, size, position, orient, flags);
874 }
875
876 #endif // wxUSE_UXTHEME