]>
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> | |
65571936 | 9 | // License: 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" |
cdccdfab WS |
33 | #endif |
34 | ||
9c7f49f5 | 35 | #include <gtk/gtk.h> |
9c7f49f5 | 36 | |
9c7f49f5 | 37 | // ---------------------------------------------------------------------------- |
38c4cb6a | 38 | // wxRendererGTK: our wxRendererNative implementation |
9c7f49f5 VZ |
39 | // ---------------------------------------------------------------------------- |
40 | ||
38c4cb6a | 41 | class WXDLLEXPORT wxRendererGTK : public wxDelegateRendererNative |
9c7f49f5 VZ |
42 | { |
43 | public: | |
44 | // draw the header control button (used by wxListCtrl) | |
c97c9952 | 45 | virtual int DrawHeaderButton(wxWindow *win, |
9c7f49f5 VZ |
46 | wxDC& dc, |
47 | const wxRect& rect, | |
4b94ddc4 | 48 | int flags = 0, |
80752b57 | 49 | wxHeaderSortIconType sortArrow = wxHDR_SORT_ICON_NONE, |
4b94ddc4 | 50 | wxHeaderButtonParams* params = NULL); |
9c7f49f5 | 51 | |
9c7f49f5 VZ |
52 | // draw the expanded/collapsed icon for a tree control item |
53 | virtual void DrawTreeItemButton(wxWindow *win, | |
54 | wxDC& dc, | |
55 | const wxRect& rect, | |
56 | int flags = 0); | |
9c7f49f5 | 57 | |
d16cf3cd VZ |
58 | virtual void DrawSplitterBorder(wxWindow *win, |
59 | wxDC& dc, | |
af99040c VZ |
60 | const wxRect& rect, |
61 | int flags = 0); | |
95155e75 VZ |
62 | virtual void DrawSplitterSash(wxWindow *win, |
63 | wxDC& dc, | |
64 | const wxSize& size, | |
d16cf3cd | 65 | wxCoord position, |
af99040c VZ |
66 | wxOrientation orient, |
67 | int flags = 0); | |
d16cf3cd | 68 | |
38511687 VZ |
69 | virtual void DrawComboBoxDropButton(wxWindow *win, |
70 | wxDC& dc, | |
71 | const wxRect& rect, | |
72 | int flags = 0); | |
73 | ||
4c85ab75 VZ |
74 | virtual void DrawDropArrow(wxWindow *win, |
75 | wxDC& dc, | |
76 | const wxRect& rect, | |
77 | int flags = 0); | |
78 | ||
90b903c2 WS |
79 | virtual void DrawCheckBox(wxWindow *win, |
80 | wxDC& dc, | |
81 | const wxRect& rect, | |
82 | int flags = 0); | |
2209baae RR |
83 | |
84 | virtual void DrawPushButton(wxWindow *win, | |
85 | wxDC& dc, | |
86 | const wxRect& rect, | |
87 | int flags = 0); | |
88 | ||
daebb44c RR |
89 | virtual void DrawItemSelectionRect(wxWindow *win, |
90 | wxDC& dc, | |
91 | const wxRect& rect, | |
92 | int flags = 0); | |
90b903c2 | 93 | |
6d789987 JS |
94 | virtual void DrawFocusRect(wxWindow* win, wxDC& dc, const wxRect& rect, int flags = 0); |
95 | ||
af99040c | 96 | virtual wxSplitterRenderParams GetSplitterParams(const wxWindow *win); |
e1befae3 VZ |
97 | |
98 | private: | |
bc13e772 VZ |
99 | // FIXME: shouldn't we destroy these windows somewhere? |
100 | ||
621ed8af | 101 | // used by DrawPushButton and DrawDropArrow |
bc13e772 VZ |
102 | static GtkWidget *GetButtonWidget(); |
103 | ||
bc13e772 VZ |
104 | // used by DrawTreeItemButton() |
105 | static GtkWidget *GetTreeWidget(); | |
90b903c2 WS |
106 | |
107 | // used by DrawCheckBox() | |
862d8041 | 108 | static GtkWidget *GetCheckButtonWidget(); |
621ed8af RD |
109 | |
110 | // Used by DrawHeaderButton | |
111 | static GtkWidget *GetHeaderButtonWidget(); | |
9c7f49f5 VZ |
112 | }; |
113 | ||
114 | // ============================================================================ | |
115 | // implementation | |
116 | // ============================================================================ | |
117 | ||
118 | /* static */ | |
f0244295 | 119 | wxRendererNative& wxRendererNative::GetDefault() |
9c7f49f5 VZ |
120 | { |
121 | static wxRendererGTK s_rendererGTK; | |
122 | ||
123 | return s_rendererGTK; | |
124 | } | |
125 | ||
a4622f29 | 126 | // ---------------------------------------------------------------------------- |
bc13e772 | 127 | // helper functions |
a4622f29 VZ |
128 | // ---------------------------------------------------------------------------- |
129 | ||
bc13e772 VZ |
130 | GtkWidget * |
131 | wxRendererGTK::GetButtonWidget() | |
132 | { | |
133 | static GtkWidget *s_button = NULL; | |
134 | static GtkWidget *s_window = NULL; | |
a4622f29 | 135 | |
bc13e772 VZ |
136 | if ( !s_button ) |
137 | { | |
138 | s_window = gtk_window_new( GTK_WINDOW_POPUP ); | |
139 | gtk_widget_realize( s_window ); | |
140 | s_button = gtk_button_new(); | |
141 | gtk_container_add( GTK_CONTAINER(s_window), s_button ); | |
142 | gtk_widget_realize( s_button ); | |
143 | } | |
144 | ||
145 | return s_button; | |
146 | } | |
147 | ||
862d8041 RR |
148 | GtkWidget * |
149 | wxRendererGTK::GetCheckButtonWidget() | |
150 | { | |
151 | static GtkWidget *s_button = NULL; | |
152 | static GtkWidget *s_window = NULL; | |
153 | ||
154 | if ( !s_button ) | |
155 | { | |
156 | s_window = gtk_window_new( GTK_WINDOW_POPUP ); | |
157 | gtk_widget_realize( s_window ); | |
158 | s_button = gtk_check_button_new(); | |
159 | gtk_container_add( GTK_CONTAINER(s_window), s_button ); | |
160 | gtk_widget_realize( s_button ); | |
161 | } | |
162 | ||
163 | return s_button; | |
164 | } | |
165 | ||
bc13e772 VZ |
166 | GtkWidget * |
167 | wxRendererGTK::GetTreeWidget() | |
a4622f29 | 168 | { |
bc13e772 VZ |
169 | static GtkWidget *s_tree = NULL; |
170 | static GtkWidget *s_window = NULL; | |
171 | ||
172 | if ( !s_tree ) | |
173 | { | |
174 | s_tree = gtk_tree_view_new(); | |
175 | s_window = gtk_window_new( GTK_WINDOW_POPUP ); | |
176 | gtk_widget_realize( s_window ); | |
177 | gtk_container_add( GTK_CONTAINER(s_window), s_tree ); | |
178 | gtk_widget_realize( s_tree ); | |
179 | } | |
180 | ||
181 | return s_tree; | |
a4622f29 VZ |
182 | } |
183 | ||
621ed8af | 184 | |
c7a757aa RD |
185 | // This one just gets the button used by the column header. Although it's |
186 | // still a gtk_button the themes will typically differentiate and draw them | |
187 | // differently if the button is in a treeview. | |
621ed8af RD |
188 | GtkWidget * |
189 | wxRendererGTK::GetHeaderButtonWidget() | |
190 | { | |
191 | static GtkWidget *s_button = NULL; | |
6d789987 | 192 | |
621ed8af RD |
193 | if ( !s_button ) |
194 | { | |
c7a757aa RD |
195 | // Get the dummy tree widget, give it a column, and then use the |
196 | // widget in the column header for the rendering code. | |
621ed8af | 197 | GtkWidget* treewidget = GetTreeWidget(); |
c7a757aa RD |
198 | GtkTreeViewColumn* column = gtk_tree_view_column_new(); |
199 | gtk_tree_view_append_column(GTK_TREE_VIEW(treewidget), column); | |
200 | s_button = column->button; | |
621ed8af RD |
201 | } |
202 | ||
203 | return s_button; | |
204 | } | |
205 | ||
d16cf3cd VZ |
206 | // ---------------------------------------------------------------------------- |
207 | // list/tree controls drawing | |
208 | // ---------------------------------------------------------------------------- | |
209 | ||
c97c9952 | 210 | int |
9c7f49f5 VZ |
211 | wxRendererGTK::DrawHeaderButton(wxWindow *win, |
212 | wxDC& dc, | |
213 | const wxRect& rect, | |
4b94ddc4 | 214 | int flags, |
80752b57 | 215 | wxHeaderSortIconType sortArrow, |
4b94ddc4 | 216 | wxHeaderButtonParams* params) |
9c7f49f5 | 217 | { |
9b311923 | 218 | |
621ed8af | 219 | GtkWidget *button = GetHeaderButtonWidget(); |
ab171e95 RR |
220 | |
221 | GdkWindow* gdk_window = NULL; | |
222 | #if wxUSE_NEW_DC | |
223 | wxImplDC *impl = dc.GetImpl(); | |
224 | wxGTKImplDC *gtk_impl = wxDynamicCast( impl, wxGTKImplDC ); | |
225 | if (gtk_impl) | |
226 | gdk_window = gtk_impl->GetGDKWindow(); | |
227 | #else | |
228 | gdk_window = dc.GetGDKWindow(); | |
229 | #endif | |
2e992e06 VZ |
230 | wxASSERT_MSG( gdk_window, |
231 | wxT("cannot use wxRendererNative on wxDC of this type") ); | |
232 | ||
5eefe029 RR |
233 | int x_diff = 0; |
234 | if (win->GetLayoutDirection() == wxLayout_RightToLeft) | |
235 | x_diff = rect.width; | |
f4322df6 | 236 | |
1cfc4971 RR |
237 | GtkStateType state = GTK_STATE_NORMAL; |
238 | if (flags & wxCONTROL_DISABLED) | |
239 | state = GTK_STATE_INSENSITIVE; | |
240 | else | |
241 | { | |
242 | if (flags & wxCONTROL_CURRENT) | |
243 | state = GTK_STATE_PRELIGHT; | |
244 | } | |
245 | ||
9c7f49f5 VZ |
246 | gtk_paint_box |
247 | ( | |
bc13e772 | 248 | button->style, |
2e992e06 | 249 | gdk_window, |
1cfc4971 | 250 | state, |
9c7f49f5 | 251 | GTK_SHADOW_OUT, |
38511687 | 252 | NULL, |
bc13e772 | 253 | button, |
9b311923 | 254 | "button", |
5eefe029 | 255 | dc.LogicalToDeviceX(rect.x) - x_diff, rect.y, rect.width, rect.height |
9c7f49f5 | 256 | ); |
4b94ddc4 | 257 | |
c97c9952 | 258 | return DrawHeaderButtonContents(win, dc, rect, flags, sortArrow, params); |
9c7f49f5 VZ |
259 | } |
260 | ||
9c7f49f5 | 261 | // draw a ">" or "v" button |
9c7f49f5 | 262 | void |
f8b043e7 | 263 | wxRendererGTK::DrawTreeItemButton(wxWindow* win, |
9a0b7e33 | 264 | wxDC& dc, const wxRect& rect, int flags) |
9c7f49f5 | 265 | { |
bc13e772 | 266 | GtkWidget *tree = GetTreeWidget(); |
f8b043e7 | 267 | |
ab171e95 RR |
268 | GdkWindow* gdk_window = NULL; |
269 | #if wxUSE_NEW_DC | |
270 | wxImplDC *impl = dc.GetImpl(); | |
271 | wxGTKImplDC *gtk_impl = wxDynamicCast( impl, wxGTKImplDC ); | |
272 | if (gtk_impl) | |
273 | gdk_window = gtk_impl->GetGDKWindow(); | |
274 | #else | |
275 | gdk_window = dc.GetGDKWindow(); | |
276 | #endif | |
2e992e06 VZ |
277 | wxASSERT_MSG( gdk_window, |
278 | wxT("cannot use wxRendererNative on wxDC of this type") ); | |
279 | ||
885dd597 RR |
280 | GtkStateType state; |
281 | if ( flags & wxCONTROL_CURRENT ) | |
282 | state = GTK_STATE_PRELIGHT; | |
283 | else | |
284 | state = GTK_STATE_NORMAL; | |
91af0895 | 285 | |
428f4657 RR |
286 | int x_diff = 0; |
287 | if (win->GetLayoutDirection() == wxLayout_RightToLeft) | |
288 | x_diff = rect.width; | |
2e992e06 | 289 | |
bc13e772 VZ |
290 | // VZ: I don't know how to get the size of the expander so as to centre it |
291 | // in the given rectangle, +2/3 below is just what looks good here... | |
292 | gtk_paint_expander | |
293 | ( | |
294 | tree->style, | |
2e992e06 | 295 | gdk_window, |
885dd597 | 296 | state, |
bc13e772 VZ |
297 | NULL, |
298 | tree, | |
299 | "treeview", | |
11012f47 | 300 | dc.LogicalToDeviceX(rect.x) + 6 - x_diff, |
bc13e772 VZ |
301 | dc.LogicalToDeviceY(rect.y) + 3, |
302 | flags & wxCONTROL_EXPANDED ? GTK_EXPANDER_EXPANDED | |
303 | : GTK_EXPANDER_COLLAPSED | |
304 | ); | |
9c7f49f5 VZ |
305 | } |
306 | ||
9c7f49f5 | 307 | |
d16cf3cd VZ |
308 | // ---------------------------------------------------------------------------- |
309 | // splitter sash drawing | |
310 | // ---------------------------------------------------------------------------- | |
311 | ||
38418827 RR |
312 | static int GetGtkSplitterFullSize() |
313 | { | |
38418827 RR |
314 | static GtkWidget *s_paned = NULL; |
315 | if (s_paned == NULL) | |
316 | s_paned = gtk_vpaned_new(); | |
317 | ||
318 | gint handle_size; | |
319 | gtk_widget_style_get (s_paned, "handle_size", &handle_size, NULL); | |
91af0895 | 320 | |
38418827 | 321 | return handle_size; |
38418827 RR |
322 | } |
323 | ||
af99040c | 324 | wxSplitterRenderParams |
38418827 | 325 | wxRendererGTK::GetSplitterParams(const wxWindow *WXUNUSED(win)) |
d16cf3cd | 326 | { |
af99040c VZ |
327 | // we don't draw any border, hence 0 for the second field |
328 | return wxSplitterRenderParams | |
329 | ( | |
38418827 | 330 | GetGtkSplitterFullSize(), |
af99040c | 331 | 0, |
af99040c | 332 | true // hot sensitive |
af99040c | 333 | ); |
d16cf3cd VZ |
334 | } |
335 | ||
336 | void | |
337 | wxRendererGTK::DrawSplitterBorder(wxWindow * WXUNUSED(win), | |
338 | wxDC& WXUNUSED(dc), | |
af99040c VZ |
339 | const wxRect& WXUNUSED(rect), |
340 | int WXUNUSED(flags)) | |
d16cf3cd VZ |
341 | { |
342 | // nothing to do | |
343 | } | |
95155e75 | 344 | |
95155e75 VZ |
345 | void |
346 | wxRendererGTK::DrawSplitterSash(wxWindow *win, | |
347 | wxDC& dc, | |
348 | const wxSize& size, | |
d16cf3cd | 349 | wxCoord position, |
af99040c | 350 | wxOrientation orient, |
68567a96 | 351 | int flags) |
95155e75 VZ |
352 | { |
353 | if ( !win->m_wxwindow->window ) | |
354 | { | |
0100b858 | 355 | // window not realized yet |
95155e75 VZ |
356 | return; |
357 | } | |
91af0895 | 358 | |
ab171e95 RR |
359 | GdkWindow* gdk_window = NULL; |
360 | #if wxUSE_NEW_DC | |
361 | wxImplDC *impl = dc.GetImpl(); | |
362 | wxGTKImplDC *gtk_impl = wxDynamicCast( impl, wxGTKImplDC ); | |
363 | if (gtk_impl) | |
364 | gdk_window = gtk_impl->GetGDKWindow(); | |
365 | #else | |
366 | gdk_window = dc.GetGDKWindow(); | |
367 | #endif | |
2e992e06 VZ |
368 | wxASSERT_MSG( gdk_window, |
369 | wxT("cannot use wxRendererNative on wxDC of this type") ); | |
370 | ||
38418827 | 371 | wxCoord full_size = GetGtkSplitterFullSize(); |
95155e75 | 372 | |
d16cf3cd VZ |
373 | // are we drawing vertical or horizontal splitter? |
374 | const bool isVert = orient == wxVERTICAL; | |
375 | ||
d16cf3cd | 376 | GdkRectangle rect; |
91af0895 | 377 | |
d16cf3cd VZ |
378 | if ( isVert ) |
379 | { | |
380 | rect.x = position; | |
0100b858 | 381 | rect.y = 0; |
38418827 | 382 | rect.width = full_size; |
e4161a2a | 383 | rect.height = size.y; |
d16cf3cd VZ |
384 | } |
385 | else // horz | |
386 | { | |
0100b858 | 387 | rect.x = 0; |
d16cf3cd | 388 | rect.y = position; |
38418827 | 389 | rect.height = full_size; |
e4161a2a | 390 | rect.width = size.x; |
d16cf3cd | 391 | } |
f4322df6 | 392 | |
847dfdb4 RR |
393 | int x_diff = 0; |
394 | if (win->GetLayoutDirection() == wxLayout_RightToLeft) | |
395 | x_diff = rect.width; | |
35468934 | 396 | |
af99040c VZ |
397 | gtk_paint_handle |
398 | ( | |
399 | win->m_wxwindow->style, | |
2e992e06 | 400 | gdk_window, |
af99040c VZ |
401 | flags & wxCONTROL_CURRENT ? GTK_STATE_PRELIGHT : GTK_STATE_NORMAL, |
402 | GTK_SHADOW_NONE, | |
403 | NULL /* no clipping */, | |
404 | win->m_wxwindow, | |
405 | "paned", | |
847dfdb4 RR |
406 | dc.LogicalToDeviceX(rect.x) - x_diff, |
407 | dc.LogicalToDeviceY(rect.y), | |
af99040c VZ |
408 | rect.width, |
409 | rect.height, | |
38418827 | 410 | isVert ? GTK_ORIENTATION_VERTICAL : GTK_ORIENTATION_HORIZONTAL |
af99040c | 411 | ); |
95155e75 VZ |
412 | } |
413 | ||
4c85ab75 | 414 | void |
2e992e06 | 415 | wxRendererGTK::DrawDropArrow(wxWindow *WXUNUSED(win), |
4c85ab75 VZ |
416 | wxDC& dc, |
417 | const wxRect& rect, | |
418 | int flags) | |
38511687 | 419 | { |
bc13e772 | 420 | GtkWidget *button = GetButtonWidget(); |
38511687 | 421 | |
4c85ab75 VZ |
422 | // If we give GTK_PIZZA(win->m_wxwindow)->bin_window as |
423 | // a window for gtk_paint_xxx function, then it won't | |
424 | // work for wxMemoryDC. So that is why we assume wxDC | |
425 | // is wxWindowDC (wxClientDC, wxMemoryDC and wxPaintDC | |
426 | // are derived from it) and use its m_window. | |
ab171e95 RR |
427 | GdkWindow* gdk_window = NULL; |
428 | #if wxUSE_NEW_DC | |
429 | wxImplDC *impl = dc.GetImpl(); | |
430 | wxGTKImplDC *gtk_impl = wxDynamicCast( impl, wxGTKImplDC ); | |
431 | if (gtk_impl) | |
432 | gdk_window = gtk_impl->GetGDKWindow(); | |
433 | #else | |
434 | gdk_window = dc.GetGDKWindow(); | |
435 | #endif | |
2e992e06 VZ |
436 | wxASSERT_MSG( gdk_window, |
437 | wxT("cannot use wxRendererNative on wxDC of this type") ); | |
a4622f29 | 438 | |
4c85ab75 VZ |
439 | // draw arrow so that there is even space horizontally |
440 | // on both sides | |
441 | int arrowX = rect.width/4 + 1; | |
442 | int arrowWidth = rect.width - (arrowX*2); | |
443 | ||
444 | // scale arrow's height accoording to the width | |
445 | int arrowHeight = rect.width/3; | |
446 | int arrowY = (rect.height-arrowHeight)/2 + | |
447 | ((rect.height-arrowHeight) & 1); | |
448 | ||
e1befae3 | 449 | GtkStateType state; |
a4622f29 | 450 | |
3203621a JS |
451 | if ( flags & wxCONTROL_PRESSED ) |
452 | state = GTK_STATE_ACTIVE; | |
a4622f29 VZ |
453 | else if ( flags & wxCONTROL_DISABLED ) |
454 | state = GTK_STATE_INSENSITIVE; | |
3203621a JS |
455 | else if ( flags & wxCONTROL_CURRENT ) |
456 | state = GTK_STATE_PRELIGHT; | |
e1befae3 VZ |
457 | else |
458 | state = GTK_STATE_NORMAL; | |
a4622f29 | 459 | |
a4622f29 | 460 | // draw arrow on button |
a4622f29 VZ |
461 | gtk_paint_arrow |
462 | ( | |
bc13e772 | 463 | button->style, |
2e992e06 | 464 | gdk_window, |
a4622f29 | 465 | state, |
e1befae3 | 466 | flags & wxCONTROL_PRESSED ? GTK_SHADOW_IN : GTK_SHADOW_OUT, |
a4622f29 | 467 | NULL, |
bc13e772 | 468 | button, |
a4622f29 VZ |
469 | "arrow", |
470 | GTK_ARROW_DOWN, | |
a8ac548e | 471 | FALSE, |
4c85ab75 VZ |
472 | rect.x + arrowX, |
473 | rect.y + arrowY, | |
474 | arrowWidth, | |
475 | arrowHeight | |
a4622f29 | 476 | ); |
38511687 VZ |
477 | } |
478 | ||
4c85ab75 VZ |
479 | void |
480 | wxRendererGTK::DrawComboBoxDropButton(wxWindow *win, | |
481 | wxDC& dc, | |
482 | const wxRect& rect, | |
483 | int flags) | |
484 | { | |
2209baae RR |
485 | DrawPushButton(win,dc,rect,flags); |
486 | DrawDropArrow(win,dc,rect); | |
487 | } | |
488 | ||
cdccdfab | 489 | void |
2e992e06 | 490 | wxRendererGTK::DrawCheckBox(wxWindow *WXUNUSED(win), |
90b903c2 WS |
491 | wxDC& dc, |
492 | const wxRect& rect, | |
493 | int flags ) | |
2209baae RR |
494 | { |
495 | GtkWidget *button = GetCheckButtonWidget(); | |
ab171e95 RR |
496 | |
497 | GdkWindow* gdk_window = NULL; | |
498 | #if wxUSE_NEW_DC | |
499 | wxImplDC *impl = dc.GetImpl(); | |
500 | wxGTKImplDC *gtk_impl = wxDynamicCast( impl, wxGTKImplDC ); | |
501 | if (gtk_impl) | |
502 | gdk_window = gtk_impl->GetGDKWindow(); | |
503 | #else | |
504 | gdk_window = dc.GetGDKWindow(); | |
505 | #endif | |
2e992e06 VZ |
506 | wxASSERT_MSG( gdk_window, |
507 | wxT("cannot use wxRendererNative on wxDC of this type") ); | |
90b903c2 | 508 | |
4c85ab75 VZ |
509 | GtkStateType state; |
510 | ||
3203621a JS |
511 | if ( flags & wxCONTROL_PRESSED ) |
512 | state = GTK_STATE_ACTIVE; | |
4c85ab75 VZ |
513 | else if ( flags & wxCONTROL_DISABLED ) |
514 | state = GTK_STATE_INSENSITIVE; | |
3203621a JS |
515 | else if ( flags & wxCONTROL_CURRENT ) |
516 | state = GTK_STATE_PRELIGHT; | |
4c85ab75 VZ |
517 | else |
518 | state = GTK_STATE_NORMAL; | |
90b903c2 | 519 | |
2209baae | 520 | gtk_paint_check |
4c85ab75 VZ |
521 | ( |
522 | button->style, | |
2e992e06 | 523 | gdk_window, |
4c85ab75 | 524 | state, |
2209baae | 525 | flags & wxCONTROL_CHECKED ? GTK_SHADOW_IN : GTK_SHADOW_OUT, |
4c85ab75 VZ |
526 | NULL, |
527 | button, | |
2209baae | 528 | "cellcheck", |
cdccdfab WS |
529 | dc.LogicalToDeviceX(rect.x)+2, |
530 | dc.LogicalToDeviceY(rect.y)+3, | |
506d54a3 | 531 | 13, 13 |
4c85ab75 | 532 | ); |
4c85ab75 VZ |
533 | } |
534 | ||
2209baae | 535 | void |
2e992e06 | 536 | wxRendererGTK::DrawPushButton(wxWindow *WXUNUSED(win), |
2209baae RR |
537 | wxDC& dc, |
538 | const wxRect& rect, | |
539 | int flags) | |
862d8041 | 540 | { |
2209baae | 541 | GtkWidget *button = GetButtonWidget(); |
862d8041 | 542 | |
ab171e95 RR |
543 | GdkWindow* gdk_window = NULL; |
544 | #if wxUSE_NEW_DC | |
545 | wxImplDC *impl = dc.GetImpl(); | |
546 | wxGTKImplDC *gtk_impl = wxDynamicCast( impl, wxGTKImplDC ); | |
547 | if (gtk_impl) | |
548 | gdk_window = gtk_impl->GetGDKWindow(); | |
549 | #else | |
550 | gdk_window = dc.GetGDKWindow(); | |
551 | #endif | |
2e992e06 VZ |
552 | wxASSERT_MSG( gdk_window, |
553 | wxT("cannot use wxRendererNative on wxDC of this type") ); | |
2209baae RR |
554 | |
555 | // draw button | |
862d8041 RR |
556 | GtkStateType state; |
557 | ||
558 | if ( flags & wxCONTROL_PRESSED ) | |
559 | state = GTK_STATE_ACTIVE; | |
560 | else if ( flags & wxCONTROL_DISABLED ) | |
561 | state = GTK_STATE_INSENSITIVE; | |
562 | else if ( flags & wxCONTROL_CURRENT ) | |
563 | state = GTK_STATE_PRELIGHT; | |
564 | else | |
565 | state = GTK_STATE_NORMAL; | |
2209baae RR |
566 | |
567 | gtk_paint_box | |
862d8041 RR |
568 | ( |
569 | button->style, | |
2e992e06 | 570 | gdk_window, |
862d8041 | 571 | state, |
2209baae | 572 | flags & wxCONTROL_PRESSED ? GTK_SHADOW_IN : GTK_SHADOW_OUT, |
862d8041 RR |
573 | NULL, |
574 | button, | |
2209baae RR |
575 | "button", |
576 | rect.x, rect.y, rect.width, rect.height | |
862d8041 RR |
577 | ); |
578 | } | |
daebb44c | 579 | |
cdccdfab | 580 | void |
daebb44c | 581 | wxRendererGTK::DrawItemSelectionRect(wxWindow *win, |
cdccdfab WS |
582 | wxDC& dc, |
583 | const wxRect& rect, | |
584 | int flags ) | |
daebb44c | 585 | { |
ab171e95 RR |
586 | GdkWindow* gdk_window = NULL; |
587 | #if wxUSE_NEW_DC | |
588 | wxImplDC *impl = dc.GetImpl(); | |
589 | wxGTKImplDC *gtk_impl = wxDynamicCast( impl, wxGTKImplDC ); | |
590 | if (gtk_impl) | |
591 | gdk_window = gtk_impl->GetGDKWindow(); | |
592 | #else | |
593 | gdk_window = dc.GetGDKWindow(); | |
594 | #endif | |
2e992e06 VZ |
595 | wxASSERT_MSG( gdk_window, |
596 | wxT("cannot use wxRendererNative on wxDC of this type") ); | |
597 | ||
08f57d21 RR |
598 | int x_diff = 0; |
599 | if (win->GetLayoutDirection() == wxLayout_RightToLeft) | |
600 | x_diff = rect.width; | |
601 | ||
daebb44c | 602 | GtkStateType state; |
90b903c2 | 603 | if (flags & wxCONTROL_SELECTED) |
daebb44c | 604 | { |
05d97538 RR |
605 | // the wxCONTROL_FOCUSED state is deduced |
606 | // directly from the m_wxwindow by GTK+ | |
607 | state = GTK_STATE_SELECTED; | |
daebb44c | 608 | |
05d97538 | 609 | gtk_paint_flat_box( win->m_widget->style, |
2e992e06 | 610 | gdk_window, |
daebb44c RR |
611 | state, |
612 | GTK_SHADOW_NONE, | |
cdccdfab | 613 | NULL, |
daebb44c | 614 | win->m_wxwindow, |
05d97538 | 615 | "cell_even", |
08f57d21 | 616 | dc.LogicalToDeviceX(rect.x) - x_diff, |
daebb44c RR |
617 | dc.LogicalToDeviceY(rect.y), |
618 | rect.width, | |
619 | rect.height ); | |
620 | } | |
72be9a3a VZ |
621 | else // !wxCONTROL_SELECTED |
622 | { | |
623 | state = GTK_STATE_NORMAL; | |
624 | } | |
90b903c2 | 625 | |
ce0cf2b8 | 626 | if ((flags & wxCONTROL_CURRENT) && (flags & wxCONTROL_FOCUSED)) |
daebb44c | 627 | { |
f4322df6 | 628 | gtk_paint_focus( win->m_widget->style, |
05d97538 | 629 | gdk_window, |
72be9a3a | 630 | state, |
05d97538 RR |
631 | NULL, |
632 | win->m_wxwindow, | |
633 | "treeview", | |
634 | dc.LogicalToDeviceX(rect.x), | |
635 | dc.LogicalToDeviceY(rect.y), | |
636 | rect.width, | |
637 | rect.height ); | |
daebb44c RR |
638 | } |
639 | } | |
6d789987 JS |
640 | |
641 | void wxRendererGTK::DrawFocusRect(wxWindow* win, wxDC& dc, const wxRect& rect, int flags) | |
642 | { | |
ab171e95 RR |
643 | GdkWindow* gdk_window = NULL; |
644 | #if wxUSE_NEW_DC | |
645 | wxImplDC *impl = dc.GetImpl(); | |
646 | wxGTKImplDC *gtk_impl = wxDynamicCast( impl, wxGTKImplDC ); | |
647 | if (gtk_impl) | |
648 | gdk_window = gtk_impl->GetGDKWindow(); | |
649 | #else | |
650 | gdk_window = dc.GetGDKWindow(); | |
651 | #endif | |
6d789987 JS |
652 | wxASSERT_MSG( gdk_window, |
653 | wxT("cannot use wxRendererNative on wxDC of this type") ); | |
654 | ||
655 | GtkStateType state; | |
656 | if (flags & wxCONTROL_SELECTED) | |
657 | state = GTK_STATE_SELECTED; | |
658 | else | |
659 | state = GTK_STATE_NORMAL; | |
660 | ||
661 | gtk_paint_focus( win->m_widget->style, | |
662 | gdk_window, | |
663 | state, | |
664 | NULL, | |
665 | win->m_wxwindow, | |
666 | NULL, | |
667 | dc.LogicalToDeviceX(rect.x), | |
668 | dc.LogicalToDeviceY(rect.y), | |
669 | rect.width, | |
670 | rect.height ); | |
671 | } |