]> git.saurik.com Git - wxWidgets.git/blame - include/wx/gtk/private/gtk2-compat.h
wxMessageBox off the main thread lost result code.
[wxWidgets.git] / include / wx / gtk / private / gtk2-compat.h
CommitLineData
fc9ab22a
VS
1///////////////////////////////////////////////////////////////////////////////
2// Name: wx/gtk/private/compat.h
3// Purpose: Compatibility code for older GTK+ versions
4// Author: Vaclav Slavik
5// Created: 2011-03-25
fc9ab22a
VS
6// Copyright: (c) 2011 Vaclav Slavik <vslavik@fastmail.fm>
7// Licence: wxWindows licence
8///////////////////////////////////////////////////////////////////////////////
9
10#ifndef _WX_GTK_PRIVATE_COMPAT_H_
11#define _WX_GTK_PRIVATE_COMPAT_H_
12
13// ----------------------------------------------------------------------------
14// Implementations of new accessors for older GTK+ versions
15// ----------------------------------------------------------------------------
16
17// GTK+ deprecated direct access to struct members and some other stuff,
18// replacing them with simple accessor functions. These aren't available in
19// older versions, though, so we have to provide them for compatibility.
20//
21// Note: wx_ prefix is used to avoid symbol conflicts at runtime
0b669520
VS
22//
23// Note 2: We support building against newer GTK+ version and using an older
24// one at runtime, so we must provide our implementations of these
25// functions even if GTK_CHECK_VERSION would indicate the function is
26// already available in GTK+.
27
9dc44eff 28#ifndef __WXGTK3__
a8886b11
PC
29
30// ----------------------------------------------------------------------------
31// the following were introduced in GTK+ 2.8
32
33static inline GtkWidget* wx_gtk_scrolled_window_get_hscrollbar(GtkScrolledWindow* scrolled_window)
34{
35 return scrolled_window->hscrollbar;
36}
37#define gtk_scrolled_window_get_hscrollbar wx_gtk_scrolled_window_get_hscrollbar
38
39static inline GtkWidget* wx_gtk_scrolled_window_get_vscrollbar(GtkScrolledWindow* scrolled_window)
40{
41 return scrolled_window->vscrollbar;
42}
43#define gtk_scrolled_window_get_vscrollbar wx_gtk_scrolled_window_get_vscrollbar
44
45// ----------------------------------------------------------------------------
46// the following were introduced in GLib 2.10
47
48static inline gpointer wx_g_object_ref_sink(gpointer object)
49{
50 g_object_ref(object);
51 gtk_object_sink(GTK_OBJECT(object));
52 return object;
53}
54#define g_object_ref_sink wx_g_object_ref_sink
55
385e8575 56// ----------------------------------------------------------------------------
59f76658 57// the following were introduced in GTK+ 2.12
385e8575
PC
58
59static inline void wx_gtk_about_dialog_set_program_name(GtkAboutDialog* about, const gchar* name)
60{
61 gtk_about_dialog_set_name(about, name);
62}
63#define gtk_about_dialog_set_program_name wx_gtk_about_dialog_set_program_name
64
a8886b11
PC
65// ----------------------------------------------------------------------------
66// the following were introduced in GTK+ 2.14
67
68static inline gdouble wx_gtk_adjustment_get_lower(GtkAdjustment* adjustment)
69{
70 return adjustment->lower;
71}
72#define gtk_adjustment_get_lower wx_gtk_adjustment_get_lower
73
74static inline gdouble wx_gtk_adjustment_get_page_increment(GtkAdjustment* adjustment)
75{
76 return adjustment->page_increment;
77}
78#define gtk_adjustment_get_page_increment wx_gtk_adjustment_get_page_increment
79
80static inline gdouble wx_gtk_adjustment_get_page_size(GtkAdjustment* adjustment)
81{
82 return adjustment->page_size;
83}
84#define gtk_adjustment_get_page_size wx_gtk_adjustment_get_page_size
85
86static inline gdouble wx_gtk_adjustment_get_step_increment(GtkAdjustment* adjustment)
87{
88 return adjustment->step_increment;
89}
90#define gtk_adjustment_get_step_increment wx_gtk_adjustment_get_step_increment
91
92static inline gdouble wx_gtk_adjustment_get_upper(GtkAdjustment* adjustment)
93{
94 return adjustment->upper;
95}
96#define gtk_adjustment_get_upper wx_gtk_adjustment_get_upper
97
385e8575
PC
98static inline void wx_gtk_adjustment_set_page_size(GtkAdjustment* adjustment, gdouble page_size)
99{
100 adjustment->page_size = page_size;
101}
102#define gtk_adjustment_set_page_size wx_gtk_adjustment_set_page_size
103
a8886b11
PC
104static inline GtkWidget* wx_gtk_color_selection_dialog_get_color_selection(GtkColorSelectionDialog* csd)
105{
106 return csd->colorsel;
107}
108#define gtk_color_selection_dialog_get_color_selection wx_gtk_color_selection_dialog_get_color_selection
109
110static inline GtkWidget* wx_gtk_dialog_get_content_area(GtkDialog* dialog)
111{
112 return dialog->vbox;
113}
114#define gtk_dialog_get_content_area wx_gtk_dialog_get_content_area
115
116static inline GtkWidget* wx_gtk_dialog_get_action_area(GtkDialog* dialog)
117{
118 return dialog->action_area;
119}
120#define gtk_dialog_get_action_area wx_gtk_dialog_get_action_area
121
385e8575
PC
122static inline guint16 wx_gtk_entry_get_text_length(GtkEntry* entry)
123{
124 return entry->text_length;
125}
126#define gtk_entry_get_text_length wx_gtk_entry_get_text_length
127
385e8575
PC
128static inline const guchar* wx_gtk_selection_data_get_data(GtkSelectionData* selection_data)
129{
130 return selection_data->data;
131}
132#define gtk_selection_data_get_data wx_gtk_selection_data_get_data
133
a8886b11
PC
134static inline GdkAtom wx_gtk_selection_data_get_data_type(GtkSelectionData* selection_data)
135{
136 return selection_data->type;
137}
138#define gtk_selection_data_get_data_type wx_gtk_selection_data_get_data_type
139
140static inline gint wx_gtk_selection_data_get_format(GtkSelectionData* selection_data)
141{
142 return selection_data->format;
143}
144#define gtk_selection_data_get_format wx_gtk_selection_data_get_format
145
146static inline gint wx_gtk_selection_data_get_length(GtkSelectionData* selection_data)
147{
148 return selection_data->length;
149}
150#define gtk_selection_data_get_length wx_gtk_selection_data_get_length
151
152static inline GdkAtom wx_gtk_selection_data_get_target(GtkSelectionData* selection_data)
153{
154 return selection_data->target;
155}
156#define gtk_selection_data_get_target wx_gtk_selection_data_get_target
157
158static inline GdkWindow* wx_gtk_widget_get_window(GtkWidget* widget)
159{
160 return widget->window;
161}
162#define gtk_widget_get_window wx_gtk_widget_get_window
163
385e8575
PC
164static inline GtkWidget* wx_gtk_window_get_default_widget(GtkWindow* window)
165{
166 return window->default_widget;
167}
168#define gtk_window_get_default_widget wx_gtk_window_get_default_widget
169
a8886b11
PC
170// ----------------------------------------------------------------------------
171// the following were introduced in GTK+ 2.16
172
173static inline GdkAtom wx_gtk_selection_data_get_selection(GtkSelectionData* selection_data)
174{
175 return selection_data->selection;
176}
177#define gtk_selection_data_get_selection wx_gtk_selection_data_get_selection
178
179// ----------------------------------------------------------------------------
180// the following were introduced in GTK+ 2.18
181
385e8575
PC
182static inline void wx_gtk_cell_renderer_get_alignment(GtkCellRenderer* cell, gfloat* xalign, gfloat* yalign)
183{
184 *xalign = cell->xalign;
185 *yalign = cell->yalign;
186}
187#define gtk_cell_renderer_get_alignment wx_gtk_cell_renderer_get_alignment
188
189static inline void wx_gtk_cell_renderer_get_padding(GtkCellRenderer* cell, gint* xpad, gint* ypad)
190{
191 *xpad = cell->xpad;
192 *ypad = cell->ypad;
193}
194#define gtk_cell_renderer_get_padding wx_gtk_cell_renderer_get_padding
195
a8886b11
PC
196static inline void wx_gtk_widget_get_allocation(GtkWidget* widget, GtkAllocation* allocation)
197{
198 *allocation = widget->allocation;
199}
200#define gtk_widget_get_allocation wx_gtk_widget_get_allocation
0b669520
VS
201
202inline gboolean wx_gtk_widget_get_has_window(GtkWidget *widget)
203{
204 return !GTK_WIDGET_NO_WINDOW(widget);
205}
206#define gtk_widget_get_has_window wx_gtk_widget_get_has_window
207
208
209inline gboolean wx_gtk_widget_get_has_grab(GtkWidget *widget)
210{
211 return GTK_WIDGET_HAS_GRAB(widget);
212}
213#define gtk_widget_get_has_grab wx_gtk_widget_get_has_grab
214
215
216inline gboolean wx_gtk_widget_get_visible(GtkWidget *widget)
217{
218 return GTK_WIDGET_VISIBLE(widget);
219}
220#define gtk_widget_get_visible wx_gtk_widget_get_visible
221
222
223inline gboolean wx_gtk_widget_get_sensitive(GtkWidget *widget)
224{
a8db6ab7 225 return GTK_WIDGET_SENSITIVE(widget);
0b669520
VS
226}
227#define gtk_widget_get_sensitive wx_gtk_widget_get_sensitive
228
229
230inline gboolean wx_gtk_widget_is_drawable(GtkWidget *widget)
231{
232 return GTK_WIDGET_DRAWABLE(widget);
233}
234#define gtk_widget_is_drawable wx_gtk_widget_is_drawable
235
236
237inline gboolean wx_gtk_widget_get_can_focus(GtkWidget *widget)
238{
239 return GTK_WIDGET_CAN_FOCUS(widget);
240}
241#define gtk_widget_get_can_focus wx_gtk_widget_get_can_focus
242
7c491c85 243inline void wx_gtk_widget_set_can_focus(GtkWidget *widget, gboolean can)
0b669520
VS
244{
245 if ( can )
246 GTK_WIDGET_SET_FLAGS(widget, GTK_CAN_FOCUS);
247 else
248 GTK_WIDGET_UNSET_FLAGS(widget, GTK_CAN_FOCUS);
249}
7c491c85 250#define gtk_widget_set_can_focus wx_gtk_widget_set_can_focus
0b669520
VS
251
252
253inline gboolean wx_gtk_widget_get_can_default(GtkWidget *widget)
254{
255 return GTK_WIDGET_CAN_DEFAULT(widget);
256}
257#define gtk_widget_get_can_default wx_gtk_widget_get_can_default
258
259inline void wx_gtk_widget_set_can_default(GtkWidget *widget, gboolean can)
260{
261 if ( can )
262 GTK_WIDGET_SET_FLAGS(widget, GTK_CAN_DEFAULT);
263 else
264 GTK_WIDGET_UNSET_FLAGS(widget, GTK_CAN_DEFAULT);
265}
266#define gtk_widget_set_can_default wx_gtk_widget_set_can_default
267
268
269inline gboolean wx_gtk_widget_has_default(GtkWidget *widget)
270{
271 return GTK_WIDGET_HAS_DEFAULT(widget);
272}
273#define gtk_widget_has_default wx_gtk_widget_has_default
274
275
276inline GtkStateType wx_gtk_widget_get_state(GtkWidget *widget)
277{
278 return (GtkStateType)GTK_WIDGET_STATE(widget);
279}
280#define gtk_widget_get_state wx_gtk_widget_get_state
281
282
283inline gboolean wx_gtk_widget_get_double_buffered(GtkWidget *widget)
284{
285 return GTK_WIDGET_DOUBLE_BUFFERED(widget);
286}
287#define gtk_widget_get_double_buffered wx_gtk_widget_get_double_buffered
288
a8886b11
PC
289static inline gboolean wx_gtk_widget_has_grab(GtkWidget* widget)
290{
291 return GTK_WIDGET_HAS_GRAB(widget);
292}
293#define gtk_widget_has_grab wx_gtk_widget_has_grab
294
295static inline void wx_gtk_widget_set_allocation(GtkWidget* widget, const GtkAllocation* allocation)
296{
297 widget->allocation = *allocation;
298}
299#define gtk_widget_set_allocation wx_gtk_widget_set_allocation
300
301// ----------------------------------------------------------------------------
302// the following were introduced in GTK+ 2.20
0b669520
VS
303
304inline gboolean wx_gtk_widget_get_realized(GtkWidget *widget)
305{
306 return GTK_WIDGET_REALIZED(widget);
307}
308#define gtk_widget_get_realized wx_gtk_widget_get_realized
309
fc9ab22a 310
0b669520
VS
311inline gboolean wx_gtk_widget_get_mapped(GtkWidget *widget)
312{
313 return GTK_WIDGET_MAPPED(widget);
314}
315#define gtk_widget_get_mapped wx_gtk_widget_get_mapped
fc9ab22a 316
385e8575
PC
317static inline void wx_gtk_widget_get_requisition(GtkWidget* widget, GtkRequisition* requisition)
318{
319 *requisition = widget->requisition;
320}
321#define gtk_widget_get_requisition wx_gtk_widget_get_requisition
322
a8886b11
PC
323static inline GdkWindow* wx_gtk_entry_get_text_window(GtkEntry* entry)
324{
325 return entry->text_area;
326}
327#define gtk_entry_get_text_window wx_gtk_entry_get_text_window
328
9dc44eff
PC
329// ----------------------------------------------------------------------------
330// the following were introduced in GTK+ 2.22
331
332static inline GdkWindow* wx_gtk_button_get_event_window(GtkButton* button)
333{
334 return button->event_window;
335}
336#define gtk_button_get_event_window wx_gtk_button_get_event_window
337
338static inline GdkDragAction wx_gdk_drag_context_get_actions(GdkDragContext* context)
339{
340 return context->actions;
341}
342#define gdk_drag_context_get_actions wx_gdk_drag_context_get_actions
343
344static inline GdkDragAction wx_gdk_drag_context_get_selected_action(GdkDragContext* context)
345{
346 return context->action;
347}
348#define gdk_drag_context_get_selected_action wx_gdk_drag_context_get_selected_action
349
350static inline GdkDragAction wx_gdk_drag_context_get_suggested_action(GdkDragContext* context)
351{
352 return context->suggested_action;
353}
354#define gdk_drag_context_get_suggested_action wx_gdk_drag_context_get_suggested_action
355
356static inline GList* wx_gdk_drag_context_list_targets(GdkDragContext* context)
357{
358 return context->targets;
359}
360#define gdk_drag_context_list_targets wx_gdk_drag_context_list_targets
361
362static inline gint wx_gdk_visual_get_depth(GdkVisual* visual)
363{
364 return visual->depth;
365}
366#define gdk_visual_get_depth wx_gdk_visual_get_depth
367
4ea2d0d5
PC
368static inline gboolean wx_gtk_window_has_group(GtkWindow* window)
369{
370 return window->group != NULL;
371}
372#define gtk_window_has_group wx_gtk_window_has_group
373
4ccb6db0
PC
374// ----------------------------------------------------------------------------
375// the following were introduced in GTK+ 2.24
376
9dc44eff
PC
377static inline GdkDisplay* wx_gdk_window_get_display(GdkWindow* window)
378{
379 return gdk_drawable_get_display(window);
380}
381#define gdk_window_get_display wx_gdk_window_get_display
382
383static inline GdkScreen* wx_gdk_window_get_screen(GdkWindow* window)
384{
385 return gdk_drawable_get_screen(window);
386}
387#define gdk_window_get_screen wx_gdk_window_get_screen
388
4ccb6db0
PC
389static inline gint wx_gdk_window_get_height(GdkWindow* window)
390{
391 int h;
392 gdk_drawable_get_size(window, NULL, &h);
393 return h;
394}
395#define gdk_window_get_height wx_gdk_window_get_height
396
397static inline gint wx_gdk_window_get_width(GdkWindow* window)
398{
399 int w;
400 gdk_drawable_get_size(window, &w, NULL);
401 return w;
402}
403#define gdk_window_get_width wx_gdk_window_get_width
404
ac900e6b
PC
405#if GTK_CHECK_VERSION(2,10,0)
406static inline void wx_gdk_cairo_set_source_window(cairo_t* cr, GdkWindow* window, gdouble x, gdouble y)
407{
408 gdk_cairo_set_source_pixmap(cr, window, x, y);
409}
410#define gdk_cairo_set_source_window wx_gdk_cairo_set_source_window
411#endif
412
9dc44eff
PC
413// ----------------------------------------------------------------------------
414// the following were introduced in GTK+ 3.0
415
416static inline void wx_gdk_window_get_geometry(GdkWindow* window, gint* x, gint* y, gint* width, gint* height)
417{
418 gdk_window_get_geometry(window, x, y, width, height, NULL);
419}
420#define gdk_window_get_geometry wx_gdk_window_get_geometry
fc9ab22a 421
9dc44eff
PC
422static inline GtkWidget* wx_gtk_tree_view_column_get_button(GtkTreeViewColumn* tree_column)
423{
424 return tree_column->button;
425}
1897abe1
PC
426#define gtk_tree_view_column_get_button wx_gtk_tree_view_column_get_button
427
428static inline GtkWidget* wx_gtk_box_new(GtkOrientation orientation, gint spacing)
429{
430 GtkWidget* widget;
431 if (orientation == GTK_ORIENTATION_HORIZONTAL)
432 widget = gtk_hbox_new(false, spacing);
433 else
434 widget = gtk_vbox_new(false, spacing);
435 return widget;
436}
437#define gtk_box_new wx_gtk_box_new
438
439static inline GtkWidget* wx_gtk_button_box_new(GtkOrientation orientation)
440{
441 GtkWidget* widget;
442 if (orientation == GTK_ORIENTATION_HORIZONTAL)
443 widget = gtk_hbutton_box_new();
444 else
445 widget = gtk_vbutton_box_new();
446 return widget;
447}
448#define gtk_button_box_new wx_gtk_button_box_new
449
450static inline GtkWidget* wx_gtk_scale_new(GtkOrientation orientation, GtkAdjustment* adjustment)
451{
452 GtkWidget* widget;
453 if (orientation == GTK_ORIENTATION_HORIZONTAL)
454 widget = gtk_hscale_new(adjustment);
455 else
456 widget = gtk_vscale_new(adjustment);
457 return widget;
458}
459#define gtk_scale_new wx_gtk_scale_new
460
461static inline GtkWidget* wx_gtk_scrollbar_new(GtkOrientation orientation, GtkAdjustment* adjustment)
462{
463 GtkWidget* widget;
464 if (orientation == GTK_ORIENTATION_HORIZONTAL)
465 widget = gtk_hscrollbar_new(adjustment);
466 else
467 widget = gtk_vscrollbar_new(adjustment);
468 return widget;
469}
470#define gtk_scrollbar_new wx_gtk_scrollbar_new
471
472static inline GtkWidget* wx_gtk_separator_new(GtkOrientation orientation)
473{
474 GtkWidget* widget;
475 if (orientation == GTK_ORIENTATION_HORIZONTAL)
476 widget = gtk_hseparator_new();
477 else
478 widget = gtk_vseparator_new();
479 return widget;
480}
481#define gtk_separator_new wx_gtk_separator_new
482
483static inline void wx_gtk_widget_get_preferred_height(GtkWidget* widget, gint* minimum, gint* natural)
484{
485 GtkRequisition req;
486 gtk_widget_size_request(widget, &req);
487 if (minimum)
488 *minimum = req.height;
489 if (natural)
490 *natural = req.height;
491}
492#define gtk_widget_get_preferred_height wx_gtk_widget_get_preferred_height
493
494static inline void wx_gtk_widget_get_preferred_width(GtkWidget* widget, gint* minimum, gint* natural)
495{
496 GtkRequisition req;
497 gtk_widget_size_request(widget, &req);
498 if (minimum)
499 *minimum = req.width;
500 if (natural)
501 *natural = req.width;
502}
503#define gtk_widget_get_preferred_width wx_gtk_widget_get_preferred_width
504
505static inline void wx_gtk_widget_get_preferred_size(GtkWidget* widget, GtkRequisition* minimum, GtkRequisition* natural)
506{
507 GtkRequisition* req = minimum;
508 if (req == NULL)
509 req = natural;
510 gtk_widget_size_request(widget, req);
511}
512#define gtk_widget_get_preferred_size wx_gtk_widget_get_preferred_size
fc9ab22a 513
9dc44eff 514#endif // !__WXGTK3__
fc9ab22a 515#endif // _WX_GTK_PRIVATE_COMPAT_H_