sheet.c 15 KB
Newer Older
Arturo Espinosa's avatar
Arturo Espinosa committed
1 2 3 4 5 6 7 8
/*
 * Sheet.c:  Implements the sheet management and per-sheet storage
 * (C) 1998 The Free Software Foundation
 *
 * Author:
 *  Miguel de Icaza (miguel@gnu.org)
 *
 */
Arturo Espinosa's avatar
Arturo Espinosa committed
9 10 11 12
#include <gnome.h>
#include "gnumeric.h"
#include "gnumeric-sheet.h"

Arturo Espinosa's avatar
Arturo Espinosa committed
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
static void
sheet_redraw_all (Sheet *sheet)
{
	gnome_canvas_request_redraw (
		GNOME_CANVAS (sheet->sheet_view),
		0, 0, INT_MAX, INT_MAX);
}

static void
sheet_init_default_styles (Sheet *sheet)
{
	/* The default column style */
	sheet->default_col_style.pos        = -1;
	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.selected   = 0;
Arturo Espinosa's avatar
Arturo Espinosa committed
32
	sheet->default_col_style.data       = NULL;
Arturo Espinosa's avatar
Arturo Espinosa committed
33 34 35 36 37 38 39 40 41

	/* The default row style */
	sheet->default_row_style.pos      = -1;
	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.selected = 0;
Arturo Espinosa's avatar
Arturo Espinosa committed
42
	sheet->default_row_style.data     = NULL;
Arturo Espinosa's avatar
Arturo Espinosa committed
43 44 45
}

/* Initialize some of the columns and rows, to test the display engine */
46 47 48
static void
sheet_init_dummy_stuff (Sheet *sheet)
{
Arturo Espinosa's avatar
Arturo Espinosa committed
49
	ColRowInfo *cp, *rp;
50 51 52
	int x, y;

	for (x = 0; x < 40; x += 2){
Arturo Espinosa's avatar
Arturo Espinosa committed
53
		cp = sheet_row_new (sheet);
54 55
		cp->pos = x;
		cp->units = (x+1) * 30;
Arturo Espinosa's avatar
Arturo Espinosa committed
56
		sheet_col_add (sheet, cp);
57 58 59
	}

	for (y = 0; y < 6; y += 2){
Arturo Espinosa's avatar
Arturo Espinosa committed
60
		rp = sheet_row_new (sheet);
61 62
		rp->pos = y;
		rp->units = (20 * (y + 1));
63
		rp->selected = 0;
Arturo Espinosa's avatar
Arturo Espinosa committed
64
		sheet_row_add (sheet, rp);
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
	}
}

static GtkWidget *
new_canvas_bar (Sheet *sheet, GtkOrientation o, GnomeCanvasItem **itemp)
{
	GnomeCanvasGroup *group;
	GnomeCanvasItem *item;
	GtkWidget *canvas;
	int w, h;
	
	canvas = gnome_canvas_new (
		gtk_widget_get_default_visual (),
		gtk_widget_get_default_colormap ());

	if (o == GTK_ORIENTATION_VERTICAL){
		w = 60;
		h = 1;
	} else {
		w = 1;
		h = 20;
	}
	gnome_canvas_set_size (GNOME_CANVAS (canvas), w, h);
	group = GNOME_CANVAS_GROUP (GNOME_CANVAS (canvas)->root);
	item = gnome_canvas_item_new (GNOME_CANVAS (canvas), group,
				      item_bar_get_type (),
				      "ItemBar::Sheet", sheet,
				      "ItemBar::Orientation", o,
				      "ItemBar::First", 0,
				      NULL);
Arturo Espinosa's avatar
Arturo Espinosa committed
95

96 97 98 99 100
	*itemp = GNOME_CANVAS_ITEM (item);
	gtk_widget_show (canvas);
	return canvas;
}

Arturo Espinosa's avatar
Arturo Espinosa committed
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
static void
sheet_col_selection_changed (ItemBar *item_bar, int column, Sheet *sheet)
{
	printf ("Sheet signal: Column %d selection changed\n", column);
}

