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

« back to all changes in this revision

Viewing changes to app/core/gimp-gui.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-2002 Spencer Kimball, Peter Mattis, and others
 
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 <glib-object.h>
 
22
 
 
23
#include "core-types.h"
 
24
 
 
25
#include "gimp.h"
 
26
#include "gimp-gui.h"
 
27
#include "gimpcontainer.h"
 
28
#include "gimpcontext.h"
 
29
#include "gimpimage.h"
 
30
#include "gimpprogress.h"
 
31
 
 
32
#include "libgimpbase/gimputils.h"
 
33
 
 
34
#include "gimp-intl.h"
 
35
 
 
36
 
 
37
void
 
38
gimp_gui_init (Gimp *gimp)
 
39
{
 
40
  g_return_if_fail (GIMP_IS_GIMP (gimp));
 
41
 
 
42
  gimp->gui.threads_enter      = NULL;
 
43
  gimp->gui.threads_leave      = NULL;
 
44
  gimp->gui.set_busy           = NULL;
 
45
  gimp->gui.unset_busy         = NULL;
 
46
  gimp->gui.message            = NULL;
 
47
  gimp->gui.help               = NULL;
 
48
  gimp->gui.get_program_class  = NULL;
 
49
  gimp->gui.get_display_name   = NULL;
 
50
  gimp->gui.get_theme_dir      = NULL;
 
51
  gimp->gui.display_get_by_id  = NULL;
 
52
  gimp->gui.display_get_id     = NULL;
 
53
  gimp->gui.display_create     = NULL;
 
54
  gimp->gui.display_delete     = NULL;
 
55
  gimp->gui.displays_reconnect = NULL;
 
56
  gimp->gui.menus_init         = NULL;
 
57
  gimp->gui.menus_create       = NULL;
 
58
  gimp->gui.menus_delete       = NULL;
 
59
  gimp->gui.progress_new       = NULL;
 
60
  gimp->gui.progress_free      = NULL;
 
61
  gimp->gui.pdb_dialog_set     = NULL;
 
62
  gimp->gui.pdb_dialog_close   = NULL;
 
63
  gimp->gui.pdb_dialogs_check  = NULL;
 
64
}
 
65
 
 
66
void
 
67
gimp_threads_enter (Gimp *gimp)
 
68
{
 
69
  g_return_if_fail (GIMP_IS_GIMP (gimp));
 
70
 
 
71
  if (gimp->gui.threads_enter)
 
72
    gimp->gui.threads_enter (gimp);
 
73
}
 
74
 
 
75
void
 
76
gimp_threads_leave (Gimp *gimp)
 
77
{
 
78
  g_return_if_fail (GIMP_IS_GIMP (gimp));
 
79
 
 
80
  if (gimp->gui.threads_leave)
 
81
    gimp->gui.threads_leave (gimp);
 
82
}
 
83
 
 
84
void
 
85
gimp_set_busy (Gimp *gimp)
 
86
{
 
87
  g_return_if_fail (GIMP_IS_GIMP (gimp));
 
88
 
 
89
  /* FIXME: gimp_busy HACK */
 
90
  gimp->busy++;
 
91
 
 
92
  if (gimp->busy == 1)
 
93
    {
 
94
      if (gimp->gui.set_busy)
 
95
        gimp->gui.set_busy (gimp);
 
96
    }
 
97
}
 
98
 
 
99
static gboolean
 
100
gimp_idle_unset_busy (gpointer data)
 
101
{
 
102
  Gimp *gimp = data;
 
103
 
 
104
  gimp_unset_busy (gimp);
 
105
 
 
106
  gimp->busy_idle_id = 0;
 
107
 
 
108
  return FALSE;
 
109
}
 
110
 
 
111
void
 
112
gimp_set_busy_until_idle (Gimp *gimp)
 
