]>
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> | |
0a53b9b8 | 9 | // License: wxWindows license |
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" | |
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 | 70 | |
f33cef9f VZ |
71 | virtual void DrawComboBoxDropButton(wxWindow *win, |
72 | wxDC& dc, | |
73 | const wxRect& rect, | |
74 | int flags = 0); | |
75 | ||
4c85ab75 VZ |
76 | virtual void DrawDropArrow(wxWindow *win, |
77 | wxDC& dc, | |
78 | const wxRect& rect, | |
79 | int flags = 0); | |
b3208e11 | 80 | |
af99040c | 81 | virtual wxSplitterRenderParams GetSplitterParams(const wxWindow *win); |
b3208e11 | 82 | |
04857cb7 VZ |
83 | virtual wxRendererVersion GetVersion() const |
84 | { | |
85 | return wxRendererVersion(wxRendererVersion::Current_Version, | |
86 | wxRendererVersion::Current_Age); | |
87 | } | |
88 | ||
89 | ||
0872a451 JS |
90 | // Cleanup by deleting standard renderer |
91 | static void Cleanup(); | |
92 | ||
93 | // Get the generic object | |
94 | static wxRendererGeneric* DoGetGeneric(); | |
b3208e11 VZ |
95 | |
96 | protected: | |
97 | // draw the rectange using the first pen for the left and top sides and | |
98 | // the second one for the bottom and right ones | |
99 | void DrawShadedRect(wxDC& dc, wxRect *rect, | |
100 | const wxPen& pen1, const wxPen& pen2); | |
101 | ||
102 | // the standard pens | |
103 | wxPen m_penBlack, | |
104 | m_penDarkGrey, | |
105 | m_penLightGrey, | |
106 | m_penHighlight; | |
0872a451 JS |
107 | |
108 | static wxRendererGeneric* sm_rendererGeneric; | |
9c7f49f5 VZ |
109 | }; |
110 | ||
111 | // ============================================================================ | |
b3208e11 | 112 | // wxRendererGeneric implementation |
9c7f49f5 VZ |
113 | // ============================================================================ |
114 | ||
0872a451 JS |
115 | // Get the generic object |
116 | wxRendererGeneric* wxRendererGeneric::DoGetGeneric() | |
117 | { | |
118 | if (!sm_rendererGeneric) | |
119 | sm_rendererGeneric = new wxRendererGeneric; | |
120 | return sm_rendererGeneric; | |
121 | } | |
122 | ||
9c7f49f5 VZ |
123 | // ---------------------------------------------------------------------------- |
124 | // wxRendererGeneric creation | |
125 | // ---------------------------------------------------------------------------- | |
126 | ||
127 | /* static */ | |
38c4cb6a | 128 | wxRendererNative& wxRendererNative::GetGeneric() |
9c7f49f5 | 129 | { |
0872a451 JS |
130 | return * wxRendererGeneric::DoGetGeneric(); |
131 | } | |
9c7f49f5 | 132 | |
0872a451 JS |
133 | void wxRendererGeneric::Cleanup() |
134 | { | |
135 | if (sm_rendererGeneric) | |
136 | delete sm_rendererGeneric; | |
ca65c044 | 137 | |
0872a451 | 138 | sm_rendererGeneric = NULL; |
9c7f49f5 VZ |
139 | } |
140 | ||
0872a451 JS |
141 | wxRendererGeneric* wxRendererGeneric::sm_rendererGeneric = NULL; |
142 | ||
b3208e11 VZ |
143 | wxRendererGeneric::wxRendererGeneric() |
144 | : m_penBlack(wxSystemSettings::GetColour(wxSYS_COLOUR_3DDKSHADOW)), | |
145 | m_penDarkGrey(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW)), | |
146 | m_penLightGrey(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE)), | |
147 | m_penHighlight(wxSystemSettings::GetColour(wxSYS_COLOUR_3DHIGHLIGHT)) | |
148 | { | |
149 | } | |
150 | ||
9c7f49f5 | 151 | // ---------------------------------------------------------------------------- |
b3208e11 VZ |
152 | // wxRendererGeneric helpers |
153 | // ---------------------------------------------------------------------------- | |
154 | ||
155 | void | |
156 | wxRendererGeneric::DrawShadedRect(wxDC& dc, | |
157 | wxRect *rect, | |
158 | const wxPen& pen1, | |
159 | const wxPen& pen2) | |
160 | { | |
161 | // draw the rectangle | |
162 | dc.SetPen(pen1); | |
163 | dc.DrawLine(rect->GetLeft(), rect->GetTop(), | |
164 | rect->GetLeft(), rect->GetBottom()); | |
165 | dc.DrawLine(rect->GetLeft() + 1, rect->GetTop(), | |
166 | rect->GetRight(), rect->GetTop()); | |
167 | dc.SetPen(pen2); | |
168 | dc.DrawLine(rect->GetRight(), rect->GetTop(), | |
169 | rect->GetRight(), rect->GetBottom()); | |
170 | dc.DrawLine(rect->GetLeft(), rect->GetBottom(), | |
171 | rect->GetRight() + 1, rect->GetBottom()); | |
172 | ||
173 | // adjust the rect | |
174 | rect->Inflate(-1); | |
175 | } | |
176 | ||
177 | // ---------------------------------------------------------------------------- | |
178 | // tree/list ctrl drawing | |
9c7f49f5 VZ |
179 | // ---------------------------------------------------------------------------- |
180 | ||
181 | void | |
2eb10e2a | 182 | wxRendererGeneric::DrawHeaderButton(wxWindow * WXUNUSED(win), |
9c7f49f5 VZ |
183 | wxDC& dc, |
184 | const wxRect& rect, | |
2eb10e2a | 185 | int WXUNUSED(flags)) |
9c7f49f5 | 186 | { |
38c4cb6a VZ |
187 | const int CORNER = 1; |
188 | ||
189 | const wxCoord x = rect.x, | |
190 | y = rect.y, | |
191 | w = rect.width, | |
192 | h = rect.height; | |
9c7f49f5 | 193 | |
b3208e11 | 194 | dc.SetBrush(*wxTRANSPARENT_BRUSH); |
9c7f49f5 | 195 | |
b3208e11 | 196 | dc.SetPen(m_penBlack); |
38c4cb6a VZ |
197 | dc.DrawLine( x+w-CORNER+1, y, x+w, y+h ); // right (outer) |
198 | dc.DrawRectangle( x, y+h, w+1, 1 ); // bottom (outer) | |
9c7f49f5 | 199 | |
b3208e11 | 200 | dc.SetPen(m_penDarkGrey); |
38c4cb6a VZ |
201 | dc.DrawLine( x+w-CORNER, y, x+w-1, y+h ); // right (inner) |
202 | dc.DrawRectangle( x+1, y+h-1, w-2, 1 ); // bottom (inner) | |
9c7f49f5 | 203 | |
b3208e11 | 204 | dc.SetPen(m_penHighlight); |
38c4cb6a VZ |
205 | dc.DrawRectangle( x, y, w-CORNER+1, 1 ); // top (outer) |
206 | dc.DrawRectangle( x, y, 1, h ); // left (outer) | |
207 | dc.DrawLine( x, y+h-1, x+1, y+h-1 ); | |
208 | dc.DrawLine( x+w-1, y, x+w-1, y+1 ); | |
9c7f49f5 VZ |
209 | } |
210 | ||
211 | // draw the plus or minus sign | |
212 | void | |
2eb10e2a | 213 | wxRendererGeneric::DrawTreeItemButton(wxWindow * WXUNUSED(win), |
9c7f49f5 VZ |
214 | wxDC& dc, |
215 | const wxRect& rect, | |
216 | int flags) | |
217 | { | |
218 | // white background | |
219 | dc.SetPen(*wxGREY_PEN); | |
220 | dc.SetBrush(*wxWHITE_BRUSH); | |
0e7761fa | 221 | dc.DrawRectangle(rect); |
9c7f49f5 VZ |
222 | |
223 | // black lines | |
224 | const wxCoord xMiddle = rect.x + rect.width/2; | |
225 | const wxCoord yMiddle = rect.y + rect.height/2; | |
226 | ||
0e7761fa VZ |
227 | // half of the length of the horz lines in "-" and "+" |
228 | const wxCoord halfWidth = rect.width/2 - 2; | |
9c7f49f5 | 229 | dc.SetPen(*wxBLACK_PEN); |
429ef4bc VZ |
230 | dc.DrawLine(xMiddle - halfWidth, yMiddle, |
231 | xMiddle + halfWidth + 1, yMiddle); | |
232 | ||
e8448b79 | 233 | if ( !(flags & wxCONTROL_EXPANDED) ) |
9c7f49f5 VZ |
234 | { |
235 | // turn "-" into "+" | |
0e7761fa VZ |
236 | const wxCoord halfHeight = rect.height/2 - 2; |
237 | dc.DrawLine(xMiddle, yMiddle - halfHeight, | |
429ef4bc | 238 | xMiddle, yMiddle + halfHeight + 1); |
9c7f49f5 VZ |
239 | } |
240 | } | |
241 | ||
b3208e11 VZ |
242 | // ---------------------------------------------------------------------------- |
243 | // sash drawing | |
244 | // ---------------------------------------------------------------------------- | |
245 | ||
af99040c VZ |
246 | wxSplitterRenderParams |
247 | wxRendererGeneric::GetSplitterParams(const wxWindow *win) | |
b3208e11 VZ |
248 | { |
249 | // see below | |
af99040c VZ |
250 | wxCoord sashWidth, |
251 | border; | |
252 | ||
4666bb5f | 253 | if ( win->HasFlag(wxSP_3DSASH) ) |
af99040c | 254 | sashWidth = 7; |
4666bb5f JS |
255 | else if ( win->HasFlag(wxSP_NOSASH) ) |
256 | sashWidth = 0; | |
af99040c | 257 | else // no 3D effect |
28f9eac4 | 258 | sashWidth = 3; |
4666bb5f JS |
259 | |
260 | if ( win->HasFlag(wxSP_3DBORDER) ) | |
261 | border = 2; | |
262 | else // no 3D effect | |
af99040c | 263 | border = 0; |
af99040c VZ |
264 | |
265 | return wxSplitterRenderParams(sashWidth, border, false); | |
b3208e11 VZ |
266 | } |
267 | ||
268 | void | |
52c14774 | 269 | wxRendererGeneric::DrawSplitterBorder(wxWindow *win, |
b3208e11 | 270 | wxDC& dc, |
af99040c VZ |
271 | const wxRect& rectOrig, |
272 | int WXUNUSED(falgs)) | |
b3208e11 | 273 | { |
4666bb5f | 274 | if ( win->HasFlag(wxSP_3DBORDER) ) |
52c14774 VZ |
275 | { |
276 | wxRect rect = rectOrig; | |
277 | DrawShadedRect(dc, &rect, m_penDarkGrey, m_penHighlight); | |
278 | DrawShadedRect(dc, &rect, m_penBlack, m_penLightGrey); | |
279 | } | |
b3208e11 VZ |
280 | } |
281 | ||
282 | void | |
52c14774 | 283 | wxRendererGeneric::DrawSplitterSash(wxWindow *win, |
62dc9cb4 VZ |
284 | wxDC& dcReal, |
285 | const wxSize& sizeReal, | |
286 | wxCoord position, | |
af99040c VZ |
287 | wxOrientation orient, |
288 | int WXUNUSED(flags)) | |
b3208e11 | 289 | { |
62dc9cb4 VZ |
290 | // to avoid duplicating the same code for horizontal and vertical sashes, |
291 | // simply mirror the DC instead if needed (i.e. if horz splitter) | |
292 | wxMirrorDC dc(dcReal, orient != wxVERTICAL); | |
293 | wxSize size = dc.Reflect(sizeReal); | |
294 | ||
295 | ||
52c14774 | 296 | // we draw a Win32-like grey sash with possible 3D border here: |
b3208e11 VZ |
297 | // |
298 | // ---- this is position | |
299 | // / | |
300 | // v | |
301 | // dWGGGDd | |
302 | // GWGGGDB | |
303 | // GWGGGDB where G is light grey (face) | |
304 | // GWGGGDB W white (light) | |
305 | // GWGGGDB D dark grey (shadow) | |
306 | // GWGGGDB B black (dark shadow) | |
307 | // GWGGGDB | |
308 | // GWGGGDB and lower letters are our border (already drawn) | |
309 | // GWGGGDB | |
310 | // wWGGGDd | |
52c14774 VZ |
311 | // |
312 | // only the middle 3 columns are drawn unless wxSP_3D is specified | |
b3208e11 VZ |
313 | |
314 | const wxCoord h = size.y; | |
8aa528db | 315 | wxCoord offset = 0; |
ca65c044 | 316 | |
4666bb5f JS |
317 | // If we're drawing the border, draw the sash 3d lines shorter |
318 | if ( win->HasFlag(wxSP_3DBORDER) ) | |
8aa528db | 319 | { |
4666bb5f | 320 | offset = 1; |
8aa528db | 321 | } |
b3208e11 | 322 | |
4666bb5f | 323 | dc.SetPen(*wxTRANSPARENT_PEN); |
ca65c044 WS |
324 | dc.SetBrush(wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE))); |
325 | ||
4666bb5f | 326 | if ( win->HasFlag(wxSP_3DSASH) ) |
52c14774 | 327 | { |
4666bb5f JS |
328 | // Draw the 3D sash |
329 | dc.DrawRectangle(position + 2, 0, 3, h); | |
330 | ||
52c14774 | 331 | dc.SetPen(m_penLightGrey); |
4666bb5f | 332 | dc.DrawLine(position, offset, position, h - offset); |
b3208e11 | 333 | |
52c14774 | 334 | dc.SetPen(m_penHighlight); |
4666bb5f | 335 | dc.DrawLine(position + 1, 0, position + 1, h); |
b3208e11 | 336 | |
52c14774 | 337 | dc.SetPen(m_penDarkGrey); |
4666bb5f | 338 | dc.DrawLine(position + 5, 0, position + 5, h); |
b3208e11 | 339 | |
52c14774 | 340 | dc.SetPen(m_penBlack); |
4666bb5f JS |
341 | dc.DrawLine(position + 6, offset, position + 6, h - offset); |
342 | } | |
343 | else | |
344 | { | |
345 | // Draw a flat sash | |
346 | dc.DrawRectangle(position, 0, 3, h); | |
52c14774 | 347 | } |
b3208e11 | 348 | } |
9c7f49f5 | 349 | |
4c85ab75 VZ |
350 | // ---------------------------------------------------------------------------- |
351 | // button drawing | |
352 | // ---------------------------------------------------------------------------- | |
353 | ||
f33cef9f VZ |
354 | void |
355 | wxRendererGeneric::DrawComboBoxDropButton(wxWindow *win, | |
356 | wxDC& dc, | |
357 | const wxRect& rect, | |
358 | int WXUNUSED(flags)) | |
359 | { | |
caad7637 JS |
360 | // Creating a generic button background that would actually be |
361 | // useful is rather difficult to accomplish. Best compromise | |
362 | // is to use window's background colour to achieve transparent' | |
363 | // ish appearance that should look decent in combo box style | |
364 | // controls. | |
365 | wxColour col = win->GetBackgroundColour(); | |
366 | dc.SetBrush(wxBrush(col)); | |
367 | dc.SetPen(wxPen(col)); | |
368 | dc.DrawRectangle(rect); | |
4c85ab75 VZ |
369 | DrawDropArrow(win,dc,rect); |
370 | } | |
371 | ||
f33cef9f | 372 | |
4c85ab75 VZ |
373 | void |
374 | wxRendererGeneric::DrawDropArrow(wxWindow *win, | |
375 | wxDC& dc, | |
376 | const wxRect& rect, | |
377 | int WXUNUSED(flags)) | |
378 | { | |
379 | // This generic implementation should be good | |
380 | // enough for Windows platforms (including XP). | |
381 | ||
382 | int arrowHalf = rect.width/5; | |
383 | int rectMid = rect.width / 2; | |
384 | int arrowTopY = (rect.height/2) - (arrowHalf/2); | |
385 | ||
386 | // This should always result in arrow with odd width. | |
106a7999 | 387 | wxPoint pt[] = |
f33cef9f | 388 | { |
4c85ab75 VZ |
389 | wxPoint(rectMid - arrowHalf, arrowTopY), |
390 | wxPoint(rectMid + arrowHalf, arrowTopY), | |
391 | wxPoint(rectMid, arrowTopY + arrowHalf) | |
f33cef9f VZ |
392 | }; |
393 | dc.SetBrush(wxBrush(win->GetForegroundColour())); | |
394 | dc.SetPen(wxPen(win->GetForegroundColour())); | |
106a7999 | 395 | dc.DrawPolygon(WXSIZEOF(pt), pt, rect.x, rect.y); |
f33cef9f VZ |
396 | } |
397 | ||
f33cef9f | 398 | // ---------------------------------------------------------------------------- |
0872a451 | 399 | // A module to allow cleanup of generic renderer. |
f33cef9f VZ |
400 | // ---------------------------------------------------------------------------- |
401 | ||
0872a451 JS |
402 | class wxGenericRendererModule: public wxModule |
403 | { | |
404 | DECLARE_DYNAMIC_CLASS(wxGenericRendererModule) | |
405 | public: | |
406 | wxGenericRendererModule() {} | |
407 | bool OnInit() { return true; }; | |
408 | void OnExit() { wxRendererGeneric::Cleanup(); }; | |
409 | }; | |
410 | ||
411 | IMPLEMENT_DYNAMIC_CLASS(wxGenericRendererModule, wxModule) | |
412 |