• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

xap_Gtk2Compat.h

Go to the documentation of this file.
00001 /* AbiWord
00002  * Copyright (C) 2011-2013 Hubert Figuiere
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00017  * 02110-1301 USA.
00018  */
00019 
00020 // header for gtk2 compatibility
00021 
00022 #ifndef _XAP_GTK2COMPAT_H_
00023 #define _XAP_GTK2COMPAT_H_
00024 
00025 #include "ut_types.h"
00026 
00027 #include <gtk/gtk.h>
00028 
00029 #if !GTK_CHECK_VERSION(3,0,0)
00030 #include <gdk/gdkkeysyms.h>
00031 #endif
00032 
00033 // keynames
00034 #if GTK_CHECK_VERSION(2,22,0)
00035 #include <gdk/gdkkeysyms-compat.h>
00036 #else
00037 #define GDK_KEY_3270_Enter   GDK_3270_Enter
00038 #define GDK_KEY_BackSpace    GDK_BackSpace
00039 #define GDK_KEY_Delete       GDK_Delete
00040 #define GDK_KEY_Down         GDK_Down
00041 #define GDK_KEY_Escape       GDK_Escape
00042 #define GDK_KEY_F1           GDK_F1
00043 #define GDK_KEY_Help         GDK_Help
00044 #define GDK_KEY_ISO_Enter    GDK_ISO_Enter
00045 #define GDK_KEY_KP_0         GDK_KP_0
00046 #define GDK_KEY_KP_9         GDK_KP_9
00047 #define GDK_KEY_KP_Down      GDK_KP_Down
00048 #define GDK_KEY_KP_Enter     GDK_KP_Enter
00049 #define GDK_KEY_KP_Escape    GDK_KP_Escape
00050 #define GDK_KEY_KP_Left      GDK_KP_Left
00051 #define GDK_KEY_KP_Right     GDK_KP_Right
00052 #define GDK_KEY_KP_Space     GDK_KP_Space
00053 #define GDK_KEY_KP_Up        GDK_KP_Up
00054 #define GDK_KEY_Left         GDK_Left
00055 #define GDK_KEY_Return       GDK_Return
00056 #define GDK_KEY_Right        GDK_Right
00057 #define GDK_KEY_space        GDK_space
00058 #define GDK_KEY_Tab          GDK_Tab
00059 #define GDK_KEY_ISO_Left_Tab GDK_ISO_Left_Tab
00060 #define GDK_KEY_Up           GDK_Up
00061 #define GDK_KEY_VoidSymbol   GDK_VoidSymbol
00062 #endif
00063 
00064 
00065 // Gtk2 compatibility for GSEAL
00066 
00067 #if !GTK_CHECK_VERSION(2,14,0)
00068 inline GdkWindow* gtk_widget_get_window(GtkWidget* w)
00069 {
00070   return w->window;
00071 }
00072 
00073 inline const guchar *gtk_selection_data_get_data(const GtkSelectionData *s)
00074 {
00075     return s->data;
00076 }
00077 
00078 inline GdkAtom gtk_selection_data_get_target(const GtkSelectionData *s)
00079 {
00080   return s->target;
00081 }
00082 
00083 inline gint gtk_selection_data_get_length(const GtkSelectionData *s)
00084 {
00085   return s->length;
00086 }
00087 
00088 inline GtkWidget* gtk_dialog_get_action_area(GtkDialog* dialog)
00089 {
00090   return dialog->action_area;
00091 }
00092 
00093 inline GtkWidget* gtk_dialog_get_content_area(GtkDialog* dialog)
00094 {
00095   return dialog->vbox;
00096 }
00097 
00098 inline GtkWidget* gtk_color_selection_dialog_get_color_selection(GtkColorSelectionDialog* d)
00099 {
00100   return d->colorsel;
00101 }
00102 
00103 inline void gtk_adjustment_configure(GtkAdjustment *adjustment,
00104                      gdouble value, gdouble lower,
00105                      gdouble upper, gdouble step_increment,
00106                      gdouble page_increment, gdouble page_size)
00107 {
00108   adjustment->value = value;
00109   adjustment->lower = lower;
00110   adjustment->upper = upper;
00111   adjustment->step_increment = step_increment;
00112   adjustment->page_increment = page_increment;
00113   adjustment->page_size = page_size;
00114   g_signal_emit_by_name(G_OBJECT(adjustment), "changed");
00115 }
00116 #endif
00117 
00118 #if !GTK_CHECK_VERSION(2,18,0)
00119 inline void gtk_widget_get_allocation(GtkWidget* widget, GtkAllocation* alloc)
00120 {
00121   *alloc = widget->allocation;
00122 }
00123 
00124 inline gboolean gtk_widget_has_focus(GtkWidget* widget)
00125 {
00126   return GTK_WIDGET_HAS_FOCUS(widget);
00127 }
00128 
00129 inline gboolean gtk_widget_has_grab(GtkWidget* widget)
00130 {
00131   return GTK_WIDGET_HAS_GRAB(widget);
00132 }
00133 
00134 inline gboolean gtk_widget_is_toplevel(GtkWidget* widget)
00135 {
00136   return GTK_WIDGET_TOPLEVEL(widget);
00137 }
00138 
00139 inline gboolean gtk_widget_get_double_buffered(GtkWidget* widget)
00140 {
00141   return GTK_WIDGET_DOUBLE_BUFFERED(widget);
00142 }
00143 
00144 inline void gtk_widget_set_can_default(GtkWidget* w, gboolean can_default)
00145 {
00146   if (can_default) {
00147     GTK_WIDGET_SET_FLAGS(w, GTK_CAN_DEFAULT);
00148   }
00149   else {
00150     GTK_WIDGET_UNSET_FLAGS(w, GTK_CAN_DEFAULT);
00151   }
00152 }
00153 
00154 inline void gtk_widget_set_can_focus(GtkWidget* w, gboolean can_focus)
00155 {
00156   if (can_focus) {
00157     GTK_WIDGET_SET_FLAGS(w, GTK_CAN_FOCUS);
00158   }
00159   else {
00160     GTK_WIDGET_UNSET_FLAGS(w, GTK_CAN_FOCUS);
00161   }
00162 }
00163 
00164 inline gboolean gtk_widget_get_sensitive(GtkWidget *widget)
00165 {
00166   return GTK_WIDGET_SENSITIVE(widget);
00167 }
00168 
00169 inline gboolean gtk_widget_get_visible(GtkWidget *widget)
00170 {
00171   return GTK_WIDGET_VISIBLE(widget);
00172 }
00173 
00174 inline void gtk_widget_set_visible(GtkWidget *widget, gboolean visible)
00175 {
00176   visible ? gtk_widget_show(widget) : gtk_widget_hide(widget);
00177 }
00178 #endif
00179 
00180 #if !GTK_CHECK_VERSION(2,20,0)
00181 inline void gtk_widget_get_requisition(GtkWidget* widget, GtkRequisition* requisition)
00182 {
00183   *requisition = widget->requisition;
00184 }
00185 
00186 inline gboolean gtk_widget_get_mapped(GtkWidget* w)
00187 {
00188   return GTK_WIDGET_MAPPED(w);
00189 }
00190 
00191 inline gboolean gtk_widget_get_realized(GtkWidget* w)
00192 {
00193   return GTK_WIDGET_REALIZED(w);
00194 }
00195 #endif
00196 
00197 #if !GTK_CHECK_VERSION(2,24,0)
00198 
00199 #define GTK_COMBO_BOX_TEXT GTK_COMBO_BOX
00200 #define GtkComboBoxText    GtkComboBox
00201 
00202 inline GtkWidget* gtk_combo_box_text_new()
00203 {
00204   return gtk_combo_box_new_text();
00205 }
00206 
00207 inline GtkWidget* gtk_combo_box_text_new_with_entry()
00208 {
00209   return gtk_combo_box_entry_new_text();
00210 }
00211 
00212 inline void gtk_combo_box_text_append_text(GtkComboBox* combo, const gchar* text)
00213 {
00214   gtk_combo_box_append_text(combo, text);
00215 }
00216 
00217 inline gchar* gtk_combo_box_text_get_active_text(GtkComboBox* combo)
00218 {
00219   return gtk_combo_box_get_active_text(combo);
00220 }
00221 
00222 inline void gtk_combo_box_text_remove(GtkComboBox* combo, gint position)
00223 {
00224   gtk_combo_box_remove_text(combo, position);
00225 }
00226 
00227 inline GtkWidget * gtk_combo_box_new_with_model_and_entry(GtkTreeModel *model)
00228 {
00229   return gtk_combo_box_entry_new_with_model(model,0);
00230 }
00231 
00232 inline GdkDisplay * gdk_window_get_display (GdkWindow *window)
00233 {
00234   g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
00235   return gdk_drawable_get_display (GDK_DRAWABLE (window));
00236 }
00237 #endif
00238 
00239 #if !GTK_CHECK_VERSION(3,0,0)
00240 
00241 // UGLY
00242 typedef GdkColor GdkRGBA;
00243 
00244 
00245 inline GtkWidget* gtk_color_chooser_dialog_new(const gchar* title,
00246                            GtkWindow* parent)
00247 {
00248   GtkWidget* w = gtk_color_selection_dialog_new (title);
00249   if(parent)
00250     gtk_window_set_transient_for(GTK_WINDOW(w), parent);
00251   return w;
00252 }
00253 
00254 // in Gtk 3 we use GtkRGBA.
00255 inline void gtk_color_selection_get_current_rgba (GtkColorSelection *colorsel,
00256                                                   GdkColor *color)
00257 {
00258   gtk_color_selection_get_current_color(colorsel, color);
00259 }
00260 
00261 inline void gtk_color_selection_set_current_rgba (GtkColorSelection *colorsel,
00262                                                   GdkColor *color)
00263 {
00264   gtk_color_selection_set_current_color(colorsel, color);
00265 }
00266 
00267 inline void gdk_rgba_free(GdkColor* color)
00268 {
00269   gdk_color_free(color);
00270 }
00271 
00272 inline void gtk_color_button_set_rgba(GtkColorButton* button,
00273                      const GdkColor* color)
00274 {
00275   gtk_color_button_set_color(button, color);
00276 }
00277 
00278 inline void gtk_color_button_get_rgba(GtkColorButton* button,
00279                      GdkColor* color)
00280 {
00281   gtk_color_button_get_color(button, color);
00282 }
00283 
00284 inline GtkWidget* gtk_box_new(GtkOrientation orientation, gint spacing)
00285 {
00286   if(orientation == GTK_ORIENTATION_VERTICAL) {
00287     return gtk_vbox_new(FALSE, spacing);
00288   }
00289   return gtk_hbox_new(FALSE, spacing);
00290 }
00291 
00292 inline GtkWidget* gtk_scrollbar_new(GtkOrientation orientation, GtkAdjustment* adj)
00293 {
00294   if(orientation == GTK_ORIENTATION_VERTICAL) {
00295     return gtk_vscrollbar_new(adj);
00296   }
00297   return gtk_hscrollbar_new(adj);
00298 }
00299 
00300 inline GtkWidget* gtk_separator_new(GtkOrientation orientation)
00301 {
00302   if(orientation == GTK_ORIENTATION_VERTICAL) {
00303     return gtk_vseparator_new();
00304   }
00305   return gtk_hseparator_new();
00306 }
00307 
00308 inline void gtk_combo_box_text_remove_all(GtkComboBoxText *combo_box)
00309 {
00310   gtk_list_store_clear(GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(combo_box))));
00311 }
00312 
00313 inline void gtk_widget_get_preferred_size(GtkWidget *widget,
00314                       GtkRequisition *minimum_size,
00315                       GtkRequisition * /*natural_size*/)
00316 {
00317     return gtk_widget_size_request(widget, minimum_size);
00318 }
00319 
00320 #endif
00321 
00322 #if !GTK_CHECK_VERSION(3,4,0)
00323 
00324 #define GTK_COLOR_CHOOSER GTK_COLOR_SELECTION
00325 
00326 typedef GtkColorSelection GtkColorChooserWidget;
00327 typedef GtkColorSelection GtkColorChooser;
00328 
00329 inline GtkWidget* gtk_color_chooser_widget_new()
00330 {
00331   return gtk_color_selection_new();
00332 }
00333 
00334 inline void gtk_color_chooser_set_use_alpha(GtkColorSelection* chooser,
00335                         gboolean opacity)
00336 {
00337   gtk_color_selection_set_has_opacity_control(chooser,opacity);
00338 }
00339 
00340 inline void gtk_color_chooser_get_rgba(GtkColorSelection *chooser,
00341                        GdkRGBA *color)
00342 {
00343   gtk_color_selection_get_current_rgba (chooser, color);
00344 }
00345 
00346 inline void gtk_color_chooser_set_rgba(GtkColorSelection *chooser,
00347                        GdkRGBA *color)
00348 {
00349   gtk_color_selection_set_current_rgba (chooser, color);
00350 }
00351 
00352 #endif
00353 
00354 #if GTK_CHECK_VERSION(3,0,0)
00355 
00356 typedef GdkWindow GdkDrawable;
00357 
00358 #endif
00359 
00360 
00361 // wrapper because gtk_color_button_set_rgba is deprecated.
00362 inline void XAP_gtk_color_button_set_rgba(GtkColorButton* colorbtn,
00363                      const GdkRGBA* color)
00364 {
00365 #if GTK_CHECK_VERSION(3,4,0)
00366   gtk_color_chooser_set_rgba(GTK_COLOR_CHOOSER(colorbtn), color);
00367 #else
00368   gtk_color_button_set_rgba (colorbtn, color);
00369 #endif
00370 }
00371 
00372 // wrapper because gtk_color_button_get_rgba is deprecated.
00373 inline void XAP_gtk_color_button_get_rgba(GtkColorButton* colorbtn,
00374                       GdkRGBA* color)
00375 {
00376 #if GTK_CHECK_VERSION(3,4,0)
00377   gtk_color_chooser_get_rgba(GTK_COLOR_CHOOSER(colorbtn), color);
00378 #else
00379   gtk_color_button_get_rgba (colorbtn, color);
00380 #endif
00381 }
00382 
00383 
00384 // Now onto the device were the deprecated functions are to be
00385 // with several line of code.
00386 inline
00387 GdkGrabStatus XAP_gdk_keyboard_grab(GdkWindow *window,
00388                     gboolean owner_events,
00389                     guint32 time_)
00390 {
00391 #if GTK_CHECK_VERSION(3,0,0)
00392     GdkDeviceManager *manager
00393         = gdk_display_get_device_manager(gdk_display_get_default());
00394     GdkDevice *device = gdk_device_manager_get_client_pointer (manager);
00395 
00396     return gdk_device_grab (gdk_device_get_associated_device(device),
00397                 window,
00398                 GDK_OWNERSHIP_WINDOW,
00399                 owner_events,
00400                 GDK_ALL_EVENTS_MASK,
00401                 NULL,
00402                 time_);
00403 #else
00404     return gdk_keyboard_grab(window, owner_events, time_);
00405 #endif
00406 }
00407 
00408 inline
00409 GdkGrabStatus XAP_gdk_pointer_grab(GdkWindow *window,
00410                    gboolean owner_events,
00411                    GdkEventMask event_mask,
00412                    GdkWindow *confine_to,
00413                    GdkCursor *cursor,
00414                    guint32 time_)
00415 {
00416 #if GTK_CHECK_VERSION(3,0,0)
00417     GdkDeviceManager *manager
00418         = gdk_display_get_device_manager(gdk_display_get_default());
00419     GdkDevice *device = gdk_device_manager_get_client_pointer (manager);
00420     UT_UNUSED(confine_to);
00421     return gdk_device_grab (device, window,
00422                 GDK_OWNERSHIP_WINDOW,
00423                 owner_events, event_mask,
00424                 cursor, time_);
00425 #else
00426     return gdk_pointer_grab(window, owner_events, event_mask,
00427                 confine_to, cursor, time_);
00428 #endif
00429 }
00430 
00431 
00432 // http://permalink.gmane.org/gmane.comp.gnome.svn/520942
00433 inline
00434 void XAP_gdk_keyboard_ungrab(guint32 t)
00435 {
00436 #if GTK_CHECK_VERSION(3,0,0)
00437     GdkDeviceManager *manager
00438         = gdk_display_get_device_manager(gdk_display_get_default());
00439     GdkDevice *device = gdk_device_manager_get_client_pointer (manager);
00440     gdk_device_ungrab (gdk_device_get_associated_device(device),
00441                t);
00442 #else
00443     gdk_keyboard_ungrab(t);
00444 #endif
00445 }
00446 
00447 inline
00448 void XAP_gdk_pointer_ungrab(guint32 t)
00449 {
00450 #if GTK_CHECK_VERSION(3,0,0)
00451     GdkDeviceManager *manager
00452         = gdk_display_get_device_manager(gdk_display_get_default());
00453     GdkDevice *device = gdk_device_manager_get_client_pointer (manager);
00454     gdk_device_ungrab (device, t);
00455 #else
00456     gdk_pointer_ungrab(t);
00457 #endif
00458 }
00459 
00460 #endif

Generated on Thu Jun 20 2013 for AbiWord by  doxygen 1.7.1