[PATCH] Flip "text besides icon" items in RTL environment



The attached patch is meant to flip the "text besides icons" items in an
RTL environment. I've renamed the private "canvas_rect" variable for the
sake of readability, and additionally modified the x offset for the
drawn text wrt the text_rect, which wasn't centered before.

The whole size calculation logic was completely moved out of
nautilus_icon_canvas_item_get_icon_rectangle and
nautilus_icon_canvas_item_get_text_rectangle, so that we have one point
(the "bounds" handler) to update all the cached rectangles. The bounds
cache code is a bit tricky: It first calculates the text dimension, then
the icon rect (incorporating the text dimensions), and finally the text
rect, which may be on the right, on the left or at the bottom of the
icon rectangle.

The new get_icon_rectangke and get_text_rectangle functions request a
nautilus_icon_canvas_item_update_bounds recalculation (if not
cached/valid) to ensure that the item has valid bounds.

lay_down_icons_horizontal was also adapted to line up the icons on their
text_rect.x1, although it still need some love for laying items out from
right to left.

Some sanity checking was added to the renaming code, so that we don't
end up with renaming widgets outside the screen. We may want to add
something similar for its vertical dimensions and shift the size
calculation code into an allocation handler, which ensures that the
renaming item is always visible.

One notable modification was the new pango layout size logic. We're
first setting it to the max. allowed width, then calculating the text
extents, and then shrinking it again to its demanded width. That was the
most tricky part of the patch. Without limiting the size after the
calculation to the actual text width, right-aligned (i.e. RTL text in an
RTL environment) text will end up somewhere on the icon or on the right
hand side of it.

Let's call it a vast improvement :).

