~ubuntu-branches/ubuntu/jaunty/gimp/jaunty-security

« back to all changes in this revision

Viewing changes to app/widgets/gimpcontainerpopup.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2007-05-02 16:33:03 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070502163303-bvzhjzbpw8qglc4y
Tags: 2.3.16-1ubuntu1
* Resynchronized with Debian, remaining Ubuntu changes:
  - debian/rules: i18n magic.
* debian/control.in:
  - Maintainer: Ubuntu Core Developers <ubuntu-devel@lists.ubuntu.com>
* debian/patches/02_help-message.patch,
  debian/patches/03_gimp.desktop.in.in.patch,
  debian/patches/10_dont_show_wizard.patch: updated.
* debian/patches/04_composite-signedness.patch,
  debian/patches/05_add-letter-spacing.patch: dropped, used upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* The GIMP -- an image manipulation program
 
1
/* GIMP - The GNU Image Manipulation Program
2
2
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
3
3
 *
4
4
 * gimpcontainerpopup.c
5
 
 * Copyright (C) 2003 Michael Natterer <mitch@gimp.org>
 
5
 * Copyright (C) 2003-2005 Michael Natterer <mitch@gimp.org>
6
6
 *
7
7
 * This program is free software; you can redistribute it and/or modify
8
8
 * it under the terms of the GNU General Public License as published by
33
33
#include "core/gimpmarshal.h"
34
34
#include "core/gimpviewable.h"
35
35
 
 
36
#include "gimpcontainerbox.h"
36
37
#include "gimpcontainereditor.h"
37
38
#include "gimpcontainerpopup.h"
38
 
#include "gimpcontainergridview.h"
39
 
#include "gimpcontainertreeview.h"
40
39
#include "gimpcontainerview.h"
41
40
#include "gimpdialogfactory.h"
42
41
#include "gimpviewrenderer.h"
52
51
};
53
52
 
54
53
 
55
 
static void     gimp_container_popup_class_init (GimpContainerPopupClass *klass);
56
 
static void     gimp_container_popup_init       (GimpContainerPopup      *view);
57
 
 
58
54
static void     gimp_container_popup_finalize     (GObject            *object);
 
55
 
59
56
static void     gimp_container_popup_map          (GtkWidget          *widget);
60
57
static gboolean gimp_container_popup_button_press (GtkWidget          *widget,
61
58
                                                   GdkEventButton     *bevent);
62
59
static gboolean gimp_container_popup_key_press    (GtkWidget          *widget,
63
60
                                                   GdkEventKey        *kevent);
 
61
 
64
62
static void     gimp_container_popup_real_cancel  (GimpContainerPopup *popup);
65
63
static void     gimp_container_popup_real_confirm (GimpContainerPopup *popup);
66
64
 
76
74
                                                   GimpContainerPopup *popup);
77
75
 
78
76
 
79
 
static GtkWindowClass *parent_class = NULL;
 
77
G_DEFINE_TYPE (GimpContainerPopup, gimp_container_popup, GTK_TYPE_WINDOW)
 
78
 
 
79
#define parent_class gimp_container_popup_parent_class
80
80
 
81
81
static guint popup_signals[LAST_SIGNAL];
82
82
 
83
83
 
84
 
GType
85
 
gimp_container_popup_get_type (void)
86
 
{
87
 
  static GType popup_type = 0;
88
 
 
89
 
  if (! popup_type)
90
 
    {
91
 
      static const GTypeInfo popup_info =
92
 
      {
93
 
        sizeof (GimpContainerPopupClass),
94
 
        NULL,           /* base_init */
95
 
        NULL,           /* base_finalize */
96
 
        (GClassInitFunc) gimp_container_popup_class_init,
97
 
        NULL,           /* class_finalize */
98
 
        NULL,           /* class_data */
99
 
        sizeof (GimpContainerPopup),
100
 
        0,              /* n_preallocs */
101
 
        (GInstanceInitFunc) gimp_container_popup_init,
102
 
      };
103
 
 
104
 
      popup_type = g_type_register_static (GTK_TYPE_WINDOW,
105
 
                                           "GimpContainerPopup",
106
 
                                           &popup_info, 0);
107
 
    }
108
 
 
109
 
  return popup_type;
