mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-20 11:48:30 -06:00
Use previously created functions
Use the previously created functions to reduce code and for conformity. As part of this some variables were renamed to be common.
This commit is contained in:
parent
8a6ce10aa8
commit
67e4b35294
@ -69,6 +69,7 @@ static void
|
||||
gnc_header_draw_offscreen (GncHeader *header)
|
||||
{
|
||||
SheetBlockStyle *style = header->style;
|
||||
GncItemEdit *item_edit = GNC_ITEM_EDIT(header->sheet->item_editor);
|
||||
Table *table = header->sheet->table;
|
||||
VirtualLocation virt_loc;
|
||||
VirtualCell *vcell;
|
||||
@ -125,7 +126,7 @@ gnc_header_draw_offscreen (GncHeader *header)
|
||||
for (i = 0; i < style->nrows; i++)
|
||||
{
|
||||
int col_offset = 0;
|
||||
int h = 0, j;
|
||||
int height = 0, j;
|
||||
virt_loc.phys_row_offset = i;
|
||||
|
||||
/* TODO: This routine is duplicated in several places.
|
||||
@ -139,26 +140,29 @@ gnc_header_draw_offscreen (GncHeader *header)
|
||||
double text_x, text_y, text_w, text_h;
|
||||
BasicCell *cell;
|
||||
const char *text;
|
||||
int w;
|
||||
int width;
|
||||
PangoLayout *layout;
|
||||
PangoRectangle logical_rect;
|
||||
GdkRectangle rect;
|
||||
int x_offset;
|
||||
|
||||
virt_loc.phys_col_offset = j;
|
||||
|
||||
cd = gnucash_style_get_cell_dimensions (style, i, j);
|
||||
h = cd->pixel_height;
|
||||
height = cd->pixel_height;
|
||||
if (header->in_resize && (j == header->resize_col))
|
||||
w = header->resize_col_width;
|
||||
width = header->resize_col_width;
|
||||
else
|
||||
w = cd->pixel_width;
|
||||
width = cd->pixel_width;
|
||||
|
||||
cell = gnc_cellblock_get_cell (cb, i, j);
|
||||
if (!cell || !cell->cell_name)
|
||||
{
|
||||
col_offset += w;
|
||||
col_offset += width;
|
||||
continue;
|
||||
}
|
||||
|
||||
cairo_rectangle (cr, col_offset - 0.5, row_offset + 0.5, w, h);
|
||||
cairo_rectangle (cr, col_offset - 0.5, row_offset + 0.5, width, height);
|
||||
cairo_set_line_width (cr, 1.0);
|
||||
cairo_stroke (cr);
|
||||
|
||||
@ -169,38 +173,28 @@ gnc_header_draw_offscreen (GncHeader *header)
|
||||
text = "";
|
||||
|
||||
layout = gtk_widget_create_pango_layout (GTK_WIDGET (header->sheet), text);
|
||||
switch (gnc_table_get_align (table, virt_loc))
|
||||
{
|
||||
default:
|
||||
case CELL_ALIGN_LEFT:
|
||||
pango_layout_set_alignment (layout, PANGO_ALIGN_LEFT);
|
||||
break;
|
||||
|
||||
case CELL_ALIGN_RIGHT:
|
||||
pango_layout_set_alignment (layout, PANGO_ALIGN_RIGHT);
|
||||
break;
|
||||
pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
|
||||
|
||||
case CELL_ALIGN_CENTER:
|
||||
pango_layout_set_alignment (layout, PANGO_ALIGN_CENTER);
|
||||
break;
|
||||
}
|
||||
gnucash_sheet_set_text_bounds (header->sheet, &rect,
|
||||
col_offset, row_offset, width, height);
|
||||
|
||||
text_x = col_offset + CELL_HPADDING;
|
||||
text_y = row_offset + 1;
|
||||
text_w = MAX (0, w - (2 * CELL_HPADDING));
|
||||
text_h = h - 2;
|
||||
cairo_save (cr);
|
||||
cairo_rectangle (cr, text_x, text_y, text_w, text_h);
|
||||
cairo_rectangle (cr, rect.x, rect.y, rect.width, rect.height);
|
||||
cairo_clip (cr);
|
||||
|
||||
gtk_render_layout (stylectxt, cr, text_x, text_y, layout);
|
||||
x_offset = gnucash_sheet_get_text_offset (header->sheet, virt_loc,
|
||||
rect.width, logical_rect.width);
|
||||
|
||||
gtk_render_layout (stylectxt, cr, rect.x + x_offset,
|
||||
rect.y + gnc_item_edit_get_padding_border (item_edit, top), layout);
|
||||
|
||||
cairo_restore (cr);
|
||||
g_object_unref (layout);
|
||||
|
||||
col_offset += w;
|
||||
col_offset += width;
|
||||
}
|
||||
row_offset += h;
|
||||
row_offset += height;
|
||||
}
|
||||
gtk_style_context_restore (stylectxt);
|
||||
|
||||
|
@ -381,6 +381,7 @@ draw_cell (GnucashSheet *sheet,
|
||||
cairo_t *cr,
|
||||
int x, int y, int width, int height)
|
||||
{
|
||||
GncItemEdit *item_edit = GNC_ITEM_EDIT(sheet->item_editor);
|
||||
Table *table = sheet->table;
|
||||
PhysicalCellBorders borders;
|
||||
const char *text;
|
||||
@ -522,39 +523,19 @@ draw_cell (GnucashSheet *sheet,
|
||||
goto exit;
|
||||
}
|
||||
|
||||
pango_layout_get_pixel_extents(layout,
|
||||
NULL,
|
||||
&logical_rect);
|
||||
pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
|
||||
|
||||
rect.x = x + CELL_HPADDING;
|
||||
rect.y = y + CELL_VPADDING;
|
||||
rect.width = MAX (0, width - (2 * CELL_HPADDING));
|
||||
rect.height = height - 2;
|
||||
gnucash_sheet_set_text_bounds (sheet, &rect, x, y, width, height);
|
||||
|
||||
cairo_save (cr);
|
||||
cairo_rectangle (cr, rect.x, rect.y, rect.width, rect.height);
|
||||
cairo_clip (cr);
|
||||
|
||||
switch (gnc_table_get_align (table, virt_loc))
|
||||
{
|
||||
default:
|
||||
case CELL_ALIGN_LEFT:
|
||||
x_offset = 0;
|
||||
break;
|
||||
x_offset = gnucash_sheet_get_text_offset (sheet, virt_loc,
|
||||
rect.width, logical_rect.width);
|
||||
|
||||
case CELL_ALIGN_RIGHT:
|
||||
x_offset = width - 2 * CELL_HPADDING - logical_rect.width - 3;
|
||||
break;
|
||||
|
||||
case CELL_ALIGN_CENTER:
|
||||
if (logical_rect.width > width - 2 * CELL_HPADDING)
|
||||
x_offset = 0;
|
||||
else
|
||||
x_offset = (width - 2 * CELL_HPADDING -
|
||||
logical_rect.width) / 2;
|
||||
break;
|
||||
}
|
||||
gtk_render_layout (stylectxt, cr, rect.x + x_offset + 1, rect.y, layout);
|
||||
gtk_render_layout (stylectxt, cr, rect.x + x_offset,
|
||||
rect.y + gnc_item_edit_get_padding_border (item_edit, top), layout);
|
||||
|
||||
cairo_restore (cr);
|
||||
|
||||
|
@ -312,7 +312,7 @@ gnucash_sheet_get_text_cursor_position (GnucashSheet *sheet, const VirtualLocati
|
||||
PangoLayout *layout;
|
||||
PangoRectangle logical_rect;
|
||||
GdkRectangle rect;
|
||||
gint x, y, w, h;
|
||||
gint x, y, width, height;
|
||||
gint index, trailing;
|
||||
gboolean result;
|
||||
gint x_offset = 0;
|
||||
@ -321,7 +321,7 @@ gnucash_sheet_get_text_cursor_position (GnucashSheet *sheet, const VirtualLocati
|
||||
return 0;
|
||||
|
||||
// Get the item_edit position
|
||||
gnc_item_edit_get_pixel_coords (item_edit, &x, &y, &w, &h);
|
||||
gnc_item_edit_get_pixel_coords (item_edit, &x, &y, &width, &height);
|
||||
|
||||
layout = gtk_widget_create_pango_layout (GTK_WIDGET (sheet), text);
|
||||
|
||||
@ -330,35 +330,14 @@ gnucash_sheet_get_text_cursor_position (GnucashSheet *sheet, const VirtualLocati
|
||||
|
||||
pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
|
||||
|
||||
rect.x = x + CELL_HPADDING;
|
||||
rect.y = y + CELL_VPADDING;
|
||||
rect.width = MAX (0, w - (2 * CELL_HPADDING));
|
||||
rect.height = h - 2;
|
||||
gnucash_sheet_set_text_bounds (sheet, &rect, x, y, width, height);
|
||||
|
||||
// Get the alignment of the cell
|
||||
switch (gnc_table_get_align (table, virt_loc))
|
||||
{
|
||||
default:
|
||||
case CELL_ALIGN_LEFT:
|
||||
x_offset = 0;
|
||||
break;
|
||||
|
||||
case CELL_ALIGN_RIGHT:
|
||||
x_offset = w - 2 * CELL_HPADDING - logical_rect.width - 3;
|
||||
break;
|
||||
|
||||
case CELL_ALIGN_CENTER:
|
||||
if (logical_rect.width > w - 2 * CELL_HPADDING)
|
||||
x_offset = 0;
|
||||
else
|
||||
x_offset = (w - 2 * CELL_HPADDING -
|
||||
logical_rect.width) / 2;
|
||||
break;
|
||||
}
|
||||
x_offset = gnucash_sheet_get_text_offset (sheet, virt_loc,
|
||||
rect.width, logical_rect.width);
|
||||
|
||||
result = pango_layout_xy_to_index (layout,
|
||||
PANGO_SCALE * (sheet->button_x - rect.x - x_offset),
|
||||
PANGO_SCALE * (h/2), &index, &trailing);
|
||||
PANGO_SCALE * (height/2), &index, &trailing);
|
||||
|
||||
g_object_unref (layout);
|
||||
|
||||
@ -2231,6 +2210,7 @@ gnucash_sheet_col_max_width (GnucashSheet *sheet, gint virt_col, gint cell_col)
|
||||
SheetBlock *block;
|
||||
SheetBlockStyle *style;
|
||||
PangoLayout *layout = gtk_widget_create_pango_layout (GTK_WIDGET (sheet), "");
|
||||
GncItemEdit *item_edit = GNC_ITEM_EDIT(sheet->item_editor);
|
||||
|
||||
g_return_val_if_fail (virt_col >= 0, 0);
|
||||
g_return_val_if_fail (virt_col < sheet->num_virt_cols, 0);
|
||||
|
@ -33,10 +33,6 @@
|
||||
* @brief Public declarations of GnucashSheet class.
|
||||
*/
|
||||
|
||||
#define CELL_VPADDING 2
|
||||
#define CELL_HPADDING 5
|
||||
|
||||
|
||||
#define GNUCASH_TYPE_SHEET (gnucash_sheet_get_type ())
|
||||
#define GNUCASH_SHEET(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GNUCASH_TYPE_SHEET, GnucashSheet))
|
||||
#define GNUCASH_SHEET_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), GNUCASH_TYPE_SHEET))
|
||||
|
Loading…
Reference in New Issue
Block a user