Commit 90259c03 authored by Arturo Espinosa's avatar Arturo Espinosa

Basically: got font changing working.



Basically: got font changing working.

Miguel.
parent c2f2e55f
1998-08-28 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/sheet.c (sheet_row_set_internal_height): New routine used to
change the heigh of a sheet. Now we also keep a variable to see
if the user has hardcoded the dimensions of the row.
(sheet_compute_visible_ranges): New function to compute the
visible ranges of the Sheets.
* src/item-edit.c (item_edit_init): Init all values.
(item_edit_set_arg): Set the child bounds
(item_edit_draw): Use the style font for the current cell when
drawing the cell.
* src/dialog-cell-format.c (apply_font_format, create_font_page):
New cell property configuration page: font selector.
* src/cell.c (cell_set_font, cell_set_font_from_style): New
routines to change a cell's font.
* src/item-bar.c (item_bar_start_resize): Fix routine after the
massive changes of yesterday.
1998-08-28 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/format.c (format_number): Rewrote the format parser. I
......
1998-08-28 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/sheet.c (sheet_row_set_internal_height): New routine used to
change the heigh of a sheet. Now we also keep a variable to see
if the user has hardcoded the dimensions of the row.
(sheet_compute_visible_ranges): New function to compute the
visible ranges of the Sheets.
* src/item-edit.c (item_edit_init): Init all values.
(item_edit_set_arg): Set the child bounds
(item_edit_draw): Use the style font for the current cell when
drawing the cell.
* src/dialog-cell-format.c (apply_font_format, create_font_page):
New cell property configuration page: font selector.
* src/cell.c (cell_set_font, cell_set_font_from_style): New
routines to change a cell's font.
* src/item-bar.c (item_bar_start_resize): Fix routine after the
massive changes of yesterday.
1998-08-28 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/format.c (format_number): Rewrote the format parser. I
......
1998-08-28 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/sheet.c (sheet_row_set_internal_height): New routine used to
change the heigh of a sheet. Now we also keep a variable to see
if the user has hardcoded the dimensions of the row.
(sheet_compute_visible_ranges): New function to compute the
visible ranges of the Sheets.
* src/item-edit.c (item_edit_init): Init all values.
(item_edit_set_arg): Set the child bounds
(item_edit_draw): Use the style font for the current cell when
drawing the cell.
* src/dialog-cell-format.c (apply_font_format, create_font_page):
New cell property configuration page: font selector.
* src/cell.c (cell_set_font, cell_set_font_from_style): New
routines to change a cell's font.
* src/item-bar.c (item_bar_start_resize): Fix routine after the
massive changes of yesterday.
1998-08-28 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/format.c (format_number): Rewrote the format parser. I
......
1998-08-28 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/sheet.c (sheet_row_set_internal_height): New routine used to
change the heigh of a sheet. Now we also keep a variable to see
if the user has hardcoded the dimensions of the row.
(sheet_compute_visible_ranges): New function to compute the
visible ranges of the Sheets.
* src/item-edit.c (item_edit_init): Init all values.
(item_edit_set_arg): Set the child bounds
(item_edit_draw): Use the style font for the current cell when
drawing the cell.
* src/dialog-cell-format.c (apply_font_format, create_font_page):
New cell property configuration page: font selector.
* src/cell.c (cell_set_font, cell_set_font_from_style): New
routines to change a cell's font.
* src/item-bar.c (item_bar_start_resize): Fix routine after the
massive changes of yesterday.
1998-08-28 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/format.c (format_number): Rewrote the format parser. I
......
......@@ -62,6 +62,44 @@ cell_set_alignment (Cell *cell, int halign, int valign, int orient)
cell_queue_redraw (cell);
}
void
cell_set_font_from_style (Cell *cell, StyleFont *style_font)
{
GdkFont *font;
int height;
g_return_if_fail (cell != NULL);
g_return_if_fail (style_font != NULL);
style_font_unref (cell->style->font);
style_font_ref (style_font);
cell->style->font = style_font;
font = style_font->font;
height = font->ascent + font->descent;
if (!cell->row->hard_size)
sheet_row_set_internal_height (cell->sheet, cell->row, height);
cell_queue_redraw (cell);
}
void
cell_set_font (Cell *cell, char *font_name)
{
StyleFont *style_font;
g_return_if_fail (cell != NULL);
g_return_if_fail (font_name != NULL);
style_font = style_font_new (font_name, 1);
if (style_font)
cell_set_font_from_style (cell, style_font);
}
/*
* cell_calc_dimensions
* @cell: The cell
......
......@@ -14,7 +14,7 @@ typedef struct {
int pixels; /* we compute this from the above parameters */
unsigned int selected:1; /* is this selected? */
unsigned int hard_size:1; /* has the user explicitly set the dimensions? */
void *data;
} ColRowInfo;
......@@ -62,6 +62,8 @@ char *value_format (Value *value, StyleFormat *format, char *
void cell_set_text (Cell *cell, char *text);
void cell_set_formula (Cell *cell, char *text);
void cell_set_format (Cell *cell, char *format);
void cell_set_font (Cell *cell, char *font_name);
void cell_set_font_from_style (Cell *cell, StyleFont *style_font);
void cell_set_alignment (Cell *cell, int halign, int valign, int orientation);
void cell_set_rendered_text (Cell *cell, char *rendered_text);
void cell_formula_relocate (Cell *cell, int target_col, int target_row);
......
......@@ -22,6 +22,8 @@ static GtkWidget *number_input;
static GtkWidget *number_cat_list;
static GtkWidget *number_format_list;
static GtkWidget *font_widget;
/* There point to the radio groups in the format/alignment page */
static GSList *hradio_list;
static GSList *vradio_list;
......@@ -295,12 +297,14 @@ create_number_format_page (GtkWidget *prop_win, CellList *cells)
format = cells_get_format (cells);
/* 1. Categories */
gtk_table_attach_defaults (t, l = gtk_label_new (_("Categories")), 0, 1, BOXES_LINE, BOXES_LINE+1);
gtk_table_attach (t, l = gtk_label_new (_("Categories")),
0, 1, BOXES_LINE, BOXES_LINE+1,
GTK_FILL | GTK_EXPAND, 0, 0, 0);
gtk_misc_set_alignment (GTK_MISC (l), 0.0, 0.5);
number_cat_list = my_clist_new ();
gtk_table_attach (t, number_cat_list, 0, 1, BOXES_LINE+1, BOXES_LINE+2,
GTK_FILL | GTK_EXPAND, 0, 4, 0);
GTK_FILL | GTK_EXPAND, GTK_FILL | GTK_EXPAND, 4, 0);
/* 1.1 Connect our signal handler */
gtk_signal_connect (GTK_OBJECT (number_cat_list), "select_row",
......@@ -338,7 +342,9 @@ create_number_format_page (GtkWidget *prop_win, CellList *cells)
/* 3. Format codes */
number_format_list = my_clist_new ();
gtk_table_attach_defaults (t, l = gtk_label_new (_("Format codes")), 1, 2, BOXES_LINE, BOXES_LINE+1);
gtk_table_attach (t, l = gtk_label_new (_("Format codes")),
1, 2, BOXES_LINE, BOXES_LINE+1,
GTK_FILL | GTK_EXPAND, 0, 0, 0);
gtk_misc_set_alignment (GTK_MISC (l), 0.0, 0.5);
gtk_table_attach_defaults (t, number_format_list, 1, 2, BOXES_LINE + 1, BOXES_LINE + 2);
format_list_fill (0);
......@@ -518,6 +524,65 @@ apply_align_format (Style *style, Sheet *sheet, CellList *cells)
style->valid_flags |= STYLE_ALIGN;
}
static void
font_changed (GtkWidget *widget, GtkStyle *previous_style, GnomePropertyBox *prop_win)
{
gnome_property_box_changed (prop_win);
}
static GtkWidget *
create_font_page (GtkWidget *prop_win, CellList *cells)
{
font_widget = gtk_font_selection_new ();
gtk_widget_show (font_widget);
gtk_signal_connect (GTK_OBJECT (GTK_FONT_SELECTION (font_widget)->preview_entry),
"style_set",
GTK_SIGNAL_FUNC (font_changed), prop_win);
return font_widget;
}
static void
apply_font_format (Style *style, Sheet *sheet, CellList *cells)
{
GtkFontSelection *font_sel = GTK_FONT_SELECTION (font_widget);
GdkFont *gdk_font;
GList *l;
char *font_name;
int height;
font_name = gtk_font_selection_get_font_name (font_sel);
if (!font_name)
return;
gdk_font = gtk_font_selection_get_font (font_sel);
height = gdk_font->ascent + gdk_font->descent;
/* Apply the new font to all of the cell rows */
for (; cells; cells = cells->next){
Cell *cell = cells->data;
cell_set_font (cell, font_name);
}
/* Now apply it to every row in the selection */
for (l = sheet->selections; l; l = l->next){
SheetSelection *ss = l->data;
int i;
for (i = ss->start_row; i <= ss->end_row; i++){
ColRowInfo *ri;
ri = sheet_row_get (sheet, i);
sheet_row_set_internal_height (sheet, ri, height);
}
}
style->valid_flags |= STYLE_FONT;
style->font = style_font_new (font_name, 10);
}
static struct {
char *title;
GtkWidget *(*create_page)(GtkWidget *prop_win, CellList *cells);
......@@ -525,6 +590,7 @@ static struct {
} cell_format_pages [] = {
{ N_("Number"), create_number_format_page, apply_number_formats },
{ N_("Alignment"), create_align_page, apply_align_format },
{ N_("Font"), create_font_page, apply_font_format },
{ NULL, NULL }
};
......
......@@ -22,6 +22,8 @@ static GtkWidget *number_input;
static GtkWidget *number_cat_list;
static GtkWidget *number_format_list;
static GtkWidget *font_widget;
/* There point to the radio groups in the format/alignment page */
static GSList *hradio_list;
static GSList *vradio_list;
......@@ -295,12 +297,14 @@ create_number_format_page (GtkWidget *prop_win, CellList *cells)
format = cells_get_format (cells);
/* 1. Categories */
gtk_table_attach_defaults (t, l = gtk_label_new (_("Categories")), 0, 1, BOXES_LINE, BOXES_LINE+1);
gtk_table_attach (t, l = gtk_label_new (_("Categories")),
0, 1, BOXES_LINE, BOXES_LINE+1,
GTK_FILL | GTK_EXPAND, 0, 0, 0);
gtk_misc_set_alignment (GTK_MISC (l), 0.0, 0.5);
number_cat_list = my_clist_new ();
gtk_table_attach (t, number_cat_list, 0, 1, BOXES_LINE+1, BOXES_LINE+2,
GTK_FILL | GTK_EXPAND, 0, 4, 0);
GTK_FILL | GTK_EXPAND, GTK_FILL | GTK_EXPAND, 4, 0);
/* 1.1 Connect our signal handler */
gtk_signal_connect (GTK_OBJECT (number_cat_list), "select_row",
......@@ -338,7 +342,9 @@ create_number_format_page (GtkWidget *prop_win, CellList *cells)
/* 3. Format codes */
number_format_list = my_clist_new ();
gtk_table_attach_defaults (t, l = gtk_label_new (_("Format codes")), 1, 2, BOXES_LINE, BOXES_LINE+1);
gtk_table_attach (t, l = gtk_label_new (_("Format codes")),
1, 2, BOXES_LINE, BOXES_LINE+1,
GTK_FILL | GTK_EXPAND, 0, 0, 0);
gtk_misc_set_alignment (GTK_MISC (l), 0.0, 0.5);
gtk_table_attach_defaults (t, number_format_list, 1, 2, BOXES_LINE + 1, BOXES_LINE + 2);
format_list_fill (0);
......@@ -518,6 +524,65 @@ apply_align_format (Style *style, Sheet *sheet, CellList *cells)
style->valid_flags |= STYLE_ALIGN;
}
static void
font_changed (GtkWidget *widget, GtkStyle *previous_style, GnomePropertyBox *prop_win)
{
gnome_property_box_changed (prop_win);
}
static GtkWidget *
create_font_page (GtkWidget *prop_win, CellList *cells)
{
font_widget = gtk_font_selection_new ();
gtk_widget_show (font_widget);
gtk_signal_connect (GTK_OBJECT (GTK_FONT_SELECTION (font_widget)->preview_entry),
"style_set",
GTK_SIGNAL_FUNC (font_changed), prop_win);
return font_widget;
}
static void
apply_font_format (Style *style, Sheet *sheet, CellList *cells)
{
GtkFontSelection *font_sel = GTK_FONT_SELECTION (font_widget);
GdkFont *gdk_font;
GList *l;
char *font_name;
int height;
font_name = gtk_font_selection_get_font_name (font_sel);
if (!font_name)
return;
gdk_font = gtk_font_selection_get_font (font_sel);
height = gdk_font->ascent + gdk_font->descent;
/* Apply the new font to all of the cell rows */
for (; cells; cells = cells->next){
Cell *cell = cells->data;
cell_set_font (cell, font_name);
}
/* Now apply it to every row in the selection */
for (l = sheet->selections; l; l = l->next){
SheetSelection *ss = l->data;
int i;
for (i = ss->start_row; i <= ss->end_row; i++){
ColRowInfo *ri;
ri = sheet_row_get (sheet, i);
sheet_row_set_internal_height (sheet, ri, height);
}
}
style->valid_flags |= STYLE_FONT;
style->font = style_font_new (font_name, 10);
}
static struct {
char *title;
GtkWidget *(*create_page)(GtkWidget *prop_win, CellList *cells);
......@@ -525,6 +590,7 @@ static struct {
} cell_format_pages [] = {
{ N_("Number"), create_number_format_page, apply_number_formats },
{ N_("Alignment"), create_align_page, apply_align_format },
{ N_("Font"), create_font_page, apply_font_format },
{ NULL, NULL }
};
......
......@@ -285,7 +285,7 @@ item_bar_start_resize (ItemBar *item_bar, int pos, int pixels)
double x1, x2, y1, y2;
int division_pos;
gsheet = GNUMERIC_SHEET (canvas);
gsheet = GNUMERIC_SHEET (item_bar->sheet_view->sheet_view);
sheet = item_bar->sheet_view->sheet;
if (item_bar->orientation == GTK_ORIENTATION_VERTICAL){
......
......@@ -47,7 +47,7 @@ item_edit_draw (GnomeCanvasItem *item, GdkDrawable *drawable,
char *text;
int cursor_pos, text_len, first_part_len, total_len;
font = canvas->style->font;
font = item_edit->style->font->font;
text = gtk_entry_get_text (GTK_ENTRY (item_edit->editor));
text_len = strlen (text);
cursor_pos = GTK_EDITABLE (item_edit->editor)->current_pos;
......@@ -119,15 +119,20 @@ item_edit_event (GnomeCanvasItem *item, GdkEvent *event)
static void
item_edit_reconfigure (GnomeCanvasItem *item)
{
ItemEdit *item_edit = ITEM_EDIT (item);
int x, y, w, h;
item_edit_get_pixel_coords (ITEM_EDIT (item), &x, &y, &w, &h);
item_edit_get_pixel_coords (item_edit, &x, &y, &w, &h);
item->x1 = x;
item->y1 = y;
item->x2 = x + w;
item->y2 = y + h;
gnome_canvas_group_child_bounds (GNOME_CANVAS_GROUP (item->parent), item);
if (item_edit->style)
style_destroy (item_edit->style);
item_edit->style = sheet_style_compute (item_edit->sheet, item_edit->col, item_edit->row);
}
/*
......@@ -144,7 +149,11 @@ item_edit_init (ItemEdit *item_edit)
item->y2 = 1;
item_edit->col_span = 1;
/* Set invalid values so that we know when we have been fully initialized */
item_edit->sheet = 0;
item_edit->col = -1;
item_edit->row = -1;
}
static void
......@@ -171,6 +180,7 @@ item_edit_destroy (GtkObject *o)
int x, y, w, h;
/* Repaint the area where we had edited */
style_destroy (item_edit->style);
item_edit_get_pixel_coords (item_edit, &x, &y, &w, &h);
gnome_canvas_request_redraw (GNOME_CANVAS_ITEM (item_edit)->canvas, x, y, x+w, y+h);
......@@ -233,6 +243,10 @@ item_edit_set_arg (GtkObject *o, GtkArg *arg, guint arg_id)
item_edit->row = GTK_VALUE_INT (*arg);
break;
}
/* Once all of our parameters have been set, do the reconfiguration */
if (item_edit->sheet && item_edit->col != -1 && item_edit->row != -1)
item_edit_reconfigure (item);
}
/*
......
......@@ -19,6 +19,8 @@ typedef struct {
/* Where are we */
int col, row, col_span;
int pixel_span;
Style *style;
} ItemEdit;
GtkType item_edit_get_type (void);
......
......@@ -237,7 +237,7 @@ sheet_view_row_size_changed (ItemBar *item_bar, int row, int height, SheetView *
{
Sheet *sheet = sheet_view->sheet;
sheet_row_set_height (sheet, row, height);
sheet_row_set_height (sheet, row, height, TRUE);
gnumeric_sheet_compute_visible_ranges (GNUMERIC_SHEET (sheet_view->sheet_view));
}
......
......@@ -237,7 +237,7 @@ sheet_view_row_size_changed (ItemBar *item_bar, int row, int height, SheetView *
{
Sheet *sheet = sheet_view->sheet;
sheet_row_set_height (sheet, row, height);
sheet_row_set_height (sheet, row, height, TRUE);
gnumeric_sheet_compute_visible_ranges (GNUMERIC_SHEET (sheet_view->sheet_view));
}
......
......@@ -198,6 +198,9 @@ sheet_set_zoom_factor (Sheet *sheet, double factor)
}
}
/*
* Duplicates a column or row
*/
ColRowInfo *
sheet_duplicate_colrow (ColRowInfo *original)
{
......@@ -303,8 +306,20 @@ sheet_row_get_info (Sheet *sheet, int row)
return &sheet->default_row_style;
}
void
sheet_compute_visible_ranges (Sheet *sheet)
{
GList *l;
for (l = sheet->sheet_views; l; l = l->next){
GnumericSheet *gsheet = GNUMERIC_SHEET_VIEW (l->data);
gnumeric_sheet_compute_visible_ranges (gsheet);
}
}
static void
colrow_set_units (Sheet *sheet,ColRowInfo *info)
colrow_set_units (Sheet *sheet, ColRowInfo *info)
{
double pix = sheet->last_zoom_factor_used;
......@@ -312,8 +327,19 @@ colrow_set_units (Sheet *sheet,ColRowInfo *info)
(info->margin_a + info->margin_b + 1)) / pix;
}
/*
* sheet_row_set_height
* @sheet: The sheet
* @row: The row
* @height: The desired height
* @height_set_by_user: TRUE if this was done by a user (ie, user manually
* set the width)
*
* Sets the height of a row in terms of the total visible space (as opossite
* to the internal required space, which does not include the margins).
*/
void
sheet_row_set_height (Sheet *sheet, int row, int height)
sheet_row_set_height (Sheet *sheet, int row, int height, gboolean height_set_by_user)
{
ColRowInfo *ri;
int add = 0;
......@@ -321,14 +347,49 @@ sheet_row_set_height (Sheet *sheet, int row, int height)
ri = sheet_row_get_info (sheet, row);
if (ri == &sheet->default_row_style){
ri = sheet_duplicate_colrow (ri);
ri->pos = row;
add = 1;
}
ri->pos = row;
if (height_set_by_user)
ri->hard_size = 1;
ri->pixels = height;
colrow_set_units (sheet, ri);
if (add)
sheet_row_add (sheet, ri);
sheet_compute_visible_ranges (sheet);
sheet_redraw_all (sheet);
}
/*
* sheet_row_set_internal_height
* @sheet: The sheet
* @row: The row
* @height: The desired height
*
* Sets the height of a row in terms of the internal required space (the total
* size of the row will include the margins.
*/
void
sheet_row_set_internal_height (Sheet *sheet, ColRowInfo *ri, int height)
{
double pix;
g_return_if_fail (sheet != NULL);
g_return_if_fail (IS_SHEET (sheet));
g_return_if_fail (ri != NULL);
g_return_if_fail (ri != &sheet->default_row_style);
pix = sheet->last_zoom_factor_used;
if (ri->units == height)
return;
ri->units = height;
ri->pixels = (ri->units * pix) + (ri->margin_a + ri->margin_b - 1);
sheet_compute_visible_ranges (sheet);
sheet_redraw_all (sheet);
}
......@@ -350,6 +411,7 @@ sheet_col_set_width (Sheet *sheet, int col, int width)
if (add)
sheet_col_add (sheet, ci);
sheet_compute_visible_ranges (sheet);
sheet_redraw_all (sheet);
}
......
......@@ -140,20 +140,20 @@ void sheet_selection_append_range (Sheet *sheet,
CellList *sheet_selection_to_list (Sheet *sheet);
/* Operations on the selection */
void sheet_selection_clear_content (Sheet *sheet);
void sheet_selection_clear_formats (Sheet *sheet);
void sheet_selection_clear (Sheet *sheet);
void sheet_selection_clear_content (Sheet *sheet);
void sheet_selection_clear_formats (Sheet *sheet);
void sheet_selection_clear (Sheet *sheet);
/* Cut/Copy/Paste on the workbook selection */
gboolean sheet_selection_copy (Sheet *sheet);
gboolean sheet_selection_cut (Sheet *sheet);
void sheet_selection_paste (Sheet *sheet,
int dest_col, int dest_row,
int paste_flags);
int sheet_selection_walk_step (Sheet *sheet,
int forward, int horizontal,
int current_col, int current_row,
int *new_col, int *new_row);
gboolean sheet_selection_copy (Sheet *sheet);
gboolean sheet_selection_cut (Sheet *sheet);
void sheet_selection_paste (Sheet *sheet,
int dest_col, int dest_row,
int paste_flags);
int sheet_selection_walk_step (Sheet *sheet,
int forward, int horizontal,
int current_col, int current_row,
int *new_col, int *new_row);
void sheet_selection_extend_horizontal (Sheet *sheet, int count);
void sheet_selection_extend_vertical (Sheet *sheet, int count);
int sheet_selection_is_cell_selected (Sheet *sheet, int col, int row);
......@@ -161,92 +161,95 @@ int sheet_selection_is_cell_selected (Sheet *sheet, int col, int row);
gboolean sheet_verify_selection_simple (Sheet *sheet, char *command_name);
/* Cell management */
Cell *sheet_cell_new (Sheet *sheet, int col, int row);
void sheet_cell_add (Sheet *sheet, Cell *cell,
int col, int row);
void sheet_cell_remove (Sheet *sheet, Cell *cell);
int sheet_cell_foreach_range (Sheet *sheet, int only_existing,
int start_col, int start_row,
int end_col, int end_row,
sheet_cell_foreach_callback callback,
void *closure);
Cell *sheet_cell_get (Sheet *sheet, int col, int row);
void sheet_cell_formula_link (Cell *cell);
void sheet_cell_formula_unlink (Cell *cell);
Cell *sheet_cell_new (Sheet *sheet, int col, int row);