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__) && !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 int 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 void DrawItemSelectionRect(wxWindow
*win
,
163 virtual wxSplitterRenderParams
GetSplitterParams(const wxWindow
*win
);
165 DECLARE_NO_COPY_CLASS(wxRendererXP
)
168 #endif // wxUSE_UXTHEME
170 // ============================================================================
171 // wxRendererNative and wxRendererMSW implementation
172 // ============================================================================
175 wxRendererNative
& wxRendererNative::GetDefault()
178 wxUxThemeEngine
*themeEngine
= wxUxThemeEngine::Get();
179 if ( themeEngine
&& themeEngine
->IsAppThemed() )
180 return wxRendererXP::Get();
181 #endif // wxUSE_UXTHEME
183 return wxRendererMSW::Get();
187 wxRendererNative
& wxRendererMSW::Get()
189 static wxRendererMSW s_rendererMSW
;
191 return s_rendererMSW
;
195 wxRendererMSW::DrawComboBoxDropButton(wxWindow
* WXUNUSED(win
),
201 r
.left
= rect
.GetLeft();
202 r
.top
= rect
.GetTop();
203 r
.bottom
= rect
.y
+ rect
.height
;
204 r
.right
= rect
.x
+ rect
.width
;
206 int style
= DFCS_SCROLLCOMBOBOX
;
207 if ( flags
& wxCONTROL_DISABLED
)
208 style
|= DFCS_INACTIVE
;
209 if ( flags
& wxCONTROL_PRESSED
)
210 style
|= DFCS_PUSHED
| DFCS_FLAT
;
212 ::DrawFrameControl(GetHdcOf(dc
), &r
, DFC_SCROLL
, style
);
216 wxRendererMSW::DrawPushButton(wxWindow
* WXUNUSED(win
),
218 const wxRect
& rectOrig
,
221 wxRect
rect(rectOrig
);
223 int style
= DFCS_BUTTONPUSH
;
224 if ( flags
& wxCONTROL_DISABLED
)
225 style
|= DFCS_INACTIVE
;
226 if ( flags
& wxCONTROL_PRESSED
)
227 style
|= DFCS_PUSHED
| DFCS_FLAT
;
228 if ( flags
& wxCONTROL_ISDEFAULT
)
230 // DrawFrameControl() doesn't seem to support default buttons so we
231 // have to draw the border ourselves
232 wxDCPenChanger
pen(dc
, *wxBLACK_PEN
);
233 wxDCBrushChanger
brush(dc
, *wxTRANSPARENT_BRUSH
);
234 dc
.DrawRectangle(rect
);
239 wxCopyRectToRECT(rect
, rc
);
241 ::DrawFrameControl(GetHdcOf(dc
), &rc
, DFC_BUTTON
, style
);
244 // ============================================================================
245 // wxRendererXP implementation
246 // ============================================================================
251 wxRendererNative
& wxRendererXP::Get()
253 static wxRendererXP s_rendererXP
;
258 // NOTE: There is no guarantee that the button drawn fills the entire rect (XP
259 // default theme, for example), so the caller should have cleared button's
260 // background before this call. This is quite likely a wxMSW-specific thing.
262 wxRendererXP::DrawComboBoxDropButton(wxWindow
* win
,
267 wxUxThemeHandle
hTheme(win
, L
"COMBOBOX");
270 m_rendererNative
.DrawComboBoxDropButton(win
, dc
, rect
, flags
);
275 wxCopyRectToRECT(rect
, r
);
278 if ( flags
& wxCONTROL_PRESSED
)
279 state
= CBXS_PRESSED
;
280 else if ( flags
& wxCONTROL_CURRENT
)
282 else if ( flags
& wxCONTROL_DISABLED
)
283 state
= CBXS_DISABLED
;
287 wxUxThemeEngine::Get()->DrawThemeBackground
300 wxRendererXP::DrawHeaderButton(wxWindow
*win
,
304 wxHeaderSortIconType sortArrow
,
305 wxHeaderButtonParams
* params
)
307 wxUxThemeHandle
hTheme(win
, L
"HEADER");
310 return m_rendererNative
.DrawHeaderButton(win
, dc
, rect
, flags
, sortArrow
, params
);
314 wxCopyRectToRECT(rect
, r
);
317 if ( flags
& wxCONTROL_PRESSED
)
319 else if ( flags
& wxCONTROL_CURRENT
)
323 wxUxThemeEngine::Get()->DrawThemeBackground
333 // NOTE: Using the theme to draw HP_HEADERSORTARROW doesn't do anything.
334 // Why? If this can be fixed then draw the sort arrows using the theme
335 // and then clear those flags before calling DrawHeaderButtonContents.
337 // Add any extras that are specified in flags and params
338 return DrawHeaderButtonContents(win
, dc
, rect
, flags
, sortArrow
, params
);
343 wxRendererXP::GetHeaderButtonHeight(wxWindow
*win
)
345 wxUxThemeHandle
hTheme(win
, L
"HEADER");
348 return m_rendererNative
.GetHeaderButtonHeight(win
);
354 hr
= wxUxThemeEngine::Get()->GetThemeMetric( hTheme
,
368 wxRendererXP::DrawTreeItemButton(wxWindow
*win
,
373 wxUxThemeHandle
hTheme(win
, L
"TREEVIEW");
376 m_rendererNative
.DrawTreeItemButton(win
, dc
, rect
, flags
);
381 wxCopyRectToRECT(rect
, r
);
383 int state
= flags
& wxCONTROL_EXPANDED
? GLPS_OPENED
: GLPS_CLOSED
;
384 wxUxThemeEngine::Get()->DrawThemeBackground
396 wxRendererXP::DrawCheckBox(wxWindow
*win
,
401 wxUxThemeHandle
hTheme(win
, L
"BUTTON");
404 m_rendererNative
.DrawCheckBox(win
, dc
, rect
, flags
);
409 wxCopyRectToRECT(rect
, r
);
412 if ( flags
& wxCONTROL_CHECKED
)
413 state
= CBS_CHECKEDNORMAL
;
414 else if ( flags
& wxCONTROL_UNDETERMINED
)
415 state
= CBS_MIXEDNORMAL
;
417 state
= CBS_UNCHECKEDNORMAL
;
419 // CBS_XXX is followed by CBX_XXXGOT, then CBS_XXXPRESSED and DISABLED
420 if ( flags
& wxCONTROL_CURRENT
)
422 else if ( flags
& wxCONTROL_PRESSED
)
424 else if ( flags
& wxCONTROL_DISABLED
)
427 wxUxThemeEngine::Get()->DrawThemeBackground
439 wxRendererXP::DrawPushButton(wxWindow
* win
,
444 wxUxThemeHandle
hTheme(win
, L
"BUTTON");
447 m_rendererNative
.DrawPushButton(win
, dc
, rect
, flags
);
452 wxCopyRectToRECT(rect
, r
);
455 if ( flags
& wxCONTROL_PRESSED
)
457 else if ( flags
& wxCONTROL_CURRENT
)
459 else if ( flags
& wxCONTROL_DISABLED
)
460 state
= PBS_DISABLED
;
461 else if ( flags
& wxCONTROL_ISDEFAULT
)
462 state
= PBS_DEFAULTED
;
466 wxUxThemeEngine::Get()->DrawThemeBackground
479 wxRendererXP::DrawItemSelectionRect(wxWindow
* WXUNUSED(win
),
485 if ( flags
& wxCONTROL_SELECTED
)
487 if ( flags
& wxCONTROL_FOCUSED
)
489 brush
= wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT
));
493 brush
= wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNSHADOW
));
498 brush
= *wxTRANSPARENT_BRUSH
;
503 // unlike for wxRendererGeneric, on windows we _never_ want to draw
504 // the outline of the rectangle:
505 dc
.SetPen(*wxTRANSPARENT_PEN
);
507 dc
.DrawRectangle( rect
);
512 // ----------------------------------------------------------------------------
514 // ----------------------------------------------------------------------------
516 // the width of the sash: this is the same as used by Explorer...
517 static const wxCoord SASH_WIDTH
= 4;
519 wxSplitterRenderParams
520 wxRendererXP::GetSplitterParams(const wxWindow
* win
)
522 if ( win
->HasFlag(wxSP_NO_XP_THEME
) )
523 return m_rendererNative
.GetSplitterParams(win
);
525 return wxSplitterRenderParams(SASH_WIDTH
, 0, false);
529 wxRendererXP::DrawSplitterBorder(wxWindow
* win
,
534 if ( win
->HasFlag(wxSP_NO_XP_THEME
) )
536 m_rendererNative
.DrawSplitterBorder(win
, dc
, rect
, flags
);
541 wxRendererXP::DrawSplitterSash(wxWindow
*win
,
545 wxOrientation orient
,
548 if ( !win
->HasFlag(wxSP_NO_XP_THEME
) )
550 dc
.SetPen(*wxTRANSPARENT_PEN
);
551 dc
.SetBrush(wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
)));
552 if ( orient
== wxVERTICAL
)
554 dc
.DrawRectangle(position
, 0, SASH_WIDTH
, size
.y
);
558 dc
.DrawRectangle(0, position
, size
.x
, SASH_WIDTH
);
564 m_rendererNative
.DrawSplitterSash(win
, dc
, size
, position
, orient
, flags
);
567 #endif // wxUSE_UXTHEME