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/scopeguard.h"
35 #include "wx/splitter.h"
36 #include "wx/renderer.h"
37 #include "wx/msw/private.h"
38 #include "wx/msw/uxtheme.h"
40 // tmschema.h is in Win32 Platform SDK and might not be available with earlier
42 #ifndef CP_DROPDOWNBUTTON
43 #define BP_PUSHBUTTON 1
45 #define CBS_UNCHECKEDNORMAL 1
46 #define CBS_CHECKEDNORMAL (CBS_UNCHECKEDNORMAL + 4)
47 #define CBS_MIXEDNORMAL (CBS_CHECKEDNORMAL + 4)
52 #define PBS_DISABLED 4
53 #define PBS_DEFAULTED 5
55 #define CP_DROPDOWNBUTTON 1
59 #define CBXS_PRESSED 3
60 #define CBXS_DISABLED 4
67 #define HP_HEADERITEM 1
73 #define TMT_HEIGHT 2417
75 #define HP_HEADERSORTARROW 4
76 #define HSAS_SORTEDUP 1
77 #define HSAS_SORTEDDOWN 2
80 #if defined(__WXWINCE__)
90 #define DFCS_HOT 0x1000
93 // ----------------------------------------------------------------------------
94 // wxRendererMSW: wxRendererNative implementation for "old" Win32 systems
95 // ----------------------------------------------------------------------------
97 class WXDLLEXPORT wxRendererMSW
: public wxDelegateRendererNative
102 static wxRendererNative
& Get();
104 virtual void DrawComboBoxDropButton(wxWindow
*win
,
109 virtual void DrawCheckBox(wxWindow
*win
,
114 virtual void DrawPushButton(wxWindow
*win
,
119 virtual void DrawFocusRect(wxWindow
* win
,
124 virtual int GetHeaderButtonHeight(wxWindow
*win
);
127 DECLARE_NO_COPY_CLASS(wxRendererMSW
)
130 // ----------------------------------------------------------------------------
131 // wxRendererXP: wxRendererNative implementation for Windows XP and later
132 // ----------------------------------------------------------------------------
136 class WXDLLEXPORT wxRendererXP
: public wxDelegateRendererNative
139 wxRendererXP() : wxDelegateRendererNative(wxRendererMSW::Get()) { }
141 static wxRendererNative
& Get();
143 virtual int DrawHeaderButton(wxWindow
*win
,
147 wxHeaderSortIconType sortArrow
= wxHDR_SORT_ICON_NONE
,
148 wxHeaderButtonParams
* params
= NULL
);
150 virtual void DrawTreeItemButton(wxWindow
*win
,
154 virtual void DrawSplitterBorder(wxWindow
*win
,
158 virtual void DrawSplitterSash(wxWindow
*win
,
162 wxOrientation orient
,
164 virtual void DrawComboBoxDropButton(wxWindow
*win
,
168 virtual void DrawCheckBox(wxWindow
*win
,
173 virtual void DrawPushButton(wxWindow
*win
,
178 virtual void DrawItemSelectionRect(wxWindow
*win
,
184 virtual wxSplitterRenderParams
GetSplitterParams(const wxWindow
*win
);
186 DECLARE_NO_COPY_CLASS(wxRendererXP
)
189 #endif // wxUSE_UXTHEME
191 // ============================================================================
192 // wxRendererNative and wxRendererMSW implementation
193 // ============================================================================
196 wxRendererNative
& wxRendererNative::GetDefault()
199 wxUxThemeEngine
*themeEngine
= wxUxThemeEngine::Get();
200 if ( themeEngine
&& themeEngine
->IsAppThemed() )
201 return wxRendererXP::Get();
202 #endif // wxUSE_UXTHEME
204 return wxRendererMSW::Get();
208 wxRendererNative
& wxRendererMSW::Get()
210 static wxRendererMSW s_rendererMSW
;
212 return s_rendererMSW
;
216 wxRendererMSW::DrawComboBoxDropButton(wxWindow
* WXUNUSED(win
),
222 wxCopyRectToRECT(rect
, r
);
224 int style
= DFCS_SCROLLCOMBOBOX
;
225 if ( flags
& wxCONTROL_DISABLED
)
226 style
|= DFCS_INACTIVE
;
227 if ( flags
& wxCONTROL_PRESSED
)
228 style
|= DFCS_PUSHED
| DFCS_FLAT
;
230 ::DrawFrameControl(GetHdcOf(dc
), &r
, DFC_SCROLL
, style
);
234 wxRendererMSW::DrawCheckBox(wxWindow
* WXUNUSED(win
),
240 wxCopyRectToRECT(rect
, r
);
242 int style
= DFCS_BUTTONCHECK
;
243 if ( flags
& wxCONTROL_CHECKED
)
244 style
|= DFCS_CHECKED
;
245 if ( flags
& wxCONTROL_DISABLED
)
246 style
|= DFCS_INACTIVE
;
247 if ( flags
& wxCONTROL_FLAT
)
249 if ( flags
& wxCONTROL_PRESSED
)
250 style
|= DFCS_PUSHED
;
251 if ( flags
& wxCONTROL_CURRENT
)
254 ::DrawFrameControl(GetHdcOf(dc
), &r
, DFC_BUTTON
, style
);
258 wxRendererMSW::DrawPushButton(wxWindow
* WXUNUSED(win
),
260 const wxRect
& rectOrig
,
263 wxRect
rect(rectOrig
);
265 int style
= DFCS_BUTTONPUSH
;
266 if ( flags
& wxCONTROL_DISABLED
)
267 style
|= DFCS_INACTIVE
;
268 if ( flags
& wxCONTROL_PRESSED
)
269 style
|= DFCS_PUSHED
| DFCS_FLAT
;
270 if ( flags
& wxCONTROL_ISDEFAULT
)
272 // DrawFrameControl() doesn't seem to support default buttons so we
273 // have to draw the border ourselves
274 wxDCPenChanger
pen(dc
, *wxBLACK_PEN
);
275 wxDCBrushChanger
brush(dc
, *wxTRANSPARENT_BRUSH
);
276 dc
.DrawRectangle(rect
);
281 wxCopyRectToRECT(rect
, rc
);
283 ::DrawFrameControl(GetHdcOf(dc
), &rc
, DFC_BUTTON
, style
);
286 void wxRendererMSW::DrawFocusRect(wxWindow
* WXUNUSED(win
),
292 wxCopyRectToRECT(rect
, rc
);
294 ::DrawFocusRect(GetHdcOf(dc
), &rc
);
297 int wxRendererMSW::GetHeaderButtonHeight(wxWindow
* WXUNUSED(win
))
299 // some "reasonable" value returned in case of error, it doesn't really
300 // correspond to anything but it's better than returning 0
301 static const int DEFAULT_HEIGHT
= 20;
304 // create a temporary header window just to get its geometry
305 HWND hwndHeader
= ::CreateWindow(WC_HEADER
, NULL
, 0,
306 0, 0, 0, 0, NULL
, NULL
, NULL
, NULL
);
308 return DEFAULT_HEIGHT
;
310 wxON_BLOCK_EXIT1( ::DestroyWindow
, hwndHeader
);
312 // initialize the struct filled with the values by Header_Layout()
313 RECT parentRect
= { 0, 0, 100, 100 };
314 WINDOWPOS wp
= { 0, 0, 0, 0, 0, 0, 0 };
315 HDLAYOUT hdl
= { &parentRect
, &wp
};
317 return Header_Layout(hwndHeader
, &hdl
) ? wp
.cy
: DEFAULT_HEIGHT
;
320 // ============================================================================
321 // wxRendererXP implementation
322 // ============================================================================
327 wxRendererNative
& wxRendererXP::Get()
329 static wxRendererXP s_rendererXP
;
334 // NOTE: There is no guarantee that the button drawn fills the entire rect (XP
335 // default theme, for example), so the caller should have cleared button's
336 // background before this call. This is quite likely a wxMSW-specific thing.
338 wxRendererXP::DrawComboBoxDropButton(wxWindow
* win
,
343 wxUxThemeHandle
hTheme(win
, L
"COMBOBOX");
346 m_rendererNative
.DrawComboBoxDropButton(win
, dc
, rect
, flags
);
351 wxCopyRectToRECT(rect
, r
);
354 if ( flags
& wxCONTROL_PRESSED
)
355 state
= CBXS_PRESSED
;
356 else if ( flags
& wxCONTROL_CURRENT
)
358 else if ( flags
& wxCONTROL_DISABLED
)
359 state
= CBXS_DISABLED
;
363 wxUxThemeEngine::Get()->DrawThemeBackground
376 wxRendererXP::DrawHeaderButton(wxWindow
*win
,
380 wxHeaderSortIconType sortArrow
,
381 wxHeaderButtonParams
* params
)
383 wxUxThemeHandle
hTheme(win
, L
"HEADER");
386 return m_rendererNative
.DrawHeaderButton(win
, dc
, rect
, flags
, sortArrow
, params
);
390 wxCopyRectToRECT(rect
, r
);
393 if ( flags
& wxCONTROL_PRESSED
)
395 else if ( flags
& wxCONTROL_CURRENT
)
399 wxUxThemeEngine::Get()->DrawThemeBackground
409 // NOTE: Using the theme to draw HP_HEADERSORTARROW doesn't do anything.
410 // Why? If this can be fixed then draw the sort arrows using the theme
411 // and then clear those flags before calling DrawHeaderButtonContents.
413 // Add any extras that are specified in flags and params
414 return DrawHeaderButtonContents(win
, dc
, rect
, flags
, sortArrow
, params
);
419 wxRendererXP::DrawTreeItemButton(wxWindow
*win
,
424 wxUxThemeHandle
hTheme(win
, L
"TREEVIEW");
427 m_rendererNative
.DrawTreeItemButton(win
, dc
, rect
, flags
);
432 wxCopyRectToRECT(rect
, r
);
434 int state
= flags
& wxCONTROL_EXPANDED
? GLPS_OPENED
: GLPS_CLOSED
;
435 wxUxThemeEngine::Get()->DrawThemeBackground
447 wxRendererXP::DrawCheckBox(wxWindow
*win
,
452 wxUxThemeHandle
hTheme(win
, L
"BUTTON");
455 m_rendererNative
.DrawCheckBox(win
, dc
, rect
, flags
);
460 wxCopyRectToRECT(rect
, r
);
463 if ( flags
& wxCONTROL_CHECKED
)
464 state
= CBS_CHECKEDNORMAL
;
465 else if ( flags
& wxCONTROL_UNDETERMINED
)
466 state
= CBS_MIXEDNORMAL
;
468 state
= CBS_UNCHECKEDNORMAL
;
470 // CBS_XXX is followed by CBX_XXXHOT, then CBS_XXXPRESSED and DISABLED
474 CBS_PRESSED_OFFSET
= 2,
475 CBS_DISABLED_OFFSET
= 3
478 if ( flags
& wxCONTROL_DISABLED
)
479 state
+= CBS_DISABLED_OFFSET
;
480 else if ( flags
& wxCONTROL_PRESSED
)
481 state
+= CBS_PRESSED_OFFSET
;
482 else if ( flags
& wxCONTROL_CURRENT
)
483 state
+= CBS_HOT_OFFSET
;
485 wxUxThemeEngine::Get()->DrawThemeBackground
497 wxRendererXP::DrawPushButton(wxWindow
* win
,
502 wxUxThemeHandle
hTheme(win
, L
"BUTTON");
505 m_rendererNative
.DrawPushButton(win
, dc
, rect
, flags
);
510 wxCopyRectToRECT(rect
, r
);
513 if ( flags
& wxCONTROL_PRESSED
)
515 else if ( flags
& wxCONTROL_CURRENT
)
517 else if ( flags
& wxCONTROL_DISABLED
)
518 state
= PBS_DISABLED
;
519 else if ( flags
& wxCONTROL_ISDEFAULT
)
520 state
= PBS_DEFAULTED
;
524 wxUxThemeEngine::Get()->DrawThemeBackground
537 wxRendererXP::DrawItemSelectionRect(wxWindow
* WXUNUSED(win
),
543 if ( flags
& wxCONTROL_SELECTED
)
545 if ( flags
& wxCONTROL_FOCUSED
)
547 brush
= wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT
));
551 brush
= wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNSHADOW
));
556 brush
= *wxTRANSPARENT_BRUSH
;
561 // unlike for wxRendererGeneric, on windows we _never_ want to draw
562 // the outline of the rectangle:
563 dc
.SetPen(*wxTRANSPARENT_PEN
);
565 dc
.DrawRectangle( rect
);
570 // ----------------------------------------------------------------------------
572 // ----------------------------------------------------------------------------
574 // the width of the sash: this is the same as used by Explorer...
575 static const wxCoord SASH_WIDTH
= 4;
577 wxSplitterRenderParams
578 wxRendererXP::GetSplitterParams(const wxWindow
* win
)
580 if ( win
->HasFlag(wxSP_NO_XP_THEME
) )
581 return m_rendererNative
.GetSplitterParams(win
);
583 return wxSplitterRenderParams(SASH_WIDTH
, 0, false);
587 wxRendererXP::DrawSplitterBorder(wxWindow
* win
,
592 if ( win
->HasFlag(wxSP_NO_XP_THEME
) )
594 m_rendererNative
.DrawSplitterBorder(win
, dc
, rect
, flags
);
599 wxRendererXP::DrawSplitterSash(wxWindow
*win
,
603 wxOrientation orient
,
606 if ( !win
->HasFlag(wxSP_NO_XP_THEME
) )
608 dc
.SetPen(*wxTRANSPARENT_PEN
);
609 dc
.SetBrush(wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
)));
610 if ( orient
== wxVERTICAL
)
612 dc
.DrawRectangle(position
, 0, SASH_WIDTH
, size
.y
);
616 dc
.DrawRectangle(0, position
, size
.x
, SASH_WIDTH
);
622 m_rendererNative
.DrawSplitterSash(win
, dc
, size
, position
, orient
, flags
);
625 #endif // wxUSE_UXTHEME