Commit ff33e68b authored by Christian Hergert's avatar Christian Hergert

gtksourceview: add GIMP style color formats

This implements an alternate format so that we can have DnD coming from
the GIMP color picker. With this patch, we can drag from the color picker
into the GtkSourceView.
parent bfdd88c8
......@@ -4322,30 +4322,52 @@ view_dnd_drop (GtkTextView *view,
if (info == TARGET_COLOR)
{
guint16 *vals;
GdkRGBA rgba;
gchar string[] = "#000000";
gint buffer_x;
gint buffer_y;
gint length = gtk_selection_data_get_length (selection_data);
guint format;
if (length < 0)
{
return;
}
if (gtk_selection_data_get_format (selection_data) != 16 || length != 8)
format = gtk_selection_data_get_format (selection_data);
if (format == 8 && length == 4)
{
g_warning ("Received invalid color data\n");
return;
guint8 *vals;
vals = (gpointer) gtk_selection_data_get_data (selection_data);
rgba.red = vals[0] / 256.0;
rgba.green = vals[1] / 256.0;
rgba.blue = vals[2] / 256.0;
rgba.alpha = 1.0;
}
else if (format == 16 && length == 8)
{
guint16 *vals;
vals = (gpointer) gtk_selection_data_get_data (selection_data);
vals = (gpointer) gtk_selection_data_get_data (selection_data);
vals[0] /= 256;
vals[1] /= 256;
vals[2] /= 256;
rgba.red = vals[0] / 65535.0;
rgba.green = vals[1] / 65535.0;
rgba.blue = vals[2] / 65535.0;
rgba.alpha = 1.0;
}
else
{
g_warning ("Received invalid color data\n");
return;
}
g_snprintf (string, sizeof (string), "#%02X%02X%02X", vals[0], vals[1], vals[2]);
g_snprintf (string, sizeof string, "#%02X%02X%02X",
(gint)(rgba.red * 256),
(gint)(rgba.green * 256),
(gint)(rgba.blue * 256));
gtk_text_view_window_to_buffer_coords (view,
GTK_TEXT_WINDOW_TEXT,
......
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