[Gnucash-changes] r13137 - gnucash/trunk - Scott Oonk' patch to fix
a couple of problems with right justified
David Hampton
hampton at cvs.gnucash.org
Mon Feb 6 20:56:46 EST 2006
Author: hampton
Date: 2006-02-06 20:56:45 -0500 (Mon, 06 Feb 2006)
New Revision: 13137
Trac: http://svn.gnucash.org/trac/changeset/13137
Modified:
gnucash/trunk/ChangeLog
gnucash/trunk/src/register/register-gnome/gnucash-grid.c
gnucash/trunk/src/register/register-gnome/gnucash-item-edit.c
Log:
Scott Oonk' patch to fix a couple of problems with right justified
cells in the register.
Modified: gnucash/trunk/ChangeLog
===================================================================
--- gnucash/trunk/ChangeLog 2006-02-06 22:09:21 UTC (rev 13136)
+++ gnucash/trunk/ChangeLog 2006-02-07 01:56:45 UTC (rev 13137)
@@ -1,3 +1,17 @@
+2006-02-06 David Hampton <hampton at employees.org>
+
+ * src/register/register-gnome/gnucash-item-edit.c:
+ * src/register/register-gnome/gnucash-grid.c: Scott Oonk' patch to
+ fix a couple of problems with right justified cells in the
+ register.
+
+ - Make sure the text in the cell stays right justified when
+ deleting characters.
+ - Adjust the positioning of text to account for the popup toggle.
+ - Change gnucash-item-edit to use logical extents instead of ink
+ extents. This syncs gnucash-item-edit.c with change made to
+ gnucash-grid.c in r12155.
+
2006-02-05 Derek Atkins <derek at ihtfp.com>
* src/backend/file/test/Makefile.am: link against libcore-utils.
Modified: gnucash/trunk/src/register/register-gnome/gnucash-grid.c
===================================================================
--- gnucash/trunk/src/register/register-gnome/gnucash-grid.c 2006-02-06 22:09:21 UTC (rev 13136)
+++ gnucash/trunk/src/register/register-gnome/gnucash-grid.c 2006-02-07 01:56:45 UTC (rev 13137)
@@ -510,7 +510,7 @@
break;
case CELL_ALIGN_RIGHT:
- x_offset = width - 2 * CELL_HPADDING - logical_rect.width + 1;
+ x_offset = width - 2 * CELL_HPADDING - logical_rect.width;
break;
case CELL_ALIGN_CENTER:
Modified: gnucash/trunk/src/register/register-gnome/gnucash-item-edit.c
===================================================================
--- gnucash/trunk/src/register/register-gnome/gnucash-item-edit.c 2006-02-06 22:09:21 UTC (rev 13136)
+++ gnucash/trunk/src/register/register-gnome/gnucash-item-edit.c 2006-02-07 01:56:45 UTC (rev 13137)
@@ -118,7 +118,52 @@
*y += yd;
}
+static void
+gnc_item_edit_update_offset (GncItemEdit *item_edit, TextDrawInfo *info)
+{
+ gint drawable_width;
+ gint visible_width;
+ PangoRectangle logical_rect;
+ g_return_if_fail (item_edit != NULL);
+ g_return_if_fail (GNC_IS_ITEM_EDIT (item_edit));
+
+ pango_layout_get_pixel_extents (info->layout, NULL, &logical_rect);
+
+ drawable_width = info->text_rect.width - 2 * CELL_HPADDING;
+
+ // Layout is smaller than drawable area, or we've entered a
+ // new cell. Use default x_offset.
+ if (logical_rect.width <= drawable_width || item_edit->reset_pos)
+ {
+ gnc_item_edit_reset_offset (item_edit);
+ }
+
+ // Layout is wider than drawable area
+ if (logical_rect.width > drawable_width)
+ {
+ //Make sure cursor is inside the drawn area
+ if (info->cursor_rect.x + item_edit->x_offset >
+ info->text_rect.x + drawable_width)
+ {
+ item_edit->x_offset = (info->text_rect.x + drawable_width)
+ - info->cursor_rect.x;
+ }
+ else if (info->cursor_rect.x + item_edit->x_offset < info->text_rect.x)
+ {
+ item_edit->x_offset = - info->cursor_rect.x;
+ }
+
+ // Make sure the entire drawable area is filled.
+ visible_width = logical_rect.width + item_edit->x_offset;
+
+ if (visible_width < drawable_width)
+ {
+ item_edit->x_offset += (drawable_width - visible_width);
+ }
+ }
+}
+
static void
gnc_item_edit_draw_info (GncItemEdit *item_edit, int x, int y, TextDrawInfo *info)
{
@@ -218,13 +263,6 @@
// pango_layout_set_ellipsize(...) as of pango 1.6 may be useful for
// strings longer than the field width.
- // Default x_offset based on cell alignment
- if (item_edit->reset_pos)
- {
- gnc_item_edit_reset_offset (item_edit);
- item_edit->reset_pos = FALSE;
- }
-
pango_layout_get_cursor_pos (info->layout, cursor_byte_pos, &strong_pos, NULL);
info->cursor_rect.x = dx + PANGO_PIXELS (strong_pos.x);
@@ -239,6 +277,8 @@
info->hatch_rect.width = wd;
info->hatch_rect.height = hd;
}
+
+ gnc_item_edit_update_offset (item_edit, info);
}
static void
@@ -251,22 +291,6 @@
}
static void
-gnc_item_edit_update_scroll_offset(GncItemEdit *item_edit,
- TextDrawInfo *info) {
- if (info->cursor_rect.x + item_edit->x_offset >
- info->text_rect.x + info->text_rect.width - CELL_HPADDING)
- {
- item_edit->x_offset =
- (info->text_rect.x + info->text_rect.width - CELL_HPADDING)
- - info->cursor_rect.x;
- }
- else if (info->cursor_rect.x + item_edit->x_offset < info->text_rect.x)
- {
- item_edit->x_offset = - info->cursor_rect.x;
- }
-}
-
-static void
gnc_item_edit_draw (GnomeCanvasItem *item, GdkDrawable *drawable,
int x, int y, int width, int height)
{
@@ -299,8 +323,6 @@
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 +
@@ -569,18 +591,26 @@
gnc_item_edit_reset_offset (GncItemEdit *item_edit)
{
Table *table;
- PangoRectangle ink_rect;
+ PangoRectangle logical_rect;
PangoLayout *layout;
gint x, y, width, height;
+ gint drawable_width;
+ gint toggle_space;
g_return_if_fail (item_edit != NULL);
g_return_if_fail (GNC_IS_ITEM_EDIT(item_edit));
table = item_edit->sheet->table;
layout = gtk_entry_get_layout (GTK_ENTRY(item_edit->editor));
- pango_layout_get_pixel_extents (layout, &ink_rect, NULL);
+
+ pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
gnc_item_edit_get_pixel_coords (item_edit, &x, &y, &width, &height);
+ toggle_space = item_edit->is_popup ?
+ item_edit->popup_toggle.toggle_offset : 0;
+
+ drawable_width = width - 2 * CELL_HPADDING - toggle_space;
+
switch (gnc_table_get_align (table, item_edit->virt_loc))
{
default:
@@ -589,20 +619,18 @@
break;
case CELL_ALIGN_RIGHT:
- item_edit->x_offset = width
- - 2 * CELL_HPADDING
- - ink_rect.width;
+ item_edit->x_offset = drawable_width - logical_rect.width;
break;
case CELL_ALIGN_CENTER:
- if (ink_rect.width > width - 2 * CELL_HPADDING)
+ if (logical_rect.width > drawable_width)
item_edit->x_offset = 0;
else
- item_edit->x_offset = (width
- - 2 * CELL_HPADDING
- - ink_rect.width) / 2;
+ item_edit->x_offset = (drawable_width - logical_rect.width) / 2;
break;
}
+
+ item_edit->reset_pos = FALSE;
}
/*
@@ -754,7 +782,16 @@
o_x = cd->origin_x + item_edit->x_offset;
o_y = cd->origin_y;
+ if (changed_cells)
+ {
+ CellAlignment align;
+ align = gnc_table_get_align (table, item_edit->virt_loc);
+
+ if (align == CELL_ALIGN_RIGHT && item_edit->is_popup)
+ o_x += item_edit->popup_toggle.toggle_offset;
+ }
+
// get the text index for the mouse position into pos
{
PangoLayout *layout;
More information about the gnucash-changes
mailing list