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