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