gimp-gui.c 13.9 KB
Newer Older
1
/* GIMP - The GNU Image Manipulation Program
2 3
 * Copyright (C) 1995-2002 Spencer Kimball, Peter Mattis, and others
 *
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 3 of the License, or
7 8 9 10 11 12 13 14
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
15
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 17 18 19
 */

#include "config.h"

20
#include <gdk-pixbuf/gdk-pixbuf.h>
21
#include <gegl.h>
22

Sven Neumann's avatar
Sven Neumann committed
23
#include "libgimpbase/gimpbase.h"
24

25 26 27 28 29 30 31
#include "core-types.h"

#include "gimp.h"
#include "gimp-gui.h"
#include "gimpcontainer.h"
#include "gimpcontext.h"
#include "gimpimage.h"
32
#include "gimpprogress.h"
33

34
#include "about.h"
35

36 37 38 39 40 41 42 43
#include "gimp-intl.h"


void
gimp_gui_init (Gimp *gimp)
{
  g_return_if_fail (GIMP_IS_GIMP (gimp));

44 45 46 47 48 49 50 51 52 53 54
  gimp->gui.ungrab                 = NULL;
  gimp->gui.threads_enter          = NULL;
  gimp->gui.threads_leave          = NULL;
  gimp->gui.set_busy               = NULL;
  gimp->gui.unset_busy             = NULL;
  gimp->gui.show_message           = NULL;
  gimp->gui.help                   = NULL;
  gimp->gui.get_program_class      = NULL;
  gimp->gui.get_display_name       = NULL;
  gimp->gui.get_user_time          = NULL;
  gimp->gui.get_theme_dir          = NULL;
55
  gimp->gui.get_icon_theme_dir     = NULL;
56 57 58 59 60 61 62 63 64 65 66 67
  gimp->gui.display_get_by_id      = NULL;
  gimp->gui.display_get_id         = NULL;
  gimp->gui.display_get_window_id  = NULL;
  gimp->gui.display_create         = NULL;
  gimp->gui.display_delete         = NULL;
  gimp->gui.displays_reconnect     = NULL;
  gimp->gui.progress_new           = NULL;
  gimp->gui.progress_free          = NULL;
  gimp->gui.pdb_dialog_set         = NULL;
  gimp->gui.pdb_dialog_close       = NULL;
  gimp->gui.recent_list_add_file   = NULL;
  gimp->gui.recent_list_load       = NULL;
68
  gimp->gui.get_mount_operation    = NULL;
69
  gimp->gui.query_profile_policy   = NULL;
70 71
}

72 73 74 75 76 77 78 79 80
void
gimp_gui_ungrab (Gimp *gimp)
{
  g_return_if_fail (GIMP_IS_GIMP (gimp));

  if (gimp->gui.ungrab)
    gimp->gui.ungrab (gimp);
}

81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
void
gimp_threads_enter (Gimp *gimp)
{
  g_return_if_fail (GIMP_IS_GIMP (gimp));

  if (gimp->gui.threads_enter)
    gimp->gui.threads_enter (gimp);
}

void
gimp_threads_leave (Gimp *gimp)
{
  g_return_if_fail (GIMP_IS_GIMP (gimp));

  if (gimp->gui.threads_leave)
    gimp->gui.threads_leave (gimp);
}

void
gimp_set_busy (Gimp *gimp)
{
  g_return_if_fail (GIMP_IS_GIMP (gimp));

  /* FIXME: gimp_busy HACK */
  gimp->busy++;

  if (gimp->busy == 1)
    {
      if (gimp->gui.set_busy)
        gimp->gui.set_busy (gimp);
    }
}

static gboolean
gimp_idle_unset_busy (gpointer data)
{
  Gimp *gimp = data;

  gimp_unset_busy (gimp);

  gimp->busy_idle_id = 0;

  return FALSE;
}

void
gimp_set_busy_until_idle (Gimp *gimp)
{
  g_return_if_fail (GIMP_IS_GIMP (gimp));

  if (! gimp->busy_idle_id)
    {
      gimp_set_busy (gimp);

      gimp->busy_idle_id = g_idle_add_full (G_PRIORITY_HIGH,
136 137
                                            gimp_idle_unset_busy, gimp,
                                            NULL);
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
    }
}

