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