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/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
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
73 #if defined(__WXWINCE__) && !defined(DFCS_FLAT)
77 // ----------------------------------------------------------------------------
78 // wxRendererMSW: wxRendererNative implementation for "old" Win32 systems
79 // ----------------------------------------------------------------------------
81 class WXDLLEXPORT wxRendererMSW
: public wxDelegateRendererNative
86 static wxRendererNative
& Get();
88 virtual void DrawComboBoxDropButton(wxWindow
*win
,
93 virtual void DrawPushButton(wxWindow
*win
,
99 DECLARE_NO_COPY_CLASS(wxRendererMSW
)
102 // ----------------------------------------------------------------------------
103 // wxRendererXP: wxRendererNative implementation for Windows XP and later
104 // ----------------------------------------------------------------------------
108 class WXDLLEXPORT wxRendererXP
: public wxDelegateRendererNative
111 wxRendererXP() : wxDelegateRendererNative(wxRendererMSW::Get()) { }
113 static wxRendererNative
& Get();
115 virtual void DrawHeaderButton(wxWindow
*win
,
119 virtual void DrawTreeItemButton(wxWindow
*win
,
123 virtual void DrawSplitterBorder(wxWindow
*win
,
127 virtual void DrawSplitterSash(wxWindow
*win
,
131 wxOrientation orient
,
133 virtual void DrawComboBoxDropButton(wxWindow
*win
,
137 virtual void DrawCheckBox(wxWindow
*win
,
142 virtual void DrawPushButton(wxWindow
*win
,
147 virtual wxSplitterRenderParams
GetSplitterParams(const wxWindow
*win
);
149 DECLARE_NO_COPY_CLASS(wxRendererXP
)
152 #endif // wxUSE_UXTHEME
154 // ============================================================================
155 // wxRendererNative and wxRendererMSW implementation
156 // ============================================================================
159 wxRendererNative
& wxRendererNative::GetDefault()
162 wxUxThemeEngine
*themeEngine
= wxUxThemeEngine::Get();
163 if ( themeEngine
&& themeEngine
->IsAppThemed() )
164 return wxRendererXP::Get();
165 #endif // wxUSE_UXTHEME
167 return wxRendererMSW::Get();
171 wxRendererNative
& wxRendererMSW::Get()
173 static wxRendererMSW s_rendererMSW
;
175 return s_rendererMSW
;
179 wxRendererMSW::DrawComboBoxDropButton(wxWindow
* WXUNUSED(win
),
185 r
.left
= rect
.GetLeft();
186 r
.top
= rect
.GetTop();
187 r
.bottom
= rect
.y
+ rect
.height
;
188 r
.right
= rect
.x
+ rect
.width
;
190 int style
= DFCS_SCROLLCOMBOBOX
;
191 if ( flags
& wxCONTROL_DISABLED
)
192 style
|= DFCS_INACTIVE
;
193 if ( flags
& wxCONTROL_PRESSED
)
194 style
|= DFCS_PUSHED
| DFCS_FLAT
;
196 ::DrawFrameControl(GetHdcOf(dc
), &r
, DFC_SCROLL
, style
);
200 wxRendererMSW::DrawPushButton(wxWindow
* WXUNUSED(win
),
206 r
.left
= rect
.GetLeft();
207 r
.top
= rect
.GetTop();
208 r
.bottom
= rect
.y
+ rect
.height
;
209 r
.right
= rect
.x
+ rect
.width
;
211 int style
= DFCS_BUTTONPUSH
;
212 if ( flags
& wxCONTROL_DISABLED
)
213 style
|= DFCS_INACTIVE
;
214 if ( flags
& wxCONTROL_PRESSED
)
215 style
|= DFCS_PUSHED
| DFCS_FLAT
;
217 ::DrawFrameControl(GetHdcOf(dc
), &r
, DFC_BUTTON
, style
);
220 // ============================================================================
221 // wxRendererXP implementation
222 // ============================================================================
227 wxRendererNative
& wxRendererXP::Get()
229 static wxRendererXP s_rendererXP
;
234 // NOTE: There is no guarantee that the button drawn fills the entire rect (XP
235 // default theme, for example), so the caller should have cleared button's
236 // background before this call. This is quite likely a wxMSW-specific thing.
238 wxRendererXP::DrawComboBoxDropButton(wxWindow
* win
,
243 wxUxThemeHandle
hTheme(win
, L
"COMBOBOX");
246 m_rendererNative
.DrawComboBoxDropButton(win
, dc
, rect
, flags
);
251 wxCopyRectToRECT(rect
, r
);
254 if ( flags
& wxCONTROL_PRESSED
)
255 state
= CBXS_PRESSED
;
256 else if ( flags
& wxCONTROL_CURRENT
)
258 else if ( flags
& wxCONTROL_DISABLED
)
259 state
= CBXS_DISABLED
;
263 wxUxThemeEngine::Get()->DrawThemeBackground
276 wxRendererXP::DrawHeaderButton(wxWindow
*win
,
281 wxUxThemeHandle
hTheme(win
, L
"HEADER");
284 m_rendererNative
.DrawHeaderButton(win
, dc
, rect
, flags
);
289 wxCopyRectToRECT(rect
, r
);
292 if ( flags
& wxCONTROL_PRESSED
)
294 else if ( flags
& wxCONTROL_CURRENT
)
298 wxUxThemeEngine::Get()->DrawThemeBackground
310 wxRendererXP::DrawTreeItemButton(wxWindow
*win
,
315 wxUxThemeHandle
hTheme(win
, L
"TREEVIEW");
318 m_rendererNative
.DrawTreeItemButton(win
, dc
, rect
, flags
);
323 wxCopyRectToRECT(rect
, r
);
325 int state
= flags
& wxCONTROL_EXPANDED
? GLPS_OPENED
: GLPS_CLOSED
;
326 wxUxThemeEngine::Get()->DrawThemeBackground
338 wxRendererXP::DrawCheckBox(wxWindow
*win
,
343 wxUxThemeHandle
hTheme(win
, L
"BUTTON");
346 m_rendererNative
.DrawCheckBox(win
, dc
, rect
, flags
);
351 wxCopyRectToRECT(rect
, r
);
354 if ( flags
& wxCONTROL_CHECKED
)
355 state
= CBS_CHECKEDNORMAL
;
356 else if ( flags
& wxCONTROL_UNDETERMINED
)
357 state
= CBS_MIXEDNORMAL
;
359 state
= CBS_UNCHECKEDNORMAL
;
361 // CBS_XXX is followed by CBX_XXXGOT, then CBS_XXXPRESSED and DISABLED
362 if ( flags
& wxCONTROL_CURRENT
)
364 else if ( flags
& wxCONTROL_PRESSED
)
366 else if ( flags
& wxCONTROL_DISABLED
)
369 wxUxThemeEngine::Get()->DrawThemeBackground
381 wxRendererXP::DrawPushButton(wxWindow
* win
,
386 wxUxThemeHandle
hTheme(win
, L
"BUTTON");
389 m_rendererNative
.DrawPushButton(win
, dc
, rect
, flags
);
394 wxCopyRectToRECT(rect
, r
);
397 if ( flags
& wxCONTROL_PRESSED
)
399 else if ( flags
& wxCONTROL_CURRENT
)
401 else if ( flags
& wxCONTROL_DISABLED
)
402 state
= PBS_DISABLED
;
403 else if ( flags
& wxCONTROL_ISDEFAULT
)
404 state
= PBS_DEFAULTED
;
408 wxUxThemeEngine::Get()->DrawThemeBackground
420 // ----------------------------------------------------------------------------
422 // ----------------------------------------------------------------------------
424 // the width of the sash: this is the same as used by Explorer...
425 static const wxCoord SASH_WIDTH
= 4;
427 wxSplitterRenderParams
428 wxRendererXP::GetSplitterParams(const wxWindow
* win
)
430 if ( win
->HasFlag(wxSP_NO_XP_THEME
) )
431 return m_rendererNative
.GetSplitterParams(win
);
433 return wxSplitterRenderParams(SASH_WIDTH
, 0, false);
437 wxRendererXP::DrawSplitterBorder(wxWindow
* win
,
442 if ( win
->HasFlag(wxSP_NO_XP_THEME
) )
444 m_rendererNative
.DrawSplitterBorder(win
, dc
, rect
, flags
);
449 wxRendererXP::DrawSplitterSash(wxWindow
*win
,
453 wxOrientation orient
,
456 if ( !win
->HasFlag(wxSP_NO_XP_THEME
) )
458 dc
.SetPen(*wxTRANSPARENT_PEN
);
459 dc
.SetBrush(wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
)));
460 if ( orient
== wxVERTICAL
)
462 dc
.DrawRectangle(position
, 0, SASH_WIDTH
, size
.y
);
466 dc
.DrawRectangle(0, position
, size
.x
, SASH_WIDTH
);
472 m_rendererNative
.DrawSplitterSash(win
, dc
, size
, position
, orient
, flags
);
475 #endif // wxUSE_UXTHEME