110
 
}
111
 
 
112
84
static void
113
85
gimp_container_popup_class_init (GimpContainerPopupClass *klass)
114
86
{
116
88
  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
117
89
  GtkBindingSet  *binding_set;
118
90
 
119
 
  parent_class = g_type_class_peek_parent (klass);
120
 
 
121
91
  popup_signals[CANCEL] =
122
92
    g_signal_new ("cancel",
123
93
                  G_OBJECT_CLASS_TYPE (klass),
160
130
static void
161
131
gimp_container_popup_init (GimpContainerPopup *popup)
162
132
{
163
 
  popup->view_type            = GIMP_VIEW_TYPE_LIST;
164
 
  popup->default_preview_size = GIMP_VIEW_SIZE_SMALL;
165
 
  popup->preview_size         = GIMP_VIEW_SIZE_SMALL;
166
 
  popup->preview_border_width = 1;
 
133
  popup->view_type         = GIMP_VIEW_TYPE_LIST;
 
134
  popup->default_view_size = GIMP_VIEW_SIZE_SMALL;
 
135
  popup->view_size         = GIMP_VIEW_SIZE_SMALL;
 
136
  popup->view_border_width = 1;
167
137
 
168
138
  popup->frame = gtk_frame_new (NULL);
169
139
  gtk_frame_set_shadow_type (GTK_FRAME (popup->frame), GTK_SHADOW_OUT);
351
321
gimp_container_popup_new (GimpContainer     *container,
352
322
                          GimpContext       *context,
353
323
                          GimpViewType       view_type,
354
 
                          gint               default_preview_size,
355
 
                          gint               preview_size,
356
 
                          gint               preview_border_width,
 
324
                          gint               default_view_size,
 
325
                          gint               view_size,
 
326
                          gint               view_border_width,
357
327
                          GimpDialogFactory *dialog_factory,
358
328
                          const gchar       *dialog_identifier,
359
329
                          const gchar       *dialog_stock_id,
363
333
 
364
334
  g_return_val_if_fail (GIMP_IS_CONTAINER (container), NULL);
365
335
  g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
366
 
  g_return_val_if_fail (default_preview_size >  0 &&
367
 
                        default_preview_size <= GIMP_VIEWABLE_MAX_POPUP_SIZE,
 
336
  g_return_val_if_fail (default_view_size >  0 &&
 
337
                        default_view_size <= GIMP_VIEWABLE_MAX_POPUP_SIZE,
368
338
                        NULL);
369
 
  g_return_val_if_fail (preview_size >  0 &&
370
 
                        preview_size <= GIMP_VIEWABLE_MAX_POPUP_SIZE, NULL);
371
 
  g_return_val_if_fail (preview_border_width >= 0 &&
372
 
                        preview_border_width <= GIMP_VIEW_MAX_BORDER_WIDTH,
 
339
  g_return_val_if_fail (view_size >  0 &&
 
340
                        view_size <= GIMP_VIEWABLE_MAX_POPUP_SIZE, NULL);
 
341
  g_return_val_if_fail (view_border_width >= 0 &&
 
342
                        view_border_width <= GIMP_VIEW_MAX_BORDER_WIDTH,
373
343
                        NULL);
374
344
  g_return_val_if_fail (dialog_factory == NULL ||
375
345
                        GIMP_IS_DIALOG_FACTORY (dialog_factory), NULL);
389
359
  popup->orig_context = context;
390
360
  popup->context      = gimp_context_new (context->gimp, "popup", context);
391
361
 
392
 
  popup->view_type            = view_type;
393
 
  popup->default_preview_size = default_preview_size;
394
 
  popup->preview_size         = preview_size;
395
 
  popup->preview_border_width = preview_border_width;
 
362
  popup->view_type         = view_type;
 
363
  popup->default_view_size = default_view_size;
 
364
  popup->view_size         = view_size;
 
365
  popup->view_border_width = view_border_width;
396
366
 
397
367
  g_signal_connect (popup->context,
398
368
                    gimp_context_type_to_signal_name (container->children_type),
466
436
  gtk_widget_show (GTK_WIDGET (popup));
467
437
}
468
438
 
 
439
GimpViewType
 
440
gimp_container_popup_get_view_type (GimpContainerPopup *popup)
 
441
{
 
442
  g_return_val_if_fail (GIMP_IS_CONTAINER_POPUP (popup), GIMP_VIEW_TYPE_LIST);
 
443
 
 
444
  return popup->view_type;
 
445
}
 
446
 
 
447
void
 
448
gimp_container_popup_set_view_type (GimpContainerPopup *popup,
 
449
                                    GimpViewType        view_type)
 
450
{
 
451
  g_return_if_fail (GIMP_IS_CONTAINER_POPUP (popup));
 
452
 
 
453
  if (view_type != popup->view_type)
 
454
    {
 
455
      popup->view_type = view_type;
 
456
 
 
457
      gtk_container_remove (GTK_CONTAINER (popup->frame),
 
458
                            GTK_WIDGET (popup->editor));
 
459
      gimp_container_popup_create_view (popup);
 
460
    }
 
461
}
 
462
 
 
463
gint
 
464
gimp_container_popup_get_view_size (GimpContainerPopup *popup)
 
465
{
 
466
  g_return_val_if_fail (GIMP_IS_CONTAINER_POPUP (popup), GIMP_VIEW_SIZE_SMALL);
 
467
 
 
468
  return popup->view_size;
 
469
}
 
470
 
 
471
void
 
472
gimp_container_popup_set_view_size (GimpContainerPopup *popup,
 
473
                                    gint                view_size)
 
474
{
 
475
  GtkWidget *scrolled_win;
 
476
  gint       viewport_width;
 
477
 
 
478
  g_return_if_fail (GIMP_IS_CONTAINER_POPUP (popup));
 
479
 
 
480
  scrolled_win = GIMP_CONTAINER_BOX (popup->editor->view)->scrolled_win;
 
481
 
 
482
  viewport_width = GTK_BIN (scrolled_win)->child->allocation.width;
 
483
 
 
484
  view_size = CLAMP (view_size, GIMP_VIEW_SIZE_TINY,
 
485
                     MIN (GIMP_VIEW_SIZE_GIGANTIC,
 
486
                          viewport_width - 2 * popup->view_border_width));
 
487
 
 
488
  if (view_size != popup->view_size)
 
489
    {
 
490
      popup->view_size = view_size;
 
491
 
 
492
      gimp_container_view_set_view_size (popup->editor->view,
 
493
                                         popup->view_size,
 
494
                                         popup->view_border_width);
 
495
    }
 
496
}
 
497
 
 
498
 
 
499
/*  private functions  */
 
500
 
469
501
static void
470
502
gimp_container_popup_create_view (GimpContainerPopup *popup)
471
503
{
477
509
                                   popup->view_type,
478
510
                                   popup->container,
479
511
                                   popup->context,
480
 
                                   popup->preview_size,
481
 
                                   popup->preview_border_width,
 
512
                                   popup->view_size,
 
513
                                   popup->view_border_width,
482
514
                                   NULL, NULL, NULL);
483
515
 
484
516
  gimp_container_view_set_reorderable (GIMP_CONTAINER_VIEW (popup->editor->view),
485
517
                                       FALSE);
486
518
 
487
519
  gimp_container_box_set_size_request (GIMP_CONTAINER_BOX (popup->editor->view),
488
 
                                       6  * (popup->default_preview_size +
489
 
                                             2 * popup->preview_border_width),
490
 
                                       10 * (popup->default_preview_size +
491
 
                                             2 * popup->preview_border_width));
 
520
                                       6  * (popup->default_view_size +
 
521
                                             2 * popup->view_border_width),
 
522
                                       10 * (popup->default_view_size +
 
523
                                             2 * popup->view_border_width));
492
524
 
493
 
  if (GIMP_IS_CONTAINER_GRID_VIEW (popup->editor->view))
494
 
    gtk_widget_hide (GIMP_CONTAINER_GRID_VIEW (popup->editor->view)->name_label);
 
525
  if (GIMP_IS_EDITOR (popup->editor->view))
 
526
    gimp_editor_set_show_name (GIMP_EDITOR (popup->editor->view), FALSE);
495
527
 
496
528
  gtk_container_add (GTK_CONTAINER (popup->frame), GTK_WIDGET (popup->editor));
497
529
  gtk_widget_show (GTK_WIDGET (popup->editor));
528
560
gimp_container_popup_smaller_clicked (GtkWidget          *button,
529
561
                                      GimpContainerPopup *popup)
530
562
{
531
 
  gint preview_size;
532
 
 
533
 
  preview_size = gimp_container_view_get_preview_size (popup->editor->view,
534
 
                                                       NULL);
535
 
 
536
 
  preview_size = MAX (GIMP_VIEW_SIZE_TINY, preview_size * 0.8);
537
 
 
538
 
  if (preview_size != popup->preview_size)
539
 
    {
540
 
      popup->preview_size = preview_size;
541
 
 
542
 
      gimp_container_view_set_preview_size (popup->editor->view,
543
 
                                            popup->preview_size,
544
 
                                            popup->preview_border_width);
545
 
    }
 
563
  gint view_size;
 
564
 
 
565
  view_size = gimp_container_view_get_view_size (popup->editor->view, NULL);
 
566
 
 
567
  gimp_container_popup_set_view_size (popup, view_size * 0.8);
546
568
}
547
569
 
548
570
static void
549
571
gimp_container_popup_larger_clicked (GtkWidget          *button,
550
572
                                     GimpContainerPopup *popup)
551
573
{
552
 
  gint preview_size;
553
 
 
554
 
  preview_size = gimp_container_view_get_preview_size (popup->editor->view,
555
 
                                                       NULL);
556
 
 
557
 
  preview_size = MAX (GIMP_VIEW_SIZE_TINY, preview_size * 1.2);
558
 
 
559
 
  if (preview_size != popup->preview_size)
560
 
    {
561
 
      popup->preview_size = preview_size;
562
 
 
563
 
      gimp_container_view_set_preview_size (popup->editor->view,
564
 
                                            popup->preview_size,
565
 
                                            popup->preview_border_width);
566
 
    }
 
574
  gint view_size;
 
575
 
 
576
  view_size = gimp_container_view_get_view_size (popup->editor->view, NULL);
 
577
 
 
578
  gimp_container_popup_set_view_size (popup, view_size * 1.2);
567
579
}
568
580
 
569
581
static void
577
589
      view_type = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (button),
578
590
                                                      "gimp-item-data"));
579
591
 
580
 
      if (view_type != popup->view_type)
581
 
        {
582
 
          popup->view_type = view_type;
583
 
 
584
 
          gtk_container_remove (GTK_CONTAINER (popup->frame),
585
 
                                GTK_WIDGET (popup->editor));
586
 
          gimp_container_popup_create_view (popup);
587
 
        }
 
592
      gimp_container_popup_set_view_type (popup, view_type);
588
593
    }
589
594
}
590
595