~ubuntu-branches/ubuntu/jaunty/gimp/jaunty-security

« back to all changes in this revision

Viewing changes to libgimpwidgets/gimpenumcombobox.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2007-05-02 16:33:03 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070502163303-bvzhjzbpw8qglc4y
Tags: 2.3.16-1ubuntu1
* Resynchronized with Debian, remaining Ubuntu changes:
  - debian/rules: i18n magic.
* debian/control.in:
  - Maintainer: Ubuntu Core Developers <ubuntu-devel@lists.ubuntu.com>
* debian/patches/02_help-message.patch,
  debian/patches/03_gimp.desktop.in.in.patch,
  debian/patches/10_dont_show_wizard.patch: updated.
* debian/patches/04_composite-signedness.patch,
  debian/patches/05_add-letter-spacing.patch: dropped, used upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* LIBGIMP - The GIMP Library
 
2
 * Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
 
3
 *
 
4
 * gimpenumcombobox.c
 
5
 * Copyright (C) 2004  Sven Neumann <sven@gimp.org>
 
6
 *
 
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.
 
11
 *
 
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.
 
16
 *
 
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.
 
21
 */
 
22
 
 
23
#include "config.h"
 
24
 
 
25
#include <gtk/gtk.h>
 
26
 
 
27
#include "gimpwidgetstypes.h"
 
28
 
 
29
#include "gimpenumcombobox.h"
 
30
#include "gimpenumstore.h"
 
31
 
 
32
#include "libgimp/libgimp-intl.h"
 
33
 
 
34
 
 
35
enum
 
36
{
 
37
  PROP_0,
 
38
  PROP_MODEL
 
39
};
 
40
 
 
41
 
 
42
static void  gimp_enum_combo_box_set_property (GObject      *object,
 
43
                                               guint         prop_id,
 
44
                                               const GValue *value,
 
45
                                               GParamSpec   *pspec);
 
46
static void  gimp_enum_combo_box_get_property (GObject      *object,
 
47
                                               guint         prop_id,
 
48
                                               GValue       *value,
 
49
                                               GParamSpec   *pspec);
 
50
 
 
51
 
 
52
G_DEFINE_TYPE (GimpEnumComboBox, gimp_enum_combo_box,
 
53
               GIMP_TYPE_INT_COMBO_BOX)
 
54
 
 
55
#define parent_class gimp_enum_combo_box_parent_class
 
56
 
 
57
 
 
58
static void
 
59
gimp_enum_combo_box_class_init (GimpEnumComboBoxClass *klass)
 
60
{
 
61
  GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
62
 
 
63
  object_class->set_property = gimp_enum_combo_box_set_property;
 
64
  object_class->get_property = gimp_enum_combo_box_get_property;
 
65
 
 
66
  /*  override the "model" property of GtkComboBox  */
 
67
  g_object_class_install_property (object_class,
 
68
                                   PROP_MODEL,
 
69
                                   g_param_spec_object ("model", NULL, NULL,
 
70
                                                        GIMP_TYPE_ENUM_STORE,
 
71
                                                        GIMP_PARAM_READWRITE));
 
72
}
 
73
 
 
74
static void
 
75
gimp_enum_combo_box_init (GimpEnumComboBox *combo_box)
 
76
{
 
77
}
 
78
 
 
79
static void
 
80
gimp_enum_combo_box_set_property (GObject      *object,
 
81
                                  guint         prop_id,
 
82
                                  const GValue *value,
 
83
                                  GParamSpec   *pspec)
 
84
{
 
85
  GtkComboBox *combo_box = GTK_COMBO_BOX (object);
 
86
 
 
87
  switch (prop_id)
 
88
    {
 
89
    case PROP_MODEL:
 
90
      gtk_combo_box_set_model (combo_box, g_value_get_object (value));
 
91
      break;
 
92
 
 
93
    default:
 
94
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 
95
      break;
 
96
    }
 
97
}
 
98
 
 
99
static void
 
100
gimp_enum_combo_box_get_property (GObject    *object,
 
101
                                  guint       prop_id,
 
102
                                  GValue     *value,
 
103
                                  GParamSpec *pspec)
 
104
{
 
105
  GtkComboBox *combo_box = GTK_COMBO_BOX (object);
 
106
 
 
107
  switch (prop_id)
 
108
    {
 
109
    case PROP_MODEL:
 
110
      g_value_set_object (value, gtk_combo_box_get_model (combo_box));
 
111
      break;
 
112
 
 
113
    default:
 
114
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 
115
      break;
 
116
    }
 
117
}
 
118
 
 
119
 
 
120
/**
 
121
 * gimp_enum_combo_box_new:
 
122
 * @enum_type: the #GType of an enum.
 
123
 *
 
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.
 
129
 *
 
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().
 
133
 *
 
134
 * Return value: a new #GimpEnumComboBox.
 
135
 *
 
136
 * Since: GIMP 2.4
 
137
 **/
 
138
GtkWidget *
 
139
gimp_enum_combo_box_new (GType enum_type)
 
140
{
 
141
  GtkListStore *store;
 
142
  GtkWidget    *combo_box;
 
143
 
 
144
  g_return_val_if_fail (G_TYPE_IS_ENUM (enum_type), NULL);
 
145
 
 
146
  store = gimp_enum_store_new (enum_type);
 
147
 
 
148
  combo_box = g_object_new (GIMP_TYPE_ENUM_COMBO_BOX,
 
149
                            "model", store,
 
150
                            NULL);
 
151
 
 
152
  g_object_unref (store);
 
153
 
 
154
  return combo_box;
 
155
}
 
156
 
 
157
/**
 
158
 * gimp_enum_combo_box_new_with_model
 
159
 * @enum_store: a #GimpEnumStore to use as the model
 
160
 *
 
161
 * Creates a #GtkComboBox for the given @enum_store.
 
162
 *
 
163
 * Return value: a new #GimpEnumComboBox.
 
164
 *
 
165
 * Since: GIMP 2.4
 
166
 **/
 
167
GtkWidget *
 
168
gimp_enum_combo_box_new_with_model (GimpEnumStore *enum_store)
 
169
{
 
170
  g_return_val_if_fail (GIMP_IS_ENUM_STORE (enum_store), NULL);
 
171
 
 
172
  return g_object_new (GIMP_TYPE_ENUM_COMBO_BOX,
 
173
                       "model", enum_store,
 
174
                       NULL);
 
175
}
 
176
 
 
177
/**
 
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
 
181
 *
 
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.
 
184
 *
 
185
 * Since: GIMP 2.4
 
186
 **/
 
187
void
 
188
gimp_enum_combo_box_set_stock_prefix (GimpEnumComboBox *combo_box,
 
189
                                      const gchar      *stock_prefix)
 
190
{
 
191
  GtkTreeModel *model;
 
192
 
 
193
  g_return_if_fail (GIMP_IS_ENUM_COMBO_BOX (combo_box));
 
194
 
 
195
  model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo_box));
 
196
 
 
197
  gimp_enum_store_set_stock_prefix (GIMP_ENUM_STORE (model), stock_prefix);
 
198
}