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 wxHeaderSortIconType sortArrow
= wxHDR_SORT_ICON_NONE
,
126 wxHeaderButtonParams
* params
= NULL
);
127 virtual int GetHeaderButtonHeight(wxWindow
*win
);
129 virtual void DrawTreeItemButton(wxWindow
*win
,
133 virtual void DrawSplitterBorder(wxWindow
*win
,
137 virtual void DrawSplitterSash(wxWindow
*win
,
141 wxOrientation orient
,
143 virtual void DrawComboBoxDropButton(wxWindow
*win
,
147 virtual void DrawCheckBox(wxWindow
*win
,
152 virtual void DrawPushButton(wxWindow
*win
,
157 virtual wxSplitterRenderParams
GetSplitterParams(const wxWindow
*win
);
159 DECLARE_NO_COPY_CLASS(wxRendererXP
)
162 #endif // wxUSE_UXTHEME
164 // ============================================================================
165 // wxRendererNative and wxRendererMSW implementation
166 // ============================================================================
169 wxRendererNative
& wxRendererNative::GetDefault()
172 wxUxThemeEngine
*themeEngine
= wxUxThemeEngine::Get();
173 if ( themeEngine
&& themeEngine
->IsAppThemed() )
174 return wxRendererXP::Get();
175 #endif // wxUSE_UXTHEME
177 return wxRendererMSW::Get();
181 wxRendererNative
& wxRendererMSW::Get()
183 static wxRendererMSW s_rendererMSW
;
185 return s_rendererMSW
;
189 wxRendererMSW::DrawComboBoxDropButton(wxWindow
* WXUNUSED(win
),
195 r
.left
= rect
.GetLeft();
196 r
.top
= rect
.GetTop();
197 r
.bottom
= rect
.y
+ rect
.height
;
198 r
.right
= rect
.x
+ rect
.width
;
200 int style
= DFCS_SCROLLCOMBOBOX
;
201 if ( flags
& wxCONTROL_DISABLED
)
202 style
|= DFCS_INACTIVE
;
203 if ( flags
& wxCONTROL_PRESSED
)
204 style
|= DFCS_PUSHED
| DFCS_FLAT
;
206 ::DrawFrameControl(GetHdcOf(dc
), &r
, DFC_SCROLL
, style
);
210 wxRendererMSW::DrawPushButton(wxWindow
* WXUNUSED(win
),
216 r
.left
= rect
.GetLeft();
217 r
.top
= rect
.GetTop();
218 r
.bottom
= rect
.y
+ rect
.height
;
219 r
.right
= rect
.x
+ rect
.width
;
221 int style
= DFCS_BUTTONPUSH
;
222 if ( flags
& wxCONTROL_DISABLED
)
223 style
|= DFCS_INACTIVE
;
224 if ( flags
& wxCONTROL_PRESSED
)
225 style
|= DFCS_PUSHED
| DFCS_FLAT
;
227 ::DrawFrameControl(GetHdcOf(dc
), &r
, DFC_BUTTON
, style
);
230 // ============================================================================
231 // wxRendererXP implementation
232 // ============================================================================
237 wxRendererNative
& wxRendererXP::Get()
239 static wxRendererXP s_rendererXP
;
244 // NOTE: There is no guarantee that the button drawn fills the entire rect (XP
245 // default theme, for example), so the caller should have cleared button's
246 // background before this call. This is quite likely a wxMSW-specific thing.
248 wxRendererXP::DrawComboBoxDropButton(wxWindow
* win
,
253 wxUxThemeHandle
hTheme(win
, L
"COMBOBOX");
256 m_rendererNative
.DrawComboBoxDropButton(win
, dc
, rect
, flags
);
261 wxCopyRectToRECT(rect
, r
);
264 if ( flags
& wxCONTROL_PRESSED
)
265 state
= CBXS_PRESSED
;
266 else if ( flags
& wxCONTROL_CURRENT
)
268 else if ( flags
& wxCONTROL_DISABLED
)
269 state
= CBXS_DISABLED
;
273 wxUxThemeEngine::Get()->DrawThemeBackground
286 wxRendererXP::DrawHeaderButton(wxWindow
*win
,
290 wxHeaderSortIconType sortArrow
,
291 wxHeaderButtonParams
* params
)
293 wxUxThemeHandle
hTheme(win
, L
"HEADER");
296 m_rendererNative
.DrawHeaderButton(win
, dc
, rect
, flags
, sortArrow
, params
);
301 wxCopyRectToRECT(rect
, r
);
304 if ( flags
& wxCONTROL_PRESSED
)
306 else if ( flags
& wxCONTROL_CURRENT
)
310 wxUxThemeEngine::Get()->DrawThemeBackground
320 // NOTE: Using the theme to draw HP_HEADERSORTARROW doesn't do anything.
321 // Why? If this can be fixed then draw the sort arrows using the theme
322 // and then clear those flags before calling DrawHeaderButtonContents.
324 // Add any extras that are specified in flags and params
325 DrawHeaderButtonContents(win
, dc
, rect
, flags
, sortArrow
, params
);
330 wxRendererXP::GetHeaderButtonHeight(wxWindow
*win
)
332 wxUxThemeHandle
hTheme(win
, L
"HEADER");
335 return m_rendererNative
.GetHeaderButtonHeight(win
);
341 hr
= wxUxThemeEngine::Get()->GetThemeMetric( hTheme
,
355 wxRendererXP::DrawTreeItemButton(wxWindow
*win
,
360 wxUxThemeHandle
hTheme(win
, L
"TREEVIEW");
363 m_rendererNative
.DrawTreeItemButton(win
, dc
, rect
, flags
);
368 wxCopyRectToRECT(rect
, r
);
370 int state
= flags
& wxCONTROL_EXPANDED
? GLPS_OPENED
: GLPS_CLOSED
;
371 wxUxThemeEngine::Get()->DrawThemeBackground
383 wxRendererXP::DrawCheckBox(wxWindow
*win
,
388 wxUxThemeHandle
hTheme(win
, L
"BUTTON");
391 m_rendererNative
.DrawCheckBox(win
, dc
, rect
, flags
);
396 wxCopyRectToRECT(rect
, r
);
399 if ( flags
& wxCONTROL_CHECKED
)
400 state
= CBS_CHECKEDNORMAL
;
401 else if ( flags
& wxCONTROL_UNDETERMINED
)
402 state
= CBS_MIXEDNORMAL
;
404 state
= CBS_UNCHECKEDNORMAL
;
406 // CBS_XXX is followed by CBX_XXXGOT, then CBS_XXXPRESSED and DISABLED
407 if ( flags
& wxCONTROL_CURRENT
)
409 else if ( flags
& wxCONTROL_PRESSED
)
411 else if ( flags
& wxCONTROL_DISABLED
)
414 wxUxThemeEngine::Get()->DrawThemeBackground
426 wxRendererXP::DrawPushButton(wxWindow
* win
,
431 wxUxThemeHandle
hTheme(win
, L
"BUTTON");
434 m_rendererNative
.DrawPushButton(win
, dc
, rect
, flags
);
439 wxCopyRectToRECT(rect
, r
);
442 if ( flags
& wxCONTROL_PRESSED
)
444 else if ( flags
& wxCONTROL_CURRENT
)
446 else if ( flags
& wxCONTROL_DISABLED
)
447 state
= PBS_DISABLED
;
448 else if ( flags
& wxCONTROL_ISDEFAULT
)
449 state
= PBS_DEFAULTED
;
453 wxUxThemeEngine::Get()->DrawThemeBackground
465 // ----------------------------------------------------------------------------
467 // ----------------------------------------------------------------------------
469 // the width of the sash: this is the same as used by Explorer...
470 static const wxCoord SASH_WIDTH
= 4;
472 wxSplitterRenderParams
473 wxRendererXP::GetSplitterParams(const wxWindow
* win
)
475 if ( win
->HasFlag(wxSP_NO_XP_THEME
) )
476 return m_rendererNative
.GetSplitterParams(win
);
478 return wxSplitterRenderParams(SASH_WIDTH
, 0, false);
482 wxRendererXP::DrawSplitterBorder(wxWindow
* win
,
487 if ( win
->HasFlag(wxSP_NO_XP_THEME
) )
489 m_rendererNative
.DrawSplitterBorder(win
, dc
, rect
, flags
);
494 wxRendererXP::DrawSplitterSash(wxWindow
*win
,
498 wxOrientation orient
,
501 if ( !win
->HasFlag(wxSP_NO_XP_THEME
) )
503 dc
.SetPen(*wxTRANSPARENT_PEN
);
504 dc
.SetBrush(wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
)));
505 if ( orient
== wxVERTICAL
)
507 dc
.DrawRectangle(position
, 0, SASH_WIDTH
, size
.y
);
511 dc
.DrawRectangle(0, position
, size
.x
, SASH_WIDTH
);
517 m_rendererNative
.DrawSplitterSash(win
, dc
, size
, position
, orient
, flags
);
520 #endif // wxUSE_UXTHEME