Commit cd53b607 authored by Michael Natterer's avatar Michael Natterer 😴 Committed by Michael Natterer
Browse files

added gimp_clipboard_has_svg() and gimp_clipboard_get_svg().

2005-05-16  Michael Natterer  <mitch@gimp.org>

	* app/widgets/gimpclipboard.[ch]: added gimp_clipboard_has_svg()
	and gimp_clipboard_get_svg().

	* app/actions/edit-commands.c (edit_paste_cmd_callback): enabled
	pasting of SVG data using gimp_vectors_import_buffer().
parent 19cdc80c
2005-05-16 Michael Natterer <mitch@gimp.org>
* app/widgets/gimpclipboard.[ch]: added gimp_clipboard_has_svg()
and gimp_clipboard_get_svg().
* app/actions/edit-commands.c (edit_paste_cmd_callback): enabled
pasting of SVG data using gimp_vectors_import_buffer().
2005-05-14 Helvetix Victorinox <helvetix@gimp.org>
* app/composite/gimp-composite-altivec-installer.c
......
......@@ -35,6 +35,8 @@
#include "core/gimpimage.h"
#include "core/gimpimage-undo.h"
#include "vectors/gimpvectors-import.h"
#include "display/gimpdisplay.h"
#include "display/gimpdisplayshell.h"
#include "display/gimpdisplayshell-transform.h"
......@@ -309,24 +311,45 @@ static void
edit_paste (GimpDisplay *gdisp,
gboolean paste_into)
{
GimpBuffer *buffer = gimp_clipboard_get_buffer (gdisp->gimage->gimp);
guchar *svg;
gsize svg_size;
if (buffer)
svg = gimp_clipboard_get_svg (gdisp->gimage->gimp, &svg_size);
if (svg)
{
GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (gdisp->shell);
gint x, y;
gint width, height;
if (gimp_vectors_import_buffer (gdisp->gimage, svg, svg_size,
TRUE, TRUE, -1, NULL))
{
gimp_image_flush (gdisp->gimage);
}
gimp_display_shell_untransform_viewport (shell, &x, &y, &width, &height);
g_free (svg);
}
else
{
GimpBuffer *buffer;
if (gimp_edit_paste (gdisp->gimage,
gimp_image_active_drawable (gdisp->gimage),
buffer, paste_into, x, y, width, height))
{
gimp_image_flush (gdisp->gimage);
}
buffer = gimp_clipboard_get_buffer (gdisp->gimage->gimp);
g_object_unref (buffer);
if (buffer)
{
GimpDisplayShell *shell = GIMP_DISPLAY_SHELL (gdisp->shell);
gint x, y;
gint width, height;
gimp_display_shell_untransform_viewport (shell,
&x, &y, &width, &height);
if (gimp_edit_paste (gdisp->gimage,
gimp_image_active_drawable (gdisp->gimage),
buffer, paste_into, x, y, width, height))
{
gimp_image_flush (gdisp->gimage);
}
g_object_unref (buffer);
}
}
}
......
......@@ -62,6 +62,7 @@ static void gimp_clipboard_send_buffer (GtkClipboard *clipboard,
static GdkAtom * gimp_clipboard_wait_for_targets (gint *n_targets);
static GdkAtom gimp_clipboard_wait_for_buffer (Gimp *gimp);
static GdkAtom gimp_clipboard_wait_for_svg (Gimp *gimp);
void
......@@ -193,6 +194,24 @@ gimp_clipboard_has_buffer (Gimp *gimp)
return (gimp_clipboard_wait_for_buffer (gimp) != GDK_NONE);
}
/**
* gimp_clipboard_has_svg:
* @gimp: pointer to #Gimp
*
* Tests if there's SVG data in %GDK_SELECTION_CLIPBOARD.
* This is done in a main-loop similar to
* gtk_clipboard_wait_is_text_available(). The same caveats apply here.
*
* Return value: %TRUE if there's SVG data in the clipboard, %FALSE otherwise
**/
gboolean
gimp_clipboard_has_svg (Gimp *gimp)
{
g_return_val_if_fail (GIMP_IS_GIMP (gimp), FALSE);
return (gimp_clipboard_wait_for_svg (gimp) != GDK_NONE);
}
/**
* gimp_clipboard_get_buffer:
* @gimp: pointer to #Gimp
......@@ -250,6 +269,57 @@ gimp_clipboard_get_buffer (Gimp *gimp)
return buffer;
}
/**
* gimp_clipboard_get_svg:
* @gimp: pointer to #Gimp
*
* Retrieves SVG data from %GDK_SELECTION_CLIPBOARD.
*
* The returned data needs to be freed when it's no longer
* needed.
*
* Return value: a reference to a #GimpBuffer or %NULL if there's no
* image data
**/
guchar *
gimp_clipboard_get_svg (Gimp *gimp,
gsize *svg_size)
{
GtkClipboard *clipboard;
GdkAtom atom;
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
g_return_val_if_fail (svg_size != NULL, NULL);
clipboard = gtk_clipboard_get_for_display (gdk_display_get_default (),
GDK_SELECTION_CLIPBOARD);
if (clipboard &&
gtk_clipboard_get_owner (clipboard) != G_OBJECT (gimp) &&
(atom = gimp_clipboard_wait_for_svg (gimp)) != GDK_NONE)
{
GtkSelectionData *data;
data = gtk_clipboard_wait_for_contents (clipboard, atom);
if (data)
{
guchar *svg;
svg = (guchar *) gimp_selection_data_get_stream (data, svg_size);
if (svg)
svg = g_memdup (svg, *svg_size);
gtk_selection_data_free (data);
return svg;
}
}
return NULL;
}
/* private functions */
......@@ -408,6 +478,41 @@ gimp_clipboard_wait_for_buffer (Gimp *gimp)
return result;
}
static GdkAtom
gimp_clipboard_wait_for_svg (Gimp *gimp)
{
GdkAtom *targets;
gint n_targets;
GdkAtom result = GDK_NONE;
targets = gimp_clipboard_wait_for_targets (&n_targets);
if (targets)
{
GdkAtom svg_atom = gdk_atom_intern ("image/svg", FALSE);
GdkAtom svg_xml_atom = gdk_atom_intern ("image/svg+xml", FALSE);
gint i;
for (i = 0; i < n_targets; i++)
{
if (targets[i] == svg_atom)
{
result = svg_atom;
break;
}
else if (targets[i] == svg_xml_atom)
{
result = svg_xml_atom;
break;
}
}
g_free (targets);
}
return result;
}
static void
gimp_clipboard_send_buffer (GtkClipboard *clipboard,
GtkSelectionData *selection_data,
......
......@@ -20,11 +20,15 @@
#define __GIMP_CLIPBOARD_H__
void gimp_clipboard_init (Gimp *gimp);
void gimp_clipboard_exit (Gimp *gimp);
void gimp_clipboard_init (Gimp *gimp);
void gimp_clipboard_exit (Gimp *gimp);
gboolean gimp_clipboard_has_buffer (Gimp *gimp);
GimpBuffer * gimp_clipboard_get_buffer (Gimp *gimp);
gboolean gimp_clipboard_has_buffer (Gimp *gimp);
GimpBuffer * gimp_clipboard_get_buffer (Gimp *gimp);
gboolean gimp_clipboard_has_svg (Gimp *gimp);
guchar * gimp_clipboard_get_svg (Gimp *gimp,
gsize *svg_length);
#endif /* __GIMP_CLIPBOARD_H__ */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment