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