2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2001-06-26 20:09:43 +08:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* gimpbufferview.c
|
2004-01-16 18:06:19 +08:00
|
|
|
* Copyright (C) 2001-2004 Michael Natterer <mitch@gimp.org>
|
2001-06-26 20:09:43 +08:00
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2001-06-26 20:09:43 +08:00
|
|
|
* it under the terms of the GNU General Public License as published by
|
2009-01-18 06:28:01 +08:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2001-06-26 20:09:43 +08:00
|
|
|
* (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
|
2018-07-12 05:27:07 +08:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2001-06-26 20:09:43 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2008-10-10 04:24:04 +08:00
|
|
|
#include <gegl.h>
|
2001-06-26 20:09:43 +08:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
|
|
|
|
|
|
|
#include "widgets-types.h"
|
|
|
|
|
2004-07-13 04:25:05 +08:00
|
|
|
#include "core/gimp.h"
|
2001-07-04 02:38:56 +08:00
|
|
|
#include "core/gimpbuffer.h"
|
2001-06-26 20:09:43 +08:00
|
|
|
#include "core/gimpcontainer.h"
|
|
|
|
#include "core/gimpcontext.h"
|
|
|
|
#include "core/gimpimage.h"
|
|
|
|
|
2017-11-15 03:37:19 +08:00
|
|
|
#include "gimpcontainertreeview.h"
|
2001-06-26 20:09:43 +08:00
|
|
|
#include "gimpcontainerview.h"
|
|
|
|
#include "gimpbufferview.h"
|
|
|
|
#include "gimpdnd.h"
|
2006-08-30 05:44:51 +08:00
|
|
|
#include "gimpdocked.h"
|
2005-06-05 05:20:31 +08:00
|
|
|
#include "gimpeditor.h"
|
2003-08-24 21:52:51 +08:00
|
|
|
#include "gimphelp-ids.h"
|
2004-08-25 01:16:46 +08:00
|
|
|
#include "gimpview.h"
|
2004-09-14 20:19:16 +08:00
|
|
|
#include "gimpviewrendererbuffer.h"
|
2004-05-12 00:05:21 +08:00
|
|
|
#include "gimpuimanager.h"
|
2017-11-13 01:41:05 +08:00
|
|
|
#include "gimpwidgets-utils.h"
|
2001-06-26 20:09:43 +08:00
|
|
|
|
2003-03-26 00:38:19 +08:00
|
|
|
#include "gimp-intl.h"
|
2001-06-26 20:09:43 +08:00
|
|
|
|
|
|
|
|
2006-08-30 05:44:51 +08:00
|
|
|
static void gimp_buffer_view_docked_iface_init (GimpDockedInterface *iface);
|
2004-07-13 04:25:05 +08:00
|
|
|
|
2006-08-30 05:44:51 +08:00
|
|
|
static void gimp_buffer_view_set_context (GimpDocked *docked,
|
|
|
|
GimpContext *context);
|
2001-06-26 20:09:43 +08:00
|
|
|
|
2006-08-30 05:44:51 +08:00
|
|
|
static void gimp_buffer_view_activate_item (GimpContainerEditor *editor,
|
|
|
|
GimpViewable *viewable);
|
2001-06-26 20:09:43 +08:00
|
|
|
|
2016-09-17 23:39:54 +08:00
|
|
|
static void gimp_buffer_view_clipboard_changed (Gimp *gimp,
|
2006-08-30 05:44:51 +08:00
|
|
|
GimpBufferView *buffer_view);
|
|
|
|
static void gimp_buffer_view_view_notify (GimpContainerView *view,
|
|
|
|
GParamSpec *pspec,
|
|
|
|
GimpBufferView *buffer_view);
|
|
|
|
|
|
|
|
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (GimpBufferView, gimp_buffer_view,
|
|
|
|
GIMP_TYPE_CONTAINER_EDITOR,
|
|
|
|
G_IMPLEMENT_INTERFACE (GIMP_TYPE_DOCKED,
|
|
|
|
gimp_buffer_view_docked_iface_init))
|
2001-06-26 20:09:43 +08:00
|
|
|
|
2005-12-20 06:37:49 +08:00
|
|
|
#define parent_class gimp_buffer_view_parent_class
|
2001-06-26 20:09:43 +08:00
|
|
|
|
2006-08-30 05:44:51 +08:00
|
|
|
static GimpDockedInterface *parent_docked_iface = NULL;
|
|
|
|
|
2001-06-26 20:09:43 +08:00
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_buffer_view_class_init (GimpBufferViewClass *klass)
|
|
|
|
{
|
2004-04-22 00:33:17 +08:00
|
|
|
GimpContainerEditorClass *editor_class = GIMP_CONTAINER_EDITOR_CLASS (klass);
|
2001-06-26 20:09:43 +08:00
|
|
|
|
2001-06-30 03:25:03 +08:00
|
|
|
editor_class->activate_item = gimp_buffer_view_activate_item;
|
2001-06-26 20:09:43 +08:00
|
|
|
}
|
|
|
|
|
2006-08-30 05:44:51 +08:00
|
|
|
static void
|
|
|
|
gimp_buffer_view_docked_iface_init (GimpDockedInterface *iface)
|
|
|
|
{
|
|
|
|
parent_docked_iface = g_type_interface_peek_parent (iface);
|
|
|
|
|
|
|
|
if (! parent_docked_iface)
|
|
|
|
parent_docked_iface = g_type_default_interface_peek (GIMP_TYPE_DOCKED);
|
|
|
|
|
|
|
|
iface->set_context = gimp_buffer_view_set_context;
|
|
|
|
}
|
|
|
|
|
2001-06-26 20:09:43 +08:00
|
|
|
static void
|
|
|
|
gimp_buffer_view_init (GimpBufferView *view)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2006-08-30 05:44:51 +08:00
|
|
|
static void
|
|
|
|
gimp_buffer_view_set_context (GimpDocked *docked,
|
|
|
|
GimpContext *context)
|
|
|
|
{
|
|
|
|
GimpBufferView *view = GIMP_BUFFER_VIEW (docked);
|
|
|
|
|
|
|
|
parent_docked_iface->set_context (docked, context);
|
|
|
|
|
2016-09-17 23:39:54 +08:00
|
|
|
gimp_view_renderer_set_context (GIMP_VIEW (view->clipboard_view)->renderer,
|
2006-08-30 05:44:51 +08:00
|
|
|
context);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* public functions */
|
|
|
|
|
2001-06-26 20:09:43 +08:00
|
|
|
GtkWidget *
|
2002-01-26 02:34:33 +08:00
|
|
|
gimp_buffer_view_new (GimpViewType view_type,
|
2004-08-25 01:16:46 +08:00
|
|
|
GimpContainer *container,
|
|
|
|
GimpContext *context,
|
|
|
|
gint view_size,
|
|
|
|
gint view_border_width,
|
|
|
|
GimpMenuFactory *menu_factory)
|
2001-06-26 20:09:43 +08:00
|
|
|
{
|
|
|
|
GimpBufferView *buffer_view;
|
|
|
|
GimpContainerEditor *editor;
|
2004-07-13 04:25:05 +08:00
|
|
|
GtkWidget *frame;
|
|
|
|
GtkWidget *hbox;
|
2001-06-26 20:09:43 +08:00
|
|
|
|
2011-10-10 03:04:49 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_CONTAINER (container), NULL);
|
|
|
|
g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
|
|
|
|
g_return_val_if_fail (view_size > 0 &&
|
|
|
|
view_size <= GIMP_VIEWABLE_MAX_PREVIEW_SIZE, FALSE);
|
|
|
|
g_return_val_if_fail (view_border_width >= 0 &&
|
|
|
|
view_border_width <= GIMP_VIEW_MAX_BORDER_WIDTH,
|
|
|
|
FALSE);
|
|
|
|
|
2011-10-10 02:40:56 +08:00
|
|
|
buffer_view = g_object_new (GIMP_TYPE_BUFFER_VIEW,
|
2011-10-10 03:04:49 +08:00
|
|
|
"view-type", view_type,
|
|
|
|
"container", container,
|
|
|
|
"context", context,
|
|
|
|
"view-size", view_size,
|
|
|
|
"view-border-width", view_border_width,
|
2011-10-10 03:45:02 +08:00
|
|
|
"menu-factory", menu_factory,
|
|
|
|
"menu-identifier", "<Buffers>",
|
|
|
|
"ui-path", "/buffers-popup",
|
2011-10-10 02:40:56 +08:00
|
|
|
NULL);
|
2001-06-26 20:09:43 +08:00
|
|
|
|
|
|
|
editor = GIMP_CONTAINER_EDITOR (buffer_view);
|
|
|
|
|
2017-11-15 03:37:19 +08:00
|
|
|
if (GIMP_IS_CONTAINER_TREE_VIEW (editor->view))
|
|
|
|
{
|
|
|
|
GimpContainerTreeView *tree_view;
|
|
|
|
|
|
|
|
tree_view = GIMP_CONTAINER_TREE_VIEW (editor->view);
|
|
|
|
|
|
|
|
gimp_container_tree_view_connect_name_edited (tree_view,
|
2017-11-15 03:54:38 +08:00
|
|
|
G_CALLBACK (gimp_container_tree_view_name_edited),
|
|
|
|
tree_view);
|
2017-11-15 03:37:19 +08:00
|
|
|
}
|
|
|
|
|
2004-07-13 04:25:05 +08:00
|
|
|
frame = gtk_frame_new (NULL);
|
|
|
|
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
|
|
|
|
gtk_box_pack_start (GTK_BOX (editor), frame, FALSE, FALSE, 0);
|
|
|
|
gtk_box_reorder_child (GTK_BOX (editor), frame, 0);
|
|
|
|
gtk_widget_show (frame);
|
|
|
|
|
2011-09-30 17:29:11 +08:00
|
|
|
hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
|
2004-07-13 04:25:05 +08:00
|
|
|
gtk_container_set_border_width (GTK_CONTAINER (hbox), 2);
|
|
|
|
gtk_container_add (GTK_CONTAINER (frame), hbox);
|
|
|
|
gtk_widget_show (hbox);
|
|
|
|
|
2017-04-20 03:53:04 +08:00
|
|
|
/* FIXME: enable preview of a clipboard image, not just buffer */
|
2016-09-17 23:39:54 +08:00
|
|
|
buffer_view->clipboard_view =
|
2006-08-30 05:44:51 +08:00
|
|
|
gimp_view_new_full_by_types (NULL,
|
|
|
|
GIMP_TYPE_VIEW,
|
2004-09-14 20:19:16 +08:00
|
|
|
GIMP_TYPE_BUFFER,
|
|
|
|
view_size, view_size, view_border_width,
|
|
|
|
FALSE, FALSE, TRUE);
|
2016-09-17 23:39:54 +08:00
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), buffer_view->clipboard_view,
|
2004-07-13 04:25:05 +08:00
|
|
|
FALSE, FALSE, 0);
|
2016-09-17 23:39:54 +08:00
|
|
|
gtk_widget_show (buffer_view->clipboard_view);
|
2004-07-13 04:25:05 +08:00
|
|
|
|
2006-01-17 18:08:50 +08:00
|
|
|
g_signal_connect_object (editor->view, "notify::view-size",
|
|
|
|
G_CALLBACK (gimp_buffer_view_view_notify),
|
2004-07-13 04:25:05 +08:00
|
|
|
buffer_view, 0);
|
2006-01-17 18:08:50 +08:00
|
|
|
g_signal_connect_object (editor->view, "notify::view-border-width",
|
|
|
|
G_CALLBACK (gimp_buffer_view_view_notify),
|
2004-07-13 04:25:05 +08:00
|
|
|
buffer_view, 0);
|
|
|
|
|
2016-09-17 23:39:54 +08:00
|
|
|
buffer_view->clipboard_label = gtk_label_new (_("(None)"));
|
|
|
|
gtk_box_pack_start (GTK_BOX (hbox), buffer_view->clipboard_label,
|
2004-07-13 04:25:05 +08:00
|
|
|
FALSE, FALSE, 0);
|
2016-09-17 23:39:54 +08:00
|
|
|
gtk_widget_show (buffer_view->clipboard_label);
|
2004-07-13 04:25:05 +08:00
|
|
|
|
2016-09-17 23:39:54 +08:00
|
|
|
g_signal_connect_object (context->gimp, "clipboard-changed",
|
|
|
|
G_CALLBACK (gimp_buffer_view_clipboard_changed),
|
2004-07-13 04:25:05 +08:00
|
|
|
G_OBJECT (buffer_view), 0);
|
|
|
|
|
2016-09-17 23:39:54 +08:00
|
|
|
gimp_buffer_view_clipboard_changed (context->gimp, buffer_view);
|
2004-07-13 04:25:05 +08:00
|
|
|
|
2001-08-05 04:38:54 +08:00
|
|
|
buffer_view->paste_button =
|
2004-05-12 00:05:21 +08:00
|
|
|
gimp_editor_add_action_button (GIMP_EDITOR (editor->view), "buffers",
|
2017-11-13 01:41:05 +08:00
|
|
|
"buffers-paste",
|
|
|
|
"buffers-paste-in-place",
|
|
|
|
gimp_get_extend_selection_mask (),
|
|
|
|
NULL);
|
2001-08-05 04:38:54 +08:00
|
|
|
|
|
|
|
buffer_view->paste_into_button =
|
2004-05-12 00:05:21 +08:00
|
|
|
gimp_editor_add_action_button (GIMP_EDITOR (editor->view), "buffers",
|
2017-11-13 01:41:05 +08:00
|
|
|
"buffers-paste-into",
|
|
|
|
"buffers-paste-into-in-place",
|
|
|
|
gimp_get_extend_selection_mask (),
|
|
|
|
NULL);
|
2001-08-05 04:38:54 +08:00
|
|
|
|
2016-09-21 02:43:01 +08:00
|
|
|
buffer_view->paste_as_new_layer_button =
|
|
|
|
gimp_editor_add_action_button (GIMP_EDITOR (editor->view), "buffers",
|
2017-11-13 01:41:05 +08:00
|
|
|
"buffers-paste-as-new-layer",
|
|
|
|
"buffers-paste-as-new-layer-in-place",
|
|
|
|
gimp_get_extend_selection_mask (),
|
|
|
|
NULL);
|
2016-09-21 02:43:01 +08:00
|
|
|
|
2016-09-19 18:14:02 +08:00
|
|
|
buffer_view->paste_as_new_image_button =
|
2004-05-12 00:05:21 +08:00
|
|
|
gimp_editor_add_action_button (GIMP_EDITOR (editor->view), "buffers",
|
2016-09-19 18:14:02 +08:00
|
|
|
"buffers-paste-as-new-image", NULL);
|
2001-08-05 04:38:54 +08:00
|
|
|
|
|
|
|
buffer_view->delete_button =
|
2004-05-12 00:05:21 +08:00
|
|
|
gimp_editor_add_action_button (GIMP_EDITOR (editor->view), "buffers",
|
2004-05-13 02:36:33 +08:00
|
|
|
"buffers-delete", NULL);
|
2001-08-05 04:38:54 +08:00
|
|
|
|
|
|
|
gimp_container_view_enable_dnd (editor->view,
|
2004-08-25 01:16:46 +08:00
|
|
|
GTK_BUTTON (buffer_view->paste_button),
|
|
|
|
GIMP_TYPE_BUFFER);
|
2001-08-05 04:38:54 +08:00
|
|
|
gimp_container_view_enable_dnd (editor->view,
|
2004-08-25 01:16:46 +08:00
|
|
|
GTK_BUTTON (buffer_view->paste_into_button),
|
|
|
|
GIMP_TYPE_BUFFER);
|
2016-09-21 02:43:01 +08:00
|
|
|
gimp_container_view_enable_dnd (editor->view,
|
|
|
|
GTK_BUTTON (buffer_view->paste_as_new_layer_button),
|
|
|
|
GIMP_TYPE_BUFFER);
|
2001-08-05 04:38:54 +08:00
|
|
|
gimp_container_view_enable_dnd (editor->view,
|
2016-09-19 18:14:02 +08:00
|
|
|
GTK_BUTTON (buffer_view->paste_as_new_image_button),
|
2004-08-25 01:16:46 +08:00
|
|
|
GIMP_TYPE_BUFFER);
|
2001-08-05 04:38:54 +08:00
|
|
|
gimp_container_view_enable_dnd (editor->view,
|
2004-08-25 01:16:46 +08:00
|
|
|
GTK_BUTTON (buffer_view->delete_button),
|
|
|
|
GIMP_TYPE_BUFFER);
|
2001-06-26 20:09:43 +08:00
|
|
|
|
2011-04-10 01:51:51 +08:00
|
|
|
gimp_ui_manager_update (gimp_editor_get_ui_manager (GIMP_EDITOR (editor->view)),
|
|
|
|
editor);
|
2001-06-26 20:09:43 +08:00
|
|
|
|
2004-05-12 00:05:21 +08:00
|
|
|
return GTK_WIDGET (buffer_view);
|
2001-06-26 20:09:43 +08:00
|
|
|
}
|
|
|
|
|
2006-08-30 05:44:51 +08:00
|
|
|
|
|
|
|
/* private functions */
|
|
|
|
|
2001-06-26 20:09:43 +08:00
|
|
|
static void
|
2001-06-30 03:25:03 +08:00
|
|
|
gimp_buffer_view_activate_item (GimpContainerEditor *editor,
|
2004-08-25 01:16:46 +08:00
|
|
|
GimpViewable *viewable)
|
2001-06-26 20:09:43 +08:00
|
|
|
{
|
2004-01-15 22:36:43 +08:00
|
|
|
GimpBufferView *view = GIMP_BUFFER_VIEW (editor);
|
2004-05-11 01:16:50 +08:00
|
|
|
GimpContainer *container;
|
2001-06-30 03:25:03 +08:00
|
|
|
|
|
|
|
if (GIMP_CONTAINER_EDITOR_CLASS (parent_class)->activate_item)
|
|
|
|
GIMP_CONTAINER_EDITOR_CLASS (parent_class)->activate_item (editor, viewable);
|
|
|
|
|
2004-05-11 01:16:50 +08:00
|
|
|
container = gimp_container_view_get_container (editor->view);
|
|
|
|
|
|
|
|
if (viewable && gimp_container_have (container, GIMP_OBJECT (viewable)))
|
2001-06-26 20:09:43 +08:00
|
|
|
{
|
2004-05-12 00:05:21 +08:00
|
|
|
gtk_button_clicked (GTK_BUTTON (view->paste_button));
|
2001-06-26 20:09:43 +08:00
|
|
|
}
|
|
|
|
}
|
2004-07-13 04:25:05 +08:00
|
|
|
|
|
|
|
static void
|
2016-09-17 23:39:54 +08:00
|
|
|
gimp_buffer_view_clipboard_changed (Gimp *gimp,
|
|
|
|
GimpBufferView *buffer_view)
|
2004-07-13 04:25:05 +08:00
|
|
|
{
|
2016-09-17 23:39:54 +08:00
|
|
|
GimpBuffer *buffer = gimp_get_clipboard_buffer (gimp);
|
2004-07-13 04:25:05 +08:00
|
|
|
|
2016-09-17 23:39:54 +08:00
|
|
|
gimp_view_set_viewable (GIMP_VIEW (buffer_view->clipboard_view),
|
|
|
|
GIMP_VIEWABLE (buffer));
|
2004-07-13 04:25:05 +08:00
|
|
|
|
2016-09-17 23:39:54 +08:00
|
|
|
if (buffer)
|
|
|
|
{
|
|
|
|
gchar *desc = gimp_viewable_get_description (GIMP_VIEWABLE (buffer),
|
|
|
|
NULL);
|
|
|
|
gtk_label_set_text (GTK_LABEL (buffer_view->clipboard_label), desc);
|
2004-07-13 04:25:05 +08:00
|
|
|
g_free (desc);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-09-17 23:39:54 +08:00
|
|
|
gtk_label_set_text (GTK_LABEL (buffer_view->clipboard_label), _("(None)"));
|
2004-07-13 04:25:05 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2006-01-17 18:08:50 +08:00
|
|
|
gimp_buffer_view_view_notify (GimpContainerView *container_view,
|
|
|
|
GParamSpec *pspec,
|
|
|
|
GimpBufferView *buffer_view)
|
2004-07-13 04:25:05 +08:00
|
|
|
{
|
2016-09-17 23:39:54 +08:00
|
|
|
GimpView *view = GIMP_VIEW (buffer_view->clipboard_view);
|
2004-08-25 01:16:46 +08:00
|
|
|
gint view_size;
|
|
|
|
gint view_border_width;
|
2004-07-13 04:25:05 +08:00
|
|
|
|
2006-01-17 18:08:50 +08:00
|
|
|
view_size = gimp_container_view_get_view_size (container_view,
|
|
|
|
&view_border_width);
|
2004-07-13 04:25:05 +08:00
|
|
|
|
2004-09-14 20:19:16 +08:00
|
|
|
gimp_view_renderer_set_size_full (view->renderer,
|
|
|
|
view_size, view_size, view_border_width);
|
2004-07-13 04:25:05 +08:00
|
|
|
}
|