static void
sheet_col_size_changed (ItemBar *item_bar, int col, int width, Sheet *sheet)
{
	sheet_col_set_width (sheet, col, width);
}

static void
sheet_row_selection_changed (ItemBar *item_bar, int row, Sheet *sheet)
{
	printf ("Sheet signal: Row %d selection changed\n", row);
}

static void
sheet_row_size_changed (ItemBar *item_bar, int row, int height, Sheet *sheet)
{
	sheet_row_set_height (sheet, row, height);
}

Arturo Espinosa's avatar
Arturo Espinosa committed
125 126 127 128
Sheet *
sheet_new (Workbook *wb, char *name)
{
	Sheet *sheet;
129
	int rows_shown, cols_shown;
Arturo Espinosa's avatar
Arturo Espinosa committed
130

131 132
	rows_shown = cols_shown = 40;
	
Arturo Espinosa's avatar
Arturo Espinosa committed
133 134 135
	sheet = g_new0 (Sheet, 1);
	sheet->parent_workbook = wb;
	sheet->name = g_strdup (name);
136 137
	sheet->last_zoom_factor_used = -1.0;
	sheet->toplevel = gtk_table_new (0, 0, 0);
138 139 140
	sheet->max_col_used = cols_shown;
	sheet->max_row_used = rows_shown;
	
Arturo Espinosa's avatar
Arturo Espinosa committed
141 142
	sheet_init_default_styles (sheet);
	
143 144 145
	/* Dummy initialization */
	sheet_init_dummy_stuff (sheet);
	
Arturo Espinosa's avatar
Arturo Espinosa committed
146 147
	sheet->sheet_view = gnumeric_sheet_new (sheet);
	gtk_widget_show (sheet->sheet_view);
148 149 150 151 152 153 154 155 156 157 158
	gtk_widget_show (sheet->toplevel);
	
	gtk_table_attach (GTK_TABLE (sheet->toplevel), sheet->sheet_view,
			  1, 2, 1, 2,
			  GTK_FILL | GTK_EXPAND, GTK_FILL | GTK_EXPAND, 0, 0);

	/* Column canvas */
	sheet->col_canvas = new_canvas_bar (sheet, GTK_ORIENTATION_HORIZONTAL, &sheet->col_item);
	gtk_table_attach (GTK_TABLE (sheet->toplevel), sheet->col_canvas,
			  1, 2, 0, 1,
			  GTK_FILL | GTK_EXPAND, 0, 0, 0);
Arturo Espinosa's avatar
Arturo Espinosa committed
159 160 161 162 163 164
	gtk_signal_connect (GTK_OBJECT (sheet->col_item), "selection_changed",
			    GTK_SIGNAL_FUNC (sheet_col_selection_changed),
			    sheet);
	gtk_signal_connect (GTK_OBJECT (sheet->col_item), "size_changed",
			    GTK_SIGNAL_FUNC (sheet_col_size_changed),
			    sheet);
165 166 167 168 169
	/* Row canvas */
	sheet->row_canvas = new_canvas_bar (sheet, GTK_ORIENTATION_VERTICAL, &sheet->row_item);
	gtk_table_attach (GTK_TABLE (sheet->toplevel), sheet->row_canvas,
			  0, 1, 1, 2,
			  0, GTK_FILL | GTK_EXPAND, 0, 0);
Arturo Espinosa's avatar
Arturo Espinosa committed
170 171 172 173 174 175
	gtk_signal_connect (GTK_OBJECT (sheet->row_item), "selection_changed",
			    GTK_SIGNAL_FUNC (sheet_row_selection_changed),
			    sheet);
	gtk_signal_connect (GTK_OBJECT (sheet->row_item), "size_changed",
			    GTK_SIGNAL_FUNC (sheet_row_size_changed),
			    sheet);
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192

	/* Scroll bars and their adjustments */
	sheet->va = gtk_adjustment_new (0.0, 0.0, sheet->max_row_used, 1.0, rows_shown, 1.0);
	sheet->ha = gtk_adjustment_new (0.0, 0.0, sheet->max_col_used, 1.0, cols_shown, 1.0);
	
	sheet->hs = gtk_hscrollbar_new (GTK_ADJUSTMENT (sheet->ha));
	sheet->vs = gtk_vscrollbar_new (GTK_ADJUSTMENT (sheet->va));

	/* Attach the horizontal scroll */
	gtk_table_attach (GTK_TABLE (sheet->toplevel), sheet->hs,
			  1, 2, 2, 3,
			  GTK_FILL | GTK_EXPAND, 0, 0, 0);

	/* Attach the vertical scroll */
	gtk_table_attach (GTK_TABLE (sheet->toplevel), sheet->vs,
			  2, 3, 1, 2,
			  0, GTK_FILL | GTK_EXPAND, 0, 0);
Arturo Espinosa's avatar
Arturo Espinosa committed
193
	
194
	sheet_set_zoom_factor (sheet, 1.0);
Arturo Espinosa's avatar
Arturo Espinosa committed
195 196 197
	return sheet;
}

