Commit c81d44ec authored by Arturo Espinosa's avatar Arturo Espinosa

Weee! I realized that columns were not rows and rows were not columns.



Weee!  I realized that columns were not rows and rows were not
columns.  Cell storage manager works now.

Now I also keep a hash table with the cell contents just for the
lookup portion of the code.

Also the code for displaying various alignements is there give
or take a couple of off-by-ones clipping rectangles (the code
right now has hardcoded styles so different columns have different
alignment styles, just in case someone tested this).

Miguel.
parent ffd38f45
......@@ -58,7 +58,7 @@ item_edit_draw (GnomeCanvasItem *item, GdkDrawable *drawable,
if (total_len >= wd)
item_edit->col_span++;
} while (total_len >= wd);
dx = xd - x;
dy = yd - y;
......@@ -68,7 +68,7 @@ item_edit_draw (GnomeCanvasItem *item, GdkDrawable *drawable,
first_part_len = gdk_text_width (font, text, cursor_pos);
gdk_draw_text (drawable, font, canvas->style->black_gc,
dx + 1, dy + hd - font->descent, text, cursor_pos);
dx, dy + hd - font->descent, text, cursor_pos);
gdk_draw_line (drawable, canvas->style->black_gc,
first_part_len + dx + 1,
dy + hd - font->descent,
......
......@@ -154,16 +154,19 @@ item_grid_draw_cell (GdkDrawable *drawable, ItemGrid *item_grid,
int x1, int y1, int width, int height, int col, int row)
{
GnumericSheet *gsheet = GNUMERIC_SHEET (item_grid->sheet->sheet_view);
GnomeCanvas *canvas = GNOME_CANVAS_ITEM (item_grid)->canvas;
Sheet *sheet = item_grid->sheet;
GdkGC *gc = item_grid->gc;
GnomeCanvas *canvas = GNOME_CANVAS_ITEM (item_grid)->canvas;
GdkFont *font;
Cell *cell;
GdkGC *gc = item_grid->gc;
GdkGC *white_gc = GTK_WIDGET (canvas)->style->white_gc;
Sheet *sheet = item_grid->sheet;
Cell *cell, *clip_left, *clip_right;
Style *style;
int x_offset, y_offset;
Cell *clip_left, *clip_right;
int x_offset, y_offset, text_base, pixels;
GdkRectangle rect;
#if 0
item_debug_cross (drawable, gc, x1, y1, x1+width, y1+height);
#endif
/* If cell is selected, draw selection */
if (sheet_selection_is_cell_selected (sheet, col, row)){
......@@ -188,23 +191,41 @@ item_grid_draw_cell (GdkDrawable *drawable, ItemGrid *item_grid,
style = cell->style;
font = style->font->font;
/* Code to test the different alignements, hardcoded for now */
switch (col){
case 0:
style->halign = HALIGN_GENERAL;
break;
case 1:
style->halign = HALIGN_LEFT;
break;
case 2:
style->halign = HALIGN_RIGHT;
break;
case 3:
style->halign = HALIGN_CENTER;
break;
case 4:
style->halign = HALIGN_FILL;
break;
}
switch (style->halign){
case HALIGN_GENERAL:
if (col < SHEET_MAX_COLS-1)
clip_right = sheet_cell_get (sheet, col+1, row);
x_offset = 0;
x_offset = cell->col->margin_a;
break;
case HALIGN_LEFT:
if (col < SHEET_MAX_COLS-1)
clip_right = sheet_cell_get (sheet, col+1, row);
x_offset = 0;
x_offset = cell->col->margin_a;
break;
case HALIGN_RIGHT:
if (col > 0)
clip_left = sheet_cell_get (sheet, col-1, row);
x_offset = cell->col->pixels - cell->width;
x_offset = cell->col->pixels - (cell->width - cell->col->margin_b);
break;
case HALIGN_CENTER:
......@@ -218,7 +239,8 @@ item_grid_draw_cell (GdkDrawable *drawable, ItemGrid *item_grid,
case HALIGN_FILL:
if (col < SHEET_MAX_COLS-1)
clip_right = sheet_cell_get (sheet, col-1, row);
x_offset = 0;
clip_left = clip_right = (Cell *) TRUE;
x_offset = cell->col->margin_a;
break;
case HALIGN_JUSTIFY:
......@@ -230,16 +252,34 @@ item_grid_draw_cell (GdkDrawable *drawable, ItemGrid *item_grid,
gdk_gc_set_foreground (gc, &cell->color);
} else
gdk_gc_set_foreground (gc, &item_grid->default_color);
text_base = y1 + cell->row->pixels - cell->row->margin_b - font->descent + 1;
gdk_gc_set_foreground (gc, &item_grid->default_color);
printf ("(%d,%d), text: %s\n", col, row, cell->text);
gdk_draw_text (drawable, font, gc, x1, y1, "TEXTO", 5);
/*
x1 + x_offset,
y1 + y_offset,
cell->text, strlen (cell->text));
*/
if (clip_left || clip_right){
rect.x = x1;
rect.y = y1;
rect.width = width;
rect.height = height;
gdk_gc_set_clip_rectangle (gc, &rect);
} else
gdk_gc_set_clip_rectangle (gc, NULL);
gdk_draw_rectangle (drawable, white_gc, TRUE,
x1 + cell->col->margin_a,
y1 + cell->row->margin_a,
cell->width - (cell->col->margin_a + cell->col->margin_b),
height - (cell->row->margin_a + cell->row->margin_b));
pixels = 0;
do {
gdk_draw_text (drawable, font, gc,
x1 + x_offset,
text_base + y_offset,
cell->text, strlen (cell->text));
pixels += cell->width;
} while (style->halign == HALIGN_FILL && pixels < cell->col->pixels);
}
static void
......
......@@ -26,8 +26,8 @@ sheet_init_default_styles (Sheet *sheet)
sheet->default_col_style.style = style_new ();
sheet->default_col_style.units = 40;
sheet->default_col_style.pixels = 0;
sheet->default_col_style.margin_a = 0;
sheet->default_col_style.margin_b = 0;
sheet->default_col_style.margin_a = 1;
sheet->default_col_style.margin_b = 1;
sheet->default_col_style.selected = 0;
sheet->default_col_style.data = NULL;
......@@ -36,8 +36,8 @@ sheet_init_default_styles (Sheet *sheet)
sheet->default_row_style.style = style_new ();
sheet->default_row_style.units = 20;
sheet->default_row_style.pixels = 0;
sheet->default_row_style.margin_a = 0;
sheet->default_row_style.margin_b = 0;
sheet->default_row_style.margin_a = 1;
sheet->default_row_style.margin_b = 1;
sheet->default_row_style.selected = 0;
sheet->default_row_style.data = NULL;
}
......@@ -124,6 +124,30 @@ sheet_row_size_changed (ItemBar *item_bar, int row, int height, Sheet *sheet)
gnumeric_sheet_compute_visible_ranges (GNUMERIC_SHEET (sheet->sheet_view));
}
static guint
cell_hash (gconstpointer key)
{
CellRef *ca = (CellRef *) key;
return (ca->row << 8) | ca->col;
}
static gint
cell_compare (gconstpointer a, gconstpointer b)
{
CellRef *ca, *cb;
ca = (CellRef *) a;
cb = (CellRef *) b;
if (ca->row != cb->row)
return 0;
if (ca->col != cb->col)
return 0;
return 1;
}
Sheet *
sheet_new (Workbook *wb, char *name)
{
......@@ -140,6 +164,8 @@ sheet_new (Workbook *wb, char *name)
sheet->max_col_used = cols_shown;
sheet->max_row_used = rows_shown;
sheet->cell_hash = g_hash_table_new (cell_hash, cell_compare);
sheet_init_default_styles (sheet);
/* Dummy initialization */
......@@ -200,6 +226,12 @@ sheet_new (Workbook *wb, char *name)
return sheet;
}
static void
cell_hash_free_key (gpointer key, gpointer value, gpointer user_data)
{
g_free (key);
}
void
sheet_destroy (Sheet *sheet)
{
......@@ -210,7 +242,8 @@ sheet_destroy (Sheet *sheet)
style_destroy (sheet->default_row_style.style);
style_destroy (sheet->default_col_style.style);
g_hash_table_foreach (sheet->cell_hash, cell_hash_free_key, NULL);
gtk_widget_destroy (sheet->toplevel);
g_free (sheet);
......@@ -755,6 +788,7 @@ sheet_col_get (Sheet *sheet, int pos)
return col;
}
col = sheet_col_new (sheet);
col->pos = pos;
sheet_col_add (sheet, col);
return col;
......@@ -777,8 +811,9 @@ sheet_row_get (Sheet *sheet, int pos)
if (row->pos == pos)
return row;
}
row = sheet_col_new (sheet);
sheet_col_add (sheet, row);
row = sheet_row_new (sheet);
row->pos = pos;
sheet_row_add (sheet, row);
return row;
}
......@@ -807,27 +842,16 @@ gen_col_blanks (Sheet *sheet, int start_col, int end_col,
Cell *
sheet_cell_get (Sheet *sheet, int col, int row)
{
GList *cols;
GList *rows;
Cell *cell;
CellRef cellref;
g_return_val_if_fail (sheet != NULL, NULL);
for (cols = sheet->cols_info; cols; cols = cols->next){
ColRowInfo *ci = cols->data;
if (ci->pos == col){
rows = (GList *) ci->data;
for (; rows; rows = rows->next){
Cell *cell = (Cell *) rows->data;
if (cell->row->pos == row)
return cell;
}
return NULL;
}
}
return NULL;
cellref.col = col;
cellref.row = row;
cell = g_hash_table_lookup (sheet->cell_hash, &cellref);
return cell;
}
/*
......@@ -920,21 +944,27 @@ CRowSort (gconstpointer a, gconstpointer b)
Cell *ca = (Cell *) a;
Cell *cb = (Cell *) b;
return ca->row->pos - cb->row->pos;
return cb->row->pos - ca->row->pos;
}
Cell *
sheet_cell_new (Sheet *sheet, int col, int row)
{
Cell *cell;
CellRef *cellref;
g_return_val_if_fail (sheet != NULL, NULL);
printf ("Creating cell at %d,%d\n", col, row);
cell = g_new0 (Cell, 1);
cell->col = sheet_col_get (sheet, col);
cell->row = sheet_row_get (sheet, col);
cell->row = sheet_row_get (sheet, row);
cell->style = sheet_style_compute (sheet, col, row);
cellref = g_new0 (CellRef, 1);
cellref->col = col;
cellref->row = row;
g_hash_table_insert (sheet->cell_hash, cellref, cell);
cell->col->data = g_list_insert_sorted (cell->col->data, cell, CRowSort);
return cell;
......
......@@ -45,7 +45,7 @@ typedef struct {
ColRowInfo default_row_style;
GList *rows_info;
void *contents;
GHashTable *cell_hash; /* The cells in hashed format */
GList *selections;
......
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