]> git.saurik.com Git - wxWidgets.git/blame - src/msw/renderer.cpp
Added missing wx_aui.dsp file
[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"
8b97949e 36#include "wx/msw/uxtheme.h"
03f01e63 37#include "wx/msw/private.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
7cf3223a
VZ
71#endif
72
9f93b45e
VZ
73#if defined(__WXWINCE__) && !defined(DFCS_FLAT)
74 #define DFCS_FLAT 0
75#endif
76
9c7f49f5 77// ----------------------------------------------------------------------------
8b97949e 78// wxRendererMSW: wxRendererNative implementation for "old" Win32 systems
9c7f49f5
VZ
79// ----------------------------------------------------------------------------
80
38c4cb6a 81class WXDLLEXPORT wxRendererMSW : public wxDelegateRendererNative
9c7f49f5 82{
2eb10e2a
VZ
83public:
84 wxRendererMSW() { }
85
8b97949e
VZ
86 static wxRendererNative& Get();
87
7402677a
VZ
88 virtual void DrawComboBoxDropButton(wxWindow *win,
89 wxDC& dc,
90 const wxRect& rect,
91 int flags = 0);
92
2209baae
RR
93 virtual void DrawPushButton(wxWindow *win,
94 wxDC& dc,
95 const wxRect& rect,
96 int flags = 0);
97
2eb10e2a
VZ
98private:
99 DECLARE_NO_COPY_CLASS(wxRendererMSW)
9c7f49f5
VZ
100};
101
8b97949e
VZ
102// ----------------------------------------------------------------------------
103// wxRendererXP: wxRendererNative implementation for Windows XP and later
104// ----------------------------------------------------------------------------
105
7cf3223a
VZ
106#if wxUSE_UXTHEME
107
8b97949e
VZ
108class WXDLLEXPORT wxRendererXP : public wxDelegateRendererNative
109{
110public:
111 wxRendererXP() : wxDelegateRendererNative(wxRendererMSW::Get()) { }
112
113 static wxRendererNative& Get();
114
9f93b45e
VZ
115 virtual void DrawHeaderButton(wxWindow *win,
116 wxDC& dc,
117 const wxRect& rect,
118 int flags = 0);
119 virtual void DrawTreeItemButton(wxWindow *win,
120 wxDC& dc,
121 const wxRect& rect,
122 int flags = 0);
8b97949e
VZ
123 virtual void DrawSplitterBorder(wxWindow *win,
124 wxDC& dc,
c4e6c15e
VZ
125 const wxRect& rect,
126 int flags = 0);
8b97949e
VZ
127 virtual void DrawSplitterSash(wxWindow *win,
128 wxDC& dc,
129 const wxSize& size,
130 wxCoord position,
c4e6c15e
VZ
131 wxOrientation orient,
132 int flags = 0);
7cf3223a
VZ
133 virtual void DrawComboBoxDropButton(wxWindow *win,
134 wxDC& dc,
135 const wxRect& rect,
136 int flags = 0);
90b903c2
WS
137 virtual void DrawCheckBox(wxWindow *win,
138 wxDC& dc,
139 const wxRect& rect,
140 int flags = 0);
9f93b45e 141
2209baae
RR
142 virtual void DrawPushButton(wxWindow *win,
143 wxDC& dc,
144 const wxRect& rect,
145 int flags = 0);
146
9f93b45e 147 virtual wxSplitterRenderParams GetSplitterParams(const wxWindow *win);
8b97949e
VZ
148private:
149 DECLARE_NO_COPY_CLASS(wxRendererXP)
150};
151
7cf3223a
VZ
152#endif // wxUSE_UXTHEME
153
9c7f49f5 154// ============================================================================
8b97949e 155// wxRendererNative and wxRendererMSW implementation
9c7f49f5
VZ
156// ============================================================================
157
158/* static */
f0244295 159wxRendererNative& wxRendererNative::GetDefault()
8b97949e 160{
7cf3223a 161#if wxUSE_UXTHEME
8b97949e 162 wxUxThemeEngine *themeEngine = wxUxThemeEngine::Get();
7cf3223a
VZ
163 if ( themeEngine && themeEngine->IsAppThemed() )
164 return wxRendererXP::Get();
165#endif // wxUSE_UXTHEME
166
167 return wxRendererMSW::Get();
8b97949e
VZ
168}
169
170/* static */
171wxRendererNative& wxRendererMSW::Get()
9c7f49f5
VZ
172{
173 static wxRendererMSW s_rendererMSW;
174
175 return s_rendererMSW;
176}
177
7402677a
VZ
178void
179wxRendererMSW::DrawComboBoxDropButton(wxWindow * WXUNUSED(win),
180 wxDC& dc,
181 const wxRect& rect,
182 int flags)
183{
184 RECT r;
185 r.left = rect.GetLeft();
186 r.top = rect.GetTop();
7cf3223a
VZ
187 r.bottom = rect.y + rect.height;
188 r.right = rect.x + rect.width;
7402677a
VZ
189
190 int style = DFCS_SCROLLCOMBOBOX;
191 if ( flags & wxCONTROL_DISABLED )
192 style |= DFCS_INACTIVE;
193 if ( flags & wxCONTROL_PRESSED )
7cf3223a 194 style |= DFCS_PUSHED | DFCS_FLAT;
7402677a
VZ
195
196 ::DrawFrameControl(GetHdcOf(dc), &r, DFC_SCROLL, style);
197}
198
2209baae
RR
199void
200wxRendererMSW::DrawPushButton(wxWindow * WXUNUSED(win),
201 wxDC& dc,
202 const wxRect& rect,
203 int flags)
204{
205 RECT r;
206 r.left = rect.GetLeft();
207 r.top = rect.GetTop();
208 r.bottom = rect.y + rect.height;
209 r.right = rect.x + rect.width;
210
211 int style = DFCS_BUTTONPUSH;
212 if ( flags & wxCONTROL_DISABLED )
213 style |= DFCS_INACTIVE;
214 if ( flags & wxCONTROL_PRESSED )
215 style |= DFCS_PUSHED | DFCS_FLAT;
216
217 ::DrawFrameControl(GetHdcOf(dc), &r, DFC_BUTTON, style);
218}
219
8b97949e
VZ
220// ============================================================================
221// wxRendererXP implementation
222// ============================================================================
223
7cf3223a
VZ
224#if wxUSE_UXTHEME
225
8b97949e
VZ
226/* static */
227wxRendererNative& wxRendererXP::Get()
228{
229 static wxRendererXP s_rendererXP;
230
231 return s_rendererXP;
232}
233
7cf3223a
VZ
234// NOTE: There is no guarantee that the button drawn fills the entire rect (XP
235// default theme, for example), so the caller should have cleared button's
236// background before this call. This is quite likely a wxMSW-specific thing.
237void
238wxRendererXP::DrawComboBoxDropButton(wxWindow * win,
239 wxDC& dc,
240 const wxRect& rect,
241 int flags)
242{
243 wxUxThemeHandle hTheme(win, L"COMBOBOX");
9f93b45e 244 if ( !hTheme )
7cf3223a 245 {
9f93b45e
VZ
246 m_rendererNative.DrawComboBoxDropButton(win, dc, rect, flags);
247 return;
248 }
249
250 RECT r;
251 wxCopyRectToRECT(rect, r);
7cf3223a 252
9f93b45e
VZ
253 int state;
254 if ( flags & wxCONTROL_PRESSED )
255 state = CBXS_PRESSED;
256 else if ( flags & wxCONTROL_CURRENT )
257 state = CBXS_HOT;
258 else if ( flags & wxCONTROL_DISABLED )
259 state = CBXS_DISABLED;
260 else
261 state = CBXS_NORMAL;
262
263 wxUxThemeEngine::Get()->DrawThemeBackground
264 (
265 hTheme,
266 GetHdcOf(dc),
267 CP_DROPDOWNBUTTON,
268 state,
269 &r,
270 NULL
271 );
272
273}
274
275void
276wxRendererXP::DrawHeaderButton(wxWindow *win,
277 wxDC& dc,
278 const wxRect& rect,
279 int flags)
280{
281 wxUxThemeHandle hTheme(win, L"HEADER");
282 if ( !hTheme )
283 {
284 m_rendererNative.DrawHeaderButton(win, dc, rect, flags);
285 return;
7cf3223a 286 }
9f93b45e
VZ
287
288 RECT r;
289 wxCopyRectToRECT(rect, r);
290
291 int state;
292 if ( flags & wxCONTROL_PRESSED )
293 state = HIS_PRESSED;
294 else if ( flags & wxCONTROL_CURRENT )
295 state = HIS_HOT;
296 else
297 state = HIS_NORMAL;
298 wxUxThemeEngine::Get()->DrawThemeBackground
299 (
300 hTheme,
301 GetHdcOf(dc),
302 HP_HEADERITEM,
303 state,
304 &r,
305 NULL
306 );
307}
308
309void
310wxRendererXP::DrawTreeItemButton(wxWindow *win,
311 wxDC& dc,
312 const wxRect& rect,
313 int flags)
314{
315 wxUxThemeHandle hTheme(win, L"TREEVIEW");
316 if ( !hTheme )
317 {
318 m_rendererNative.DrawTreeItemButton(win, dc, rect, flags);
319 return;
320 }
321
322 RECT r;
323 wxCopyRectToRECT(rect, r);
324
325 int state = flags & wxCONTROL_EXPANDED ? GLPS_OPENED : GLPS_CLOSED;
326 wxUxThemeEngine::Get()->DrawThemeBackground
327 (
328 hTheme,
329 GetHdcOf(dc),
330 TVP_GLYPH,
331 state,
332 &r,
333 NULL
334 );
335}
336
337void
90b903c2
WS
338wxRendererXP::DrawCheckBox(wxWindow *win,
339 wxDC& dc,
340 const wxRect& rect,
341 int flags)
9f93b45e
VZ
342{
343 wxUxThemeHandle hTheme(win, L"BUTTON");
344 if ( !hTheme )
345 {
90b903c2 346 m_rendererNative.DrawCheckBox(win, dc, rect, flags);
9f93b45e
VZ
347 return;
348 }
349
350 RECT r;
351 wxCopyRectToRECT(rect, r);
352
353 int state;
354 if ( flags & wxCONTROL_CHECKED )
355 state = CBS_CHECKEDNORMAL;
356 else if ( flags & wxCONTROL_UNDETERMINED )
357 state = CBS_MIXEDNORMAL;
358 else
359 state = CBS_UNCHECKEDNORMAL;
360
361 // CBS_XXX is followed by CBX_XXXGOT, then CBS_XXXPRESSED and DISABLED
362 if ( flags & wxCONTROL_CURRENT )
363 state += 1;
364 else if ( flags & wxCONTROL_PRESSED )
365 state += 2;
366 else if ( flags & wxCONTROL_DISABLED )
367 state += 3;
368
369 wxUxThemeEngine::Get()->DrawThemeBackground
370 (
371 hTheme,
372 GetHdcOf(dc),
373 BP_CHECKBOX,
374 state,
375 &r,
376 NULL
377 );
7cf3223a
VZ
378}
379
2209baae
RR
380void
381wxRendererXP::DrawPushButton(wxWindow * win,
382 wxDC& dc,
383 const wxRect& rect,
384 int flags)
385{
386 wxUxThemeHandle hTheme(win, L"BUTTON");
387 if ( !hTheme )
388 {
389 m_rendererNative.DrawPushButton(win, dc, rect, flags);
390 return;
391 }
392
393 RECT r;
394 wxCopyRectToRECT(rect, r);
395
396 int state;
397 if ( flags & wxCONTROL_PRESSED )
398 state = PBS_PRESSED;
399 else if ( flags & wxCONTROL_CURRENT )
400 state = PBS_HOT;
401 else if ( flags & wxCONTROL_DISABLED )
402 state = PBS_DISABLED;
403 else if ( flags & wxCONTROL_ISDEFAULT )
404 state = PBS_DEFAULTED;
405 else
406 state = PBS_NORMAL;
407
408 wxUxThemeEngine::Get()->DrawThemeBackground
409 (
410 hTheme,
411 GetHdcOf(dc),
412 BP_PUSHBUTTON,
413 state,
414 &r,
415 NULL
416 );
417
418}
419
8b97949e
VZ
420// ----------------------------------------------------------------------------
421// splitter drawing
422// ----------------------------------------------------------------------------
423
424// the width of the sash: this is the same as used by Explorer...
425static const wxCoord SASH_WIDTH = 4;
426
c4e6c15e 427wxSplitterRenderParams
3c2544bb 428wxRendererXP::GetSplitterParams(const wxWindow * win)
8b97949e 429{
9f93b45e 430 if ( win->HasFlag(wxSP_NO_XP_THEME) )
3c2544bb
JS
431 return m_rendererNative.GetSplitterParams(win);
432 else
433 return wxSplitterRenderParams(SASH_WIDTH, 0, false);
8b97949e
VZ
434}
435
436void
3c2544bb
JS
437wxRendererXP::DrawSplitterBorder(wxWindow * win,
438 wxDC& dc,
439 const wxRect& rect,
440 int flags)
8b97949e 441{
9f93b45e 442 if ( win->HasFlag(wxSP_NO_XP_THEME) )
3c2544bb
JS
443 {
444 m_rendererNative.DrawSplitterBorder(win, dc, rect, flags);
445 }
8b97949e
VZ
446}
447
448void
449wxRendererXP::DrawSplitterSash(wxWindow *win,
450 wxDC& dc,
451 const wxSize& size,
452 wxCoord position,
c4e6c15e 453 wxOrientation orient,
3c2544bb 454 int flags)
8b97949e 455{
6421119d 456 if ( !win->HasFlag(wxSP_NO_XP_THEME) )
8b97949e 457 {
fe404d1a
JS
458 dc.SetPen(*wxTRANSPARENT_PEN);
459 dc.SetBrush(wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE)));
460 if ( orient == wxVERTICAL )
8b97949e 461 {
fe404d1a 462 dc.DrawRectangle(position, 0, SASH_WIDTH, size.y);
8b97949e 463 }
fe404d1a
JS
464 else // wxHORIZONTAL
465 {
466 dc.DrawRectangle(0, position, size.x, SASH_WIDTH);
467 }
468
469 return;
8b97949e 470 }
6421119d
VZ
471
472 m_rendererNative.DrawSplitterSash(win, dc, size, position, orient, flags);
8b97949e
VZ
473}
474
7cf3223a 475#endif // wxUSE_UXTHEME