Commit 1abfce71 authored by Arturo Espinosa's avatar Arturo Espinosa

Add color support, take 1

parent 061a1e74
1998-08-26 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/style.c (style_color_new, style_color_ref,
style_color_unref): New functions. Color for a cell will be kept
as part of the style. Hack note: if valid_flags reports
STYLE_COLOR style->color might be NULL: this means use the default
sheet colors for this cell.
* src/cell.h: Get rid of GdkColor field.
* src/item-grid.c (item_grid_draw_cell): Draw selected cells
smartly. Now we invert the resulting area (this works for my
16-bpp display, have to try the XOR trick tomorrow on a paletted
display).
1998-08-25 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/sheet.c (sheet_row_selection_changed,
......
1998-08-26 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/style.c (style_color_new, style_color_ref,
style_color_unref): New functions. Color for a cell will be kept
as part of the style. Hack note: if valid_flags reports
STYLE_COLOR style->color might be NULL: this means use the default
sheet colors for this cell.
* src/cell.h: Get rid of GdkColor field.
* src/item-grid.c (item_grid_draw_cell): Draw selected cells
smartly. Now we invert the resulting area (this works for my
16-bpp display, have to try the XOR trick tomorrow on a paletted
display).
1998-08-25 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/sheet.c (sheet_row_selection_changed,
......
1998-08-26 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/style.c (style_color_new, style_color_ref,
style_color_unref): New functions. Color for a cell will be kept
as part of the style. Hack note: if valid_flags reports
STYLE_COLOR style->color might be NULL: this means use the default
sheet colors for this cell.
* src/cell.h: Get rid of GdkColor field.
* src/item-grid.c (item_grid_draw_cell): Draw selected cells
smartly. Now we invert the resulting area (this works for my
16-bpp display, have to try the XOR trick tomorrow on a paletted
display).
1998-08-25 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/sheet.c (sheet_row_selection_changed,
......
1998-08-26 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/style.c (style_color_new, style_color_ref,
style_color_unref): New functions. Color for a cell will be kept
as part of the style. Hack note: if valid_flags reports
STYLE_COLOR style->color might be NULL: this means use the default
sheet colors for this cell.
* src/cell.h: Get rid of GdkColor field.
* src/item-grid.c (item_grid_draw_cell): Draw selected cells
smartly. Now we invert the resulting area (this works for my
16-bpp display, have to try the XOR trick tomorrow on a paletted
display).
1998-08-25 Miguel de Icaza <miguel@nuclecu.unam.mx>
* src/sheet.c (sheet_row_selection_changed,
......
......@@ -2,6 +2,18 @@
GNOME Spread Sheet task list
* Split the sheet from the view
Right now the code has a Sheet (which is the repository for
information) and this Sheet has a GnumericSheet inside (which is the
display canvas).
We need to make the Sheet control multiple "views". Say, SheetView
objects, which will in turn include GnumericSheet objects.
Cursor position should be moved from GnumericSheet to Sheet as
well
* Format engine
The format engine needs to support the following format styles:
......
......@@ -4,11 +4,6 @@
typedef unsigned char ColType;
typedef unsigned short RowType;
typedef struct {
int ref_count;
GdkColor color;
} CellColor;
typedef struct {
int pos; /* the column or row number */
......@@ -23,18 +18,6 @@ typedef struct {
void *data;
} ColRowInfo;
typedef enum {
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 {
void *sheet;
ColRowInfo *col;
......@@ -50,7 +33,6 @@ typedef struct {
/* computed versions of the cell contents */
String *text; /* Text rendered and displayed */
GdkColor color; /* color for the displayed text */
int width; /* Width of text */
int height; /* Height of text */
......
......@@ -162,23 +162,27 @@ item_grid_draw_cell (GdkDrawable *drawable, ItemGrid *item_grid,
int x_offset, y_offset, text_base, pixels;
GdkRectangle rect;
int halign;
int cell_is_selected;
#if 0
item_debug_cross (drawable, gc, x1, y1, x1+width, y1+height);
#endif
/* If cell is selected, draw selection */
if (sheet_selection_is_cell_selected (sheet, col, row)){
GdkGC *black_gc = GTK_WIDGET (canvas)->style->black_gc;
cell_is_selected = sheet_selection_is_cell_selected (sheet, col, row);
if (!(gsheet->cursor_col == col && gsheet->cursor_row == row))
gdk_draw_rectangle (drawable, black_gc, TRUE,
x1+1, y1+1, width - 2, height - 2);
}
cell = sheet_cell_get (sheet, col, row);
if (!cell)
/*
* If the cell does not exist, there is little to do: only
* check if we should paint it as a selected cell
*/
if (!cell){
if (cell_is_selected){
GdkGC *black_gc = GTK_WIDGET (canvas)->style->black_gc;
if (!(gsheet->cursor_col == col && gsheet->cursor_row == row))
gdk_draw_rectangle (drawable, black_gc, TRUE,
x1+1, y1+1, width - 2, height - 2);
}
return;
}
/* The offsets where we start drawing the text */
x_offset = y_offset = 0;
......@@ -258,8 +262,9 @@ item_grid_draw_cell (GdkDrawable *drawable, ItemGrid *item_grid,
break;
}
if (cell->flags & CELL_COLOR_IS_SET){
gdk_gc_set_foreground (gc, &cell->color);
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);
......@@ -283,8 +288,10 @@ item_grid_draw_cell (GdkDrawable *drawable, ItemGrid *item_grid,
height - (cell->row->margin_a + cell->row->margin_b));
pixels = 0;
if (!cell->entered_text)
if (!cell->entered_text){
printf ("No entered text in cell %d,%d\n", cell->col->pos, cell->row->pos);
return;
}
do {
char *text;
......@@ -298,6 +305,18 @@ item_grid_draw_cell (GdkDrawable *drawable, ItemGrid *item_grid,
pixels += cell->width;
} while (style->halign == HALIGN_FILL &&
pixels < cell->col->pixels);
if (cell_is_selected){
if (gsheet->cursor_col == col && gsheet->cursor_row == row)
return;
gdk_gc_set_function (gc, GDK_INVERT);
gdk_gc_set_foreground (gc, &gs_black);
gdk_draw_rectangle (drawable, gc, TRUE,
x1 + 1,
y1 + 1,
width - 1, height - 1);
}
}
static void
......
......@@ -1268,8 +1268,9 @@ sheet_selection_is_cell_selected (Sheet *sheet, int col, int row)
SheetSelection *ss = list->data;
if ((ss->start_col <= col) && (col <= ss->end_col) &&
(ss->start_row <= row) && (row <= ss->end_row))
(ss->start_row <= row) && (row <= ss->end_row)){
return 1;
}
}
return 0;
}
......
......@@ -13,6 +13,7 @@
static GHashTable *style_format_hash;
static GHashTable *style_font_hash;
static GHashTable *style_border_hash;
static GHashTable *style_color_hash;
StyleFormat *
style_format_new (char *name)
......@@ -169,6 +170,38 @@ style_border_new_plain (void)
NULL, NULL, NULL, NULL);
}
StyleColor *
style_color_new (char *fore, char *back)
{
g_warning ("Style color not yet implemented\n");
g_warning ("Remember to deallocate colors\n");
return NULL;
}
void
style_color_ref (StyleColor *sc)
{
g_return_if_fail (sc != NULL);
sc->ref_count++;
}
void
style_color_unref (StyleColor *sc)
{
g_return_if_fail (sc != NULL);
g_return_if_fail (sc->ref_count > 0);
sc->ref_count--;
if (sc->ref_count != 0)
return;
g_warning ("Need to deallocate colors\n");
g_hash_table_remove (style_color_hash, sc);
g_free (sc);
}
Style *
style_new (void)
{
......@@ -181,7 +214,7 @@ style_new (void)
style->format = style_format_new ("General");
style->font = style_font_new ("-adobe-helvetica-medium-r-normal--*-120-*-*-*-*-*-*", 14);
style->border = style_border_new_plain ();
style->color = NULL;
style->halign = HALIGN_GENERAL;
style->valign = VALIGN_CENTER;
style->orientation = ORIENT_HORIZ;
......@@ -214,6 +247,10 @@ style_destroy (Style *style)
if (style->valid_flags & STYLE_BORDER)
style_border_unref (style->border);
if (style->valid_flags & STYLE_COLOR)
if (style->color)
style_color_unref (style->color);
g_free (style);
}
......@@ -245,6 +282,12 @@ style_duplicate (Style *original)
else
style->border = NULL;
if (style->valid_flags & STYLE_COLOR)
if (style->color)
style_color_ref (style->color);
else
style->color = NULL;
return style;
}
......@@ -308,12 +351,34 @@ border_hash (gconstpointer v)
return (k->left << 12) | (k->right << 8) | (k->top << 4) | (k->bottom);
}
static gint
color_equal (gconstpointer v, gconstpointer v2)
{
StyleColor *k1 = (StyleColor *) v;
StyleColor *k2 = (StyleColor *) v2;
if ((k1->foreground.pixel == k2->foreground.pixel) &&
(k1->background.pixel == k2->background.pixel))
return 1;
return 0;
}
static guint
color_hash (gconstpointer v)
{
StyleColor *k = (StyleColor *)v;
return k->foreground.pixel + k->background.pixel;
}
void
style_init (void)
{
style_format_hash = g_hash_table_new (g_str_hash, g_str_equal);
style_font_hash = g_hash_table_new (font_hash, font_equal);
style_border_hash = g_hash_table_new (border_hash, border_equal);
style_color_hash = g_hash_table_new (color_hash, color_equal);
}
void
......@@ -347,4 +412,12 @@ style_merge_to (Style *target, Style *source)
target->valign = source->valign;
target->orientation = source->orientation;
}
if (!(target->valid_flags & STYLE_COLOR))
if (source->valid_flags & STYLE_COLOR){
target->valid_flags |= STYLE_COLOR;
target->color = source->color;
if (target->color)
style_color_ref (target->color);
}
}
......@@ -50,6 +50,12 @@ typedef struct {
int pattern;
} StyleShade;
typedef struct {
int ref_count;
GdkColor foreground;
GdkColor background;
} StyleColor;
/* Alignment definitions */
typedef enum {
HALIGN_GENERAL = 1,
......@@ -79,16 +85,19 @@ typedef enum {
#define STYLE_BORDER 4
#define STYLE_SHADING 8
#define STYLE_ALIGN 16
#define STYLE_COLOR 32
/* Define all of the styles we actually know about */
#define STYLE_ALL (STYLE_FORMAT | STYLE_FONT | STYLE_BORDER | STYLE_ALIGN)
#define STYLE_ALL (STYLE_FORMAT | STYLE_FONT | STYLE_BORDER | STYLE_ALIGN | STYLE_COLOR)
typedef struct {
StyleFormat *format;
StyleFont *font;
StyleBorder *border;
StyleShade *shading;
StyleColor *color; /* it might be null even if STYLE_COLOR is set
* that means use the default spreadsheet colors.
*/
unsigned int halign:6;
unsigned int valign:4;
unsigned int orientation:4;
......@@ -110,6 +119,10 @@ StyleFont *style_font_new (char *font_name, int units);
void style_font_ref (StyleFont *sf);
void style_font_unref (StyleFont *sf);
StyleColor *style_color_new (char *fore, char *back);
void style_color_ref (StyleColor *sc);
void style_color_unref (StyleColor *sc);
StyleBorder *style_border_new_plain (void);
void style_border_ref (StyleBorder *sb);
void style_border_unref (StyleBorder *sb);
......
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