libegg r851 - in trunk: . libegg/toolpalette
- From: hasselmm svn gnome org
- To: svn-commits-list gnome org
- Subject: libegg r851 - in trunk: . libegg/toolpalette
- Date: Wed, 23 Jan 2008 12:05:16 +0000 (GMT)
Author: hasselmm
Date: Wed Jan 23 12:05:15 2008
New Revision: 851
URL: http://svn.gnome.org/viewvc/libegg?rev=851&view=rev
Log:
Implement functions for reordering and finding items.
* libegg/toolpalette/eggtoolitemgroup.c:
Implement egg_tool_item_group_set_item_position()
and egg_tool_item_group_get_drop_item().
* libegg/toolpalette/eggtoolpalette.c:
Implement egg_tool_palette_get_drop_item()
and egg_tool_palette_get_drop_group().
* libegg/toolpalette/eggtoolpalette.h:
Add egg_tool_palette_get_drop_group().
* libegg/toolpalette/testtoolpalette.c:
Allow reordering of tool items by drag-and-drop.
Modified:
trunk/ChangeLog
trunk/libegg/toolpalette/eggtoolitemgroup.c
trunk/libegg/toolpalette/eggtoolpalette.c
trunk/libegg/toolpalette/eggtoolpalette.h
trunk/libegg/toolpalette/testtoolpalette.c
Modified: trunk/libegg/toolpalette/eggtoolitemgroup.c
==============================================================================
--- trunk/libegg/toolpalette/eggtoolitemgroup.c (original)
+++ trunk/libegg/toolpalette/eggtoolitemgroup.c Wed Jan 23 12:05:15 2008
@@ -866,11 +866,43 @@
GtkToolItem *item,
guint position)
{
+ gint old_position;
+ gpointer src, dst;
+ gsize len;
+
g_return_if_fail (EGG_IS_TOOL_ITEM_GROUP (group));
g_return_if_fail (GTK_IS_TOOL_ITEM (item));
- g_return_if_fail (position < egg_tool_item_group_get_n_items (group));
- g_return_if_reached ();
+ egg_tool_item_group_repack (group);
+
+ g_return_if_fail (position < group->priv->items_length);
+
+ if (item == group->priv->items[position])
+ return;
+
+ old_position = egg_tool_item_group_get_item_position (group, item);
+
+ g_return_if_fail (old_position >= 0);
+
+g_print ("%s: old=%d, new=%d\n", G_STRFUNC, old_position, position);
+
+ if (position < (guint) old_position)
+ {
+ dst = group->priv->items + position + 1;
+ src = group->priv->items + position;
+ len = old_position - position;
+ }
+ else
+ {
+ dst = group->priv->items + old_position;
+ src = group->priv->items + old_position + 1;
+ len = position - old_position;
+ }
+
+ memmove (dst, src, len * sizeof (*group->priv->items));
+ group->priv->items[position] = item;
+
+ gtk_widget_queue_resize (GTK_WIDGET (group));
}
gint
@@ -918,15 +950,36 @@
gint y)
{
GtkAllocation *allocation;
+ GtkOrientation orientation;
+ guint i;
g_return_val_if_fail (EGG_IS_TOOL_ITEM_GROUP (group), NULL);
allocation = >K_WIDGET (group)->allocation;
+ orientation = egg_tool_item_group_get_orientation (GTK_TOOL_SHELL (group));
g_return_val_if_fail (x >= 0 && x < allocation->width, NULL);
- g_return_val_if_fail (y >= 0 && y < allocation->width, NULL);
+ g_return_val_if_fail (y >= 0 && y < allocation->height, NULL);
+
+ for (i = 0; i < group->priv->items_length; ++i)
+ {
+ GtkToolItem *item = group->priv->items[i];
+ gint x0, y0;
+
+ if (!item || !egg_tool_item_group_is_item_visible (item, orientation))
+ continue;
+
+ allocation = >K_WIDGET (item)->allocation;
+
+ x0 = x - allocation->x;
+ y0 = y - allocation->y;
+
+ if (x0 >= 0 && x0 < allocation->width &&
+ y0 >= 0 && y0 < allocation->height)
+ return item;
+ }
- g_return_val_if_reached (NULL);
+ return NULL;
}
void
Modified: trunk/libegg/toolpalette/eggtoolpalette.c
==============================================================================
--- trunk/libegg/toolpalette/eggtoolpalette.c (original)
+++ trunk/libegg/toolpalette/eggtoolpalette.c Wed Jan 23 12:05:15 2008
@@ -229,6 +229,7 @@
if (palette->priv->groups)
{
+ palette->priv->groups_length = 0;
g_free (palette->priv->groups);
palette->priv->groups = NULL;
}
@@ -451,17 +452,16 @@
{
guint si, di;
- if (palette->priv->sparse_groups)
- for (si = di = 0; di < palette->priv->groups_length; ++si)
- {
- if (palette->priv->groups[si])
- {
- palette->priv->groups[di] = palette->priv->groups[si];
- ++di;
- }
- else
- --palette->priv->groups_length;
- }
+ for (si = di = 0; di < palette->priv->groups_length; ++si)
+ {
+ if (palette->priv->groups[si])
+ {
+ palette->priv->groups[di] = palette->priv->groups[si];
+ ++di;
+ }
+ else
+ --palette->priv->groups_length;
+ }
palette->priv->sparse_groups = FALSE;
}
@@ -676,20 +676,54 @@
}
GtkToolItem*
-egg_tool_palette_get_drop_item (EggToolPalette *palette,
- gint x,
- gint y)
+egg_tool_palette_get_drop_item (EggToolPalette *palette,
+ gint x,
+ gint y)
+{
+ GtkWidget *group = egg_tool_palette_get_drop_group (palette, x, y);
+
+ if (group)
+ return egg_tool_item_group_get_drop_item (EGG_TOOL_ITEM_GROUP (group),
+ x - group->allocation.x,
+ y - group->allocation.y);
+
+ return NULL;
+}
+
+GtkWidget*
+egg_tool_palette_get_drop_group (EggToolPalette *palette,
+ gint x,
+ gint y)
{
GtkAllocation *allocation;
+ guint i;
g_return_val_if_fail (EGG_IS_TOOL_PALETTE (palette), NULL);
allocation = >K_WIDGET (palette)->allocation;
g_return_val_if_fail (x >= 0 && x < allocation->width, NULL);
- g_return_val_if_fail (y >= 0 && y < allocation->width, NULL);
+ g_return_val_if_fail (y >= 0 && y < allocation->height, NULL);
+
+ for (i = 0; i < palette->priv->groups_length; ++i)
+ {
+ EggToolItemGroup *group = palette->priv->groups[i];
+ gint x0, y0;
+
+ if (!group)
+ continue;
+
+ allocation = >K_WIDGET (group)->allocation;
+
+ x0 = x - allocation->x;
+ y0 = y - allocation->y;
+
+ if (x0 >= 0 && x0 < allocation->width &&
+ y0 >= 0 && y0 < allocation->height)
+ return GTK_WIDGET (group);
+ }
- g_return_val_if_reached (NULL);
+ return NULL;
}
GtkToolItem*
@@ -725,9 +759,16 @@
palette->priv->drag_source = TRUE;
for (i = 0; i < palette->priv->groups_length; ++i)
- gtk_container_foreach (GTK_CONTAINER (palette->priv->groups[i]),
- _egg_tool_palette_item_set_drag_source,
- palette);
+ {
+ EggToolItemGroup *group = palette->priv->groups[i];
+
+ if (!group)
+ continue;
+
+ gtk_container_foreach (GTK_CONTAINER (group),
+ _egg_tool_palette_item_set_drag_source,
+ palette);
+ }
}
void
Modified: trunk/libegg/toolpalette/eggtoolpalette.h
==============================================================================
--- trunk/libegg/toolpalette/eggtoolpalette.h (original)
+++ trunk/libegg/toolpalette/eggtoolpalette.h Wed Jan 23 12:05:15 2008
@@ -75,6 +75,9 @@
GtkToolItem* egg_tool_palette_get_drop_item (EggToolPalette *palette,
gint x,
gint y);
+GtkWidget* egg_tool_palette_get_drop_group (EggToolPalette *palette,
+ gint x,
+ gint y);
GtkToolItem* egg_tool_palette_get_drag_item (EggToolPalette *palette,
GtkSelectionData *selection);
Modified: trunk/libegg/toolpalette/testtoolpalette.c
==============================================================================
--- trunk/libegg/toolpalette/testtoolpalette.c (original)
+++ trunk/libegg/toolpalette/testtoolpalette.c Wed Jan 23 12:05:15 2008
@@ -97,6 +97,58 @@
return TRUE;
}
+/*****************************/
+/* ====== Palette DnD ====== */
+/*****************************/
+
+static void
+palette_drag_data_received (GtkWidget *widget,
+ GdkDragContext *context,
+ gint x,
+ gint y,
+ GtkSelectionData *selection,
+ guint info G_GNUC_UNUSED,
+ guint time G_GNUC_UNUSED,
+ gpointer data G_GNUC_UNUSED)
+{
+ GtkWidget *drag_palette = gtk_drag_get_source_widget (context);
+ GtkWidget *drag_group = NULL, *drop_group = NULL;
+ GtkToolItem *drag_item = NULL, *drop_item = NULL;
+ gint drop_position = -1;
+
+ while (drag_palette && !EGG_IS_TOOL_PALETTE (drag_palette))
+ drag_palette = gtk_widget_get_parent (drag_palette);
+
+ if (drag_palette)
+ drag_item = egg_tool_palette_get_drag_item (EGG_TOOL_PALETTE (drag_palette), selection);
+ if (drag_item)
+ drop_group = egg_tool_palette_get_drop_group (EGG_TOOL_PALETTE (widget), x, y);
+
+ if (drop_group)
+ {
+ drop_item = egg_tool_item_group_get_drop_item (EGG_TOOL_ITEM_GROUP (drop_group),
+ x - drop_group->allocation.x,
+ y - drop_group->allocation.y);
+
+ if (drop_item)
+ drop_position = egg_tool_item_group_get_item_position (EGG_TOOL_ITEM_GROUP (drop_group), drop_item);
+
+ drag_group = gtk_widget_get_parent (GTK_WIDGET (drag_item));
+
+ if (drag_group != drop_group)
+ {
+ g_object_ref (drag_item);
+ gtk_container_remove (GTK_CONTAINER (drag_group), GTK_WIDGET (drag_item));
+ egg_tool_item_group_insert (EGG_TOOL_ITEM_GROUP (drop_group),
+ drag_item, drop_position);
+ g_object_unref (drag_item);
+ }
+ else
+ egg_tool_item_group_set_item_position (EGG_TOOL_ITEM_GROUP (drop_group),
+ drag_item, drop_position);
+ }
+}
+
/********************************/
/* ====== Passive Canvas ====== */
/********************************/
@@ -503,6 +555,14 @@
notebook = gtk_notebook_new ();
gtk_container_set_border_width (GTK_CONTAINER (notebook), 6);
+ /* ===== DnD for tool items ===== */
+
+ g_signal_connect (palette, "drag-data-received",
+ G_CALLBACK (palette_drag_data_received),
+ NULL);
+ egg_tool_palette_add_drag_dest (EGG_TOOL_PALETTE (palette),
+ palette, GTK_DEST_DEFAULT_ALL);
+
/* ===== passive DnD dest ===== */
contents = gtk_drawing_area_new ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]