1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/renderer.cpp
3 // Purpose: implementation of wxRendererNative for Windows
4 // Author: Vadim Zeitlin
8 // Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwindows.org>
9 // License: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // for compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
28 #include "wx/string.h"
29 #include "wx/window.h"
31 #include "wx/settings.h"
34 #include "wx/splitter.h"
35 #include "wx/renderer.h"
36 #include "wx/msw/private.h"
37 #include "wx/msw/uxtheme.h"
39 // tmschema.h is in Win32 Platform SDK and might not be available with earlier
41 #ifndef CP_DROPDOWNBUTTON
42 #define BP_PUSHBUTTON 1
44 #define CBS_UNCHECKEDNORMAL 1
45 #define CBS_CHECKEDNORMAL (CBS_UNCHECKEDNORMAL + 4)
46 #define CBS_MIXEDNORMAL (CBS_CHECKEDNORMAL + 4)
51 #define PBS_DISABLED 4
52 #define PBS_DEFAULTED 5
54 #define CP_DROPDOWNBUTTON 1
58 #define CBXS_PRESSED 3
59 #define CBXS_DISABLED 4
66 #define HP_HEADERITEM 1
72 #define TMT_HEIGHT 2417
74 #define HP_HEADERSORTARROW 4
75 #define HSAS_SORTEDUP 1
76 #define HSAS_SORTEDDOWN 2
79 #if defined(__WXWINCE__) && !defined(DFCS_FLAT)
84 #define DFCS_HOT 0x1000
87 // ----------------------------------------------------------------------------
88 // wxRendererMSW: wxRendererNative implementation for "old" Win32 systems
89 // ----------------------------------------------------------------------------
91 class WXDLLEXPORT wxRendererMSW
: public wxDelegateRendererNative
96 static wxRendererNative
& Get();
98 virtual void DrawComboBoxDropButton(wxWindow
*win
,
103 virtual void DrawCheckBox(wxWindow
*win
,
108 virtual void DrawPushButton(wxWindow
*win
,
114 DECLARE_NO_COPY_CLASS(wxRendererMSW
)
117 // ----------------------------------------------------------------------------
118 // wxRendererXP: wxRendererNative implementation for Windows XP and later
119 // ----------------------------------------------------------------------------
123 class WXDLLEXPORT wxRendererXP
: public wxDelegateRendererNative
126 wxRendererXP() : wxDelegateRendererNative(wxRendererMSW::Get()) { }
128 static wxRendererNative
& Get();
130 virtual int DrawHeaderButton(wxWindow
*win
,
134 wxHeaderSortIconType sortArrow
= wxHDR_SORT_ICON_NONE
,
135 wxHeaderButtonParams
* params
= NULL
);
136 virtual int GetHeaderButtonHeight(wxWindow
*win
);
138 virtual void DrawTreeItemButton(wxWindow
*win
,
142 virtual void DrawSplitterBorder(wxWindow
*win
,
146 virtual void DrawSplitterSash(wxWindow
*win
,
150 wxOrientation orient
,
152 virtual void DrawComboBoxDropButton(wxWindow
*win
,
156 virtual void DrawCheckBox(wxWindow
*win
,
161 virtual void DrawPushButton(wxWindow
*win
,
166 virtual void DrawItemSelectionRect(wxWindow
*win
,
172 virtual wxSplitterRenderParams
GetSplitterParams(const wxWindow
*win
);
174 DECLARE_NO_COPY_CLASS(wxRendererXP
)
177 #endif // wxUSE_UXTHEME
179 // ============================================================================
180 // wxRendererNative and wxRendererMSW implementation
181 // ============================================================================
184 wxRendererNative
& wxRendererNative::GetDefault()
187 wxUxThemeEngine
*themeEngine
= wxUxThemeEngine::Get();
188 if ( themeEngine
&& themeEngine
->IsAppThemed() )
189 return wxRendererXP::Get();
190 #endif // wxUSE_UXTHEME
192 return wxRendererMSW::Get();
196 wxRendererNative
& wxRendererMSW::Get()
198 static wxRendererMSW s_rendererMSW
;
200 return s_rendererMSW
;
204 wxRendererMSW::DrawComboBoxDropButton(wxWindow
* WXUNUSED(win
),
210 r
.left
= rect
.GetLeft();
211 r
.top
= rect
.GetTop();
212 r
.bottom
= rect
.y
+ rect
.height
;
213 r
.right
= rect
.x
+ rect
.width
;
215 int style
= DFCS_SCROLLCOMBOBOX
;
216 if ( flags
& wxCONTROL_DISABLED
)
217 style
|= DFCS_INACTIVE
;
218 if ( flags
& wxCONTROL_PRESSED
)
219 style
|= DFCS_PUSHED
| DFCS_FLAT
;
221 ::DrawFrameControl(GetHdcOf(dc
), &r
, DFC_SCROLL
, style
);
225 wxRendererMSW::DrawCheckBox(wxWindow
* WXUNUSED(win
),
231 wxCopyRectToRECT(rect
, r
);
233 int style
= DFCS_BUTTONCHECK
;
234 if ( flags
& wxCONTROL_CHECKED
)
235 style
|= DFCS_CHECKED
;
236 if ( flags
& wxCONTROL_DISABLED
)
237 style
|= DFCS_INACTIVE
;
238 if ( flags
& wxCONTROL_FLAT
)
240 if ( flags
& wxCONTROL_PRESSED
)
241 style
|= DFCS_PUSHED
;
242 if ( flags
& wxCONTROL_CURRENT
)
245 ::DrawFrameControl(GetHdcOf(dc
), &r
, DFC_BUTTON
, style
);
249 wxRendererMSW::DrawPushButton(wxWindow
* WXUNUSED(win
),
251 const wxRect
& rectOrig
,
254 wxRect
rect(rectOrig
);
256 int style
= DFCS_BUTTONPUSH
;
257 if ( flags
& wxCONTROL_DISABLED
)
258 style
|= DFCS_INACTIVE
;
259 if ( flags
& wxCONTROL_PRESSED
)
260 style
|= DFCS_PUSHED
| DFCS_FLAT
;
261 if ( flags
& wxCONTROL_ISDEFAULT
)
263 // DrawFrameControl() doesn't seem to support default buttons so we
264 // have to draw the border ourselves
265 wxDCPenChanger
pen(dc
, *wxBLACK_PEN
);
266 wxDCBrushChanger
brush(dc
, *wxTRANSPARENT_BRUSH
);
267 dc
.DrawRectangle(rect
);
272 wxCopyRectToRECT(rect
, rc
);
274 ::DrawFrameControl(GetHdcOf(dc
), &rc
, DFC_BUTTON
, style
);
277 // ============================================================================
278 // wxRendererXP implementation
279 // ============================================================================
284 wxRendererNative
& wxRendererXP::Get()
286 static wxRendererXP s_rendererXP
;
291 // NOTE: There is no guarantee that the button drawn fills the entire rect (XP
292 // default theme, for example), so the caller should have cleared button's
293 // background before this call. This is quite likely a wxMSW-specific thing.
295 wxRendererXP::DrawComboBoxDropButton(wxWindow
* win
,
300 wxUxThemeHandle
hTheme(win
, L
"COMBOBOX");
303 m_rendererNative
.DrawComboBoxDropButton(win
, dc
, rect
, flags
);
308 wxCopyRectToRECT(rect
, r
);
311 if ( flags
& wxCONTROL_PRESSED
)
312 state
= CBXS_PRESSED
;
313 else if ( flags
& wxCONTROL_CURRENT
)
315 else if ( flags
& wxCONTROL_DISABLED
)
316 state
= CBXS_DISABLED
;
320 wxUxThemeEngine::Get()->DrawThemeBackground
333 wxRendererXP::DrawHeaderButton(wxWindow
*win
,
337 wxHeaderSortIconType sortArrow
,
338 wxHeaderButtonParams
* params
)
340 wxUxThemeHandle
hTheme(win
, L
"HEADER");
343 return m_rendererNative
.DrawHeaderButton(win
, dc
, rect
, flags
, sortArrow
, params
);
347 wxCopyRectToRECT(rect
, r
);
350 if ( flags
& wxCONTROL_PRESSED
)
352 else if ( flags
& wxCONTROL_CURRENT
)
356 wxUxThemeEngine::Get()->DrawThemeBackground
366 // NOTE: Using the theme to draw HP_HEADERSORTARROW doesn't do anything.
367 // Why? If this can be fixed then draw the sort arrows using the theme
368 // and then clear those flags before calling DrawHeaderButtonContents.
370 // Add any extras that are specified in flags and params
371 return DrawHeaderButtonContents(win
, dc
, rect
, flags
, sortArrow
, params
);
376 wxRendererXP::GetHeaderButtonHeight(wxWindow
*win
)
378 wxUxThemeHandle
hTheme(win
, L
"HEADER");
381 return m_rendererNative
.GetHeaderButtonHeight(win
);
387 hr
= wxUxThemeEngine::Get()->GetThemeMetric( hTheme
,
401 wxRendererXP::DrawTreeItemButton(wxWindow
*win
,
406 wxUxThemeHandle
hTheme(win
, L
"TREEVIEW");
409 m_rendererNative
.DrawTreeItemButton(win
, dc
, rect
, flags
);
414 wxCopyRectToRECT(rect
, r
);
416 int state
= flags
& wxCONTROL_EXPANDED
? GLPS_OPENED
: GLPS_CLOSED
;
417 wxUxThemeEngine::Get()->DrawThemeBackground
429 wxRendererXP::DrawCheckBox(wxWindow
*win
,
434 wxUxThemeHandle
hTheme(win
, L
"BUTTON");
437 m_rendererNative
.DrawCheckBox(win
, dc
, rect
, flags
);
442 wxCopyRectToRECT(rect
, r
);
445 if ( flags
& wxCONTROL_CHECKED
)
446 state
= CBS_CHECKEDNORMAL
;
447 else if ( flags
& wxCONTROL_UNDETERMINED
)
448 state
= CBS_MIXEDNORMAL
;
450 state
= CBS_UNCHECKEDNORMAL
;
452 // CBS_XXX is followed by CBX_XXXHOT, then CBS_XXXPRESSED and DISABLED
456 CBS_PRESSED_OFFSET
= 2,
457 CBS_DISABLED_OFFSET
= 3
460 if ( flags
& wxCONTROL_DISABLED
)
461 state
+= CBS_DISABLED_OFFSET
;
462 else if ( flags
& wxCONTROL_PRESSED
)
463 state
+= CBS_PRESSED_OFFSET
;
464 else if ( flags
& wxCONTROL_CURRENT
)
465 state
+= CBS_HOT_OFFSET
;
467 wxUxThemeEngine::Get()->DrawThemeBackground
479 wxRendererXP::DrawPushButton(wxWindow
* win
,
484 wxUxThemeHandle
hTheme(win
, L
"BUTTON");
487 m_rendererNative
.DrawPushButton(win
, dc
, rect
, flags
);
492 wxCopyRectToRECT(rect
, r
);
495 if ( flags
& wxCONTROL_PRESSED
)
497 else if ( flags
& wxCONTROL_CURRENT
)
499 else if ( flags
& wxCONTROL_DISABLED
)
500 state
= PBS_DISABLED
;
501 else if ( flags
& wxCONTROL_ISDEFAULT
)
502 state
= PBS_DEFAULTED
;
506 wxUxThemeEngine::Get()->DrawThemeBackground
519 wxRendererXP::DrawItemSelectionRect(wxWindow
* WXUNUSED(win
),
525 if ( flags
& wxCONTROL_SELECTED
)
527 if ( flags
& wxCONTROL_FOCUSED
)
529 brush
= wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT
));
533 brush
= wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNSHADOW
));
538 brush
= *wxTRANSPARENT_BRUSH
;
543 // unlike for wxRendererGeneric, on windows we _never_ want to draw
544 // the outline of the rectangle:
545 dc
.SetPen(*wxTRANSPARENT_PEN
);
547 dc
.DrawRectangle( rect
);
552 // ----------------------------------------------------------------------------
554 // ----------------------------------------------------------------------------
556 // the width of the sash: this is the same as used by Explorer...
557 static const wxCoord SASH_WIDTH
= 4;
559 wxSplitterRenderParams
560 wxRendererXP::GetSplitterParams(const wxWindow
* win
)
562 if ( win
->HasFlag(wxSP_NO_XP_THEME
) )
563 return m_rendererNative
.GetSplitterParams(win
);
565 return wxSplitterRenderParams(SASH_WIDTH
, 0, false);
569 wxRendererXP::DrawSplitterBorder(wxWindow
* win
,
574 if ( win
->HasFlag(wxSP_NO_XP_THEME
) )
576 m_rendererNative
.DrawSplitterBorder(win
, dc
, rect
, flags
);
581 wxRendererXP::DrawSplitterSash(wxWindow
*win
,
585 wxOrientation orient
,
588 if ( !win
->HasFlag(wxSP_NO_XP_THEME
) )
590 dc
.SetPen(*wxTRANSPARENT_PEN
);
591 dc
.SetBrush(wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
)));
592 if ( orient
== wxVERTICAL
)
594 dc
.DrawRectangle(position
, 0, SASH_WIDTH
, size
.y
);
598 dc
.DrawRectangle(0, position
, size
.x
, SASH_WIDTH
);
604 m_rendererNative
.DrawSplitterSash(win
, dc
, size
, position
, orient
, flags
);
607 #endif // wxUSE_UXTHEME