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

« back to all changes in this revision

Viewing changes to app/widgets/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
 
/* The GIMP -- an image manipulation program
2
 
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
3
 
 *
4
 
 * gimpenumcombobox.c
5
 
 * Copyright (C) 2004  Sven Neumann <sven@gimp.org>
6
 
 *
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.
11
 
 *
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.
16
 
 *
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.
20
 
 */
21
 
 
22
 
#include "config.h"
23
 
 
24
 
#include <gtk/gtk.h>
25
 
 
26
 
#include "libgimpwidgets/gimpwidgets.h"
27
 
 
28
 
#include "widgets-types.h"
29
 
 
30
 
#include "gimpenumcombobox.h"
31
 
#include "gimpenumstore.h"
32
 
 
33
 
#include "gimp-intl.h"
34
 
 
35
 
 
36
 
GType
37
 
gimp_enum_combo_box_get_type (void)
38
 
{
39
 
  static GType enum_combo_box_type = 0;
40
 
 
41
 
  if (!enum_combo_box_type)
42
 
    {
43
 
      static const GTypeInfo enum_combo_box_info =
44
 
      {
45
 
        sizeof (GimpEnumComboBoxClass),
46
 
        NULL,           /* base_init      */
47
 
        NULL,           /* base_finalize  */
48
 
        NULL,           /* class_init     */
49
 
        NULL,           /* class_finalize */
50
 
        NULL,           /* class_data     */
51
 
        sizeof (GimpEnumComboBox),
52
 
        0,              /* n_preallocs    */
53
 
        NULL            /* instance_init  */
54
 
      };
55
 
 
56
 
      enum_combo_box_type = g_type_register_static (GIMP_TYPE_INT_COMBO_BOX,
57
 
                                                    "GimpEnumComboBox",
58
 
                                                    &enum_combo_box_info, 0);
59
 
    }
60
 
 
61
 
  return enum_combo_box_type;
62
 
}
63
 
 
64
 
/**
65
 
 * gimp_enum_combo_box_new:
66
 
 * @enum_type: the #GType of an enum.
67
 
 *
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.
71
 
 *
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().
75
 
 *
76
 
 * Return value: a new #GimpEnumComboBox.
77
 
 **/
78
 
GtkWidget *
79
 
gimp_enum_combo_box_new (GType enum_type)
80
 
{
81
 
  GtkListStore *store;
82
 
  GtkWidget    *combo_box;
83
 
 
84
 
  g_return_val_if_fail (G_TYPE_IS_ENUM (enum_type), NULL);
85
 
 
86
 
  store = gimp_enum_store_new (enum_type);
87
 
 
88
 
  combo_box = g_object_new (GIMP_TYPE_ENUM_COMBO_BOX,
89
 
                            "model", store,
90
 
                            NULL);
91
 
 
92
 
  g_object_unref (store);
93
 
 
94
 
  return combo_box;
95
 
}
96
 
 
97
 
/**
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
101
 
 *
102
 
 * Attempts to create and set icons for all items in the
103
 
 * @combo_box. See gimp_enum_store_set_icons() for more info.
104
 
 **/
105
 
void
106
 
gimp_enum_combo_box_set_stock_prefix (GimpEnumComboBox *combo_box,
107
 
                                      const gchar      *stock_prefix)
108
 
{
109
 
  GtkTreeModel *model;
110
 
 
111
 
  g_return_if_fail (GIMP_IS_ENUM_COMBO_BOX (combo_box));
112
 
 
113
 
  model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo_box));
114
 
 
115
 
  gimp_enum_store_set_stock_prefix (GIMP_ENUM_STORE (model), stock_prefix);
116
 
}
117
 
 
118
 
/**
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
123
 
 *
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.
128
 
 *
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
132
 
 * model.
133
 
 *
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
137
 
 * GTK+-2.6).
138
 
 **/
139
 
void
140
 
gimp_enum_combo_box_set_visible (GimpEnumComboBox              *combo_box,
141
 
                                 GtkTreeModelFilterVisibleFunc  func,
142
 
                                 gpointer                       data)
143
 
{
144
 
  GtkTreeModel       *model;
145
 
  GtkTreeModelFilter *filter;
146
 
 
147
 
  g_return_if_fail (GIMP_IS_ENUM_COMBO_BOX (combo_box));
148
 
  g_return_if_fail (func != NULL);
149
 
 
150
 
  model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo_box));
151
 
 
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);
155
 
 
156
 
  gtk_tree_model_filter_set_visible_func (filter, func, data, NULL);
157
 
  gtk_tree_model_filter_refilter (filter);
158
 
}