]> git.saurik.com Git - wxWidgets.git/blob - src/msw/renderer.cpp
send wxWindowCreateEvent from SubclassWin(), not WM_CREATE handler as we don't get...
[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 #endif //WX_PRECOMP
32
33 #include "wx/splitter.h"
34 #include "wx/renderer.h"
35 #include "wx/settings.h"
36 #include "wx/msw/uxtheme.h"
37 #include "wx/msw/private.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 #endif
72
73 #if defined(__WXWINCE__) && !defined(DFCS_FLAT)
74 #define DFCS_FLAT 0
75 #endif
76
77 // ----------------------------------------------------------------------------
78 // wxRendererMSW: wxRendererNative implementation for "old" Win32 systems
79 // ----------------------------------------------------------------------------
80
81 class WXDLLEXPORT wxRendererMSW : public wxDelegateRendererNative
82 {
83 public:
84 wxRendererMSW() { }
85
86 static wxRendererNative& Get();
87
88 virtual void DrawComboBoxDropButton(wxWindow *win,
89 wxDC& dc,
90 const wxRect& rect,
91 int flags = 0);
92
93 virtual void DrawPushButton(wxWindow *win,
94 wxDC& dc,
95 const wxRect& rect,
96 int flags = 0);
97
98 private:
99 DECLARE_NO_COPY_CLASS(wxRendererMSW)
100 };
101
102 // ----------------------------------------------------------------------------
103 // wxRendererXP: wxRendererNative implementation for Windows XP and later
104 // ----------------------------------------------------------------------------
105
106 #if wxUSE_UXTHEME
107
108 class WXDLLEXPORT wxRendererXP : public wxDelegateRendererNative
109 {
110 public:
111 wxRendererXP() : wxDelegateRendererNative(wxRendererMSW::Get()) { }
112
113 static wxRendererNative& Get();
114
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);
123 virtual void DrawSplitterBorder(wxWindow *win,
124 wxDC& dc,
125 const wxRect& rect,
126 int flags = 0);
127 virtual void DrawSplitterSash(wxWindow *win,
128 wxDC& dc,
129 const wxSize& size,
130 wxCoord position,
131 wxOrientation orient,
132 int flags = 0);
133 virtual void DrawComboBoxDropButton(wxWindow *win,
134 wxDC& dc,
135 const wxRect& rect,
136 int flags = 0);
137 virtual void DrawCheckBox(wxWindow *win,
138 wxDC& dc,
139 const wxRect& rect,
140 int flags = 0);
141
142 virtual void DrawPushButton(wxWindow *win,
143 wxDC& dc,
144 const wxRect& rect,
145 int flags = 0);
146
147 virtual wxSplitterRenderParams GetSplitterParams(const wxWindow *win);
148 private:
149 DECLARE_NO_COPY_CLASS(wxRendererXP)
150 };
151
152 #endif // wxUSE_UXTHEME
153
154 // ============================================================================
155 // wxRendererNative and wxRendererMSW implementation
156 // ============================================================================
157
158 /* static */
159 wxRendererNative& wxRendererNative::GetDefault()
160 {
161 #if wxUSE_UXTHEME
162 wxUxThemeEngine *themeEngine = wxUxThemeEngine::Get();
163 if ( themeEngine && themeEngine->IsAppThemed() )
164 return wxRendererXP::Get();
165 #endif // wxUSE_UXTHEME
166
167 return wxRendererMSW::Get();
168 }
169
170 /* static */
171 wxRendererNative& wxRendererMSW::Get()
172 {
173 static wxRendererMSW s_rendererMSW;
174
175 return s_rendererMSW;
176 }
177
178 void
179 wxRendererMSW::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();
187 r.bottom = rect.y + rect.height;
188 r.right = rect.x + rect.width;
189
190 int style = DFCS_SCROLLCOMBOBOX;
191 if ( flags & wxCONTROL_DISABLED )
192 style |= DFCS_INACTIVE;
193 if ( flags & wxCONTROL_PRESSED )
194 style |= DFCS_PUSHED | DFCS_FLAT;
195
196 ::DrawFrameControl(GetHdcOf(dc), &r, DFC_SCROLL, style);
197 }
198
199 void
200 wxRendererMSW::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
220 // ============================================================================
221 // wxRendererXP implementation
222 // ============================================================================
223
224 #if wxUSE_UXTHEME
225
226 /* static */
227 wxRendererNative& wxRendererXP::Get()
228 {
229 static wxRendererXP s_rendererXP;
230
231 return s_rendererXP;
232 }
233
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.
237 void
238 wxRendererXP::DrawComboBoxDropButton(wxWindow * win,
239 wxDC& dc,
240 const wxRect& rect,
241 int flags)
242 {
243 wxUxThemeHandle hTheme(win, L"COMBOBOX");
244 if ( !hTheme )
245 {
246 m_rendererNative.DrawComboBoxDropButton(win, dc, rect, flags);
247 return;
248 }
249
250 RECT r;
251 wxCopyRectToRECT(rect, r);
252
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
275 void
276 wxRendererXP::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;
286 }
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
309 void
310 wxRendererXP::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
337 void
338 wxRendererXP::DrawCheckBox(wxWindow *win,
339 wxDC& dc,
340 const wxRect& rect,
341 int flags)
342 {
343 wxUxThemeHandle hTheme(win, L"BUTTON");
344 if ( !hTheme )
345 {
346 m_rendererNative.DrawCheckBox(win, dc, rect, flags);
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 );
378 }
379
380 void
381 wxRendererXP::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
420 // ----------------------------------------------------------------------------
421 // splitter drawing
422 // ----------------------------------------------------------------------------
423
424 // the width of the sash: this is the same as used by Explorer...
425 static const wxCoord SASH_WIDTH = 4;
426
427 wxSplitterRenderParams
428 wxRendererXP::GetSplitterParams(const wxWindow * win)
429 {
430 if ( win->HasFlag(wxSP_NO_XP_THEME) )
431 return m_rendererNative.GetSplitterParams(win);
432 else
433 return wxSplitterRenderParams(SASH_WIDTH, 0, false);
434 }
435
436 void
437 wxRendererXP::DrawSplitterBorder(wxWindow * win,
438 wxDC& dc,
439 const wxRect& rect,
440 int flags)
441 {
442 if ( win->HasFlag(wxSP_NO_XP_THEME) )
443 {
444 m_rendererNative.DrawSplitterBorder(win, dc, rect, flags);
445 }
446 }
447
448 void
449 wxRendererXP::DrawSplitterSash(wxWindow *win,
450 wxDC& dc,
451 const wxSize& size,
452 wxCoord position,
453 wxOrientation orient,
454 int flags)
455 {
456 if ( !win->HasFlag(wxSP_NO_XP_THEME) )
457 {
458 dc.SetPen(*wxTRANSPARENT_PEN);
459 dc.SetBrush(wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE)));
460 if ( orient == wxVERTICAL )
461 {
462 dc.DrawRectangle(position, 0, SASH_WIDTH, size.y);
463 }
464 else // wxHORIZONTAL
465 {
466 dc.DrawRectangle(0, position, size.x, SASH_WIDTH);
467 }
468
469 return;
470 }
471
472 m_rendererNative.DrawSplitterSash(win, dc, size, position, orient, flags);
473 }
474
475 #endif // wxUSE_UXTHEME