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