[evolution-patches] 37894: ECellText justification



The attached patch uses the layout alignment and size properties to
properly handle justification.

Mike
Index: gal/e-table/e-cell-text.c
===================================================================
RCS file: /cvs/gnome/gal/gal/e-table/e-cell-text.c,v
retrieving revision 1.121
diff -u -p -w -r1.121 e-cell-text.c
--- gal/e-table/e-cell-text.c	8 Apr 2003 19:48:38 -0000	1.121
+++ gal/e-table/e-cell-text.c	15 Apr 2003 20:54:00 -0000
@@ -434,7 +434,7 @@ ect_free_color (gchar *color_spec, GdkCo
 }
 
 static PangoLayout *
-build_layout (ECellTextView *text_view, int row, const char *text)
+build_layout (ECellTextView *text_view, int row, const char *text, gint width)
 {
 	ECellView *ecell_view = (ECellView *) text_view;
 	ECellText *ect = E_CELL_TEXT (ecell_view->ecell);
@@ -482,11 +482,26 @@ build_layout (ECellTextView *text_view, 
 		pango_attr_list_unref (attrs);
 	}
 
+	if (width > 0)
+		pango_layout_set_width (layout, width * PANGO_SCALE);
+
+	switch (ect->justify) {
+	case GTK_JUSTIFY_RIGHT:
+		pango_layout_set_alignment (layout, PANGO_ALIGN_RIGHT);
+		break;
+	case GTK_JUSTIFY_CENTER:
+		pango_layout_set_alignment (layout, PANGO_ALIGN_CENTER);
+		break;
+	case GTK_JUSTIFY_LEFT:
+	default:
+		break;
+	}
+	
 	return layout;
 }
 
 static PangoLayout *
-generate_layout (ECellTextView *text_view, int model_col, int view_col, int row)
+generate_layout (ECellTextView *text_view, int model_col, int view_col, int row, int width)
 {
 	ECellView *ecell_view = (ECellView *) text_view;
 	ECellText *ect = E_CELL_TEXT (ecell_view->ecell);
@@ -495,15 +510,16 @@ generate_layout (ECellTextView *text_vie
 
 	if (edit && edit->model_col == model_col && edit->row == row) {
 		g_object_ref (edit->layout);
+		pango_layout_set_width (edit->layout, width);
 		return edit->layout;
 	}
 
 	if (row >= 0) {
 		char *temp = e_cell_text_get_text(ect, ecell_view->e_table_model, model_col, row);
-		layout = build_layout (text_view, row, temp);
+		layout = build_layout (text_view, row, temp, width);
 		e_cell_text_free_text(ect, temp);
 	} else
-		layout = build_layout (text_view, row, "Mumbo Jumbo");
+		layout = build_layout (text_view, row, "Mumbo Jumbo", width);
 
 	return layout;
 }
@@ -621,7 +637,7 @@ ect_draw (ECellView *ecell_view, GdkDraw
 	gdk_gc_set_clip_rectangle (text_view->gc, &clip_rect);
 	/*	clip_rect = ▭*/
 
-	layout = generate_layout (text_view, model_col, view_col, row);
+	layout = generate_layout (text_view, model_col, view_col, row, x2 - x1);
 
 	gdk_draw_layout (drawable, text_view->gc,
 			 x_origin, y_origin,
@@ -940,7 +956,7 @@ ect_height (ECellView *ecell_view, int m
 	gint height;
 	PangoLayout *layout;
 
-	layout = generate_layout (text_view, model_col, view_col, row);
+	layout = generate_layout (text_view, model_col, view_col, row, 0);
 	pango_layout_get_pixel_size (layout, NULL, &height);
 	g_object_unref (layout);
 	return height + 2;
@@ -964,8 +980,6 @@ ect_enter_edit (ECellView *ecell_view, i
 	edit->model_col = -1;
 	edit->row = -1;
 
-	edit->layout = generate_layout (text_view, model_col, view_col, row);
-	
 	edit->text_view = text_view;
 	edit->model_col = model_col;
 	edit->view_col = view_col;
@@ -974,6 +988,8 @@ ect_enter_edit (ECellView *ecell_view, i
 		((ETableItem *)ecell_view->e_table_item_view)->header,
 		view_col)->width - 8;
 
+	edit->layout = generate_layout (text_view, model_col, view_col, row, edit->cell_width);
+	
 	edit->xofs_edit = 0.0;
 	edit->yofs_edit = 0.0;
 	
@@ -1139,7 +1155,7 @@ ect_max_width (ECellView *ecell_view,
 	number_of_rows = e_table_model_row_count (ecell_view->e_table_model);
 
 	for (row = 0; row < number_of_rows; row++) {
-		PangoLayout *layout = generate_layout (text_view, model_col, view_col, row);
+		PangoLayout *layout = generate_layout (text_view, model_col, view_col, row, 0);
 		int width;
 
 		pango_layout_get_pixel_size (layout, &width, NULL);
@@ -1165,7 +1181,7 @@ ect_max_width_by_row (ECellView *ecell_v
 	if (row >= e_table_model_row_count (ecell_view->e_table_model))
 		return 0;
 
-	layout = generate_layout (text_view, model_col, view_col, row);
+	layout = generate_layout (text_view, model_col, view_col, row, 0);
 	pango_layout_get_pixel_size (layout, &width, NULL);
 	g_object_unref (layout);
 	
@@ -1239,7 +1255,7 @@ ect_show_tooltip (ECellView *ecell_view,
 
 	tooltip->timer = 0;
 
-	layout = generate_layout (text_view, model_col, view_col, row);
+	layout = generate_layout (text_view, model_col, view_col, row, col_width);
 
 	pango_layout_get_pixel_size (layout, &width, &height);
 	if (width < col_width - 8) {
@@ -2068,9 +2084,10 @@ e_cell_text_view_command (ETextEventProc
 	}
 
 	if (change) {
+		e_table_item_leave_edit_ (text_view->cell_view.e_table_item_view);
 		if (edit->layout)
 			g_object_unref (edit->layout);
-		edit->layout = build_layout (text_view, edit->row, edit->text);
+		edit->layout = build_layout (text_view, edit->row, edit->text, edit->cell_width);
 	}
 
 	if (!edit->button_down) {


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