1
/* The GIMP -- an image manipulation program
1
/* GIMP - The GNU Image Manipulation Program
2
2
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
4
4
* gimpcontainerpopup.c
5
* Copyright (C) 2003 Michael Natterer <mitch@gimp.org>
5
* Copyright (C) 2003-2005 Michael Natterer <mitch@gimp.org>
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"
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"
55
static void gimp_container_popup_class_init (GimpContainerPopupClass *klass);
56
static void gimp_container_popup_init (GimpContainerPopup *view);
58
54
static void gimp_container_popup_finalize (GObject *object);
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);
64
62
static void gimp_container_popup_real_cancel (GimpContainerPopup *popup);
65
63
static void gimp_container_popup_real_confirm (GimpContainerPopup *popup);
76
74
GimpContainerPopup *popup);
79
static GtkWindowClass *parent_class = NULL;
77
G_DEFINE_TYPE (GimpContainerPopup, gimp_container_popup, GTK_TYPE_WINDOW)
79
#define parent_class gimp_container_popup_parent_class
81
81
static guint popup_signals[LAST_SIGNAL];
85
gimp_container_popup_get_type (void)
87
static GType popup_type = 0;
91
static const GTypeInfo popup_info =
93
sizeof (GimpContainerPopupClass),
95
NULL, /* base_finalize */
96
(GClassInitFunc) gimp_container_popup_class_init,
97
NULL, /* class_finalize */
98
NULL, /* class_data */
99
sizeof (GimpContainerPopup),
101
(GInstanceInitFunc) gimp_container_popup_init,
104
popup_type = g_type_register_static (GTK_TYPE_WINDOW,
105
"GimpContainerPopup",
113
85
gimp_container_popup_class_init (GimpContainerPopupClass *klass)
116
88
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
117
89
GtkBindingSet *binding_set;
119
parent_class = g_type_class_peek_parent (klass);
121
91
popup_signals[CANCEL] =
122
92
g_signal_new ("cancel",
123
93
G_OBJECT_CLASS_TYPE (klass),
161
131
gimp_container_popup_init (GimpContainerPopup *popup)
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;
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,
356
gint preview_border_width,
324
gint default_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,
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,
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,
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);
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;
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));
440
gimp_container_popup_get_view_type (GimpContainerPopup *popup)
442
g_return_val_if_fail (GIMP_IS_CONTAINER_POPUP (popup), GIMP_VIEW_TYPE_LIST);
444
return popup->view_type;
448
gimp_container_popup_set_view_type (GimpContainerPopup *popup,
449
GimpViewType view_type)
451
g_return_if_fail (GIMP_IS_CONTAINER_POPUP (popup));
453
if (view_type != popup->view_type)
455
popup->view_type = view_type;
457
gtk_container_remove (GTK_CONTAINER (popup->frame),
458
GTK_WIDGET (popup->editor));
459
gimp_container_popup_create_view (popup);
464
gimp_container_popup_get_view_size (GimpContainerPopup *popup)
466
g_return_val_if_fail (GIMP_IS_CONTAINER_POPUP (popup), GIMP_VIEW_SIZE_SMALL);
468
return popup->view_size;
472
gimp_container_popup_set_view_size (GimpContainerPopup *popup,
475
GtkWidget *scrolled_win;
478
g_return_if_fail (GIMP_IS_CONTAINER_POPUP (popup));
480
scrolled_win = GIMP_CONTAINER_BOX (popup->editor->view)->scrolled_win;
482
viewport_width = GTK_BIN (scrolled_win)->child->allocation.width;
484
view_size = CLAMP (view_size, GIMP_VIEW_SIZE_TINY,
485
MIN (GIMP_VIEW_SIZE_GIGANTIC,
486
viewport_width - 2 * popup->view_border_width));
488
if (view_size != popup->view_size)
490
popup->view_size = view_size;
492
gimp_container_view_set_view_size (popup->editor->view,
494
popup->view_border_width);
499
/* private functions */
470
502
gimp_container_popup_create_view (GimpContainerPopup *popup)
477
509
popup->view_type,
478
510
popup->container,
481
popup->preview_border_width,
513
popup->view_border_width,
482
514
NULL, NULL, NULL);
484
516
gimp_container_view_set_reorderable (GIMP_CONTAINER_VIEW (popup->editor->view),
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));
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);
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)
533
preview_size = gimp_container_view_get_preview_size (popup->editor->view,
536
preview_size = MAX (GIMP_VIEW_SIZE_TINY, preview_size * 0.8);
538
if (preview_size != popup->preview_size)
540
popup->preview_size = preview_size;
542
gimp_container_view_set_preview_size (popup->editor->view,
544
popup->preview_border_width);
565
view_size = gimp_container_view_get_view_size (popup->editor->view, NULL);
567
gimp_container_popup_set_view_size (popup, view_size * 0.8);
549
571
gimp_container_popup_larger_clicked (GtkWidget *button,
550
572
GimpContainerPopup *popup)
554
preview_size = gimp_container_view_get_preview_size (popup->editor->view,
557
preview_size = MAX (GIMP_VIEW_SIZE_TINY, preview_size * 1.2);
559
if (preview_size != popup->preview_size)
561
popup->preview_size = preview_size;
563
gimp_container_view_set_preview_size (popup->editor->view,
565
popup->preview_border_width);
576
view_size = gimp_container_view_get_view_size (popup->editor->view, NULL);
578
gimp_container_popup_set_view_size (popup, view_size * 1.2);
577
589
view_type = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (button),
578
590
"gimp-item-data"));
580
if (view_type != popup->view_type)
582
popup->view_type = view_type;
584
gtk_container_remove (GTK_CONTAINER (popup->frame),
585
GTK_WIDGET (popup->editor));
586
gimp_container_popup_create_view (popup);
592
gimp_container_popup_set_view_type (popup, view_type);