]>
Commit | Line | Data |
---|---|---|
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> | |
526954c5 | 9 | // Licence: 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 | ||
066bd251 | 34 | #include "wx/dcgraph.h" |
51c42fc5 | 35 | #include "wx/scopeguard.h" |
3c2544bb | 36 | #include "wx/splitter.h" |
9c7f49f5 | 37 | #include "wx/renderer.h" |
03f01e63 | 38 | #include "wx/msw/private.h" |
4614c8e5 | 39 | #include "wx/msw/uxtheme.h" |
8b97949e | 40 | |
7cf3223a VZ |
41 | // tmschema.h is in Win32 Platform SDK and might not be available with earlier |
42 | // compilers | |
43 | #ifndef CP_DROPDOWNBUTTON | |
2209baae | 44 | #define BP_PUSHBUTTON 1 |
e4131985 | 45 | #define BP_RADIOBUTTON 2 |
9f93b45e | 46 | #define BP_CHECKBOX 3 |
e4131985 KO |
47 | #define RBS_UNCHECKEDNORMAL 1 |
48 | #define RBS_CHECKEDNORMAL (RBS_UNCHECKEDNORMAL + 4) | |
49 | #define RBS_MIXEDNORMAL (RBS_CHECKEDNORMAL + 4) | |
9f93b45e VZ |
50 | #define CBS_UNCHECKEDNORMAL 1 |
51 | #define CBS_CHECKEDNORMAL (CBS_UNCHECKEDNORMAL + 4) | |
52 | #define CBS_MIXEDNORMAL (CBS_CHECKEDNORMAL + 4) | |
53 | ||
2209baae RR |
54 | #define PBS_NORMAL 1 |
55 | #define PBS_HOT 2 | |
56 | #define PBS_PRESSED 3 | |
57 | #define PBS_DISABLED 4 | |
58 | #define PBS_DEFAULTED 5 | |
59 | ||
7cf3223a VZ |
60 | #define CP_DROPDOWNBUTTON 1 |
61 | ||
62 | #define CBXS_NORMAL 1 | |
63 | #define CBXS_HOT 2 | |
64 | #define CBXS_PRESSED 3 | |
65 | #define CBXS_DISABLED 4 | |
a9d9e2f2 | 66 | |
9f93b45e VZ |
67 | #define TVP_GLYPH 2 |
68 | ||
69 | #define GLPS_CLOSED 1 | |
a9d9e2f2 JS |
70 | #define GLPS_OPENED 2 |
71 | ||
72 | #define HP_HEADERITEM 1 | |
73 | ||
74 | #define HIS_NORMAL 1 | |
75 | #define HIS_HOT 2 | |
76 | #define HIS_PRESSED 3 | |
4b94ddc4 RD |
77 | |
78 | #define TMT_HEIGHT 2417 | |
79 | ||
80 | #define HP_HEADERSORTARROW 4 | |
81 | #define HSAS_SORTEDUP 1 | |
82 | #define HSAS_SORTEDDOWN 2 | |
e4131985 KO |
83 | |
84 | #define EP_EDITTEXT 1 | |
85 | #define ETS_NORMAL 1 | |
86 | #define ETS_HOT 2 | |
87 | #define ETS_SELECTED 3 | |
88 | #define ETS_DISABLED 4 | |
89 | #define ETS_FOCUSED 5 | |
90 | #define ETS_READONLY 6 | |
91 | #define ETS_ASSIST 7 | |
92 | #define TMT_FILLCOLOR 3802 | |
93 | #define TMT_TEXTCOLOR 3803 | |
94 | #define TMT_BORDERCOLOR 3801 | |
95 | #define TMT_EDGEFILLCOLOR 3808 | |
b50d93d1 VZ |
96 | |
97 | #define WP_MINBUTTON 15 | |
98 | #define WP_MAXBUTTON 17 | |
99 | #define WP_CLOSEBUTTON 18 | |
100 | #define WP_RESTOREBUTTON 21 | |
101 | #define WP_HELPBUTTON 23 | |
7cf3223a VZ |
102 | #endif |
103 | ||
d6f2a891 VZ |
104 | #if defined(__WXWINCE__) |
105 | #ifndef DFCS_FLAT | |
106 | #define DFCS_FLAT 0 | |
107 | #endif | |
108 | #ifndef DFCS_MONO | |
109 | #define DFCS_MONO 0 | |
110 | #endif | |
9f93b45e VZ |
111 | #endif |
112 | ||
59ee63e9 VZ |
113 | #ifndef DFCS_HOT |
114 | #define DFCS_HOT 0x1000 | |
115 | #endif | |
116 | ||
de4bf0b3 FM |
117 | // ---------------------------------------------------------------------------- |
118 | // methods common to wxRendererMSW and wxRendererXP | |
119 | // ---------------------------------------------------------------------------- | |
120 | ||
121 | class wxRendererMSWBase : public wxDelegateRendererNative | |
122 | { | |
123 | public: | |
124 | wxRendererMSWBase() { } | |
125 | wxRendererMSWBase(wxRendererNative& rendererNative) | |
126 | : wxDelegateRendererNative(rendererNative) { } | |
127 | ||
128 | void DrawFocusRect(wxWindow * win, | |
129 | wxDC& dc, | |
130 | const wxRect& rect, | |
131 | int flags = 0); | |
132 | ||
133 | void DrawItemSelectionRect(wxWindow *win, | |
134 | wxDC& dc, | |
135 | const wxRect& rect, | |
136 | int flags = 0); | |
137 | }; | |
138 | ||
9c7f49f5 | 139 | // ---------------------------------------------------------------------------- |
8b97949e | 140 | // wxRendererMSW: wxRendererNative implementation for "old" Win32 systems |
9c7f49f5 VZ |
141 | // ---------------------------------------------------------------------------- |
142 | ||
5aac6f3f | 143 | class wxRendererMSW : public wxRendererMSWBase |
9c7f49f5 | 144 | { |
2eb10e2a VZ |
145 | public: |
146 | wxRendererMSW() { } | |
147 | ||
8b97949e VZ |
148 | static wxRendererNative& Get(); |
149 | ||
7402677a VZ |
150 | virtual void DrawComboBoxDropButton(wxWindow *win, |
151 | wxDC& dc, | |
152 | const wxRect& rect, | |
153 | int flags = 0); | |
154 | ||
59ee63e9 VZ |
155 | virtual void DrawCheckBox(wxWindow *win, |
156 | wxDC& dc, | |
157 | const wxRect& rect, | |
081b3342 VZ |
158 | int flags = 0) |
159 | { | |
160 | DoDrawButton(DFCS_BUTTONCHECK, win, dc, rect, flags); | |
161 | } | |
59ee63e9 | 162 | |
2209baae RR |
163 | virtual void DrawPushButton(wxWindow *win, |
164 | wxDC& dc, | |
165 | const wxRect& rect, | |
166 | int flags = 0); | |
167 | ||
7280c828 VZ |
168 | virtual void DrawChoice(wxWindow* win, |
169 | wxDC& dc, | |
170 | const wxRect& rect, | |
081b3342 | 171 | int flags = 0); |
e4131985 | 172 | |
7280c828 | 173 | virtual void DrawComboBox(wxWindow* win, |
081b3342 VZ |
174 | wxDC& dc, |
175 | const wxRect& rect, | |
176 | int flags = 0); | |
e4131985 | 177 | |
7280c828 | 178 | virtual void DrawTextCtrl(wxWindow* win, |
081b3342 VZ |
179 | wxDC& dc, |
180 | const wxRect& rect, | |
181 | int flags = 0); | |
e4131985 | 182 | |
6e6b532c | 183 | virtual void DrawRadioBitmap(wxWindow* win, |
081b3342 VZ |
184 | wxDC& dc, |
185 | const wxRect& rect, | |
186 | int flags = 0) | |
187 | { | |
188 | DoDrawButton(DFCS_BUTTONRADIO, win, dc, rect, flags); | |
189 | } | |
e4131985 | 190 | |
b50d93d1 VZ |
191 | virtual void DrawTitleBarBitmap(wxWindow *win, |
192 | wxDC& dc, | |
193 | const wxRect& rect, | |
194 | wxTitleBarButton button, | |
195 | int flags = 0); | |
196 | ||
191e43fd | 197 | virtual wxSize GetCheckBoxSize(wxWindow *win); |
e8759560 | 198 | |
51c42fc5 VZ |
199 | virtual int GetHeaderButtonHeight(wxWindow *win); |
200 | ||
9aebcb5e VS |
201 | virtual int GetHeaderButtonMargin(wxWindow *win); |
202 | ||
2eb10e2a | 203 | private: |
b50d93d1 VZ |
204 | // wrapper of DrawFrameControl() |
205 | void DoDrawFrameControl(UINT type, | |
206 | UINT kind, | |
207 | wxWindow *win, | |
208 | wxDC& dc, | |
209 | const wxRect& rect, | |
210 | int flags); | |
211 | ||
081b3342 VZ |
212 | // common part of Draw{PushButton,CheckBox,RadioBitmap}(): wraps |
213 | // DrawFrameControl(DFC_BUTTON) | |
214 | void DoDrawButton(UINT kind, | |
215 | wxWindow *win, | |
216 | wxDC& dc, | |
217 | const wxRect& rect, | |
b50d93d1 VZ |
218 | int flags) |
219 | { | |
220 | DoDrawFrameControl(DFC_BUTTON, kind, win, dc, rect, flags); | |
221 | } | |
081b3342 | 222 | |
c0c133e1 | 223 | wxDECLARE_NO_COPY_CLASS(wxRendererMSW); |
9c7f49f5 VZ |
224 | }; |
225 | ||
8b97949e VZ |
226 | // ---------------------------------------------------------------------------- |
227 | // wxRendererXP: wxRendererNative implementation for Windows XP and later | |
228 | // ---------------------------------------------------------------------------- | |
229 | ||
7cf3223a VZ |
230 | #if wxUSE_UXTHEME |
231 | ||
5aac6f3f | 232 | class wxRendererXP : public wxRendererMSWBase |
8b97949e VZ |
233 | { |
234 | public: | |
de4bf0b3 | 235 | wxRendererXP() : wxRendererMSWBase(wxRendererMSW::Get()) { } |
8b97949e VZ |
236 | |
237 | static wxRendererNative& Get(); | |
238 | ||
c97c9952 | 239 | virtual int DrawHeaderButton(wxWindow *win, |
4b94ddc4 RD |
240 | wxDC& dc, |
241 | const wxRect& rect, | |
242 | int flags = 0, | |
80752b57 | 243 | wxHeaderSortIconType sortArrow = wxHDR_SORT_ICON_NONE, |
4b94ddc4 | 244 | wxHeaderButtonParams* params = NULL); |
f4322df6 | 245 | |
9f93b45e VZ |
246 | virtual void DrawTreeItemButton(wxWindow *win, |
247 | wxDC& dc, | |
248 | const wxRect& rect, | |
249 | int flags = 0); | |
8b97949e VZ |
250 | virtual void DrawSplitterBorder(wxWindow *win, |
251 | wxDC& dc, | |
c4e6c15e VZ |
252 | const wxRect& rect, |
253 | int flags = 0); | |
8b97949e VZ |
254 | virtual void DrawSplitterSash(wxWindow *win, |
255 | wxDC& dc, | |
256 | const wxSize& size, | |
257 | wxCoord position, | |
c4e6c15e VZ |
258 | wxOrientation orient, |
259 | int flags = 0); | |
7cf3223a VZ |
260 | virtual void DrawComboBoxDropButton(wxWindow *win, |
261 | wxDC& dc, | |
262 | const wxRect& rect, | |
263 | int flags = 0); | |
90b903c2 WS |
264 | virtual void DrawCheckBox(wxWindow *win, |
265 | wxDC& dc, | |
266 | const wxRect& rect, | |
6c9aaf7d VZ |
267 | int flags = 0) |
268 | { | |
269 | if ( !DoDrawXPButton(BP_CHECKBOX, win, dc, rect, flags) ) | |
270 | m_rendererNative.DrawCheckBox(win, dc, rect, flags); | |
271 | } | |
9f93b45e | 272 | |
2209baae RR |
273 | virtual void DrawPushButton(wxWindow *win, |
274 | wxDC& dc, | |
275 | const wxRect& rect, | |
6c9aaf7d VZ |
276 | int flags = 0) |
277 | { | |
278 | if ( !DoDrawXPButton(BP_PUSHBUTTON, win, dc, rect, flags) ) | |
279 | m_rendererNative.DrawPushButton(win, dc, rect, flags); | |
280 | } | |
2209baae | 281 | |
081b3342 VZ |
282 | virtual void DrawRadioBitmap(wxWindow *win, |
283 | wxDC& dc, | |
284 | const wxRect& rect, | |
6c9aaf7d VZ |
285 | int flags = 0) |
286 | { | |
287 | if ( !DoDrawXPButton(BP_RADIOBUTTON, win, dc, rect, flags) ) | |
288 | m_rendererNative.DrawRadioBitmap(win, dc, rect, flags); | |
289 | } | |
081b3342 | 290 | |
b50d93d1 VZ |
291 | virtual void DrawTitleBarBitmap(wxWindow *win, |
292 | wxDC& dc, | |
293 | const wxRect& rect, | |
294 | wxTitleBarButton button, | |
295 | int flags = 0); | |
296 | ||
9f93b45e | 297 | virtual wxSplitterRenderParams GetSplitterParams(const wxWindow *win); |
081b3342 | 298 | |
8b97949e | 299 | private: |
b50d93d1 VZ |
300 | // wrapper around DrawThemeBackground() translating flags to NORMAL/HOT/ |
301 | // PUSHED/DISABLED states (and so suitable for drawing anything | |
302 | // button-like) | |
303 | void DoDrawButtonLike(HTHEME htheme, | |
304 | int part, | |
305 | wxDC& dc, | |
306 | const wxRect& rect, | |
307 | int flags); | |
308 | ||
6c9aaf7d VZ |
309 | // common part of DrawCheckBox(), DrawPushButton() and DrawRadioBitmap() |
310 | bool DoDrawXPButton(int kind, | |
311 | wxWindow *win, | |
312 | wxDC& dc, | |
313 | const wxRect& rect, | |
314 | int flags); | |
315 | ||
c0c133e1 | 316 | wxDECLARE_NO_COPY_CLASS(wxRendererXP); |
8b97949e VZ |
317 | }; |
318 | ||
7cf3223a VZ |
319 | #endif // wxUSE_UXTHEME |
320 | ||
de4bf0b3 FM |
321 | |
322 | // ============================================================================ | |
323 | // wxRendererMSWBase implementation | |
324 | // ============================================================================ | |
325 | ||
326 | void wxRendererMSWBase::DrawFocusRect(wxWindow * WXUNUSED(win), | |
327 | wxDC& dc, | |
328 | const wxRect& rect, | |
329 | int WXUNUSED(flags)) | |
330 | { | |
331 | RECT rc; | |
332 | wxCopyRectToRECT(rect, rc); | |
333 | ||
942d5e2d | 334 | ::DrawFocusRect(GetHdcOf(dc.GetTempHDC()), &rc); |
de4bf0b3 FM |
335 | } |
336 | ||
337 | void wxRendererMSWBase::DrawItemSelectionRect(wxWindow *win, | |
338 | wxDC& dc, | |
339 | const wxRect& rect, | |
340 | int flags) | |
341 | { | |
342 | wxBrush brush; | |
343 | if ( flags & wxCONTROL_SELECTED ) | |
344 | { | |
345 | if ( flags & wxCONTROL_FOCUSED ) | |
346 | { | |
347 | brush = wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT)); | |
348 | } | |
349 | else // !focused | |
350 | { | |
351 | brush = wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE)); | |
352 | } | |
353 | } | |
354 | else // !selected | |
355 | { | |
356 | brush = *wxTRANSPARENT_BRUSH; | |
357 | } | |
358 | ||
359 | dc.SetBrush(brush); | |
360 | dc.SetPen(*wxTRANSPARENT_PEN); | |
361 | dc.DrawRectangle( rect ); | |
362 | ||
363 | if ((flags & wxCONTROL_FOCUSED) && (flags & wxCONTROL_CURRENT)) | |
364 | DrawFocusRect( win, dc, rect, flags ); | |
365 | } | |
366 | ||
367 | ||
9c7f49f5 | 368 | // ============================================================================ |
8b97949e | 369 | // wxRendererNative and wxRendererMSW implementation |
9c7f49f5 VZ |
370 | // ============================================================================ |
371 | ||
372 | /* static */ | |
f0244295 | 373 | wxRendererNative& wxRendererNative::GetDefault() |
8b97949e | 374 | { |
7cf3223a | 375 | #if wxUSE_UXTHEME |
8b97949e | 376 | wxUxThemeEngine *themeEngine = wxUxThemeEngine::Get(); |
7cf3223a VZ |
377 | if ( themeEngine && themeEngine->IsAppThemed() ) |
378 | return wxRendererXP::Get(); | |
379 | #endif // wxUSE_UXTHEME | |
380 | ||
381 | return wxRendererMSW::Get(); | |
8b97949e VZ |
382 | } |
383 | ||
384 | /* static */ | |
385 | wxRendererNative& wxRendererMSW::Get() | |
9c7f49f5 VZ |
386 | { |
387 | static wxRendererMSW s_rendererMSW; | |
388 | ||
389 | return s_rendererMSW; | |
390 | } | |
391 | ||
7402677a VZ |
392 | void |
393 | wxRendererMSW::DrawComboBoxDropButton(wxWindow * WXUNUSED(win), | |
394 | wxDC& dc, | |
395 | const wxRect& rect, | |
396 | int flags) | |
397 | { | |
53d4bdbc VZ |
398 | wxCHECK_RET( dc.GetImpl(), wxT("Invalid wxDC") ); |
399 | ||
400 | wxRect adjustedRect = dc.GetImpl()->MSWApplyGDIPlusTransform(rect); | |
066bd251 | 401 | |
7402677a | 402 | RECT r; |
066bd251 | 403 | wxCopyRectToRECT(adjustedRect, r); |
7402677a VZ |
404 | |
405 | int style = DFCS_SCROLLCOMBOBOX; | |
406 | if ( flags & wxCONTROL_DISABLED ) | |
407 | style |= DFCS_INACTIVE; | |
408 | if ( flags & wxCONTROL_PRESSED ) | |
7cf3223a | 409 | style |= DFCS_PUSHED | DFCS_FLAT; |
7402677a | 410 | |
942d5e2d | 411 | ::DrawFrameControl(GetHdcOf(dc.GetTempHDC()), &r, DFC_SCROLL, style); |
7402677a VZ |
412 | } |
413 | ||
59ee63e9 | 414 | void |
b50d93d1 VZ |
415 | wxRendererMSW::DoDrawFrameControl(UINT type, |
416 | UINT kind, | |
417 | wxWindow * WXUNUSED(win), | |
418 | wxDC& dc, | |
419 | const wxRect& rect, | |
420 | int flags) | |
59ee63e9 | 421 | { |
53d4bdbc VZ |
422 | wxCHECK_RET( dc.GetImpl(), wxT("Invalid wxDC") ); |
423 | ||
424 | wxRect adjustedRect = dc.GetImpl()->MSWApplyGDIPlusTransform(rect); | |
066bd251 | 425 | |
59ee63e9 | 426 | RECT r; |
066bd251 | 427 | wxCopyRectToRECT(adjustedRect, r); |
59ee63e9 | 428 | |
081b3342 | 429 | int style = kind; |
59ee63e9 VZ |
430 | if ( flags & wxCONTROL_CHECKED ) |
431 | style |= DFCS_CHECKED; | |
432 | if ( flags & wxCONTROL_DISABLED ) | |
433 | style |= DFCS_INACTIVE; | |
8a461249 VZ |
434 | if ( flags & wxCONTROL_FLAT ) |
435 | style |= DFCS_MONO; | |
59ee63e9 VZ |
436 | if ( flags & wxCONTROL_PRESSED ) |
437 | style |= DFCS_PUSHED; | |
438 | if ( flags & wxCONTROL_CURRENT ) | |
439 | style |= DFCS_HOT; | |
07968bbd DS |
440 | if ( flags & wxCONTROL_UNDETERMINED ) |
441 | // Using DFCS_BUTTON3STATE here doesn't work (as might be expected), | |
442 | // use the following two styles to get the same look of a check box | |
443 | // in the undetermined state. | |
444 | style |= DFCS_INACTIVE | DFCS_CHECKED; | |
59ee63e9 | 445 | |
b50d93d1 | 446 | ::DrawFrameControl(GetHdcOf(dc.GetTempHDC()), &r, type, style); |
59ee63e9 VZ |
447 | } |
448 | ||
2209baae | 449 | void |
081b3342 | 450 | wxRendererMSW::DrawPushButton(wxWindow *win, |
2209baae | 451 | wxDC& dc, |
f2ea4255 | 452 | const wxRect& rectOrig, |
2209baae RR |
453 | int flags) |
454 | { | |
f2ea4255 | 455 | wxRect rect(rectOrig); |
f2ea4255 VZ |
456 | if ( flags & wxCONTROL_ISDEFAULT ) |
457 | { | |
458 | // DrawFrameControl() doesn't seem to support default buttons so we | |
459 | // have to draw the border ourselves | |
460 | wxDCPenChanger pen(dc, *wxBLACK_PEN); | |
461 | wxDCBrushChanger brush(dc, *wxTRANSPARENT_BRUSH); | |
462 | dc.DrawRectangle(rect); | |
844b9f5f | 463 | rect.Deflate(1); |
f2ea4255 VZ |
464 | } |
465 | ||
081b3342 | 466 | DoDrawButton(DFCS_BUTTONPUSH, win, dc, rect, flags); |
2209baae RR |
467 | } |
468 | ||
b50d93d1 VZ |
469 | void |
470 | wxRendererMSW::DrawTitleBarBitmap(wxWindow *win, | |
471 | wxDC& dc, | |
472 | const wxRect& rect, | |
473 | wxTitleBarButton button, | |
474 | int flags) | |
475 | { | |
476 | UINT kind; | |
477 | switch ( button ) | |
478 | { | |
479 | case wxTITLEBAR_BUTTON_CLOSE: | |
480 | kind = DFCS_CAPTIONCLOSE; | |
481 | break; | |
482 | ||
483 | case wxTITLEBAR_BUTTON_MAXIMIZE: | |
484 | kind = DFCS_CAPTIONMAX; | |
485 | break; | |
486 | ||
487 | case wxTITLEBAR_BUTTON_ICONIZE: | |
488 | kind = DFCS_CAPTIONMIN; | |
489 | break; | |
490 | ||
491 | case wxTITLEBAR_BUTTON_RESTORE: | |
492 | kind = DFCS_CAPTIONRESTORE; | |
493 | break; | |
494 | ||
495 | case wxTITLEBAR_BUTTON_HELP: | |
496 | kind = DFCS_CAPTIONHELP; | |
497 | break; | |
498 | ||
499 | default: | |
500 | wxFAIL_MSG( "unsupported title bar button" ); | |
501 | return; | |
502 | } | |
503 | ||
504 | DoDrawFrameControl(DFC_CAPTION, kind, win, dc, rect, flags); | |
505 | } | |
506 | ||
191e43fd | 507 | wxSize wxRendererMSW::GetCheckBoxSize(wxWindow * WXUNUSED(win)) |
e8759560 VZ |
508 | { |
509 | return wxSize(::GetSystemMetrics(SM_CXMENUCHECK), | |
510 | ::GetSystemMetrics(SM_CYMENUCHECK)); | |
511 | } | |
512 | ||
51c42fc5 VZ |
513 | int wxRendererMSW::GetHeaderButtonHeight(wxWindow * WXUNUSED(win)) |
514 | { | |
515 | // some "reasonable" value returned in case of error, it doesn't really | |
516 | // correspond to anything but it's better than returning 0 | |
517 | static const int DEFAULT_HEIGHT = 20; | |
518 | ||
519 | ||
520 | // create a temporary header window just to get its geometry | |
a268f4b7 | 521 | HWND hwndHeader = ::CreateWindow(WC_HEADER, NULL, 0, |
51c42fc5 VZ |
522 | 0, 0, 0, 0, NULL, NULL, NULL, NULL); |
523 | if ( !hwndHeader ) | |
524 | return DEFAULT_HEIGHT; | |
525 | ||
526 | wxON_BLOCK_EXIT1( ::DestroyWindow, hwndHeader ); | |
527 | ||
528 | // initialize the struct filled with the values by Header_Layout() | |
529 | RECT parentRect = { 0, 0, 100, 100 }; | |
11fa6e63 | 530 | WINDOWPOS wp = { 0, 0, 0, 0, 0, 0, 0 }; |
51c42fc5 VZ |
531 | HDLAYOUT hdl = { &parentRect, &wp }; |
532 | ||
533 | return Header_Layout(hwndHeader, &hdl) ? wp.cy : DEFAULT_HEIGHT; | |
534 | } | |
535 | ||
9aebcb5e VS |
536 | int wxRendererMSW::GetHeaderButtonMargin(wxWindow *WXUNUSED(win)) |
537 | { | |
538 | return 10; | |
539 | } | |
540 | ||
e4131985 KO |
541 | // Uses the theme to draw the border and fill for something like a wxTextCtrl |
542 | void wxRendererMSW::DrawTextCtrl(wxWindow* win, wxDC& dc, const wxRect& rect, int flags) | |
543 | { | |
544 | wxColour fill; | |
545 | wxColour bdr; | |
546 | COLORREF cref; | |
7280c828 | 547 | |
e4131985 KO |
548 | #if wxUSE_UXTHEME |
549 | wxUxThemeHandle hTheme(win, L"EDIT"); | |
550 | if (hTheme) | |
551 | { | |
552 | wxUxThemeEngine::Get()->GetThemeColor(hTheme, EP_EDITTEXT, | |
553 | ETS_NORMAL, TMT_FILLCOLOR, &cref); | |
554 | fill = wxRGBToColour(cref); | |
555 | ||
556 | int etsState; | |
557 | if ( flags & wxCONTROL_DISABLED ) | |
558 | etsState = ETS_DISABLED; | |
559 | else | |
560 | etsState = ETS_NORMAL; | |
7280c828 | 561 | |
e4131985 KO |
562 | wxUxThemeEngine::Get()->GetThemeColor(hTheme, EP_EDITTEXT, |
563 | etsState, TMT_BORDERCOLOR, &cref); | |
7280c828 | 564 | bdr = wxRGBToColour(cref); |
e4131985 KO |
565 | } |
566 | else | |
567 | #endif | |
568 | { | |
569 | fill = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW); | |
570 | bdr = *wxBLACK; | |
571 | } | |
7280c828 | 572 | |
e4131985 KO |
573 | dc.SetPen( bdr ); |
574 | dc.SetBrush( fill ); | |
575 | dc.DrawRectangle(rect); | |
576 | } | |
577 | ||
578 | ||
081b3342 | 579 | // Draw the equivalent of a wxComboBox |
e4131985 KO |
580 | void wxRendererMSW::DrawComboBox(wxWindow* win, wxDC& dc, const wxRect& rect, int flags) |
581 | { | |
582 | // Draw the main part of the control same as TextCtrl | |
7280c828 VZ |
583 | DrawTextCtrl(win, dc, rect, flags); |
584 | ||
e4131985 KO |
585 | // Draw the button inside the border, on the right side |
586 | wxRect br(rect); | |
587 | br.height -= 2; | |
588 | br.x += br.width - br.height - 1; | |
589 | br.width = br.height; | |
590 | br.y += 1; | |
591 | ||
592 | DrawComboBoxDropButton(win, dc, br, flags); | |
593 | } | |
594 | ||
595 | ||
596 | void wxRendererMSW::DrawChoice(wxWindow* win, wxDC& dc, | |
597 | const wxRect& rect, int flags) | |
598 | { | |
599 | DrawComboBox(win, dc, rect, flags); | |
600 | } | |
601 | ||
8b97949e VZ |
602 | // ============================================================================ |
603 | // wxRendererXP implementation | |
604 | // ============================================================================ | |
605 | ||
7cf3223a VZ |
606 | #if wxUSE_UXTHEME |
607 | ||
8b97949e VZ |
608 | /* static */ |
609 | wxRendererNative& wxRendererXP::Get() | |
610 | { | |
611 | static wxRendererXP s_rendererXP; | |
612 | ||
613 | return s_rendererXP; | |
614 | } | |
615 | ||
7cf3223a VZ |
616 | // NOTE: There is no guarantee that the button drawn fills the entire rect (XP |
617 | // default theme, for example), so the caller should have cleared button's | |
618 | // background before this call. This is quite likely a wxMSW-specific thing. | |
619 | void | |
620 | wxRendererXP::DrawComboBoxDropButton(wxWindow * win, | |
621 | wxDC& dc, | |
622 | const wxRect& rect, | |
623 | int flags) | |
624 | { | |
625 | wxUxThemeHandle hTheme(win, L"COMBOBOX"); | |
9f93b45e | 626 | if ( !hTheme ) |
7cf3223a | 627 | { |
9f93b45e VZ |
628 | m_rendererNative.DrawComboBoxDropButton(win, dc, rect, flags); |
629 | return; | |
630 | } | |
631 | ||
53d4bdbc VZ |
632 | wxCHECK_RET( dc.GetImpl(), wxT("Invalid wxDC") ); |
633 | ||
634 | wxRect adjustedRect = dc.GetImpl()->MSWApplyGDIPlusTransform(rect); | |
066bd251 | 635 | |
9f93b45e | 636 | RECT r; |
066bd251 | 637 | wxCopyRectToRECT(adjustedRect, r); |
7cf3223a | 638 | |
9f93b45e VZ |
639 | int state; |
640 | if ( flags & wxCONTROL_PRESSED ) | |
641 | state = CBXS_PRESSED; | |
642 | else if ( flags & wxCONTROL_CURRENT ) | |
643 | state = CBXS_HOT; | |
644 | else if ( flags & wxCONTROL_DISABLED ) | |
645 | state = CBXS_DISABLED; | |
646 | else | |
647 | state = CBXS_NORMAL; | |
648 | ||
649 | wxUxThemeEngine::Get()->DrawThemeBackground | |
650 | ( | |
651 | hTheme, | |
942d5e2d | 652 | GetHdcOf(dc.GetTempHDC()), |
9f93b45e VZ |
653 | CP_DROPDOWNBUTTON, |
654 | state, | |
655 | &r, | |
656 | NULL | |
657 | ); | |
658 | ||
659 | } | |
660 | ||
c97c9952 | 661 | int |
9f93b45e VZ |
662 | wxRendererXP::DrawHeaderButton(wxWindow *win, |
663 | wxDC& dc, | |
664 | const wxRect& rect, | |
4b94ddc4 | 665 | int flags, |
80752b57 | 666 | wxHeaderSortIconType sortArrow, |
4b94ddc4 | 667 | wxHeaderButtonParams* params) |
9f93b45e VZ |
668 | { |
669 | wxUxThemeHandle hTheme(win, L"HEADER"); | |
670 | if ( !hTheme ) | |
671 | { | |
c97c9952 | 672 | return m_rendererNative.DrawHeaderButton(win, dc, rect, flags, sortArrow, params); |
7cf3223a | 673 | } |
9f93b45e | 674 | |
53d4bdbc VZ |
675 | wxCHECK_MSG( dc.GetImpl(), -1, wxT("Invalid wxDC") ); |
676 | ||
677 | wxRect adjustedRect = dc.GetImpl()->MSWApplyGDIPlusTransform(rect); | |
066bd251 | 678 | |
9f93b45e | 679 | RECT r; |
066bd251 | 680 | wxCopyRectToRECT(adjustedRect, r); |
9f93b45e VZ |
681 | |
682 | int state; | |
683 | if ( flags & wxCONTROL_PRESSED ) | |
684 | state = HIS_PRESSED; | |
685 | else if ( flags & wxCONTROL_CURRENT ) | |
686 | state = HIS_HOT; | |
687 | else | |
688 | state = HIS_NORMAL; | |
689 | wxUxThemeEngine::Get()->DrawThemeBackground | |
690 | ( | |
691 | hTheme, | |
942d5e2d | 692 | GetHdcOf(dc.GetTempHDC()), |
9f93b45e VZ |
693 | HP_HEADERITEM, |
694 | state, | |
695 | &r, | |
696 | NULL | |
697 | ); | |
4b94ddc4 RD |
698 | |
699 | // NOTE: Using the theme to draw HP_HEADERSORTARROW doesn't do anything. | |
700 | // Why? If this can be fixed then draw the sort arrows using the theme | |
701 | // and then clear those flags before calling DrawHeaderButtonContents. | |
f4322df6 | 702 | |
4b94ddc4 | 703 | // Add any extras that are specified in flags and params |
c97c9952 | 704 | return DrawHeaderButtonContents(win, dc, rect, flags, sortArrow, params); |
9f93b45e VZ |
705 | } |
706 | ||
4b94ddc4 | 707 | |
9f93b45e VZ |
708 | void |
709 | wxRendererXP::DrawTreeItemButton(wxWindow *win, | |
710 | wxDC& dc, | |
711 | const wxRect& rect, | |
712 | int flags) | |
713 | { | |
714 | wxUxThemeHandle hTheme(win, L"TREEVIEW"); | |
715 | if ( !hTheme ) | |
716 | { | |
717 | m_rendererNative.DrawTreeItemButton(win, dc, rect, flags); | |
718 | return; | |
719 | } | |
720 | ||
53d4bdbc VZ |
721 | wxCHECK_RET( dc.GetImpl(), wxT("Invalid wxDC") ); |
722 | ||
723 | wxRect adjustedRect = dc.GetImpl()->MSWApplyGDIPlusTransform(rect); | |
066bd251 | 724 | |
9f93b45e | 725 | RECT r; |
066bd251 | 726 | wxCopyRectToRECT(adjustedRect, r); |
9f93b45e VZ |
727 | |
728 | int state = flags & wxCONTROL_EXPANDED ? GLPS_OPENED : GLPS_CLOSED; | |
729 | wxUxThemeEngine::Get()->DrawThemeBackground | |
730 | ( | |
731 | hTheme, | |
942d5e2d | 732 | GetHdcOf(dc.GetTempHDC()), |
9f93b45e VZ |
733 | TVP_GLYPH, |
734 | state, | |
735 | &r, | |
736 | NULL | |
737 | ); | |
738 | } | |
739 | ||
6c9aaf7d VZ |
740 | bool |
741 | wxRendererXP::DoDrawXPButton(int kind, | |
742 | wxWindow *win, | |
743 | wxDC& dc, | |
744 | const wxRect& rect, | |
745 | int flags) | |
9f93b45e VZ |
746 | { |
747 | wxUxThemeHandle hTheme(win, L"BUTTON"); | |
748 | if ( !hTheme ) | |
6c9aaf7d | 749 | return false; |
9f93b45e | 750 | |
b50d93d1 | 751 | DoDrawButtonLike(hTheme, kind, dc, rect, flags); |
59ee63e9 | 752 | |
b50d93d1 VZ |
753 | return true; |
754 | } | |
9f93b45e | 755 | |
b50d93d1 VZ |
756 | void |
757 | wxRendererXP::DoDrawButtonLike(HTHEME htheme, | |
758 | int part, | |
759 | wxDC& dc, | |
760 | const wxRect& rect, | |
761 | int flags) | |
762 | { | |
53d4bdbc VZ |
763 | wxCHECK_RET( dc.GetImpl(), wxT("Invalid wxDC") ); |
764 | ||
765 | wxRect adjustedRect = dc.GetImpl()->MSWApplyGDIPlusTransform(rect); | |
066bd251 | 766 | |
b50d93d1 | 767 | RECT r; |
066bd251 | 768 | wxCopyRectToRECT(adjustedRect, r); |
7cf3223a | 769 | |
b50d93d1 VZ |
770 | // the base state is always 1, whether it is PBS_NORMAL, |
771 | // {CBS,RBS}_UNCHECKEDNORMAL or CBS_NORMAL | |
772 | int state = 1; | |
081b3342 | 773 | |
6c9aaf7d VZ |
774 | // XBS_XXX is followed by XBX_XXXHOT, then XBS_XXXPRESSED and DISABLED |
775 | enum | |
776 | { | |
777 | NORMAL_OFFSET, | |
778 | HOT_OFFSET, | |
779 | PRESSED_OFFSET, | |
780 | DISABLED_OFFSET, | |
781 | STATES_COUNT | |
782 | }; | |
081b3342 | 783 | |
6c9aaf7d VZ |
784 | // in both RBS_ and CBS_ enums CHECKED elements are offset by 4 from base |
785 | // (UNCHECKED) ones and MIXED are offset by 4 again as there are all states | |
786 | // from the above enum in between them | |
081b3342 | 787 | if ( flags & wxCONTROL_CHECKED ) |
6c9aaf7d | 788 | state += STATES_COUNT; |
081b3342 | 789 | else if ( flags & wxCONTROL_UNDETERMINED ) |
6c9aaf7d | 790 | state += 2*STATES_COUNT; |
081b3342 | 791 | |
6c9aaf7d VZ |
792 | if ( flags & wxCONTROL_DISABLED ) |
793 | state += DISABLED_OFFSET; | |
081b3342 | 794 | else if ( flags & wxCONTROL_PRESSED ) |
6c9aaf7d | 795 | state += PRESSED_OFFSET; |
2209baae | 796 | else if ( flags & wxCONTROL_CURRENT ) |
6c9aaf7d VZ |
797 | state += HOT_OFFSET; |
798 | // wxCONTROL_ISDEFAULT flag is only valid for push buttons | |
b50d93d1 | 799 | else if ( part == BP_PUSHBUTTON && (flags & wxCONTROL_ISDEFAULT) ) |
2209baae | 800 | state = PBS_DEFAULTED; |
2209baae RR |
801 | |
802 | wxUxThemeEngine::Get()->DrawThemeBackground | |
803 | ( | |
b50d93d1 | 804 | htheme, |
942d5e2d | 805 | GetHdcOf(dc.GetTempHDC()), |
b50d93d1 | 806 | part, |
2209baae RR |
807 | state, |
808 | &r, | |
809 | NULL | |
810 | ); | |
b50d93d1 | 811 | } |
2209baae | 812 | |
b50d93d1 VZ |
813 | void |
814 | wxRendererXP::DrawTitleBarBitmap(wxWindow *win, | |
815 | wxDC& dc, | |
816 | const wxRect& rect, | |
817 | wxTitleBarButton button, | |
818 | int flags) | |
819 | { | |
820 | wxUxThemeHandle hTheme(win, L"WINDOW"); | |
821 | if ( !hTheme ) | |
822 | { | |
823 | m_rendererNative.DrawTitleBarBitmap(win, dc, rect, button, flags); | |
824 | return; | |
825 | } | |
826 | ||
827 | int part; | |
828 | switch ( button ) | |
829 | { | |
830 | case wxTITLEBAR_BUTTON_CLOSE: | |
831 | part = WP_CLOSEBUTTON; | |
832 | break; | |
833 | ||
834 | case wxTITLEBAR_BUTTON_MAXIMIZE: | |
835 | part = WP_MAXBUTTON; | |
836 | break; | |
837 | ||
838 | case wxTITLEBAR_BUTTON_ICONIZE: | |
839 | part = WP_MINBUTTON; | |
840 | break; | |
841 | ||
842 | case wxTITLEBAR_BUTTON_RESTORE: | |
843 | part = WP_RESTOREBUTTON; | |
844 | break; | |
845 | ||
846 | case wxTITLEBAR_BUTTON_HELP: | |
847 | part = WP_HELPBUTTON; | |
848 | break; | |
849 | ||
850 | default: | |
851 | wxFAIL_MSG( "unsupported title bar button" ); | |
852 | return; | |
853 | } | |
854 | ||
855 | DoDrawButtonLike(hTheme, part, dc, rect, flags); | |
6c9aaf7d | 856 | } |
a9fdf824 | 857 | |
8b97949e VZ |
858 | // ---------------------------------------------------------------------------- |
859 | // splitter drawing | |
860 | // ---------------------------------------------------------------------------- | |
861 | ||
862 | // the width of the sash: this is the same as used by Explorer... | |
863 | static const wxCoord SASH_WIDTH = 4; | |
864 | ||
c4e6c15e | 865 | wxSplitterRenderParams |
3c2544bb | 866 | wxRendererXP::GetSplitterParams(const wxWindow * win) |
8b97949e | 867 | { |
9f93b45e | 868 | if ( win->HasFlag(wxSP_NO_XP_THEME) ) |
3c2544bb JS |
869 | return m_rendererNative.GetSplitterParams(win); |
870 | else | |
871 | return wxSplitterRenderParams(SASH_WIDTH, 0, false); | |
8b97949e VZ |
872 | } |
873 | ||
874 | void | |
3c2544bb JS |
875 | wxRendererXP::DrawSplitterBorder(wxWindow * win, |
876 | wxDC& dc, | |
877 | const wxRect& rect, | |
878 | int flags) | |
8b97949e | 879 | { |
9f93b45e | 880 | if ( win->HasFlag(wxSP_NO_XP_THEME) ) |
3c2544bb JS |
881 | { |
882 | m_rendererNative.DrawSplitterBorder(win, dc, rect, flags); | |
883 | } | |
8b97949e VZ |
884 | } |
885 | ||
886 | void | |
887 | wxRendererXP::DrawSplitterSash(wxWindow *win, | |
888 | wxDC& dc, | |
889 | const wxSize& size, | |
890 | wxCoord position, | |
c4e6c15e | 891 | wxOrientation orient, |
3c2544bb | 892 | int flags) |
8b97949e | 893 | { |
6421119d | 894 | if ( !win->HasFlag(wxSP_NO_XP_THEME) ) |
8b97949e | 895 | { |
fe404d1a JS |
896 | dc.SetPen(*wxTRANSPARENT_PEN); |
897 | dc.SetBrush(wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE))); | |
898 | if ( orient == wxVERTICAL ) | |
8b97949e | 899 | { |
fe404d1a | 900 | dc.DrawRectangle(position, 0, SASH_WIDTH, size.y); |
8b97949e | 901 | } |
fe404d1a JS |
902 | else // wxHORIZONTAL |
903 | { | |
904 | dc.DrawRectangle(0, position, size.x, SASH_WIDTH); | |
905 | } | |
906 | ||
907 | return; | |
8b97949e | 908 | } |
6421119d VZ |
909 | |
910 | m_rendererNative.DrawSplitterSash(win, dc, size, position, orient, flags); | |
8b97949e VZ |
911 | } |
912 | ||
7cf3223a | 913 | #endif // wxUSE_UXTHEME |