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)
84 #define DFCS_HOT 0x1000
87 // ----------------------------------------------------------------------------
88 // wxRendererMSW: wxRendererNative implementation for "old" Win32 systems
89 // ----------------------------------------------------------------------------
91 class WXDLLEXPORT wxRendererMSW
: public wxDelegateRendererNative
96 static wxRendererNative
& Get();
98 virtual void DrawComboBoxDropButton(wxWindow
*win
,
103 virtual void DrawCheckBox(wxWindow
*win
,
108 virtual void DrawPushButton(wxWindow
*win
,
114 DECLARE_NO_COPY_CLASS(wxRendererMSW
)
117 // ----------------------------------------------------------------------------
118 // wxRendererXP: wxRendererNative implementation for Windows XP and later
119 // ----------------------------------------------------------------------------
123 class WXDLLEXPORT wxRendererXP
: public wxDelegateRendererNative
126 wxRendererXP() : wxDelegateRendererNative(wxRendererMSW::Get()) { }
128 static wxRendererNative
& Get();
130 virtual int DrawHeaderButton(wxWindow
*win
,
134 wxHeaderSortIconType sortArrow
= wxHDR_SORT_ICON_NONE
,
135 wxHeaderButtonParams
* params
= NULL
);
136 virtual int GetHeaderButtonHeight(wxWindow
*win
);
138 virtual void DrawTreeItemButton(wxWindow
*win
,
142 virtual void DrawSplitterBorder(wxWindow
*win
,
146 virtual void DrawSplitterSash(wxWindow
*win
,
150 wxOrientation orient
,
152 virtual void DrawComboBoxDropButton(wxWindow
*win
,
156 virtual void DrawCheckBox(wxWindow
*win
,
161 virtual void DrawPushButton(wxWindow
*win
,
166 virtual void DrawItemSelectionRect(wxWindow
*win
,
172 virtual wxSplitterRenderParams
GetSplitterParams(const wxWindow
*win
);
174 DECLARE_NO_COPY_CLASS(wxRendererXP
)
177 #endif // wxUSE_UXTHEME
179 // ============================================================================
180 // wxRendererNative and wxRendererMSW implementation
181 // ============================================================================
184 wxRendererNative
& wxRendererNative::GetDefault()
187 wxUxThemeEngine
*themeEngine
= wxUxThemeEngine::Get();
188 if ( themeEngine
&& themeEngine
->IsAppThemed() )
189 return wxRendererXP::Get();
190 #endif // wxUSE_UXTHEME
192 return wxRendererMSW::Get();
196 wxRendererNative
& wxRendererMSW::Get()
198 static wxRendererMSW s_rendererMSW
;
200 return s_rendererMSW
;
204 wxRendererMSW::DrawComboBoxDropButton(wxWindow
* WXUNUSED(win
),
210 wxCopyRectToRECT(rect
, r
);
212 int style
= DFCS_SCROLLCOMBOBOX
;
213 if ( flags
& wxCONTROL_DISABLED
)
214 style
|= DFCS_INACTIVE
;
215 if ( flags
& wxCONTROL_PRESSED
)
216 style
|= DFCS_PUSHED
| DFCS_FLAT
;
218 ::DrawFrameControl(GetHdcOf(dc
), &r
, DFC_SCROLL
, style
);
222 wxRendererMSW::DrawCheckBox(wxWindow
* WXUNUSED(win
),
228 wxCopyRectToRECT(rect
, r
);
230 int style
= DFCS_BUTTONCHECK
;
231 if ( flags
& wxCONTROL_CHECKED
)
232 style
|= DFCS_CHECKED
;
233 if ( flags
& wxCONTROL_DISABLED
)
234 style
|= DFCS_INACTIVE
;
235 if ( flags
& wxCONTROL_FLAT
)
237 if ( flags
& wxCONTROL_PRESSED
)
238 style
|= DFCS_PUSHED
;
239 if ( flags
& wxCONTROL_CURRENT
)
242 ::DrawFrameControl(GetHdcOf(dc
), &r
, DFC_BUTTON
, style
);
246 wxRendererMSW::DrawPushButton(wxWindow
* WXUNUSED(win
),
248 const wxRect
& rectOrig
,
251 wxRect
rect(rectOrig
);
253 int style
= DFCS_BUTTONPUSH
;
254 if ( flags
& wxCONTROL_DISABLED
)
255 style
|= DFCS_INACTIVE
;
256 if ( flags
& wxCONTROL_PRESSED
)
257 style
|= DFCS_PUSHED
| DFCS_FLAT
;
258 if ( flags
& wxCONTROL_ISDEFAULT
)
260 // DrawFrameControl() doesn't seem to support default buttons so we
261 // have to draw the border ourselves
262 wxDCPenChanger
pen(dc
, *wxBLACK_PEN
);
263 wxDCBrushChanger
brush(dc
, *wxTRANSPARENT_BRUSH
);
264 dc
.DrawRectangle(rect
);
269 wxCopyRectToRECT(rect
, rc
);
271 ::DrawFrameControl(GetHdcOf(dc
), &rc
, DFC_BUTTON
, style
);
274 // ============================================================================
275 // wxRendererXP implementation
276 // ============================================================================
281 wxRendererNative
& wxRendererXP::Get()
283 static wxRendererXP s_rendererXP
;
288 // NOTE: There is no guarantee that the button drawn fills the entire rect (XP
289 // default theme, for example), so the caller should have cleared button's
290 // background before this call. This is quite likely a wxMSW-specific thing.
292 wxRendererXP::DrawComboBoxDropButton(wxWindow
* win
,
297 wxUxThemeHandle
hTheme(win
, L
"COMBOBOX");
300 m_rendererNative
.DrawComboBoxDropButton(win
, dc
, rect
, flags
);
305 wxCopyRectToRECT(rect
, r
);
308 if ( flags
& wxCONTROL_PRESSED
)
309 state
= CBXS_PRESSED
;
310 else if ( flags
& wxCONTROL_CURRENT
)
312 else if ( flags
& wxCONTROL_DISABLED
)
313 state
= CBXS_DISABLED
;
317 wxUxThemeEngine::Get()->DrawThemeBackground
330 wxRendererXP::DrawHeaderButton(wxWindow
*win
,
334 wxHeaderSortIconType sortArrow
,
335 wxHeaderButtonParams
* params
)
337 wxUxThemeHandle
hTheme(win
, L
"HEADER");
340 return m_rendererNative
.DrawHeaderButton(win
, dc
, rect
, flags
, sortArrow
, params
);
344 wxCopyRectToRECT(rect
, r
);
347 if ( flags
& wxCONTROL_PRESSED
)
349 else if ( flags
& wxCONTROL_CURRENT
)
353 wxUxThemeEngine::Get()->DrawThemeBackground
363 // NOTE: Using the theme to draw HP_HEADERSORTARROW doesn't do anything.
364 // Why? If this can be fixed then draw the sort arrows using the theme
365 // and then clear those flags before calling DrawHeaderButtonContents.
367 // Add any extras that are specified in flags and params
368 return DrawHeaderButtonContents(win
, dc
, rect
, flags
, sortArrow
, params
);
373 wxRendererXP::GetHeaderButtonHeight(wxWindow
*win
)
375 wxUxThemeHandle
hTheme(win
, L
"HEADER");
378 return m_rendererNative
.GetHeaderButtonHeight(win
);
384 hr
= wxUxThemeEngine::Get()->GetThemeMetric( hTheme
,
398 wxRendererXP::DrawTreeItemButton(wxWindow
*win
,
403 wxUxThemeHandle
hTheme(win
, L
"TREEVIEW");
406 m_rendererNative
.DrawTreeItemButton(win
, dc
, rect
, flags
);
411 wxCopyRectToRECT(rect
, r
);
413 int state
= flags
& wxCONTROL_EXPANDED
? GLPS_OPENED
: GLPS_CLOSED
;
414 wxUxThemeEngine::Get()->DrawThemeBackground
426 wxRendererXP::DrawCheckBox(wxWindow
*win
,
431 wxUxThemeHandle
hTheme(win
, L
"BUTTON");
434 m_rendererNative
.DrawCheckBox(win
, dc
, rect
, flags
);
439 wxCopyRectToRECT(rect
, r
);
442 if ( flags
& wxCONTROL_CHECKED
)
443 state
= CBS_CHECKEDNORMAL
;
444 else if ( flags
& wxCONTROL_UNDETERMINED
)
445 state
= CBS_MIXEDNORMAL
;
447 state
= CBS_UNCHECKEDNORMAL
;
449 // CBS_XXX is followed by CBX_XXXHOT, then CBS_XXXPRESSED and DISABLED
453 CBS_PRESSED_OFFSET
= 2,
454 CBS_DISABLED_OFFSET
= 3
457 if ( flags
& wxCONTROL_DISABLED
)
458 state
+= CBS_DISABLED_OFFSET
;
459 else if ( flags
& wxCONTROL_PRESSED
)
460 state
+= CBS_PRESSED_OFFSET
;
461 else if ( flags
& wxCONTROL_CURRENT
)
462 state
+= CBS_HOT_OFFSET
;
464 wxUxThemeEngine::Get()->DrawThemeBackground
476 wxRendererXP::DrawPushButton(wxWindow
* win
,
481 wxUxThemeHandle
hTheme(win
, L
"BUTTON");
484 m_rendererNative
.DrawPushButton(win
, dc
, rect
, flags
);
489 wxCopyRectToRECT(rect
, r
);
492 if ( flags
& wxCONTROL_PRESSED
)
494 else if ( flags
& wxCONTROL_CURRENT
)
496 else if ( flags
& wxCONTROL_DISABLED
)
497 state
= PBS_DISABLED
;
498 else if ( flags
& wxCONTROL_ISDEFAULT
)
499 state
= PBS_DEFAULTED
;
503 wxUxThemeEngine::Get()->DrawThemeBackground
516 wxRendererXP::DrawItemSelectionRect(wxWindow
* WXUNUSED(win
),
522 if ( flags
& wxCONTROL_SELECTED
)
524 if ( flags
& wxCONTROL_FOCUSED
)
526 brush
= wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT
));
530 brush
= wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNSHADOW
));
535 brush
= *wxTRANSPARENT_BRUSH
;
540 // unlike for wxRendererGeneric, on windows we _never_ want to draw
541 // the outline of the rectangle:
542 dc
.SetPen(*wxTRANSPARENT_PEN
);
544 dc
.DrawRectangle( rect
);
549 // ----------------------------------------------------------------------------
551 // ----------------------------------------------------------------------------
553 // the width of the sash: this is the same as used by Explorer...
554 static const wxCoord SASH_WIDTH
= 4;
556 wxSplitterRenderParams
557 wxRendererXP::GetSplitterParams(const wxWindow
* win
)
559 if ( win
->HasFlag(wxSP_NO_XP_THEME
) )
560 return m_rendererNative
.GetSplitterParams(win
);
562 return wxSplitterRenderParams(SASH_WIDTH
, 0, false);
566 wxRendererXP::DrawSplitterBorder(wxWindow
* win
,
571 if ( win
->HasFlag(wxSP_NO_XP_THEME
) )
573 m_rendererNative
.DrawSplitterBorder(win
, dc
, rect
, flags
);
578 wxRendererXP::DrawSplitterSash(wxWindow
*win
,
582 wxOrientation orient
,
585 if ( !win
->HasFlag(wxSP_NO_XP_THEME
) )
587 dc
.SetPen(*wxTRANSPARENT_PEN
);
588 dc
.SetBrush(wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
)));
589 if ( orient
== wxVERTICAL
)
591 dc
.DrawRectangle(position
, 0, SASH_WIDTH
, size
.y
);
595 dc
.DrawRectangle(0, position
, size
.x
, SASH_WIDTH
);
601 m_rendererNative
.DrawSplitterSash(win
, dc
, size
, position
, orient
, flags
);
604 #endif // wxUSE_UXTHEME