]> git.saurik.com Git - wxWidgets.git/blame - src/msw/renderer.cpp
always set flat toolbar style, even under XP with themes: this is necessary or separa...
[wxWidgets.git] / src / msw / renderer.cpp
CommitLineData
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 53class WXDLLEXPORT wxRendererMSW : public wxDelegateRendererNative
9c7f49f5 54{
2eb10e2a
VZ
55public:
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
65private:
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
75class WXDLLEXPORT wxRendererXP : public wxDelegateRendererNative
76{
77public:
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
99private:
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 110wxRendererNative& 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 */
122wxRendererNative& 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
133void
134wxRendererMSW::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 */
161wxRendererNative& 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.
171void
172wxRendererXP::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...
214static const wxCoord SASH_WIDTH = 4;
215
c4e6c15e 216wxSplitterRenderParams
3c2544bb 217wxRendererXP::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
225void
3c2544bb
JS
226wxRendererXP::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
237void
238wxRendererXP::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 {
84c62b4f 247 wxUxThemeHandle hTheme(win, L"REBAR");
6421119d 248 if ( hTheme )
8b97949e 249 {
6421119d
VZ
250 RECT rect;
251 if ( orient == wxVERTICAL )
252 {
253 rect.left = position;
254 rect.right = position + SASH_WIDTH;
255 rect.top = 0;
256 rect.bottom = size.y;
257 }
258 else // wxHORIZONTAL
259 {
260 rect.left = 0;
261 rect.right = size.x;
262 rect.top = position;
263 rect.bottom = position + SASH_WIDTH;
264 }
265
266 wxUxThemeEngine::Get()->DrawThemeBackground
267 (
92199f4c
JS
268 hTheme,
269 (HDC) dc.GetHDC(),
6421119d
VZ
270 29, // WP_DIALOG: dlg background
271 0, // no particular state
272 &rect,
273 NULL
274 );
275 return;
8b97949e 276 }
8b97949e 277 }
6421119d
VZ
278
279 m_rendererNative.DrawSplitterSash(win, dc, size, position, orient, flags);
8b97949e
VZ
280}
281
7cf3223a
VZ
282#endif // wxUSE_UXTHEME
283