implemented DrawComboBoxDropButton() for classic Win32
[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
37 // ----------------------------------------------------------------------------
38 // wxRendererMSW: wxRendererNative implementation for "old" Win32 systems
39 // ----------------------------------------------------------------------------
40
41 class WXDLLEXPORT wxRendererMSW : public wxDelegateRendererNative
42 {
43 public:
44 wxRendererMSW() { }
45
46 static wxRendererNative& Get();
47
48 virtual void DrawComboBoxDropButton(wxWindow *win,
49 wxDC& dc,
50 const wxRect& rect,
51 int flags = 0);
52
53 private:
54 DECLARE_NO_COPY_CLASS(wxRendererMSW)
55 };
56
57 // ----------------------------------------------------------------------------
58 // wxRendererXP: wxRendererNative implementation for Windows XP and later
59 // ----------------------------------------------------------------------------
60
61 class WXDLLEXPORT wxRendererXP : public wxDelegateRendererNative
62 {
63 public:
64 wxRendererXP() : wxDelegateRendererNative(wxRendererMSW::Get()) { }
65
66 static wxRendererNative& Get();
67
68 virtual void DrawSplitterBorder(wxWindow *win,
69 wxDC& dc,
70 const wxRect& rect,
71 int flags = 0);
72 virtual void DrawSplitterSash(wxWindow *win,
73 wxDC& dc,
74 const wxSize& size,
75 wxCoord position,
76 wxOrientation orient,
77 int flags = 0);
78
79 virtual wxSplitterRenderParams GetSplitterParams(const wxWindow *win);
80
81 private:
82 DECLARE_NO_COPY_CLASS(wxRendererXP)
83 };
84
85 // ============================================================================
86 // wxRendererNative and wxRendererMSW implementation
87 // ============================================================================
88
89 /* static */
90 wxRendererNative& wxRendererNative::GetDefault()
91 {
92 wxUxThemeEngine *themeEngine = wxUxThemeEngine::Get();
93 return themeEngine && themeEngine->IsAppThemed() ? wxRendererXP::Get()
94 : wxRendererMSW::Get();
95 }
96
97 /* static */
98 wxRendererNative& wxRendererMSW::Get()
99 {
100 static wxRendererMSW s_rendererMSW;
101
102 return s_rendererMSW;
103 }
104
105 void
106 wxRendererMSW::DrawComboBoxDropButton(wxWindow * WXUNUSED(win),
107 wxDC& dc,
108 const wxRect& rect,
109 int flags)
110 {
111 RECT r;
112 r.left = rect.GetLeft();
113 r.top = rect.GetTop();
114 r.bottom = rect.GetBottom();
115 r.right = rect.GetRight();
116
117 int style = DFCS_SCROLLCOMBOBOX;
118 if ( flags & wxCONTROL_DISABLED )
119 style |= DFCS_INACTIVE;
120 if ( flags & wxCONTROL_PRESSED )
121 style |= DFCS_PUSHED;
122
123 ::DrawFrameControl(GetHdcOf(dc), &r, DFC_SCROLL, style);
124 }
125
126 // ============================================================================
127 // wxRendererXP implementation
128 // ============================================================================
129
130 /* static */
131 wxRendererNative& wxRendererXP::Get()
132 {
133 static wxRendererXP s_rendererXP;
134
135 return s_rendererXP;
136 }
137
138 // ----------------------------------------------------------------------------
139 // splitter drawing
140 // ----------------------------------------------------------------------------
141
142 // the width of the sash: this is the same as used by Explorer...
143 static const wxCoord SASH_WIDTH = 4;
144
145 wxSplitterRenderParams
146 wxRendererXP::GetSplitterParams(const wxWindow * win)
147 {
148 if (win->GetWindowStyle() & wxSP_NO_XP_THEME)
149 return m_rendererNative.GetSplitterParams(win);
150 else
151 return wxSplitterRenderParams(SASH_WIDTH, 0, false);
152 }
153
154 void
155 wxRendererXP::DrawSplitterBorder(wxWindow * win,
156 wxDC& dc,
157 const wxRect& rect,
158 int flags)
159 {
160 if (win->GetWindowStyle() & wxSP_NO_XP_THEME)
161 {
162 m_rendererNative.DrawSplitterBorder(win, dc, rect, flags);
163 }
164 }
165
166 void
167 wxRendererXP::DrawSplitterSash(wxWindow *win,
168 wxDC& dc,
169 const wxSize& size,
170 wxCoord position,
171 wxOrientation orient,
172 int flags)
173 {
174 if ( !win->HasFlag(wxSP_NO_XP_THEME) )
175 {
176 wxUxThemeHandle hTheme(win, L"WINDOW");
177 if ( hTheme )
178 {
179 RECT rect;
180 if ( orient == wxVERTICAL )
181 {
182 rect.left = position;
183 rect.right = position + SASH_WIDTH;
184 rect.top = 0;
185 rect.bottom = size.y;
186 }
187 else // wxHORIZONTAL
188 {
189 rect.left = 0;
190 rect.right = size.x;
191 rect.top = position;
192 rect.bottom = position + SASH_WIDTH;
193 }
194
195 wxUxThemeEngine::Get()->DrawThemeBackground
196 (
197 (WXHTHEME)hTheme,
198 dc.GetHDC(),
199 29, // WP_DIALOG: dlg background
200 0, // no particular state
201 &rect,
202 NULL
203 );
204 return;
205 }
206 }
207
208 m_rendererNative.DrawSplitterSash(win, dc, size, position, orient, flags);
209 }
210