Commit 116d59c0 authored by Arturo Espinosa's avatar Arturo Espinosa

First take at the span looklup code -mig

parent c852cd15
1998-09-03 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/utils.c (int_get_from_range): Bug fix, we were not doing the
range thing for the "big" case. Thanks to Alan for finding this
bug.
1998-09-02 Tristan Tarrant <ttarrant@etnoteam.it>
* configure.in: Included it in ALL_LINGUAS
......
1998-09-03 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/utils.c (int_get_from_range): Bug fix, we were not doing the
range thing for the "big" case. Thanks to Alan for finding this
bug.
1998-09-02 Tristan Tarrant <ttarrant@etnoteam.it>
* configure.in: Included it in ALL_LINGUAS
......
1998-09-03 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/utils.c (int_get_from_range): Bug fix, we were not doing the
range thing for the "big" case. Thanks to Alan for finding this
bug.
1998-09-02 Tristan Tarrant <ttarrant@etnoteam.it>
* configure.in: Included it in ALL_LINGUAS
......
1998-09-03 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/utils.c (int_get_from_range): Bug fix, we were not doing the
range thing for the "big" case. Thanks to Alan for finding this
bug.
1998-09-02 Tristan Tarrant <ttarrant@etnoteam.it>
* configure.in: Included it in ALL_LINGUAS
......
......@@ -907,4 +907,146 @@ cell_draw (Cell *cell, void *sv, GdkGC *gc, GdkDrawable *drawable, int x1, int y
}
}
static guint
col_hash (gconstpointer key)
{
const int *col = key;
return *col;
}
static gint
col_compare (gconstpointer a, gconstpointer b)
{
const int *col_a = a;
const int *col_b = b;
if (*col_a == *col_b)
return 1;
return 0;
}
/*
* Initializes the hash table in the RowInfo for keeping track
* of cell spans (ie, which cells on the spreadsheet are displayed
* by which cell). This is required, as cells might be using
* more display space than the one where they store their information
*/
void
row_init_span (ColRowInfo *ri)
{
g_return_if_fail (ri != NULL);
ri->data = g_hash_table_new (col_hash, col_compare);
}
static void
free_hash_key (gconstpointer key, gconstpointer value, gconstpointer user_data)
{
g_free ((void *)key);
}
void
row_destroy_span (ColRowInfo *ri)
{
g_return_if_fail (ri != NULL);
g_hash_table_foreach (ri->data, free_hash_key, NULL);
g_hash_table_destroy (ri->data);
}
/*
* sheet_cell_register_span
* @cell: The cell to register the span
* @left: the leftmost column used by the cell
* @right: the rightmost column used by the cell
*
* Registers the region
*/
void
cell_register_span (Cell *cell, int left, int right)
{
ColRowInfo *ri;
int col, i;
g_return_if_fail (cell != NULL);
g_return_if_fail (left <= right);
ri = cell->row;
col = cell->col->pos;
for (i = left; i <= right; i++){
int *key;
/* Do not register our column, as we already keep this on the main hash */
if (i != col)
continue;
key = g_new (int, 1);
*key = i;
g_hash_table_insert (ri->data, key, cell);
}
}
typedef struct {
Cell *cell;
GList *list_of_keys;
} unregister_closure_t;
static void
assemble_unregister_span_list (gpointer key, gpointer value, gpointer user_data)
{
unregister_closure_t *c = user_data;
if (c->cell == value)
c->list_of_keys = g_list_prepend (c->list_of_keys, key);
}
/*
* sheet_cell_unregister_span
* @cell: The cell to remove from the span information
*
* Remove all of the references to this cell on the span hash
* table
*/
void
cell_unregister_span (Cell *cell)
{
unregister_closure_t c;
GList *l;
g_return_if_fail (cell != NULL);
c.cell = cell;
c.list_of_keys = NULL;
g_hash_table_foreach (cell->row->data, assemble_unregister_span_list, &c);
for (l = c.list_of_keys; l; l = l->next){
int *key = l->data;
g_hash_table_remove (cell->row->data, key);
g_free (key);
}
g_list_free (c.list_of_keys);
}
/*
* row_cell_get_displayed_at
* @ri: The ColRowInfo for the row we are looking up
* @col: the column position
*
* Returns the Cell* which happens to display at the column
*/
Cell *
row_cell_get_displayed_at (ColRowInfo *ri, int col)
{
Cell *cell;
g_return_val_if_fail (ri != NULL, NULL);
/* Ok, cell was not found, check the registered span regions */
cell = g_hash_table_lookup (ri->data, &col);
return cell;
}
......@@ -89,5 +89,13 @@ void cell_draw (Cell *cell, void *sheet_view,
void calc_text_dimensions (int is_number, Style *style, char *text,
int cell_w, int cell_h, int *h, int *w);
/* Routines used to lookup which cells displays on a given column */
Cell * row_cell_get_displayed_at (ColRowInfo *ri, int col);
void cell_register_span (Cell *cell, int left, int right);
void cell_unregister_span (Cell *cell);
void row_init_span (ColRowInfo *ri);
void row_destroy_span (ColRowInfo *ri);
#endif /* GNUMERIC_CELL_H */
......@@ -51,7 +51,7 @@ int_get_from_range (char *start, char *end, int_t *t)
} else {
p = g_malloc (size + 1);
strcpy (p, start);
strncpy (p, start, size);
p [size] = 0;
}
#ifdef GNUMERIC_USE_GMP
......
......@@ -165,21 +165,18 @@ typedef struct {
* Draw a cell. It gets pixel level coordinates
*/
static void
item_grid_draw_cell (GdkDrawable *drawable, ItemGrid *item_grid,
item_grid_draw_cell (GdkDrawable *drawable, ItemGrid *item_grid, Cell *cell,
int x1, int y1, ColRowInfo *ci, ColRowInfo *ri, int col, int row)
{
GnomeCanvas *canvas = GNOME_CANVAS_ITEM (item_grid)->canvas;
GdkGC *gc = item_grid->gc;
Sheet *sheet = item_grid->sheet;
Cell *cell;
int cell_is_selected;
int width = ci->pixels;
int height = ri->pixels;
cell_is_selected = sheet_selection_is_cell_selected (sheet, col, row);
cell = sheet_cell_get (sheet, col, row);
#if 0
/* Debugging code for testing the stipples */
gdk_gc_set_stipple (gc, GNUMERIC_SHEET (canvas)->patterns [col % 8]);
......@@ -237,6 +234,7 @@ item_grid_draw (GnomeCanvasItem *item, GdkDrawable *drawable, int x, int y, int
ItemGrid *item_grid = ITEM_GRID (item);
Sheet *sheet = item_grid->sheet;
GdkGC *grid_gc = item_grid->grid_gc;
Cell *cell;
int end_x, end_y;
int paint_col, paint_row, max_paint_col, max_paint_row;
int col, row;
......@@ -304,26 +302,26 @@ item_grid_draw (GnomeCanvasItem *item, GdkDrawable *drawable, int x, int y, int
paint_col, paint_row, max_paint_col, max_paint_row);
#endif
col = paint_col;
for (x_paint = -diff_x; x_paint < end_x; col++){
ColRowInfo *ci;
ci = sheet_col_get_info (sheet, col);
row = paint_row;
for (y_paint = -diff_y; y_paint < end_y; row++){
ColRowInfo *ri;
ri = sheet_row_get_info (sheet, row);
item_grid_draw_cell (drawable, item_grid,
row = paint_row;
for (y_paint = -diff_y; y_paint < end_y; row++){
ColRowInfo *ri;
ri = sheet_row_get_info (sheet, row);
col = paint_col;
for (x_paint = -diff_x; x_paint < end_x; col++){
ColRowInfo *ci;
ci = sheet_col_get_info (sheet, col);
cell = sheet_cell_get (sheet, col, row);
item_grid_draw_cell (drawable, item_grid, cell,
x_paint, y_paint,
ci,
ri,
col, row);
y_paint += ri->pixels;
x_paint += ci->pixels;
}
x_paint += ci->pixels;
y_paint += ri->pixels;
}
#undef DEBUG_EXPOSES
......
......@@ -2690,4 +2690,3 @@ sheet_cursor_set (Sheet *sheet, int start_col, int start_row, int end_col, int e
}
}
......@@ -51,7 +51,7 @@ int_get_from_range (char *start, char *end, int_t *t)
} else {
p = g_malloc (size + 1);
strcpy (p, start);
strncpy (p, start, size);
p [size] = 0;
}
#ifdef GNUMERIC_USE_GMP
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment