diff --git a/src/SplitLedger.c b/src/SplitLedger.c index a7c3b51ab2..10b74d452a 100644 --- a/src/SplitLedger.c +++ b/src/SplitLedger.c @@ -3234,6 +3234,10 @@ xaccSRGetBGColorHandler (VirtualLocation virt_loc, gpointer user_data) if (!vcell || !vcell->cellblock) return bg_color; + if ((virt_loc.phys_col_offset < vcell->cellblock->start_col) || + (virt_loc.phys_col_offset > vcell->cellblock->stop_col)) + return bg_color; + is_current = virt_cell_loc_equal (reg->table->current_cursor_loc.vcell_loc, virt_loc.vcell_loc); diff --git a/src/gnome/top-level.c b/src/gnome/top-level.c index c822cb430d..1f93a9e750 100644 --- a/src/gnome/top-level.c +++ b/src/gnome/top-level.c @@ -606,19 +606,20 @@ gnc_configure_register_borders_cb(void *data) static void gnc_configure_register_borders(void) { - RegisterBorders reg_borders = 0; + gboolean use_vertical_lines; + gboolean use_horizontal_lines; + + use_vertical_lines = gnc_lookup_boolean_option("Register", + "Show Vertical Borders", + TRUE); - if (gnc_lookup_boolean_option("Register", - "Show Vertical Borders", - TRUE)) - reg_borders |= STYLE_BORDER_LEFT | STYLE_BORDER_RIGHT; - if (gnc_lookup_boolean_option("Register", - "Show Horizontal Borders", - TRUE)) - reg_borders |= STYLE_BORDER_TOP | STYLE_BORDER_BOTTOM; - - gnucash_style_set_register_borders (reg_borders); + use_horizontal_lines = gnc_lookup_boolean_option("Register", + "Show Horizontal Borders", + TRUE); + + gnucash_style_config_register_borders (use_vertical_lines, + use_horizontal_lines); } /* gnc_configure_auto_raise_cb diff --git a/src/register/cellblock.c b/src/register/cellblock.c index 0fe912d304..7e2548a26f 100644 --- a/src/register/cellblock.c +++ b/src/register/cellblock.c @@ -96,6 +96,9 @@ gnc_cellblock_init (CellBlock *cellblock, int rows, int cols) cellblock->num_rows = rows; cellblock->num_cols = cols; + cellblock->start_col = cols; + cellblock->stop_col = -1; + /* malloc new cell table */ cellblock->cb_cells = g_table_new (sizeof (CellBlockCell), gnc_cellblock_cell_construct, diff --git a/src/register/cellblock.h b/src/register/cellblock.h index 8baef4a6f8..35343e33ca 100644 --- a/src/register/cellblock.h +++ b/src/register/cellblock.h @@ -91,6 +91,9 @@ typedef struct short num_rows; short num_cols; + short start_col; + short stop_col; + short cursor_type; GTable *cb_cells; /* Holds the CellBlockCell table */ diff --git a/src/register/gnome/gnucash-cursor.c b/src/register/gnome/gnucash-cursor.c index dea1db0102..998ad36fdd 100644 --- a/src/register/gnome/gnucash-cursor.c +++ b/src/register/gnome/gnucash-cursor.c @@ -23,8 +23,9 @@ * * Based heavily (i.e., cut and pasted from) on the Gnumeric ItemCursor. * - * Author: - * Heath Martin + * Authors: + * Heath Martin + * Dave Peticolas */ #include "gnucash-sheet.h" @@ -44,13 +45,17 @@ enum { static void -gnucash_cursor_get_pixel_coords (GnucashCursor *cursor, gint *x, gint *y, +gnucash_cursor_get_pixel_coords (GnucashCursor *cursor, + gint *x, gint *y, gint *w, gint *h) { GnucashSheet *sheet = cursor->sheet; GnucashItemCursor *item_cursor; VirtualCellLocation vcell_loc; + CellDimensions *cd; + VirtualCell *vcell; SheetBlock *block; + gint col; item_cursor = GNUCASH_ITEM_CURSOR(cursor->cursor[GNUCASH_CURSOR_BLOCK]); @@ -59,14 +64,46 @@ gnucash_cursor_get_pixel_coords (GnucashCursor *cursor, gint *x, gint *y, vcell_loc.virt_col = item_cursor->col; block = gnucash_sheet_get_block (sheet, vcell_loc); - if (block == NULL) + if (!block) return; + vcell = gnc_table_get_virtual_cell (sheet->table, vcell_loc); + if (!vcell) + return; + + for (col = 0; col < vcell->cellblock->num_cols; col++) + { + CellBlockCell *cb_cell; + + cb_cell = gnc_cellblock_get_cell (vcell->cellblock, 0, col); + if (cb_cell->cell_type != NO_CELL) + break; + } + *y = block->origin_y; - *x = block->origin_x; + + cd = gnucash_style_get_cell_dimensions (block->style, 0, col); + if (cd) + *x = cd->origin_x; + else + *x = block->origin_x; + + for (col = vcell->cellblock->num_cols - 1; col >= 0; col--) + { + CellBlockCell *cb_cell; + + cb_cell = gnc_cellblock_get_cell (vcell->cellblock, 0, col); + if (cb_cell->cell_type != NO_CELL) + break; + } *h = block->style->dimensions->height; - *w = block->style->dimensions->width; + + cd = gnucash_style_get_cell_dimensions (block->style, 0, col); + if (cd) + *w = cd->origin_x + cd->pixel_width - *x; + else + *w = block->style->dimensions->width - *x; } @@ -117,19 +154,17 @@ void gnucash_cursor_configure (GnucashCursor *cursor) { GnomeCanvasItem *item; - GnucashItemCursor *item_cursor; - GnomeCanvasGroup *group; + GnucashItemCursor *block_cursor; + GnucashItemCursor *cell_cursor; GnomeCanvas *canvas; gint x, y, w, h; double wx, wy; - + g_return_if_fail (cursor != NULL); g_return_if_fail (GNUCASH_IS_CURSOR (cursor)); canvas = GNOME_CANVAS(GNOME_CANVAS_ITEM(cursor)->canvas); - group = GNOME_CANVAS_GROUP(cursor); - item = GNOME_CANVAS_ITEM (cursor); gnucash_cursor_get_pixel_coords (cursor, &x, &y, &w, &h); @@ -147,40 +182,40 @@ gnucash_cursor_configure (GnucashCursor *cursor) item->y2 = y + h; item = cursor->cursor[GNUCASH_CURSOR_BLOCK]; - item_cursor = GNUCASH_ITEM_CURSOR (item); + block_cursor = GNUCASH_ITEM_CURSOR (item); wx = 0; wy = 0; gnome_canvas_item_i2w (item, &wx, &wy); - gnome_canvas_w2c (canvas, wx, wy, &item_cursor->x, &item_cursor->y); - item_cursor->w = w; - item_cursor->h = h; + gnome_canvas_w2c (canvas, wx, wy, &block_cursor->x, &block_cursor->y); + block_cursor->w = w; + block_cursor->h = h; - item->x1 = item_cursor->x; - item->y1 = item_cursor->y; - item->x2 = item_cursor->x + w; - item->y2 = item_cursor->y + h; + item->x1 = block_cursor->x; + item->y1 = block_cursor->y; + item->x2 = block_cursor->x + w; + item->y2 = block_cursor->y + h; item = cursor->cursor[GNUCASH_CURSOR_CELL]; - item_cursor = GNUCASH_ITEM_CURSOR(item); + cell_cursor = GNUCASH_ITEM_CURSOR(item); gnucash_sheet_style_get_cell_pixel_rel_coords (cursor->style, - item_cursor->row, - item_cursor->col, + cell_cursor->row, + cell_cursor->col, &x, &y, &w, &h); - wx = x; + wx = x - block_cursor->x; wy = y; gnome_canvas_item_i2w (item, &wx, &wy); - gnome_canvas_w2c (canvas, wx, wy, &item_cursor->x, &item_cursor->y); - item_cursor->w = w; - item_cursor->h = h; + gnome_canvas_w2c (canvas, wx, wy, &cell_cursor->x, &cell_cursor->y); + cell_cursor->w = w; + cell_cursor->h = h; - item->x1 = item_cursor->x; - item->y1 = item_cursor->y; - item->x2 = item_cursor->x+ w; - item->y2 = item_cursor->y + h; + item->x1 = cell_cursor->x; + item->y1 = cell_cursor->y; + item->x2 = cell_cursor->x + w; + item->y2 = cell_cursor->y + h; } @@ -205,7 +240,7 @@ gnucash_item_cursor_draw (GnomeCanvasItem *item, GdkDrawable *drawable, GDK_LINE_SOLID, -1, -1); gdk_gc_set_foreground (cursor->gc, &gn_black); gdk_gc_set_background (cursor->gc, &gn_white); - + gdk_draw_rectangle (drawable, cursor->gc, FALSE, dx+2, dy+2, dw-4, dh-4); gdk_draw_rectangle (drawable, cursor->gc, FALSE, diff --git a/src/register/gnome/gnucash-cursor.h b/src/register/gnome/gnucash-cursor.h index 92e8f63de0..29badad6e7 100644 --- a/src/register/gnome/gnucash-cursor.h +++ b/src/register/gnome/gnucash-cursor.h @@ -39,14 +39,16 @@ GtkType gnucash_item_cursor_get_type (void); GtkType gnucash_cursor_get_type (void); -enum { +enum +{ GNUCASH_CURSOR_CELL, GNUCASH_CURSOR_BLOCK, - GNUCASH_CURSOR_MAX, + GNUCASH_CURSOR_NUM }; -typedef struct { +typedef struct +{ GnomeCanvasItem canvas_item; gint type; @@ -55,8 +57,7 @@ typedef struct { gint col; /* precomputed pixel coords for the item cursor*/ - gint x, y, w, h; - + gint x, y, w, h; } GnucashItemCursor; @@ -64,20 +65,21 @@ typedef struct { GnomeCanvasGroup canvas_group; - GnomeCanvasItem *cursor[GNUCASH_CURSOR_MAX]; + GnomeCanvasItem *cursor[GNUCASH_CURSOR_NUM]; GnucashSheet *sheet; GnucashGrid *grid; /* precomputed pixel coords for the block cursor*/ - gint x, y, w, h; + gint x, y, w, h; - GdkGC *gc; + GdkGC *gc; SheetBlockStyle *style; } GnucashCursor; -typedef struct { +typedef struct +{ GnomeCanvasItemClass parent_class; } GnucashItemCursorClass; @@ -90,7 +92,8 @@ typedef struct GnomeCanvasItem *gnucash_cursor_new (GnomeCanvasGroup *parent); -void gnucash_cursor_get_virt (GnucashCursor *cursor, VirtualLocation *virt_loc); +void gnucash_cursor_get_virt (GnucashCursor *cursor, + VirtualLocation *virt_loc); void gnucash_cursor_set (GnucashCursor *cursor, VirtualLocation virt_loc); diff --git a/src/register/gnome/gnucash-grid.c b/src/register/gnome/gnucash-grid.c index 36e3ccdb28..6b2ed28c35 100644 --- a/src/register/gnome/gnucash-grid.c +++ b/src/register/gnome/gnucash-grid.c @@ -251,6 +251,86 @@ gnucash_grid_find_loc_by_pixel (GnucashGrid *grid, gint x, gint y, return gnucash_grid_find_cell_by_pixel (grid, x, y, virt_loc); } +G_INLINE_FUNC void +draw_cell_line (GdkDrawable *drawable, + GdkGC *gc, GdkColor *bg_color, + int x1, int y1, int x2, int y2, + PhysicalCellBorderLineStyle style); + +G_INLINE_FUNC void +draw_cell_line (GdkDrawable *drawable, + GdkGC *gc, GdkColor *bg_color, + int x1, int y1, int x2, int y2, + PhysicalCellBorderLineStyle style) +{ + GdkColor *fg_color; + + switch (style) + { + case CELL_BORDER_LINE_NONE: + fg_color = bg_color; + break; + + case CELL_BORDER_LINE_LIGHT: + fg_color = &gn_light_gray; + break; + + case CELL_BORDER_LINE_NORMAL: + case CELL_BORDER_LINE_HEAVY: + fg_color = &gn_black; + break; + + default: + return; + } + + gdk_gc_set_foreground (gc, fg_color); + gdk_draw_line (drawable, gc, x1, y1, x2, y2); +} + +static void +get_cell_borders (GnucashSheet *sheet, VirtualLocation virt_loc, + PhysicalCellBorders *borders) +{ + VirtualLocation v_loc; + PhysicalCellBorders neighbor; + + gnucash_sheet_get_borders (sheet, virt_loc, borders); + + /* top */ + v_loc = virt_loc; + if (gnc_table_move_vertical_position (sheet->table, &v_loc, -1)) + { + gnucash_sheet_get_borders (sheet, v_loc, &neighbor); + borders->top = MAX (borders->top, neighbor.bottom); + } + + /* bottom */ + v_loc = virt_loc; + if (gnc_table_move_vertical_position (sheet->table, &v_loc, 1)) + { + gnucash_sheet_get_borders (sheet, v_loc, &neighbor); + borders->bottom = MAX (borders->bottom, neighbor.top); + } + + /* left */ + v_loc = virt_loc; + v_loc.phys_col_offset--; + if (gnc_table_virtual_loc_valid (sheet->table, v_loc, TRUE)) + { + gnucash_sheet_get_borders (sheet, v_loc, &neighbor); + borders->left = MAX (borders->left, neighbor.right); + } + + /* right */ + v_loc = virt_loc; + v_loc.phys_col_offset++; + if (gnc_table_virtual_loc_valid (sheet->table, v_loc, TRUE)) + { + gnucash_sheet_get_borders (sheet, v_loc, &neighbor); + borders->right = MAX (borders->right, neighbor.left); + } +} static void draw_cell (GnucashGrid *grid, @@ -260,6 +340,7 @@ draw_cell (GnucashGrid *grid, int x, int y, int width, int height) { Table *table = grid->sheet->table; + PhysicalCellBorders borders; const char *text; GdkFont *font; GdkColor *bg_color; @@ -267,7 +348,6 @@ draw_cell (GnucashGrid *grid, gint x_offset, y_offset; GdkRectangle rect; guint32 argb; - gint borders; gdk_gc_set_background (grid->gc, &gn_white); @@ -275,28 +355,30 @@ draw_cell (GnucashGrid *grid, bg_color = gnucash_color_argb_to_gdk (argb); gdk_gc_set_foreground (grid->gc, bg_color); - gdk_draw_rectangle (drawable, grid->gc, TRUE, x, y, width, height); + gdk_draw_rectangle (drawable, grid->gc, TRUE, + x + 1, y + 1, width - 1, height - 1); - gdk_gc_set_foreground (grid->gc, &gn_black); - - borders = gnucash_sheet_get_borders (grid->sheet, virt_loc); + get_cell_borders (grid->sheet, virt_loc, &borders); + /* top */ - if (borders & STYLE_BORDER_TOP) - gdk_draw_line (drawable, grid->gc, x, y, x+width, y); + draw_cell_line (drawable, grid->gc, bg_color, + x, y, x + width, y, + borders.top); /* right */ - if (borders & STYLE_BORDER_RIGHT) - gdk_draw_line (drawable, grid->gc, x+width, y, - x+width, y+height); + draw_cell_line (drawable, grid->gc, bg_color, + x + width, y, x + width, y + height, + borders.right); /* bottom */ - if (borders & STYLE_BORDER_BOTTOM) - gdk_draw_line (drawable, grid->gc, x+width, - y+height, x, y+height); + draw_cell_line (drawable, grid->gc, bg_color, + x + width, y + height, x, y + height, + borders.bottom); /* left */ - if (borders & STYLE_BORDER_LEFT) - gdk_draw_line (drawable, grid->gc, x, y+height, x, y); + draw_cell_line (drawable, grid->gc, bg_color, + x, y + height, x, y, + borders.left); /* dividing line */ if ((virt_loc.phys_row_offset == 0) && (table->dividing_row >= 0)) @@ -355,14 +437,14 @@ draw_cell (GnucashGrid *grid, x_offset = CELL_HPADDING; else { x_offset = width / 2; - x_offset -= gdk_string_measure (font, text) / 2; + x_offset -= gdk_string_measure(font, text) / 2; } break; } rect.x = x + CELL_HPADDING; rect.y = y + CELL_VPADDING; - rect.width = width - 2*CELL_HPADDING; + rect.width = width - 2 * CELL_HPADDING; rect.height = height; gdk_gc_set_clip_rectangle (grid->gc, &rect); @@ -428,7 +510,6 @@ draw_block (GnucashGrid *grid, } } -/* FIXME: this only does the first virtual column */ static void gnucash_grid_draw (GnomeCanvasItem *item, GdkDrawable *drawable, int x, int y, int width, int height) @@ -437,12 +518,8 @@ gnucash_grid_draw (GnomeCanvasItem *item, GdkDrawable *drawable, VirtualLocation virt_loc; SheetBlock *sheet_block; - g_return_if_fail(x >= 0); - g_return_if_fail(y >= 0); - - /* The default background */ - gdk_draw_rectangle (drawable, grid->fill_gc, TRUE, - 0, 0, width, height); + if (x < 0 || y < 0) + return; /* compute our initial values where we start drawing */ sheet_block = gnucash_grid_find_block_by_pixel (grid, x, y, diff --git a/src/register/gnome/gnucash-style.c b/src/register/gnome/gnucash-style.c index 19d9c211c6..f5783e2dea 100644 --- a/src/register/gnome/gnucash-style.c +++ b/src/register/gnome/gnucash-style.c @@ -43,7 +43,8 @@ GdkFont *gnucash_register_hint_font = NULL; static char *register_font_name = NULL; static char *register_hint_font_name = NULL; -static RegisterBorders reg_borders = 0; +static gboolean use_vertical_lines = TRUE; +static gboolean use_horizontal_lines = TRUE; static char * style_get_key (SheetBlockStyle *style) @@ -485,34 +486,45 @@ gnucash_sheet_styles_recompile(GnucashSheet *sheet) void -gnucash_style_set_register_borders (int reg_borders_new) +gnucash_style_config_register_borders (gboolean use_vertical_lines_in, + gboolean use_horizontal_lines_in) { - reg_borders = reg_borders_new; + use_vertical_lines = use_vertical_lines_in; + use_horizontal_lines = use_horizontal_lines_in; } -gint -gnucash_sheet_get_borders (GnucashSheet *sheet, VirtualLocation virt_loc) +void +gnucash_sheet_get_borders (GnucashSheet *sheet, VirtualLocation virt_loc, + PhysicalCellBorders *borders) { SheetBlockStyle *style; - gint borders; + PhysicalCellBorderLineStyle line_style; - g_return_val_if_fail (sheet != NULL, 0); - g_return_val_if_fail (GNUCASH_IS_SHEET (sheet), 0); + g_return_if_fail (sheet != NULL); + g_return_if_fail (GNUCASH_IS_SHEET (sheet)); - borders = reg_borders; + line_style = use_vertical_lines ? + CELL_BORDER_LINE_NORMAL : CELL_BORDER_LINE_NONE; + + borders->top = line_style; + borders->bottom = line_style; + + line_style = use_horizontal_lines ? + CELL_BORDER_LINE_NORMAL : CELL_BORDER_LINE_NONE; + + borders->left = line_style; + borders->right = line_style; if (virt_loc.phys_col_offset == 0) - return borders |= STYLE_BORDER_LEFT; + borders->left = CELL_BORDER_LINE_NORMAL; style = sheet->cursor_styles[CURSOR_TYPE_HEADER]; - if (style == NULL) - return borders; + if (style) + if (virt_loc.phys_col_offset == (style->ncols - 1)) + borders->right = CELL_BORDER_LINE_NORMAL; - if (virt_loc.phys_col_offset == (style->ncols - 1)) - return borders |= STYLE_BORDER_RIGHT; - - return borders; + gnc_table_get_borders (sheet->table, virt_loc, borders); } diff --git a/src/register/gnome/gnucash-style.h b/src/register/gnome/gnucash-style.h index add6e3f4b7..170cad91e1 100644 --- a/src/register/gnome/gnucash-style.h +++ b/src/register/gnome/gnucash-style.h @@ -26,13 +26,6 @@ #include "splitreg.h" #include "gnucash-sheet.h" -#define STYLE_BORDER_LEFT (1 << 0) -#define STYLE_BORDER_RIGHT (1 << 1) -#define STYLE_BORDER_TOP (1 << 2) -#define STYLE_BORDER_BOTTOM (1 << 3) - -typedef int RegisterBorders; - typedef struct { gint pixel_height; @@ -116,11 +109,13 @@ void gnucash_sheet_style_get_cell_pixel_rel_coords (SheetBlockStyle *style, gint *x, gint *y, gint *w, gint *h); -void gnucash_style_ref (SheetBlockStyle *style); +void gnucash_style_ref (SheetBlockStyle *style); void gnucash_style_unref (SheetBlockStyle *style); -void gnucash_style_set_register_borders (int reg_borders_new); -gint gnucash_sheet_get_borders (GnucashSheet *sheet, VirtualLocation virt_loc); +void gnucash_style_config_register_borders (gboolean use_vertical_lines, + gboolean use_horizontal_lines); +void gnucash_sheet_get_borders (GnucashSheet *sheet, VirtualLocation virt_loc, + PhysicalCellBorders *borders); void gnucash_sheet_get_header_widths (GnucashSheet *sheet, int *header_widths); void gnucash_sheet_set_header_widths (GnucashSheet *sheet, int *header_widths); diff --git a/src/register/splitreg.c b/src/register/splitreg.c index f5d2d38bbc..7349af96ee 100644 --- a/src/register/splitreg.c +++ b/src/register/splitreg.c @@ -308,6 +308,12 @@ set_cell (SplitRegister *reg, CellBlock *cursor, CellBlockCell *cb_cell; BasicCell *hcell; + cursor->start_col = MIN (cursor->start_col, col); + cursor->stop_col = MAX (cursor->stop_col, col); + + reg->cursor_header->start_col = MIN (reg->cursor_header->start_col, col); + reg->cursor_header->stop_col = MAX (reg->cursor_header->stop_col, col); + hcell = reg->header_cells[cell_type]; cb_cell = gnc_cellblock_get_cell (cursor, row, col); @@ -335,12 +341,6 @@ set_cell (SplitRegister *reg, CellBlock *cursor, } } -/* SET_CELL macro initializes cells in the register */ - -#define SET_CELL(NAME,col,row) { \ - set_cell (reg, curs, NAME##_CELL, row, col); \ -} - static void copy_cursor_row (SplitRegister *reg, CellBlock *to, CellBlock *from, int row) { @@ -408,41 +408,41 @@ configLayout (SplitRegister *reg) case EQUITY_REGISTER: { curs = reg->cursor_ledger_single; - SET_CELL (DATE, 0, 0); - SET_CELL (NUM, 1, 0); - SET_CELL (DESC, 2, 0); - SET_CELL (MXFRM, 3, 0); - SET_CELL (RECN, 4, 0); - SET_CELL (DEBT, 5, 0); - SET_CELL (CRED, 6, 0); - SET_CELL (BALN, 7, 0); + set_cell (reg, curs, DATE_CELL, 0, 0); + set_cell (reg, curs, NUM_CELL, 0, 1); + set_cell (reg, curs, DESC_CELL, 0, 2); + set_cell (reg, curs, MXFRM_CELL, 0, 3); + set_cell (reg, curs, RECN_CELL, 0, 4); + set_cell (reg, curs, DEBT_CELL, 0, 5); + set_cell (reg, curs, CRED_CELL, 0, 6); + set_cell (reg, curs, BALN_CELL, 0, 7); curs = reg->cursor_ledger_double; copy_cursor_row (reg, curs, reg->cursor_ledger_single, 0); - SET_CELL (ACTN, 1, 1); - SET_CELL (MEMO, 2, 1); + set_cell (reg, curs, ACTN_CELL, 1, 1); + set_cell (reg, curs, MEMO_CELL, 1, 2); curs = reg->cursor_journal_single; - SET_CELL (DATE, 0, 0); - SET_CELL (NUM, 1, 0); - SET_CELL (DESC, 2, 0); - SET_CELL (RECN, 4, 0); - SET_CELL (DEBT, 5, 0); - SET_CELL (CRED, 6, 0); - SET_CELL (BALN, 7, 0); + set_cell (reg, curs, DATE_CELL, 0, 0); + set_cell (reg, curs, NUM_CELL, 0, 1); + set_cell (reg, curs, DESC_CELL, 0, 2); + set_cell (reg, curs, RECN_CELL, 0, 4); + set_cell (reg, curs, DEBT_CELL, 0, 5); + set_cell (reg, curs, CRED_CELL, 0, 6); + set_cell (reg, curs, BALN_CELL, 0, 7); curs = reg->cursor_journal_double; copy_cursor_row (reg, curs, reg->cursor_journal_single, 0); - SET_CELL (MEMO, 2, 1); + set_cell (reg, curs, MEMO_CELL, 1, 2); curs = reg->cursor_split; - SET_CELL (ACTN, 1, 0); - SET_CELL (MEMO, 2, 0); - SET_CELL (XFRM, 3, 0); - SET_CELL (DEBT, 5, 0); - SET_CELL (CRED, 6, 0); + set_cell (reg, curs, ACTN_CELL, 0, 1); + set_cell (reg, curs, MEMO_CELL, 0, 2); + set_cell (reg, curs, XFRM_CELL, 0, 3); + set_cell (reg, curs, DEBT_CELL, 0, 5); + set_cell (reg, curs, CRED_CELL, 0, 6); break; } @@ -453,41 +453,41 @@ configLayout (SplitRegister *reg) case SEARCH_LEDGER: { curs = reg->cursor_ledger_single; - SET_CELL (DATE, 0, 0); - SET_CELL (NUM, 1, 0); - SET_CELL (DESC, 2, 0); - SET_CELL (XTO, 3, 0); - SET_CELL (MXFRM, 4, 0); - SET_CELL (RECN, 5, 0); - SET_CELL (DEBT, 6, 0); - SET_CELL (CRED, 7, 0); + set_cell (reg, curs, DATE_CELL, 0, 0); + set_cell (reg, curs, NUM_CELL, 0, 1); + set_cell (reg, curs, DESC_CELL, 0, 2); + set_cell (reg, curs, XTO_CELL, 0, 3); + set_cell (reg, curs, MXFRM_CELL, 0, 4); + set_cell (reg, curs, RECN_CELL, 0, 5); + set_cell (reg, curs, DEBT_CELL, 0, 6); + set_cell (reg, curs, CRED_CELL, 0, 7); curs = reg->cursor_ledger_double; copy_cursor_row (reg, curs, reg->cursor_ledger_single, 0); - SET_CELL (ACTN, 1, 1); - SET_CELL (MEMO, 2, 1); + set_cell (reg, curs, ACTN_CELL, 1, 1); + set_cell (reg, curs, MEMO_CELL, 1, 2); curs = reg->cursor_journal_single; - SET_CELL (DATE, 0, 0); - SET_CELL (NUM, 1, 0); - SET_CELL (DESC, 2, 0); - SET_CELL (XTO, 3, 0); - SET_CELL (RECN, 5, 0); - SET_CELL (DEBT, 6, 0); - SET_CELL (CRED, 7, 0); + set_cell (reg, curs, DATE_CELL, 0, 0); + set_cell (reg, curs, NUM_CELL, 0, 1); + set_cell (reg, curs, DESC_CELL, 0, 2); + set_cell (reg, curs, XTO_CELL, 0, 3); + set_cell (reg, curs, RECN_CELL, 0, 5); + set_cell (reg, curs, DEBT_CELL, 0, 6); + set_cell (reg, curs, CRED_CELL, 0, 7); curs = reg->cursor_journal_double; copy_cursor_row (reg, curs, reg->cursor_journal_single, 0); - SET_CELL (MEMO, 2, 1); + set_cell (reg, curs, MEMO_CELL, 1, 2); curs = reg->cursor_split; - SET_CELL (ACTN, 1, 0); - SET_CELL (MEMO, 2, 0); - SET_CELL (XFRM, 4, 0); - SET_CELL (DEBT, 6, 0); - SET_CELL (CRED, 7, 0); + set_cell (reg, curs, ACTN_CELL, 0, 1); + set_cell (reg, curs, MEMO_CELL, 0, 2); + set_cell (reg, curs, XFRM_CELL, 0, 4); + set_cell (reg, curs, DEBT_CELL, 0, 6); + set_cell (reg, curs, CRED_CELL, 0, 7); break; } @@ -497,47 +497,47 @@ configLayout (SplitRegister *reg) case CURRENCY_REGISTER: { curs = reg->cursor_ledger_single; - SET_CELL (DATE, 0, 0); - SET_CELL (NUM, 1, 0); - SET_CELL (DESC, 2, 0); - SET_CELL (MXFRM, 3, 0); - SET_CELL (RECN, 4, 0); - SET_CELL (SHRS, 5, 0); - SET_CELL (PRIC, 6, 0); - SET_CELL (DEBT, 7, 0); - SET_CELL (CRED, 8, 0); - SET_CELL (SHRBALN, 9, 0); - SET_CELL (BALN, 10, 0); + set_cell (reg, curs, DATE_CELL, 0, 0); + set_cell (reg, curs, NUM_CELL, 0, 1); + set_cell (reg, curs, DESC_CELL, 0, 2); + set_cell (reg, curs, MXFRM_CELL, 0, 3); + set_cell (reg, curs, RECN_CELL, 0, 4); + set_cell (reg, curs, SHRS_CELL, 0, 5); + set_cell (reg, curs, PRIC_CELL, 0, 6); + set_cell (reg, curs, DEBT_CELL, 0, 7); + set_cell (reg, curs, CRED_CELL, 0, 8); + set_cell (reg, curs, SHRBALN_CELL, 0, 9); + set_cell (reg, curs, BALN_CELL, 0, 10); curs = reg->cursor_ledger_double; copy_cursor_row (reg, curs, reg->cursor_ledger_single, 0); - SET_CELL (ACTN, 1, 1); - SET_CELL (MEMO, 2, 1); + set_cell (reg, curs, ACTN_CELL, 1, 1); + set_cell (reg, curs, MEMO_CELL, 1, 2); curs = reg->cursor_journal_single; - SET_CELL (DATE, 0, 0); - SET_CELL (NUM, 1, 0); - SET_CELL (DESC, 2, 0); - SET_CELL (RECN, 4, 0); - SET_CELL (SHRS, 5, 0); - SET_CELL (PRIC, 6, 0); - SET_CELL (DEBT, 7, 0); - SET_CELL (CRED, 8, 0); - SET_CELL (SHRBALN, 9, 0); - SET_CELL (BALN, 10, 0); + set_cell (reg, curs, DATE_CELL, 0, 0); + set_cell (reg, curs, NUM_CELL, 0, 1); + set_cell (reg, curs, DESC_CELL, 0, 2); + set_cell (reg, curs, RECN_CELL, 0, 4); + set_cell (reg, curs, SHRS_CELL, 0, 5); + set_cell (reg, curs, PRIC_CELL, 0, 6); + set_cell (reg, curs, DEBT_CELL, 0, 7); + set_cell (reg, curs, CRED_CELL, 0, 8); + set_cell (reg, curs, SHRBALN_CELL, 0, 9); + set_cell (reg, curs, BALN_CELL, 0, 10); curs = reg->cursor_journal_double; copy_cursor_row (reg, curs, reg->cursor_journal_single, 0); - SET_CELL (MEMO, 2, 1); + set_cell (reg, curs, MEMO_CELL, 1, 2); curs = reg->cursor_split; - SET_CELL (ACTN, 1, 0); - SET_CELL (MEMO, 2, 0); - SET_CELL (XFRM, 3, 0); - SET_CELL (DEBT, 7, 0); - SET_CELL (CRED, 8, 0); + set_cell (reg, curs, ACTN_CELL, 0, 1); + set_cell (reg, curs, MEMO_CELL, 0, 2); + set_cell (reg, curs, XFRM_CELL, 0, 3); + set_cell (reg, curs, DEBT_CELL, 0, 7); + set_cell (reg, curs, CRED_CELL, 0, 8); break; } @@ -546,47 +546,47 @@ configLayout (SplitRegister *reg) case PORTFOLIO_LEDGER: { curs = reg->cursor_ledger_single; - SET_CELL (DATE, 0, 0); - SET_CELL (NUM, 1, 0); - SET_CELL (DESC, 2, 0); - SET_CELL (XTO, 3, 0); - SET_CELL (MXFRM, 4, 0); - SET_CELL (RECN, 5, 0); - SET_CELL (SHRS, 6, 0); - SET_CELL (PRIC, 7, 0); - SET_CELL (DEBT, 8, 0); - SET_CELL (CRED, 9, 0); - SET_CELL (SHRBALN, 10, 0); + set_cell (reg, curs, DATE_CELL, 0, 0); + set_cell (reg, curs, NUM_CELL, 0, 1); + set_cell (reg, curs, DESC_CELL, 0, 2); + set_cell (reg, curs, XTO_CELL, 0, 3); + set_cell (reg, curs, MXFRM_CELL, 0, 4); + set_cell (reg, curs, RECN_CELL, 0, 5); + set_cell (reg, curs, SHRS_CELL, 0, 6); + set_cell (reg, curs, PRIC_CELL, 0, 7); + set_cell (reg, curs, DEBT_CELL, 0, 8); + set_cell (reg, curs, CRED_CELL, 0, 9); + set_cell (reg, curs, SHRBALN_CELL, 0, 10); curs = reg->cursor_ledger_double; copy_cursor_row (reg, curs, reg->cursor_ledger_single, 0); - SET_CELL (ACTN, 1, 1); - SET_CELL (MEMO, 2, 1); + set_cell (reg, curs, ACTN_CELL, 1, 1); + set_cell (reg, curs, MEMO_CELL, 1, 2); curs = reg->cursor_journal_single; - SET_CELL (DATE, 0, 0); - SET_CELL (NUM, 1, 0); - SET_CELL (DESC, 2, 0); - SET_CELL (XTO, 3, 0); - SET_CELL (RECN, 5, 0); - SET_CELL (SHRS, 6, 0); - SET_CELL (PRIC, 7, 0); - SET_CELL (DEBT, 8, 0); - SET_CELL (CRED, 9, 0); - SET_CELL (SHRBALN, 10, 0); + set_cell (reg, curs, DATE_CELL, 0, 0); + set_cell (reg, curs, NUM_CELL, 0, 1); + set_cell (reg, curs, DESC_CELL, 0, 2); + set_cell (reg, curs, XTO_CELL, 0, 3); + set_cell (reg, curs, RECN_CELL, 0, 5); + set_cell (reg, curs, SHRS_CELL, 0, 6); + set_cell (reg, curs, PRIC_CELL, 0, 7); + set_cell (reg, curs, DEBT_CELL, 0, 8); + set_cell (reg, curs, CRED_CELL, 0, 9); + set_cell (reg, curs, SHRBALN_CELL, 0, 10); curs = reg->cursor_journal_double; copy_cursor_row (reg, curs, reg->cursor_journal_single, 0); - SET_CELL (MEMO, 2, 1); + set_cell (reg, curs, MEMO_CELL, 1, 2); curs = reg->cursor_split; - SET_CELL (ACTN, 1, 0); - SET_CELL (MEMO, 2, 0); - SET_CELL (XFRM, 4, 0); - SET_CELL (DEBT, 8, 0); - SET_CELL (CRED, 9, 0); + set_cell (reg, curs, ACTN_CELL, 0, 1); + set_cell (reg, curs, MEMO_CELL, 0, 2); + set_cell (reg, curs, XFRM_CELL, 0, 4); + set_cell (reg, curs, DEBT_CELL, 0, 8); + set_cell (reg, curs, CRED_CELL, 0, 9); break; } @@ -683,6 +683,30 @@ mallocCursors (SplitRegister *reg) /* ============================================== */ +static void +sr_get_cell_borders (VirtualLocation virt_loc, + PhysicalCellBorders *borders, + gpointer user_data) +{ + SplitRegister *reg = user_data; + VirtualCell *vcell; + + vcell = gnc_table_get_virtual_cell (reg->table, virt_loc.vcell_loc); + if (!vcell || !vcell->cellblock) + return; + + if ((virt_loc.phys_col_offset < vcell->cellblock->start_col) || + (virt_loc.phys_col_offset > vcell->cellblock->stop_col)) + { + borders->top = CELL_BORDER_LINE_NONE; + borders->bottom = CELL_BORDER_LINE_NONE; + borders->left = CELL_BORDER_LINE_NONE; + borders->right = CELL_BORDER_LINE_NONE; + } +} + +/* ============================================== */ + #define NEW(NAME, CN, TYPE) \ reg->CN##Cell = xaccMalloc##TYPE##Cell(); \ reg->cells[NAME##_CELL] = (BasicCell *) reg->CN##Cell; @@ -733,7 +757,6 @@ xaccInitSplitRegister (SplitRegister *reg, NEW (RECN, recn, Recn); NEW (SHRBALN, shrbaln, Price); NEW (BALN, balance, Price); - NEW (XFRM, xfrm, Combo); NEW (MXFRM, mxfrm, Combo); NEW (XTO, xto, Combo); @@ -847,8 +870,14 @@ xaccInitSplitRegister (SplitRegister *reg, /* add menu items for the action cell */ configAction (reg); - table = gnc_table_new (entry_handler, fg_color_handler, bg_color_handler, - reg, allocator, deallocator, copy); + table = gnc_table_new (entry_handler, + fg_color_handler, + bg_color_handler, + sr_get_cell_borders, + reg, + allocator, + deallocator, + copy); /* Set up header */ { diff --git a/src/register/table-allgui.c b/src/register/table-allgui.c index 024277fe7c..c8ec350f2e 100644 --- a/src/register/table-allgui.c +++ b/src/register/table-allgui.c @@ -62,6 +62,7 @@ Table * gnc_table_new (TableGetEntryHandler entry_handler, TableGetFGColorHandler fg_color_handler, TableGetBGColorHandler bg_color_handler, + TableGetCellBorderHandler cell_border_handler, gpointer handler_user_data, VirtCellDataAllocator allocator, VirtCellDataDeallocator deallocator, @@ -76,6 +77,7 @@ gnc_table_new (TableGetEntryHandler entry_handler, table->entry_handler = entry_handler; table->fg_color_handler = fg_color_handler; table->bg_color_handler = bg_color_handler; + table->cell_border_handler = cell_border_handler; table->handler_user_data = handler_user_data; table->vcell_data_allocator = allocator; table->vcell_data_deallocator = deallocator; @@ -263,6 +265,18 @@ gnc_table_get_bg_color (Table *table, VirtualLocation virt_loc) /* ==================================================== */ +void +gnc_table_get_borders (Table *table, VirtualLocation virt_loc, + PhysicalCellBorders *borders) +{ + if (!table->cell_border_handler) + return; + + table->cell_border_handler (virt_loc, borders, table->handler_user_data); +} + +/* ==================================================== */ + CellAlignment gnc_table_get_align (Table *table, VirtualLocation virt_loc) { @@ -877,7 +891,7 @@ gnc_table_leave_update(Table *table, VirtualLocation virt_loc) int cell_col; if (table == NULL) - return NULL; + return; cb = table->current_cursor; diff --git a/src/register/table-allgui.h b/src/register/table-allgui.h index 81398e7d4f..b73d5a3146 100644 --- a/src/register/table-allgui.h +++ b/src/register/table-allgui.h @@ -96,7 +96,8 @@ #include "gtable.h" -typedef enum { +typedef enum +{ GNC_TABLE_TRAVERSE_POINTER, GNC_TABLE_TRAVERSE_LEFT, GNC_TABLE_TRAVERSE_RIGHT, @@ -118,6 +119,23 @@ struct _VirtualCell }; +typedef enum +{ + CELL_BORDER_LINE_NONE, + CELL_BORDER_LINE_LIGHT, + CELL_BORDER_LINE_NORMAL, + CELL_BORDER_LINE_HEAVY +} PhysicalCellBorderLineStyle; + +typedef struct +{ + PhysicalCellBorderLineStyle top; + PhysicalCellBorderLineStyle bottom; + PhysicalCellBorderLineStyle left; + PhysicalCellBorderLineStyle right; +} PhysicalCellBorders; + + typedef struct _Table Table; typedef void (*TableMoveFunc) (Table *table, @@ -142,6 +160,10 @@ typedef guint32 (*TableGetFGColorHandler) (VirtualLocation virt_loc, typedef guint32 (*TableGetBGColorHandler) (VirtualLocation virt_loc, gpointer user_data); +typedef void (*TableGetCellBorderHandler) (VirtualLocation virt_loc, + PhysicalCellBorders *borders, + gpointer user_data); + typedef gpointer (*VirtCellDataAllocator) (void); typedef void (*VirtCellDataDeallocator) (gpointer user_data); typedef void (*VirtCellDataCopy) (gpointer to, gconstpointer from); @@ -190,6 +212,7 @@ struct _Table TableGetEntryHandler entry_handler; TableGetFGColorHandler fg_color_handler; TableGetBGColorHandler bg_color_handler; + TableGetCellBorderHandler cell_border_handler; gpointer handler_user_data; @@ -205,6 +228,7 @@ struct _Table Table * gnc_table_new (TableGetEntryHandler entry_handler, TableGetFGColorHandler fg_color_handler, TableGetBGColorHandler bg_color_handler, + TableGetCellBorderHandler cell_border_handler, gpointer handler_user_data, VirtCellDataAllocator allocator, VirtCellDataDeallocator deallocator, @@ -245,6 +269,9 @@ guint32 gnc_table_get_fg_color (Table *table, VirtualLocation virt_loc); guint32 gnc_table_get_bg_color (Table *table, VirtualLocation virt_loc); +void gnc_table_get_borders (Table *table, VirtualLocation virt_loc, + PhysicalCellBorders *borders); + CellAlignment gnc_table_get_align (Table *table, VirtualLocation virt_loc); /* Return the virtual cell of the header */