]>
Commit | Line | Data |
---|---|---|
9c7f49f5 | 1 | /////////////////////////////////////////////////////////////////////////////// |
90b903c2 | 2 | // Name: src/msw/renderer.cpp |
38c4cb6a | 3 | // Purpose: implementation of wxRendererNative for Windows |
9c7f49f5 VZ |
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> | |
65571936 | 9 | // License: wxWindows licence |
9c7f49f5 VZ |
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" | |
85b657c7 VS |
29 | #include "wx/window.h" |
30 | #include "wx/dc.h" | |
9eddec69 | 31 | #include "wx/settings.h" |
9c7f49f5 VZ |
32 | #endif //WX_PRECOMP |
33 | ||
3c2544bb | 34 | #include "wx/splitter.h" |
9c7f49f5 | 35 | #include "wx/renderer.h" |
8b97949e | 36 | #include "wx/msw/uxtheme.h" |
03f01e63 | 37 | #include "wx/msw/private.h" |
8b97949e | 38 | |
7cf3223a VZ |
39 | // tmschema.h is in Win32 Platform SDK and might not be available with earlier |
40 | // compilers | |
41 | #ifndef CP_DROPDOWNBUTTON | |
2209baae | 42 | #define BP_PUSHBUTTON 1 |
9f93b45e VZ |
43 | #define BP_CHECKBOX 3 |
44 | #define CBS_UNCHECKEDNORMAL 1 | |
45 | #define CBS_CHECKEDNORMAL (CBS_UNCHECKEDNORMAL + 4) | |
46 | #define CBS_MIXEDNORMAL (CBS_CHECKEDNORMAL + 4) | |
47 | ||
2209baae RR |
48 | #define PBS_NORMAL 1 |
49 | #define PBS_HOT 2 | |
50 | #define PBS_PRESSED 3 | |
51 | #define PBS_DISABLED 4 | |
52 | #define PBS_DEFAULTED 5 | |
53 | ||
7cf3223a VZ |
54 | #define CP_DROPDOWNBUTTON 1 |
55 | ||
56 | #define CBXS_NORMAL 1 | |
57 | #define CBXS_HOT 2 | |
58 | #define CBXS_PRESSED 3 | |
59 | #define CBXS_DISABLED 4 | |
a9d9e2f2 | 60 | |
9f93b45e VZ |
61 | #define TVP_GLYPH 2 |
62 | ||
63 | #define GLPS_CLOSED 1 | |
a9d9e2f2 JS |
64 | #define GLPS_OPENED 2 |
65 | ||
66 | #define HP_HEADERITEM 1 | |
67 | ||
68 | #define HIS_NORMAL 1 | |
69 | #define HIS_HOT 2 | |
70 | #define HIS_PRESSED 3 | |
4b94ddc4 RD |
71 | |
72 | #define TMT_HEIGHT 2417 | |
73 | ||
74 | #define HP_HEADERSORTARROW 4 | |
75 | #define HSAS_SORTEDUP 1 | |
76 | #define HSAS_SORTEDDOWN 2 | |
7cf3223a VZ |
77 | #endif |
78 | ||
9f93b45e VZ |
79 | #if defined(__WXWINCE__) && !defined(DFCS_FLAT) |
80 | #define DFCS_FLAT 0 | |
81 | #endif | |
82 | ||
9c7f49f5 | 83 | // ---------------------------------------------------------------------------- |
8b97949e | 84 | // wxRendererMSW: wxRendererNative implementation for "old" Win32 systems |
9c7f49f5 VZ |
85 | // ---------------------------------------------------------------------------- |
86 | ||
38c4cb6a | 87 | class WXDLLEXPORT wxRendererMSW : public wxDelegateRendererNative |
9c7f49f5 | 88 | { |
2eb10e2a VZ |
89 | public: |
90 | wxRendererMSW() { } | |
91 | ||
8b97949e VZ |
92 | static wxRendererNative& Get(); |
93 | ||
7402677a VZ |
94 | virtual void DrawComboBoxDropButton(wxWindow *win, |
95 | wxDC& dc, | |
96 | const wxRect& rect, | |
97 | int flags = 0); | |
98 | ||
2209baae RR |
99 | virtual void DrawPushButton(wxWindow *win, |
100 | wxDC& dc, | |
101 | const wxRect& rect, | |
102 | int flags = 0); | |
103 | ||
2eb10e2a VZ |
104 | private: |
105 | DECLARE_NO_COPY_CLASS(wxRendererMSW) | |
9c7f49f5 VZ |
106 | }; |
107 | ||
8b97949e VZ |
108 | // ---------------------------------------------------------------------------- |
109 | // wxRendererXP: wxRendererNative implementation for Windows XP and later | |
110 | // ---------------------------------------------------------------------------- | |
111 | ||
7cf3223a VZ |
112 | #if wxUSE_UXTHEME |
113 | ||
8b97949e VZ |
114 | class WXDLLEXPORT wxRendererXP : public wxDelegateRendererNative |
115 | { | |
116 | public: | |
117 | wxRendererXP() : wxDelegateRendererNative(wxRendererMSW::Get()) { } | |
118 | ||
119 | static wxRendererNative& Get(); | |
120 | ||
9f93b45e | 121 | virtual void DrawHeaderButton(wxWindow *win, |
4b94ddc4 RD |
122 | wxDC& dc, |
123 | const wxRect& rect, | |
124 | int flags = 0, | |
80752b57 | 125 | wxHeaderSortIconType sortArrow = wxHDR_SORT_ICON_NONE, |
4b94ddc4 RD |
126 | wxHeaderButtonParams* params = NULL); |
127 | virtual int GetHeaderButtonHeight(wxWindow *win); | |
128 | ||
9f93b45e VZ |
129 | virtual void DrawTreeItemButton(wxWindow *win, |
130 | wxDC& dc, | |
131 | const wxRect& rect, | |
132 | int flags = 0); | |
8b97949e VZ |
133 | virtual void DrawSplitterBorder(wxWindow *win, |
134 | wxDC& dc, | |
c4e6c15e VZ |
135 | const wxRect& rect, |
136 | int flags = 0); | |
8b97949e VZ |
137 | virtual void DrawSplitterSash(wxWindow *win, |
138 | wxDC& dc, | |
139 | const wxSize& size, | |
140 | wxCoord position, | |
c4e6c15e VZ |
141 | wxOrientation orient, |
142 | int flags = 0); | |
7cf3223a VZ |
143 | virtual void DrawComboBoxDropButton(wxWindow *win, |
144 | wxDC& dc, | |
145 | const wxRect& rect, | |
146 | int flags = 0); | |
90b903c2 WS |
147 | virtual void DrawCheckBox(wxWindow *win, |
148 | wxDC& dc, | |
149 | const wxRect& rect, | |
150 | int flags = 0); | |
9f93b45e | 151 | |
2209baae RR |
152 | virtual void DrawPushButton(wxWindow *win, |
153 | wxDC& dc, | |
154 | const wxRect& rect, | |
155 | int flags = 0); | |
156 | ||
9f93b45e | 157 | virtual wxSplitterRenderParams GetSplitterParams(const wxWindow *win); |
8b97949e VZ |
158 | private: |
159 | DECLARE_NO_COPY_CLASS(wxRendererXP) | |
160 | }; | |
161 | ||
7cf3223a VZ |
162 | #endif // wxUSE_UXTHEME |
163 | ||
9c7f49f5 | 164 | // ============================================================================ |
8b97949e | 165 | // wxRendererNative and wxRendererMSW implementation |
9c7f49f5 VZ |
166 | // ============================================================================ |
167 | ||
168 | /* static */ | |
f0244295 | 169 | wxRendererNative& wxRendererNative::GetDefault() |
8b97949e | 170 | { |
7cf3223a | 171 | #if wxUSE_UXTHEME |
8b97949e | 172 | wxUxThemeEngine *themeEngine = wxUxThemeEngine::Get(); |
7cf3223a VZ |
173 | if ( themeEngine && themeEngine->IsAppThemed() ) |
174 | return wxRendererXP::Get(); | |
175 | #endif // wxUSE_UXTHEME | |
176 | ||
177 | return wxRendererMSW::Get(); | |
8b97949e VZ |
178 | } |
179 | ||
180 | /* static */ | |
181 | wxRendererNative& wxRendererMSW::Get() | |
9c7f49f5 VZ |
182 | { |
183 | static wxRendererMSW s_rendererMSW; | |
184 | ||
185 | return s_rendererMSW; | |
186 | } | |
187 | ||
7402677a VZ |
188 | void |
189 | wxRendererMSW::DrawComboBoxDropButton(wxWindow * WXUNUSED(win), | |
190 | wxDC& dc, | |
191 | const wxRect& rect, | |
192 | int flags) | |
193 | { | |
194 | RECT r; | |
195 | r.left = rect.GetLeft(); | |
196 | r.top = rect.GetTop(); | |
7cf3223a VZ |
197 | r.bottom = rect.y + rect.height; |
198 | r.right = rect.x + rect.width; | |
7402677a VZ |
199 | |
200 | int style = DFCS_SCROLLCOMBOBOX; | |
201 | if ( flags & wxCONTROL_DISABLED ) | |
202 | style |= DFCS_INACTIVE; | |
203 | if ( flags & wxCONTROL_PRESSED ) | |
7cf3223a | 204 | style |= DFCS_PUSHED | DFCS_FLAT; |
7402677a VZ |
205 | |
206 | ::DrawFrameControl(GetHdcOf(dc), &r, DFC_SCROLL, style); | |
207 | } | |
208 | ||
2209baae RR |
209 | void |
210 | wxRendererMSW::DrawPushButton(wxWindow * WXUNUSED(win), | |
211 | wxDC& dc, | |
212 | const wxRect& rect, | |
213 | int flags) | |
214 | { | |
215 | RECT r; | |
216 | r.left = rect.GetLeft(); | |
217 | r.top = rect.GetTop(); | |
218 | r.bottom = rect.y + rect.height; | |
219 | r.right = rect.x + rect.width; | |
220 | ||
221 | int style = DFCS_BUTTONPUSH; | |
222 | if ( flags & wxCONTROL_DISABLED ) | |
223 | style |= DFCS_INACTIVE; | |
224 | if ( flags & wxCONTROL_PRESSED ) | |
225 | style |= DFCS_PUSHED | DFCS_FLAT; | |
226 | ||
227 | ::DrawFrameControl(GetHdcOf(dc), &r, DFC_BUTTON, style); | |
228 | } | |
229 | ||
8b97949e VZ |
230 | // ============================================================================ |
231 | // wxRendererXP implementation | |
232 | // ============================================================================ | |
233 | ||
7cf3223a VZ |
234 | #if wxUSE_UXTHEME |
235 | ||
8b97949e VZ |
236 | /* static */ |
237 | wxRendererNative& wxRendererXP::Get() | |
238 | { | |
239 | static wxRendererXP s_rendererXP; | |
240 | ||
241 | return s_rendererXP; | |
242 | } | |
243 | ||
7cf3223a VZ |
244 | // NOTE: There is no guarantee that the button drawn fills the entire rect (XP |
245 | // default theme, for example), so the caller should have cleared button's | |
246 | // background before this call. This is quite likely a wxMSW-specific thing. | |
247 | void | |
248 | wxRendererXP::DrawComboBoxDropButton(wxWindow * win, | |
249 | wxDC& dc, | |
250 | const wxRect& rect, | |
251 | int flags) | |
252 | { | |
253 | wxUxThemeHandle hTheme(win, L"COMBOBOX"); | |
9f93b45e | 254 | if ( !hTheme ) |
7cf3223a | 255 | { |
9f93b45e VZ |
256 | m_rendererNative.DrawComboBoxDropButton(win, dc, rect, flags); |
257 | return; | |
258 | } | |
259 | ||
260 | RECT r; | |
261 | wxCopyRectToRECT(rect, r); | |
7cf3223a | 262 | |
9f93b45e VZ |
263 | int state; |
264 | if ( flags & wxCONTROL_PRESSED ) | |
265 | state = CBXS_PRESSED; | |
266 | else if ( flags & wxCONTROL_CURRENT ) | |
267 | state = CBXS_HOT; | |
268 | else if ( flags & wxCONTROL_DISABLED ) | |
269 | state = CBXS_DISABLED; | |
270 | else | |
271 | state = CBXS_NORMAL; | |
272 | ||
273 | wxUxThemeEngine::Get()->DrawThemeBackground | |
274 | ( | |
275 | hTheme, | |
276 | GetHdcOf(dc), | |
277 | CP_DROPDOWNBUTTON, | |
278 | state, | |
279 | &r, | |
280 | NULL | |
281 | ); | |
282 | ||
283 | } | |
284 | ||
285 | void | |
286 | wxRendererXP::DrawHeaderButton(wxWindow *win, | |
287 | wxDC& dc, | |
288 | const wxRect& rect, | |
4b94ddc4 | 289 | int flags, |
80752b57 | 290 | wxHeaderSortIconType sortArrow, |
4b94ddc4 | 291 | wxHeaderButtonParams* params) |
9f93b45e VZ |
292 | { |
293 | wxUxThemeHandle hTheme(win, L"HEADER"); | |
294 | if ( !hTheme ) | |
295 | { | |
80752b57 | 296 | m_rendererNative.DrawHeaderButton(win, dc, rect, flags, sortArrow, params); |
9f93b45e | 297 | return; |
7cf3223a | 298 | } |
9f93b45e VZ |
299 | |
300 | RECT r; | |
301 | wxCopyRectToRECT(rect, r); | |
302 | ||
303 | int state; | |
304 | if ( flags & wxCONTROL_PRESSED ) | |
305 | state = HIS_PRESSED; | |
306 | else if ( flags & wxCONTROL_CURRENT ) | |
307 | state = HIS_HOT; | |
308 | else | |
309 | state = HIS_NORMAL; | |
310 | wxUxThemeEngine::Get()->DrawThemeBackground | |
311 | ( | |
312 | hTheme, | |
313 | GetHdcOf(dc), | |
314 | HP_HEADERITEM, | |
315 | state, | |
316 | &r, | |
317 | NULL | |
318 | ); | |
4b94ddc4 RD |
319 | |
320 | // NOTE: Using the theme to draw HP_HEADERSORTARROW doesn't do anything. | |
321 | // Why? If this can be fixed then draw the sort arrows using the theme | |
322 | // and then clear those flags before calling DrawHeaderButtonContents. | |
323 | ||
324 | // Add any extras that are specified in flags and params | |
80752b57 | 325 | DrawHeaderButtonContents(win, dc, rect, flags, sortArrow, params); |
9f93b45e VZ |
326 | } |
327 | ||
4b94ddc4 RD |
328 | |
329 | int | |
330 | wxRendererXP::GetHeaderButtonHeight(wxWindow *win) | |
331 | { | |
332 | wxUxThemeHandle hTheme(win, L"HEADER"); | |
333 | if ( !hTheme ) | |
334 | { | |
335 | return m_rendererNative.GetHeaderButtonHeight(win); | |
336 | } | |
337 | ||
338 | HRESULT hr; | |
339 | int value = -1; | |
340 | ||
341 | hr = wxUxThemeEngine::Get()->GetThemeMetric( hTheme, | |
342 | NULL, | |
343 | HP_HEADERITEM, | |
344 | HIS_NORMAL, | |
345 | TMT_HEIGHT, | |
346 | &value ); | |
347 | if ( hr == S_OK ) | |
348 | return value; | |
349 | else | |
350 | return 20; | |
351 | } | |
352 | ||
353 | ||
9f93b45e VZ |
354 | void |
355 | wxRendererXP::DrawTreeItemButton(wxWindow *win, | |
356 | wxDC& dc, | |
357 | const wxRect& rect, | |
358 | int flags) | |
359 | { | |
360 | wxUxThemeHandle hTheme(win, L"TREEVIEW"); | |
361 | if ( !hTheme ) | |
362 | { | |
363 | m_rendererNative.DrawTreeItemButton(win, dc, rect, flags); | |
364 | return; | |
365 | } | |
366 | ||
367 | RECT r; | |
368 | wxCopyRectToRECT(rect, r); | |
369 | ||
370 | int state = flags & wxCONTROL_EXPANDED ? GLPS_OPENED : GLPS_CLOSED; | |
371 | wxUxThemeEngine::Get()->DrawThemeBackground | |
372 | ( | |
373 | hTheme, | |
374 | GetHdcOf(dc), | |
375 | TVP_GLYPH, | |
376 | state, | |
377 | &r, | |
378 | NULL | |
379 | ); | |
380 | } | |
381 | ||
382 | void | |
90b903c2 WS |
383 | wxRendererXP::DrawCheckBox(wxWindow *win, |
384 | wxDC& dc, | |
385 | const wxRect& rect, | |
386 | int flags) | |
9f93b45e VZ |
387 | { |
388 | wxUxThemeHandle hTheme(win, L"BUTTON"); | |
389 | if ( !hTheme ) | |
390 | { | |
90b903c2 | 391 | m_rendererNative.DrawCheckBox(win, dc, rect, flags); |
9f93b45e VZ |
392 | return; |
393 | } | |
394 | ||
395 | RECT r; | |
396 | wxCopyRectToRECT(rect, r); | |
397 | ||
398 | int state; | |
399 | if ( flags & wxCONTROL_CHECKED ) | |
400 | state = CBS_CHECKEDNORMAL; | |
401 | else if ( flags & wxCONTROL_UNDETERMINED ) | |
402 | state = CBS_MIXEDNORMAL; | |
403 | else | |
404 | state = CBS_UNCHECKEDNORMAL; | |
405 | ||
406 | // CBS_XXX is followed by CBX_XXXGOT, then CBS_XXXPRESSED and DISABLED | |
407 | if ( flags & wxCONTROL_CURRENT ) | |
408 | state += 1; | |
409 | else if ( flags & wxCONTROL_PRESSED ) | |
410 | state += 2; | |
411 | else if ( flags & wxCONTROL_DISABLED ) | |
412 | state += 3; | |
413 | ||
414 | wxUxThemeEngine::Get()->DrawThemeBackground | |
415 | ( | |
416 | hTheme, | |
417 | GetHdcOf(dc), | |
418 | BP_CHECKBOX, | |
419 | state, | |
420 | &r, | |
421 | NULL | |
422 | ); | |
7cf3223a VZ |
423 | } |
424 | ||
2209baae RR |
425 | void |
426 | wxRendererXP::DrawPushButton(wxWindow * win, | |
427 | wxDC& dc, | |
428 | const wxRect& rect, | |
429 | int flags) | |
430 | { | |
431 | wxUxThemeHandle hTheme(win, L"BUTTON"); | |
432 | if ( !hTheme ) | |
433 | { | |
434 | m_rendererNative.DrawPushButton(win, dc, rect, flags); | |
435 | return; | |
436 | } | |
437 | ||
438 | RECT r; | |
439 | wxCopyRectToRECT(rect, r); | |
440 | ||
441 | int state; | |
442 | if ( flags & wxCONTROL_PRESSED ) | |
443 | state = PBS_PRESSED; | |
444 | else if ( flags & wxCONTROL_CURRENT ) | |
445 | state = PBS_HOT; | |
446 | else if ( flags & wxCONTROL_DISABLED ) | |
447 | state = PBS_DISABLED; | |
448 | else if ( flags & wxCONTROL_ISDEFAULT ) | |
449 | state = PBS_DEFAULTED; | |
450 | else | |
451 | state = PBS_NORMAL; | |
452 | ||
453 | wxUxThemeEngine::Get()->DrawThemeBackground | |
454 | ( | |
455 | hTheme, | |
456 | GetHdcOf(dc), | |
457 | BP_PUSHBUTTON, | |
458 | state, | |
459 | &r, | |
460 | NULL | |
461 | ); | |
462 | ||
463 | } | |
464 | ||
8b97949e VZ |
465 | // ---------------------------------------------------------------------------- |
466 | // splitter drawing | |
467 | // ---------------------------------------------------------------------------- | |
468 | ||
469 | // the width of the sash: this is the same as used by Explorer... | |
470 | static const wxCoord SASH_WIDTH = 4; | |
471 | ||
c4e6c15e | 472 | wxSplitterRenderParams |
3c2544bb | 473 | wxRendererXP::GetSplitterParams(const wxWindow * win) |
8b97949e | 474 | { |
9f93b45e | 475 | if ( win->HasFlag(wxSP_NO_XP_THEME) ) |
3c2544bb JS |
476 | return m_rendererNative.GetSplitterParams(win); |
477 | else | |
478 | return wxSplitterRenderParams(SASH_WIDTH, 0, false); | |
8b97949e VZ |
479 | } |
480 | ||
481 | void | |
3c2544bb JS |
482 | wxRendererXP::DrawSplitterBorder(wxWindow * win, |
483 | wxDC& dc, | |
484 | const wxRect& rect, | |
485 | int flags) | |
8b97949e | 486 | { |
9f93b45e | 487 | if ( win->HasFlag(wxSP_NO_XP_THEME) ) |
3c2544bb JS |
488 | { |
489 | m_rendererNative.DrawSplitterBorder(win, dc, rect, flags); | |
490 | } | |
8b97949e VZ |
491 | } |
492 | ||
493 | void | |
494 | wxRendererXP::DrawSplitterSash(wxWindow *win, | |
495 | wxDC& dc, | |
496 | const wxSize& size, | |
497 | wxCoord position, | |
c4e6c15e | 498 | wxOrientation orient, |
3c2544bb | 499 | int flags) |
8b97949e | 500 | { |
6421119d | 501 | if ( !win->HasFlag(wxSP_NO_XP_THEME) ) |
8b97949e | 502 | { |
fe404d1a JS |
503 | dc.SetPen(*wxTRANSPARENT_PEN); |
504 | dc.SetBrush(wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE))); | |
505 | if ( orient == wxVERTICAL ) | |
8b97949e | 506 | { |
fe404d1a | 507 | dc.DrawRectangle(position, 0, SASH_WIDTH, size.y); |
8b97949e | 508 | } |
fe404d1a JS |
509 | else // wxHORIZONTAL |
510 | { | |
511 | dc.DrawRectangle(0, position, size.x, SASH_WIDTH); | |
512 | } | |
513 | ||
514 | return; | |
8b97949e | 515 | } |
6421119d VZ |
516 | |
517 | m_rendererNative.DrawSplitterSash(win, dc, size, position, orient, flags); | |
8b97949e VZ |
518 | } |
519 | ||
7cf3223a | 520 | #endif // wxUSE_UXTHEME |