Debian Codegraph @

src/af/xap/gtk/xap_Gtk2Compat.h

raw
1 /* AbiWord
2 * Copyright (C) 2011-2013 Hubert Figuiere
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 * 02110-1301 USA.
18 */
19
20 // header for gtk2 compatibility
21
22 #ifndef _XAP_GTK2COMPAT_H_
23 #define _XAP_GTK2COMPAT_H_
24
25 #include "ut_types.h"
26
27 #include <gtk/gtk.h>
28
29 #if !GTK_CHECK_VERSION(3,0,0)
30 #include <gdk/gdkkeysyms.h>
31 #endif
32
33 // keynames
34 #if GTK_CHECK_VERSION(2,22,0)
35 #include <gdk/gdkkeysyms-compat.h>
36 #else
37 #define GDK_KEY_3270_Enter GDK_3270_Enter
38 #define GDK_KEY_BackSpace GDK_BackSpace
39 #define GDK_KEY_Delete GDK_Delete
40 #define GDK_KEY_Down GDK_Down
41 #define GDK_KEY_Escape GDK_Escape
42 #define GDK_KEY_F1 GDK_F1
43 #define GDK_KEY_Help GDK_Help
44 #define GDK_KEY_ISO_Enter GDK_ISO_Enter
45 #define GDK_KEY_KP_0 GDK_KP_0
46 #define GDK_KEY_KP_9 GDK_KP_9
47 #define GDK_KEY_KP_Down GDK_KP_Down
48 #define GDK_KEY_KP_Enter GDK_KP_Enter
49 #define GDK_KEY_KP_Escape GDK_KP_Escape
50 #define GDK_KEY_KP_Left GDK_KP_Left
51 #define GDK_KEY_KP_Right GDK_KP_Right
52 #define GDK_KEY_KP_Space GDK_KP_Space
53 #define GDK_KEY_KP_Up GDK_KP_Up
54 #define GDK_KEY_Left GDK_Left
55 #define GDK_KEY_Return GDK_Return
56 #define GDK_KEY_Right GDK_Right
57 #define GDK_KEY_space GDK_space
58 #define GDK_KEY_Tab GDK_Tab
59 #define GDK_KEY_ISO_Left_Tab GDK_ISO_Left_Tab
60 #define GDK_KEY_Up GDK_Up
61 #define GDK_KEY_VoidSymbol GDK_VoidSymbol
62 #endif
63
64
65 // Gtk2 compatibility for GSEAL
66
67 #if !GTK_CHECK_VERSION(2,14,0)
68 inline GdkWindow* gtk_widget_get_window(GtkWidget* w)
69 {
70 return w->window;
71 }
72
73 inline const guchar *gtk_selection_data_get_data(const GtkSelectionData *s)
74 {
75 return s->data;
76 }
77
78 inline GdkAtom gtk_selection_data_get_target(const GtkSelectionData *s)
79 {
80 return s->target;
81 }
82
83 inline gint gtk_selection_data_get_length(const GtkSelectionData *s)
84 {
85 return s->length;
86 }
87
88 inline GtkWidget* gtk_dialog_get_action_area(GtkDialog* dialog)
89 {
90 return dialog->action_area;
91 }
92
93 inline GtkWidget* gtk_dialog_get_content_area(GtkDialog* dialog)
94 {
95 return dialog->vbox;
96 }
97
98 inline GtkWidget* gtk_color_selection_dialog_get_color_selection(GtkColorSelectionDialog* d)
99 {
100 return d->colorsel;
101 }
102
103 inline void gtk_adjustment_configure(GtkAdjustment *adjustment,
104 gdouble value, gdouble lower,
105 gdouble upper, gdouble step_increment,
106 gdouble page_increment, gdouble page_size)
107 {
108 adjustment->value = value;
109 adjustment->lower = lower;
110 adjustment->upper = upper;
111 adjustment->step_increment = step_increment;
112 adjustment->page_increment = page_increment;
113 adjustment->page_size = page_size;
114 g_signal_emit_by_name(G_OBJECT(adjustment), "changed");
115 }
116 #endif
117
118 #if !GTK_CHECK_VERSION(2,18,0)
119 inline void gtk_widget_get_allocation(GtkWidget* widget, GtkAllocation* alloc)
120 {
121 *alloc = widget->allocation;
122 }
123
124 inline gboolean gtk_widget_has_focus(GtkWidget* widget)
125 {
126 return GTK_WIDGET_HAS_FOCUS(widget);
127 }
128
129 inline gboolean gtk_widget_has_grab(GtkWidget* widget)
130 {
131 return GTK_WIDGET_HAS_GRAB(widget);
132 }
133
134 inline gboolean gtk_widget_is_toplevel(GtkWidget* widget)
135 {
136 return GTK_WIDGET_TOPLEVEL(widget);
137 }
138
139 inline gboolean gtk_widget_get_double_buffered(GtkWidget* widget)
140 {
141 return GTK_WIDGET_DOUBLE_BUFFERED(widget);
142 }
143
144 inline void gtk_widget_set_can_default(GtkWidget* w, gboolean can_default)
145 {
146 if (can_default) {
147 GTK_WIDGET_SET_FLAGS(w, GTK_CAN_DEFAULT);
148 }
149 else {
150 GTK_WIDGET_UNSET_FLAGS(w, GTK_CAN_DEFAULT);
151 }
152 }
153
154 inline void gtk_widget_set_can_focus(GtkWidget* w, gboolean can_focus)
155 {
156 if (can_focus) {
157 GTK_WIDGET_SET_FLAGS(w, GTK_CAN_FOCUS);
158 }
159 else {
160 GTK_WIDGET_UNSET_FLAGS(w, GTK_CAN_FOCUS);
161 }
162 }
163
164 inline gboolean gtk_widget_get_sensitive(GtkWidget *widget)
165 {
166 return GTK_WIDGET_SENSITIVE(widget);
167 }
168
169 inline gboolean gtk_widget_get_visible(GtkWidget *widget)
170 {
171 return GTK_WIDGET_VISIBLE(widget);
172 }
173
174 inline void gtk_widget_set_visible(GtkWidget *widget, gboolean visible)
175 {
176 visible ? gtk_widget_show(widget) : gtk_widget_hide(widget);
177 }
178 #endif
179
180 #if !GTK_CHECK_VERSION(2,20,0)
181 inline void gtk_widget_get_requisition(GtkWidget* widget, GtkRequisition* requisition)
182 {
183 *requisition = widget->requisition;
184 }
185
186 inline gboolean gtk_widget_get_mapped(GtkWidget* w)
187 {
188 return GTK_WIDGET_MAPPED(w);
189 }
190
191 inline gboolean gtk_widget_get_realized(GtkWidget* w)
192 {
193 return GTK_WIDGET_REALIZED(w);
194 }
195 #endif
196
197 #if !GTK_CHECK_VERSION(2,24,0)
198
199 #define GTK_COMBO_BOX_TEXT GTK_COMBO_BOX
200 #define GtkComboBoxText GtkComboBox
201
202 inline GtkWidget* gtk_combo_box_text_new()
203 {
204 return gtk_combo_box_new_text();
205 }
206
207 inline GtkWidget* gtk_combo_box_text_new_with_entry()
208 {
209 return gtk_combo_box_entry_new_text();
210 }
211
212 inline void gtk_combo_box_text_append_text(GtkComboBox* combo, const gchar* text)
213 {
214 gtk_combo_box_append_text(combo, text);
215 }
216
217 inline gchar* gtk_combo_box_text_get_active_text(GtkComboBox* combo)
218 {
219 return gtk_combo_box_get_active_text(combo);
220 }
221
222 inline void gtk_combo_box_text_remove(GtkComboBox* combo, gint position)
223 {
224 gtk_combo_box_remove_text(combo, position);
225 }
226
227 inline GtkWidget * gtk_combo_box_new_with_model_and_entry(GtkTreeModel *model)
228 {
229 return gtk_combo_box_entry_new_with_model(model,0);
230 }
231
232 inline GdkDisplay * gdk_window_get_display (GdkWindow *window)
233 {
234 g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
235 return gdk_drawable_get_display (GDK_DRAWABLE (window));
236 }
237 #endif
238
239 #if !GTK_CHECK_VERSION(3,0,0)
240
241 // UGLY
242 typedef GdkColor GdkRGBA;
243
244
245 inline GtkWidget* gtk_color_chooser_dialog_new(const gchar* title,
246 GtkWindow* parent)
247 {
248 GtkWidget* w = gtk_color_selection_dialog_new (title);
249 if(parent)
250 gtk_window_set_transient_for(GTK_WINDOW(w), parent);
251 return w;
252 }
253
254 // in Gtk 3 we use GtkRGBA.
255 inline void gtk_color_selection_get_current_rgba (GtkColorSelection *colorsel,
256 GdkColor *color)
257 {
258 gtk_color_selection_get_current_color(colorsel, color);
259 }
260
261 inline void gtk_color_selection_set_current_rgba (GtkColorSelection *colorsel,
262 GdkColor *color)
263 {
264 gtk_color_selection_set_current_color(colorsel, color);
265 }
266
267 inline void gdk_rgba_free(GdkColor* color)
268 {
269 gdk_color_free(color);
270 }
271
272 inline void gtk_color_button_set_rgba(GtkColorButton* button,
273 const GdkColor* color)
274 {
275 gtk_color_button_set_color(button, color);
276 }
277
278 inline void gtk_color_button_get_rgba(GtkColorButton* button,
279 GdkColor* color)
280 {
281 gtk_color_button_get_color(button, color);
282 }
283
284 inline GtkWidget* gtk_box_new(GtkOrientation orientation, gint spacing)
285 {
286 if(orientation == GTK_ORIENTATION_VERTICAL) {
287 return gtk_vbox_new(FALSE, spacing);
288 }
289 return gtk_hbox_new(FALSE, spacing);
290 }
291
292 inline GtkWidget* gtk_scrollbar_new(GtkOrientation orientation, GtkAdjustment* adj)
293 {
294 if(orientation == GTK_ORIENTATION_VERTICAL) {
295 return gtk_vscrollbar_new(adj);
296 }
297 return gtk_hscrollbar_new(adj);
298 }
299
300 inline GtkWidget* gtk_separator_new(GtkOrientation orientation)
301 {
302 if(orientation == GTK_ORIENTATION_VERTICAL) {
303 return gtk_vseparator_new();
304 }
305 return gtk_hseparator_new();
306 }
307
308 inline void gtk_combo_box_text_remove_all(GtkComboBoxText *combo_box)
309 {
310 gtk_list_store_clear(GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(combo_box))));
311 }
312
313 inline void gtk_widget_get_preferred_size(GtkWidget *widget,
314 GtkRequisition *minimum_size,
315 GtkRequisition * /*natural_size*/)
316 {
317 return gtk_widget_size_request(widget, minimum_size);
318 }
319
320 #endif
321
322 #if !GTK_CHECK_VERSION(3,4,0)
323
324 #define GTK_COLOR_CHOOSER GTK_COLOR_SELECTION
325
326 typedef GtkColorSelection GtkColorChooserWidget;
327 typedef GtkColorSelection GtkColorChooser;
328
329 inline GtkWidget* gtk_color_chooser_widget_new()
330 {
331 return gtk_color_selection_new();
332 }
333
334 inline void gtk_color_chooser_set_use_alpha(GtkColorSelection* chooser,
335 gboolean opacity)
336 {
337 gtk_color_selection_set_has_opacity_control(chooser,opacity);
338 }
339
340 inline void gtk_color_chooser_get_rgba(GtkColorSelection *chooser,
341 GdkRGBA *color)
342 {
343 gtk_color_selection_get_current_rgba (chooser, color);
344 }
345
346 inline void gtk_color_chooser_set_rgba(GtkColorSelection *chooser,
347 GdkRGBA *color)
348 {
349 gtk_color_selection_set_current_rgba (chooser, color);
350 }
351
352 #endif
353
354 #if GTK_CHECK_VERSION(3,0,0)
355
356 typedef GdkWindow GdkDrawable;
357
358 #endif
359
360
361 // wrapper because gtk_color_button_set_rgba is deprecated.
362 inline void XAP_gtk_color_button_set_rgba(GtkColorButton* colorbtn,
363 const GdkRGBA* color)
364 {
365 #if GTK_CHECK_VERSION(3,4,0)
366 gtk_color_chooser_set_rgba(GTK_COLOR_CHOOSER(colorbtn), color);
367 #else
368 gtk_color_button_set_rgba (colorbtn, color);
369 #endif
370 }
371
372 // wrapper because gtk_color_button_get_rgba is deprecated.
373 inline void XAP_gtk_color_button_get_rgba(GtkColorButton* colorbtn,
374 GdkRGBA* color)
375 {
376 #if GTK_CHECK_VERSION(3,4,0)
377 gtk_color_chooser_get_rgba(GTK_COLOR_CHOOSER(colorbtn), color);
378 #else
379 gtk_color_button_get_rgba (colorbtn, color);
380 #endif
381 }
382
383
384 // Now onto the device were the deprecated functions are to be
385 // with several line of code.
386 inline
387 GdkGrabStatus XAP_gdk_keyboard_grab(GdkWindow *window,
388 gboolean owner_events,
389 guint32 time_)
390 {
391 #if GTK_CHECK_VERSION(3,0,0)
392 GdkDeviceManager *manager
393 = gdk_display_get_device_manager(gdk_display_get_default());
394 GdkDevice *device = gdk_device_manager_get_client_pointer (manager);
395
396 return gdk_device_grab (gdk_device_get_associated_device(device),
397 window,
398 GDK_OWNERSHIP_WINDOW,
399 owner_events,
400 GDK_ALL_EVENTS_MASK,
401 NULL,
402 time_);
403 #else
404 return gdk_keyboard_grab(window, owner_events, time_);
405 #endif
406 }
407
408 inline
409 GdkGrabStatus XAP_gdk_pointer_grab(GdkWindow *window,
410 gboolean owner_events,
411 GdkEventMask event_mask,
412 GdkWindow *confine_to,
413 GdkCursor *cursor,
414 guint32 time_)
415 {
416 #if GTK_CHECK_VERSION(3,0,0)
417 GdkDeviceManager *manager
418 = gdk_display_get_device_manager(gdk_display_get_default());
419 GdkDevice *device = gdk_device_manager_get_client_pointer (manager);
420 UT_UNUSED(confine_to);
421 return gdk_device_grab (device, window,
422 GDK_OWNERSHIP_WINDOW,
423 owner_events, event_mask,
424 cursor, time_);
425 #else
426 return gdk_pointer_grab(window, owner_events, event_mask,
427 confine_to, cursor, time_);
428 #endif
429 }
430
431
432 // http://permalink.gmane.org/gmane.comp.gnome.svn/520942
433 inline
434 void XAP_gdk_keyboard_ungrab(guint32 t)
435 {
436 #if GTK_CHECK_VERSION(3,0,0)
437 GdkDeviceManager *manager
438 = gdk_display_get_device_manager(gdk_display_get_default());
439 GdkDevice *device = gdk_device_manager_get_client_pointer (manager);
440 gdk_device_ungrab (gdk_device_get_associated_device(device),
441 t);
442 #else
443 gdk_keyboard_ungrab(t);
444 #endif
445 }
446
447 inline
448 void XAP_gdk_pointer_ungrab(guint32 t)
449 {
450 #if GTK_CHECK_VERSION(3,0,0)
451 GdkDeviceManager *manager
452 = gdk_display_get_device_manager(gdk_display_get_default());
453 GdkDevice *device = gdk_device_manager_get_client_pointer (manager);
454 gdk_device_ungrab (device, t);
455 #else
456 gdk_pointer_ungrab(t);
457 #endif
458 }
459
460 #endif