diff --git a/src/cell.c b/src/cell.c index ac6e4652ae70d1e2ab5f49e66b8482db08666d69..4d8e697e12591d3976e3e1abe6f17bc938ecda2b 100644 --- a/src/cell.c +++ b/src/cell.c @@ -8,6 +8,7 @@ #include #include #include "gnumeric.h" +#include "gnumeric-sheet.h" #include "eval.h" #include "format.h" @@ -52,7 +53,7 @@ cell_set_formula (Cell *cell, char *text) * This routine changes the alignment of a cell to those specified. */ void -cell_set_alignment (Cell *cell, int halign, int valign, int orient) +cell_set_alignment (Cell *cell, int halign, int valign, int orient, int auto_return) { g_return_if_fail (cell != NULL); g_return_if_fail (cell->style != NULL); @@ -65,7 +66,10 @@ cell_set_alignment (Cell *cell, int halign, int valign, int orient) cell->style->halign = halign; cell->style->valign = valign; cell->style->orientation = orient; - + cell->style->fit_in_cell = auto_return; + + cell_calc_dimensions (cell); + cell_queue_redraw (cell); } @@ -73,7 +77,6 @@ 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); @@ -85,10 +88,7 @@ cell_set_font_from_style (Cell *cell, StyleFont *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_calc_dimensions (cell); cell_queue_redraw (cell); } @@ -393,6 +393,7 @@ cell_get_span (Cell *cell, int *col1, int *col2) cell->style->fit_in_cell || cell->style->valign == VALIGN_JUSTIFY || cell->style->halign == HALIGN_JUSTIFY || + cell->style->halign == HALIGN_FILL || cell_contents_fit_inside_column (cell)){ *col1 = *col2 = cell->col->pos; return; @@ -402,7 +403,7 @@ cell_get_span (Cell *cell, int *col1, int *col2) align = cell_get_horizontal_align (cell); row = cell->row->pos; - switch (cell->style->halign){ + switch (align){ case HALIGN_LEFT: *col1 = *col2 = cell->col->pos; pos = cell->col->pos + 1; @@ -475,7 +476,7 @@ cell_get_span (Cell *cell, int *col1, int *col2) ColRowInfo *ci; Cell *left_sibling, *right_sibling; - if (*col1 - 1 > 0){ + if (*col1 - 1 >= 0){ left_sibling = sheet_cell_get (sheet, *col1 - 1, row); if (left_sibling) @@ -508,7 +509,11 @@ cell_get_span (Cell *cell, int *col1, int *col2) left_right = 0; } /* for */ - + break; + + default: + g_warning ("Unknown horizontal alignment type\n"); + *col1 = *col2 = cell->col->pos; } /* case HALIGN_CENTER */ } /* switch */ @@ -569,12 +574,13 @@ calc_text_dimensions (int is_number, Style *style, char *text, int cell_w, int c used = gdk_text_width (font, ideal_cut_spot, n); } else { - used = 0; + used = len; } - *h += CELL_TEXT_INTER_SPACE + font_height; + printf ("Anadiendo %d pixeles\n", font_height); + *h += font_height; ideal_cut_spot = NULL; - } - used += len; + } else + used += len; if (*p == ' ') last_was_cut_point = TRUE; @@ -622,11 +628,259 @@ cell_calc_dimensions (Cell *cell) cell->width = cell->col->margin_a + cell->col->margin_b; } -#if 0 +static void +draw_overflow (GdkDrawable *drawable, GdkGC *gc, GdkFont *font, int x1, int y1, int text_base, int width, int height) +{ + GdkRectangle rect; + int len = gdk_string_width (font, "#"); + int total, offset; + + rect.x = x1; + rect.y = y1; + rect.width = width; + rect.height = height; + gdk_gc_set_clip_rectangle (gc, &rect); + + offset = x1 + width - len; + for (total = len; offset > len; total += len){ + gdk_draw_text (drawable, font, gc, x1 + offset, text_base, "#", 1); + offset -= len; + } +} + +static GList * +cell_split_text (GdkFont *font, char *text, int width) +{ + GList *list; + char *p, *line, *line_begin, *ideal_cut_spot = NULL; + int line_len, used, last_was_cut_point; + + list = NULL; + used = 0; + last_was_cut_point = FALSE; + for (line_begin = p = text; *p; p++){ + int len; + + if (last_was_cut_point && *p != ' ') + ideal_cut_spot = p; + + len = gdk_text_width (font, p, 1); + + /* If we have overflowed, do the wrap */ + if (used + len > width){ + char *begin = line_begin; + + if (ideal_cut_spot){ + int n = p - ideal_cut_spot + 1; + + line_len = ideal_cut_spot - line_begin; + used = gdk_text_width (font, ideal_cut_spot, n); + line_begin = ideal_cut_spot; + } else { + used = len; + line_len = p - line_begin; + line_begin = p; + } + + line = g_malloc (line_len + 1); + memcpy (line, begin, line_len); + line [line_len] = 0; + list = g_list_append (list, line); + + ideal_cut_spot = NULL; + } else + used += len; + + if (*p == ' ') + last_was_cut_point = TRUE; + else + last_was_cut_point = FALSE; + } + if (*line_begin){ + line_len = p - line_begin; + line = g_malloc (line_len); + memcpy (line, line_begin, line_len); + line [line_len] = 0; + list = g_list_append (list, line); + } + + return list; +} + void -cell_draw (GdkDrawable *drawable, GdkFont *font, GdkGc *gc, - Style *style, int x_offset, int y_offset, int width, char *text) +cell_draw (Cell *cell, void *sv, GdkGC *gc, GdkDrawable *drawable, int x1, int y1) { + Style *style = cell->style; + GdkFont *font = style->font->font; + SheetView *sheet_view = sv; + GdkGC *white_gc = GTK_WIDGET (sheet_view->sheet_view)->style->white_gc; + GdkRectangle rect; + int start_col, end_col; + int width, height; + int text_base = y1 + cell->row->pixels - cell->row->margin_b - font->descent + 1; + int font_height; + int halign; + int do_multi_line; + char *text; + + cell_get_span (cell, &start_col, &end_col); + + width = COL_INTERNAL_WIDTH (cell->col); + height = ROW_INTERNAL_HEIGHT (cell->row); + + gdk_gc_set_function (gc, GDK_COPY); + + font_height = font->ascent + font->descent; + + halign = cell_get_horizontal_align (cell); + text = CELL_TEXT_GET (cell); + + if ((cell->style->valid_flags & STYLE_COLOR) && cell->style->color){ + gdk_gc_set_background (gc, &cell->style->color->background); + } + + /* if a number overflows, do special drawing */ + if (width < cell->width && cell_is_number (cell)){ + draw_overflow (drawable, gc, font, x1 + cell->col->margin_a, y1, text_base, + width, height); + return; + } + + if (halign == HALIGN_JUSTIFY || style->valign == VALIGN_JUSTIFY || style->fit_in_cell) + do_multi_line = TRUE; + else + do_multi_line = FALSE; + + if (do_multi_line){ + GList *lines, *l; + int cell_pixel_height = ROW_INTERNAL_HEIGHT (cell->row); + int line_count, x_offset, y_offset, inter_space; + + lines = cell_split_text (font, text, width); + line_count = g_list_length (lines); + + rect.x = x1; + rect.y = y1; + rect.height = cell->height; + rect.width = cell->width; + gdk_gc_set_clip_rectangle (gc, &rect); + + switch (style->valign){ + case VALIGN_TOP: + y_offset = 0; + inter_space = font_height; + break; + + case VALIGN_BOTTOM: + y_offset = cell_pixel_height - (line_count * font_height); + inter_space = font_height; + break; + + case VALIGN_CENTER: + y_offset = (cell_pixel_height - (line_count * font_height))/2; + inter_space = font_height; + break; + + case VALIGN_JUSTIFY: + y_offset = 0; + inter_space = font_height + + (cell_pixel_height - (line_count * font_height)) + / line_count; + break; + default: + g_warning ("Unhandled cell vertical alignment\n"); + y_offset = 0; + inter_space = font_height; + } + + y_offset += font_height - 1; + for (l = lines; l; l = l->next){ + char *str = l->data; + + switch (halign){ + case HALIGN_LEFT: + case HALIGN_JUSTIFY: + x_offset = cell->col->margin_a; + break; + + case HALIGN_RIGHT: + x_offset = cell->col->pixels - cell->col->margin_b - gdk_string_width (font, str); + break; + + case HALIGN_CENTER: + x_offset = (cell->col->pixels - cell->width) / 2; + break; + default: + g_warning ("Multi-line justification style not supported\n"); + x_offset = cell->col->margin_a; + } + /* Advance one pixel for the border */ + x_offset++; + gc = GTK_WIDGET (sheet_view->sheet_view)->style->black_gc; + gdk_draw_text (drawable, font, gc, x1 + x_offset, y1 + y_offset, str, strlen (str)); + y_offset += inter_space; + + g_free (str); + } + g_list_free (lines); + + } else { + int x, diff, total, len; + + /* + * x1, y1 are relative to this cell origin, but the cell might be using + * columns to the left (if it is set to right justify or center justify) + * compute the pixel difference + */ + if (start_col != cell->col->pos) + diff = -sheet_col_get_distance (cell->sheet, start_col, cell->col->pos); + else + diff = 0; + + /* This rectangle has the whole area used by this cell */ + rect.x = x1 + 1 + diff; + rect.y = y1 + 1; + rect.width = sheet_col_get_distance (cell->sheet, start_col, end_col+1) - 2; + rect.height = cell->row->pixels - 2; + + /* Set the clip rectangle */ + gdk_gc_set_clip_rectangle (gc, &rect); + gdk_draw_rectangle (drawable, white_gc, TRUE, + rect.x, rect.y, rect.width, rect.height); + + len = 0; + switch (halign){ + case HALIGN_FILL: + printf ("FILL!\n"); + len = gdk_string_width (font, text); + /* fall down */ + + case HALIGN_LEFT: + x = cell->col->margin_a; + break; + + case HALIGN_RIGHT: + x = cell->col->pixels - cell->col->margin_b - cell->width; + break; + + case HALIGN_CENTER: + x = (cell->col->pixels - cell->width)/2; + break; + + default: + g_warning ("Single-line justification style not supported\n"); + x = cell->col->margin_a; + break; + } + + total = 0; + do { + gdk_draw_text (drawable, font, gc, 1 + x1 + x, text_base, text, strlen (text)); + x1 += len; + total += len; + } while (halign == HALIGN_FILL && total < rect.width); + } } -#endif + + diff --git a/src/cell.h b/src/cell.h index c63da9c4256f171e95af9d1e86991ceefeefb0bc..30057fbd2692d1916cb0b9fe13dee6d7e6241bd2 100644 --- a/src/cell.h +++ b/src/cell.h @@ -48,7 +48,6 @@ typedef GList CellList; #define CELL_TEXT_GET(cell) ((cell)->text ? cell->text->str : cell->entered_text->str) #define CELL_IS_FORMULA(cell) (cell->entered_text->str [0] == '=') -#define CELL_TEXT_INTER_SPACE 2 typedef struct { int col_offset, row_offset; /* Position of the cell */ @@ -69,7 +68,7 @@ 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_alignment (Cell *cell, int halign, int valign, int orientation, int auto_return); void cell_set_rendered_text (Cell *cell, char *rendered_text); void cell_formula_relocate (Cell *cell, int target_col, int target_row); void cell_get_span (Cell *cell, int *col1, int *col2); @@ -82,6 +81,10 @@ void cell_formula_changed (Cell *cell); void cell_queue_redraw (Cell *cell); int cell_get_horizontal_align (Cell *cell); +void cell_draw (Cell *cell, void *sheet_view, + GdkGC *gc, GdkDrawable *drawable, + int x, int y); + void calc_text_dimensions (int is_number, Style *style, char *text, int cell_w, int cell_h, int *h, int *w); diff --git a/src/dialog-cell-format.c b/src/dialog-cell-format.c index fecd44c0e0ecd272e0ccddda0db716e36ee29f4a..5f720b9222e742770076ae907c6711ffff883f87 100644 --- a/src/dialog-cell-format.c +++ b/src/dialog-cell-format.c @@ -27,6 +27,7 @@ static GtkWidget *font_widget; /* There point to the radio groups in the format/alignment page */ static GSList *hradio_list; static GSList *vradio_list; +static GtkWidget *auto_return; /* Points to the first cell in the selection */ static Cell *first_cell; @@ -406,8 +407,21 @@ static align_def_t vertical_aligns [] = { { NULL, 0 } }; +static void +do_disable (GtkWidget *widget, GtkWidget *op) +{ + int v; + + if (GTK_TOGGLE_BUTTON (widget)->active) + v = FALSE; + else + v = TRUE; + + gtk_widget_set_sensitive (op, v); +} + static GtkWidget * -make_radio_selection (GtkWidget *prop_win, char *title, align_def_t *array, GSList **dest_list) +make_radio_selection (GtkWidget *prop_win, char *title, align_def_t *array, GSList **dest_list, GtkWidget *disable) { GtkWidget *frame, *vbox; GSList *group; @@ -422,6 +436,11 @@ make_radio_selection (GtkWidget *prop_win, char *title, align_def_t *array, GSLi item = gtk_radio_button_new_with_label (group, _(array->name)); group = gtk_radio_button_group (GTK_RADIO_BUTTON (item)); gtk_box_pack_start_defaults (GTK_BOX (vbox), item); + + if (disable && strcmp (array->name, "Fill") == 0){ + gtk_signal_connect (GTK_OBJECT (item), "toggled", + GTK_SIGNAL_FUNC (do_disable), disable); + } } *dest_list = group; @@ -439,28 +458,35 @@ create_align_page (GtkWidget *prop_win, CellList *cells) { GtkTable *t; GtkWidget *w; - int ha, va, ok = 0; + int ha, va, autor, ok = 0; GList *l; GSList *sl; t = (GtkTable *) gtk_table_new (0, 0, 0); - /* Horizontal alignment */ - w = make_radio_selection (prop_win, _("Horizontal"), horizontal_aligns, &hradio_list); - gtk_table_attach (t, w, 0, 1, 0, 2, 0, GTK_FILL, 4, 0); - /* Vertical alignment */ - w = make_radio_selection (prop_win, _("Vertical"), vertical_aligns, &vradio_list); + w = make_radio_selection (prop_win, _("Vertical"), vertical_aligns, &vradio_list, NULL); gtk_table_attach (t, w, 1, 2, 0, 1, 0, GTK_FILL, 4, 0); + /* Horizontal alignment */ + w = make_radio_selection (prop_win, _("Horizontal"), horizontal_aligns, &hradio_list, w); + gtk_table_attach (t, w, 0, 1, 0, 2, 0, GTK_FILL, 4, 0); + + auto_return = gtk_check_button_new_with_label ("Auto return"); + gtk_table_attach (t, auto_return, 0, 3, 2, 3, 0, 0, 0, 0); + /* Check if all cells have the same properties */ if (cells){ - ha = ((Cell *) (cells->data))->style->halign; - va = ((Cell *) (cells->data))->style->valign; + ha = ((Cell *) (cells->data))->style->halign; + va = ((Cell *) (cells->data))->style->valign; + autor = ((Cell *) (cells->data))->style->fit_in_cell; + for (ok = 1, l = cells; l; l = l->next){ Cell *cell = l->data; - if (cell->style->halign != ha || cell->style->valign != va){ + if (cell->style->halign != ha || + cell->style->valign != va || + cell->style->fit_in_cell != autor){ ok = 0; break; } @@ -481,6 +507,9 @@ create_align_page (GtkWidget *prop_win, CellList *cells) gtk_radio_button_select (vradio_list, n); break; } + + if (autor) + gtk_toggle_button_toggled (GTK_TOGGLE_BUTTON (auto_return)); } } @@ -506,17 +535,18 @@ static void apply_align_format (Style *style, Sheet *sheet, CellList *cells) { int i; - int halign, valign; + int halign, valign, autor; 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; - + autor = GTK_TOGGLE_BUTTON (auto_return)->active; + for (; cells; cells = cells->next){ Cell *cell = cells->data; - cell_set_alignment (cell, halign, valign, ORIENT_HORIZ); + cell_set_alignment (cell, halign, valign, ORIENT_HORIZ, autor); } style->halign = halign; style->valign = valign; diff --git a/src/dialogs/dialog-cell-format.c b/src/dialogs/dialog-cell-format.c index fecd44c0e0ecd272e0ccddda0db716e36ee29f4a..5f720b9222e742770076ae907c6711ffff883f87 100644 --- a/src/dialogs/dialog-cell-format.c +++ b/src/dialogs/dialog-cell-format.c @@ -27,6 +27,7 @@ static GtkWidget *font_widget; /* There point to the radio groups in the format/alignment page */ static GSList *hradio_list; static GSList *vradio_list; +static GtkWidget *auto_return; /* Points to the first cell in the selection */ static Cell *first_cell; @@ -406,8 +407,21 @@ static align_def_t vertical_aligns [] = { { NULL, 0 } }; +static void +do_disable (GtkWidget *widget, GtkWidget *op) +{ + int v; + + if (GTK_TOGGLE_BUTTON (widget)->active) + v = FALSE; + else + v = TRUE; + + gtk_widget_set_sensitive (op, v); +} + static GtkWidget * -make_radio_selection (GtkWidget *prop_win, char *title, align_def_t *array, GSList **dest_list) +make_radio_selection (GtkWidget *prop_win, char *title, align_def_t *array, GSList **dest_list, GtkWidget *disable) { GtkWidget *frame, *vbox; GSList *group; @@ -422,6 +436,11 @@ make_radio_selection (GtkWidget *prop_win, char *title, align_def_t *array, GSLi item = gtk_radio_button_new_with_label (group, _(array->name)); group = gtk_radio_button_group (GTK_RADIO_BUTTON (item)); gtk_box_pack_start_defaults (GTK_BOX (vbox), item); + + if (disable && strcmp (array->name, "Fill") == 0){ + gtk_signal_connect (GTK_OBJECT (item), "toggled", + GTK_SIGNAL_FUNC (do_disable), disable); + } } *dest_list = group; @@ -439,28 +458,35 @@ create_align_page (GtkWidget *prop_win, CellList *cells) { GtkTable *t; GtkWidget *w; - int ha, va, ok = 0; + int ha, va, autor, ok = 0; GList *l; GSList *sl; t = (GtkTable *) gtk_table_new (0, 0, 0); - /* Horizontal alignment */ - w = make_radio_selection (prop_win, _("Horizontal"), horizontal_aligns, &hradio_list); - gtk_table_attach (t, w, 0, 1, 0, 2, 0, GTK_FILL, 4, 0); - /* Vertical alignment */ - w = make_radio_selection (prop_win, _("Vertical"), vertical_aligns, &vradio_list); + w = make_radio_selection (prop_win, _("Vertical"), vertical_aligns, &vradio_list, NULL); gtk_table_attach (t, w, 1, 2, 0, 1, 0, GTK_FILL, 4, 0); + /* Horizontal alignment */ + w = make_radio_selection (prop_win, _("Horizontal"), horizontal_aligns, &hradio_list, w); + gtk_table_attach (t, w, 0, 1, 0, 2, 0, GTK_FILL, 4, 0); + + auto_return = gtk_check_button_new_with_label ("Auto return"); + gtk_table_attach (t, auto_return, 0, 3, 2, 3, 0, 0, 0, 0); + /* Check if all cells have the same properties */ if (cells){ - ha = ((Cell *) (cells->data))->style->halign; - va = ((Cell *) (cells->data))->style->valign; + ha = ((Cell *) (cells->data))->style->halign; + va = ((Cell *) (cells->data))->style->valign; + autor = ((Cell *) (cells->data))->style->fit_in_cell; + for (ok = 1, l = cells; l; l = l->next){ Cell *cell = l->data; - if (cell->style->halign != ha || cell->style->valign != va){ + if (cell->style->halign != ha || + cell->style->valign != va || + cell->style->fit_in_cell != autor){ ok = 0; break; } @@ -481,6 +507,9 @@ create_align_page (GtkWidget *prop_win, CellList *cells) gtk_radio_button_select (vradio_list, n); break; } + + if (autor) + gtk_toggle_button_toggled (GTK_TOGGLE_BUTTON (auto_return)); } } @@ -506,17 +535,18 @@ static void apply_align_format (Style *style, Sheet *sheet, CellList *cells) { int i; - int halign, valign; + int halign, valign, autor; 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; - + autor = GTK_TOGGLE_BUTTON (auto_return)->active; + for (; cells; cells = cells->next){ Cell *cell = cells->data; - cell_set_alignment (cell, halign, valign, ORIENT_HORIZ); + cell_set_alignment (cell, halign, valign, ORIENT_HORIZ, autor); } style->halign = halign; style->valign = valign; diff --git a/src/format.c b/src/format.c index 5d1c8643b5644ebda4f5d26482ad93315d8777f7..bf8f8959c4a7a7c4e0cea290d4435c4906c140da 100644 --- a/src/format.c +++ b/src/format.c @@ -792,7 +792,7 @@ do_render_number (gdouble number, format_info_t *info) else decimal_point = ""; -#ifdef 0 +#if 0 printf ("Rendering: %g with:\n", number); printf ("left_req: %d\n" "right_req: %d\n" @@ -1128,7 +1128,6 @@ format_value (StyleFormat *format, Value *value, char **color_name) /* Try to parse a color specification */ if (entry.format [0] == '['){ char *end = strchr (entry.format, ']'); - char *color; if (end){ if (color_name) diff --git a/src/item-edit.c b/src/item-edit.c index 4299f241dd5fabc1e869e26bf173a489232188d9..69e5e1c710ea3ee92bf5458444e29c9c4810dfcf 100644 --- a/src/item-edit.c +++ b/src/item-edit.c @@ -72,6 +72,9 @@ item_edit_draw (GnomeCanvasItem *item, GdkDrawable *drawable, gdk_draw_rectangle (drawable, canvas->style->white_gc, TRUE, dx + 1, dy + 1, wd - 1, hd - 1); + /* The margin, plus the pixel consumed by the border */ + dx += ci->margin_a + 1; + first_part_len = gdk_text_width (font, text, cursor_pos); gdk_draw_text (drawable, font, canvas->style->black_gc, dx, dy + hd - font->descent, text, cursor_pos); diff --git a/src/item-grid.c b/src/item-grid.c index 60ef85939044c8e1567110e4b4ea11a45d987efb..39b8696353c16a94f9e66b6d31e33b8069596c41 100644 --- a/src/item-grid.c +++ b/src/item-grid.c @@ -166,19 +166,15 @@ typedef struct { */ static void item_grid_draw_cell (GdkDrawable *drawable, ItemGrid *item_grid, - int x1, int y1, int width, int height, int col, int row) + int x1, int y1, ColRowInfo *ci, ColRowInfo *ri, int col, int row) { - GnomeCanvas *canvas = GNOME_CANVAS_ITEM (item_grid)->canvas; - GdkGC *white_gc = GTK_WIDGET (canvas)->style->white_gc; - GdkGC *gc = item_grid->gc; - Sheet *sheet = item_grid->sheet; - GdkFont *font; - Cell *cell, *clip_left, *clip_right; - Style *style; - int x_offset, y_offset, text_base, pixels; - GdkRectangle rect; - int halign; - int cell_is_selected; + GnomeCanvas *canvas = GNOME_CANVAS_ITEM (item_grid)->canvas; + GdkGC *gc = item_grid->gc; + Sheet *sheet = item_grid->sheet; + Cell *cell; + int cell_is_selected; + int width = ci->pixels; + int height = ri->pixels; cell_is_selected = sheet_selection_is_cell_selected (sheet, col, row); @@ -200,95 +196,8 @@ item_grid_draw_cell (GdkDrawable *drawable, ItemGrid *item_grid, return; } - /* The offsets where we start drawing the text */ - x_offset = y_offset = 0; - - /* True if we have a sibling cell in the direction where we paint */ - clip_left = NULL; - clip_right = NULL; - - style = cell->style; - font = style->font->font; - - halign = cell_get_horizontal_align (cell); - - switch (halign){ - case HALIGN_LEFT: - if (col < SHEET_MAX_COLS-1) - clip_right = sheet_cell_get (sheet, col+1, row); - x_offset = cell->col->margin_a; - break; - - case HALIGN_RIGHT: - if (col > 0) - clip_left = sheet_cell_get (sheet, col-1, row); - x_offset = cell->col->pixels - cell->width - (cell->col->margin_b + cell->col->margin_a); - break; - - case HALIGN_CENTER: - if (col > 0) - clip_left = sheet_cell_get (sheet, col-1, row); - if (col < SHEET_MAX_COLS-1) - clip_right = sheet_cell_get (sheet, col-1, row); - x_offset = (cell->col->pixels - cell->width)/2; - break; - - case HALIGN_FILL: - if (col < SHEET_MAX_COLS-1) - clip_right = sheet_cell_get (sheet, col-1, row); - clip_left = clip_right = (Cell *) TRUE; - x_offset = cell->col->margin_a; - break; - - case HALIGN_JUSTIFY: - g_warning ("No horizontal justification supported yet\n"); - break; - } - - if ((cell->style->valid_flags & STYLE_COLOR) && cell->style->color){ - gdk_gc_set_foreground (gc, &cell->style->color->foreground); - gdk_gc_set_background (gc, &cell->style->color->background); - } else - gdk_gc_set_foreground (gc, &item_grid->default_color); - - text_base = y1 + cell->row->pixels - cell->row->margin_b - font->descent + 1; - gdk_gc_set_foreground (gc, &item_grid->default_color); - gdk_gc_set_function (gc, GDK_COPY); - - if (clip_left || clip_right){ - rect.x = x1; - rect.y = y1; - rect.width = width; - rect.height = height; - gdk_gc_set_clip_rectangle (gc, &rect); - } else - gdk_gc_set_clip_rectangle (gc, NULL); - - gdk_draw_rectangle (drawable, white_gc, TRUE, - x1 + x_offset, - y1 + cell->row->margin_a, - cell->width - (cell->col->margin_a + cell->col->margin_b), - height - (cell->row->margin_a + cell->row->margin_b)); - - pixels = 0; - if (!cell->entered_text){ - printf ("No entered text in cell %d,%d\n", cell->col->pos, cell->row->pos); - return; - } - - do { - char *text; - - text = CELL_TEXT_GET (cell); - gdk_draw_text (drawable, font, gc, - x1 + x_offset, - text_base + y_offset, - text, strlen (text)); - - pixels += cell->width; - } while (style->halign == HALIGN_FILL && - pixels < cell->col->pixels); + cell_draw (cell, item_grid->sheet_view, gc, drawable, x1, y1); /* * If the cell is selected, turn the inverse video on @@ -398,8 +307,8 @@ item_grid_draw (GnomeCanvasItem *item, GdkDrawable *drawable, int x, int y, int ri = sheet_row_get_info (sheet, row); item_grid_draw_cell (drawable, item_grid, x_paint, y_paint, - ci->pixels, - ri->pixels, + ci, + ri, col, row); y_paint += ri->pixels; } diff --git a/src/pixmaps.h b/src/pixmaps.h new file mode 100644 index 0000000000000000000000000000000000000000..6bd344ac23e588422c737bdebcf99855e741c6f0 --- /dev/null +++ b/src/pixmaps.h @@ -0,0 +1,3 @@ +#include "pixmaps/align-center.xpm" +#include "pixmaps/align-left.xpm" +#include "pixmaps/align-right.xpm" diff --git a/src/sheet-control-gui.c b/src/sheet-control-gui.c index e16e622837580ccfc5c7f1c013c44037fefde23b..a68ba6d96b612f9ecc3b62b9da839a47292c0aa3 100644 --- a/src/sheet-control-gui.c +++ b/src/sheet-control-gui.c @@ -86,8 +86,8 @@ sheet_view_redraw_cell_region (SheetView *sheet_view, int start_col, int start_r min_col = MAX (first_visible_col, min_col); max_col = MIN (last_visible_col, max_col); - x = sheet_col_get_distance (sheet, gsheet->top_col, min_col+1); - y = sheet_col_get_distance (sheet, gsheet->top_row, first_visible_row+1); + x = sheet_col_get_distance (sheet, gsheet->top_col, min_col); + y = sheet_col_get_distance (sheet, gsheet->top_row, first_visible_row); w = sheet_col_get_distance (sheet, min_col, max_col+1); h = sheet_col_get_distance (sheet, first_visible_row, last_visible_row+1); diff --git a/src/sheet-view.c b/src/sheet-view.c index e16e622837580ccfc5c7f1c013c44037fefde23b..a68ba6d96b612f9ecc3b62b9da839a47292c0aa3 100644 --- a/src/sheet-view.c +++ b/src/sheet-view.c @@ -86,8 +86,8 @@ sheet_view_redraw_cell_region (SheetView *sheet_view, int start_col, int start_r min_col = MAX (first_visible_col, min_col); max_col = MIN (last_visible_col, max_col); - x = sheet_col_get_distance (sheet, gsheet->top_col, min_col+1); - y = sheet_col_get_distance (sheet, gsheet->top_row, first_visible_row+1); + x = sheet_col_get_distance (sheet, gsheet->top_col, min_col); + y = sheet_col_get_distance (sheet, gsheet->top_row, first_visible_row); w = sheet_col_get_distance (sheet, min_col, max_col+1); h = sheet_col_get_distance (sheet, first_visible_row, last_visible_row+1); diff --git a/src/workbook.c b/src/workbook.c index f3f233114c032660a6984c9b67ea6e7ad757dcb1..d85c23af9b499eb315260153e5eaec359d6eb878 100644 --- a/src/workbook.c +++ b/src/workbook.c @@ -5,6 +5,9 @@ #include "gnumeric-util.h" #include "gnumeric-sheet.h" #include "dialogs.h" +#include "xml-io.h" + +#include "pixmaps.h" /* The locations within the main table in the workbook */ #define WB_EA_LINE 0 @@ -15,6 +18,36 @@ Workbook *current_workbook; +static void +workbook_new_cmd (void) +{ +} + +static void +workbook_open_cmd (void) +{ +} + +static void +workbook_save_cmd (void) +{ +} + +static void +left_align_cmd (void) +{ +} + +static void +right_align_cmd (void) +{ +} + +static void +center_cmd (void) +{ +} + static void quit_cmd (void) { @@ -24,8 +57,7 @@ quit_cmd (void) static void save_cmd (GtkWidget *widget, Workbook *wb) { - -/* gnumericWriteXmlWorkbook (wb, "default.wb"); */ + gnumericWriteXmlWorkbook (wb, "default.wb"); } static void @@ -220,6 +252,39 @@ static GnomeUIInfo workbook_menu [] = { GNOMEUIINFO_END }; +static GnomeUIInfo workbook_toolbar [] = { + GNOMEUIINFO_ITEM_STOCK (N_("New"), + N_("Create a new sheet"), + workbook_new_cmd, GNOME_STOCK_PIXMAP_NEW), + GNOMEUIINFO_ITEM_STOCK (N_("Open"), + N_("Opens an existing workbook"), + workbook_open_cmd, GNOME_STOCK_PIXMAP_OPEN), + GNOMEUIINFO_ITEM_STOCK (N_("Save"), + N_("Saves the workbook"), + workbook_save_cmd, GNOME_STOCK_PIXMAP_SAVE), + GNOMEUIINFO_SEPARATOR, + GNOMEUIINFO_ITEM_STOCK (N_("Cut"), + N_("Cuts the selection to the clipboard"), + cut_cmd, GNOME_STOCK_PIXMAP_CUT), + GNOMEUIINFO_ITEM_STOCK (N_("Copy"), + N_("Copies the selection to the clipboard"), + copy_cmd, GNOME_STOCK_PIXMAP_COPY), + GNOMEUIINFO_ITEM_STOCK (N_("Paste"), + N_("Pastes the clipboard"), + paste_cmd, GNOME_STOCK_PIXMAP_PASTE), + GNOMEUIINFO_SEPARATOR, + GNOMEUIINFO_ITEM_DATA (N_("Left align"), + N_("Sets the cell alignment to the left"), + left_align_cmd, NULL, align_left), + GNOMEUIINFO_ITEM_DATA (N_("Center"), + N_("Centers the cell contents"), + center_cmd, NULL, align_center), + GNOMEUIINFO_ITEM_DATA (N_("Right align"), + N_("Sets the cell alignment to the right"), + right_align_cmd, NULL, align_right), + GNOMEUIINFO_END +}; + static void workbook_setup_sheets (Workbook *wb) { @@ -512,6 +577,9 @@ workbook_new (void) workbook_setup_sheets (wb); gnome_app_set_contents (GNOME_APP (wb->toplevel), wb->table); gnome_app_create_menus_with_data (GNOME_APP (wb->toplevel), workbook_menu, wb); + gnome_app_create_toolbar_with_data (GNOME_APP (wb->toplevel), workbook_toolbar, wb); + gtk_toolbar_set_style (GTK_TOOLBAR (GNOME_APP (wb->toplevel)->toolbar), GTK_TOOLBAR_ICONS); + /* gtk_accel_group_attach (GTK_OBJECT (wb->toplevel)); */ /* Set the default operation to be performed over selections */