1 /* GIMP - The GNU Image Manipulation Program
2  * Copyright (C) 1995 Spencer Kimball and Peter Mattis
3  *
4  * gimpdocumentview.c
5  * Copyright (C) 2001 Michael Natterer <mitch@gimp.org>
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19  */
20 
21 #include "config.h"
22 
23 #include <gegl.h>
24 #include <gtk/gtk.h>
25 
26 #include "libgimpwidgets/gimpwidgets.h"
27 
28 #include "widgets-types.h"
29 
30 #include "core/gimpcontainer.h"
31 #include "core/gimpcontext.h"
32 #include "core/gimpimage.h"
33 
34 #include "gimpcontainerview.h"
35 #include "gimpeditor.h"
36 #include "gimpimageview.h"
37 #include "gimpdnd.h"
38 #include "gimpmenufactory.h"
39 #include "gimpuimanager.h"
40 #include "gimpviewrenderer.h"
41 
42 #include "gimp-intl.h"
43 
44 
45 static void   gimp_image_view_activate_item (GimpContainerEditor *editor,
46                                              GimpViewable        *viewable);
47 
48 
G_DEFINE_TYPE(GimpImageView,gimp_image_view,GIMP_TYPE_CONTAINER_EDITOR)49 G_DEFINE_TYPE (GimpImageView, gimp_image_view, GIMP_TYPE_CONTAINER_EDITOR)
50 
51 #define parent_class gimp_image_view_parent_class
52 
53 
54 static void
55 gimp_image_view_class_init (GimpImageViewClass *klass)
56 {
57   GimpContainerEditorClass *editor_class = GIMP_CONTAINER_EDITOR_CLASS (klass);
58 
59   editor_class->activate_item = gimp_image_view_activate_item;
60 }
61 
62 static void
gimp_image_view_init(GimpImageView * view)63 gimp_image_view_init (GimpImageView *view)
64 {
65   view->raise_button  = NULL;
66   view->new_button    = NULL;
67   view->delete_button = NULL;
68 }
69 
70 GtkWidget *
gimp_image_view_new(GimpViewType view_type,GimpContainer * container,GimpContext * context,gint view_size,gint view_border_width,GimpMenuFactory * menu_factory)71 gimp_image_view_new (GimpViewType     view_type,
72                      GimpContainer   *container,
73                      GimpContext     *context,
74                      gint             view_size,
75                      gint             view_border_width,
76                      GimpMenuFactory *menu_factory)
77 {
78   GimpImageView       *image_view;
79   GimpContainerEditor *editor;
80 
81   g_return_val_if_fail (GIMP_IS_CONTAINER (container), NULL);
82   g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
83   g_return_val_if_fail (view_size > 0 &&
84                         view_size <= GIMP_VIEWABLE_MAX_PREVIEW_SIZE, NULL);
85   g_return_val_if_fail (view_border_width >= 0 &&
86                         view_border_width <= GIMP_VIEW_MAX_BORDER_WIDTH,
87                         NULL);
88   g_return_val_if_fail (menu_factory == NULL ||
89                         GIMP_IS_MENU_FACTORY (menu_factory), NULL);
90 
91   image_view = g_object_new (GIMP_TYPE_IMAGE_VIEW,
92                              "view-type",         view_type,
93                              "container",         container,
94                              "context",           context,
95                              "view-size",         view_size,
96                              "view-border-width", view_border_width,
97                              "menu-factory",      menu_factory,
98                              "menu-identifier",   "<Images>",
99                              "ui-path",           "/images-popup",
100                              NULL);
101 
102   editor = GIMP_CONTAINER_EDITOR (image_view);
103 
104   image_view->raise_button =
105     gimp_editor_add_action_button (GIMP_EDITOR (editor->view), "images",
106                                    "images-raise-views", NULL);
107 
108   image_view->new_button =
109     gimp_editor_add_action_button (GIMP_EDITOR (editor->view), "images",
110                                    "images-new-view", NULL);
111 
112   image_view->delete_button =
113     gimp_editor_add_action_button (GIMP_EDITOR (editor->view), "images",
114                                    "images-delete", NULL);
115 
116   if (view_type == GIMP_VIEW_TYPE_LIST)
117     {
118       GtkWidget *dnd_widget;
119 
120       dnd_widget = gimp_container_view_get_dnd_widget (editor->view);
121 
122       gimp_dnd_xds_source_add (dnd_widget,
123                                (GimpDndDragViewableFunc) gimp_dnd_get_drag_data,
124                                NULL);
125     }
126 
127   gimp_container_view_enable_dnd (editor->view,
128                                   GTK_BUTTON (image_view->raise_button),
129                                   GIMP_TYPE_IMAGE);
130   gimp_container_view_enable_dnd (editor->view,
131                                   GTK_BUTTON (image_view->new_button),
132                                   GIMP_TYPE_IMAGE);
133   gimp_container_view_enable_dnd (editor->view,
134                                   GTK_BUTTON (image_view->delete_button),
135                                   GIMP_TYPE_IMAGE);
136 
137   gimp_ui_manager_update (gimp_editor_get_ui_manager (GIMP_EDITOR (editor->view)),
138                           editor);
139 
140   return GTK_WIDGET (image_view);
141 }
142 
143 static void
gimp_image_view_activate_item(GimpContainerEditor * editor,GimpViewable * viewable)144 gimp_image_view_activate_item (GimpContainerEditor *editor,
145                                GimpViewable        *viewable)
146 {
147   GimpImageView *view = GIMP_IMAGE_VIEW (editor);
148   GimpContainer *container;
149 
150   if (GIMP_CONTAINER_EDITOR_CLASS (parent_class)->activate_item)
151     GIMP_CONTAINER_EDITOR_CLASS (parent_class)->activate_item (editor, viewable);
152 
153   container = gimp_container_view_get_container (editor->view);
154 
155   if (viewable && gimp_container_have (container, GIMP_OBJECT (viewable)))
156     {
157       gtk_button_clicked (GTK_BUTTON (view->raise_button));
158     }
159 }
160