]>
Commit | Line | Data |
---|---|---|
1 | /////////////////////////////////////////////////////////////////////////////// | |
2 | // Name: src/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 | #include "wx/settings.h" | |
32 | #endif //WX_PRECOMP | |
33 | ||
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" | |
40 | ||
41 | #if wxUSE_GRAPHICS_CONTEXT | |
42 | // TODO remove this dependency (gdiplus needs the macros) | |
43 | #ifndef max | |
44 | #define max(a,b) (((a) > (b)) ? (a) : (b)) | |
45 | #endif | |
46 | ||
47 | #ifndef min | |
48 | #define min(a,b) (((a) < (b)) ? (a) : (b)) | |
49 | #endif | |
50 | ||
51 | #include "wx/dcgraph.h" | |
52 | #include "gdiplus.h" | |
53 | using namespace Gdiplus; | |
54 | #endif // wxUSE_GRAPHICS_CONTEXT | |
55 | ||
56 | // tmschema.h is in Win32 Platform SDK and might not be available with earlier | |
57 | // compilers | |
58 | #ifndef CP_DROPDOWNBUTTON | |
59 | #define BP_PUSHBUTTON 1 | |
60 | #define BP_RADIOBUTTON 2 | |
61 | #define BP_CHECKBOX 3 | |
62 | #define RBS_UNCHECKEDNORMAL 1 | |
63 | #define RBS_CHECKEDNORMAL (RBS_UNCHECKEDNORMAL + 4) | |
64 | #define RBS_MIXEDNORMAL (RBS_CHECKEDNORMAL + 4) | |
65 | #define CBS_UNCHECKEDNORMAL 1 | |
66 | #define CBS_CHECKEDNORMAL (CBS_UNCHECKEDNORMAL + 4) | |
67 | #define CBS_MIXEDNORMAL (CBS_CHECKEDNORMAL + 4) | |
68 | ||
69 | #define PBS_NORMAL 1 | |
70 | #define PBS_HOT 2 | |
71 | #define PBS_PRESSED 3 | |
72 | #define PBS_DISABLED 4 | |
73 | #define PBS_DEFAULTED 5 | |
74 | ||
75 | #define CP_DROPDOWNBUTTON 1 | |
76 | ||
77 | #define CBXS_NORMAL 1 | |
78 | #define CBXS_HOT 2 | |
79 | #define CBXS_PRESSED 3 | |
80 | #define CBXS_DISABLED 4 | |
81 | ||
82 | #define TVP_GLYPH 2 | |
83 | ||
84 | #define GLPS_CLOSED 1 | |
85 | #define GLPS_OPENED 2 | |
86 | ||
87 | #define HP_HEADERITEM 1 | |
88 | ||
89 | #define HIS_NORMAL 1 | |
90 | #define HIS_HOT 2 | |
91 | #define HIS_PRESSED 3 | |
92 | ||
93 | #define TMT_HEIGHT 2417 | |
94 | ||
95 | #define HP_HEADERSORTARROW 4 | |
96 | #define HSAS_SORTEDUP 1 | |
97 | #define HSAS_SORTEDDOWN 2 | |
98 | ||
99 | #define EP_EDITTEXT 1 | |
100 | #define ETS_NORMAL 1 | |
101 | #define ETS_HOT 2 | |
102 | #define ETS_SELECTED 3 | |
103 | #define ETS_DISABLED 4 | |
104 | #define ETS_FOCUSED 5 | |
105 | #define ETS_READONLY 6 | |
106 | #define ETS_ASSIST 7 | |
107 | #define TMT_FILLCOLOR 3802 | |
108 | #define TMT_TEXTCOLOR 3803 | |
109 | #define TMT_BORDERCOLOR 3801 | |
110 | #define TMT_EDGEFILLCOLOR 3808 | |
111 | #endif | |
112 | ||
113 | ||
114 | // ---------------------------------------------------------------------------- | |
115 | // If the DC is a wxGCDC then pull out the HDC from the GraphicsContext when | |
116 | // it is needed, and handle the Release when done. | |
117 | ||
118 | class GraphicsHDC | |
119 | { | |
120 | public: | |
121 | GraphicsHDC(wxDC* dc) | |
122 | { | |
123 | #if wxUSE_GRAPHICS_CONTEXT | |
124 | m_graphics = NULL; | |
125 | wxGCDC* gcdc = wxDynamicCast(dc, wxGCDC); | |
126 | if (gcdc) { | |
127 | m_graphics = (Graphics*)gcdc->GetGraphicsContext()->GetNativeContext(); | |
128 | m_hdc = m_graphics->GetHDC(); | |
129 | } | |
130 | else | |
131 | #endif | |
132 | m_hdc = GetHdcOf(*((wxMSWDCImpl*)dc->GetImpl())); | |
133 | } | |
134 | ||
135 | ~GraphicsHDC() | |
136 | { | |
137 | #if wxUSE_GRAPHICS_CONTEXT | |
138 | if (m_graphics) | |
139 | m_graphics->ReleaseHDC(m_hdc); | |
140 | #endif | |
141 | } | |
142 | ||
143 | operator HDC() const { return m_hdc; } | |
144 | ||
145 | private: | |
146 | HDC m_hdc; | |
147 | #if wxUSE_GRAPHICS_CONTEXT | |
148 | Graphics* m_graphics; | |
149 | #endif | |
150 | }; | |
151 | ||
152 | #if defined(__WXWINCE__) | |
153 | #ifndef DFCS_FLAT | |
154 | #define DFCS_FLAT 0 | |
155 | #endif | |
156 | #ifndef DFCS_MONO | |
157 | #define DFCS_MONO 0 | |
158 | #endif | |
159 | #endif | |
160 | ||
161 | #ifndef DFCS_HOT | |
162 | #define DFCS_HOT 0x1000 | |
163 | #endif | |
164 | ||
165 | // ---------------------------------------------------------------------------- | |
166 | // methods common to wxRendererMSW and wxRendererXP | |
167 | // ---------------------------------------------------------------------------- | |
168 | ||
169 | class wxRendererMSWBase : public wxDelegateRendererNative | |
170 | { | |
171 | public: | |
172 | wxRendererMSWBase() { } | |
173 | wxRendererMSWBase(wxRendererNative& rendererNative) | |
174 | : wxDelegateRendererNative(rendererNative) { } | |
175 | ||
176 | void DrawFocusRect(wxWindow * win, | |
177 | wxDC& dc, | |
178 | const wxRect& rect, | |
179 | int flags = 0); | |
180 | ||
181 | void DrawItemSelectionRect(wxWindow *win, | |
182 | wxDC& dc, | |
183 | const wxRect& rect, | |
184 | int flags = 0); | |
185 | }; | |
186 | ||
187 | // ---------------------------------------------------------------------------- | |
188 | // wxRendererMSW: wxRendererNative implementation for "old" Win32 systems | |
189 | // ---------------------------------------------------------------------------- | |
190 | ||
191 | class wxRendererMSW : public wxRendererMSWBase | |
192 | { | |
193 | public: | |
194 | wxRendererMSW() { } | |
195 | ||
196 | static wxRendererNative& Get(); | |
197 | ||
198 | virtual void DrawComboBoxDropButton(wxWindow *win, | |
199 | wxDC& dc, | |
200 | const wxRect& rect, | |
201 | int flags = 0); | |
202 | ||
203 | virtual void DrawCheckBox(wxWindow *win, | |
204 | wxDC& dc, | |
205 | const wxRect& rect, | |
206 | int flags = 0); | |
207 | ||
208 | virtual void DrawPushButton(wxWindow *win, | |
209 | wxDC& dc, | |
210 | const wxRect& rect, | |
211 | int flags = 0); | |
212 | ||
213 | virtual void DrawChoice(wxWindow* win, | |
214 | wxDC& dc, | |
215 | const wxRect& rect, | |
216 | int flags=0); | |
217 | ||
218 | virtual void DrawComboBox(wxWindow* win, | |
219 | wxDC& dc, | |
220 | const wxRect& rect, | |
221 | int flags=0); | |
222 | ||
223 | virtual void DrawTextCtrl(wxWindow* win, | |
224 | wxDC& dc, | |
225 | const wxRect& rect, | |
226 | int flags=0); | |
227 | ||
228 | virtual void DrawRadioButton(wxWindow* win, | |
229 | wxDC& dc, | |
230 | const wxRect& rect, | |
231 | int flags=0); | |
232 | ||
233 | virtual wxSize GetCheckBoxSize(wxWindow *win); | |
234 | ||
235 | virtual int GetHeaderButtonHeight(wxWindow *win); | |
236 | ||
237 | private: | |
238 | wxDECLARE_NO_COPY_CLASS(wxRendererMSW); | |
239 | }; | |
240 | ||
241 | // ---------------------------------------------------------------------------- | |
242 | // wxRendererXP: wxRendererNative implementation for Windows XP and later | |
243 | // ---------------------------------------------------------------------------- | |
244 | ||
245 | #if wxUSE_UXTHEME | |
246 | ||
247 | class wxRendererXP : public wxRendererMSWBase | |
248 | { | |
249 | public: | |
250 | wxRendererXP() : wxRendererMSWBase(wxRendererMSW::Get()) { } | |
251 | ||
252 | static wxRendererNative& Get(); | |
253 | ||
254 | virtual int DrawHeaderButton(wxWindow *win, | |
255 | wxDC& dc, | |
256 | const wxRect& rect, | |
257 | int flags = 0, | |
258 | wxHeaderSortIconType sortArrow = wxHDR_SORT_ICON_NONE, | |
259 | wxHeaderButtonParams* params = NULL); | |
260 | ||
261 | virtual void DrawTreeItemButton(wxWindow *win, | |
262 | wxDC& dc, | |
263 | const wxRect& rect, | |
264 | int flags = 0); | |
265 | virtual void DrawSplitterBorder(wxWindow *win, | |
266 | wxDC& dc, | |
267 | const wxRect& rect, | |
268 | int flags = 0); | |
269 | virtual void DrawSplitterSash(wxWindow *win, | |
270 | wxDC& dc, | |
271 | const wxSize& size, | |
272 | wxCoord position, | |
273 | wxOrientation orient, | |
274 | int flags = 0); | |
275 | virtual void DrawComboBoxDropButton(wxWindow *win, | |
276 | wxDC& dc, | |
277 | const wxRect& rect, | |
278 | int flags = 0); | |
279 | virtual void DrawCheckBox(wxWindow *win, | |
280 | wxDC& dc, | |
281 | const wxRect& rect, | |
282 | int flags = 0); | |
283 | ||
284 | virtual void DrawPushButton(wxWindow *win, | |
285 | wxDC& dc, | |
286 | const wxRect& rect, | |
287 | int flags = 0); | |
288 | ||
289 | virtual wxSplitterRenderParams GetSplitterParams(const wxWindow *win); | |
290 | private: | |
291 | wxDECLARE_NO_COPY_CLASS(wxRendererXP); | |
292 | }; | |
293 | ||
294 | #endif // wxUSE_UXTHEME | |
295 | ||
296 | ||
297 | // ============================================================================ | |
298 | // wxRendererMSWBase implementation | |
299 | // ============================================================================ | |
300 | ||
301 | void wxRendererMSWBase::DrawFocusRect(wxWindow * WXUNUSED(win), | |
302 | wxDC& dc, | |
303 | const wxRect& rect, | |
304 | int WXUNUSED(flags)) | |
305 | { | |
306 | RECT rc; | |
307 | wxCopyRectToRECT(rect, rc); | |
308 | ||
309 | ::DrawFocusRect(GraphicsHDC(&dc), &rc); | |
310 | } | |
311 | ||
312 | void wxRendererMSWBase::DrawItemSelectionRect(wxWindow *win, | |
313 | wxDC& dc, | |
314 | const wxRect& rect, | |
315 | int flags) | |
316 | { | |
317 | wxBrush brush; | |
318 | if ( flags & wxCONTROL_SELECTED ) | |
319 | { | |
320 | if ( flags & wxCONTROL_FOCUSED ) | |
321 | { | |
322 | brush = wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT)); | |
323 | } | |
324 | else // !focused | |
325 | { | |
326 | brush = wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE)); | |
327 | } | |
328 | } | |
329 | else // !selected | |
330 | { | |
331 | brush = *wxTRANSPARENT_BRUSH; | |
332 | } | |
333 | ||
334 | dc.SetBrush(brush); | |
335 | dc.SetPen(*wxTRANSPARENT_PEN); | |
336 | dc.DrawRectangle( rect ); | |
337 | ||
338 | if ((flags & wxCONTROL_FOCUSED) && (flags & wxCONTROL_CURRENT)) | |
339 | DrawFocusRect( win, dc, rect, flags ); | |
340 | } | |
341 | ||
342 | ||
343 | // ============================================================================ | |
344 | // wxRendererNative and wxRendererMSW implementation | |
345 | // ============================================================================ | |
346 | ||
347 | /* static */ | |
348 | wxRendererNative& wxRendererNative::GetDefault() | |
349 | { | |
350 | #if wxUSE_UXTHEME | |
351 | wxUxThemeEngine *themeEngine = wxUxThemeEngine::Get(); | |
352 | if ( themeEngine && themeEngine->IsAppThemed() ) | |
353 | return wxRendererXP::Get(); | |
354 | #endif // wxUSE_UXTHEME | |
355 | ||
356 | return wxRendererMSW::Get(); | |
357 | } | |
358 | ||
359 | /* static */ | |
360 | wxRendererNative& wxRendererMSW::Get() | |
361 | { | |
362 | static wxRendererMSW s_rendererMSW; | |
363 | ||
364 | return s_rendererMSW; | |
365 | } | |
366 | ||
367 | void | |
368 | wxRendererMSW::DrawComboBoxDropButton(wxWindow * WXUNUSED(win), | |
369 | wxDC& dc, | |
370 | const wxRect& rect, | |
371 | int flags) | |
372 | { | |
373 | RECT r; | |
374 | wxCopyRectToRECT(rect, r); | |
375 | ||
376 | int style = DFCS_SCROLLCOMBOBOX; | |
377 | if ( flags & wxCONTROL_DISABLED ) | |
378 | style |= DFCS_INACTIVE; | |
379 | if ( flags & wxCONTROL_PRESSED ) | |
380 | style |= DFCS_PUSHED | DFCS_FLAT; | |
381 | ||
382 | ::DrawFrameControl(GraphicsHDC(&dc), &r, DFC_SCROLL, style); | |
383 | } | |
384 | ||
385 | void | |
386 | wxRendererMSW::DrawCheckBox(wxWindow * WXUNUSED(win), | |
387 | wxDC& dc, | |
388 | const wxRect& rect, | |
389 | int flags) | |
390 | { | |
391 | RECT r; | |
392 | wxCopyRectToRECT(rect, r); | |
393 | ||
394 | int style = DFCS_BUTTONCHECK; | |
395 | if ( flags & wxCONTROL_CHECKED ) | |
396 | style |= DFCS_CHECKED; | |
397 | if ( flags & wxCONTROL_DISABLED ) | |
398 | style |= DFCS_INACTIVE; | |
399 | if ( flags & wxCONTROL_FLAT ) | |
400 | style |= DFCS_MONO; | |
401 | if ( flags & wxCONTROL_PRESSED ) | |
402 | style |= DFCS_PUSHED; | |
403 | if ( flags & wxCONTROL_CURRENT ) | |
404 | style |= DFCS_HOT; | |
405 | ||
406 | ::DrawFrameControl(GraphicsHDC(&dc), &r, DFC_BUTTON, style); | |
407 | } | |
408 | ||
409 | void | |
410 | wxRendererMSW::DrawPushButton(wxWindow * WXUNUSED(win), | |
411 | wxDC& dc, | |
412 | const wxRect& rectOrig, | |
413 | int flags) | |
414 | { | |
415 | wxRect rect(rectOrig); | |
416 | ||
417 | int style = DFCS_BUTTONPUSH; | |
418 | if ( flags & wxCONTROL_DISABLED ) | |
419 | style |= DFCS_INACTIVE; | |
420 | if ( flags & wxCONTROL_PRESSED ) | |
421 | style |= DFCS_PUSHED | DFCS_FLAT; | |
422 | if ( flags & wxCONTROL_ISDEFAULT ) | |
423 | { | |
424 | // DrawFrameControl() doesn't seem to support default buttons so we | |
425 | // have to draw the border ourselves | |
426 | wxDCPenChanger pen(dc, *wxBLACK_PEN); | |
427 | wxDCBrushChanger brush(dc, *wxTRANSPARENT_BRUSH); | |
428 | dc.DrawRectangle(rect); | |
429 | rect.Deflate(1); | |
430 | } | |
431 | ||
432 | RECT rc; | |
433 | wxCopyRectToRECT(rect, rc); | |
434 | ||
435 | ::DrawFrameControl(GraphicsHDC(&dc), &rc, DFC_BUTTON, style); | |
436 | } | |
437 | ||
438 | wxSize wxRendererMSW::GetCheckBoxSize(wxWindow * WXUNUSED(win)) | |
439 | { | |
440 | return wxSize(::GetSystemMetrics(SM_CXMENUCHECK), | |
441 | ::GetSystemMetrics(SM_CYMENUCHECK)); | |
442 | } | |
443 | ||
444 | int wxRendererMSW::GetHeaderButtonHeight(wxWindow * WXUNUSED(win)) | |
445 | { | |
446 | // some "reasonable" value returned in case of error, it doesn't really | |
447 | // correspond to anything but it's better than returning 0 | |
448 | static const int DEFAULT_HEIGHT = 20; | |
449 | ||
450 | ||
451 | // create a temporary header window just to get its geometry | |
452 | HWND hwndHeader = ::CreateWindow(WC_HEADER, NULL, 0, | |
453 | 0, 0, 0, 0, NULL, NULL, NULL, NULL); | |
454 | if ( !hwndHeader ) | |
455 | return DEFAULT_HEIGHT; | |
456 | ||
457 | wxON_BLOCK_EXIT1( ::DestroyWindow, hwndHeader ); | |
458 | ||
459 | // initialize the struct filled with the values by Header_Layout() | |
460 | RECT parentRect = { 0, 0, 100, 100 }; | |
461 | WINDOWPOS wp = { 0, 0, 0, 0, 0, 0, 0 }; | |
462 | HDLAYOUT hdl = { &parentRect, &wp }; | |
463 | ||
464 | return Header_Layout(hwndHeader, &hdl) ? wp.cy : DEFAULT_HEIGHT; | |
465 | } | |
466 | ||
467 | // Uses the theme to draw the border and fill for something like a wxTextCtrl | |
468 | void wxRendererMSW::DrawTextCtrl(wxWindow* win, wxDC& dc, const wxRect& rect, int flags) | |
469 | { | |
470 | wxColour fill; | |
471 | wxColour bdr; | |
472 | COLORREF cref; | |
473 | ||
474 | #if wxUSE_UXTHEME | |
475 | wxUxThemeHandle hTheme(win, L"EDIT"); | |
476 | if (hTheme) | |
477 | { | |
478 | wxUxThemeEngine::Get()->GetThemeColor(hTheme, EP_EDITTEXT, | |
479 | ETS_NORMAL, TMT_FILLCOLOR, &cref); | |
480 | fill = wxRGBToColour(cref); | |
481 | ||
482 | int etsState; | |
483 | if ( flags & wxCONTROL_DISABLED ) | |
484 | etsState = ETS_DISABLED; | |
485 | else | |
486 | etsState = ETS_NORMAL; | |
487 | ||
488 | wxUxThemeEngine::Get()->GetThemeColor(hTheme, EP_EDITTEXT, | |
489 | etsState, TMT_BORDERCOLOR, &cref); | |
490 | bdr = wxRGBToColour(cref); | |
491 | } | |
492 | else | |
493 | #endif | |
494 | { | |
495 | fill = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW); | |
496 | bdr = *wxBLACK; | |
497 | } | |
498 | ||
499 | dc.SetPen( bdr ); | |
500 | dc.SetBrush( fill ); | |
501 | dc.DrawRectangle(rect); | |
502 | } | |
503 | ||
504 | ||
505 | // Draw the equivallent of a wxComboBox | |
506 | void wxRendererMSW::DrawComboBox(wxWindow* win, wxDC& dc, const wxRect& rect, int flags) | |
507 | { | |
508 | // Draw the main part of the control same as TextCtrl | |
509 | DrawTextCtrl(win, dc, rect, flags); | |
510 | ||
511 | // Draw the button inside the border, on the right side | |
512 | wxRect br(rect); | |
513 | br.height -= 2; | |
514 | br.x += br.width - br.height - 1; | |
515 | br.width = br.height; | |
516 | br.y += 1; | |
517 | ||
518 | DrawComboBoxDropButton(win, dc, br, flags); | |
519 | } | |
520 | ||
521 | ||
522 | void wxRendererMSW::DrawChoice(wxWindow* win, wxDC& dc, | |
523 | const wxRect& rect, int flags) | |
524 | { | |
525 | DrawComboBox(win, dc, rect, flags); | |
526 | } | |
527 | ||
528 | ||
529 | // Draw a themed radio button | |
530 | void wxRendererMSW::DrawRadioButton(wxWindow* win, wxDC& dc, const wxRect& rect, int flags) | |
531 | { | |
532 | #if wxUSE_UXTHEME | |
533 | wxUxThemeHandle hTheme(win, L"BUTTON"); | |
534 | if ( !hTheme ) | |
535 | #endif | |
536 | { | |
537 | // ??? m_rendererNative.DrawRadioButton(win, dc, rect, flags); | |
538 | return; | |
539 | } | |
540 | ||
541 | #if wxUSE_UXTHEME | |
542 | RECT r; | |
543 | wxCopyRectToRECT(rect, r); | |
544 | ||
545 | int state; | |
546 | if ( flags & wxCONTROL_CHECKED ) | |
547 | state = RBS_CHECKEDNORMAL; | |
548 | else if ( flags & wxCONTROL_UNDETERMINED ) | |
549 | state = RBS_MIXEDNORMAL; | |
550 | else | |
551 | state = RBS_UNCHECKEDNORMAL; | |
552 | ||
553 | // RBS_XXX is followed by RBX_XXXGOT, then RBS_XXXPRESSED and DISABLED | |
554 | if ( flags & wxCONTROL_CURRENT ) | |
555 | state += 1; | |
556 | else if ( flags & wxCONTROL_PRESSED ) | |
557 | state += 2; | |
558 | else if ( flags & wxCONTROL_DISABLED ) | |
559 | state += 3; | |
560 | ||
561 | wxUxThemeEngine::Get()->DrawThemeBackground | |
562 | ( | |
563 | hTheme, | |
564 | GraphicsHDC(&dc), | |
565 | BP_RADIOBUTTON, | |
566 | state, | |
567 | &r, | |
568 | NULL | |
569 | ); | |
570 | #endif | |
571 | } | |
572 | ||
573 | // ============================================================================ | |
574 | // wxRendererXP implementation | |
575 | // ============================================================================ | |
576 | ||
577 | #if wxUSE_UXTHEME | |
578 | ||
579 | /* static */ | |
580 | wxRendererNative& wxRendererXP::Get() | |
581 | { | |
582 | static wxRendererXP s_rendererXP; | |
583 | ||
584 | return s_rendererXP; | |
585 | } | |
586 | ||
587 | // NOTE: There is no guarantee that the button drawn fills the entire rect (XP | |
588 | // default theme, for example), so the caller should have cleared button's | |
589 | // background before this call. This is quite likely a wxMSW-specific thing. | |
590 | void | |
591 | wxRendererXP::DrawComboBoxDropButton(wxWindow * win, | |
592 | wxDC& dc, | |
593 | const wxRect& rect, | |
594 | int flags) | |
595 | { | |
596 | wxUxThemeHandle hTheme(win, L"COMBOBOX"); | |
597 | if ( !hTheme ) | |
598 | { | |
599 | m_rendererNative.DrawComboBoxDropButton(win, dc, rect, flags); | |
600 | return; | |
601 | } | |
602 | ||
603 | RECT r; | |
604 | wxCopyRectToRECT(rect, r); | |
605 | ||
606 | int state; | |
607 | if ( flags & wxCONTROL_PRESSED ) | |
608 | state = CBXS_PRESSED; | |
609 | else if ( flags & wxCONTROL_CURRENT ) | |
610 | state = CBXS_HOT; | |
611 | else if ( flags & wxCONTROL_DISABLED ) | |
612 | state = CBXS_DISABLED; | |
613 | else | |
614 | state = CBXS_NORMAL; | |
615 | ||
616 | wxUxThemeEngine::Get()->DrawThemeBackground | |
617 | ( | |
618 | hTheme, | |
619 | GetHdcOf(*((wxMSWDCImpl*)dc.GetImpl())), | |
620 | CP_DROPDOWNBUTTON, | |
621 | state, | |
622 | &r, | |
623 | NULL | |
624 | ); | |
625 | ||
626 | } | |
627 | ||
628 | int | |
629 | wxRendererXP::DrawHeaderButton(wxWindow *win, | |
630 | wxDC& dc, | |
631 | const wxRect& rect, | |
632 | int flags, | |
633 | wxHeaderSortIconType sortArrow, | |
634 | wxHeaderButtonParams* params) | |
635 | { | |
636 | wxUxThemeHandle hTheme(win, L"HEADER"); | |
637 | if ( !hTheme ) | |
638 | { | |
639 | return m_rendererNative.DrawHeaderButton(win, dc, rect, flags, sortArrow, params); | |
640 | } | |
641 | ||
642 | RECT r; | |
643 | wxCopyRectToRECT(rect, r); | |
644 | ||
645 | int state; | |
646 | if ( flags & wxCONTROL_PRESSED ) | |
647 | state = HIS_PRESSED; | |
648 | else if ( flags & wxCONTROL_CURRENT ) | |
649 | state = HIS_HOT; | |
650 | else | |
651 | state = HIS_NORMAL; | |
652 | wxUxThemeEngine::Get()->DrawThemeBackground | |
653 | ( | |
654 | hTheme, | |
655 | GetHdcOf(*((wxMSWDCImpl*)dc.GetImpl())), | |
656 | HP_HEADERITEM, | |
657 | state, | |
658 | &r, | |
659 | NULL | |
660 | ); | |
661 | ||
662 | // NOTE: Using the theme to draw HP_HEADERSORTARROW doesn't do anything. | |
663 | // Why? If this can be fixed then draw the sort arrows using the theme | |
664 | // and then clear those flags before calling DrawHeaderButtonContents. | |
665 | ||
666 | // Add any extras that are specified in flags and params | |
667 | return DrawHeaderButtonContents(win, dc, rect, flags, sortArrow, params); | |
668 | } | |
669 | ||
670 | ||
671 | void | |
672 | wxRendererXP::DrawTreeItemButton(wxWindow *win, | |
673 | wxDC& dc, | |
674 | const wxRect& rect, | |
675 | int flags) | |
676 | { | |
677 | wxUxThemeHandle hTheme(win, L"TREEVIEW"); | |
678 | if ( !hTheme ) | |
679 | { | |
680 | m_rendererNative.DrawTreeItemButton(win, dc, rect, flags); | |
681 | return; | |
682 | } | |
683 | ||
684 | RECT r; | |
685 | wxCopyRectToRECT(rect, r); | |
686 | ||
687 | int state = flags & wxCONTROL_EXPANDED ? GLPS_OPENED : GLPS_CLOSED; | |
688 | wxUxThemeEngine::Get()->DrawThemeBackground | |
689 | ( | |
690 | hTheme, | |
691 | GetHdcOf(*((wxMSWDCImpl*)dc.GetImpl())), | |
692 | TVP_GLYPH, | |
693 | state, | |
694 | &r, | |
695 | NULL | |
696 | ); | |
697 | } | |
698 | ||
699 | ||
700 | ||
701 | void | |
702 | wxRendererXP::DrawCheckBox(wxWindow *win, | |
703 | wxDC& dc, | |
704 | const wxRect& rect, | |
705 | int flags) | |
706 | { | |
707 | wxUxThemeHandle hTheme(win, L"BUTTON"); | |
708 | if ( !hTheme ) | |
709 | { | |
710 | m_rendererNative.DrawCheckBox(win, dc, rect, flags); | |
711 | return; | |
712 | } | |
713 | ||
714 | RECT r; | |
715 | wxCopyRectToRECT(rect, r); | |
716 | ||
717 | int state; | |
718 | if ( flags & wxCONTROL_CHECKED ) | |
719 | state = CBS_CHECKEDNORMAL; | |
720 | else if ( flags & wxCONTROL_UNDETERMINED ) | |
721 | state = CBS_MIXEDNORMAL; | |
722 | else | |
723 | state = CBS_UNCHECKEDNORMAL; | |
724 | ||
725 | // CBS_XXX is followed by CBX_XXXHOT, then CBS_XXXPRESSED and DISABLED | |
726 | enum | |
727 | { | |
728 | CBS_HOT_OFFSET = 1, | |
729 | CBS_PRESSED_OFFSET = 2, | |
730 | CBS_DISABLED_OFFSET = 3 | |
731 | }; | |
732 | ||
733 | if ( flags & wxCONTROL_DISABLED ) | |
734 | state += CBS_DISABLED_OFFSET; | |
735 | else if ( flags & wxCONTROL_PRESSED ) | |
736 | state += CBS_PRESSED_OFFSET; | |
737 | else if ( flags & wxCONTROL_CURRENT ) | |
738 | state += CBS_HOT_OFFSET; | |
739 | ||
740 | wxUxThemeEngine::Get()->DrawThemeBackground | |
741 | ( | |
742 | hTheme, | |
743 | GetHdcOf(*((wxMSWDCImpl*)dc.GetImpl())), | |
744 | BP_CHECKBOX, | |
745 | state, | |
746 | &r, | |
747 | NULL | |
748 | ); | |
749 | } | |
750 | ||
751 | void | |
752 | wxRendererXP::DrawPushButton(wxWindow * win, | |
753 | wxDC& dc, | |
754 | const wxRect& rect, | |
755 | int flags) | |
756 | { | |
757 | wxUxThemeHandle hTheme(win, L"BUTTON"); | |
758 | if ( !hTheme ) | |
759 | { | |
760 | m_rendererNative.DrawPushButton(win, dc, rect, flags); | |
761 | return; | |
762 | } | |
763 | ||
764 | RECT r; | |
765 | wxCopyRectToRECT(rect, r); | |
766 | ||
767 | int state; | |
768 | if ( flags & wxCONTROL_PRESSED ) | |
769 | state = PBS_PRESSED; | |
770 | else if ( flags & wxCONTROL_CURRENT ) | |
771 | state = PBS_HOT; | |
772 | else if ( flags & wxCONTROL_DISABLED ) | |
773 | state = PBS_DISABLED; | |
774 | else if ( flags & wxCONTROL_ISDEFAULT ) | |
775 | state = PBS_DEFAULTED; | |
776 | else | |
777 | state = PBS_NORMAL; | |
778 | ||
779 | wxUxThemeEngine::Get()->DrawThemeBackground | |
780 | ( | |
781 | hTheme, | |
782 | GetHdcOf(*((wxMSWDCImpl*)dc.GetImpl())), | |
783 | BP_PUSHBUTTON, | |
784 | state, | |
785 | &r, | |
786 | NULL | |
787 | ); | |
788 | } | |
789 | ||
790 | ||
791 | // ---------------------------------------------------------------------------- | |
792 | // splitter drawing | |
793 | // ---------------------------------------------------------------------------- | |
794 | ||
795 | // the width of the sash: this is the same as used by Explorer... | |
796 | static const wxCoord SASH_WIDTH = 4; | |
797 | ||
798 | wxSplitterRenderParams | |
799 | wxRendererXP::GetSplitterParams(const wxWindow * win) | |
800 | { | |
801 | if ( win->HasFlag(wxSP_NO_XP_THEME) ) | |
802 | return m_rendererNative.GetSplitterParams(win); | |
803 | else | |
804 | return wxSplitterRenderParams(SASH_WIDTH, 0, false); | |
805 | } | |
806 | ||
807 | void | |
808 | wxRendererXP::DrawSplitterBorder(wxWindow * win, | |
809 | wxDC& dc, | |
810 | const wxRect& rect, | |
811 | int flags) | |
812 | { | |
813 | if ( win->HasFlag(wxSP_NO_XP_THEME) ) | |
814 | { | |
815 | m_rendererNative.DrawSplitterBorder(win, dc, rect, flags); | |
816 | } | |
817 | } | |
818 | ||
819 | void | |
820 | wxRendererXP::DrawSplitterSash(wxWindow *win, | |
821 | wxDC& dc, | |
822 | const wxSize& size, | |
823 | wxCoord position, | |
824 | wxOrientation orient, | |
825 | int flags) | |
826 | { | |
827 | if ( !win->HasFlag(wxSP_NO_XP_THEME) ) | |
828 | { | |
829 | dc.SetPen(*wxTRANSPARENT_PEN); | |
830 | dc.SetBrush(wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE))); | |
831 | if ( orient == wxVERTICAL ) | |
832 | { | |
833 | dc.DrawRectangle(position, 0, SASH_WIDTH, size.y); | |
834 | } | |
835 | else // wxHORIZONTAL | |
836 | { | |
837 | dc.DrawRectangle(0, position, size.x, SASH_WIDTH); | |
838 | } | |
839 | ||
840 | return; | |
841 | } | |
842 | ||
843 | m_rendererNative.DrawSplitterSash(win, dc, size, position, orient, flags); | |
844 | } | |
845 | ||
846 | #endif // wxUSE_UXTHEME |