]>
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" |
9eddec69 | 32 | #include "wx/settings.h" |
dd05139a | 33 | #include "wx/gdicmn.h" |
02761f6c | 34 | #include "wx/module.h" |
9c7f49f5 VZ |
35 | #endif //WX_PRECOMP |
36 | ||
52c14774 | 37 | #include "wx/splitter.h" |
62dc9cb4 | 38 | #include "wx/dcmirror.h" |
9c7f49f5 VZ |
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 | ||
c97c9952 | 49 | virtual int DrawHeaderButton(wxWindow *win, |
9c7f49f5 VZ |
50 | wxDC& dc, |
51 | const wxRect& rect, | |
4b94ddc4 | 52 | int flags = 0, |
9c97f006 | 53 | wxHeaderSortIconType sortArrow = wxHDR_SORT_ICON_NONE, |
4b94ddc4 RD |
54 | wxHeaderButtonParams* params = NULL); |
55 | ||
c97c9952 | 56 | virtual int DrawHeaderButtonContents(wxWindow *win, |
4b94ddc4 RD |
57 | wxDC& dc, |
58 | const wxRect& rect, | |
59 | int flags = 0, | |
9c97f006 | 60 | wxHeaderSortIconType sortArrow = wxHDR_SORT_ICON_NONE, |
4b94ddc4 RD |
61 | wxHeaderButtonParams* params = NULL); |
62 | ||
63 | virtual int GetHeaderButtonHeight(wxWindow *win); | |
9c7f49f5 | 64 | |
9c7f49f5 VZ |
65 | virtual void DrawTreeItemButton(wxWindow *win, |
66 | wxDC& dc, | |
67 | const wxRect& rect, | |
68 | int flags = 0); | |
b3208e11 VZ |
69 | |
70 | virtual void DrawSplitterBorder(wxWindow *win, | |
71 | wxDC& dc, | |
af99040c VZ |
72 | const wxRect& rect, |
73 | int flags = 0); | |
b3208e11 VZ |
74 | |
75 | virtual void DrawSplitterSash(wxWindow *win, | |
76 | wxDC& dc, | |
77 | const wxSize& size, | |
62dc9cb4 | 78 | wxCoord position, |
af99040c VZ |
79 | wxOrientation orient, |
80 | int flags = 0); | |
b3208e11 | 81 | |
f33cef9f VZ |
82 | virtual void DrawComboBoxDropButton(wxWindow *win, |
83 | wxDC& dc, | |
84 | const wxRect& rect, | |
85 | int flags = 0); | |
86 | ||
4c85ab75 VZ |
87 | virtual void DrawDropArrow(wxWindow *win, |
88 | wxDC& dc, | |
89 | const wxRect& rect, | |
90 | int flags = 0); | |
b3208e11 | 91 | |
90b903c2 WS |
92 | virtual void DrawCheckBox(wxWindow *win, |
93 | wxDC& dc, | |
94 | const wxRect& rect, | |
95 | int flags = 0); | |
2209baae RR |
96 | |
97 | virtual void DrawPushButton(wxWindow *win, | |
98 | wxDC& dc, | |
99 | const wxRect& rect, | |
100 | int flags = 0); | |
101 | ||
daebb44c RR |
102 | virtual void DrawItemSelectionRect(wxWindow *win, |
103 | wxDC& dc, | |
104 | const wxRect& rect, | |
105 | int flags = 0); | |
784d2408 | 106 | |
6d789987 JS |
107 | virtual void DrawFocusRect(wxWindow* win, wxDC& dc, const wxRect& rect, int flags = 0); |
108 | ||
af99040c | 109 | virtual wxSplitterRenderParams GetSplitterParams(const wxWindow *win); |
b3208e11 | 110 | |
04857cb7 VZ |
111 | virtual wxRendererVersion GetVersion() const |
112 | { | |
113 | return wxRendererVersion(wxRendererVersion::Current_Version, | |
114 | wxRendererVersion::Current_Age); | |
115 | } | |
116 | ||
117 | ||
0872a451 JS |
118 | // Cleanup by deleting standard renderer |
119 | static void Cleanup(); | |
120 | ||
121 | // Get the generic object | |
122 | static wxRendererGeneric* DoGetGeneric(); | |
b3208e11 VZ |
123 | |
124 | protected: | |
125 | // draw the rectange using the first pen for the left and top sides and | |
126 | // the second one for the bottom and right ones | |
127 | void DrawShadedRect(wxDC& dc, wxRect *rect, | |
128 | const wxPen& pen1, const wxPen& pen2); | |
129 | ||
130 | // the standard pens | |
131 | wxPen m_penBlack, | |
132 | m_penDarkGrey, | |
133 | m_penLightGrey, | |
134 | m_penHighlight; | |
0872a451 JS |
135 | |
136 | static wxRendererGeneric* sm_rendererGeneric; | |
9c7f49f5 VZ |
137 | }; |
138 | ||
139 | // ============================================================================ | |
b3208e11 | 140 | // wxRendererGeneric implementation |
9c7f49f5 VZ |
141 | // ============================================================================ |
142 | ||
0872a451 JS |
143 | // Get the generic object |
144 | wxRendererGeneric* wxRendererGeneric::DoGetGeneric() | |
145 | { | |
146 | if (!sm_rendererGeneric) | |
147 | sm_rendererGeneric = new wxRendererGeneric; | |
148 | return sm_rendererGeneric; | |
149 | } | |
150 | ||
9c7f49f5 VZ |
151 | // ---------------------------------------------------------------------------- |
152 | // wxRendererGeneric creation | |
153 | // ---------------------------------------------------------------------------- | |
154 | ||
155 | /* static */ | |
38c4cb6a | 156 | wxRendererNative& wxRendererNative::GetGeneric() |
9c7f49f5 | 157 | { |
0872a451 JS |
158 | return * wxRendererGeneric::DoGetGeneric(); |
159 | } | |
9c7f49f5 | 160 | |
0872a451 JS |
161 | void wxRendererGeneric::Cleanup() |
162 | { | |
163 | if (sm_rendererGeneric) | |
164 | delete sm_rendererGeneric; | |
ca65c044 | 165 | |
0872a451 | 166 | sm_rendererGeneric = NULL; |
9c7f49f5 VZ |
167 | } |
168 | ||
0872a451 JS |
169 | wxRendererGeneric* wxRendererGeneric::sm_rendererGeneric = NULL; |
170 | ||
b3208e11 VZ |
171 | wxRendererGeneric::wxRendererGeneric() |
172 | : m_penBlack(wxSystemSettings::GetColour(wxSYS_COLOUR_3DDKSHADOW)), | |
173 | m_penDarkGrey(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW)), | |
174 | m_penLightGrey(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE)), | |
175 | m_penHighlight(wxSystemSettings::GetColour(wxSYS_COLOUR_3DHIGHLIGHT)) | |
176 | { | |
177 | } | |
178 | ||
9c7f49f5 | 179 | // ---------------------------------------------------------------------------- |
b3208e11 VZ |
180 | // wxRendererGeneric helpers |
181 | // ---------------------------------------------------------------------------- | |
182 | ||
183 | void | |
184 | wxRendererGeneric::DrawShadedRect(wxDC& dc, | |
185 | wxRect *rect, | |
186 | const wxPen& pen1, | |
187 | const wxPen& pen2) | |
188 | { | |
189 | // draw the rectangle | |
190 | dc.SetPen(pen1); | |
191 | dc.DrawLine(rect->GetLeft(), rect->GetTop(), | |
192 | rect->GetLeft(), rect->GetBottom()); | |
193 | dc.DrawLine(rect->GetLeft() + 1, rect->GetTop(), | |
194 | rect->GetRight(), rect->GetTop()); | |
195 | dc.SetPen(pen2); | |
196 | dc.DrawLine(rect->GetRight(), rect->GetTop(), | |
197 | rect->GetRight(), rect->GetBottom()); | |
198 | dc.DrawLine(rect->GetLeft(), rect->GetBottom(), | |
199 | rect->GetRight() + 1, rect->GetBottom()); | |
200 | ||
201 | // adjust the rect | |
202 | rect->Inflate(-1); | |
203 | } | |
204 | ||
205 | // ---------------------------------------------------------------------------- | |
206 | // tree/list ctrl drawing | |
9c7f49f5 VZ |
207 | // ---------------------------------------------------------------------------- |
208 | ||
c97c9952 | 209 | int |
4b94ddc4 | 210 | wxRendererGeneric::DrawHeaderButton(wxWindow* win, |
9c7f49f5 VZ |
211 | wxDC& dc, |
212 | const wxRect& rect, | |
4b94ddc4 | 213 | int flags, |
80752b57 | 214 | wxHeaderSortIconType sortArrow, |
4b94ddc4 | 215 | wxHeaderButtonParams* params) |
9c7f49f5 | 216 | { |
38c4cb6a VZ |
217 | const int CORNER = 1; |
218 | ||
219 | const wxCoord x = rect.x, | |
220 | y = rect.y, | |
221 | w = rect.width, | |
222 | h = rect.height; | |
9c7f49f5 | 223 | |
4b94ddc4 RD |
224 | dc.SetBrush(wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE))); |
225 | dc.SetPen(*wxTRANSPARENT_PEN); | |
226 | dc.DrawRectangle(rect); | |
6d789987 | 227 | |
b3208e11 | 228 | dc.SetBrush(*wxTRANSPARENT_BRUSH); |
9c7f49f5 | 229 | |
b3208e11 | 230 | dc.SetPen(m_penBlack); |
38c4cb6a VZ |
231 | dc.DrawLine( x+w-CORNER+1, y, x+w, y+h ); // right (outer) |
232 | dc.DrawRectangle( x, y+h, w+1, 1 ); // bottom (outer) | |
9c7f49f5 | 233 | |
b3208e11 | 234 | dc.SetPen(m_penDarkGrey); |
38c4cb6a VZ |
235 | dc.DrawLine( x+w-CORNER, y, x+w-1, y+h ); // right (inner) |
236 | dc.DrawRectangle( x+1, y+h-1, w-2, 1 ); // bottom (inner) | |
9c7f49f5 | 237 | |
b3208e11 | 238 | dc.SetPen(m_penHighlight); |
38c4cb6a VZ |
239 | dc.DrawRectangle( x, y, w-CORNER+1, 1 ); // top (outer) |
240 | dc.DrawRectangle( x, y, 1, h ); // left (outer) | |
241 | dc.DrawLine( x, y+h-1, x+1, y+h-1 ); | |
242 | dc.DrawLine( x+w-1, y, x+w-1, y+1 ); | |
4b94ddc4 | 243 | |
c97c9952 | 244 | return DrawHeaderButtonContents(win, dc, rect, flags, sortArrow, params); |
9c7f49f5 VZ |
245 | } |
246 | ||
80752b57 | 247 | |
c97c9952 | 248 | int |
4b94ddc4 RD |
249 | wxRendererGeneric::DrawHeaderButtonContents(wxWindow *win, |
250 | wxDC& dc, | |
251 | const wxRect& rect, | |
252 | int flags, | |
80752b57 | 253 | wxHeaderSortIconType sortArrow, |
4b94ddc4 RD |
254 | wxHeaderButtonParams* params) |
255 | { | |
c97c9952 | 256 | int labelWidth = 0; |
6d789987 | 257 | |
4b94ddc4 RD |
258 | // Mark this item as selected. For the generic version we'll just draw an |
259 | // underline | |
260 | if ( flags & wxCONTROL_SELECTED ) | |
261 | { | |
262 | // draw a line at the bottom of the header button, overlaying the | |
263 | // native hot-tracking line (on XP) | |
264 | const int penwidth = 3; | |
265 | int y = rect.y + rect.height + 1 - penwidth; | |
266 | wxColour c = (params && params->m_selectionColour.Ok()) ? | |
267 | params->m_selectionColour : wxColour(0x66, 0x66, 0x66); | |
268 | wxPen pen(c, penwidth); | |
269 | pen.SetCap(wxCAP_BUTT); | |
270 | dc.SetPen(pen); | |
271 | dc.DrawLine(rect.x, y, rect.x + rect.width, y); | |
272 | } | |
273 | ||
274 | // Draw an up or down arrow | |
275 | int arrowSpace = 0; | |
80752b57 | 276 | if (sortArrow != wxHDR_SORT_ICON_NONE ) |
4b94ddc4 RD |
277 | { |
278 | wxRect ar = rect; | |
279 | ||
280 | // make a rect for the arrow | |
281 | ar.height = 4; | |
282 | ar.width = 8; | |
283 | ar.y += (rect.height - ar.height)/2; | |
284 | ar.x = ar.x + rect.width - 3*ar.width/2; | |
285 | arrowSpace = 3*ar.width/2; // space to preserve when drawing the label | |
6d789987 | 286 | |
4b94ddc4 | 287 | wxPoint triPt[3]; |
80752b57 | 288 | if ( sortArrow & wxHDR_SORT_ICON_UP ) |
4b94ddc4 RD |
289 | { |
290 | triPt[0].x = ar.width / 2; | |
291 | triPt[0].y = 0; | |
292 | triPt[1].x = ar.width; | |
293 | triPt[1].y = ar.height; | |
294 | triPt[2].x = 0; | |
295 | triPt[2].y = ar.height; | |
296 | } | |
297 | else | |
298 | { | |
299 | triPt[0].x = 0; | |
300 | triPt[0].y = 0; | |
301 | triPt[1].x = ar.width; | |
302 | triPt[1].y = 0; | |
303 | triPt[2].x = ar.width / 2; | |
304 | triPt[2].y = ar.height; | |
305 | } | |
306 | ||
307 | wxColour c = (params && params->m_arrowColour.Ok()) ? | |
308 | params->m_arrowColour : wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW); | |
309 | dc.SetPen(wxPen(c)); | |
310 | dc.SetBrush(wxBrush(c)); | |
6d789987 | 311 | dc.DrawPolygon( 3, triPt, ar.x, ar.y); |
4b94ddc4 | 312 | } |
c97c9952 | 313 | labelWidth += arrowSpace; |
6d789987 | 314 | |
4b94ddc4 RD |
315 | const int margin = 5; // number of pixels to reserve on either side of the label |
316 | int bmpWidth = 0; | |
317 | int txtEnd = 0; | |
6d789987 | 318 | |
4b94ddc4 RD |
319 | if ( params && params->m_labelBitmap.Ok() ) |
320 | bmpWidth = params->m_labelBitmap.GetWidth() + 2; | |
c97c9952 RD |
321 | |
322 | labelWidth += bmpWidth + 2*margin; | |
6d789987 | 323 | |
4b94ddc4 RD |
324 | // Draw a label if one is given |
325 | if ( params && !params->m_labelText.empty() ) | |
326 | { | |
327 | wxFont font = params->m_labelFont.Ok() ? | |
328 | params->m_labelFont : win->GetFont(); | |
329 | wxColour clr = params->m_labelColour.Ok() ? | |
330 | params->m_labelColour : win->GetForegroundColour(); | |
331 | ||
332 | wxString label( params->m_labelText ); | |
6d789987 | 333 | |
4b94ddc4 RD |
334 | dc.SetFont(font); |
335 | dc.SetTextForeground(clr); | |
336 | dc.SetBackgroundMode(wxTRANSPARENT); | |
337 | ||
338 | int tw, th, td, x, y; | |
339 | dc.GetTextExtent( label, &tw, &th, &td); | |
c97c9952 | 340 | labelWidth += tw; |
4b94ddc4 | 341 | y = rect.y + wxMax(0, (rect.height - (th+td)) / 2); |
6d789987 | 342 | |
4b94ddc4 RD |
343 | // truncate and add an ellipsis (...) if the text is too wide. |
344 | int targetWidth = rect.width - arrowSpace - bmpWidth - 2*margin; | |
6d789987 | 345 | if ( tw > targetWidth ) |
4b94ddc4 RD |
346 | { |
347 | int ellipsisWidth; | |
348 | dc.GetTextExtent( wxT("..."), &ellipsisWidth, NULL); | |
349 | do { | |
350 | label.Truncate( label.length() - 1 ); | |
351 | dc.GetTextExtent( label, &tw, &th); | |
352 | } while (tw + ellipsisWidth > targetWidth && label.length() ); | |
353 | label.append( wxT("...") ); | |
354 | tw += ellipsisWidth; | |
355 | } | |
6d789987 | 356 | |
4b94ddc4 RD |
357 | switch (params->m_labelAlignment) |
358 | { | |
359 | default: | |
360 | case wxALIGN_LEFT: | |
361 | x = rect.x + margin; | |
362 | break; | |
363 | case wxALIGN_CENTER: | |
364 | x = rect.x + wxMax(0, (rect.width - arrowSpace - tw - bmpWidth)/2); | |
365 | break; | |
366 | case wxALIGN_RIGHT: | |
367 | x = rect.x + wxMax(0, rect.width - arrowSpace - margin - tw - bmpWidth); | |
368 | break; | |
369 | } | |
370 | ||
371 | dc.DrawText(label, x, y); | |
372 | txtEnd = x + tw + 2; | |
373 | } | |
374 | ||
375 | // draw the bitmap if there is one | |
376 | if ( params && params->m_labelBitmap.Ok() ) | |
377 | { | |
378 | int w, h, x, y; | |
379 | w = params->m_labelBitmap.GetWidth(); | |
380 | h = params->m_labelBitmap.GetHeight(); | |
381 | ||
382 | y = rect.y + wxMax(1, (rect.height - h) / 2); | |
383 | ||
384 | // if there is a text label, then put the bitmap at the end of the label | |
385 | if ( txtEnd != 0 ) | |
386 | { | |
387 | x = txtEnd; | |
388 | } | |
389 | // otherwise use the alignment flags | |
390 | else | |
391 | { | |
392 | switch (params->m_labelAlignment) | |
393 | { | |
394 | default: | |
395 | case wxALIGN_LEFT: | |
396 | x = rect.x + margin; | |
397 | break; | |
398 | case wxALIGN_CENTER: | |
399 | x = rect.x + wxMax(1, (rect.width - arrowSpace - w)/2); | |
400 | break; | |
401 | case wxALIGN_RIGHT: | |
402 | x = rect.x + wxMax(1, rect.width - arrowSpace - margin - w); | |
403 | break; | |
404 | } | |
405 | } | |
406 | dc.DrawBitmap(params->m_labelBitmap, x, y, true); | |
407 | } | |
c97c9952 | 408 | return labelWidth; |
4b94ddc4 RD |
409 | } |
410 | ||
411 | ||
412 | int wxRendererGeneric::GetHeaderButtonHeight(wxWindow *win) | |
413 | { | |
414 | // Copied and adapted from src/generic/listctrl.cpp | |
415 | const int HEADER_OFFSET_Y = 1; | |
416 | const int EXTRA_HEIGHT = 4; | |
417 | ||
418 | int w=0, h=14, d=0; | |
419 | if (win) | |
420 | win->GetTextExtent(wxT("Hg"), &w, &h, &d); | |
421 | ||
422 | return h + d + 2 * HEADER_OFFSET_Y + EXTRA_HEIGHT; | |
423 | } | |
424 | ||
425 | ||
9c7f49f5 VZ |
426 | // draw the plus or minus sign |
427 | void | |
2eb10e2a | 428 | wxRendererGeneric::DrawTreeItemButton(wxWindow * WXUNUSED(win), |
9c7f49f5 VZ |
429 | wxDC& dc, |
430 | const wxRect& rect, | |
431 | int flags) | |
432 | { | |
75d6ba56 | 433 | // store settings |
0164f8eb WS |
434 | wxDCPenChanger penChanger(dc, *wxGREY_PEN); |
435 | wxDCBrushChanger brushChanger(dc, *wxWHITE_BRUSH); | |
4660e6ac | 436 | |
0e7761fa | 437 | dc.DrawRectangle(rect); |
9c7f49f5 VZ |
438 | |
439 | // black lines | |
440 | const wxCoord xMiddle = rect.x + rect.width/2; | |
441 | const wxCoord yMiddle = rect.y + rect.height/2; | |
442 | ||
0e7761fa VZ |
443 | // half of the length of the horz lines in "-" and "+" |
444 | const wxCoord halfWidth = rect.width/2 - 2; | |
9c7f49f5 | 445 | dc.SetPen(*wxBLACK_PEN); |
429ef4bc VZ |
446 | dc.DrawLine(xMiddle - halfWidth, yMiddle, |
447 | xMiddle + halfWidth + 1, yMiddle); | |
448 | ||
e8448b79 | 449 | if ( !(flags & wxCONTROL_EXPANDED) ) |
9c7f49f5 VZ |
450 | { |
451 | // turn "-" into "+" | |
0e7761fa VZ |
452 | const wxCoord halfHeight = rect.height/2 - 2; |
453 | dc.DrawLine(xMiddle, yMiddle - halfHeight, | |
429ef4bc | 454 | xMiddle, yMiddle + halfHeight + 1); |
9c7f49f5 VZ |
455 | } |
456 | } | |
457 | ||
b3208e11 VZ |
458 | // ---------------------------------------------------------------------------- |
459 | // sash drawing | |
460 | // ---------------------------------------------------------------------------- | |
461 | ||
af99040c VZ |
462 | wxSplitterRenderParams |
463 | wxRendererGeneric::GetSplitterParams(const wxWindow *win) | |
b3208e11 VZ |
464 | { |
465 | // see below | |
af99040c VZ |
466 | wxCoord sashWidth, |
467 | border; | |
468 | ||
4666bb5f | 469 | if ( win->HasFlag(wxSP_3DSASH) ) |
af99040c | 470 | sashWidth = 7; |
4666bb5f JS |
471 | else if ( win->HasFlag(wxSP_NOSASH) ) |
472 | sashWidth = 0; | |
af99040c | 473 | else // no 3D effect |
28f9eac4 | 474 | sashWidth = 3; |
4666bb5f JS |
475 | |
476 | if ( win->HasFlag(wxSP_3DBORDER) ) | |
477 | border = 2; | |
478 | else // no 3D effect | |
af99040c | 479 | border = 0; |
af99040c VZ |
480 | |
481 | return wxSplitterRenderParams(sashWidth, border, false); | |
b3208e11 VZ |
482 | } |
483 | ||
484 | void | |
52c14774 | 485 | wxRendererGeneric::DrawSplitterBorder(wxWindow *win, |
b3208e11 | 486 | wxDC& dc, |
af99040c VZ |
487 | const wxRect& rectOrig, |
488 | int WXUNUSED(falgs)) | |
b3208e11 | 489 | { |
4666bb5f | 490 | if ( win->HasFlag(wxSP_3DBORDER) ) |
52c14774 VZ |
491 | { |
492 | wxRect rect = rectOrig; | |
493 | DrawShadedRect(dc, &rect, m_penDarkGrey, m_penHighlight); | |
494 | DrawShadedRect(dc, &rect, m_penBlack, m_penLightGrey); | |
495 | } | |
b3208e11 VZ |
496 | } |
497 | ||
498 | void | |
52c14774 | 499 | wxRendererGeneric::DrawSplitterSash(wxWindow *win, |
62dc9cb4 VZ |
500 | wxDC& dcReal, |
501 | const wxSize& sizeReal, | |
502 | wxCoord position, | |
af99040c VZ |
503 | wxOrientation orient, |
504 | int WXUNUSED(flags)) | |
b3208e11 | 505 | { |
62dc9cb4 VZ |
506 | // to avoid duplicating the same code for horizontal and vertical sashes, |
507 | // simply mirror the DC instead if needed (i.e. if horz splitter) | |
508 | wxMirrorDC dc(dcReal, orient != wxVERTICAL); | |
509 | wxSize size = dc.Reflect(sizeReal); | |
510 | ||
511 | ||
52c14774 | 512 | // we draw a Win32-like grey sash with possible 3D border here: |
b3208e11 VZ |
513 | // |
514 | // ---- this is position | |
515 | // / | |
516 | // v | |
517 | // dWGGGDd | |
518 | // GWGGGDB | |
519 | // GWGGGDB where G is light grey (face) | |
520 | // GWGGGDB W white (light) | |
521 | // GWGGGDB D dark grey (shadow) | |
522 | // GWGGGDB B black (dark shadow) | |
523 | // GWGGGDB | |
524 | // GWGGGDB and lower letters are our border (already drawn) | |
525 | // GWGGGDB | |
526 | // wWGGGDd | |
52c14774 VZ |
527 | // |
528 | // only the middle 3 columns are drawn unless wxSP_3D is specified | |
b3208e11 VZ |
529 | |
530 | const wxCoord h = size.y; | |
8aa528db | 531 | wxCoord offset = 0; |
ca65c044 | 532 | |
4666bb5f JS |
533 | // If we're drawing the border, draw the sash 3d lines shorter |
534 | if ( win->HasFlag(wxSP_3DBORDER) ) | |
8aa528db | 535 | { |
4666bb5f | 536 | offset = 1; |
8aa528db | 537 | } |
b3208e11 | 538 | |
4666bb5f | 539 | dc.SetPen(*wxTRANSPARENT_PEN); |
ca65c044 WS |
540 | dc.SetBrush(wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE))); |
541 | ||
4666bb5f | 542 | if ( win->HasFlag(wxSP_3DSASH) ) |
52c14774 | 543 | { |
4666bb5f JS |
544 | // Draw the 3D sash |
545 | dc.DrawRectangle(position + 2, 0, 3, h); | |
546 | ||
52c14774 | 547 | dc.SetPen(m_penLightGrey); |
4666bb5f | 548 | dc.DrawLine(position, offset, position, h - offset); |
b3208e11 | 549 | |
52c14774 | 550 | dc.SetPen(m_penHighlight); |
4666bb5f | 551 | dc.DrawLine(position + 1, 0, position + 1, h); |
b3208e11 | 552 | |
52c14774 | 553 | dc.SetPen(m_penDarkGrey); |
4666bb5f | 554 | dc.DrawLine(position + 5, 0, position + 5, h); |
b3208e11 | 555 | |
52c14774 | 556 | dc.SetPen(m_penBlack); |
4666bb5f JS |
557 | dc.DrawLine(position + 6, offset, position + 6, h - offset); |
558 | } | |
559 | else | |
560 | { | |
561 | // Draw a flat sash | |
562 | dc.DrawRectangle(position, 0, 3, h); | |
52c14774 | 563 | } |
b3208e11 | 564 | } |
9c7f49f5 | 565 | |
4c85ab75 VZ |
566 | // ---------------------------------------------------------------------------- |
567 | // button drawing | |
568 | // ---------------------------------------------------------------------------- | |
569 | ||
f33cef9f VZ |
570 | void |
571 | wxRendererGeneric::DrawComboBoxDropButton(wxWindow *win, | |
572 | wxDC& dc, | |
573 | const wxRect& rect, | |
2209baae | 574 | int flags) |
f33cef9f | 575 | { |
2209baae RR |
576 | DrawPushButton(win,dc,rect,flags); |
577 | DrawDropArrow(win,dc,rect,flags); | |
4c85ab75 VZ |
578 | } |
579 | ||
4c85ab75 VZ |
580 | void |
581 | wxRendererGeneric::DrawDropArrow(wxWindow *win, | |
582 | wxDC& dc, | |
583 | const wxRect& rect, | |
584 | int WXUNUSED(flags)) | |
585 | { | |
586 | // This generic implementation should be good | |
587 | // enough for Windows platforms (including XP). | |
588 | ||
589 | int arrowHalf = rect.width/5; | |
590 | int rectMid = rect.width / 2; | |
591 | int arrowTopY = (rect.height/2) - (arrowHalf/2); | |
592 | ||
593 | // This should always result in arrow with odd width. | |
106a7999 | 594 | wxPoint pt[] = |
f33cef9f | 595 | { |
4c85ab75 VZ |
596 | wxPoint(rectMid - arrowHalf, arrowTopY), |
597 | wxPoint(rectMid + arrowHalf, arrowTopY), | |
598 | wxPoint(rectMid, arrowTopY + arrowHalf) | |
f33cef9f VZ |
599 | }; |
600 | dc.SetBrush(wxBrush(win->GetForegroundColour())); | |
601 | dc.SetPen(wxPen(win->GetForegroundColour())); | |
106a7999 | 602 | dc.DrawPolygon(WXSIZEOF(pt), pt, rect.x, rect.y); |
f33cef9f VZ |
603 | } |
604 | ||
784d2408 | 605 | void |
90b903c2 WS |
606 | wxRendererGeneric::DrawCheckBox(wxWindow *WXUNUSED(win), |
607 | wxDC& dc, | |
608 | const wxRect& rect, | |
609 | int flags) | |
862d8041 | 610 | { |
3061e2fb | 611 | dc.SetPen(*(flags & wxCONTROL_DISABLED ? wxGREY_PEN : wxBLACK_PEN)); |
862d8041 | 612 | dc.SetBrush( *wxTRANSPARENT_BRUSH ); |
3061e2fb VZ |
613 | dc.DrawRectangle(rect); |
614 | ||
615 | if ( flags & wxCONTROL_CHECKED ) | |
862d8041 | 616 | { |
3061e2fb | 617 | dc.DrawCheckMark(rect.Deflate(2, 2)); |
862d8041 RR |
618 | } |
619 | } | |
620 | ||
2209baae RR |
621 | void |
622 | wxRendererGeneric::DrawPushButton(wxWindow *win, | |
623 | wxDC& dc, | |
624 | const wxRect& rect, | |
625 | int flags) | |
626 | { | |
627 | // Don't try anything too fancy. It'll just turn out looking | |
628 | // out-of-place on most platforms. | |
629 | wxColour bgCol = flags & wxCONTROL_DISABLED ? | |
630 | wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE) : | |
631 | win->GetBackgroundColour(); | |
632 | dc.SetBrush(wxBrush(bgCol)); | |
633 | dc.SetPen(wxPen(bgCol)); | |
634 | dc.DrawRectangle(rect); | |
635 | } | |
636 | ||
784d2408 VZ |
637 | void |
638 | wxRendererGeneric::DrawItemSelectionRect(wxWindow * WXUNUSED(win), | |
639 | wxDC& dc, | |
640 | const wxRect& rect, | |
641 | int flags) | |
daebb44c | 642 | { |
784d2408 VZ |
643 | wxBrush brush; |
644 | if ( flags & wxCONTROL_SELECTED ) | |
daebb44c | 645 | { |
784d2408 | 646 | if ( flags & wxCONTROL_FOCUSED ) |
daebb44c | 647 | { |
784d2408 | 648 | brush = wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT)); |
daebb44c | 649 | } |
784d2408 | 650 | else // !focused |
daebb44c | 651 | { |
784d2408 | 652 | brush = wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNSHADOW)); |
daebb44c RR |
653 | } |
654 | } | |
784d2408 | 655 | else // !selected |
daebb44c | 656 | { |
784d2408 | 657 | brush = *wxTRANSPARENT_BRUSH; |
daebb44c | 658 | } |
784d2408 VZ |
659 | |
660 | dc.SetBrush(brush); | |
661 | dc.SetPen(flags & wxCONTROL_CURRENT ? *wxBLACK_PEN : *wxTRANSPARENT_PEN); | |
662 | ||
663 | dc.DrawRectangle( rect ); | |
daebb44c RR |
664 | } |
665 | ||
6d789987 JS |
666 | void |
667 | wxRendererGeneric::DrawFocusRect(wxWindow* WXUNUSED(win), wxDC& dc, const wxRect& rect, int WXUNUSED(flags)) | |
668 | { | |
669 | // draw the pixels manually because the "dots" in wxPen with wxDOT style | |
670 | // may be short traits and not really dots | |
671 | // | |
672 | // note that to behave in the same manner as DrawRect(), we must exclude | |
673 | // the bottom and right borders from the rectangle | |
674 | wxCoord x1 = rect.GetLeft(), | |
675 | y1 = rect.GetTop(), | |
676 | x2 = rect.GetRight(), | |
677 | y2 = rect.GetBottom(); | |
678 | ||
679 | dc.SetPen(m_penBlack); | |
680 | ||
e2125bdc JS |
681 | #ifdef __WXMAC__ |
682 | dc.SetLogicalFunction(wxCOPY); | |
683 | #else | |
6d789987 JS |
684 | // this seems to be closer than what Windows does than wxINVERT although |
685 | // I'm still not sure if it's correct | |
686 | dc.SetLogicalFunction(wxAND_REVERSE); | |
e2125bdc | 687 | #endif |
6d789987 JS |
688 | |
689 | wxCoord z; | |
690 | for ( z = x1 + 1; z < x2; z += 2 ) | |
691 | dc.DrawPoint(z, rect.GetTop()); | |
692 | ||
693 | wxCoord shift = z == x2 ? 0 : 1; | |
694 | for ( z = y1 + shift; z < y2; z += 2 ) | |
695 | dc.DrawPoint(x2, z); | |
696 | ||
697 | shift = z == y2 ? 0 : 1; | |
698 | for ( z = x2 - shift; z > x1; z -= 2 ) | |
699 | dc.DrawPoint(z, y2); | |
700 | ||
701 | shift = z == x1 ? 0 : 1; | |
702 | for ( z = y2 - shift; z > y1; z -= 2 ) | |
703 | dc.DrawPoint(x1, z); | |
704 | ||
705 | dc.SetLogicalFunction(wxCOPY); | |
706 | } | |
daebb44c | 707 | |
f33cef9f | 708 | // ---------------------------------------------------------------------------- |
0872a451 | 709 | // A module to allow cleanup of generic renderer. |
f33cef9f VZ |
710 | // ---------------------------------------------------------------------------- |
711 | ||
0872a451 JS |
712 | class wxGenericRendererModule: public wxModule |
713 | { | |
714 | DECLARE_DYNAMIC_CLASS(wxGenericRendererModule) | |
715 | public: | |
716 | wxGenericRendererModule() {} | |
47b378bd VS |
717 | bool OnInit() { return true; } |
718 | void OnExit() { wxRendererGeneric::Cleanup(); } | |
0872a451 JS |
719 | }; |
720 | ||
721 | IMPLEMENT_DYNAMIC_CLASS(wxGenericRendererModule, wxModule) |