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