Commit 491136d7 authored by Miguel de Icaza's avatar Miguel de Icaza Committed by Arturo Espinosa

Dropped the ColInfo and RowInfo structures, they are now unified into a

1998-07-09  Miguel de Icaza  <miguel@nuclecu.unam.mx>

	* src/*: Dropped the ColInfo and RowInfo structures, they are now
	unified into a single ColRowInfo structure, they were really the
	same thing.  Thanks to Federico for the suggestion.
parent 2d356b1d
1998-07-09 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/*: Dropped the ColInfo and RowInfo structures, they are now
unified into a single ColRowInfo structure, they were really the
same thing. Thanks to Federico for the suggestion.
* src/item-grid.c:
New paint strategy for the grid (uses what apparently Excel does);
It now correctly uses the coordinate system from the canvas (ie,
......
1998-07-09 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/*: Dropped the ColInfo and RowInfo structures, they are now
unified into a single ColRowInfo structure, they were really the
same thing. Thanks to Federico for the suggestion.
* src/item-grid.c:
New paint strategy for the grid (uses what apparently Excel does);
It now correctly uses the coordinate system from the canvas (ie,
......
1998-07-09 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/*: Dropped the ColInfo and RowInfo structures, they are now
unified into a single ColRowInfo structure, they were really the
same thing. Thanks to Federico for the suggestion.
* src/item-grid.c:
New paint strategy for the grid (uses what apparently Excel does);
It now correctly uses the coordinate system from the canvas (ie,
......
1998-07-09 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/*: Dropped the ColInfo and RowInfo structures, they are now
unified into a single ColRowInfo structure, they were really the
same thing. Thanks to Federico for the suggestion.
* src/item-grid.c:
New paint strategy for the grid (uses what apparently Excel does);
It now correctly uses the coordinate system from the canvas (ie,
......
......@@ -29,30 +29,19 @@ typedef struct {
} CellColor;
typedef struct {
RowType row;
int pos; /* the column or row number */
Style *style; /* if existant, this row style */
/* The height */
int unit_height; /* In units */
int top_margin; /* in pixels: top margin */
int bottom_margin; /* in pixels: bottom margin */
int height; /* we compute this from the above parameters */
} RowInfo;
int units; /* In units */
int margin_a; /* in pixels: top/left margin */
int margin_b; /* in pixels: bottom/right margin */
int pixels; /* we compute this from the above parameters */
} ColRowInfo;
typedef struct {
ColType col;
Style *style; /* if existant, this column style */
/* The width */
int unit_width; /* in units */
int left_margin; /* in pixels: left margin */
int right_margin; /* in pixels: right margin */
int width; /* w2pix (unit_width) + margins */
} ColInfo;
typedef struct {
ColInfo *col;
RowInfo *row;
ColRowInfo *col;
ColRowInfo *row;
/* Text as entered by the user */
char *entered_text;
......@@ -71,3 +60,4 @@ typedef struct {
#define CELL_IS_FORMULA(cell) (cell->entered_text [0] == '=')
#endif /* GNUMERIC_CELL_H */
......@@ -126,8 +126,8 @@ item_bar_draw (GnomeCanvasItem *item, GdkDrawable *drawable, int x, int y, int w
{
ItemBar *item_bar = ITEM_BAR (item);
Sheet *sheet = item_bar->sheet;
ColInfo *ci;
RowInfo *ri;
ColRowInfo *ci;
ColRowInfo *ri;
int element, total, pixels, limit;
char *str;
......@@ -142,7 +142,7 @@ item_bar_draw (GnomeCanvasItem *item, GdkDrawable *drawable, int x, int y, int w
do {
if (item_bar->orientation == GTK_ORIENTATION_VERTICAL){
ri = sheet_get_row_info (sheet, element);
pixels = ri->height;
pixels = ri->pixels;
if (total+pixels >= y){
str = get_row_name (element);
bar_draw_cell (item_bar, drawable, str,
......@@ -152,7 +152,7 @@ item_bar_draw (GnomeCanvasItem *item, GdkDrawable *drawable, int x, int y, int w
}
} else {
ci = sheet_get_col_info (sheet, element);
pixels = ci->width;
pixels = ci->pixels;
if (total+pixels >= x){
str = get_col_name (element);
bar_draw_cell (item_bar, drawable, str,
......@@ -184,22 +184,18 @@ item_bar_translate (GnomeCanvasItem *item, double dx, double dy)
static int
is_pointer_on_division (ItemBar *item_bar, int pos)
{
ColInfo *ci;
RowInfo *ri;
ColRowInfo *cri;
int i, total, pixels;
total = 0;
for (i = item_bar->first_element; total < pos; i++){
if (item_bar->orientation == GTK_ORIENTATION_VERTICAL){
ri = sheet_get_row_info (item_bar->sheet, i);
pixels = ri->height;
} else {
ci = sheet_get_col_info (item_bar->sheet, i);
pixels = ci->width;
}
total += pixels;
if (item_bar->orientation == GTK_ORIENTATION_VERTICAL)
cri = sheet_get_row_info (item_bar->sheet, i);
else
cri = sheet_get_col_info (item_bar->sheet, i);
total += cri->pixels;
if ((total - 4 < pos) && (pos < total + 4))
return 1;
}
......
......@@ -121,15 +121,15 @@ find_col (ItemGrid *item_grid, int x, int *col_origin)
int pixel = item_grid->left_offset;
do {
ColInfo *ci = sheet_get_col_info (item_grid->sheet, col);
ColRowInfo *ci = sheet_get_col_info (item_grid->sheet, col);
if (x >= pixel && x <= pixel + ci->width){
if (x >= pixel && x <= pixel + ci->pixels){
if (col_origin)
*col_origin = pixel;
return col;
}
col++;
pixel += ci->width;
pixel += ci->pixels;
} while (1);
}
......@@ -143,15 +143,15 @@ find_row (ItemGrid *item_grid, int y, int *row_origin)
int pixel = item_grid->top_offset;
do {
RowInfo *ri = sheet_get_row_info (item_grid->sheet, row);
ColRowInfo *ri = sheet_get_row_info (item_grid->sheet, row);
if (y >= pixel && y <= pixel + ri->height){
if (y >= pixel && y <= pixel + ri->pixels){
if (row_origin)
*row_origin = pixel;
return row;
}
row++;
pixel += ri->height;
pixel += ri->pixels;
} while (1);
}
......@@ -196,49 +196,49 @@ item_grid_draw (GnomeCanvasItem *item, GdkDrawable *drawable, int x, int y, int
/* 2. the grids */
for (x_paint = -diff_x; x_paint < end_x; col++){
ColInfo *ci;
ColRowInfo *ci;
ci = sheet_get_col_info (sheet, col);
g_assert (ci->width != 0);
g_assert (ci->pixels != 0);
gdk_draw_line (drawable, grid_gc, x_paint, 0, x_paint, height);
x_paint += ci->width;
x_paint += ci->pixels;
}
row = paint_row;
for (y_paint = -diff_y; y_paint < end_y; row++){
RowInfo *ri;
ColRowInfo *ri;
ri = sheet_get_row_info (sheet, row);
gdk_draw_line (drawable, grid_gc, 0, y_paint, width, y_paint);
y_paint += ri->height;
y_paint += ri->pixels;
}
for (x_paint = -diff_x; x_paint < end_x; col++){
ColInfo *ci;
ColRowInfo *ci;
ci = sheet_get_col_info (sheet, col);
row = paint_row;
for (y_paint = -diff_y; y_paint < end_y; row++){
RowInfo *ri;
ColRowInfo *ri;
ri = sheet_get_row_info (sheet, row);
#if 0
item_debug_cross (drawable, item_grid->grid_gc,
x_paint, y_paint,
x_paint + ci->width,
y_paint + ri->height);
x_paint + ci->pixels,
y_paint + ri->pixels);
item_grid_draw_cell (drawable, item_grid,
x_paint, y_paint,
x_paint + ci->width,
y_paint + ri->height);
x_paint + ci->pixels,
y_paint + ri->pixels);
#endif
y_paint += ri->height;
y_paint += ri->pixels;
}
x_paint += ci->width;
x_paint += ci->pixels;
}
#undef DEBUG_EXPOSES
......
......@@ -6,42 +6,41 @@ static void
sheet_init_dummy_stuff (Sheet *sheet)
{
int x, y;
ColInfo c, *cp;
RowInfo *rp;
ColRowInfo c, *cp, *rp;
c.col = 0;
c.style = NULL;
c.unit_width = 40;
c.width = 0;
c.left_margin = 0;
c.right_margin = 0;
c.pos = 0;
c.style = NULL;
c.units = 40;
c.pixels = 0;
c.margin_a = 0;
c.margin_b = 0;
sheet->default_col_style = c;
/* Initialize some of the columns */
for (x = 0; x < 40; x += 2){
cp = g_new0 (ColInfo, 1);
cp = g_new0 (ColRowInfo, 1);
*cp = c;
cp->col = x;
cp->unit_width = (x+1) * 30;
cp->pos = x;
cp->units = (x+1) * 30;
sheet->cols_info = g_list_append (sheet->cols_info, cp);
}
/* Rows, we keep them consistent for now */
sheet->default_row_style.row = 0;
sheet->default_row_style.style = NULL;
sheet->default_row_style.unit_height = 20;
sheet->default_row_style.height = 0;
sheet->default_row_style.top_margin = 0;
sheet->default_row_style.bottom_margin = 0;
sheet->default_row_style.pos = 0;
sheet->default_row_style.style = NULL;
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;
for (y = 0; y < 6; y += 2){
rp = g_new0 (RowInfo, 1);
rp = g_new0 (ColRowInfo, 1);
*rp = sheet->default_row_style;
rp->row = y;
rp->unit_height = (20 * (y + 1));
rp->pos = y;
rp->units = (20 * (y + 1));
sheet->rows_info = g_list_append (sheet->rows_info, rp);
}
}
......@@ -117,7 +116,7 @@ sheet_new (Workbook *wb, char *name)
}
void
sheet_foreach_col (Sheet *sheet, sheet_col_callback callback, void *user_data)
sheet_foreach_col (Sheet *sheet, sheet_col_row_callback callback, void *user_data)
{
GList *l = sheet->cols_info;
......@@ -132,7 +131,7 @@ sheet_foreach_col (Sheet *sheet, sheet_col_callback callback, void *user_data)
}
void
sheet_foreach_row (Sheet *sheet, sheet_row_callback callback, void *user_data)
sheet_foreach_row (Sheet *sheet, sheet_col_row_callback callback, void *user_data)
{
GList *l = sheet->rows_info;
......@@ -147,21 +146,12 @@ sheet_foreach_row (Sheet *sheet, sheet_row_callback callback, void *user_data)
}
static void
sheet_compute_col_size (Sheet *sheet, ColInfo *ci, void *data)
sheet_compute_col_row_new_size (Sheet *sheet, ColRowInfo *ci, void *data)
{
double pix_per_unit = sheet->last_zoom_factor_used;
ci->width = (ci->unit_width * pix_per_unit) +
ci->left_margin + ci->right_margin + 1;
}
static void
sheet_compute_row_size (Sheet *sheet, RowInfo *ri, void *data)
{
double pix_per_unit = sheet->last_zoom_factor_used;
ri->height = (ri->unit_height * pix_per_unit) +
ri->top_margin + ri->bottom_margin + 1;
ci->pixels = (ci->units * pix_per_unit) +
ci->margin_a + ci->margin_b + 1;
}
/*
......@@ -177,8 +167,8 @@ sheet_reconfigure_zoom (Sheet *sheet)
return;
sheet->last_zoom_factor_used = pixels_per_unit;
sheet_foreach_col (sheet, sheet_compute_col_size, NULL);
sheet_foreach_row (sheet, sheet_compute_row_size, NULL);
sheet_foreach_col (sheet, sheet_compute_col_row_new_size, NULL);
sheet_foreach_row (sheet, sheet_compute_col_row_new_size, NULL);
}
void
......@@ -193,30 +183,30 @@ sheet_set_zoom_factor (Sheet *sheet, double factor)
gnome_canvas_scroll_to (GNOME_CANVAS (sheet->row_canvas), 0, 0);
}
ColInfo *
ColRowInfo *
sheet_get_col_info (Sheet *sheet, int col)
{
GList *l = sheet->cols_info;
for (; l; l = l->next){
ColInfo *ci = l->data;
ColRowInfo *ci = l->data;
if (ci->col == col)
if (ci->pos == col)
return ci;
}
return &sheet->default_col_style;
}
RowInfo *
ColRowInfo *
sheet_get_row_info (Sheet *sheet, int row)
{
GList *l = sheet->rows_info;
for (; l; l = l->next){
RowInfo *ri = l->data;
ColRowInfo *ri = l->data;
if (ri->row == row)
if (ri->pos == row)
return ri;
}
......@@ -229,17 +219,17 @@ sheet_get_row_info (Sheet *sheet, int row)
int
sheet_col_get_distance (Sheet *sheet, int from_col, int to_col)
{
ColInfo *ci;
ColRowInfo *ci;
int pixels = 0, i;
g_assert (from_col <= to_col);
/* This can be optimized, yes, but the implementation
* of the RowInfo, ColInfo sets is going to change anyways
* of the ColRowInfo sets is going to change anyways
*/
for (i = from_col; i < to_col; i++){
ci = sheet_get_col_info (sheet, i);
pixels += ci->width;
pixels += ci->pixels;
}
return pixels;
}
......@@ -250,7 +240,7 @@ sheet_col_get_distance (Sheet *sheet, int from_col, int to_col)
int
sheet_row_get_distance (Sheet *sheet, int from_row, int to_row)
{
RowInfo *ri;
ColRowInfo *ri;
int pixels = 0, i;
g_assert (from_row <= to_row);
......@@ -260,7 +250,7 @@ sheet_row_get_distance (Sheet *sheet, int from_row, int to_row)
*/
for (i = from_row; i < to_row; i++){
ri = sheet_get_row_info (sheet, i);
pixels += ri->height;
pixels += ri->pixels;
}
return pixels;
}
......
......@@ -24,30 +24,29 @@ typedef struct {
Style style;
ColInfo default_col_style;
ColRowInfo default_col_style;
GList *cols_info;
RowInfo default_row_style;
ColRowInfo default_row_style;
GList *rows_info;
void *contents;
} Sheet;
typedef void (*sheet_col_callback)(Sheet *sheet, ColInfo *ci, void *user_data);
typedef void (*sheet_row_callback)(Sheet *sheet, RowInfo *ci, void *user_data);
Sheet *sheet_new (Workbook *wb, char *name);
ColInfo *sheet_get_col_info (Sheet *, int col);
RowInfo *sheet_get_row_info (Sheet *, int row);
int sheet_col_get_distance (Sheet *sheet, int from_col, int to_col);
int sheet_row_get_distance (Sheet *sheet, int from_row, int to_row);
void sheet_foreach_col (Sheet *sheet, sheet_col_callback, void *user_data);
void sheet_foreach_row (Sheet *sheet, sheet_row_callback, void *user_data);
void sheet_set_zoom_factor (Sheet *sheet, double factor);
void sheet_get_cell_bounds (Sheet *sheet, ColType col, RowType row, int *x, int *y, int *w, int *h);
Workbook *workbook_new (void);
Workbook *workbook_new_with_sheets (int sheet_count);
void workbook_attach_sheet (Workbook *, Sheet *);
typedef void (*sheet_col_row_callback)(Sheet *sheet, ColRowInfo *ci, void *user_data);
Sheet *sheet_new (Workbook *wb, char *name);
ColRowInfo *sheet_get_col_info (Sheet *, int col);
ColRowInfo *sheet_get_row_info (Sheet *, int row);
int sheet_col_get_distance (Sheet *sheet, int from_col, int to_col);
int sheet_row_get_distance (Sheet *sheet, int from_row, int to_row);
void sheet_foreach_col (Sheet *sheet, sheet_col_row_callback, void *user_data);
void sheet_foreach_row (Sheet *sheet, sheet_col_row_callback, void *user_data);
void sheet_set_zoom_factor (Sheet *sheet, double factor);
void sheet_get_cell_bounds (Sheet *sheet, ColType col, RowType row, int *x, int *y, int *w, int *h);
Workbook *workbook_new (void);
Workbook *workbook_new_with_sheets (int sheet_count);
void workbook_attach_sheet (Workbook *, Sheet *);
/*
* Callback routine: invoked when the first view ItemGrid
......
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