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