mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
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:
parent
ddba24dfe7
commit
2120e4867a
@ -259,7 +259,6 @@ draw_cell (GnucashGrid *grid, int block,
|
||||
Table *table = grid->sheet->table;
|
||||
const char *text;
|
||||
GdkFont *font;
|
||||
CellStyle *cs;
|
||||
SheetBlock *sheet_block;
|
||||
VirtualLocation virt_loc;
|
||||
GdkColor *bg_color;
|
||||
@ -267,6 +266,7 @@ draw_cell (GnucashGrid *grid, int block,
|
||||
gint x_offset, y_offset;
|
||||
GdkRectangle rect;
|
||||
guint32 argb;
|
||||
gint borders;
|
||||
|
||||
virt_loc.vcell_loc.virt_row = block;
|
||||
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);
|
||||
|
||||
cs = gnucash_style_get_cell_style (style, i, j);
|
||||
|
||||
borders = gnucash_sheet_get_borders (grid->sheet, virt_loc);
|
||||
/* top */
|
||||
if (cs->border & STYLE_BORDER_TOP)
|
||||
if (borders & STYLE_BORDER_TOP)
|
||||
gdk_draw_line (drawable, grid->gc, x, y, x+width, y);
|
||||
|
||||
/* right */
|
||||
if (cs->border & STYLE_BORDER_RIGHT)
|
||||
if (borders & STYLE_BORDER_RIGHT)
|
||||
gdk_draw_line (drawable, grid->gc, x+width, y,
|
||||
x+width, y+height);
|
||||
|
||||
/* bottom */
|
||||
if (cs->border & STYLE_BORDER_BOTTOM)
|
||||
if (borders & STYLE_BORDER_BOTTOM)
|
||||
gdk_draw_line (drawable, grid->gc, x+width,
|
||||
y+height, x, y+height);
|
||||
|
||||
/* left */
|
||||
if (cs->border & STYLE_BORDER_LEFT)
|
||||
if (borders & STYLE_BORDER_LEFT)
|
||||
gdk_draw_line (drawable, grid->gc, x, y+height, x, y);
|
||||
|
||||
/* dividing line */
|
||||
@ -347,16 +346,16 @@ draw_cell (GnucashGrid *grid, int block,
|
||||
|
||||
y_offset = height - MAX(CELL_VPADDING, font->descent + 4);
|
||||
|
||||
switch (cs->alignment) {
|
||||
switch (gnc_table_get_align (table, virt_loc)) {
|
||||
default:
|
||||
case GTK_JUSTIFY_LEFT:
|
||||
case CELL_ALIGN_LEFT:
|
||||
x_offset = CELL_HPADDING;
|
||||
break;
|
||||
case GTK_JUSTIFY_RIGHT:
|
||||
case CELL_ALIGN_RIGHT:
|
||||
x_offset = width - CELL_HPADDING
|
||||
- gdk_string_measure (font, text);
|
||||
break;
|
||||
case GTK_JUSTIFY_CENTER:
|
||||
case CELL_ALIGN_CENTER:
|
||||
if (width < gdk_string_measure (font, text))
|
||||
x_offset = CELL_HPADDING;
|
||||
else {
|
||||
|
@ -74,7 +74,6 @@ gnucash_header_draw (GnomeCanvasItem *item, GdkDrawable *drawable,
|
||||
int w = 0, h = 0;
|
||||
const char *text;
|
||||
GdkFont *font;
|
||||
CellStyle *cs;
|
||||
GdkColor *bg_color;
|
||||
guint32 argb;
|
||||
|
||||
@ -123,7 +122,6 @@ gnucash_header_draw (GnomeCanvasItem *item, GdkDrawable *drawable,
|
||||
virt_loc.phys_col_offset = 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))
|
||||
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);
|
||||
|
||||
switch (cs->alignment) {
|
||||
switch (gnc_table_get_align (table, virt_loc)) {
|
||||
default:
|
||||
case GTK_JUSTIFY_LEFT:
|
||||
case CELL_ALIGN_LEFT:
|
||||
x_offset = CELL_HPADDING;
|
||||
break;
|
||||
case GTK_JUSTIFY_RIGHT:
|
||||
case CELL_ALIGN_RIGHT:
|
||||
x_offset = w - CELL_HPADDING;
|
||||
x_offset -= gdk_string_measure(font, text);
|
||||
break;
|
||||
case GTK_JUSTIFY_CENTER:
|
||||
case CELL_ALIGN_CENTER:
|
||||
if (w < gdk_string_measure (font, text))
|
||||
x_offset = CELL_HPADDING;
|
||||
else {
|
||||
|
@ -118,10 +118,8 @@ item_edit_get_pixel_coords (ItemEdit *item_edit,
|
||||
static void
|
||||
item_edit_draw_info(ItemEdit *item_edit, int x, int y, TextDrawInfo *info)
|
||||
{
|
||||
GtkJustification align;
|
||||
SheetBlockStyle *style;
|
||||
GtkEditable *editable;
|
||||
CellStyle *cs;
|
||||
Table *table;
|
||||
|
||||
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;
|
||||
|
||||
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);
|
||||
|
||||
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.height = hd - (2 * CELL_VPADDING - info->font->descent);
|
||||
|
||||
align = cs->alignment;
|
||||
|
||||
toggle_space = (item_edit->is_combo) ?
|
||||
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.height = hd - (2*CELL_VPADDING - info->font->descent);
|
||||
|
||||
switch (align) {
|
||||
case GTK_JUSTIFY_RIGHT:
|
||||
switch (gnc_table_get_align (table, item_edit->virt_loc)) {
|
||||
case CELL_ALIGN_RIGHT:
|
||||
xoffset = info->text_rect.width -
|
||||
(2*CELL_HPADDING + total_width);
|
||||
if (xoffset > 0)
|
||||
break;
|
||||
default:
|
||||
case GTK_JUSTIFY_LEFT:
|
||||
case GTK_JUSTIFY_CENTER:
|
||||
xoffset = MIN (CELL_HPADDING,
|
||||
info->text_rect.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);
|
||||
|
||||
if (changed_cells) {
|
||||
GtkJustification align;
|
||||
CellStyle *cs;
|
||||
CellAlignment align;
|
||||
|
||||
cs = gnucash_style_get_cell_style
|
||||
(item_edit->style,
|
||||
item_edit->virt_loc.phys_row_offset,
|
||||
item_edit->virt_loc.phys_col_offset);
|
||||
align = gnc_table_get_align (table, item_edit->virt_loc);
|
||||
|
||||
align = cs->alignment;
|
||||
|
||||
if (align == GTK_JUSTIFY_RIGHT)
|
||||
if (align == CELL_ALIGN_RIGHT)
|
||||
gtk_editable_set_position(editable, -1);
|
||||
else
|
||||
gtk_editable_set_position(editable, 0);
|
||||
|
@ -114,6 +114,8 @@ typedef struct {
|
||||
|
||||
gint alignment;
|
||||
|
||||
gint cell_borders;
|
||||
|
||||
gint editing;
|
||||
|
||||
gint button; /* mouse button being held down */
|
||||
|
@ -482,41 +482,13 @@ static void
|
||||
gnucash_sheet_style_recompile(SheetBlockStyle *style, gint cursor_type)
|
||||
{
|
||||
CellBlock *cursor;
|
||||
gint i, j, type;
|
||||
|
||||
g_assert (style != NULL);
|
||||
g_assert (style->cursor != NULL);
|
||||
|
||||
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;
|
||||
|
||||
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
|
||||
@ -531,21 +503,6 @@ gnucash_sheet_styles_recompile(GnucashSheet *sheet)
|
||||
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
|
||||
gnucash_style_set_register_borders (int reg_borders_new)
|
||||
@ -554,49 +511,31 @@ 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)
|
||||
{
|
||||
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++) {
|
||||
CellStyle *cs;
|
||||
borders = reg_borders;
|
||||
|
||||
for (col = 0; col < style->ncols; col++)
|
||||
gnucash_style_set_cell_borders (style, row, col,
|
||||
border);
|
||||
if (virt_loc.phys_col_offset == 0)
|
||||
return borders |= STYLE_BORDER_LEFT;
|
||||
|
||||
cs = gnucash_style_get_cell_style (style, row, 0);
|
||||
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)
|
||||
{
|
||||
style = sheet->cursor_styles[GNUCASH_CURSOR_HEADER];
|
||||
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 *
|
||||
gnucash_sheet_style_new (GnucashSheet *sheet, CellBlock *cursor,
|
||||
GNCCursorType cursor_type)
|
||||
@ -615,9 +554,6 @@ gnucash_sheet_style_new (GnucashSheet *sheet, CellBlock *cursor,
|
||||
style->nrows = cursor->num_rows;
|
||||
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_style_dimensions_init (sheet, style);
|
||||
@ -655,9 +591,6 @@ gnucash_sheet_style_destroy (GnucashSheet *sheet, SheetBlockStyle *style)
|
||||
if (style == NULL)
|
||||
return;
|
||||
|
||||
g_table_destroy (style->cell_styles);
|
||||
style->cell_styles = NULL;
|
||||
|
||||
style->dimensions->refcount--;
|
||||
|
||||
if (style->dimensions->refcount == 0) {
|
||||
|
@ -59,12 +59,6 @@ typedef struct
|
||||
gint refcount;
|
||||
} BlockDimensions;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
GtkJustification alignment;
|
||||
int border;
|
||||
} CellStyle;
|
||||
|
||||
struct _SheetBlockStyle
|
||||
{
|
||||
CellBlock * cursor;
|
||||
@ -72,13 +66,10 @@ struct _SheetBlockStyle
|
||||
gint nrows;
|
||||
gint ncols;
|
||||
|
||||
gint reg_type;
|
||||
gint cursor_type;
|
||||
|
||||
BlockDimensions *dimensions;
|
||||
|
||||
GTable *cell_styles;
|
||||
|
||||
GdkFont *header_font;
|
||||
|
||||
gint refcount;
|
||||
@ -100,9 +91,6 @@ gint gnucash_style_col_is_resizable (SheetBlockStyle *style, int col);
|
||||
CellDimensions * gnucash_style_get_cell_dimensions (SheetBlockStyle *style,
|
||||
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);
|
||||
|
||||
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_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_borders (SheetBlockStyle *style, int border);
|
||||
void gnucash_sheet_set_borders (GnucashSheet *sheet, int border);
|
||||
gint gnucash_sheet_get_borders (GnucashSheet *sheet, VirtualLocation virt_loc);
|
||||
|
||||
void gnucash_sheet_get_header_widths (GnucashSheet *sheet, int *header_widths);
|
||||
void gnucash_sheet_set_header_widths (GnucashSheet *sheet, int *header_widths);
|
||||
|
@ -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
|
||||
gnc_table_set_size (Table * table, int virt_rows, int virt_cols)
|
||||
{
|
||||
|
@ -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);
|
||||
|
||||
CellAlignment gnc_table_get_align (Table *table, VirtualLocation virt_loc);
|
||||
|
||||
/* Return the virtual cell of the header */
|
||||
VirtualCell * gnc_table_get_header_cell (Table *table);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user