void
gimp_unset_busy (Gimp *gimp)
{
  g_return_if_fail (GIMP_IS_GIMP (gimp));
  g_return_if_fail (gimp->busy > 0);

  /* FIXME: gimp_busy HACK */
  gimp->busy--;

  if (gimp->busy == 0)
    {
      if (gimp->gui.unset_busy)
        gimp->gui.unset_busy (gimp);
    }
}

void
158 159 160 161
gimp_show_message (Gimp                *gimp,
                   GObject             *handler,
                   GimpMessageSeverity  severity,
                   const gchar         *domain,
162
                   const gchar         *message)
163
{
164
  const gchar *desc = (severity == GIMP_MESSAGE_ERROR) ? "Error" : "Message";
165

166
  g_return_if_fail (GIMP_IS_GIMP (gimp));
167
  g_return_if_fail (handler == NULL || G_IS_OBJECT (handler));
168
  g_return_if_fail (message != NULL);
169

170
  if (! domain)
171
    domain = GIMP_ACRONYM;
172

173
  if (! gimp->console_messages)
174
    {
175 176
      if (gimp->gui.show_message)
        {
177
          gimp->gui.show_message (gimp, handler, severity,
178
                                  domain, message);
179 180 181 182 183 184 185 186 187
          return;
        }
      else if (GIMP_IS_PROGRESS (handler) &&
               gimp_progress_message (GIMP_PROGRESS (handler), gimp,
                                      severity, domain, message))
        {
          /* message has been handled by GimpProgress */
          return;
        }
188
    }
189 190 191 192

  gimp_enum_get_value (GIMP_TYPE_MESSAGE_SEVERITY, severity,
                       NULL, NULL, &desc, NULL);
  g_printerr ("%s-%s: %s\n\n", domain, desc, message);
193 194 195
}

void
196 197 198 199
gimp_help (Gimp         *gimp,
           GimpProgress *progress,
           const gchar  *help_domain,
           const gchar  *help_id)
200 201
{
  g_return_if_fail (GIMP_IS_GIMP (gimp));
202
  g_return_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress));
203 204

  if (gimp->gui.help)
205
    gimp->gui.help (gimp, progress, help_domain, help_id);
206 207 208 209 210 211 212 213 214 215 216 217 218 219
}

const gchar *
gimp_get_program_class (Gimp *gimp)
{
  g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);

  if (gimp->gui.get_program_class)
    return gimp->gui.get_program_class (gimp);

  return NULL;
}

gchar *
220 221 222 223
gimp_get_display_name (Gimp     *gimp,
                       gint      display_ID,
                       GObject **screen,
                       gint     *monitor)
224 225
{
  g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
226 227
  g_return_val_if_fail (screen != NULL, NULL);
  g_return_val_if_fail (monitor != NULL, NULL);
228 229

  if (gimp->gui.get_display_name)
230
    return gimp->gui.get_display_name (gimp, display_ID, screen, monitor);
231

232 233
  *screen  = NULL;
  *monitor = 0;
234 235 236 237

  return NULL;
}

238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258
/**
 * gimp_get_user_time:
 * @gimp:
 *
 * Returns the timestamp of the last user interaction. The timestamp is
 * taken from events caused by user interaction such as key presses or
 * pointer movements. See gdk_x11_display_get_user_time().
 *
 * Return value: the timestamp of the last user interaction
 */
guint32
gimp_get_user_time (Gimp *gimp)
{
  g_return_val_if_fail (GIMP_IS_GIMP (gimp), 0);

  if (gimp->gui.get_user_time)
    return gimp->gui.get_user_time (gimp);

  return 0;
}

259
GFile *
260 261 262 263 264 265 266 267 268 269
gimp_get_theme_dir (Gimp *gimp)
{
  g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);

  if (gimp->gui.get_theme_dir)
    return gimp->gui.get_theme_dir (gimp);

  return NULL;
}

270 271 272 273 274 275 276 277 278 279 280
GFile *
gimp_get_icon_theme_dir (Gimp *gimp)
{
  g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);

  if (gimp->gui.get_icon_theme_dir)
    return gimp->gui.get_icon_theme_dir (gimp);

  return NULL;
}

281 282 283 284 285 286 287 288 289 290 291
GimpObject *
gimp_get_window_strategy (Gimp *gimp)
{
  g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);

  if (gimp->gui.get_window_strategy)
    return gimp->gui.get_window_strategy (gimp);

  return NULL;
}

