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 int GetHeaderButtonHeight(wxWindow
*win
);
128 DECLARE_NO_COPY_CLASS(wxRendererMSW
)
131 // ----------------------------------------------------------------------------
132 // wxRendererXP: wxRendererNative implementation for Windows XP and later
133 // ----------------------------------------------------------------------------
137 class WXDLLEXPORT wxRendererXP
: public wxDelegateRendererNative
140 wxRendererXP() : wxDelegateRendererNative(wxRendererMSW::Get()) { }
142 static wxRendererNative
& Get();
144 virtual int DrawHeaderButton(wxWindow
*win
,
148 wxHeaderSortIconType sortArrow
= wxHDR_SORT_ICON_NONE
,
149 wxHeaderButtonParams
* params
= NULL
);
151 virtual void DrawTreeItemButton(wxWindow
*win
,
155 virtual void DrawSplitterBorder(wxWindow
*win
,
159 virtual void DrawSplitterSash(wxWindow
*win
,
163 wxOrientation orient
,
165 virtual void DrawComboBoxDropButton(wxWindow
*win
,
169 virtual void DrawCheckBox(wxWindow
*win
,
174 virtual void DrawPushButton(wxWindow
*win
,
179 virtual void DrawItemSelectionRect(wxWindow
*win
,
185 virtual wxSplitterRenderParams
GetSplitterParams(const wxWindow
*win
);
187 DECLARE_NO_COPY_CLASS(wxRendererXP
)
190 #endif // wxUSE_UXTHEME
192 // ============================================================================
193 // wxRendererNative and wxRendererMSW implementation
194 // ============================================================================
197 wxRendererNative
& wxRendererNative::GetDefault()
200 wxUxThemeEngine
*themeEngine
= wxUxThemeEngine::Get();
201 if ( themeEngine
&& themeEngine
->IsAppThemed() )
202 return wxRendererXP::Get();
203 #endif // wxUSE_UXTHEME
205 return wxRendererMSW::Get();
209 wxRendererNative
& wxRendererMSW::Get()
211 static wxRendererMSW s_rendererMSW
;
213 return s_rendererMSW
;
217 wxRendererMSW::DrawComboBoxDropButton(wxWindow
* WXUNUSED(win
),
223 wxCopyRectToRECT(rect
, r
);
225 int style
= DFCS_SCROLLCOMBOBOX
;
226 if ( flags
& wxCONTROL_DISABLED
)
227 style
|= DFCS_INACTIVE
;
228 if ( flags
& wxCONTROL_PRESSED
)
229 style
|= DFCS_PUSHED
| DFCS_FLAT
;
231 ::DrawFrameControl(GetHdcOf(*((wxMSWDCImpl
*)dc
.GetImpl())), &r
, DFC_SCROLL
, style
);
235 wxRendererMSW::DrawCheckBox(wxWindow
* WXUNUSED(win
),
241 wxCopyRectToRECT(rect
, r
);
243 int style
= DFCS_BUTTONCHECK
;
244 if ( flags
& wxCONTROL_CHECKED
)
245 style
|= DFCS_CHECKED
;
246 if ( flags
& wxCONTROL_DISABLED
)
247 style
|= DFCS_INACTIVE
;
248 if ( flags
& wxCONTROL_FLAT
)
250 if ( flags
& wxCONTROL_PRESSED
)
251 style
|= DFCS_PUSHED
;
252 if ( flags
& wxCONTROL_CURRENT
)
255 ::DrawFrameControl(GetHdcOf(*((wxMSWDCImpl
*)dc
.GetImpl())), &r
, DFC_BUTTON
, style
);
259 wxRendererMSW::DrawPushButton(wxWindow
* WXUNUSED(win
),
261 const wxRect
& rectOrig
,
264 wxRect
rect(rectOrig
);
266 int style
= DFCS_BUTTONPUSH
;
267 if ( flags
& wxCONTROL_DISABLED
)
268 style
|= DFCS_INACTIVE
;
269 if ( flags
& wxCONTROL_PRESSED
)
270 style
|= DFCS_PUSHED
| DFCS_FLAT
;
271 if ( flags
& wxCONTROL_ISDEFAULT
)
273 // DrawFrameControl() doesn't seem to support default buttons so we
274 // have to draw the border ourselves
275 wxDCPenChanger
pen(dc
, *wxBLACK_PEN
);
276 wxDCBrushChanger
brush(dc
, *wxTRANSPARENT_BRUSH
);
277 dc
.DrawRectangle(rect
);
282 wxCopyRectToRECT(rect
, rc
);
284 ::DrawFrameControl(GetHdcOf(*((wxMSWDCImpl
*)dc
.GetImpl())), &rc
, DFC_BUTTON
, style
);
287 void wxRendererMSW::DrawFocusRect(wxWindow
* WXUNUSED(win
),
293 wxCopyRectToRECT(rect
, rc
);
295 ::DrawFocusRect(GetHdcOf(*((wxMSWDCImpl
*)dc
.GetImpl())), &rc
);
298 int wxRendererMSW::GetHeaderButtonHeight(wxWindow
* WXUNUSED(win
))
300 // some "reasonable" value returned in case of error, it doesn't really
301 // correspond to anything but it's better than returning 0
302 static const int DEFAULT_HEIGHT
= 20;
305 // create a temporary header window just to get its geometry
306 HWND hwndHeader
= ::CreateWindow(WC_HEADER
, NULL
, 0,
307 0, 0, 0, 0, NULL
, NULL
, NULL
, NULL
);
309 return DEFAULT_HEIGHT
;
311 wxON_BLOCK_EXIT1( ::DestroyWindow
, hwndHeader
);
313 // initialize the struct filled with the values by Header_Layout()
314 RECT parentRect
= { 0, 0, 100, 100 };
315 WINDOWPOS wp
= { 0, 0, 0, 0, 0, 0, 0 };
316 HDLAYOUT hdl
= { &parentRect
, &wp
};
318 return Header_Layout(hwndHeader
, &hdl
) ? wp
.cy
: DEFAULT_HEIGHT
;
321 // ============================================================================
322 // wxRendererXP implementation
323 // ============================================================================
328 wxRendererNative
& wxRendererXP::Get()
330 static wxRendererXP s_rendererXP
;
335 // NOTE: There is no guarantee that the button drawn fills the entire rect (XP
336 // default theme, for example), so the caller should have cleared button's
337 // background before this call. This is quite likely a wxMSW-specific thing.
339 wxRendererXP::DrawComboBoxDropButton(wxWindow
* win
,
344 wxUxThemeHandle
hTheme(win
, L
"COMBOBOX");
347 m_rendererNative
.DrawComboBoxDropButton(win
, dc
, rect
, flags
);
352 wxCopyRectToRECT(rect
, r
);
355 if ( flags
& wxCONTROL_PRESSED
)
356 state
= CBXS_PRESSED
;
357 else if ( flags
& wxCONTROL_CURRENT
)
359 else if ( flags
& wxCONTROL_DISABLED
)
360 state
= CBXS_DISABLED
;
364 wxUxThemeEngine::Get()->DrawThemeBackground
367 GetHdcOf(*((wxMSWDCImpl
*)dc
.GetImpl())),
377 wxRendererXP::DrawHeaderButton(wxWindow
*win
,
381 wxHeaderSortIconType sortArrow
,
382 wxHeaderButtonParams
* params
)
384 wxUxThemeHandle
hTheme(win
, L
"HEADER");
387 return m_rendererNative
.DrawHeaderButton(win
, dc
, rect
, flags
, sortArrow
, params
);
391 wxCopyRectToRECT(rect
, r
);
394 if ( flags
& wxCONTROL_PRESSED
)
396 else if ( flags
& wxCONTROL_CURRENT
)
400 wxUxThemeEngine::Get()->DrawThemeBackground
403 GetHdcOf(*((wxMSWDCImpl
*)dc
.GetImpl())),
410 // NOTE: Using the theme to draw HP_HEADERSORTARROW doesn't do anything.
411 // Why? If this can be fixed then draw the sort arrows using the theme
412 // and then clear those flags before calling DrawHeaderButtonContents.
414 // Add any extras that are specified in flags and params
415 return DrawHeaderButtonContents(win
, dc
, rect
, flags
, sortArrow
, params
);
420 wxRendererXP::DrawTreeItemButton(wxWindow
*win
,
425 wxUxThemeHandle
hTheme(win
, L
"TREEVIEW");
428 m_rendererNative
.DrawTreeItemButton(win
, dc
, rect
, flags
);
433 wxCopyRectToRECT(rect
, r
);
435 int state
= flags
& wxCONTROL_EXPANDED
? GLPS_OPENED
: GLPS_CLOSED
;
436 wxUxThemeEngine::Get()->DrawThemeBackground
439 GetHdcOf(*((wxMSWDCImpl
*)dc
.GetImpl())),
448 wxRendererXP::DrawCheckBox(wxWindow
*win
,
453 wxUxThemeHandle
hTheme(win
, L
"BUTTON");
456 m_rendererNative
.DrawCheckBox(win
, dc
, rect
, flags
);
461 wxCopyRectToRECT(rect
, r
);
464 if ( flags
& wxCONTROL_CHECKED
)
465 state
= CBS_CHECKEDNORMAL
;
466 else if ( flags
& wxCONTROL_UNDETERMINED
)
467 state
= CBS_MIXEDNORMAL
;
469 state
= CBS_UNCHECKEDNORMAL
;
471 // CBS_XXX is followed by CBX_XXXHOT, then CBS_XXXPRESSED and DISABLED
475 CBS_PRESSED_OFFSET
= 2,
476 CBS_DISABLED_OFFSET
= 3
479 if ( flags
& wxCONTROL_DISABLED
)
480 state
+= CBS_DISABLED_OFFSET
;
481 else if ( flags
& wxCONTROL_PRESSED
)
482 state
+= CBS_PRESSED_OFFSET
;
483 else if ( flags
& wxCONTROL_CURRENT
)
484 state
+= CBS_HOT_OFFSET
;
486 wxUxThemeEngine::Get()->DrawThemeBackground
489 GetHdcOf(*((wxMSWDCImpl
*)dc
.GetImpl())),
498 wxRendererXP::DrawPushButton(wxWindow
* win
,
503 wxUxThemeHandle
hTheme(win
, L
"BUTTON");
506 m_rendererNative
.DrawPushButton(win
, dc
, rect
, flags
);
511 wxCopyRectToRECT(rect
, r
);
514 if ( flags
& wxCONTROL_PRESSED
)
516 else if ( flags
& wxCONTROL_CURRENT
)
518 else if ( flags
& wxCONTROL_DISABLED
)
519 state
= PBS_DISABLED
;
520 else if ( flags
& wxCONTROL_ISDEFAULT
)
521 state
= PBS_DEFAULTED
;
525 wxUxThemeEngine::Get()->DrawThemeBackground
528 GetHdcOf(*((wxMSWDCImpl
*)dc
.GetImpl())),
538 wxRendererXP::DrawItemSelectionRect(wxWindow
*win
,
544 if ( flags
& wxCONTROL_SELECTED
)
546 if ( flags
& wxCONTROL_FOCUSED
)
548 brush
= wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT
));
552 brush
= wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE
));
557 brush
= *wxTRANSPARENT_BRUSH
;
561 dc
.SetPen(*wxTRANSPARENT_PEN
);
562 dc
.DrawRectangle( rect
);
564 if ((flags
& wxCONTROL_FOCUSED
) && (flags
& wxCONTROL_CURRENT
))
565 DrawFocusRect( win
, dc
, rect
, flags
);
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