56 find_block_by_pixel (GnucashSheet *sheet,
58 VirtualCellLocation *vcell_loc)
61 VirtualCellLocation vc_loc = { 1, 0 };
63 g_return_val_if_fail (y >= 0, NULL);
64 g_return_val_if_fail (x >= 0, NULL);
68 block = gnucash_sheet_get_block (sheet, vc_loc);
74 y < block->origin_y + block->
style->dimensions->height)
77 vcell_loc->virt_row = vc_loc.virt_row;
82 while (vc_loc.virt_row < sheet->num_virt_rows);
84 if (vc_loc.virt_row == sheet->num_virt_rows)
89 block = gnucash_sheet_get_block (sheet, vc_loc);
94 x >= block->origin_x &&
95 x < block->origin_x + block->
style->dimensions->width)
98 vcell_loc->virt_col = vc_loc.virt_col;
103 while (vc_loc.virt_col < sheet->num_virt_cols);
105 if (vc_loc.virt_col == sheet->num_virt_cols)
112 find_cell_by_pixel (GnucashSheet *sheet, gint x, gint y,
113 VirtualLocation *virt_loc)
116 SheetBlockStyle *style;
121 g_return_val_if_fail (virt_loc != NULL, FALSE);
123 block = gnucash_sheet_get_block (sheet, virt_loc->vcell_loc);
128 x -= block->origin_x;
131 style = block->
style;
137 cd = gnucash_style_get_cell_dimensions (style, row, 0);
139 if (cd && y >= cd->origin_y && y < cd->origin_y + cd->pixel_height)
144 while (row < style->nrows);
146 if (row == style->nrows)
151 cd = gnucash_style_get_cell_dimensions (style, row, col);
153 if (cd && x >= cd->origin_x && x < cd->origin_x + cd->pixel_width)
158 while (col < style->ncols);
160 if (col == style->ncols)
164 virt_loc->phys_row_offset = row;
166 virt_loc->phys_col_offset = col;
172 gnucash_sheet_find_loc_by_pixel (GnucashSheet *sheet, gint x, gint y,
173 VirtualLocation *virt_loc)
177 if (virt_loc == NULL)
180 block = find_block_by_pixel (sheet, x, y,
181 &virt_loc->vcell_loc);
185 return find_cell_by_pixel (sheet, x, y, virt_loc);
189 get_cell_borders (GnucashSheet *sheet, VirtualLocation virt_loc,
192 VirtualLocation v_loc;
195 gnucash_sheet_get_borders (sheet, virt_loc, borders);
201 gnucash_sheet_get_borders (sheet, v_loc, &neighbor);
202 borders->top = MAX(borders->top, neighbor.bottom);
209 gnucash_sheet_get_borders (sheet, v_loc, &neighbor);
210 borders->bottom = MAX(borders->bottom, neighbor.top);
215 v_loc.phys_col_offset--;
216 if (gnc_table_virtual_loc_valid (sheet->table, v_loc, TRUE))
218 gnucash_sheet_get_borders (sheet, v_loc, &neighbor);
219 borders->left = MAX(borders->left, neighbor.right);
224 v_loc.phys_col_offset++;
225 if (gnc_table_virtual_loc_valid (sheet->table, v_loc, TRUE))
227 gnucash_sheet_get_borders (sheet, v_loc, &neighbor);
228 borders->right = MAX(borders->right, neighbor.left);
233 #ifdef READONLY_LINES_WITH_CHANGED_FG_COLOR 238 static guint8 inc_intensity_byte (guint8 input,
int numerator,
int denominator)
240 guint8 result_inv, result;
241 guint8 input_inv = 0xff - input;
242 result_inv = (input_inv * numerator) / denominator;
243 result = 0xff - result_inv;
250 static guint32 inc_intensity_10percent (guint32 argb)
253 (inc_intensity_byte ((argb & 0x00FF0000) >> 16, 8, 10) << 16)
254 + (inc_intensity_byte ((argb & 0x0000FF00) >> 8, 8, 10) << 8)
255 + (inc_intensity_byte (argb & 0x000000FF, 8, 10));
263 draw_cell_line (cairo_t *cr, GdkRGBA *bg_color,
264 double x1,
double y1,
double x2,
double y2,
265 PhysicalCellBorderLineStyle style);
268 draw_cell_line (cairo_t *cr, GdkRGBA *bg_color,
269 double x1,
double y1,
double x2,
double y2,
270 PhysicalCellBorderLineStyle style)
276 case CELL_BORDER_LINE_NONE:
280 case CELL_BORDER_LINE_LIGHT:
281 fg_color = &gn_light_gray;
284 case CELL_BORDER_LINE_NORMAL:
285 case CELL_BORDER_LINE_HEAVY:
286 fg_color = &gn_black;
289 case CELL_BORDER_LINE_HIGHLIGHT:
297 cairo_set_line_width (cr, 1.0);
298 cairo_set_source_rgb (cr, fg_color->red, fg_color->green, fg_color->blue);
299 cairo_move_to (cr, x1, y1);
300 cairo_line_to (cr, x2, y2);
305 draw_hatching (cairo_t *cr,
double x,
double y,
306 G_GNUC_UNUSED
double width,
double height)
309 double h_x = x + 2.5;
310 double h_y = y + 2.5;
311 double h_size = height / 3 - 1;
313 cairo_set_line_width (cr, 1.0);
314 fg_color = &gn_light_gray;
315 cairo_set_source_rgb (cr, fg_color->red, fg_color->green, fg_color->blue);
317 cairo_rectangle (cr, h_x, h_y, h_size, h_size);
318 cairo_move_to (cr, h_x, h_y);
319 cairo_rel_line_to (cr, h_size, h_size);
320 cairo_rel_move_to (cr, -h_size, 0);
321 cairo_rel_line_to (cr, h_size, -h_size);
326 draw_divider_line (cairo_t *cr, VirtualLocation virt_loc,
327 int div_row,
int n_phys_rows, GdkRGBA *fg_color,
328 double x,
double y,
double width,
double height)
335 if ((virt_loc.phys_row_offset == 0) &&
336 (virt_loc.vcell_loc.virt_row == div_row))
339 else if ((virt_loc.phys_row_offset == n_phys_rows - 1) &&
340 (virt_loc.vcell_loc.virt_row == div_row - 1))
345 cairo_set_source_rgb (cr, fg_color->red, fg_color->green, fg_color->blue);
347 cairo_set_line_width (cr, 3.0);
348 cairo_move_to (cr, x, y - 0.5 + offset);
349 cairo_rel_line_to (cr, width, 0);
354 set_cell_insensitive (GtkStyleContext *stylectxt)
356 if (!gtk_style_context_has_class (stylectxt, GTK_STYLE_CLASS_BACKGROUND))
357 gtk_style_context_set_state (stylectxt, GTK_STATE_FLAG_INSENSITIVE);
361 draw_cell (GnucashSheet *sheet,
SheetBlock *block,
362 VirtualLocation virt_loc, cairo_t *cr,
363 int x,
int y,
int width,
int height)
365 GncItemEdit *item_edit = GNC_ITEM_EDIT(sheet->item_editor);
366 Table *
table = sheet->table;
370 PangoContext *context;
371 PangoFontDescription *font;
372 PangoRectangle logical_rect;
373 GdkRGBA *bg_color, *fg_color;
378 GtkStyleContext *stylectxt = gtk_widget_get_style_context (GTK_WIDGET(sheet));
380 gboolean use_neg_class = TRUE;
382 gtk_style_context_save (stylectxt);
384 text = gnc_table_get_entry (
table, virt_loc);
387 if (!text || *text ==
'\0')
388 use_neg_class = FALSE;
391 color_type = gnc_table_get_color (
table, virt_loc, &hatching);
394 if (sheet->read_only)
395 set_cell_insensitive (stylectxt);
398 if (gtk_style_context_has_class (stylectxt, GTK_STYLE_CLASS_BACKGROUND))
399 gtk_style_context_set_state (stylectxt, GTK_STATE_FLAG_NORMAL);
403 if ((virt_loc.phys_row_offset < block->
style->nrows)
404 && (
table->model->dividing_row_upper >= 0))
406 if (
table->model->reverse_sort)
408 if ((
table->model->blank_trans_row <
table->model->dividing_row_upper)
409 && (virt_loc.vcell_loc.virt_row >=
table->model->dividing_row_upper))
411 set_cell_insensitive (stylectxt);
414 if ((virt_loc.vcell_loc.virt_row >=
table->model->dividing_row_upper)
415 && (virt_loc.vcell_loc.virt_row <
table->model->blank_trans_row))
417 set_cell_insensitive (stylectxt);
422 if (virt_loc.vcell_loc.virt_row <
table->model->dividing_row_upper)
423 set_cell_insensitive (stylectxt);
427 gtk_render_background (stylectxt, cr, x, y, width, height);
429 gdk_rgba_parse (&color,
"black");
434 get_cell_borders (sheet, virt_loc, &borders);
437 draw_cell_line (cr, bg_color,
438 (borders.top >= borders.left ? x : x + 1.0),
440 (borders.top >= borders.right ?
441 x + width : x + width - 1),
446 draw_cell_line (cr, bg_color,
447 (borders.bottom >= borders.left ? x : x + 1.0),
449 (borders.bottom >= borders.right ?
450 x + width : x + width - 1),
455 draw_cell_line (cr, bg_color,
456 (x == 0 ? x + 0.5 : x - 0.5),
457 (borders.left > borders.top ? y : y),
458 (x == 0 ? x + 0.5 : x - 0.5),
459 (borders.left > borders.bottom ?
460 y + height : y + height),
464 draw_cell_line (cr, bg_color,
466 (borders.right > borders.top ? y : y),
468 (borders.right > borders.bottom ?
469 y + height : y + height),
473 draw_hatching (cr, x, y, width, height);
477 draw_divider_line (cr, virt_loc,
478 table->model->dividing_row_upper, block->
style->nrows,
479 fg_color, x, y, width, height);
483 draw_divider_line (cr, virt_loc,
484 table->model->dividing_row, block->
style->nrows,
485 fg_color, x, y, width, height);
488 draw_divider_line (cr, virt_loc,
489 table->model->dividing_row_lower, block->
style->nrows,
490 fg_color, x, y, width, height);
492 layout = gtk_widget_create_pango_layout (GTK_WIDGET (sheet), text);
494 if (gtk_style_context_has_class (stylectxt, GTK_STYLE_CLASS_VIEW))
495 gtk_style_context_remove_class (stylectxt, GTK_STYLE_CLASS_VIEW);
498 pango_layout_set_width (layout, -1);
499 context = pango_layout_get_context (layout);
500 font = pango_font_description_copy (pango_context_get_font_description (context));
502 #ifdef READONLY_LINES_WITH_CHANGED_FG_COLOR 504 if ((virt_loc.phys_row_offset < block->
style->nrows)
505 && (
table->model->dividing_row_upper >= 0)
506 && (virt_loc.vcell_loc.virt_row <
table->model->dividing_row_upper))
509 gtk_style_context_add_class (stylectxt,
"gnc-class-lighter-grey-mix");
513 if ((text != NULL) && (*text !=
'\0') && g_strcmp0 (PRICE_CELL_TYPE_NAME,
514 gnc_table_get_cell_type_name (
table, virt_loc)) == 0)
517 int text_border_padding;
519 pango_layout_get_pixel_size (layout, &text_width, NULL);
521 text_border_padding = gnc_item_edit_get_margin (item_edit, left_right) +
522 gnc_item_edit_get_padding_border (item_edit, left_right);
524 if (text_width + text_border_padding > width)
526 int pango_width = (width - text_border_padding) * PANGO_SCALE;
528 pango_layout_set_width (layout, pango_width);
529 pango_layout_set_ellipsize (layout, PANGO_ELLIPSIZE_END);
535 if ((
table->current_cursor_loc.vcell_loc.virt_row ==
536 virt_loc.vcell_loc.virt_row) &&
537 (!text || strlen(text) == 0))
539 text = gnc_table_get_label (
table, virt_loc);
540 if ((text == NULL) || (*text ==
'\0'))
544 gtk_style_context_add_class (stylectxt,
"gnc-class-lighter-grey-mix");
546 pango_layout_set_text (layout, text, strlen (text));
547 pango_font_description_set_style (font, PANGO_STYLE_ITALIC);
548 pango_context_set_font_description (context, font);
551 if ((text == NULL) || (*text ==
'\0'))
556 pango_layout_get_pixel_extents (layout, NULL, &logical_rect);
558 gnucash_sheet_set_text_bounds (sheet, &rect, x, y, width, height);
561 cairo_rectangle (cr, rect.x, rect.y, rect.width, rect.height);
564 x_offset = gnucash_sheet_get_text_offset (sheet, virt_loc,
565 rect.width, logical_rect.width);
567 gtk_render_layout (stylectxt, cr, rect.x + x_offset,
568 rect.y + gnc_item_edit_get_padding_border (item_edit, top), layout);
573 pango_font_description_set_style (font, PANGO_STYLE_NORMAL);
574 pango_context_set_font_description (context, font);
575 pango_font_description_free (font);
576 g_object_unref (layout);
578 gtk_style_context_restore (stylectxt);
582 draw_block (GnucashSheet *sheet,
SheetBlock *block,
583 VirtualLocation virt_loc, cairo_t *cr,
584 int x,
int y,
int width,
int height)
591 for (virt_loc.phys_row_offset = 0;
592 virt_loc.phys_row_offset < block->
style->nrows ;
593 virt_loc.phys_row_offset++)
595 for (virt_loc.phys_col_offset = 0;
596 virt_loc.phys_col_offset < block->
style->ncols ;
597 virt_loc.phys_col_offset++)
599 cd = gnucash_style_get_cell_dimensions
601 virt_loc.phys_row_offset,
602 virt_loc.phys_col_offset);
606 x_paint = block->origin_x + cd->origin_x - x;
610 y_paint = block->
origin_y + cd->origin_y - y;
611 if (y_paint > height)
614 h = cd->pixel_height;
626 draw_cell (sheet, block, virt_loc, cr,
627 x_paint, y_paint, w, h);
633 gnucash_sheet_draw_internal (GnucashSheet* sheet, cairo_t* cr,
634 GtkAllocation* alloc)
636 VirtualLocation virt_loc = {{0, 0}, 0, 0};
640 int width = alloc->width;
641 int height = alloc->height;
644 adj = gtk_scrollable_get_hadjustment (GTK_SCROLLABLE(sheet));
645 x = (gint) gtk_adjustment_get_value (adj);
646 adj = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE(sheet));
647 y = (gint) gtk_adjustment_get_value (adj);
653 sheet_block = find_block_by_pixel (sheet, x, y, &virt_loc.vcell_loc);
654 if (!sheet_block || !sheet_block->
style)
657 sheet->read_only = gnc_table_model_read_only (sheet->table->model);
659 for ( ; virt_loc.vcell_loc.virt_row < sheet->num_virt_rows;
660 virt_loc.vcell_loc.virt_row++ )
664 sheet_block = gnucash_sheet_get_block (sheet, virt_loc.vcell_loc);
666 if (!sheet_block || !sheet_block->
style)
672 virt_loc.vcell_loc.virt_row++;
675 if (y + height < sheet_block->origin_y)
678 draw_block (sheet, sheet_block, virt_loc, cr,
679 x, y, width, height);
686 gnucash_sheet_draw_cursor (
GnucashCursor *cursor, cairo_t *cr)
694 adj = gtk_scrollable_get_hadjustment (GTK_SCROLLABLE(cursor->sheet));
695 x = (gint) gtk_adjustment_get_value (adj);
696 adj = gtk_scrollable_get_vadjustment (GTK_SCROLLABLE(cursor->sheet));
697 y = (gint) gtk_adjustment_get_value (adj);
699 fg_color = &gn_black;
702 cairo_set_source_rgb (cr, fg_color->red, fg_color->green, fg_color->blue);
704 cairo_rectangle (cr, cursor->x - x + 0.5, cursor->y - y - 0.5, cursor->w - 1.0, cursor->h - 2.0);
706 cairo_rectangle (cr, cursor->x - x - 0.5, cursor->y - y - 0.5, cursor->w, cursor->h - 2.0);
708 cairo_set_line_width (cr, 1.0);
712 cairo_move_to (cr, cursor->x - x + 0.5, cursor->y - y + cursor->h - 3.5);
713 cairo_rel_line_to (cr, cursor->w, 0);
714 cairo_set_line_width (cr, 1.0);
718 cairo_set_source_rgb (cr, fg_color->red, fg_color->green, fg_color->blue);
720 cairo_rectangle (cr, cc->x - x - 0.5, cursor->y + cc->y - y - 0.5, cc->w, cc->h);
722 cairo_rectangle (cr, cc->x - x + 0.5, cursor->y + cc->y - y - 0.5, cc->w - 1.0, cc->h);
724 cairo_set_line_width (cr, 1.0);
Convenience wrapper around GdkRGBA for use in Register Gnome classes.
void gnc_style_context_get_background_color(GtkStyleContext *context, GtkStateFlags state, GdkRGBA *color)
Wrapper to get the background color of a widget for a given state.
void gnucash_get_style_classes(GnucashSheet *sheet, GtkStyleContext *stylectxt, RegisterColor field_type, gboolean use_neg_class)
Map a cell color type to a css style class.
gboolean visible
y origin of block
Public declarations of GnucashRegister class.
Private declarations for GnucashSheet class.
gboolean gnc_table_move_vertical_position(Table *table, VirtualLocation *virt_loc, int phys_row_offset)
Moves away from virtual location virt_loc by phys_row_offset physical rows.
SheetBlockStyle * style
The style for this block.
Styling functions for RegisterGnome.
gint origin_y
x origin of block