Commit 4ec6073e authored by Arturo Espinosa's avatar Arturo Espinosa

Color attributes in formats work (ie, you can get colored cells now);



Color attributes in formats work (ie, you can get colored cells now);

My first -futile attempts- at getting various different cursors working on the
spreadsheet (we need a cross and various other cursors for a better emulation
of Excel).

The beginning of autofill, but I really need to see Excel live before implementing
this.

Miguel.
parent dd85b128
1998-09-13 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/gnumeric-sheet.c (gnumeric_sheet_realize): Fix: initilaize
the GdkWindow pointer after we have invoked our parent method.
* src/cursors.c: New file. Loads the various cursors used by
Gnumeric.
* src/item-cursor.c (item_cursor_autofill_event): Implement the
cursor growing autofill rules.
1998-09-12 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/workbook.c (workbook_setup_sheets): Dont let the workbooks
take the focus.
(do_focus_sheet): Do focus the current sheet on
page change.
(workbook_setup_signals): Focus the GnumericSheet if no widget has
the focus.
* src/cell.c (cell_draw): Use the value-specified color.
* src/format.c (lookup_color, format_color_init,
format_color_shutdown): New routines to use StyleColors instead of
color names.
1998-09-11 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/cell.c (queue_cell, cell_freeze_redraws, cell_thaw_redraws):
......
1998-09-13 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/gnumeric-sheet.c (gnumeric_sheet_realize): Fix: initilaize
the GdkWindow pointer after we have invoked our parent method.
* src/cursors.c: New file. Loads the various cursors used by
Gnumeric.
* src/item-cursor.c (item_cursor_autofill_event): Implement the
cursor growing autofill rules.
1998-09-12 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/workbook.c (workbook_setup_sheets): Dont let the workbooks
take the focus.
(do_focus_sheet): Do focus the current sheet on
page change.
(workbook_setup_signals): Focus the GnumericSheet if no widget has
the focus.
* src/cell.c (cell_draw): Use the value-specified color.
* src/format.c (lookup_color, format_color_init,
format_color_shutdown): New routines to use StyleColors instead of
color names.
1998-09-11 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/cell.c (queue_cell, cell_freeze_redraws, cell_thaw_redraws):
......
1998-09-13 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/gnumeric-sheet.c (gnumeric_sheet_realize): Fix: initilaize
the GdkWindow pointer after we have invoked our parent method.
* src/cursors.c: New file. Loads the various cursors used by
Gnumeric.
* src/item-cursor.c (item_cursor_autofill_event): Implement the
cursor growing autofill rules.
1998-09-12 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/workbook.c (workbook_setup_sheets): Dont let the workbooks
take the focus.
(do_focus_sheet): Do focus the current sheet on
page change.
(workbook_setup_signals): Focus the GnumericSheet if no widget has
the focus.
* src/cell.c (cell_draw): Use the value-specified color.
* src/format.c (lookup_color, format_color_init,
format_color_shutdown): New routines to use StyleColors instead of
color names.
1998-09-11 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/cell.c (queue_cell, cell_freeze_redraws, cell_thaw_redraws):
......
1998-09-13 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/gnumeric-sheet.c (gnumeric_sheet_realize): Fix: initilaize
the GdkWindow pointer after we have invoked our parent method.
* src/cursors.c: New file. Loads the various cursors used by
Gnumeric.
* src/item-cursor.c (item_cursor_autofill_event): Implement the
cursor growing autofill rules.
1998-09-12 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/workbook.c (workbook_setup_sheets): Dont let the workbooks
take the focus.
(do_focus_sheet): Do focus the current sheet on
page change.
(workbook_setup_signals): Focus the GnumericSheet if no widget has
the focus.
* src/cell.c (cell_draw): Use the value-specified color.
* src/format.c (lookup_color, format_color_init,
format_color_shutdown): New routines to use StyleColors instead of
color names.
1998-09-11 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/cell.c (queue_cell, cell_freeze_redraws, cell_thaw_redraws):
......
......@@ -20,6 +20,8 @@ GNUMERIC_BASE_SOURCES = \
clipboard.h \
color.c \
color.h \
cursors.c \
cursors.h \
dialog-cell-format.c \
dialog-goto-cell.c \
dialog-insert-cells.c \
......@@ -61,6 +63,8 @@ GNUMERIC_BASE_SOURCES = \
plugin-manager.c \
sheet.c \
sheet.h \
sheet-autofill.c \
sheet-autofill.h \
sheet-object.c \
sheet-object.h \
sheet-view.c \
......
......@@ -174,14 +174,20 @@ cell_set_rendered_text (Cell *cell, char *rendered_text)
void
cell_render_value (Cell *cell)
{
char *color_name;
StyleColor *color;
char *str;
g_return_if_fail (cell != NULL);
g_return_if_fail (cell->value != NULL);
str = format_value (cell->style->format, cell->value, NULL);
if (cell->render_color){
style_color_unref (cell->render_color);
cell->render_color = NULL;
}
str = format_value (cell->style->format, cell->value, &color);
cell->render_color = color;
cell_set_rendered_text (cell, str);
g_free (str);
}
......@@ -299,10 +305,13 @@ cell_destroy (Cell *cell)
expr_tree_unref (cell->parsed_node);
}
string_unref (cell->entered_text);
string_unref (cell->text);
style_destroy (cell->style);
value_release (cell->value);
if (cell->render_color)
style_color_unref (cell->render_color);
string_unref (cell->entered_text);
string_unref (cell->text);
style_destroy (cell->style);
value_release (cell->value);
}
void
......@@ -833,9 +842,12 @@ cell_draw (Cell *cell, void *sv, GdkGC *gc, GdkDrawable *drawable, int x1, int y
if (cell->style->valid_flags & STYLE_BACK_COLOR)
gdk_gc_set_background (gc, &cell->style->back_color->color);
if (cell->style->valid_flags & STYLE_FORE_COLOR)
gdk_gc_set_foreground (gc, &cell->style->fore_color->color);
if (cell->render_color)
gdk_gc_set_foreground (gc, &cell->render_color->color);
else {
if (cell->style->valid_flags & STYLE_FORE_COLOR)
gdk_gc_set_foreground (gc, &cell->style->fore_color->color);
}
/* if a number overflows, do special drawing */
if (width < cell->width && cell_is_number (cell)){
......
......@@ -23,25 +23,27 @@ typedef struct {
typedef struct {
void *sheet;
ColRowInfo *col;
ColRowInfo *row;
void *sheet;
ColRowInfo *col;
ColRowInfo *row;
/* Text as entered by the user */
String *entered_text;
String *entered_text;
/* Type of the content and the actual parsed content */
ExprTree *parsed_node; /* Parse tree with the expression */
Value *value; /* Last value computed */
Style *style;
ExprTree *parsed_node; /* Parse tree with the expression */
Value *value; /* Last value computed */
Style *style; /* The Cell's style */
StyleColor *render_color; /* If a manually entered color has been selected */
/* computed versions of the cell contents */
String *text; /* Text rendered and displayed */
int width; /* Width of text */
int height; /* Height of text */
String *text; /* Text rendered and displayed */
int width; /* Width of text */
int height; /* Height of text */
int flags;
char generation;
int flags;
char generation;
} Cell;
typedef GList CellList;
......
#include <config.h>
#include <gnome.h>
#include "color.h"
#include "cursors.h"
#include "pixmaps.h"
#define GNUMERIC_CURSORS 10
GdkCursor *gnumeric_cursors [GNUMERIC_CURSORS] = { NULL, };
void
cursors_init (void)
{
GdkImlibImage *image;
GdkPixmap *pixmap;
GdkBitmap *bitmap;
image = gdk_imlib_create_image_from_xpm_data (arrow_xpm);
if (!image){
g_warning ("Could not create image\n");
return;
}
gdk_imlib_render (image, image->rgb_width, image->rgb_height);
pixmap = gdk_imlib_move_image (image);
bitmap = gdk_imlib_move_mask (image);
gnumeric_cursors [0] = gdk_cursor_new_from_pixmap (bitmap, bitmap, &gs_white, &gs_black, 1, 1);
gdk_imlib_destroy_image (image);
}
void
cursors_shutdown (void)
{
gdk_cursor_destroy (gnumeric_cursors [0]);
}
#ifndef CURSORS_H
#define CURSORS_H
extern GdkCursor *gnumeric_cursors [];
void cursors_init (void);
void cursors_shutdown (void);
#endif
......@@ -340,7 +340,7 @@ create_number_format_page (GtkWidget *prop_win, CellList *cells)
/* 1.2 Fill the category list */
gtk_clist_freeze (GTK_CLIST (number_cat_list));
for (i = 0; cell_formats [i].name; i++){
char *text [1] = { cell_formats [i].name };
char *text [1] = { _(cell_formats [i].name) };
gtk_clist_append (GTK_CLIST (number_cat_list), text);
}
......
......@@ -340,7 +340,7 @@ create_number_format_page (GtkWidget *prop_win, CellList *cells)
/* 1.2 Fill the category list */
gtk_clist_freeze (GTK_CLIST (number_cat_list));
for (i = 0; cell_formats [i].name; i++){
char *text [1] = { cell_formats [i].name };
char *text [1] = { _(cell_formats [i].name) };
gtk_clist_append (GTK_CLIST (number_cat_list), text);
}
......
......@@ -424,29 +424,58 @@ format_destroy (StyleFormat *format)
format->format_list = NULL;
}
static char *format_colors [] = {
N_("black"),
N_("blue"),
N_("cyan"),
N_("green"),
N_("magenta"),
N_("red"),
N_("white"),
N_("yellow"),
NULL
static struct {
char *name;
StyleColor *color;
} format_colors [] = {
{ N_("black") },
{ N_("blue") },
{ N_("cyan") },
{ N_("green") },
{ N_("magenta") },
{ N_("red") },
{ N_("white") },
{ N_("yellow") },
{ NULL, NULL }
};
static char *
void
format_color_init (void)
{
int i;
for (i = 0; format_colors [i].name; i++){
StyleColor *sc;
GdkColor c;
gdk_color_parse (format_colors [i].name, &c);
sc = style_color_new (c.red, c.green, c.blue);
format_colors [i].color = sc;
}
}
void
format_color_shutdown (void)
{
int i;
for (i = 0; format_colors [i].name; i++)
style_color_unref (format_colors [i].color);
}
static StyleColor *
lookup_color (char *str, char *end)
{
int i;
for (i = 0; format_colors [i]; i++){
int len = strlen (format_colors [i]);
for (i = 0; format_colors [i].name; i++){
int len = strlen (format_colors [i].name);
if ((strncasecmp (format_colors [i], str, len) == 0) ||
(strncasecmp (_(format_colors [i]), str, len) == 0)){
return format_colors [i];
if ((strncasecmp (format_colors [i].name, str, len) == 0) ||
(strncasecmp (_(format_colors [i].name), str, len) == 0)){
style_color_ref (format_colors [i].color);
return format_colors [i].color;
}
}
return NULL;
......@@ -1101,15 +1130,15 @@ check_valid (StyleFormatEntry *entry, Value *value)
}
gchar *
format_value (StyleFormat *format, Value *value, char **color_name)
format_value (StyleFormat *format, Value *value, StyleColor **color)
{
char *v = NULL;
StyleFormatEntry entry;
GList *list;
int is_general = 0;
if (color_name)
*color_name = NULL;
if (color)
*color = NULL;
/* get format */
for (list = format->format_list; list; list = g_list_next (list))
......@@ -1126,8 +1155,8 @@ format_value (StyleFormat *format, Value *value, char **color_name)
char *end = strchr (entry.format, ']');
if (end){
if (color_name)
*color_name = lookup_color (&entry.format [1], end);
if (color)
*color = lookup_color (&entry.format [1], end);
entry.format = end+1;
}
}
......
......@@ -3,6 +3,8 @@
void format_destroy (StyleFormat *format);
void format_compile (StyleFormat *format);
gchar *format_value (StyleFormat *format, Value *value, char **color_name);
gchar *format_value (StyleFormat *format, Value *value, StyleColor **color);
void format_color_init (void);
void format_color_shutdown (void);
#endif
......@@ -15,16 +15,20 @@
#include "gnumeric.h"
#include "gnumeric-sheet.h"
#include "color.h"
#include "cursors.h"
#define CURSOR_COL(gsheet) gsheet->sheet_view->sheet->cursor_col
#define CURSOR_ROW(gsheet) gsheet->sheet_view->sheet->cursor_row
/* Public colors: shared by all of our items in Gnumeric */
GdkColor gs_white, gs_black, gs_light_gray, gs_dark_gray;
static GnomeCanvasClass *sheet_parent_class;
static void stop_cell_selection (GnumericSheet *gsheet);
static void
gnumeric_sheet_destroy (GtkObject *object)
{
......@@ -793,21 +797,25 @@ gnumeric_sheet_pattern_t gnumeric_sheet_patterns [GNUMERIC_SHEET_PATTERNS] = {
{ 0x80, 0x80, 0x80, 0xff, 0x04, 0x04, 0x04, 0xff } },
};
static void
gnumeric_sheet_realize (GtkWidget *widget)
{
GnumericSheet *gsheet = GNUMERIC_SHEET (widget);
GdkWindow *window = widget->window;
GdkWindow *window;
int i;
if (GTK_WIDGET_CLASS (sheet_parent_class)->realize)
(*GTK_WIDGET_CLASS (sheet_parent_class)->realize)(widget);
window = widget->window;
gdk_window_set_back_pixmap (GTK_LAYOUT (widget)->bin_window, NULL, FALSE);
for (i = 0; i < GNUMERIC_SHEET_PATTERNS; i++)
gsheet->patterns [i] = gdk_bitmap_create_from_data (
window, gnumeric_sheet_patterns [i].pattern, 8, 8);
/* gdk_window_set_cursor (window, gnumeric_cursors [0]); */
}
void
......@@ -988,6 +996,15 @@ gnumeric_size_allocate (GtkWidget *widget, GtkAllocation *allocation)
gnumeric_sheet_compute_visible_ranges (GNUMERIC_SHEET (widget));
}
static gint
gnumeric_button_press (GtkWidget *widget, GdkEventButton *event)
{
if (!GTK_WIDGET_HAS_FOCUS (widget))
gtk_widget_grab_focus (widget);
return FALSE;
}
static void
gnumeric_sheet_class_init (GnumericSheetClass *class)
{
......
......@@ -15,16 +15,20 @@
#include "gnumeric.h"
#include "gnumeric-sheet.h"
#include "color.h"
#include "cursors.h"
#define CURSOR_COL(gsheet) gsheet->sheet_view->sheet->cursor_col
#define CURSOR_ROW(gsheet) gsheet->sheet_view->sheet->cursor_row
/* Public colors: shared by all of our items in Gnumeric */
GdkColor gs_white, gs_black, gs_light_gray, gs_dark_gray;
static GnomeCanvasClass *sheet_parent_class;
static void stop_cell_selection (GnumericSheet *gsheet);
static void
gnumeric_sheet_destroy (GtkObject *object)
{
......@@ -793,21 +797,25 @@ gnumeric_sheet_pattern_t gnumeric_sheet_patterns [GNUMERIC_SHEET_PATTERNS] = {
{ 0x80, 0x80, 0x80, 0xff, 0x04, 0x04, 0x04, 0xff } },
};
static void
gnumeric_sheet_realize (GtkWidget *widget)
{
GnumericSheet *gsheet = GNUMERIC_SHEET (widget);
GdkWindow *window = widget->window;
GdkWindow *window;
int i;
if (GTK_WIDGET_CLASS (sheet_parent_class)->realize)
(*GTK_WIDGET_CLASS (sheet_parent_class)->realize)(widget);
window = widget->window;
gdk_window_set_back_pixmap (GTK_LAYOUT (widget)->bin_window, NULL, FALSE);
for (i = 0; i < GNUMERIC_SHEET_PATTERNS; i++)
gsheet->patterns [i] = gdk_bitmap_create_from_data (
window, gnumeric_sheet_patterns [i].pattern, 8, 8);
/* gdk_window_set_cursor (window, gnumeric_cursors [0]); */
}
void
......@@ -988,6 +996,15 @@ gnumeric_size_allocate (GtkWidget *widget, GtkAllocation *allocation)
gnumeric_sheet_compute_visible_ranges (GNUMERIC_SHEET (widget));
}
static gint
gnumeric_button_press (GtkWidget *widget, GdkEventButton *event)
{
if (!GTK_WIDGET_HAS_FOCUS (widget))
gtk_widget_grab_focus (widget);
return FALSE;
}
static void
gnumeric_sheet_class_init (GnumericSheetClass *class)
{
......
......@@ -26,7 +26,7 @@ enum {
ARG_0,
ARG_SHEET, /* The Sheet * argument */
ARG_ITEM_GRID, /* The ItemGrid * argument */
ARG_STYLE /* The style type */
ARG_STYLE, /* The style type */
};
static void
......@@ -365,7 +365,18 @@ item_cursor_translate (GnomeCanvasItem *item, double dx, double dy)
printf ("item_cursor_translate %g, %g\n", dx, dy);
}
#define convert(c,sx,sy,x,y) gnome_canvas_w2c (c,sx,sy,x,y)
static void
item_cursor_setup_auto_fill (ItemCursor *item_cursor, ItemCursor *parent, int x, int y)
{
item_cursor->base_x = x;
item_cursor->base_y = y;
item_cursor->base_cols = parent->end_col - parent->start_col;
item_cursor->base_rows = parent->end_row - parent->start_row;
item_cursor->base_col = parent->start_col;
item_cursor->base_row = parent->start_row;
}
static gint
item_cursor_selection_event (GnomeCanvasItem *item, GdkEvent *event)
......@@ -380,8 +391,8 @@ item_cursor_selection_event (GnomeCanvasItem *item, GdkEvent *event)
GnomeCanvasGroup *group;
int style;
printf ("cursor: got event\n");
convert (canvas, event->button.x, event->button.y, &x, &y);
gnome_canvas_w2c (
canvas, event->button.x, event->button.y, &x, &y);
group = GNOME_CANVAS_GROUP (canvas->root);
......@@ -400,13 +411,16 @@ item_cursor_selection_event (GnomeCanvasItem *item, GdkEvent *event)
"ItemCursor::Grid", item_cursor->item_grid,
"ItemCursor::Style", style,
NULL);
if (style == ITEM_CURSOR_AUTOFILL)
item_cursor_setup_auto_fill (
ITEM_CURSOR (new_item), item_cursor, x, y);
item_cursor_set_bounds (
ITEM_CURSOR (new_item),
item_cursor->start_col, item_cursor->start_row,
item_cursor->end_col, item_cursor->end_row);
printf ("Creating new cursor!\n");
gnome_canvas_update_now (canvas);
gnome_canvas_item_grab (
new_item,
......@@ -561,7 +575,6 @@ item_cursor_drag_event (GnomeCanvasItem *item, GdkEvent *event)
switch (event->type){
case GDK_BUTTON_RELEASE:
printf ("button release\n");
gnome_canvas_item_ungrab (item, event->button.time);
item_cursor_do_drop (item_cursor, event);
gtk_object_destroy (GTK_OBJECT (item));
......@@ -574,7 +587,7 @@ item_cursor_drag_event (GnomeCanvasItem *item, GdkEvent *event)
return TRUE;
case GDK_MOTION_NOTIFY:
convert (canvas, event->button.x, event->button.y, &x, &y);
gnome_canvas_w2c (canvas, event->button.x, event->button.y, &x, &y);
if (x < 0)
x = 0;
if (y < 0)
......@@ -594,12 +607,48 @@ item_cursor_drag_event (GnomeCanvasItem *item, GdkEvent *event)
}
static gint
item_cursor_autofill (GnomeCanvasItem *item, GdkEvent *event)
item_cursor_autofill_event (GnomeCanvasItem *item, GdkEvent *event)
{
GnomeCanvas *canvas = item->canvas;
ItemCursor *item_cursor = ITEM_CURSOR (item);
int col, row, x, y;
switch (event->type){
case GDK_BUTTON_RELEASE:
case GDK_BUTTON_RELEASE: {
Sheet *sheet = item_cursor->sheet;
gnome_canvas_item_ungrab (item, event->button.time);
sheet_autofill (sheet,
item_cursor->base_col, item_cursor->base_row,
item_cursor->base_cols, item_cursor->base_rows,
item_cursor->end_col, item_cursor->end_row);
gtk_object_destroy (GTK_OBJECT (item));
return TRUE;
}
case GDK_MOTION_NOTIFY:
gnome_canvas_w2c (canvas, event->button.x, event->button.y, &x, &y);
col = item_grid_find_col (item_cursor->item_grid, x, NULL);
row = item_grid_find_row (item_cursor->item_grid, y, NULL);
if ((item_cursor->base_x - x) > (item_cursor->base_y - y)){
item_cursor_set_bounds_visibly (
item_cursor,
item_cursor->base_col,