2002-02-26 13:42:14 +08:00
|
|
|
/* The GIMP -- an image manipulation program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2003-03-16 19:14:29 +08:00
|
|
|
* gimpvectorstreeview.c
|
2004-05-13 02:36:33 +08:00
|
|
|
* Copyright (C) 2001-2004 Michael Natterer <mitch@gimp.org>
|
2002-02-26 13:42:14 +08:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (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
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2004-06-29 21:34:16 +08:00
|
|
|
#include <string.h>
|
|
|
|
|
2002-02-26 13:42:14 +08:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
#include "libgimpwidgets/gimpwidgets.h"
|
|
|
|
|
|
|
|
#include "widgets-types.h"
|
|
|
|
|
2003-09-02 01:56:44 +08:00
|
|
|
#include "core/gimp.h"
|
2002-02-26 13:42:14 +08:00
|
|
|
#include "core/gimpcontainer.h"
|
2003-09-02 01:56:44 +08:00
|
|
|
#include "core/gimpcontext.h"
|
2002-02-26 13:42:14 +08:00
|
|
|
#include "core/gimpimage.h"
|
|
|
|
|
|
|
|
#include "vectors/gimpvectors.h"
|
2004-06-29 21:34:16 +08:00
|
|
|
#include "vectors/gimpvectors-export.h"
|
|
|
|
#include "vectors/gimpvectors-import.h"
|
2002-02-26 13:42:14 +08:00
|
|
|
|
2004-05-11 07:22:39 +08:00
|
|
|
#include "gimpcontainerview.h"
|
2003-03-16 19:14:29 +08:00
|
|
|
#include "gimpvectorstreeview.h"
|
2002-02-26 13:42:14 +08:00
|
|
|
#include "gimpdnd.h"
|
2002-12-20 00:33:29 +08:00
|
|
|
#include "gimpwidgets-utils.h"
|
2002-02-26 13:42:14 +08:00
|
|
|
|
2003-03-26 00:38:19 +08:00
|
|
|
#include "gimp-intl.h"
|
2002-02-26 13:42:14 +08:00
|
|
|
|
|
|
|
|
2005-12-20 06:37:49 +08:00
|
|
|
static void gimp_vectors_tree_view_view_iface_init (GimpContainerViewInterface *iface);
|
2004-07-06 18:54:46 +08:00
|
|
|
|
|
|
|
static GObject * gimp_vectors_tree_view_constructor (GType type,
|
|
|
|
guint n_params,
|
|
|
|
GObjectConstructParam *params);
|
|
|
|
static void gimp_vectors_tree_view_set_container (GimpContainerView *view,
|
|
|
|
GimpContainer *container);
|
|
|
|
static void gimp_vectors_tree_view_drop_svg (GimpContainerTreeView *tree_view,
|
|
|
|
const gchar *svg_data,
|
|
|
|
gsize svg_data_len,
|
|
|
|
GimpViewable *dest_viewable,
|
|
|
|
GtkTreeViewDropPosition drop_pos);
|
2004-10-16 23:48:23 +08:00
|
|
|
static GimpItem * gimp_vectors_tree_view_item_new (GimpImage *image);
|
2004-07-06 18:54:46 +08:00
|
|
|
static guchar * gimp_vectors_tree_view_drag_svg (GtkWidget *widget,
|
|
|
|
gsize *svg_data_len,
|
|
|
|
gpointer data);
|
2004-05-11 07:22:39 +08:00
|
|
|
|
2002-02-26 13:42:14 +08:00
|
|
|
|
2005-12-20 06:37:49 +08:00
|
|
|
G_DEFINE_TYPE_WITH_CODE (GimpVectorsTreeView, gimp_vectors_tree_view,
|
|
|
|
GIMP_TYPE_ITEM_TREE_VIEW,
|
|
|
|
G_IMPLEMENT_INTERFACE (GIMP_TYPE_CONTAINER_VIEW,
|
|
|
|
gimp_vectors_tree_view_view_iface_init));
|
2002-02-26 13:42:14 +08:00
|
|
|
|
2005-12-20 06:37:49 +08:00
|
|
|
#define parent_class gimp_vectors_tree_view_parent_class
|
|
|
|
|
|
|
|
static GimpContainerViewInterface *parent_view_iface = NULL;
|
2002-02-26 13:42:14 +08:00
|
|
|
|
|
|
|
|
|
|
|
static void
|
2003-03-16 19:14:29 +08:00
|
|
|
gimp_vectors_tree_view_class_init (GimpVectorsTreeViewClass *klass)
|
2002-02-26 13:42:14 +08:00
|
|
|
{
|
2005-12-20 06:37:49 +08:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
GimpContainerTreeViewClass *view_class = GIMP_CONTAINER_TREE_VIEW_CLASS (klass);
|
|
|
|
GimpItemTreeViewClass *iv_class = GIMP_ITEM_TREE_VIEW_CLASS (klass);
|
|
|
|
|
|
|
|
object_class->constructor = gimp_vectors_tree_view_constructor;
|
|
|
|
|
|
|
|
view_class->drop_svg = gimp_vectors_tree_view_drop_svg;
|
|
|
|
|
|
|
|
iv_class->item_type = GIMP_TYPE_VECTORS;
|
|
|
|
iv_class->signal_name = "active-vectors-changed";
|
|
|
|
|
|
|
|
iv_class->get_container = gimp_image_get_vectors;
|
|
|
|
iv_class->get_active_item = (GimpGetItemFunc) gimp_image_get_active_vectors;
|
|
|
|
iv_class->set_active_item = (GimpSetItemFunc) gimp_image_set_active_vectors;
|
|
|
|
iv_class->reorder_item = (GimpReorderItemFunc) gimp_image_position_vectors;
|
|
|
|
iv_class->add_item = (GimpAddItemFunc) gimp_image_add_vectors;
|
|
|
|
iv_class->remove_item = (GimpRemoveItemFunc) gimp_image_remove_vectors;
|
|
|
|
iv_class->new_item = gimp_vectors_tree_view_item_new;
|
|
|
|
|
|
|
|
iv_class->action_group = "vectors";
|
|
|
|
iv_class->activate_action = "vectors-path-tool";
|
|
|
|
iv_class->edit_action = "vectors-edit-attributes";
|
|
|
|
iv_class->new_action = "vectors-new";
|
|
|
|
iv_class->new_default_action = "vectors-new-last-values";
|
|
|
|
iv_class->raise_action = "vectors-raise";
|
|
|
|
iv_class->raise_top_action = "vectors-raise-to-top";
|
|
|
|
iv_class->lower_action = "vectors-lower";
|
|
|
|
iv_class->lower_bottom_action = "vectors-lower-to-bottom";
|
|
|
|
iv_class->duplicate_action = "vectors-duplicate";
|
|
|
|
iv_class->delete_action = "vectors-delete";
|
|
|
|
iv_class->reorder_desc = _("Reorder path");
|
2002-02-26 13:42:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-03-16 19:14:29 +08:00
|
|
|
gimp_vectors_tree_view_init (GimpVectorsTreeView *view)
|
2002-02-26 13:42:14 +08:00
|
|
|
{
|
2004-05-13 02:36:33 +08:00
|
|
|
}
|
|
|
|
|
2004-06-29 21:34:16 +08:00
|
|
|
static void
|
2005-12-20 06:37:49 +08:00
|
|
|
gimp_vectors_tree_view_view_iface_init (GimpContainerViewInterface *iface)
|
2004-06-29 21:34:16 +08:00
|
|
|
{
|
2005-12-20 06:37:49 +08:00
|
|
|
parent_view_iface = g_type_interface_peek_parent (iface);
|
2004-06-29 21:34:16 +08:00
|
|
|
|
2005-12-20 06:37:49 +08:00
|
|
|
iface->set_container = gimp_vectors_tree_view_set_container;
|
2004-06-29 21:34:16 +08:00
|
|
|
}
|
|
|
|
|
2004-05-13 02:36:33 +08:00
|
|
|
static GObject *
|
|
|
|
gimp_vectors_tree_view_constructor (GType type,
|
|
|
|
guint n_params,
|
|
|
|
GObjectConstructParam *params)
|
|
|
|
{
|
2004-06-29 21:34:16 +08:00
|
|
|
GObject *object;
|
|
|
|
GimpEditor *editor;
|
|
|
|
GimpContainerTreeView *tree_view;
|
|
|
|
GimpVectorsTreeView *view;
|
2004-05-13 02:36:33 +08:00
|
|
|
|
|
|
|
object = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params);
|
|
|
|
|
2004-06-29 21:34:16 +08:00
|
|
|
editor = GIMP_EDITOR (object);
|
|
|
|
tree_view = GIMP_CONTAINER_TREE_VIEW (object);
|
|
|
|
view = GIMP_VECTORS_TREE_VIEW (object);
|
2002-02-26 13:42:14 +08:00
|
|
|
|
2004-10-17 01:10:04 +08:00
|
|
|
/* hide basically useless edit button */
|
2004-03-17 07:45:48 +08:00
|
|
|
gtk_widget_hide (GIMP_ITEM_TREE_VIEW (view)->edit_button);
|
|
|
|
|
2002-02-26 13:42:14 +08:00
|
|
|
view->toselection_button =
|
2004-05-13 02:36:33 +08:00
|
|
|
gimp_editor_add_action_button (editor, "vectors",
|
|
|
|
"vectors-selection-replace",
|
|
|
|
"vectors-selection-add",
|
|
|
|
GDK_SHIFT_MASK,
|
2004-10-17 01:10:04 +08:00
|
|
|
"vectors-selection-subtract",
|
|
|
|
GDK_CONTROL_MASK,
|
|
|
|
"vectors-selection-intersect",
|
|
|
|
GDK_SHIFT_MASK | GDK_CONTROL_MASK,
|
2004-05-13 02:36:33 +08:00
|
|
|
NULL);
|
2004-10-17 01:10:04 +08:00
|
|
|
gimp_container_view_enable_dnd (GIMP_CONTAINER_VIEW (editor),
|
|
|
|
GTK_BUTTON (view->toselection_button),
|
|
|
|
GIMP_TYPE_VECTORS);
|
|
|
|
gtk_box_reorder_child (GTK_BOX (editor->button_box),
|
|
|
|
view->toselection_button, 5);
|
2003-05-15 22:31:22 +08:00
|
|
|
|
|
|
|
view->tovectors_button =
|
2004-05-13 02:36:33 +08:00
|
|
|
gimp_editor_add_action_button (editor, "vectors",
|
|
|
|
"vectors-selection-to-vectors",
|
|
|
|
"vectors-selection-to-vectors-advanced",
|
|
|
|
GDK_SHIFT_MASK,
|
|
|
|
NULL);
|
2004-10-17 01:10:04 +08:00
|
|
|
gtk_box_reorder_child (GTK_BOX (editor->button_box),
|
|
|
|
view->tovectors_button, 6);
|
2003-05-15 22:31:22 +08:00
|
|
|
|
2002-02-26 13:42:14 +08:00
|
|
|
view->stroke_button =
|
2004-05-13 02:36:33 +08:00
|
|
|
gimp_editor_add_action_button (editor, "vectors",
|
2004-10-23 08:53:48 +08:00
|
|
|
"vectors-stroke",
|
|
|
|
"vectors-stroke-last-values",
|
|
|
|
GDK_SHIFT_MASK,
|
|
|
|
NULL);
|
2004-10-17 01:10:04 +08:00
|
|
|
gimp_container_view_enable_dnd (GIMP_CONTAINER_VIEW (editor),
|
|
|
|
GTK_BUTTON (view->stroke_button),
|
|
|
|
GIMP_TYPE_VECTORS);
|
2003-05-15 22:31:22 +08:00
|
|
|
gtk_box_reorder_child (GTK_BOX (editor->button_box),
|
|
|
|
view->stroke_button, 7);
|
2002-02-26 22:40:30 +08:00
|
|
|
|
2004-06-29 21:34:16 +08:00
|
|
|
gimp_dnd_svg_dest_add (GTK_WIDGET (tree_view->view), NULL, view);
|
|
|
|
|
2004-05-13 02:36:33 +08:00
|
|
|
return object;
|
2002-02-26 13:42:14 +08:00
|
|
|
}
|
2004-06-29 21:34:16 +08:00
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_vectors_tree_view_set_container (GimpContainerView *view,
|
|
|
|
GimpContainer *container)
|
|
|
|
{
|
|
|
|
GimpContainerTreeView *tree_view = GIMP_CONTAINER_TREE_VIEW (view);
|
|
|
|
GimpContainer *old_container;
|
|
|
|
|
|
|
|
old_container = gimp_container_view_get_container (GIMP_CONTAINER_VIEW (view));
|
|
|
|
|
|
|
|
if (old_container && ! container)
|
|
|
|
{
|
|
|
|
gimp_dnd_svg_source_remove (GTK_WIDGET (tree_view->view));
|
|
|
|
}
|
|
|
|
|
|
|
|
parent_view_iface->set_container (view, container);
|
|
|
|
|
|
|
|
if (! old_container && container)
|
|
|
|
{
|
|
|
|
gimp_dnd_svg_source_add (GTK_WIDGET (tree_view->view),
|
|
|
|
gimp_vectors_tree_view_drag_svg,
|
|
|
|
tree_view);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gimp_vectors_tree_view_drop_svg (GimpContainerTreeView *tree_view,
|
|
|
|
const gchar *svg_data,
|
2004-06-30 19:57:17 +08:00
|
|
|
gsize svg_data_len,
|
2004-06-29 21:34:16 +08:00
|
|
|
GimpViewable *dest_viewable,
|
|
|
|
GtkTreeViewDropPosition drop_pos)
|
|
|
|
{
|
2005-01-17 23:28:08 +08:00
|
|
|
GimpItemTreeView *view = GIMP_ITEM_TREE_VIEW (tree_view);
|
|
|
|
GimpImage *image = view->gimage;
|
|
|
|
gint index = -1;
|
|
|
|
GError *error = NULL;
|
2004-06-29 21:34:16 +08:00
|
|
|
|
2005-01-17 23:28:08 +08:00
|
|
|
if (image->gimp->be_verbose)
|
2004-11-17 11:42:47 +08:00
|
|
|
g_print ("%s: SVG dropped (len = %d)\n", G_STRFUNC, (gint) svg_data_len);
|
2004-06-29 21:34:16 +08:00
|
|
|
|
2005-01-17 23:28:08 +08:00
|
|
|
if (dest_viewable)
|
|
|
|
{
|
|
|
|
index = gimp_image_get_vectors_index (image,
|
|
|
|
GIMP_VECTORS (dest_viewable));
|
2004-06-29 21:34:16 +08:00
|
|
|
|
2005-01-17 23:28:08 +08:00
|
|
|
if (drop_pos == GTK_TREE_VIEW_DROP_AFTER)
|
|
|
|
index++;
|
|
|
|
}
|
2004-06-29 21:34:16 +08:00
|
|
|
|
2005-01-17 23:28:08 +08:00
|
|
|
if (! gimp_vectors_import_buffer (image, svg_data, svg_data_len,
|
2004-06-29 21:34:16 +08:00
|
|
|
TRUE, TRUE, index, &error))
|
|
|
|
{
|
|
|
|
g_message (error->message);
|
|
|
|
g_clear_error (&error);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-01-17 23:28:08 +08:00
|
|
|
gimp_image_flush (image);
|
2004-06-29 21:34:16 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-10-16 23:48:23 +08:00
|
|
|
static GimpItem *
|
|
|
|
gimp_vectors_tree_view_item_new (GimpImage *image)
|
|
|
|
{
|
|
|
|
GimpVectors *new_vectors;
|
|
|
|
|
|
|
|
new_vectors = gimp_vectors_new (image, _("Empty Path"));
|
|
|
|
|
|
|
|
gimp_image_add_vectors (image, new_vectors, -1);
|
|
|
|
|
|
|
|
return GIMP_ITEM (new_vectors);
|
|
|
|
}
|
|
|
|
|
2004-07-06 18:54:46 +08:00
|
|
|
static guchar *
|
2004-06-29 21:34:16 +08:00
|
|
|
gimp_vectors_tree_view_drag_svg (GtkWidget *widget,
|
2004-06-30 19:57:17 +08:00
|
|
|
gsize *svg_data_len,
|
2004-06-29 21:34:16 +08:00
|
|
|
gpointer data)
|
|
|
|
{
|
|
|
|
GimpItemTreeView *view = GIMP_ITEM_TREE_VIEW (data);
|
|
|
|
GimpImage *gimage = view->gimage;
|
|
|
|
GimpItem *item;
|
|
|
|
gchar *svg_data = NULL;
|
|
|
|
|
|
|
|
item = GIMP_ITEM_TREE_VIEW_GET_CLASS (view)->get_active_item (gimage);
|
|
|
|
|
|
|
|
*svg_data_len = 0;
|
|
|
|
|
|
|
|
if (item)
|
|
|
|
{
|
|
|
|
svg_data = gimp_vectors_export_string (gimage, GIMP_VECTORS (item));
|
|
|
|
|
|
|
|
if (svg_data)
|
2005-09-20 05:33:03 +08:00
|
|
|
*svg_data_len = strlen (svg_data);
|
2004-06-29 21:34:16 +08:00
|
|
|
}
|
|
|
|
|
2004-07-06 18:54:46 +08:00
|
|
|
return (guchar *) svg_data;
|
2004-06-29 21:34:16 +08:00
|
|
|
}
|