198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213
void
sheet_destroy (Sheet *sheet)
{
	g_assert (sheet != NULL);
	
	sheet_selection_clear (sheet);
	g_free (sheet->name);
	
	style_destroy (sheet->default_row_style.style);
	style_destroy (sheet->default_col_style.style);
	
	gtk_widget_destroy (sheet->toplevel);
	
	g_free (sheet);
}

214
void
215
sheet_foreach_col (Sheet *sheet, sheet_col_row_callback callback, void *user_data)
216 217 218 219 220 221 222 223 224 225 226 227 228 229
{
	GList *l = sheet->cols_info;

	/* Invoke the callback for the default style */
	(*callback)(sheet, &sheet->default_col_style, user_data);

	/* And then for the rest */
	while (l){
		(*callback)(sheet, l->data, user_data);
		l = l->next;
	}
}

void
230
sheet_foreach_row (Sheet *sheet, sheet_col_row_callback callback, void *user_data)
231 232 233 234 235 236 237 238 239 240 241 242 243 244
{
	GList *l = sheet->rows_info;

	/* Invoke the callback for the default style */
	(callback)(sheet, &sheet->default_row_style, user_data);

	/* And then for the rest */
	while (l){
		(*callback)(sheet, l->data, user_data);
		l = l->next;
	}
}

static void
245
sheet_compute_col_row_new_size (Sheet *sheet, ColRowInfo *ci, void *data)
246 247 248
{
	double pix_per_unit = sheet->last_zoom_factor_used;

249 250
	ci->pixels = (ci->units * pix_per_unit) +
		ci->margin_a + ci->margin_b + 1;
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265
}

/*
 * Updates the values used for display after a zoom change
 */
static void
sheet_reconfigure_zoom (Sheet *sheet)
{
	GnomeCanvas *gnumeric_canvas = GNOME_CANVAS (sheet->sheet_view);
	double pixels_per_unit = gnumeric_canvas->pixels_per_unit;
	
	if (pixels_per_unit == sheet->last_zoom_factor_used)
		return;

	sheet->last_zoom_factor_used = pixels_per_unit;
266 267
	sheet_foreach_col (sheet, sheet_compute_col_row_new_size, NULL);
	sheet_foreach_row (sheet, sheet_compute_col_row_new_size, NULL);
268 269 270 271 272 273 274 275 276 277 278 279 280 281
}

void
sheet_set_zoom_factor (Sheet *sheet, double factor)
{
	gnome_canvas_set_pixels_per_unit (GNOME_CANVAS (sheet->sheet_view), factor);
	gnome_canvas_set_pixels_per_unit (GNOME_CANVAS (sheet->col_canvas), factor);
	gnome_canvas_set_pixels_per_unit (GNOME_CANVAS (sheet->row_canvas), factor);
	sheet_reconfigure_zoom (sheet);
	gnome_canvas_scroll_to (GNOME_CANVAS (sheet->sheet_view), 0, 0);
	gnome_canvas_scroll_to (GNOME_CANVAS (sheet->col_canvas), 0, 0);
	gnome_canvas_scroll_to (GNOME_CANVAS (sheet->row_canvas), 0, 0);
}

282
ColRowInfo *
Arturo Espinosa's avatar
Arturo Espinosa committed
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306
sheet_duplicate_colrow (ColRowInfo *original)
{
	ColRowInfo *info = g_new (ColRowInfo, 1);

	*info = *original;
	
	info->style = style_duplicate (original->style);
	
	return info;
}

ColRowInfo *
sheet_row_new (Sheet *sheet)
{
	return sheet_duplicate_colrow (&sheet->default_row_style);
}

ColRowInfo *
sheet_col_new (Sheet *sheet)
{
	return sheet_duplicate_colrow (&sheet->default_col_style);
}


Arturo Espinosa's avatar
Arturo Espinosa committed
307 308 309 310 311 312 313 314 315
static gint
CRsort (gconstpointer a, gconstpointer b)
{
	ColRowInfo *ia = (ColRowInfo *) a;
	ColRowInfo *ib = (ColRowInfo *) b;

	return (ia->pos - ib->pos);
}

Arturo Espinosa's avatar
Arturo Espinosa committed
316 317 318
void
sheet_col_add (Sheet *sheet, ColRowInfo *cp)
{
Arturo Espinosa's avatar
Arturo Espinosa committed
319
	sheet->cols_info = g_list_insert_sorted (sheet->cols_info, cp, CRsort);
Arturo Espinosa's avatar
Arturo Espinosa committed
320 321 322 323 324
}

void
sheet_row_add (Sheet *sheet, ColRowInfo *rp)
{
Arturo Espinosa's avatar
Arturo Espinosa committed
325
	sheet->rows_info = g_list_insert_sorted (sheet->rows_info, rp, CRsort);
Arturo Espinosa's avatar
Arturo Espinosa committed
326 327 328 329
}

ColRowInfo *
sheet_col_get_info (Sheet *sheet, int col)
330
{
331
	GList *l = sheet->cols_info;
332

333
	for (; l; l = l->next){
334
		ColRowInfo *ci = l->data;
335

336
		if (ci->pos == col)
337 338 339 340
			return ci;
	}

	return &sheet->default_col_style;
341 342
}

343
ColRowInfo *
Arturo Espinosa's avatar
Arturo Espinosa committed
344
sheet_row_get_info (Sheet *sheet, int row)
345
{
346
	GList *l = sheet->rows_info;
347

348
	for (; l; l = l->next){
349
		ColRowInfo *ri = l->data;
350

351
		if (ri->pos == row)
352 353
			return ri;
	}
354

355
	return &sheet->default_row_style;
356 357
}

Arturo Espinosa's avatar
Arturo Espinosa committed
358 359 360 361 362 363
static void
colrow_set_units (Sheet *sheet,ColRowInfo *info)
{
	double pix = sheet->last_zoom_factor_used;
	
	info->units  = (info->pixels -
364
			(info->margin_a + info->margin_b + 1)) / pix;
Arturo Espinosa's avatar
Arturo Espinosa committed
365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382
}

void
sheet_row_set_height (Sheet *sheet, int row, int height)
{
	ColRowInfo *ri;
	int add = 0;
	
	ri = sheet_row_get_info (sheet, row);
	if (ri == &sheet->default_row_style){
		ri = sheet_duplicate_colrow (ri);
		add = 1;
	}

	ri->pos = row;
	ri->pixels = height;
	colrow_set_units (sheet, ri);
	if (add)
383
		sheet_row_add (sheet, ri);
Arturo Espinosa's avatar
Arturo Espinosa committed
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407
	sheet_redraw_all (sheet);
}

void
sheet_col_set_width (Sheet *sheet, int col, int width)
{
	ColRowInfo *ci;
	int add = 0;
	
	ci = sheet_col_get_info (sheet, col);
	if (ci == &sheet->default_col_style){
		ci = sheet_duplicate_colrow (ci);
		add = 1;
	}

	ci->pixels = width;
	ci->pos = col;
	colrow_set_units (sheet, ci);
	if (add)
		sheet_col_add (sheet, ci);

	sheet_redraw_all (sheet);
}

408 409 410 411 412 413
/*
 * Return the number of pixels between from_col to to_col
 */
int
sheet_col_get_distance (Sheet *sheet, int from_col, int to_col)
{
414
	ColRowInfo *ci;
415 416 417
	int pixels = 0, i;

	g_assert (from_col <= to_col);
418 419

	/* This can be optimized, yes, but the implementation
420
	 * of the ColRowInfo sets is going to change anyways
421
	 */
422
	for (i = from_col; i < to_col; i++){
Arturo Espinosa's avatar
Arturo Espinosa committed
423
		ci = sheet_col_get_info (sheet, i);
424
		pixels += ci->pixels;
425 426 427 428 429 430 431 432 433 434
	}
	return pixels;
}

/*
 * Return the number of pixels between from_row to to_row
 */
int
sheet_row_get_distance (Sheet *sheet, int from_row, int to_row)
{
435
	ColRowInfo *ri;
436 437 438 439
	int pixels = 0, i;

	g_assert (from_row <= to_row);
	
440 441 442
	/* This can be optimized, yes, but the implementation
	 * of the RowInfo, ColInfo sets is going to change anyways
	 */
443
	for (i = from_row; i < to_row; i++){
Arturo Espinosa's avatar
Arturo Espinosa committed
444
		ri = sheet_row_get_info (sheet, i);
445
		pixels += ri->pixels;
446 447 448
	}
	return pixels;
}
449 450 451 452 453 454 455 456 457 458 459 460

void
sheet_get_cell_bounds (Sheet *sheet, ColType col, RowType row, int *x, int *y, int *w, int *h)
{
	GnumericSheet *gsheet = GNUMERIC_SHEET (sheet->sheet_view);
	
	*x = sheet_col_get_distance (sheet, gsheet->top_col, col);
	*y = sheet_row_get_distance (sheet, gsheet->top_row, row);

	*w = sheet_col_get_distance (sheet, col, col + 1);
	*h = sheet_row_get_distance (sheet, row, row + 1);
}
461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478

void
sheet_selection_append (Sheet *sheet, int col, int row)
{
	SheetSelection *ss;

	ss = g_new0 (SheetSelection, 1);

	ss->base_col  = col;
	ss->base_row  = row;

	ss->start_col = col;
	ss->end_col   = col;
	ss->start_row = row;
	ss->end_row   = row;
	
	sheet->selections = g_list_prepend (sheet->selections, ss);

Arturo Espinosa's avatar
Arturo Espinosa committed
479 480 481
	gnumeric_sheet_accept_pending_output (GNUMERIC_SHEET (sheet->sheet_view));
	gnumeric_sheet_load_cell_val (GNUMERIC_SHEET (sheet->sheet_view));
	
482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546
	gnumeric_sheet_set_selection (GNUMERIC_SHEET (sheet->sheet_view),
				      col, row, col, row);
	sheet_redraw_all (sheet);
}

void
sheet_selection_extend_to (Sheet *sheet, int col, int row)
{
	SheetSelection *ss;
	
	g_assert (sheet->selections);
	ss = (SheetSelection *) sheet->selections->data;

	if (col < ss->base_col){
		ss->start_col = col;
		ss->end_col   = ss->base_col;
	} else {
		ss->start_col = ss->base_col;
		ss->end_col   = col;
	}

	if (row < ss->base_row){
		ss->end_row   = ss->base_row;
		ss->start_row = row;
	} else {
		ss->end_row   = row;
		ss->start_row = ss->base_row;
	}

	gnumeric_sheet_set_selection (GNUMERIC_SHEET (sheet->sheet_view),
				      ss->start_col, ss->start_row,
				      ss->end_col, ss->end_row);
				      
	sheet_redraw_all (sheet);
}

