1998-12-07 Federico Mena Quintero <federico@nuclecu.unam.mx>

* gdesktop.c (drop_desktop_icons): New function to perform a drop
	from desktop icons to the desktop.  It effectively moves the icons
	around.
	(desktop_icon_info_place): Do not place the icons past the edge of
	the screen.
This commit is contained in:
Miguel de Icaza 1998-12-07 15:47:00 +00:00
parent fc5a9c57c2
commit 8942d7e613
2 changed files with 96 additions and 4 deletions

View File

@ -1,3 +1,11 @@
1998-12-07 Federico Mena Quintero <federico@nuclecu.unam.mx>
* gdesktop.c (drop_desktop_icons): New function to perform a drop
from desktop icons to the desktop. It effectively moves the icons
around.
(desktop_icon_info_place): Do not place the icons past the edge of
the screen.
1998-12-06 Federico Mena Quintero <federico@nuclecu.unam.mx> 1998-12-06 Federico Mena Quintero <federico@nuclecu.unam.mx>
* gdesktop.c (file_entry_from_file): Finished implementing * gdesktop.c (file_entry_from_file): Finished implementing

View File

@ -75,6 +75,8 @@ static char *desktop_directory;
/* Layout information: number of rows/columns for the layout slots, and the array of slots. Each /* Layout information: number of rows/columns for the layout slots, and the array of slots. Each
* slot is an integer that specifies the number of icons that belong to that slot. * slot is an integer that specifies the number of icons that belong to that slot.
*/ */
static int layout_screen_width;
static int layout_screen_height;
static int layout_cols; static int layout_cols;
static int layout_rows; static int layout_rows;
static struct layout_slot *layout_slots; static struct layout_slot *layout_slots;
@ -210,6 +212,12 @@ desktop_icon_info_place (struct desktop_icon_info *dii, int auto_pos, int xpos,
get_icon_snap_pos (&xpos, &ypos); get_icon_snap_pos (&xpos, &ypos);
} }
if (xpos > layout_screen_width)
xpos = layout_screen_width - DESKTOP_SNAP_X;
if (ypos > layout_screen_height)
ypos = layout_screen_height - DESKTOP_SNAP_Y;
/* Increase the number of icons in the corresponding slot */ /* Increase the number of icons in the corresponding slot */
remove_from_slot (dii); remove_from_slot (dii);
@ -905,8 +913,10 @@ desktop_icon_info_free (struct desktop_icon_info *dii)
static void static void
create_layout_info (void) create_layout_info (void)
{ {
layout_cols = (gdk_screen_width () + DESKTOP_SNAP_X - 1) / DESKTOP_SNAP_X; layout_screen_width = gdk_screen_width ();
layout_rows = (gdk_screen_height () + DESKTOP_SNAP_Y - 1) / DESKTOP_SNAP_Y; layout_screen_height = gdk_screen_height ();
layout_cols = (layout_screen_width + DESKTOP_SNAP_X - 1) / DESKTOP_SNAP_X;
layout_rows = (layout_screen_height + DESKTOP_SNAP_Y - 1) / DESKTOP_SNAP_Y;
layout_slots = g_new0 (struct layout_slot, layout_cols * layout_rows); layout_slots = g_new0 (struct layout_slot, layout_cols * layout_rows);
} }
@ -1030,6 +1040,80 @@ setup_xdnd_proxy (guint32 xid, GdkWindow *proxy_window)
return FALSE; return FALSE;
} }
/* Returns the desktop icon that started the drag from the specified context */
struct desktop_icon_info *
find_icon_by_drag_context (GdkDragContext *context)
{
GtkWidget *source;
int i;
GList *l;
struct desktop_icon_info *dii;
source = gtk_drag_get_source_widget (context);
if (!source)
return NULL;
source = gtk_widget_get_toplevel (source);
for (i = 0; i < (layout_cols * layout_rows); i++)
for (l = layout_slots[i].icons; l; l = l->next) {
dii = l->data;
if (dii->dicon == source)
return dii;
}
return NULL;
}
/* Performs a drop of desktop icons onto the desktop. It basically moves the icons from their
* original position to the new coordinates.
*/
static void
drop_desktop_icons (GdkDragContext *context, GtkSelectionData *data, int x, int y)
{
struct desktop_icon_info *source_dii, *dii;
int dx, dy;
int i;
GList *l;
GSList *sel_icons, *sl;
/* Find the icon that the user is dragging */
source_dii = find_icon_by_drag_context (context);
if (!source_dii) {
g_warning ("Eeeeek, could not find the icon that started the drag!");
return;
}
/* Compute the distance to move icons */
dx = x - source_dii->x;
dy = y - source_dii->y;
/* Build a list of selected icons */
sel_icons = NULL;
for (i = 0; i < (layout_cols * layout_rows); i++)
for (l = layout_slots[i].icons; l; l = l->next) {
dii = l->data;
if (dii->selected)
sel_icons = g_slist_prepend (sel_icons, l->data);
}
/* Move the icons */
for (sl = sel_icons; sl; sl = sl->next) {
dii = sl->data;
desktop_icon_info_place (dii, FALSE, dii->x + dx, dii->y + dy);
}
/* Clean up */
g_slist_free (sel_icons);
}
/* Callback used when the root window receives a drop */ /* Callback used when the root window receives a drop */
static void static void
drag_data_received (GtkWidget *widget, GdkDragContext *context, gint x, gint y, drag_data_received (GtkWidget *widget, GdkDragContext *context, gint x, gint y,
@ -1040,7 +1124,7 @@ drag_data_received (GtkWidget *widget, GdkDragContext *context, gint x, gint y,
switch (info) { switch (info) {
case TARGET_MC_DESKTOP_ICON: case TARGET_MC_DESKTOP_ICON:
printf ("Dropped desktop icons!\n"); /* FIXME */ drop_desktop_icons (context, data, x, y);
break; break;
case TARGET_URI_LIST: case TARGET_URI_LIST:
@ -1056,7 +1140,7 @@ drag_data_received (GtkWidget *widget, GdkDragContext *context, gint x, gint y,
if (retval) if (retval)
reload_desktop_icons (TRUE, x, y); reload_desktop_icons (TRUE, x, y);
return; break;
default: default:
break; break;