~ubuntu-branches/ubuntu/breezy/gimp/breezy

« back to all changes in this revision

Viewing changes to app/core/gimptoolinfo.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2005-10-04 19:04:46 UTC
  • Revision ID: james.westby@ubuntu.com-20051004190446-ukh32kwk56s4sjhu
Tags: upstream-2.2.8
ImportĀ upstreamĀ versionĀ 2.2.8

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
 * This program is free software; you can redistribute it and/or modify
 
5
 * it under the terms of the GNU General Public License as published by
 
6
 * the Free Software Foundation; either version 2 of the License, or
 
7
 * (at your option) any later version.
 
8
 *
 
9
 * This program is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
 * GNU General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU General Public License
 
15
 * along with this program; if not, write to the Free Software
 
16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
17
 */
 
18
 
 
19
#include "config.h"
 
20
 
 
21
#include <string.h>
 
22
 
 
23
#include <glib-object.h>
 
24
 
 
25
#include "core-types.h"
 
26
 
 
27
#include "base/temp-buf.h"
 
28
 
 
29
#include "config/gimpconfig-params.h"
 
30
 
 
31
#include "gimp.h"
 
32
#include "gimpcontainer.h"
 
33
#include "gimpcontext.h"
 
34
#include "gimplist.h"
 
35
#include "gimppaintinfo.h"
 
36
#include "gimptoolinfo.h"
 
37
#include "gimptooloptions.h"
 
38
 
 
39
 
 
40
enum
 
41
{
 
42
  PROP_0,
 
43
  PROP_VISIBLE
 
44
};
 
45
 
 
46
 
 
47
static void    gimp_tool_info_class_init      (GimpToolInfoClass *klass);
 
48
static void    gimp_tool_info_init            (GimpToolInfo      *tool_info);
 
49
 
 
50
static void    gimp_tool_info_finalize        (GObject           *object);
 
51
static void    gimp_tool_info_get_property    (GObject           *object,
 
52
                                               guint              property_id,
 
53
                                               GValue            *value,
 
54
                                               GParamSpec        *pspec);
 
55
static void    gimp_tool_info_set_property    (GObject           *object,
 
56
                                               guint              property_id,
 
57
                                               const GValue      *value,
 
58
                                               GParamSpec        *pspec);
 
59
static gchar * gimp_tool_info_get_description (GimpViewable      *viewable,
 
60
                                               gchar            **tooltip);
 
61
 
 
62
 
 
63
static GimpViewableClass *parent_class = NULL;
 
64
 
 
65
 
 
66
GType
 
67
gimp_tool_info_get_type (void)
 
68
{
 
69
  static GType tool_info_type = 0;
 
70
 
 
71
  if (! tool_info_type)
 
72
    {
 
73
      static const GTypeInfo tool_info_info =
 
74
      {
 
75
        sizeof (GimpToolInfoClass),
 
76
        (GBaseInitFunc) NULL,
 
77
        (GBaseFinalizeFunc) NULL,
 
78
        (GClassInitFunc) gimp_tool_info_class_init,
 
79
        NULL,           /* class_finalize */
 
80
        NULL,           /* class_data     */
 
81
        sizeof (GimpToolInfo),
 
82
        0,              /* n_preallocs    */
 
83
        (GInstanceInitFunc) gimp_tool_info_init,
 
84
      };
 
85
 
 
86
      tool_info_type = g_type_register_static (GIMP_TYPE_VIEWABLE,
 
87
                                               "GimpToolInfo",
 
88
                                               &tool_info_info, 0);
 
89
    }
 
90
 
 
91
  return tool_info_type;
 
92
}
 
93
 
 
94
static void
 
95
gimp_tool_info_class_init (GimpToolInfoClass *klass)
 
96
{
 
97
  GObjectClass      *object_class   = G_OBJECT_CLASS (klass);
 
98
  GimpViewableClass *viewable_class = GIMP_VIEWABLE_CLASS (klass);
 
99
 
 
100
  parent_class = g_type_class_peek_parent (klass);
 
101
 
 
102
  object_class->finalize          = gimp_tool_info_finalize;
 
103
  object_class->get_property      = gimp_tool_info_get_property;
 
104
  object_class->set_property      = gimp_tool_info_set_property;
 
105
 
 
106
  viewable_class->get_description = gimp_tool_info_get_description;
 
107
 
 
108
  GIMP_CONFIG_INSTALL_PROP_BOOLEAN (object_class, PROP_VISIBLE, "visible",
 
109
                                    NULL, TRUE, 0);
 
110
}
 
111
 
 
112
static void
 
113
gimp_tool_info_init (GimpToolInfo *tool_info)
 