292 293 294 295 296 297 298 299 300 301 302
GimpObject *
gimp_get_empty_display (Gimp *gimp)
{
  g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);

  if (gimp->gui.get_empty_display)
    return gimp->gui.get_empty_display (gimp);

  return NULL;
}

303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327
GimpObject *
gimp_get_display_by_ID (Gimp *gimp,
                        gint  ID)
{
  g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);

  if (gimp->gui.display_get_by_id)
    return gimp->gui.display_get_by_id (gimp, ID);

  return NULL;
}

gint
gimp_get_display_ID (Gimp       *gimp,
                     GimpObject *display)
{
  g_return_val_if_fail (GIMP_IS_GIMP (gimp), -1);
  g_return_val_if_fail (GIMP_IS_OBJECT (display), -1);

  if (gimp->gui.display_get_id)
    return gimp->gui.display_get_id (display);

  return -1;
}

Sven Neumann's avatar
Sven Neumann committed
328
guint32
329 330
gimp_get_display_window_id (Gimp       *gimp,
                            GimpObject *display)
Sven Neumann's avatar
Sven Neumann committed
331 332 333 334
{
  g_return_val_if_fail (GIMP_IS_GIMP (gimp), -1);
  g_return_val_if_fail (GIMP_IS_OBJECT (display), -1);

335 336
  if (gimp->gui.display_get_window_id)
    return gimp->gui.display_get_window_id (display);
Sven Neumann's avatar
Sven Neumann committed
337 338 339 340

  return -1;
}

341 342
GimpObject *
gimp_create_display (Gimp      *gimp,
343
                     GimpImage *image,
344
                     GimpUnit   unit,
345 346 347
                     gdouble    scale,
                     GObject   *screen,
                     gint       monitor)
348 349
{
  g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
350
  g_return_val_if_fail (image == NULL || GIMP_IS_IMAGE (image), NULL);
351
  g_return_val_if_fail (screen == NULL || G_IS_OBJECT (screen), NULL);
352 353

  if (gimp->gui.display_create)
354
    return gimp->gui.display_create (gimp, image, unit, scale, screen, monitor);
355

356
  return NULL;
357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383
}

void
gimp_delete_display (Gimp       *gimp,
                     GimpObject *display)
{
  g_return_if_fail (GIMP_IS_GIMP (gimp));
  g_return_if_fail (GIMP_IS_OBJECT (display));

  if (gimp->gui.display_delete)
    gimp->gui.display_delete (display);
}

void
gimp_reconnect_displays (Gimp      *gimp,
                         GimpImage *old_image,
                         GimpImage *new_image)
{
  g_return_if_fail (GIMP_IS_GIMP (gimp));
  g_return_if_fail (GIMP_IS_IMAGE (old_image));
  g_return_if_fail (GIMP_IS_IMAGE (new_image));

  if (gimp->gui.displays_reconnect)
    gimp->gui.displays_reconnect (gimp, old_image, new_image);
}

GimpProgress *
384 385
gimp_new_progress (Gimp       *gimp,
                   GimpObject *display)
386 387
{
  g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
388
  g_return_val_if_fail (display == NULL || GIMP_IS_OBJECT (display), NULL);
389

390
  if (gimp->gui.progress_new)
391
    return gimp->gui.progress_new (gimp, display);
392 393 394 395 396

  return NULL;
}

void
397 398
gimp_free_progress (Gimp         *gimp,
                    GimpProgress *progress)
399 400
{
  g_return_if_fail (GIMP_IS_GIMP (gimp));
401
  g_return_if_fail (GIMP_IS_PROGRESS (progress));
402

403 404
  if (gimp->gui.progress_free)
    gimp->gui.progress_free (gimp, progress);
405 406 407 408 409
}

gboolean
gimp_pdb_dialog_new (Gimp          *gimp,
                     GimpContext   *context,
410
                     GimpProgress  *progress,
411 412 413 414 415 416 417 418 419 420
                     GimpContainer *container,
                     const gchar   *title,
                     const gchar   *callback_name,
                     const gchar   *object_name,
                     ...)
{
  gboolean retval = FALSE;

  g_return_val_if_fail (GIMP_IS_GIMP (gimp), FALSE);
  g_return_val_if_fail (GIMP_IS_CONTEXT (context), FALSE);
421
  g_return_val_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress), FALSE);
