Commit 031ceea8 authored by Jody Goldberg's avatar Jody Goldberg Committed by Jody Goldberg

Use the newly minted Gnome Application Library (GAL)

2000-09-17  Jody Goldberg <jgoldberg@home.com>

	* src/workbook-format-toolbar.c : Use the new Gnome App Libs (GAL)
	  routines.
	* src/workbook-view.c : Ditto.
	* src/workbook.c : Ditto.

	* src/main.c (gnumeric_main) : call e_color_init and e_color_shutdown.

	* src/gnumeric-util.c (gnumeric_create_tooltip) :
	  Rename from color -> e_color.
	* src/style.c (style_color_new) : Ditto.

	* src/gnumeric-sheet.c (gnumeric_sheet_realize) :
	  Rename from cursor -> e_cursor.
	* src/item-cursor.c (item_cursor_set_cursor) : Ditto.
	* src/cell-comment.c (cell_comment_clicked) : Ditto.
	* src/item-grid.c (item_grid_event) : Ditto.
	* src/sheet-object.c : Ditto.

	* src/color.c : Split the utilities into the gal library.

	* src/Makefile.am : Remove cursors.[ch]

	* configure.in : Handle the new Gnome App Lib (GAL)
parent 8259d107
2000-09-17 Jody Goldberg <jgoldberg@home.com>
* src/workbook-format-toolbar.c : Use the new Gnome App Libs (GAL)
routines.
* src/workbook-view.c : Ditto.
* src/workbook.c : Ditto.
* src/main.c (gnumeric_main) : call e_color_init and e_color_shutdown.
* src/gnumeric-util.c (gnumeric_create_tooltip) :
Rename from color -> e_color.
* src/style.c (style_color_new) : Ditto.
* src/gnumeric-sheet.c (gnumeric_sheet_realize) :
Rename from cursor -> e_cursor.
* src/item-cursor.c (item_cursor_set_cursor) : Ditto.
* src/cell-comment.c (cell_comment_clicked) : Ditto.
* src/item-grid.c (item_grid_event) : Ditto.
* src/sheet-object.c : Ditto.
* src/color.c : Split the utilities into the gal library.
* src/Makefile.am : Remove cursors.[ch]
* configure.in : Handle the new Gnome App Lib (GAL)
2000-09-17 Jody Goldberg <jgoldberg@home.com>
* src/dialogs/dialog-graph-guru.c (cb_create_series_from_range) :
......
2000-09-17 Jody Goldberg <jgoldberg@home.com>
* src/workbook-format-toolbar.c : Use the new Gnome App Libs (GAL)
routines.
* src/workbook-view.c : Ditto.
* src/workbook.c : Ditto.
* src/main.c (gnumeric_main) : call e_color_init and e_color_shutdown.
* src/gnumeric-util.c (gnumeric_create_tooltip) :
Rename from color -> e_color.
* src/style.c (style_color_new) : Ditto.
* src/gnumeric-sheet.c (gnumeric_sheet_realize) :
Rename from cursor -> e_cursor.
* src/item-cursor.c (item_cursor_set_cursor) : Ditto.
* src/cell-comment.c (cell_comment_clicked) : Ditto.
* src/item-grid.c (item_grid_event) : Ditto.
* src/sheet-object.c : Ditto.
* src/color.c : Split the utilities into the gal library.
* src/Makefile.am : Remove cursors.[ch]
* configure.in : Handle the new Gnome App Lib (GAL)
2000-09-17 Jody Goldberg <jgoldberg@home.com>
* src/dialogs/dialog-graph-guru.c (cb_create_series_from_range) :
......
2000-09-17 Jody Goldberg <jgoldberg@home.com>
* src/workbook-format-toolbar.c : Use the new Gnome App Libs (GAL)
routines.
* src/workbook-view.c : Ditto.
* src/workbook.c : Ditto.
* src/main.c (gnumeric_main) : call e_color_init and e_color_shutdown.
* src/gnumeric-util.c (gnumeric_create_tooltip) :
Rename from color -> e_color.
* src/style.c (style_color_new) : Ditto.
* src/gnumeric-sheet.c (gnumeric_sheet_realize) :
Rename from cursor -> e_cursor.
* src/item-cursor.c (item_cursor_set_cursor) : Ditto.
* src/cell-comment.c (cell_comment_clicked) : Ditto.
* src/item-grid.c (item_grid_event) : Ditto.
* src/sheet-object.c : Ditto.
* src/color.c : Split the utilities into the gal library.
* src/Makefile.am : Remove cursors.[ch]
* configure.in : Handle the new Gnome App Lib (GAL)
2000-09-17 Jody Goldberg <jgoldberg@home.com>
* src/dialogs/dialog-graph-guru.c (cb_create_series_from_range) :
......
2000-09-17 Jody Goldberg <jgoldberg@home.com>
* src/workbook-format-toolbar.c : Use the new Gnome App Libs (GAL)
routines.
* src/workbook-view.c : Ditto.
* src/workbook.c : Ditto.
* src/main.c (gnumeric_main) : call e_color_init and e_color_shutdown.
* src/gnumeric-util.c (gnumeric_create_tooltip) :
Rename from color -> e_color.
* src/style.c (style_color_new) : Ditto.
* src/gnumeric-sheet.c (gnumeric_sheet_realize) :
Rename from cursor -> e_cursor.
* src/item-cursor.c (item_cursor_set_cursor) : Ditto.
* src/cell-comment.c (cell_comment_clicked) : Ditto.
* src/item-grid.c (item_grid_event) : Ditto.
* src/sheet-object.c : Ditto.
* src/color.c : Split the utilities into the gal library.
* src/Makefile.am : Remove cursors.[ch]
* configure.in : Handle the new Gnome App Lib (GAL)
2000-09-17 Jody Goldberg <jgoldberg@home.com>
* src/dialogs/dialog-graph-guru.c (cb_create_series_from_range) :
......
2000-09-17 Jody Goldberg <jgoldberg@home.com>
* src/workbook-format-toolbar.c : Use the new Gnome App Libs (GAL)
routines.
* src/workbook-view.c : Ditto.
* src/workbook.c : Ditto.
* src/main.c (gnumeric_main) : call e_color_init and e_color_shutdown.
* src/gnumeric-util.c (gnumeric_create_tooltip) :
Rename from color -> e_color.
* src/style.c (style_color_new) : Ditto.
* src/gnumeric-sheet.c (gnumeric_sheet_realize) :
Rename from cursor -> e_cursor.
* src/item-cursor.c (item_cursor_set_cursor) : Ditto.
* src/cell-comment.c (cell_comment_clicked) : Ditto.
* src/item-grid.c (item_grid_event) : Ditto.
* src/sheet-object.c : Ditto.
* src/color.c : Split the utilities into the gal library.
* src/Makefile.am : Remove cursors.[ch]
* configure.in : Handle the new Gnome App Lib (GAL)
2000-09-17 Jody Goldberg <jgoldberg@home.com>
* src/dialogs/dialog-graph-guru.c (cb_create_series_from_range) :
......
2000-09-17 Jody Goldberg <jgoldberg@home.com>
* src/workbook-format-toolbar.c : Use the new Gnome App Libs (GAL)
routines.
* src/workbook-view.c : Ditto.
* src/workbook.c : Ditto.
* src/main.c (gnumeric_main) : call e_color_init and e_color_shutdown.
* src/gnumeric-util.c (gnumeric_create_tooltip) :
Rename from color -> e_color.
* src/style.c (style_color_new) : Ditto.
* src/gnumeric-sheet.c (gnumeric_sheet_realize) :
Rename from cursor -> e_cursor.
* src/item-cursor.c (item_cursor_set_cursor) : Ditto.
* src/cell-comment.c (cell_comment_clicked) : Ditto.
* src/item-grid.c (item_grid_event) : Ditto.
* src/sheet-object.c : Ditto.
* src/color.c : Split the utilities into the gal library.
* src/Makefile.am : Remove cursors.[ch]
* configure.in : Handle the new Gnome App Lib (GAL)
2000-09-17 Jody Goldberg <jgoldberg@home.com>
* src/dialogs/dialog-graph-guru.c (cb_create_series_from_range) :
......
2000-09-17 Jody Goldberg <jgoldberg@home.com>
* src/workbook-format-toolbar.c : Use the new Gnome App Libs (GAL)
routines.
* src/workbook-view.c : Ditto.
* src/workbook.c : Ditto.
* src/main.c (gnumeric_main) : call e_color_init and e_color_shutdown.
* src/gnumeric-util.c (gnumeric_create_tooltip) :
Rename from color -> e_color.
* src/style.c (style_color_new) : Ditto.
* src/gnumeric-sheet.c (gnumeric_sheet_realize) :
Rename from cursor -> e_cursor.
* src/item-cursor.c (item_cursor_set_cursor) : Ditto.
* src/cell-comment.c (cell_comment_clicked) : Ditto.
* src/item-grid.c (item_grid_event) : Ditto.
* src/sheet-object.c : Ditto.
* src/color.c : Split the utilities into the gal library.
* src/Makefile.am : Remove cursors.[ch]
* configure.in : Handle the new Gnome App Lib (GAL)
2000-09-17 Jody Goldberg <jgoldberg@home.com>
* src/dialogs/dialog-graph-guru.c (cb_create_series_from_range) :
......
......@@ -81,8 +81,6 @@ GNUMERIC_BASE_SOURCES = \
complex.h \
complex.c \
corba.h \
cursors.c \
cursors.h \
dates.c \
dates.h \
datetime.c \
......
......@@ -8,7 +8,7 @@
#include "gnumeric.h"
#include "cell.h"
#include "cell-comment.h"
#include "cursors.h"
#include "gal/widgets/e-cursors.h"
#include "sheet-view.h"
#include "gnumeric-sheet.h"
......@@ -92,7 +92,7 @@ cell_comment_clicked (GnomeCanvasItem *item, GdkEvent *event, Cell *cell)
case GDK_ENTER_NOTIFY:
cell->comment->timer_tag = gtk_timeout_add (1000, &cell_popup_comment, cell);
cursor_set_widget (canvas, GNUMERIC_CURSOR_ARROW);
e_cursor_set_widget (canvas, E_CURSOR_ARROW);
break;
case GDK_LEAVE_NOTIFY:
......
......@@ -10,65 +10,28 @@
#include <config.h>
#include <gnome.h>
#include "color.h"
#include <gal/widgets/e-colors.h>
static int color_inited;
static GdkColorContext *gnumeric_color_context;
/* Public colors: shared by all of our items in Gnumeric */
GdkColor gs_white, gs_black, gs_light_gray, gs_dark_gray, gs_red, gs_lavender;
int
color_alloc (gushort red, gushort green, gushort blue)
{
int failed;
if (!color_inited)
color_init ();
return gdk_color_context_get_pixel (gnumeric_color_context,
red, green, blue, &failed);
}
void
color_alloc_gdk (GdkColor *c)
{
int failed;
g_return_if_fail (c != NULL);
c->pixel = gdk_color_context_get_pixel (gnumeric_color_context, c->red, c->green, c->blue, &failed);
}
void
color_alloc_name (const char *name, GdkColor *c)
{
int failed;
g_return_if_fail (name != NULL);
g_return_if_fail (c != NULL);
gdk_color_parse (name, c);
c->pixel = 0;
c->pixel = gdk_color_context_get_pixel (gnumeric_color_context, c->red, c->green, c->blue, &failed);
}
void
color_init (void)
gnumeric_color_init (void)
{
GdkColormap *colormap = gtk_widget_get_default_colormap ();
/* Initialize the color context */
gnumeric_color_context = gdk_color_context_new (
gtk_widget_get_default_visual (), colormap);
e_color_init ();
/* Allocate the default colors */
gdk_color_white (colormap, &gs_white);
gdk_color_black (colormap, &gs_black);
color_alloc_name ("gray78", &gs_light_gray);
color_alloc_name ("gray20", &gs_dark_gray);
color_alloc_name ("red", &gs_red);
color_alloc_name ("lavender",&gs_lavender);
e_color_alloc_name ("gray78", &gs_light_gray);
e_color_alloc_name ("gray20", &gs_dark_gray);
e_color_alloc_name ("red", &gs_red);
e_color_alloc_name ("lavender",&gs_lavender);
color_inited = 1;
}
#ifndef GNUMERIC_COLOR_H
#define GNUMERIC_COLOR_H
void color_init (void);
/* Return the pixel value for the given red, green and blue */
int color_alloc (gushort red, gushort green, gushort blue);
void color_alloc_name (const char *name, GdkColor *color);
void color_alloc_gdk (GdkColor *color);
void gnumeric_color_init (void);
/* Colors used by any GnumericSheet item */
extern GdkColor gs_white, gs_light_gray, gs_dark_gray, gs_black, gs_red, gs_lavender;
......
/*
* cursors.c: cursor handling for Gnumeric
*
* Authors:
* Miguel de Icaza (miguel@gnu.org)
*/
#include <config.h>
#include <gnome.h>
#include "color.h"
#include "cursors.h"
#include "pixmaps/cursor_cross.xpm"
#include "pixmaps/cursor_zoom_in.xpm"
#include "pixmaps/cursor_zoom_out.xpm"
#include "pixmaps/cursor_hand_open.xpm"
#include "pixmaps/cursor_hand_closed.xpm"
#define GDK_INTERNAL_CURSOR -1
typedef struct {
GdkCursor *cursor;
int hot_x, hot_y;
char **xpm;
} CursorDef;
static CursorDef cursors [] = {
{ NULL, 17, 17, cursor_cross_xpm },
{ NULL, GDK_INTERNAL_CURSOR, GDK_CROSSHAIR, NULL },
{ NULL, GDK_INTERNAL_CURSOR, GDK_ARROW, NULL },
{ NULL, GDK_INTERNAL_CURSOR, GDK_FLEUR, NULL },
{ NULL, 24, 24, cursor_zoom_in_xpm },
{ NULL, 24, 24, cursor_zoom_out_xpm },
{ NULL, GDK_INTERNAL_CURSOR, GDK_SB_H_DOUBLE_ARROW, NULL },
{ NULL, GDK_INTERNAL_CURSOR, GDK_SB_V_DOUBLE_ARROW, NULL },
{ NULL, GDK_INTERNAL_CURSOR, GDK_SIZING, NULL },
{ NULL, GDK_INTERNAL_CURSOR, GDK_SIZING, NULL },
{ NULL, GDK_INTERNAL_CURSOR, GDK_HAND2, NULL },
{ NULL, 10, 10, cursor_hand_open_xpm },
{ NULL, 10, 10, cursor_hand_closed_xpm },
{ NULL, 0, 0, NULL }
};
static void
create_bitmap_and_mask_from_xpm (GdkBitmap **bitmap, GdkBitmap **mask, gchar **xpm)
{
int height, width, colors;
char pixmap_buffer [(32 * 32)/8];
char mask_buffer [(32 * 32)/8];
int x, y, pix, yofs;
int transparent_color, black_color;
sscanf (xpm [0], "%d %d %d %d", &height, &width, &colors, &pix);
g_assert (height == 32);
g_assert (width == 32);
g_assert (colors <= 3);
transparent_color = ' ';
black_color = '.';
yofs = colors + 1;
for (y = 0; y < 32; y++){
for (x = 0; x < 32;){
char value = 0, maskv = 0;
for (pix = 0; pix < 8; pix++, x++){
if (xpm [y + yofs][x] != transparent_color){
maskv |= 1 << pix;
/*
* Invert the colours here because it seems
* to workaround a bug the Matrox G100 Xserver?
* We reverse the foreground & background in the next
* routine to compensate.
*/
if (xpm [y + yofs][x] == black_color){
value |= 1 << pix;
}
}
}
pixmap_buffer [(y * 4 + x/8)-1] = value;
mask_buffer [(y * 4 + x/8)-1] = maskv;
}
}
*bitmap = gdk_bitmap_create_from_data (NULL, pixmap_buffer, 32, 32);
*mask = gdk_bitmap_create_from_data (NULL, mask_buffer, 32, 32);
}
void
cursors_init (void)
{
int i;
for (i = 0; cursors [i].hot_x; i++){
GdkBitmap *bitmap, *mask;
if (cursors [i].hot_x < 0)
cursors [i].cursor = gdk_cursor_new (cursors [i].hot_y);
else {
create_bitmap_and_mask_from_xpm (&bitmap, &mask, cursors [i].xpm);
/* The foreground and background colours are reversed.
* See comment above for explanation.
*/
cursors [i].cursor =
gdk_cursor_new_from_pixmap (
bitmap, mask,
&gs_black, &gs_white,
cursors [i].hot_x,
cursors [i].hot_y);
}
}
g_assert (i == GNUMERIC_CURSOR_NUM_CURSORS);
}
void
cursors_shutdown (void)
{
int i;
for (i = 0; cursors [i].hot_x; i++)
gdk_cursor_destroy (cursors [i].cursor);
}
/* Returns a cursor given its type */
GdkCursor *
cursor_get (CursorType type)
{
g_return_val_if_fail (type >= 0 && type < GNUMERIC_CURSOR_NUM_CURSORS, NULL);
return cursors [type].cursor;
}
#ifndef GNUMERIC_CURSORS_H
#define GNUMERIC_CURSORS_H
#include <gdk/gdk.h>
typedef enum {
GNUMERIC_CURSOR_FAT_CROSS,
GNUMERIC_CURSOR_THIN_CROSS,
GNUMERIC_CURSOR_ARROW,
GNUMERIC_CURSOR_MOVE,
GNUMERIC_CURSOR_ZOOM_IN,
GNUMERIC_CURSOR_ZOOM_OUT,
GNUMERIC_CURSOR_SIZE_X,
GNUMERIC_CURSOR_SIZE_Y,
GNUMERIC_CURSOR_SIZE_TL,
GNUMERIC_CURSOR_SIZE_TR,
GNUMERIC_CURSOR_PRESS,
GNUMERIC_CURSOR_HAND_OPEN,
GNUMERIC_CURSOR_HAND_CLOSED,
GNUMERIC_CURSOR_NUM_CURSORS
} CursorType;
void cursors_init (void);
void cursors_shutdown (void);
#define cursor_set(win, c) \
G_STMT_START { \
if (win) \
gdk_window_set_cursor (win, cursor_get (c)); \
} G_STMT_END
#define cursor_set_widget(w, c) \
G_STMT_START { \
if (GTK_WIDGET (w)->window) \
gdk_window_set_cursor (GTK_WIDGET (w)->window, cursor_get (c)); \
} G_STMT_END
GdkCursor *cursor_get (CursorType type);
#endif /* GNUMERIC_CURSORS_H */
/*
* color-group.c : Utility to keep a shered memory of custom and
* current colors between arbitrary widgets
*
* Author:
* Michael Levy (mlevy@genoscope.cns.fr)
*
* (C) 2000 Michael Levy
*/
#include <string.h>
#include "gnumeric-type-util.h"
#include "color-group.h"
#define PARENT_TYPE gtk_object_get_type ()
#define PARENT_CLASS gtk_type_class ( gtk_object_get_type ())
enum {
COLOR_CHANGE,
LAST_SIGNAL
};
struct _ColorGroup {
GtkObject parent;
gchar *name;
GdkColor **color_history; /* custom color history */
GdkColor *current_color ;
gint history_size; /* length of color_history */
gint history_iterator; /* used to cycle through the colors */
};
typedef struct {
GtkObjectClass parent_class;
/* Signals emited by this object */
void (*color_change) (ColorGroup *color_group, GdkColor *color, gboolean custom);
} ColorGroupClass;
static gint color_group_signals [LAST_SIGNAL] = { 0 };
typedef void (*GtkSignal_NONE__POINTER_BOOL) (GtkObject * object,
gpointer arg1,
gboolean arg2,
gpointer user_data);
static void
marshal_NONE__POINTER_BOOL (GtkObject * object,
GtkSignalFunc func,
gpointer func_data,
GtkArg * args)
{
GtkSignal_NONE__POINTER_BOOL rfunc;
rfunc = (GtkSignal_NONE__POINTER_BOOL) func;
(*rfunc) (object,
GTK_VALUE_POINTER (args[0]),
GTK_VALUE_BOOL (args[1]),
func_data);
}
static void color_group_destroy(GtkObject *obj);
static void
color_group_class_init (ColorGroupClass *class)
{
GtkObjectClass *object_class;
object_class = (GtkObjectClass*) class;
object_class->destroy = &color_group_destroy;
color_group_signals[COLOR_CHANGE] =
gtk_signal_new("color_change",
GTK_RUN_LAST,
object_class->type,
GTK_SIGNAL_OFFSET (ColorGroupClass, color_change),
marshal_NONE__POINTER_BOOL,
GTK_TYPE_NONE, 2, GTK_TYPE_POINTER, GTK_TYPE_BOOL);
gtk_object_class_add_signals (object_class, color_group_signals, LAST_SIGNAL);
/* No default handler */
class->color_change = NULL;
}
static void
color_group_init (ColorGroup *cg)
{
cg->name = NULL;
cg->color_history= NULL;
cg->current_color = NULL;
cg->history_size = 0;
cg->history_iterator = 0;
}
GNUMERIC_MAKE_TYPE(color_group,
"ColorGroup",
ColorGroup,
color_group_class_init,
color_group_init,
PARENT_TYPE);
/* Hash table used to ensure unicity in newly created names*/
static GHashTable *group_names = NULL;
static void
initialize_group_names(void)
{
g_assert(group_names == NULL);
group_names = g_hash_table_new ((GHashFunc) g_str_hash, (GCompareFunc) g_str_equal);
}
GtkObject *
color_group_from_name (const gchar * name)
{
gpointer res;
g_assert(group_names);
g_return_val_if_fail(name != NULL, NULL);
res = g_hash_table_lookup(group_names, name);
if(res != NULL)
return GTK_OBJECT(res);
else
return NULL;
}
static gchar *
create_unique_name(void)
{
const gchar *prefix = "__cg_autogen_name__";
static gint latest_suff = 0;
gchar *new_name;
for(;;latest_suff++) {
new_name = g_strdup_printf("%s%i", prefix, latest_suff);
if(color_group_from_name (new_name) == NULL)
return new_name;
else
g_free(new_name);
}
g_assert_not_reached();
}
static void
color_group_destroy(GtkObject *obj)
{
ColorGroup *cg;
g_return_if_fail(obj != NULL);
g_return_if_fail(IS_COLOR_GROUP(obj));
g_assert(group_names != NULL);
cg = COLOR_GROUP(obj);
/* make this name available */
g_hash_table_remove (group_names, cg->name);
g_free (cg->name);
if(cg->color_history != NULL)
g_free(cg->color_history);
cg->color_history = NULL;
if(cg->current_color)
g_free(cg->current_color);
cg->history_size = 0;
cg->history_iterator = 0;
/* call the base class destructor */
if (GTK_OBJECT_CLASS (PARENT_CLASS)->destroy)
(* GTK_OBJECT_CLASS (PARENT_CLASS)->destroy) (obj);
}
/*
get the size of the custom color history
*/
gint
color_group_get_history_size (ColorGroup *cg)
{
g_return_val_if_fail(cg != NULL, 0);
return cg->history_size;
}
/*
Change the size of the custom color history.
*/
void
color_group_set_history_size (ColorGroup *cg, gint size)
{
g_return_if_fail(cg != NULL);
g_return_if_fail(size >= 0);
if(size == 0) {
if(cg->color_history != NULL)
g_free(cg->color_history);
cg->color_history = NULL;
cg->history_size = 0;
cg->history_iterator = 0;
return;
}
cg->color_history = (GdkColor**) g_realloc(cg->color_history,
size * sizeof(GdkColor *));
/* Initialize to NULL */
for (; cg->history_size < size; (cg->history_size)++)
cg->color_history[cg->history_size] = NULL;
/*
Need to do the following in case this function was called to
reduce the size of the historyh
*/
cg->history_size = size;
if(cg->history_iterator >= cg->history_size)
cg->history_iterator = 0;
}
/*
* Create a new color group.
* if name is NULL or a name not currently in use by another group
* then a new group is created and returned. If name was NULL
* then the new group is given a unique name prefixed by "__cg_autogen_name__"
* (thereby insuring namespace separation).
* If name was already used by a group then the reference count is
* incremented and a pointer to the group is returned.
*/
GtkObject *