114
{
 
115
  tool_info->gimp              = NULL;
 
116
 
 
117
  tool_info->tool_type         = G_TYPE_NONE;
 
118
  tool_info->tool_options_type = G_TYPE_NONE;
 
119
  tool_info->context_props     = 0;
 
120
 
 
121
  tool_info->blurb             = NULL;
 
122
  tool_info->help              = NULL;
 
123
 
 
124
  tool_info->menu_path         = NULL;
 
125
  tool_info->menu_accel        = NULL;
 
126
 
 
127
  tool_info->help_domain       = NULL;
 
128
  tool_info->help_id           = NULL;
 
129
 
 
130
  tool_info->visible           = TRUE;
 
131
  tool_info->tool_options      = NULL;
 
132
  tool_info->paint_info        = NULL;
 
133
}
 
134
 
 
135
static void
 
136
gimp_tool_info_finalize (GObject *object)
 
137
{
 
138
  GimpToolInfo *tool_info = GIMP_TOOL_INFO (object);
 
139
 
 
140
  if (tool_info->blurb)
 
141
    {
 
142
      g_free (tool_info->blurb);
 
143
      tool_info->blurb = NULL;
 
144
    }
 
145
  if (tool_info->help)
 
146
    {
 
147
      g_free (tool_info->help);
 
148
      tool_info->blurb = NULL;
 
149
    }
 
150
 
 
151
  if (tool_info->menu_path)
 
152
    {
 
153
      g_free (tool_info->menu_path);
 
154
      tool_info->menu_path = NULL;
 
155
    }
 
156
  if (tool_info->menu_accel)
 
157
    {
 
158
      g_free (tool_info->menu_accel);
 
159
      tool_info->menu_accel = NULL;
 
160
    }
 
161
 
 
162
  if (tool_info->help_domain)
 
163
    {
 
164
      g_free (tool_info->help_domain);
 
165
      tool_info->help_domain = NULL;
 
166
    }
 
167
  if (tool_info->help_id)
 
168
    {
 
169
      g_free (tool_info->help_id);
 
170
      tool_info->help_id = NULL;
 
171
    }
 
172
 
 
173
  if (tool_info->tool_options)
 
174
    {
 
175
      g_object_unref (tool_info->tool_options);
 
176
      tool_info->tool_options = NULL;
 
177
    }
 
178
 
 
179
  if (tool_info->options_presets)
 
180
    {
 
181
      g_object_unref (tool_info->options_presets);
 
182
      tool_info->options_presets = NULL;
 
183
    }
 
184
 
 
185
  G_OBJECT_CLASS (parent_class)->finalize (object);
 
186
}
 
187
 
 
188
static void
 
189
gimp_tool_info_get_property (GObject    *object,
 
190
                             guint       property_id,
 
191
                             GValue     *value,
 
192
                             GParamSpec *pspec)
 
193
{
 
194
  GimpToolInfo *tool_info = GIMP_TOOL_INFO (object);
 
195
 
 
196
  switch (property_id)
 
197
    {
 
198
    case PROP_VISIBLE:
 
199
      g_value_set_boolean (value, tool_info->visible);
 
200
      break;
 
201
    default:
 
202
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 
203
      break;
 
204
    }
 
205
}
 
206
 
 
207
static void
 
208
gimp_tool_info_set_property (GObject      *object,
 
209
                             guint         property_id,
 
210
                             const GValue *value,
 
211
                             GParamSpec   *pspec)
 
212
{
 
213
  GimpToolInfo *tool_info = GIMP_TOOL_INFO (object);
 
214
 
 
215
  switch (property_id)
 
216
    {
 
217
    case PROP_VISIBLE:
 
218
      tool_info->visible = g_value_get_boolean (value);
 
219
      break;
 
220
    default:
 
221
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
 
222
      break;
 
223
    }
 
224
}
 
225
 
 
226
static gchar *
 
227
gimp_tool_info_get_description (GimpViewable  *viewable,
 
228
                                gchar        **tooltip)
 
229
{
 
230
  GimpToolInfo *tool_info = GIMP_TOOL_INFO (viewable);
 
231
 
 
232
  if (tooltip)
 
233
    *tooltip = NULL;
 
234
 
 
235
  return g_strdup (tool_info->blurb);
 
236
}
 
237
 
 
238
GimpToolInfo *
 
239
gimp_tool_info_new (Gimp                *gimp,
 
240
                    GType                tool_type,
 
241
                    GType                tool_options_type,
 
242
                    GimpContextPropMask  context_props,
 
243
                    const gchar         *identifier,
 
244
                    const gchar         *blurb,
 
245
                    const gchar         *help,
 
246
                    const gchar         *menu_path,
 
247
                    const gchar         *menu_accel,
 
248
                    const gchar         *help_domain,
 
249
                    const gchar         *help_id,
 
250
                    const gchar         *paint_core_name,
 
251
                    const gchar         *stock_id)
 
