[Gnucash-changes] Didier Vidal's patch to restore horizontal scrolling in the editable

David Hampton hampton at cvs.gnucash.org
Fri Oct 14 18:19:08 EDT 2005


Log Message:
-----------
Didier Vidal's patch to restore horizontal scrolling in the editable
cells of the register if the content is too wide. It also maintains
the cell alignment when you switch to edit mode.

Tags:
----
gnucash-gnome2-dev

Modified Files:
--------------
    gnucash:
        ChangeLog
    gnucash/src/register/register-gnome:
        gnucash-item-edit.c

Revision Data
-------------
Index: ChangeLog
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/ChangeLog,v
retrieving revision 1.1487.2.339
retrieving revision 1.1487.2.340
diff -LChangeLog -LChangeLog -u -r1.1487.2.339 -r1.1487.2.340
--- ChangeLog
+++ ChangeLog
@@ -1,5 +1,10 @@
 2005-10-14  David Hampton  <hampton at employees.org>
 
+	* src/register/register-gnome/gnucash-item-edit.c: Didier Vidal's
+	patch to restore horizontal scrolling in the editable cells of the
+	register if the content is too wide. It also maintains the cell
+	alignment when you switch to edit mode.
+
 	* src/report/report-system/html-acct-table.scm: Patch from Chris
 	Shoemaker to fix one use of price source where exchange-fn was
 	needed.  Added lots of comments, clarify some explanations,
Index: gnucash-item-edit.c
===================================================================
RCS file: /home/cvs/cvsroot/gnucash/src/register/register-gnome/gnucash-item-edit.c,v
retrieving revision 1.1.6.13
retrieving revision 1.1.6.14
diff -Lsrc/register/register-gnome/gnucash-item-edit.c -Lsrc/register/register-gnome/gnucash-item-edit.c -u -r1.1.6.13 -r1.1.6.14
--- src/register/register-gnome/gnucash-item-edit.c
+++ src/register/register-gnome/gnucash-item-edit.c
@@ -247,6 +247,20 @@
 }
 
 static void
+gnc_item_edit_update_scroll_offset(GncItemEdit *item_edit,
+				   TextDrawInfo *info) {
+	gint cursor_margin = CELL_HPADDING + 3;
+	if (PANGO_PIXELS (info->cursor.x) + item_edit->x_offset 
+	    > info->text_rect.width - cursor_margin) {
+		item_edit->x_offset = info->text_rect.width
+			- PANGO_PIXELS (info->cursor.x) - cursor_margin;
+	} else if (PANGO_PIXELS (info->cursor.x) + item_edit->x_offset 
+		   < 0) {
+		item_edit->x_offset = - PANGO_PIXELS (info->cursor.x);
+	}
+}
+
+static void
 gnc_item_edit_draw (GnomeCanvasItem *item, GdkDrawable *drawable,
                 int x, int y, int width, int height)
 {
@@ -281,17 +295,22 @@
 
         gdk_gc_set_foreground (item_edit->gc, info.fg_color);
 
+	gnc_item_edit_update_scroll_offset(item_edit, &info);
+
 	gdk_draw_layout (drawable,
 			 item_edit->gc,
-			 info.text_rect.x + CELL_HPADDING,
+			 info.text_rect.x + CELL_HPADDING + 
+			 item_edit->x_offset,
 			 info.text_rect.y + 1,
 			 info.layout);
 
         gdk_draw_line (drawable,
                        item_edit->gc,
-                       PANGO_PIXELS (info.cursor.x) + CELL_HPADDING,
+                       PANGO_PIXELS (info.cursor.x) + CELL_HPADDING 
+		       + item_edit->x_offset,
                        PANGO_PIXELS (info.cursor.y),
-                       PANGO_PIXELS (info.cursor.x) + CELL_HPADDING,
+                       PANGO_PIXELS (info.cursor.x) + CELL_HPADDING
+		       + item_edit->x_offset,
                        PANGO_PIXELS (info.cursor.y + info.cursor.height));
 
         gdk_gc_set_clip_rectangle (item_edit->gc, NULL);
@@ -691,9 +710,6 @@
 
         cd = gnucash_style_get_cell_dimensions (style, cell_row, cell_col);
 
-        o_x = cd->origin_x;
-        o_y = cd->origin_y;
-
         if (!virt_loc_equal (virt_loc, item_edit->virt_loc))
                 return FALSE;
 
@@ -705,15 +721,34 @@
 
                 align = gnc_table_get_align (table, item_edit->virt_loc);
 
-                if (align == CELL_ALIGN_RIGHT)
+                if (align == CELL_ALIGN_RIGHT) {
+			PangoRectangle ink_rect;
+			PangoLayout *layout;
+
                         gtk_editable_set_position(editable, -1);
-                else
-                        gtk_editable_set_position(editable, 0);
+
+			layout = gtk_entry_get_layout( GTK_ENTRY(item_edit->
+								 editor) );
+			pango_layout_get_pixel_extents(layout,
+						       &ink_rect,
+						       NULL);
+
+			item_edit->x_offset = 
+				cd->pixel_width - ink_rect.width -
+				2* CELL_HPADDING;
+		}
+                else {
+			gtk_editable_set_position(editable, 0);
+			item_edit->x_offset = 0;
+		}
 
                 if (item_edit->is_popup)
                         x -= item_edit->popup_toggle.toggle_offset;
         }
 
+        o_x = cd->origin_x + item_edit->x_offset;
+        o_y = cd->origin_y;
+
 
         // get the text index for the mouse position into pos
         {


More information about the gnucash-changes mailing list