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