252
{
 
253
  GimpPaintInfo *paint_info;
 
254
  GimpToolInfo  *tool_info;
 
255
 
 
256
  g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
 
257
  g_return_val_if_fail (identifier != NULL, NULL);
 
258
  g_return_val_if_fail (blurb != NULL, NULL);
 
259
  g_return_val_if_fail (help != NULL, NULL);
 
260
  g_return_val_if_fail (menu_path != NULL, NULL);
 
261
  g_return_val_if_fail (help_id != NULL, NULL);
 
262
  g_return_val_if_fail (paint_core_name != NULL, NULL);
 
263
  g_return_val_if_fail (stock_id != NULL, NULL);
 
264
 
 
265
  paint_info = (GimpPaintInfo *)
 
266
    gimp_container_get_child_by_name (gimp->paint_info_list, paint_core_name);
 
267
 
 
268
  g_return_val_if_fail (GIMP_IS_PAINT_INFO (paint_info), NULL);
 
269
 
 
270
  tool_info = g_object_new (GIMP_TYPE_TOOL_INFO,
 
271
                            "name",     identifier,
 
272
                            "stock-id", stock_id,
 
273
                            NULL);
 
274
 
 
275
  tool_info->gimp              = gimp;
 
276
  tool_info->tool_type         = tool_type;
 
277
  tool_info->tool_options_type = tool_options_type;
 
278
  tool_info->context_props     = context_props;
 
279
 
 
280
  tool_info->blurb             = g_strdup (blurb);
 
281
  tool_info->help              = g_strdup (help);
 
282
 
 
283
  tool_info->menu_path         = g_strdup (menu_path);
 
284
  tool_info->menu_accel        = g_strdup (menu_accel);
 
285
 
 
286
  tool_info->help_domain       = g_strdup (help_domain);
 
287
  tool_info->help_id           = g_strdup (help_id);
 
288
 
 
289
  tool_info->paint_info        = paint_info;
 
290
 
 
291
  if (tool_info->tool_options_type == paint_info->paint_options_type)
 
292
    {
 
293
      gimp_viewable_set_stock_id (GIMP_VIEWABLE (paint_info), stock_id);
 
294
 
 
295
      tool_info->tool_options = g_object_ref (paint_info->paint_options);
 
296
    }
 
297
  else
 
298
    {
 
299
      tool_info->tool_options = g_object_new (tool_info->tool_options_type,
 
300
                                              "gimp", gimp,
 
301
                                              NULL);
 
302
    }
 
303
 
 
304
  g_object_set (tool_info->tool_options, "tool-info", tool_info, NULL);
 
305
 
 
306
  if (tool_info->context_props)
 
307
    {
 
308
      gimp_context_define_properties (GIMP_CONTEXT (tool_info->tool_options),
 
309
                                      tool_info->context_props, FALSE);
 
310
 
 
311
      gimp_context_copy_properties (gimp_get_user_context (gimp),
 
312
                                    GIMP_CONTEXT (tool_info->tool_options),
 
313
                                    GIMP_CONTEXT_ALL_PROPS_MASK);
 
314
    }
 
315
 
 
316
  gimp_context_set_serialize_properties (GIMP_CONTEXT (tool_info->tool_options),
 
317
                                         tool_info->context_props);
 
318
 
 
319
  if (tool_info->tool_options_type != GIMP_TYPE_TOOL_OPTIONS)
 
320
    {
 
321
      tool_info->options_presets = gimp_list_new (tool_info->tool_options_type,
 
322
                                                  TRUE);
 
323
    }
 
324
 
 
325
  return tool_info;
 
326
}
 
327
 
 
328
void
 
329
gimp_tool_info_set_standard (Gimp         *gimp,
 
330
                             GimpToolInfo *tool_info)
 
331
{
 
332
  g_return_if_fail (GIMP_IS_GIMP (gimp));
 
333
  g_return_if_fail (! tool_info || GIMP_IS_TOOL_INFO (tool_info));
 
334
 
 
335
  if (tool_info != gimp->standard_tool_info)
 
336
    {
 
337
      if (gimp->standard_tool_info)
 
338
        g_object_unref (gimp->standard_tool_info);
 
339
 
 
340
      gimp->standard_tool_info = tool_info;
 
341
 
 
342
      if (gimp->standard_tool_info)
 
343
        g_object_ref (gimp->standard_tool_info);
 
344
    }
 
345
}
 
346
 
 
347
GimpToolInfo *
 
348
gimp_tool_info_get_standard (Gimp *gimp)
 
349
{
 
350
  g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
 
351
 
 
352
  return gimp->standard_tool_info;
 
353
}