113
{
 
114
  g_return_if_fail (GIMP_IS_GIMP (gimp));
 
115
 
 
116
  if (! gimp->busy_idle_id)
 
117
    {
 
118
      gimp_set_busy (gimp);
 
119
 
 
120
      gimp->busy_idle_id = g_idle_add_full (G_PRIORITY_HIGH,
 
121
                                            gimp_idle_unset_busy, gimp,
 
122
                                            NULL);
 
123
    }
 
124
}
 
125
 
 
126
void
 
127
gimp_unset_busy (Gimp *gimp)
 
128
{
 
129
  g_return_if_fail (GIMP_IS_GIMP (gimp));
 
130
  g_return_if_fail (gimp->busy > 0);
 
131
 
 
132
  /* FIXME: gimp_busy HACK */
 
133
  gimp->busy--;
 
134
 
 
135
  if (gimp->busy == 0)
 
136
    {
 
137
      if (gimp->gui.unset_busy)
 
138
        gimp->gui.unset_busy (gimp);
 
139
    }
 
140
}
 
141
 
 
142
void
 
143
gimp_message (Gimp        *gimp,
 
144
              const gchar *domain,
 
145
              const gchar *message)
 
146
{
 
147
  gchar *message2 = gimp_any_to_utf8 (message, -1,
 
148
                                      "Cannot convert message to utf8.");
 
149
 
 
150
  g_return_if_fail (GIMP_IS_GIMP (gimp));
 
151
 
 
152
  if (! domain)
 
153
    domain = _("GIMP");
 
154
 
 
155
  if (! gimp->console_messages && gimp->gui.message)
 
156
    gimp->gui.message (gimp, domain, message2);
 
157
  else
 
158
    g_printerr ("%s: %s\n\n", domain, message2);
 
159
 
 
160
  g_free (message2);
 
161
}
 
162
 
 
163
void
 
164
gimp_help (Gimp        *gimp,
 
165
           const gchar *help_domain,
 
166
           const gchar *help_id)
 
167
{
 
168
  g_return_if_fail (GIMP_IS_GIMP (gimp));
 
169
 
 
170
  if (gimp->gui.help)
 
171
    gimp->gui.help (gimp, help_domain, help_id);
 
172
}
 
173
 
 
174
const gchar *
 
175
gimp_get_program_class (Gimp *gimp)
 
176
{
 
177
  g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
 
178
 
 
179
  if (gimp->gui.get_program_class)
 
180
    return gimp->gui.get_program_class (gimp);
 
181
 
 
182
  return NULL;
 
183
}
 
184
 
 
185
gchar *
 
186
gimp_get_display_name (Gimp *gimp,
 
187
                       gint  gdisp_ID,
 
188
                       gint *monitor_number)
 
189
{
 
190
  g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
 
191
  g_return_val_if_fail (monitor_number != NULL, NULL);
 
192
 
 
193
  if (gimp->gui.get_display_name)
 
194
    return gimp->gui.get_display_name (gimp, gdisp_ID, monitor_number);
 
195
 
 
196
  *monitor_number = 0;
 
197
 
 
198
  return NULL;
 
199
}
 
200
 
 
201
const gchar *
 
202
gimp_get_theme_dir (Gimp *gimp)
 
203
{
 
204
  g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
 
205
 
 
206
  if (gimp->gui.get_theme_dir)
 
207
    return gimp->gui.get_theme_dir (gimp);
 
208
 
 
209
  return NULL;
 
210
}
 
211
 
 
212
GimpObject *
 
213
gimp_get_display_by_ID (Gimp *gimp,
 
214
                        gint  ID)
 
215
{
 
216
  g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
 
217
 
 
218
  if (gimp->gui.display_get_by_id)
 
219
    return gimp->gui.display_get_by_id (gimp, ID);
 
220
 
 
221
  return NULL;
 
222
}
 
223
 
 
224
gint
 
225
gimp_get_display_ID (Gimp       *gimp,
 
226
                     GimpObject *display)
 
