]> git.saurik.com Git - wxWidgets.git/blob - src/msw/renderer.cpp
Added logic, API and docs for wxDataViewModel::HasDefaultCompare indicating a compare...
[wxWidgets.git] / src / msw / renderer.cpp
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/splitter.h"
35 #include "wx/renderer.h"
36 #include "wx/msw/private.h"
37 #include "wx/msw/uxtheme.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_PUSHBUTTON 1
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
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
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
60
61 #define TVP_GLYPH 2
62
63 #define GLPS_CLOSED 1
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
71
72 #define TMT_HEIGHT 2417
73
74 #define HP_HEADERSORTARROW 4
75 #define HSAS_SORTEDUP 1
76 #define HSAS_SORTEDDOWN 2
77 #endif
78
79 #if defined(__WXWINCE__)
80 #ifndef DFCS_FLAT
81 #define DFCS_FLAT 0
82 #endif
83 #ifndef DFCS_MONO
84 #define DFCS_MONO 0
85 #endif
86 #endif
87
88 #ifndef DFCS_HOT
89 #define DFCS_HOT 0x1000
90 #endif
91
92 // ----------------------------------------------------------------------------
93 // wxRendererMSW: wxRendererNative implementation for "old" Win32 systems
94 // ----------------------------------------------------------------------------
95
96 class WXDLLEXPORT wxRendererMSW : public wxDelegateRendererNative
97 {
98 public:
99 wxRendererMSW() { }
100
101 static wxRendererNative& Get();
102
103 virtual void DrawComboBoxDropButton(wxWindow *win,
104 wxDC& dc,
105 const wxRect& rect,
106 int flags = 0);
107
108 virtual void DrawCheckBox(wxWindow *win,
109 wxDC& dc,
110 const wxRect& rect,
111 int flags = 0);
112
113 virtual void DrawPushButton(wxWindow *win,
114 wxDC& dc,
115 const wxRect& rect,
116 int flags = 0);
117
118 virtual void DrawFocusRect(wxWindow* win, wxDC& dc, const wxRect& rect, int flags = 0);
119 private:
120 DECLARE_NO_COPY_CLASS(wxRendererMSW)
121 };
122
123 // ----------------------------------------------------------------------------
124 // wxRendererXP: wxRendererNative implementation for Windows XP and later
125 // ----------------------------------------------------------------------------
126
127 #if wxUSE_UXTHEME
128
129 class WXDLLEXPORT wxRendererXP : public wxDelegateRendererNative
130 {
131 public:
132 wxRendererXP() : wxDelegateRendererNative(wxRendererMSW::Get()) { }
133
134 static wxRendererNative& Get();
135
136 virtual int DrawHeaderButton(wxWindow *win,
137 wxDC& dc,
138 const wxRect& rect,
139 int flags = 0,
140 wxHeaderSortIconType sortArrow = wxHDR_SORT_ICON_NONE,
141 wxHeaderButtonParams* params = NULL);
142 virtual int GetHeaderButtonHeight(wxWindow *win);
143
144 virtual void DrawTreeItemButton(wxWindow *win,
145 wxDC& dc,
146 const wxRect& rect,
147 int flags = 0);
148 virtual void DrawSplitterBorder(wxWindow *win,
149 wxDC& dc,
150 const wxRect& rect,
151 int flags = 0);
152 virtual void DrawSplitterSash(wxWindow *win,
153 wxDC& dc,
154 const wxSize& size,
155 wxCoord position,
156 wxOrientation orient,
157 int flags = 0);
158 virtual void DrawComboBoxDropButton(wxWindow *win,
159 wxDC& dc,
160 const wxRect& rect,
161 int flags = 0);
162 virtual void DrawCheckBox(wxWindow *win,
163 wxDC& dc,
164 const wxRect& rect,
165 int flags = 0);
166
167 virtual void DrawPushButton(wxWindow *win,
168 wxDC& dc,
169 const wxRect& rect,
170 int flags = 0);
171
172 virtual void DrawItemSelectionRect(wxWindow *win,
173 wxDC& dc,
174 const wxRect& rect,
175 int flags = 0 );
176
177
178 virtual wxSplitterRenderParams GetSplitterParams(const wxWindow *win);
179 private:
180 DECLARE_NO_COPY_CLASS(wxRendererXP)
181 };
182
183 #endif // wxUSE_UXTHEME
184
185 // ============================================================================
186 // wxRendererNative and wxRendererMSW implementation
187 // ============================================================================
188
189 /* static */
190 wxRendererNative& wxRendererNative::GetDefault()
191 {
192 #if wxUSE_UXTHEME
193 wxUxThemeEngine *themeEngine = wxUxThemeEngine::Get();
194 if ( themeEngine && themeEngine->IsAppThemed() )
195 return wxRendererXP::Get();
196 #endif // wxUSE_UXTHEME
197
198 return wxRendererMSW::Get();
199 }
200
201 /* static */
202 wxRendererNative& wxRendererMSW::Get()
203 {
204 static wxRendererMSW s_rendererMSW;
205
206 return s_rendererMSW;
207 }
208
209 void
210 wxRendererMSW::DrawComboBoxDropButton(wxWindow * WXUNUSED(win),
211 wxDC& dc,
212 const wxRect& rect,
213 int flags)
214 {
215 RECT r;
216 wxCopyRectToRECT(rect, r);
217
218 int style = DFCS_SCROLLCOMBOBOX;
219 if ( flags & wxCONTROL_DISABLED )
220 style |= DFCS_INACTIVE;
221 if ( flags & wxCONTROL_PRESSED )
222 style |= DFCS_PUSHED | DFCS_FLAT;
223
224 ::DrawFrameControl(GetHdcOf(dc), &r, DFC_SCROLL, style);
225 }
226
227 void
228 wxRendererMSW::DrawCheckBox(wxWindow * WXUNUSED(win),
229 wxDC& dc,
230 const wxRect& rect,
231 int flags)
232 {
233 RECT r;
234 wxCopyRectToRECT(rect, r);
235
236 int style = DFCS_BUTTONCHECK;
237 if ( flags & wxCONTROL_CHECKED )
238 style |= DFCS_CHECKED;
239 if ( flags & wxCONTROL_DISABLED )
240 style |= DFCS_INACTIVE;
241 if ( flags & wxCONTROL_FLAT )
242 style |= DFCS_MONO;
243 if ( flags & wxCONTROL_PRESSED )
244 style |= DFCS_PUSHED;
245 if ( flags & wxCONTROL_CURRENT )
246 style |= DFCS_HOT;
247
248 ::DrawFrameControl(GetHdcOf(dc), &r, DFC_BUTTON, style);
249 }
250
251 void
252 wxRendererMSW::DrawPushButton(wxWindow * WXUNUSED(win),
253 wxDC& dc,
254 const wxRect& rectOrig,
255 int flags)
256 {
257 wxRect rect(rectOrig);
258
259 int style = DFCS_BUTTONPUSH;
260 if ( flags & wxCONTROL_DISABLED )
261 style |= DFCS_INACTIVE;
262 if ( flags & wxCONTROL_PRESSED )
263 style |= DFCS_PUSHED | DFCS_FLAT;
264 if ( flags & wxCONTROL_ISDEFAULT )
265 {
266 // DrawFrameControl() doesn't seem to support default buttons so we
267 // have to draw the border ourselves
268 wxDCPenChanger pen(dc, *wxBLACK_PEN);
269 wxDCBrushChanger brush(dc, *wxTRANSPARENT_BRUSH);
270 dc.DrawRectangle(rect);
271 rect.Deflate(1);
272 }
273
274 RECT rc;
275 wxCopyRectToRECT(rect, rc);
276
277 ::DrawFrameControl(GetHdcOf(dc), &rc, DFC_BUTTON, style);
278 }
279
280 void wxRendererMSW::DrawFocusRect(wxWindow* WXUNUSED(win), wxDC& dc, const wxRect& rect, int WXUNUSED(flags))
281 {
282 RECT rc;
283 wxCopyRectToRECT(rect, rc);
284
285 ::DrawFocusRect(GetHdcOf(dc), &rc);
286 }
287
288 // ============================================================================
289 // wxRendererXP implementation
290 // ============================================================================
291
292 #if wxUSE_UXTHEME
293
294 /* static */
295 wxRendererNative& wxRendererXP::Get()
296 {
297 static wxRendererXP s_rendererXP;
298
299 return s_rendererXP;
300 }
301
302 // NOTE: There is no guarantee that the button drawn fills the entire rect (XP
303 // default theme, for example), so the caller should have cleared button's
304 // background before this call. This is quite likely a wxMSW-specific thing.
305 void
306 wxRendererXP::DrawComboBoxDropButton(wxWindow * win,
307 wxDC& dc,
308 const wxRect& rect,
309 int flags)
310 {
311 wxUxThemeHandle hTheme(win, L"COMBOBOX");
312 if ( !hTheme )
313 {
314 m_rendererNative.DrawComboBoxDropButton(win, dc, rect, flags);
315 return;
316 }
317
318 RECT r;
319 wxCopyRectToRECT(rect, r);
320
321 int state;
322 if ( flags & wxCONTROL_PRESSED )
323 state = CBXS_PRESSED;
324 else if ( flags & wxCONTROL_CURRENT )
325 state = CBXS_HOT;
326 else if ( flags & wxCONTROL_DISABLED )
327 state = CBXS_DISABLED;
328 else
329 state = CBXS_NORMAL;
330
331 wxUxThemeEngine::Get()->DrawThemeBackground
332 (
333 hTheme,
334 GetHdcOf(dc),
335 CP_DROPDOWNBUTTON,
336 state,
337 &r,
338 NULL
339 );
340
341 }
342
343 int
344 wxRendererXP::DrawHeaderButton(wxWindow *win,
345 wxDC& dc,
346 const wxRect& rect,
347 int flags,
348 wxHeaderSortIconType sortArrow,
349 wxHeaderButtonParams* params)
350 {
351 wxUxThemeHandle hTheme(win, L"HEADER");
352 if ( !hTheme )
353 {
354 return m_rendererNative.DrawHeaderButton(win, dc, rect, flags, sortArrow, params);
355 }
356
357 RECT r;
358 wxCopyRectToRECT(rect, r);
359
360 int state;
361 if ( flags & wxCONTROL_PRESSED )
362 state = HIS_PRESSED;
363 else if ( flags & wxCONTROL_CURRENT )
364 state = HIS_HOT;
365 else
366 state = HIS_NORMAL;
367 wxUxThemeEngine::Get()->DrawThemeBackground
368 (
369 hTheme,
370 GetHdcOf(dc),
371 HP_HEADERITEM,
372 state,
373 &r,
374 NULL
375 );
376
377 // NOTE: Using the theme to draw HP_HEADERSORTARROW doesn't do anything.
378 // Why? If this can be fixed then draw the sort arrows using the theme
379 // and then clear those flags before calling DrawHeaderButtonContents.
380
381 // Add any extras that are specified in flags and params
382 return DrawHeaderButtonContents(win, dc, rect, flags, sortArrow, params);
383 }
384
385
386 int
387 wxRendererXP::GetHeaderButtonHeight(wxWindow *win)
388 {
389 wxUxThemeHandle hTheme(win, L"HEADER");
390 if ( !hTheme )
391 {
392 return m_rendererNative.GetHeaderButtonHeight(win);
393 }
394
395 HRESULT hr;
396 int value = -1;
397
398 hr = wxUxThemeEngine::Get()->GetThemeMetric( hTheme,
399 NULL,
400 HP_HEADERITEM,
401 HIS_NORMAL,
402 TMT_HEIGHT,
403 &value );
404 if ( hr == S_OK )
405 return value;
406 else
407 return 20;
408 }
409
410
411 void
412 wxRendererXP::DrawTreeItemButton(wxWindow *win,
413 wxDC& dc,
414 const wxRect& rect,
415 int flags)
416 {
417 wxUxThemeHandle hTheme(win, L"TREEVIEW");
418 if ( !hTheme )
419 {
420 m_rendererNative.DrawTreeItemButton(win, dc, rect, flags);
421 return;
422 }
423
424 RECT r;
425 wxCopyRectToRECT(rect, r);
426
427 int state = flags & wxCONTROL_EXPANDED ? GLPS_OPENED : GLPS_CLOSED;
428 wxUxThemeEngine::Get()->DrawThemeBackground
429 (
430 hTheme,
431 GetHdcOf(dc),
432 TVP_GLYPH,
433 state,
434 &r,
435 NULL
436 );
437 }
438
439 void
440 wxRendererXP::DrawCheckBox(wxWindow *win,
441 wxDC& dc,
442 const wxRect& rect,
443 int flags)
444 {
445 wxUxThemeHandle hTheme(win, L"BUTTON");
446 if ( !hTheme )
447 {
448 m_rendererNative.DrawCheckBox(win, dc, rect, flags);
449 return;
450 }
451
452 RECT r;
453 wxCopyRectToRECT(rect, r);
454
455 int state;
456 if ( flags & wxCONTROL_CHECKED )
457 state = CBS_CHECKEDNORMAL;
458 else if ( flags & wxCONTROL_UNDETERMINED )
459 state = CBS_MIXEDNORMAL;
460 else
461 state = CBS_UNCHECKEDNORMAL;
462
463 // CBS_XXX is followed by CBX_XXXHOT, then CBS_XXXPRESSED and DISABLED
464 enum
465 {
466 CBS_HOT_OFFSET = 1,
467 CBS_PRESSED_OFFSET = 2,
468 CBS_DISABLED_OFFSET = 3
469 };
470
471 if ( flags & wxCONTROL_DISABLED )
472 state += CBS_DISABLED_OFFSET;
473 else if ( flags & wxCONTROL_PRESSED )
474 state += CBS_PRESSED_OFFSET;
475 else if ( flags & wxCONTROL_CURRENT )
476 state += CBS_HOT_OFFSET;
477
478 wxUxThemeEngine::Get()->DrawThemeBackground
479 (
480 hTheme,
481 GetHdcOf(dc),
482 BP_CHECKBOX,
483 state,
484 &r,
485 NULL
486 );
487 }
488
489 void
490 wxRendererXP::DrawPushButton(wxWindow * win,
491 wxDC& dc,
492 const wxRect& rect,
493 int flags)
494 {
495 wxUxThemeHandle hTheme(win, L"BUTTON");
496 if ( !hTheme )
497 {
498 m_rendererNative.DrawPushButton(win, dc, rect, flags);
499 return;
500 }
501
502 RECT r;
503 wxCopyRectToRECT(rect, r);
504
505 int state;
506 if ( flags & wxCONTROL_PRESSED )
507 state = PBS_PRESSED;
508 else if ( flags & wxCONTROL_CURRENT )
509 state = PBS_HOT;
510 else if ( flags & wxCONTROL_DISABLED )
511 state = PBS_DISABLED;
512 else if ( flags & wxCONTROL_ISDEFAULT )
513 state = PBS_DEFAULTED;
514 else
515 state = PBS_NORMAL;
516
517 wxUxThemeEngine::Get()->DrawThemeBackground
518 (
519 hTheme,
520 GetHdcOf(dc),
521 BP_PUSHBUTTON,
522 state,
523 &r,
524 NULL
525 );
526
527 }
528
529 void
530 wxRendererXP::DrawItemSelectionRect(wxWindow * WXUNUSED(win),
531 wxDC& dc,
532 const wxRect& rect,
533 int flags)
534 {
535 wxBrush brush;
536 if ( flags & wxCONTROL_SELECTED )
537 {
538 if ( flags & wxCONTROL_FOCUSED )
539 {
540 brush = wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT));
541 }
542 else // !focused
543 {
544 brush = wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNSHADOW));
545 }
546 }
547 else // !selected
548 {
549 brush = *wxTRANSPARENT_BRUSH;
550 }
551
552 dc.SetBrush(brush);
553
554 // unlike for wxRendererGeneric, on windows we _never_ want to draw
555 // the outline of the rectangle:
556 dc.SetPen(*wxTRANSPARENT_PEN);
557
558 dc.DrawRectangle( rect );
559 }
560
561
562
563 // ----------------------------------------------------------------------------
564 // splitter drawing
565 // ----------------------------------------------------------------------------
566
567 // the width of the sash: this is the same as used by Explorer...
568 static const wxCoord SASH_WIDTH = 4;
569
570 wxSplitterRenderParams
571 wxRendererXP::GetSplitterParams(const wxWindow * win)
572 {
573 if ( win->HasFlag(wxSP_NO_XP_THEME) )
574 return m_rendererNative.GetSplitterParams(win);
575 else
576 return wxSplitterRenderParams(SASH_WIDTH, 0, false);
577 }
578
579 void
580 wxRendererXP::DrawSplitterBorder(wxWindow * win,
581 wxDC& dc,
582 const wxRect& rect,
583 int flags)
584 {
585 if ( win->HasFlag(wxSP_NO_XP_THEME) )
586 {
587 m_rendererNative.DrawSplitterBorder(win, dc, rect, flags);
588 }
589 }
590
591 void
592 wxRendererXP::DrawSplitterSash(wxWindow *win,
593 wxDC& dc,
594 const wxSize& size,
595 wxCoord position,
596 wxOrientation orient,
597 int flags)
598 {
599 if ( !win->HasFlag(wxSP_NO_XP_THEME) )
600 {
601 dc.SetPen(*wxTRANSPARENT_PEN);
602 dc.SetBrush(wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE)));
603 if ( orient == wxVERTICAL )
604 {
605 dc.DrawRectangle(position, 0, SASH_WIDTH, size.y);
606 }
607 else // wxHORIZONTAL
608 {
609 dc.DrawRectangle(0, position, size.x, SASH_WIDTH);
610 }
611
612 return;
613 }
614
615 m_rendererNative.DrawSplitterSash(win, dc, size, position, orient, flags);
616 }
617
618 #endif // wxUSE_UXTHEME