void
sheet_selection_clear (Sheet *sheet)
{
	GList *list = sheet->selections;

	for (list = sheet->selections; list; list = list->next){
		SheetSelection *ss = list->data;

		g_free (ss);
	}
	g_list_free (sheet->selections);
	sheet->selections = NULL;
	sheet_redraw_all (sheet);
}

int
sheet_selection_is_cell_selected (Sheet *sheet, int col, int row)
{
	GList *list = sheet->selections;

	for (list = sheet->selections; list; list = list->next){
		SheetSelection *ss = list->data;

		if ((ss->start_col <= col) && (col <= ss->end_col) &&
		    (ss->start_row <= row) && (row <= ss->end_row))
			return 1;
	}
	return 0;
}
Arturo Espinosa's avatar
Arturo Espinosa committed
547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663

/*
 * Returns an allocated column:  either an existing one, or a fresh copy
 */
ColRowInfo *
sheet_col_get (Sheet *sheet, int pos)
{
	GList *clist = sheet->cols_info;
	ColRowInfo *col;
	
	for (; clist; clist = clist->next){
		col = (ColRowInfo *) clist->data;

		if (col->pos == pos)
			return col;
	}
	col = sheet_col_new (sheet);
	sheet_col_add (sheet, col);
	
	return col;
}

/*
 * Returns an allocated column:  either an existing one, or a fresh copy
 */
ColRowInfo *
sheet_row_get (Sheet *sheet, int pos)
{
	GList *rlist = sheet->rows_info;
	ColRowInfo *row;
	
	for (; rlist; rlist = rlist->next){
		row = (ColRowInfo *) rlist->data;

		if (row->pos == pos)
			return row;
	}
	row = sheet_col_new (sheet);
	sheet_col_add (sheet, row);
	
	return row;
}

/*
 * For each existing cell in the range specified, invoke the
 * callback routine
 */
void
sheet_cell_foreach_range (Sheet *sheet,
			  int start_col, int start_row,
			  int end_col, int end_row,
			  sheet_cell_foreach_callback callback,
			  void *closure)
{
	GList *col = sheet->cols_info;
	GList *row;

	for (; col; col = col->next){
		ColRowInfo *ci = col->data;

		if (ci->pos < start_col)
			continue;
		if (ci->pos > end_col)
			break;

		for (row = (GList *) ci->data; row; row = row->data){
			ColRowInfo *ri = row->data;

			if (ri->pos < start_row)
				continue;

			if (ri->pos > end_row)
				break;

			(*callback)(sheet, (Cell *) ri->data);
		}
	}
}

Style *
sheet_style_compute (Sheet *sheet, int col, int row)
{
	/* FIXME: This should compute the style based on the
	 * story of the styles applied to the worksheet, the
	 * sheet, the column and the row and return that.
	 *
	 * for now, we just return the col style
	 */
	return style_duplicate (sheet_col_get_info (sheet, col)->style);
}

Cell *
sheet_cell_new (Sheet *sheet, int col, int row)
{
	Cell *cell = g_new0 (Cell, 1);

	cell->col = sheet_col_get (sheet, col);
	cell->row = sheet_row_get (sheet, row);

	cell->style = sheet_style_compute (sheet, col, row);
	return cell;
}

Cell *
sheet_cell_new_with_text (Sheet *sheet, int col, int row, char *text)
{
	Cell *cell;
	GdkFont *font;
	
	cell = sheet_cell_new (sheet, col, row);
	cell->text = g_strdup (text);
	font = cell->style->font->font;
	cell->width = gdk_text_width (font, text, strlen (text));
	cell->height = font->ascent + font->descent;
	
	return cell;
}