Skip to content

Commit

Permalink
Bug 644242 - Register Panning Problem
Browse files Browse the repository at this point in the history
If the horizontal scrollbar is present for a register and you start to
tab from one cell to the next one that is not in view the sheet does
not scroll to keep the active cell in view.

This commit fixes that by getting the active cell horizontal offset and
width and comparing it to the sheet width and window width.
  • Loading branch information
Bob-IT committed Nov 15, 2020
1 parent 20f2efb commit 8ad9d0a
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
25 changes: 25 additions & 0 deletions gnucash/register/register-gnome/gnucash-header.c
Expand Up @@ -188,6 +188,31 @@ gnc_header_draw_offscreen (GncHeader *header)
}


gint
gnc_header_get_cell_offset (GncHeader *header, gint col, gint *cell_width)
{
SheetBlockStyle *style = header->style;
gint j;
gint offset = 0;

for (j = 0; j < style->ncols; j++)
{
CellDimensions *cd;

cd = gnucash_style_get_cell_dimensions (style, 0, j);
if (!cd) continue;

if (j == col)
{
*cell_width = cd->pixel_width;
break;
}
offset = offset + cd->pixel_width;
}
return offset;
}


static gboolean
gnc_header_draw (GtkWidget *header, cairo_t *cr)
{
Expand Down
5 changes: 5 additions & 0 deletions gnucash/register/register-gnome/gnucash-header.h
Expand Up @@ -74,5 +74,10 @@ void gnc_header_request_redraw (GncHeader *header);

void gnc_header_set_header_rows (GncHeader *header,
int num_phys_rows);

gint gnc_header_get_cell_offset (GncHeader *header,
gint col,
gint *cell_width);

/** @} */
#endif /* GNUCASH_HEADER_H */
27 changes: 27 additions & 0 deletions gnucash/register/register-gnome/gnucash-sheet.c
Expand Up @@ -1627,6 +1627,27 @@ gnucash_sheet_clipboard_event (GnucashSheet *sheet, GdkEventKey *event)
return handled;
}

static void
gnucash_sheet_need_horizontal_scroll (GnucashSheet *sheet,
VirtualLocation *new_virt_loc)
{
gint hscroll_val;
gint cell_width = 0;
gint offset;

if (sheet->window_width == sheet->width)
return;

// get the horizontal scroll window value
hscroll_val = (gint) gtk_adjustment_get_value (sheet->hadj);

// offset is the start of the cell for column
offset = gnc_header_get_cell_offset (GNC_HEADER(sheet->header_item), new_virt_loc->phys_col_offset, &cell_width);

if (((offset + cell_width) > sheet->window_width) || (offset < hscroll_val))
gtk_adjustment_set_value (sheet->hadj, offset);
}

static gboolean
process_motion_keys (GnucashSheet *sheet, GdkEventKey *event, gboolean *pass_on,
gncTableTraversalDir *direction,
Expand Down Expand Up @@ -1735,6 +1756,9 @@ process_motion_keys (GnucashSheet *sheet, GdkEventKey *event, gboolean *pass_on,
*pass_on = TRUE;
break;
}
// does the sheet need horizontal scrolling due to tab
gnucash_sheet_need_horizontal_scroll (sheet, new_virt_loc);

return FALSE;
}

Expand Down Expand Up @@ -1894,6 +1918,9 @@ gnucash_sheet_goto_virt_loc (GnucashSheet *sheet, VirtualLocation virt_loc)
if (abort_move)
return;

// does the sheet need horizontal scrolling
gnucash_sheet_need_horizontal_scroll (sheet, &virt_loc);

gnucash_sheet_cursor_move (sheet, virt_loc);
}

Expand Down

0 comments on commit 8ad9d0a

Please sign in to comment.