]>
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 | ||
6de67633 RR |
184 | // used elsewhere |
185 | GtkWidget *GetEntryWidget() | |
186 | { | |
187 | static GtkWidget *s_entry = NULL; | |
188 | static GtkWidget *s_window = NULL; | |
189 | ||
190 | if ( !s_entry ) | |
191 | { | |
192 | s_window = gtk_window_new( GTK_WINDOW_POPUP ); | |
193 | gtk_widget_realize( s_window ); | |
194 | s_entry = gtk_entry_new(); | |
195 | gtk_container_add( GTK_CONTAINER(s_window), s_entry ); | |
196 | gtk_widget_realize( s_entry ); | |
197 | } | |
198 | ||
199 | return s_entry; | |
200 | } | |
201 | ||
202 | // used elsewhere | |
203 | GtkWidget *GetScrolledWidget() | |
204 | { | |
205 | static GtkWidget *s_entry = NULL; | |
206 | static GtkWidget *s_window = NULL; | |
207 | ||
208 | if ( !s_entry ) | |
209 | { | |
210 | s_window = gtk_window_new( GTK_WINDOW_POPUP ); | |
211 | gtk_widget_realize( s_window ); | |
212 | s_entry = gtk_scrolled_window_new( NULL, NULL); | |
213 | gtk_container_add( GTK_CONTAINER(s_window), s_entry ); | |
214 | gtk_widget_realize( s_entry ); | |
215 | } | |
216 | ||
217 | return s_entry; | |
218 | } | |
621ed8af | 219 | |
c7a757aa RD |
220 | // This one just gets the button used by the column header. Although it's |
221 | // still a gtk_button the themes will typically differentiate and draw them | |
222 | // differently if the button is in a treeview. | |
621ed8af RD |
223 | GtkWidget * |
224 | wxRendererGTK::GetHeaderButtonWidget() | |
225 | { | |
226 | static GtkWidget *s_button = NULL; | |
6d789987 | 227 | |
621ed8af RD |
228 | if ( !s_button ) |
229 | { | |
c7a757aa RD |
230 | // Get the dummy tree widget, give it a column, and then use the |
231 | // widget in the column header for the rendering code. | |
621ed8af | 232 | GtkWidget* treewidget = GetTreeWidget(); |
c7a757aa RD |
233 | GtkTreeViewColumn* column = gtk_tree_view_column_new(); |
234 | gtk_tree_view_append_column(GTK_TREE_VIEW(treewidget), column); | |
235 | s_button = column->button; | |
621ed8af RD |
236 | } |
237 | ||
238 | return s_button; | |
239 | } | |
240 | ||
d16cf3cd VZ |
241 | // ---------------------------------------------------------------------------- |
242 | // list/tree controls drawing | |
243 | // ---------------------------------------------------------------------------- | |
244 | ||
c97c9952 | 245 | int |
9c7f49f5 VZ |
246 | wxRendererGTK::DrawHeaderButton(wxWindow *win, |
247 | wxDC& dc, | |
248 | const wxRect& rect, | |
4b94ddc4 | 249 | int flags, |
80752b57 | 250 | wxHeaderSortIconType sortArrow, |
4b94ddc4 | 251 | wxHeaderButtonParams* params) |
9c7f49f5 | 252 | { |
9b311923 | 253 | |
621ed8af | 254 | GtkWidget *button = GetHeaderButtonWidget(); |
ab171e95 RR |
255 | |
256 | GdkWindow* gdk_window = NULL; | |
257 | #if wxUSE_NEW_DC | |
258 | wxImplDC *impl = dc.GetImpl(); | |
259 | wxGTKImplDC *gtk_impl = wxDynamicCast( impl, wxGTKImplDC ); | |
260 | if (gtk_impl) | |
261 | gdk_window = gtk_impl->GetGDKWindow(); | |
262 | #else | |
263 | gdk_window = dc.GetGDKWindow(); | |
264 | #endif | |
2e992e06 VZ |
265 | wxASSERT_MSG( gdk_window, |
266 | wxT("cannot use wxRendererNative on wxDC of this type") ); | |
267 | ||
5eefe029 RR |
268 | int x_diff = 0; |
269 | if (win->GetLayoutDirection() == wxLayout_RightToLeft) | |
270 | x_diff = rect.width; | |
f4322df6 | 271 | |
1cfc4971 RR |
272 | GtkStateType state = GTK_STATE_NORMAL; |
273 | if (flags & wxCONTROL_DISABLED) | |
274 | state = GTK_STATE_INSENSITIVE; | |
275 | else | |
276 | { | |
277 | if (flags & wxCONTROL_CURRENT) | |
278 | state = GTK_STATE_PRELIGHT; | |
279 | } | |
280 | ||
9c7f49f5 VZ |
281 | gtk_paint_box |
282 | ( | |
bc13e772 | 283 | button->style, |
2e992e06 | 284 | gdk_window, |
1cfc4971 | 285 | state, |
9c7f49f5 | 286 | GTK_SHADOW_OUT, |
38511687 | 287 | NULL, |
bc13e772 | 288 | button, |
9b311923 | 289 | "button", |
5eefe029 | 290 | dc.LogicalToDeviceX(rect.x) - x_diff, rect.y, rect.width, rect.height |
9c7f49f5 | 291 | ); |
4b94ddc4 | 292 | |
c97c9952 | 293 | return DrawHeaderButtonContents(win, dc, rect, flags, sortArrow, params); |
9c7f49f5 VZ |
294 | } |
295 | ||
9c7f49f5 | 296 | // draw a ">" or "v" button |
9c7f49f5 | 297 | void |
f8b043e7 | 298 | wxRendererGTK::DrawTreeItemButton(wxWindow* win, |
9a0b7e33 | 299 | wxDC& dc, const wxRect& rect, int flags) |
9c7f49f5 | 300 | { |
bc13e772 | 301 | GtkWidget *tree = GetTreeWidget(); |
f8b043e7 | 302 | |
ab171e95 RR |
303 | GdkWindow* gdk_window = NULL; |
304 | #if wxUSE_NEW_DC | |
305 | wxImplDC *impl = dc.GetImpl(); | |
306 | wxGTKImplDC *gtk_impl = wxDynamicCast( impl, wxGTKImplDC ); | |
307 | if (gtk_impl) | |
308 | gdk_window = gtk_impl->GetGDKWindow(); | |
309 | #else | |
310 | gdk_window = dc.GetGDKWindow(); | |
311 | #endif | |
2e992e06 VZ |
312 | wxASSERT_MSG( gdk_window, |
313 | wxT("cannot use wxRendererNative on wxDC of this type") ); | |
314 | ||
885dd597 RR |
315 | GtkStateType state; |
316 | if ( flags & wxCONTROL_CURRENT ) | |
317 | state = GTK_STATE_PRELIGHT; | |
318 | else | |
319 | state = GTK_STATE_NORMAL; | |
91af0895 | 320 | |
428f4657 RR |
321 | int x_diff = 0; |
322 | if (win->GetLayoutDirection() == wxLayout_RightToLeft) | |
323 | x_diff = rect.width; | |
2e992e06 | 324 | |
bc13e772 VZ |
325 | // VZ: I don't know how to get the size of the expander so as to centre it |
326 | // in the given rectangle, +2/3 below is just what looks good here... | |
327 | gtk_paint_expander | |
328 | ( | |
329 | tree->style, | |
2e992e06 | 330 | gdk_window, |
885dd597 | 331 | state, |
bc13e772 VZ |
332 | NULL, |
333 | tree, | |
334 | "treeview", | |
11012f47 | 335 | dc.LogicalToDeviceX(rect.x) + 6 - x_diff, |
bc13e772 VZ |
336 | dc.LogicalToDeviceY(rect.y) + 3, |
337 | flags & wxCONTROL_EXPANDED ? GTK_EXPANDER_EXPANDED | |
338 | : GTK_EXPANDER_COLLAPSED | |
339 | ); | |
9c7f49f5 VZ |
340 | } |
341 | ||
9c7f49f5 | 342 | |
d16cf3cd VZ |
343 | // ---------------------------------------------------------------------------- |
344 | // splitter sash drawing | |
345 | // ---------------------------------------------------------------------------- | |
346 | ||
38418827 RR |
347 | static int GetGtkSplitterFullSize() |
348 | { | |
38418827 RR |
349 | static GtkWidget *s_paned = NULL; |
350 | if (s_paned == NULL) | |
351 | s_paned = gtk_vpaned_new(); | |
352 | ||
353 | gint handle_size; | |
354 | gtk_widget_style_get (s_paned, "handle_size", &handle_size, NULL); | |
91af0895 | 355 | |
38418827 | 356 | return handle_size; |
38418827 RR |
357 | } |
358 | ||
af99040c | 359 | wxSplitterRenderParams |
38418827 | 360 | wxRendererGTK::GetSplitterParams(const wxWindow *WXUNUSED(win)) |
d16cf3cd | 361 | { |
af99040c VZ |
362 | // we don't draw any border, hence 0 for the second field |
363 | return wxSplitterRenderParams | |
364 | ( | |
38418827 | 365 | GetGtkSplitterFullSize(), |
af99040c | 366 | 0, |
af99040c | 367 | true // hot sensitive |
af99040c | 368 | ); |
d16cf3cd VZ |
369 | } |
370 | ||
371 | void | |
372 | wxRendererGTK::DrawSplitterBorder(wxWindow * WXUNUSED(win), | |
373 | wxDC& WXUNUSED(dc), | |
af99040c VZ |
374 | const wxRect& WXUNUSED(rect), |
375 | int WXUNUSED(flags)) | |
d16cf3cd VZ |
376 | { |
377 | // nothing to do | |
378 | } | |
95155e75 | 379 | |
95155e75 VZ |
380 | void |
381 | wxRendererGTK::DrawSplitterSash(wxWindow *win, | |
382 | wxDC& dc, | |
383 | const wxSize& size, | |
d16cf3cd | 384 | wxCoord position, |
af99040c | 385 | wxOrientation orient, |
68567a96 | 386 | int flags) |
95155e75 VZ |
387 | { |
388 | if ( !win->m_wxwindow->window ) | |
389 | { | |
0100b858 | 390 | // window not realized yet |
95155e75 VZ |
391 | return; |
392 | } | |
91af0895 | 393 | |
ab171e95 RR |
394 | GdkWindow* gdk_window = NULL; |
395 | #if wxUSE_NEW_DC | |
396 | wxImplDC *impl = dc.GetImpl(); | |
397 | wxGTKImplDC *gtk_impl = wxDynamicCast( impl, wxGTKImplDC ); | |
398 | if (gtk_impl) | |
399 | gdk_window = gtk_impl->GetGDKWindow(); | |
400 | #else | |
401 | gdk_window = dc.GetGDKWindow(); | |
402 | #endif | |
2e992e06 VZ |
403 | wxASSERT_MSG( gdk_window, |
404 | wxT("cannot use wxRendererNative on wxDC of this type") ); | |
405 | ||
38418827 | 406 | wxCoord full_size = GetGtkSplitterFullSize(); |
95155e75 | 407 | |
d16cf3cd VZ |
408 | // are we drawing vertical or horizontal splitter? |
409 | const bool isVert = orient == wxVERTICAL; | |
410 | ||
d16cf3cd | 411 | GdkRectangle rect; |
91af0895 | 412 | |
d16cf3cd VZ |
413 | if ( isVert ) |
414 | { | |
415 | rect.x = position; | |
0100b858 | 416 | rect.y = 0; |
38418827 | 417 | rect.width = full_size; |
e4161a2a | 418 | rect.height = size.y; |
d16cf3cd VZ |
419 | } |
420 | else // horz | |
421 | { | |
0100b858 | 422 | rect.x = 0; |
d16cf3cd | 423 | rect.y = position; |
38418827 | 424 | rect.height = full_size; |
e4161a2a | 425 | rect.width = size.x; |
d16cf3cd | 426 | } |
f4322df6 | 427 | |
847dfdb4 RR |
428 | int x_diff = 0; |
429 | if (win->GetLayoutDirection() == wxLayout_RightToLeft) | |
430 | x_diff = rect.width; | |
35468934 | 431 | |
af99040c VZ |
432 | gtk_paint_handle |
433 | ( | |
434 | win->m_wxwindow->style, | |
2e992e06 | 435 | gdk_window, |
af99040c VZ |
436 | flags & wxCONTROL_CURRENT ? GTK_STATE_PRELIGHT : GTK_STATE_NORMAL, |
437 | GTK_SHADOW_NONE, | |
438 | NULL /* no clipping */, | |
439 | win->m_wxwindow, | |
440 | "paned", | |
847dfdb4 RR |
441 | dc.LogicalToDeviceX(rect.x) - x_diff, |
442 | dc.LogicalToDeviceY(rect.y), | |
af99040c VZ |
443 | rect.width, |
444 | rect.height, | |
38418827 | 445 | isVert ? GTK_ORIENTATION_VERTICAL : GTK_ORIENTATION_HORIZONTAL |
af99040c | 446 | ); |
95155e75 VZ |
447 | } |
448 | ||
4c85ab75 | 449 | void |
2e992e06 | 450 | wxRendererGTK::DrawDropArrow(wxWindow *WXUNUSED(win), |
4c85ab75 VZ |
451 | wxDC& dc, |
452 | const wxRect& rect, | |
453 | int flags) | |
38511687 | 454 | { |
bc13e772 | 455 | GtkWidget *button = GetButtonWidget(); |
38511687 | 456 | |
4c85ab75 VZ |
457 | // If we give GTK_PIZZA(win->m_wxwindow)->bin_window as |
458 | // a window for gtk_paint_xxx function, then it won't | |
459 | // work for wxMemoryDC. So that is why we assume wxDC | |
460 | // is wxWindowDC (wxClientDC, wxMemoryDC and wxPaintDC | |
461 | // are derived from it) and use its m_window. | |
ab171e95 RR |
462 | GdkWindow* gdk_window = NULL; |
463 | #if wxUSE_NEW_DC | |
464 | wxImplDC *impl = dc.GetImpl(); | |
465 | wxGTKImplDC *gtk_impl = wxDynamicCast( impl, wxGTKImplDC ); | |
466 | if (gtk_impl) | |
467 | gdk_window = gtk_impl->GetGDKWindow(); | |
468 | #else | |
469 | gdk_window = dc.GetGDKWindow(); | |
470 | #endif | |
2e992e06 VZ |
471 | wxASSERT_MSG( gdk_window, |
472 | wxT("cannot use wxRendererNative on wxDC of this type") ); | |
a4622f29 | 473 | |
4c85ab75 VZ |
474 | // draw arrow so that there is even space horizontally |
475 | // on both sides | |
476 | int arrowX = rect.width/4 + 1; | |
477 | int arrowWidth = rect.width - (arrowX*2); | |
478 | ||
479 | // scale arrow's height accoording to the width | |
480 | int arrowHeight = rect.width/3; | |
481 | int arrowY = (rect.height-arrowHeight)/2 + | |
482 | ((rect.height-arrowHeight) & 1); | |
483 | ||
e1befae3 | 484 | GtkStateType state; |
a4622f29 | 485 | |
3203621a JS |
486 | if ( flags & wxCONTROL_PRESSED ) |
487 | state = GTK_STATE_ACTIVE; | |
a4622f29 VZ |
488 | else if ( flags & wxCONTROL_DISABLED ) |
489 | state = GTK_STATE_INSENSITIVE; | |
3203621a JS |
490 | else if ( flags & wxCONTROL_CURRENT ) |
491 | state = GTK_STATE_PRELIGHT; | |
e1befae3 VZ |
492 | else |
493 | state = GTK_STATE_NORMAL; | |
a4622f29 | 494 | |
a4622f29 | 495 | // draw arrow on button |
a4622f29 VZ |
496 | gtk_paint_arrow |
497 | ( | |
bc13e772 | 498 | button->style, |
2e992e06 | 499 | gdk_window, |
a4622f29 | 500 | state, |
e1befae3 | 501 | flags & wxCONTROL_PRESSED ? GTK_SHADOW_IN : GTK_SHADOW_OUT, |
a4622f29 | 502 | NULL, |
bc13e772 | 503 | button, |
a4622f29 VZ |
504 | "arrow", |
505 | GTK_ARROW_DOWN, | |
a8ac548e | 506 | FALSE, |
4c85ab75 VZ |
507 | rect.x + arrowX, |
508 | rect.y + arrowY, | |
509 | arrowWidth, | |
510 | arrowHeight | |
a4622f29 | 511 | ); |
38511687 VZ |
512 | } |
513 | ||
4c85ab75 VZ |
514 | void |
515 | wxRendererGTK::DrawComboBoxDropButton(wxWindow *win, | |
516 | wxDC& dc, | |
517 | const wxRect& rect, | |
518 | int flags) | |
519 | { | |
2209baae RR |
520 | DrawPushButton(win,dc,rect,flags); |
521 | DrawDropArrow(win,dc,rect); | |
522 | } | |
523 | ||
cdccdfab | 524 | void |
2e992e06 | 525 | wxRendererGTK::DrawCheckBox(wxWindow *WXUNUSED(win), |
90b903c2 WS |
526 | wxDC& dc, |
527 | const wxRect& rect, | |
528 | int flags ) | |
2209baae RR |
529 | { |
530 | GtkWidget *button = GetCheckButtonWidget(); | |
ab171e95 RR |
531 | |
532 | GdkWindow* gdk_window = NULL; | |
533 | #if wxUSE_NEW_DC | |
534 | wxImplDC *impl = dc.GetImpl(); | |
535 | wxGTKImplDC *gtk_impl = wxDynamicCast( impl, wxGTKImplDC ); | |
536 | if (gtk_impl) | |
537 | gdk_window = gtk_impl->GetGDKWindow(); | |
538 | #else | |
539 | gdk_window = dc.GetGDKWindow(); | |
540 | #endif | |
2e992e06 VZ |
541 | wxASSERT_MSG( gdk_window, |
542 | wxT("cannot use wxRendererNative on wxDC of this type") ); | |
90b903c2 | 543 | |
4c85ab75 VZ |
544 | GtkStateType state; |
545 | ||
3203621a JS |
546 | if ( flags & wxCONTROL_PRESSED ) |
547 | state = GTK_STATE_ACTIVE; | |
4c85ab75 VZ |
548 | else if ( flags & wxCONTROL_DISABLED ) |
549 | state = GTK_STATE_INSENSITIVE; | |
3203621a JS |
550 | else if ( flags & wxCONTROL_CURRENT ) |
551 | state = GTK_STATE_PRELIGHT; | |
4c85ab75 VZ |
552 | else |
553 | state = GTK_STATE_NORMAL; | |
90b903c2 | 554 | |
2209baae | 555 | gtk_paint_check |
4c85ab75 VZ |
556 | ( |
557 | button->style, | |
2e992e06 | 558 | gdk_window, |
4c85ab75 | 559 | state, |
2209baae | 560 | flags & wxCONTROL_CHECKED ? GTK_SHADOW_IN : GTK_SHADOW_OUT, |
4c85ab75 VZ |
561 | NULL, |
562 | button, | |
2209baae | 563 | "cellcheck", |
cdccdfab WS |
564 | dc.LogicalToDeviceX(rect.x)+2, |
565 | dc.LogicalToDeviceY(rect.y)+3, | |
506d54a3 | 566 | 13, 13 |
4c85ab75 | 567 | ); |
4c85ab75 VZ |
568 | } |
569 | ||
2209baae | 570 | void |
2e992e06 | 571 | wxRendererGTK::DrawPushButton(wxWindow *WXUNUSED(win), |
2209baae RR |
572 | wxDC& dc, |
573 | const wxRect& rect, | |
574 | int flags) | |
862d8041 | 575 | { |
2209baae | 576 | GtkWidget *button = GetButtonWidget(); |
862d8041 | 577 | |
ab171e95 RR |
578 | GdkWindow* gdk_window = NULL; |
579 | #if wxUSE_NEW_DC | |
580 | wxImplDC *impl = dc.GetImpl(); | |
581 | wxGTKImplDC *gtk_impl = wxDynamicCast( impl, wxGTKImplDC ); | |
582 | if (gtk_impl) | |
583 | gdk_window = gtk_impl->GetGDKWindow(); | |
584 | #else | |
585 | gdk_window = dc.GetGDKWindow(); | |
586 | #endif | |
2e992e06 VZ |
587 | wxASSERT_MSG( gdk_window, |
588 | wxT("cannot use wxRendererNative on wxDC of this type") ); | |
2209baae RR |
589 | |
590 | // draw button | |
862d8041 RR |
591 | GtkStateType state; |
592 | ||
593 | if ( flags & wxCONTROL_PRESSED ) | |
594 | state = GTK_STATE_ACTIVE; | |
595 | else if ( flags & wxCONTROL_DISABLED ) | |
596 | state = GTK_STATE_INSENSITIVE; | |
597 | else if ( flags & wxCONTROL_CURRENT ) | |
598 | state = GTK_STATE_PRELIGHT; | |
599 | else | |
600 | state = GTK_STATE_NORMAL; | |
2209baae RR |
601 | |
602 | gtk_paint_box | |
862d8041 RR |
603 | ( |
604 | button->style, | |
2e992e06 | 605 | gdk_window, |
862d8041 | 606 | state, |
2209baae | 607 | flags & wxCONTROL_PRESSED ? GTK_SHADOW_IN : GTK_SHADOW_OUT, |
862d8041 RR |
608 | NULL, |
609 | button, | |
2209baae RR |
610 | "button", |
611 | rect.x, rect.y, rect.width, rect.height | |
862d8041 RR |
612 | ); |
613 | } | |
daebb44c | 614 | |
cdccdfab | 615 | void |
daebb44c | 616 | wxRendererGTK::DrawItemSelectionRect(wxWindow *win, |
cdccdfab WS |
617 | wxDC& dc, |
618 | const wxRect& rect, | |
619 | int flags ) | |
daebb44c | 620 | { |
ab171e95 RR |
621 | GdkWindow* gdk_window = NULL; |
622 | #if wxUSE_NEW_DC | |
623 | wxImplDC *impl = dc.GetImpl(); | |
624 | wxGTKImplDC *gtk_impl = wxDynamicCast( impl, wxGTKImplDC ); | |
625 | if (gtk_impl) | |
626 | gdk_window = gtk_impl->GetGDKWindow(); | |
627 | #else | |
628 | gdk_window = dc.GetGDKWindow(); | |
629 | #endif | |
2e992e06 VZ |
630 | wxASSERT_MSG( gdk_window, |
631 | wxT("cannot use wxRendererNative on wxDC of this type") ); | |
632 | ||
08f57d21 RR |
633 | int x_diff = 0; |
634 | if (win->GetLayoutDirection() == wxLayout_RightToLeft) | |
635 | x_diff = rect.width; | |
636 | ||
daebb44c | 637 | GtkStateType state; |
90b903c2 | 638 | if (flags & wxCONTROL_SELECTED) |
daebb44c | 639 | { |
05d97538 RR |
640 | // the wxCONTROL_FOCUSED state is deduced |
641 | // directly from the m_wxwindow by GTK+ | |
642 | state = GTK_STATE_SELECTED; | |
daebb44c | 643 | |
05d97538 | 644 | gtk_paint_flat_box( win->m_widget->style, |
2e992e06 | 645 | gdk_window, |
daebb44c RR |
646 | state, |
647 | GTK_SHADOW_NONE, | |
cdccdfab | 648 | NULL, |
daebb44c | 649 | win->m_wxwindow, |
05d97538 | 650 | "cell_even", |
08f57d21 | 651 | dc.LogicalToDeviceX(rect.x) - x_diff, |
daebb44c RR |
652 | dc.LogicalToDeviceY(rect.y), |
653 | rect.width, | |
654 | rect.height ); | |
655 | } | |
72be9a3a VZ |
656 | else // !wxCONTROL_SELECTED |
657 | { | |
658 | state = GTK_STATE_NORMAL; | |
659 | } | |
90b903c2 | 660 | |
ce0cf2b8 | 661 | if ((flags & wxCONTROL_CURRENT) && (flags & wxCONTROL_FOCUSED)) |
daebb44c | 662 | { |
f4322df6 | 663 | gtk_paint_focus( win->m_widget->style, |
05d97538 | 664 | gdk_window, |
72be9a3a | 665 | state, |
05d97538 RR |
666 | NULL, |
667 | win->m_wxwindow, | |
668 | "treeview", | |
669 | dc.LogicalToDeviceX(rect.x), | |
670 | dc.LogicalToDeviceY(rect.y), | |
671 | rect.width, | |
672 | rect.height ); | |
daebb44c RR |
673 | } |
674 | } | |
6d789987 JS |
675 | |
676 | void wxRendererGTK::DrawFocusRect(wxWindow* win, wxDC& dc, const wxRect& rect, int flags) | |
677 | { | |
ab171e95 RR |
678 | GdkWindow* gdk_window = NULL; |
679 | #if wxUSE_NEW_DC | |
680 | wxImplDC *impl = dc.GetImpl(); | |
681 | wxGTKImplDC *gtk_impl = wxDynamicCast( impl, wxGTKImplDC ); | |
682 | if (gtk_impl) | |
683 | gdk_window = gtk_impl->GetGDKWindow(); | |
684 | #else | |
685 | gdk_window = dc.GetGDKWindow(); | |
686 | #endif | |
6d789987 JS |
687 | wxASSERT_MSG( gdk_window, |
688 | wxT("cannot use wxRendererNative on wxDC of this type") ); | |
689 | ||
690 | GtkStateType state; | |
691 | if (flags & wxCONTROL_SELECTED) | |
692 | state = GTK_STATE_SELECTED; | |
693 | else | |
694 | state = GTK_STATE_NORMAL; | |
695 | ||
696 | gtk_paint_focus( win->m_widget->style, | |
697 | gdk_window, | |
698 | state, | |
699 | NULL, | |
700 | win->m_wxwindow, | |
701 | NULL, | |
702 | dc.LogicalToDeviceX(rect.x), | |
703 | dc.LogicalToDeviceY(rect.y), | |
704 | rect.width, | |
705 | rect.height ); | |
706 | } |