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__)
89 #define DFCS_HOT 0x1000
92 // ----------------------------------------------------------------------------
93 // wxRendererMSW: wxRendererNative implementation for "old" Win32 systems
94 // ----------------------------------------------------------------------------
96 class WXDLLEXPORT wxRendererMSW
: public wxDelegateRendererNative
101 static wxRendererNative
& Get();
103 virtual void DrawComboBoxDropButton(wxWindow
*win
,
108 virtual void DrawCheckBox(wxWindow
*win
,
113 virtual void DrawPushButton(wxWindow
*win
,
119 DECLARE_NO_COPY_CLASS(wxRendererMSW
)
122 // ----------------------------------------------------------------------------
123 // wxRendererXP: wxRendererNative implementation for Windows XP and later
124 // ----------------------------------------------------------------------------
128 class WXDLLEXPORT wxRendererXP
: public wxDelegateRendererNative
131 wxRendererXP() : wxDelegateRendererNative(wxRendererMSW::Get()) { }
133 static wxRendererNative
& Get();
135 virtual int DrawHeaderButton(wxWindow
*win
,
139 wxHeaderSortIconType sortArrow
= wxHDR_SORT_ICON_NONE
,
140 wxHeaderButtonParams
* params
= NULL
);
141 virtual int GetHeaderButtonHeight(wxWindow
*win
);
143 virtual void DrawTreeItemButton(wxWindow
*win
,
147 virtual void DrawSplitterBorder(wxWindow
*win
,
151 virtual void DrawSplitterSash(wxWindow
*win
,
155 wxOrientation orient
,
157 virtual void DrawComboBoxDropButton(wxWindow
*win
,
161 virtual void DrawCheckBox(wxWindow
*win
,
166 virtual void DrawPushButton(wxWindow
*win
,
171 virtual void DrawItemSelectionRect(wxWindow
*win
,
177 virtual wxSplitterRenderParams
GetSplitterParams(const wxWindow
*win
);
179 DECLARE_NO_COPY_CLASS(wxRendererXP
)
182 #endif // wxUSE_UXTHEME
184 // ============================================================================
185 // wxRendererNative and wxRendererMSW implementation
186 // ============================================================================
189 wxRendererNative
& wxRendererNative::GetDefault()
192 wxUxThemeEngine
*themeEngine
= wxUxThemeEngine::Get();
193 if ( themeEngine
&& themeEngine
->IsAppThemed() )
194 return wxRendererXP::Get();
195 #endif // wxUSE_UXTHEME
197 return wxRendererMSW::Get();
201 wxRendererNative
& wxRendererMSW::Get()
203 static wxRendererMSW s_rendererMSW
;
205 return s_rendererMSW
;
209 wxRendererMSW::DrawComboBoxDropButton(wxWindow
* WXUNUSED(win
),
215 wxCopyRectToRECT(rect
, r
);
217 int style
= DFCS_SCROLLCOMBOBOX
;
218 if ( flags
& wxCONTROL_DISABLED
)
219 style
|= DFCS_INACTIVE
;
220 if ( flags
& wxCONTROL_PRESSED
)
221 style
|= DFCS_PUSHED
| DFCS_FLAT
;
223 ::DrawFrameControl(GetHdcOf(dc
), &r
, DFC_SCROLL
, style
);
227 wxRendererMSW::DrawCheckBox(wxWindow
* WXUNUSED(win
),
233 wxCopyRectToRECT(rect
, r
);
235 int style
= DFCS_BUTTONCHECK
;
236 if ( flags
& wxCONTROL_CHECKED
)
237 style
|= DFCS_CHECKED
;
238 if ( flags
& wxCONTROL_DISABLED
)
239 style
|= DFCS_INACTIVE
;
240 if ( flags
& wxCONTROL_FLAT
)
242 if ( flags
& wxCONTROL_PRESSED
)
243 style
|= DFCS_PUSHED
;
244 if ( flags
& wxCONTROL_CURRENT
)
247 ::DrawFrameControl(GetHdcOf(dc
), &r
, DFC_BUTTON
, style
);
251 wxRendererMSW::DrawPushButton(wxWindow
* WXUNUSED(win
),
253 const wxRect
& rectOrig
,
256 wxRect
rect(rectOrig
);
258 int style
= DFCS_BUTTONPUSH
;
259 if ( flags
& wxCONTROL_DISABLED
)
260 style
|= DFCS_INACTIVE
;
261 if ( flags
& wxCONTROL_PRESSED
)
262 style
|= DFCS_PUSHED
| DFCS_FLAT
;
263 if ( flags
& wxCONTROL_ISDEFAULT
)
265 // DrawFrameControl() doesn't seem to support default buttons so we
266 // have to draw the border ourselves
267 wxDCPenChanger
pen(dc
, *wxBLACK_PEN
);
268 wxDCBrushChanger
brush(dc
, *wxTRANSPARENT_BRUSH
);
269 dc
.DrawRectangle(rect
);
274 wxCopyRectToRECT(rect
, rc
);
276 ::DrawFrameControl(GetHdcOf(dc
), &rc
, DFC_BUTTON
, style
);
279 // ============================================================================
280 // wxRendererXP implementation
281 // ============================================================================
286 wxRendererNative
& wxRendererXP::Get()
288 static wxRendererXP s_rendererXP
;
293 // NOTE: There is no guarantee that the button drawn fills the entire rect (XP
294 // default theme, for example), so the caller should have cleared button's
295 // background before this call. This is quite likely a wxMSW-specific thing.
297 wxRendererXP::DrawComboBoxDropButton(wxWindow
* win
,
302 wxUxThemeHandle
hTheme(win
, L
"COMBOBOX");
305 m_rendererNative
.DrawComboBoxDropButton(win
, dc
, rect
, flags
);
310 wxCopyRectToRECT(rect
, r
);
313 if ( flags
& wxCONTROL_PRESSED
)
314 state
= CBXS_PRESSED
;
315 else if ( flags
& wxCONTROL_CURRENT
)
317 else if ( flags
& wxCONTROL_DISABLED
)
318 state
= CBXS_DISABLED
;
322 wxUxThemeEngine::Get()->DrawThemeBackground
335 wxRendererXP::DrawHeaderButton(wxWindow
*win
,
339 wxHeaderSortIconType sortArrow
,
340 wxHeaderButtonParams
* params
)
342 wxUxThemeHandle
hTheme(win
, L
"HEADER");
345 return m_rendererNative
.DrawHeaderButton(win
, dc
, rect
, flags
, sortArrow
, params
);
349 wxCopyRectToRECT(rect
, r
);
352 if ( flags
& wxCONTROL_PRESSED
)
354 else if ( flags
& wxCONTROL_CURRENT
)
358 wxUxThemeEngine::Get()->DrawThemeBackground
368 // NOTE: Using the theme to draw HP_HEADERSORTARROW doesn't do anything.
369 // Why? If this can be fixed then draw the sort arrows using the theme
370 // and then clear those flags before calling DrawHeaderButtonContents.
372 // Add any extras that are specified in flags and params
373 return DrawHeaderButtonContents(win
, dc
, rect
, flags
, sortArrow
, params
);
378 wxRendererXP::GetHeaderButtonHeight(wxWindow
*win
)
380 wxUxThemeHandle
hTheme(win
, L
"HEADER");
383 return m_rendererNative
.GetHeaderButtonHeight(win
);
389 hr
= wxUxThemeEngine::Get()->GetThemeMetric( hTheme
,
403 wxRendererXP::DrawTreeItemButton(wxWindow
*win
,
408 wxUxThemeHandle
hTheme(win
, L
"TREEVIEW");
411 m_rendererNative
.DrawTreeItemButton(win
, dc
, rect
, flags
);
416 wxCopyRectToRECT(rect
, r
);
418 int state
= flags
& wxCONTROL_EXPANDED
? GLPS_OPENED
: GLPS_CLOSED
;
419 wxUxThemeEngine::Get()->DrawThemeBackground
431 wxRendererXP::DrawCheckBox(wxWindow
*win
,
436 wxUxThemeHandle
hTheme(win
, L
"BUTTON");
439 m_rendererNative
.DrawCheckBox(win
, dc
, rect
, flags
);
444 wxCopyRectToRECT(rect
, r
);
447 if ( flags
& wxCONTROL_CHECKED
)
448 state
= CBS_CHECKEDNORMAL
;
449 else if ( flags
& wxCONTROL_UNDETERMINED
)
450 state
= CBS_MIXEDNORMAL
;
452 state
= CBS_UNCHECKEDNORMAL
;
454 // CBS_XXX is followed by CBX_XXXHOT, then CBS_XXXPRESSED and DISABLED
458 CBS_PRESSED_OFFSET
= 2,
459 CBS_DISABLED_OFFSET
= 3
462 if ( flags
& wxCONTROL_DISABLED
)
463 state
+= CBS_DISABLED_OFFSET
;
464 else if ( flags
& wxCONTROL_PRESSED
)
465 state
+= CBS_PRESSED_OFFSET
;
466 else if ( flags
& wxCONTROL_CURRENT
)
467 state
+= CBS_HOT_OFFSET
;
469 wxUxThemeEngine::Get()->DrawThemeBackground
481 wxRendererXP::DrawPushButton(wxWindow
* win
,
486 wxUxThemeHandle
hTheme(win
, L
"BUTTON");
489 m_rendererNative
.DrawPushButton(win
, dc
, rect
, flags
);
494 wxCopyRectToRECT(rect
, r
);
497 if ( flags
& wxCONTROL_PRESSED
)
499 else if ( flags
& wxCONTROL_CURRENT
)
501 else if ( flags
& wxCONTROL_DISABLED
)
502 state
= PBS_DISABLED
;
503 else if ( flags
& wxCONTROL_ISDEFAULT
)
504 state
= PBS_DEFAULTED
;
508 wxUxThemeEngine::Get()->DrawThemeBackground
521 wxRendererXP::DrawItemSelectionRect(wxWindow
* WXUNUSED(win
),
527 if ( flags
& wxCONTROL_SELECTED
)
529 if ( flags
& wxCONTROL_FOCUSED
)
531 brush
= wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT
));
535 brush
= wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNSHADOW
));
540 brush
= *wxTRANSPARENT_BRUSH
;
545 // unlike for wxRendererGeneric, on windows we _never_ want to draw
546 // the outline of the rectangle:
547 dc
.SetPen(*wxTRANSPARENT_PEN
);
549 dc
.DrawRectangle( rect
);
554 // ----------------------------------------------------------------------------
556 // ----------------------------------------------------------------------------
558 // the width of the sash: this is the same as used by Explorer...
559 static const wxCoord SASH_WIDTH
= 4;
561 wxSplitterRenderParams
562 wxRendererXP::GetSplitterParams(const wxWindow
* win
)
564 if ( win
->HasFlag(wxSP_NO_XP_THEME
) )
565 return m_rendererNative
.GetSplitterParams(win
);
567 return wxSplitterRenderParams(SASH_WIDTH
, 0, false);
571 wxRendererXP::DrawSplitterBorder(wxWindow
* win
,
576 if ( win
->HasFlag(wxSP_NO_XP_THEME
) )
578 m_rendererNative
.DrawSplitterBorder(win
, dc
, rect
, flags
);
583 wxRendererXP::DrawSplitterSash(wxWindow
*win
,
587 wxOrientation orient
,
590 if ( !win
->HasFlag(wxSP_NO_XP_THEME
) )
592 dc
.SetPen(*wxTRANSPARENT_PEN
);
593 dc
.SetBrush(wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
)));
594 if ( orient
== wxVERTICAL
)
596 dc
.DrawRectangle(position
, 0, SASH_WIDTH
, size
.y
);
600 dc
.DrawRectangle(0, position
, size
.x
, SASH_WIDTH
);
606 m_rendererNative
.DrawSplitterSash(win
, dc
, size
, position
, orient
, flags
);
609 #endif // wxUSE_UXTHEME