mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Reduce grid object from a complete widget to only two utility functions
There was no added value in it being a full widget. It only served two functions really - speed draw the visible and non-editable part of a register window - locating a cell starting from a pixel Both are used exclusively by the sheet object, so I have made them private functions of the sheet. They are still kept in a separate file though for length considerations.
This commit is contained in:
parent
3025e30e4a
commit
6c06336d3e
@ -554,12 +554,12 @@ src/register/register-gnome/gncmod-register-gnome.c
|
||||
src/register/register-gnome/gnucash-color.c
|
||||
src/register/register-gnome/gnucash-cursor.c
|
||||
src/register/register-gnome/gnucash-date-picker.c
|
||||
src/register/register-gnome/gnucash-grid.c
|
||||
src/register/register-gnome/gnucash-header.c
|
||||
src/register/register-gnome/gnucash-item-edit.c
|
||||
src/register/register-gnome/gnucash-item-list.c
|
||||
src/register/register-gnome/gnucash-scrolled-window.c
|
||||
src/register/register-gnome/gnucash-sheet.c
|
||||
src/register/register-gnome/gnucash-sheet-private.c
|
||||
src/register/register-gnome/gnucash-style.c
|
||||
src/register/register-gnome/pricecell-gnome.c
|
||||
src/register/register-gnome/quickfillcell-gnome.c
|
||||
|
@ -8,11 +8,11 @@ SET (register_gnome_SOURCES
|
||||
gnucash-color.c
|
||||
gnucash-cursor.c
|
||||
gnucash-date-picker.c
|
||||
gnucash-grid.c
|
||||
gnucash-header.c
|
||||
gnucash-item-edit.c
|
||||
gnucash-item-list.c
|
||||
gnucash-scrolled-window.c
|
||||
gnucash-sheet-private.c
|
||||
gnucash-sheet.c
|
||||
gnucash-style.c
|
||||
pricecell-gnome.c
|
||||
@ -25,7 +25,6 @@ SET (register_gnome_noinst_HEADERS
|
||||
gnucash-color.h
|
||||
gnucash-cursor.h
|
||||
gnucash-date-picker.h
|
||||
gnucash-grid.h
|
||||
gnucash-header.h
|
||||
gnucash-item-edit.h
|
||||
gnucash-item-list.h
|
||||
|
@ -23,11 +23,11 @@ libgncmod_register_gnome_la_SOURCES = \
|
||||
gnucash-color.c \
|
||||
gnucash-cursor.c \
|
||||
gnucash-date-picker.c \
|
||||
gnucash-grid.c \
|
||||
gnucash-header.c \
|
||||
gnucash-item-edit.c \
|
||||
gnucash-item-list.c \
|
||||
gnucash-scrolled-window.c \
|
||||
gnucash-sheet-private.c \
|
||||
gnucash-sheet.c \
|
||||
gnucash-style.c \
|
||||
pricecell-gnome.c \
|
||||
@ -39,7 +39,6 @@ noinst_HEADERS = \
|
||||
gnucash-color.h \
|
||||
gnucash-cursor.h \
|
||||
gnucash-date-picker.h \
|
||||
gnucash-grid.h \
|
||||
gnucash-header.h \
|
||||
gnucash-item-edit.h \
|
||||
gnucash-item-list.h \
|
||||
|
@ -32,7 +32,6 @@
|
||||
|
||||
#include "gnucash-color.h"
|
||||
#include "gnucash-cursor.h"
|
||||
#include "gnucash-grid.h"
|
||||
#include "gnucash-sheet.h"
|
||||
#include "gnucash-sheetP.h"
|
||||
#include "gnucash-style.h"
|
||||
|
@ -22,7 +22,6 @@
|
||||
#define GNUCASH_CURSOR_H
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
#include "gnucash-grid.h"
|
||||
#include "gnucash-sheet.h"
|
||||
|
||||
/** @ingroup Register
|
||||
|
@ -1,55 +0,0 @@
|
||||
/********************************************************************\
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation; either version 2 of *
|
||||
* the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License*
|
||||
* along with this program; if not, contact: *
|
||||
* *
|
||||
* Free Software Foundation Voice: +1-617-542-5942 *
|
||||
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
|
||||
* Boston, MA 02110-1301, USA gnu@gnu.org *
|
||||
* *
|
||||
\********************************************************************/
|
||||
|
||||
#ifndef GNUCASH_GRID_H
|
||||
#define GNUCASH_GRID_H
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
#include "table-allgui.h"
|
||||
#include "gnucash-sheet.h"
|
||||
|
||||
/** @ingroup Register
|
||||
* @addtogroup Gnome
|
||||
* @{
|
||||
*/
|
||||
/** @file gnucash-grid.h
|
||||
* @brief GnucashGrid declarations
|
||||
*/
|
||||
|
||||
#define GNUCASH_TYPE_GRID (gnucash_grid_get_type ())
|
||||
#define GNUCASH_GRID(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GNUCASH_TYPE_GRID, GnucashGrid))
|
||||
#define GNUCASH_GRID_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), GNUCASH_TYPE_GRID, GnucashGridClass))
|
||||
#define GNUCASH_IS_GRID(o) (G_TYPE_CHECK_INSTANCE_TYPE((o), GNUCASH_TYPE_GRID))
|
||||
|
||||
typedef struct _GnucashGrid GnucashGrid;
|
||||
typedef struct _GnucashGridClass GnucashGridClass;
|
||||
|
||||
|
||||
GType gnucash_grid_get_type (void);
|
||||
GtkWidget *gnucash_grid_new (GnucashSheet *sheet);
|
||||
|
||||
gboolean gnucash_grid_find_loc_by_pixel (GnucashGrid *grid, gint x, gint y,
|
||||
VirtualLocation *vcell_loc);
|
||||
|
||||
void gnucash_draw_hatching (cairo_t *cr,
|
||||
double x, double y, double width, double height);
|
||||
void gnc_grid_configure (GtkWidget *widget);
|
||||
/** @} */
|
||||
#endif /* GNUCASH_GRID_H */
|
@ -34,7 +34,6 @@
|
||||
#include "gnucash-sheetP.h"
|
||||
#include "gnucash-color.h"
|
||||
#include "gnucash-style.h"
|
||||
#include "gnucash-grid.h"
|
||||
#include "gnucash-cursor.h"
|
||||
#include "gnucash-item-edit.h"
|
||||
|
||||
|
@ -35,7 +35,6 @@
|
||||
#include "gnucash-color.h"
|
||||
#include "gnucash-cursor.h"
|
||||
#include "gnucash-item-edit.h"
|
||||
#include "gnucash-grid.h"
|
||||
#include "gnucash-sheet.h"
|
||||
#include "gnucash-sheetP.h"
|
||||
#include "gnucash-style.h"
|
||||
|
@ -19,12 +19,18 @@
|
||||
\********************************************************************/
|
||||
|
||||
/*
|
||||
* The Gnucash Grid Canvas Item
|
||||
* The Gnucash Grid drawing functions
|
||||
*
|
||||
* Based heavily (i.e., cut and pasted from) on the Gnumeric ItemGrid.
|
||||
* The gnucash grid used to be a fully fledged object. However it has no
|
||||
* intelligence of its own, so instead I have reduced it to just a complex
|
||||
* drawing function.
|
||||
* It specializes in drawing the non-editable parts of a gnucash sheet, that is
|
||||
* - the rows and columns with proper backgrounds and borders
|
||||
* - the text for each cell in the table
|
||||
* - dividing lines (red and blue)
|
||||
*
|
||||
* Author:
|
||||
* Heath Martin <martinh@pegasus.cc.ucf.edu>
|
||||
* This could have been addedi directly into gnucash_sheet.c, but is kept
|
||||
* separate to not oversize that file.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
@ -33,76 +39,9 @@
|
||||
|
||||
#include "gnucash-sheet.h"
|
||||
#include "gnucash-sheetP.h"
|
||||
#include "gnucash-grid.h"
|
||||
#include "gnucash-color.h"
|
||||
#include "gnucash-style.h"
|
||||
|
||||
|
||||
struct _GnucashGrid
|
||||
{
|
||||
GtkDrawingArea area;
|
||||
|
||||
GnucashSheet *sheet;
|
||||
};
|
||||
|
||||
|
||||
struct _GnucashGridClass
|
||||
{
|
||||
GtkDrawingAreaClass parent_class;
|
||||
};
|
||||
|
||||
static GtkDrawingAreaClass *gnucash_grid_parent_class;
|
||||
|
||||
/* Our arguments */
|
||||
enum
|
||||
{
|
||||
PROP_0,
|
||||
PROP_SHEET
|
||||
};
|
||||
|
||||
|
||||
static gboolean
|
||||
gnc_grid_configure_cb (GtkWidget *widget,
|
||||
G_GNUC_UNUSED GdkEventConfigure *event)
|
||||
{
|
||||
gnc_grid_configure (widget);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
gnc_grid_configure (GtkWidget *widget)
|
||||
{
|
||||
GnucashGrid *grid = GNUCASH_GRID(widget);
|
||||
GtkRequisition cur_rec;
|
||||
gint cur_x, cur_y;
|
||||
guint w , h;
|
||||
|
||||
gtk_container_child_get(GTK_CONTAINER(grid->sheet),
|
||||
widget,
|
||||
"x", &cur_x, "y", &cur_y, NULL);
|
||||
if ((cur_x != 0) || (cur_y != 0))
|
||||
gtk_layout_move (GTK_LAYOUT(grid->sheet),
|
||||
GTK_WIDGET(grid), 0, 0);
|
||||
|
||||
gtk_layout_get_size (GTK_LAYOUT(grid->sheet), &w, &h);
|
||||
gtk_widget_get_requisition(GTK_WIDGET(grid), &cur_rec);
|
||||
if ((cur_rec.height != h) || (cur_rec.width != w))
|
||||
gtk_widget_set_size_request(GTK_WIDGET(grid), w, h);
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
gnucash_grid_realize (GtkWidget *widget)
|
||||
{
|
||||
|
||||
if (GTK_WIDGET_CLASS (gnucash_grid_parent_class)->realize)
|
||||
(GTK_WIDGET_CLASS
|
||||
(gnucash_grid_parent_class)->realize)(widget);
|
||||
|
||||
gnc_grid_configure (widget);
|
||||
}
|
||||
|
||||
/*
|
||||
* Sets virt_row, virt_col to the block coordinates for the
|
||||
* block containing pixel (x, y). Also sets o_x, o_y, to the
|
||||
@ -113,9 +52,9 @@ gnucash_grid_realize (GtkWidget *widget)
|
||||
* All coordinates are with respect to the canvas origin.
|
||||
*/
|
||||
static SheetBlock *
|
||||
gnucash_grid_find_block_by_pixel (GnucashGrid *grid,
|
||||
gint x, gint y,
|
||||
VirtualCellLocation *vcell_loc)
|
||||
find_block_by_pixel (GnucashSheet *sheet,
|
||||
gint x, gint y,
|
||||
VirtualCellLocation *vcell_loc)
|
||||
{
|
||||
SheetBlock *block;
|
||||
VirtualCellLocation vc_loc = { 1, 0 };
|
||||
@ -125,7 +64,7 @@ gnucash_grid_find_block_by_pixel (GnucashGrid *grid,
|
||||
|
||||
do
|
||||
{
|
||||
block = gnucash_sheet_get_block (grid->sheet, vc_loc);
|
||||
block = gnucash_sheet_get_block (sheet, vc_loc);
|
||||
if (!block)
|
||||
return NULL;
|
||||
|
||||
@ -139,14 +78,14 @@ gnucash_grid_find_block_by_pixel (GnucashGrid *grid,
|
||||
}
|
||||
vc_loc.virt_row++;
|
||||
}
|
||||
while (vc_loc.virt_row < grid->sheet->num_virt_rows);
|
||||
while (vc_loc.virt_row < sheet->num_virt_rows);
|
||||
|
||||
if (vc_loc.virt_row == grid->sheet->num_virt_rows)
|
||||
if (vc_loc.virt_row == sheet->num_virt_rows)
|
||||
return NULL;
|
||||
|
||||
do
|
||||
{
|
||||
block = gnucash_sheet_get_block (grid->sheet, vc_loc);
|
||||
block = gnucash_sheet_get_block (sheet, vc_loc);
|
||||
if (!block)
|
||||
return NULL;
|
||||
|
||||
@ -160,17 +99,17 @@ gnucash_grid_find_block_by_pixel (GnucashGrid *grid,
|
||||
}
|
||||
vc_loc.virt_col++;
|
||||
}
|
||||
while (vc_loc.virt_col < grid->sheet->num_virt_cols);
|
||||
while (vc_loc.virt_col < sheet->num_virt_cols);
|
||||
|
||||
if (vc_loc.virt_col == grid->sheet->num_virt_cols)
|
||||
if (vc_loc.virt_col == sheet->num_virt_cols)
|
||||
return NULL;
|
||||
|
||||
return block;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gnucash_grid_find_cell_by_pixel (GnucashGrid *grid, gint x, gint y,
|
||||
VirtualLocation *virt_loc)
|
||||
find_cell_by_pixel (GnucashSheet *sheet, gint x, gint y,
|
||||
VirtualLocation *virt_loc)
|
||||
{
|
||||
SheetBlock *block;
|
||||
SheetBlockStyle *style;
|
||||
@ -180,7 +119,7 @@ gnucash_grid_find_cell_by_pixel (GnucashGrid *grid, gint x, gint y,
|
||||
|
||||
g_return_val_if_fail (virt_loc != NULL, FALSE);
|
||||
|
||||
block = gnucash_sheet_get_block (grid->sheet, virt_loc->vcell_loc);
|
||||
block = gnucash_sheet_get_block (sheet, virt_loc->vcell_loc);
|
||||
if (block == NULL)
|
||||
return FALSE;
|
||||
|
||||
@ -229,62 +168,20 @@ gnucash_grid_find_cell_by_pixel (GnucashGrid *grid, gint x, gint y,
|
||||
}
|
||||
|
||||
gboolean
|
||||
gnucash_grid_find_loc_by_pixel (GnucashGrid *grid, gint x, gint y,
|
||||
VirtualLocation *virt_loc)
|
||||
gnucash_sheet_find_loc_by_pixel (GnucashSheet *sheet, gint x, gint y,
|
||||
VirtualLocation *virt_loc)
|
||||
{
|
||||
SheetBlock *block;
|
||||
|
||||
if (virt_loc == NULL)
|
||||
return FALSE;
|
||||
|
||||
block = gnucash_grid_find_block_by_pixel (grid, x, y,
|
||||
block = find_block_by_pixel (sheet, x, y,
|
||||
&virt_loc->vcell_loc);
|
||||
if (block == NULL)
|
||||
return FALSE;
|
||||
|
||||
return gnucash_grid_find_cell_by_pixel (grid, x, y, virt_loc);
|
||||
}
|
||||
|
||||
G_INLINE_FUNC void
|
||||
draw_cell_line (cairo_t *cr, cairo_rgb *bg_color,
|
||||
double x1, double y1, double x2, double y2,
|
||||
PhysicalCellBorderLineStyle style);
|
||||
|
||||
void
|
||||
draw_cell_line (cairo_t *cr, cairo_rgb *bg_color,
|
||||
double x1, double y1, double x2, double y2,
|
||||
PhysicalCellBorderLineStyle style)
|
||||
{
|
||||
cairo_rgb fg_color;
|
||||
|
||||
switch (style)
|
||||
{
|
||||
case CELL_BORDER_LINE_NONE:
|
||||
fg_color = *bg_color;
|
||||
break;
|
||||
|
||||
case CELL_BORDER_LINE_LIGHT:
|
||||
to_cairo_rgb (&gn_light_gray, &fg_color);
|
||||
break;
|
||||
|
||||
case CELL_BORDER_LINE_NORMAL:
|
||||
case CELL_BORDER_LINE_HEAVY:
|
||||
to_cairo_rgb (&gn_black, &fg_color);
|
||||
break;
|
||||
|
||||
case CELL_BORDER_LINE_HIGHLIGHT:
|
||||
to_cairo_rgb (&gn_red, &fg_color);
|
||||
break;
|
||||
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
cairo_set_line_width (cr, 1.0);
|
||||
cairo_set_source_rgb (cr, fg_color.red, fg_color.green, fg_color.blue);
|
||||
cairo_move_to (cr, x1, y1);
|
||||
cairo_line_to (cr, x2, y2);
|
||||
cairo_stroke (cr);
|
||||
return find_cell_by_pixel (sheet, x, y, virt_loc);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -331,57 +228,6 @@ get_cell_borders (GnucashSheet *sheet, VirtualLocation virt_loc,
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
gnucash_draw_hatching (cairo_t *cr,
|
||||
double x, double y, G_GNUC_UNUSED double width, double height)
|
||||
{
|
||||
cairo_rgb fg_color;
|
||||
double h_x = x + 2.5;
|
||||
double h_y = y + 2.5;
|
||||
double h_size = height / 3 - 1;
|
||||
|
||||
cairo_set_line_width (cr, 1.0);
|
||||
to_cairo_rgb(&gn_light_gray, &fg_color);
|
||||
cairo_set_source_rgb (cr, fg_color.red, fg_color.green, fg_color.blue);
|
||||
|
||||
cairo_rectangle (cr, h_x, h_y, h_size, h_size);
|
||||
|
||||
cairo_move_to (cr, h_x, h_y);
|
||||
cairo_rel_line_to (cr, h_size, h_size);
|
||||
|
||||
cairo_rel_move_to (cr, -h_x, 0);
|
||||
cairo_rel_line_to (cr, h_size, -h_size);
|
||||
cairo_stroke (cr);
|
||||
}
|
||||
|
||||
static void
|
||||
grid_draw_divider_line (cairo_t *cr, VirtualLocation virt_loc,
|
||||
int div_row, int n_phys_rows, cairo_rgb *fg_color,
|
||||
double x, double y, double width, double height)
|
||||
{
|
||||
double offset;
|
||||
if (div_row < 0)
|
||||
return;
|
||||
|
||||
/* Test if divider line should be drawn before the current row */
|
||||
if ((virt_loc.phys_row_offset == 0) &&
|
||||
(virt_loc.vcell_loc.virt_row == div_row))
|
||||
offset = 0.0;
|
||||
/* Test if divider line should be drawn after the current row */
|
||||
else if ((virt_loc.phys_row_offset == n_phys_rows - 1) &&
|
||||
(virt_loc.vcell_loc.virt_row == div_row - 1))
|
||||
offset = height;
|
||||
else
|
||||
return;
|
||||
|
||||
cairo_set_source_rgb (cr, fg_color->red, fg_color->green, fg_color->blue);
|
||||
|
||||
cairo_set_line_width (cr, 3.0);
|
||||
cairo_move_to (cr, x, y + 0.5 + offset);
|
||||
cairo_rel_line_to (cr, width, 0);
|
||||
cairo_stroke (cr);
|
||||
}
|
||||
|
||||
|
||||
#ifdef READONLY_LINES_WITH_CHANGED_FG_COLOR
|
||||
/** For a given byte value, multiply the difference to 0xFF by a rational number,
|
||||
@ -434,14 +280,109 @@ static guint32 dec_intensity_10percent(guint32 argb)
|
||||
return result;
|
||||
}
|
||||
|
||||
/* Actual drawing routines */
|
||||
|
||||
G_INLINE_FUNC void
|
||||
draw_cell_line (cairo_t *cr, cairo_rgb *bg_color,
|
||||
double x1, double y1, double x2, double y2,
|
||||
PhysicalCellBorderLineStyle style);
|
||||
|
||||
void
|
||||
draw_cell_line (cairo_t *cr, cairo_rgb *bg_color,
|
||||
double x1, double y1, double x2, double y2,
|
||||
PhysicalCellBorderLineStyle style)
|
||||
{
|
||||
cairo_rgb fg_color;
|
||||
|
||||
switch (style)
|
||||
{
|
||||
case CELL_BORDER_LINE_NONE:
|
||||
fg_color = *bg_color;
|
||||
break;
|
||||
|
||||
case CELL_BORDER_LINE_LIGHT:
|
||||
to_cairo_rgb (&gn_light_gray, &fg_color);
|
||||
break;
|
||||
|
||||
case CELL_BORDER_LINE_NORMAL:
|
||||
case CELL_BORDER_LINE_HEAVY:
|
||||
to_cairo_rgb (&gn_black, &fg_color);
|
||||
break;
|
||||
|
||||
case CELL_BORDER_LINE_HIGHLIGHT:
|
||||
to_cairo_rgb (&gn_red, &fg_color);
|
||||
break;
|
||||
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
cairo_set_line_width (cr, 1.0);
|
||||
cairo_set_source_rgb (cr, fg_color.red, fg_color.green, fg_color.blue);
|
||||
cairo_move_to (cr, x1, y1);
|
||||
cairo_line_to (cr, x2, y2);
|
||||
cairo_stroke (cr);
|
||||
}
|
||||
|
||||
static void
|
||||
draw_cell (GnucashGrid *grid,
|
||||
draw_hatching (cairo_t *cr,
|
||||
double x, double y, G_GNUC_UNUSED double width, double height)
|
||||
{
|
||||
cairo_rgb fg_color;
|
||||
double h_x = x + 2.5;
|
||||
double h_y = y + 2.5;
|
||||
double h_size = height / 3 - 1;
|
||||
|
||||
cairo_set_line_width (cr, 1.0);
|
||||
to_cairo_rgb(&gn_light_gray, &fg_color);
|
||||
cairo_set_source_rgb (cr, fg_color.red, fg_color.green, fg_color.blue);
|
||||
|
||||
cairo_rectangle (cr, h_x, h_y, h_size, h_size);
|
||||
|
||||
cairo_move_to (cr, h_x, h_y);
|
||||
cairo_rel_line_to (cr, h_size, h_size);
|
||||
|
||||
cairo_rel_move_to (cr, -h_x, 0);
|
||||
cairo_rel_line_to (cr, h_size, -h_size);
|
||||
cairo_stroke (cr);
|
||||
}
|
||||
|
||||
static void
|
||||
draw_divider_line (cairo_t *cr, VirtualLocation virt_loc,
|
||||
int div_row, int n_phys_rows, cairo_rgb *fg_color,
|
||||
double x, double y, double width, double height)
|
||||
{
|
||||
double offset;
|
||||
if (div_row < 0)
|
||||
return;
|
||||
|
||||
/* Test if divider line should be drawn before the current row */
|
||||
if ((virt_loc.phys_row_offset == 0) &&
|
||||
(virt_loc.vcell_loc.virt_row == div_row))
|
||||
offset = 0.0;
|
||||
/* Test if divider line should be drawn after the current row */
|
||||
else if ((virt_loc.phys_row_offset == n_phys_rows - 1) &&
|
||||
(virt_loc.vcell_loc.virt_row == div_row - 1))
|
||||
offset = height;
|
||||
else
|
||||
return;
|
||||
|
||||
cairo_set_source_rgb (cr, fg_color->red, fg_color->green, fg_color->blue);
|
||||
|
||||
cairo_set_line_width (cr, 3.0);
|
||||
cairo_move_to (cr, x, y + 0.5 + offset);
|
||||
cairo_rel_line_to (cr, width, 0);
|
||||
cairo_stroke (cr);
|
||||
}
|
||||
|
||||
static void
|
||||
draw_cell (GnucashSheet *sheet,
|
||||
SheetBlock *block,
|
||||
VirtualLocation virt_loc,
|
||||
cairo_t *cr,
|
||||
int x, int y, int width, int height)
|
||||
{
|
||||
Table *table = grid->sheet->table;
|
||||
Table *table = sheet->table;
|
||||
PhysicalCellBorders borders;
|
||||
const char *text;
|
||||
PangoLayout *layout;
|
||||
@ -455,11 +396,11 @@ draw_cell (GnucashGrid *grid,
|
||||
guint32 argb, color_type;
|
||||
int x_offset;
|
||||
|
||||
if (grid->sheet->use_theme_colors)
|
||||
if (sheet->use_theme_colors)
|
||||
{
|
||||
color_type = gnc_table_get_gtkrc_bg_color (table, virt_loc,
|
||||
&hatching);
|
||||
gdk_bg_color = get_gtkrc_color(grid->sheet, color_type);
|
||||
gdk_bg_color = get_gtkrc_color(sheet, color_type);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -479,7 +420,7 @@ draw_cell (GnucashGrid *grid,
|
||||
cairo_rectangle (cr, x, y, width, height);
|
||||
cairo_fill (cr);
|
||||
|
||||
get_cell_borders (grid->sheet, virt_loc, &borders);
|
||||
get_cell_borders (sheet, virt_loc, &borders);
|
||||
|
||||
/* top */
|
||||
draw_cell_line (cr, &bg_color,
|
||||
@ -518,38 +459,38 @@ draw_cell (GnucashGrid *grid,
|
||||
borders.right);
|
||||
|
||||
if (hatching)
|
||||
gnucash_draw_hatching (cr,
|
||||
draw_hatching (cr,
|
||||
x, y, width, height);
|
||||
|
||||
/* dividing line upper (red) */
|
||||
to_cairo_rgb (&gn_red, &fg_color);
|
||||
grid_draw_divider_line(cr, virt_loc,
|
||||
draw_divider_line(cr, virt_loc,
|
||||
table->model->dividing_row_upper, block->style->nrows,
|
||||
&fg_color, x, y, width, height);
|
||||
|
||||
/* dividing line (blue) */
|
||||
to_cairo_rgb (&gn_blue, &fg_color);
|
||||
grid_draw_divider_line(cr, virt_loc,
|
||||
draw_divider_line(cr, virt_loc,
|
||||
table->model->dividing_row, block->style->nrows,
|
||||
&fg_color, x, y, width, height);
|
||||
|
||||
/* dividing line lower (blue) */
|
||||
grid_draw_divider_line(cr, virt_loc,
|
||||
draw_divider_line(cr, virt_loc,
|
||||
table->model->dividing_row_lower, block->style->nrows,
|
||||
&fg_color, x, y, width, height);
|
||||
|
||||
text = gnc_table_get_entry (table, virt_loc);
|
||||
|
||||
layout = gtk_widget_create_pango_layout (GTK_WIDGET (grid), text);
|
||||
layout = gtk_widget_create_pango_layout (GTK_WIDGET (sheet), text);
|
||||
// We don't need word wrap or line wrap
|
||||
pango_layout_set_width (layout, -1);
|
||||
context = pango_layout_get_context (layout);
|
||||
font = pango_font_description_copy (pango_context_get_font_description (context));
|
||||
|
||||
if (grid->sheet->use_theme_colors)
|
||||
if (sheet->use_theme_colors)
|
||||
{
|
||||
color_type = gnc_table_get_gtkrc_fg_color (table, virt_loc);
|
||||
gdk_fg_color = get_gtkrc_color(grid->sheet, color_type);
|
||||
gdk_fg_color = get_gtkrc_color(sheet, color_type);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -637,7 +578,7 @@ exit:
|
||||
}
|
||||
|
||||
static void
|
||||
draw_block (GnucashGrid *grid,
|
||||
draw_block (GnucashSheet *sheet,
|
||||
SheetBlock *block,
|
||||
VirtualLocation virt_loc,
|
||||
cairo_t *cr,
|
||||
@ -681,41 +622,35 @@ draw_block (GnucashGrid *grid,
|
||||
if (y_paint + h < y)
|
||||
continue;
|
||||
|
||||
draw_cell (grid, block, virt_loc, cr,
|
||||
draw_cell (sheet, block, virt_loc, cr,
|
||||
x_paint, y_paint, w, h);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gnucash_grid_draw (GtkWidget *widget, GdkEventExpose *event)
|
||||
gboolean
|
||||
gnucash_sheet_draw_internal (GnucashSheet *sheet, cairo_t *cr,
|
||||
int x, int y, int width, int height)
|
||||
{
|
||||
GnucashGrid *grid = GNUCASH_GRID (widget);
|
||||
VirtualLocation virt_loc;
|
||||
SheetBlock *sheet_block;
|
||||
int x = event->area.x;
|
||||
int y = event->area.y;
|
||||
int width = event->area.width;
|
||||
int height = event->area.height;
|
||||
GdkWindow *binwin = gtk_widget_get_window(widget);
|
||||
cairo_t *cr = gdk_cairo_create (binwin);
|
||||
|
||||
if (x < 0 || y < 0)
|
||||
return FALSE;
|
||||
|
||||
/* compute our initial values where we start drawing */
|
||||
sheet_block = gnucash_grid_find_block_by_pixel (grid, x, y,
|
||||
sheet_block = find_block_by_pixel (sheet, x, y,
|
||||
&virt_loc.vcell_loc);
|
||||
if (!sheet_block || !sheet_block->style)
|
||||
return FALSE;
|
||||
|
||||
for ( ; virt_loc.vcell_loc.virt_row < grid->sheet->num_virt_rows;
|
||||
for ( ; virt_loc.vcell_loc.virt_row < sheet->num_virt_rows;
|
||||
virt_loc.vcell_loc.virt_row++ )
|
||||
{
|
||||
while (TRUE)
|
||||
{
|
||||
sheet_block = gnucash_sheet_get_block
|
||||
(grid->sheet, virt_loc.vcell_loc);
|
||||
(sheet, virt_loc.vcell_loc);
|
||||
|
||||
if (!sheet_block || !sheet_block->style)
|
||||
return TRUE;
|
||||
@ -729,133 +664,9 @@ gnucash_grid_draw (GtkWidget *widget, GdkEventExpose *event)
|
||||
if (y + height < sheet_block->origin_y)
|
||||
return TRUE;
|
||||
|
||||
draw_block (grid, sheet_block, virt_loc, cr,
|
||||
draw_block (sheet, sheet_block, virt_loc, cr,
|
||||
x, y, width, height);
|
||||
}
|
||||
|
||||
// cairo_set_source_surface (cr, surface, 0, 0);
|
||||
// cairo_paint (cr);
|
||||
cairo_destroy (cr);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
gnucash_grid_init (GnucashGrid *grid)
|
||||
{
|
||||
grid->sheet = NULL;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
gnucash_grid_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
GnucashGrid *grid = GNUCASH_GRID (object);
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_SHEET:
|
||||
if (grid->sheet)
|
||||
gtk_container_remove(GTK_CONTAINER(grid->sheet), GTK_WIDGET(grid));
|
||||
grid->sheet =
|
||||
GNUCASH_SHEET (g_value_get_object (value));
|
||||
if (grid->sheet)
|
||||
gtk_layout_put (GTK_LAYOUT(grid->sheet), GTK_WIDGET(grid), 0, 0);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Note that g_value_set_object() refs the object, as does
|
||||
* g_object_get(). But g_object_get() only unrefs once when it disgorges
|
||||
* the object, leaving an unbalanced ref, which leaks. So instead of
|
||||
* using g_value_set_object(), use g_value_take_object() which doesn't
|
||||
* ref the object when used in get_property().
|
||||
*/
|
||||
static void
|
||||
gnucash_grid_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
GnucashGrid *grid = GNUCASH_GRID (object);
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_SHEET:
|
||||
g_value_take_object (value, grid->sheet);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
gnucash_grid_class_init (GnucashGridClass *klass)
|
||||
{
|
||||
GObjectClass *object_class;
|
||||
GtkWidgetClass *widget_class;
|
||||
|
||||
object_class = G_OBJECT_CLASS (klass);
|
||||
widget_class = GTK_WIDGET_CLASS (klass);
|
||||
|
||||
gnucash_grid_parent_class = g_type_class_peek_parent (klass);
|
||||
|
||||
/* GObject method overrides */
|
||||
object_class->set_property = gnucash_grid_set_property;
|
||||
object_class->get_property = gnucash_grid_get_property;
|
||||
|
||||
/* GtkWidget method overrides */
|
||||
// widget_class->configure_event = gnc_grid_configure_cb;
|
||||
widget_class->realize = gnucash_grid_realize;
|
||||
widget_class->expose_event = gnucash_grid_draw;
|
||||
|
||||
/* properties */
|
||||
g_object_class_install_property
|
||||
(object_class,
|
||||
PROP_SHEET,
|
||||
g_param_spec_object ("sheet",
|
||||
"Sheet Value",
|
||||
"Sheet Value",
|
||||
GNUCASH_TYPE_SHEET,
|
||||
G_PARAM_READWRITE));
|
||||
}
|
||||
|
||||
|
||||
GType
|
||||
gnucash_grid_get_type (void)
|
||||
{
|
||||
static GType gnucash_grid_type = 0;
|
||||
|
||||
if (!gnucash_grid_type)
|
||||
{
|
||||
static const GTypeInfo gnucash_grid_info =
|
||||
{
|
||||
sizeof (GnucashGridClass),
|
||||
NULL, /* base_init */
|
||||
NULL, /* base_finalize */
|
||||
(GClassInitFunc) gnucash_grid_class_init,
|
||||
NULL, /* class_finalize */
|
||||
NULL, /* class_data */
|
||||
sizeof (GnucashGrid),
|
||||
0, /* n_preallocs */
|
||||
(GInstanceInitFunc) gnucash_grid_init
|
||||
};
|
||||
|
||||
gnucash_grid_type =
|
||||
g_type_register_static (GTK_TYPE_DRAWING_AREA,
|
||||
"GnucashGrid",
|
||||
&gnucash_grid_info, 0);
|
||||
}
|
||||
|
||||
return gnucash_grid_type;
|
||||
}
|
||||
|
||||
|
@ -39,7 +39,6 @@
|
||||
#include "dialog-utils.h"
|
||||
#include "gnc-prefs.h"
|
||||
#include "gnucash-color.h"
|
||||
#include "gnucash-grid.h"
|
||||
#include "gnucash-cursor.h"
|
||||
#include "gnucash-style.h"
|
||||
#include "gnucash-header.h"
|
||||
@ -1112,6 +1111,25 @@ gnucash_sheet_delete_cb (GtkWidget *widget,
|
||||
g_string_free (new_text_gs, TRUE);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gnucash_sheet_draw (GtkWidget *widget, GdkEventExpose *event)
|
||||
{
|
||||
GnucashSheet *sheet = GNUCASH_SHEET (widget);
|
||||
int x = event->area.x;
|
||||
int y = event->area.y;
|
||||
int width = event->area.width;
|
||||
int height = event->area.height;
|
||||
GdkWindow *binwin = gtk_layout_get_bin_window(GTK_LAYOUT(sheet));
|
||||
cairo_t *cr;
|
||||
gboolean result;
|
||||
|
||||
cr = gdk_cairo_create (binwin);
|
||||
result = gnucash_sheet_draw_internal (sheet, cr, x, y, width, height);
|
||||
cairo_destroy(cr);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
gnucash_sheet_size_allocate (GtkWidget *widget, GtkAllocation *allocation)
|
||||
@ -1435,7 +1453,7 @@ gnucash_button_press_event (GtkWidget *widget, GdkEventButton *event)
|
||||
|
||||
gnucash_cursor_get_virt (GNUCASH_CURSOR(sheet->cursor), &cur_virt_loc);
|
||||
|
||||
if (!gnucash_grid_find_loc_by_pixel(GNUCASH_GRID(sheet->grid),
|
||||
if (!gnucash_sheet_find_loc_by_pixel(sheet,
|
||||
event->x, event->y, &new_virt_loc))
|
||||
return TRUE;
|
||||
|
||||
@ -2448,9 +2466,6 @@ gnucash_sheet_set_scroll_region (GnucashSheet *sheet)
|
||||
|
||||
if (new_w != old_w || new_h != old_h)
|
||||
gtk_layout_set_size (GTK_LAYOUT(sheet), new_w, new_h);
|
||||
|
||||
if (sheet->grid)
|
||||
gnc_grid_configure (sheet->grid);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -2768,6 +2783,8 @@ gnucash_sheet_class_init (GnucashSheetClass *klass)
|
||||
widget_class->motion_notify_event = gnucash_motion_event;
|
||||
widget_class->scroll_event = gnucash_scroll_event;
|
||||
|
||||
widget_class->expose_event = gnucash_sheet_draw;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -2866,12 +2883,6 @@ gnucash_sheet_new (Table *table)
|
||||
|
||||
sheet = gnucash_sheet_create (table);
|
||||
|
||||
/* The grid */
|
||||
sheet->grid = g_object_new (GNUCASH_TYPE_GRID,
|
||||
"sheet", sheet,
|
||||
NULL);
|
||||
gtk_widget_show (sheet->grid);
|
||||
|
||||
/* The cursor */
|
||||
sheet->cursor = gnucash_cursor_new (sheet);
|
||||
|
||||
|
@ -51,7 +51,6 @@ struct _GnucashSheet
|
||||
|
||||
GtkWidget *header_item;
|
||||
GtkWidget *cursor;
|
||||
GtkWidget *grid;
|
||||
|
||||
GHashTable *cursor_styles;
|
||||
|
||||
@ -156,5 +155,11 @@ GncItemEdit *gnucash_sheet_get_item_edit (GnucashSheet *sheet);
|
||||
//gint gnucash_sheet_get_num_virt_rows (GnucashSheet *sheet);
|
||||
//gint gnucash_sheet_get_num_virt_cols (GnucashSheet *sheet);
|
||||
|
||||
gboolean gnucash_sheet_find_loc_by_pixel (GnucashSheet *sheet, gint x, gint y,
|
||||
VirtualLocation *vcell_loc);
|
||||
gboolean gnucash_sheet_draw_internal (GnucashSheet *sheet, cairo_t *cr,
|
||||
int x, int y, int width, int height);
|
||||
|
||||
|
||||
/** @} */
|
||||
#endif
|
||||
|
@ -24,7 +24,6 @@
|
||||
|
||||
#include "config.h"
|
||||
#include "gnucash-color.h"
|
||||
#include "gnucash-grid.h"
|
||||
#include "gnucash-item-edit.h"
|
||||
#include "gnucash-sheet.h"
|
||||
#include "gnucash-sheetP.h"
|
||||
@ -166,7 +165,6 @@ static void
|
||||
set_dimensions_pass_one (GnucashSheet *sheet, CellBlock *cursor,
|
||||
BlockDimensions *dimensions)
|
||||
{
|
||||
/* GdkFont *font = GNUCASH_GRID(sheet->grid)->normal_font; */
|
||||
CellDimensions *cd;
|
||||
int row, col;
|
||||
gint max_height = -1;
|
||||
@ -291,8 +289,6 @@ set_dimensions_pass_two (GnucashSheet *sheet, int default_width)
|
||||
}
|
||||
else if (width > default_width && width == sheet->window_width)
|
||||
{
|
||||
/*GdkFont *font = GNUCASH_GRID(sheet->grid)->normal_font;*/
|
||||
|
||||
for (col = 0; col < num_cols; col++)
|
||||
{
|
||||
BasicCell *cell;
|
||||
|
Loading…
Reference in New Issue
Block a user