1
/* LIBGIMP - The GIMP Library
2
* Copyright (C) 1995-1999 Peter Mattis and Spencer Kimball
5
* Copyright (C) 2004, 2008 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 3 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
* Library 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, see
19
* <http://www.gnu.org/licenses/>.
26
#include "gimpwidgetstypes.h"
28
#include "gimpunitcombobox.h"
29
#include "gimpunitstore.h"
33
* SECTION: gimpunitcombobox
34
* @title: GimpUnitComboBox
35
* @short_description: A #GtkComboBox to select a #GimpUnit.
36
* @see_also: #GimpUnit, #GimpUnitStore
38
* #GimpUnitComboBox allows to select units stored in a #GimpUnitStore.
39
* It replaces the deprecated #GimpUnitMenu.
43
static void gimp_unit_combo_box_style_set (GtkWidget *widget,
44
GtkStyle *prev_style);
47
G_DEFINE_TYPE (GimpUnitComboBox, gimp_unit_combo_box, GTK_TYPE_COMBO_BOX)
49
#define parent_class gimp_unit_combo_box_parent_class
53
gimp_unit_combo_box_class_init (GimpUnitComboBoxClass *klass)
55
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
57
widget_class->style_set = gimp_unit_combo_box_style_set;
59
gtk_widget_class_install_style_property (widget_class,
60
g_param_spec_double ("label-scale",
65
GIMP_PARAM_READABLE));
69
gimp_unit_combo_box_init (GimpUnitComboBox *combo)
71
GtkCellLayout *layout = GTK_CELL_LAYOUT (combo);
72
GtkCellRenderer *cell;
74
cell = gtk_cell_renderer_text_new ();
75
gtk_cell_layout_pack_start (layout, cell, TRUE);
76
gtk_cell_layout_set_attributes (layout, cell,
77
"text", GIMP_UNIT_STORE_UNIT_LONG_FORMAT,
82
gimp_unit_combo_box_style_set (GtkWidget *widget,
85
GtkCellLayout *layout;
86
GtkCellRenderer *cell;
89
GTK_WIDGET_CLASS (parent_class)->style_set (widget, prev_style);
91
gtk_widget_style_get (widget, "label-scale", &scale, NULL);
94
layout = GTK_CELL_LAYOUT (gtk_bin_get_child (GTK_BIN (widget)));
95
gtk_cell_layout_clear (layout);
97
cell = g_object_new (GTK_TYPE_CELL_RENDERER_TEXT,
100
gtk_cell_layout_pack_start (layout, cell, TRUE);
101
gtk_cell_layout_set_attributes (layout, cell,
102
"text", GIMP_UNIT_STORE_UNIT_SHORT_FORMAT,
107
* gimp_unit_combo_box_new:
109
* Return value: a new #GimpUnitComboBox.
112
gimp_unit_combo_box_new (void)
114
GtkWidget *combo_box;
115
GimpUnitStore *store;
117
store = gimp_unit_store_new (0);
119
combo_box = g_object_new (GIMP_TYPE_UNIT_COMBO_BOX,
123
g_object_unref (store);
129
* gimp_unit_combo_box_new_with_model:
130
* @model: a GimpUnitStore
132
* Return value: a new #GimpUnitComboBox.
135
gimp_unit_combo_box_new_with_model (GimpUnitStore *model)
137
return g_object_new (GIMP_TYPE_UNIT_COMBO_BOX,
143
gimp_unit_combo_box_get_active (GimpUnitComboBox *combo)
148
g_return_val_if_fail (GIMP_IS_UNIT_COMBO_BOX (combo), -1);
150
gtk_combo_box_get_active_iter (GTK_COMBO_BOX (combo), &iter);
152
gtk_tree_model_get (gtk_combo_box_get_model (GTK_COMBO_BOX (combo)), &iter,
153
GIMP_UNIT_STORE_UNIT, &unit,
156
return (GimpUnit) unit;
160
gimp_unit_combo_box_set_active (GimpUnitComboBox *combo,
167
g_return_if_fail (GIMP_IS_UNIT_COMBO_BOX (combo));
169
model = gtk_combo_box_get_model (GTK_COMBO_BOX (combo));
171
for (iter_valid = gtk_tree_model_get_iter_first (model, &iter);
173
iter_valid = gtk_tree_model_iter_next (model, &iter))
177
gtk_tree_model_get (model, &iter,
178
GIMP_UNIT_STORE_UNIT, &iter_unit,
181
if (unit == (GimpUnit) iter_unit)
183
gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combo), &iter);