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