1
/* GIMP - The GNU Image Manipulation Program
2
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
5
* Copyright (C) 2004, 2008 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 "widgets-types.h"
28
#include "gimpunitcombobox.h"
29
#include "gimpunitstore.h"
32
static void gimp_unit_combo_box_style_set (GtkWidget *widget,
33
GtkStyle *prev_style);
36
G_DEFINE_TYPE (GimpUnitComboBox, gimp_unit_combo_box, GTK_TYPE_COMBO_BOX)
38
#define parent_class gimp_unit_combo_box_parent_class
42
gimp_unit_combo_box_class_init (GimpUnitComboBoxClass *klass)
44
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
46
widget_class->style_set = gimp_unit_combo_box_style_set;
48
gtk_widget_class_install_style_property (widget_class,
49
g_param_spec_double ("label-scale",
54
GIMP_PARAM_READABLE));
58
gimp_unit_combo_box_init (GimpUnitComboBox *combo)
60
GtkCellLayout *layout = GTK_CELL_LAYOUT (combo);
61
GtkCellRenderer *cell;
63
cell = gtk_cell_renderer_text_new ();
64
gtk_cell_layout_pack_start (layout, cell, TRUE);
65
gtk_cell_layout_set_attributes (layout, cell,
66
"text", GIMP_UNIT_STORE_UNIT_PLURAL,
71
gimp_unit_combo_box_style_set (GtkWidget *widget,
74
GtkCellLayout *layout;
75
GtkCellRenderer *cell;
78
GTK_WIDGET_CLASS (parent_class)->style_set (widget, prev_style);
80
gtk_widget_style_get (widget, "label-scale", &scale, NULL);
83
layout = GTK_CELL_LAYOUT (gtk_bin_get_child (GTK_BIN (widget)));
84
gtk_cell_layout_clear (layout);
86
cell = g_object_new (GTK_TYPE_CELL_RENDERER_TEXT,
89
gtk_cell_layout_pack_start (layout, cell, TRUE);
90
gtk_cell_layout_set_attributes (layout, cell,
91
"text", GIMP_UNIT_STORE_UNIT_ABBREVIATION,
96
* gimp_unit_combo_box_new:
98
* Return value: a new #GimpUnitComboBox.
101
gimp_unit_combo_box_new (void)
103
GtkWidget *combo_box;
104
GimpUnitStore *store;
106
store = gimp_unit_store_new (0);
108
combo_box = g_object_new (GIMP_TYPE_UNIT_COMBO_BOX,
112
g_object_unref (store);
118
* gimp_unit_combo_box_new_with_model:
119
* @model: a GimpUnitStore
121
* Return value: a new #GimpUnitComboBox.
124
gimp_unit_combo_box_new_with_model (GimpUnitStore *model)
126
return g_object_new (GIMP_TYPE_UNIT_COMBO_BOX,
132
gimp_unit_combo_box_get_active (GimpUnitComboBox *combo)
134
g_return_val_if_fail (GIMP_IS_UNIT_COMBO_BOX (combo), -1);
136
return gtk_combo_box_get_active (GTK_COMBO_BOX (combo));
140
gimp_unit_combo_box_set_active (GimpUnitComboBox *combo,
143
g_return_if_fail (GIMP_IS_UNIT_COMBO_BOX (combo));
145
gtk_combo_box_set_active (GTK_COMBO_BOX (combo), unit);