Re: align layout patch



On Tue, 2002-09-10 at 22:17, Dave Bordoley wrote:
> Uhh this patch does some funky things like cleaup by name on the desktop
> causes the icons to be spaced way far apart, does this in the icon view
> too for directories with few icons. I can email you a screenshot if
> needed.
I see.  This behavior is not a bug it is a design feature that removes
excess leftover space on the opposite side of primary layout direction. 
I've disable this behavior for the case where there is only one line
icons.

    
> dave
> -- 
> nautilus-list mailing list
> nautilus-list gnome org
> http://mail.gnome.org/mailman/listinfo/nautilus-list
-- 
 "There has grown in the minds of certain groups in this country the
idea that just because
a man or corporation has made a profit out of the public for a number of
years, the
government and the courts are charged with guaranteeing such profit in
the future, even in
the face of changing circumstances and contrary to public interest. This
strange doctrine
is supported by neither statue or common law. Neither corporations or
individuals have the
right to come into court and ask that the clock of history be stopped,
or turned back."

-Robert Heinlein, Life Line, 1939
? nautilus/autom4te-2.53.cache
? nautilus/components/adapter/Nautilus_ComponentAdapterFactory_std.server.in
? nautilus/components/history/Nautilus_View_history.server.in
? nautilus/components/loser/content/Nautilus_View_content-loser.server.in
? nautilus/components/loser/sidebar/Nautilus_View_sidebar-loser.server.in
? nautilus/components/music/Nautilus_View_music.server.in
? nautilus/components/notes/Nautilus_View_notes.server.in
? nautilus/components/sample/Nautilus_View_sample.server.in
? nautilus/components/text/Nautilus_View_text.server.in
? nautilus/components/throbber/Nautilus_Control_throbber.server.in
? nautilus/components/tree/Nautilus_View_tree.server.in
Index: nautilus/libnautilus-private/nautilus-icon-container.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-icon-container.c,v
retrieving revision 1.295
diff -u -b -B -p -u -r1.295 nautilus-icon-container.c
--- nautilus/libnautilus-private/nautilus-icon-container.c	9 Sep 2002 17:21:36 -0000	1.295
+++ nautilus/libnautilus-private/nautilus-icon-container.c	11 Sep 2002 10:07:29 -0000
@@ -28,6 +28,7 @@
 #include "nautilus-icon-container.h"
 
 #include "nautilus-global-preferences.h"
+#include "nautilus-file-utilities.h"
 #include "nautilus-icon-private.h"
 #include "nautilus-lib-self-check-functions.h"
 #include "nautilus-marshal.h"
@@ -159,7 +160,7 @@ static void          setup_label_gcs    
 
 static int click_policy_auto_value;
 
-static gpointer accessible_parent_class;
+gpointer accessible_parent_class;
 
 static GQuark accessible_private_data_quark = 0;
 
