diff --git a/ChangeLog b/ChangeLog index b084a9e23b..b35fcd82a6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,28 @@ +2004-04-20 Sven Neumann + + * libgimpwidgets/Makefile.am + * libgimpwidgets/gimpwidgets.h + * libgimpwidgets/gimpwidgetstypes.h + * libgimpwidgets/gimpintstore.[ch]: added a GimpIntStore, derived + from GtkListStore, to be used by GimpIntComboBox and also by the + image and drawable menus. + + * libgimpwidgets/gimpintcombobox.c: use the new GimpIntStore. + + * app/widgets/gimpenumstore.[ch]: derive from GimpIntStore, + removed API that is provided by the parent class. + + * app/widgets/gimpenumcombobox.[ch]: derive from GimpIntComboBox, + removed API that is provided by the parent class. + + * app/gui/resize-dialog.c + * app/tools/gimpcurvestool.c + * app/tools/gimplevelstool.c + * app/widgets/gimpcolorframe.c + * app/widgets/gimphistogrameditor.c + * app/widgets/gimppropwidgets.c + * app/widgets/gimpstrokeeditor.c: changed accordingly. + 2004-04-20 Sven Neumann * app/widgets/gimpenumstore.[ch] diff --git a/app/dialogs/resize-dialog.c b/app/dialogs/resize-dialog.c index aaae24b713..c57055ea20 100644 --- a/app/dialogs/resize-dialog.c +++ b/app/dialogs/resize-dialog.c @@ -709,14 +709,13 @@ resize_widget_new (GimpViewable *viewable, gtk_widget_show (label); combo = gimp_enum_combo_box_new (GIMP_TYPE_INTERPOLATION_TYPE); - gimp_enum_combo_box_set_active (GIMP_ENUM_COMBO_BOX (combo), - resize->interpolation); + gimp_int_combo_box_set_active (GIMP_INT_COMBO_BOX (combo), + resize->interpolation); + g_signal_connect (combo, "changed", - G_CALLBACK (gimp_enum_combo_box_get_active), + G_CALLBACK (gimp_int_combo_box_get_active), &resize->interpolation); - gimp_enum_combo_box_set_active (GIMP_ENUM_COMBO_BOX (combo), - resize->interpolation); gtk_box_pack_start (GTK_BOX (hbox), combo, FALSE, FALSE, 0); gtk_widget_show (combo); @@ -896,8 +895,8 @@ response_callback (GtkWidget *widget, resize->interpolation = resize->gimage->gimp->config->interpolation_type; - gimp_enum_combo_box_set_active (GIMP_ENUM_COMBO_BOX (private->interpolation_menu), - resize->interpolation); + gimp_int_combo_box_set_active (GIMP_INT_COMBO_BOX (private->interpolation_menu), + resize->interpolation); } break; diff --git a/app/gui/resize-dialog.c b/app/gui/resize-dialog.c index aaae24b713..c57055ea20 100644 --- a/app/gui/resize-dialog.c +++ b/app/gui/resize-dialog.c @@ -709,14 +709,13 @@ resize_widget_new (GimpViewable *viewable, gtk_widget_show (label); combo = gimp_enum_combo_box_new (GIMP_TYPE_INTERPOLATION_TYPE); - gimp_enum_combo_box_set_active (GIMP_ENUM_COMBO_BOX (combo), - resize->interpolation); + gimp_int_combo_box_set_active (GIMP_INT_COMBO_BOX (combo), + resize->interpolation); + g_signal_connect (combo, "changed", - G_CALLBACK (gimp_enum_combo_box_get_active), + G_CALLBACK (gimp_int_combo_box_get_active), &resize->interpolation); - gimp_enum_combo_box_set_active (GIMP_ENUM_COMBO_BOX (combo), - resize->interpolation); gtk_box_pack_start (GTK_BOX (hbox), combo, FALSE, FALSE, 0); gtk_widget_show (combo); @@ -896,8 +895,8 @@ response_callback (GtkWidget *widget, resize->interpolation = resize->gimage->gimp->config->interpolation_type; - gimp_enum_combo_box_set_active (GIMP_ENUM_COMBO_BOX (private->interpolation_menu), - resize->interpolation); + gimp_int_combo_box_set_active (GIMP_INT_COMBO_BOX (private->interpolation_menu), + resize->interpolation); } break; diff --git a/app/tools/gimpcurvestool.c b/app/tools/gimpcurvestool.c index 6b0f71aff4..bfef22635d 100644 --- a/app/tools/gimpcurvestool.c +++ b/app/tools/gimpcurvestool.c @@ -307,8 +307,8 @@ gimp_curves_tool_initialize (GimpTool *tool, gimp_enum_combo_box_set_visible (GIMP_ENUM_COMBO_BOX (c_tool->channel_menu), curves_menu_visible_func, c_tool); - gimp_enum_combo_box_set_active (GIMP_ENUM_COMBO_BOX (c_tool->channel_menu), - c_tool->channel); + gimp_int_combo_box_set_active (GIMP_INT_COMBO_BOX (c_tool->channel_menu), + c_tool->channel); if (! c_tool->color && c_tool->alpha) c_tool->channel = 1; @@ -797,16 +797,14 @@ static void curves_channel_callback (GtkWidget *widget, GimpCurvesTool *tool) { - if (gimp_enum_combo_box_get_active (GIMP_ENUM_COMBO_BOX (widget), - (gint *) &tool->channel)) - { - gimp_histogram_view_set_channel (GIMP_HISTOGRAM_VIEW (tool->graph), - tool->channel); + gimp_int_combo_box_get_active (GIMP_INT_COMBO_BOX (widget), + (gint *) &tool->channel); + gimp_histogram_view_set_channel (GIMP_HISTOGRAM_VIEW (tool->graph), + tool->channel); - /* FIXME: hack */ - if (! tool->color && tool->alpha) - tool->channel = (tool->channel > 1) ? 2 : 1; - } + /* FIXME: hack */ + if (! tool->color && tool->alpha) + tool->channel = (tool->channel > 1) ? 2 : 1; gimp_int_radio_group_set_active (GTK_RADIO_BUTTON (tool->curve_type), tool->curves->curve_type[tool->channel]); @@ -836,7 +834,7 @@ curves_menu_visible_func (GtkTreeModel *model, GimpHistogramChannel channel; gtk_tree_model_get (model, iter, - GIMP_ENUM_STORE_VALUE, &channel, + GIMP_INT_STORE_VALUE, &channel, -1); switch (channel) diff --git a/app/tools/gimplevelstool.c b/app/tools/gimplevelstool.c index ab8b76b090..9472886720 100644 --- a/app/tools/gimplevelstool.c +++ b/app/tools/gimplevelstool.c @@ -305,8 +305,8 @@ gimp_levels_tool_initialize (GimpTool *tool, gimp_enum_combo_box_set_visible (GIMP_ENUM_COMBO_BOX (l_tool->channel_menu), levels_menu_visible_func, l_tool); - gimp_enum_combo_box_set_active (GIMP_ENUM_COMBO_BOX (l_tool->channel_menu), - l_tool->channel); + gimp_int_combo_box_set_active (GIMP_INT_COMBO_BOX (l_tool->channel_menu), + l_tool->channel); if (! l_tool->color && l_tool->alpha) l_tool->channel = 1; @@ -905,16 +905,15 @@ static void levels_channel_callback (GtkWidget *widget, GimpLevelsTool *tool) { - if (gimp_enum_combo_box_get_active (GIMP_ENUM_COMBO_BOX (widget), - (gint *) &tool->channel)) - { - gimp_histogram_view_set_channel (GIMP_HISTOGRAM_VIEW (tool->hist_view), - tool->channel); + gimp_int_combo_box_get_active (GIMP_INT_COMBO_BOX (widget), + (gint *) &tool->channel); - /* FIXME: hack */ - if (! tool->color && tool->alpha) - tool->channel = (tool->channel > 1) ? 2 : 1; - } + gimp_histogram_view_set_channel (GIMP_HISTOGRAM_VIEW (tool->hist_view), + tool->channel); + + /* FIXME: hack */ + if (! tool->color && tool->alpha) + tool->channel = (tool->channel > 1) ? 2 : 1; levels_update (tool, ALL); } @@ -938,7 +937,7 @@ levels_menu_visible_func (GtkTreeModel *model, GimpHistogramChannel channel; gtk_tree_model_get (model, iter, - GIMP_ENUM_STORE_VALUE, &channel, + GIMP_INT_STORE_VALUE, &channel, -1); switch (channel) diff --git a/app/widgets/gimpcolorframe.c b/app/widgets/gimpcolorframe.c index 01a1aef674..52df38ec76 100644 --- a/app/widgets/gimpcolorframe.c +++ b/app/widgets/gimpcolorframe.c @@ -151,7 +151,7 @@ gimp_color_frame_set_mode (GimpColorFrame *frame, { g_return_if_fail (GIMP_IS_COLOR_FRAME (frame)); - gimp_enum_combo_box_set_active (GIMP_ENUM_COMBO_BOX (frame->menu), mode); + gimp_int_combo_box_set_active (GIMP_INT_COMBO_BOX (frame->menu), mode); frame->frame_mode = mode; gimp_color_frame_update (frame); @@ -213,9 +213,9 @@ static void gimp_color_frame_menu_callback (GtkWidget *widget, GimpColorFrame *frame) { - if (gimp_enum_combo_box_get_active (GIMP_ENUM_COMBO_BOX (widget), - (gint *) &frame->frame_mode)) - gimp_color_frame_update (frame); + gimp_int_combo_box_get_active (GIMP_INT_COMBO_BOX (widget), + (gint *) &frame->frame_mode); + gimp_color_frame_update (frame); } static void diff --git a/app/widgets/gimpenumcombobox.c b/app/widgets/gimpenumcombobox.c index aa1a9010a3..648a5f73f9 100644 --- a/app/widgets/gimpenumcombobox.c +++ b/app/widgets/gimpenumcombobox.c @@ -53,7 +53,7 @@ gimp_enum_combo_box_get_type (void) NULL /* instance_init */ }; - enum_combo_box_type = g_type_register_static (GTK_TYPE_COMBO_BOX, + enum_combo_box_type = g_type_register_static (GIMP_TYPE_INT_COMBO_BOX, "GimpEnumComboBox", &enum_combo_box_info, 0); } @@ -85,113 +85,15 @@ gimp_enum_combo_box_new (GType enum_type) store = gimp_enum_store_new (enum_type); - combo_box = gimp_enum_combo_box_new_with_model (GIMP_ENUM_STORE (store)); + combo_box = g_object_new (GIMP_TYPE_ENUM_COMBO_BOX, + "model", store, + NULL); g_object_unref (store); return combo_box; } -/** - * gimp_enum_combo_box_new_with_model: - * @enum_store: a #GimpEnumStore to use as the tree model - * - * Creates a new #GimpEnumComboBox using the #GimpEnumStore as its model. - * - * Return value: a new #GimpEnumComboBox. - **/ -GtkWidget * -gimp_enum_combo_box_new_with_model (GimpEnumStore *enum_store) -{ - GtkWidget *combo_box; - GtkCellRenderer *cell; - - g_return_val_if_fail (GIMP_IS_ENUM_STORE (enum_store), NULL); - - combo_box = g_object_new (GIMP_TYPE_ENUM_COMBO_BOX, - "model", enum_store, - NULL); - - cell = g_object_new (GTK_TYPE_CELL_RENDERER_PIXBUF, - "stock_size", GTK_ICON_SIZE_MENU, - NULL); - gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_box), cell, FALSE); - gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo_box), cell, - "stock_id", GIMP_ENUM_STORE_ICON, - NULL); - - cell = g_object_new (GTK_TYPE_CELL_RENDERER_TEXT, NULL); - gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_box), cell, TRUE); - gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo_box), cell, - "text", GIMP_ENUM_STORE_LABEL, - NULL); - - return combo_box; -} - -/** - * gimp_enum_combo_box_set_active: - * @combo_box: a #GimpEnumComboBox - * @value: an enum value - * - * Looks up the item that belongs to the given @value and makes it the - * selected item in the @combo_box. - * - * Return value: %TRUE on success or %FALSE if there was no item for - * this value. - **/ -gboolean -gimp_enum_combo_box_set_active (GimpEnumComboBox *combo_box, - gint value) -{ - GtkTreeModel *model; - GtkTreeIter iter; - - g_return_val_if_fail (GIMP_IS_ENUM_COMBO_BOX (combo_box), FALSE); - - model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo_box)); - - if (gimp_enum_store_lookup_by_value (model, value, &iter)) - { - gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo_box), &iter); - return TRUE; - } - - return FALSE; -} - -/** - * gimp_enum_combo_box_get_active: - * @combo_box: a #GimpEnumComboBox - * @value: return location for enum value - * - * Retrieves the enum value of the selected (active) item in the - * @combo_box. - * - * Return value: %TRUE if @value has been set or %FALSE if no item was - * active. - **/ -gboolean -gimp_enum_combo_box_get_active (GimpEnumComboBox *combo_box, - gint *value) -{ - GtkTreeIter iter; - - g_return_val_if_fail (GIMP_IS_ENUM_COMBO_BOX (combo_box), FALSE); - g_return_val_if_fail (value != NULL, FALSE); - - if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (combo_box), &iter)) - { - gtk_tree_model_get (gtk_combo_box_get_model (GTK_COMBO_BOX (combo_box)), - &iter, - GIMP_ENUM_STORE_VALUE, value, - -1); - return TRUE; - } - - return FALSE; -} - /** * gimp_enum_combo_box_set_stock_prefix: * @combo_box: a #GimpEnumComboBox diff --git a/app/widgets/gimpenumcombobox.h b/app/widgets/gimpenumcombobox.h index 8770d37564..ded922114c 100644 --- a/app/widgets/gimpenumcombobox.h +++ b/app/widgets/gimpenumcombobox.h @@ -22,7 +22,7 @@ #ifndef __GIMP_ENUM_COMBO_BOX_H__ #define __GIMP_ENUM_COMBO_BOX_H__ -#include +#include #define GIMP_TYPE_ENUM_COMBO_BOX (gimp_enum_combo_box_get_type ()) @@ -37,23 +37,18 @@ typedef struct _GimpEnumComboBoxClass GimpEnumComboBoxClass; struct _GimpEnumComboBoxClass { - GtkComboBoxClass parent_instance; + GimpIntComboBoxClass parent_instance; }; struct _GimpEnumComboBox { - GtkComboBox parent_instance; + GimpIntComboBox parent_instance; }; GType gimp_enum_combo_box_get_type (void) G_GNUC_CONST; GtkWidget * gimp_enum_combo_box_new (GType enum_type); -GtkWidget * gimp_enum_combo_box_new_with_model (GimpEnumStore *enum_store); -gboolean gimp_enum_combo_box_set_active (GimpEnumComboBox *combo_box, - gint value); -gboolean gimp_enum_combo_box_get_active (GimpEnumComboBox *combo_box, - gint *value); void gimp_enum_combo_box_set_stock_prefix (GimpEnumComboBox *combo_box, const gchar *stock_prefix); diff --git a/app/widgets/gimpenumstore.c b/app/widgets/gimpenumstore.c index caebc52ca1..a9ae1a4db3 100644 --- a/app/widgets/gimpenumstore.c +++ b/app/widgets/gimpenumstore.c @@ -34,14 +34,13 @@ static void gimp_enum_store_class_init (GimpEnumStoreClass *klass); -static void gimp_enum_store_init (GimpEnumStore *enum_store); static void gimp_enum_store_finalize (GObject *object); static void gimp_enum_store_add_value (GtkListStore *store, GEnumValue *value); -static GtkListStoreClass *parent_class = NULL; +static GimpEnumStoreClass *parent_class = NULL; GType @@ -54,17 +53,17 @@ gimp_enum_store_get_type (void) static const GTypeInfo enum_store_info = { sizeof (GimpEnumStoreClass), - NULL, /* base_init */ - NULL, /* base_finalize */ + NULL, /* base_init */ + NULL, /* base_finalize */ (GClassInitFunc) gimp_enum_store_class_init, NULL, /* class_finalize */ - NULL, /* class_data */ + NULL, /* class_data */ sizeof (GimpEnumStore), - 0, /* n_preallocs */ - (GInstanceInitFunc) gimp_enum_store_init, + 0, /* n_preallocs */ + NULL /* instance_init */ }; - enum_store_type = g_type_register_static (GTK_TYPE_LIST_STORE, + enum_store_type = g_type_register_static (GIMP_TYPE_INT_STORE, "GimpEnumStore", &enum_store_info, 0); } @@ -82,23 +81,6 @@ gimp_enum_store_class_init (GimpEnumStoreClass *klass) object_class->finalize = gimp_enum_store_finalize; } -static void -gimp_enum_store_init (GimpEnumStore *enum_store) -{ - GType types[GIMP_ENUM_STORE_NUM_COLUMNS] = - { - G_TYPE_INT, /* GIMP_ENUM_STORE_VALUE */ - G_TYPE_STRING, /* GIMP_ENUM_STORE_LABEL */ - G_TYPE_STRING, /* GIMP_ENUM_STORE_ICON */ - G_TYPE_POINTER /* GIMP_ENUM_STORE_USER_DATA */ - }; - - enum_store->enum_class = NULL; - - gtk_list_store_set_column_types (GTK_LIST_STORE (enum_store), - GIMP_ENUM_STORE_NUM_COLUMNS, types); -} - static void gimp_enum_store_finalize (GObject *object) { @@ -118,10 +100,8 @@ gimp_enum_store_add_value (GtkListStore *store, gtk_list_store_append (store, &iter); gtk_list_store_set (store, &iter, - GIMP_ENUM_STORE_VALUE, value->value, - GIMP_ENUM_STORE_LABEL, gettext (value->value_name), - GIMP_ENUM_STORE_ICON, NULL, - GIMP_ENUM_STORE_USER_DATA, NULL, + GIMP_INT_STORE_VALUE, value->value, + GIMP_INT_STORE_LABEL, gettext (value->value_name), -1); } @@ -261,43 +241,6 @@ gimp_enum_store_new_with_values_valist (GType enum_type, return store; } -/** - * gimp_enum_store_lookup_by_value: - * @model: a #GimpEnumStore - * @value: an enum values to lookup in the @model - * @iter: return location for the iter of the given @value - * - * Iterate over the @model looking for @value. - * - * Return value: %TRUE if the value has been located and @iter is - * valid, %FALSE otherwise. - **/ -gboolean -gimp_enum_store_lookup_by_value (GtkTreeModel *model, - gint value, - GtkTreeIter *iter) -{ - gboolean iter_valid; - - g_return_val_if_fail (GTK_IS_TREE_MODEL (model), FALSE); - g_return_val_if_fail (iter != NULL, FALSE); - - for (iter_valid = gtk_tree_model_get_iter_first (model, iter); - iter_valid; - iter_valid = gtk_tree_model_iter_next (model, iter)) - { - gint this; - - gtk_tree_model_get (model, iter, - GIMP_ENUM_STORE_VALUE, &this, - -1); - if (this == value) - break; - } - - return iter_valid; -} - /** * gimp_enum_store_set_stock_prefix: * @store: a #GimpEnumStore @@ -331,7 +274,7 @@ gimp_enum_store_set_stock_prefix (GimpEnumStore *store, gint value; gtk_tree_model_get (model, &iter, - GIMP_ENUM_STORE_VALUE, &value, + GIMP_INT_STORE_VALUE, &value, -1); enum_value = g_enum_get_value (store->enum_class, value); @@ -342,7 +285,7 @@ gimp_enum_store_set_stock_prefix (GimpEnumStore *store, } gtk_list_store_set (GTK_LIST_STORE (store), &iter, - GIMP_ENUM_STORE_ICON, stock_id, + GIMP_INT_STORE_STOCK_ID, stock_id, -1); if (stock_id) diff --git a/app/widgets/gimpenumstore.h b/app/widgets/gimpenumstore.h index 26a314966a..cd643ff041 100644 --- a/app/widgets/gimpenumstore.h +++ b/app/widgets/gimpenumstore.h @@ -22,17 +22,7 @@ #ifndef __GIMP_ENUM_STORE_H__ #define __GIMP_ENUM_STORE_H__ -#include - - -typedef enum -{ - GIMP_ENUM_STORE_VALUE, - GIMP_ENUM_STORE_LABEL, - GIMP_ENUM_STORE_ICON, - GIMP_ENUM_STORE_USER_DATA, - GIMP_ENUM_STORE_NUM_COLUMNS -} GimpEnumStoreColumns; +#include #define GIMP_TYPE_ENUM_STORE (gimp_enum_store_get_type ()) @@ -47,14 +37,14 @@ typedef struct _GimpEnumStoreClass GimpEnumStoreClass; struct _GimpEnumStoreClass { - GtkListStoreClass parent_instance; + GimpIntStoreClass parent_instance; }; struct _GimpEnumStore { - GtkListStore parent_instance; + GimpIntStore parent_instance; - GEnumClass *enum_class; + GEnumClass *enum_class; }; @@ -71,10 +61,6 @@ GtkListStore * gimp_enum_store_new_with_values_valist (GType enum_type, gint n_values, va_list args); -gboolean gimp_enum_store_lookup_by_value (GtkTreeModel *model, - gint value, - GtkTreeIter *iter); - void gimp_enum_store_set_stock_prefix (GimpEnumStore *store, const gchar *stock_prefix); diff --git a/app/widgets/gimphistogrameditor.c b/app/widgets/gimphistogrameditor.c index ac0af3e65d..600baacff4 100644 --- a/app/widgets/gimphistogrameditor.c +++ b/app/widgets/gimphistogrameditor.c @@ -387,7 +387,7 @@ gimp_histogram_editor_item_visible (GtkTreeModel *model, GimpHistogramChannel channel; gtk_tree_model_get (model, iter, - GIMP_ENUM_STORE_VALUE, &channel, + GIMP_INT_STORE_VALUE, &channel, -1); switch (channel) diff --git a/app/widgets/gimppropwidgets.c b/app/widgets/gimppropwidgets.c index 10d5529f72..46a10c606c 100644 --- a/app/widgets/gimppropwidgets.c +++ b/app/widgets/gimppropwidgets.c @@ -322,7 +322,9 @@ gimp_prop_enum_combo_box_new (GObject *config, store = gimp_enum_store_new_with_range (param_spec->value_type, minimum, maximum); - combo_box = gimp_enum_combo_box_new_with_model (GIMP_ENUM_STORE (store)); + combo_box = g_object_new (GIMP_TYPE_ENUM_COMBO_BOX, + "model", store, + NULL); g_object_unref (store); } @@ -331,7 +333,7 @@ gimp_prop_enum_combo_box_new (GObject *config, combo_box = gimp_enum_combo_box_new (param_spec->value_type); } - gimp_enum_combo_box_set_active (GIMP_ENUM_COMBO_BOX (combo_box), value); + gimp_int_combo_box_set_active (GIMP_INT_COMBO_BOX (combo_box), value); g_signal_connect (combo_box, "changed", G_CALLBACK (gimp_prop_enum_combo_box_callback), @@ -357,7 +359,7 @@ gimp_prop_enum_combo_box_callback (GtkWidget *widget, if (! param_spec) return; - if (gimp_enum_combo_box_get_active (GIMP_ENUM_COMBO_BOX (widget), &value)) + if (gimp_int_combo_box_get_active (GIMP_INT_COMBO_BOX (widget), &value)) { g_object_set (config, param_spec->name, value, @@ -376,7 +378,7 @@ gimp_prop_enum_combo_box_notify (GObject *config, param_spec->name, &value, NULL); - gimp_enum_combo_box_set_active (GIMP_ENUM_COMBO_BOX (combo_box), value); + gimp_int_combo_box_set_active (GIMP_INT_COMBO_BOX (combo_box), value); } @@ -441,7 +443,7 @@ gimp_prop_boolean_combo_box_callback (GtkWidget *widget, if (! param_spec) return; - value = gtk_combo_box_get_active (GTK_COMBO_BOX (widget)); + value = gtk_combo_box_get_active (GTK_COMBO_BOX (widget)); g_object_set (config, param_spec->name, value ? FALSE : TRUE, diff --git a/app/widgets/gimpstrokeeditor.c b/app/widgets/gimpstrokeeditor.c index c8c83685fc..d1bca74025 100644 --- a/app/widgets/gimpstrokeeditor.c +++ b/app/widgets/gimpstrokeeditor.c @@ -265,7 +265,7 @@ gimp_stroke_editor_constructor (GType type, G_CALLBACK (gimp_stroke_editor_dash_preset), editor->options); g_signal_connect_object (editor->options, "dash_info_changed", - G_CALLBACK (gimp_enum_combo_box_set_active), + G_CALLBACK (gimp_int_combo_box_set_active), box, G_CONNECT_SWAPPED); gimp_table_attach_aligned (GTK_TABLE (table), 0, row++, @@ -340,6 +340,6 @@ gimp_stroke_editor_dash_preset (GtkWidget *widget, { gint value; - if (gimp_enum_combo_box_get_active (GIMP_ENUM_COMBO_BOX (widget), &value)) + if (gimp_int_combo_box_get_active (GIMP_INT_COMBO_BOX (widget), &value)) gimp_stroke_options_set_dash_preset (GIMP_STROKE_OPTIONS (data), value); } diff --git a/devel-docs/ChangeLog b/devel-docs/ChangeLog index 41a9eeb97d..3ac2aba9cb 100644 --- a/devel-docs/ChangeLog +++ b/devel-docs/ChangeLog @@ -1,9 +1,17 @@ +2004-04-20 Sven Neumann + + * libgimpwidgets/libgimpwidgets-docs.sgml + * libgimpwidgets/libgimpwidgets-sections.txt + * libgimpwidgets/libgimpwidgets.types + * libgimpwidgets/tmpl/gimpintstore.sgml: added docs for GimpIntStore. + 2004-04-20 Sven Neumann * libgimpwidgets/libgimpwidgets-docs.sgml * libgimpwidgets/libgimpwidgets-sections.txt * libgimpwidgets/tmpl/gimpoldwidgets.sgml - * libgimpwidgets/tmpl/gimpwidgets.sgml + * libgimpwidgets/tmpl/gimpwidgets.sgml: added a new chapter for + deprecated API. 2004-04-20 Sven Neumann diff --git a/devel-docs/libgimpwidgets/libgimpwidgets-docs.sgml b/devel-docs/libgimpwidgets/libgimpwidgets-docs.sgml index e2d395f633..9f0a63c504 100644 --- a/devel-docs/libgimpwidgets/libgimpwidgets-docs.sgml +++ b/devel-docs/libgimpwidgets/libgimpwidgets-docs.sgml @@ -28,6 +28,7 @@ + diff --git a/devel-docs/libgimpwidgets/libgimpwidgets-sections.txt b/devel-docs/libgimpwidgets/libgimpwidgets-sections.txt index c00d20fc77..087f9e82fc 100644 --- a/devel-docs/libgimpwidgets/libgimpwidgets-sections.txt +++ b/devel-docs/libgimpwidgets/libgimpwidgets-sections.txt @@ -160,6 +160,24 @@ GIMP_IS_PIXMAP_CLASS GIMP_PIXMAP_GET_CLASS +
+gimpintstore +GimpIntStore +GimpIntStore +GimpIntStoreColumns +gimp_int_store_new +gimp_int_store_lookup_by_value + +GimpIntStoreClass +GIMP_INT_STORE +GIMP_IS_INT_STORE +GIMP_TYPE_INT_STORE +gimp_int_store_get_type +GIMP_INT_STORE_CLASS +GIMP_IS_INT_STORE_CLASS +GIMP_INT_STORE_GET_CLASS +
+
gimpintcombobox GimpIntComboBox diff --git a/devel-docs/libgimpwidgets/libgimpwidgets.types b/devel-docs/libgimpwidgets/libgimpwidgets.types index 64f56bfd66..09229e91e5 100644 --- a/devel-docs/libgimpwidgets/libgimpwidgets.types +++ b/devel-docs/libgimpwidgets/libgimpwidgets.types @@ -19,6 +19,7 @@ gimp_color_selection_get_type gimp_dialog_get_type gimp_file_entry_get_type gimp_int_combo_box_get_type +gimp_int_store_get_type gimp_memsize_entry_get_type gimp_offset_area_get_type gimp_path_editor_get_type diff --git a/devel-docs/libgimpwidgets/tmpl/gimpintstore.sgml b/devel-docs/libgimpwidgets/tmpl/gimpintstore.sgml new file mode 100644 index 0000000000..c77967a06b --- /dev/null +++ b/devel-docs/libgimpwidgets/tmpl/gimpintstore.sgml @@ -0,0 +1,55 @@ + +GimpIntStore + + + + + + + + + + + + + + + + + + + + + + + + + + + +@GIMP_INT_STORE_VALUE: +@GIMP_INT_STORE_LABEL: +@GIMP_INT_STORE_STOCK_ID: +@GIMP_INT_STORE_PIXBUF: +@GIMP_INT_STORE_USER_DATA: +@GIMP_INT_STORE_NUM_COLUMNS: + + + + + + +@Returns: + + + + + + + +@model: +@value: +@iter: +@Returns: + + diff --git a/devel-docs/libgimpwidgets/tmpl/gimpoldwidgets.sgml b/devel-docs/libgimpwidgets/tmpl/gimpoldwidgets.sgml index e5d4e602c4..e1f1533bf5 100644 --- a/devel-docs/libgimpwidgets/tmpl/gimpoldwidgets.sgml +++ b/devel-docs/libgimpwidgets/tmpl/gimpoldwidgets.sgml @@ -9,13 +9,11 @@ Old API that is still available but declared as deprecated. These functions are not defined if you #define GIMP_DISABLE_DEPRECATED. - GimpIntComboBox - diff --git a/libgimpwidgets/Makefile.am b/libgimpwidgets/Makefile.am index 4c0b0d0e69..d2662bb8eb 100644 --- a/libgimpwidgets/Makefile.am +++ b/libgimpwidgets/Makefile.am @@ -94,6 +94,8 @@ libgimpwidgets_2_0_la_sources = \ gimphelpui.h \ gimpintcombobox.c \ gimpintcombobox.h \ + gimpintstore.c \ + gimpintstore.h \ gimpmemsizeentry.c \ gimpmemsizeentry.h \ gimpoldwidgets.c \ @@ -151,6 +153,7 @@ libgimpwidgetsinclude_HEADERS = \ gimpfileentry.h \ gimphelpui.h \ gimpintcombobox.h \ + gimpintstore.h \ gimpmemsizeentry.h \ gimpoldwidgets.h \ gimpoffsetarea.h \ diff --git a/libgimpwidgets/gimpenumcombobox.c b/libgimpwidgets/gimpenumcombobox.c index aa1a9010a3..648a5f73f9 100644 --- a/libgimpwidgets/gimpenumcombobox.c +++ b/libgimpwidgets/gimpenumcombobox.c @@ -53,7 +53,7 @@ gimp_enum_combo_box_get_type (void) NULL /* instance_init */ }; - enum_combo_box_type = g_type_register_static (GTK_TYPE_COMBO_BOX, + enum_combo_box_type = g_type_register_static (GIMP_TYPE_INT_COMBO_BOX, "GimpEnumComboBox", &enum_combo_box_info, 0); } @@ -85,113 +85,15 @@ gimp_enum_combo_box_new (GType enum_type) store = gimp_enum_store_new (enum_type); - combo_box = gimp_enum_combo_box_new_with_model (GIMP_ENUM_STORE (store)); + combo_box = g_object_new (GIMP_TYPE_ENUM_COMBO_BOX, + "model", store, + NULL); g_object_unref (store); return combo_box; } -/** - * gimp_enum_combo_box_new_with_model: - * @enum_store: a #GimpEnumStore to use as the tree model - * - * Creates a new #GimpEnumComboBox using the #GimpEnumStore as its model. - * - * Return value: a new #GimpEnumComboBox. - **/ -GtkWidget * -gimp_enum_combo_box_new_with_model (GimpEnumStore *enum_store) -{ - GtkWidget *combo_box; - GtkCellRenderer *cell; - - g_return_val_if_fail (GIMP_IS_ENUM_STORE (enum_store), NULL); - - combo_box = g_object_new (GIMP_TYPE_ENUM_COMBO_BOX, - "model", enum_store, - NULL); - - cell = g_object_new (GTK_TYPE_CELL_RENDERER_PIXBUF, - "stock_size", GTK_ICON_SIZE_MENU, - NULL); - gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_box), cell, FALSE); - gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo_box), cell, - "stock_id", GIMP_ENUM_STORE_ICON, - NULL); - - cell = g_object_new (GTK_TYPE_CELL_RENDERER_TEXT, NULL); - gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_box), cell, TRUE); - gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo_box), cell, - "text", GIMP_ENUM_STORE_LABEL, - NULL); - - return combo_box; -} - -/** - * gimp_enum_combo_box_set_active: - * @combo_box: a #GimpEnumComboBox - * @value: an enum value - * - * Looks up the item that belongs to the given @value and makes it the - * selected item in the @combo_box. - * - * Return value: %TRUE on success or %FALSE if there was no item for - * this value. - **/ -gboolean -gimp_enum_combo_box_set_active (GimpEnumComboBox *combo_box, - gint value) -{ - GtkTreeModel *model; - GtkTreeIter iter; - - g_return_val_if_fail (GIMP_IS_ENUM_COMBO_BOX (combo_box), FALSE); - - model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo_box)); - - if (gimp_enum_store_lookup_by_value (model, value, &iter)) - { - gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo_box), &iter); - return TRUE; - } - - return FALSE; -} - -/** - * gimp_enum_combo_box_get_active: - * @combo_box: a #GimpEnumComboBox - * @value: return location for enum value - * - * Retrieves the enum value of the selected (active) item in the - * @combo_box. - * - * Return value: %TRUE if @value has been set or %FALSE if no item was - * active. - **/ -gboolean -gimp_enum_combo_box_get_active (GimpEnumComboBox *combo_box, - gint *value) -{ - GtkTreeIter iter; - - g_return_val_if_fail (GIMP_IS_ENUM_COMBO_BOX (combo_box), FALSE); - g_return_val_if_fail (value != NULL, FALSE); - - if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (combo_box), &iter)) - { - gtk_tree_model_get (gtk_combo_box_get_model (GTK_COMBO_BOX (combo_box)), - &iter, - GIMP_ENUM_STORE_VALUE, value, - -1); - return TRUE; - } - - return FALSE; -} - /** * gimp_enum_combo_box_set_stock_prefix: * @combo_box: a #GimpEnumComboBox diff --git a/libgimpwidgets/gimpenumcombobox.h b/libgimpwidgets/gimpenumcombobox.h index 8770d37564..ded922114c 100644 --- a/libgimpwidgets/gimpenumcombobox.h +++ b/libgimpwidgets/gimpenumcombobox.h @@ -22,7 +22,7 @@ #ifndef __GIMP_ENUM_COMBO_BOX_H__ #define __GIMP_ENUM_COMBO_BOX_H__ -#include +#include #define GIMP_TYPE_ENUM_COMBO_BOX (gimp_enum_combo_box_get_type ()) @@ -37,23 +37,18 @@ typedef struct _GimpEnumComboBoxClass GimpEnumComboBoxClass; struct _GimpEnumComboBoxClass { - GtkComboBoxClass parent_instance; + GimpIntComboBoxClass parent_instance; }; struct _GimpEnumComboBox { - GtkComboBox parent_instance; + GimpIntComboBox parent_instance; }; GType gimp_enum_combo_box_get_type (void) G_GNUC_CONST; GtkWidget * gimp_enum_combo_box_new (GType enum_type); -GtkWidget * gimp_enum_combo_box_new_with_model (GimpEnumStore *enum_store); -gboolean gimp_enum_combo_box_set_active (GimpEnumComboBox *combo_box, - gint value); -gboolean gimp_enum_combo_box_get_active (GimpEnumComboBox *combo_box, - gint *value); void gimp_enum_combo_box_set_stock_prefix (GimpEnumComboBox *combo_box, const gchar *stock_prefix); diff --git a/libgimpwidgets/gimpenumstore.c b/libgimpwidgets/gimpenumstore.c index caebc52ca1..a9ae1a4db3 100644 --- a/libgimpwidgets/gimpenumstore.c +++ b/libgimpwidgets/gimpenumstore.c @@ -34,14 +34,13 @@ static void gimp_enum_store_class_init (GimpEnumStoreClass *klass); -static void gimp_enum_store_init (GimpEnumStore *enum_store); static void gimp_enum_store_finalize (GObject *object); static void gimp_enum_store_add_value (GtkListStore *store, GEnumValue *value); -static GtkListStoreClass *parent_class = NULL; +static GimpEnumStoreClass *parent_class = NULL; GType @@ -54,17 +53,17 @@ gimp_enum_store_get_type (void) static const GTypeInfo enum_store_info = { sizeof (GimpEnumStoreClass), - NULL, /* base_init */ - NULL, /* base_finalize */ + NULL, /* base_init */ + NULL, /* base_finalize */ (GClassInitFunc) gimp_enum_store_class_init, NULL, /* class_finalize */ - NULL, /* class_data */ + NULL, /* class_data */ sizeof (GimpEnumStore), - 0, /* n_preallocs */ - (GInstanceInitFunc) gimp_enum_store_init, + 0, /* n_preallocs */ + NULL /* instance_init */ }; - enum_store_type = g_type_register_static (GTK_TYPE_LIST_STORE, + enum_store_type = g_type_register_static (GIMP_TYPE_INT_STORE, "GimpEnumStore", &enum_store_info, 0); } @@ -82,23 +81,6 @@ gimp_enum_store_class_init (GimpEnumStoreClass *klass) object_class->finalize = gimp_enum_store_finalize; } -static void -gimp_enum_store_init (GimpEnumStore *enum_store) -{ - GType types[GIMP_ENUM_STORE_NUM_COLUMNS] = - { - G_TYPE_INT, /* GIMP_ENUM_STORE_VALUE */ - G_TYPE_STRING, /* GIMP_ENUM_STORE_LABEL */ - G_TYPE_STRING, /* GIMP_ENUM_STORE_ICON */ - G_TYPE_POINTER /* GIMP_ENUM_STORE_USER_DATA */ - }; - - enum_store->enum_class = NULL; - - gtk_list_store_set_column_types (GTK_LIST_STORE (enum_store), - GIMP_ENUM_STORE_NUM_COLUMNS, types); -} - static void gimp_enum_store_finalize (GObject *object) { @@ -118,10 +100,8 @@ gimp_enum_store_add_value (GtkListStore *store, gtk_list_store_append (store, &iter); gtk_list_store_set (store, &iter, - GIMP_ENUM_STORE_VALUE, value->value, - GIMP_ENUM_STORE_LABEL, gettext (value->value_name), - GIMP_ENUM_STORE_ICON, NULL, - GIMP_ENUM_STORE_USER_DATA, NULL, + GIMP_INT_STORE_VALUE, value->value, + GIMP_INT_STORE_LABEL, gettext (value->value_name), -1); } @@ -261,43 +241,6 @@ gimp_enum_store_new_with_values_valist (GType enum_type, return store; } -/** - * gimp_enum_store_lookup_by_value: - * @model: a #GimpEnumStore - * @value: an enum values to lookup in the @model - * @iter: return location for the iter of the given @value - * - * Iterate over the @model looking for @value. - * - * Return value: %TRUE if the value has been located and @iter is - * valid, %FALSE otherwise. - **/ -gboolean -gimp_enum_store_lookup_by_value (GtkTreeModel *model, - gint value, - GtkTreeIter *iter) -{ - gboolean iter_valid; - - g_return_val_if_fail (GTK_IS_TREE_MODEL (model), FALSE); - g_return_val_if_fail (iter != NULL, FALSE); - - for (iter_valid = gtk_tree_model_get_iter_first (model, iter); - iter_valid; - iter_valid = gtk_tree_model_iter_next (model, iter)) - { - gint this; - - gtk_tree_model_get (model, iter, - GIMP_ENUM_STORE_VALUE, &this, - -1); - if (this == value) - break; - } - - return iter_valid; -} - /** * gimp_enum_store_set_stock_prefix: * @store: a #GimpEnumStore @@ -331,7 +274,7 @@ gimp_enum_store_set_stock_prefix (GimpEnumStore *store, gint value; gtk_tree_model_get (model, &iter, - GIMP_ENUM_STORE_VALUE, &value, + GIMP_INT_STORE_VALUE, &value, -1); enum_value = g_enum_get_value (store->enum_class, value); @@ -342,7 +285,7 @@ gimp_enum_store_set_stock_prefix (GimpEnumStore *store, } gtk_list_store_set (GTK_LIST_STORE (store), &iter, - GIMP_ENUM_STORE_ICON, stock_id, + GIMP_INT_STORE_STOCK_ID, stock_id, -1); if (stock_id) diff --git a/libgimpwidgets/gimpenumstore.h b/libgimpwidgets/gimpenumstore.h index 26a314966a..cd643ff041 100644 --- a/libgimpwidgets/gimpenumstore.h +++ b/libgimpwidgets/gimpenumstore.h @@ -22,17 +22,7 @@ #ifndef __GIMP_ENUM_STORE_H__ #define __GIMP_ENUM_STORE_H__ -#include - - -typedef enum -{ - GIMP_ENUM_STORE_VALUE, - GIMP_ENUM_STORE_LABEL, - GIMP_ENUM_STORE_ICON, - GIMP_ENUM_STORE_USER_DATA, - GIMP_ENUM_STORE_NUM_COLUMNS -} GimpEnumStoreColumns; +#include #define GIMP_TYPE_ENUM_STORE (gimp_enum_store_get_type ()) @@ -47,14 +37,14 @@ typedef struct _GimpEnumStoreClass GimpEnumStoreClass; struct _GimpEnumStoreClass { - GtkListStoreClass parent_instance; + GimpIntStoreClass parent_instance; }; struct _GimpEnumStore { - GtkListStore parent_instance; + GimpIntStore parent_instance; - GEnumClass *enum_class; + GEnumClass *enum_class; }; @@ -71,10 +61,6 @@ GtkListStore * gimp_enum_store_new_with_values_valist (GType enum_type, gint n_values, va_list args); -gboolean gimp_enum_store_lookup_by_value (GtkTreeModel *model, - gint value, - GtkTreeIter *iter); - void gimp_enum_store_set_stock_prefix (GimpEnumStore *store, const gchar *stock_prefix); diff --git a/libgimpwidgets/gimpintcombobox.c b/libgimpwidgets/gimpintcombobox.c index 43c468f924..e307ab45e8 100644 --- a/libgimpwidgets/gimpintcombobox.c +++ b/libgimpwidgets/gimpintcombobox.c @@ -28,13 +28,7 @@ #include "gimpwidgetstypes.h" #include "gimpintcombobox.h" - - -enum -{ - GIMP_INT_STORE_VALUE, - GIMP_INT_STORE_LABEL -}; +#include "gimpintstore.h" static void gimp_int_combo_box_init (GimpIntComboBox *combo_box); @@ -74,12 +68,19 @@ gimp_int_combo_box_init (GimpIntComboBox *combo_box) GtkListStore *store; GtkCellRenderer *cell; - store = gtk_list_store_new (2, G_TYPE_INT, G_TYPE_STRING); + store = gimp_int_store_new (); gtk_combo_box_set_model (GTK_COMBO_BOX (combo_box), GTK_TREE_MODEL (store)); g_object_unref (store); + cell = gtk_cell_renderer_pixbuf_new (); + gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_box), cell, FALSE); + gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo_box), cell, + "stock_id", GIMP_INT_STORE_STOCK_ID, + "pixbuf", GIMP_INT_STORE_PIXBUF, + NULL); + cell = gtk_cell_renderer_text_new (); gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo_box), cell, TRUE); gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo_box), cell, @@ -146,9 +147,12 @@ gimp_int_combo_box_new_valist (const gchar *first_label, g_return_val_if_fail (first_label != NULL, NULL); - combo_box = g_object_new (GIMP_TYPE_INT_COMBO_BOX, NULL); + store = gimp_int_store_new (); - store = GTK_LIST_STORE (gtk_combo_box_get_model (GTK_COMBO_BOX (combo_box))); + combo_box = g_object_new (GIMP_TYPE_INT_COMBO_BOX, + "model", store, + NULL); + g_object_unref (store); for (label = first_label, value = first_value; label; @@ -189,9 +193,12 @@ gimp_int_combo_box_new_array (gint n_values, g_return_val_if_fail (n_values > 0, NULL); g_return_val_if_fail (labels != NULL, NULL); - combo_box = g_object_new (GIMP_TYPE_INT_COMBO_BOX, NULL); + store = gimp_int_store_new (); - store = GTK_LIST_STORE (gtk_combo_box_get_model (GTK_COMBO_BOX (combo_box))); + combo_box = g_object_new (GIMP_TYPE_INT_COMBO_BOX, + "model", store, + NULL); + g_object_unref (store); for (i = 0; i < n_values; i++) { @@ -229,26 +236,12 @@ gimp_int_combo_box_set_active (GimpIntComboBox *combo_box, { GtkTreeModel *model; GtkTreeIter iter; - gboolean iter_valid; g_return_val_if_fail (GIMP_IS_INT_COMBO_BOX (combo_box), FALSE); model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo_box)); - for (iter_valid = gtk_tree_model_get_iter_first (model, &iter); - iter_valid; - iter_valid = gtk_tree_model_iter_next (model, &iter)) - { - gint this; - - gtk_tree_model_get (model, &iter, - GIMP_INT_STORE_VALUE, &this, - -1); - if (this == value) - break; - } - - if (iter_valid) + if (gimp_int_store_lookup_by_value (model, value, &iter)) { gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo_box), &iter); return TRUE; diff --git a/libgimpwidgets/gimpintstore.c b/libgimpwidgets/gimpintstore.c new file mode 100644 index 0000000000..686da06382 --- /dev/null +++ b/libgimpwidgets/gimpintstore.c @@ -0,0 +1,131 @@ +/* The GIMP -- an image manipulation program + * Copyright (C) 1995 Spencer Kimball and Peter Mattis + * + * gimpintstore.c + * Copyright (C) 2004 Sven Neumann + * + * 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 "gimpwidgetstypes.h" + +#include "gimpintstore.h" + + +static void gimp_int_store_init (GimpIntStore *store); + + +GType +gimp_int_store_get_type (void) +{ + static GType store_type = 0; + + if (! store_type) + { + static const GTypeInfo store_info = + { + sizeof (GimpIntStoreClass), + NULL, /* base_init */ + NULL, /* base_finalize */ + NULL, /* class_init */ + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof (GimpIntStore), + 0, /* n_preallocs */ + (GInstanceInitFunc) gimp_int_store_init + }; + + store_type = g_type_register_static (GTK_TYPE_LIST_STORE, + "GimpIntStore", + &store_info, 0); + } + + return store_type; +} + +static void +gimp_int_store_init (GimpIntStore *store) +{ + GType types[GIMP_INT_STORE_NUM_COLUMNS] = + { + G_TYPE_INT, /* GIMP_INT_STORE_VALUE */ + G_TYPE_STRING, /* GIMP_INT_STORE_LABEL */ + G_TYPE_STRING, /* GIMP_INT_STORE_STOCK_ID */ + GDK_TYPE_PIXBUF, /* GIMP_INT_STORE_PIXBUF */ + G_TYPE_POINTER /* GIMP_INT_STORE_USER_DATA */ + }; + + gtk_list_store_set_column_types (GTK_LIST_STORE (store), + GIMP_INT_STORE_NUM_COLUMNS, types); +} + + +/** + * gimp_int_store_new: + * + * Creates a #GtkListStore with a number of useful columns. + * #GimpIntStore is especially useful if the items you want to store + * are identified using an integer value. + * + * Return value: a new #GimpIntStore. + * + * Since: GIMP 2.2 + **/ +GtkListStore * +gimp_int_store_new (void) +{ + return g_object_new (GIMP_TYPE_INT_STORE, NULL); +} + +/** + * gimp_int_store_lookup_by_value: + * @model: a #GimpIntStore + * @value: an integer value to lookup in the @model + * @iter: return location for the iter of the given @value + * + * Iterate over the @model looking for @value. + * + * Return value: %TRUE if the value has been located and @iter is + * valid, %FALSE otherwise. + **/ +gboolean +gimp_int_store_lookup_by_value (GtkTreeModel *model, + gint value, + GtkTreeIter *iter) +{ + gboolean iter_valid; + + g_return_val_if_fail (GTK_IS_TREE_MODEL (model), FALSE); + g_return_val_if_fail (iter != NULL, FALSE); + + for (iter_valid = gtk_tree_model_get_iter_first (model, iter); + iter_valid; + iter_valid = gtk_tree_model_iter_next (model, iter)) + { + gint this; + + gtk_tree_model_get (model, iter, + GIMP_INT_STORE_VALUE, &this, + -1); + if (this == value) + break; + } + + return iter_valid; +} diff --git a/libgimpwidgets/gimpintstore.h b/libgimpwidgets/gimpintstore.h new file mode 100644 index 0000000000..ea235ce2c8 --- /dev/null +++ b/libgimpwidgets/gimpintstore.h @@ -0,0 +1,72 @@ +/* The GIMP -- an image manipulation program + * Copyright (C) 1995 Spencer Kimball and Peter Mattis + * + * gimpintstore.h + * Copyright (C) 2004 Sven Neumann + * + * 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_INT_STORE_H__ +#define __GIMP_INT_STORE_H__ + +#include + +G_BEGIN_DECLS + +typedef enum +{ + GIMP_INT_STORE_VALUE, + GIMP_INT_STORE_LABEL, + GIMP_INT_STORE_STOCK_ID, + GIMP_INT_STORE_PIXBUF, + GIMP_INT_STORE_USER_DATA, + GIMP_INT_STORE_NUM_COLUMNS +} GimpIntStoreColumns; + + +#define GIMP_TYPE_INT_STORE (gimp_int_store_get_type ()) +#define GIMP_INT_STORE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GIMP_TYPE_INT_STORE, GimpIntStore)) +#define GIMP_INT_STORE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GIMP_TYPE_INT_STORE, GimpIntStoreClass)) +#define GIMP_IS_INT_STORE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GIMP_TYPE_INT_STORE)) +#define GIMP_IS_INT_STORE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GIMP_TYPE_INT_STORE)) +#define GIMP_INT_STORE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GIMP_TYPE_INT_STORE, GimpIntStoreClass)) + + +typedef struct _GimpIntStoreClass GimpIntStoreClass; + +struct _GimpIntStoreClass +{ + GtkListStoreClass parent_instance; +}; + +struct _GimpIntStore +{ + GtkListStore parent_instance; +}; + + +GType gimp_int_store_get_type (void) G_GNUC_CONST; + +GtkListStore * gimp_int_store_new (void); + +gboolean gimp_int_store_lookup_by_value (GtkTreeModel *model, + gint value, + GtkTreeIter *iter); + + +G_END_DECLS + +#endif /* __GIMP_INT_STORE_H__ */ diff --git a/libgimpwidgets/gimppropwidgets.c b/libgimpwidgets/gimppropwidgets.c index 10d5529f72..46a10c606c 100644 --- a/libgimpwidgets/gimppropwidgets.c +++ b/libgimpwidgets/gimppropwidgets.c @@ -322,7 +322,9 @@ gimp_prop_enum_combo_box_new (GObject *config, store = gimp_enum_store_new_with_range (param_spec->value_type, minimum, maximum); - combo_box = gimp_enum_combo_box_new_with_model (GIMP_ENUM_STORE (store)); + combo_box = g_object_new (GIMP_TYPE_ENUM_COMBO_BOX, + "model", store, + NULL); g_object_unref (store); } @@ -331,7 +333,7 @@ gimp_prop_enum_combo_box_new (GObject *config, combo_box = gimp_enum_combo_box_new (param_spec->value_type); } - gimp_enum_combo_box_set_active (GIMP_ENUM_COMBO_BOX (combo_box), value); + gimp_int_combo_box_set_active (GIMP_INT_COMBO_BOX (combo_box), value); g_signal_connect (combo_box, "changed", G_CALLBACK (gimp_prop_enum_combo_box_callback), @@ -357,7 +359,7 @@ gimp_prop_enum_combo_box_callback (GtkWidget *widget, if (! param_spec) return; - if (gimp_enum_combo_box_get_active (GIMP_ENUM_COMBO_BOX (widget), &value)) + if (gimp_int_combo_box_get_active (GIMP_INT_COMBO_BOX (widget), &value)) { g_object_set (config, param_spec->name, value, @@ -376,7 +378,7 @@ gimp_prop_enum_combo_box_notify (GObject *config, param_spec->name, &value, NULL); - gimp_enum_combo_box_set_active (GIMP_ENUM_COMBO_BOX (combo_box), value); + gimp_int_combo_box_set_active (GIMP_INT_COMBO_BOX (combo_box), value); } @@ -441,7 +443,7 @@ gimp_prop_boolean_combo_box_callback (GtkWidget *widget, if (! param_spec) return; - value = gtk_combo_box_get_active (GTK_COMBO_BOX (widget)); + value = gtk_combo_box_get_active (GTK_COMBO_BOX (widget)); g_object_set (config, param_spec->name, value ? FALSE : TRUE, diff --git a/libgimpwidgets/gimpwidgets.h b/libgimpwidgets/gimpwidgets.h index 34770bdf57..c8e8e5f4b0 100644 --- a/libgimpwidgets/gimpwidgets.h +++ b/libgimpwidgets/gimpwidgets.h @@ -42,6 +42,7 @@ #include #include #include +#include #include #include #include diff --git a/libgimpwidgets/gimpwidgetstypes.h b/libgimpwidgets/gimpwidgetstypes.h index 13f3a6731e..ba82add7fe 100644 --- a/libgimpwidgets/gimpwidgetstypes.h +++ b/libgimpwidgets/gimpwidgetstypes.h @@ -70,6 +70,7 @@ typedef struct _GimpColorSelection GimpColorSelection; typedef struct _GimpDialog GimpDialog; typedef struct _GimpFileEntry GimpFileEntry; typedef struct _GimpIntComboBox GimpIntComboBox; +typedef struct _GimpIntStore GimpIntStore; typedef struct _GimpMemsizeEntry GimpMemsizeEntry; typedef struct _GimpOffsetArea GimpOffsetArea; typedef struct _GimpPathEditor GimpPathEditor;