1
/* The GIMP -- an image manipulation program
2
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
5
* Copyright (C) 2004 Sven Neumann <sven@gimp.org>
7
* This program is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; either version 2 of the License, or
10
* (at your option) any later version.
12
* This program 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
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with this program; if not, write to the Free Software
19
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26
#include "libgimpwidgets/gimpwidgets.h"
28
#include "widgets-types.h"
30
#include "gimpenumcombobox.h"
31
#include "gimpenumstore.h"
33
#include "gimp-intl.h"
37
gimp_enum_combo_box_get_type (void)
39
static GType enum_combo_box_type = 0;
41
if (!enum_combo_box_type)
43
static const GTypeInfo enum_combo_box_info =
45
sizeof (GimpEnumComboBoxClass),
47
NULL, /* base_finalize */
48
NULL, /* class_init */
49
NULL, /* class_finalize */
50
NULL, /* class_data */
51
sizeof (GimpEnumComboBox),
53
NULL /* instance_init */
56
enum_combo_box_type = g_type_register_static (GIMP_TYPE_INT_COMBO_BOX,
58
&enum_combo_box_info, 0);
61
return enum_combo_box_type;
65
* gimp_enum_combo_box_new:
66
* @enum_type: the #GType of an enum.
68
* Creates a #GtkComboBox readily filled with all enum values from a
69
* given @enum_type. The enum needs to be registered to the type
70
* system and should have translatable value names.
72
* This is just a convenience function. If you need more control over
73
* the enum values that appear in the combo_box, you can create your
74
* own #GimpEnumStore and use gimp_enum_combo_box_new_with_model().
76
* Return value: a new #GimpEnumComboBox.
79
gimp_enum_combo_box_new (GType enum_type)
84
g_return_val_if_fail (G_TYPE_IS_ENUM (enum_type), NULL);
86
store = gimp_enum_store_new (enum_type);
88
combo_box = g_object_new (GIMP_TYPE_ENUM_COMBO_BOX,
92
g_object_unref (store);
98
* gimp_enum_combo_box_set_stock_prefix:
99
* @combo_box: a #GimpEnumComboBox
100
* @stock_prefix: a prefix to create icon stock ID from enum values
102
* Attempts to create and set icons for all items in the
103
* @combo_box. See gimp_enum_store_set_icons() for more info.
106
gimp_enum_combo_box_set_stock_prefix (GimpEnumComboBox *combo_box,
107
const gchar *stock_prefix)
111
g_return_if_fail (GIMP_IS_ENUM_COMBO_BOX (combo_box));
113
model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo_box));
115
gimp_enum_store_set_stock_prefix (GIMP_ENUM_STORE (model), stock_prefix);
119
* gimp_enum_combo_box_set_visible:
120
* @combo_box: a #GimpEnumComboBox
121
* @func: a #GtkTreeModelFilterVisibleFunc
122
* @data: a pointer that is passed to @func
124
* Sets a filter on the combo_box that selectively hides items. The
125
* registered callback @func is called with an iter for each item and
126
* must return %TRUE or %FALSE indicating whether the respective row
127
* should be visible or not.
129
* This function must only be called once for a @combo_box. If you
130
* want to refresh the visibility of the items in the @combo_box
131
* later, call gtk_tree_model_filter_refilter() on the @combo_box's
134
* This is a kludge to allow to work around the inability of
135
* #GtkComboBox to set the sensitivity of it's items (bug #135875).
136
* It should be removed as soon as this bug is fixed (probably with
140
gimp_enum_combo_box_set_visible (GimpEnumComboBox *combo_box,
141
GtkTreeModelFilterVisibleFunc func,
145
GtkTreeModelFilter *filter;
147
g_return_if_fail (GIMP_IS_ENUM_COMBO_BOX (combo_box));
148
g_return_if_fail (func != NULL);
150
model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo_box));
152
filter = GTK_TREE_MODEL_FILTER (gtk_tree_model_filter_new (model, NULL));
153
gtk_combo_box_set_model (GTK_COMBO_BOX (combo_box), GTK_TREE_MODEL (filter));
154
g_object_unref (filter);
156
gtk_tree_model_filter_set_visible_func (filter, func, data, NULL);
157
gtk_tree_model_filter_refilter (filter);