-- 
Christian Neumair <chris gnome-de org>
Index: libnautilus-private/nautilus-icon-canvas-item.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-icon-canvas-item.c,v
retrieving revision 1.196
diff -u -p -r1.196 nautilus-icon-canvas-item.c
--- libnautilus-private/nautilus-icon-canvas-item.c	27 Feb 2006 12:45:41 -0000	1.196
+++ libnautilus-private/nautilus-icon-canvas-item.c	28 Feb 2006 08:07:10 -0000
@@ -82,7 +82,7 @@ struct NautilusIconCanvasItemDetails {
 	/* Size of the text at current font. */
 	int text_width;
 	int text_height;
-	
+
 	/* preview state */
 	guint is_active : 1;
 
@@ -110,7 +110,7 @@ struct NautilusIconCanvasItemDetails {
 	PangoLayout *embedded_text_layout;
 
 	/* Cached rectangle in canvas coordinates */
-	ArtIRect canvas_rect;
+	ArtIRect icon_rect;
 	ArtIRect text_rect;
 	ArtIRect emblem_rect;
 
@@ -736,10 +738,16 @@ compute_text_rectangle (const NautilusIc
 	}
 	
 	if (NAUTILUS_ICON_CONTAINER (EEL_CANVAS_ITEM (item)->canvas)->details->label_position == NAUTILUS_ICON_LABEL_POSITION_BESIDE) {
-                text_rectangle.x0 = icon_rectangle.x1;
-                text_rectangle.x1 = text_rectangle.x0 + text_width;
-                text_rectangle.y0 = (icon_rectangle.y0 + icon_rectangle.y1) / 2- (int) text_height / 2;
-                text_rectangle.y1 = text_rectangle.y0 + text_height + LABEL_OFFSET / pixels_per_unit;
+		if (gtk_widget_get_direction (GTK_WIDGET (EEL_CANVAS_ITEM (item)->canvas)) == GTK_TEXT_DIR_RTL) {
+			text_rectangle.x1 = icon_rectangle.x0;
+			text_rectangle.x0 = text_rectangle.x1 - text_width;
+		} else {
+			text_rectangle.x0 = icon_rectangle.x1;
+			text_rectangle.x1 = text_rectangle.x0 + text_width;
+		}
+
+		text_rectangle.y0 = (icon_rectangle.y0 + icon_rectangle.y1) / 2- (int) text_height / 2;
+		text_rectangle.y1 = text_rectangle.y0 + text_height + LABEL_OFFSET / pixels_per_unit;
 	} else {
                 text_rectangle.x0 = (icon_rectangle.x0 + icon_rectangle.x1) / 2 - (int) text_width / 2;
                 text_rectangle.y0 = icon_rectangle.y1;
@@ -787,15 +795,15 @@ nautilus_icon_canvas_item_update_bounds 
 	}
 	
 	/* Update canvas and text rect cache */
-	get_icon_canvas_rectangle (item, &item->details->canvas_rect);
-	item->details->text_rect = compute_text_rectangle (item, item->details->canvas_rect, TRUE);
+	get_icon_canvas_rectangle (item, &item->details->icon_rect);
+	item->details->text_rect = compute_text_rectangle (item, item->details->icon_rect, TRUE);
 	
 	/* Update emblem rect cache */
 	item->details->emblem_rect.x0 = 0;
 	item->details->emblem_rect.x1 = 0;
 	item->details->emblem_rect.y0 = 0;
 	item->details->emblem_rect.y1 = 0;
-	emblem_layout_reset (&emblem_layout, item, item->details->canvas_rect);
+	emblem_layout_reset (&emblem_layout, item, item->details->icon_rect);
 	while (emblem_layout_next (&emblem_layout, &emblem_pixbuf, &emblem_rect)) {
 		art_irect_union (&item->details->emblem_rect, &item->details->emblem_rect, &emblem_rect);
 	}
@@ -939,7 +947,6 @@ draw_or_measure_label_text (NautilusIcon
 	PangoLayout *editable_layout;
 	PangoLayout *additional_layout;
 	GdkColor *label_color;
-	int icon_width;
 	gboolean have_editable, have_additional, needs_highlight, needs_frame;
 	int max_text_width;
 	int x;
@@ -947,7 +954,6 @@ draw_or_measure_label_text (NautilusIcon
 	ArtIRect text_rect;
 	int text_back_padding_x, text_back_padding_y;
 	
-	icon_width = 0;
 	gc = NULL;
 
 	details = item->details;
@@ -986,9 +992,6 @@ draw_or_measure_label_text (NautilusIcon
 #endif
 
 	canvas_item = EEL_CANVAS_ITEM (item);
-	if (drawable != NULL) {
-		icon_width = details->pixbuf == NULL ? 0 : gdk_pixbuf_get_width (details->pixbuf);
-	}
 	
 	editable_width = 0;
 	editable_height = 0;
@@ -1003,18 +1006,28 @@ draw_or_measure_label_text (NautilusIcon
 
 	if (have_editable) {
 		editable_layout = get_label_layout (&details->editable_text_layout, item, details->editable_text);
-		
+		pango_layout_set_width (editable_layout, max_text_width * PANGO_SCALE);
+
 		pango_layout_get_pixel_size (editable_layout, 
 					     &editable_width,
 					     &editable_height);
+
+		if (container->details->label_position == NAUTILUS_ICON_LABEL_POSITION_BESIDE) {
+			pango_layout_set_width (editable_layout, editable_width * PANGO_SCALE);
+		}
 	}
 
 	if (have_additional) {
 		additional_layout = get_label_layout (&details->additional_text_layout, item, details->additional_text);
+		pango_layout_set_width (additional_layout, max_text_width * PANGO_SCALE);
 
 		pango_layout_get_pixel_size (additional_layout, 
 					     &additional_width,
 					     &additional_height);
+
+		if (container->details->label_position == NAUTILUS_ICON_LABEL_POSITION_BESIDE) {
+			pango_layout_set_width (editable_layout, additional_width * PANGO_SCALE);
+		}
 	}
 
 	details->text_width = MAX (editable_width, additional_width);
@@ -1052,7 +1065,7 @@ draw_or_measure_label_text (NautilusIcon
 	}
 
 	text_rect = compute_text_rectangle (item, icon_rect, TRUE);
-	
+
 	/* if the icon is highlighted, do some set-up */
 	if (needs_highlight && !details->is_renaming &&
 	    details->text_width > 0 && details->text_height > 0) {
@@ -1068,7 +1081,7 @@ draw_or_measure_label_text (NautilusIcon
 
 		
 	if (container->details->label_position == NAUTILUS_ICON_LABEL_POSITION_BESIDE) {
-		x = text_rect.x0 + 2;
+		x = text_rect.x0 + text_back_padding_x;
 	} else {
 		x = text_rect.x0 + ((text_rect.x1 - text_rect.x0) - max_text_width) / 2;
 	}
@@ -1550,7 +1563,7 @@ nautilus_icon_canvas_item_draw (EelCanva
 		return;
 	}
 
-	icon_rect = icon_item->details->canvas_rect;
+	icon_rect = icon_item->details->icon_rect;
 	
 	/* if the pre-lit or selection flag is set, make a pre-lit or darkened pixbuf and draw that instead */
 	temp_pixbuf = map_pixbuf (icon_item);
@@ -1607,6 +1620,7 @@ create_label_layout (NautilusIconCanvasI
 	GString *str;
 	char *zeroified_text;
 	const char *p;
+	gboolean rtl;
 
 	canvas_item = EEL_CANVAS_ITEM (item);
 
@@ -1636,9 +1650,11 @@ create_label_layout (NautilusIconCanvasI
 
 	pango_layout_set_text (layout, zeroified_text, -1);
 	pango_layout_set_width (layout, floor (nautilus_icon_canvas_item_get_max_text_width (item)) * PANGO_SCALE);
+
+	rtl = gtk_widget_get_direction (GTK_WIDGET (container)) == GTK_TEXT_DIR_RTL;
 			
 	if (container->details->label_position == NAUTILUS_ICON_LABEL_POSITION_BESIDE) {
-		pango_layout_set_alignment (layout, PANGO_ALIGN_LEFT);
+		pango_layout_set_alignment (layout, rtl ? PANGO_ALIGN_RIGHT : PANGO_ALIGN_LEFT);
 	} else {
 		pango_layout_set_alignment (layout, PANGO_ALIGN_CENTER);
 	}
@@ -1881,7 +1897,7 @@ hit_test (NautilusIconCanvasItem *icon_i
 	details = icon_item->details;
 	
 	/* Quick check to see if the rect hits the icon, text or emblems at all. */
-	if (!eel_art_irect_hits_irect (icon_item->details->canvas_rect, canvas_rect)
+	if (!eel_art_irect_hits_irect (icon_item->details->icon_rect, canvas_rect)
 	    && (!eel_art_irect_hits_irect (details->text_rect, canvas_rect))
 	    && (!eel_art_irect_hits_irect (details->emblem_rect, canvas_rect))) {
 		return FALSE;
@@ -1893,7 +1909,7 @@ hit_test (NautilusIconCanvasItem *icon_i
 	}
 	
 	/* Check for hit in the icon. */
-	if (eel_art_irect_hits_irect (icon_item->details->canvas_rect, canvas_rect)) {
+	if (eel_art_irect_hits_irect (icon_item->details->icon_rect, canvas_rect)) {
 		return TRUE;
 	}
 
@@ -1904,7 +1920,7 @@ hit_test (NautilusIconCanvasItem *icon_i
 	}
 
 	/* Check for hit in the emblem pixbufs. */
-	emblem_layout_reset (&emblem_layout, icon_item, icon_item->details->canvas_rect);
+	emblem_layout_reset (&emblem_layout, icon_item, icon_item->details->icon_rect);
 	while (emblem_layout_next (&emblem_layout, &emblem_pixbuf, &emblem_rect)) {
 		if (hit_test_pixbuf (emblem_pixbuf, emblem_rect, canvas_rect)) {
 			return TRUE;
@@ -1948,7 +1964,7 @@ nautilus_icon_canvas_item_translate (Eel
 	details->x += dx;
 	details->y += dy;
 }
-	
+
 /* Bounds handler for the icon canvas item. */
 static void
 nautilus_icon_canvas_item_bounds (EelCanvasItem *item,
@@ -1956,37 +1972,46 @@ nautilus_icon_canvas_item_bounds (EelCan
 {
 	NautilusIconCanvasItem *icon_item;
 	NautilusIconCanvasItemDetails *details;
+	NautilusIconContainer *container;
 	ArtIRect icon_rect, text_rect, total_rect, emblem_rect;
+	int icon_height, icon_width;
 	double pixels_per_unit;
 	EmblemLayout emblem_layout;
 	GdkPixbuf *emblem_pixbuf;
 
+	icon_item = NAUTILUS_ICON_CANVAS_ITEM (item);
+	details = icon_item->details;
+
 	g_assert (x1 != NULL);
 	g_assert (y1 != NULL);
 	g_assert (x2 != NULL);
 	g_assert (y2 != NULL);
-	
-	icon_item = NAUTILUS_ICON_CANVAS_ITEM (item);
-	details = icon_item->details;
 
 	if (details->bounds_cached) {
 		total_rect = details->bounds_cache;
-	} else {	
+	} else {
 		measure_label_text (icon_item);
 
 		pixels_per_unit = item->canvas->pixels_per_unit;
 
+		icon_width = details->pixbuf != NULL ? gdk_pixbuf_get_width (details->pixbuf) / pixels_per_unit : 0;
+		icon_height = details->pixbuf != NULL ? gdk_pixbuf_get_height (details->pixbuf) / pixels_per_unit : 0;
+
+		container = NAUTILUS_ICON_CONTAINER (item->canvas);
+
 		/* Compute icon rectangle. */
-		icon_rect.x0 = 0;
-		icon_rect.y0 = 0;
-		if (details->pixbuf == NULL) {
-			icon_rect.x1 = icon_rect.x0;
-			icon_rect.y1 = icon_rect.y0;
+		if (container->details->label_position == NAUTILUS_ICON_LABEL_POSITION_BESIDE &&
+		    gtk_widget_get_direction (GTK_WIDGET (container)) == GTK_TEXT_DIR_RTL) {
+			icon_rect.x1 = (NAUTILUS_ICON_CANVAS_ITEM (item)->details->text_width / pixels_per_unit) + icon_width;
+			icon_rect.x0 = icon_rect.x1 - icon_width;
 		} else {
-			icon_rect.x1 = icon_rect.x0 + gdk_pixbuf_get_width (details->pixbuf) / pixels_per_unit;
-			icon_rect.y1 = icon_rect.y0 + gdk_pixbuf_get_height (details->pixbuf) / pixels_per_unit;
+			icon_rect.x0 = 0;
+			icon_rect.x1 = icon_rect.x0 + icon_width;
 		}
-		
+
+		icon_rect.y0 = 0;
+		icon_rect.y1 = icon_rect.y0 + icon_height;
+
 		/* Compute text rectangle. */
 		text_rect = compute_text_rectangle (icon_item, icon_rect, FALSE);
 		
@@ -2005,7 +2030,7 @@ nautilus_icon_canvas_item_bounds (EelCan
 		details->bounds_cache = total_rect;
 		details->bounds_cached = TRUE;
 	}
-        
+
 	/* Return the result. */
 	*x1 = (int)details->x + total_rect.x0;
 	*y1 = (int)details->y + total_rect.y0;
@@ -2015,69 +2040,49 @@ nautilus_icon_canvas_item_bounds (EelCan
 
 /* Get the rectangle of the icon only, in world coordinates. */
 ArtDRect
-nautilus_icon_canvas_item_get_icon_rectangle (const NautilusIconCanvasItem *item)
+nautilus_icon_canvas_item_get_icon_rectangle (NautilusIconCanvasItem *item)
 {
+	EelCanvas *canvas;
 	ArtDRect rectangle;
-	double pixels_per_unit;
-	GdkPixbuf *pixbuf;
-	
-	g_return_val_if_fail (NAUTILUS_IS_ICON_CANVAS_ITEM (item), eel_art_drect_empty);
 
-	rectangle.x0 = item->details->x;
-	rectangle.y0 = item->details->y;
-	
-	pixbuf = item->details->pixbuf;
-	
-	pixels_per_unit = EEL_CANVAS_ITEM (item)->canvas->pixels_per_unit;
-	rectangle.x1 = rectangle.x0 + (pixbuf == NULL ? 0 : gdk_pixbuf_get_width (pixbuf)) / pixels_per_unit;
-	rectangle.y1 = rectangle.y0 + (pixbuf == NULL ? 0 : gdk_pixbuf_get_height (pixbuf)) / pixels_per_unit;
+	g_assert (NAUTILUS_IS_ICON_CANVAS_ITEM (item));
 
-	eel_canvas_item_i2w (EEL_CANVAS_ITEM (item),
-			     &rectangle.x0,
-			     &rectangle.y0);
-	eel_canvas_item_i2w (EEL_CANVAS_ITEM (item),
-			     &rectangle.x1,
-			     &rectangle.y1);
+	nautilus_icon_canvas_item_update_bounds (item, 0, 0);
+
+	canvas = EEL_CANVAS_ITEM (item)->canvas;
+	eel_canvas_c2w (canvas,
+			item->details->icon_rect.x0,
+			item->details->icon_rect.y0,
+			&rectangle.x0, &rectangle.y0);
+	eel_canvas_c2w (canvas,
+			item->details->icon_rect.x1,
+			item->details->icon_rect.y1,
+			&rectangle.x1, &rectangle.y1);
 
 	return rectangle;
 }
 
 ArtDRect
-nautilus_icon_canvas_item_get_text_rectangle (const NautilusIconCanvasItem *item)
+nautilus_icon_canvas_item_get_text_rectangle (NautilusIconCanvasItem *item)
 {
-	/* FIXME */
-	ArtIRect icon_rectangle;
-	ArtIRect text_rectangle;
-	ArtDRect ret;
-	double pixels_per_unit;
-	GdkPixbuf *pixbuf;
-	
-	g_return_val_if_fail (NAUTILUS_IS_ICON_CANVAS_ITEM (item), eel_art_drect_empty);
+	EelCanvas *canvas;
+	ArtDRect rectangle;
 
-	icon_rectangle.x0 = item->details->x;
-	icon_rectangle.y0 = item->details->y;
-	
-	pixbuf = item->details->pixbuf;
-	
-	pixels_per_unit = EEL_CANVAS_ITEM (item)->canvas->pixels_per_unit;
-	icon_rectangle.x1 = icon_rectangle.x0 + (pixbuf == NULL ? 0 : gdk_pixbuf_get_width (pixbuf)) / pixels_per_unit;
-	icon_rectangle.y1 = icon_rectangle.y0 + (pixbuf == NULL ? 0 : gdk_pixbuf_get_height (pixbuf)) / pixels_per_unit;
+	g_assert (NAUTILUS_IS_ICON_CANVAS_ITEM (item));
 
-	text_rectangle = compute_text_rectangle (item, icon_rectangle, FALSE);
- 
-	ret.x0 = text_rectangle.x0;
-	ret.y0 = text_rectangle.y0;
-	ret.x1 = text_rectangle.x1;
-	ret.y1 = text_rectangle.y1;
-
-        eel_canvas_item_i2w (EEL_CANVAS_ITEM (item),
-                             &ret.x0,
-                             &ret.y0);
-        eel_canvas_item_i2w (EEL_CANVAS_ITEM (item),
-                             &ret.x1,
-                             &ret.y1);
- 
-        return ret;
+	nautilus_icon_canvas_item_update_bounds (item, 0, 0);
+
+	canvas = EEL_CANVAS_ITEM (item)->canvas;
+	eel_canvas_c2w (canvas,
+			item->details->text_rect.x0,
+			item->details->text_rect.y0,
+			&rectangle.x0, &rectangle.y0);
+	eel_canvas_c2w (canvas,
+			item->details->text_rect.x1,
+			item->details->text_rect.y1,
+			&rectangle.x1, &rectangle.y1);
+
+        return rectangle;
 }
 
 
@@ -2086,19 +2091,32 @@ static void
 get_icon_canvas_rectangle (NautilusIconCanvasItem *item,
 			   ArtIRect *rect)
 {
+	NautilusIconContainer *container;
 	GdkPixbuf *pixbuf;
+	gboolean text_beside;
+	int x, y;
 
-	g_return_if_fail (NAUTILUS_IS_ICON_CANVAS_ITEM (item));
-	g_return_if_fail (rect != NULL);
+	g_assert (NAUTILUS_IS_ICON_CANVAS_ITEM (item));
+	g_assert (rect != NULL);
+
+	/* also measures label text */
+	recompute_bounding_box (item, 0, 0);
+
+	container = NAUTILUS_ICON_CONTAINER (EEL_CANVAS_ITEM (item)->canvas);
+
+	x = item->details->x;
+	y = item->details->y;
+
+	text_beside = container->details->label_position == NAUTILUS_ICON_LABEL_POSITION_BESIDE;
+	if (text_beside && gtk_widget_get_direction (GTK_WIDGET (container)) == GTK_TEXT_DIR_RTL) {
+		x += item->details->text_width;
+	}
+
+	eel_canvas_w2c (EEL_CANVAS (container),
+			x, y, &rect->x0, &rect->y0);
 
-	eel_canvas_w2c (EEL_CANVAS_ITEM (item)->canvas,
-			item->details->x,
-			item->details->y,
-			&rect->x0,
-			&rect->y0);
-	
 	pixbuf = item->details->pixbuf;
-	
+
 	rect->x1 = rect->x0 + (pixbuf == NULL ? 0 : gdk_pixbuf_get_width (pixbuf));
 	rect->y1 = rect->y0 + (pixbuf == NULL ? 0 : gdk_pixbuf_get_height (pixbuf));
 }
@@ -2137,7 +2155,7 @@ hit_test_stretch_handle (NautilusIconCan
 	}
 
 	/* Quick check to see if the rect hits the icon at all. */
-	icon_rect = item->details->canvas_rect;
+	icon_rect = item->details->icon_rect;
 	if (!eel_art_irect_hits_irect (probe_canvas_rect, icon_rect)) {
 		return FALSE;
 	}
@@ -2647,30 +2665,30 @@ nautilus_icon_canvas_item_accessible_get
 	if (!item) {
 		return;
 	}
-	if (!item->details->canvas_rect.x0 && !item->details->canvas_rect.x1) {
+	if (!item->details->icon_rect.x0 && !item->details->icon_rect.x1) {
 		return;
 	} else {
 		x_offset = 0;
 		y_offset = 0;
 		if (item->details->text_width) {
-			itmp = item->details->canvas_rect.x0 -
+			itmp = item->details->icon_rect.x0 -
 			       item->details->text_rect.x0;
 			if (itmp > x_offset) {
 				x_offset = itmp;
 			}
-			itmp = item->details->canvas_rect.y0 -
+			itmp = item->details->icon_rect.y0 -
 			       item->details->text_rect.y0;
 			if (itmp > y_offset) {
 				y_offset = itmp;
 			}
 		}
 		if (item->details->emblem_pixbufs) {
-			itmp = item->details->canvas_rect.x0 -
+			itmp = item->details->icon_rect.x0 -
 			       item->details->emblem_rect.x0;
 			if (itmp > x_offset) {
 				x_offset = itmp;
 			}
-			itmp = item->details->canvas_rect.y0 -
+			itmp = item->details->icon_rect.y0 -
 			       item->details->emblem_rect.y0;
 			if (itmp > y_offset) {
 				y_offset = itmp;
Index: libnautilus-private/nautilus-icon-canvas-item.h
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-icon-canvas-item.h,v
retrieving revision 1.28
diff -u -p -r1.28 nautilus-icon-canvas-item.h
--- libnautilus-private/nautilus-icon-canvas-item.h	28 Oct 2005 12:41:19 -0000	1.28
+++ libnautilus-private/nautilus-icon-canvas-item.h	28 Feb 2006 08:07:10 -0000
@@ -87,8 +87,8 @@ gboolean    nautilus_icon_canvas_item_hi
 								ArtPoint                      world_point,
 								GtkCornerType *corner);
 void        nautilus_icon_canvas_item_invalidate_label_size    (NautilusIconCanvasItem       *item);
-ArtDRect    nautilus_icon_canvas_item_get_icon_rectangle       (const NautilusIconCanvasItem *item);
-ArtDRect    nautilus_icon_canvas_item_get_text_rectangle       (const NautilusIconCanvasItem *item);
+ArtDRect    nautilus_icon_canvas_item_get_icon_rectangle       (NautilusIconCanvasItem       *item);
+ArtDRect    nautilus_icon_canvas_item_get_text_rectangle       (NautilusIconCanvasItem       *item);
 void        nautilus_icon_canvas_item_update_bounds            (NautilusIconCanvasItem       *item,
 								double i2w_dx, double i2w_dy);
 
Index: libnautilus-private/nautilus-icon-container.c
===================================================================
RCS file: /cvs/gnome/nautilus/libnautilus-private/nautilus-icon-container.c,v
retrieving revision 1.410
diff -u -p -r1.410 nautilus-icon-container.c
--- libnautilus-private/nautilus-icon-container.c	27 Feb 2006 14:03:58 -0000	1.410
+++ libnautilus-private/nautilus-icon-container.c	28 Feb 2006 08:07:29 -0000
@@ -1100,7 +1100,11 @@ lay_down_icons_horizontal (NautilusIconC
 
 		if (container->details->label_position == NAUTILUS_ICON_LABEL_POSITION_BESIDE) {
 			if (gridded_layout) {
-				position->x_offset = max_icon_width + ICON_PAD_LEFT + ICON_PAD_RIGHT - (icon_bounds.x1 - icon_bounds.x0);
+				if (gtk_widget_get_direction (GTK_WIDGET (container)) == GTK_TEXT_DIR_RTL) {
+					position->x_offset = max_text_width + ICON_PAD_LEFT + ICON_PAD_RIGHT - (text_bounds.x1 - text_bounds.x0);
+				} else {
+					position->x_offset = max_icon_width + ICON_PAD_LEFT + ICON_PAD_RIGHT - (icon_bounds.x1 - icon_bounds.x0);
+				}
 			} else {
 				position->x_offset = icon_width - ((icon_bounds.x1 - icon_bounds.x0) + (text_bounds.x1 - text_bounds.x0));
 			}
@@ -6680,12 +6685,13 @@ nautilus_icon_container_start_renaming_s
 {
 	NautilusIconContainerDetails *details;
 	NautilusIcon *icon;
-	ArtDRect icon_rect;
+	ArtDRect icon_rect, text_rect;
 	PangoContext *context;
 	PangoFontDescription *desc;
 	const char *editable_text;
 	int x, y, width;
 	int start_offset, end_offset;
+	gboolean rtl;
 
 	/* Check if it already in renaming mode. */
 	details = container->details;
@@ -6749,13 +6755,16 @@ nautilus_icon_container_start_renaming_s
 	pango_font_description_free (desc);
 	
 	icon_rect = nautilus_icon_canvas_item_get_icon_rectangle (icon->item);
+
+	text_rect = nautilus_icon_canvas_item_get_text_rectangle (icon->item);
 	
 	width = nautilus_icon_canvas_item_get_max_text_width (icon->item);
 
+	rtl = gtk_widget_get_direction (GTK_WIDGET (container)) == GTK_TEXT_DIR_RTL;
 
 	if (details->label_position == NAUTILUS_ICON_LABEL_POSITION_BESIDE) {
 		eel_canvas_w2c (EEL_CANVAS_ITEM (icon->item)->canvas,
-				icon_rect.x1,
+				rtl ? text_rect.x1 - width : text_rect.x0,
 				icon_rect.y0,
 				&x, &y);
 	} else {
@@ -6765,6 +6774,10 @@ nautilus_icon_container_start_renaming_s
 				&x, &y);
 		x = x - width / 2 - 1;
 	}
+
+	/* sanitize width. */
+	x = MAX (x, 0);
+	width = MIN (width, GTK_WIDGET (container)->allocation.width - x);
 
 	gtk_layout_move (GTK_LAYOUT (container),
 			 details->rename_widget,


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