~ubuntu-branches/ubuntu/vivid/gimp/vivid

« back to all changes in this revision

Viewing changes to app/widgets/gimpunitcombobox.c

  • Committer: Package Import Robot
  • Author(s): Jordi Mallach
  • Date: 2012-05-08 18:50:03 UTC
  • mto: (1.1.26) (0.5.1 experimental)
  • mto: This revision was merged to the branch mainline in revision 71.
  • Revision ID: package-import@ubuntu.com-20120508185003-tltkvbaysf8d2426
ImportĀ upstreamĀ versionĀ 2.8.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* GIMP - The GNU Image Manipulation Program
2
 
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
3
 
 *
4
 
 * gimpunitcombobox.c
5
 
 * Copyright (C) 2004, 2008  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 "widgets-types.h"
27
 
 
28
 
#include "gimpunitcombobox.h"
29
 
#include "gimpunitstore.h"
30
 
 
31
 
 
32
 
static void  gimp_unit_combo_box_style_set (GtkWidget *widget,
33
 
                                            GtkStyle  *prev_style);
34
 
 
35
 
 
36
 
G_DEFINE_TYPE (GimpUnitComboBox, gimp_unit_combo_box, GTK_TYPE_COMBO_BOX)
37
 
 
38
 
#define parent_class gimp_unit_combo_box_parent_class
39
 
 
40
 
 
41
 
static void
42
 
gimp_unit_combo_box_class_init (GimpUnitComboBoxClass *klass)
43
 
{
44
 
  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
45
 
 
46
 
  widget_class->style_set = gimp_unit_combo_box_style_set;
47
 
 
48
 
  gtk_widget_class_install_style_property (widget_class,
49
 
                                           g_param_spec_double ("label-scale",
50
 
                                                                NULL, NULL,
51
 
                                                                0.0,
52
 
                                                                G_MAXDOUBLE,
53
 
                                                                1.0,
54
 
                                                                GIMP_PARAM_READABLE));
55
 
}
56
 
 
57
 
static void
58
 
gimp_unit_combo_box_init (GimpUnitComboBox *combo)
59
 
{
60
 
  GtkCellLayout   *layout = GTK_CELL_LAYOUT (combo);
61
 
  GtkCellRenderer *cell;
62
 
 
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,
67
 
                                  NULL);
68
 
}
69
 
 
70
 
static void
71
 
gimp_unit_combo_box_style_set (GtkWidget *widget,
72
 
                               GtkStyle  *prev_style)
73
 
{
74
 
  GtkCellLayout   *layout;
75
 
  GtkCellRenderer *cell;
76
 
  gdouble          scale;
77
 
 
78
 
  GTK_WIDGET_CLASS (parent_class)->style_set (widget, prev_style);
79
 
 
80
 
  gtk_widget_style_get (widget, "label-scale", &scale, NULL);
81
 
 
82
 
  /*  hackedehack ...  */
83
 
  layout = GTK_CELL_LAYOUT (gtk_bin_get_child (GTK_BIN (widget)));
84
 
  gtk_cell_layout_clear (layout);
85
 
 
86
 
  cell = g_object_new (GTK_TYPE_CELL_RENDERER_TEXT,
87
 
                       "scale", scale,
88
 
                       NULL);
89
 
  gtk_cell_layout_pack_start (layout, cell, TRUE);
90
 
  gtk_cell_layout_set_attributes (layout, cell,
91
 
                                  "text",  GIMP_UNIT_STORE_UNIT_ABBREVIATION,
92
 
                                  NULL);
93
 
}
94
 
 
95
 
/**
96
 
 * gimp_unit_combo_box_new:
97
 
 *
98
 
 * Return value: a new #GimpUnitComboBox.
99
 
 **/
100
 
GtkWidget *
101
 
gimp_unit_combo_box_new (void)
102
 
{
103
 
  GtkWidget     *combo_box;
104
 
  GimpUnitStore *store;
105
 
 
106
 
  store = gimp_unit_store_new (0);
107
 
 
108
 
  combo_box = g_object_new (GIMP_TYPE_UNIT_COMBO_BOX,
109
 
                            "model", store,
110
 
                            NULL);
111
 
 
112
 
  g_object_unref (store);
113
 
 
114
 
  return combo_box;
115
 
}
116
 
 
117
 
/**
118
 
 * gimp_unit_combo_box_new_with_model:
119
 
 * @model: a GimpUnitStore
120
 
 *
121
 
 * Return value: a new #GimpUnitComboBox.
122
 
 **/
123
 
GtkWidget *
124
 
gimp_unit_combo_box_new_with_model (GimpUnitStore *model)
125
 
{
126
 
  return g_object_new (GIMP_TYPE_UNIT_COMBO_BOX,
127
 
                       "model", model,
128
 
                       NULL);
129
 
}
130
 
 
131
 
GimpUnit
132
 
gimp_unit_combo_box_get_active (GimpUnitComboBox *combo)
133
 
{
134
 
  g_return_val_if_fail (GIMP_IS_UNIT_COMBO_BOX (combo), -1);
135
 
 
136
 
  return gtk_combo_box_get_active (GTK_COMBO_BOX (combo));
137
 
}
138
 
 
139
 
void
140
 
gimp_unit_combo_box_set_active (GimpUnitComboBox *combo,
141
 
                                GimpUnit          unit)
142
 
{
143
 
  g_return_if_fail (GIMP_IS_UNIT_COMBO_BOX (combo));
144
 
 
145
 
  gtk_combo_box_set_active (GTK_COMBO_BOX (combo), unit);
146
 
}