2 * gtkcompat.h - this file is part of Geany, a fast and lightweight IDE
4 * Copyright 2012 Colomban Wendling <ban(at)herbesfolles(dot)org>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 /* Compatibility macros to support older GTK+ versions */
27 #if GTK_CHECK_VERSION(3, 0, 0)
28 # include <gdk/gdkkeysyms-compat.h>
35 /* This is actually available in GTK 2.24, but we expose GtkComboBoxText in the
36 * API so we don't want the type to change for no good reason (although this
37 * should probably be harmless since it's only a derivated type). However, since
38 * a plugin needs to be rebuilt and tuned to work with GTK3 we don't mind that
39 * a type changes between the GTK2 and GTK3 version */
40 #if ! GTK_CHECK_VERSION(3, 0, 0)
41 /* undef those not to get warnings about redefinitions under GTK 2.24 */
42 # undef GTK_COMBO_BOX_TEXT
43 # undef GTK_COMBO_BOX_TEXT_CLASS
44 # undef GTK_COMBO_BOX_TEXT_GET_CLASS
45 # undef GTK_IS_COMBO_BOX_TEXT
46 # undef GTK_IS_COMBO_BOX_TEXT_CLASS
47 # undef GTK_TYPE_COMBO_BOX_TEXT
49 # define GTK_COMBO_BOX_TEXT GTK_COMBO_BOX
50 # define GTK_COMBO_BOX_TEXT_CLASS GTK_COMBO_BOX_CLASS
51 # define GTK_COMBO_BOX_TEXT_GET_CLASS GTK_COMBO_BOX_GET_CLASS
52 # define GTK_IS_COMBO_BOX_TEXT GTK_IS_COMBO_BOX
53 # define GTK_IS_COMBO_BOX_TEXT_CLASS GTK_IS_COMBO_BOX_CLASS
54 # define GTK_TYPE_COMBO_BOX_TEXT GTK_TYPE_COMBO_BOX
55 # define GtkComboBoxText GtkComboBox
56 # define gtk_combo_box_text_new gtk_combo_box_new_text
57 # define gtk_combo_box_text_new_with_entry gtk_combo_box_entry_new_text
58 # define gtk_combo_box_text_append_text gtk_combo_box_append_text
59 # define gtk_combo_box_text_insert_text gtk_combo_box_insert_text
60 # define gtk_combo_box_text_prepend_text gtk_combo_box_prepend_text
61 # define gtk_combo_box_text_remove gtk_combo_box_remove_text
62 # define gtk_combo_box_text_get_active_text gtk_combo_box_get_active_text
66 /* GTK 2.22 deprecated dialog separators and 3.0 removed them
67 * We keep those however in case 2.16 has separators by default */
68 #if GTK_CHECK_VERSION(3, 0, 0)
69 # define gtk_dialog_set_has_separator(dialog, setting) /* nothing */
70 # define GTK_DIALOG_NO_SEPARATOR 0
74 #if ! GTK_CHECK_VERSION(2, 18, 0)
75 # define compat_widget_set_flag(widget, flag, enable) \
77 GtkWidget *set_flag__widget = (widget); \
78 GtkWidgetFlags set_flag__flag = (flag); \
80 GTK_WIDGET_SET_FLAGS(set_flag__widget, set_flag__flag); \
82 GTK_WIDGET_UNSET_FLAGS(set_flag__widget, set_flag__flag); \
84 # define gtk_widget_set_can_default(widget, can_default) \
85 compat_widget_set_flag((widget), GTK_CAN_DEFAULT, (can_default))
86 # define gtk_widget_is_toplevel(widget) GTK_WIDGET_TOPLEVEL(widget)
87 # define gtk_widget_is_sensitive(widget) GTK_WIDGET_IS_SENSITIVE(widget)
88 # define gtk_widget_has_focus(widget) GTK_WIDGET_HAS_FOCUS(widget)
89 # define gtk_widget_get_sensitive(widget) GTK_WIDGET_SENSITIVE(widget)
90 # define gtk_widget_get_visible(widget) GTK_WIDGET_VISIBLE(widget)
91 # define gtk_widget_set_has_window(widget, has_window) \
92 compat_widget_set_flag((widget), GTK_NO_WINDOW, !(has_window))
93 # define gtk_widget_set_can_focus(widget, can_focus) \
94 compat_widget_set_flag((widget), GTK_CAN_FOCUS, (can_focus))
96 #if ! GTK_CHECK_VERSION(2, 20, 0)
97 # define gtk_widget_get_mapped(widget) GTK_WIDGET_MAPPED(widget)
99 #if ! GTK_CHECK_VERSION(3, 0, 0)
100 # define gtk_widget_get_allocated_height(widget) (((GtkWidget *) (widget))->allocation.height)
101 # define gtk_widget_get_allocated_width(widget) (((GtkWidget *) (widget))->allocation.width)
105 /* Mappings below only prevent some deprecation warnings on GTK3 for things
106 * that didn't exist on GTK2. That's not future-proof. */
107 #if GTK_CHECK_VERSION(3, 0, 0)
109 # define compat_gtk_box_new(orientation, homogeneous, spacing) \
110 g_object_new(GTK_TYPE_BOX, \
111 "orientation", (orientation), \
112 "homogeneous", (homogeneous), \
113 "spacing", (spacing), \
115 # define gtk_vbox_new(homogeneous, spacing) \
116 compat_gtk_box_new(GTK_ORIENTATION_VERTICAL, (homogeneous), (spacing))
117 # define gtk_hbox_new(homogeneous, spacing) \
118 compat_gtk_box_new(GTK_ORIENTATION_HORIZONTAL, (homogeneous), (spacing))
119 /* Gtk[VH]ButtonBox */
120 # define gtk_vbutton_box_new() gtk_button_box_new(GTK_ORIENTATION_VERTICAL)
121 # define gtk_hbutton_box_new() gtk_button_box_new(GTK_ORIENTATION_HORIZONTAL)
122 /* Gtk[VH]Separator */
123 # define gtk_vseparator_new() gtk_separator_new(GTK_ORIENTATION_VERTICAL)
124 # define gtk_hseparator_new() gtk_separator_new(GTK_ORIENTATION_HORIZONTAL)
126 # define gtk_vpaned_new() gtk_paned_new(GTK_ORIENTATION_VERTICAL)
127 # define gtk_hpaned_new() gtk_paned_new(GTK_ORIENTATION_HORIZONTAL)
128 /* Gtk[VH]Scrollbar */
129 # define gtk_vscrollbar_new(adj) gtk_scrollbar_new(GTK_ORIENTATION_VERTICAL, (adj))
130 # define gtk_hscrollbar_new(adj) gtk_scrollbar_new(GTK_ORIENTATION_HORIZONTAL, (adj))
136 #endif /* GTK_COMPAT_H */