1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: 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"
33 #include "wx/splitter.h"
34 #include "wx/renderer.h"
35 #include "wx/settings.h"
36 #include "wx/msw/uxtheme.h"
37 #include "wx/msw/private.h"
39 // tmschema.h is in Win32 Platform SDK and might not be available with earlier
41 #ifndef CP_DROPDOWNBUTTON
43 #define CBS_UNCHECKEDNORMAL 1
44 #define CBS_CHECKEDNORMAL (CBS_UNCHECKEDNORMAL + 4)
45 #define CBS_MIXEDNORMAL (CBS_CHECKEDNORMAL + 4)
47 #define CP_DROPDOWNBUTTON 1
51 #define CBXS_PRESSED 3
52 #define CBXS_DISABLED 4
59 #define HP_HEADERITEM 1
66 #if defined(__WXWINCE__) && !defined(DFCS_FLAT)
70 // ----------------------------------------------------------------------------
71 // wxRendererMSW: wxRendererNative implementation for "old" Win32 systems
72 // ----------------------------------------------------------------------------
74 class WXDLLEXPORT wxRendererMSW
: public wxDelegateRendererNative
79 static wxRendererNative
& Get();
81 virtual void DrawComboBoxDropButton(wxWindow
*win
,
87 DECLARE_NO_COPY_CLASS(wxRendererMSW
)
90 // ----------------------------------------------------------------------------
91 // wxRendererXP: wxRendererNative implementation for Windows XP and later
92 // ----------------------------------------------------------------------------
96 class WXDLLEXPORT wxRendererXP
: public wxDelegateRendererNative
99 wxRendererXP() : wxDelegateRendererNative(wxRendererMSW
::Get()) { }
101 static wxRendererNative
& Get();
103 virtual void DrawHeaderButton(wxWindow
*win
,
107 virtual void DrawTreeItemButton(wxWindow
*win
,
111 virtual void DrawSplitterBorder(wxWindow
*win
,
115 virtual void DrawSplitterSash(wxWindow
*win
,
119 wxOrientation orient
,
121 virtual void DrawComboBoxDropButton(wxWindow
*win
,
125 virtual void DrawCheckButton(wxWindow
*win
,
130 virtual wxSplitterRenderParams
GetSplitterParams(const wxWindow
*win
);
132 DECLARE_NO_COPY_CLASS(wxRendererXP
)
135 #endif // wxUSE_UXTHEME
137 // ============================================================================
138 // wxRendererNative and wxRendererMSW implementation
139 // ============================================================================
142 wxRendererNative
& wxRendererNative
::GetDefault()
145 wxUxThemeEngine
*themeEngine
= wxUxThemeEngine
::Get();
146 if ( themeEngine
&& themeEngine
->IsAppThemed() )
147 return wxRendererXP
::Get();
148 #endif // wxUSE_UXTHEME
150 return wxRendererMSW
::Get();
154 wxRendererNative
& wxRendererMSW
::Get()
156 static wxRendererMSW s_rendererMSW
;
158 return s_rendererMSW
;
162 wxRendererMSW
::DrawComboBoxDropButton(wxWindow
* WXUNUSED(win
),
168 r
.left
= rect
.GetLeft();
169 r
.top
= rect
.GetTop();
170 r
.bottom
= rect
.y
+ rect
.height
;
171 r
.right
= rect
.x
+ rect
.width
;
173 int style
= DFCS_SCROLLCOMBOBOX
;
174 if ( flags
& wxCONTROL_DISABLED
)
175 style
|= DFCS_INACTIVE
;
176 if ( flags
& wxCONTROL_PRESSED
)
177 style
|= DFCS_PUSHED
| DFCS_FLAT
;
179 ::DrawFrameControl(GetHdcOf(dc
), &r
, DFC_SCROLL
, style
);
182 // ============================================================================
183 // wxRendererXP implementation
184 // ============================================================================
189 wxRendererNative
& wxRendererXP
::Get()
191 static wxRendererXP s_rendererXP
;
196 // NOTE: There is no guarantee that the button drawn fills the entire rect (XP
197 // default theme, for example), so the caller should have cleared button's
198 // background before this call. This is quite likely a wxMSW-specific thing.
200 wxRendererXP
::DrawComboBoxDropButton(wxWindow
* win
,
205 wxUxThemeHandle
hTheme(win
, L
"COMBOBOX");
208 m_rendererNative
.DrawComboBoxDropButton(win
, dc
, rect
, flags
);
213 wxCopyRectToRECT(rect
, r
);
216 if ( flags
& wxCONTROL_PRESSED
)
217 state
= CBXS_PRESSED
;
218 else if ( flags
& wxCONTROL_CURRENT
)
220 else if ( flags
& wxCONTROL_DISABLED
)
221 state
= CBXS_DISABLED
;
225 wxUxThemeEngine
::Get()->DrawThemeBackground
238 wxRendererXP
::DrawHeaderButton(wxWindow
*win
,
243 wxUxThemeHandle
hTheme(win
, L
"HEADER");
246 m_rendererNative
.DrawHeaderButton(win
, dc
, rect
, flags
);
251 wxCopyRectToRECT(rect
, r
);
254 if ( flags
& wxCONTROL_PRESSED
)
256 else if ( flags
& wxCONTROL_CURRENT
)
260 wxUxThemeEngine
::Get()->DrawThemeBackground
272 wxRendererXP
::DrawTreeItemButton(wxWindow
*win
,
277 wxUxThemeHandle
hTheme(win
, L
"TREEVIEW");
280 m_rendererNative
.DrawTreeItemButton(win
, dc
, rect
, flags
);
285 wxCopyRectToRECT(rect
, r
);
287 int state
= flags
& wxCONTROL_EXPANDED ? GLPS_OPENED
: GLPS_CLOSED
;
288 wxUxThemeEngine
::Get()->DrawThemeBackground
300 wxRendererXP
::DrawCheckButton(wxWindow
*win
,
305 wxUxThemeHandle
hTheme(win
, L
"BUTTON");
308 m_rendererNative
.DrawCheckButton(win
, dc
, rect
, flags
);
313 wxCopyRectToRECT(rect
, r
);
316 if ( flags
& wxCONTROL_CHECKED
)
317 state
= CBS_CHECKEDNORMAL
;
318 else if ( flags
& wxCONTROL_UNDETERMINED
)
319 state
= CBS_MIXEDNORMAL
;
321 state
= CBS_UNCHECKEDNORMAL
;
323 // CBS_XXX is followed by CBX_XXXGOT, then CBS_XXXPRESSED and DISABLED
324 if ( flags
& wxCONTROL_CURRENT
)
326 else if ( flags
& wxCONTROL_PRESSED
)
328 else if ( flags
& wxCONTROL_DISABLED
)
331 wxUxThemeEngine
::Get()->DrawThemeBackground
342 // ----------------------------------------------------------------------------
344 // ----------------------------------------------------------------------------
346 // the width of the sash: this is the same as used by Explorer...
347 static const wxCoord SASH_WIDTH
= 4;
349 wxSplitterRenderParams
350 wxRendererXP
::GetSplitterParams(const wxWindow
* win
)
352 if ( win
->HasFlag(wxSP_NO_XP_THEME
) )
353 return m_rendererNative
.GetSplitterParams(win
);
355 return wxSplitterRenderParams(SASH_WIDTH
, 0, false);
359 wxRendererXP
::DrawSplitterBorder(wxWindow
* win
,
364 if ( win
->HasFlag(wxSP_NO_XP_THEME
) )
366 m_rendererNative
.DrawSplitterBorder(win
, dc
, rect
, flags
);
371 wxRendererXP
::DrawSplitterSash(wxWindow
*win
,
375 wxOrientation orient
,
378 if ( !win
->HasFlag(wxSP_NO_XP_THEME
) )
380 dc
.SetPen(*wxTRANSPARENT_PEN
);
381 dc
.SetBrush(wxBrush(wxSystemSettings
::GetColour(wxSYS_COLOUR_BTNFACE
)));
382 if ( orient
== wxVERTICAL
)
384 dc
.DrawRectangle(position
, 0, SASH_WIDTH
, size
.y
);
388 dc
.DrawRectangle(0, position
, size
.x
, SASH_WIDTH
);
394 m_rendererNative
.DrawSplitterSash(win
, dc
, size
, position
, orient
, flags
);
397 #endif // wxUSE_UXTHEME