From e785fa4cdaf24545c738cc7cf0d0299854b26435 Mon Sep 17 00:00:00 2001 From: Michael Natterer Date: Tue, 1 Jun 1999 23:09:48 +0000 Subject: [PATCH] app/disp_callbacks.c app/gimpset.[ch] app/gimpsetP.h applied Simon's 1999-06-02 Michael Natterer * app/disp_callbacks.c * app/gimpset.[ch] * app/gimpsetP.h * app/layers_dialog.c: applied Simon's active image patch. GimpSet has an "active_changed" signal now. The image_context emits it whenever there is a button or key event in the gdisplay and the L&C dlg. connects to it for the new auto-update feature. --- ChangeLog | 11 ++++++ app/disp_callbacks.c | 7 ++++ app/display/gimpdisplay-callbacks.c | 7 ++++ app/display/gimpdisplayshell-callbacks.c | 7 ++++ app/gimpset.c | 22 ++++++++++++ app/gimpset.h | 5 ++- app/gimpsetP.h | 1 + app/gui/layers-dialog.c | 45 ++++++++++++++++++++++++ app/layers_dialog.c | 45 ++++++++++++++++++++++++ 9 files changed, 149 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index a956d8bb36..6306fdf852 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +1999-06-02 Michael Natterer + + * app/disp_callbacks.c + * app/gimpset.[ch] + * app/gimpsetP.h + * app/layers_dialog.c: applied Simon's + active image patch. + GimpSet has an "active_changed" signal now. The image_context + emits it whenever there is a button or key event in the gdisplay + and the L&C dlg. connects to it for the new auto-update feature. + 1999-06-01 Michael Natterer * app/commands.[ch] diff --git a/app/disp_callbacks.c b/app/disp_callbacks.c index 013d1839db..015da4d09b 100644 --- a/app/disp_callbacks.c +++ b/app/disp_callbacks.c @@ -25,6 +25,7 @@ #include "gdisplay.h" #include "general.h" #include "gimprc.h" +#include "gimpset.h" #include "interface.h" #include "layer_select.h" #include "move.h" @@ -196,6 +197,9 @@ gdisplay_canvas_events (GtkWidget *canvas, bevent = (GdkEventButton *) event; state = bevent->state; + /* Set the active Image to the image where the user clicked */ + gimp_set_set_active(image_context, gdisp->gimage); + switch (bevent->button) { case 1: @@ -384,6 +388,9 @@ gdisplay_canvas_events (GtkWidget *canvas, kevent = (GdkEventKey *) event; state = kevent->state; + /* Set the active Image to the image where the user typed */ + gimp_set_set_active(image_context, gdisp->gimage); + switch (kevent->keyval) { case GDK_Left: case GDK_Right: diff --git a/app/display/gimpdisplay-callbacks.c b/app/display/gimpdisplay-callbacks.c index 013d1839db..015da4d09b 100644 --- a/app/display/gimpdisplay-callbacks.c +++ b/app/display/gimpdisplay-callbacks.c @@ -25,6 +25,7 @@ #include "gdisplay.h" #include "general.h" #include "gimprc.h" +#include "gimpset.h" #include "interface.h" #include "layer_select.h" #include "move.h" @@ -196,6 +197,9 @@ gdisplay_canvas_events (GtkWidget *canvas, bevent = (GdkEventButton *) event; state = bevent->state; + /* Set the active Image to the image where the user clicked */ + gimp_set_set_active(image_context, gdisp->gimage); + switch (bevent->button) { case 1: @@ -384,6 +388,9 @@ gdisplay_canvas_events (GtkWidget *canvas, kevent = (GdkEventKey *) event; state = kevent->state; + /* Set the active Image to the image where the user typed */ + gimp_set_set_active(image_context, gdisp->gimage); + switch (kevent->keyval) { case GDK_Left: case GDK_Right: diff --git a/app/display/gimpdisplayshell-callbacks.c b/app/display/gimpdisplayshell-callbacks.c index 013d1839db..015da4d09b 100644 --- a/app/display/gimpdisplayshell-callbacks.c +++ b/app/display/gimpdisplayshell-callbacks.c @@ -25,6 +25,7 @@ #include "gdisplay.h" #include "general.h" #include "gimprc.h" +#include "gimpset.h" #include "interface.h" #include "layer_select.h" #include "move.h" @@ -196,6 +197,9 @@ gdisplay_canvas_events (GtkWidget *canvas, bevent = (GdkEventButton *) event; state = bevent->state; + /* Set the active Image to the image where the user clicked */ + gimp_set_set_active(image_context, gdisp->gimage); + switch (bevent->button) { case 1: @@ -384,6 +388,9 @@ gdisplay_canvas_events (GtkWidget *canvas, kevent = (GdkEventKey *) event; state = kevent->state; + /* Set the active Image to the image where the user typed */ + gimp_set_set_active(image_context, gdisp->gimage); + switch (kevent->keyval) { case GDK_Left: case GDK_Right: diff --git a/app/gimpset.c b/app/gimpset.c index 63feb04619..98d790d1f7 100644 --- a/app/gimpset.c +++ b/app/gimpset.c @@ -20,6 +20,7 @@ enum { ADD, REMOVE, + ACTIVE_CHANGED, LAST_SIGNAL }; @@ -53,6 +54,7 @@ gimp_set_init (GimpSet* set) set->list=NULL; set->type=GTK_TYPE_OBJECT; set->handlers=g_array_new(FALSE, FALSE, sizeof(GimpSetHandler)); + set->active_element=NULL; } static void @@ -69,6 +71,8 @@ gimp_set_class_init (GimpSetClass* klass) gimp_signal_new ("add", GTK_RUN_FIRST, type, 0, gimp_sigtype_pointer); gimp_set_signals[REMOVE]= gimp_signal_new ("remove", GTK_RUN_FIRST, type, 0, gimp_sigtype_pointer); + gimp_set_signals[ACTIVE_CHANGED]= + gimp_signal_new ("active_changed", GTK_RUN_FIRST, type, 0, gimp_sigtype_pointer); gtk_object_class_add_signals (object_class, gimp_set_signals, LAST_SIGNAL); @@ -222,6 +226,24 @@ gimp_set_type (GimpSet* set){ return set->type; } +void +gimp_set_set_active (GimpSet* set, gpointer ob) +{ + if (ob != set->active_element && gimp_set_have(set, ob)) { + /* g_warning("Gimp_Set got new active element"); */ + set->active_element = ob; + gtk_signal_emit (GTK_OBJECT(set), gimp_set_signals[ACTIVE_CHANGED], ob); + } +} + +gpointer +gimp_set_get_active(GimpSet* set) +{ + if (gimp_set_have(set, set->active_element)) + return set->active_element; + return NULL; +} + GimpSetHandlerId gimp_set_add_handler(GimpSet* set, const gchar* signame, GtkSignalFunc handler, gpointer user_data){ diff --git a/app/gimpset.h b/app/gimpset.h index 313274ee45..a8ffac5995 100644 --- a/app/gimpset.h +++ b/app/gimpset.h @@ -27,7 +27,7 @@ /* Signals: add remove - member_modified + active_changed */ typedef guint GimpSetHandlerId; @@ -43,6 +43,9 @@ void gimp_set_foreach(GimpSet* gimpset, GFunc func, gpointer user_data); gint gimp_set_size (GimpSet* gimpset); +void gimp_set_set_active(GimpSet* gimpset, gpointer ob); +gpointer gimp_set_get_active(GimpSet* gimpset); + GimpSetHandlerId gimp_set_add_handler (GimpSet* set, const gchar* signame, GtkSignalFunc handler, diff --git a/app/gimpsetP.h b/app/gimpsetP.h index 9d92dd8cd7..b2b1cba63f 100644 --- a/app/gimpsetP.h +++ b/app/gimpsetP.h @@ -10,6 +10,7 @@ struct _GimpSet{ GSList* list; GArray* handlers; gboolean weak; + gpointer active_element; }; struct _GimpSetClass{ diff --git a/app/gui/layers-dialog.c b/app/gui/layers-dialog.c index 44ba6646d2..b19a59982e 100644 --- a/app/gui/layers-dialog.c +++ b/app/gui/layers-dialog.c @@ -104,6 +104,7 @@ struct _LayersDialog { GimpImage* gimage; Layer * active_layer; Channel * active_channel; + gboolean auto_follow_active; Layer * floating_sel; GSList * layer_widgets; }; @@ -172,9 +173,11 @@ static void layers_dialog_flatten_image_callback (GtkWidget *, gpointer); static void layers_dialog_alpha_select_callback (GtkWidget *, gpointer); static void layers_dialog_mask_select_callback (GtkWidget *, gpointer); static void layers_dialog_add_alpha_channel_callback (GtkWidget *, gpointer); +static gint lc_dialog_auto_callback (GtkWidget *, gpointer); static gint lc_dialog_close_callback (GtkWidget *, gpointer); static void lc_dialog_update_cb (GimpSet *, GimpImage *, gpointer); +static void lc_dialog_change_image (GimpSet *, GimpImage *, gpointer); /* layer widget function prototypes */ static LayerWidget *layer_widget_get_ID (Layer *); @@ -314,6 +317,7 @@ void lc_dialog_create (GimpImage* gimage) { GtkWidget *util_box; + GtkWidget *auto_button; GtkWidget *button; GtkWidget *label; GtkWidget *notebook; @@ -363,6 +367,16 @@ lc_dialog_create (GimpImage* gimage) gtk_option_menu_set_history (GTK_OPTION_MENU (image_option_menu), default_index); gtk_widget_show (label); + /* The Auto-button */ + + auto_button = gtk_toggle_button_new_with_label (_("Auto")); + gtk_box_pack_start (GTK_BOX (util_box), auto_button, FALSE, FALSE, 2); + gtk_signal_connect_object (GTK_OBJECT (auto_button), "clicked", + (GtkSignalFunc) lc_dialog_auto_callback, + GTK_OBJECT(auto_button)); + gtk_widget_show (auto_button); + /* State will be set, when LayersD exists (see below) */ + gtk_widget_show (util_box); separator = gtk_hseparator_new (); @@ -379,6 +393,10 @@ lc_dialog_create (GimpImage* gimage) label); gtk_widget_show (label); + /* Now layersD exists, we can set the Auto-togglebutton */ + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (auto_button), + layersD->auto_follow_active); + label = gtk_label_new (_("Channels")); gtk_notebook_append_page (GTK_NOTEBOOK (notebook), channels_dialog_create (), @@ -424,6 +442,8 @@ lc_dialog_create (GimpImage* gimage) GTK_SIGNAL_FUNC (lc_dialog_update_cb), NULL); gtk_signal_connect (GTK_OBJECT (image_context), "remove", GTK_SIGNAL_FUNC(lc_dialog_update_cb), NULL); + gtk_signal_connect (GTK_OBJECT (image_context), "active_changed", + GTK_SIGNAL_FUNC(lc_dialog_change_image), NULL); layers_dialog_update (gimage); channels_dialog_update (gimage); @@ -1988,6 +2008,16 @@ layers_dialog_add_alpha_channel_callback (GtkWidget *w, } +static gint +lc_dialog_auto_callback (GtkWidget *toggle_button, gpointer client_data) +{ + if (layersD) + layersD->auto_follow_active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toggle_button)); + + return TRUE; +} + + static gint lc_dialog_close_callback (GtkWidget *w, gpointer client_data) @@ -2010,6 +2040,21 @@ lc_dialog_update_cb (GimpSet *set, } +static void +lc_dialog_change_image (GimpSet *set, + GimpImage *gimage, + gpointer user_data) +{ + if (layersD && layersD->auto_follow_active && gimage) { + layers_dialog_update (gimage); + channels_dialog_update (gimage); + paths_dialog_update (gimage); + lc_dialog_update_image_list (); + gdisplays_flush (); + } +} + + /****************************/ /* layer widget functions */ /****************************/ diff --git a/app/layers_dialog.c b/app/layers_dialog.c index 44ba6646d2..b19a59982e 100644 --- a/app/layers_dialog.c +++ b/app/layers_dialog.c @@ -104,6 +104,7 @@ struct _LayersDialog { GimpImage* gimage; Layer * active_layer; Channel * active_channel; + gboolean auto_follow_active; Layer * floating_sel; GSList * layer_widgets; }; @@ -172,9 +173,11 @@ static void layers_dialog_flatten_image_callback (GtkWidget *, gpointer); static void layers_dialog_alpha_select_callback (GtkWidget *, gpointer); static void layers_dialog_mask_select_callback (GtkWidget *, gpointer); static void layers_dialog_add_alpha_channel_callback (GtkWidget *, gpointer); +static gint lc_dialog_auto_callback (GtkWidget *, gpointer); static gint lc_dialog_close_callback (GtkWidget *, gpointer); static void lc_dialog_update_cb (GimpSet *, GimpImage *, gpointer); +static void lc_dialog_change_image (GimpSet *, GimpImage *, gpointer); /* layer widget function prototypes */ static LayerWidget *layer_widget_get_ID (Layer *); @@ -314,6 +317,7 @@ void lc_dialog_create (GimpImage* gimage) { GtkWidget *util_box; + GtkWidget *auto_button; GtkWidget *button; GtkWidget *label; GtkWidget *notebook; @@ -363,6 +367,16 @@ lc_dialog_create (GimpImage* gimage) gtk_option_menu_set_history (GTK_OPTION_MENU (image_option_menu), default_index); gtk_widget_show (label); + /* The Auto-button */ + + auto_button = gtk_toggle_button_new_with_label (_("Auto")); + gtk_box_pack_start (GTK_BOX (util_box), auto_button, FALSE, FALSE, 2); + gtk_signal_connect_object (GTK_OBJECT (auto_button), "clicked", + (GtkSignalFunc) lc_dialog_auto_callback, + GTK_OBJECT(auto_button)); + gtk_widget_show (auto_button); + /* State will be set, when LayersD exists (see below) */ + gtk_widget_show (util_box); separator = gtk_hseparator_new (); @@ -379,6 +393,10 @@ lc_dialog_create (GimpImage* gimage) label); gtk_widget_show (label); + /* Now layersD exists, we can set the Auto-togglebutton */ + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (auto_button), + layersD->auto_follow_active); + label = gtk_label_new (_("Channels")); gtk_notebook_append_page (GTK_NOTEBOOK (notebook), channels_dialog_create (), @@ -424,6 +442,8 @@ lc_dialog_create (GimpImage* gimage) GTK_SIGNAL_FUNC (lc_dialog_update_cb), NULL); gtk_signal_connect (GTK_OBJECT (image_context), "remove", GTK_SIGNAL_FUNC(lc_dialog_update_cb), NULL); + gtk_signal_connect (GTK_OBJECT (image_context), "active_changed", + GTK_SIGNAL_FUNC(lc_dialog_change_image), NULL); layers_dialog_update (gimage); channels_dialog_update (gimage); @@ -1988,6 +2008,16 @@ layers_dialog_add_alpha_channel_callback (GtkWidget *w, } +static gint +lc_dialog_auto_callback (GtkWidget *toggle_button, gpointer client_data) +{ + if (layersD) + layersD->auto_follow_active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(toggle_button)); + + return TRUE; +} + + static gint lc_dialog_close_callback (GtkWidget *w, gpointer client_data) @@ -2010,6 +2040,21 @@ lc_dialog_update_cb (GimpSet *set, } +static void +lc_dialog_change_image (GimpSet *set, + GimpImage *gimage, + gpointer user_data) +{ + if (layersD && layersD->auto_follow_active && gimage) { + layers_dialog_update (gimage); + channels_dialog_update (gimage); + paths_dialog_update (gimage); + lc_dialog_update_image_list (); + gdisplays_flush (); + } +} + + /****************************/ /* layer widget functions */ /****************************/