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

Basically:



Basically:

	- auto-alignment on cells without style works.

	- Clean ups (use the new cell_ routines).

	- Couple of bug fixes.

	- Figured that aligment code works better if you
	  actually call the routine on the cell.

Miguel

1998-08-19  Miguel de Icaza  <miguel@nuclecu.unam.mx>

	* src/sheet.c (sheet_cursor_set): New function.  Use this instead
	of the view-specific routine (gnumeric_cursor_set).

	* src/gnumeric-sheet.c (gnumeric_sheet_can_move_cursor): ':' is a
	valid separator for activating the cursor-cell selection mode.

	* src/cell.c (cell_auto_align): New function.  This tries to
	auto-align the cell contents depending on the value type.

	* src/dialog-cell-format.c (cell_properties_apply): Create a
	single style that is attached to a region and let each property
	page fill the structure in.
	(apply_align_format): Implement.  No wonder it was not working
	last night.
	(apply_number_formats): Fill the passed Style structure only.
	Remove obsolete code.

	* src/sheet.c (sheet_cell_new): New cells are born with auto-style
	flag turned on.

	* src/clipboard.c (paste_cell): Render the cell after computation
	is finished.  Clean up the usage of the cell manipulation;  make
	auto-style work on pasted cells.

	* src/str.c (string_ref): Return the value referenced.
