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/dc.h"
39 #include "wx/msw/uxtheme.h"
41 // tmschema.h is in Win32 Platform SDK and might not be available with earlier
43 #ifndef CP_DROPDOWNBUTTON
44 #define BP_PUSHBUTTON 1
46 #define CBS_UNCHECKEDNORMAL 1
47 #define CBS_CHECKEDNORMAL (CBS_UNCHECKEDNORMAL + 4)
48 #define CBS_MIXEDNORMAL (CBS_CHECKEDNORMAL + 4)
53 #define PBS_DISABLED 4
54 #define PBS_DEFAULTED 5
56 #define CP_DROPDOWNBUTTON 1
60 #define CBXS_PRESSED 3
61 #define CBXS_DISABLED 4
68 #define HP_HEADERITEM 1
74 #define TMT_HEIGHT 2417
76 #define HP_HEADERSORTARROW 4
77 #define HSAS_SORTEDUP 1
78 #define HSAS_SORTEDDOWN 2
81 #if defined(__WXWINCE__)
91 #define DFCS_HOT 0x1000
94 // ----------------------------------------------------------------------------
95 // wxRendererMSW: wxRendererNative implementation for "old" Win32 systems
96 // ----------------------------------------------------------------------------
98 class WXDLLEXPORT wxRendererMSW
: public wxDelegateRendererNative
103 static wxRendererNative
& Get();
105 virtual void DrawComboBoxDropButton(wxWindow
*win
,
110 virtual void DrawCheckBox(wxWindow
*win
,
115 virtual void DrawPushButton(wxWindow
*win
,
120 virtual void DrawFocusRect(wxWindow
* win
,
125 virtual wxSize
GetCheckBoxSize(wxWindow
*win
);
127 virtual int GetHeaderButtonHeight(wxWindow
*win
);
130 DECLARE_NO_COPY_CLASS(wxRendererMSW
)
133 // ----------------------------------------------------------------------------
134 // wxRendererXP: wxRendererNative implementation for Windows XP and later
135 // ----------------------------------------------------------------------------
139 class WXDLLEXPORT wxRendererXP
: public wxDelegateRendererNative
142 wxRendererXP() : wxDelegateRendererNative(wxRendererMSW::Get()) { }
144 static wxRendererNative
& Get();
146 virtual int DrawHeaderButton(wxWindow
*win
,
150 wxHeaderSortIconType sortArrow
= wxHDR_SORT_ICON_NONE
,
151 wxHeaderButtonParams
* params
= NULL
);
153 virtual void DrawTreeItemButton(wxWindow
*win
,
157 virtual void DrawSplitterBorder(wxWindow
*win
,
161 virtual void DrawSplitterSash(wxWindow
*win
,
165 wxOrientation orient
,
167 virtual void DrawComboBoxDropButton(wxWindow
*win
,
171 virtual void DrawCheckBox(wxWindow
*win
,
176 virtual void DrawPushButton(wxWindow
*win
,
181 virtual void DrawItemSelectionRect(wxWindow
*win
,
187 virtual wxSplitterRenderParams
GetSplitterParams(const wxWindow
*win
);
189 DECLARE_NO_COPY_CLASS(wxRendererXP
)
192 #endif // wxUSE_UXTHEME
194 // ============================================================================
195 // wxRendererNative and wxRendererMSW implementation
196 // ============================================================================
199 wxRendererNative
& wxRendererNative::GetDefault()
202 wxUxThemeEngine
*themeEngine
= wxUxThemeEngine::Get();
203 if ( themeEngine
&& themeEngine
->IsAppThemed() )
204 return wxRendererXP::Get();
205 #endif // wxUSE_UXTHEME
207 return wxRendererMSW::Get();
211 wxRendererNative
& wxRendererMSW::Get()
213 static wxRendererMSW s_rendererMSW
;
215 return s_rendererMSW
;
219 wxRendererMSW::DrawComboBoxDropButton(wxWindow
* WXUNUSED(win
),
225 wxCopyRectToRECT(rect
, r
);
227 int style
= DFCS_SCROLLCOMBOBOX
;
228 if ( flags
& wxCONTROL_DISABLED
)
229 style
|= DFCS_INACTIVE
;
230 if ( flags
& wxCONTROL_PRESSED
)
231 style
|= DFCS_PUSHED
| DFCS_FLAT
;
233 ::DrawFrameControl(GetHdcOf(*((wxMSWDCImpl
*)dc
.GetImpl())), &r
, DFC_SCROLL
, style
);
237 wxRendererMSW::DrawCheckBox(wxWindow
* WXUNUSED(win
),
243 wxCopyRectToRECT(rect
, r
);
245 int style
= DFCS_BUTTONCHECK
;
246 if ( flags
& wxCONTROL_CHECKED
)
247 style
|= DFCS_CHECKED
;
248 if ( flags
& wxCONTROL_DISABLED
)
249 style
|= DFCS_INACTIVE
;
250 if ( flags
& wxCONTROL_FLAT
)
252 if ( flags
& wxCONTROL_PRESSED
)
253 style
|= DFCS_PUSHED
;
254 if ( flags
& wxCONTROL_CURRENT
)
257 ::DrawFrameControl(GetHdcOf(*((wxMSWDCImpl
*)dc
.GetImpl())), &r
, DFC_BUTTON
, style
);
261 wxRendererMSW::DrawPushButton(wxWindow
* WXUNUSED(win
),
263 const wxRect
& rectOrig
,
266 wxRect
rect(rectOrig
);
268 int style
= DFCS_BUTTONPUSH
;
269 if ( flags
& wxCONTROL_DISABLED
)
270 style
|= DFCS_INACTIVE
;
271 if ( flags
& wxCONTROL_PRESSED
)
272 style
|= DFCS_PUSHED
| DFCS_FLAT
;
273 if ( flags
& wxCONTROL_ISDEFAULT
)
275 // DrawFrameControl() doesn't seem to support default buttons so we
276 // have to draw the border ourselves
277 wxDCPenChanger
pen(dc
, *wxBLACK_PEN
);
278 wxDCBrushChanger
brush(dc
, *wxTRANSPARENT_BRUSH
);
279 dc
.DrawRectangle(rect
);
284 wxCopyRectToRECT(rect
, rc
);
286 ::DrawFrameControl(GetHdcOf(*((wxMSWDCImpl
*)dc
.GetImpl())), &rc
, DFC_BUTTON
, style
);
289 void wxRendererMSW::DrawFocusRect(wxWindow
* WXUNUSED(win
),
295 wxCopyRectToRECT(rect
, rc
);
297 ::DrawFocusRect(GetHdcOf(*((wxMSWDCImpl
*)dc
.GetImpl())), &rc
);
300 wxSize
wxRendererMSW::GetCheckBoxSize(wxWindow
* WXUNUSED(win
))
302 return wxSize(::GetSystemMetrics(SM_CXMENUCHECK
),
303 ::GetSystemMetrics(SM_CYMENUCHECK
));
306 int wxRendererMSW::GetHeaderButtonHeight(wxWindow
* WXUNUSED(win
))
308 // some "reasonable" value returned in case of error, it doesn't really
309 // correspond to anything but it's better than returning 0
310 static const int DEFAULT_HEIGHT
= 20;
313 // create a temporary header window just to get its geometry
314 HWND hwndHeader
= ::CreateWindow(WC_HEADER
, NULL
, 0,
315 0, 0, 0, 0, NULL
, NULL
, NULL
, NULL
);
317 return DEFAULT_HEIGHT
;
319 wxON_BLOCK_EXIT1( ::DestroyWindow
, hwndHeader
);
321 // initialize the struct filled with the values by Header_Layout()
322 RECT parentRect
= { 0, 0, 100, 100 };
323 WINDOWPOS wp
= { 0, 0, 0, 0, 0, 0, 0 };
324 HDLAYOUT hdl
= { &parentRect
, &wp
};
326 return Header_Layout(hwndHeader
, &hdl
) ? wp
.cy
: DEFAULT_HEIGHT
;
329 // ============================================================================
330 // wxRendererXP implementation
331 // ============================================================================
336 wxRendererNative
& wxRendererXP::Get()
338 static wxRendererXP s_rendererXP
;
343 // NOTE: There is no guarantee that the button drawn fills the entire rect (XP
344 // default theme, for example), so the caller should have cleared button's
345 // background before this call. This is quite likely a wxMSW-specific thing.
347 wxRendererXP::DrawComboBoxDropButton(wxWindow
* win
,
352 wxUxThemeHandle
hTheme(win
, L
"COMBOBOX");
355 m_rendererNative
.DrawComboBoxDropButton(win
, dc
, rect
, flags
);
360 wxCopyRectToRECT(rect
, r
);
363 if ( flags
& wxCONTROL_PRESSED
)
364 state
= CBXS_PRESSED
;
365 else if ( flags
& wxCONTROL_CURRENT
)
367 else if ( flags
& wxCONTROL_DISABLED
)
368 state
= CBXS_DISABLED
;
372 wxUxThemeEngine::Get()->DrawThemeBackground
375 GetHdcOf(*((wxMSWDCImpl
*)dc
.GetImpl())),
385 wxRendererXP::DrawHeaderButton(wxWindow
*win
,
389 wxHeaderSortIconType sortArrow
,
390 wxHeaderButtonParams
* params
)
392 wxUxThemeHandle
hTheme(win
, L
"HEADER");
395 return m_rendererNative
.DrawHeaderButton(win
, dc
, rect
, flags
, sortArrow
, params
);
399 wxCopyRectToRECT(rect
, r
);
402 if ( flags
& wxCONTROL_PRESSED
)
404 else if ( flags
& wxCONTROL_CURRENT
)
408 wxUxThemeEngine::Get()->DrawThemeBackground
411 GetHdcOf(*((wxMSWDCImpl
*)dc
.GetImpl())),
418 // NOTE: Using the theme to draw HP_HEADERSORTARROW doesn't do anything.
419 // Why? If this can be fixed then draw the sort arrows using the theme
420 // and then clear those flags before calling DrawHeaderButtonContents.
422 // Add any extras that are specified in flags and params
423 return DrawHeaderButtonContents(win
, dc
, rect
, flags
, sortArrow
, params
);
428 wxRendererXP::DrawTreeItemButton(wxWindow
*win
,
433 wxUxThemeHandle
hTheme(win
, L
"TREEVIEW");
436 m_rendererNative
.DrawTreeItemButton(win
, dc
, rect
, flags
);
441 wxCopyRectToRECT(rect
, r
);
443 int state
= flags
& wxCONTROL_EXPANDED
? GLPS_OPENED
: GLPS_CLOSED
;
444 wxUxThemeEngine::Get()->DrawThemeBackground
447 GetHdcOf(*((wxMSWDCImpl
*)dc
.GetImpl())),
456 wxRendererXP::DrawCheckBox(wxWindow
*win
,
461 wxUxThemeHandle
hTheme(win
, L
"BUTTON");
464 m_rendererNative
.DrawCheckBox(win
, dc
, rect
, flags
);
469 wxCopyRectToRECT(rect
, r
);
472 if ( flags
& wxCONTROL_CHECKED
)
473 state
= CBS_CHECKEDNORMAL
;
474 else if ( flags
& wxCONTROL_UNDETERMINED
)
475 state
= CBS_MIXEDNORMAL
;
477 state
= CBS_UNCHECKEDNORMAL
;
479 // CBS_XXX is followed by CBX_XXXHOT, then CBS_XXXPRESSED and DISABLED
483 CBS_PRESSED_OFFSET
= 2,
484 CBS_DISABLED_OFFSET
= 3
487 if ( flags
& wxCONTROL_DISABLED
)
488 state
+= CBS_DISABLED_OFFSET
;
489 else if ( flags
& wxCONTROL_PRESSED
)
490 state
+= CBS_PRESSED_OFFSET
;
491 else if ( flags
& wxCONTROL_CURRENT
)
492 state
+= CBS_HOT_OFFSET
;
494 wxUxThemeEngine::Get()->DrawThemeBackground
497 GetHdcOf(*((wxMSWDCImpl
*)dc
.GetImpl())),
506 wxRendererXP::DrawPushButton(wxWindow
* win
,
511 wxUxThemeHandle
hTheme(win
, L
"BUTTON");
514 m_rendererNative
.DrawPushButton(win
, dc
, rect
, flags
);
519 wxCopyRectToRECT(rect
, r
);
522 if ( flags
& wxCONTROL_PRESSED
)
524 else if ( flags
& wxCONTROL_CURRENT
)
526 else if ( flags
& wxCONTROL_DISABLED
)
527 state
= PBS_DISABLED
;
528 else if ( flags
& wxCONTROL_ISDEFAULT
)
529 state
= PBS_DEFAULTED
;
533 wxUxThemeEngine::Get()->DrawThemeBackground
536 GetHdcOf(*((wxMSWDCImpl
*)dc
.GetImpl())),
546 wxRendererXP::DrawItemSelectionRect(wxWindow
*win
,
552 if ( flags
& wxCONTROL_SELECTED
)
554 if ( flags
& wxCONTROL_FOCUSED
)
556 brush
= wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT
));
560 brush
= wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
));
565 brush
= *wxTRANSPARENT_BRUSH
;
569 dc
.SetPen(*wxTRANSPARENT_PEN
);
570 dc
.DrawRectangle( rect
);
572 if ((flags
& wxCONTROL_FOCUSED
) && (flags
& wxCONTROL_CURRENT
))
573 DrawFocusRect( win
, dc
, rect
, flags
);
578 // ----------------------------------------------------------------------------
580 // ----------------------------------------------------------------------------
582 // the width of the sash: this is the same as used by Explorer...
583 static const wxCoord SASH_WIDTH
= 4;
585 wxSplitterRenderParams
586 wxRendererXP::GetSplitterParams(const wxWindow
* win
)
588 if ( win
->HasFlag(wxSP_NO_XP_THEME
) )
589 return m_rendererNative
.GetSplitterParams(win
);
591 return wxSplitterRenderParams(SASH_WIDTH
, 0, false);
595 wxRendererXP::DrawSplitterBorder(wxWindow
* win
,
600 if ( win
->HasFlag(wxSP_NO_XP_THEME
) )
602 m_rendererNative
.DrawSplitterBorder(win
, dc
, rect
, flags
);
607 wxRendererXP::DrawSplitterSash(wxWindow
*win
,
611 wxOrientation orient
,
614 if ( !win
->HasFlag(wxSP_NO_XP_THEME
) )
616 dc
.SetPen(*wxTRANSPARENT_PEN
);
617 dc
.SetBrush(wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
)));
618 if ( orient
== wxVERTICAL
)
620 dc
.DrawRectangle(position
, 0, SASH_WIDTH
, size
.y
);
624 dc
.DrawRectangle(0, position
, size
.x
, SASH_WIDTH
);
630 m_rendererNative
.DrawSplitterSash(win
, dc
, size
, position
, orient
, flags
);
633 #endif // wxUSE_UXTHEME