diff --git a/ChangeLog b/ChangeLog index 3f4fae4c7c..f2ed6a9668 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,26 @@ +2003-10-24 Sven Neumann + + * app/tools/Makefile.am + * app/tools/gimphistogramoptions.[ch]: new tool options class + GimpHistogramOptions, derived from GimpColorOptions. + + * app/tools/gimpcoloroptions.c (gimp_color_options_gui): add + gimp_histogram_options_gui() when called with GimpHistogramOptions. + This a bit weird since the class hierarchy is the other way around + but it makes things easier. + + * app/tools/gimphistogramtool.c + * app/tools/gimplevelstool.c + * app/tools/gimpthresholdtool.c: use GimpHistogramOptions and + connect the histogram views to the "histogram-scale" property. + Perhaps not perfect GUI-wise but it let's you choose the histogram + scale and stores this setting per tool. Fixes bug #125306. + + * app/widgets/gimphistogramview.c: prefixed property names with + "histogram-" so they match the GimpHistogramOptions property. + + * app/widgets/gimphistogrambox.c: minor cleanup. + 2003-10-24 Sven Neumann * themes/Default/images/Makefile.am diff --git a/app/tools/Makefile.am b/app/tools/Makefile.am index aa7b4b9c7b..62591a603b 100644 --- a/app/tools/Makefile.am +++ b/app/tools/Makefile.am @@ -66,6 +66,8 @@ libapptools_a_sources = \ gimpfuzzyselecttool.h \ gimphistogramtool.c \ gimphistogramtool.h \ + gimphistogramoptions.c \ + gimphistogramoptions.h \ gimphuesaturationtool.c \ gimphuesaturationtool.h \ gimpimagemaptool.c \ diff --git a/app/tools/gimpcoloroptions.c b/app/tools/gimpcoloroptions.c index 894609d05f..365f45ef50 100644 --- a/app/tools/gimpcoloroptions.c +++ b/app/tools/gimpcoloroptions.c @@ -28,6 +28,7 @@ #include "widgets/gimppropwidgets.h" +#include "gimphistogramoptions.h" #include "gimpcoloroptions.h" #include "gimptooloptions-gui.h" @@ -169,7 +170,10 @@ gimp_color_options_gui (GimpToolOptions *tool_options) GtkWidget *table; GtkWidget *button; - vbox = gimp_tool_options_gui (tool_options); + if (GIMP_IS_HISTOGRAM_OPTIONS (tool_options)) + vbox = gimp_histogram_options_gui (tool_options); + else + vbox = gimp_tool_options_gui (tool_options); /* the sample average options */ frame = gtk_frame_new (NULL); diff --git a/app/tools/gimphistogramoptions.c b/app/tools/gimphistogramoptions.c new file mode 100644 index 0000000000..285598c7f3 --- /dev/null +++ b/app/tools/gimphistogramoptions.c @@ -0,0 +1,199 @@ +/* The GIMP -- an image manipulation program + * Copyright (C) 1995-2001 Spencer Kimball, Peter Mattis, and others + * + * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#include "config.h" + +#include + +#include "tools-types.h" + +#include "config/gimpconfig-params.h" + +#include "widgets/gimphistogramview.h" +#include "widgets/gimppropwidgets.h" + +#include "gimphistogramoptions.h" +#include "gimptooloptions-gui.h" + +#include "gimp-intl.h" + + +enum +{ + PROP_0, + PROP_SCALE +}; + + +static void gimp_histogram_options_class_init (GimpHistogramOptionsClass *options_class); + +static void gimp_histogram_options_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec); +static void gimp_histogram_options_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec); + +static void gimp_histogram_options_scale_notify (GObject *src, + GParamSpec *pspec, + GObject *dest); + + +static GimpColorOptionsClass *parent_class = NULL; + + +GType +gimp_histogram_options_get_type (void) +{ + static GType type = 0; + + if (! type) + { + static const GTypeInfo info = + { + sizeof (GimpHistogramOptionsClass), + (GBaseInitFunc) NULL, + (GBaseFinalizeFunc) NULL, + (GClassInitFunc) gimp_histogram_options_class_init, + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof (GimpHistogramOptions), + 0, /* n_preallocs */ + NULL /* instance_init */ + }; + + type = g_type_register_static (GIMP_TYPE_COLOR_OPTIONS, + "GimpHistogramOptions", + &info, 0); + } + + return type; +} + +static void +gimp_histogram_options_class_init (GimpHistogramOptionsClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + parent_class = g_type_class_peek_parent (klass); + + object_class->set_property = gimp_histogram_options_set_property; + object_class->get_property = gimp_histogram_options_get_property; + + GIMP_CONFIG_INSTALL_PROP_ENUM (object_class, PROP_SCALE, + "histogram-scale", NULL, + GIMP_TYPE_HISTOGRAM_SCALE, + GIMP_HISTOGRAM_SCALE_LOGARITHMIC, + 0); +} + +static void +gimp_histogram_options_set_property (GObject *object, + guint property_id, + const GValue *value, + GParamSpec *pspec) +{ + GimpHistogramOptions *options = GIMP_HISTOGRAM_OPTIONS (object); + + switch (property_id) + { + case PROP_SCALE: + options->scale = g_value_get_enum (value); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +static void +gimp_histogram_options_get_property (GObject *object, + guint property_id, + GValue *value, + GParamSpec *pspec) +{ + GimpHistogramOptions *options = GIMP_HISTOGRAM_OPTIONS (object); + + switch (property_id) + { + case PROP_SCALE: + g_value_set_enum (value, options->scale); + break; + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); + break; + } +} + +GtkWidget * +gimp_histogram_options_gui (GimpToolOptions *tool_options) +{ + GObject *config = G_OBJECT (tool_options); + GtkWidget *vbox; + GtkWidget *frame; + + vbox = gimp_tool_options_gui (tool_options); + + frame = gimp_prop_enum_radio_frame_new (config, "histogram-scale", + _("Histogram Scale"), 0, 0); + gtk_box_pack_start (GTK_BOX (vbox), frame, TRUE, TRUE, 0); + gtk_widget_show (frame); + + return vbox; +} + +void +gimp_histogram_options_connect_view (GimpHistogramOptions *options, + GimpHistogramView *view) +{ + g_return_if_fail (GIMP_IS_HISTOGRAM_OPTIONS (options)); + g_return_if_fail (GIMP_IS_HISTOGRAM_VIEW (view)); + + g_signal_connect_object (options, "notify::histogram-scale", + G_CALLBACK (gimp_histogram_options_scale_notify), + view, 0); + g_signal_connect_object (view, "notify::histogram-scale", + G_CALLBACK (gimp_histogram_options_scale_notify), + options, 0); + + g_object_notify (G_OBJECT (options), "histogram-scale"); +} + +static void +gimp_histogram_options_scale_notify (GObject *src, + GParamSpec *pspec, + GObject *dest) +{ + GValue value = { 0, }; + + g_return_if_fail (g_type_is_a (pspec->value_type, + GIMP_TYPE_HISTOGRAM_SCALE)); + + g_value_init (&value, pspec->value_type); + + g_object_get_property (src, pspec->name, &value); + + g_signal_handlers_block_by_func (dest, + gimp_histogram_options_scale_notify, src); + g_object_set_property (dest, pspec->name, &value); + g_signal_handlers_unblock_by_func (dest, + gimp_histogram_options_scale_notify, src); + + g_value_unset (&value); +} diff --git a/app/tools/gimphistogramoptions.h b/app/tools/gimphistogramoptions.h new file mode 100644 index 0000000000..880e07ded7 --- /dev/null +++ b/app/tools/gimphistogramoptions.h @@ -0,0 +1,52 @@ +/* The GIMP -- an image manipulation program + * Copyright (C) 1995 Spencer Kimball and Peter Mattis + * + * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef __GIMP_HISTOGRAM_OPTIONS_H__ +#define __GIMP_HISTOGRAM_OPTIONS_H__ + + +#include "gimpcoloroptions.h" + + +#define GIMP_TYPE_HISTOGRAM_OPTIONS (gimp_histogram_options_get_type ()) +#define GIMP_HISTOGRAM_OPTIONS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_HISTOGRAM_OPTIONS, GimpHistogramOptions)) +#define GIMP_HISTOGRAM_OPTIONS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_HISTOGRAM_OPTIONS, GimpHistogramOptionsClass)) +#define GIMP_IS_HISTOGRAM_OPTIONS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_HISTOGRAM_OPTIONS)) +#define GIMP_IS_HISTOGRAM_OPTIONS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_HISTOGRAM_OPTIONS)) +#define GIMP_HISTOGRAM_OPTIONS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_HISTOGRAM_OPTIONS, GimpHistogramOptionsClass)) + + +typedef struct _GimpHistogramOptions GimpHistogramOptions; +typedef struct _GimpToolOptionsClass GimpHistogramOptionsClass; + +struct _GimpHistogramOptions +{ + GimpColorOptions parent_instance; + + GimpHistogramScale scale; +}; + + +GType gimp_histogram_options_get_type (void) G_GNUC_CONST; + +GtkWidget * gimp_histogram_options_gui (GimpToolOptions *tool_options); +void gimp_histogram_options_connect_view (GimpHistogramOptions *options, + GimpHistogramView *view); + + +#endif /* __GIMP_HISTOGRAM_OPTIONS_H__ */ diff --git a/app/tools/gimphistogramtool.c b/app/tools/gimphistogramtool.c index 51793e9102..7554e8b73a 100644 --- a/app/tools/gimphistogramtool.c +++ b/app/tools/gimphistogramtool.c @@ -45,6 +45,7 @@ #include "display/gimpdisplay.h" +#include "gimphistogramoptions.h" #include "gimphistogramtool.h" #include "tool_manager.h" @@ -116,7 +117,8 @@ gimp_histogram_tool_register (GimpToolRegisterCallback callback, gpointer data) { (* callback) (GIMP_TYPE_HISTOGRAM_TOOL, - G_TYPE_NONE, NULL, + GIMP_TYPE_HISTOGRAM_OPTIONS, + gimp_histogram_options_gui, 0, "gimp-histogram-tool", _("Histogram"), @@ -158,9 +160,7 @@ gimp_histogram_tool_get_type (void) static void gimp_histogram_tool_class_init (GimpHistogramToolClass *klass) { - GimpToolClass *tool_class; - - tool_class = GIMP_TOOL_CLASS (klass); + GimpToolClass *tool_class = GIMP_TOOL_CLASS (klass); parent_class = g_type_class_peek_parent (klass); @@ -357,6 +357,9 @@ histogram_tool_dialog_new (GimpToolInfo *tool_info) htd->histogram_box = GIMP_HISTOGRAM_BOX (gimp_histogram_box_new (_("Intensity Range:"))); + gimp_histogram_options_connect_view (GIMP_HISTOGRAM_OPTIONS (tool_info->tool_options), + htd->histogram_box->histogram); + /* The option menu for selecting channels */ hbox = gtk_hbox_new (FALSE, 6); gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0); @@ -368,7 +371,7 @@ histogram_tool_dialog_new (GimpToolInfo *tool_info) htd->channel_menu = gimp_prop_enum_option_menu_new (G_OBJECT (htd->histogram_box->histogram), - "channel", 0, 0); + "histogram-channel", 0, 0); gimp_enum_option_menu_set_stock_prefix (GTK_OPTION_MENU (htd->channel_menu), "gimp-channel"); gtk_box_pack_start (GTK_BOX (hbox), htd->channel_menu, TRUE, TRUE, 0); @@ -377,7 +380,7 @@ histogram_tool_dialog_new (GimpToolInfo *tool_info) /* The option menu for selecting the histogram scale */ menu = gimp_prop_enum_stock_box_new (G_OBJECT (htd->histogram_box->histogram), - "scale", "gimp-histogram", 0, 0); + "histogram-scale", "gimp-histogram", 0, 0); gtk_box_pack_end (GTK_BOX (hbox), menu, FALSE, FALSE, 0); gtk_widget_show (menu); diff --git a/app/tools/gimplevelstool.c b/app/tools/gimplevelstool.c index a732f5e3df..cb2e06e63c 100644 --- a/app/tools/gimplevelstool.c +++ b/app/tools/gimplevelstool.c @@ -55,7 +55,7 @@ #include "display/gimpdisplay.h" -#include "gimpcoloroptions.h" +#include "gimphistogramoptions.h" #include "gimplevelstool.h" #include "gimptoolcontrol.h" @@ -156,7 +156,7 @@ gimp_levels_tool_register (GimpToolRegisterCallback callback, gpointer data) { (* callback) (GIMP_TYPE_LEVELS_TOOL, - GIMP_TYPE_COLOR_OPTIONS, + GIMP_TYPE_HISTOGRAM_OPTIONS, gimp_color_options_gui, 0, "gimp-levels-tool", @@ -385,20 +385,21 @@ gimp_levels_tool_color_picker_new (GimpLevelsTool *tool, static void gimp_levels_tool_dialog (GimpImageMapTool *image_map_tool) { - GimpLevelsTool *l_tool; - GtkWidget *vbox; - GtkWidget *vbox2; - GtkWidget *vbox3; - GtkWidget *hbox; - GtkWidget *hbox2; - GtkWidget *label; - GtkWidget *menu; - GtkWidget *frame; - GtkWidget *channel_hbox; - GtkWidget *hbbox; - GtkWidget *button; - GtkWidget *spinbutton; - GtkObject *data; + GimpLevelsTool *l_tool; + GimpToolOptions *tool_options; + GtkWidget *vbox; + GtkWidget *vbox2; + GtkWidget *vbox3; + GtkWidget *hbox; + GtkWidget *hbox2; + GtkWidget *label; + GtkWidget *menu; + GtkWidget *frame; + GtkWidget *channel_hbox; + GtkWidget *hbbox; + GtkWidget *button; + GtkWidget *spinbutton; + GtkObject *data; l_tool = GIMP_LEVELS_TOOL (image_map_tool); @@ -465,6 +466,10 @@ gimp_levels_tool_dialog (GimpImageMapTool *image_map_tool) gtk_container_add (GTK_CONTAINER (frame), l_tool->hist_view); gtk_widget_show (GTK_WIDGET (l_tool->hist_view)); + tool_options = GIMP_TOOL (l_tool)->tool_info->tool_options; + gimp_histogram_options_connect_view (GIMP_HISTOGRAM_OPTIONS (tool_options), + GIMP_HISTOGRAM_VIEW (l_tool->hist_view)); + /* The input levels drawing area */ hbox = gtk_hbox_new (TRUE, 2); gtk_box_pack_start (GTK_BOX (vbox2), hbox, TRUE, FALSE, 0); diff --git a/app/tools/gimpthresholdtool.c b/app/tools/gimpthresholdtool.c index 06013b7c7e..82b652bd66 100644 --- a/app/tools/gimpthresholdtool.c +++ b/app/tools/gimpthresholdtool.c @@ -42,6 +42,7 @@ #include "display/gimpdisplay.h" +#include "gimphistogramoptions.h" #include "gimpthresholdtool.h" #include "gimp-intl.h" @@ -83,7 +84,8 @@ gimp_threshold_tool_register (GimpToolRegisterCallback callback, gpointer data) { (* callback) (GIMP_TYPE_THRESHOLD_TOOL, - G_TYPE_NONE, NULL, + GIMP_TYPE_HISTOGRAM_OPTIONS, + gimp_histogram_options_gui, 0, "gimp-threshold-tool", _("Threshold"), @@ -164,9 +166,7 @@ gimp_threshold_tool_init (GimpThresholdTool *t_tool) static void gimp_threshold_tool_finalize (GObject *object) { - GimpThresholdTool *t_tool; - - t_tool = GIMP_THRESHOLD_TOOL (object); + GimpThresholdTool *t_tool = GIMP_THRESHOLD_TOOL (object); if (t_tool->threshold) { @@ -233,9 +233,7 @@ gimp_threshold_tool_initialize (GimpTool *tool, static void gimp_threshold_tool_map (GimpImageMapTool *image_map_tool) { - GimpThresholdTool *t_tool; - - t_tool = GIMP_THRESHOLD_TOOL (image_map_tool); + GimpThresholdTool *t_tool = GIMP_THRESHOLD_TOOL (image_map_tool); gimp_image_map_apply (image_map_tool->image_map, threshold, @@ -251,6 +249,7 @@ static void gimp_threshold_tool_dialog (GimpImageMapTool *image_map_tool) { GimpThresholdTool *t_tool; + GimpToolOptions *tool_options; GtkWidget *box; t_tool = GIMP_THRESHOLD_TOOL (image_map_tool); @@ -264,14 +263,16 @@ gimp_threshold_tool_dialog (GimpImageMapTool *image_map_tool) g_signal_connect (t_tool->histogram_box->histogram, "range_changed", G_CALLBACK (gimp_threshold_tool_histogram_range), t_tool); + + tool_options = GIMP_TOOL (t_tool)->tool_info->tool_options; + gimp_histogram_options_connect_view (GIMP_HISTOGRAM_OPTIONS (tool_options), + t_tool->histogram_box->histogram); } static void gimp_threshold_tool_reset (GimpImageMapTool *image_map_tool) { - GimpThresholdTool *t_tool; - - t_tool = GIMP_THRESHOLD_TOOL (image_map_tool); + GimpThresholdTool *t_tool = GIMP_THRESHOLD_TOOL (image_map_tool); t_tool->threshold->low_threshold = 127.0; t_tool->threshold->high_threshold = 255.0; diff --git a/app/widgets/gimphistogrambox.c b/app/widgets/gimphistogrambox.c index a9b27dbe96..a4dad69178 100644 --- a/app/widgets/gimphistogrambox.c +++ b/app/widgets/gimphistogrambox.c @@ -194,8 +194,11 @@ gimp_histogram_box_finalize (GObject *object) { GimpHistogramBox *box = GIMP_HISTOGRAM_BOX (object); - g_free (box->gradient_buf); - box->gradient_buf = NULL; + if (box->gradient_buf) + { + g_free (box->gradient_buf); + box->gradient_buf = NULL; + } G_OBJECT_CLASS (parent_class)->finalize (object); } @@ -318,9 +321,7 @@ gimp_histogram_box_gradient_expose (GtkWidget *widget, GtkWidget * gimp_histogram_box_new (const gchar *label) { - GimpHistogramBox *box; - - box = g_object_new (GIMP_TYPE_HISTOGRAM_BOX, NULL); + GimpHistogramBox *box = g_object_new (GIMP_TYPE_HISTOGRAM_BOX, NULL); gtk_label_set_text (GTK_LABEL (box->label), label); diff --git a/app/widgets/gimphistogramview.c b/app/widgets/gimphistogramview.c index 9dfc2b0f2e..011e954241 100644 --- a/app/widgets/gimphistogramview.c +++ b/app/widgets/gimphistogramview.c @@ -125,14 +125,14 @@ gimp_histogram_view_class_init (GimpHistogramViewClass *klass) klass->range_changed = NULL; g_object_class_install_property (object_class, PROP_CHANNEL, - g_param_spec_enum ("channel", NULL, NULL, + g_param_spec_enum ("histogram-channel", NULL, NULL, GIMP_TYPE_HISTOGRAM_CHANNEL, GIMP_HISTOGRAM_VALUE, G_PARAM_READWRITE | G_PARAM_CONSTRUCT)); g_object_class_install_property (object_class, PROP_SCALE, - g_param_spec_enum ("scale", NULL, NULL, + g_param_spec_enum ("histogram-scale", NULL, NULL, GIMP_TYPE_HISTOGRAM_SCALE, GIMP_HISTOGRAM_SCALE_LOGARITHMIC, G_PARAM_READWRITE | @@ -207,14 +207,12 @@ static gboolean gimp_histogram_view_expose (GtkWidget *widget, GdkEventExpose *event) { - GimpHistogramView *view; + GimpHistogramView *view = GIMP_HISTOGRAM_VIEW (widget); gint x; gint x1, x2; gint width, height; gdouble max; - view = GIMP_HISTOGRAM_VIEW (widget); - if (!view->histogram) return TRUE; @@ -301,13 +299,11 @@ static gint gimp_histogram_view_events (GimpHistogramView *view, GdkEvent *event) { - GtkWidget *widget; + GtkWidget *widget = GTK_WIDGET (view); GdkEventButton *bevent; GdkEventMotion *mevent; gint width; - widget = GTK_WIDGET (view); - switch (event->type) { case GDK_BUTTON_PRESS: @@ -368,9 +364,7 @@ gimp_histogram_view_new (gint width, gint height, gboolean range) { - GtkWidget *view; - - view = g_object_new (GIMP_TYPE_HISTOGRAM_VIEW, NULL); + GtkWidget *view = g_object_new (GIMP_TYPE_HISTOGRAM_VIEW, NULL); gtk_widget_set_size_request (view, width + 2, height + 2); @@ -430,7 +424,7 @@ gimp_histogram_view_set_channel (GimpHistogramView *view, view->channel = channel; - g_object_notify (G_OBJECT (view), "channel"); + g_object_notify (G_OBJECT (view), "histogram-channel"); gtk_widget_queue_draw (GTK_WIDGET (view)); @@ -455,7 +449,7 @@ gimp_histogram_view_set_scale (GimpHistogramView *view, view->scale = scale; - g_object_notify (G_OBJECT (view), "scale"); + g_object_notify (G_OBJECT (view), "histogram-scale"); gtk_widget_queue_draw (GTK_WIDGET (view)); }