@@ -677,11 +678,18 @@ nautilus_icon_container_update_scroll_re
 	if (nautilus_icon_container_get_is_fixed_size (container)) {
 		pixels_per_unit = GNOME_CANVAS (container)->pixels_per_unit;
 		
+		/* Changes panel avoidance behavior for T_B_R_L
+		   layout mode.*/
+		if (container->details->layout_mode == NAUTILUS_ICON_LAYOUT_T_B_R_L) {
+			x1 = (double) container->details->right_margin;
+		} else {
+			x1 = (double) - container->details->left_margin;
+		}
+
 		/* Set the scroll region to the size of the container allocation */
 		allocation = &GTK_WIDGET (container)->allocation;			
 		eel_gnome_canvas_set_scroll_region_left_justify
-			(GNOME_CANVAS (container),
-			 (double) - container->details->left_margin,
+			(GNOME_CANVAS (container), x1,
 			 (double) - container->details->top_margin,
 			 (double) (allocation->width - 1) / pixels_per_unit
 			 - container->details->left_margin
@@ -708,6 +716,19 @@ nautilus_icon_container_update_scroll_re
 	}
 
 	if (reset_scroll_region) {
+		/* Workaround that prevents left justifications
+		   of icons in T_B_R_L layout mode in regular
+		   directories */
+		if (container->details->layout_mode == NAUTILUS_ICON_LAYOUT_T_B_R_L) {
+			pixels_per_unit = GNOME_CANVAS (container)->pixels_per_unit;
+			hadj = gtk_layout_get_hadjustment (GTK_LAYOUT (container));
+			allocation = &GTK_WIDGET (container)->allocation;
+			
+			x1 = MIN (CONTAINER_PAD_LEFT + CONTAINER_PAD_RIGHT
+				  + (allocation->width - hadj->page_size) / pixels_per_unit, x1);
+			x2 = (allocation->width - 1) / pixels_per_unit - CONTAINER_PAD_RIGHT;
+		}
+		
 		eel_gnome_canvas_set_scroll_region_left_justify
 			(GNOME_CANVAS (container),
 			 x1 - CONTAINER_PAD_LEFT,
@@ -779,7 +800,7 @@ resort (NautilusIconContainer *container
 /* Given an icon's bounds, compute the width of the space it should be
  * placed in.
  */
-static int
+static inline int
 get_icon_space_width (NautilusIconContainer *container, const ArtDRect *bounds)
 {
 	double world_width;
@@ -796,147 +817,425 @@ get_icon_space_width (NautilusIconContai
 }
 
 typedef struct {
-	double width;
+	/* {x,y} Cartesian basis */
+	double *x;
+	double *y;
+	
+	/* {u, m} IconLayout basis */
+	double u;
+	double m;
+	
+	/* 0 or 180 degrees depending on
+	   layout mode. Initial value
+	   also depends on layout mode */
+	double m_direction;
+} IconLayoutBases;
+
+typedef struct {
+	double origin;
+	double end;
+} IconLayoutBasisComponent;
+
+typedef struct {
+	IconLayoutBasisComponent *icon_u_component;
+	IconLayoutBasisComponent *icon_m_component;
 	double x_offset;
 	double y_offset;
-} IconPositions;
+} IconLayoutIconInfo;
 
-static void
-lay_down_one_line (NautilusIconContainer *container,
-		   GList *line_start,
-		   GList *line_end,
-		   double y,
-		   GArray *positions)
-{
-	GList *p;
-	NautilusIcon *icon;
-	double x;
-	IconPositions *position;
-	int i;
+typedef struct {
+	/* u is the primary vector (L_R or T_B) in which 
+	   icons are going to layed down depending on 
+	   layout mode.  m vector is orthogonal to u. */
+	GArray *u_components;
+	GHashTable *m_components;
+	unsigned int u_index;
+	unsigned int m_index;
+} IconLayoutGridCells;
 
-	/* FIXME: Should layout differently when in RTL base mode */
+typedef struct {
+	NautilusIconContainer *container;
+	IconLayoutGridCells *cells;
+	IconLayoutBases bases;
+	IconLayoutBasisComponent max_m_component;
+	double line_u_length;
+	double canvas_u_length;
+	double u_adjustment;
+} IconLayoutGrid;
 
-	/* Lay out the icons along the baseline. */
-	x = 0;
-	i = 0;
-	for (p = line_start; p != line_end; p = p->next) {
-		icon = p->data;
+static inline IconLayoutIconInfo*
+icon_layout_get_icon_info (NautilusIconContainer *container,
+			   NautilusIcon *icon,
+			   GHashTable *icons_informations)
+{
+	ArtDRect bounds;
+	ArtDRect icon_bounds;
+	IconLayoutIconInfo *info;
 
-		position = &g_array_index (positions, IconPositions, i++);
+	info = g_hash_table_lookup (icons_informations, icon);
 
-		icon_set_position
-			(icon,
-			 x + position->x_offset,
-			 y + position->y_offset);
+	if (info == NULL) {
+		/* Assume it's only one level hierarchy to avoid costly affine calculations */
+		gnome_canvas_item_get_bounds (GNOME_CANVAS_ITEM (icon->item),
+					      &bounds.x0, &bounds.y0,
+					      &bounds.x1, &bounds.y1);
+		icon_bounds = nautilus_icon_canvas_item_get_icon_rectangle (icon->item);
+
+		info = g_new0 (IconLayoutIconInfo, 1);
+		info->icon_u_component = g_new0 (IconLayoutBasisComponent, 1);
+		info->icon_m_component = g_new0 (IconLayoutBasisComponent, 1);
+		info->y_offset = icon_bounds.y0 - icon_bounds.y1;
+		info->x_offset = (icon_bounds.x0 - icon_bounds.x1) / 2;
 
-		x += position->width;
+		switch (container->details->layout_mode) 
+			{
+			case NAUTILUS_ICON_LAYOUT_L_R_T_B:
+				info->icon_u_component->origin = get_icon_space_width (container, &bounds) / 2;
+				info->icon_u_component->end = info->icon_u_component->origin;
+				info->icon_m_component->origin =  ICON_PAD_TOP + icon_bounds.y1 - bounds.y0;
+				info->icon_m_component->end = bounds.y1 - icon_bounds.y1 + ICON_PAD_BOTTOM;
+				break;
+			case NAUTILUS_ICON_LAYOUT_T_B_L_R:
+			case NAUTILUS_ICON_LAYOUT_T_B_R_L:
+				info->icon_u_component->origin =  ICON_PAD_TOP + icon_bounds.y1 - bounds.y0;
+				info->icon_u_component->end = bounds.y1 - icon_bounds.y1 + ICON_PAD_BOTTOM;
+				info->icon_m_component->origin = get_icon_space_width (container, &bounds) / 2;
+				info->icon_m_component->end = info->icon_m_component->origin;
+				break;
+			default:
+				g_assert_not_reached ();
 	}
+		g_hash_table_insert (icons_informations, icon, info);
+	}
+
+	return info;
 }
 
+static inline void
+icon_layout_grid_reset (IconLayoutGrid *grid)
+{
+	unsigned int i;
+	IconLayoutBasisComponent *cell_u_component;
+	
+	for (i = 0; i < grid->cells->u_components->len; i++) {
+		cell_u_component = &g_array_index (grid->cells->u_components, 
+						   IconLayoutBasisComponent, 
+						   i);
+		cell_u_component->origin = 0;
+		cell_u_component->end = 0;
+	}
+
+	grid->line_u_length = 0;
+	grid->max_m_component.origin = 0;
+	grid->max_m_component.end = 0;
+	grid->cells->m_index = 0;
+	grid->cells->u_index = 0;			
+}
 
 static void
-lay_down_icons_horizontal (NautilusIconContainer *container,
-			   GList *icons,
-			   double start_y)
+icon_layout_grid_init (IconLayoutGrid *grid,
+		       NautilusIconContainer *container,
+		       GList *icon_list,
+		       GHashTable *icons_informations) 
 {
-	GList *p, *line_start;
-	NautilusIcon *icon;
-	double canvas_width, line_width, space_width, y;
-	GArray *positions;
-	IconPositions *position;
-	ArtDRect bounds;
-	ArtDRect icon_bounds;
-	GnomeCanvasItem *item;
-	double max_height_above, max_height_below;
-	double height_above, height_below;
-	int i;
+	IconLayoutIconInfo *info = NULL;
+	unsigned int i;
+	GList *p;
 
-	g_assert (NAUTILUS_IS_ICON_CONTAINER (container));
+	switch (container->details->layout_mode) 
+		{
+		case NAUTILUS_ICON_LAYOUT_L_R_T_B:
+			/* u vector is parallel to x and m vector is 
+			   parallel y. */
+			grid->canvas_u_length = (double) (GTK_WIDGET (container)->allocation.width - 1)
+				/ GNOME_CANVAS (container)->pixels_per_unit
+				- container->details->left_margin
+				- container->details->right_margin;
 
-	positions = g_array_new (FALSE, FALSE, sizeof (IconPositions));
+			/* Change {u, m} basis to {x,y} basis */
+			grid->bases.x = &grid->bases.u;
+			grid->bases.y = &grid->bases.m;
 	
-	/* Lay out icons a line at a time. */
-	canvas_width = (GTK_WIDGET (container)->allocation.width
-			- container->details->left_margin
-			- container->details->right_margin)
+			grid->bases.m_direction = 1;		
+			grid->bases.m = 0;
+			
+			break;
+		case NAUTILUS_ICON_LAYOUT_T_B_L_R:
+			/* u vector is parallel to y and m vector is
+			   parallel to x. */
+			grid->canvas_u_length = (double) (GTK_WIDGET (container)->allocation.height - 1)
+				/ GNOME_CANVAS (container)->pixels_per_unit
+				- container->details->top_margin
+				- container->details->bottom_margin;
+			
+			/* Change {u, m} basis to {x,y} basis */
+			grid->bases.x = &grid->bases.m;
+			grid->bases.y = &grid->bases.u;
+			
+			grid->bases.m_direction = 1;		
+			grid->bases.m = 0;
+
+			break;
+		case NAUTILUS_ICON_LAYOUT_T_B_R_L:
+			/* u vector is parallel to y and m vector is
+			   parallel to x. */
+			grid->canvas_u_length = (double) (GTK_WIDGET (container)->allocation.height - 1)
+				/ GNOME_CANVAS (container)->pixels_per_unit
+				- container->details->top_margin
+				- container->details->bottom_margin;
+			
+			/* Change {u, m} basis to {x,y} basis */
+			grid->bases.x = &grid->bases.m;
+			grid->bases.y = &grid->bases.u;
+	
+			grid->bases.m_direction = -1;		
+			grid->bases.m = (double) (GTK_WIDGET (container)->allocation.width - 1)
 		/ GNOME_CANVAS (container)->pixels_per_unit;
-	line_width = 0;
-	line_start = icons;
-	y = start_y;
-	i = 0;
-	max_height_above = 0;
-	max_height_below = 0;
-	for (p = icons; p != NULL; p = p->next) {
-		icon = p->data;
 
-		/* Get the width of the icon. */
-		item = GNOME_CANVAS_ITEM (icon->item);
+			break;
+		default:
+			g_assert_not_reached ();
+		}
 		
-		/* Assume it's only one level hierarchy to avoid costly affine calculations */
-		gnome_canvas_item_get_bounds (item,
-					      &bounds.x0, &bounds.y0,
-					      &bounds.x1, &bounds.y1);
+	for (p = icon_list, i = 0, grid->line_u_length = 0; 
+	     p != NULL && grid->line_u_length <= grid->canvas_u_length; 
+	     p = p->next, i++) {
 		
-		space_width = get_icon_space_width (container, &bounds);
+		info = icon_layout_get_icon_info (container,
+						  p->data, 
+						  icons_informations);
 		
-		icon_bounds = nautilus_icon_canvas_item_get_icon_rectangle (icon->item);
+		grid->line_u_length += info->icon_u_component->origin 
+			+ info->icon_u_component->end;	
+	}
 
-		/* Calculate size above/below baseline */
-		height_above = icon_bounds.y1 - bounds.y0;
-		height_below = bounds.y1 - icon_bounds.y1;
+	g_array_set_size (grid->cells->u_components, i);
+	icon_layout_grid_reset (grid);
+}
 
-		/* If this icon doesn't fit, it's time to lay out the line that's queued up. */
 		
-		/* FIXME: why don't we want to guarantee a small white space to the right of
-		 * the last column just like we guarantee a small white space to the left of
-		 * the first column?
-		 */
-		if (line_start != p && line_width + space_width - ICON_PAD_RIGHT > canvas_width) {
-			/* Advance to the baseline. */
-			y += ICON_PAD_TOP + max_height_above;
+static IconLayoutGrid*
+icon_layout_grid_new () 
+{
+	IconLayoutGrid *grid;
+	
+	grid = g_new0 (IconLayoutGrid, 1);
+	grid->cells = g_new0 (IconLayoutGridCells, 1);
+			
+	grid->cells->m_components = g_hash_table_new (NULL, NULL);
+	grid->cells->u_components = g_array_new (FALSE, 
+						 FALSE,
+						 sizeof (IconLayoutBasisComponent));
+	
+	return grid;
+}
+			
+static void
+icon_layout_grid_free (IconLayoutGrid *grid) 
+{
+	g_array_free (grid->cells->u_components, TRUE);
+	g_hash_table_destroy (grid->cells->m_components);
+	g_free (grid->cells);
+	g_free (grid);
+}
 			
-			lay_down_one_line (container, line_start, p, y, positions);
+static void
+icon_layout_grid_lay_down_icons (IconLayoutGrid *grid,
+				 GList *icon_list,
+				 GHashTable *icons_informations)
+{
+	GList  *p;
+	IconLayoutIconInfo *info;
+	IconLayoutBasisComponent *cell_u_component, *cell_m_component;
+	unsigned int i, j, m_size;
+	
+	m_size = g_hash_table_size (grid->cells->m_components);
+	for (i = 0, p = icon_list; i < m_size; i++) {
+		cell_m_component = g_hash_table_lookup (grid->cells->m_components, 
+							GUINT_TO_POINTER (i));
+		grid->bases.m += grid->bases.m_direction * cell_m_component->origin;
+		
+		for (j = 0, grid->bases.u = 0; 
+		     j < grid->cells->u_components->len && p != NULL; 
+		     j++, p = p->next ) {	
+			
+			info = g_hash_table_lookup (icons_informations, p->data);
+			
+			cell_u_component = &g_array_index (grid->cells->u_components, 
+							   IconLayoutBasisComponent, 
+							   j);
+			
+			grid->bases.u += cell_u_component->origin;
+		
+			icon_set_position
+				(p->data,
+				 *grid->bases.x + info->x_offset,
+				 *grid->bases.y + info->y_offset);
+			
+			/* next cell u component */
+			grid->bases.u += cell_u_component->end + grid->u_adjustment;
+			
+			g_free(info->icon_u_component);
+			g_free(info->icon_m_component);
+			g_free(info);
+		}
+		grid->bases.m += grid->bases.m_direction * cell_m_component->end;
+		g_free (cell_m_component);
+	}
+}
 			
-			/* Advance to next line. */
-			y += max_height_below + ICON_PAD_BOTTOM;
+static inline gboolean
+icon_layout_grid_set_cell_u_component (IconLayoutGrid *grid,
+				       IconLayoutBasisComponent *icon_u_component)
+{
+	double *new, *old;
+	unsigned int i;
+		
+	/* set cell u component */
+	new = (double*) icon_u_component;
+	old = (double*) &g_array_index (grid->cells->u_components, 
+					IconLayoutBasisComponent, 
+					grid->cells->u_index);	
+	for (i = 0; i < 2; i++) {
+		if(new[i] > old[i]) {	
+			if (grid->cells->u_components->len > 1 && 
+			    grid->line_u_length + new[i] - old[i] > grid->canvas_u_length) {
+				/* new grid u line length would exceeds canvas u length */
+				
+				/* discard grid cells aligned along last grid line
+				 * parallel to m layout vector */
+				g_array_set_size (grid->cells->u_components, 
+						  grid->cells->u_components->len - 1);
 
-			line_width = 0;
-			line_start = p;
-			i = 0;
+				/* start over */
+				icon_layout_grid_reset (grid);	
 			
-			max_height_above = height_above;
-			max_height_below = height_below;
+				return FALSE;
 		} else {
-			if (height_above > max_height_above) {
-				max_height_above = height_above;
+				grid->line_u_length += new[i] - old[i];
+				old[i] = new[i];
 			}
-			if (height_below > max_height_below) {
-				max_height_below = height_below;
 			}
 		}
+	return TRUE;
+}
 		
-		g_array_set_size (positions, i + 1);
-		position = &g_array_index (positions, IconPositions, i++);
-		position->width = space_width;
-		position->x_offset = (space_width - (icon_bounds.x1 - icon_bounds.x0)) / 2;
-		position->y_offset = icon_bounds.y0 - icon_bounds.y1;
+static inline void 
+icon_layout_grid_set_cell_m_component (IconLayoutGrid *grid,
+				       IconLayoutBasisComponent *icon_m_component)
+{
+	IconLayoutBasisComponent *cell_m_component;
+	
+	/* Finds maximum cells's m size for all cells along 
+	   one u grid line */
+	if (icon_m_component->origin > grid->max_m_component.origin) {
+		grid->max_m_component.origin = icon_m_component->origin;
+	}
+	if (icon_m_component->end > grid->max_m_component.end) {
+		grid->max_m_component.end = icon_m_component->end;
+	}
+	
+	/* check for end of u line */
+	if (grid->cells->u_index == grid->cells->u_components->len - 1) {
+		/* End of u grid line */
+		if ((cell_m_component = g_hash_table_lookup (grid->cells->m_components,  
+							     GUINT_TO_POINTER (grid->cells->m_index))) == NULL) {
+			
+			cell_m_component = g_new0 (IconLayoutBasisComponent, 1);
+			g_hash_table_insert (grid->cells->m_components,  
+					     GUINT_TO_POINTER (grid->cells->m_index), 
+					     cell_m_component);				
+		}
+		
+		/* set cells' m size for cells on current 
+		   u grid line */
+		cell_m_component->origin = grid->max_m_component.origin;
+		cell_m_component->end = grid->max_m_component.end;
+		
+		/* Advance to new u grid line */
+		++grid->cells->m_index;
+		grid->cells->u_index = 0;
+		grid->max_m_component.origin = 0;
+		grid->max_m_component.end = 0;
+	} else {
+		/* next grid u cell component */
+		grid->cells->u_index++;
+	}
+}
+
+static void
+icon_layout_grid_finalize (IconLayoutGrid *grid,
+			   GHashTable *icons_informations)
+{
+	IconLayoutBasisComponent *cell_m_component;
+	
+	/* Check for possible incomplete last u grid line */
+	if (g_hash_table_size (icons_informations) % grid->cells->u_components->len) {
+		cell_m_component = g_new0 (IconLayoutBasisComponent, 1);
+		cell_m_component->origin = grid->max_m_component.origin;
+		cell_m_component->end = grid->max_m_component.end;
+		g_hash_table_insert (grid->cells->m_components,
+				     GUINT_TO_POINTER (grid->cells->m_index),
+				     cell_m_component);	
+	}
 
-		/* Add this icon. */
-		line_width += space_width;
+	if (g_hash_table_size (grid->cells->m_components) == 1) {
+		grid->u_adjustment = 0;
+	} else {		
+		grid->u_adjustment = (grid->canvas_u_length - grid->line_u_length) 
+			/ ((double) grid->cells->u_components->len);
 	}
+}
 
-	/* Lay down that last line of icons. */
-	if (line_start != NULL) {
-		/* Advance to the baseline. */
-		y += ICON_PAD_TOP + max_height_above;
+static void
+lay_down_icons_in_auto_layout (NautilusIconContainer *container,
+				GList *icon_list)
+{
+	GList *p;
+	gboolean result;
+	IconLayoutIconInfo *info;
+	IconLayoutGrid *grid;
+	GHashTable *icons_informations;
 		
-		lay_down_one_line (container, line_start, NULL, y, positions);
+	g_return_if_fail (icon_list != NULL);
+	g_assert (NAUTILUS_IS_ICON_CONTAINER (container));
 		
-		/* Advance to next line. */
-		y += max_height_below + ICON_PAD_BOTTOM;
+	icons_informations = g_hash_table_new (NULL, NULL);
+		
+	grid = icon_layout_grid_new ();
+	icon_layout_grid_init (grid, 
+			       container,
+			       icon_list, 
+			       icons_informations);
+	
+	p = icon_list;
+	while (p != NULL) {	
+		info = icon_layout_get_icon_info (container,
+						  p->data,
+						  icons_informations);
+		
+		/* set cell size parallel to u grid line */
+		result = icon_layout_grid_set_cell_u_component (grid, 
+								info->icon_u_component);
+		if (result == FALSE) {
+			/* start over */
+			p = icon_list;
+			continue;
+		}
+		
+		/* set cells m size when the end of the current 
+		   u grid line is reached */
+		icon_layout_grid_set_cell_m_component (grid, info->icon_m_component);
+		
+		/* next icon */
+		p = p->next;
 	}
+	icon_layout_grid_finalize (grid, icons_informations);	
+
+	icon_layout_grid_lay_down_icons (grid, icon_list, icons_informations);
 
-	g_array_free (positions, TRUE);
+	icon_layout_grid_free (grid);
+	g_hash_table_destroy (icons_informations);
 }
 
 /* Search for available space at location */
@@ -1072,13 +1371,13 @@ mark_icon_locations_in_grid (GList *icon
 }
 
 static void
-lay_down_icons_tblr (NautilusIconContainer *container, GList *icons)
+lay_down_icons_in_non_auto_layout (NautilusIconContainer *container, GList *icons)
 {
 	GList *p, *placed_icons, *unplaced_icons;
-	int index, total, new_length, placed;
+	int index;
 	NautilusIcon *icon;
-	int width, height, max_width, icon_width, icon_height;
-	int x, y, x1, x2, y1, y2;
+	int width, height;
+	int x, y;
 	int *grid_memory;
 	int **icon_grid;
 	int num_rows, num_columns;
@@ -1098,10 +1397,6 @@ lay_down_icons_tblr (NautilusIconContain
 	placed_icons = NULL;
 	unplaced_icons = NULL;
 	
-	total = g_list_length (container->details->icons);
-	new_length = g_list_length (icons);
-	placed = total - new_length;
-	if (placed > 0) {
 		/* Add only placed icons in list */
 		for (p = container->details->icons; p != NULL; p = p->next) {
 			icon = p->data;
@@ -1158,37 +1453,13 @@ lay_down_icons_tblr (NautilusIconContain
 		free (grid_memory);
 		g_list_free (placed_icons);
 		g_list_free (unplaced_icons);
-	} else {
-		/* There are no placed icons.  Just lay them down using our rules */		
-		x = DESKTOP_PAD_HORIZONTAL;
-		y = DESKTOP_PAD_VERTICAL;
-		max_width = 0;
-
-		for (p = icons; p != NULL; p = p->next) {
-			icon = p->data;
-			icon_get_bounding_box (icon, &x1, &y1, &x2, &y2);
-
-			icon_width = x2 - x1;
-			icon_height = y2 - y1;
-
-			/* Check and see if we need to move to a new column */
-			if (y > height - icon_height) {
-				x += max_width + DESKTOP_PAD_VERTICAL;
-				y = DESKTOP_PAD_VERTICAL;
-				max_width = 0;
-			}
-
-			icon_set_position (icon, x, y);
-
-			/* Check for increase in column width */
-			if (max_width < icon_width) {
-				max_width = icon_width;
-			}
-
-			y += icon_height + DESKTOP_PAD_VERTICAL;
-		}
-	}
+}
 
+static void
+lay_down_icons (NautilusIconContainer *container, GList *icons)
+{
+	if(!container->details->auto_layout) {
+		lay_down_icons_in_non_auto_layout (container, icons);
 	/* These modes are special. We freeze all of our positions
 	 * after we do the layout.
 	 */
@@ -1197,27 +1468,9 @@ lay_down_icons_tblr (NautilusIconContain
 	 * It should be a separate switch.
 	 */
 	nautilus_icon_container_freeze_icon_positions (container);
-}
-
-
-static void
-lay_down_icons (NautilusIconContainer *container, GList *icons, double start_y)
-{
-	switch (container->details->layout_mode)
-	{
-	case NAUTILUS_ICON_LAYOUT_L_R_T_B:
-		lay_down_icons_horizontal (container, icons, start_y);
-		break;
-		
-	case NAUTILUS_ICON_LAYOUT_T_B_L_R:
-	case NAUTILUS_ICON_LAYOUT_T_B_R_L:
-		/* FIXME bugzilla.gnome.org 42479: 
-		 * Need to handle T_B_R_L differently. */
-		lay_down_icons_tblr (container, icons);
-		break;
+	} else {
 		
-	default:
-		g_assert_not_reached ();
+		lay_down_icons_in_auto_layout (container, icons);
 	}
 }
 
@@ -1234,7 +1487,7 @@ redo_layout_internal (NautilusIconContai
 	if (container->details->auto_layout
 	    && container->details->drag_state != DRAG_STATE_STRETCH) {
 		resort (container);
-		lay_down_icons (container, container->details->icons, 0);
+		lay_down_icons (container, container->details->icons);
 	}
 
 	nautilus_icon_container_update_scroll_region (container);
@@ -1282,23 +1535,27 @@ redo_layout (NautilusIconContainer *cont
 }
 
 static void
-reload_icon_positions (NautilusIconContainer *container)
+reload_icon_positions_only_for_desktop (NautilusIconContainer *container)
 {
 	GList *p, *no_position_icons;
 	NautilusIcon *icon;
 	gboolean have_stored_position;
 	NautilusIconPosition position;
-	ArtDRect bounds;
-	double bottom;
+	char *desktop_uri;
+	char *container_uri;
+       
 
 	g_assert (!container->details->auto_layout);
 
-	resort (container);
+	g_signal_emit_by_name (container, "get_container_uri", &container_uri);
+	desktop_uri = nautilus_get_desktop_directory ();
 
 	no_position_icons = NULL;
 
+	/* Reload icon positions only if current directory
+	   is the desktop */
+	if (strcmp (desktop_uri, &container_uri[7]) == 0) {		
 	/* Place all the icons with positions. */
-	bottom = 0;
 	for (p = container->details->icons; p != NULL; p = p->next) {
 		icon = p->data;
 
@@ -1310,13 +1567,10 @@ reload_icon_positions (NautilusIconConta
 				 &have_stored_position);
 		if (have_stored_position) {
 			icon_set_position (icon, position.x, position.y);
-			bounds = eel_gnome_canvas_item_get_world_bounds
-				(GNOME_CANVAS_ITEM (icon->item));
-			if (bounds.y1 > bottom) {
-				bottom = bounds.y1;
-			}
 		} else {
 			no_position_icons = g_list_prepend (no_position_icons, icon);
+				icon->x = -1;
+				icon->y = -1;
 		}
 	}
 	no_position_icons = g_list_reverse (no_position_icons);
@@ -1320,9 +1574,12 @@ reload_icon_positions (NautilusIconConta
 		}
 	}
 	no_position_icons = g_list_reverse (no_position_icons);
-
 	/* Place all the other icons. */
-	lay_down_icons (container, no_position_icons, bottom + ICON_PAD_BOTTOM);
+		lay_down_icons_in_non_auto_layout (container, no_position_icons);	
+	}
+	
+	g_free (desktop_uri);
+	g_free (container_uri);
 	g_list_free (no_position_icons);
 }
 
@@ -2166,6 +2423,8 @@ keyboard_space (NautilusIconContainer *c
 	    (event->state & GDK_CONTROL_MASK) != 0) {
 		icon_toggle_selected (container, container->details->keyboard_focus);
 		g_signal_emit (container, signals[SELECTION_CHANGED], 0);
+	} else {
+		activate_selected_items (container);
 	}
 }
 
@@ -2410,12 +2669,6 @@ realize (GtkWidget *widget)
 
 	GTK_WIDGET_CLASS (parent_class)->realize (widget);
 
-	gtk_widget_modify_bg (widget, GTK_STATE_NORMAL,
-			      &widget->style->base[GTK_STATE_NORMAL]);
-	gdk_window_set_background
-		(GTK_LAYOUT (widget)->bin_window,
-		 &widget->style->bg[GTK_STATE_NORMAL]);
-
 	setup_label_gcs (NAUTILUS_ICON_CONTAINER (widget));
 
  	/* make us the focused widget */
@@ -3988,7 +4241,6 @@ finish_adding_new_icons (NautilusIconCon
 {
 	GList *p, *new_icons, *no_position_icons;
 	NautilusIcon *icon;
-	double bottom;
 
 	new_icons = container->details->new_icons;
 	container->details->new_icons = NULL;
@@ -4010,8 +4262,7 @@ finish_adding_new_icons (NautilusIconCon
 		g_assert (!container->details->auto_layout);
 		
 		sort_icons (container, &no_position_icons);
-		get_all_icon_bounds (container, NULL, NULL, NULL, &bottom);		
-		lay_down_icons (container, no_position_icons, bottom + ICON_PAD_BOTTOM);
+		lay_down_icons (container, no_position_icons);
 		g_list_free (no_position_icons);
 	}
 }
@@ -4696,7 +4947,7 @@ nautilus_icon_container_set_auto_layout 
 	container->details->auto_layout = auto_layout;
 
 	if (!auto_layout) {
-		reload_icon_positions (container);
+		reload_icon_positions_only_for_desktop (container);			
 		nautilus_icon_container_freeze_icon_positions (container);
 	}
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]