diff --git a/src/Makefile.am b/src/Makefile.am index 43f3565..e57b3b9 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -5,6 +5,7 @@ AM_CPPFLAGS = @GTK_CFLAGS@ bin_PROGRAMS = gmrun gmrun_SOURCES = \ + gtkcompat.c gtkcompat.h \ gtkcompletionline.cc gtkcompletionline.h \ history.cc history.h \ main.cc main.h \ diff --git a/src/gtkcompat.c b/src/gtkcompat.c new file mode 100644 index 0000000..71c853d --- /dev/null +++ b/src/gtkcompat.c @@ -0,0 +1,245 @@ +/* + * Copyright (C) 2020 + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + */ + +#include "gtkcompat.h" + +/* ================================================== */ +/* GTK < 3.0 */ +/* ================================================== */ + +#if ! GTK_CHECK_VERSION (3, 0, 0) + +GtkWidget * +gtk_box_new (GtkOrientation orientation, gint spacing) +{ + // the HOMOGENEOUS property defaults to FALSE + // add this to make it TRUE + // gtk_box_set_homogeneous (GTK_BOX(hbox), TRUE); + if (orientation == GTK_ORIENTATION_HORIZONTAL) { + return gtk_hbox_new (FALSE, spacing); + } + if (orientation == GTK_ORIENTATION_VERTICAL) { + return gtk_vbox_new (FALSE, spacing); + } + return NULL; +} + +GtkWidget * +gtk_button_box_new (GtkOrientation orientation) +{ + if (orientation == GTK_ORIENTATION_HORIZONTAL) { + return gtk_hbutton_box_new (); + } + if (orientation == GTK_ORIENTATION_VERTICAL) { + return gtk_vbutton_box_new (); + } + return NULL; +} + +GtkWidget * +gtk_scale_new (GtkOrientation orientation, GtkAdjustment *adjustment) +{ + if (orientation == GTK_ORIENTATION_HORIZONTAL) { + return gtk_hscale_new (adjustment); + } + if (orientation == GTK_ORIENTATION_VERTICAL) { + return gtk_vscale_new (adjustment); + } + return NULL; +} + +GtkWidget * +gtk_scale_new_with_range (GtkOrientation orientation, + gdouble min, + gdouble max, + gdouble step) +{ + if (orientation == GTK_ORIENTATION_HORIZONTAL) { + return gtk_hscale_new_with_range (min, max, step); + } + if (orientation == GTK_ORIENTATION_VERTICAL) { + return gtk_vscale_new_with_range (min, max, step); + } + return NULL; +} + +GtkWidget * +gtk_separator_new (GtkOrientation orientation) +{ + if (orientation == GTK_ORIENTATION_HORIZONTAL) { + return gtk_hseparator_new (); + } + if (orientation == GTK_ORIENTATION_VERTICAL) { + return gtk_vseparator_new (); + } + return NULL; +} + +GtkWidget * +gtk_scrollbar_new (GtkOrientation orientation, GtkAdjustment *adjustment) +{ + if (orientation == GTK_ORIENTATION_HORIZONTAL) { + return gtk_hscrollbar_new (adjustment); + } + if (orientation == GTK_ORIENTATION_VERTICAL) { + return gtk_vscrollbar_new (adjustment); + } + return NULL; +} + +GtkWidget * +gtk_paned_new (GtkOrientation orientation) +{ + if (orientation == GTK_ORIENTATION_HORIZONTAL) { + return gtk_hpaned_new (); + } + if (orientation == GTK_ORIENTATION_VERTICAL) { + return gtk_vpaned_new (); + } + return NULL; +} + +#endif + + +/* ================================================== */ +/* GTK < 2.22 */ +/* ================================================== */ + +#if ! (GTK_CHECK_VERSION (2, 22, 0)) + +gboolean gtk_window_has_group (GtkWindow *window) +{ + return window->group != NULL; +} + +GtkWidget * gtk_window_group_get_current_grab (GtkWindowGroup *window_group) +{ + if (window_group->grabs) { + return GTK_WIDGET (window_group->grabs->data); + } + return NULL; +} + +#endif + +/* ================================================== */ +/* GTK < 2.20 */ +/* ================================================== */ + +#if ! (GTK_CHECK_VERSION (2, 20, 0)) + +void +gtk_widget_set_mapped (GtkWidget *widget, gboolean mapped) +{ + if (mapped) + GTK_OBJECT_FLAGS (widget) |= GTK_MAPPED; + else + GTK_OBJECT_FLAGS (widget) &= ~(GTK_MAPPED); +} + +void +gtk_widget_set_realized (GtkWidget *widget, gboolean realized) +{ + if (realized) + GTK_OBJECT_FLAGS (widget) |= GTK_REALIZED; + else + GTK_OBJECT_FLAGS (widget) &= ~(GTK_REALIZED); +} + +GtkWindowType +gtk_window_get_window_type (GtkWindow *window) +{ + return (window->type); +} + +#endif + + +/* ================================================== */ +/* GTK < 2.18 */ +/* ================================================== */ + +#if ! (GTK_CHECK_VERSION (2, 18, 0)) + +void gtk_widget_get_allocation (GtkWidget *widget, GtkAllocation *allocation) +{ + *allocation = widget->allocation; +} + +void gtk_widget_set_allocation (GtkWidget *widget, const GtkAllocation *allocation) +{ + widget->allocation = *allocation; +} + +void gtk_widget_set_can_default (GtkWidget *widget, gboolean can_default) +{ + if (can_default != gtk_widget_get_can_default (widget)) + { + if (can_default) + GTK_OBJECT_FLAGS (widget) |= GTK_CAN_DEFAULT; + else + GTK_OBJECT_FLAGS (widget) &= ~(GTK_CAN_DEFAULT); + } +} + +void gtk_widget_set_can_focus (GtkWidget *widget, gboolean can_focus) +{ + if (can_focus != gtk_widget_get_can_focus (widget)) + { + if (can_focus) + GTK_OBJECT_FLAGS (widget) |= GTK_CAN_FOCUS; + else + GTK_OBJECT_FLAGS (widget) &= ~(GTK_CAN_FOCUS); + } +} + +void gtk_widget_set_has_window (GtkWidget *widget, gboolean has_window) +{ + if (has_window) + GTK_OBJECT_FLAGS (widget) &= ~(GTK_NO_WINDOW); + else + GTK_OBJECT_FLAGS (widget) |= GTK_NO_WINDOW; +} + +void gtk_widget_set_visible (GtkWidget *widget, gboolean visible) +{ + if (visible) + gtk_widget_show (widget); + else + gtk_widget_hide (widget); +} +#endif + + +/* ================================================== */ +/* GTK < 2.14 */ +/* ================================================== */ + +#if ! (GTK_CHECK_VERSION (2, 14, 0)) + +GtkWidget * gtk_dialog_get_action_area (GtkDialog *dialog) { + return (dialog->action_area); +} + +GtkWidget * gtk_dialog_get_content_area (GtkDialog *dialog) { + return (dialog->vbox); +} + +GdkWindow * gtk_widget_get_window (GtkWidget *widget) { + return (widget->window); +} + +GtkWidget * gtk_window_get_default_widget (GtkWindow *window) { + return (window->default_widget); +} + +#endif + diff --git a/src/gtkcompat.h b/src/gtkcompat.h new file mode 100644 index 0000000..841fb94 --- /dev/null +++ b/src/gtkcompat.h @@ -0,0 +1,164 @@ +/* + * Copyright (C) 2020 + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + */ + +#ifndef __GTKCOMPAT_H +#define __GTKCOMPAT_H + +#ifdef __cplusplus +extern "C" +{ +#endif + +#include +#include + +// ================================================== + +// GLIB < 2.58 +#if ! GLIB_CHECK_VERSION (2, 58, 0) +#define G_SOURCE_FUNC(f) ((GSourceFunc) (void (*)(void)) (f)) +#endif + +// GLIB < 2.32 +#if ! GLIB_CHECK_VERSION (2, 32, 0) +#define G_SOURCE_REMOVE FALSE +#define G_SOURCE_CONTINUE TRUE +#define g_hash_table_add(ht, key) g_hash_table_replace(ht, key, key) +#define g_hash_table_contains(ht, key) g_hash_table_lookup_extended(ht, key, NULL, NULL) +#define GRecMutex GStaticRecMutex +#define g_rec_mutex_init(x) g_static_rec_mutex_init(x) +#define g_rec_mutex_lock(x) g_static_rec_mutex_lock(x) +#define g_rec_mutex_unlock(x) g_static_rec_mutex_unlock(x) +#define g_thread_new(name,func,data) g_thread_create(func,data,TRUE,NULL) +#define g_thread_try_new(name,func,data,error) g_thread_create(func,data,TRUE,error) +#endif + +// ================================================== + +// GTK < 3.0 +#if ! GTK_CHECK_VERSION (3, 0, 0) +GtkWidget *gtk_box_new (GtkOrientation orientation, gint spacing) ; +GtkWidget *gtk_button_box_new (GtkOrientation orientation); +GtkWidget *gtk_scale_new (GtkOrientation orientation, GtkAdjustment *adjustment); +GtkWidget *gtk_scale_new_with_range (GtkOrientation orientation, gdouble min, gdouble max, gdouble step); +GtkWidget *gtk_separator_new (GtkOrientation orientation); +GtkWidget *gtk_scrollbar_new (GtkOrientation orientation, GtkAdjustment *adjustment); +GtkWidget *gtk_paned_new (GtkOrientation orientation); +#define gtk_widget_get_allocated_height(widget) ( ((GtkWidget *)(widget))->allocation.height ) +#define gtk_widget_get_allocated_width(widget) ( ((GtkWidget *)(widget))->allocation.width ) +#endif + + +// GTK < 2.24 +#if ! GTK_CHECK_VERSION (2, 24, 0) +typedef struct _GtkComboBox GtkComboBoxText; +typedef struct _GtkComboBoxClass GtkComboBoxTextClass; +typedef struct _GtkComboBoxPrivate GtkComboBoxTextPrivate; +#define GTK_TYPE_COMBO_BOX_TEXT (gtk_combo_box_get_type ()) +#define GTK_COMBO_BOX_TEXT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_COMBO_BOX, GtkComboBoxText)) +#define GTK_COMBO_BOX_TEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_COMBO_BOX, GtkComboBoxTextClass)) +#define GTK_IS_COMBO_BOX_TEXT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_COMBO_BOX)) +#define GTK_IS_COMBO_BOX_TEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_COMBO_BOX)) +#define GTK_COMBO_BOX_TEXT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_COMBO_BOX, GtkComboBoxTextClass)) +#define gtk_combo_box_text_new() gtk_combo_box_new_text() +#define gtk_combo_box_text_append_text(combo,text) gtk_combo_box_append_text(combo,text) +#define gtk_combo_box_text_insert_text(combox,pos,text) gtk_combo_box_insert_text(combox,pos,text) +#define gtk_combo_box_text_prepend_text(combo,text) gtk_combo_box_prepend_text(combo,text) +#define gtk_combo_box_text_remove(combo,pos) gtk_combo_box_remove_text(combo,pos) +#define gtk_combo_box_text_get_active_text(combo) gtk_combo_box_get_active_text(combo) +#endif + + +// GTK < 2.22 +#if ! (GTK_CHECK_VERSION (2, 22, 0)) +gboolean gtk_window_has_group (GtkWindow *window); +GtkWidget * gtk_window_group_get_current_grab (GtkWindowGroup *window_group); +#endif + + +// GTK < 2.20 +#if ! (GTK_CHECK_VERSION (2, 20, 0)) +#define gtk_widget_get_mapped(wid) ((GTK_WIDGET_FLAGS (wid) & GTK_MAPPED) != 0) +#define gtk_widget_get_realized(wid) ((GTK_WIDGET_FLAGS (wid) & GTK_REALIZED) != 0) +void gtk_widget_set_mapped (GtkWidget *widget, gboolean mapped); +void gtk_widget_set_realized (GtkWidget *widget, gboolean realized); +GtkWindowType gtk_window_get_window_type (GtkWindow *window); +#endif + + +// GTK < 2.18 +#if ! (GTK_CHECK_VERSION (2, 18, 0)) +//GtkStateType gtk_widget_get_state (GtkWidget *widget); +#define gtk_widget_get_state(wid) (GTK_WIDGET (wid)->state) +#define gtk_widget_is_toplevel(wid) ((GTK_WIDGET_FLAGS (wid) & GTK_TOPLEVEL) != 0) +#define gtk_widget_get_has_window(wid) !((GTK_WIDGET_FLAGS (wid) & GTK_NO_WINDOW) != 0) +#define gtk_widget_get_visible(wid) ((GTK_WIDGET_FLAGS (wid) & GTK_VISIBLE) != 0) +#define gtk_widget_is_drawable(wid) (GTK_WIDGET_VISIBLE (wid) && GTK_WIDGET_MAPPED (wid)) +#define gtk_widget_get_sensitive(wid) ((GTK_WIDGET_FLAGS (wid) & GTK_SENSITIVE) != 0) +#define gtk_widget_get_can_focus(wid) ((GTK_WIDGET_FLAGS (wid) & GTK_CAN_FOCUS) != 0) +#define gtk_widget_has_focus(wid) ((GTK_WIDGET_FLAGS (wid) & GTK_HAS_FOCUS) != 0) +#define gtk_widget_get_can_default(wid) ((GTK_WIDGET_FLAGS (wid) & GTK_CAN_DEFAULT) != 0) +#define gtk_widget_get_receives_default(wid) ((GTK_WIDGET_FLAGS (wid) & GTK_RECEIVES_DEFAULT) != 0) +#define gtk_widget_has_default(wid) ((GTK_WIDGET_FLAGS (wid) & GTK_HAS_DEFAULT) != 0) +#define gtk_widget_has_grab(wid) ((GTK_WIDGET_FLAGS (wid) & GTK_HAS_GRAB) != 0) +#define gtk_widget_get_app_paintable(wid) ((GTK_WIDGET_FLAGS (wid) & GTK_APP_PAINTABLE) != 0) +#define gtk_widget_get_double_buffered(wid) ((GTK_WIDGET_FLAGS (wid) & GTK_DOUBLE_BUFFERED) != 0) +void gtk_widget_get_allocation (GtkWidget *widget, GtkAllocation *allocation); +void gtk_widget_set_allocation (GtkWidget *widget, const GtkAllocation *allocation); +void gtk_widget_set_can_default (GtkWidget *widget, gboolean can_default); +void gtk_widget_set_can_focus (GtkWidget *widget, gboolean can_focus); +void gtk_widget_set_has_window (GtkWidget *widget, gboolean has_window); +void gtk_widget_set_receives_default (GtkWidget *widget, gboolean receives_default); +void gtk_widget_set_visible (GtkWidget *widget, gboolean visible); +#endif + + +// GTK < 2.14 +#if ! (GTK_CHECK_VERSION (2, 14, 0)) +GtkWidget * gtk_dialog_get_action_area (GtkDialog *dialog); +GtkWidget * gtk_dialog_get_content_area (GtkDialog *dialog); +GdkWindow * gtk_widget_get_window (GtkWidget *widget); +GtkWidget * gtk_window_get_default_widget (GtkWindow *window); +#endif + + +// KEYS +#ifndef GDK_KEY_a +# define GDK_KEY_Control_R GDK_Control_R +# define GDK_KEY_Control_L GDK_Control_L +# define GDK_KEY_Shift_R GDK_Shift_R +# define GDK_KEY_Shift_L GDK_Shift_L +# define GDK_KEY_Alt_R GDK_Alt_R +# define GDK_KEY_Alt_L GDK_Alt_L +# define GDK_KEY_Tab GDK_Tab +# define GDK_KEY_Up GDK_Up +# define GDK_KEY_space GDK_space +# define GDK_KEY_Down GDK_Down +# define GDK_KEY_Return GDK_Return +# define GDK_KEY_exclam GDK_exclam +# define GDK_KEY_R GDK_R +# define GDK_KEY_r GDK_r +# define GDK_KEY_S GDK_S +# define GDK_KEY_s GDK_s +# define GDK_KEY_BackSpace GDK_BackSpace +# define GDK_KEY_Home GDK_Home +# define GDK_KEY_End GDK_End +# define GDK_KEY_Escape GDK_Escape +# define GDK_KEY_G GDK_G +# define GDK_KEY_g GDK_g +# define GDK_KEY_E GDK_E +# define GDK_KEY_e GDK_e +#endif + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/gtkcompletionline.cc b/src/gtkcompletionline.cc index 7b4caff..84b6931 100644 --- a/src/gtkcompletionline.cc +++ b/src/gtkcompletionline.cc @@ -12,6 +12,7 @@ #include #include +#include "gtkcompat.h" #include #include