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
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)
83 // ----------------------------------------------------------------------------
84 // wxRendererMSW: wxRendererNative implementation for "old" Win32 systems
85 // ----------------------------------------------------------------------------
87 class WXDLLEXPORT wxRendererMSW
: public wxDelegateRendererNative
92 static wxRendererNative
& Get();
94 virtual void DrawComboBoxDropButton(wxWindow
*win
,
99 virtual void DrawPushButton(wxWindow
*win
,
105 DECLARE_NO_COPY_CLASS(wxRendererMSW
)
108 // ----------------------------------------------------------------------------
109 // wxRendererXP: wxRendererNative implementation for Windows XP and later
110 // ----------------------------------------------------------------------------
114 class WXDLLEXPORT wxRendererXP
: public wxDelegateRendererNative
117 wxRendererXP() : wxDelegateRendererNative(wxRendererMSW::Get()) { }
119 static wxRendererNative
& Get();
121 virtual void DrawHeaderButton(wxWindow
*win
,
125 wxHeaderButtonParams
* params
= NULL
);
126 virtual int GetHeaderButtonHeight(wxWindow
*win
);
128 virtual void DrawTreeItemButton(wxWindow
*win
,
132 virtual void DrawSplitterBorder(wxWindow
*win
,
136 virtual void DrawSplitterSash(wxWindow
*win
,
140 wxOrientation orient
,
142 virtual void DrawComboBoxDropButton(wxWindow
*win
,
146 virtual void DrawCheckBox(wxWindow
*win
,
151 virtual void DrawPushButton(wxWindow
*win
,
156 virtual wxSplitterRenderParams
GetSplitterParams(const wxWindow
*win
);
158 DECLARE_NO_COPY_CLASS(wxRendererXP
)
161 #endif // wxUSE_UXTHEME
163 // ============================================================================
164 // wxRendererNative and wxRendererMSW implementation
165 // ============================================================================
168 wxRendererNative
& wxRendererNative::GetDefault()
171 wxUxThemeEngine
*themeEngine
= wxUxThemeEngine::Get();
172 if ( themeEngine
&& themeEngine
->IsAppThemed() )
173 return wxRendererXP::Get();
174 #endif // wxUSE_UXTHEME
176 return wxRendererMSW::Get();
180 wxRendererNative
& wxRendererMSW::Get()
182 static wxRendererMSW s_rendererMSW
;
184 return s_rendererMSW
;
188 wxRendererMSW::DrawComboBoxDropButton(wxWindow
* WXUNUSED(win
),
194 r
.left
= rect
.GetLeft();
195 r
.top
= rect
.GetTop();
196 r
.bottom
= rect
.y
+ rect
.height
;
197 r
.right
= rect
.x
+ rect
.width
;
199 int style
= DFCS_SCROLLCOMBOBOX
;
200 if ( flags
& wxCONTROL_DISABLED
)
201 style
|= DFCS_INACTIVE
;
202 if ( flags
& wxCONTROL_PRESSED
)
203 style
|= DFCS_PUSHED
| DFCS_FLAT
;
205 ::DrawFrameControl(GetHdcOf(dc
), &r
, DFC_SCROLL
, style
);
209 wxRendererMSW::DrawPushButton(wxWindow
* WXUNUSED(win
),
215 r
.left
= rect
.GetLeft();
216 r
.top
= rect
.GetTop();
217 r
.bottom
= rect
.y
+ rect
.height
;
218 r
.right
= rect
.x
+ rect
.width
;
220 int style
= DFCS_BUTTONPUSH
;
221 if ( flags
& wxCONTROL_DISABLED
)
222 style
|= DFCS_INACTIVE
;
223 if ( flags
& wxCONTROL_PRESSED
)
224 style
|= DFCS_PUSHED
| DFCS_FLAT
;
226 ::DrawFrameControl(GetHdcOf(dc
), &r
, DFC_BUTTON
, style
);
229 // ============================================================================
230 // wxRendererXP implementation
231 // ============================================================================
236 wxRendererNative
& wxRendererXP::Get()
238 static wxRendererXP s_rendererXP
;
243 // NOTE: There is no guarantee that the button drawn fills the entire rect (XP
244 // default theme, for example), so the caller should have cleared button's
245 // background before this call. This is quite likely a wxMSW-specific thing.
247 wxRendererXP::DrawComboBoxDropButton(wxWindow
* win
,
252 wxUxThemeHandle
hTheme(win
, L
"COMBOBOX");
255 m_rendererNative
.DrawComboBoxDropButton(win
, dc
, rect
, flags
);
260 wxCopyRectToRECT(rect
, r
);
263 if ( flags
& wxCONTROL_PRESSED
)
264 state
= CBXS_PRESSED
;
265 else if ( flags
& wxCONTROL_CURRENT
)
267 else if ( flags
& wxCONTROL_DISABLED
)
268 state
= CBXS_DISABLED
;
272 wxUxThemeEngine::Get()->DrawThemeBackground
285 wxRendererXP::DrawHeaderButton(wxWindow
*win
,
289 wxHeaderButtonParams
* params
)
291 wxUxThemeHandle
hTheme(win
, L
"HEADER");
294 m_rendererNative
.DrawHeaderButton(win
, dc
, rect
, flags
, params
);
299 wxCopyRectToRECT(rect
, r
);
302 if ( flags
& wxCONTROL_PRESSED
)
304 else if ( flags
& wxCONTROL_CURRENT
)
308 wxUxThemeEngine::Get()->DrawThemeBackground
318 // NOTE: Using the theme to draw HP_HEADERSORTARROW doesn't do anything.
319 // Why? If this can be fixed then draw the sort arrows using the theme
320 // and then clear those flags before calling DrawHeaderButtonContents.
322 // Add any extras that are specified in flags and params
323 DrawHeaderButtonContents(win
, dc
, rect
, flags
, params
);
328 wxRendererXP::GetHeaderButtonHeight(wxWindow
*win
)
330 wxUxThemeHandle
hTheme(win
, L
"HEADER");
333 return m_rendererNative
.GetHeaderButtonHeight(win
);
339 hr
= wxUxThemeEngine::Get()->GetThemeMetric( hTheme
,
353 wxRendererXP::DrawTreeItemButton(wxWindow
*win
,
358 wxUxThemeHandle
hTheme(win
, L
"TREEVIEW");
361 m_rendererNative
.DrawTreeItemButton(win
, dc
, rect
, flags
);
366 wxCopyRectToRECT(rect
, r
);
368 int state
= flags
& wxCONTROL_EXPANDED
? GLPS_OPENED
: GLPS_CLOSED
;
369 wxUxThemeEngine::Get()->DrawThemeBackground
381 wxRendererXP::DrawCheckBox(wxWindow
*win
,
386 wxUxThemeHandle
hTheme(win
, L
"BUTTON");
389 m_rendererNative
.DrawCheckBox(win
, dc
, rect
, flags
);
394 wxCopyRectToRECT(rect
, r
);
397 if ( flags
& wxCONTROL_CHECKED
)
398 state
= CBS_CHECKEDNORMAL
;
399 else if ( flags
& wxCONTROL_UNDETERMINED
)
400 state
= CBS_MIXEDNORMAL
;
402 state
= CBS_UNCHECKEDNORMAL
;
404 // CBS_XXX is followed by CBX_XXXGOT, then CBS_XXXPRESSED and DISABLED
405 if ( flags
& wxCONTROL_CURRENT
)
407 else if ( flags
& wxCONTROL_PRESSED
)
409 else if ( flags
& wxCONTROL_DISABLED
)
412 wxUxThemeEngine::Get()->DrawThemeBackground
424 wxRendererXP::DrawPushButton(wxWindow
* win
,
429 wxUxThemeHandle
hTheme(win
, L
"BUTTON");
432 m_rendererNative
.DrawPushButton(win
, dc
, rect
, flags
);
437 wxCopyRectToRECT(rect
, r
);
440 if ( flags
& wxCONTROL_PRESSED
)
442 else if ( flags
& wxCONTROL_CURRENT
)
444 else if ( flags
& wxCONTROL_DISABLED
)
445 state
= PBS_DISABLED
;
446 else if ( flags
& wxCONTROL_ISDEFAULT
)
447 state
= PBS_DEFAULTED
;
451 wxUxThemeEngine::Get()->DrawThemeBackground
463 // ----------------------------------------------------------------------------
465 // ----------------------------------------------------------------------------
467 // the width of the sash: this is the same as used by Explorer...
468 static const wxCoord SASH_WIDTH
= 4;
470 wxSplitterRenderParams
471 wxRendererXP::GetSplitterParams(const wxWindow
* win
)
473 if ( win
->HasFlag(wxSP_NO_XP_THEME
) )
474 return m_rendererNative
.GetSplitterParams(win
);
476 return wxSplitterRenderParams(SASH_WIDTH
, 0, false);
480 wxRendererXP::DrawSplitterBorder(wxWindow
* win
,
485 if ( win
->HasFlag(wxSP_NO_XP_THEME
) )
487 m_rendererNative
.DrawSplitterBorder(win
, dc
, rect
, flags
);
492 wxRendererXP::DrawSplitterSash(wxWindow
*win
,
496 wxOrientation orient
,
499 if ( !win
->HasFlag(wxSP_NO_XP_THEME
) )
501 dc
.SetPen(*wxTRANSPARENT_PEN
);
502 dc
.SetBrush(wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
)));
503 if ( orient
== wxVERTICAL
)
505 dc
.DrawRectangle(position
, 0, SASH_WIDTH
, size
.y
);
509 dc
.DrawRectangle(0, position
, size
.x
, SASH_WIDTH
);
515 m_rendererNative
.DrawSplitterSash(win
, dc
, size
, position
, orient
, flags
);
518 #endif // wxUSE_UXTHEME