parent c3468eb6
1998-08-19 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/sheet.c (sheet_cursor_set): New function. Use this instead
of the view-specific routine (gnumeric_cursor_set).
* src/gnumeric-sheet.c (gnumeric_sheet_can_move_cursor): ':' is a
valid separator for activating the cursor-cell selection mode.
* src/cell.c (cell_auto_align): New function. This tries to
auto-align the cell contents depending on the value type.
* src/dialog-cell-format.c (cell_properties_apply): Create a
single style that is attached to a region and let each property
page fill the structure in.
(apply_align_format): Implement. No wonder it was not working
last night.
(apply_number_formats): Fill the passed Style structure only.
Remove obsolete code.
* src/sheet.c (sheet_cell_new): New cells are born with auto-style
flag turned on.
* src/clipboard.c (paste_cell): Render the cell after computation
is finished. Clean up the usage of the cell manipulation; make
auto-style work on pasted cells.
* src/str.c (string_ref): Return the value referenced.
* src/item-cursor.c (item_cursor_do_drop): New function: Handles
the action from the cursor drag operation.
......
1998-08-19 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/sheet.c (sheet_cursor_set): New function. Use this instead
of the view-specific routine (gnumeric_cursor_set).
* src/gnumeric-sheet.c (gnumeric_sheet_can_move_cursor): ':' is a
valid separator for activating the cursor-cell selection mode.
* src/cell.c (cell_auto_align): New function. This tries to
auto-align the cell contents depending on the value type.
* src/dialog-cell-format.c (cell_properties_apply): Create a
single style that is attached to a region and let each property
page fill the structure in.
(apply_align_format): Implement. No wonder it was not working
last night.
(apply_number_formats): Fill the passed Style structure only.
Remove obsolete code.
* src/sheet.c (sheet_cell_new): New cells are born with auto-style
flag turned on.
* src/clipboard.c (paste_cell): Render the cell after computation
is finished. Clean up the usage of the cell manipulation; make
auto-style work on pasted cells.
* src/str.c (string_ref): Return the value referenced.
* src/item-cursor.c (item_cursor_do_drop): New function: Handles
the action from the cursor drag operation.
......
1998-08-19 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/sheet.c (sheet_cursor_set): New function. Use this instead
of the view-specific routine (gnumeric_cursor_set).
* src/gnumeric-sheet.c (gnumeric_sheet_can_move_cursor): ':' is a
valid separator for activating the cursor-cell selection mode.
* src/cell.c (cell_auto_align): New function. This tries to
auto-align the cell contents depending on the value type.
* src/dialog-cell-format.c (cell_properties_apply): Create a
single style that is attached to a region and let each property
page fill the structure in.
(apply_align_format): Implement. No wonder it was not working
last night.
(apply_number_formats): Fill the passed Style structure only.
Remove obsolete code.
* src/sheet.c (sheet_cell_new): New cells are born with auto-style
flag turned on.
* src/clipboard.c (paste_cell): Render the cell after computation
is finished. Clean up the usage of the cell manipulation; make
auto-style work on pasted cells.
* src/str.c (string_ref): Return the value referenced.
* src/item-cursor.c (item_cursor_do_drop): New function: Handles
the action from the cursor drag operation.
......
1998-08-19 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/sheet.c (sheet_cursor_set): New function. Use this instead
of the view-specific routine (gnumeric_cursor_set).
* src/gnumeric-sheet.c (gnumeric_sheet_can_move_cursor): ':' is a
valid separator for activating the cursor-cell selection mode.
* src/cell.c (cell_auto_align): New function. This tries to
auto-align the cell contents depending on the value type.
* src/dialog-cell-format.c (cell_properties_apply): Create a
single style that is attached to a region and let each property
page fill the structure in.
(apply_align_format): Implement. No wonder it was not working
last night.
(apply_number_formats): Fill the passed Style structure only.
Remove obsolete code.
* src/sheet.c (sheet_cell_new): New cells are born with auto-style
flag turned on.
* src/clipboard.c (paste_cell): Render the cell after computation
is finished. Clean up the usage of the cell manipulation; make
auto-style work on pasted cells.
* src/str.c (string_ref): Return the value referenced.
* src/item-cursor.c (item_cursor_do_drop): New function: Handles
the action from the cursor drag operation.
......
......@@ -34,6 +34,77 @@ cell_set_formula (Cell *cell, char *text)
cell_formula_changed (cell);
}
/*
* cell_set_alignment:
*
* @cell: the cell to change the alignment of
* @halign: the horizontal alignemnt
* @valign: the vertical alignemnt
* @orient: the text orientation
*
* This routine changes the alignment of a cell to those specified.
*/
void
cell_set_alignment (Cell *cell, int halign, int valign, int orient)
{
g_return_if_fail (cell != NULL);
g_return_if_fail (cell->style != NULL);
cell->flags &= ~CELL_DEFAULT_STYLE;
if ((cell->style->halign == halign) &&
(cell->style->halign == valign) &&
(cell->style->orientation == orient))
return;
cell->style->halign = halign;
cell->style->valign = valign;
cell->style->orientation = orient;
cell_queue_redraw (cell);
}
/*
* cell_auto_align:
* @cell: The cell to configure the alignment to
*
* This routine sets the alignemnt of a cell depending on the data
* represented in the cell. This routine does nothing if a style
* has been explicitly set
*/
static void
cell_auto_align (Cell *cell)
{
int align;
if (!(cell->flags & CELL_DEFAULT_STYLE))
return;
if (!cell->value)
align = HALIGN_LEFT;
else
switch (cell->value->type){
case VALUE_STRING:
align = HALIGN_LEFT;
break;
case VALUE_INTEGER:
case VALUE_FLOAT:
align = HALIGN_RIGHT;
break;
default:
return;
}
cell->style->halign = align;
cell_queue_redraw (cell);
}
/*
* cell_calc_dimensions
* @cell: The cell
*
* This routine updates the dimensions of the the rendered text of a cell
*/
void
cell_calc_dimensions (Cell *cell)
{
......@@ -51,6 +122,14 @@ cell_calc_dimensions (Cell *cell)
cell->height = font->ascent + font->descent;
}
/*
* cell_set_rendered_text
* @cell: the cell we will modify
* @rendered_text: the text we will display
*
* This routine sets the rendered text field of the cell
* it recomputes the bounding box for the cell as well
*/
void
cell_set_rendered_text (Cell *cell, char *rendered_text)
{
......@@ -64,6 +143,12 @@ cell_set_rendered_text (Cell *cell, char *rendered_text)
cell_calc_dimensions (cell);
}
/*
* cell_render_value
* @cell: The cell whose value needs to be rendered
*
* The value of the cell is formated according to the format style
*/
void
cell_render_value (Cell *cell)
{
......@@ -72,6 +157,7 @@ cell_render_value (Cell *cell)
g_return_if_fail (cell != NULL);
g_return_if_fail (cell->value != NULL);
cell_auto_align (cell);
str = value_format (cell->value, cell->style->format, NULL);
cell_set_rendered_text (cell, str);
g_free (str);
......@@ -99,7 +185,7 @@ cell_set_text (Cell *cell, char *text)
cell->parsed_node = NULL;
}
if (text [0] == '='){
if (text [0] == '='){
cell_set_formula (cell, text);
} else {
Value *v = g_new (Value, 1);
......@@ -146,10 +232,6 @@ cell_set_text (Cell *cell, char *text)
cell->row->pos);
if (deps)
cell_queue_recalc_list (deps);
/* Finish setting the values for this cell */
cell->flags = 0;
}
/*
......@@ -222,20 +304,3 @@ cell_set_format (Cell *cell, char *format)
cell_queue_redraw (cell);
}
void
cell_set_alignment (Cell *cell, int halign, int valign, int orient)
{
g_return_if_fail (cell != NULL);
g_return_if_fail (cell->style != NULL);
if ((cell->style->halign == halign) &&
(cell->style->halign == valign) &&
(cell->style->orientation == orient))
return;
cell->style->halign = halign;
cell->style->valign = valign;
cell->style->orientation = orient;
cell_queue_redraw (cell);
}
......@@ -25,7 +25,15 @@ typedef struct {
} ColRowInfo;
typedef enum {
CELL_COLOR_IS_SET
CELL_COLOR_IS_SET = 1,
/* If this flag is set we are free to change the style of a cell
* automatically depending on the type of data entered (strings
* get left alignment, numbers right alignment, etc).
*
* If it is not set, then we can do this.
*/
CELL_DEFAULT_STYLE = 2,
} CellFlags;
typedef struct {
......
......@@ -68,7 +68,7 @@ static int
paste_cell (Sheet *dest_sheet, Cell *new_cell, int target_col, int target_row, int paste_flags)
{
sheet_cell_add (dest_sheet, new_cell, target_col, target_row);
if (!(paste_flags & PASTE_FORMULAS)){
if (new_cell->parsed_node){
expr_tree_unref (new_cell->parsed_node);
......@@ -97,16 +97,14 @@ paste_cell (Sheet *dest_sheet, Cell *new_cell, int target_col, int target_row, i
new_cell->parsed_node = NULL;
}
}
cell_render_value (new_cell);
if (!(paste_flags & PASTE_FORMULAS)){
char *rendered;
rendered = value_string (new_cell->value);
string_unref (new_cell->entered_text);
new_cell->entered_text = string_get (rendered);
g_free (rendered);
new_cell->entered_text = string_ref (new_cell->text);
}
sheet_redraw_cell_region (dest_sheet,
target_col, target_row,
target_col, target_row);
......
......@@ -35,15 +35,11 @@ cell_eval (Cell *cell)
value_release (cell->value);
if (v == NULL){
cell->text = string_get (error_msg);
cell_set_rendered_text (cell, error_msg);
cell->value = NULL;
} else {
/* FIXME: Use the format stuff */
char *str = value_format (v, cell->style->format, NULL);
cell->value = v;
cell->text = string_get (str);
g_free (str);
cell_render_value (cell);
}
cell_calc_dimensions (cell);
......
......@@ -366,11 +366,9 @@ create_number_format_page (GtkWidget *prop_win, CellList *cells)
}
static void
apply_number_formats (Sheet *sheet, CellList *list)
apply_number_formats (Style *style, Sheet *sheet, CellList *list)
{
char *str = gtk_entry_get_text (GTK_ENTRY (number_input));
Style *style;
GList *l;
for (;list; list = list->next){
Cell *cell = list->data;
......@@ -378,18 +376,8 @@ apply_number_formats (Sheet *sheet, CellList *list)
cell_set_format (cell, str);
}
style = style_new_empty ();
style->valid_flags = STYLE_FORMAT;
for (l = sheet->selections; l; l = l->next){
SheetSelection *ss = l->data;
sheet_style_attach (
sheet,
ss->start_col, ss->start_row,
ss->end_col, ss->end_row,
style);
}
style->valid_flags |= STYLE_FORMAT;
style->format = style_format_new (str);
}
typedef struct {
......@@ -493,7 +481,7 @@ create_align_page (GtkWidget *prop_win, CellList *cells)
}
}
/* Now after we *potentially toggled the radio button above, we
/* Now after we *potentially* toggled the radio button above, we
* connect the signals to activate the propertybox
*/
for (sl = hradio_list; sl; sl = sl->next){
......@@ -512,14 +500,28 @@ create_align_page (GtkWidget *prop_win, CellList *cells)
}
static void
apply_align_format (Sheet *sheet, CellList *cells)
apply_align_format (Style *style, Sheet *sheet, CellList *cells)
{
int i;
int halign, valign;
i = gtk_radio_group_get_selected (hradio_list);
halign = horizontal_aligns [i].flag;
i = gtk_radio_group_get_selected (vradio_list);
valign = vertical_aligns [i].flag;
for (; cells; cells = cells->next){
Cell *cell = cells->data;
cell_set_alignment (cell, halign, valign, ORIENT_HORIZ);
}
style->valid_flags |= STYLE_ALIGN;
}
static struct {
char *title;
GtkWidget *(*create_page)(GtkWidget *prop_win, CellList *cells);
void (*apply_page)(Sheet *sheet, CellList *cells);
void (*apply_page)(Style *style, Sheet *sheet, CellList *cells);
} cell_format_pages [] = {
{ N_("Number"), create_number_format_page, apply_number_formats },
{ N_("Alignment"), create_align_page, apply_align_format },
......@@ -530,6 +532,8 @@ static void
cell_properties_apply (GtkObject *w, int page, CellList *cells)
{
Sheet *sheet;
Style *style;
GList *l;
int i;
if (page != -1)
......@@ -537,8 +541,23 @@ cell_properties_apply (GtkObject *w, int page, CellList *cells)
sheet = (Sheet *) gtk_object_get_data (w, "Sheet");
/* Now, let each property page apply their style */
style = style_new_empty ();
style->valid_flags = 0;
for (i = 0; cell_format_pages [i].title; i++)
(*cell_format_pages [i].apply_page)(sheet, cells);
(*cell_format_pages [i].apply_page)(style, sheet, cells);
/* Attach this style to all of the selections */
for (l = sheet->selections; l; l = l->next){
SheetSelection *ss = l->data;
sheet_style_attach (
sheet,
ss->start_col, ss->start_row,
ss->end_col, ss->end_row,
style);
}
}
static void
......
......@@ -366,11 +366,9 @@ create_number_format_page (GtkWidget *prop_win, CellList *cells)
}
static void
apply_number_formats (Sheet *sheet, CellList *list)
apply_number_formats (Style *style, Sheet *sheet, CellList *list)
{
char *str = gtk_entry_get_text (GTK_ENTRY (number_input));
Style *style;
GList *l;
for (;list; list = list->next){
Cell *cell = list->data;
......@@ -378,18 +376,8 @@ apply_number_formats (Sheet *sheet, CellList *list)
cell_set_format (cell, str);
}
style = style_new_empty ();
style->valid_flags = STYLE_FORMAT;
for (l = sheet->selections; l; l = l->next){
SheetSelection *ss = l->data;
sheet_style_attach (
sheet,
ss->start_col, ss->start_row,
ss->end_col, ss->end_row,
style);
}
style->valid_flags |= STYLE_FORMAT;
style->format = style_format_new (str);
}
typedef struct {
......@@ -493,7 +481,7 @@ create_align_page (GtkWidget *prop_win, CellList *cells)
}
}
/* Now after we *potentially toggled the radio button above, we
/* Now after we *potentially* toggled the radio button above, we
* connect the signals to activate the propertybox
*/
for (sl = hradio_list; sl; sl = sl->next){
......@@ -512,14 +500,28 @@ create_align_page (GtkWidget *prop_win, CellList *cells)
}
static void
apply_align_format (Sheet *sheet, CellList *cells)
apply_align_format (Style *style, Sheet *sheet, CellList *cells)
{
int i;
int halign, valign;
i = gtk_radio_group_get_selected (hradio_list);
halign = horizontal_aligns [i].flag;
i = gtk_radio_group_get_selected (vradio_list);
valign = vertical_aligns [i].flag;
for (; cells; cells = cells->next){
Cell *cell = cells->data;
cell_set_alignment (cell, halign, valign, ORIENT_HORIZ);
}
style->valid_flags |= STYLE_ALIGN;
}
static struct {
char *title;
GtkWidget *(*create_page)(GtkWidget *prop_win, CellList *cells);
void (*apply_page)(Sheet *sheet, CellList *cells);
void (*apply_page)(Style *style, Sheet *sheet, CellList *cells);
} cell_format_pages [] = {
{ N_("Number"), create_number_format_page, apply_number_formats },
{ N_("Alignment"), create_align_page, apply_align_format },
......@@ -530,6 +532,8 @@ static void
cell_properties_apply (GtkObject *w, int page, CellList *cells)
{
Sheet *sheet;
Style *style;
GList *l;
int i;
if (page != -1)
......@@ -537,8 +541,23 @@ cell_properties_apply (GtkObject *w, int page, CellList *cells)
sheet = (Sheet *) gtk_object_get_data (w, "Sheet");
/* Now, let each property page apply their style */
style = style_new_empty ();
style->valid_flags = 0;
for (i = 0; cell_format_pages [i].title; i++)
(*cell_format_pages [i].apply_page)(sheet, cells);
(*cell_format_pages [i].apply_page)(style, sheet, cells);
/* Attach this style to all of the selections */
for (l = sheet->selections; l; l = l->next){
SheetSelection *ss = l->data;
sheet_style_attach (
sheet,
ss->start_col, ss->start_row,
ss->end_col, ss->end_row,
style);
}
}
static void
......
......@@ -35,15 +35,11 @@ cell_eval (Cell *cell)
value_release (cell->value);
if (v == NULL){
cell->text = string_get (error_msg);
cell_set_rendered_text (cell, error_msg);
cell->value = NULL;
} else {
/* FIXME: Use the format stuff */
char *str = value_format (v, cell->style->format, NULL);
cell->value = v;
cell->text = string_get (str);
g_free (str);
cell_render_value (cell);
}
cell_calc_dimensions (cell);
......
......@@ -71,6 +71,7 @@ gnumeric_sheet_set_current_value (GnumericSheet *gsheet)
col = gsheet->cursor_col;
row = gsheet->cursor_row;
cell = sheet_cell_get (gsheet->sheet, col, row);
if (!cell)
cell = sheet_cell_new (gsheet->sheet, gsheet->cursor_col, gsheet->cursor_row);
......@@ -300,6 +301,7 @@ gnumeric_sheet_can_move_cursor (GnumericSheet *gsheet)
switch (entry->text [cursor_pos-1]){
case '=': case '-': case '*': case '/': case '^':
case '+': case '&': case '(': case '%': case '!':
case ':':
return TRUE;
}
......
......@@ -71,6 +71,7 @@ gnumeric_sheet_set_current_value (GnumericSheet *gsheet)
col = gsheet->cursor_col;
row = gsheet->cursor_row;
cell = sheet_cell_get (gsheet->sheet, col, row);
if (!cell)
cell = sheet_cell_new (gsheet->sheet, gsheet->cursor_col, gsheet->cursor_row);
......@@ -300,6 +301,7 @@ gnumeric_sheet_can_move_cursor (GnumericSheet *gsheet)
switch (entry->text [cursor_pos-1]){
case '=': case '-': case '*': case '/': case '^':
case '+': case '&': case '(': case '%': case '!':
case ':':
return TRUE;
}
......
......@@ -179,7 +179,6 @@ item_grid_draw_cell (GdkDrawable *drawable, ItemGrid *item_grid,
if (!cell)
return;
printf ("Drawing %d %d: ", col, row);
/* The offsets where we start drawing the text */
x_offset = y_offset = 0;
......
......@@ -125,7 +125,7 @@ sheet_col_selection_changed (ItemBar *item_bar, int column, int reset, Sheet *sh
ci = sheet_col_get (sheet, column);
if (reset){
gnumeric_sheet_cursor_set (GNUMERIC_SHEET (sheet->sheet_view), column, 0);
sheet_cursor_set (sheet, column, 0);
sheet_selection_clear (sheet);
sheet_selection_append_range (sheet,
column, 0,
......@@ -151,7 +151,7 @@ sheet_row_selection_changed (ItemBar *item_bar, int row, int reset, Sheet *sheet
ri = sheet_row_get (sheet, row);