35#define DEFAULT_STYLE_WIDTH 680
41static QofLogModule log_module = GNC_MOD_REGISTER;
47style_get_key (SheetBlockStyle *style)
51 key = style->cursor->num_rows;
57style_create_key (SheetBlockStyle *style)
59 gint key = style->cursor->num_rows;
61 gint *new_key = g_new(gint, 1);
68cell_dimensions_construct (gpointer _cd, gpointer user_data)
73 cd->can_span_over = TRUE;
78style_dimensions_new (SheetBlockStyle *style)
84 dimensions->nrows = style->nrows;
85 dimensions->ncols = style->ncols;
88 cell_dimensions_construct,
92 style->nrows, style->ncols);
100 if (dimensions == NULL)
103 dimensions->refcount--;
105 if (dimensions->refcount == 0)
108 dimensions->cell_dimensions = NULL;
116gnucash_style_dimensions_init (GnucashSheet *sheet, SheetBlockStyle *style)
120 dimensions = g_hash_table_lookup (sheet->dimensions_hash_table,
121 style_get_key (style));
125 dimensions = style_dimensions_new (style);
126 g_hash_table_insert (sheet->dimensions_hash_table,
127 style_create_key (style), dimensions);
130 dimensions->refcount++;
132 style->dimensions = dimensions;
137gnucash_style_get_cell_dimensions (SheetBlockStyle *style,
int row,
int col)
141 if (style->dimensions == NULL)
143 if (style->dimensions->cell_dimensions == NULL)
146 return g_table_index (style->dimensions->cell_dimensions, row, col);
150compute_row_width (
BlockDimensions *dimensions,
int row,
int col1,
int col2)
156 col2 = MIN(col2, dimensions->ncols - 1);
158 for (j = col1; j <= col2; j++)
166 width += cd->pixel_width;
175set_dimensions_pass_one (GnucashSheet *sheet,
CellBlock *cursor,
180 gint max_height = -1;
182 GncItemEdit *item_edit = GNC_ITEM_EDIT(sheet->item_editor);
186 for (row = 0; row < cursor->num_rows; row++)
188 for (col = 0; col < cursor->num_cols; col++)
201 text = cell->sample_text;
203 cd->can_span_over = FALSE;
207 layout = gtk_widget_create_pango_layout (GTK_WIDGET (sheet), text);
208 pango_layout_get_pixel_size (layout, &width, &cd->pixel_height);
209 g_object_unref (layout);
210 width += gnc_item_edit_get_margin (item_edit, left_right) +
211 gnc_item_edit_get_padding_border (item_edit, left_right);
215 if (cell && cell->is_popup)
216 width += gnc_item_edit_get_button_width (item_edit) + 2;
218 cd->pixel_height += gnc_item_edit_get_margin (item_edit, top_bottom) +
219 gnc_item_edit_get_padding_border (item_edit, top_bottom);
224 cd->pixel_height = gnc_item_edit_get_margin (item_edit, top_bottom) +
225 gnc_item_edit_get_padding_border (item_edit, top_bottom);
228 max_height = MAX(max_height, cd->pixel_height + 1);
230 if (cd->pixel_width > 0)
233 cd->pixel_width = MAX (cd->pixel_width, width);
236 dimensions->height += max_height;
239 for (row = 0; row < cursor->num_rows; row++)
241 for (col = 0; col < cursor->num_cols; col++)
248 cd->pixel_height = max_height;
257set_dimensions_pass_two (GnucashSheet *sheet,
int default_width)
259 SheetBlockStyle *style;
260 GncItemEdit *item_edit = GNC_ITEM_EDIT(sheet->item_editor);
273 style = gnucash_sheet_get_style_from_cursor (sheet,
CURSOR_HEADER);
274 dimensions = style->dimensions;
275 cd_table = dimensions->cell_dimensions;
276 cursor = style->cursor;
279 num_cols = cursor->num_cols;
280 widths = g_new0 (
int, num_cols);
283 for (col = 0; col < num_cols; col++)
290 widths[col] = cd->pixel_width;
291 width += cd->pixel_width;
294 if (width < default_width)
295 for (col = 0; col < num_cols; col++)
301 if (!cell || !cell->expandable)
309 cd->pixel_width += (default_width - width);
310 widths[col] = cd->pixel_width;
314 else if (width > default_width && width == sheet->window_width)
316 for (col = 0; col < num_cols; col++)
325 if (!cell || !cell->expandable)
333 cd->pixel_width += (default_width - width);
335 text = cell->sample_text;
338 layout = gtk_widget_create_pango_layout (GTK_WIDGET (sheet), text);
339 pango_layout_get_pixel_size (layout, &sample_width, NULL);
340 g_object_unref (layout);
342 sample_width += gnc_item_edit_get_margin (item_edit, left_right) +
343 gnc_item_edit_get_padding_border (item_edit, left_right);
348 cd->pixel_width = MAX (cd->pixel_width, sample_width);
350 widths[col] = cd->pixel_width;
356 cursors = gnc_table_layout_get_cursors (sheet->table->layout);
359 for (node = cursors; node; node = node->next)
362 style = gnucash_sheet_get_style_from_cursor
363 (sheet, cursor->cursor_name);
364 dimensions = style->dimensions;
365 cd_table = dimensions->cell_dimensions;
367 for (row = 0; row < cursor->num_rows; row++)
368 for (col = 0; col < num_cols; col++)
375 cd->pixel_width = widths[col];
380 for (node = cursors; node; node = node->next)
385 style = gnucash_sheet_get_style_from_cursor
386 (sheet, cursor->cursor_name);
387 dimensions = style->dimensions;
388 cd_table = dimensions->cell_dimensions;
390 for (row = 0; row < cursor->num_rows; row++)
394 for (col = 0; col < num_cols; col++)
411 if (!cd || !cd->can_span_over)
417 if (cell->sample_text != NULL)
423 if (cd->pixel_width <= 0)
426 cd_span->pixel_width += cd->pixel_width;
436gnucash_style_row_width(SheetBlockStyle *style,
int row)
440 dimensions = style->dimensions;
442 return compute_row_width(dimensions, row, 0, dimensions->ncols - 1);
451 for (i = 0; i < dimensions->nrows; i++)
455 for (j = 0; j < dimensions->ncols; j++)
465 x += cd->pixel_width;
477 for (i = 0; i < dimensions->nrows; i++)
479 for (j = 0; j < dimensions->ncols; j++)
493 y += cd->pixel_height;
499set_dimensions_pass_three (GnucashSheet *sheet)
504 cursors = gnc_table_layout_get_cursors (sheet->table->layout);
506 for (node = cursors; node; node = node->next)
510 SheetBlockStyle *style;
513 style = gnucash_sheet_get_style_from_cursor
514 (sheet, cursor->cursor_name);
515 dimensions = style->dimensions;
517 dimensions->width = compute_row_width (dimensions, 0, 0,
518 dimensions->ncols - 1);
520 compute_cell_origins_x (dimensions);
521 compute_cell_origins_y (dimensions);
526styles_recompute_layout_dimensions (GnucashSheet *sheet,
int default_width)
529 SheetBlockStyle *style;
534 cursors = gnc_table_layout_get_cursors (sheet->table->layout);
536 for (node = cursors; node; node = node->next)
540 style = gnucash_sheet_get_style_from_cursor
541 (sheet, cursor->cursor_name);
543 dimensions = style->dimensions;
545 dimensions->height = 0;
546 dimensions->width = default_width;
548 set_dimensions_pass_one (sheet, cursor, dimensions);
551 set_dimensions_pass_two (sheet, default_width);
552 set_dimensions_pass_three (sheet);
556gnucash_sheet_styles_set_dimensions (GnucashSheet *sheet,
int default_width)
558 g_return_if_fail (sheet != NULL);
559 g_return_if_fail (GNUCASH_IS_SHEET (sheet));
561 styles_recompute_layout_dimensions (sheet, default_width);
565gnucash_style_col_is_resizable (SheetBlockStyle *style,
int col)
567 if (col < 0 || col >= style->ncols)
574gnucash_sheet_set_col_width (GnucashSheet *sheet,
int col,
int width)
577 SheetBlockStyle *style;
581 g_return_if_fail (sheet != NULL);
582 g_return_if_fail (GNUCASH_IS_SHEET(sheet));
583 g_return_if_fail (col >= 0);
588 style = gnucash_sheet_get_style_from_cursor (sheet,
CURSOR_HEADER);
590 g_return_if_fail (col < style->ncols);
592 cd = gnucash_style_get_cell_dimensions (style, 0, col);
596 diff = cd->pixel_width - width;
597 cd->pixel_width = width;
599 total = MAX (sheet->window_width, sheet->width - diff);
601 set_dimensions_pass_two (sheet, total);
602 set_dimensions_pass_three (sheet);
607gnucash_sheet_styles_recompile(GnucashSheet *sheet)
613gnucash_sheet_get_borders (GnucashSheet *sheet, VirtualLocation virt_loc,
616 SheetBlockStyle *style;
617 PhysicalCellBorderLineStyle line_style;
619 g_return_if_fail (sheet != NULL);
620 g_return_if_fail (GNUCASH_IS_SHEET (sheet));
622 line_style = sheet->use_horizontal_lines ?
623 CELL_BORDER_LINE_NORMAL : CELL_BORDER_LINE_NONE;
625 borders->top = line_style;
626 borders->bottom = line_style;
628 line_style = sheet->use_vertical_lines ?
629 CELL_BORDER_LINE_NORMAL : CELL_BORDER_LINE_NONE;
631 borders->left = line_style;
632 borders->right = line_style;
634 style = gnucash_sheet_get_style_from_cursor (sheet,
CURSOR_HEADER);
636 if (virt_loc.phys_col_offset == (style->ncols - 1))
637 borders->right = CELL_BORDER_LINE_NORMAL;
639 if (virt_cell_loc_equal (virt_loc.vcell_loc,
640 sheet->table->current_cursor_loc.vcell_loc))
642 borders->top = CELL_BORDER_LINE_NORMAL;
643 borders->bottom = CELL_BORDER_LINE_NORMAL;
646 gnc_table_get_borders (sheet->table, virt_loc, borders);
650static SheetBlockStyle *
651gnucash_sheet_style_new (GnucashSheet *sheet,
CellBlock *cursor)
653 SheetBlockStyle *style;
655 g_return_val_if_fail (sheet != NULL, NULL);
656 g_return_val_if_fail (GNUCASH_IS_SHEET (sheet), NULL);
657 g_return_val_if_fail (cursor != NULL, NULL);
659 style = g_new0 (SheetBlockStyle, 1);
661 style->cursor = cursor;
663 style->nrows = cursor->num_rows;
664 style->ncols = cursor->num_cols;
666 gnucash_style_dimensions_init (sheet, style);
672destroy_style_helper (gpointer key, gpointer value, gpointer user_data)
674 char *cursor_name = key;
675 SheetBlockStyle *style = value;
676 GnucashSheet *sheet = user_data;
678 gnucash_sheet_style_unref (sheet, style);
679 g_free (cursor_name);
683gnucash_sheet_clear_styles (GnucashSheet *sheet)
685 g_return_if_fail (sheet != NULL);
686 g_return_if_fail (GNUCASH_IS_SHEET (sheet));
688 g_hash_table_foreach (sheet->cursor_styles,
689 destroy_style_helper, sheet);
693gnucash_sheet_create_styles (GnucashSheet *sheet)
698 g_return_if_fail (sheet != NULL);
699 g_return_if_fail (GNUCASH_IS_SHEET (sheet));
701 gnucash_sheet_clear_styles (sheet);
703 cursors = gnc_table_layout_get_cursors (sheet->table->layout);
705 for (node = cursors; node; node = node->next)
708 SheetBlockStyle *style = gnucash_sheet_style_new (sheet, cursor);
710 gnucash_sheet_style_ref (sheet, style);
711 g_hash_table_insert (sheet->cursor_styles,
712 g_strdup (cursor->cursor_name),
718gnucash_sheet_compile_styles (GnucashSheet *sheet)
720 g_return_if_fail (sheet != NULL);
721 g_return_if_fail (GNUCASH_IS_SHEET (sheet));
723 ENTER(
"sheet=%p", sheet);
725 gnucash_sheet_styles_set_dimensions (sheet, DEFAULT_STYLE_WIDTH);
731gnucash_sheet_style_destroy (GnucashSheet *sheet, SheetBlockStyle *style)
738 style->dimensions->refcount--;
740 if (style->dimensions->refcount == 0)
742 style_dimensions_destroy (style->dimensions);
743 g_hash_table_remove (sheet->dimensions_hash_table,
744 style_get_key (style));
752gnucash_sheet_style_get_cell_pixel_rel_coords (SheetBlockStyle *style,
753 gint cell_row, gint cell_col,
759 g_return_if_fail (style != NULL);
760 g_return_if_fail (cell_row >= 0 && cell_row <= style->nrows);
761 g_return_if_fail (cell_col >= 0 && cell_col <= style->ncols);
763 cd = gnucash_style_get_cell_dimensions (style, cell_row, cell_col);
768 *h = cd->pixel_height;
769 *w = cd->pixel_width;
774gnucash_sheet_get_style (GnucashSheet *sheet, VirtualCellLocation vcell_loc)
778 g_return_val_if_fail (sheet != NULL, NULL);
779 g_return_val_if_fail (GNUCASH_IS_SHEET(sheet), NULL);
781 block = gnucash_sheet_get_block (sheet, vcell_loc);
791gnucash_sheet_get_style_from_table (GnucashSheet *sheet,
792 VirtualCellLocation vcell_loc)
797 SheetBlockStyle *style;
799 g_return_val_if_fail (sheet != NULL, NULL);
800 g_return_val_if_fail (GNUCASH_IS_SHEET(sheet), NULL);
802 table = sheet->table;
809 cursor = vcell->cellblock;
811 style = gnucash_sheet_get_style_from_cursor (sheet,
812 cursor->cursor_name);
816 return gnucash_sheet_get_style_from_cursor (sheet,
CURSOR_HEADER);
820gnucash_sheet_get_style_from_cursor (GnucashSheet *sheet,
821 const char *cursor_name)
823 g_return_val_if_fail (sheet != NULL, NULL);
824 g_return_val_if_fail (GNUCASH_IS_SHEET (sheet), NULL);
829 return g_hash_table_lookup (sheet->cursor_styles, cursor_name);
838gnucash_sheet_style_ref (GnucashSheet *sheet, SheetBlockStyle *style)
840 g_return_if_fail (style != NULL);
847gnucash_sheet_style_unref (GnucashSheet *sheet, SheetBlockStyle *style)
849 g_return_if_fail (style != NULL);
853 if (style->refcount == 0)
854 gnucash_sheet_style_destroy (sheet, style);
864gnc_header_widths_new (
void)
866 return g_hash_table_new (g_str_hash, g_str_equal);
870header_width_destroy_helper (gpointer key, gpointer value, gpointer user_data)
874 g_free (wn->cell_name);
875 wn->cell_name = NULL;
881gnc_header_widths_destroy (GNCHeaderWidths widths)
884 g_hash_table_foreach (widths, header_width_destroy_helper, NULL);
885 g_hash_table_destroy (widths);
889gnc_header_widths_set_width (GNCHeaderWidths widths,
890 const char *cell_name,
895 g_return_if_fail (widths != NULL);
896 g_return_if_fail (cell_name != NULL);
898 wn = g_hash_table_lookup (widths, cell_name);
903 wn->cell_name = g_strdup (cell_name);
905 g_hash_table_insert (widths, wn->cell_name, wn);
912gnc_header_widths_get_width (GNCHeaderWidths widths,
913 const char *cell_name)
917 g_return_val_if_fail (widths != NULL, 0);
919 wn = g_hash_table_lookup (widths, cell_name);
927gnucash_sheet_get_header_widths (GnucashSheet *sheet,
928 GNCHeaderWidths widths)
930 SheetBlockStyle *style;
934 g_return_if_fail (sheet != NULL);
935 g_return_if_fail (GNUCASH_IS_SHEET(sheet));
937 style = gnucash_sheet_get_style_from_cursor (sheet,
CURSOR_HEADER);
938 g_return_if_fail (style != NULL);
940 header = style->cursor;
941 g_return_if_fail (header != NULL);
943 for (row = 0; row < style->nrows; row++)
944 for (col = 0; col < style->ncols; col++)
949 cd = gnucash_style_get_cell_dimensions (style,
955 if (!cell || !cell->cell_name)
958 gnc_header_widths_set_width (widths,
965gnucash_sheet_set_header_widths (GnucashSheet *sheet,
966 GNCHeaderWidths widths)
968 SheetBlockStyle *style;
972 g_return_if_fail (sheet != NULL);
973 g_return_if_fail (GNUCASH_IS_SHEET(sheet));
975 style = gnucash_sheet_get_style_from_cursor (sheet,
CURSOR_HEADER);
976 g_return_if_fail (style != NULL);
978 header = style->cursor;
979 g_return_if_fail (header != NULL);
981 for (row = 0; row < style->nrows; row++)
982 for (col = 0; col < style->ncols; col++)
987 cd = gnucash_style_get_cell_dimensions (style,
991 if (!cell || !cell->cell_name || !cd)
994 cd->pixel_width = gnc_header_widths_get_width
995 (widths, cell->cell_name);
1000gnucash_style_init (
void)
All type declarations for the whole Gnucash engine.
Convenience wrapper around GdkRGBA for use in Register Gnome classes.
Public declarations for GncItemEdit class.
Private declarations for GnucashSheet class.
Public declarations of GnucashRegister class.
Styling functions for RegisterGnome.
BasicCell * gnc_cellblock_get_cell(CellBlock *cellblock, int row, int col)
Retrieve the Cell at the specified coordinates.
#define LEAVE(format, args...)
Print a function exit debugging message.
#define ENTER(format, args...)
Print a function entry debugging message.
void g_table_destroy(GTable *gtable)
Free the table and all associated table elements.
void g_table_resize(GTable *gtable, int rows, int cols)
Resize the table, allocating and deallocating extra table members if needed.
gpointer g_table_index(GTable *gtable, int row, int col)
Return the element at the given row and column.
GTable * g_table_new(guint entry_size, g_table_entry_constructor constructor, g_table_entry_destroyer destroyer, gpointer user_data)
Create a new table with the given entry constructor and destroyer.
#define CURSOR_HEADER
Standard Cursor Names.
VirtualCell * gnc_table_get_virtual_cell(Table *table, VirtualCellLocation vcell_loc)
returns the virtual cell associated with a particular virtual location.
SheetBlockStyle * style
The style for this block.
holds information about each virtual cell.