227
{
 
228
  g_return_val_if_fail (GIMP_IS_GIMP (gimp), -1);
 
229
  g_return_val_if_fail (GIMP_IS_OBJECT (display), -1);
 
230
 
 
231
  if (gimp->gui.display_get_id)
 
232
    return gimp->gui.display_get_id (display);
 
233
 
 
234
  return -1;
 
235
}
 
236
 
 
237
GimpObject *
 
238
gimp_create_display (Gimp      *gimp,
 
239
                     GimpImage *gimage,
 
240
                     GimpUnit   unit,
 
241
                     gdouble    scale)
 
242
{
 
243
  GimpObject *display = NULL;
 
244
 
 
245
  g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
 
246
  g_return_val_if_fail (GIMP_IS_IMAGE (gimage), NULL);
 
247
 
 
248
  if (gimp->gui.display_create)
 
249
    {
 
250
      display = gimp->gui.display_create (gimage, unit, scale);
 
251
 
 
252
      gimp_container_add (gimp->displays, display);
 
253
    }
 
254
 
 
255
  return display;
 
256
}
 
257
 
 
258
void
 
259
gimp_delete_display (Gimp       *gimp,
 
260
                     GimpObject *display)
 
261
{
 
262
  g_return_if_fail (GIMP_IS_GIMP (gimp));
 
263
  g_return_if_fail (GIMP_IS_OBJECT (display));
 
264
 
 
265
  if (gimp->gui.display_delete)
 
266
    gimp->gui.display_delete (display);
 
267
}
 
268
 
 
269
void
 
270
gimp_reconnect_displays (Gimp      *gimp,
 
271
                         GimpImage *old_image,
 
272
                         GimpImage *new_image)
 
273
{
 
274
  g_return_if_fail (GIMP_IS_GIMP (gimp));
 
275
  g_return_if_fail (GIMP_IS_IMAGE (old_image));
 
276
  g_return_if_fail (GIMP_IS_IMAGE (new_image));
 
277
 
 
278
  if (gimp->gui.displays_reconnect)
 
279
    gimp->gui.displays_reconnect (gimp, old_image, new_image);
 
280
}
 
281
 
 
282
void
 
283
gimp_menus_init (Gimp        *gimp,
 
284
                 GSList      *plug_in_defs,
 
285
                 const gchar *std_plugins_domain)
 
286
{
 
287
  g_return_if_fail (GIMP_IS_GIMP (gimp));
 
288
  g_return_if_fail (std_plugins_domain != NULL);
 
289
 
 
290
  if (gimp->gui.menus_init)
 
291
    gimp->gui.menus_init (gimp, plug_in_defs, std_plugins_domain);
 
292
}
 
293
 
 
294
void
 
295
gimp_menus_create_entry (Gimp          *gimp,
 
296
                         PlugInProcDef *proc_def,
 
297
                         const gchar   *menu_path)
 
298
{
 
299
  g_return_if_fail (GIMP_IS_GIMP (gimp));
 
300
  g_return_if_fail (proc_def != NULL);
 
301
 
 
302
  if (gimp->gui.menus_create)
 
303
    gimp->gui.menus_create (gimp, proc_def, menu_path);
 
304
}
 
305
 
 
306
void
 
307
gimp_menus_delete_entry (Gimp          *gimp,
 
308
                         PlugInProcDef *proc_def)
 
309
{
 
310
  g_return_if_fail (GIMP_IS_GIMP (gimp));
 
311
  g_return_if_fail (proc_def != NULL);
 
312
 
 
313
  if (gimp->gui.menus_delete)
 
314
    gimp->gui.menus_delete (gimp, proc_def);
 
315
}
 
316
 
 
317
GimpProgress *
 
318
gimp_new_progress (Gimp *gimp,
 
319
                   gint  display_ID)
 
320
{
 
321
  g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
 
322
 
 
323
  if (gimp->gui.progress_new)
 
324
    return gimp->gui.progress_new (gimp, display_ID);
 
325
 
 
326
  return NULL;
 
327
}
 
328
 
 
329
void
 
