[gtk+] icon browser: Set up dnd from the detail popup
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] icon browser: Set up dnd from the detail popup
- Date: Sun, 22 Feb 2015 19:44:53 +0000 (UTC)
commit 1ffcdfcc327bc3a17efdc426dc04059484b788b4
Author: Matthias Clasen <mclasen redhat com>
Date: Sun Feb 22 14:42:26 2015 -0500
icon browser: Set up dnd from the detail popup
Allow dragging the various icon sizes as images.
demos/icon-browser/iconbrowserwin.c | 62 ++++++++++++++++++++++++++++-
demos/icon-browser/window.ui | 75 +++++++++++++++++++++++------------
2 files changed, 111 insertions(+), 26 deletions(-)
---
diff --git a/demos/icon-browser/iconbrowserwin.c b/demos/icon-browser/iconbrowserwin.c
index fdf51e9..ec3a804 100644
--- a/demos/icon-browser/iconbrowserwin.c
+++ b/demos/icon-browser/iconbrowserwin.c
@@ -58,11 +58,31 @@ search_text_changed (GtkEntry *entry, IconBrowserWindow *win)
gtk_tree_model_filter_refilter (win->filter_model);
}
+static GdkPixbuf *
+get_icon (GtkWidget *image, const gchar *name, gint size)
+{
+ GtkIconInfo *info;
+ GtkStyleContext *context;
+ GdkPixbuf *pixbuf;
+
+ context = gtk_widget_get_style_context (image);
+ info = gtk_icon_theme_lookup_icon (gtk_icon_theme_get_default (), name, size, 0);
+ pixbuf = gtk_icon_info_load_symbolic_for_context (info, context, NULL, NULL);
+ g_object_unref (info);
+
+ return pixbuf;
+}
+
static void
set_image (GtkWidget *image, const gchar *name, gint size)
{
+ GdkPixbuf *pixbuf;
+
gtk_image_set_from_icon_name (GTK_IMAGE (image), name, 1);
gtk_image_set_pixel_size (GTK_IMAGE (image), size);
+ pixbuf = get_icon (image, name, size);
+ gtk_drag_source_set_icon_pixbuf (gtk_widget_get_parent (image), pixbuf);
+ g_object_unref (pixbuf);
}
static void
@@ -83,7 +103,7 @@ item_activated (GtkIconView *icon_view, GtkTreePath *path, IconBrowserWindow *wi
column, &name,
ICON_STORE_DESCRIPTION_COLUMN, &description,
-1);
-
+
if (name == NULL || !gtk_icon_theme_has_icon (gtk_icon_theme_get_default (), name))
{
g_free (description);
@@ -741,6 +761,40 @@ search_mode_toggled (GObject *searchbar, GParamSpec *pspec, IconBrowserWindow *w
}
static void
+get_image_data (GtkWidget *widget,
+ GdkDragContext *context,
+ GtkSelectionData *selection,
+ guint target_info,
+ guint time,
+ gpointer data)
+{
+ GtkWidget *image;
+ const gchar *name;
+ gint size;
+ GdkPixbuf *pixbuf;
+
+ image = gtk_bin_get_child (GTK_BIN (widget));
+
+ gtk_image_get_icon_name (GTK_IMAGE (image), &name, NULL);
+ size = gtk_image_get_pixel_size (GTK_IMAGE (image));
+
+ pixbuf = get_icon (image, name, size);
+ gtk_selection_data_set_pixbuf (selection, pixbuf);
+ g_object_unref (pixbuf);
+}
+
+static void
+setup_image_dnd (GtkWidget *image)
+{
+ GtkWidget *parent;
+
+ parent = gtk_widget_get_parent (image);
+ gtk_drag_source_set (parent, GDK_BUTTON1_MASK, NULL, 0, GDK_ACTION_COPY);
+ gtk_drag_source_add_image_targets (parent);
+ g_signal_connect (parent, "drag-data-get", G_CALLBACK (get_image_data), NULL);
+}
+
+static void
icon_browser_window_init (IconBrowserWindow *win)
{
GtkTargetList *list;
@@ -761,6 +815,12 @@ icon_browser_window_init (IconBrowserWindow *win)
gtk_target_table_free (targets, n_targets);
+ setup_image_dnd (win->image1);
+ setup_image_dnd (win->image2);
+ setup_image_dnd (win->image3);
+ setup_image_dnd (win->image4);
+ setup_image_dnd (win->image5);
+
win->contexts = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_free);
gtk_tree_model_filter_set_visible_func (win->filter_model, icon_visible_func, win, NULL);
diff --git a/demos/icon-browser/window.ui b/demos/icon-browser/window.ui
index e91d16b..54982c8 100644
--- a/demos/icon-browser/window.ui
+++ b/demos/icon-browser/window.ui
@@ -151,12 +151,17 @@
<property name="row-spacing">10</property>
<property name="column-spacing">10</property>
<child>
- <object class="GtkImage" id="image1">
+ <object class="GtkEventBox">
<property name="visible">True</property>
- <property name="xpad">4</property>
- <property name="ypad">4</property>
- <property name="halign">center</property>
- <property name="valign">end</property>
+ <child>
+ <object class="GtkImage" id="image1">
+ <property name="visible">True</property>
+ <property name="xpad">4</property>
+ <property name="ypad">4</property>
+ <property name="halign">center</property>
+ <property name="valign">end</property>
+ </object>
+ </child>
</object>
<packing>
<property name="left-attach">0</property>
@@ -164,12 +169,17 @@
</packing>
</child>
<child>
- <object class="GtkImage" id="image2">
+ <object class="GtkEventBox">
<property name="visible">True</property>
- <property name="xpad">4</property>
- <property name="ypad">4</property>
- <property name="halign">center</property>
- <property name="valign">end</property>
+ <child>
+ <object class="GtkImage" id="image2">
+ <property name="visible">True</property>
+ <property name="xpad">4</property>
+ <property name="ypad">4</property>
+ <property name="halign">center</property>
+ <property name="valign">end</property>
+ </object>
+ </child>
</object>
<packing>
<property name="left-attach">1</property>
@@ -177,12 +187,17 @@
</packing>
</child>
<child>
- <object class="GtkImage" id="image3">
+ <object class="GtkEventBox">
<property name="visible">True</property>
- <property name="xpad">4</property>
- <property name="ypad">4</property>
- <property name="halign">center</property>
- <property name="valign">end</property>
+ <child>
+ <object class="GtkImage" id="image3">
+ <property name="visible">True</property>
+ <property name="xpad">4</property>
+ <property name="ypad">4</property>
+ <property name="halign">center</property>
+ <property name="valign">end</property>
+ </object>
+ </child>
</object>
<packing>
<property name="left-attach">2</property>
@@ -190,12 +205,17 @@
</packing>
</child>
<child>
- <object class="GtkImage" id="image4">
+ <object class="GtkEventBox">
<property name="visible">True</property>
- <property name="xpad">4</property>
- <property name="ypad">4</property>
- <property name="halign">center</property>
- <property name="valign">end</property>
+ <child>
+ <object class="GtkImage" id="image4">
+ <property name="visible">True</property>
+ <property name="xpad">4</property>
+ <property name="ypad">4</property>
+ <property name="halign">center</property>
+ <property name="valign">end</property>
+ </object>
+ </child>
</object>
<packing>
<property name="left-attach">3</property>
@@ -203,12 +223,17 @@
</packing>
</child>
<child>
- <object class="GtkImage" id="image5">
+ <object class="GtkEventBox">
<property name="visible">True</property>
- <property name="xpad">4</property>
- <property name="ypad">4</property>
- <property name="halign">center</property>
- <property name="valign">end</property>
+ <child>
+ <object class="GtkImage" id="image5">
+ <property name="visible">True</property>
+ <property name="xpad">4</property>
+ <property name="ypad">4</property>
+ <property name="halign">center</property>
+ <property name="valign">end</property>
+ </object>
+ </child>
</object>
<packing>
<property name="left-attach">4</property>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]