]>
Commit | Line | Data |
---|---|---|
9c7f49f5 | 1 | /////////////////////////////////////////////////////////////////////////////// |
90b903c2 | 2 | // Name: src/gtk/renderer.cpp |
38c4cb6a | 3 | // Purpose: implementation of wxRendererNative for wxGTK |
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 | ||
e1bf3ad3 | 27 | #include "wx/renderer.h" |
cdccdfab WS |
28 | |
29 | #ifndef WX_PRECOMP | |
30 | #include "wx/window.h" | |
ed4b0fdc | 31 | #include "wx/dcclient.h" |
9eddec69 | 32 | #include "wx/settings.h" |
f1c09bed | 33 | #include "wx/module.h" |
cdccdfab WS |
34 | #endif |
35 | ||
02f07b19 | 36 | #include "wx/dcgraph.h" |
888dde65 | 37 | #include "wx/gtk/dc.h" |
e8759560 | 38 | #include "wx/gtk/private.h" |
888dde65 | 39 | |
9c7f49f5 | 40 | #include <gtk/gtk.h> |
9c7f49f5 | 41 | |
9c7f49f5 | 42 | // ---------------------------------------------------------------------------- |
38c4cb6a | 43 | // wxRendererGTK: our wxRendererNative implementation |
9c7f49f5 VZ |
44 | // ---------------------------------------------------------------------------- |
45 | ||
38c4cb6a | 46 | class WXDLLEXPORT wxRendererGTK : public wxDelegateRendererNative |
9c7f49f5 VZ |
47 | { |
48 | public: | |
49 | // draw the header control button (used by wxListCtrl) | |
c97c9952 | 50 | virtual int DrawHeaderButton(wxWindow *win, |
9c7f49f5 VZ |
51 | wxDC& dc, |
52 | const wxRect& rect, | |
4b94ddc4 | 53 | int flags = 0, |
80752b57 | 54 | wxHeaderSortIconType sortArrow = wxHDR_SORT_ICON_NONE, |
4b94ddc4 | 55 | wxHeaderButtonParams* params = NULL); |
9c7f49f5 | 56 | |
6f91f3a3 RR |
57 | virtual int GetHeaderButtonHeight(wxWindow *win); |
58 | ||
9aebcb5e VS |
59 | virtual int GetHeaderButtonMargin(wxWindow *win); |
60 | ||
6f91f3a3 | 61 | |
9c7f49f5 VZ |
62 | // draw the expanded/collapsed icon for a tree control item |
63 | virtual void DrawTreeItemButton(wxWindow *win, | |
64 | wxDC& dc, | |
65 | const wxRect& rect, | |
66 | int flags = 0); | |
9c7f49f5 | 67 | |
d16cf3cd VZ |
68 | virtual void DrawSplitterBorder(wxWindow *win, |
69 | wxDC& dc, | |
af99040c VZ |
70 | const wxRect& rect, |
71 | int flags = 0); | |
95155e75 VZ |
72 | virtual void DrawSplitterSash(wxWindow *win, |
73 | wxDC& dc, | |
74 | const wxSize& size, | |
d16cf3cd | 75 | wxCoord position, |
af99040c VZ |
76 | wxOrientation orient, |
77 | int flags = 0); | |
d16cf3cd | 78 | |
38511687 VZ |
79 | virtual void DrawComboBoxDropButton(wxWindow *win, |
80 | wxDC& dc, | |
81 | const wxRect& rect, | |
82 | int flags = 0); | |
83 | ||
4c85ab75 VZ |
84 | virtual void DrawDropArrow(wxWindow *win, |
85 | wxDC& dc, | |
86 | const wxRect& rect, | |
87 | int flags = 0); | |
88 | ||
90b903c2 WS |
89 | virtual void DrawCheckBox(wxWindow *win, |
90 | wxDC& dc, | |
91 | const wxRect& rect, | |
92 | int flags = 0); | |
2209baae RR |
93 | |
94 | virtual void DrawPushButton(wxWindow *win, | |
95 | wxDC& dc, | |
96 | const wxRect& rect, | |
97 | int flags = 0); | |
98 | ||
daebb44c RR |
99 | virtual void DrawItemSelectionRect(wxWindow *win, |
100 | wxDC& dc, | |
101 | const wxRect& rect, | |
102 | int flags = 0); | |
90b903c2 | 103 | |
99c4be68 VZ |
104 | virtual void DrawChoice(wxWindow* win, |
105 | wxDC& dc, | |
106 | const wxRect& rect, | |
e4131985 KO |
107 | int flags=0); |
108 | ||
99c4be68 VZ |
109 | virtual void DrawComboBox(wxWindow* win, |
110 | wxDC& dc, | |
111 | const wxRect& rect, | |
e4131985 KO |
112 | int flags=0); |
113 | ||
99c4be68 VZ |
114 | virtual void DrawTextCtrl(wxWindow* win, |
115 | wxDC& dc, | |
116 | const wxRect& rect, | |
e4131985 KO |
117 | int flags=0); |
118 | ||
6e6b532c | 119 | virtual void DrawRadioBitmap(wxWindow* win, |
99c4be68 VZ |
120 | wxDC& dc, |
121 | const wxRect& rect, | |
e4131985 KO |
122 | int flags=0); |
123 | ||
6d789987 JS |
124 | virtual void DrawFocusRect(wxWindow* win, wxDC& dc, const wxRect& rect, int flags = 0); |
125 | ||
191e43fd | 126 | virtual wxSize GetCheckBoxSize(wxWindow *win); |
f1c09bed | 127 | |
e8759560 | 128 | virtual wxSplitterRenderParams GetSplitterParams(const wxWindow *win); |
9c7f49f5 VZ |
129 | }; |
130 | ||
131 | // ============================================================================ | |
132 | // implementation | |
133 | // ============================================================================ | |
134 | ||
135 | /* static */ | |
f0244295 | 136 | wxRendererNative& wxRendererNative::GetDefault() |
9c7f49f5 VZ |
137 | { |
138 | static wxRendererGTK s_rendererGTK; | |
139 | ||
140 | return s_rendererGTK; | |
141 | } | |
142 | ||
02f07b19 | 143 | static GdkWindow* wxGetGdkWindowForDC(wxWindow* win, wxDC& dc) |
e4131985 KO |
144 | { |
145 | GdkWindow* gdk_window = NULL; | |
99c4be68 | 146 | |
02f07b19 KO |
147 | #if wxUSE_GRAPHICS_CONTEXT |
148 | if ( dc.IsKindOf( CLASSINFO(wxGCDC) ) ) | |
d81b2f54 | 149 | gdk_window = win->GTKGetDrawingWindow(); |
02f07b19 KO |
150 | else |
151 | #endif | |
152 | { | |
e4131985 | 153 | #if wxUSE_NEW_DC |
02f07b19 KO |
154 | wxDCImpl *impl = dc.GetImpl(); |
155 | wxGTKDCImpl *gtk_impl = wxDynamicCast( impl, wxGTKDCImpl ); | |
156 | if (gtk_impl) | |
157 | gdk_window = gtk_impl->GetGDKWindow(); | |
e4131985 | 158 | #else |
02f07b19 | 159 | gdk_window = dc.GetGDKWindow(); |
e4131985 | 160 | #endif |
02f07b19 | 161 | } |
b162ccca FM |
162 | |
163 | #if !wxUSE_GRAPHICS_CONTEXT | |
164 | wxUnusedVar(win); | |
165 | #endif | |
166 | ||
e4131985 KO |
167 | return gdk_window; |
168 | } | |
169 | ||
d16cf3cd VZ |
170 | // ---------------------------------------------------------------------------- |
171 | // list/tree controls drawing | |
172 | // ---------------------------------------------------------------------------- | |
173 | ||
c97c9952 | 174 | int |
9c7f49f5 VZ |
175 | wxRendererGTK::DrawHeaderButton(wxWindow *win, |
176 | wxDC& dc, | |
177 | const wxRect& rect, | |
4b94ddc4 | 178 | int flags, |
80752b57 | 179 | wxHeaderSortIconType sortArrow, |
4b94ddc4 | 180 | wxHeaderButtonParams* params) |
9c7f49f5 | 181 | { |
9b311923 | 182 | |
e8759560 | 183 | GtkWidget *button = wxGTKPrivate::GetHeaderButtonWidget(); |
09e72468 RR |
184 | if (flags & wxCONTROL_SPECIAL) |
185 | button = wxGTKPrivate::GetHeaderButtonWidgetFirst(); | |
6f91f3a3 | 186 | if (flags & wxCONTROL_DIRTY) |
b047e876 | 187 | button = wxGTKPrivate::GetHeaderButtonWidgetLast(); |
f1c09bed | 188 | |
02f07b19 | 189 | GdkWindow* gdk_window = wxGetGdkWindowForDC(win, dc); |
2e992e06 VZ |
190 | wxASSERT_MSG( gdk_window, |
191 | wxT("cannot use wxRendererNative on wxDC of this type") ); | |
192 | ||
5eefe029 RR |
193 | int x_diff = 0; |
194 | if (win->GetLayoutDirection() == wxLayout_RightToLeft) | |
195 | x_diff = rect.width; | |
f4322df6 | 196 | |
1cfc4971 RR |
197 | GtkStateType state = GTK_STATE_NORMAL; |
198 | if (flags & wxCONTROL_DISABLED) | |
199 | state = GTK_STATE_INSENSITIVE; | |
200 | else | |
201 | { | |
202 | if (flags & wxCONTROL_CURRENT) | |
203 | state = GTK_STATE_PRELIGHT; | |
204 | } | |
205 | ||
9c7f49f5 VZ |
206 | gtk_paint_box |
207 | ( | |
bc13e772 | 208 | button->style, |
2e992e06 | 209 | gdk_window, |
1cfc4971 | 210 | state, |
9c7f49f5 | 211 | GTK_SHADOW_OUT, |
38511687 | 212 | NULL, |
bc13e772 | 213 | button, |
9b311923 | 214 | "button", |
5eefe029 | 215 | dc.LogicalToDeviceX(rect.x) - x_diff, rect.y, rect.width, rect.height |
9c7f49f5 | 216 | ); |
99c4be68 | 217 | |
c97c9952 | 218 | return DrawHeaderButtonContents(win, dc, rect, flags, sortArrow, params); |
9c7f49f5 VZ |
219 | } |
220 | ||
6f91f3a3 RR |
221 | int wxRendererGTK::GetHeaderButtonHeight(wxWindow *WXUNUSED(win)) |
222 | { | |
223 | GtkWidget *button = wxGTKPrivate::GetHeaderButtonWidget(); | |
99c4be68 | 224 | |
6f91f3a3 RR |
225 | GtkRequisition req; |
226 | GTK_WIDGET_GET_CLASS(button)->size_request(button, &req); | |
99c4be68 | 227 | |
6f91f3a3 RR |
228 | return req.height; |
229 | } | |
230 | ||
9aebcb5e VS |
231 | int wxRendererGTK::GetHeaderButtonMargin(wxWindow *WXUNUSED(win)) |
232 | { | |
233 | wxFAIL_MSG( "GetHeaderButtonMargin() not implemented" ); | |
234 | return -1; | |
235 | } | |
236 | ||
6f91f3a3 | 237 | |
9c7f49f5 | 238 | // draw a ">" or "v" button |
9c7f49f5 | 239 | void |
f8b043e7 | 240 | wxRendererGTK::DrawTreeItemButton(wxWindow* win, |
9a0b7e33 | 241 | wxDC& dc, const wxRect& rect, int flags) |
9c7f49f5 | 242 | { |
e8759560 | 243 | GtkWidget *tree = wxGTKPrivate::GetTreeWidget(); |
f8b043e7 | 244 | |
02f07b19 | 245 | GdkWindow* gdk_window = wxGetGdkWindowForDC(win, dc); |
2e992e06 VZ |
246 | wxASSERT_MSG( gdk_window, |
247 | wxT("cannot use wxRendererNative on wxDC of this type") ); | |
248 | ||
885dd597 RR |
249 | GtkStateType state; |
250 | if ( flags & wxCONTROL_CURRENT ) | |
251 | state = GTK_STATE_PRELIGHT; | |
252 | else | |
253 | state = GTK_STATE_NORMAL; | |
91af0895 | 254 | |
428f4657 RR |
255 | int x_diff = 0; |
256 | if (win->GetLayoutDirection() == wxLayout_RightToLeft) | |
257 | x_diff = rect.width; | |
2e992e06 | 258 | |
bc13e772 VZ |
259 | // VZ: I don't know how to get the size of the expander so as to centre it |
260 | // in the given rectangle, +2/3 below is just what looks good here... | |
261 | gtk_paint_expander | |
262 | ( | |
263 | tree->style, | |
2e992e06 | 264 | gdk_window, |
885dd597 | 265 | state, |
bc13e772 VZ |
266 | NULL, |
267 | tree, | |
268 | "treeview", | |
11012f47 | 269 | dc.LogicalToDeviceX(rect.x) + 6 - x_diff, |
bc13e772 VZ |
270 | dc.LogicalToDeviceY(rect.y) + 3, |
271 | flags & wxCONTROL_EXPANDED ? GTK_EXPANDER_EXPANDED | |
272 | : GTK_EXPANDER_COLLAPSED | |
273 | ); | |
9c7f49f5 VZ |
274 | } |
275 | ||
9c7f49f5 | 276 | |
d16cf3cd VZ |
277 | // ---------------------------------------------------------------------------- |
278 | // splitter sash drawing | |
279 | // ---------------------------------------------------------------------------- | |
280 | ||
f1c09bed | 281 | static int GetGtkSplitterFullSize(GtkWidget* widget) |
38418827 | 282 | { |
38418827 | 283 | gint handle_size; |
f1c09bed | 284 | gtk_widget_style_get(widget, "handle_size", &handle_size, NULL); |
91af0895 | 285 | |
38418827 | 286 | return handle_size; |
38418827 RR |
287 | } |
288 | ||
af99040c | 289 | wxSplitterRenderParams |
38418827 | 290 | wxRendererGTK::GetSplitterParams(const wxWindow *WXUNUSED(win)) |
d16cf3cd | 291 | { |
af99040c VZ |
292 | // we don't draw any border, hence 0 for the second field |
293 | return wxSplitterRenderParams | |
294 | ( | |
e8759560 | 295 | GetGtkSplitterFullSize(wxGTKPrivate::GetSplitterWidget()), |
af99040c | 296 | 0, |
af99040c | 297 | true // hot sensitive |
af99040c | 298 | ); |
d16cf3cd VZ |
299 | } |
300 | ||
301 | void | |
302 | wxRendererGTK::DrawSplitterBorder(wxWindow * WXUNUSED(win), | |
303 | wxDC& WXUNUSED(dc), | |
af99040c VZ |
304 | const wxRect& WXUNUSED(rect), |
305 | int WXUNUSED(flags)) | |
d16cf3cd VZ |
306 | { |
307 | // nothing to do | |
308 | } | |
95155e75 | 309 | |
95155e75 | 310 | void |
02f07b19 | 311 | wxRendererGTK::DrawSplitterSash(wxWindow* win, |
95155e75 VZ |
312 | wxDC& dc, |
313 | const wxSize& size, | |
d16cf3cd | 314 | wxCoord position, |
af99040c | 315 | wxOrientation orient, |
68567a96 | 316 | int flags) |
95155e75 VZ |
317 | { |
318 | if ( !win->m_wxwindow->window ) | |
319 | { | |
0100b858 | 320 | // window not realized yet |
95155e75 VZ |
321 | return; |
322 | } | |
91af0895 | 323 | |
02f07b19 | 324 | GdkWindow* gdk_window = wxGetGdkWindowForDC(win, dc); |
2e992e06 VZ |
325 | wxASSERT_MSG( gdk_window, |
326 | wxT("cannot use wxRendererNative on wxDC of this type") ); | |
327 | ||
e8759560 | 328 | wxCoord full_size = GetGtkSplitterFullSize(wxGTKPrivate::GetSplitterWidget()); |
95155e75 | 329 | |
d16cf3cd VZ |
330 | // are we drawing vertical or horizontal splitter? |
331 | const bool isVert = orient == wxVERTICAL; | |
332 | ||
d16cf3cd | 333 | GdkRectangle rect; |
91af0895 | 334 | |
d16cf3cd VZ |
335 | if ( isVert ) |
336 | { | |
337 | rect.x = position; | |
0100b858 | 338 | rect.y = 0; |
38418827 | 339 | rect.width = full_size; |
e4161a2a | 340 | rect.height = size.y; |
d16cf3cd VZ |
341 | } |
342 | else // horz | |
343 | { | |
0100b858 | 344 | rect.x = 0; |
d16cf3cd | 345 | rect.y = position; |
38418827 | 346 | rect.height = full_size; |
e4161a2a | 347 | rect.width = size.x; |
d16cf3cd | 348 | } |
f4322df6 | 349 | |
847dfdb4 RR |
350 | int x_diff = 0; |
351 | if (win->GetLayoutDirection() == wxLayout_RightToLeft) | |
352 | x_diff = rect.width; | |
35468934 | 353 | |
af99040c VZ |
354 | gtk_paint_handle |
355 | ( | |
356 | win->m_wxwindow->style, | |
2e992e06 | 357 | gdk_window, |
af99040c VZ |
358 | flags & wxCONTROL_CURRENT ? GTK_STATE_PRELIGHT : GTK_STATE_NORMAL, |
359 | GTK_SHADOW_NONE, | |
360 | NULL /* no clipping */, | |
361 | win->m_wxwindow, | |
362 | "paned", | |
847dfdb4 RR |
363 | dc.LogicalToDeviceX(rect.x) - x_diff, |
364 | dc.LogicalToDeviceY(rect.y), | |
af99040c VZ |
365 | rect.width, |
366 | rect.height, | |
38418827 | 367 | isVert ? GTK_ORIENTATION_VERTICAL : GTK_ORIENTATION_HORIZONTAL |
af99040c | 368 | ); |
95155e75 VZ |
369 | } |
370 | ||
4c85ab75 | 371 | void |
02f07b19 | 372 | wxRendererGTK::DrawDropArrow(wxWindow* win, |
4c85ab75 VZ |
373 | wxDC& dc, |
374 | const wxRect& rect, | |
375 | int flags) | |
38511687 | 376 | { |
e8759560 | 377 | GtkWidget *button = wxGTKPrivate::GetButtonWidget(); |
38511687 | 378 | |
02f07b19 | 379 | // If we give WX_PIZZA(win->m_wxwindow)->bin_window as |
4c85ab75 VZ |
380 | // a window for gtk_paint_xxx function, then it won't |
381 | // work for wxMemoryDC. So that is why we assume wxDC | |
382 | // is wxWindowDC (wxClientDC, wxMemoryDC and wxPaintDC | |
383 | // are derived from it) and use its m_window. | |
02f07b19 | 384 | GdkWindow* gdk_window = wxGetGdkWindowForDC(win, dc); |
2e992e06 VZ |
385 | wxASSERT_MSG( gdk_window, |
386 | wxT("cannot use wxRendererNative on wxDC of this type") ); | |
a4622f29 | 387 | |
4c85ab75 VZ |
388 | // draw arrow so that there is even space horizontally |
389 | // on both sides | |
390 | int arrowX = rect.width/4 + 1; | |
391 | int arrowWidth = rect.width - (arrowX*2); | |
392 | ||
393 | // scale arrow's height accoording to the width | |
394 | int arrowHeight = rect.width/3; | |
395 | int arrowY = (rect.height-arrowHeight)/2 + | |
396 | ((rect.height-arrowHeight) & 1); | |
397 | ||
e1befae3 | 398 | GtkStateType state; |
a4622f29 | 399 | |
3203621a JS |
400 | if ( flags & wxCONTROL_PRESSED ) |
401 | state = GTK_STATE_ACTIVE; | |
a4622f29 VZ |
402 | else if ( flags & wxCONTROL_DISABLED ) |
403 | state = GTK_STATE_INSENSITIVE; | |
3203621a JS |
404 | else if ( flags & wxCONTROL_CURRENT ) |
405 | state = GTK_STATE_PRELIGHT; | |
e1befae3 VZ |
406 | else |
407 | state = GTK_STATE_NORMAL; | |
a4622f29 | 408 | |
a4622f29 | 409 | // draw arrow on button |
a4622f29 VZ |
410 | gtk_paint_arrow |
411 | ( | |
bc13e772 | 412 | button->style, |
2e992e06 | 413 | gdk_window, |
a4622f29 | 414 | state, |
e1befae3 | 415 | flags & wxCONTROL_PRESSED ? GTK_SHADOW_IN : GTK_SHADOW_OUT, |
a4622f29 | 416 | NULL, |
bc13e772 | 417 | button, |
a4622f29 VZ |
418 | "arrow", |
419 | GTK_ARROW_DOWN, | |
a8ac548e | 420 | FALSE, |
4c85ab75 VZ |
421 | rect.x + arrowX, |
422 | rect.y + arrowY, | |
423 | arrowWidth, | |
424 | arrowHeight | |
a4622f29 | 425 | ); |
38511687 VZ |
426 | } |
427 | ||
4c85ab75 VZ |
428 | void |
429 | wxRendererGTK::DrawComboBoxDropButton(wxWindow *win, | |
430 | wxDC& dc, | |
431 | const wxRect& rect, | |
432 | int flags) | |
433 | { | |
2209baae RR |
434 | DrawPushButton(win,dc,rect,flags); |
435 | DrawDropArrow(win,dc,rect); | |
436 | } | |
437 | ||
e8759560 | 438 | wxSize |
191e43fd | 439 | wxRendererGTK::GetCheckBoxSize(wxWindow *WXUNUSED(win)) |
e8759560 VZ |
440 | { |
441 | gint indicator_size, indicator_spacing; | |
442 | gtk_widget_style_get(wxGTKPrivate::GetCheckButtonWidget(), | |
443 | "indicator_size", &indicator_size, | |
444 | "indicator_spacing", &indicator_spacing, | |
445 | NULL); | |
446 | ||
447 | int size = indicator_size + indicator_spacing * 2; | |
448 | return wxSize(size, size); | |
449 | } | |
450 | ||
cdccdfab | 451 | void |
02f07b19 | 452 | wxRendererGTK::DrawCheckBox(wxWindow* win, |
90b903c2 WS |
453 | wxDC& dc, |
454 | const wxRect& rect, | |
455 | int flags ) | |
2209baae | 456 | { |
e8759560 | 457 | GtkWidget *button = wxGTKPrivate::GetCheckButtonWidget(); |
f1c09bed | 458 | |
02f07b19 | 459 | GdkWindow* gdk_window = wxGetGdkWindowForDC(win, dc); |
2e992e06 VZ |
460 | wxASSERT_MSG( gdk_window, |
461 | wxT("cannot use wxRendererNative on wxDC of this type") ); | |
90b903c2 | 462 | |
e8759560 VZ |
463 | gint indicator_size, indicator_spacing; |
464 | gtk_widget_style_get(button, | |
465 | "indicator_size", &indicator_size, | |
466 | "indicator_spacing", &indicator_spacing, | |
467 | NULL); | |
468 | ||
4c85ab75 VZ |
469 | GtkStateType state; |
470 | ||
3203621a JS |
471 | if ( flags & wxCONTROL_PRESSED ) |
472 | state = GTK_STATE_ACTIVE; | |
4c85ab75 VZ |
473 | else if ( flags & wxCONTROL_DISABLED ) |
474 | state = GTK_STATE_INSENSITIVE; | |
3203621a JS |
475 | else if ( flags & wxCONTROL_CURRENT ) |
476 | state = GTK_STATE_PRELIGHT; | |
4c85ab75 VZ |
477 | else |
478 | state = GTK_STATE_NORMAL; | |
90b903c2 | 479 | |
e78778c8 RR |
480 | GtkShadowType shadow_type; |
481 | ||
482 | if ( flags & wxCONTROL_UNDETERMINED ) | |
483 | shadow_type = GTK_SHADOW_ETCHED_IN; | |
484 | else if ( flags & wxCONTROL_CHECKED ) | |
485 | shadow_type = GTK_SHADOW_IN; | |
486 | else | |
487 | shadow_type = GTK_SHADOW_OUT; | |
488 | ||
2209baae | 489 | gtk_paint_check |
4c85ab75 VZ |
490 | ( |
491 | button->style, | |
2e992e06 | 492 | gdk_window, |
4c85ab75 | 493 | state, |
e78778c8 | 494 | shadow_type, |
4c85ab75 VZ |
495 | NULL, |
496 | button, | |
2209baae | 497 | "cellcheck", |
e8759560 VZ |
498 | dc.LogicalToDeviceX(rect.x) + indicator_spacing, |
499 | dc.LogicalToDeviceY(rect.y) + indicator_spacing, | |
500 | indicator_size, indicator_size | |
4c85ab75 | 501 | ); |
4c85ab75 VZ |
502 | } |
503 | ||
2209baae | 504 | void |
02f07b19 | 505 | wxRendererGTK::DrawPushButton(wxWindow* win, |
2209baae RR |
506 | wxDC& dc, |
507 | const wxRect& rect, | |
508 | int flags) | |
862d8041 | 509 | { |
e8759560 | 510 | GtkWidget *button = wxGTKPrivate::GetButtonWidget(); |
862d8041 | 511 | |
02f07b19 | 512 | GdkWindow* gdk_window = wxGetGdkWindowForDC(win, dc); |
2e992e06 VZ |
513 | wxASSERT_MSG( gdk_window, |
514 | wxT("cannot use wxRendererNative on wxDC of this type") ); | |
2209baae RR |
515 | |
516 | // draw button | |
862d8041 RR |
517 | GtkStateType state; |
518 | ||
519 | if ( flags & wxCONTROL_PRESSED ) | |
520 | state = GTK_STATE_ACTIVE; | |
521 | else if ( flags & wxCONTROL_DISABLED ) | |
522 | state = GTK_STATE_INSENSITIVE; | |
523 | else if ( flags & wxCONTROL_CURRENT ) | |
524 | state = GTK_STATE_PRELIGHT; | |
525 | else | |
526 | state = GTK_STATE_NORMAL; | |
2209baae RR |
527 | |
528 | gtk_paint_box | |
862d8041 RR |
529 | ( |
530 | button->style, | |
2e992e06 | 531 | gdk_window, |
862d8041 | 532 | state, |
2209baae | 533 | flags & wxCONTROL_PRESSED ? GTK_SHADOW_IN : GTK_SHADOW_OUT, |
862d8041 RR |
534 | NULL, |
535 | button, | |
2209baae | 536 | "button", |
99c4be68 VZ |
537 | dc.LogicalToDeviceX(rect.x), |
538 | dc.LogicalToDeviceY(rect.y), | |
539 | rect.width, | |
e4131985 | 540 | rect.height |
862d8041 RR |
541 | ); |
542 | } | |
daebb44c | 543 | |
cdccdfab | 544 | void |
02f07b19 | 545 | wxRendererGTK::DrawItemSelectionRect(wxWindow* win, |
cdccdfab WS |
546 | wxDC& dc, |
547 | const wxRect& rect, | |
548 | int flags ) | |
daebb44c | 549 | { |
02f07b19 | 550 | GdkWindow* gdk_window = wxGetGdkWindowForDC(win, dc); |
2e992e06 VZ |
551 | wxASSERT_MSG( gdk_window, |
552 | wxT("cannot use wxRendererNative on wxDC of this type") ); | |
553 | ||
90b903c2 | 554 | if (flags & wxCONTROL_SELECTED) |
daebb44c | 555 | { |
c70ad287 VZ |
556 | int x_diff = 0; |
557 | if (win->GetLayoutDirection() == wxLayout_RightToLeft) | |
558 | x_diff = rect.width; | |
559 | ||
05d97538 RR |
560 | // the wxCONTROL_FOCUSED state is deduced |
561 | // directly from the m_wxwindow by GTK+ | |
c70ad287 | 562 | gtk_paint_flat_box(wxGTKPrivate::GetTreeWidget()->style, |
2e992e06 | 563 | gdk_window, |
c70ad287 | 564 | GTK_STATE_SELECTED, |
daebb44c | 565 | GTK_SHADOW_NONE, |
cdccdfab | 566 | NULL, |
daebb44c | 567 | win->m_wxwindow, |
05d97538 | 568 | "cell_even", |
08f57d21 | 569 | dc.LogicalToDeviceX(rect.x) - x_diff, |
daebb44c RR |
570 | dc.LogicalToDeviceY(rect.y), |
571 | rect.width, | |
572 | rect.height ); | |
573 | } | |
90b903c2 | 574 | |
ce0cf2b8 | 575 | if ((flags & wxCONTROL_CURRENT) && (flags & wxCONTROL_FOCUSED)) |
c70ad287 | 576 | DrawFocusRect(win, dc, rect, flags); |
daebb44c | 577 | } |
6d789987 JS |
578 | |
579 | void wxRendererGTK::DrawFocusRect(wxWindow* win, wxDC& dc, const wxRect& rect, int flags) | |
580 | { | |
02f07b19 | 581 | GdkWindow* gdk_window = wxGetGdkWindowForDC(win, dc); |
6d789987 JS |
582 | wxASSERT_MSG( gdk_window, |
583 | wxT("cannot use wxRendererNative on wxDC of this type") ); | |
584 | ||
585 | GtkStateType state; | |
586 | if (flags & wxCONTROL_SELECTED) | |
587 | state = GTK_STATE_SELECTED; | |
588 | else | |
589 | state = GTK_STATE_NORMAL; | |
590 | ||
591 | gtk_paint_focus( win->m_widget->style, | |
592 | gdk_window, | |
593 | state, | |
594 | NULL, | |
595 | win->m_wxwindow, | |
596 | NULL, | |
597 | dc.LogicalToDeviceX(rect.x), | |
598 | dc.LogicalToDeviceY(rect.y), | |
599 | rect.width, | |
600 | rect.height ); | |
601 | } | |
e4131985 KO |
602 | |
603 | // Uses the theme to draw the border and fill for something like a wxTextCtrl | |
02f07b19 | 604 | void wxRendererGTK::DrawTextCtrl(wxWindow* win, wxDC& dc, const wxRect& rect, int flags) |
e4131985 KO |
605 | { |
606 | GtkWidget *entry = wxGTKPrivate::GetTextEntryWidget(); | |
607 | ||
02f07b19 | 608 | GdkWindow* gdk_window = wxGetGdkWindowForDC(win, dc); |
e4131985 KO |
609 | |
610 | GtkStateType state = GTK_STATE_NORMAL; | |
611 | if ( flags & wxCONTROL_DISABLED ) | |
612 | state = GTK_STATE_INSENSITIVE; | |
99c4be68 | 613 | |
e4131985 KO |
614 | if (flags & wxCONTROL_CURRENT ) |
615 | GTK_WIDGET_SET_FLAGS( entry, GTK_HAS_FOCUS ); | |
616 | else | |
617 | GTK_WIDGET_UNSET_FLAGS( entry, GTK_HAS_FOCUS ); | |
618 | ||
619 | gtk_paint_shadow | |
620 | ( | |
99c4be68 | 621 | entry->style, |
e4131985 KO |
622 | gdk_window, |
623 | state, | |
624 | GTK_SHADOW_OUT, | |
625 | NULL, | |
626 | entry, | |
627 | "entry", | |
628 | dc.LogicalToDeviceX(rect.x), | |
629 | dc.LogicalToDeviceY(rect.y), | |
630 | rect.width, | |
99c4be68 | 631 | rect.height |
e4131985 KO |
632 | ); |
633 | } | |
634 | ||
4c51a665 | 635 | // Draw the equivalent of a wxComboBox |
02f07b19 | 636 | void wxRendererGTK::DrawComboBox(wxWindow* win, wxDC& dc, const wxRect& rect, int flags) |
e4131985 KO |
637 | { |
638 | GtkWidget *combo = wxGTKPrivate::GetComboBoxWidget(); | |
639 | ||
02f07b19 | 640 | GdkWindow* gdk_window = wxGetGdkWindowForDC(win, dc); |
e4131985 KO |
641 | |
642 | GtkStateType state = GTK_STATE_NORMAL; | |
643 | if ( flags & wxCONTROL_DISABLED ) | |
644 | state = GTK_STATE_INSENSITIVE; | |
99c4be68 | 645 | |
e4131985 KO |
646 | if (flags & wxCONTROL_CURRENT ) |
647 | GTK_WIDGET_SET_FLAGS( combo, GTK_HAS_FOCUS ); | |
648 | else | |
649 | GTK_WIDGET_UNSET_FLAGS( combo, GTK_HAS_FOCUS ); | |
650 | ||
651 | gtk_paint_shadow | |
652 | ( | |
99c4be68 | 653 | combo->style, |
e4131985 KO |
654 | gdk_window, |
655 | state, | |
656 | GTK_SHADOW_OUT, | |
657 | NULL, | |
658 | combo, | |
659 | "combobox", | |
660 | dc.LogicalToDeviceX(rect.x), | |
661 | dc.LogicalToDeviceY(rect.y), | |
662 | rect.width, | |
99c4be68 | 663 | rect.height |
e4131985 KO |
664 | ); |
665 | ||
666 | wxRect r = rect; | |
667 | int extent = rect.height / 2; | |
668 | r.x += rect.width - extent - extent/2; | |
669 | r.y += extent/2; | |
670 | r.width = extent; | |
671 | r.height = extent; | |
672 | ||
673 | gtk_paint_arrow | |
674 | ( | |
99c4be68 | 675 | combo->style, |
e4131985 KO |
676 | gdk_window, |
677 | state, | |
678 | GTK_SHADOW_OUT, | |
679 | NULL, | |
680 | combo, | |
681 | "arrow", | |
682 | GTK_ARROW_DOWN, | |
683 | TRUE, | |
684 | dc.LogicalToDeviceX(r.x), | |
685 | dc.LogicalToDeviceY(r.y), | |
686 | r.width, | |
687 | r.height | |
688 | ); | |
689 | ||
690 | r = rect; | |
691 | r.x += rect.width - 2*extent; | |
692 | r.width = 2; | |
693 | ||
694 | gtk_paint_box | |
695 | ( | |
99c4be68 | 696 | combo->style, |
e4131985 KO |
697 | gdk_window, |
698 | state, | |
699 | GTK_SHADOW_ETCHED_OUT, | |
700 | NULL, | |
701 | combo, | |
702 | "vseparator", | |
703 | dc.LogicalToDeviceX(r.x), | |
704 | dc.LogicalToDeviceY(r.y+1), | |
705 | r.width, | |
706 | r.height-2 | |
707 | ); | |
708 | } | |
709 | ||
710 | ||
711 | void wxRendererGTK::DrawChoice(wxWindow* win, wxDC& dc, | |
712 | const wxRect& rect, int flags) | |
713 | { | |
714 | DrawComboBox( win, dc, rect, flags ); | |
715 | } | |
716 | ||
99c4be68 | 717 | |
e4131985 | 718 | // Draw a themed radio button |
6e6b532c | 719 | void wxRendererGTK::DrawRadioBitmap(wxWindow* win, wxDC& dc, const wxRect& rect, int flags) |
e4131985 KO |
720 | { |
721 | GtkWidget *button = wxGTKPrivate::GetRadioButtonWidget(); | |
722 | ||
02f07b19 | 723 | GdkWindow* gdk_window = wxGetGdkWindowForDC(win, dc); |
99c4be68 | 724 | |
e4131985 KO |
725 | GtkShadowType shadow_type = GTK_SHADOW_OUT; |
726 | if ( flags & wxCONTROL_CHECKED ) | |
727 | shadow_type = GTK_SHADOW_IN; | |
728 | else if ( flags & wxCONTROL_UNDETERMINED ) | |
729 | shadow_type = GTK_SHADOW_ETCHED_IN; | |
99c4be68 | 730 | |
e4131985 KO |
731 | GtkStateType state = GTK_STATE_NORMAL; |
732 | if ( flags & wxCONTROL_DISABLED ) | |
7e717730 | 733 | state = GTK_STATE_INSENSITIVE; |
e4131985 | 734 | if ( flags & wxCONTROL_PRESSED ) |
7e717730 | 735 | state = GTK_STATE_ACTIVE; |
e4131985 KO |
736 | /* |
737 | Don't know when to set this | |
738 | state_type = GTK_STATE_PRELIGHT; | |
739 | */ | |
740 | ||
741 | gtk_paint_option | |
742 | ( | |
743 | button->style, | |
744 | gdk_window, | |
745 | state, | |
746 | shadow_type, | |
747 | NULL, | |
748 | button, | |
749 | "radiobutton", | |
99c4be68 VZ |
750 | dc.LogicalToDeviceX(rect.x), |
751 | dc.LogicalToDeviceY(rect.y), | |
e4131985 KO |
752 | rect.width, rect.height |
753 | ); | |
754 | } |