~ubuntu-branches/ubuntu/maverick/gimp/maverick-updates

« back to all changes in this revision

Viewing changes to app/widgets/gimpstringaction.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2005-12-09 19:44:52 UTC
  • Revision ID: james.westby@ubuntu.com-20051209194452-yggpemjlofpjqyf4
Tags: upstream-2.2.9
ImportĀ upstreamĀ versionĀ 2.2.9

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
 * gimpstringaction.c
 
5
 * Copyright (C) 2004 Michael Natterer <mitch@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 "core/gimpmarshal.h"
 
29
 
 
30
#include "gimpstringaction.h"
 
31
 
 
32
 
 
33
enum
 
34
{
 
35
  SELECTED,
 
36
  LAST_SIGNAL
 
37
};
 
38
 
 
39
enum
 
40
{
 
41
  PROP_0,
 
42
  PROP_VALUE
 
43
};
 
44
 
 
45
 
 
46
static void   gimp_string_action_init       (GimpStringAction      *action);
 
47
static void   gimp_string_action_class_init (GimpStringActionClass *klass);
 
48
 
 
49
static void   gimp_string_action_finalize     (GObject      *object);
 
50
static void   gimp_string_action_set_property (GObject      *object,
 
51
                                               guint         prop_id,
 
52
                                               const GValue *value,
 
53
                                               GParamSpec   *pspec);
 
54
static void   gimp_string_action_get_property (GObject      *object,
 
55
                                               guint         prop_id,
 
56
                                               GValue       *value,
 
57
                                               GParamSpec   *pspec);
 
58
 
 
59
static void   gimp_string_action_activate     (GtkAction    *action);
 
60
 
 
61
 
 
62
static GtkActionClass *parent_class                = NULL;
 
63
static guint           action_signals[LAST_SIGNAL] = { 0 };
 
64
 
 
65
 
 
66
GType
 
67
gimp_string_action_get_type (void)
 
68
{
 
69
  static GType type = 0;
 
70
 
 
71
  if (!type)
 
72
    {
 
73
      static const GTypeInfo type_info =
 
74
      {
 
75
        sizeof (GimpStringActionClass),
 
76
        (GBaseInitFunc) NULL,
 
77
        (GBaseFinalizeFunc) NULL,
 
78
        (GClassInitFunc) gimp_string_action_class_init,
 
79
        (GClassFinalizeFunc) NULL,
 
80
        NULL,
 
81
        sizeof (GimpStringAction),
 
82
        0, /* n_preallocs */
 
83
        (GInstanceInitFunc) gimp_string_action_init,
 
84
      };
 
85
 
 
86
      type = g_type_register_static (GIMP_TYPE_ACTION,
 
87
                                     "GimpStringAction",
 
88
                                     &type_info, 0);
 
89
    }
 
90
 
 
91
  return type;
 
92
}
 
93
 
 
94
static void
 
95
gimp_string_action_class_init (GimpStringActionClass *klass)
 
96
{
 
97
  GObjectClass   *object_class = G_OBJECT_CLASS (klass);
 
98
  GtkActionClass *action_class = GTK_ACTION_CLASS (klass);
 
99
 
 
100
  parent_class = g_type_class_peek_parent (klass);
 
101
 
 
102
  object_class->finalize     = gimp_string_action_finalize;
 
103
  object_class->set_property = gimp_string_action_set_property;
 
104
  object_class->get_property = gimp_string_action_get_property;
 
105
 
 
106
  action_class->activate = gimp_string_action_activate;
 
107
 
 
108
  g_object_class_install_property (object_class, PROP_VALUE,
 
109
                                   g_param_spec_string ("value",
 
110
                                                        NULL, NULL,
 
111
                                                        NULL,
 
112
                                                        G_PARAM_READWRITE));
 
113
 
 
114
  action_signals[SELECTED] =
 
115
    g_signal_new ("selected",
 
116
                  G_TYPE_FROM_CLASS (klass),
 
117
                  G_SIGNAL_RUN_FIRST,
 
118
                  G_STRUCT_OFFSET (GimpStringActionClass, selected),
 
119
                  NULL, NULL,
 
120
                  gimp_marshal_VOID__STRING,
 
121
                  G_TYPE_NONE, 1,
 
122
                  G_TYPE_STRING);
 
123
}
 
124
 
 
125
static void
 
126
gimp_string_action_init (GimpStringAction *action)
 
127
{
 
128
  action->value = NULL;
 
129
}
 
130
 
 
131
static void
 
132
gimp_string_action_finalize (GObject *object)
 
133
{
 
134
  GimpStringAction *action = GIMP_STRING_ACTION (object);
 
135
 
 
136
  if (action->value)
 
137
    {
 
138
      g_free (action->value);
 
139
      action->value = NULL;
 
140
    }
 
141
 
 
142
  G_OBJECT_CLASS (parent_class)->finalize (object);
 
143
}
 
144
 
 
145
static void
 
146
gimp_string_action_get_property (GObject    *object,
 
147
                                 guint       prop_id,
 
148
                                 GValue     *value,
 
149
                                 GParamSpec *pspec)
 
150
{
 
151
  GimpStringAction *action = GIMP_STRING_ACTION (object);
 
152
 
 
153
  switch (prop_id)
 
154
    {
 
155
    case PROP_VALUE:
 
156
      g_value_set_string (value, action->value);
 
157
      break;
 
158
    default:
 
159
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 
160
      break;
 
161
    }
 
162
}
 
163
 
 
164
static void
 
165
gimp_string_action_set_property (GObject      *object,
 
166
                                 guint         prop_id,
 
167
                                 const GValue *value,
 
168
                                 GParamSpec   *pspec)
 
169
{
 
170
  GimpStringAction *action = GIMP_STRING_ACTION (object);
 
171
 
 
172
  switch (prop_id)
 
173
    {
 
174
    case PROP_VALUE:
 
175
      g_free (action->value);
 
176
      action->value = g_value_dup_string (value);
 
177
      break;
 
178
    default:
 
179
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 
180
      break;
 
181
    }
 
182
}
 
183
 
 
184
GimpStringAction *
 
185
gimp_string_action_new (const gchar *name,
 
186
                        const gchar *label,
 
187
                        const gchar *tooltip,
 
188
                        const gchar *stock_id,
 
189
                        const gchar *value)
 
190
{
 
191
  return g_object_new (GIMP_TYPE_STRING_ACTION,
 
192
                       "name",     name,
 
193
                       "label",    label,
 
194
                       "tooltip",  tooltip,
 
195
                       "stock_id", stock_id,
 
196
                       "value",    value,
 
197
                       NULL);
 
198
}
 
199
 
 
200
static void
 
201
gimp_string_action_activate (GtkAction *action)
 
202
{
 
203
  GimpStringAction *string_action = GIMP_STRING_ACTION (action);
 
204
 
 
205
  gimp_string_action_selected (string_action, string_action->value);
 
206
}
 
207
 
 
208
void
 
209
gimp_string_action_selected (GimpStringAction *action,
 
210
                             const gchar      *value)
 
211
{
 
212
  g_return_if_fail (GIMP_IS_STRING_ACTION (action));
 
213
 
 
214
  g_signal_emit (action, action_signals[SELECTED], 0, value);
 
215
}