330
gimp_free_progress (Gimp         *gimp,
 
331
                    GimpProgress *progress)
 
332
{
 
333
  g_return_if_fail (GIMP_IS_GIMP (gimp));
 
334
  g_return_if_fail (GIMP_IS_PROGRESS (progress));
 
335
 
 
336
  if (gimp->gui.progress_free)
 
337
    gimp->gui.progress_free (gimp, progress);
 
338
}
 
339
 
 
340
gboolean
 
341
gimp_pdb_dialog_new (Gimp          *gimp,
 
342
                     GimpContext   *context,
 
343
                     GimpContainer *container,
 
344
                     const gchar   *title,
 
345
                     const gchar   *callback_name,
 
346
                     const gchar   *object_name,
 
347
                     ...)
 
348
{
 
349
  gboolean retval = FALSE;
 
350
 
 
351
  g_return_val_if_fail (GIMP_IS_GIMP (gimp), FALSE);
 
352
  g_return_val_if_fail (GIMP_IS_CONTEXT (context), FALSE);
 
353
  g_return_val_if_fail (GIMP_IS_CONTAINER (container), FALSE);
 
354
  g_return_val_if_fail (title != NULL, FALSE);
 
355
  g_return_val_if_fail (callback_name != NULL, FALSE);
 
356
 
 
357
  if (gimp->gui.pdb_dialog_new)
 
358
    {
 
359
      va_list  args;
 
360
 
 
361
      va_start (args, object_name);
 
362
 
 
363
      retval = gimp->gui.pdb_dialog_new (gimp, context, container, title,
 
364
                                         callback_name, object_name,
 
365
                                         args);
 
366
 
 
367
      va_end (args);
 
368
    }
 
369
 
 
370
  return retval;
 
371
}
 
372
 
 
373
gboolean
 
374
gimp_pdb_dialog_set (Gimp          *gimp,
 
375
                     GimpContainer *container,
 
376
                     const gchar   *callback_name,
 
377
                     const gchar   *object_name,
 
378
                     ...)
 
379
{
 
380
  gboolean retval = FALSE;
 
381
 
 
382
  g_return_val_if_fail (GIMP_IS_GIMP (gimp), FALSE);
 
383
  g_return_val_if_fail (GIMP_IS_CONTAINER (container), FALSE);
 
384
  g_return_val_if_fail (callback_name != NULL, FALSE);
 
385
  g_return_val_if_fail (object_name != NULL, FALSE);
 
386
 
 
387
  if (gimp->gui.pdb_dialog_set)
 
388
    {
 
389
      va_list  args;
 
390
 
 
391
      va_start (args, object_name);
 
392
 
 
393
      retval = gimp->gui.pdb_dialog_set (gimp, container, callback_name,
 
394
                                         object_name, args);
 
395
 
 
396
      va_end (args);
 
397
    }
 
398
 
 
399
  return retval;
 
400
}
 
401
 
 
402
gboolean
 
403
gimp_pdb_dialog_close (Gimp          *gimp,
 
404
                       GimpContainer *container,
 
405
                       const gchar   *callback_name)
 
406
{
 
407
  g_return_val_if_fail (GIMP_IS_GIMP (gimp), FALSE);
 
408
  g_return_val_if_fail (GIMP_IS_CONTAINER (container), FALSE);
 
409
  g_return_val_if_fail (callback_name != NULL, FALSE);
 
410
 
 
411
  if (gimp->gui.pdb_dialog_close)
 
412
    return gimp->gui.pdb_dialog_close (gimp, container, callback_name);
 
413
 
 
414
  return FALSE;
 
415
}
 
416
 
 
417
void
 
418
gimp_pdb_dialogs_check (Gimp *gimp)
 
419
{
 
420
  g_return_if_fail (GIMP_IS_GIMP (gimp));
 
421
 
 
422
  if (gimp->gui.pdb_dialogs_check)
 
423
    gimp->gui.pdb_dialogs_check (gimp);
 
424
}