]> git.saurik.com Git - wxWidgets.git/blob - src/msw/renderer.cpp
implementation of wxRendererXP::DrawComboBoxDropButton() (patch 1144845)
[wxWidgets.git] / src / msw / renderer.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: 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/msw/uxtheme.h"
36 #include "wx/msw/private.h"
37
38 // tmschema.h is in Win32 Platform SDK and might not be available with earlier
39 // compilers
40 #ifndef CP_DROPDOWNBUTTON
41 #define CP_DROPDOWNBUTTON 1
42
43 #define CBXS_NORMAL 1
44 #define CBXS_HOT 2
45 #define CBXS_PRESSED 3
46 #define CBXS_DISABLED 4
47 #endif
48
49 // ----------------------------------------------------------------------------
50 // wxRendererMSW: wxRendererNative implementation for "old" Win32 systems
51 // ----------------------------------------------------------------------------
52
53 class WXDLLEXPORT wxRendererMSW : public wxDelegateRendererNative
54 {
55 public:
56 wxRendererMSW() { }
57
58 static wxRendererNative& Get();
59
60 virtual void DrawComboBoxDropButton(wxWindow *win,
61 wxDC& dc,
62 const wxRect& rect,
63 int flags = 0);
64
65 private:
66 DECLARE_NO_COPY_CLASS(wxRendererMSW)
67 };
68
69 // ----------------------------------------------------------------------------
70 // wxRendererXP: wxRendererNative implementation for Windows XP and later
71 // ----------------------------------------------------------------------------
72
73 #if wxUSE_UXTHEME
74
75 class WXDLLEXPORT wxRendererXP : public wxDelegateRendererNative
76 {
77 public:
78 wxRendererXP() : wxDelegateRendererNative(wxRendererMSW::Get()) { }
79
80 static wxRendererNative& Get();
81
82 virtual void DrawSplitterBorder(wxWindow *win,
83 wxDC& dc,
84 const wxRect& rect,
85 int flags = 0);
86 virtual void DrawSplitterSash(wxWindow *win,
87 wxDC& dc,
88 const wxSize& size,
89 wxCoord position,
90 wxOrientation orient,
91 int flags = 0);
92
93 virtual wxSplitterRenderParams GetSplitterParams(const wxWindow *win);
94
95 virtual void DrawComboBoxDropButton(wxWindow *win,
96 wxDC& dc,
97 const wxRect& rect,
98 int flags = 0);
99 private:
100 DECLARE_NO_COPY_CLASS(wxRendererXP)
101 };
102
103 #endif // wxUSE_UXTHEME
104
105 // ============================================================================
106 // wxRendererNative and wxRendererMSW implementation
107 // ============================================================================
108
109 /* static */
110 wxRendererNative& wxRendererNative::GetDefault()
111 {
112 #if wxUSE_UXTHEME
113 wxUxThemeEngine *themeEngine = wxUxThemeEngine::Get();
114 if ( themeEngine && themeEngine->IsAppThemed() )
115 return wxRendererXP::Get();
116 #endif // wxUSE_UXTHEME
117
118 return wxRendererMSW::Get();
119 }
120
121 /* static */
122 wxRendererNative& wxRendererMSW::Get()
123 {
124 static wxRendererMSW s_rendererMSW;
125
126 return s_rendererMSW;
127 }
128
129 void
130 wxRendererMSW::DrawComboBoxDropButton(wxWindow * WXUNUSED(win),
131 wxDC& dc,
132 const wxRect& rect,
133 int flags)
134 {
135 RECT r;
136 r.left = rect.GetLeft();
137 r.top = rect.GetTop();
138 r.bottom = rect.y + rect.height;
139 r.right = rect.x + rect.width;
140
141 int style = DFCS_SCROLLCOMBOBOX;
142 if ( flags & wxCONTROL_DISABLED )
143 style |= DFCS_INACTIVE;
144 if ( flags & wxCONTROL_PRESSED )
145 style |= DFCS_PUSHED | DFCS_FLAT;
146
147 ::DrawFrameControl(GetHdcOf(dc), &r, DFC_SCROLL, style);
148 }
149
150 // ============================================================================
151 // wxRendererXP implementation
152 // ============================================================================
153
154 #if wxUSE_UXTHEME
155
156 /* static */
157 wxRendererNative& wxRendererXP::Get()
158 {
159 static wxRendererXP s_rendererXP;
160
161 return s_rendererXP;
162 }
163
164 // NOTE: There is no guarantee that the button drawn fills the entire rect (XP
165 // default theme, for example), so the caller should have cleared button's
166 // background before this call. This is quite likely a wxMSW-specific thing.
167 void
168 wxRendererXP::DrawComboBoxDropButton(wxWindow * win,
169 wxDC& dc,
170 const wxRect& rect,
171 int flags)
172 {
173 wxUxThemeHandle hTheme(win, L"COMBOBOX");
174 if ( hTheme )
175 {
176 RECT r;
177 r.left = rect.x;
178 r.top = rect.y;
179 r.right = rect.x + rect.width;
180 r.bottom = rect.y + rect.height;
181
182 int state;
183 if ( flags & wxCONTROL_PRESSED )
184 state = CBXS_PRESSED;
185 else if ( flags & wxCONTROL_CURRENT )
186 state = CBXS_HOT;
187 else if ( flags & wxCONTROL_DISABLED )
188 state = CBXS_DISABLED;
189 else
190 state = CBXS_NORMAL;
191
192 wxUxThemeEngine::Get()->DrawThemeBackground
193 (
194 hTheme,
195 dc.GetHDC(),
196 CP_DROPDOWNBUTTON,
197 state,
198 &r,
199 NULL
200 );
201
202 }
203 }
204
205 // ----------------------------------------------------------------------------
206 // splitter drawing
207 // ----------------------------------------------------------------------------
208
209 // the width of the sash: this is the same as used by Explorer...
210 static const wxCoord SASH_WIDTH = 4;
211
212 wxSplitterRenderParams
213 wxRendererXP::GetSplitterParams(const wxWindow * win)
214 {
215 if (win->GetWindowStyle() & wxSP_NO_XP_THEME)
216 return m_rendererNative.GetSplitterParams(win);
217 else
218 return wxSplitterRenderParams(SASH_WIDTH, 0, false);
219 }
220
221 void
222 wxRendererXP::DrawSplitterBorder(wxWindow * win,
223 wxDC& dc,
224 const wxRect& rect,
225 int flags)
226 {
227 if (win->GetWindowStyle() & wxSP_NO_XP_THEME)
228 {
229 m_rendererNative.DrawSplitterBorder(win, dc, rect, flags);
230 }
231 }
232
233 void
234 wxRendererXP::DrawSplitterSash(wxWindow *win,
235 wxDC& dc,
236 const wxSize& size,
237 wxCoord position,
238 wxOrientation orient,
239 int flags)
240 {
241 if ( !win->HasFlag(wxSP_NO_XP_THEME) )
242 {
243 wxUxThemeHandle hTheme(win, L"WINDOW");
244 if ( hTheme )
245 {
246 RECT rect;
247 if ( orient == wxVERTICAL )
248 {
249 rect.left = position;
250 rect.right = position + SASH_WIDTH;
251 rect.top = 0;
252 rect.bottom = size.y;
253 }
254 else // wxHORIZONTAL
255 {
256 rect.left = 0;
257 rect.right = size.x;
258 rect.top = position;
259 rect.bottom = position + SASH_WIDTH;
260 }
261
262 wxUxThemeEngine::Get()->DrawThemeBackground
263 (
264 (WXHTHEME)hTheme,
265 dc.GetHDC(),
266 29, // WP_DIALOG: dlg background
267 0, // no particular state
268 &rect,
269 NULL
270 );
271 return;
272 }
273 }
274
275 m_rendererNative.DrawSplitterSash(win, dc, size, position, orient, flags);
276 }
277
278 #endif // wxUSE_UXTHEME
279