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