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
,
118 virtual void DrawFocusRect(wxWindow
* win
, wxDC
& dc
, const wxRect
& rect
, int flags
= 0);
120 DECLARE_NO_COPY_CLASS(wxRendererMSW
)
123 // ----------------------------------------------------------------------------
124 // wxRendererXP: wxRendererNative implementation for Windows XP and later
125 // ----------------------------------------------------------------------------
129 class WXDLLEXPORT wxRendererXP
: public wxDelegateRendererNative
132 wxRendererXP() : wxDelegateRendererNative(wxRendererMSW::Get()) { }
134 static wxRendererNative
& Get();
136 virtual int DrawHeaderButton(wxWindow
*win
,
140 wxHeaderSortIconType sortArrow
= wxHDR_SORT_ICON_NONE
,
141 wxHeaderButtonParams
* params
= NULL
);
142 virtual int GetHeaderButtonHeight(wxWindow
*win
);
144 virtual void DrawTreeItemButton(wxWindow
*win
,
148 virtual void DrawSplitterBorder(wxWindow
*win
,
152 virtual void DrawSplitterSash(wxWindow
*win
,
156 wxOrientation orient
,
158 virtual void DrawComboBoxDropButton(wxWindow
*win
,
162 virtual void DrawCheckBox(wxWindow
*win
,
167 virtual void DrawPushButton(wxWindow
*win
,
172 virtual void DrawItemSelectionRect(wxWindow
*win
,
178 virtual wxSplitterRenderParams
GetSplitterParams(const wxWindow
*win
);
180 DECLARE_NO_COPY_CLASS(wxRendererXP
)
183 #endif // wxUSE_UXTHEME
185 // ============================================================================
186 // wxRendererNative and wxRendererMSW implementation
187 // ============================================================================
190 wxRendererNative
& wxRendererNative::GetDefault()
193 wxUxThemeEngine
*themeEngine
= wxUxThemeEngine::Get();
194 if ( themeEngine
&& themeEngine
->IsAppThemed() )
195 return wxRendererXP::Get();
196 #endif // wxUSE_UXTHEME
198 return wxRendererMSW::Get();
202 wxRendererNative
& wxRendererMSW::Get()
204 static wxRendererMSW s_rendererMSW
;
206 return s_rendererMSW
;
210 wxRendererMSW::DrawComboBoxDropButton(wxWindow
* WXUNUSED(win
),
216 wxCopyRectToRECT(rect
, r
);
218 int style
= DFCS_SCROLLCOMBOBOX
;
219 if ( flags
& wxCONTROL_DISABLED
)
220 style
|= DFCS_INACTIVE
;
221 if ( flags
& wxCONTROL_PRESSED
)
222 style
|= DFCS_PUSHED
| DFCS_FLAT
;
224 ::DrawFrameControl(GetHdcOf(dc
), &r
, DFC_SCROLL
, style
);
228 wxRendererMSW::DrawCheckBox(wxWindow
* WXUNUSED(win
),
234 wxCopyRectToRECT(rect
, r
);
236 int style
= DFCS_BUTTONCHECK
;
237 if ( flags
& wxCONTROL_CHECKED
)
238 style
|= DFCS_CHECKED
;
239 if ( flags
& wxCONTROL_DISABLED
)
240 style
|= DFCS_INACTIVE
;
241 if ( flags
& wxCONTROL_FLAT
)
243 if ( flags
& wxCONTROL_PRESSED
)
244 style
|= DFCS_PUSHED
;
245 if ( flags
& wxCONTROL_CURRENT
)
248 ::DrawFrameControl(GetHdcOf(dc
), &r
, DFC_BUTTON
, style
);
252 wxRendererMSW::DrawPushButton(wxWindow
* WXUNUSED(win
),
254 const wxRect
& rectOrig
,
257 wxRect
rect(rectOrig
);
259 int style
= DFCS_BUTTONPUSH
;
260 if ( flags
& wxCONTROL_DISABLED
)
261 style
|= DFCS_INACTIVE
;
262 if ( flags
& wxCONTROL_PRESSED
)
263 style
|= DFCS_PUSHED
| DFCS_FLAT
;
264 if ( flags
& wxCONTROL_ISDEFAULT
)
266 // DrawFrameControl() doesn't seem to support default buttons so we
267 // have to draw the border ourselves
268 wxDCPenChanger
pen(dc
, *wxBLACK_PEN
);
269 wxDCBrushChanger
brush(dc
, *wxTRANSPARENT_BRUSH
);
270 dc
.DrawRectangle(rect
);
275 wxCopyRectToRECT(rect
, rc
);
277 ::DrawFrameControl(GetHdcOf(dc
), &rc
, DFC_BUTTON
, style
);
280 void wxRendererMSW::DrawFocusRect(wxWindow
* WXUNUSED(win
), wxDC
& dc
, const wxRect
& rect
, int WXUNUSED(flags
))
283 wxCopyRectToRECT(rect
, rc
);
285 ::DrawFocusRect(GetHdcOf(dc
), &rc
);
288 // ============================================================================
289 // wxRendererXP implementation
290 // ============================================================================
295 wxRendererNative
& wxRendererXP::Get()
297 static wxRendererXP s_rendererXP
;
302 // NOTE: There is no guarantee that the button drawn fills the entire rect (XP
303 // default theme, for example), so the caller should have cleared button's
304 // background before this call. This is quite likely a wxMSW-specific thing.
306 wxRendererXP::DrawComboBoxDropButton(wxWindow
* win
,
311 wxUxThemeHandle
hTheme(win
, L
"COMBOBOX");
314 m_rendererNative
.DrawComboBoxDropButton(win
, dc
, rect
, flags
);
319 wxCopyRectToRECT(rect
, r
);
322 if ( flags
& wxCONTROL_PRESSED
)
323 state
= CBXS_PRESSED
;
324 else if ( flags
& wxCONTROL_CURRENT
)
326 else if ( flags
& wxCONTROL_DISABLED
)
327 state
= CBXS_DISABLED
;
331 wxUxThemeEngine::Get()->DrawThemeBackground
344 wxRendererXP::DrawHeaderButton(wxWindow
*win
,
348 wxHeaderSortIconType sortArrow
,
349 wxHeaderButtonParams
* params
)
351 wxUxThemeHandle
hTheme(win
, L
"HEADER");
354 return m_rendererNative
.DrawHeaderButton(win
, dc
, rect
, flags
, sortArrow
, params
);
358 wxCopyRectToRECT(rect
, r
);
361 if ( flags
& wxCONTROL_PRESSED
)
363 else if ( flags
& wxCONTROL_CURRENT
)
367 wxUxThemeEngine::Get()->DrawThemeBackground
377 // NOTE: Using the theme to draw HP_HEADERSORTARROW doesn't do anything.
378 // Why? If this can be fixed then draw the sort arrows using the theme
379 // and then clear those flags before calling DrawHeaderButtonContents.
381 // Add any extras that are specified in flags and params
382 return DrawHeaderButtonContents(win
, dc
, rect
, flags
, sortArrow
, params
);
387 wxRendererXP::GetHeaderButtonHeight(wxWindow
*win
)
389 wxUxThemeHandle
hTheme(win
, L
"HEADER");
392 return m_rendererNative
.GetHeaderButtonHeight(win
);
398 hr
= wxUxThemeEngine::Get()->GetThemeMetric( hTheme
,
412 wxRendererXP::DrawTreeItemButton(wxWindow
*win
,
417 wxUxThemeHandle
hTheme(win
, L
"TREEVIEW");
420 m_rendererNative
.DrawTreeItemButton(win
, dc
, rect
, flags
);
425 wxCopyRectToRECT(rect
, r
);
427 int state
= flags
& wxCONTROL_EXPANDED
? GLPS_OPENED
: GLPS_CLOSED
;
428 wxUxThemeEngine::Get()->DrawThemeBackground
440 wxRendererXP::DrawCheckBox(wxWindow
*win
,
445 wxUxThemeHandle
hTheme(win
, L
"BUTTON");
448 m_rendererNative
.DrawCheckBox(win
, dc
, rect
, flags
);
453 wxCopyRectToRECT(rect
, r
);
456 if ( flags
& wxCONTROL_CHECKED
)
457 state
= CBS_CHECKEDNORMAL
;
458 else if ( flags
& wxCONTROL_UNDETERMINED
)
459 state
= CBS_MIXEDNORMAL
;
461 state
= CBS_UNCHECKEDNORMAL
;
463 // CBS_XXX is followed by CBX_XXXHOT, then CBS_XXXPRESSED and DISABLED
467 CBS_PRESSED_OFFSET
= 2,
468 CBS_DISABLED_OFFSET
= 3
471 if ( flags
& wxCONTROL_DISABLED
)
472 state
+= CBS_DISABLED_OFFSET
;
473 else if ( flags
& wxCONTROL_PRESSED
)
474 state
+= CBS_PRESSED_OFFSET
;
475 else if ( flags
& wxCONTROL_CURRENT
)
476 state
+= CBS_HOT_OFFSET
;
478 wxUxThemeEngine::Get()->DrawThemeBackground
490 wxRendererXP::DrawPushButton(wxWindow
* win
,
495 wxUxThemeHandle
hTheme(win
, L
"BUTTON");
498 m_rendererNative
.DrawPushButton(win
, dc
, rect
, flags
);
503 wxCopyRectToRECT(rect
, r
);
506 if ( flags
& wxCONTROL_PRESSED
)
508 else if ( flags
& wxCONTROL_CURRENT
)
510 else if ( flags
& wxCONTROL_DISABLED
)
511 state
= PBS_DISABLED
;
512 else if ( flags
& wxCONTROL_ISDEFAULT
)
513 state
= PBS_DEFAULTED
;
517 wxUxThemeEngine::Get()->DrawThemeBackground
530 wxRendererXP::DrawItemSelectionRect(wxWindow
* WXUNUSED(win
),
536 if ( flags
& wxCONTROL_SELECTED
)
538 if ( flags
& wxCONTROL_FOCUSED
)
540 brush
= wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT
));
544 brush
= wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNSHADOW
));
549 brush
= *wxTRANSPARENT_BRUSH
;
554 // unlike for wxRendererGeneric, on windows we _never_ want to draw
555 // the outline of the rectangle:
556 dc
.SetPen(*wxTRANSPARENT_PEN
);
558 dc
.DrawRectangle( rect
);
563 // ----------------------------------------------------------------------------
565 // ----------------------------------------------------------------------------
567 // the width of the sash: this is the same as used by Explorer...
568 static const wxCoord SASH_WIDTH
= 4;
570 wxSplitterRenderParams
571 wxRendererXP::GetSplitterParams(const wxWindow
* win
)
573 if ( win
->HasFlag(wxSP_NO_XP_THEME
) )
574 return m_rendererNative
.GetSplitterParams(win
);
576 return wxSplitterRenderParams(SASH_WIDTH
, 0, false);
580 wxRendererXP::DrawSplitterBorder(wxWindow
* win
,
585 if ( win
->HasFlag(wxSP_NO_XP_THEME
) )
587 m_rendererNative
.DrawSplitterBorder(win
, dc
, rect
, flags
);
592 wxRendererXP::DrawSplitterSash(wxWindow
*win
,
596 wxOrientation orient
,
599 if ( !win
->HasFlag(wxSP_NO_XP_THEME
) )
601 dc
.SetPen(*wxTRANSPARENT_PEN
);
602 dc
.SetBrush(wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
)));
603 if ( orient
== wxVERTICAL
)
605 dc
.DrawRectangle(position
, 0, SASH_WIDTH
, size
.y
);
609 dc
.DrawRectangle(0, position
, size
.x
, SASH_WIDTH
);
615 m_rendererNative
.DrawSplitterSash(win
, dc
, size
, position
, orient
, flags
);
618 #endif // wxUSE_UXTHEME