422 423 424 425 426 427
  g_return_val_if_fail (GIMP_IS_CONTAINER (container), FALSE);
  g_return_val_if_fail (title != NULL, FALSE);
  g_return_val_if_fail (callback_name != NULL, FALSE);

  if (gimp->gui.pdb_dialog_new)
    {
428
      va_list args;
429 430 431

      va_start (args, object_name);

432 433
      retval = gimp->gui.pdb_dialog_new (gimp, context, progress,
                                         container, title,
434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458
                                         callback_name, object_name,
                                         args);

      va_end (args);
    }

  return retval;
}

gboolean
gimp_pdb_dialog_set (Gimp          *gimp,
                     GimpContainer *container,
                     const gchar   *callback_name,
                     const gchar   *object_name,
                     ...)
{
  gboolean retval = FALSE;

  g_return_val_if_fail (GIMP_IS_GIMP (gimp), FALSE);
  g_return_val_if_fail (GIMP_IS_CONTAINER (container), FALSE);
  g_return_val_if_fail (callback_name != NULL, FALSE);
  g_return_val_if_fail (object_name != NULL, FALSE);

  if (gimp->gui.pdb_dialog_set)
    {
459
      va_list args;
460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485

      va_start (args, object_name);

      retval = gimp->gui.pdb_dialog_set (gimp, container, callback_name,
                                         object_name, args);

      va_end (args);
    }

  return retval;
}

gboolean
gimp_pdb_dialog_close (Gimp          *gimp,
                       GimpContainer *container,
                       const gchar   *callback_name)
{
  g_return_val_if_fail (GIMP_IS_GIMP (gimp), FALSE);
  g_return_val_if_fail (GIMP_IS_CONTAINER (container), FALSE);
  g_return_val_if_fail (callback_name != NULL, FALSE);

  if (gimp->gui.pdb_dialog_close)
    return gimp->gui.pdb_dialog_close (gimp, container, callback_name);

  return FALSE;
}
486 487

gboolean
488 489 490
gimp_recent_list_add_file (Gimp        *gimp,
                           GFile       *file,
                           const gchar *mime_type)
491 492
{
  g_return_val_if_fail (GIMP_IS_GIMP (gimp), FALSE);
493
  g_return_val_if_fail (G_IS_FILE (file), FALSE);
494

495 496
  if (gimp->gui.recent_list_add_file)
    return gimp->gui.recent_list_add_file (gimp, file, mime_type);
497 498 499

  return FALSE;
}
500 501 502 503 504 505 506 507 508

void
gimp_recent_list_load (Gimp *gimp)
{
  g_return_if_fail (GIMP_IS_GIMP (gimp));

  if (gimp->gui.recent_list_load)
    gimp->gui.recent_list_load (gimp);
}
509

510 511 512
GMountOperation *
gimp_get_mount_operation (Gimp         *gimp,
                          GimpProgress *progress)
513 514 515 516
{
  g_return_val_if_fail (GIMP_IS_GIMP (gimp), FALSE);
  g_return_val_if_fail (progress == NULL || GIMP_IS_PROGRESS (progress), FALSE);

517 518
  if (gimp->gui.get_mount_operation)
    return gimp->gui.get_mount_operation (gimp, progress);
519

520
  return g_mount_operation_new ();
521
}
522 523

GimpColorProfilePolicy
524 525 526 527 528 529 530
gimp_query_profile_policy (Gimp                      *gimp,
                           GimpImage                 *image,
                           GimpContext               *context,
                           GimpColorProfile         **dest_profile,
                           GimpColorRenderingIntent  *intent,
                           gboolean                  *bpc,
                           gboolean                  *dont_ask)
531 532 533 534 535 536 537 538
{
  g_return_val_if_fail (GIMP_IS_GIMP (gimp), GIMP_COLOR_PROFILE_POLICY_KEEP);
  g_return_val_if_fail (GIMP_IS_IMAGE (image), GIMP_COLOR_PROFILE_POLICY_KEEP);
  g_return_val_if_fail (GIMP_IS_CONTEXT (context), GIMP_COLOR_PROFILE_POLICY_KEEP);
  g_return_val_if_fail (dest_profile != NULL, GIMP_COLOR_PROFILE_POLICY_KEEP);

  if (gimp->gui.query_profile_policy)
    return gimp->gui.query_profile_policy (gimp, image, context,
539 540 541
                                           dest_profile,
                                           intent, bpc,
                                           dont_ask);
542 543 544

  return GIMP_COLOR_PROFILE_POLICY_KEEP;
}