implemented DrawCheckButton() for XP renderer; code cleanup
[wxWidgets.git] / src / msw / renderer.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: msw/renderer.cpp
3 // Purpose: implementation of wxRendererNative for Windows
4 // Author: Vadim Zeitlin
5 // Modified by:
6 // Created: 20.07.2003
7 // RCS-ID: $Id$
8 // Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwindows.org>
9 // License: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 // for compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
22
23 #ifdef __BORLANDC__
24 #pragma hdrstop
25 #endif
26
27 #ifndef WX_PRECOMP
28 #include "wx/string.h"
29 #include "wx/window.h"
30 #include "wx/dc.h"
31 #endif //WX_PRECOMP
32
33 #include "wx/splitter.h"
34 #include "wx/renderer.h"
35 #include "wx/settings.h"
36 #include "wx/msw/uxtheme.h"
37 #include "wx/msw/private.h"
38
39 // tmschema.h is in Win32 Platform SDK and might not be available with earlier
40 // compilers
41 #ifndef CP_DROPDOWNBUTTON
42 #define BP_CHECKBOX 3
43 #define CBS_UNCHECKEDNORMAL 1
44 #define CBS_CHECKEDNORMAL (CBS_UNCHECKEDNORMAL + 4)
45 #define CBS_MIXEDNORMAL (CBS_CHECKEDNORMAL + 4)
46
47 #define CP_DROPDOWNBUTTON 1
48
49 #define CBXS_NORMAL 1
50 #define CBXS_HOT 2
51 #define CBXS_PRESSED 3
52 #define CBXS_DISABLED 4
53
54 #define TVP_GLYPH 2
55
56 #define GLPS_CLOSED 1
57 #define GLPS_OPENED 2
58
59 #define HP_HEADERITEM 1
60
61 #define HIS_NORMAL 1
62 #define HIS_HOT 2
63 #define HIS_PRESSED 3
64 #endif
65
66 #if defined(__WXWINCE__) && !defined(DFCS_FLAT)
67 #define DFCS_FLAT 0
68 #endif
69
70 // ----------------------------------------------------------------------------
71 // wxRendererMSW: wxRendererNative implementation for "old" Win32 systems
72 // ----------------------------------------------------------------------------
73
74 class WXDLLEXPORT wxRendererMSW : public wxDelegateRendererNative
75 {
76 public:
77 wxRendererMSW() { }
78
79 static wxRendererNative& Get();
80
81 virtual void DrawComboBoxDropButton(wxWindow *win,
82 wxDC& dc,
83 const wxRect& rect,
84 int flags = 0);
85
86 private:
87 DECLARE_NO_COPY_CLASS(wxRendererMSW)
88 };
89
90 // ----------------------------------------------------------------------------
91 // wxRendererXP: wxRendererNative implementation for Windows XP and later
92 // ----------------------------------------------------------------------------
93
94 #if wxUSE_UXTHEME
95
96 class WXDLLEXPORT wxRendererXP : public wxDelegateRendererNative
97 {
98 public:
99 wxRendererXP() : wxDelegateRendererNative(wxRendererMSW::Get()) { }
100
101 static wxRendererNative& Get();
102
103 virtual void DrawHeaderButton(wxWindow *win,
104 wxDC& dc,
105 const wxRect& rect,
106 int flags = 0);
107 virtual void DrawTreeItemButton(wxWindow *win,
108 wxDC& dc,
109 const wxRect& rect,
110 int flags = 0);
111 virtual void DrawSplitterBorder(wxWindow *win,
112 wxDC& dc,
113 const wxRect& rect,
114 int flags = 0);
115 virtual void DrawSplitterSash(wxWindow *win,
116 wxDC& dc,
117 const wxSize& size,
118 wxCoord position,
119 wxOrientation orient,
120 int flags = 0);
121 virtual void DrawComboBoxDropButton(wxWindow *win,
122 wxDC& dc,
123 const wxRect& rect,
124 int flags = 0);
125 virtual void DrawCheckButton(wxWindow *win,
126 wxDC& dc,
127 const wxRect& rect,
128 int flags = 0);
129
130 virtual wxSplitterRenderParams GetSplitterParams(const wxWindow *win);
131 private:
132 DECLARE_NO_COPY_CLASS(wxRendererXP)
133 };
134
135 #endif // wxUSE_UXTHEME
136
137 // ============================================================================
138 // wxRendererNative and wxRendererMSW implementation
139 // ============================================================================
140
141 /* static */
142 wxRendererNative& wxRendererNative::GetDefault()
143 {
144 #if wxUSE_UXTHEME
145 wxUxThemeEngine *themeEngine = wxUxThemeEngine::Get();
146 if ( themeEngine && themeEngine->IsAppThemed() )
147 return wxRendererXP::Get();
148 #endif // wxUSE_UXTHEME
149
150 return wxRendererMSW::Get();
151 }
152
153 /* static */
154 wxRendererNative& wxRendererMSW::Get()
155 {
156 static wxRendererMSW s_rendererMSW;
157
158 return s_rendererMSW;
159 }
160
161 void
162 wxRendererMSW::DrawComboBoxDropButton(wxWindow * WXUNUSED(win),
163 wxDC& dc,
164 const wxRect& rect,
165 int flags)
166 {
167 RECT r;
168 r.left = rect.GetLeft();
169 r.top = rect.GetTop();
170 r.bottom = rect.y + rect.height;
171 r.right = rect.x + rect.width;
172
173 int style = DFCS_SCROLLCOMBOBOX;
174 if ( flags & wxCONTROL_DISABLED )
175 style |= DFCS_INACTIVE;
176 if ( flags & wxCONTROL_PRESSED )
177 style |= DFCS_PUSHED | DFCS_FLAT;
178
179 ::DrawFrameControl(GetHdcOf(dc), &r, DFC_SCROLL, style);
180 }
181
182 // ============================================================================
183 // wxRendererXP implementation
184 // ============================================================================
185
186 #if wxUSE_UXTHEME
187
188 /* static */
189 wxRendererNative& wxRendererXP::Get()
190 {
191 static wxRendererXP s_rendererXP;
192
193 return s_rendererXP;
194 }
195
196 // NOTE: There is no guarantee that the button drawn fills the entire rect (XP
197 // default theme, for example), so the caller should have cleared button's
198 // background before this call. This is quite likely a wxMSW-specific thing.
199 void
200 wxRendererXP::DrawComboBoxDropButton(wxWindow * win,
201 wxDC& dc,
202 const wxRect& rect,
203 int flags)
204 {
205 wxUxThemeHandle hTheme(win, L"COMBOBOX");
206 if ( !hTheme )
207 {
208 m_rendererNative.DrawComboBoxDropButton(win, dc, rect, flags);
209 return;
210 }
211
212 RECT r;
213 wxCopyRectToRECT(rect, r);
214
215 int state;
216 if ( flags & wxCONTROL_PRESSED )
217 state = CBXS_PRESSED;
218 else if ( flags & wxCONTROL_CURRENT )
219 state = CBXS_HOT;
220 else if ( flags & wxCONTROL_DISABLED )
221 state = CBXS_DISABLED;
222 else
223 state = CBXS_NORMAL;
224
225 wxUxThemeEngine::Get()->DrawThemeBackground
226 (
227 hTheme,
228 GetHdcOf(dc),
229 CP_DROPDOWNBUTTON,
230 state,
231 &r,
232 NULL
233 );
234
235 }
236
237 void
238 wxRendererXP::DrawHeaderButton(wxWindow *win,
239 wxDC& dc,
240 const wxRect& rect,
241 int flags)
242 {
243 wxUxThemeHandle hTheme(win, L"HEADER");
244 if ( !hTheme )
245 {
246 m_rendererNative.DrawHeaderButton(win, dc, rect, flags);
247 return;
248 }
249
250 RECT r;
251 wxCopyRectToRECT(rect, r);
252
253 int state;
254 if ( flags & wxCONTROL_PRESSED )
255 state = HIS_PRESSED;
256 else if ( flags & wxCONTROL_CURRENT )
257 state = HIS_HOT;
258 else
259 state = HIS_NORMAL;
260 wxUxThemeEngine::Get()->DrawThemeBackground
261 (
262 hTheme,
263 GetHdcOf(dc),
264 HP_HEADERITEM,
265 state,
266 &r,
267 NULL
268 );
269 }
270
271 void
272 wxRendererXP::DrawTreeItemButton(wxWindow *win,
273 wxDC& dc,
274 const wxRect& rect,
275 int flags)
276 {
277 wxUxThemeHandle hTheme(win, L"TREEVIEW");
278 if ( !hTheme )
279 {
280 m_rendererNative.DrawTreeItemButton(win, dc, rect, flags);
281 return;
282 }
283
284 RECT r;
285 wxCopyRectToRECT(rect, r);
286
287 int state = flags & wxCONTROL_EXPANDED ? GLPS_OPENED : GLPS_CLOSED;
288 wxUxThemeEngine::Get()->DrawThemeBackground
289 (
290 hTheme,
291 GetHdcOf(dc),
292 TVP_GLYPH,
293 state,
294 &r,
295 NULL
296 );
297 }
298
299 void
300 wxRendererXP::DrawCheckButton(wxWindow *win,
301 wxDC& dc,
302 const wxRect& rect,
303 int flags)
304 {
305 wxUxThemeHandle hTheme(win, L"BUTTON");
306 if ( !hTheme )
307 {
308 m_rendererNative.DrawCheckButton(win, dc, rect, flags);
309 return;
310 }
311
312 RECT r;
313 wxCopyRectToRECT(rect, r);
314
315 int state;
316 if ( flags & wxCONTROL_CHECKED )
317 state = CBS_CHECKEDNORMAL;
318 else if ( flags & wxCONTROL_UNDETERMINED )
319 state = CBS_MIXEDNORMAL;
320 else
321 state = CBS_UNCHECKEDNORMAL;
322
323 // CBS_XXX is followed by CBX_XXXGOT, then CBS_XXXPRESSED and DISABLED
324 if ( flags & wxCONTROL_CURRENT )
325 state += 1;
326 else if ( flags & wxCONTROL_PRESSED )
327 state += 2;
328 else if ( flags & wxCONTROL_DISABLED )
329 state += 3;
330
331 wxUxThemeEngine::Get()->DrawThemeBackground
332 (
333 hTheme,
334 GetHdcOf(dc),
335 BP_CHECKBOX,
336 state,
337 &r,
338 NULL
339 );
340 }
341
342 // ----------------------------------------------------------------------------
343 // splitter drawing
344 // ----------------------------------------------------------------------------
345
346 // the width of the sash: this is the same as used by Explorer...
347 static const wxCoord SASH_WIDTH = 4;
348
349 wxSplitterRenderParams
350 wxRendererXP::GetSplitterParams(const wxWindow * win)
351 {
352 if ( win->HasFlag(wxSP_NO_XP_THEME) )
353 return m_rendererNative.GetSplitterParams(win);
354 else
355 return wxSplitterRenderParams(SASH_WIDTH, 0, false);
356 }
357
358 void
359 wxRendererXP::DrawSplitterBorder(wxWindow * win,
360 wxDC& dc,
361 const wxRect& rect,
362 int flags)
363 {
364 if ( win->HasFlag(wxSP_NO_XP_THEME) )
365 {
366 m_rendererNative.DrawSplitterBorder(win, dc, rect, flags);
367 }
368 }
369
370 void
371 wxRendererXP::DrawSplitterSash(wxWindow *win,
372 wxDC& dc,
373 const wxSize& size,
374 wxCoord position,
375 wxOrientation orient,
376 int flags)
377 {
378 if ( !win->HasFlag(wxSP_NO_XP_THEME) )
379 {
380 dc.SetPen(*wxTRANSPARENT_PEN);
381 dc.SetBrush(wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE)));
382 if ( orient == wxVERTICAL )
383 {
384 dc.DrawRectangle(position, 0, SASH_WIDTH, size.y);
385 }
386 else // wxHORIZONTAL
387 {
388 dc.DrawRectangle(0, position, size.x, SASH_WIDTH);
389 }
390
391 return;
392 }
393
394 m_rendererNative.DrawSplitterSash(win, dc, size, position, orient, flags);
395 }
396
397 #endif // wxUSE_UXTHEME
398