1
/* LIBGIMP - The GIMP Library
2
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
5
* Copyright (C) 2004 Sven Neumann <sven@gimp.org>
7
* This library is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU Lesser General Public
9
* License as published by the Free Software Foundation; either
10
* version 2 of the License, or (at your option) any later version.
12
* This library is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
* Lesser General Public License for more details.
17
* You should have received a copy of the GNU Lesser General Public
18
* License along with this library; if not, write to the
19
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20
* Boston, MA 02111-1307, USA.
27
#include "gimpwidgetstypes.h"
29
#include "gimpenumcombobox.h"
30
#include "gimpenumstore.h"
32
#include "libgimp/libgimp-intl.h"
42
static void gimp_enum_combo_box_set_property (GObject *object,
46
static void gimp_enum_combo_box_get_property (GObject *object,
52
G_DEFINE_TYPE (GimpEnumComboBox, gimp_enum_combo_box,
53
GIMP_TYPE_INT_COMBO_BOX)
55
#define parent_class gimp_enum_combo_box_parent_class
59
gimp_enum_combo_box_class_init (GimpEnumComboBoxClass *klass)
61
GObjectClass *object_class = G_OBJECT_CLASS (klass);
63
object_class->set_property = gimp_enum_combo_box_set_property;
64
object_class->get_property = gimp_enum_combo_box_get_property;
66
/* override the "model" property of GtkComboBox */
67
g_object_class_install_property (object_class,
69
g_param_spec_object ("model", NULL, NULL,
71
GIMP_PARAM_READWRITE));
75
gimp_enum_combo_box_init (GimpEnumComboBox *combo_box)
80
gimp_enum_combo_box_set_property (GObject *object,
85
GtkComboBox *combo_box = GTK_COMBO_BOX (object);
90
gtk_combo_box_set_model (combo_box, g_value_get_object (value));
94
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
100
gimp_enum_combo_box_get_property (GObject *object,
105
GtkComboBox *combo_box = GTK_COMBO_BOX (object);
110
g_value_set_object (value, gtk_combo_box_get_model (combo_box));
114
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
121
* gimp_enum_combo_box_new:
122
* @enum_type: the #GType of an enum.
124
* Creates a #GtkComboBox readily filled with all enum values from a
125
* given @enum_type. The enum needs to be registered to the type
126
* system. It should also have %GimpEnumDesc descriptions registered
127
* that contain translatable value names. This is the case for the
128
* enums used in the GIMP PDB functions.
130
* This is just a convenience function. If you need more control over
131
* the enum values that appear in the combo_box, you can create your
132
* own #GimpEnumStore and use gimp_enum_combo_box_new_with_model().
134
* Return value: a new #GimpEnumComboBox.
139
gimp_enum_combo_box_new (GType enum_type)
142
GtkWidget *combo_box;
144
g_return_val_if_fail (G_TYPE_IS_ENUM (enum_type), NULL);
146
store = gimp_enum_store_new (enum_type);
148
combo_box = g_object_new (GIMP_TYPE_ENUM_COMBO_BOX,
152
g_object_unref (store);
158
* gimp_enum_combo_box_new_with_model
159
* @enum_store: a #GimpEnumStore to use as the model
161
* Creates a #GtkComboBox for the given @enum_store.
163
* Return value: a new #GimpEnumComboBox.
168
gimp_enum_combo_box_new_with_model (GimpEnumStore *enum_store)
170
g_return_val_if_fail (GIMP_IS_ENUM_STORE (enum_store), NULL);
172
return g_object_new (GIMP_TYPE_ENUM_COMBO_BOX,
178
* gimp_enum_combo_box_set_stock_prefix:
179
* @combo_box: a #GimpEnumComboBox
180
* @stock_prefix: a prefix to create icon stock ID from enum values
182
* Attempts to create stock icons for all items in the @combo_box. See
183
* gimp_enum_store_set_icons() to find out what to use as @stock_prefix.
188
gimp_enum_combo_box_set_stock_prefix (GimpEnumComboBox *combo_box,
189
const gchar *stock_prefix)
193
g_return_if_fail (GIMP_IS_ENUM_COMBO_BOX (combo_box));
195
model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo_box));
197
gimp_enum_store_set_stock_prefix (GIMP_ENUM_STORE (model), stock_prefix);