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

At font creation time store a couple of the font attributes for quick

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

	* src/style.c (font_compute_hints): At font creation time store a
	couple of the font attributes for quick retrieval.

	* src/sheet-view.c (sheet_view_construct): Do not allow this
	button to have the focus either.

	* src/item-bar.c (item_bar_draw): If the whole sheet is selected,
	draw all of the columns in pressed presenstation

	* src/sheet.c (sheet_is_all_selected): Return wheter all the sheet
	is selected.

	* src/utils.c (cell_name): Fixed cell name computation.
parent 4971d45c
1998-09-23 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/style.c (font_compute_hints): At font creation time store a
couple of the font attributes for quick retrieval.
* src/sheet-view.c (sheet_view_construct): Do not allow this
button to have the focus either.
* src/item-bar.c (item_bar_draw): If the whole sheet is selected,
draw all of the columns in pressed presenstation
* src/sheet.c (sheet_is_all_selected): Return wheter all the sheet
is selected.
* src/utils.c (cell_name): Fixed cell name computation.
(parse_cell_name): Fixed parsing of the cell name.
* src/item-grid.c (item_grid_event): More range checks.
* src/item-bar.c (item_bar_event): range checks here too.
* src/sheet-autofill.c (FillItem): Keep track of the originating
cell so that we can copy the format.
* src/cell.c (cell_set_style): New function.
* src/sheet.c (sheet_selection_reset_only): Simple fix: For the
row case, redraw the rows, not the columns. Cut/paste typo.
* src/dialog-goto-cell.c (dialog_goto_cell): Do not complain if
there was no target cell entered.
......
1998-09-23 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/style.c (font_compute_hints): At font creation time store a
couple of the font attributes for quick retrieval.
* src/sheet-view.c (sheet_view_construct): Do not allow this
button to have the focus either.
* src/item-bar.c (item_bar_draw): If the whole sheet is selected,
draw all of the columns in pressed presenstation
* src/sheet.c (sheet_is_all_selected): Return wheter all the sheet
is selected.
* src/utils.c (cell_name): Fixed cell name computation.
(parse_cell_name): Fixed parsing of the cell name.
* src/item-grid.c (item_grid_event): More range checks.
* src/item-bar.c (item_bar_event): range checks here too.
* src/sheet-autofill.c (FillItem): Keep track of the originating
cell so that we can copy the format.
* src/cell.c (cell_set_style): New function.
* src/sheet.c (sheet_selection_reset_only): Simple fix: For the
row case, redraw the rows, not the columns. Cut/paste typo.
* src/dialog-goto-cell.c (dialog_goto_cell): Do not complain if
there was no target cell entered.
......
1998-09-23 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/style.c (font_compute_hints): At font creation time store a
couple of the font attributes for quick retrieval.
* src/sheet-view.c (sheet_view_construct): Do not allow this
button to have the focus either.
* src/item-bar.c (item_bar_draw): If the whole sheet is selected,
draw all of the columns in pressed presenstation
* src/sheet.c (sheet_is_all_selected): Return wheter all the sheet
is selected.
* src/utils.c (cell_name): Fixed cell name computation.
(parse_cell_name): Fixed parsing of the cell name.
* src/item-grid.c (item_grid_event): More range checks.
* src/item-bar.c (item_bar_event): range checks here too.
* src/sheet-autofill.c (FillItem): Keep track of the originating
cell so that we can copy the format.
* src/cell.c (cell_set_style): New function.
* src/sheet.c (sheet_selection_reset_only): Simple fix: For the
row case, redraw the rows, not the columns. Cut/paste typo.
* src/dialog-goto-cell.c (dialog_goto_cell): Do not complain if
there was no target cell entered.
......
1998-09-23 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/style.c (font_compute_hints): At font creation time store a
couple of the font attributes for quick retrieval.
* src/sheet-view.c (sheet_view_construct): Do not allow this
button to have the focus either.
* src/item-bar.c (item_bar_draw): If the whole sheet is selected,
draw all of the columns in pressed presenstation
* src/sheet.c (sheet_is_all_selected): Return wheter all the sheet
is selected.
* src/utils.c (cell_name): Fixed cell name computation.
(parse_cell_name): Fixed parsing of the cell name.
* src/item-grid.c (item_grid_event): More range checks.
* src/item-bar.c (item_bar_event): range checks here too.
* src/sheet-autofill.c (FillItem): Keep track of the originating
cell so that we can copy the format.
* src/cell.c (cell_set_style): New function.
* src/sheet.c (sheet_selection_reset_only): Simple fix: For the
row case, redraw the rows, not the columns. Cut/paste typo.
* src/dialog-goto-cell.c (dialog_goto_cell): Do not complain if
there was no target cell entered.
......
......@@ -126,6 +126,18 @@ cell_set_font (Cell *cell, char *font_name)
cell_set_font_from_style (cell, style_font);
}
void
cell_set_style (Cell *cell, Style *reference_style)
{
g_return_if_fail (cell != NULL);
g_return_if_fail (reference_style != NULL);
cell_queue_redraw (cell);
cell->style = style_duplicate (reference_style);
cell_calc_dimensions (cell);
cell_queue_redraw (cell);
}
void
cell_set_foreground (Cell *cell, gushort red, gushort green, gushort blue)
{
......
......@@ -70,6 +70,7 @@ 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_style (Cell *cell, Style *reference_style);
void cell_set_font_from_style (Cell *cell, StyleFont *style_font);
void cell_set_foreground (Cell *cell, gushort red, gushort green, gushort blue);
void cell_set_background (Cell *cell, gushort red, gushort green, gushort blue);
......
......@@ -69,13 +69,13 @@ cell_name (int col, int row)
static char buffer [10];
char *p = buffer;
if (col < 'Z'-'A'){
if (col <= 'Z'-'A'){
*p++ = col + 'A';
} else {
int a = col / ('Z'-'A');
int b = col % ('Z'-'A');
int a = col / ('Z'-'A'+1);
int b = col % ('Z'-'A'+1);
*p++ = a + 'A';
*p++ = a + 'A' - 1;
*p++ = b + 'A';
}
sprintf (p, "%d", row+1);
......@@ -158,7 +158,7 @@ parse_cell_name (char *cell_str, int *col, int *row)
*col = toupper (*cell_str++) - 'A';
if (isalpha (*cell_str))
*col = *col * ('Z' - 'A') + toupper (*cell_str++) - 'A';
*col = ((*col+1) * ('Z' - 'A' + 1)) + (toupper (*cell_str++) - 'A');
if (!isdigit (*cell_str))
return FALSE;
......
......@@ -131,7 +131,7 @@ get_col_name (int n)
}
static void
bar_draw_cell (ItemBar *item_bar, GdkDrawable *drawable, ColRowInfo *info, char *str, int x1, int y1, int x2, int y2)
bar_draw_cell (ItemBar *item_bar, GdkDrawable *drawable, int draw_selected, char *str, int x1, int y1, int x2, int y2)
{
GtkWidget *canvas = GTK_WIDGET (GNOME_CANVAS_ITEM (item_bar)->canvas);
GdkFont *font = canvas->style->font;
......@@ -141,7 +141,7 @@ bar_draw_cell (ItemBar *item_bar, GdkDrawable *drawable, ColRowInfo *info, char
len = gdk_string_width (font, str);
texth = font->ascent + font->descent;
if (info->selected){
if (draw_selected){
shadow = GTK_SHADOW_IN;
gc = canvas->style->dark_gc [GTK_STATE_NORMAL];
} else {
......@@ -164,7 +164,7 @@ item_bar_draw (GnomeCanvasItem *item, GdkDrawable *drawable, int x, int y, int w
ItemBar *item_bar = ITEM_BAR (item);
Sheet *sheet = item_bar->sheet_view->sheet;
ColRowInfo *cri;
int element, total, pixels, limit;
int element, total, pixels, limit, all_selected;
char *str;
element = item_bar->first_element;
......@@ -175,8 +175,15 @@ item_bar_draw (GnomeCanvasItem *item, GdkDrawable *drawable, int x, int y, int w
limit = x + width;
total = 0;
if (sheet_is_all_selected (sheet))
all_selected = 1;
else
all_selected = 0;
do {
if (item_bar->orientation == GTK_ORIENTATION_VERTICAL){
if (element >= SHEET_MAX_ROWS){
GtkWidget *canvas = GTK_WIDGET (item->canvas);
......@@ -193,10 +200,11 @@ item_bar_draw (GnomeCanvasItem *item, GdkDrawable *drawable, int x, int y, int w
if (total + pixels >= y){
str = get_row_name (element);
bar_draw_cell (item_bar, drawable, cri, str,
-x, 1 + total - y,
item->canvas->width - x,
1 + total + pixels - y);
bar_draw_cell (item_bar, drawable,
cri->selected | all_selected,
str, -x, 1 + total - y,
item->canvas->width - x,
1 + total + pixels - y);
}
} else {
if (element >= SHEET_MAX_COLS){
......@@ -212,13 +220,14 @@ item_bar_draw (GnomeCanvasItem *item, GdkDrawable *drawable, int x, int y, int w
pixels = item_bar->resize_width;
else
pixels = cri->pixels;
if (total + pixels >= x){
str = get_col_name (element);
bar_draw_cell (item_bar, drawable, cri, str,
1 + total - x, -y,
1 + total + pixels - x,
item->canvas->height - y);
bar_draw_cell (item_bar, drawable,
cri->selected | all_selected,
str, 1 + total - x, -y,
1 + total + pixels - x,
item->canvas->height - y);
}
}
......@@ -447,6 +456,15 @@ item_bar_event (GnomeCanvasItem *item, GdkEvent *e)
pos = x;
cri = is_pointer_on_division (item_bar, pos, &start, &element);
if (item_bar->orientation == GTK_ORIENTATION_VERTICAL){
if (element > SHEET_MAX_ROWS-1)
break;
} else {
if (element > SHEET_MAX_COLS-1)
break;
}
if (cri){
/* Record the important bits */
item_bar->resize_pos = element;
......
......@@ -627,8 +627,13 @@ item_grid_event (GnomeCanvasItem *item, GdkEvent *event)
convert (canvas, event->button.x, event->button.y, &x, &y);
col = item_grid_find_col (item_grid, x, NULL);
row = item_grid_find_row (item_grid, y, NULL);
sheet_accept_pending_input (sheet);
if (col > SHEET_MAX_COLS-1)
return 1;
if (row > SHEET_MAX_ROWS-1)
return 1;
sheet_cursor_move (sheet, col, row);
if (!(event->button.state & GDK_CONTROL_MASK))
sheet_selection_reset_only (sheet);
......
......@@ -68,7 +68,8 @@ typedef struct {
struct FillItem {
FillType type;
Cell *reference;
union {
ExprTree *formula;
Value *value;
......@@ -197,6 +198,7 @@ fill_item_new (Cell *cell)
fi = g_new (FillItem, 1);
fi->type = FILL_EMPTY;
fi->reference = cell;
if (!cell)
return fi;
......@@ -414,6 +416,8 @@ autofill_destroy_fill_items (GList *all_items)
static void
autofill_cell (Cell *cell, int idx, FillItem *fi)
{
cell_set_style (cell, fi->reference->style);
switch (fi->type){
case FILL_EMPTY:
case FILL_INVALID:
......
......@@ -461,6 +461,7 @@ sheet_view_construct (SheetView *sheet_view)
/* The select-all button */
select_all = gtk_button_new ();
GTK_WIDGET_UNSET_FLAGS (select_all, GTK_CAN_FOCUS);
gtk_table_attach (table, select_all, 0, 1, 0, 1, GTK_FILL, GTK_FILL, 0, 0);
gtk_signal_connect (GTK_OBJECT (select_all), "clicked",
GTK_SIGNAL_FUNC (button_select_all), sheet_view);
......
......@@ -720,6 +720,24 @@ object_event (GnomeCanvasItem *item, GdkEvent *event, SheetObject *object)
return TRUE;
}
/*
* new_control_point
* @group: The canvas group to which this control point belongs
* @object: The object
* @idx: control point index to be created
* @x: x coordinate of control point
* @y: y coordinate of control point
*
* This is used to create a number of control points in a sheet
* object, the meaning of them is used in other parts of the code
* to belong to the following locations:
*
* 0 -------- 1 -------- 2
* | |
* 3 4
* | |
* 5 -------- 6 -------- 7
*/
static GnomeCanvasItem *
new_control_point (GnomeCanvasGroup *group, SheetObject *object, int idx, double x, double y)
{
......
......@@ -461,6 +461,7 @@ sheet_view_construct (SheetView *sheet_view)
/* The select-all button */
select_all = gtk_button_new ();
GTK_WIDGET_UNSET_FLAGS (select_all, GTK_CAN_FOCUS);
gtk_table_attach (table, select_all, 0, 1, 0, 1, GTK_FILL, GTK_FILL, 0, 0);
gtk_signal_connect (GTK_OBJECT (select_all), "clicked",
GTK_SIGNAL_FUNC (button_select_all), sheet_view);
......
......@@ -994,6 +994,25 @@ sheet_select_all (Sheet *sheet)
}
}
int
sheet_is_all_selected (Sheet *sheet)
{
SheetSelection *ss;
g_return_val_if_fail (sheet != NULL, FALSE);
g_return_val_if_fail (IS_SHEET (sheet), FALSE);
ss = sheet->selections->data;
if (ss->start_col == 0 &&
ss->start_row == 0 &&
ss->end_col == SHEET_MAX_COLS-1 &&
ss->end_row == SHEET_MAX_ROWS-1)
return TRUE;
else
return FALSE;
}
/*
* This routine is used to queue the redraw regions for the
* cell region specified.
......@@ -1209,7 +1228,7 @@ sheet_selection_reset_only (Sheet *sheet)
for (l = sheet->sheet_views; l; l = l->next){
SheetView *sheet_view = l->data;
sheet_view_redraw_columns (sheet_view);
sheet_view_redraw_rows (sheet_view);
}
}
......
......@@ -144,6 +144,7 @@ void sheet_cursor_move (Sheet *sheet, int col, int row);
/* Selection management */
void sheet_select_all (Sheet *sheet);
int sheet_is_all_selected (Sheet *sheet);
void sheet_selection_append (Sheet *sheet, int col, int row);
void sheet_selection_extend_to (Sheet *sheet, int col, int row);
void sheet_selection_reset (Sheet *sheet);
......
......@@ -63,6 +63,34 @@ style_format_unref (StyleFormat *sf)
g_free (sf);
}
static void
font_compute_hints (StyleFont *font)
{
char *p = font->font_name;
int hyphens = 0;
font->hint_is_bold = 0;
font->hint_is_italic = 0;
for (;*p; p++){
if (*p == '-'){
hypens++;
if (hypens == 3 && (strcmp (p+1, "bold") == 0)){
font->hint_is_bold = 1;
}
if (hypens == 4){
if (*(p+1) == 'o' || *(p+1) == 'i')
font->hint_is_italic = 1;
}
if (hypens > 5)
break;
}
}
}
StyleFont *
style_font_new_simple (char *font_name, int units)
{
......@@ -88,6 +116,9 @@ style_font_new_simple (char *font_name, int units)
font->font_name = g_strdup (font_name);
font->units = units;
font->font = gdk_font_load (font_name);
font_compute_hints (font);
g_hash_table_insert (style_font_hash, font, font);
}
font->ref_count++;
......
......@@ -20,6 +20,13 @@ typedef struct {
char *font_name;
int units;
GdkFont *font;
/*
* These are runtime optimizations, there is no need to save these
* they get computed at StyleFont creation time.
*/
unsigned int hint_is_bold:1;
unsigned int hint_is_italic:1;
} StyleFont;
typedef struct {
......
......@@ -69,13 +69,13 @@ cell_name (int col, int row)
static char buffer [10];
char *p = buffer;
if (col < 'Z'-'A'){
if (col <= 'Z'-'A'){
*p++ = col + 'A';
} else {
int a = col / ('Z'-'A');
int b = col % ('Z'-'A');
int a = col / ('Z'-'A'+1);
int b = col % ('Z'-'A'+1);
*p++ = a + 'A';
*p++ = a + 'A' - 1;
*p++ = b + 'A';
}
sprintf (p, "%d", row+1);
......@@ -158,7 +158,7 @@ parse_cell_name (char *cell_str, int *col, int *row)
*col = toupper (*cell_str++) - 'A';
if (isalpha (*cell_str))
*col = *col * ('Z' - 'A') + toupper (*cell_str++) - 'A';
*col = ((*col+1) * ('Z' - 'A' + 1)) + (toupper (*cell_str++) - 'A');
if (!isdigit (*cell_str))
return FALSE;
......
......@@ -554,6 +554,16 @@ workbook_parse_and_jump (Workbook *wb, char *text)
} else {
Sheet *sheet = workbook_get_current_sheet (wb);
if (col > SHEET_MAX_COLS-2){
gnumeric_notice (_("Column out of range"));
return FALSE;
}
if (row > SHEET_MAX_ROWS-2){
gnumeric_notice (_("Row number out of range"));
return FALSE;
}
sheet_cursor_move (sheet, col, row);
return TRUE;
}
......@@ -582,7 +592,8 @@ accept_input (GtkWidget *widget, Workbook *wb)
{
Sheet *sheet = workbook_get_current_sheet (wb);
sheet_accept_pending_input (sheet);
sheet_set_current_value (sheet);
workbook_focus_current_sheet (wb);
}
static void
......@@ -591,6 +602,7 @@ cancel_input (GtkWidget *widget, Workbook *wb)
Sheet *sheet = workbook_get_current_sheet (wb);
sheet_cancel_pending_input (sheet);
workbook_focus_current_sheet (wb);
}
static void
......
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