]>
Commit | Line | Data |
---|---|---|
9c7f49f5 VZ |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Name: generic/renderg.cpp | |
38c4cb6a | 3 | // Purpose: generic implementation of wxRendererNative (for any platform) |
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> | |
9 | // License: wxWindows license | |
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 | #endif //WX_PRECOMP | |
30 | ||
38c4cb6a VZ |
31 | #include "wx/gdicmn.h" |
32 | #include "wx/dc.h" | |
33 | ||
34 | #include "wx/settings.h" | |
52c14774 | 35 | #include "wx/splitter.h" |
62dc9cb4 | 36 | #include "wx/dcmirror.h" |
0872a451 | 37 | #include "wx/module.h" |
9c7f49f5 VZ |
38 | #include "wx/renderer.h" |
39 | ||
40 | // ---------------------------------------------------------------------------- | |
38c4cb6a | 41 | // wxRendererGeneric: our wxRendererNative implementation |
9c7f49f5 VZ |
42 | // ---------------------------------------------------------------------------- |
43 | ||
38c4cb6a | 44 | class WXDLLEXPORT wxRendererGeneric : public wxRendererNative |
9c7f49f5 VZ |
45 | { |
46 | public: | |
b3208e11 VZ |
47 | wxRendererGeneric(); |
48 | ||
9c7f49f5 VZ |
49 | virtual void DrawHeaderButton(wxWindow *win, |
50 | wxDC& dc, | |
51 | const wxRect& rect, | |
52 | int flags = 0); | |
53 | ||
9c7f49f5 VZ |
54 | virtual void DrawTreeItemButton(wxWindow *win, |
55 | wxDC& dc, | |
56 | const wxRect& rect, | |
57 | int flags = 0); | |
b3208e11 VZ |
58 | |
59 | virtual void DrawSplitterBorder(wxWindow *win, | |
60 | wxDC& dc, | |
af99040c VZ |
61 | const wxRect& rect, |
62 | int flags = 0); | |
b3208e11 VZ |
63 | |
64 | virtual void DrawSplitterSash(wxWindow *win, | |
65 | wxDC& dc, | |
66 | const wxSize& size, | |
62dc9cb4 | 67 | wxCoord position, |
af99040c VZ |
68 | wxOrientation orient, |
69 | int flags = 0); | |
b3208e11 VZ |
70 | |
71 | ||
af99040c | 72 | virtual wxSplitterRenderParams GetSplitterParams(const wxWindow *win); |
b3208e11 | 73 | |
04857cb7 VZ |
74 | virtual wxRendererVersion GetVersion() const |
75 | { | |
76 | return wxRendererVersion(wxRendererVersion::Current_Version, | |
77 | wxRendererVersion::Current_Age); | |
78 | } | |
79 | ||
80 | ||
0872a451 JS |
81 | // Cleanup by deleting standard renderer |
82 | static void Cleanup(); | |
83 | ||
84 | // Get the generic object | |
85 | static wxRendererGeneric* DoGetGeneric(); | |
b3208e11 VZ |
86 | |
87 | protected: | |
88 | // draw the rectange using the first pen for the left and top sides and | |
89 | // the second one for the bottom and right ones | |
90 | void DrawShadedRect(wxDC& dc, wxRect *rect, | |
91 | const wxPen& pen1, const wxPen& pen2); | |
92 | ||
93 | // the standard pens | |
94 | wxPen m_penBlack, | |
95 | m_penDarkGrey, | |
96 | m_penLightGrey, | |
97 | m_penHighlight; | |
0872a451 JS |
98 | |
99 | static wxRendererGeneric* sm_rendererGeneric; | |
9c7f49f5 VZ |
100 | }; |
101 | ||
102 | // ============================================================================ | |
b3208e11 | 103 | // wxRendererGeneric implementation |
9c7f49f5 VZ |
104 | // ============================================================================ |
105 | ||
0872a451 JS |
106 | // Get the generic object |
107 | wxRendererGeneric* wxRendererGeneric::DoGetGeneric() | |
108 | { | |
109 | if (!sm_rendererGeneric) | |
110 | sm_rendererGeneric = new wxRendererGeneric; | |
111 | return sm_rendererGeneric; | |
112 | } | |
113 | ||
9c7f49f5 VZ |
114 | // ---------------------------------------------------------------------------- |
115 | // wxRendererGeneric creation | |
116 | // ---------------------------------------------------------------------------- | |
117 | ||
118 | /* static */ | |
38c4cb6a | 119 | wxRendererNative& wxRendererNative::GetGeneric() |
9c7f49f5 | 120 | { |
0872a451 JS |
121 | return * wxRendererGeneric::DoGetGeneric(); |
122 | } | |
9c7f49f5 | 123 | |
0872a451 JS |
124 | void wxRendererGeneric::Cleanup() |
125 | { | |
126 | if (sm_rendererGeneric) | |
127 | delete sm_rendererGeneric; | |
128 | ||
129 | sm_rendererGeneric = NULL; | |
9c7f49f5 VZ |
130 | } |
131 | ||
0872a451 JS |
132 | wxRendererGeneric* wxRendererGeneric::sm_rendererGeneric = NULL; |
133 | ||
b3208e11 VZ |
134 | wxRendererGeneric::wxRendererGeneric() |
135 | : m_penBlack(wxSystemSettings::GetColour(wxSYS_COLOUR_3DDKSHADOW)), | |
136 | m_penDarkGrey(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW)), | |
137 | m_penLightGrey(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE)), | |
138 | m_penHighlight(wxSystemSettings::GetColour(wxSYS_COLOUR_3DHIGHLIGHT)) | |
139 | { | |
140 | } | |
141 | ||
9c7f49f5 | 142 | // ---------------------------------------------------------------------------- |
b3208e11 VZ |
143 | // wxRendererGeneric helpers |
144 | // ---------------------------------------------------------------------------- | |
145 | ||
146 | void | |
147 | wxRendererGeneric::DrawShadedRect(wxDC& dc, | |
148 | wxRect *rect, | |
149 | const wxPen& pen1, | |
150 | const wxPen& pen2) | |
151 | { | |
152 | // draw the rectangle | |
153 | dc.SetPen(pen1); | |
154 | dc.DrawLine(rect->GetLeft(), rect->GetTop(), | |
155 | rect->GetLeft(), rect->GetBottom()); | |
156 | dc.DrawLine(rect->GetLeft() + 1, rect->GetTop(), | |
157 | rect->GetRight(), rect->GetTop()); | |
158 | dc.SetPen(pen2); | |
159 | dc.DrawLine(rect->GetRight(), rect->GetTop(), | |
160 | rect->GetRight(), rect->GetBottom()); | |
161 | dc.DrawLine(rect->GetLeft(), rect->GetBottom(), | |
162 | rect->GetRight() + 1, rect->GetBottom()); | |
163 | ||
164 | // adjust the rect | |
165 | rect->Inflate(-1); | |
166 | } | |
167 | ||
168 | // ---------------------------------------------------------------------------- | |
169 | // tree/list ctrl drawing | |
9c7f49f5 VZ |
170 | // ---------------------------------------------------------------------------- |
171 | ||
172 | void | |
2eb10e2a | 173 | wxRendererGeneric::DrawHeaderButton(wxWindow * WXUNUSED(win), |
9c7f49f5 VZ |
174 | wxDC& dc, |
175 | const wxRect& rect, | |
2eb10e2a | 176 | int WXUNUSED(flags)) |
9c7f49f5 | 177 | { |
38c4cb6a VZ |
178 | const int CORNER = 1; |
179 | ||
180 | const wxCoord x = rect.x, | |
181 | y = rect.y, | |
182 | w = rect.width, | |
183 | h = rect.height; | |
9c7f49f5 | 184 | |
b3208e11 | 185 | dc.SetBrush(*wxTRANSPARENT_BRUSH); |
9c7f49f5 | 186 | |
b3208e11 | 187 | dc.SetPen(m_penBlack); |
38c4cb6a VZ |
188 | dc.DrawLine( x+w-CORNER+1, y, x+w, y+h ); // right (outer) |
189 | dc.DrawRectangle( x, y+h, w+1, 1 ); // bottom (outer) | |
9c7f49f5 | 190 | |
b3208e11 | 191 | dc.SetPen(m_penDarkGrey); |
38c4cb6a VZ |
192 | dc.DrawLine( x+w-CORNER, y, x+w-1, y+h ); // right (inner) |
193 | dc.DrawRectangle( x+1, y+h-1, w-2, 1 ); // bottom (inner) | |
9c7f49f5 | 194 | |
b3208e11 | 195 | dc.SetPen(m_penHighlight); |
38c4cb6a VZ |
196 | dc.DrawRectangle( x, y, w-CORNER+1, 1 ); // top (outer) |
197 | dc.DrawRectangle( x, y, 1, h ); // left (outer) | |
198 | dc.DrawLine( x, y+h-1, x+1, y+h-1 ); | |
199 | dc.DrawLine( x+w-1, y, x+w-1, y+1 ); | |
9c7f49f5 VZ |
200 | } |
201 | ||
202 | // draw the plus or minus sign | |
203 | void | |
2eb10e2a | 204 | wxRendererGeneric::DrawTreeItemButton(wxWindow * WXUNUSED(win), |
9c7f49f5 VZ |
205 | wxDC& dc, |
206 | const wxRect& rect, | |
207 | int flags) | |
208 | { | |
209 | // white background | |
210 | dc.SetPen(*wxGREY_PEN); | |
211 | dc.SetBrush(*wxWHITE_BRUSH); | |
212 | dc.DrawRectangle(rect.Deflate(1, 2)); | |
213 | ||
214 | // black lines | |
215 | const wxCoord xMiddle = rect.x + rect.width/2; | |
216 | const wxCoord yMiddle = rect.y + rect.height/2; | |
217 | ||
218 | dc.SetPen(*wxBLACK_PEN); | |
219 | dc.DrawLine(xMiddle - 2, yMiddle, xMiddle + 3, yMiddle); | |
e8448b79 | 220 | if ( !(flags & wxCONTROL_EXPANDED) ) |
9c7f49f5 VZ |
221 | { |
222 | // turn "-" into "+" | |
223 | dc.DrawLine(xMiddle, yMiddle - 2, xMiddle, yMiddle + 3); | |
224 | } | |
225 | } | |
226 | ||
b3208e11 VZ |
227 | // ---------------------------------------------------------------------------- |
228 | // sash drawing | |
229 | // ---------------------------------------------------------------------------- | |
230 | ||
af99040c VZ |
231 | wxSplitterRenderParams |
232 | wxRendererGeneric::GetSplitterParams(const wxWindow *win) | |
b3208e11 VZ |
233 | { |
234 | // see below | |
af99040c VZ |
235 | wxCoord sashWidth, |
236 | border; | |
237 | ||
238 | if ( win->HasFlag(wxSP_3D) ) | |
239 | { | |
240 | sashWidth = 7; | |
28f9eac4 | 241 | border = 2; |
af99040c VZ |
242 | } |
243 | else // no 3D effect | |
244 | { | |
28f9eac4 | 245 | sashWidth = 3; |
af99040c VZ |
246 | border = 0; |
247 | } | |
248 | ||
249 | return wxSplitterRenderParams(sashWidth, border, false); | |
b3208e11 VZ |
250 | } |
251 | ||
252 | void | |
52c14774 | 253 | wxRendererGeneric::DrawSplitterBorder(wxWindow *win, |
b3208e11 | 254 | wxDC& dc, |
af99040c VZ |
255 | const wxRect& rectOrig, |
256 | int WXUNUSED(falgs)) | |
b3208e11 | 257 | { |
52c14774 VZ |
258 | if ( win->HasFlag(wxSP_3D) ) |
259 | { | |
260 | wxRect rect = rectOrig; | |
261 | DrawShadedRect(dc, &rect, m_penDarkGrey, m_penHighlight); | |
262 | DrawShadedRect(dc, &rect, m_penBlack, m_penLightGrey); | |
263 | } | |
b3208e11 VZ |
264 | } |
265 | ||
266 | void | |
52c14774 | 267 | wxRendererGeneric::DrawSplitterSash(wxWindow *win, |
62dc9cb4 VZ |
268 | wxDC& dcReal, |
269 | const wxSize& sizeReal, | |
270 | wxCoord position, | |
af99040c VZ |
271 | wxOrientation orient, |
272 | int WXUNUSED(flags)) | |
b3208e11 | 273 | { |
62dc9cb4 VZ |
274 | // to avoid duplicating the same code for horizontal and vertical sashes, |
275 | // simply mirror the DC instead if needed (i.e. if horz splitter) | |
276 | wxMirrorDC dc(dcReal, orient != wxVERTICAL); | |
277 | wxSize size = dc.Reflect(sizeReal); | |
278 | ||
279 | ||
52c14774 | 280 | // we draw a Win32-like grey sash with possible 3D border here: |
b3208e11 VZ |
281 | // |
282 | // ---- this is position | |
283 | // / | |
284 | // v | |
285 | // dWGGGDd | |
286 | // GWGGGDB | |
287 | // GWGGGDB where G is light grey (face) | |
288 | // GWGGGDB W white (light) | |
289 | // GWGGGDB D dark grey (shadow) | |
290 | // GWGGGDB B black (dark shadow) | |
291 | // GWGGGDB | |
292 | // GWGGGDB and lower letters are our border (already drawn) | |
293 | // GWGGGDB | |
294 | // wWGGGDd | |
52c14774 VZ |
295 | // |
296 | // only the middle 3 columns are drawn unless wxSP_3D is specified | |
b3208e11 VZ |
297 | |
298 | const wxCoord h = size.y; | |
8aa528db JS |
299 | wxCoord offset = 0; |
300 | ||
301 | // If we're not drawing the border, droppings will | |
302 | // be left unless we make the sash shorter | |
303 | if ( !win->HasFlag(wxSP_3DBORDER) ) | |
304 | { | |
305 | offset = 3; | |
306 | } | |
b3208e11 VZ |
307 | |
308 | // from left to right | |
52c14774 VZ |
309 | if ( win->HasFlag(wxSP_3D) ) |
310 | { | |
311 | dc.SetPen(m_penLightGrey); | |
8aa528db | 312 | dc.DrawLine(position, 1 + offset, position, h - 1 - offset); |
b3208e11 | 313 | |
52c14774 | 314 | dc.SetPen(m_penHighlight); |
8aa528db | 315 | dc.DrawLine(position + 1, offset, position + 1, h - offset); |
52c14774 | 316 | } |
b3208e11 VZ |
317 | |
318 | dc.SetPen(*wxTRANSPARENT_PEN); | |
319 | dc.SetBrush(wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE))); | |
8aa528db | 320 | dc.DrawRectangle(position + 2, offset, 3, h - 2*offset); |
b3208e11 | 321 | |
52c14774 VZ |
322 | if ( win->HasFlag(wxSP_3D) ) |
323 | { | |
324 | dc.SetPen(m_penDarkGrey); | |
8aa528db | 325 | dc.DrawLine(position + 5, offset, position + 5, h - offset); |
b3208e11 | 326 | |
52c14774 | 327 | dc.SetPen(m_penBlack); |
8aa528db | 328 | dc.DrawLine(position + 6, offset, position + 6, h - 1 - offset); |
52c14774 | 329 | } |
b3208e11 | 330 | } |
9c7f49f5 | 331 | |
0872a451 JS |
332 | // A module to allow cleanup of generic renderer. |
333 | class wxGenericRendererModule: public wxModule | |
334 | { | |
335 | DECLARE_DYNAMIC_CLASS(wxGenericRendererModule) | |
336 | public: | |
337 | wxGenericRendererModule() {} | |
338 | bool OnInit() { return true; }; | |
339 | void OnExit() { wxRendererGeneric::Cleanup(); }; | |
340 | }; | |
341 | ||
342 | IMPLEMENT_DYNAMIC_CLASS(wxGenericRendererModule, wxModule) | |
343 |