[Gnucash-changes] r11901 - gnucash/trunk - Scot Oonk's patch to fix
some alignment problems in the register.
David Hampton
hampton at cvs.gnucash.org
Wed Nov 9 23:26:37 EST 2005
Author: hampton
Date: 2005-11-09 23:26:36 -0500 (Wed, 09 Nov 2005)
New Revision: 11901
Modified:
gnucash/trunk/ChangeLog
gnucash/trunk/src/register/register-gnome/gnucash-item-edit.c
Log:
Scot Oonk's patch to fix some alignment problems in the register.
Modified: gnucash/trunk/ChangeLog
===================================================================
--- gnucash/trunk/ChangeLog 2005-11-10 04:25:08 UTC (rev 11900)
+++ gnucash/trunk/ChangeLog 2005-11-10 04:26:36 UTC (rev 11901)
@@ -1,3 +1,17 @@
+2005-11-09 Scott Oonk <scott.oonk at gmail.com>
+
+ * src/register/register-gnome/gnucash-item-edit.c: Fix some
+ alignment problems in the register.
+
+ It removes the pango_layout_set_alignment code. Since we are
+ rendering a single line of text, the layout is only as wide as the
+ text. Because of this, the alignment within the layout doesn't
+ have any effect.
+
+ Use the same x_offset logic regardless of how we enter the cell.
+
+ Make sure x_offset gets reset when changing cells via the keyboard.
+
2005-11-09 David Hampton <hampton at employees.org>
* src/gnome-utils/gnc-tree-view-account.[ch]: Add a function that
Modified: gnucash/trunk/src/register/register-gnome/gnucash-item-edit.c
===================================================================
--- gnucash/trunk/src/register/register-gnome/gnucash-item-edit.c 2005-11-10 04:25:08 UTC (rev 11900)
+++ gnucash/trunk/src/register/register-gnome/gnucash-item-edit.c 2005-11-10 04:26:36 UTC (rev 11901)
@@ -218,22 +218,13 @@
// pango_layout_set_ellipsize(...) as of pango 1.6 may be useful for
// strings longer than the field width.
- switch (gnc_table_get_align (table, item_edit->virt_loc))
+ // Default x_offset based on cell alignment
+ if (item_edit->reset_pos)
{
- default:
- case CELL_ALIGN_LEFT:
- pango_layout_set_alignment (info->layout, PANGO_ALIGN_LEFT);
- break;
+ gnc_item_edit_reset_offset (item_edit);
+ item_edit->reset_pos = FALSE;
+ }
- case CELL_ALIGN_RIGHT:
- pango_layout_set_alignment (info->layout, PANGO_ALIGN_RIGHT);
- break;
-
- case CELL_ALIGN_CENTER:
- pango_layout_set_alignment (info->layout, PANGO_ALIGN_CENTER);
- break;
- }
-
pango_layout_get_cursor_pos (info->layout, cursor_byte_pos, &strong_pos, NULL);
info->cursor = strong_pos;
@@ -284,8 +275,6 @@
/* Get the measurements for drawing */
gnc_item_edit_draw_info (item_edit, x, y, &info);
- item_edit->reset_pos = FALSE;
-
/* Draw the background */
gdk_gc_set_foreground (item_edit->gc, info.bg_color);
gdk_draw_rectangle (drawable, item_edit->gc, TRUE,
@@ -575,10 +564,41 @@
void
gnc_item_edit_reset_offset (GncItemEdit *item_edit)
{
+ Table *table;
+ PangoRectangle ink_rect;
+ PangoLayout *layout;
+ gint x, y, width, height;
+
g_return_if_fail (item_edit != NULL);
g_return_if_fail (GNC_IS_ITEM_EDIT(item_edit));
- item_edit->reset_pos = TRUE;
+ table = item_edit->sheet->table;
+ layout = gtk_entry_get_layout (GTK_ENTRY(item_edit->editor));
+ pango_layout_get_pixel_extents (layout, &ink_rect, NULL);
+ gnc_item_edit_get_pixel_coords (item_edit, &x, &y, &width, &height);
+
+ switch (gnc_table_get_align (table, item_edit->virt_loc))
+ {
+ default:
+ case CELL_ALIGN_LEFT:
+ item_edit->x_offset = 0;
+ break;
+
+ case CELL_ALIGN_RIGHT:
+ item_edit->x_offset = width
+ - 2 * CELL_HPADDING
+ - ink_rect.width;
+ break;
+
+ case CELL_ALIGN_CENTER:
+ if (ink_rect.width > width - 2 * CELL_HPADDING)
+ item_edit->x_offset = 0;
+ else
+ item_edit->x_offset = (width
+ - 2 * CELL_HPADDING
+ - ink_rect.width) / 2;
+ break;
+ }
}
/*
@@ -725,36 +745,8 @@
editable = GTK_EDITABLE (item_edit->editor);
if (changed_cells)
- {
- CellAlignment align;
+ gnc_item_edit_reset_offset (item_edit);
- align = gnc_table_get_align (table, item_edit->virt_loc);
-
- if (align == CELL_ALIGN_RIGHT) {
- PangoRectangle ink_rect;
- PangoLayout *layout;
-
- gtk_editable_set_position(editable, -1);
-
- 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;
More information about the gnucash-changes
mailing list