Branch: refs/heads/master Author: Colomban Wendling ban@herbesfolles.org Committer: Colomban Wendling ban@herbesfolles.org Date: Mon, 08 Oct 2012 18:08:06 UTC Commit: a763e307f7f211b46589738e6476b72bb1d2a0de https://github.com/geany/geany/commit/a763e307f7f211b46589738e6476b72bb1d2a0...
Log Message: ----------- Don't access GtkWidget fields directly
Since many accessor are new in GTK versions we don't depend on, add a header that defines them to the direct access if they aren't available.
Modified Paths: -------------- plugins/saveactions.c plugins/splitwindow.c src/Makefile.am src/build.c src/callbacks.c src/editor.c src/gb.c src/gtkcompat.h src/keybindings.c src/notebook.c src/search.c src/ui_utils.c src/vte.c
Modified: plugins/saveactions.c 3 files changed, 2 insertions(+), 1 deletions(-) =================================================================== @@ -25,6 +25,7 @@ #endif
#include "geanyplugin.h" +#include "gtkcompat.h"
#include <unistd.h> #include <errno.h> @@ -529,7 +530,7 @@ GtkWidget *plugin_configure(GtkDialog *dialog) vbox = gtk_vbox_new(FALSE, 6);
notebook = gtk_notebook_new(); - GTK_WIDGET_UNSET_FLAGS(notebook, GTK_CAN_FOCUS); + gtk_widget_set_can_focus(notebook, FALSE); gtk_container_set_border_width(GTK_CONTAINER(notebook), 5); gtk_box_pack_start(GTK_BOX(vbox), notebook, FALSE, TRUE, 0);
Modified: plugins/splitwindow.c 5 files changed, 3 insertions(+), 2 deletions(-) =================================================================== @@ -26,6 +26,7 @@ #endif
#include "geanyplugin.h" +#include "gtkcompat.h" #include <string.h>
@@ -300,8 +301,8 @@ static void split_view(gboolean horizontal) GtkWidget *parent = gtk_widget_get_parent(notebook); GtkWidget *pane, *toolbar, *box; GeanyDocument *doc = document_get_current(); - gint width = notebook->allocation.width / 2; - gint height = notebook->allocation.height / 2; + gint width = gtk_widget_get_allocated_width(notebook) / 2; + gint height = gtk_widget_get_allocated_height(notebook) / 2;
g_return_if_fail(doc); g_return_if_fail(edit_window.editor == NULL);
Modified: src/Makefile.am 1 files changed, 1 insertions(+), 0 deletions(-) =================================================================== @@ -20,6 +20,7 @@ SRCS = \ geanymenubuttonaction.c geanymenubuttonaction.h \ geanyobject.c geanyobject.h \ geanywraplabel.c geanywraplabel.h \ + gtkcompat.h \ highlighting.c highlighting.h \ highlightingmappings.h \ keybindings.c keybindings.h \
Modified: src/build.c 3 files changed, 2 insertions(+), 1 deletions(-) =================================================================== @@ -61,6 +61,7 @@ #include "win32.h" #include "toolbar.h" #include "geanymenubuttonaction.h" +#include "gtkcompat.h"
/* g_spawn_async_with_pipes doesn't work on Windows */ #ifdef G_OS_WIN32 @@ -1936,7 +1937,7 @@ static void on_label_button_clicked(GtkWidget *wid, gpointer user_data) const gchar *old = gtk_button_get_label(GTK_BUTTON(wid)); gchar *str;
- if (GTK_WIDGET_TOPLEVEL(top_level) && GTK_IS_WINDOW(top_level)) + if (gtk_widget_is_toplevel(top_level) && GTK_IS_WINDOW(top_level)) str = dialogs_show_input(_("Set menu item label"), GTK_WINDOW(top_level), NULL, old); else str = dialogs_show_input(_("Set menu item label"), NULL, NULL, old);
Modified: src/callbacks.c 3 files changed, 2 insertions(+), 1 deletions(-) =================================================================== @@ -65,6 +65,7 @@ #include "toolbar.h" #include "highlighting.h" #include "pluginutils.h" +#include "gtkcompat.h"
#ifdef HAVE_VTE @@ -1811,7 +1812,7 @@ G_MODULE_EXPORT void on_back_activate(GtkMenuItem *menuitem, gpointer user_data)
G_MODULE_EXPORT gboolean on_motion_event(GtkWidget *widget, GdkEventMotion *event, gpointer user_data) { - if (prefs.auto_focus && ! GTK_WIDGET_HAS_FOCUS(widget)) + if (prefs.auto_focus && ! gtk_widget_has_focus(widget)) gtk_widget_grab_focus(widget);
return FALSE;
Modified: src/editor.c 3 files changed, 2 insertions(+), 1 deletions(-) =================================================================== @@ -60,6 +60,7 @@ #include "projectprivate.h" #include "main.h" #include "highlighting.h" +#include "gtkcompat.h"
/* Note: use sciwrappers.h instead where possible. @@ -191,7 +192,7 @@ static void on_snippet_keybinding_activate(gchar *key) const gchar *s; GHashTable *specials;
- if (!doc || !GTK_WIDGET_HAS_FOCUS(doc->editor->sci)) + if (!doc || !gtk_widget_has_focus(GTK_WIDGET(doc->editor->sci))) return;
s = snippets_find_completion_by_name(doc->file_type->name, key);
Modified: src/gb.c 3 files changed, 2 insertions(+), 1 deletions(-) =================================================================== @@ -29,6 +29,7 @@ #include <signal.h> #include <unistd.h> #include <gdk-pixbuf/gdk-pixdata.h> +#include "gtkcompat.h"
#define MAX_PICS 10 #define LOOP_DELAY 200000 /* micro seconds */ @@ -191,7 +192,7 @@ static GtkWidget *create_help_dialog(GtkWindow *parent) okbutton1 = gtk_button_new_from_stock(GTK_STOCK_OK); gtk_widget_show(okbutton1); gtk_dialog_add_action_widget(GTK_DIALOG(help_dialog), okbutton1, GTK_RESPONSE_OK); - GTK_WIDGET_SET_FLAGS(okbutton1, GTK_CAN_DEFAULT); + gtk_widget_set_can_default(okbutton1, TRUE);
return help_dialog; }
Modified: src/gtkcompat.h 57 files changed, 57 insertions(+), 0 deletions(-) =================================================================== @@ -0,0 +1,57 @@ +/* + * gtkcompat.h - this file is part of Geany, a fast and lightweight IDE + * + * Copyright 2012 Colomban Wendling <ban(at)herbesfolles(dot)org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +/* Compatibility macros to support older GTK+ versions */ + +#ifndef GTK_COMPAT_H +#define GTK_COMPAT_H + +#include <gtk/gtk.h> + +G_BEGIN_DECLS + + +/* GtkWidget */ +#if ! GTK_CHECK_VERSION(2, 18, 0) +# define compat_widget_set_flag(widget, flag, enable) \ + ((enable) ? GTK_WIDGET_SET_FLAGS((widget), (flag)) : GTK_WIDGET_UNSET_FLAGS((widget), (flag))) +# define gtk_widget_set_can_default(widget, can_default) \ + compat_widget_set_flag((widget), GTK_CAN_DEFAULT, (can_default)) +# define gtk_widget_is_toplevel(widget) GTK_WIDGET_TOPLEVEL(widget) +# define gtk_widget_is_sensitive(widget) GTK_WIDGET_IS_SENSITIVE(widget) +# define gtk_widget_has_focus(widget) GTK_WIDGET_HAS_FOCUS(widget) +# define gtk_widget_get_sensitive(widget) GTK_WIDGET_SENSITIVE(widget) +# define gtk_widget_set_has_window(widget, has_window) \ + compat_widget_set_flag((widget), GTK_NO_WINDOW, !(has_window)) +# define gtk_widget_set_can_focus(widget, can_focus) \ + compat_widget_set_flag((widget), GTK_CAN_FOCUS, (can_focus)) +#endif +#if ! GTK_CHECK_VERSION(2, 20, 0) +# define gtk_widget_get_mapped(widget) GTK_WIDGET_MAPPED(widget) +#endif +#if ! GTK_CHECK_VERSION(3, 0, 0) +# define gtk_widget_get_allocated_height(widget) (((GtkWidget *) (widget))->allocation.height) +# define gtk_widget_get_allocated_width(widget) (((GtkWidget *) (widget))->allocation.width) +#endif + + +G_END_DECLS + +#endif /* GTK_COMPAT_H */
Modified: src/keybindings.c 11 files changed, 6 insertions(+), 5 deletions(-) =================================================================== @@ -56,6 +56,7 @@ #include "geanywraplabel.h" #include "main.h" #include "search.h" +#include "gtkcompat.h" #ifdef HAVE_VTE # include "vte.h" #endif @@ -1061,7 +1062,7 @@ static gboolean check_menu_key(GeanyDocument *doc, guint keyval, guint state, gu static gboolean on_menu_expose_event(GtkWidget *widget, GdkEventExpose *event, gpointer user_data) { - if (!GTK_WIDGET_SENSITIVE(widget)) + if (!gtk_widget_get_sensitive(widget)) gtk_widget_set_sensitive(GTK_WIDGET(widget), TRUE); return FALSE; } @@ -1488,7 +1489,7 @@ static gboolean cb_func_build_action(guint key_id) if (doc == NULL) return TRUE;
- if (!GTK_WIDGET_IS_SENSITIVE(ui_lookup_widget(main_widgets.window, "menu_build1"))) + if (!gtk_widget_is_sensitive(ui_lookup_widget(main_widgets.window, "menu_build1"))) return TRUE;
menu_items = build_get_menu_items(doc->file_type->id); @@ -1528,7 +1529,7 @@ static gboolean cb_func_build_action(guint key_id) /* Note: For Build menu items it's OK (at the moment) to assume they are in the correct * sensitive state, but some other menus don't update the sensitive status until * they are redrawn. */ - if (item && GTK_WIDGET_IS_SENSITIVE(item)) + if (item && gtk_widget_is_sensitive(item)) gtk_menu_item_activate(GTK_MENU_ITEM(item)); return TRUE; } @@ -1611,7 +1612,7 @@ static gboolean cb_func_switch_action(guint key_id) if (doc != NULL) { GtkWidget *sci = GTK_WIDGET(doc->editor->sci); - if (GTK_WIDGET_HAS_FOCUS(sci)) + if (gtk_widget_has_focus(sci)) ui_update_statusbar(doc, -1); else gtk_widget_grab_focus(sci); @@ -1841,7 +1842,7 @@ static gboolean cb_func_goto_action(guint key_id) GtkWidget *wid = toolbar_get_widget_child_by_name("GotoEntry");
/* use toolbar item if shown & not in the drop down overflow menu */ - if (wid && GTK_WIDGET_MAPPED(wid)) + if (wid && gtk_widget_get_mapped(wid)) { gtk_widget_grab_focus(wid); return TRUE;
Modified: src/notebook.c 11 files changed, 6 insertions(+), 5 deletions(-) =================================================================== @@ -38,6 +38,7 @@ #include "utils.h" #include "keybindings.h" #include "main.h" +#include "gtkcompat.h"
#define GEANY_DND_NOTEBOOK_TAB_TYPE "geany_dnd_notebook_tab"
@@ -376,11 +377,11 @@ static gboolean is_position_on_tab_bar(GtkNotebook *notebook, GdkEventButton *ev case GTK_POS_TOP: case GTK_POS_BOTTOM: { - if (event->y >= 0 && event->y <= tab->allocation.height) + if (event->y >= 0 && event->y <= gtk_widget_get_allocated_height(tab)) { if (! gtk_notebook_show_arrows(notebook) || ( x > scroll_arrow_hlength && - x < nb->allocation.width - scroll_arrow_hlength)) + x < gtk_widget_get_allocated_width(nb) - scroll_arrow_hlength)) return TRUE; } break; @@ -388,11 +389,11 @@ static gboolean is_position_on_tab_bar(GtkNotebook *notebook, GdkEventButton *ev case GTK_POS_LEFT: case GTK_POS_RIGHT: { - if (event->x >= 0 && event->x <= tab->allocation.width) + if (event->x >= 0 && event->x <= gtk_widget_get_allocated_width(tab)) { if (! gtk_notebook_show_arrows(notebook) || ( y > scroll_arrow_vlength && - y < nb->allocation.height - scroll_arrow_vlength)) + y < gtk_widget_get_allocated_height(nb) - scroll_arrow_vlength)) return TRUE; } } @@ -666,7 +667,7 @@ gint notebook_new_tab(GeanyDocument *this) /* get button press events for the tab label and the space between it and * the close button, if any */ ebox = gtk_event_box_new(); - GTK_WIDGET_SET_FLAGS(ebox, GTK_NO_WINDOW); + gtk_widget_set_has_window(ebox, FALSE); g_signal_connect(ebox, "button-press-event", G_CALLBACK(notebook_tab_click), page); /* focus the current document after clicking on a tab */ g_signal_connect_after(ebox, "button-release-event",
Modified: src/search.c 7 files changed, 4 insertions(+), 3 deletions(-) =================================================================== @@ -41,6 +41,7 @@ #include "keyfile.h" #include "stash.h" #include "toolbar.h" +#include "gtkcompat.h"
#include <unistd.h> #include <string.h> @@ -551,7 +552,7 @@ void search_show_find_dialog(void) else { /* only set selection if the dialog is not already visible */ - if (! GTK_WIDGET_VISIBLE(find_dlg.dialog) && sel) + if (! gtk_widget_get_visible(find_dlg.dialog) && sel) gtk_entry_set_text(GTK_ENTRY(find_dlg.entry), sel); gtk_widget_grab_focus(find_dlg.entry); set_dialog_position(find_dlg.dialog, find_dlg.position); @@ -725,7 +726,7 @@ void search_show_replace_dialog(void) else { /* only set selection if the dialog is not already visible */ - if (! GTK_WIDGET_VISIBLE(replace_dlg.dialog) && sel) + if (! gtk_widget_get_visible(replace_dlg.dialog) && sel) gtk_entry_set_text(GTK_ENTRY(replace_dlg.find_entry), sel); if (sel != NULL) /* when we have a selection, reset the entry widget's background colour */ ui_set_search_entry_background(replace_dlg.find_entry, TRUE); @@ -1024,7 +1025,7 @@ void search_show_find_in_files_dialog(const gchar *dir) stash_group_display(fif_prefs, fif_dlg.dialog);
/* only set selection if the dialog is not already visible, or has just been created */ - if (doc && ! sel && ! GTK_WIDGET_VISIBLE(fif_dlg.dialog)) + if (doc && ! sel && ! gtk_widget_get_visible(fif_dlg.dialog)) sel = editor_get_default_selection(doc->editor, search_prefs.use_current_word, NULL);
entry = gtk_bin_get_child(GTK_BIN(fif_dlg.search_combo));
Modified: src/ui_utils.c 9 files changed, 5 insertions(+), 4 deletions(-) =================================================================== @@ -56,6 +56,7 @@ #include "main.h" #include "stash.h" #include "keyfile.h" +#include "gtkcompat.h"
GeanyInterfacePrefs interface_prefs; @@ -2010,7 +2011,7 @@ void ui_swap_sidebar_pos(void) g_object_unref(left); g_object_unref(right);
- gtk_paned_set_position(GTK_PANED(pane), pane->allocation.width + gtk_paned_set_position(GTK_PANED(pane), gtk_widget_get_allocated_width(pane) - gtk_paned_get_position(GTK_PANED(pane))); }
@@ -2357,7 +2358,7 @@ static void on_auto_separator_item_show_hide(GtkWidget *widget, gpointer user_da { GeanyAutoSeparator *autosep = user_data;
- if (GTK_WIDGET_VISIBLE(widget)) + if (gtk_widget_get_visible(widget)) autosep->ref_count++; else autosep->ref_count--; @@ -2369,7 +2370,7 @@ static void on_auto_separator_item_destroy(GtkWidget *widget, gpointer user_data { GeanyAutoSeparator *autosep = user_data;
- /* GTK_WIDGET_VISIBLE won't work now the widget is being destroyed, + /* gtk_widget_get_visible() won't work now the widget is being destroyed, * so assume widget was visible */ autosep->ref_count--; autosep->ref_count = MAX(autosep->ref_count, 0); @@ -2388,7 +2389,7 @@ void ui_auto_separator_add_ref(GeanyAutoSeparator *autosep, GtkWidget *item) g_signal_connect(autosep->widget, "destroy", G_CALLBACK(gtk_widget_destroyed), &autosep->widget);
- if (GTK_WIDGET_VISIBLE(item)) + if (gtk_widget_get_visible(item)) { autosep->ref_count++; auto_separator_update(autosep);
Modified: src/vte.c 3 files changed, 2 insertions(+), 1 deletions(-) =================================================================== @@ -49,6 +49,7 @@ #include "geanywraplabel.h" #include "editor.h" #include "sciwrappers.h" +#include "gtkcompat.h"
VteInfo vte_info; @@ -252,7 +253,7 @@ static void create_vte(void)
vc->vte = vte = vf->vte_terminal_new(); scrollbar = gtk_vscrollbar_new(GTK_ADJUSTMENT(VTE_TERMINAL(vte)->adjustment)); - GTK_WIDGET_UNSET_FLAGS(scrollbar, GTK_CAN_FOCUS); + gtk_widget_set_can_focus(scrollbar, FALSE);
/* create menu now so copy/paste shortcuts work */ vc->menu = vte_create_popup_menu();
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).