Remove cached cell styles.

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@3027 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Dave Peticolas 2000-10-06 22:50:43 +00:00
parent ddba24dfe7
commit 2120e4867a
8 changed files with 62 additions and 138 deletions

View File

@ -259,7 +259,6 @@ draw_cell (GnucashGrid *grid, int block,
Table *table = grid->sheet->table; Table *table = grid->sheet->table;
const char *text; const char *text;
GdkFont *font; GdkFont *font;
CellStyle *cs;
SheetBlock *sheet_block; SheetBlock *sheet_block;
VirtualLocation virt_loc; VirtualLocation virt_loc;
GdkColor *bg_color; GdkColor *bg_color;
@ -267,6 +266,7 @@ draw_cell (GnucashGrid *grid, int block,
gint x_offset, y_offset; gint x_offset, y_offset;
GdkRectangle rect; GdkRectangle rect;
guint32 argb; guint32 argb;
gint borders;
virt_loc.vcell_loc.virt_row = block; virt_loc.vcell_loc.virt_row = block;
virt_loc.vcell_loc.virt_col = 0; virt_loc.vcell_loc.virt_col = 0;
@ -286,24 +286,23 @@ draw_cell (GnucashGrid *grid, int block,
gdk_gc_set_foreground (grid->gc, &gn_black); gdk_gc_set_foreground (grid->gc, &gn_black);
cs = gnucash_style_get_cell_style (style, i, j); borders = gnucash_sheet_get_borders (grid->sheet, virt_loc);
/* top */ /* top */
if (cs->border & STYLE_BORDER_TOP) if (borders & STYLE_BORDER_TOP)
gdk_draw_line (drawable, grid->gc, x, y, x+width, y); gdk_draw_line (drawable, grid->gc, x, y, x+width, y);
/* right */ /* right */
if (cs->border & STYLE_BORDER_RIGHT) if (borders & STYLE_BORDER_RIGHT)
gdk_draw_line (drawable, grid->gc, x+width, y, gdk_draw_line (drawable, grid->gc, x+width, y,
x+width, y+height); x+width, y+height);
/* bottom */ /* bottom */
if (cs->border & STYLE_BORDER_BOTTOM) if (borders & STYLE_BORDER_BOTTOM)
gdk_draw_line (drawable, grid->gc, x+width, gdk_draw_line (drawable, grid->gc, x+width,
y+height, x, y+height); y+height, x, y+height);
/* left */ /* left */
if (cs->border & STYLE_BORDER_LEFT) if (borders & STYLE_BORDER_LEFT)
gdk_draw_line (drawable, grid->gc, x, y+height, x, y); gdk_draw_line (drawable, grid->gc, x, y+height, x, y);
/* dividing line */ /* dividing line */
@ -347,16 +346,16 @@ draw_cell (GnucashGrid *grid, int block,
y_offset = height - MAX(CELL_VPADDING, font->descent + 4); y_offset = height - MAX(CELL_VPADDING, font->descent + 4);
switch (cs->alignment) { switch (gnc_table_get_align (table, virt_loc)) {
default: default:
case GTK_JUSTIFY_LEFT: case CELL_ALIGN_LEFT:
x_offset = CELL_HPADDING; x_offset = CELL_HPADDING;
break; break;
case GTK_JUSTIFY_RIGHT: case CELL_ALIGN_RIGHT:
x_offset = width - CELL_HPADDING x_offset = width - CELL_HPADDING
- gdk_string_measure (font, text); - gdk_string_measure (font, text);
break; break;
case GTK_JUSTIFY_CENTER: case CELL_ALIGN_CENTER:
if (width < gdk_string_measure (font, text)) if (width < gdk_string_measure (font, text))
x_offset = CELL_HPADDING; x_offset = CELL_HPADDING;
else { else {

View File

@ -74,7 +74,6 @@ gnucash_header_draw (GnomeCanvasItem *item, GdkDrawable *drawable,
int w = 0, h = 0; int w = 0, h = 0;
const char *text; const char *text;
GdkFont *font; GdkFont *font;
CellStyle *cs;
GdkColor *bg_color; GdkColor *bg_color;
guint32 argb; guint32 argb;
@ -123,7 +122,6 @@ gnucash_header_draw (GnomeCanvasItem *item, GdkDrawable *drawable,
virt_loc.phys_col_offset = j; virt_loc.phys_col_offset = j;
cd = gnucash_style_get_cell_dimensions (style, i, j); cd = gnucash_style_get_cell_dimensions (style, i, j);
cs = gnucash_style_get_cell_style (style, i, j);
if (header->in_resize && (j == header->resize_col)) if (header->in_resize && (j == header->resize_col))
w = header->resize_col_width; w = header->resize_col_width;
@ -143,16 +141,16 @@ gnucash_header_draw (GnomeCanvasItem *item, GdkDrawable *drawable,
y_offset = h - MAX(CELL_VPADDING, font->descent + 4); y_offset = h - MAX(CELL_VPADDING, font->descent + 4);
switch (cs->alignment) { switch (gnc_table_get_align (table, virt_loc)) {
default: default:
case GTK_JUSTIFY_LEFT: case CELL_ALIGN_LEFT:
x_offset = CELL_HPADDING; x_offset = CELL_HPADDING;
break; break;
case GTK_JUSTIFY_RIGHT: case CELL_ALIGN_RIGHT:
x_offset = w - CELL_HPADDING; x_offset = w - CELL_HPADDING;
x_offset -= gdk_string_measure(font, text); x_offset -= gdk_string_measure(font, text);
break; break;
case GTK_JUSTIFY_CENTER: case CELL_ALIGN_CENTER:
if (w < gdk_string_measure (font, text)) if (w < gdk_string_measure (font, text))
x_offset = CELL_HPADDING; x_offset = CELL_HPADDING;
else { else {

View File

@ -118,10 +118,8 @@ item_edit_get_pixel_coords (ItemEdit *item_edit,
static void static void
item_edit_draw_info(ItemEdit *item_edit, int x, int y, TextDrawInfo *info) item_edit_draw_info(ItemEdit *item_edit, int x, int y, TextDrawInfo *info)
{ {
GtkJustification align;
SheetBlockStyle *style; SheetBlockStyle *style;
GtkEditable *editable; GtkEditable *editable;
CellStyle *cs;
Table *table; Table *table;
int text_len, total_width; int text_len, total_width;
@ -138,10 +136,6 @@ item_edit_draw_info(ItemEdit *item_edit, int x, int y, TextDrawInfo *info)
info->font = GNUCASH_GRID(item_edit->sheet->grid)->normal_font; info->font = GNUCASH_GRID(item_edit->sheet->grid)->normal_font;
cs = gnucash_style_get_cell_style (style,
item_edit->virt_loc.phys_row_offset,
item_edit->virt_loc.phys_col_offset);
argb = gnc_table_get_bg_color (table, item_edit->virt_loc); argb = gnc_table_get_bg_color (table, item_edit->virt_loc);
info->bg_color = gnucash_color_argb_to_gdk (argb); info->bg_color = gnucash_color_argb_to_gdk (argb);
@ -184,8 +178,6 @@ item_edit_draw_info(ItemEdit *item_edit, int x, int y, TextDrawInfo *info)
info->bg_rect.width = wd - (2 * CELL_HPADDING); info->bg_rect.width = wd - (2 * CELL_HPADDING);
info->bg_rect.height = hd - (2 * CELL_VPADDING - info->font->descent); info->bg_rect.height = hd - (2 * CELL_VPADDING - info->font->descent);
align = cs->alignment;
toggle_space = (item_edit->is_combo) ? toggle_space = (item_edit->is_combo) ?
item_edit->combo_toggle.toggle_offset : 0; item_edit->combo_toggle.toggle_offset : 0;
@ -194,15 +186,13 @@ item_edit_draw_info(ItemEdit *item_edit, int x, int y, TextDrawInfo *info)
info->text_rect.width = wd - toggle_space; info->text_rect.width = wd - toggle_space;
info->text_rect.height = hd - (2*CELL_VPADDING - info->font->descent); info->text_rect.height = hd - (2*CELL_VPADDING - info->font->descent);
switch (align) { switch (gnc_table_get_align (table, item_edit->virt_loc)) {
case GTK_JUSTIFY_RIGHT: case CELL_ALIGN_RIGHT:
xoffset = info->text_rect.width - xoffset = info->text_rect.width -
(2*CELL_HPADDING + total_width); (2*CELL_HPADDING + total_width);
if (xoffset > 0) if (xoffset > 0)
break; break;
default: default:
case GTK_JUSTIFY_LEFT:
case GTK_JUSTIFY_CENTER:
xoffset = MIN (CELL_HPADDING, xoffset = MIN (CELL_HPADDING,
info->text_rect.width - info->text_rect.width -
(2*CELL_HPADDING + pre_cursor_width)); (2*CELL_HPADDING + pre_cursor_width));
@ -489,17 +479,11 @@ item_edit_set_cursor_pos (ItemEdit *item_edit,
editable = GTK_EDITABLE (item_edit->editor); editable = GTK_EDITABLE (item_edit->editor);
if (changed_cells) { if (changed_cells) {
GtkJustification align; CellAlignment align;
CellStyle *cs;
cs = gnucash_style_get_cell_style align = gnc_table_get_align (table, item_edit->virt_loc);
(item_edit->style,
item_edit->virt_loc.phys_row_offset,
item_edit->virt_loc.phys_col_offset);
align = cs->alignment; if (align == CELL_ALIGN_RIGHT)
if (align == GTK_JUSTIFY_RIGHT)
gtk_editable_set_position(editable, -1); gtk_editable_set_position(editable, -1);
else else
gtk_editable_set_position(editable, 0); gtk_editable_set_position(editable, 0);

View File

@ -114,6 +114,8 @@ typedef struct {
gint alignment; gint alignment;
gint cell_borders;
gint editing; gint editing;
gint button; /* mouse button being held down */ gint button; /* mouse button being held down */

View File

@ -482,41 +482,13 @@ static void
gnucash_sheet_style_recompile(SheetBlockStyle *style, gint cursor_type) gnucash_sheet_style_recompile(SheetBlockStyle *style, gint cursor_type)
{ {
CellBlock *cursor; CellBlock *cursor;
gint i, j, type;
g_assert (style != NULL); g_assert (style != NULL);
g_assert (style->cursor != NULL); g_assert (style->cursor != NULL);
cursor = style->cursor; cursor = style->cursor;
for (i = 0; i < style->nrows; i++) {
for (j = 0; j < style->ncols; j++) {
CellBlockCell *cb_cell;
CellStyle *cs;
cb_cell = gnc_cellblock_get_cell (cursor, i, j);
cs = gnucash_style_get_cell_style (style, i, j);
type = cb_cell->cell_type;
style->header_font = gnucash_register_font; style->header_font = gnucash_register_font;
gnucash_style_set_borders (style, reg_borders);
switch (cb_cell->alignment) {
case CELL_ALIGN_RIGHT:
cs->alignment = GTK_JUSTIFY_RIGHT;
break;
case CELL_ALIGN_CENTER:
cs->alignment = GTK_JUSTIFY_CENTER;
break;
default:
case CELL_ALIGN_LEFT:
cs->alignment = GTK_JUSTIFY_LEFT;
break;
}
}
}
} }
void void
@ -531,21 +503,6 @@ gnucash_sheet_styles_recompile(GnucashSheet *sheet)
gnucash_sheet_style_recompile (sheet->cursor_styles[i], i); gnucash_sheet_style_recompile (sheet->cursor_styles[i], i);
} }
void
gnucash_style_set_cell_borders (SheetBlockStyle *style,
int row, int col, int border)
{
CellStyle *cs;
if (style == NULL)
return;
cs = gnucash_style_get_cell_style (style, row, col);
if (cs == NULL)
return;
cs->border = border;
}
void void
gnucash_style_set_register_borders (int reg_borders_new) gnucash_style_set_register_borders (int reg_borders_new)
@ -554,49 +511,31 @@ gnucash_style_set_register_borders (int reg_borders_new)
} }
void gint
gnucash_style_set_borders (SheetBlockStyle *style, int border) gnucash_sheet_get_borders (GnucashSheet *sheet, VirtualLocation virt_loc)
{ {
int row, col; SheetBlockStyle *style;
gint borders;
g_return_if_fail (style != NULL); g_return_val_if_fail (sheet != NULL, 0);
g_return_val_if_fail (GNUCASH_IS_SHEET (sheet), 0);
for (row = 0; row < style->nrows; row++) { borders = reg_borders;
CellStyle *cs;
for (col = 0; col < style->ncols; col++) if (virt_loc.phys_col_offset == 0)
gnucash_style_set_cell_borders (style, row, col, return borders |= STYLE_BORDER_LEFT;
border);
cs = gnucash_style_get_cell_style (style, row, 0); style = sheet->cursor_styles[GNUCASH_CURSOR_HEADER];
cs->border |= STYLE_BORDER_LEFT;
cs = gnucash_style_get_cell_style (style, row,
style->ncols - 1);
cs->border |= STYLE_BORDER_RIGHT;
}
}
void
gnucash_sheet_set_borders (GnucashSheet *sheet, int border)
{
int i;
g_return_if_fail (GNUCASH_IS_SHEET (sheet));
for (i = 0; i < GNUCASH_NUM_CURSORS; i++)
gnucash_style_set_borders (sheet->cursor_styles[i], border);
}
CellStyle *
gnucash_style_get_cell_style (SheetBlockStyle *style, int row, int col)
{
if (style == NULL) if (style == NULL)
return NULL; return borders;
return g_table_index (style->cell_styles, row, col); if (virt_loc.phys_col_offset == (style->ncols - 1))
return borders |= STYLE_BORDER_RIGHT;
return borders;
} }
static SheetBlockStyle * static SheetBlockStyle *
gnucash_sheet_style_new (GnucashSheet *sheet, CellBlock *cursor, gnucash_sheet_style_new (GnucashSheet *sheet, CellBlock *cursor,
GNCCursorType cursor_type) GNCCursorType cursor_type)
@ -615,9 +554,6 @@ gnucash_sheet_style_new (GnucashSheet *sheet, CellBlock *cursor,
style->nrows = cursor->num_rows; style->nrows = cursor->num_rows;
style->ncols = cursor->num_cols; style->ncols = cursor->num_cols;
style->cell_styles = g_table_new (sizeof(CellStyle), NULL, NULL, NULL);
g_table_resize (style->cell_styles, style->nrows, style->ncols);
gnucash_sheet_style_recompile(style, cursor_type); gnucash_sheet_style_recompile(style, cursor_type);
gnucash_style_dimensions_init (sheet, style); gnucash_style_dimensions_init (sheet, style);
@ -655,9 +591,6 @@ gnucash_sheet_style_destroy (GnucashSheet *sheet, SheetBlockStyle *style)
if (style == NULL) if (style == NULL)
return; return;
g_table_destroy (style->cell_styles);
style->cell_styles = NULL;
style->dimensions->refcount--; style->dimensions->refcount--;
if (style->dimensions->refcount == 0) { if (style->dimensions->refcount == 0) {

View File

@ -59,12 +59,6 @@ typedef struct
gint refcount; gint refcount;
} BlockDimensions; } BlockDimensions;
typedef struct
{
GtkJustification alignment;
int border;
} CellStyle;
struct _SheetBlockStyle struct _SheetBlockStyle
{ {
CellBlock * cursor; CellBlock * cursor;
@ -72,13 +66,10 @@ struct _SheetBlockStyle
gint nrows; gint nrows;
gint ncols; gint ncols;
gint reg_type;
gint cursor_type; gint cursor_type;
BlockDimensions *dimensions; BlockDimensions *dimensions;
GTable *cell_styles;
GdkFont *header_font; GdkFont *header_font;
gint refcount; gint refcount;
@ -100,9 +91,6 @@ gint gnucash_style_col_is_resizable (SheetBlockStyle *style, int col);
CellDimensions * gnucash_style_get_cell_dimensions (SheetBlockStyle *style, CellDimensions * gnucash_style_get_cell_dimensions (SheetBlockStyle *style,
int row, int col); int row, int col);
CellStyle * gnucash_style_get_cell_style (SheetBlockStyle *style,
int row, int col);
void gnucash_sheet_set_col_width (GnucashSheet *sheet, int col, int width); void gnucash_sheet_set_col_width (GnucashSheet *sheet, int col, int width);
gint gnucash_style_row_width(SheetBlockStyle *style, int row); gint gnucash_style_row_width(SheetBlockStyle *style, int row);
@ -133,11 +121,8 @@ void gnucash_sheet_style_get_cell_pixel_rel_coords (SheetBlockStyle *style,
void gnucash_style_ref (SheetBlockStyle *style); void gnucash_style_ref (SheetBlockStyle *style);
void gnucash_style_unref (SheetBlockStyle *style); void gnucash_style_unref (SheetBlockStyle *style);
void gnucash_style_set_cell_borders (SheetBlockStyle *style,
int row, int col, int border);
void gnucash_style_set_register_borders (int reg_borders_new); void gnucash_style_set_register_borders (int reg_borders_new);
void gnucash_style_set_borders (SheetBlockStyle *style, int border); gint gnucash_sheet_get_borders (GnucashSheet *sheet, VirtualLocation virt_loc);
void gnucash_sheet_set_borders (GnucashSheet *sheet, int border);
void gnucash_sheet_get_header_widths (GnucashSheet *sheet, int *header_widths); void gnucash_sheet_get_header_widths (GnucashSheet *sheet, int *header_widths);
void gnucash_sheet_set_header_widths (GnucashSheet *sheet, int *header_widths); void gnucash_sheet_set_header_widths (GnucashSheet *sheet, int *header_widths);

View File

@ -328,6 +328,27 @@ gnc_table_get_bg_color (Table *table, VirtualLocation virt_loc)
/* ==================================================== */ /* ==================================================== */
CellAlignment
gnc_table_get_align (Table *table, VirtualLocation virt_loc)
{
VirtualCell *vcell;
CellBlockCell *cb_cell;
vcell = gnc_table_get_virtual_cell (table, virt_loc.vcell_loc);
if (vcell == NULL)
return CELL_ALIGN_RIGHT;
cb_cell = gnc_cellblock_get_cell (vcell->cellblock,
virt_loc.phys_row_offset,
virt_loc.phys_col_offset);
if (cb_cell == NULL)
return CELL_ALIGN_RIGHT;
return cb_cell->alignment;
}
/* ==================================================== */
void void
gnc_table_set_size (Table * table, int virt_rows, int virt_cols) gnc_table_set_size (Table * table, int virt_rows, int virt_cols)
{ {

View File

@ -236,6 +236,8 @@ guint32 gnc_table_get_fg_color (Table *table, VirtualLocation virt_loc);
guint32 gnc_table_get_bg_color (Table *table, VirtualLocation virt_loc); guint32 gnc_table_get_bg_color (Table *table, VirtualLocation virt_loc);
CellAlignment gnc_table_get_align (Table *table, VirtualLocation virt_loc);
/* Return the virtual cell of the header */ /* Return the virtual cell of the header */
VirtualCell * gnc_table_get_header_cell (Table *table); VirtualCell * gnc_table_get_header_cell (Table *table);