2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
2004-06-29 04:39:54 +08:00
|
|
|
* Copyright (C) 1995-1997 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
2004-06-29 04:39:54 +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
|
2004-06-29 04:39:54 +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
|
2009-01-18 06:28:01 +08:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2004-06-29 04:39:54 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
2008-10-10 04:24:04 +08:00
|
|
|
#include <gegl.h>
|
2004-06-29 04:39:54 +08:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
#include "libgimpcolor/gimpcolor.h"
|
2010-02-17 02:58:51 +08:00
|
|
|
#include "libgimpconfig/gimpconfig.h"
|
2004-06-29 04:39:54 +08:00
|
|
|
|
|
|
|
#include "widgets-types.h"
|
|
|
|
|
2008-02-07 21:19:15 +08:00
|
|
|
#include "base/base-utils.h"
|
|
|
|
|
2004-06-29 04:39:54 +08:00
|
|
|
#include "core/gimp.h"
|
|
|
|
#include "core/gimpbrush.h"
|
|
|
|
#include "core/gimpcontainer.h"
|
2010-02-17 02:58:51 +08:00
|
|
|
#include "core/gimpcurve.h"
|
2004-06-29 04:39:54 +08:00
|
|
|
#include "core/gimpdatafactory.h"
|
|
|
|
#include "core/gimpgradient.h"
|
|
|
|
#include "core/gimpimage.h"
|
|
|
|
#include "core/gimpimagefile.h"
|
|
|
|
#include "core/gimpitem.h"
|
|
|
|
#include "core/gimppalette.h"
|
|
|
|
#include "core/gimppattern.h"
|
|
|
|
#include "core/gimptoolinfo.h"
|
|
|
|
|
|
|
|
#include "text/gimpfont.h"
|
|
|
|
|
|
|
|
#include "gimpselectiondata.h"
|
|
|
|
|
2007-11-15 21:54:15 +08:00
|
|
|
#include "gimp-log.h"
|
2004-06-29 04:39:54 +08:00
|
|
|
#include "gimp-intl.h"
|
|
|
|
|
|
|
|
|
2005-07-25 21:53:00 +08:00
|
|
|
/* local function prototypes */
|
|
|
|
|
2008-09-02 19:30:28 +08:00
|
|
|
static const gchar * gimp_selection_data_get_name (GtkSelectionData *selection,
|
|
|
|
const gchar *strfunc);
|
|
|
|
static GimpObject * gimp_selection_data_get_object (GtkSelectionData *selection,
|
|
|
|
GimpContainer *container,
|
|
|
|
GimpObject *additional);
|
|
|
|
static gchar * gimp_unescape_uri_string (const char *escaped,
|
|
|
|
int len,
|
|
|
|
const char *illegal_escaped_characters,
|
|
|
|
gboolean ascii_must_not_be_escaped);
|
2005-07-25 21:53:00 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* public functions */
|
|
|
|
|
2004-06-29 04:39:54 +08:00
|
|
|
void
|
2004-06-30 22:47:23 +08:00
|
|
|
gimp_selection_data_set_uri_list (GtkSelectionData *selection,
|
|
|
|
GList *uri_list)
|
2004-06-29 04:39:54 +08:00
|
|
|
{
|
|
|
|
GList *list;
|
|
|
|
gchar *vals = NULL;
|
|
|
|
|
|
|
|
g_return_if_fail (selection != NULL);
|
2004-06-30 22:47:23 +08:00
|
|
|
g_return_if_fail (uri_list != NULL);
|
2004-06-29 04:39:54 +08:00
|
|
|
|
2004-06-30 22:47:23 +08:00
|
|
|
for (list = uri_list; list; list = g_list_next (list))
|
2004-06-29 04:39:54 +08:00
|
|
|
{
|
|
|
|
if (vals)
|
|
|
|
{
|
|
|
|
gchar *tmp = g_strconcat (vals,
|
|
|
|
list->data,
|
|
|
|
list->next ? "\n" : NULL,
|
|
|
|
NULL);
|
|
|
|
g_free (vals);
|
|
|
|
vals = tmp;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
vals = g_strconcat (list->data,
|
|
|
|
list->next ? "\n" : NULL,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-23 00:35:53 +08:00
|
|
|
gtk_selection_data_set (selection,
|
|
|
|
gtk_selection_data_get_target (selection),
|
2008-09-02 20:00:07 +08:00
|
|
|
8, (guchar *) vals, strlen (vals));
|
2004-06-29 04:39:54 +08:00
|
|
|
|
|
|
|
g_free (vals);
|
|
|
|
}
|
|
|
|
|
|
|
|
GList *
|
2004-06-30 22:47:23 +08:00
|
|
|
gimp_selection_data_get_uri_list (GtkSelectionData *selection)
|
2004-06-29 04:39:54 +08:00
|
|
|
{
|
2005-03-23 19:26:56 +08:00
|
|
|
GList *crap_list = NULL;
|
|
|
|
GList *uri_list = NULL;
|
|
|
|
GList *list;
|
2009-03-23 00:35:53 +08:00
|
|
|
gint length;
|
|
|
|
const gchar *data;
|
2005-03-23 19:26:56 +08:00
|
|
|
const gchar *buffer;
|
2004-06-29 04:39:54 +08:00
|
|
|
|
|
|
|
g_return_val_if_fail (selection != NULL, NULL);
|
|
|
|
|
2009-03-23 00:35:53 +08:00
|
|
|
length = gtk_selection_data_get_length (selection);
|
|
|
|
|
|
|
|
if (gtk_selection_data_get_format (selection) != 8 || length < 1)
|
2004-06-29 04:39:54 +08:00
|
|
|
{
|
|
|
|
g_warning ("Received invalid file data!");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-03-23 00:35:53 +08:00
|
|
|
data = buffer = (const gchar *) gtk_selection_data_get_data (selection);
|
2004-06-29 04:39:54 +08:00
|
|
|
|
2007-11-15 21:54:15 +08:00
|
|
|
GIMP_LOG (DND, "raw buffer >>%s<<", buffer);
|
2004-06-29 04:39:54 +08:00
|
|
|
|
|
|
|
{
|
|
|
|
gchar name_buffer[1024];
|
|
|
|
|
2009-03-23 00:35:53 +08:00
|
|
|
while (*buffer && (buffer - data < length))
|
2004-06-29 04:39:54 +08:00
|
|
|
{
|
2006-04-12 20:49:29 +08:00
|
|
|
gchar *name = name_buffer;
|
|
|
|
gint len = 0;
|
2004-06-29 04:39:54 +08:00
|
|
|
|
2006-04-12 20:49:29 +08:00
|
|
|
while (len < sizeof (name_buffer) && *buffer && *buffer != '\n')
|
|
|
|
{
|
|
|
|
*name++ = *buffer++;
|
|
|
|
len++;
|
|
|
|
}
|
|
|
|
if (len == 0)
|
|
|
|
break;
|
2004-06-29 04:39:54 +08:00
|
|
|
|
2006-04-12 20:49:29 +08:00
|
|
|
if (*(name - 1) == 0xd) /* gmc uses RETURN+NEWLINE as delimiter */
|
|
|
|
len--;
|
2004-06-29 04:39:54 +08:00
|
|
|
|
2006-04-12 20:49:29 +08:00
|
|
|
if (len > 2)
|
|
|
|
crap_list = g_list_prepend (crap_list, g_strndup (name_buffer, len));
|
2004-06-29 04:39:54 +08:00
|
|
|
|
2006-04-12 20:49:29 +08:00
|
|
|
if (*buffer)
|
|
|
|
buffer++;
|
2004-06-29 04:39:54 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! crap_list)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* do various checks because file drag sources send all kinds of
|
|
|
|
* arbitrary crap...
|
|
|
|
*/
|
|
|
|
for (list = crap_list; list; list = g_list_next (list))
|
|
|
|
{
|
|
|
|
const gchar *dnd_crap = list->data;
|
|
|
|
gchar *filename;
|
2005-02-08 01:56:18 +08:00
|
|
|
gchar *hostname;
|
2004-06-29 04:39:54 +08:00
|
|
|
gchar *uri = NULL;
|
|
|
|
GError *error = NULL;
|
|
|
|
|
2007-11-15 21:54:15 +08:00
|
|
|
GIMP_LOG (DND, "trying to convert \"%s\" to an uri", dnd_crap);
|
2004-06-29 04:39:54 +08:00
|
|
|
|
2005-02-08 02:30:13 +08:00
|
|
|
filename = g_filename_from_uri (dnd_crap, &hostname, NULL);
|
2004-06-29 04:39:54 +08:00
|
|
|
|
|
|
|
if (filename)
|
|
|
|
{
|
2004-08-05 01:11:39 +08:00
|
|
|
/* if we got a correctly encoded "file:" uri...
|
|
|
|
*
|
|
|
|
* (for GLib < 2.4.4, this is escaped UTF-8,
|
|
|
|
* for GLib > 2.4.4, this is escaped local filename encoding)
|
|
|
|
*/
|
2004-06-29 04:39:54 +08:00
|
|
|
|
2005-02-08 01:56:18 +08:00
|
|
|
uri = g_filename_to_uri (filename, hostname, NULL);
|
2004-06-29 04:39:54 +08:00
|
|
|
|
2005-02-08 01:56:18 +08:00
|
|
|
g_free (hostname);
|
2004-06-29 04:39:54 +08:00
|
|
|
g_free (filename);
|
|
|
|
}
|
|
|
|
else if (g_file_test (dnd_crap, G_FILE_TEST_EXISTS))
|
|
|
|
{
|
|
|
|
/* ...else if we got a valid local filename... */
|
|
|
|
|
|
|
|
uri = g_filename_to_uri (dnd_crap, NULL, NULL);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* ...otherwise do evil things... */
|
|
|
|
|
|
|
|
const gchar *start = dnd_crap;
|
|
|
|
|
2006-11-13 04:30:50 +08:00
|
|
|
if (g_str_has_prefix (dnd_crap, "file://"))
|
2004-06-29 04:39:54 +08:00
|
|
|
{
|
|
|
|
start += strlen ("file://");
|
|
|
|
}
|
2006-11-13 04:30:50 +08:00
|
|
|
else if (g_str_has_prefix (dnd_crap, "file:"))
|
2004-06-29 04:39:54 +08:00
|
|
|
{
|
|
|
|
start += strlen ("file:");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (start != dnd_crap)
|
|
|
|
{
|
2004-08-05 01:11:39 +08:00
|
|
|
/* try if we got a "file:" uri in the wrong encoding...
|
|
|
|
*
|
|
|
|
* (for GLib < 2.4.4, this is escaped local filename encoding,
|
|
|
|
* for GLib > 2.4.4, this is escaped UTF-8)
|
|
|
|
*/
|
|
|
|
gchar *unescaped_filename;
|
2004-06-29 04:39:54 +08:00
|
|
|
|
|
|
|
if (strstr (dnd_crap, "%"))
|
|
|
|
{
|
2004-09-16 22:31:39 +08:00
|
|
|
gchar *local_filename;
|
|
|
|
|
2004-06-29 04:39:54 +08:00
|
|
|
unescaped_filename = gimp_unescape_uri_string (start, -1,
|
|
|
|
"/", FALSE);
|
2004-08-05 01:11:39 +08:00
|
|
|
|
2004-09-16 22:31:39 +08:00
|
|
|
/* check if we got a drop from an application that
|
|
|
|
* encodes file: URIs as UTF-8 (apps linked against
|
|
|
|
* GLib < 2.4.4)
|
|
|
|
*/
|
|
|
|
local_filename = g_filename_from_utf8 (unescaped_filename,
|
|
|
|
-1, NULL, NULL,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
if (local_filename)
|
2004-08-05 01:11:39 +08:00
|
|
|
{
|
2004-09-16 22:31:39 +08:00
|
|
|
g_free (unescaped_filename);
|
|
|
|
unescaped_filename = local_filename;
|
2004-08-05 01:11:39 +08:00
|
|
|
}
|
2004-06-29 04:39:54 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
unescaped_filename = g_strdup (start);
|
|
|
|
}
|
|
|
|
|
|
|
|
uri = g_filename_to_uri (unescaped_filename, NULL, &error);
|
|
|
|
|
|
|
|
if (! uri)
|
|
|
|
{
|
|
|
|
gchar *escaped_filename = g_strescape (unescaped_filename,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
g_message (_("The filename '%s' couldn't be converted to a "
|
|
|
|
"valid URI:\n\n%s"),
|
|
|
|
escaped_filename,
|
|
|
|
error->message ?
|
|
|
|
error->message : _("Invalid UTF-8"));
|
|
|
|
g_free (escaped_filename);
|
|
|
|
g_clear_error (&error);
|
|
|
|
|
|
|
|
g_free (unescaped_filename);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (unescaped_filename);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* otherwise try the crap passed anyway, in case it's
|
|
|
|
* a "http:" or whatever uri a plug-in might handle
|
|
|
|
*/
|
|
|
|
uri = g_strdup (dnd_crap);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uri_list = g_list_prepend (uri_list, uri);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_list_foreach (crap_list, (GFunc) g_free, NULL);
|
|
|
|
g_list_free (crap_list);
|
|
|
|
|
|
|
|
return uri_list;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gimp_selection_data_set_color (GtkSelectionData *selection,
|
|
|
|
const GimpRGB *color)
|
|
|
|
{
|
2007-05-23 16:57:53 +08:00
|
|
|
guint16 vals[4];
|
2004-06-29 04:39:54 +08:00
|
|
|
guchar r, g, b, a;
|
|
|
|
|
|
|
|
g_return_if_fail (selection != NULL);
|
|
|
|
g_return_if_fail (color != NULL);
|
|
|
|
|
|
|
|
gimp_rgba_get_uchar (color, &r, &g, &b, &a);
|
|
|
|
|
|
|
|
vals[0] = r + (r << 8);
|
|
|
|
vals[1] = g + (g << 8);
|
|
|
|
vals[2] = b + (b << 8);
|
|
|
|
vals[3] = a + (a << 8);
|
|
|
|
|
2009-03-23 00:35:53 +08:00
|
|
|
gtk_selection_data_set (selection,
|
|
|
|
gtk_selection_data_get_target (selection),
|
2007-05-23 16:57:53 +08:00
|
|
|
16, (const guchar *) vals, 8);
|
2004-06-29 04:39:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gimp_selection_data_get_color (GtkSelectionData *selection,
|
|
|
|
GimpRGB *color)
|
|
|
|
{
|
2009-03-23 00:35:53 +08:00
|
|
|
const guint16 *color_vals;
|
2004-06-29 04:39:54 +08:00
|
|
|
|
|
|
|
g_return_val_if_fail (selection != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (color != NULL, FALSE);
|
|
|
|
|
2009-03-23 00:35:53 +08:00
|
|
|
if (gtk_selection_data_get_format (selection) != 16 ||
|
|
|
|
gtk_selection_data_get_length (selection) != 8)
|
2004-06-29 04:39:54 +08:00
|
|
|
{
|
|
|
|
g_warning ("Received invalid color data!");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2009-03-23 00:35:53 +08:00
|
|
|
color_vals = (const guint16 *) gtk_selection_data_get_data (selection);
|
2004-06-29 04:39:54 +08:00
|
|
|
|
|
|
|
gimp_rgba_set_uchar (color,
|
2006-04-12 20:49:29 +08:00
|
|
|
(guchar) (color_vals[0] >> 8),
|
|
|
|
(guchar) (color_vals[1] >> 8),
|
|
|
|
(guchar) (color_vals[2] >> 8),
|
|
|
|
(guchar) (color_vals[3] >> 8));
|
2004-06-29 04:39:54 +08:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-06-30 19:57:17 +08:00
|
|
|
gimp_selection_data_set_stream (GtkSelectionData *selection,
|
|
|
|
const guchar *stream,
|
|
|
|
gsize stream_length)
|
2004-06-29 04:39:54 +08:00
|
|
|
{
|
|
|
|
g_return_if_fail (selection != NULL);
|
2004-06-30 19:57:17 +08:00
|
|
|
g_return_if_fail (stream != NULL);
|
|
|
|
g_return_if_fail (stream_length > 0);
|
2004-06-29 04:39:54 +08:00
|
|
|
|
2009-03-23 00:35:53 +08:00
|
|
|
gtk_selection_data_set (selection,
|
|
|
|
gtk_selection_data_get_target (selection),
|
2004-06-30 19:57:17 +08:00
|
|
|
8, (guchar *) stream, stream_length);
|
2004-06-29 04:39:54 +08:00
|
|
|
}
|
|
|
|
|
2004-06-30 19:57:17 +08:00
|
|
|
const guchar *
|
|
|
|
gimp_selection_data_get_stream (GtkSelectionData *selection,
|
|
|
|
gsize *stream_length)
|
2004-06-29 04:39:54 +08:00
|
|
|
{
|
2009-03-23 00:35:53 +08:00
|
|
|
gint length;
|
|
|
|
|
2004-06-29 04:39:54 +08:00
|
|
|
g_return_val_if_fail (selection != NULL, NULL);
|
2004-06-30 19:57:17 +08:00
|
|
|
g_return_val_if_fail (stream_length != NULL, NULL);
|
2004-06-29 04:39:54 +08:00
|
|
|
|
2009-03-23 00:35:53 +08:00
|
|
|
length = gtk_selection_data_get_length (selection);
|
|
|
|
|
|
|
|
if (gtk_selection_data_get_format (selection) != 8 || length < 1)
|
2004-06-29 04:39:54 +08:00
|
|
|
{
|
2004-06-30 19:57:17 +08:00
|
|
|
g_warning ("Received invalid data stream!");
|
2004-06-29 04:39:54 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-03-23 00:35:53 +08:00
|
|
|
*stream_length = length;
|
2004-06-29 04:39:54 +08:00
|
|
|
|
2009-03-23 00:35:53 +08:00
|
|
|
return (const guchar *) gtk_selection_data_get_data (selection);
|
2004-06-29 04:39:54 +08:00
|
|
|
}
|
|
|
|
|
2010-02-17 02:58:51 +08:00
|
|
|
void
|
|
|
|
gimp_selection_data_set_curve (GtkSelectionData *selection,
|
|
|
|
GimpCurve *curve)
|
|
|
|
{
|
|
|
|
gchar *str;
|
|
|
|
|
|
|
|
g_return_if_fail (selection != NULL);
|
|
|
|
g_return_if_fail (GIMP_IS_CURVE (curve));
|
|
|
|
|
|
|
|
str = gimp_config_serialize_to_string (GIMP_CONFIG (curve), NULL);
|
|
|
|
|
|
|
|
gtk_selection_data_set (selection,
|
|
|
|
gtk_selection_data_get_target (selection),
|
|
|
|
8, (guchar *) str, strlen (str));
|
|
|
|
|
|
|
|
g_free (str);
|
|
|
|
}
|
|
|
|
|
|
|
|
GimpCurve *
|
|
|
|
gimp_selection_data_get_curve (GtkSelectionData *selection)
|
|
|
|
{
|
|
|
|
GimpCurve *curve;
|
|
|
|
gint length;
|
|
|
|
GError *error = NULL;
|
|
|
|
|
|
|
|
g_return_val_if_fail (selection != NULL, NULL);
|
|
|
|
|
|
|
|
length = gtk_selection_data_get_length (selection);
|
|
|
|
|
|
|
|
if (gtk_selection_data_get_format (selection) != 8 || length < 1)
|
|
|
|
{
|
|
|
|
g_warning ("Received invalid curve data!");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
curve = GIMP_CURVE (gimp_curve_new ("pasted curve"));
|
|
|
|
|
|
|
|
if (! gimp_config_deserialize_string (GIMP_CONFIG (curve),
|
|
|
|
(const gchar *)
|
|
|
|
gtk_selection_data_get_data (selection),
|
|
|
|
length,
|
|
|
|
NULL,
|
|
|
|
&error))
|
|
|
|
{
|
|
|
|
g_warning ("Received invalid curve data: %s", error->message);
|
|
|
|
g_clear_error (&error);
|
|
|
|
g_object_unref (curve);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return curve;
|
|
|
|
}
|
|
|
|
|
2004-06-29 04:39:54 +08:00
|
|
|
void
|
|
|
|
gimp_selection_data_set_image (GtkSelectionData *selection,
|
2006-03-29 01:08:36 +08:00
|
|
|
GimpImage *image)
|
2004-06-29 04:39:54 +08:00
|
|
|
{
|
2005-07-25 21:53:00 +08:00
|
|
|
gchar *str;
|
2004-06-29 04:39:54 +08:00
|
|
|
|
|
|
|
g_return_if_fail (selection != NULL);
|
2006-03-29 01:08:36 +08:00
|
|
|
g_return_if_fail (GIMP_IS_IMAGE (image));
|
2004-06-29 04:39:54 +08:00
|
|
|
|
2008-02-07 21:19:15 +08:00
|
|
|
str = g_strdup_printf ("%d:%d", get_pid (), gimp_image_get_ID (image));
|
2004-06-29 04:39:54 +08:00
|
|
|
|
2009-03-23 00:35:53 +08:00
|
|
|
gtk_selection_data_set (selection,
|
|
|
|
gtk_selection_data_get_target (selection),
|
2008-09-02 20:00:07 +08:00
|
|
|
8, (guchar *) str, strlen (str));
|
2004-06-29 04:39:54 +08:00
|
|
|
|
2005-07-25 21:53:00 +08:00
|
|
|
g_free (str);
|
2004-06-29 04:39:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
GimpImage *
|
|
|
|
gimp_selection_data_get_image (GtkSelectionData *selection,
|
|
|
|
Gimp *gimp)
|
|
|
|
{
|
2008-09-02 19:30:28 +08:00
|
|
|
const gchar *str;
|
2004-06-29 04:39:54 +08:00
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
|
|
|
|
g_return_val_if_fail (selection != NULL, NULL);
|
|
|
|
|
2008-09-02 19:30:28 +08:00
|
|
|
str = gimp_selection_data_get_name (selection, G_STRFUNC);
|
2005-07-25 21:53:00 +08:00
|
|
|
|
2008-09-02 19:30:28 +08:00
|
|
|
if (str)
|
2004-06-29 04:39:54 +08:00
|
|
|
{
|
2008-09-02 19:30:28 +08:00
|
|
|
gint pid;
|
|
|
|
gint ID;
|
2004-06-29 04:39:54 +08:00
|
|
|
|
2008-09-02 19:30:28 +08:00
|
|
|
if (sscanf (str, "%i:%i", &pid, &ID) == 2 &&
|
|
|
|
pid == get_pid ())
|
|
|
|
{
|
|
|
|
return gimp_image_get_by_ID (gimp, ID);
|
|
|
|
}
|
|
|
|
}
|
2004-06-29 04:39:54 +08:00
|
|
|
|
2008-09-02 19:30:28 +08:00
|
|
|
return NULL;
|
2004-06-29 04:39:54 +08:00
|
|
|
}
|
|
|
|
|
2005-01-15 10:24:38 +08:00
|
|
|
void
|
|
|
|
gimp_selection_data_set_component (GtkSelectionData *selection,
|
2006-03-29 01:08:36 +08:00
|
|
|
GimpImage *image,
|
2005-01-15 10:24:38 +08:00
|
|
|
GimpChannelType channel)
|
|
|
|
{
|
2005-07-25 21:53:00 +08:00
|
|
|
gchar *str;
|
2005-01-15 10:24:38 +08:00
|
|
|
|
|
|
|
g_return_if_fail (selection != NULL);
|
2006-03-29 01:08:36 +08:00
|
|
|
g_return_if_fail (GIMP_IS_IMAGE (image));
|
2005-01-15 10:24:38 +08:00
|
|
|
|
2008-02-07 21:19:15 +08:00
|
|
|
str = g_strdup_printf ("%d:%d:%d", get_pid (), gimp_image_get_ID (image),
|
2005-07-25 21:53:00 +08:00
|
|
|
(gint) channel);
|
2005-01-15 10:24:38 +08:00
|
|
|
|
2009-03-23 00:35:53 +08:00
|
|
|
gtk_selection_data_set (selection,
|
|
|
|
gtk_selection_data_get_target (selection),
|
2008-09-02 20:00:07 +08:00
|
|
|
8, (guchar *) str, strlen (str));
|
2005-01-15 10:24:38 +08:00
|
|
|
|
2005-07-25 21:53:00 +08:00
|
|
|
g_free (str);
|
2005-01-15 10:24:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
GimpImage *
|
|
|
|
gimp_selection_data_get_component (GtkSelectionData *selection,
|
|
|
|
Gimp *gimp,
|
|
|
|
GimpChannelType *channel)
|
|
|
|
{
|
2008-09-02 19:30:28 +08:00
|
|
|
const gchar *str;
|
2005-01-15 10:24:38 +08:00
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
|
|
|
|
g_return_val_if_fail (selection != NULL, NULL);
|
|
|
|
|
2005-07-25 21:53:00 +08:00
|
|
|
if (channel)
|
|
|
|
*channel = 0;
|
2005-01-15 10:24:38 +08:00
|
|
|
|
2008-09-02 19:30:28 +08:00
|
|
|
str = gimp_selection_data_get_name (selection, G_STRFUNC);
|
2005-01-15 10:24:38 +08:00
|
|
|
|
2008-09-02 19:30:28 +08:00
|
|
|
if (str)
|
2005-03-23 20:29:56 +08:00
|
|
|
{
|
2008-09-02 19:30:28 +08:00
|
|
|
gint pid;
|
|
|
|
gint ID;
|
|
|
|
gint ch;
|
2005-01-15 10:24:38 +08:00
|
|
|
|
2008-09-02 19:30:28 +08:00
|
|
|
if (sscanf (str, "%i:%i:%i", &pid, &ID, &ch) == 3 &&
|
|
|
|
pid == get_pid ())
|
|
|
|
{
|
|
|
|
GimpImage *image = gimp_image_get_by_ID (gimp, ID);
|
2005-01-15 10:24:38 +08:00
|
|
|
|
2008-09-02 19:30:28 +08:00
|
|
|
if (image && channel)
|
|
|
|
*channel = ch;
|
2005-01-15 10:24:38 +08:00
|
|
|
|
2008-09-02 19:30:28 +08:00
|
|
|
return image;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
2005-01-15 10:24:38 +08:00
|
|
|
}
|
|
|
|
|
2004-06-29 04:39:54 +08:00
|
|
|
void
|
|
|
|
gimp_selection_data_set_item (GtkSelectionData *selection,
|
|
|
|
GimpItem *item)
|
|
|
|
{
|
2005-07-25 21:53:00 +08:00
|
|
|
gchar *str;
|
2004-06-29 04:39:54 +08:00
|
|
|
|
|
|
|
g_return_if_fail (selection != NULL);
|
|
|
|
g_return_if_fail (GIMP_IS_ITEM (item));
|
|
|
|
|
2008-02-07 21:19:15 +08:00
|
|
|
str = g_strdup_printf ("%d:%d", get_pid (), gimp_item_get_ID (item));
|
2004-06-29 04:39:54 +08:00
|
|
|
|
2009-03-23 00:35:53 +08:00
|
|
|
gtk_selection_data_set (selection,
|
|
|
|
gtk_selection_data_get_target (selection),
|
2008-09-02 20:00:07 +08:00
|
|
|
8, (guchar *) str, strlen (str));
|
2004-06-29 04:39:54 +08:00
|
|
|
|
2005-07-25 21:53:00 +08:00
|
|
|
g_free (str);
|
2004-06-29 04:39:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
GimpItem *
|
|
|
|
gimp_selection_data_get_item (GtkSelectionData *selection,
|
|
|
|
Gimp *gimp)
|
|
|
|
{
|
2008-09-02 19:30:28 +08:00
|
|
|
const gchar *str;
|
2004-06-29 04:39:54 +08:00
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
|
|
|
|
g_return_val_if_fail (selection != NULL, NULL);
|
|
|
|
|
2008-09-02 19:30:28 +08:00
|
|
|
str = gimp_selection_data_get_name (selection, G_STRFUNC);
|
2005-07-25 21:53:00 +08:00
|
|
|
|
2008-09-02 19:30:28 +08:00
|
|
|
if (str)
|
2004-06-29 04:39:54 +08:00
|
|
|
{
|
2008-09-02 19:30:28 +08:00
|
|
|
gint pid;
|
|
|
|
gint ID;
|
2004-06-29 04:39:54 +08:00
|
|
|
|
2008-09-02 19:30:28 +08:00
|
|
|
if (sscanf (str, "%i:%i", &pid, &ID) == 2 &&
|
|
|
|
pid == get_pid ())
|
|
|
|
{
|
|
|
|
return gimp_item_get_by_ID (gimp, ID);
|
|
|
|
}
|
|
|
|
}
|
2004-06-29 04:39:54 +08:00
|
|
|
|
2008-09-02 19:30:28 +08:00
|
|
|
return NULL;
|
2004-06-29 04:39:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2005-07-25 21:53:00 +08:00
|
|
|
gimp_selection_data_set_object (GtkSelectionData *selection,
|
|
|
|
GimpObject *object)
|
2004-06-29 04:39:54 +08:00
|
|
|
{
|
|
|
|
const gchar *name;
|
|
|
|
|
|
|
|
g_return_if_fail (selection != NULL);
|
2005-07-25 21:53:00 +08:00
|
|
|
g_return_if_fail (GIMP_IS_OBJECT (object));
|
2004-06-29 04:39:54 +08:00
|
|
|
|
2005-07-25 21:53:00 +08:00
|
|
|
name = gimp_object_get_name (object);
|
2004-06-29 04:39:54 +08:00
|
|
|
|
|
|
|
if (name)
|
2005-03-23 19:30:52 +08:00
|
|
|
{
|
2005-07-25 21:53:00 +08:00
|
|
|
gchar *str;
|
2005-03-23 19:26:56 +08:00
|
|
|
|
2008-02-07 21:19:15 +08:00
|
|
|
str = g_strdup_printf ("%d:%p:%s", get_pid (), object, name);
|
2008-09-02 20:00:07 +08:00
|
|
|
|
2009-03-23 00:35:53 +08:00
|
|
|
gtk_selection_data_set (selection,
|
|
|
|
gtk_selection_data_get_target (selection),
|
2008-09-02 20:00:07 +08:00
|
|
|
8, (guchar *) str, strlen (str));
|
|
|
|
|
2005-07-25 21:53:00 +08:00
|
|
|
g_free (str);
|
|
|
|
}
|
2005-03-23 19:26:56 +08:00
|
|
|
}
|
|
|
|
|
2004-06-29 04:39:54 +08:00
|
|
|
GimpBrush *
|
|
|
|
gimp_selection_data_get_brush (GtkSelectionData *selection,
|
|
|
|
Gimp *gimp)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
|
|
|
|
g_return_val_if_fail (selection != NULL, NULL);
|
|
|
|
|
2005-07-25 21:53:00 +08:00
|
|
|
return (GimpBrush *)
|
|
|
|
gimp_selection_data_get_object (selection,
|
2008-12-20 05:58:17 +08:00
|
|
|
gimp_data_factory_get_container (gimp->brush_factory),
|
2010-04-05 19:24:54 +08:00
|
|
|
GIMP_OBJECT (gimp_brush_get_standard (gimp_get_user_context (gimp))));
|
2004-06-29 04:39:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
GimpPattern *
|
|
|
|
gimp_selection_data_get_pattern (GtkSelectionData *selection,
|
|
|
|
Gimp *gimp)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
|
|
|
|
g_return_val_if_fail (selection != NULL, NULL);
|
|
|
|
|
2005-07-25 21:53:00 +08:00
|
|
|
return (GimpPattern *)
|
|
|
|
gimp_selection_data_get_object (selection,
|
2008-12-20 05:58:17 +08:00
|
|
|
gimp_data_factory_get_container (gimp->pattern_factory),
|
2010-04-05 19:24:54 +08:00
|
|
|
GIMP_OBJECT (gimp_pattern_get_standard (gimp_get_user_context (gimp))));
|
2004-06-29 04:39:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
GimpGradient *
|
|
|
|
gimp_selection_data_get_gradient (GtkSelectionData *selection,
|
|
|
|
Gimp *gimp)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
|
|
|
|
g_return_val_if_fail (selection != NULL, NULL);
|
|
|
|
|
2005-07-25 21:53:00 +08:00
|
|
|
return (GimpGradient *)
|
|
|
|
gimp_selection_data_get_object (selection,
|
2008-12-20 05:58:17 +08:00
|
|
|
gimp_data_factory_get_container (gimp->gradient_factory),
|
2010-04-05 19:24:54 +08:00
|
|
|
GIMP_OBJECT (gimp_gradient_get_standard (gimp_get_user_context (gimp))));
|
2004-06-29 04:39:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
GimpPalette *
|
|
|
|
gimp_selection_data_get_palette (GtkSelectionData *selection,
|
|
|
|
Gimp *gimp)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
|
|
|
|
g_return_val_if_fail (selection != NULL, NULL);
|
|
|
|
|
2005-07-25 21:53:00 +08:00
|
|
|
return (GimpPalette *)
|
|
|
|
gimp_selection_data_get_object (selection,
|
2008-12-20 05:58:17 +08:00
|
|
|
gimp_data_factory_get_container (gimp->palette_factory),
|
2010-04-05 19:24:54 +08:00
|
|
|
GIMP_OBJECT (gimp_palette_get_standard (gimp_get_user_context (gimp))));
|
2004-06-29 04:39:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
GimpFont *
|
|
|
|
gimp_selection_data_get_font (GtkSelectionData *selection,
|
|
|
|
Gimp *gimp)
|
|
|
|
{
|
2005-07-25 21:53:00 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
|
|
|
|
g_return_val_if_fail (selection != NULL, NULL);
|
2004-06-29 04:39:54 +08:00
|
|
|
|
2005-07-25 21:53:00 +08:00
|
|
|
return (GimpFont *)
|
|
|
|
gimp_selection_data_get_object (selection,
|
|
|
|
gimp->fonts,
|
|
|
|
GIMP_OBJECT (gimp_font_get_standard ()));
|
|
|
|
}
|
|
|
|
|
|
|
|
GimpBuffer *
|
|
|
|
gimp_selection_data_get_buffer (GtkSelectionData *selection,
|
|
|
|
Gimp *gimp)
|
|
|
|
{
|
2004-06-29 04:39:54 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
|
|
|
|
g_return_val_if_fail (selection != NULL, NULL);
|
|
|
|
|
2005-07-25 21:53:00 +08:00
|
|
|
return (GimpBuffer *)
|
|
|
|
gimp_selection_data_get_object (selection,
|
|
|
|
gimp->named_buffers,
|
|
|
|
GIMP_OBJECT (gimp->global_buffer));
|
|
|
|
}
|
2004-06-29 04:39:54 +08:00
|
|
|
|
2005-07-25 21:53:00 +08:00
|
|
|
GimpImagefile *
|
|
|
|
gimp_selection_data_get_imagefile (GtkSelectionData *selection,
|
|
|
|
Gimp *gimp)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
|
|
|
|
g_return_val_if_fail (selection != NULL, NULL);
|
2004-06-29 04:39:54 +08:00
|
|
|
|
2005-07-25 21:53:00 +08:00
|
|
|
return (GimpImagefile *) gimp_selection_data_get_object (selection,
|
|
|
|
gimp->documents,
|
|
|
|
NULL);
|
|
|
|
}
|
2004-06-29 04:39:54 +08:00
|
|
|
|
2005-07-25 21:53:00 +08:00
|
|
|
GimpTemplate *
|
|
|
|
gimp_selection_data_get_template (GtkSelectionData *selection,
|
|
|
|
Gimp *gimp)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
|
|
|
|
g_return_val_if_fail (selection != NULL, NULL);
|
2005-03-23 19:26:56 +08:00
|
|
|
|
2005-07-25 21:53:00 +08:00
|
|
|
return (GimpTemplate *) gimp_selection_data_get_object (selection,
|
|
|
|
gimp->templates,
|
|
|
|
NULL);
|
2004-06-29 04:39:54 +08:00
|
|
|
}
|
|
|
|
|
2005-07-25 21:53:00 +08:00
|
|
|
GimpToolInfo *
|
|
|
|
gimp_selection_data_get_tool_info (GtkSelectionData *selection,
|
|
|
|
Gimp *gimp)
|
2004-06-29 04:39:54 +08:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
|
|
|
|
g_return_val_if_fail (selection != NULL, NULL);
|
|
|
|
|
2006-05-04 03:03:44 +08:00
|
|
|
return (GimpToolInfo *)
|
|
|
|
gimp_selection_data_get_object (selection,
|
|
|
|
gimp->tool_info_list,
|
|
|
|
GIMP_OBJECT (gimp_tool_info_get_standard (gimp)));
|
2004-06-29 04:39:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-07-25 21:53:00 +08:00
|
|
|
/* private functions */
|
|
|
|
|
2008-09-02 19:30:28 +08:00
|
|
|
static const gchar *
|
|
|
|
gimp_selection_data_get_name (GtkSelectionData *selection,
|
|
|
|
const gchar *strfunc)
|
2005-07-25 21:53:00 +08:00
|
|
|
{
|
2008-09-02 19:30:28 +08:00
|
|
|
const gchar *name;
|
2004-06-29 04:39:54 +08:00
|
|
|
|
2009-03-23 00:35:53 +08:00
|
|
|
if (gtk_selection_data_get_format (selection) != 8 ||
|
|
|
|
gtk_selection_data_get_length (selection) < 1)
|
2004-06-29 04:39:54 +08:00
|
|
|
{
|
2008-09-02 19:30:28 +08:00
|
|
|
g_warning ("%s: received invalid selection data", strfunc);
|
2004-06-29 04:39:54 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2009-03-23 00:35:53 +08:00
|
|
|
name = (const gchar *) gtk_selection_data_get_data (selection);
|
2004-06-29 04:39:54 +08:00
|
|
|
|
2005-07-25 21:53:00 +08:00
|
|
|
if (! g_utf8_validate (name, -1, NULL))
|
|
|
|
{
|
2008-09-02 19:30:28 +08:00
|
|
|
g_warning ("%s: received invalid selection data "
|
|
|
|
"(doesn't validate as UTF-8)", strfunc);
|
2005-07-25 21:53:00 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
2004-06-29 04:39:54 +08:00
|
|
|
|
2007-11-15 21:54:15 +08:00
|
|
|
GIMP_LOG (DND, "name = '%s'", name);
|
2005-03-23 19:26:56 +08:00
|
|
|
|
2005-07-25 21:53:00 +08:00
|
|
|
return name;
|
2004-06-29 04:39:54 +08:00
|
|
|
}
|
|
|
|
|
2005-07-25 21:53:00 +08:00
|
|
|
static GimpObject *
|
|
|
|
gimp_selection_data_get_object (GtkSelectionData *selection,
|
|
|
|
GimpContainer *container,
|
|
|
|
GimpObject *additional)
|
2004-06-29 04:39:54 +08:00
|
|
|
{
|
2008-09-02 19:30:28 +08:00
|
|
|
const gchar *str;
|
2004-06-29 04:39:54 +08:00
|
|
|
|
2008-09-02 19:30:28 +08:00
|
|
|
str = gimp_selection_data_get_name (selection, G_STRFUNC);
|
2005-07-25 21:53:00 +08:00
|
|
|
|
2008-09-02 19:30:28 +08:00
|
|
|
if (str)
|
|
|
|
{
|
|
|
|
gint pid;
|
|
|
|
gpointer object_addr;
|
|
|
|
gint name_offset = 0;
|
2005-07-25 21:53:00 +08:00
|
|
|
|
2008-09-02 19:30:28 +08:00
|
|
|
if (sscanf (str, "%i:%p:%n", &pid, &object_addr, &name_offset) >= 2 &&
|
|
|
|
pid == get_pid () && name_offset > 0)
|
2005-07-25 21:53:00 +08:00
|
|
|
{
|
2008-09-02 19:30:28 +08:00
|
|
|
const gchar *name = str + name_offset;
|
|
|
|
|
|
|
|
GIMP_LOG (DND, "pid = %d, addr = %p, name = '%s'",
|
|
|
|
pid, object_addr, name);
|
2005-07-25 21:53:00 +08:00
|
|
|
|
2008-09-02 19:30:28 +08:00
|
|
|
if (additional &&
|
|
|
|
strcmp (name, gimp_object_get_name (additional)) == 0 &&
|
|
|
|
object_addr == (gpointer) additional)
|
|
|
|
{
|
|
|
|
return additional;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GimpObject *object;
|
|
|
|
|
|
|
|
object = gimp_container_get_child_by_name (container, name);
|
|
|
|
|
|
|
|
if (object_addr == (gpointer) object)
|
|
|
|
return object;
|
|
|
|
}
|
2005-07-25 21:53:00 +08:00
|
|
|
}
|
2004-06-29 04:39:54 +08:00
|
|
|
}
|
|
|
|
|
2008-09-02 19:30:28 +08:00
|
|
|
return NULL;
|
2005-07-25 21:53:00 +08:00
|
|
|
}
|
2004-06-29 04:39:54 +08:00
|
|
|
|
2005-07-25 21:53:00 +08:00
|
|
|
/* the next two functions are straight cut'n'paste from glib/glib/gconvert.c,
|
|
|
|
* except that gimp_unescape_uri_string() does not try to UTF-8 validate
|
|
|
|
* the unescaped result.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
unescape_character (const char *scanner)
|
|
|
|
{
|
|
|
|
int first_digit;
|
|
|
|
int second_digit;
|
2005-03-23 19:26:56 +08:00
|
|
|
|
2005-07-25 21:53:00 +08:00
|
|
|
first_digit = g_ascii_xdigit_value (scanner[0]);
|
|
|
|
if (first_digit < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
second_digit = g_ascii_xdigit_value (scanner[1]);
|
|
|
|
if (second_digit < 0)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return (first_digit << 4) | second_digit;
|
2004-06-29 04:39:54 +08:00
|
|
|
}
|
|
|
|
|
2005-07-25 21:53:00 +08:00
|
|
|
static gchar *
|
|
|
|
gimp_unescape_uri_string (const char *escaped,
|
|
|
|
int len,
|
|
|
|
const char *illegal_escaped_characters,
|
|
|
|
gboolean ascii_must_not_be_escaped)
|
2004-06-29 04:39:54 +08:00
|
|
|
{
|
2005-07-25 21:53:00 +08:00
|
|
|
const gchar *in, *in_end;
|
|
|
|
gchar *out, *result;
|
|
|
|
int c;
|
2004-06-29 04:39:54 +08:00
|
|
|
|
2005-07-25 21:53:00 +08:00
|
|
|
if (escaped == NULL)
|
|
|
|
return NULL;
|
2004-06-29 04:39:54 +08:00
|
|
|
|
2005-07-25 21:53:00 +08:00
|
|
|
if (len < 0)
|
|
|
|
len = strlen (escaped);
|
|
|
|
|
|
|
|
result = g_malloc (len + 1);
|
|
|
|
|
|
|
|
out = result;
|
|
|
|
for (in = escaped, in_end = escaped + len; in < in_end; in++)
|
2004-06-29 04:39:54 +08:00
|
|
|
{
|
2005-07-25 21:53:00 +08:00
|
|
|
c = *in;
|
2004-06-29 04:39:54 +08:00
|
|
|
|
2005-07-25 21:53:00 +08:00
|
|
|
if (c == '%')
|
|
|
|
{
|
|
|
|
/* catch partial escape sequences past the end of the substring */
|
|
|
|
if (in + 3 > in_end)
|
|
|
|
break;
|
2004-06-29 04:39:54 +08:00
|
|
|
|
2005-07-25 21:53:00 +08:00
|
|
|
c = unescape_character (in + 1);
|
2004-06-29 04:39:54 +08:00
|
|
|
|
2005-07-25 21:53:00 +08:00
|
|
|
/* catch bad escape sequences and NUL characters */
|
|
|
|
if (c <= 0)
|
|
|
|
break;
|
2005-03-23 19:26:56 +08:00
|
|
|
|
2005-07-25 21:53:00 +08:00
|
|
|
/* catch escaped ASCII */
|
|
|
|
if (ascii_must_not_be_escaped && c <= 0x7F)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* catch other illegal escaped characters */
|
|
|
|
if (strchr (illegal_escaped_characters, c) != NULL)
|
|
|
|
break;
|
|
|
|
|
|
|
|
in += 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
*out++ = c;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_assert (out - result <= len);
|
|
|
|
*out = '\0';
|
|
|
|
|
|
|
|
if (in != in_end)
|
|
|
|
{
|
|
|
|
g_free (result);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
2004-06-29 04:39:54 +08:00
|
|
|
}
|