From 82aa4084abd2b8d87bce345185aab9087fb27c8a Mon Sep 17 00:00:00 2001 From: Michael Natterer Date: Thu, 24 Sep 2009 09:35:34 +0200 Subject: [PATCH] Add gimp_statusbar_set_shell() Reconnect signals when a new shell is set; reorganize internal code to not set up permanent connections to one specific shell. --- app/display/gimpstatusbar.c | 47 ++++++++++++++++++++++++++++++------- app/display/gimpstatusbar.h | 2 ++ 2 files changed, 40 insertions(+), 9 deletions(-) diff --git a/app/display/gimpstatusbar.c b/app/display/gimpstatusbar.c index 99756d47bd..94c0288afe 100644 --- a/app/display/gimpstatusbar.c +++ b/app/display/gimpstatusbar.c @@ -105,6 +105,8 @@ static void gimp_statusbar_unit_changed (GimpUnitComboBox *combo, GimpStatusbar *statusbar); static void gimp_statusbar_scale_changed (GimpScaleComboBox *combo, GimpStatusbar *statusbar); +static void gimp_statusbar_scale_activated (GimpScaleComboBox *combo, + GimpStatusbar *statusbar); static void gimp_statusbar_shell_scaled (GimpDisplayShell *shell, GimpStatusbar *statusbar); static guint gimp_statusbar_get_context_id (GimpStatusbar *statusbar, @@ -207,6 +209,10 @@ gimp_statusbar_init (GimpStatusbar *statusbar) G_CALLBACK (gimp_statusbar_scale_changed), statusbar); + g_signal_connect (statusbar->scale_combo, "entry-activated", + G_CALLBACK (gimp_statusbar_scale_activated), + statusbar); + /* put the label back into our hbox */ gtk_box_pack_start (GTK_BOX (hbox), GTK_STATUSBAR (statusbar)->label, TRUE, TRUE, 1); @@ -651,19 +657,35 @@ gimp_statusbar_new (GimpDisplayShell *shell) statusbar = g_object_new (GIMP_TYPE_STATUSBAR, NULL); - statusbar->shell = shell; - - g_signal_connect_object (shell, "scaled", - G_CALLBACK (gimp_statusbar_shell_scaled), - statusbar, 0); - - g_signal_connect_object (statusbar->scale_combo, "entry-activated", - G_CALLBACK (gtk_widget_grab_focus), - shell->canvas, G_CONNECT_SWAPPED); + gimp_statusbar_set_shell (statusbar, shell); return GTK_WIDGET (statusbar); } +void +gimp_statusbar_set_shell (GimpStatusbar *statusbar, + GimpDisplayShell *shell) +{ + g_return_if_fail (GIMP_IS_STATUSBAR (statusbar)); + g_return_if_fail (GIMP_IS_DISPLAY_SHELL (shell)); + + if (shell == statusbar->shell) + return; + + if (statusbar->shell) + { + g_signal_handlers_disconnect_by_func (statusbar->shell, + gimp_statusbar_shell_scaled, + statusbar); + } + + statusbar->shell = shell; + + g_signal_connect_object (statusbar->shell, "scaled", + G_CALLBACK (gimp_statusbar_shell_scaled), + statusbar, 0); +} + gboolean gimp_statusbar_get_visible (GimpStatusbar *statusbar) { @@ -1391,6 +1413,13 @@ gimp_statusbar_scale_changed (GimpScaleComboBox *combo, GIMP_ZOOM_FOCUS_BEST_GUESS); } +static void +gimp_statusbar_scale_activated (GimpScaleComboBox *combo, + GimpStatusbar *statusbar) +{ + gtk_widget_grab_focus (statusbar->shell->canvas); +} + static guint gimp_statusbar_get_context_id (GimpStatusbar *statusbar, const gchar *context) diff --git a/app/display/gimpstatusbar.h b/app/display/gimpstatusbar.h index 6582e24f5d..bebc2edc92 100644 --- a/app/display/gimpstatusbar.h +++ b/app/display/gimpstatusbar.h @@ -73,6 +73,8 @@ struct _GimpStatusbarClass GType gimp_statusbar_get_type (void) G_GNUC_CONST; GtkWidget * gimp_statusbar_new (GimpDisplayShell *shell); +void gimp_statusbar_set_shell (GimpStatusbar *statusbar, + GimpDisplayShell *shell); gboolean gimp_statusbar_get_visible (GimpStatusbar *statusbar); void gimp_statusbar_set_visible (GimpStatusbar *statusbar,