From: Jim Evins Date: Sun, 12 Oct 2008 05:40:18 +0000 (+0000) Subject: 2008-10-12 Jim Evins X-Git-Tag: glabels-2_3_0~256 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=7ef35253c18443a10f4f38d53143341c09c06015;p=glabels 2008-10-12 Jim Evins * src/mygal/Makefile.am: * src/mygal/color-group.c: * src/mygal/color-group.h: * src/mygal/color-palette.c: * src/mygal/color-palette.h: * src/mygal/e-colors.c: * src/mygal/e-colors.h: * src/mygal/e-marshal.list: * src/mygal/e-util.h: * src/mygal/mygal-combo-box.c: * src/mygal/mygal-combo-box.h: * src/mygal/widget-color-combo.c: * src/mygal/widget-color-combo.h: * AUTHORS: * configure.in: Deleted mygal. * src/color-combo.c: * src/color-combo.h: * src/color-combo-color-menu-item.c: * src/color-combo-color-menu-item.h: * src/color-combo-history.c: * src/color-combo-history.h: * src/color-combo-menu.c: * src/color-combo-menu.h: * src/marshal.list: * src/util.c: * src/util.h: * src/Makefile.am: Created new glColorCombo widget. * src/object-editor-bc-page.c: * src/object-editor-edit-page.c: * src/object-editor-fill-page.c: * src/object-editor-line-page.c: * src/object-editor-shadow-page.c: * src/object-editor-text-page.c: * src/object-editor.c: * src/prefs-dialog.c: * src/ui-property-bar.c: Replaced use of mygal color combo with new glColorCombo widget. git-svn-id: https://glabels.svn.sourceforge.net/svnroot/glabels/trunk@784 f5e0f49d-192f-0410-a22d-a8d8700d0965 --- diff --git a/glabels2/AUTHORS b/glabels2/AUTHORS index 425cccb0..4dfad6c3 100644 --- a/glabels2/AUTHORS +++ b/glabels2/AUTHORS @@ -15,13 +15,6 @@ information. The author: - The iec16022 library provides encoding for 2D barcodes. See iec16022-0.2.1/README for more information. -- Glabels includes modified versions of several widgets from the GAL library. -These are copyright: - - * Copyright 2000, 2001, Ximian, Inc. - * Copyright 2000, Michael Levy - * Copyright 2001, Almer S. Tigelaar - - Glabels includes a modified version of the gimpchainbutton widget from the gimp, as well as several stock icons from the gimp's default theme. These are copyright: diff --git a/glabels2/ChangeLog b/glabels2/ChangeLog index 15e7f152..c4749fd1 100644 --- a/glabels2/ChangeLog +++ b/glabels2/ChangeLog @@ -1,3 +1,45 @@ +2008-10-12 Jim Evins + + * src/mygal/Makefile.am: + * src/mygal/color-group.c: + * src/mygal/color-group.h: + * src/mygal/color-palette.c: + * src/mygal/color-palette.h: + * src/mygal/e-colors.c: + * src/mygal/e-colors.h: + * src/mygal/e-marshal.list: + * src/mygal/e-util.h: + * src/mygal/mygal-combo-box.c: + * src/mygal/mygal-combo-box.h: + * src/mygal/widget-color-combo.c: + * src/mygal/widget-color-combo.h: + * AUTHORS: + * configure.in: + Deleted mygal. + * src/color-combo.c: + * src/color-combo.h: + * src/color-combo-color-menu-item.c: + * src/color-combo-color-menu-item.h: + * src/color-combo-history.c: + * src/color-combo-history.h: + * src/color-combo-menu.c: + * src/color-combo-menu.h: + * src/marshal.list: + * src/util.c: + * src/util.h: + * src/Makefile.am: + Created new glColorCombo widget. + * src/object-editor-bc-page.c: + * src/object-editor-edit-page.c: + * src/object-editor-fill-page.c: + * src/object-editor-line-page.c: + * src/object-editor-shadow-page.c: + * src/object-editor-text-page.c: + * src/object-editor.c: + * src/prefs-dialog.c: + * src/ui-property-bar.c: + Replaced use of mygal color combo with new glColorCombo widget. + 2008-08-29 Jim Evins * src/file.c: (gl_file_open), (gl_file_save_as): diff --git a/glabels2/configure.in b/glabels2/configure.in index dbd1468a..24efed30 100644 --- a/glabels2/configure.in +++ b/glabels2/configure.in @@ -115,18 +115,6 @@ AC_SUBST(LIBGLABELS_CFLAGS) AC_SUBST(LIBGLABELS_LIBS) -dnl --------------------------------------------------------------------------- -dnl - MYGAL prerequisites -dnl --------------------------------------------------------------------------- -PKG_CHECK_MODULES(MYGAL, \ -gtk+-2.0 >= $GTK_REQUIRED \ -libgnomeui-2.0 >= $LIBGNOMEUI_REQUIRED \ -) - -AC_SUBST(MYGAL_CFLAGS) -AC_SUBST(MYGAL_LIBS) - - dnl --------------------------------------------------------------------------- dnl - Enable deprecation testing dnl --------------------------------------------------------------------------- @@ -191,7 +179,6 @@ libglabels/libglabels.pc src/Makefile src/pixmaps/Makefile src/stock-pixmaps/Makefile -src/mygal/Makefile data/Makefile data/templates/Makefile data/pixmaps/Makefile diff --git a/glabels2/src/Makefile.am b/glabels2/src/Makefile.am index 41158b67..e866d5f6 100644 --- a/glabels2/src/Makefile.am +++ b/glabels2/src/Makefile.am @@ -1,7 +1,7 @@ LIB_BARCODE_DIR = ../barcode-0.98 LIB_IEC16022_DIR = ../iec16022-0.2.1 -SUBDIRS= pixmaps stock-pixmaps mygal +SUBDIRS= pixmaps stock-pixmaps bin_PROGRAMS = glabels glabels-batch @@ -27,7 +27,6 @@ glabels_LDFLAGS = -export-dynamic glabels_LDADD = \ $(GLABELS_LIBS) \ ../libglabels/libglabels.la \ - mygal/libmygal.la \ $(LIB_BARCODE_DIR)/libbarcode.la \ $(LIB_IEC16022_DIR)/libiec16022.la @@ -176,6 +175,14 @@ glabels_SOURCES = \ wdgt-chain-button.h \ wdgt-merge-menu.c \ wdgt-merge-menu.h \ + color-combo.c \ + color-combo.h \ + color-combo-menu.c \ + color-combo-menu.h \ + color-combo-color-menu-item.c \ + color-combo-color-menu-item.h \ + color-combo-history.c \ + color-combo-history.h \ cairo-label-path.c \ cairo-label-path.h \ cairo-markup-path.c \ diff --git a/glabels2/src/color-combo-color-menu-item.c b/glabels2/src/color-combo-color-menu-item.c new file mode 100644 index 00000000..a98748b3 --- /dev/null +++ b/glabels2/src/color-combo-color-menu-item.c @@ -0,0 +1,222 @@ +/* + * color-combo-color-menu-item.c + * Copyright (C) 2008 Jim Evins . + * + * This file is part of gLabels. + * + * gLabels is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * gLabels is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with gLabels. If not, see . + */ + +#include + +#include "color-combo-color-menu-item.h" + +#include "marshal.h" +#include +#include +#include +#include +#include +#include "color.h" + + +/*===========================================*/ +/* Private macros and constants. */ +/*===========================================*/ + + +/*===========================================*/ +/* Private types */ +/*===========================================*/ + +struct _glColorComboColorMenuItemPrivate { + + gint id; +}; + + +/*===========================================*/ +/* Private globals */ +/*===========================================*/ + + +/*===========================================*/ +/* Local function prototypes */ +/*===========================================*/ + +static void gl_color_combo_color_menu_item_finalize (GObject *object); + +static GdkPixbuf * +create_color_pixbuf (gdouble w, + gdouble h, + guint color); + +/****************************************************************************/ +/* Boilerplate Object stuff. */ +/****************************************************************************/ +G_DEFINE_TYPE (glColorComboColorMenuItem, gl_color_combo_color_menu_item, GTK_TYPE_MENU_ITEM); + + +/*****************************************************************************/ +/* Class Init Function. */ +/*****************************************************************************/ +static void +gl_color_combo_color_menu_item_class_init (glColorComboColorMenuItemClass *class) +{ + GObjectClass *gobject_class = G_OBJECT_CLASS (class); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class); + + gl_color_combo_color_menu_item_parent_class = g_type_class_peek_parent (class); + + gobject_class->finalize = gl_color_combo_color_menu_item_finalize; +} + + +/*****************************************************************************/ +/* Object Instance Init Function. */ +/*****************************************************************************/ +static void +gl_color_combo_color_menu_item_init (glColorComboColorMenuItem *this) +{ + this->priv = g_new0 (glColorComboColorMenuItemPrivate, 1); +} + + +/*****************************************************************************/ +/* Finalize Method. */ +/*****************************************************************************/ +static void +gl_color_combo_color_menu_item_finalize (GObject *object) +{ + glColorComboColorMenuItem *this = GL_COLOR_COMBO_COLOR_MENU_ITEM (object); + + g_return_if_fail (object != NULL); + g_return_if_fail (GL_IS_COLOR_COMBO_COLOR_MENU_ITEM (object)); + + g_free (this->priv); + + G_OBJECT_CLASS (gl_color_combo_color_menu_item_parent_class)->finalize (object); +} + + +/*****************************************************************************/ +/** New Object Generator. */ +/*****************************************************************************/ +GtkWidget * +gl_color_combo_color_menu_item_new (gint id, + guint color, + const gchar *tip) +{ + glColorComboColorMenuItem *this; + GdkPixbuf *pixbuf; + + this = g_object_new (GL_TYPE_COLOR_COMBO_COLOR_MENU_ITEM, NULL); + + this->priv->id = id; + + pixbuf = create_color_pixbuf (16, 16, color); + gtk_container_add (GTK_CONTAINER (this), + gtk_image_new_from_pixbuf (pixbuf)); + + gtk_widget_set_tooltip_text (GTK_WIDGET (this), tip); + + return GTK_WIDGET (this); +} + + +/*****************************************************************************/ +/* Set color. */ +/*****************************************************************************/ +void +gl_color_combo_color_menu_item_set_color(glColorComboColorMenuItem *this, + gint id, + guint color, + const gchar *tip) +{ + GdkPixbuf *pixbuf; + + this->priv->id = id; + + pixbuf = create_color_pixbuf (16, 16, color); + gtk_image_set_from_pixbuf (GTK_IMAGE (gtk_bin_get_child (GTK_BIN (this))), + pixbuf); + + gtk_widget_set_tooltip_text (GTK_WIDGET (this), tip); + } + + +/*****************************************************************************/ +/* Create new pixbuf with color preview. */ +/*****************************************************************************/ +static GdkPixbuf * +create_color_pixbuf (gdouble w, + gdouble h, + guint color) +{ + cairo_surface_t *surface; + cairo_t *cr; + GdkPixbuf *pixbuf; + + surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, w, h); + + cr = cairo_create (surface); + + cairo_set_antialias (cr, CAIRO_ANTIALIAS_NONE); + + cairo_save (cr); + cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR); + cairo_paint (cr); + cairo_restore (cr); + + cairo_rectangle( cr, 2, 2, w-3, h-3 ); + + cairo_set_source_rgba (cr, + GL_COLOR_F_RED (color), + GL_COLOR_F_GREEN (color), + GL_COLOR_F_BLUE (color), + GL_COLOR_F_ALPHA (color)); + cairo_fill_preserve( cr ); + + cairo_set_line_width (cr, 1.0); + cairo_set_source_rgb (cr, 0.5, 0.5, 0.5); + cairo_stroke (cr); + + cairo_destroy( cr ); + + pixbuf = gl_util_cairo_convert_to_pixbuf (surface); + cairo_surface_destroy (surface); + + return pixbuf; +} + + +/*****************************************************************************/ +/* Get id. */ +/*****************************************************************************/ +gint +gl_color_combo_color_menu_item_get_id (glColorComboColorMenuItem *this) +{ + return this->priv->id; +} + + + +/* + * Local Variables: -- emacs + * mode: C -- emacs + * c-basic-offset: 8 -- emacs + * tab-width: 8 -- emacs + * indent-tabs-mode: nil -- emacs + * End: -- emacs + */ diff --git a/glabels2/src/color-combo-color-menu-item.h b/glabels2/src/color-combo-color-menu-item.h new file mode 100644 index 00000000..cb5daa46 --- /dev/null +++ b/glabels2/src/color-combo-color-menu-item.h @@ -0,0 +1,82 @@ +/* + * color-combo-color-menu-item.h + * Copyright (C) 2008 Jim Evins . + * + * This file is part of gLabels. + * + * gLabels is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * gLabels is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with gLabels. If not, see . + */ + +#ifndef __COLOR_COMBO_COLOR_MENU_ITEM_H__ +#define __COLOR_COMBO_COLOR_MENU_ITEM_H__ + + +#include + + +G_BEGIN_DECLS + +#define GL_TYPE_COLOR_COMBO_COLOR_MENU_ITEM (gl_color_combo_color_menu_item_get_type ()) +#define GL_COLOR_COMBO_COLOR_MENU_ITEM(obj) \ + (GTK_CHECK_CAST((obj), GL_TYPE_COLOR_COMBO_COLOR_MENU_ITEM, glColorComboColorMenuItem )) +#define GL_COLOR_COMBO_COLOR_MENU_ITEM_CLASS(klass) \ + (GTK_CHECK_CLASS_CAST ((klass), GL_TYPE_COLOR_COMBO_COLOR_MENU_ITEM, glColorComboColorMenuItemClass)) +#define GL_IS_COLOR_COMBO_COLOR_MENU_ITEM(obj) \ + (GTK_CHECK_TYPE ((obj), GL_TYPE_COLOR_COMBO_COLOR_MENU_ITEM)) +#define GL_IS_COLOR_COMBO_COLOR_MENU_ITEM_CLASS(klass) \ + (GTK_CHECK_CLASS_TYPE ((klass), GL_TYPE_COLOR_COMBO_COLOR_MENU_ITEM)) + +typedef struct _glColorComboColorMenuItem glColorComboColorMenuItem; +typedef struct _glColorComboColorMenuItemPrivate glColorComboColorMenuItemPrivate; +typedef struct _glColorComboColorMenuItemClass glColorComboColorMenuItemClass; + +struct _glColorComboColorMenuItem { + GtkMenuItem parent_widget; + + glColorComboColorMenuItemPrivate *priv; +}; + +struct _glColorComboColorMenuItemClass { + GtkMenuItemClass parent_class; +}; + + +GType gl_color_combo_color_menu_item_get_type (void) G_GNUC_CONST; + +GtkWidget *gl_color_combo_color_menu_item_new (gint id, + guint color, + const gchar *tip); + +gint gl_color_combo_color_menu_item_get_id (glColorComboColorMenuItem *this); + +void gl_color_combo_color_menu_item_set_color(glColorComboColorMenuItem *this, + gint id, + guint color, + const gchar *tip); + + +G_END_DECLS + +#endif /* __COLOR_COMBO_COLOR_MENU_ITEM_H__ */ + + + +/* + * Local Variables: -- emacs + * mode: C -- emacs + * c-basic-offset: 8 -- emacs + * tab-width: 8 -- emacs + * indent-tabs-mode: nil -- emacs + * End: -- emacs + */ diff --git a/glabels2/src/color-combo-history.c b/glabels2/src/color-combo-history.c new file mode 100644 index 00000000..fa62c0d8 --- /dev/null +++ b/glabels2/src/color-combo-history.c @@ -0,0 +1,183 @@ +/* + * color-combo-history.c + * Copyright (C) 2008 Jim Evins . + * + * This file is part of gLabels. + * + * gLabels is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * gLabels is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with gLabels. If not, see . + */ + +#include + + +#include "color-combo-history.h" + +#include "color.h" + + +/*========================================================*/ +/* Private types. */ +/*========================================================*/ + +/** GL_COLOR_COMBO_HISTORY Private fields */ +struct _glColorComboHistoryPrivate { + + guint max_n; + + guint n; + guint *color; +}; + + +/*========================================================*/ +/* Private globals. */ +/*========================================================*/ + + +/*========================================================*/ +/* Private function prototypes. */ +/*========================================================*/ + +static void gl_color_combo_history_finalize (GObject *object); + + +/*****************************************************************************/ +/* Object infrastructure. */ +/*****************************************************************************/ +G_DEFINE_TYPE (glColorComboHistory, gl_color_combo_history, G_TYPE_OBJECT); + + +/*****************************************************************************/ +/* Class Init Function. */ +/*****************************************************************************/ +static void +gl_color_combo_history_class_init (glColorComboHistoryClass *class) +{ + GObjectClass *gobject_class = (GObjectClass *) class; + glColorComboHistoryClass *object_class = (glColorComboHistoryClass *) class; + + gl_color_combo_history_parent_class = g_type_class_peek_parent (class); + + gobject_class->finalize = gl_color_combo_history_finalize; +} + + +/*****************************************************************************/ +/* Object Instance Init Function. */ +/*****************************************************************************/ +static void +gl_color_combo_history_init (glColorComboHistory *this) +{ + this->priv = g_new0 (glColorComboHistoryPrivate, 1); +} + + +/*****************************************************************************/ +/* Finalize Method. */ +/*****************************************************************************/ +static void +gl_color_combo_history_finalize (GObject *object) +{ + glColorComboHistory *this; + + g_return_if_fail (object && IS_GL_COLOR_COMBO_HISTORY (object)); + this = GL_COLOR_COMBO_HISTORY (object); + + g_free (this->priv->color); + g_free (this->priv); + + G_OBJECT_CLASS (gl_color_combo_history_parent_class)->finalize (object); +} + + +/*****************************************************************************/ +/** New Object Generator. */ +/*****************************************************************************/ +glColorComboHistory * +gl_color_combo_history_new (guint n) +{ + glColorComboHistory *this; + + this = g_object_new (TYPE_GL_COLOR_COMBO_HISTORY, NULL); + + this->priv->max_n = n; + this->priv->n = 0; + if (n > 0) + { + this->priv->color = g_new0 (guint, n); + } + + return this; +} + + +/*****************************************************************************/ +/* Add color to history. */ +/*****************************************************************************/ +void +gl_color_combo_history_add_color (glColorComboHistory *this, + guint color) +{ + guint i; + + /* + * First check for duplicate color. + */ + for ( i=0; i < this->priv->n; i++ ) + { + if ( this->priv->color[i] == color ) + { + return; + } + } + + /* + * Simple case. + */ + if ( this->priv->n < this->priv->max_n ) + { + this->priv->color[ this->priv->n ] = color; + this->priv->n++; + + return; + } + + /* Move colors down, dropping oldest. */ + for ( i=0; i < (this->priv->n - 1); i++ ) + { + this->priv->color[i] = this->priv->color[i+1]; + } + this->priv->color[ this->priv->n - 1 ] = color; +} + +/*****************************************************************************/ +/* Get color. */ +/*****************************************************************************/ +guint +gl_color_combo_history_get_color (glColorComboHistory *this, + guint i) +{ + return this->priv->color[i]; +} + + + +/* + * Local Variables: -- emacs + * mode: C -- emacs + * c-basic-offset: 8 -- emacs + * tab-width: 8 -- emacs + * indent-tabs-mode: nil -- emacs + * End: -- emacs + */ diff --git a/glabels2/src/color-combo-history.h b/glabels2/src/color-combo-history.h new file mode 100644 index 00000000..a5439a39 --- /dev/null +++ b/glabels2/src/color-combo-history.h @@ -0,0 +1,82 @@ +/* + * color-combo-history.h + * Copyright (C) 2008 Jim Evins . + * + * This file is part of gLabels. + * + * gLabels is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * gLabels is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with gLabels. If not, see . + */ + +#ifndef __GL_COLOR_COMBO_HISTORY_H__ +#define __GL_COLOR_COMBO_HISTORY_H__ + + +#include + + +G_BEGIN_DECLS + +/* Utility Macros */ +#define TYPE_GL_COLOR_COMBO_HISTORY (gl_color_combo_history_get_type ()) +#define GL_COLOR_COMBO_HISTORY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_GL_COLOR_COMBO_HISTORY, glColorComboHistory)) +#define GL_COLOR_COMBO_HISTORY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_GL_COLOR_COMBO_HISTORY, glColorComboHistoryClass)) +#define IS_GL_COLOR_COMBO_HISTORY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_GL_COLOR_COMBO_HISTORY)) +#define IS_GL_COLOR_COMBO_HISTORY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_GL_COLOR_COMBO_HISTORY)) +#define GL_COLOR_COMBO_HISTORY_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS ((object), TYPE_GL_COLOR_COMBO_HISTORY, glColorComboHistoryClass)) + + +/* Type definitions */ +typedef struct _glColorComboHistory glColorComboHistory; +typedef struct _glColorComboHistoryPrivate glColorComboHistoryPrivate; +typedef struct _glColorComboHistoryClass glColorComboHistoryClass; + + +/** GL_COLOR_COMBO_HISTORY Object */ +struct _glColorComboHistory { + GObject parent; + + glColorComboHistoryPrivate *priv; +}; + +/** GL_COLOR_COMBO_HISTORY Class */ +struct _glColorComboHistoryClass { + GObjectClass parent_class; +}; + + +GType gl_color_combo_history_get_type (void) G_GNUC_CONST; + +glColorComboHistory *gl_color_combo_history_new (guint n); + +void gl_color_combo_history_add_color (glColorComboHistory *this, + guint color); + +guint gl_color_combo_history_get_color (glColorComboHistory *this, + guint i); + + +G_END_DECLS + +#endif /* __GL_COLOR_COMBO_HISTORY_H__ */ + + + +/* + * Local Variables: -- emacs + * mode: C -- emacs + * c-basic-offset: 8 -- emacs + * tab-width: 8 -- emacs + * indent-tabs-mode: nil -- emacs + * End: -- emacs + */ diff --git a/glabels2/src/color-combo-menu.c b/glabels2/src/color-combo-menu.c new file mode 100644 index 00000000..c3425273 --- /dev/null +++ b/glabels2/src/color-combo-menu.c @@ -0,0 +1,453 @@ +/* + * color-combo-menu.c + * Copyright (C) 2008 Jim Evins . + * + * This file is part of gLabels. + * + * gLabels is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * gLabels is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with gLabels. If not, see . + */ + +#include + +#include "color-combo-menu.h" + +#include "marshal.h" +#include +#include +#include +#include +#include +#include +#include "color-combo-color-menu-item.h" +#include "color-combo-history.h" +#include "color.h" + + +/*===========================================*/ +/* Private macros and constants. */ +/*===========================================*/ + +#define PALETTE_COLS 7 +#define PALETTE_ROWS (G_N_ELEMENTS(color_table)/PALETTE_COLS + (G_N_ELEMENTS(color_table)%PALETTE_COLS ? 1 : 0)) + +#define ROW_DEFAULT (0) +#define ROW_SEP_1 (ROW_DEFAULT + 1) +#define ROW_PALETTE (ROW_SEP_1 + 1) +#define ROW_SEP_2 (ROW_PALETTE + PALETTE_ROWS) +#define ROW_HISTORY (ROW_SEP_2 + 1) +#define ROW_SEP_3 (ROW_HISTORY + 1) +#define ROW_CUSTOM (ROW_SEP_3 + 1) + +/*===========================================*/ +/* Private types */ +/*===========================================*/ + +struct _glColorComboMenuPrivate { + + GtkWidget *default_menu_item; + GtkWidget *custom_menu_item; + + GtkWidget *history_menu_item[PALETTE_COLS]; + + guint color; +}; + +enum { + COLOR_CHANGED, + LAST_SIGNAL +}; + +typedef struct { + guint color; + gchar *name; +} ColorTableEntry; + + +/*===========================================*/ +/* Private globals */ +/*===========================================*/ + +static guint signals[LAST_SIGNAL] = {0}; + +static ColorTableEntry color_table[] = +{ + + { GL_COLOR (139, 0, 0), N_("Dark Red") }, + { GL_COLOR (165, 42, 42), N_("Brown") }, + { GL_COLOR (205, 149, 12), N_("Dark Goldenrod") }, + { GL_COLOR ( 0, 100, 0), N_("Dark Green") }, + { GL_COLOR ( 0, 139, 139), N_("Dark Cyan") }, + { GL_COLOR ( 0, 0, 128), N_("Navy Blue") }, + { GL_COLOR (148, 0, 211), N_("Dark Violet") }, + + { GL_COLOR (255, 0, 0), N_("Red") }, + { GL_COLOR (255, 165, 0), N_("Orange") }, + { GL_COLOR (205, 205, 0), N_("Dark Yellow") }, + { GL_COLOR ( 0, 205, 0), N_("Medium green") }, + { GL_COLOR ( 64, 224, 208), N_("Turquoise") }, + { GL_COLOR ( 0, 0, 255), N_("Blue") }, + { GL_COLOR (160, 32, 240), N_("Purple") }, + + { GL_COLOR (250, 128, 114), N_("Salmon") }, + { GL_COLOR (255, 215, 0), N_("Gold") }, + { GL_COLOR (255, 255, 0), N_("Yellow") }, + { GL_COLOR ( 0, 255, 0), N_("Green") }, + { GL_COLOR ( 0, 255, 255), N_("Cyan") }, + { GL_COLOR (135, 206, 235), N_("SkyBlue") }, + { GL_COLOR (238, 130, 238), N_("Violet") }, + + { GL_COLOR (255, 192, 203), N_("Pink") }, + { GL_COLOR (255, 246, 143), N_("Khaki") }, + { GL_COLOR (255, 255, 224), N_("Light Yellow") }, + { GL_COLOR (144, 238, 144), N_("Light Green") }, + { GL_COLOR (224, 255, 255), N_("Light Cyan") }, + { GL_COLOR (198, 226, 255), N_("Slate Gray") }, + { GL_COLOR (216, 191, 216), N_("Thistle") }, + + { GL_COLOR (255, 255, 255), N_("White") }, + { GL_COLOR (230, 230, 230), N_("10% Gray") }, + { GL_COLOR (192, 192, 192), N_("25% Gray") }, + { GL_COLOR (153, 153, 153), N_("40% Gray") }, + { GL_COLOR (128, 128, 128), N_("50% Gray") }, + { GL_COLOR (102, 102, 102), N_("60% Gray") }, + { GL_COLOR ( 0, 0, 0), N_("Black") }, + +}; + +static glColorComboHistory *custom_color_history = NULL; + + +/*===========================================*/ +/* Local function prototypes */ +/*===========================================*/ + +static void gl_color_combo_menu_finalize (GObject *object); + +static void load_custom_color_history (glColorComboMenu *this); + +static gboolean map_event_cb (GtkWidget *widget, + GdkEventAny *event); + +static void default_menu_item_activate_cb (glColorComboMenu *this); +static void custom_menu_item_activate_cb (glColorComboMenu *this); + +static void palette_menu_item_activate_cb (GtkMenuItem *item, + glColorComboMenu *this); + +static void history_menu_item_activate_cb (GtkMenuItem *item, + glColorComboMenu *this); + + +/****************************************************************************/ +/* Boilerplate Object stuff. */ +/****************************************************************************/ +G_DEFINE_TYPE (glColorComboMenu, gl_color_combo_menu, GTK_TYPE_MENU); + + +/*****************************************************************************/ +/* Class Init Function. */ +/*****************************************************************************/ +static void +gl_color_combo_menu_class_init (glColorComboMenuClass *class) +{ + GObjectClass *gobject_class = G_OBJECT_CLASS (class); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class); + + gl_color_combo_menu_parent_class = g_type_class_peek_parent (class); + + gobject_class->finalize = gl_color_combo_menu_finalize; + + widget_class->map_event = map_event_cb; + + signals[COLOR_CHANGED] = + g_signal_new ("color_changed", + G_OBJECT_CLASS_TYPE (gobject_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (glColorComboMenuClass, color_changed), + NULL, NULL, + gl_marshal_VOID__UINT_BOOLEAN, + G_TYPE_NONE, + 2, G_TYPE_POINTER, G_TYPE_BOOLEAN); +} + + +/*****************************************************************************/ +/* Object Instance Init Function. */ +/*****************************************************************************/ +static void +gl_color_combo_menu_init (glColorComboMenu *this) +{ + GtkWidget *separator_menu_item; + gint i, i_row, i_col; + GtkWidget *palette_menu_item; + + + /* + * Initialize history, if needed. + */ + if ( !custom_color_history ) + { + custom_color_history = gl_color_combo_history_new (PALETTE_COLS); + } + + + this->priv = g_new0 (glColorComboMenuPrivate, 1); + + this->priv->default_menu_item = gtk_menu_item_new_with_label (""); + gtk_menu_attach (GTK_MENU (this), this->priv->default_menu_item, + 0, PALETTE_COLS, ROW_DEFAULT, ROW_DEFAULT+1); + + separator_menu_item = gtk_separator_menu_item_new (); + gtk_menu_attach (GTK_MENU (this), separator_menu_item, + 0, PALETTE_COLS, ROW_SEP_1, ROW_SEP_1+1); + + for ( i=0; i < G_N_ELEMENTS(color_table); i++ ) + { + + i_row = i / PALETTE_COLS; + i_col = i % PALETTE_COLS; + + palette_menu_item = gl_color_combo_color_menu_item_new (i, + color_table[i].color, + color_table[i].name); + g_signal_connect (palette_menu_item, "activate", + G_CALLBACK (palette_menu_item_activate_cb), this); + + gtk_menu_attach (GTK_MENU (this), palette_menu_item, + i_col, i_col+1, + ROW_PALETTE+i_row, ROW_PALETTE+i_row+1); + } + + separator_menu_item = gtk_separator_menu_item_new (); + gtk_menu_attach (GTK_MENU (this), separator_menu_item, + 0, PALETTE_COLS, ROW_SEP_2, ROW_SEP_2+1); + + for ( i=0; i < PALETTE_COLS; i++ ) + { + this->priv->history_menu_item[i] = + gl_color_combo_color_menu_item_new (i, 0, NULL); + gtk_widget_set_sensitive (this->priv->history_menu_item[i], FALSE); + g_signal_connect (this->priv->history_menu_item[i], "activate", + G_CALLBACK (history_menu_item_activate_cb), this); + gtk_menu_attach (GTK_MENU (this), this->priv->history_menu_item[i], + i, i+1, + ROW_HISTORY, ROW_HISTORY+1); + } + + separator_menu_item = gtk_separator_menu_item_new (); + gtk_menu_attach (GTK_MENU (this), separator_menu_item, + 0, PALETTE_COLS, ROW_SEP_3, ROW_SEP_3+1); + + this->priv->custom_menu_item = gtk_menu_item_new_with_label (_("Custom Color")); + gtk_menu_attach (GTK_MENU (this), this->priv->custom_menu_item, + 0, PALETTE_COLS, ROW_CUSTOM, ROW_CUSTOM+1); + + g_signal_connect_swapped (this->priv->default_menu_item, "activate", + G_CALLBACK (default_menu_item_activate_cb), this); + g_signal_connect_swapped (this->priv->custom_menu_item, "activate", + G_CALLBACK (custom_menu_item_activate_cb), this); + +} + + +/*****************************************************************************/ +/* Finalize Method. */ +/*****************************************************************************/ +static void +gl_color_combo_menu_finalize (GObject *object) +{ + glColorComboMenu *this = GL_COLOR_COMBO_MENU (object); + + g_return_if_fail (object != NULL); + g_return_if_fail (GL_IS_COLOR_COMBO_MENU (object)); + + g_free (this->priv); + + G_OBJECT_CLASS (gl_color_combo_menu_parent_class)->finalize (object); +} + + +/*****************************************************************************/ +/** New Object Generator. */ +/*****************************************************************************/ +GtkWidget * +gl_color_combo_menu_new (const gchar *default_label, + guint color) +{ + glColorComboMenu *this; + + this = g_object_new (gl_color_combo_menu_get_type (), NULL); + + gtk_label_set_text ( GTK_LABEL (gtk_bin_get_child (GTK_BIN (this->priv->default_menu_item))), + default_label); + + this->priv->color = color; + + return GTK_WIDGET (this); +} + + +/*****************************************************************************/ +/* Load menu with custom color history. */ +/*****************************************************************************/ +static void +load_custom_color_history (glColorComboMenu *this) +{ + guint i; + guint color; + gchar *tip; + + for ( i=0; i < PALETTE_COLS; i++ ) + { + color = gl_color_combo_history_get_color (custom_color_history, i); + + if (color) + { + tip = g_strdup_printf (_("Custom Color #%u"), i+1); + + gl_color_combo_color_menu_item_set_color (GL_COLOR_COMBO_COLOR_MENU_ITEM (this->priv->history_menu_item[i]), + i, + color, + tip); + g_free (tip); + gtk_widget_set_sensitive (this->priv->history_menu_item[i], TRUE); + } + } +} + + +/*****************************************************************************/ +/* Map event callback. */ +/*****************************************************************************/ +static gboolean +map_event_cb (GtkWidget *widget, + GdkEventAny *event) +{ + glColorComboMenu *this = GL_COLOR_COMBO_MENU (widget); + + load_custom_color_history (this); +} + + +/*****************************************************************************/ +/* "Default" menu_item activate callback. */ +/*****************************************************************************/ +static void +default_menu_item_activate_cb (glColorComboMenu *this) +{ + g_signal_emit (this, signals[COLOR_CHANGED], 0, + NULL, TRUE); + + gtk_widget_hide (GTK_WIDGET (this)); +} + + +/*****************************************************************************/ +/* "Custom color" menu_item activate callback. */ +/*****************************************************************************/ +static void +custom_menu_item_activate_cb (glColorComboMenu *this) +{ + GtkWidget *custom_dialog; + GtkWidget *colorsel; + gint response; + GdkColor color; + + gtk_widget_hide (GTK_WIDGET (this)); + + custom_dialog = gtk_color_selection_dialog_new (_("Custom Color")); + + colorsel = GTK_COLOR_SELECTION_DIALOG (custom_dialog)->colorsel; + color.red = GL_COLOR_F_RED (this->priv->color) * 65535; + color.green = GL_COLOR_F_GREEN (this->priv->color) * 65535; + color.blue = GL_COLOR_F_BLUE (this->priv->color) * 65535; + + gtk_color_selection_set_current_color (GTK_COLOR_SELECTION (colorsel), + &color); + + response = gtk_dialog_run (GTK_DIALOG (custom_dialog)); + + switch (response) { + + case GTK_RESPONSE_OK: + gtk_color_selection_get_current_color (GTK_COLOR_SELECTION (colorsel), + &color); + this->priv->color = GL_COLOR ((color.red >>8), + (color.green >>8), + (color.blue >>8)); + + gl_color_combo_history_add_color (custom_color_history, + this->priv->color); + + g_signal_emit (this, signals[COLOR_CHANGED], 0, + this->priv->color, FALSE); + + gtk_widget_destroy (custom_dialog); + break; + default: + gtk_widget_destroy (custom_dialog); + break; + } +} + + +/*****************************************************************************/ +/* Palette color changed callback. */ +/*****************************************************************************/ +static void +palette_menu_item_activate_cb (GtkMenuItem *item, + glColorComboMenu *this) +{ + gint i; + + i = gl_color_combo_color_menu_item_get_id (GL_COLOR_COMBO_COLOR_MENU_ITEM (item)); + + this->priv->color = color_table[i].color; + + g_signal_emit (this, signals[COLOR_CHANGED], 0, + this->priv->color, FALSE); + + gtk_widget_hide (GTK_WIDGET (this)); +} + +/*****************************************************************************/ +/* History color menu item callback. */ +/*****************************************************************************/ +static void +history_menu_item_activate_cb (GtkMenuItem *item, + glColorComboMenu *this) +{ + gint i; + + i = gl_color_combo_color_menu_item_get_id (GL_COLOR_COMBO_COLOR_MENU_ITEM (item)); + + this->priv->color = gl_color_combo_history_get_color (custom_color_history, + i); + + g_signal_emit (this, signals[COLOR_CHANGED], 0, + this->priv->color, FALSE); + + gtk_widget_hide (GTK_WIDGET (this)); +} + + + +/* + * Local Variables: -- emacs + * mode: C -- emacs + * c-basic-offset: 8 -- emacs + * tab-width: 8 -- emacs + * indent-tabs-mode: nil -- emacs + * End: -- emacs + */ diff --git a/glabels2/src/color-combo-menu.h b/glabels2/src/color-combo-menu.h new file mode 100644 index 00000000..e89a3017 --- /dev/null +++ b/glabels2/src/color-combo-menu.h @@ -0,0 +1,84 @@ +/* + * color-combo-menu.h + * Copyright (C) 2008 Jim Evins . + * + * This file is part of gLabels. + * + * gLabels is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * gLabels is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with gLabels. If not, see . + */ + +#ifndef __COLOR_COMBO_MENU_H__ +#define __COLOR_COMBO_MENU_H__ + +#include + + +G_BEGIN_DECLS + +#define GL_TYPE_COLOR_COMBO_MENU (gl_color_combo_menu_get_type ()) +#define GL_COLOR_COMBO_MENU(obj) \ + (GTK_CHECK_CAST((obj), GL_TYPE_COLOR_COMBO_MENU, glColorComboMenu )) +#define GL_COLOR_COMBO_MENU_CLASS(klass) \ + (GTK_CHECK_CLASS_CAST ((klass), GL_TYPE_COLOR_COMBO_MENU, glColorComboMenuClass)) +#define GL_IS_COLOR_COMBO_MENU(obj) \ + (GTK_CHECK_TYPE ((obj), GL_TYPE_COLOR_COMBO_MENU)) +#define GL_IS_COLOR_COMBO_MENU_CLASS(klass) \ + (GTK_CHECK_CLASS_TYPE ((klass), GL_TYPE_COLOR_COMBO_MENU)) + +typedef struct _glColorComboMenu glColorComboMenu; +typedef struct _glColorComboMenuPrivate glColorComboMenuPrivate; +typedef struct _glColorComboMenuClass glColorComboMenuClass; + +struct _glColorComboMenu { + GtkMenu parent_widget; + + glColorComboMenuPrivate *priv; +}; + +struct _glColorComboMenuClass { + GtkMenuClass parent_class; + + /* + * Signals + */ + void (*color_changed) (glColorComboMenu *object, + guint color, + gboolean is_default, + gpointer user_data); + +}; + + +GType gl_color_combo_menu_get_type (void) G_GNUC_CONST; + +GtkWidget *gl_color_combo_menu_new (const gchar *default_label, + guint color); + + +G_END_DECLS + + +#endif /* __COLOR_COMBO_MENU_H__ */ + + + +/* + * Local Variables: -- emacs + * mode: C -- emacs + * c-basic-offset: 8 -- emacs + * tab-width: 8 -- emacs + * indent-tabs-mode: nil -- emacs + * End: -- emacs + */ + diff --git a/glabels2/src/color-combo.c b/glabels2/src/color-combo.c new file mode 100644 index 00000000..c98b8b61 --- /dev/null +++ b/glabels2/src/color-combo.c @@ -0,0 +1,463 @@ +/* + * color-combo.c + * Copyright (C) 2008 Jim Evins . + * + * This file is part of gLabels. + * + * gLabels is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * gLabels is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with gLabels. If not, see . + */ + +#include + +#include "color-combo.h" + +#include "color-combo-menu.h" +#include +#include +#include +#include +#include +#include "marshal.h" +#include "util.h" +#include "color.h" + + +#define IMAGE_W 24 +#define IMAGE_H 24 + +/*========================================================*/ +/* Private types. */ +/*========================================================*/ + +/** GL_COLOR_COMBO Private fields */ +struct _glColorComboPrivate { + + guint color; + gboolean is_default_flag; + + guint default_color; + + GdkPixbuf *icon; + + GtkWidget *button; + GtkWidget *button_image; + GtkWidget *dropdown_button; + + GtkWidget *menu; +}; + +enum { + COLOR_CHANGED, + LAST_SIGNAL +}; + + +/*========================================================*/ +/* Private globals. */ +/*========================================================*/ + +static guint signals[LAST_SIGNAL] = {0}; + + +/*========================================================*/ +/* Private function prototypes. */ +/*========================================================*/ + +static void gl_color_combo_finalize (GObject *object); + +static void +button_clicked_cb (glColorCombo *this); + +static GdkPixbuf * +create_pixbuf (glColorCombo *this, + gdouble w, + gdouble h); + +static gboolean +dropdown_button_press_event_cb (GtkWidget *widget, + GdkEventButton *event, + glColorCombo *this); + +static void +menu_color_changed_cb (glColorComboMenu *object, + guint color, + gboolean is_default, + glColorCombo *this); + + +/*****************************************************************************/ +/* Object infrastructure. */ +/*****************************************************************************/ +G_DEFINE_TYPE (glColorCombo, gl_color_combo, GTK_TYPE_HBOX); + + +/*****************************************************************************/ +/* Class Init Function. */ +/*****************************************************************************/ +static void +gl_color_combo_class_init (glColorComboClass *class) +{ + GObjectClass *gobject_class = (GObjectClass *) class; + GtkWidgetClass *widget_class = (GtkWidgetClass *) class; + glColorComboClass *object_class = (glColorComboClass *) class; + + gl_color_combo_parent_class = g_type_class_peek_parent (class); + + gobject_class->finalize = gl_color_combo_finalize; + + signals[COLOR_CHANGED] = + g_signal_new ("color_changed", + G_OBJECT_CLASS_TYPE (gobject_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (glColorComboClass, color_changed), + NULL, NULL, + gl_marshal_VOID__UINT_BOOLEAN, + G_TYPE_NONE, + 2, G_TYPE_POINTER, G_TYPE_BOOLEAN); + +} + + +/*****************************************************************************/ +/* Object Instance Init Function. */ +/*****************************************************************************/ +static void +gl_color_combo_init (glColorCombo *this) +{ + GtkWidget *button_vbox; + GtkWidget *arrow; + + gtk_box_set_spacing (GTK_BOX (this), 0); + + this->priv = g_new0 (glColorComboPrivate, 1); + + this->priv->button = gtk_button_new (); + this->priv->button_image = gtk_image_new (); + gtk_button_set_image (GTK_BUTTON (this->priv->button), + this->priv->button_image); + gtk_button_set_focus_on_click (GTK_BUTTON (this->priv->button), FALSE); + g_signal_connect_swapped (this->priv->button, "clicked", + G_CALLBACK(button_clicked_cb), this); + + gtk_box_pack_start (GTK_BOX (this), this->priv->button, FALSE, FALSE, 0); + + this->priv->dropdown_button = gtk_button_new (); + arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_IN); + gtk_container_add (GTK_CONTAINER (this->priv->dropdown_button), arrow); + gtk_button_set_relief (GTK_BUTTON (this->priv->dropdown_button), GTK_RELIEF_NONE); + gtk_button_set_focus_on_click (GTK_BUTTON (this->priv->dropdown_button), FALSE); + g_signal_connect (this->priv->dropdown_button, "button_press_event", + G_CALLBACK(dropdown_button_press_event_cb), this); + + gtk_box_pack_start (GTK_BOX (this), this->priv->dropdown_button, FALSE, FALSE, 0); +} + + +/*****************************************************************************/ +/* Finalize Method. */ +/*****************************************************************************/ +static void +gl_color_combo_finalize (GObject *object) +{ + glColorCombo *this; + + g_return_if_fail (object && IS_GL_COLOR_COMBO (object)); + this = GL_COLOR_COMBO (object); + + if (this->priv->icon) + { + g_object_unref (this->priv->icon); + } + + g_free (this->priv); + + G_OBJECT_CLASS (gl_color_combo_parent_class)->finalize (object); +} + + +/*****************************************************************************/ +/** New Object Generator. */ +/*****************************************************************************/ +GtkWidget * +gl_color_combo_new (GdkPixbuf *icon, + const gchar *default_label, + guint default_color, + guint color) +{ + glColorCombo *this; + GtkWidget *separator_menuitem; + + this = g_object_new (TYPE_GL_COLOR_COMBO, NULL); + + if (icon) + { + this->priv->icon = g_object_ref (icon); + } + + if (!default_label) + { + default_label = _("Default Color"); + } + + this->priv->default_color = default_color; + this->priv->color = color; + + this->priv->menu = gl_color_combo_menu_new (default_label, + color); + gtk_widget_show_all (this->priv->menu); + + gtk_image_set_from_pixbuf (GTK_IMAGE (this->priv->button_image), + create_pixbuf (this, IMAGE_W, IMAGE_H)); + + g_signal_connect (this->priv->menu, "color_changed", + G_CALLBACK (menu_color_changed_cb), this); + + return GTK_WIDGET (this); +} + + +/*****************************************************************************/ +/* Set color. */ +/*****************************************************************************/ +void +gl_color_combo_set_color (glColorCombo *this, + guint color) +{ + this->priv->color = color; + + gtk_image_set_from_pixbuf (GTK_IMAGE (this->priv->button_image), + create_pixbuf (this, IMAGE_W, IMAGE_H)); +} + + +/*****************************************************************************/ +/* Set to default color. */ +/*****************************************************************************/ +void +gl_color_combo_set_to_default (glColorCombo *this) +{ + gl_color_combo_set_color (this, this->priv->default_color); +} + +/*****************************************************************************/ +/* Get color. */ +/*****************************************************************************/ +guint +gl_color_combo_get_color (glColorCombo *this, + gboolean *is_default) +{ + if (is_default) + { + *is_default = this->priv->is_default_flag; + } + + return this->priv->color; +} + + +/*****************************************************************************/ +/** Set relief style. */ +/*****************************************************************************/ +void +gl_color_combo_set_relief( glColorCombo *this, + GtkReliefStyle relief ) +{ + gtk_button_set_relief (GTK_BUTTON (this->priv->button), relief); +} + + +/*****************************************************************************/ +/* Color button "clicked" callback. */ +/*****************************************************************************/ +static void +button_clicked_cb( glColorCombo *this ) +{ + g_signal_emit (this, signals[COLOR_CHANGED], 0, + this->priv->color, + this->priv->is_default_flag); +} + + +/*****************************************************************************/ +/* Create new pixbuf with color preview. */ +/*****************************************************************************/ +static GdkPixbuf * +create_pixbuf (glColorCombo *this, + gdouble w, + gdouble h) +{ + cairo_surface_t *surface; + cairo_t *cr; + gdouble image_w, image_h; + gdouble swatch_h; + GdkPixbuf *pixbuf; + + surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, w, h); + + cr = cairo_create (surface); + + cairo_set_antialias (cr, CAIRO_ANTIALIAS_NONE); + + cairo_save (cr); + cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR); + cairo_paint (cr); + cairo_restore (cr); + + if (this->priv->icon) + { + image_w = gdk_pixbuf_get_width (this->priv->icon); + image_h = gdk_pixbuf_get_height (this->priv->icon); + + cairo_save (cr); + + cairo_rectangle (cr, 0, 0, w, h); + cairo_scale (cr, w/image_w, h/image_h); + gdk_cairo_set_source_pixbuf (cr, this->priv->icon, 0, 0); + cairo_fill (cr); + + cairo_restore (cr); + + swatch_h = h/5 + 1; + } + else + { + swatch_h = h; + } + + cairo_rectangle( cr, 1, h-swatch_h+1, w-2, swatch_h-2 ); + + cairo_set_source_rgba (cr, + GL_COLOR_F_RED (this->priv->color), + GL_COLOR_F_GREEN (this->priv->color), + GL_COLOR_F_BLUE (this->priv->color), + GL_COLOR_F_ALPHA (this->priv->color)); + cairo_fill_preserve( cr ); + + cairo_set_line_width (cr, 1.0); + cairo_set_source_rgb (cr, 0.5, 0.5, 0.5); + cairo_stroke (cr); + + cairo_destroy( cr ); + + pixbuf = gl_util_cairo_convert_to_pixbuf (surface); + cairo_surface_destroy (surface); + + return pixbuf; +} + + +/*****************************************************************************/ +/* Menu positioning function. */ +/*****************************************************************************/ +static void +menu_position_function (GtkMenu *menu, + gint *x, + gint *y, + gboolean *push_in, + gpointer user_data) +{ + glColorCombo *this = GL_COLOR_COMBO (user_data); + gint x1, y1; + gint menu_h, menu_w; + + gdk_window_get_origin (GTK_WIDGET (this)->window, &x1, &y1); + *x = x1 + GTK_WIDGET (this)->allocation.x; + *y = y1 + GTK_WIDGET (this)->allocation.y + + GTK_WIDGET (this)->allocation.height; + + menu_h = this->priv->menu->allocation.height; + menu_w = this->priv->menu->allocation.width; + + if ((*y + menu_h) > gdk_screen_height ()) + { + *y = y1 + GTK_WIDGET (this)->allocation.y - menu_h; + if ( *y < 0 ) + { + *y = gdk_screen_height () - menu_h; + } + } + + if ((*x + menu_w) > gdk_screen_width ()) + { + *x = gdk_screen_width () - menu_w; + } + + *push_in = TRUE; +} + + +/*****************************************************************************/ +/* Dropdown button "clicked" callback. */ +/*****************************************************************************/ +static gboolean +dropdown_button_press_event_cb (GtkWidget *widget, + GdkEventButton *event, + glColorCombo *this) +{ + switch (event->button) + { + + case 1: + gtk_menu_popup (GTK_MENU (this->priv->menu), + NULL, NULL, + menu_position_function, this, + event->button, event->time); + break; + + default: + break; + + } + + return FALSE; +} + + +/*****************************************************************************/ +/* Menu "color changed" callback. */ +/*****************************************************************************/ +static void +menu_color_changed_cb (glColorComboMenu *object, + guint color, + gboolean is_default, + glColorCombo *this) +{ + if (is_default) + { + this->priv->color = this->priv->default_color; + } + else + { + this->priv->color = color; + } + this->priv->is_default_flag = is_default; + + gtk_image_set_from_pixbuf (GTK_IMAGE (this->priv->button_image), + create_pixbuf (this, IMAGE_W, IMAGE_H)); + + g_signal_emit (this, signals[COLOR_CHANGED], 0, + this->priv->color, + this->priv->is_default_flag); +} + + + +/* + * Local Variables: -- emacs + * mode: C -- emacs + * c-basic-offset: 8 -- emacs + * tab-width: 8 -- emacs + * indent-tabs-mode: nil -- emacs + * End: -- emacs + */ diff --git a/glabels2/src/color-combo.h b/glabels2/src/color-combo.h new file mode 100644 index 00000000..55456b45 --- /dev/null +++ b/glabels2/src/color-combo.h @@ -0,0 +1,95 @@ +/* + * color-combo.h + * Copyright (C) 2008 Jim Evins . + * + * This file is part of gLabels. + * + * gLabels is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * gLabels is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with gLabels. If not, see . + */ + +#ifndef __GL_COLOR_COMBO_H__ +#define __GL_COLOR_COMBO_H__ + + +#include + + +G_BEGIN_DECLS + +#define TYPE_GL_COLOR_COMBO (gl_color_combo_get_type ()) +#define GL_COLOR_COMBO(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_GL_COLOR_COMBO, glColorCombo)) +#define GL_COLOR_COMBO_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_GL_COLOR_COMBO, glColorComboClass)) +#define IS_GL_COLOR_COMBO(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_GL_COLOR_COMBO)) +#define IS_GL_COLOR_COMBO_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_GL_COLOR_COMBO)) +#define GL_COLOR_COMBO_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS ((object), TYPE_GL_COLOR_COMBO, glColorComboClass)) + + +typedef struct _glColorCombo glColorCombo; +typedef struct _glColorComboPrivate glColorComboPrivate; +typedef struct _glColorComboClass glColorComboClass; + + +struct _glColorCombo { + GtkHBox parent; + + glColorComboPrivate *priv; +}; + +struct _glColorComboClass { + GtkHBoxClass parent_class; + + /* + * Signals + */ + void (*color_changed) (glColorCombo *object, + guint color, + gboolean is_default, + gpointer user_data); + +}; + + +GType gl_color_combo_get_type (void) G_GNUC_CONST; + +GtkWidget *gl_color_combo_new (GdkPixbuf *icon, + const gchar *default_label, + guint default_color, + guint color); + +void gl_color_combo_set_color (glColorCombo *this, + guint color); + +void gl_color_combo_set_to_default (glColorCombo *this); + +guint gl_color_combo_get_color (glColorCombo *this, + gboolean *is_default); + +void gl_color_combo_set_relief (glColorCombo *this, + GtkReliefStyle relief); + + +G_END_DECLS + +#endif /* __GL_COLOR_COMBO_H__ */ + + + +/* + * Local Variables: -- emacs + * mode: C -- emacs + * c-basic-offset: 8 -- emacs + * tab-width: 8 -- emacs + * indent-tabs-mode: nil -- emacs + * End: -- emacs + */ diff --git a/glabels2/src/marshal.list b/glabels2/src/marshal.list index 82aa892c..edc75344 100644 --- a/glabels2/src/marshal.list +++ b/glabels2/src/marshal.list @@ -6,3 +6,4 @@ VOID:DOUBLE VOID:DOUBLE,DOUBLE VOID:OBJECT VOID:STRING +VOID:UINT,BOOLEAN diff --git a/glabels2/src/mygal/Makefile.am b/glabels2/src/mygal/Makefile.am deleted file mode 100644 index 054cbe7a..00000000 --- a/glabels2/src/mygal/Makefile.am +++ /dev/null @@ -1,44 +0,0 @@ -INCLUDES = \ - $(MYGAL_CFLAGS) - - -libmygal_la_LDFLAGS=\ - $(MYGAL_LIBS) - -noinst_LTLIBRARIES = libmygal.la - -libmygal_la_SOURCES = \ - widget-color-combo.c \ - widget-color-combo.h \ - e-util.h \ - e-colors.c \ - e-colors.h \ - mygal-combo-box.c \ - mygal-combo-box.h \ - color-palette.c \ - color-palette.h \ - color-group.c \ - color-group.h \ - e-marshal.c \ - e-marshal.h - -marshal_sources = \ - e-marshal.c \ - e-marshal.h - -$(libmygal_la_OBJECTS) : $(marshal_sources) - -e-marshal.h: e-marshal.list $(GLIB_GENMARSHAL) - $(GLIB_GENMARSHAL) $< --header --prefix=e_marshal > $@ -e-marshal.c: e-marshal.list $(GLIB_GENMARSHAL) - $(GLIB_GENMARSHAL) $< --body --prefix=e_marshal > $@ - -EXTRA_DIST = e-marshal.list -CLEANFILES = $(marshal_sources) - -DONT_DIST_SOURCE = $(marshal_sources) - -dist-hook: - for file in $(DONT_DIST_SOURCE) ; do \ - rm -f $(distdir)/$$file ; \ - done diff --git a/glabels2/src/mygal/color-group.c b/glabels2/src/mygal/color-group.c deleted file mode 100644 index 3f35257c..00000000 --- a/glabels2/src/mygal/color-group.c +++ /dev/null @@ -1,333 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * color-group.c - Utility to keep a shered memory of custom colors - * between arbitrary widgets. - * Copyright 2000, Michael Levy - * Copyright 2001, Almer S. Tigelaar - * - * Authors: - * Michael Levy (mlevy@genoscope.cns.fr) - * Revised and polished by: - * Almer S. Tigelaar - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public - * License, version 2, as published by the Free Software Foundation. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - */ - -#include "color-group.h" -#include -#include -#include "e-util.h" -#include - -#define PARENT_TYPE G_TYPE_OBJECT - -enum { - CUSTOM_COLOR_ADD, - LAST_SIGNAL -}; - -static GObjectClass *parent_class; - -static GQuark color_group_signals [LAST_SIGNAL] = { 0 }; - -static void color_group_finalize (GObject *obj); - -static void -color_group_class_init (ColorGroupClass *klass) -{ - GObjectClass *object_class; - - object_class = (GObjectClass*) klass; - - object_class->finalize = &color_group_finalize; - parent_class = g_type_class_peek (PARENT_TYPE); - - color_group_signals [CUSTOM_COLOR_ADD] = - g_signal_new ("custom_color_add", - COLOR_GROUP_TYPE, - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ColorGroupClass, custom_color_add), - (GSignalAccumulator) NULL, NULL, - g_cclosure_marshal_VOID__POINTER, - G_TYPE_NONE, - 1, G_TYPE_POINTER); -} - -static void -color_group_init (ColorGroup *cg) -{ - cg->name = NULL; - cg->history = NULL; - cg->history_size = 0; -} - -E_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 guint -cg_hash (gconstpointer key) -{ - /* Do NOT use smart type checking it will not work for the tmp_key */ - return g_str_hash (((ColorGroup *)key)->name); -} - -static gint -cg_cmp (gconstpointer a, gconstpointer b) -{ - /* Do NOT use smart type checking it will not work for the tmp_key */ - ColorGroup const *cg_a = (ColorGroup *)a; - ColorGroup const *cg_b = (ColorGroup *)b; - if (cg_a == cg_b) - return TRUE; - if (cg_a->context != cg_b->context) - return FALSE; - return g_str_equal (cg_a->name, cg_b->name); -} - -static void -initialize_group_names (void) -{ - g_assert (group_names == NULL); - group_names = g_hash_table_new (cg_hash, cg_cmp); -} - -/** - * color_group_get : - * @name : - * @context : - * - * Look up the name/context specific color-group. Return NULL if it is not found. - * No reference is added if it is found. - */ -ColorGroup * -color_group_get (const gchar * name, gpointer context) -{ - ColorGroup tmp_key; - gpointer res; - - g_assert(group_names); - - g_return_val_if_fail(name != NULL, NULL); - - tmp_key.name = (char *)name; - tmp_key.context = context; - res = g_hash_table_lookup (group_names, &tmp_key); - - if (res != NULL) - return COLOR_GROUP (res); - else - return NULL; -} - -static gchar * -create_unique_name (gpointer context) -{ - 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_get (new_name, context) == NULL) - return new_name; - else - g_free(new_name); - } - g_assert_not_reached(); -} - -static void -color_group_finalize (GObject *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 */ - if (cg->name) { - g_hash_table_remove (group_names, cg); - g_free (cg->name); - cg->name = NULL; - } - - if (cg->history) { - /* Free the whole colour history */ - while ((int) cg->history->len > 0) - gdk_color_free ((GdkColor *) - g_ptr_array_remove_index (cg->history, 0)); - g_ptr_array_free (cg->history, TRUE); - cg->history = NULL; - } - - if (parent_class->finalize) - (parent_class->finalize) (obj); -} - -/* - * color_group_get_history_size: - * 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); - - /* Remove excess elements (begin with kicking out the oldest) */ - while ((int) cg->history->len > size) - gdk_color_free ((GdkColor *) g_ptr_array_remove_index (cg->history, 0)); -} - -/* - * color_group_fetch : - * @name : - * @context : - * - * 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. - */ -ColorGroup * -color_group_fetch (const gchar *name, gpointer context) -{ - ColorGroup *cg; - gchar *new_name; - - if (group_names == NULL) - initialize_group_names(); - - if (name == NULL) - new_name = create_unique_name (context); - else - new_name = g_strdup (name); - - cg = color_group_get (new_name, context); - if (cg != NULL) { - g_free (new_name); - g_object_ref (G_OBJECT (cg)); - return cg; - } - - /* Take care of creating the new object */ - cg = g_object_new (color_group_get_type (), NULL); - g_return_val_if_fail(cg != NULL, NULL); - - cg->name = new_name; - cg->context = context; - - /* Create history */ - cg->history = g_ptr_array_new (); - - /* FIXME: Why not 8? We never use more then 8 on the palette, - * maybe we can't free colors while they are still on the palette and - * need to be sure they are not on it when we free them and thus we - * make the upper limit twice the size of the number of displayed items - * (2 * 8) ? - */ - cg->history_size = 16; - - /* lastly register this name */ - g_hash_table_insert (group_names, cg, cg); - - return cg; -} - -/* - * color_group_get_custom_colors: - * Retrieve all custom colors currently in the history using a callback - * mechanism. The custom colors will be passed from the oldest to the newest. - */ -void -color_group_get_custom_colors (ColorGroup *cg, CbCustomColors callback, gpointer user_data) -{ - int i; - - g_return_if_fail (cg != NULL); - - /* Invoke the callback for our full history */ - for (i = 0; i < (int) cg->history->len; i++) { - GdkColor const * const color = g_ptr_array_index (cg->history, i); - - callback (color, user_data); - } -} - -/* - * color_group_add_color: - * Changes the colors. The color to be set should always be a custom - * color! It has no use adding a color which is already in the default - * palette. - */ -void -color_group_add_color (ColorGroup *cg, GdkColor const * const color) -{ - int i; - - g_return_if_fail(cg != NULL); - g_return_if_fail(color != NULL); /* Can't be NULL */ - - /* Let's be smart and see if it's already in our history, no need to add it again*/ - for (i = 0; i < (int) cg->history->len; i++) { - GdkColor *current = g_ptr_array_index (cg->history, i); - - if (gdk_color_equal (color, current)) - return; - } - - /* - * We make our own private copy of the color passed and put - * it in the history, this is freed later. - */ - if (cg->history_size > 0) - g_ptr_array_add (cg->history, gdk_color_copy (color)); - - /* Shift out the oldest item if we grow beyond our set size */ - if ((int) cg->history->len > cg->history_size) - gdk_color_free ((GdkColor *) g_ptr_array_remove_index (cg->history, 0)); - - /* Tell color-palette's that use this group that - * a new custom color was added. - */ - g_signal_emit (G_OBJECT(cg), - color_group_signals [CUSTOM_COLOR_ADD], - 0, - color); -} diff --git a/glabels2/src/mygal/color-group.h b/glabels2/src/mygal/color-group.h deleted file mode 100644 index b35ad614..00000000 --- a/glabels2/src/mygal/color-group.h +++ /dev/null @@ -1,77 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * color-group.h - Utility to keep a shered memory of custom colors - * between arbitrary widgets. - * Copyright 2000, Michael Levy - * Copyright 2001, Almer S. Tigelaar - * - * Authors: - * Michael Levy (mlevy@genoscope.cns.fr) - * Revised and polished by: - * Almer S. Tigelaar - * - * Modified for gLabels by: - * Jim Evins - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public - * License, version 2, as published by the Free Software Foundation. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - */ - -#ifndef GNOME_APP_LIB__COLOR_GROUP_H -#define GNOME_APP_LIB__COLOR_GROUP_H - -#include -#include -#include - -G_BEGIN_DECLS - -typedef gboolean (* CbCustomColors) (GdkColor const * const color, gpointer data); - -typedef struct _ColorGroup { - GObject parent; - - gchar *name; - gpointer context; - - GPtrArray *history; /* The custom color history */ - gint history_size; /* length of color_history */ -} ColorGroup; - -typedef struct { - GObjectClass parent_class; - - /* Signals emited by this object */ - void (*custom_color_add) (ColorGroup *color_group, GdkColor const * const color); -} ColorGroupClass; - -#define COLOR_GROUP_TYPE (color_group_get_type ()) -#define COLOR_GROUP(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), COLOR_GROUP_TYPE, ColorGroup)) -#define COLOR_GROUP_CLASS(k) (G_TYPE_CHECK_CLASS_CAST (k), COLOR_GROUP_TYPE) -#define IS_COLOR_GROUP(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), COLOR_GROUP_TYPE)) - -GType color_group_get_type (void); -ColorGroup *color_group_fetch (const gchar *name, gpointer context); -ColorGroup *color_group_get (const gchar *name, gpointer context); - -void color_group_set_history_size (ColorGroup *cg, gint size); -gint color_group_get_history_size (ColorGroup *cg); - -void color_group_get_custom_colors (ColorGroup *cg, CbCustomColors callback, - gpointer user_data); -void color_group_add_color (ColorGroup *cg, GdkColor const * const color); - -G_END_DECLS - -#endif /* GNOME_APP_LIB__COLOR_GROUP_H */ diff --git a/glabels2/src/mygal/color-palette.c b/glabels2/src/mygal/color-palette.c deleted file mode 100644 index 49d47795..00000000 --- a/glabels2/src/mygal/color-palette.c +++ /dev/null @@ -1,661 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * color-palette.c - A color selector palette - * Copyright 2000, 2001, Ximian, Inc. - * - * Authors: - * This code was extracted from widget-color-combo.c - * written by Miguel de Icaza (miguel@kernel.org) and - * Dom Lachowicz (dominicl@seas.upenn.edu). The extracted - * code was re-packaged into a separate object by - * Michael Levy (mlevy@genoscope.cns.fr) - * And later revised and polished by - * Almer S. Tigelaar (almer@gnome.org) - * - * Modified for gLabels by: - * Jim Evins - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public - * License, version 2, as published by the Free Software Foundation. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include "e-util.h" -#include "color-group.h" -#include "color-palette.h" -#include "e-colors.h" - -#define COLOR_PREVIEW_WIDTH 15 -#define COLOR_PREVIEW_HEIGHT 15 - -enum { - COLOR_CHANGED, - LAST_SIGNAL -}; - -struct _ColorNamePair { - char *color; /* rgb color or otherwise - eg. "#FFFFFF" */ - char *name; /* english name - eg. "white" */ -}; - -static guint color_palette_signals [LAST_SIGNAL] = { 0, }; - -#define PARENT_TYPE GTK_TYPE_VBOX -static GObjectClass *color_palette_parent_class; - -#define make_color(P,COL) (((COL) != NULL) ? (COL) : ((P) ? ((P)->default_color) : NULL)) - -static void -color_palette_destroy (GtkObject *object) -{ - ColorPalette *P = COLOR_PALETTE (object); - GtkObjectClass *klass = (GtkObjectClass *)color_palette_parent_class; - - if (P->tool_tip) { - g_object_unref (P->tool_tip); - P->tool_tip = NULL; - } - - if (P->current_color) { - gdk_color_free (P->current_color); - P->current_color = NULL; - } - - color_palette_set_group (P, NULL); - - memset (P->items, 0, P->total * sizeof (GnomeCanvasItem *)); - - if (klass->destroy) - klass->destroy (object); -} - -static void -color_palette_finalize (GObject *object) -{ - ColorPalette *P = COLOR_PALETTE (object); - - g_free (P->items); - - (*color_palette_parent_class->finalize) (object); -} - -static void -color_palette_class_init (GObjectClass *object_class) -{ - object_class->finalize = color_palette_finalize; - ((GtkObjectClass *)object_class)->destroy = color_palette_destroy; - - color_palette_parent_class = g_type_class_peek_parent (object_class); - - color_palette_signals [COLOR_CHANGED] = - g_signal_new ("color_changed", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ColorPaletteClass, color_changed), - NULL, NULL, - e_marshal_NONE__POINTER_BOOLEAN_BOOLEAN_BOOLEAN, - G_TYPE_NONE, 4, G_TYPE_POINTER, - G_TYPE_BOOLEAN, G_TYPE_BOOLEAN, G_TYPE_BOOLEAN); -} - -E_MAKE_TYPE (color_palette, - "ColorPalette", - ColorPalette, - color_palette_class_init, - NULL, - PARENT_TYPE) - -static void -emit_color_changed (ColorPalette *P, GdkColor *color, - gboolean custom, gboolean by_user, gboolean is_default) -{ - GdkColor *new = make_color (P, color); - - if (new != NULL) - new = gdk_color_copy (new); - if (P->current_color) - gdk_color_free (P->current_color); - P->current_color = new; - P->current_is_default = is_default; - - /* Only add custom colors to the group */ - if (custom && color) - color_group_add_color (P->color_group, color); - - g_signal_emit (P, color_palette_signals [COLOR_CHANGED], 0, - color, custom, by_user, is_default); -} - - -/* - * Add the new custom color as the first custom color in the custom color rows - * and shift all of the others 'one step down' - * - * Also take care of setting up the GtkColorButton 'display' - */ -static void -color_palette_change_custom_color (ColorPalette *P, GdkColor const * const new) -{ - int index; - GnomeCanvasItem *item; - GnomeCanvasItem *next_item; - - g_return_if_fail (P != NULL); - g_return_if_fail (new != NULL); - g_return_if_fail (P->picker); - - /* make sure there is room */ - if (P->custom_color_pos == -1) - return; - - for (index = P->custom_color_pos; index < P->total - 1; index++) { - GdkColor *color; - GdkColor *outline; - item = P->items[index]; - next_item = P->items[index + 1]; - - g_object_get (G_OBJECT (next_item), - "fill_color_gdk", &color, - "outline_color_gdk", &outline, - NULL); - gnome_canvas_item_set (item, - "fill_color_gdk", color, - "outline_color_gdk", outline, - NULL); - gdk_color_free (color); - gdk_color_free (outline); - } - item = P->items[index]; - gnome_canvas_item_set (item, - "fill_color_gdk", new, - "outline_color_gdk", new, - NULL); - gtk_color_button_set_color (P->picker, new); -} - -/* - * The custom color box was clicked. Find out its value and emit it - * And add it to the custom color row - */ -static void -cust_color_set (GtkWidget *color_picker, ColorPalette *P) -{ - GdkColor c_color; - - gtk_color_button_get_color (GTK_COLOR_BUTTON (color_picker), &c_color); - - e_color_alloc_gdk (NULL, &c_color); - emit_color_changed (P, &c_color, TRUE, TRUE, FALSE); -} - -static void -cb_default_clicked (GtkWidget *button, ColorPalette *P) -{ - emit_color_changed (P, P->default_color, FALSE, TRUE, TRUE); -} - -/* - * Something in our table was clicked. Find out what and emit it - */ -static void -color_clicked (GtkWidget *button, ColorPalette *P) -{ - int index; - GnomeCanvasItem *item; - GdkColor *gdk_color; - - index = GPOINTER_TO_INT (gtk_object_get_user_data (GTK_OBJECT (button))); - item = P->items[index]; - - g_object_get (item, - "fill_color_gdk", &gdk_color, - NULL); - - emit_color_changed (P, gdk_color, FALSE, TRUE, FALSE); - - gdk_color_free (gdk_color); -} - -/* - * The color group sent the 'custom_color_add' signal - */ -static void -cb_group_custom_color_add (GtkObject *cg, GdkColor *color, ColorPalette *P) -{ - GdkColor *new; - - new = make_color (P, color); - color_palette_change_custom_color (P, new); -} - -/* - * Find out if a color is in the default palette (not in the custom colors!) - * - * Utility function - */ -static gboolean -color_in_palette (ColorNamePair *set, GdkColor *color) -{ - int i; - - g_return_val_if_fail (set != NULL, FALSE); - - if (color == NULL) - return TRUE; - - /* Iterator over all the colors and try to find - * if we can find @color - */ - for (i = 0; set[i].color != NULL; i++) { - GdkColor current; - - gdk_color_parse (set[i].color, ¤t); - - if (gdk_color_equal (color, ¤t)) - return TRUE; - } - - return FALSE; -} - -/* - * Create the individual color buttons - * - * Utility function - */ -static GnomeCanvasItem * -color_palette_button_new(ColorPalette *P, GtkTable* table, - GtkTooltips *tool_tip, ColorNamePair* color_name, - gint col, gint row, int data) -{ - GtkWidget *button; - GtkWidget *canvas; - GnomeCanvasItem *item; - - button = gtk_button_new (); - gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE); - - canvas = gnome_canvas_new (); - - gtk_widget_set_usize (canvas, COLOR_PREVIEW_WIDTH, COLOR_PREVIEW_HEIGHT); - gtk_container_add (GTK_CONTAINER (button), canvas); - - item = gnome_canvas_item_new (GNOME_CANVAS_GROUP (gnome_canvas_root - (GNOME_CANVAS (canvas))), - gnome_canvas_rect_get_type (), - "x1", 0.0, - "y1", 0.0, - "x2", (double) COLOR_PREVIEW_WIDTH, - "y2", (double) COLOR_PREVIEW_HEIGHT, - "fill_color", color_name->color, - NULL); - - gtk_tooltips_set_tip (tool_tip, button, _(color_name->name), - "Private+Unused"); - - gtk_table_attach (table, button, - col, col+1, row, row+1, GTK_FILL, GTK_FILL, 1, 1); - - g_signal_connect (button, "clicked", - G_CALLBACK (color_clicked), P); - gtk_object_set_user_data (GTK_OBJECT (button), - GINT_TO_POINTER (data)); - return item; -} - -static void -cb_custom_colors (GdkColor const * const color, gpointer data) -{ - ColorPalette *P = data; - - if (color) - color_palette_change_custom_color (P, color); -} - -/* - * gets history information from the group - */ -static void -custom_color_history_setup(ColorPalette *P) -{ - g_return_if_fail (P != NULL); - g_return_if_fail (P->color_group != NULL); - - /* Sync our own palette with all the custom colors in the group */ - color_group_get_custom_colors (P->color_group, (CbCustomColors) cb_custom_colors, P); -} - -/* - * Creates the color table - */ -static GtkWidget * -color_palette_setup (ColorPalette *P, - char const * const no_color_label, - int ncols, int nrows, - ColorNamePair *color_names) -{ - GtkWidget *default_button; - GtkWidget *cust_label; - GtkWidget *table; - GtkTooltips *tool_tip; - int total, row, col; - - table = gtk_table_new (ncols, nrows, FALSE); - - if (no_color_label != NULL) { - default_button = gtk_button_new_with_label (no_color_label); - - gtk_table_attach (GTK_TABLE (table), default_button, - 0, ncols, 0, 1, GTK_FILL | GTK_EXPAND, 0, 0, 0); - g_signal_connect (default_button, "clicked", - G_CALLBACK (cb_default_clicked), P); - } - - P->tool_tip = tool_tip = gtk_tooltips_new (); - g_object_ref (P->tool_tip); - gtk_object_sink (GTK_OBJECT (P->tool_tip)); - - P->custom_color_pos = -1; - total = 0; - - for (row = 0; row < nrows; row++) { - for (col = 0; col < ncols; col++) { - int pos; - - pos = row * ncols + col; - /* - * If we are done with all of the colors in color_names - */ - if (color_names [pos].color == NULL) { - /* This is the default custom color */ - ColorNamePair color_name = {"#000", N_("custom")}; - row++; - if (col == 0 || row < nrows) { - /* Add a full row for custom colors */ - for (col = 0; col < ncols; col++) { - /* Have we set custom pos yet ? */ - if (P->custom_color_pos == -1) { - P->custom_color_pos = total; - } - P->items[total] = - color_palette_button_new( - P, - GTK_TABLE (table), - GTK_TOOLTIPS (tool_tip), - &(color_name), - col, - row + 1, - total); - total++; - } - } - /* Break out of two for-loops. */ - row = nrows; - break; - } - - P->items[total] = - color_palette_button_new ( - P, - GTK_TABLE (table), - GTK_TOOLTIPS (tool_tip), - &(color_names [pos]), - col, - row + 1, - total); - total++; - } - } - P->total = total; - - - /* "Custom" color - we'll pop up a GtkColorButton */ - cust_label = gtk_label_new (_("Custom Color:")); - gtk_table_attach (GTK_TABLE (table), cust_label, 0, ncols - 3 , - row + 1, row + 2, GTK_FILL | GTK_EXPAND, 0, 0, 0); - /* - Keep a pointer to the picker so that we can update it's color - to keep it in synch with that of other members of the group - */ - P->picker = GTK_COLOR_BUTTON (gtk_color_button_new ()); - gtk_color_button_set_title (P->picker, _("Choose Custom Color")); - gtk_table_attach (GTK_TABLE (table), GTK_WIDGET (P->picker), ncols - 3, ncols, - row + 1, row + 2, GTK_FILL | GTK_EXPAND, 0, 0, 0); - g_signal_connect (P->picker, "color-set", - G_CALLBACK (cust_color_set), P); - return table; -} - -void -color_palette_set_color_to_default (ColorPalette *P) -{ - g_return_if_fail (P != NULL); - g_return_if_fail (IS_COLOR_GROUP (P->color_group)); - - emit_color_changed (P, P->default_color, FALSE, TRUE, TRUE); -} - -void -color_palette_set_current_color (ColorPalette *P, GdkColor *color) -{ - g_return_if_fail (P != NULL); - g_return_if_fail (IS_COLOR_GROUP (P->color_group)); - - if (color) - emit_color_changed - (P, color, color_in_palette (P->default_set, color), - FALSE, FALSE); - else - color_palette_set_color_to_default (P); -} - -GdkColor * -color_palette_get_current_color (ColorPalette *P, gboolean *is_default) -{ - g_return_val_if_fail (P != NULL, NULL); - g_return_val_if_fail (IS_COLOR_GROUP (P->color_group), NULL); - - if (is_default != NULL) - *is_default = P->current_is_default; - - return P->current_color ? gdk_color_copy (P->current_color) : NULL; -} - -GtkWidget * -color_palette_get_color_picker (ColorPalette *P) -{ - g_return_val_if_fail (IS_COLOR_PALETTE (P), NULL); - - return GTK_WIDGET (P->picker); -} - - -/* - * Where the actual construction goes on - */ -static void -color_palette_construct (ColorPalette *P, - char const * const no_color_label, - int ncols, int nrows) -{ - GtkWidget * table; - g_return_if_fail (P != NULL); - g_return_if_fail (IS_COLOR_PALETTE (P)); - - P->items = g_malloc (sizeof (GnomeCanvasItem *) * ncols * nrows); - - /* - * Our table selector - */ - table = color_palette_setup (P, no_color_label, ncols, - nrows, P->default_set); - gtk_container_add (GTK_CONTAINER(P), table); -} - -/* - * More verbose constructor. Allows for specifying the rows, columns, and - * Colors this palette will contain - * - * Note that if after placing all of the color_names there remains an entire - * row available then a row of custum colors (initialized to black) is added - * - */ -static GtkWidget* -color_palette_new_with_vals (char const * const no_color_label, - int ncols, int nrows, ColorNamePair *color_names, - GdkColor *default_color, - ColorGroup *cg) -{ - ColorPalette *P; - - g_return_val_if_fail (color_names != NULL, NULL); - - P = g_object_new (COLOR_PALETTE_TYPE, NULL); - - P->default_set = color_names; - P->default_color = default_color; - P->current_color = default_color ? gdk_color_copy (default_color) : NULL; - P->current_is_default = TRUE; - color_palette_set_group (P, cg); - - color_palette_construct (P, no_color_label, ncols, nrows); - custom_color_history_setup(P); - - return GTK_WIDGET (P); -} - -/** - * color_palette_set_group : absorbs the reference to the group - */ -void -color_palette_set_group (ColorPalette *P, ColorGroup *cg) -{ - if (P->color_group == cg) - return; - - if (P->color_group) { - g_signal_handlers_disconnect_by_func ( - G_OBJECT (P->color_group), - G_CALLBACK (cb_group_custom_color_add), - P); - g_object_unref (G_OBJECT (P->color_group)); - P->color_group = NULL; - } - if (cg != NULL) { - P->color_group = COLOR_GROUP (cg); - g_signal_connect (G_OBJECT (cg), "custom_color_add", - G_CALLBACK (cb_group_custom_color_add), - P); - - } -} - -static ColorNamePair default_color_set [] = { - {"#000000", N_("black")}, - {"#993300", N_("light brown")}, - {"#333300", N_("brown gold")}, - {"#003300", N_("dark green #2")}, - {"#003366", N_("navy")}, - {"#000080", N_("dark blue")}, - {"#333399", N_("purple #2")}, - {"#333333", N_("very dark gray")}, - - - {"#800000", N_("dark red")}, - {"#FF6600", N_("red-orange")}, - {"#808000", N_("gold")}, - {"#008000", N_("dark green")}, - {"#008080", N_("dull blue")}, - {"#0000FF", N_("blue")}, - {"#666699", N_("dull purple")}, - {"#808080", N_("dark grey")}, - - - {"#FF0000", N_("red")}, - {"#FF9900", N_("orange")}, - {"#99CC00", N_("lime")}, - {"#339966", N_("dull green")}, - {"#33CCCC",N_("dull blue #2")}, - {"#3366FF", N_("sky blue #2")}, - {"#800080", N_("purple")}, - {"#969696", N_("gray")}, - - - {"#FF00FF", N_("magenta")}, - {"#FFCC00", N_("bright orange")}, - {"#FFFF00", N_("yellow")}, - {"#00FF00", N_("green")}, - {"#00FFFF", N_("cyan")}, - {"#00CCFF", N_("bright blue")}, - {"#993366", N_("red purple")}, - {"#C0C0C0", N_("light grey")}, - - - {"#FF99CC", N_("pink")}, - {"#FFCC99", N_("light orange")}, - {"#FFFF99", N_("light yellow")}, - {"#CCFFCC", N_("light green")}, - {"#CCFFFF", N_("light cyan")}, - {"#99CCFF", N_("light blue")}, - {"#CC99FF", N_("light purple")}, - {"#FFFFFF", N_("white")}, - - /* Disable these for now, they are mostly repeats */ - {NULL, NULL}, - - {"#9999FF", N_("purplish blue")}, - {"#993366", N_("red purple")}, - {"#FFFFCC", N_("light yellow")}, - {"#CCFFFF", N_("light blue")}, - {"#660066", N_("dark purple")}, - {"#FF8080", N_("pink")}, - {"#0066CC", N_("sky blue")}, - {"#CCCCFF", N_("light purple")}, - - {"#000080", N_("dark blue")}, - {"#FF00FF", N_("magenta")}, - {"#FFFF00", N_("yellow")}, - {"#00FFFF", N_("cyan")}, - {"#800080", N_("purple")}, - {"#800000", N_("dark red")}, - {"#008080", N_("dull blue")}, - {"#0000FF", N_("blue")}, - - {NULL, NULL} -}; - - - -/* - * Default constructor. Pass an optional label for - * the no/auto color button. - * - */ -GtkWidget* -color_palette_new (const char *no_color_label, - GdkColor *default_color, ColorGroup *color_group) -{ - /* specify 6 rows to allow for a row of custom colors */ - return color_palette_new_with_vals (no_color_label, - 8, 6, - default_color_set, default_color, - color_group); -} diff --git a/glabels2/src/mygal/color-palette.h b/glabels2/src/mygal/color-palette.h deleted file mode 100644 index b2b281c7..00000000 --- a/glabels2/src/mygal/color-palette.h +++ /dev/null @@ -1,113 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * color-palette.h - A color selector palette - * Copyright 2000, 2001, Ximian, Inc. - * - * Authors: - * This code was extracted from widget-color-combo.c - * written by Miguel de Icaza (miguel@kernel.org) and - * Dom Lachowicz (dominicl@seas.upenn.edu). The extracted - * code was re-packaged into a separate object by - * Michael Levy (mlevy@genoscope.cns.fr) - * And later revised and polished by - * Almer S. Tigelaar (almer@gnome.org) - * - * Modified for gLabels by: - * Jim Evins - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public - * License, version 2, as published by the Free Software Foundation. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - */ - -#ifndef GNUMERIC_COLOR_PALETTE_H -#define GNUMERIC_COLOR_PALETTE_H - -#include -#include -#include -#include -#include -#include "color-group.h" - -G_BEGIN_DECLS - -typedef struct _ColorNamePair ColorNamePair; - -typedef struct _ColorPalette { - GtkVBox vbox; - GtkTooltips *tool_tip; - GtkColorButton *picker; - /* - * Array of colors - */ - GnomeCanvasItem **items; - /* The (potentially NULL) default color */ - GdkColor *default_color; - - /* The current color */ - GdkColor *current_color; - gboolean current_is_default; - - /* - * Position of the last possible position - * for custom colors in **items - * (i.e. custom colors go from items[custom_color_pos] - * to items[total - 1]) - * - * If custom_color_pos == -1, there is no room for custom colors - */ - int custom_color_pos; - /* - * Number of default colors in **items - */ - int total; - - /* The table with our default color names */ - ColorNamePair *default_set; - - /* The color group to which we belong */ - ColorGroup *color_group; -} ColorPalette; - -typedef struct { - GtkVBoxClass parent_class; - - /* Signals emited by this widget */ - void (* color_changed) (ColorPalette *color_palette, GdkColor *color, - gboolean custom, gboolean by_user, gboolean is_default); -} ColorPaletteClass; - -#define COLOR_PALETTE_TYPE (color_palette_get_type ()) -#define COLOR_PALETTE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), COLOR_PALETTE_TYPE, ColorPalette)) -#define COLOR_PALETTE_CLASS(k) (G_TYPE_CHECK_CLASS_CAST(k), COLOR_PALETTE_TYPE) -#define IS_COLOR_PALETTE(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), COLOR_PALETTE_TYPE)) - -GtkType color_palette_get_type (void); - -GtkWidget *color_palette_new (const char *no_color_label, - GdkColor *default_color, - ColorGroup *color_group); -void color_palette_set_group (ColorPalette *P, - ColorGroup *cg); - -void color_palette_set_current_color (ColorPalette *P, GdkColor *color); -void color_palette_set_color_to_default (ColorPalette *P); -GdkColor *color_palette_get_current_color (ColorPalette *P, gboolean *is_default); -GtkWidget *color_palette_get_color_picker (ColorPalette *P); - -G_END_DECLS - -#endif /* GNUMERIC_PALETTE_H */ - - diff --git a/glabels2/src/mygal/e-colors.c b/glabels2/src/mygal/e-colors.c deleted file mode 100644 index fc4bf483..00000000 --- a/glabels2/src/mygal/e-colors.c +++ /dev/null @@ -1,106 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * e-colors.c - General color allocation utilities - * Copyright 2000, 2001, Ximian, Inc. - * - * Authors: - * Miguel de Icaza (miguel@kernel.org) - * - * Modified for gLabels by: - * Jim Evins - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public - * License, version 2, as published by the Free Software Foundation. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - */ - -/* We keep our own color context, as the color allocation might take - * place before things are realized. - */ - -#include -#include -#include "e-colors.h" - -GdkColor e_white, e_dark_gray, e_black; - -gulong -e_color_alloc (gushort red, gushort green, gushort blue) -{ - e_color_init (); - - red >>= 8; - green >>= 8; - blue >>= 8; - return gdk_rgb_xpixel_from_rgb ( - ((red & 0xff) << 16) | ((green & 0xff) << 8) | - (blue & 0xff)); -} - -void -e_color_alloc_gdk (GtkWidget *widget, GdkColor *c) -{ - GdkColormap *map; - - e_color_init (); - - if (widget) - map = gtk_widget_get_colormap (widget); - else /* FIXME: multi depth broken ? */ - map = gtk_widget_get_default_colormap (); - - gdk_rgb_find_color (map, c); -} - -void -e_color_alloc_name (GtkWidget *widget, const char *name, GdkColor *c) -{ - GdkColormap *map; - - e_color_init (); - - gdk_color_parse (name, c); - - if (widget) - map = gtk_widget_get_colormap (widget); - else /* FIXME: multi depth broken ? */ - map = gtk_widget_get_default_colormap (); - - gdk_rgb_find_color (map, c); -} - -void -e_color_init (void) -{ - static gboolean e_color_inited = FALSE; - - /* It's surprisingly easy to end up calling this twice. Survive. */ - if (e_color_inited) - return; - - e_color_inited = TRUE; - - /* Allocate the default colors */ - e_white.red = 65535; - e_white.green = 65535; - e_white.blue = 65535; - e_color_alloc_gdk (NULL, &e_white); - - e_black.red = 0; - e_black.green = 0; - e_black.blue = 0; - e_color_alloc_gdk (NULL, &e_black); - - e_color_alloc_name (NULL, "gray20", &e_dark_gray); -} - diff --git a/glabels2/src/mygal/e-colors.h b/glabels2/src/mygal/e-colors.h deleted file mode 100644 index 13665046..00000000 --- a/glabels2/src/mygal/e-colors.h +++ /dev/null @@ -1,47 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * e-colors.h - * Copyright 2000, 2001, Ximian, Inc. - * - * Authors: - * Miguel de Icaza (miguel@kernel.org) - * - * Modified for gLabels by: - * Jim Evins - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public - * License, version 2, as published by the Free Software Foundation. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - */ - -#ifndef GNOME_APP_LIBS_COLOR_H -#define GNOME_APP_LIBS_COLOR_H - -#include -#include -#include - -G_BEGIN_DECLS - -void e_color_init (void); - -/* Return the pixel value for the given red, green and blue */ -gulong e_color_alloc (gushort red, gushort green, gushort blue); -void e_color_alloc_name (GtkWidget *widget, const char *name, GdkColor *color); -void e_color_alloc_gdk (GtkWidget *widget, GdkColor *color); - -extern GdkColor e_white, e_dark_gray, e_black; - -G_END_DECLS - -#endif /* GNOME_APP_LIBS_COLOR_H */ diff --git a/glabels2/src/mygal/e-marshal.list b/glabels2/src/mygal/e-marshal.list deleted file mode 100644 index 92496dbd..00000000 --- a/glabels2/src/mygal/e-marshal.list +++ /dev/null @@ -1,51 +0,0 @@ -BOOLEAN:INT,INT,OBJECT,INT,INT,UINT -BOOLEAN:INT,POINTER,INT,OBJECT,INT,INT,UINT -BOOLEAN:NONE -BOOLEAN:OBJECT -BOOLEAN:OBJECT,DOUBLE,DOUBLE,BOOLEAN -BOOLEAN:POINTER,POINTER,INT,INT,INT -BOOLEAN:POINTER,POINTER,POINTER,INT,INT,INT -BOOLEAN:STRING,INT -DOUBLE:OBJECT,DOUBLE,DOUBLE,BOOLEAN -INT:BOXED -INT:INT -INT:INT,INT,BOXED -INT:INT,POINTER,INT,BOXED -INT:OBJECT,BOXED -INT:POINTER -NONE:BOXED -NONE:BOXED,INT -NONE:BOXED,INT,INT -NONE:DOUBLE -NONE:INT -NONE:INT,INT -NONE:INT,INT,BOXED -NONE:INT,INT,OBJECT -NONE:INT,INT,OBJECT,BOXED,UINT,UINT -NONE:INT,INT,OBJECT,INT,INT,BOXED,UINT,UINT -NONE:INT,INT,OBJECT,POINTER,UINT,UINT -NONE:INT,INT,OBJECT,UINT -NONE:INT,INT,STRING,STRING -NONE:INT,INT,STRING,STRING,POINTER -NONE:INT,POINTER -NONE:INT,POINTER,INT,BOXED -NONE:INT,POINTER,INT,OBJECT -NONE:INT,POINTER,INT,OBJECT,BOXED,UINT,UINT -NONE:INT,POINTER,INT,OBJECT,INT,INT,BOXED,UINT,UINT -NONE:INT,POINTER,INT,OBJECT,UINT -NONE:INT,STRING -NONE:NONE -NONE:OBJECT -NONE:OBJECT,OBJECT -NONE:OBJECT,DOUBLE,DOUBLE,BOOLEAN -NONE:POINTER -NONE:POINTER,BOOLEAN -NONE:POINTER,BOOLEAN,BOOLEAN,BOOLEAN -NONE:POINTER,INT -NONE:POINTER,INT,INT -NONE:POINTER,INT,INT,INT -NONE:POINTER,INT,OBJECT -NONE:POINTER,POINTER -NONE:POINTER,POINTER,INT -OBJECT:OBJECT,DOUBLE,DOUBLE,BOOLEAN -POINTER:NONE diff --git a/glabels2/src/mygal/e-util.h b/glabels2/src/mygal/e-util.h deleted file mode 100644 index 7bc39783..00000000 --- a/glabels2/src/mygal/e-util.h +++ /dev/null @@ -1,234 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * e-util.h - * Copyright 2000, 2001, Ximian, Inc. - * - * Authors: - * Chris Lahey - * - * Modified for gLabels by: - * Jim Evins - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public - * License, version 2, as published by the Free Software Foundation. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - */ - -#ifndef _E_UTIL_H_ -#define _E_UTIL_H_ - -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#pragma } -#endif /* __cplusplus */ - -#include "e-marshal.h" - -#define E_MAKE_TYPE(l,str,t,ci,i,parent) \ -GType l##_get_type(void)\ -{\ - static GType type = 0; \ - if (!type){ \ - static GTypeInfo const object_info = { \ - sizeof (t##Class), \ - \ - (GBaseInitFunc) NULL, \ - (GBaseFinalizeFunc) NULL, \ - \ - (GClassInitFunc) ci, \ - (GClassFinalizeFunc) NULL, \ - NULL, /* class_data */ \ - \ - sizeof (t), \ - 0, /* n_preallocs */ \ - (GInstanceInitFunc) i, \ - }; \ - type = g_type_register_static (parent, str, &object_info, 0); \ - } \ - return type; \ -} - - -#define E_MAKE_X_TYPE(l,str,t,ci,i,parent,poa_init,offset) \ -GtkType l##_get_type(void) \ -{ \ - static GtkType type = 0; \ - if (!type){ \ - GTypeInfo info = { \ - sizeof (t##Class), \ - \ - (GBaseInitFunc) NULL, \ - (GBaseFinalizeFunc) NULL, \ - \ - (GClassInitFunc) ci, \ - (GClassFinalizeFunc) NULL, \ - \ - NULL, /* class_data */ \ - \ - sizeof (t), \ - 0, /* n_preallocs */ \ - (GInstanceInitFunc) i, \ - }; \ - type = bonobo_x_type_unique ( \ - parent, poa_init, NULL, \ - offset, &info, str); \ - } \ - return type; \ -} - -#define GET_STRING_ARRAY_FROM_ELLIPSIS(labels, first_string) \ - { \ - va_list args; \ - int i; \ - char *s; \ - \ - va_start (args, (first_string)); \ - \ - i = 0; \ - for (s = (first_string); s; s = va_arg (args, char *)) \ - i++; \ - va_end (args); \ - \ - (labels) = g_new (char *, i + 1); \ - \ - va_start (args, (first_string)); \ - i = 0; \ - for (s = (first_string); s; s = va_arg (args, char *)) \ - (labels)[i++] = s; \ - \ - va_end (args); \ - (labels)[i] = NULL; \ - } - - -#define GET_DUPLICATED_STRING_ARRAY_FROM_ELLIPSIS(labels, first_string) \ - { \ - int i; \ - GET_STRING_ARRAY_FROM_ELLIPSIS ((labels), (first_string)); \ - for (i = 0; labels[i]; i++) \ - labels[i] = g_strdup (labels[i]); \ - } - - -#if 0 -# define E_OBJECT_CLASS_ADD_SIGNALS(oc,sigs,last) \ - gtk_object_class_add_signals (oc, sigs, last) -# define E_OBJECT_CLASS_TYPE(oc) (oc)->type -#else -# define E_OBJECT_CLASS_ADD_SIGNALS(oc,sigs,last) -# define E_OBJECT_CLASS_TYPE(oc) G_TYPE_FROM_CLASS (oc) -#endif - - -typedef enum { - E_FOCUS_NONE, - E_FOCUS_CURRENT, - E_FOCUS_START, - E_FOCUS_END -} EFocus; -int g_str_compare (const void *x, - const void *y); -int g_collate_compare (const void *x, - const void *y); -int g_int_compare (const void *x, - const void *y); -char *e_strdup_strip (const char *string); -void e_free_object_list (GList *list); -void e_free_object_slist (GSList *list); -void e_free_string_list (GList *list); -void e_free_string_slist (GSList *list); -char *e_read_file (const char *filename); -int e_write_file (const char *filename, - const char *data, - int flags); -int e_write_file_mkstemp (char *filename, - const char *data); -int e_mkdir_hier (const char *path, - mode_t mode); - -gchar **e_strsplit (const gchar *string, - const gchar *delimiter, - gint max_tokens); -gchar *e_strstrcase (const gchar *haystack, - const gchar *needle); -/* This only makes a filename safe for usage as a filename. It still may have shell meta-characters in it. */ -void e_filename_make_safe (gchar *string); -gchar *e_format_number (gint number); -gchar *e_format_number_float (gfloat number); -gboolean e_create_directory (gchar *directory); -gchar **e_strdupv (const gchar **str_array); - - -typedef int (*ESortCompareFunc) (const void *first, - const void *second, - gpointer closure); -void e_sort (void *base, - size_t nmemb, - size_t size, - ESortCompareFunc compare, - gpointer closure); -void e_bsearch (const void *key, - const void *base, - size_t nmemb, - size_t size, - ESortCompareFunc compare, - gpointer closure, - size_t *start, - size_t *end); -size_t e_strftime_fix_am_pm (char *s, - size_t max, - const char *fmt, - const struct tm *tm); - -size_t e_strftime (char *s, - size_t max, - const char *fmt, - const struct tm *tm); - -size_t e_utf8_strftime_fix_am_pm (char *s, - size_t max, - const char *fmt, - const struct tm *tm); - -size_t e_utf8_strftime (char *s, - size_t max, - const char *fmt, - const struct tm *tm); - -/* String to/from double conversion functions */ -gdouble e_flexible_strtod (const gchar *nptr, - gchar **endptr); - -/* 29 bytes should enough for all possible values that - * g_ascii_dtostr can produce with the %.17g format. - * Then add 10 for good measure */ -#define E_ASCII_DTOSTR_BUF_SIZE (DBL_DIG + 12 + 10) -gchar *e_ascii_dtostr (gchar *buffer, - gint buf_len, - const gchar *format, - gdouble d); - -/* Alternating char * and int arguments with a NULL char * to end. - Less than 0 for the int means copy the whole string. */ -gchar *e_strdup_append_strings (gchar *first_string, - ...); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* _E_UTIL_H_ */ diff --git a/glabels2/src/mygal/mygal-combo-box.c b/glabels2/src/mygal/mygal-combo-box.c deleted file mode 100644 index adf1c648..00000000 --- a/glabels2/src/mygal/mygal-combo-box.c +++ /dev/null @@ -1,837 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * mygal-combo-box.c - a customizable combobox - * Copyright 2000, 2001, Ximian, Inc. - * - * Authors: - * Miguel de Icaza (miguel@gnu.org) - * Adrian E Feiguin (feiguin@ifir.edu.ar) - * Paolo Molnaro (lupus@debian.org). - * Jon K Hellan (hellan@acm.org) - * - * Modified for gLabels by: - * Jim Evins - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public - * License, version 2, as published by the Free Software Foundation. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "mygal-combo-box.h" -#include "e-util.h" - -#define PARENT_TYPE GTK_TYPE_HBOX -static GObjectClass *mygal_combo_box_parent_class; - -static int mygal_combo_toggle_pressed (GtkToggleButton *tbutton, - MygalComboBox *combo_box); -static void mygal_combo_popup_tear_off (MygalComboBox *combo, - gboolean set_position); -static void mygal_combo_set_tearoff_state (MygalComboBox *combo, - gboolean torn_off); -static void mygal_combo_popup_reparent (GtkWidget *popup, GtkWidget *new_parent, - gboolean unrealize); -static gboolean cb_popup_delete (GtkWidget *w, GdkEventAny *event, - MygalComboBox *combo); -static void mygal_combo_tearoff_bg_copy (MygalComboBox *combo); - -enum { - POP_DOWN_WIDGET, - POP_DOWN_DONE, - PRE_POP_DOWN, - POST_POP_HIDE, - LAST_SIGNAL -}; - -static guint mygal_combo_box_signals [LAST_SIGNAL] = { 0, }; - -struct _MygalComboBoxPrivate { - GtkWidget *pop_down_widget; - GtkWidget *display_widget; - - /* - * Internal widgets used to implement the ComboBox - */ - GtkWidget *frame; - GtkWidget *arrow_button; - - GtkWidget *toplevel; /* Popup's toplevel when not torn off */ - GtkWidget *tearoff_window; /* Popup's toplevel when torn off */ - guint torn_off; - - GtkWidget *tearable; /* The tearoff "button" */ - GtkWidget *popup; /* Popup */ - - /* - * Closure for invoking the callbacks above - */ - void *closure; -}; - -static void -mygal_combo_box_finalize (GObject *object) -{ - MygalComboBox *combo_box = MYGAL_COMBO_BOX (object); - - g_free (combo_box->priv); - - mygal_combo_box_parent_class->finalize (object); -} - -static void -mygal_combo_box_destroy (GtkObject *object) -{ - GtkObjectClass *klass = (GtkObjectClass *)mygal_combo_box_parent_class; - MygalComboBox *combo_box = MYGAL_COMBO_BOX (object); - - if (combo_box->priv->toplevel) { - gtk_object_destroy (GTK_OBJECT (combo_box->priv->toplevel)); - combo_box->priv->toplevel = NULL; - } - - if (combo_box->priv->tearoff_window) { - gtk_object_destroy (GTK_OBJECT (combo_box->priv->tearoff_window)); - combo_box->priv->tearoff_window = NULL; - } - - if (klass->destroy) - klass->destroy (object); -} - -static gboolean -mygal_combo_box_mnemonic_activate (GtkWidget *w, gboolean group_cycling) -{ - MygalComboBox *combo_box = MYGAL_COMBO_BOX (w); - gtk_toggle_button_set_active ( - GTK_TOGGLE_BUTTON (combo_box->priv->arrow_button), TRUE); - return TRUE; -} - -static void -mygal_combo_box_class_init (GObjectClass *object_class) -{ - GtkWidgetClass *widget_class = (GtkWidgetClass *)object_class; - mygal_combo_box_parent_class = g_type_class_peek_parent (object_class); - - object_class->finalize = mygal_combo_box_finalize; - widget_class->mnemonic_activate = mygal_combo_box_mnemonic_activate; - ((GtkObjectClass *)object_class)->destroy = mygal_combo_box_destroy; - - mygal_combo_box_signals [POP_DOWN_WIDGET] = g_signal_new ( - "pop_down_widget", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (MygalComboBoxClass, pop_down_widget), - NULL, NULL, - e_marshal_POINTER__NONE, - G_TYPE_POINTER, 0, G_TYPE_NONE); - - mygal_combo_box_signals [POP_DOWN_DONE] = g_signal_new ( - "pop_down_done", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (MygalComboBoxClass, pop_down_done), - NULL, NULL, - e_marshal_BOOLEAN__OBJECT, - G_TYPE_BOOLEAN, 1, G_TYPE_OBJECT); - - mygal_combo_box_signals [PRE_POP_DOWN] = g_signal_new ( - "pre_pop_down", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (MygalComboBoxClass, pre_pop_down), - NULL, NULL, - e_marshal_NONE__NONE, - G_TYPE_NONE, 0); - - mygal_combo_box_signals [POST_POP_HIDE] = g_signal_new ( - "post_pop_hide", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (MygalComboBoxClass, post_pop_hide), - NULL, NULL, - e_marshal_NONE__NONE, - G_TYPE_NONE, 0); -} - -static void -deactivate_arrow (MygalComboBox *combo_box) -{ - GtkToggleButton *arrow; - - arrow = GTK_TOGGLE_BUTTON (combo_box->priv->arrow_button); - g_signal_handlers_block_matched (arrow, - G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, - 0, 0, NULL, - mygal_combo_toggle_pressed, combo_box); - - gtk_toggle_button_set_active (arrow, FALSE); - - g_signal_handlers_unblock_matched (arrow, - G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, - 0, 0, NULL, - mygal_combo_toggle_pressed, combo_box); -} - -/** - * mygal_combo_box_popup_hide_unconditional - * @combo_box: Combo box - * - * Hide popup, whether or not it is torn off. - */ -static void -mygal_combo_box_popup_hide_unconditional (MygalComboBox *combo_box) -{ - gboolean popup_info_destroyed = FALSE; - - g_return_if_fail (combo_box != NULL); - g_return_if_fail (MYGAL_IS_COMBO_BOX (combo_box)); - - gtk_widget_hide (combo_box->priv->toplevel); - gtk_widget_hide (combo_box->priv->popup); - if (combo_box->priv->torn_off) { - GTK_TEAROFF_MENU_ITEM (combo_box->priv->tearable)->torn_off - = FALSE; - mygal_combo_set_tearoff_state (combo_box, FALSE); - } - - gtk_grab_remove (combo_box->priv->toplevel); - gdk_pointer_ungrab (GDK_CURRENT_TIME); - - g_object_ref (combo_box->priv->pop_down_widget); - g_signal_emit (combo_box, - mygal_combo_box_signals [POP_DOWN_DONE], 0, - combo_box->priv->pop_down_widget, &popup_info_destroyed); - - if (popup_info_destroyed){ - gtk_container_remove ( - GTK_CONTAINER (combo_box->priv->frame), - combo_box->priv->pop_down_widget); - combo_box->priv->pop_down_widget = NULL; - } - g_object_unref (combo_box->priv->pop_down_widget); - deactivate_arrow (combo_box); - - g_signal_emit (combo_box, mygal_combo_box_signals [POST_POP_HIDE], 0); -} - -/** - * mygal_combo_box_popup_hide: - * @combo_box: Combo box - * - * Hide popup, but not when it is torn off. - * This is the external interface - for subclasses and apps which expect a - * regular combo which doesn't do tearoffs. - */ -void -mygal_combo_box_popup_hide (MygalComboBox *combo_box) -{ - if (!combo_box->priv->torn_off) - mygal_combo_box_popup_hide_unconditional (combo_box); - else if (GTK_WIDGET_VISIBLE (combo_box->priv->toplevel)) { - /* Both popup and tearoff window present. Get rid of just - the popup shell. */ - mygal_combo_popup_tear_off (combo_box, FALSE); - deactivate_arrow (combo_box); - } -} - -/* - * Find best location for displaying - */ -void -mygal_combo_box_get_pos (MygalComboBox *combo_box, int *x, int *y) -{ - GtkWidget *wcombo = GTK_WIDGET (combo_box); - int ph, pw; - - gdk_window_get_origin (wcombo->window, x, y); - *y += wcombo->allocation.height + wcombo->allocation.y; - *x += wcombo->allocation.x; - - ph = combo_box->priv->popup->allocation.height; - pw = combo_box->priv->popup->allocation.width; - - if ((*y + ph) > gdk_screen_height ()) - *y = gdk_screen_height () - ph; - - if ((*x + pw) > gdk_screen_width ()) - *x = gdk_screen_width () - pw; -} - -static void -mygal_combo_box_popup_display (MygalComboBox *combo_box) -{ - int x, y; - - g_return_if_fail (combo_box != NULL); - g_return_if_fail (MYGAL_IS_COMBO_BOX (combo_box)); - - /* - * If we have no widget to display on the popdown, - * create it - */ - if (!combo_box->priv->pop_down_widget){ - GtkWidget *pw = NULL; - - g_signal_emit (combo_box, - mygal_combo_box_signals [POP_DOWN_WIDGET], 0, &pw); - g_assert (pw != NULL); - combo_box->priv->pop_down_widget = pw; - gtk_container_add (GTK_CONTAINER (combo_box->priv->frame), pw); - } - - g_signal_emit (combo_box, mygal_combo_box_signals [PRE_POP_DOWN], 0); - - if (combo_box->priv->torn_off) { - /* To give the illusion that tearoff still displays the - * popup, we copy the image in the popup window to the - * background. Thus, it won't be blank after reparenting */ - mygal_combo_tearoff_bg_copy (combo_box); - - /* We force an unrealize here so that we don't trigger - * redrawing/ clearing code - we just want to reveal our - * backing pixmap. - */ - mygal_combo_popup_reparent (combo_box->priv->popup, - combo_box->priv->toplevel, TRUE); - } - - mygal_combo_box_get_pos (combo_box, &x, &y); - - gtk_widget_set_uposition (combo_box->priv->toplevel, x, y); - gtk_widget_realize (combo_box->priv->popup); - gtk_widget_show (combo_box->priv->popup); - gtk_widget_realize (combo_box->priv->toplevel); - gtk_widget_show (combo_box->priv->toplevel); - - gtk_grab_add (combo_box->priv->toplevel); - gdk_pointer_grab (combo_box->priv->toplevel->window, TRUE, - GDK_BUTTON_PRESS_MASK | - GDK_BUTTON_RELEASE_MASK | - GDK_POINTER_MOTION_MASK, - NULL, NULL, GDK_CURRENT_TIME); -} - -static int -mygal_combo_toggle_pressed (GtkToggleButton *tbutton, MygalComboBox *combo_box) -{ - if (tbutton->active) - mygal_combo_box_popup_display (combo_box); - else - mygal_combo_box_popup_hide_unconditional (combo_box); - - return TRUE; -} - -static gint -mygal_combo_box_button_press (GtkWidget *widget, GdkEventButton *event, MygalComboBox *combo_box) -{ - GtkWidget *child; - - child = gtk_get_event_widget ((GdkEvent *) event); - if (child != widget){ - while (child){ - if (child == widget) - return FALSE; - child = child->parent; - } - } - - mygal_combo_box_popup_hide (combo_box); - return TRUE; -} - -/** - * mygal_combo_box_key_press - * @widget: Widget - * @event: Event - * @combo_box: Combo box - * - * Key press handler which dismisses popup on escape. - * Popup is dismissed whether or not popup is torn off. - */ -static gint -mygal_combo_box_key_press (GtkWidget *widget, GdkEventKey *event, - MygalComboBox *combo_box) -{ - if (event->keyval == GDK_Escape) { - mygal_combo_box_popup_hide_unconditional (combo_box); - return TRUE; - } else - return FALSE; -} - -static void -cb_state_change (GtkWidget *widget, GtkStateType old_state, MygalComboBox *combo_box) -{ - GtkStateType const new_state = GTK_WIDGET_STATE(widget); - gtk_widget_set_state (combo_box->priv->display_widget, new_state); -} - -static void -mygal_combo_box_init (MygalComboBox *combo_box) -{ - GtkWidget *arrow; - GdkCursor *cursor; - - combo_box->priv = g_new0 (MygalComboBoxPrivate, 1); - - /* - * Create the arrow - */ - combo_box->priv->arrow_button = gtk_toggle_button_new (); - gtk_button_set_relief (GTK_BUTTON (combo_box->priv->arrow_button), GTK_RELIEF_NONE); - GTK_WIDGET_UNSET_FLAGS (combo_box->priv->arrow_button, GTK_CAN_FOCUS); - - arrow = gtk_arrow_new (GTK_ARROW_DOWN, GTK_SHADOW_IN); - gtk_container_add (GTK_CONTAINER (combo_box->priv->arrow_button), arrow); - gtk_box_pack_end (GTK_BOX (combo_box), combo_box->priv->arrow_button, FALSE, FALSE, 0); - g_signal_connect (combo_box->priv->arrow_button, "toggled", - G_CALLBACK (mygal_combo_toggle_pressed), combo_box); - gtk_widget_show_all (combo_box->priv->arrow_button); - - /* - * prelight the display widget when mousing over the arrow. - */ - g_signal_connect (combo_box->priv->arrow_button, "state-changed", - G_CALLBACK (cb_state_change), combo_box); - - /* - * The pop-down container - */ - - combo_box->priv->toplevel = gtk_window_new (GTK_WINDOW_POPUP); - gtk_widget_ref (combo_box->priv->toplevel); - gtk_object_sink (GTK_OBJECT (combo_box->priv->toplevel)); - gtk_window_set_policy (GTK_WINDOW (combo_box->priv->toplevel), - FALSE, TRUE, FALSE); - - combo_box->priv->popup = gtk_event_box_new (); - gtk_container_add (GTK_CONTAINER (combo_box->priv->toplevel), - combo_box->priv->popup); - gtk_widget_show (combo_box->priv->popup); - - gtk_widget_realize (combo_box->priv->popup); - cursor = gdk_cursor_new (GDK_TOP_LEFT_ARROW); - gdk_window_set_cursor (combo_box->priv->popup->window, cursor); - gdk_cursor_unref (cursor); - - combo_box->priv->torn_off = FALSE; - combo_box->priv->tearoff_window = NULL; - - combo_box->priv->frame = gtk_frame_new (NULL); - gtk_container_add (GTK_CONTAINER (combo_box->priv->popup), - combo_box->priv->frame); - gtk_frame_set_shadow_type (GTK_FRAME (combo_box->priv->frame), GTK_SHADOW_OUT); - - g_signal_connect (combo_box->priv->toplevel, "button_press_event", - G_CALLBACK (mygal_combo_box_button_press), combo_box); - g_signal_connect (combo_box->priv->toplevel, "key_press_event", - G_CALLBACK (mygal_combo_box_key_press), combo_box); -} - -E_MAKE_TYPE (mygal_combo_box, - "MygalComboBox", - MygalComboBox, - mygal_combo_box_class_init, - mygal_combo_box_init, - PARENT_TYPE) - -/** - * mygal_combo_box_set_display: - * @combo_box: the Combo Box to modify - * @display_widget: The widget to be displayed - - * Sets the displayed widget for the @combo_box to be @display_widget - */ -void -mygal_combo_box_set_display (MygalComboBox *combo_box, GtkWidget *display_widget) -{ - g_return_if_fail (combo_box != NULL); - g_return_if_fail (MYGAL_IS_COMBO_BOX (combo_box)); - g_return_if_fail (display_widget != NULL); - g_return_if_fail (GTK_IS_WIDGET (display_widget)); - - if (combo_box->priv->display_widget && - combo_box->priv->display_widget != display_widget) - gtk_container_remove (GTK_CONTAINER (combo_box), - combo_box->priv->display_widget); - - combo_box->priv->display_widget = display_widget; - - gtk_box_pack_start (GTK_BOX (combo_box), display_widget, TRUE, TRUE, 0); -} - -static gboolean -cb_tearable_enter_leave (GtkWidget *w, GdkEventCrossing *event, gpointer data) -{ - gboolean const flag = GPOINTER_TO_INT(data); - gtk_widget_set_state (w, flag ? GTK_STATE_PRELIGHT : GTK_STATE_NORMAL); - return FALSE; -} - -/** - * mygal_combo_popup_tear_off - * @combo: Combo box - * @set_position: Set to position of popup shell if true - * - * Tear off the popup - * - * FIXME: - * Gtk popup menus are toplevel windows, not dialogs. I think this is wrong, - * and make the popups dialogs. But may be there should be a way to make - * them toplevel. We can do this after creating: - * GTK_WINDOW (tearoff)->type = GTK_WINDOW_TOPLEVEL; - */ -static void -mygal_combo_popup_tear_off (MygalComboBox *combo, gboolean set_position) -{ - int x, y; - - if (!combo->priv->tearoff_window) { - GtkWidget *tearoff; - gchar *title; - - /* FIXME: made this a toplevel, not a dialog ! */ - tearoff = gtk_window_new (GTK_WINDOW_TOPLEVEL); - gtk_widget_ref (tearoff); - gtk_object_sink (GTK_OBJECT (tearoff)); - combo->priv->tearoff_window = tearoff; - gtk_widget_set_app_paintable (tearoff, TRUE); - g_signal_connect (tearoff, "key_press_event", - G_CALLBACK (mygal_combo_box_key_press), - combo); - gtk_widget_realize (tearoff); - title = g_object_get_data (G_OBJECT (combo), - "gtk-combo-title"); - if (title) - gdk_window_set_title (tearoff->window, title); - gtk_window_set_policy (GTK_WINDOW (tearoff), - FALSE, TRUE, FALSE); - gtk_window_set_transient_for - (GTK_WINDOW (tearoff), - GTK_WINDOW (gtk_widget_get_toplevel - GTK_WIDGET (combo))); - } - - if (GTK_WIDGET_VISIBLE (combo->priv->popup)) { - gtk_widget_hide (combo->priv->toplevel); - - gtk_grab_remove (combo->priv->toplevel); - gdk_pointer_ungrab (GDK_CURRENT_TIME); - } - - mygal_combo_popup_reparent (combo->priv->popup, - combo->priv->tearoff_window, FALSE); - - /* It may have got confused about size */ - gtk_widget_queue_resize (GTK_WIDGET (combo->priv->popup)); - - if (set_position) { - mygal_combo_box_get_pos (combo, &x, &y); - gtk_widget_set_uposition (combo->priv->tearoff_window, x, y); - } - gtk_widget_show (GTK_WIDGET (combo->priv->popup)); - gtk_widget_show (combo->priv->tearoff_window); - -} - -/** - * mygal_combo_set_tearoff_state - * @combo_box: Combo box - * @torn_off: TRUE: Tear off. FALSE: Pop down and reattach - * - * Set the tearoff state of the popup - * - * Compare with gtk_menu_set_tearoff_state in gtk/gtkmenu.c - */ -static void -mygal_combo_set_tearoff_state (MygalComboBox *combo, - gboolean torn_off) -{ - g_return_if_fail (combo != NULL); - g_return_if_fail (MYGAL_IS_COMBO_BOX (combo)); - - if (combo->priv->torn_off != torn_off) { - combo->priv->torn_off = torn_off; - - if (combo->priv->torn_off) { - mygal_combo_popup_tear_off (combo, TRUE); - deactivate_arrow (combo); - } else { - gtk_widget_hide (combo->priv->tearoff_window); - mygal_combo_popup_reparent (combo->priv->popup, - combo->priv->toplevel, - FALSE); - } - } -} - -/** - * mygal_combo_tearoff_bg_copy - * @combo_box: Combo box - * - * Copy popup window image to the tearoff window. - */ -static void -mygal_combo_tearoff_bg_copy (MygalComboBox *combo) -{ - GdkPixmap *pixmap; - GdkGC *gc; - GdkGCValues gc_values; - - GtkWidget *widget = combo->priv->popup; - - if (combo->priv->torn_off) { - gc_values.subwindow_mode = GDK_INCLUDE_INFERIORS; - gc = gdk_gc_new_with_values (widget->window, - &gc_values, GDK_GC_SUBWINDOW); - - pixmap = gdk_pixmap_new (widget->window, - widget->allocation.width, - widget->allocation.height, - -1); - - gdk_draw_drawable (pixmap, gc, - widget->window, - 0, 0, 0, 0, -1, -1); - gdk_gc_unref (gc); - - gtk_widget_set_usize (combo->priv->tearoff_window, - widget->allocation.width, - widget->allocation.height); - - gdk_window_set_back_pixmap - (combo->priv->tearoff_window->window, pixmap, FALSE); - gdk_drawable_unref (pixmap); - } -} - -/** - * mygal_combo_popup_reparent - * @popup: Popup - * @new_parent: New parent - * @unrealize: Unrealize popup if TRUE. - * - * Reparent the popup, taking care of the refcounting - * - * Compare with gtk_menu_reparent in gtk/gtkmenu.c - */ -static void -mygal_combo_popup_reparent (GtkWidget *popup, - GtkWidget *new_parent, - gboolean unrealize) -{ - GtkObject *object = GTK_OBJECT (popup); - gboolean was_floating = GTK_OBJECT_FLOATING (object); - - g_object_ref (object); - gtk_object_sink (object); - - if (unrealize) { - g_object_ref (object); - gtk_container_remove (GTK_CONTAINER (popup->parent), popup); - gtk_container_add (GTK_CONTAINER (new_parent), popup); - g_object_unref (object); - } - else - gtk_widget_reparent (GTK_WIDGET (popup), new_parent); - gtk_widget_set_usize (new_parent, -1, -1); - - if (was_floating) - GTK_OBJECT_SET_FLAGS (object, GTK_FLOATING); - else - g_object_unref (object); -} - -/** - * cb_tearable_button_release - * @w: Widget - * @event: Event - * @combo: Combo box - * - * Toggle tearoff state. - */ -static gboolean -cb_tearable_button_release (GtkWidget *w, GdkEventButton *event, - MygalComboBox *combo) -{ - GtkTearoffMenuItem *tearable; - - g_return_val_if_fail (w != NULL, FALSE); - g_return_val_if_fail (GTK_IS_TEAROFF_MENU_ITEM (w), FALSE); - - tearable = GTK_TEAROFF_MENU_ITEM (w); - tearable->torn_off = !tearable->torn_off; - - if (!combo->priv->torn_off) { - gboolean need_connect; - - need_connect = (!combo->priv->tearoff_window); - mygal_combo_set_tearoff_state (combo, TRUE); - if (need_connect) - g_signal_connect (combo->priv->tearoff_window, - "delete_event", - G_CALLBACK (cb_popup_delete), - combo); - } else - mygal_combo_box_popup_hide_unconditional (combo); - - return TRUE; -} - -static gboolean -cb_popup_delete (GtkWidget *w, GdkEventAny *event, MygalComboBox *combo) -{ - mygal_combo_box_popup_hide_unconditional (combo); - return TRUE; -} - -void -mygal_combo_box_construct (MygalComboBox *combo_box, GtkWidget *display_widget, GtkWidget *pop_down_widget) -{ - GtkWidget *tearable; - GtkWidget *vbox; - - g_return_if_fail (combo_box != NULL); - g_return_if_fail (MYGAL_IS_COMBO_BOX (combo_box)); - g_return_if_fail (display_widget != NULL); - g_return_if_fail (GTK_IS_WIDGET (display_widget)); - - GTK_BOX (combo_box)->spacing = 0; - GTK_BOX (combo_box)->homogeneous = FALSE; - - combo_box->priv->pop_down_widget = pop_down_widget; - combo_box->priv->display_widget = NULL; - - vbox = gtk_vbox_new (FALSE, 5); - tearable = gtk_tearoff_menu_item_new (); - g_signal_connect (tearable, "enter-notify-event", - G_CALLBACK (cb_tearable_enter_leave), - GINT_TO_POINTER (TRUE)); - g_signal_connect (tearable, "leave-notify-event", - G_CALLBACK (cb_tearable_enter_leave), - GINT_TO_POINTER (FALSE)); - g_signal_connect (tearable, "button-release-event", - G_CALLBACK (cb_tearable_button_release), - (gpointer) combo_box); - gtk_box_pack_start (GTK_BOX (vbox), tearable, FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX (vbox), pop_down_widget, TRUE, TRUE, 0); - combo_box->priv->tearable = tearable; - - /* - * Finish setup - */ - mygal_combo_box_set_display (combo_box, display_widget); - - gtk_container_add (GTK_CONTAINER (combo_box->priv->frame), vbox); - gtk_widget_show_all (combo_box->priv->frame); -} - -GtkWidget * -mygal_combo_box_new (GtkWidget *display_widget, GtkWidget *optional_popdown) -{ - MygalComboBox *combo_box; - - g_return_val_if_fail (display_widget != NULL, NULL); - g_return_val_if_fail (GTK_IS_WIDGET (display_widget), NULL); - - combo_box = g_object_new (MYGAL_COMBO_BOX_TYPE, NULL); - mygal_combo_box_construct (combo_box, display_widget, optional_popdown); - return GTK_WIDGET (combo_box); -} - -void -mygal_combo_box_set_arrow_relief (MygalComboBox *cc, GtkReliefStyle relief) -{ - g_return_if_fail (cc != NULL); - g_return_if_fail (MYGAL_IS_COMBO_BOX (cc)); - - gtk_button_set_relief (GTK_BUTTON (cc->priv->arrow_button), relief); -} - -/** - * mygal_combo_box_set_title - * @combo: Combo box - * @title: Title - * - * Set a title to display over the tearoff window. - * - * FIXME: - * - * This should really change the title even when the popup is already torn off. - * I guess the tearoff window could attach a listener to title change or - * something. But I don't think we need the functionality, so I didn't bother - * to investigate. - */ -void -mygal_combo_box_set_title (MygalComboBox *combo, - const gchar *title) -{ - g_return_if_fail (combo != NULL); - g_return_if_fail (MYGAL_IS_COMBO_BOX (combo)); - - g_object_set_data_full (G_OBJECT (combo), "gtk-combo-title", - g_strdup (title), (GDestroyNotify) g_free); -} - -/** - * mygal_combo_box_set_arrow_sensitive - * @combo: Combo box - * @sensitive: Sensitivity value - * - * Toggle the sensitivity of the arrow button - */ - -void -mygal_combo_box_set_arrow_sensitive (MygalComboBox *combo, - gboolean sensitive) -{ - g_return_if_fail (combo != NULL); - - gtk_widget_set_sensitive (combo->priv->arrow_button, sensitive); -} - -/** - * mygal_combo_box_set_tearable: - * @combo: Combo box - * @tearable: whether to allow the @combo to be tearable - * - * controls whether the combo box's pop up widget can be torn off. - */ -void -mygal_combo_box_set_tearable (MygalComboBox *combo, gboolean tearable) -{ - g_return_if_fail (combo != NULL); - g_return_if_fail (MYGAL_IS_COMBO_BOX (combo)); - - if (tearable){ - gtk_widget_show (combo->priv->tearable); - } else { - mygal_combo_set_tearoff_state (combo, FALSE); - gtk_widget_hide (combo->priv->tearable); - } -} diff --git a/glabels2/src/mygal/mygal-combo-box.h b/glabels2/src/mygal/mygal-combo-box.h deleted file mode 100644 index e1785f2d..00000000 --- a/glabels2/src/mygal/mygal-combo-box.h +++ /dev/null @@ -1,94 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * mygal-combo-box.h - a customizable combobox - * Copyright 2000, 2001, Ximian, Inc. - * - * Authors: - * Miguel de Icaza - * - * Modified for gLabels by: - * Jim Evins - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public - * License, version 2, as published by the Free Software Foundation. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - */ - -#ifndef _MYGAL_COMBO_BOX_H_ -#define _MYGAL_COMBO_BOX_H_ - -#include - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#define MYGAL_COMBO_BOX_TYPE (mygal_combo_box_get_type()) -#define MYGAL_COMBO_BOX(obj) G_TYPE_CHECK_INSTANCE_CAST (obj, mygal_combo_box_get_type (), MygalComboBox) -#define MYGAL_COMBO_BOX_CLASS(klass) G_TYPE_CHECK_CLASS_CAST (klass, mygal_combo_box_get_type (), MygalComboBoxClass) -#define MYGAL_IS_COMBO_BOX(obj) G_TYPE_CHECK_INSTANCE_TYPE (obj, mygal_combo_box_get_type ()) - -typedef struct _MygalComboBox MygalComboBox; -typedef struct _MygalComboBoxPrivate MygalComboBoxPrivate; -typedef struct _MygalComboBoxClass MygalComboBoxClass; - -struct _MygalComboBox { - GtkHBox hbox; - MygalComboBoxPrivate *priv; -}; - -struct _MygalComboBoxClass { - GtkHBoxClass parent_class; - - GtkWidget *(*pop_down_widget) (MygalComboBox *cbox); - - /* - * invoked when the popup has been hidden, if the signal - * returns TRUE, it means it should be killed from the - */ - gboolean *(*pop_down_done) (MygalComboBox *cbox, GtkWidget *); - - /* - * Notification signals. - */ - void (*pre_pop_down) (MygalComboBox *cbox); - void (*post_pop_hide) (MygalComboBox *cbox); -}; - -GtkType mygal_combo_box_get_type (void); -void mygal_combo_box_construct (MygalComboBox *combo_box, - GtkWidget *display_widget, - GtkWidget *optional_pop_down_widget); -void mygal_combo_box_get_pos (MygalComboBox *combo_box, int *x, int *y); - -GtkWidget *mygal_combo_box_new (GtkWidget *display_widget, - GtkWidget *optional_pop_down_widget); -void mygal_combo_box_popup_hide (MygalComboBox *combo_box); - -void mygal_combo_box_set_display (MygalComboBox *combo_box, - GtkWidget *display_widget); - -void mygal_combo_box_set_title (MygalComboBox *combo, - const gchar *title); - -void mygal_combo_box_set_tearable (MygalComboBox *combo, - gboolean tearable); -void mygal_combo_box_set_arrow_sensitive (MygalComboBox *combo, - gboolean sensitive); -void mygal_combo_box_set_arrow_relief (MygalComboBox *cc, - GtkReliefStyle relief); -#ifdef __cplusplus -}; -#endif /* __cplusplus */ - -#endif /* _MYGAL_COMBO_BOX_H_ */ diff --git a/glabels2/src/mygal/widget-color-combo.c b/glabels2/src/mygal/widget-color-combo.c deleted file mode 100644 index 5ca2708f..00000000 --- a/glabels2/src/mygal/widget-color-combo.c +++ /dev/null @@ -1,335 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * widget-color-combo.c - A color selector combo box - * Copyright 2000, 2001, Ximian, Inc. - * - * Authors: - * Miguel de Icaza (miguel@kernel.org) - * Dom Lachowicz (dominicl@seas.upenn.edu) - * - * Reworked and split up into a separate ColorPalette object: - * Michael Levy (mlevy@genoscope.cns.fr) - * - * And later revised and polished by: - * Almer S. Tigelaar (almer@gnome.org) - * - * Modified for gLabels by: - * Jim Evins - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public - * License, version 2, as published by the Free Software Foundation. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - */ - -#include - -#include -#include -#include -#include "e-util.h" -#include "e-colors.h" -#include "widget-color-combo.h" - -enum { - CHANGED, - LAST_SIGNAL -}; - -static guint color_combo_signals [LAST_SIGNAL] = { 0, }; - -#define PARENT_TYPE MYGAL_COMBO_BOX_TYPE -static GObjectClass *color_combo_parent_class; - -#define make_color(CC,COL) (((COL) != NULL) ? (COL) : ((CC) ? ((CC)->default_color) : NULL)) -#define RGBA_TO_UINT(r,g,b,a) ((((guint)(r))<<24)|(((guint)(g))<<16)|(((guint)(b))<<8)|(guint)(a)) -#define GDK_TO_UINT(c) RGBA_TO_UINT(((c).red>>8), ((c).green>>8), ((c).blue>>8), 0xff) - -#define PREVIEW_SIZE 20 - -static void -color_combo_set_color_internal (ColorCombo *cc, GdkColor *color) -{ - guint color_y, color_height; - guint height, width; - GdkPixbuf *pixbuf; - GdkPixbuf *color_pixbuf; - GdkColor *new_color; - GdkColor *outline_color; - - new_color = make_color (cc,color); - /* If the new and the default are NULL draw an outline */ - outline_color = (new_color) ? new_color : &e_dark_gray; - - pixbuf = gtk_image_get_pixbuf (GTK_IMAGE (cc->preview_image)); - - if (!pixbuf) - return; - - width = gdk_pixbuf_get_width (pixbuf); - height = gdk_pixbuf_get_height (pixbuf); - - if (cc->preview_is_icon) { - color_y = height - 4; - color_height = 4; - } - else { - color_y = 0; - color_height = height; - } - - color_pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, - TRUE, 8, - width, - color_height); - gdk_pixbuf_fill (color_pixbuf, GDK_TO_UINT (*outline_color)); - gdk_pixbuf_copy_area (color_pixbuf, 0, 0, width, color_height, - pixbuf, 0, color_y); - - if (new_color != NULL) - gdk_pixbuf_fill (color_pixbuf, GDK_TO_UINT (*new_color)); - else - gdk_pixbuf_fill (color_pixbuf, 0xffffff00); - gdk_pixbuf_copy_area (color_pixbuf, 0, 0, width - 2, color_height -2, - pixbuf, 1, color_y + 1); - - g_object_unref (color_pixbuf); - - gtk_widget_queue_draw (GTK_WIDGET (cc)); -} - -static void -color_combo_class_init (GObjectClass *object_class) -{ - color_combo_parent_class = g_type_class_ref (PARENT_TYPE); - - color_combo_signals [CHANGED] = - g_signal_new ("color_changed", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ColorComboClass, color_changed), - NULL, NULL, - e_marshal_NONE__POINTER_BOOLEAN_BOOLEAN_BOOLEAN, - G_TYPE_NONE, 4, G_TYPE_POINTER, - G_TYPE_BOOLEAN, G_TYPE_BOOLEAN, G_TYPE_BOOLEAN); -} - -E_MAKE_TYPE (color_combo, - "ColorCombo", - ColorCombo, - color_combo_class_init, - NULL, - PARENT_TYPE) - -/* - * Fires signal "color_changed" with the current color as its param - */ -static void -emit_color_changed (ColorCombo *cc, GdkColor *color, - gboolean is_custom, gboolean by_user, gboolean is_default) -{ - g_signal_emit (cc, - color_combo_signals [CHANGED], 0, - color, is_custom, by_user, is_default); - mygal_combo_box_popup_hide (MYGAL_COMBO_BOX (cc)); -} - -static void -cb_palette_color_changed (ColorPalette *P, GdkColor *color, - gboolean custom, gboolean by_user, gboolean is_default, - ColorCombo *cc) -{ - color_combo_set_color_internal (cc, color); - emit_color_changed (cc, color, custom, by_user, is_default); -} - -static void -preview_clicked (GtkWidget *button, ColorCombo *cc) -{ - gboolean is_default; - GdkColor *color = color_palette_get_current_color (cc->palette, &is_default); - emit_color_changed (cc, color, FALSE, TRUE, is_default); - if (color) - gdk_color_free (color); -} - -static void -cb_cust_color_clicked (GtkWidget *widget, ColorCombo *cc) -{ - mygal_combo_box_popup_hide (MYGAL_COMBO_BOX (cc)); -} - -/* - * Creates the color table - */ -static void -color_table_setup (ColorCombo *cc, - char const *no_color_label, ColorGroup *color_group) -{ - g_return_if_fail (cc != NULL); - - /* Tell the palette that we will be changing it's custom colors */ - cc->palette = - COLOR_PALETTE (color_palette_new (no_color_label, - cc->default_color, - color_group)); - - { - GtkWidget *picker = color_palette_get_color_picker (cc->palette); - g_signal_connect (picker, "clicked", - G_CALLBACK (cb_cust_color_clicked), cc); - } - - g_signal_connect (cc->palette, "color_changed", - G_CALLBACK (cb_palette_color_changed), cc); - - gtk_widget_show_all (GTK_WIDGET (cc->palette)); - - return; -} - -void -color_combo_box_set_preview_relief (ColorCombo *cc, GtkReliefStyle relief) -{ - g_return_if_fail (cc != NULL); - g_return_if_fail (IS_COLOR_COMBO (cc)); - - gtk_button_set_relief (GTK_BUTTON (cc->preview_button), relief); -} - -/* - * Where the actual construction goes on - */ -static void -color_combo_construct (ColorCombo *cc, GdkPixbuf *icon, - char const *no_color_label, - ColorGroup *color_group) -{ - GdkColor *color; - GdkPixbuf *pixbuf = NULL; - - g_return_if_fail (cc != NULL); - g_return_if_fail (IS_COLOR_COMBO (cc)); - - /* - * Our button with the gtk_image preview - */ - cc->preview_button = gtk_button_new (); - cc->preview_is_icon = FALSE; - - if (icon) - /* use icon only if size > 4*4 */ - if ((gdk_pixbuf_get_width (icon) > 4) && - (gdk_pixbuf_get_height (icon) > 4)) - { - cc->preview_is_icon = TRUE; - pixbuf = gdk_pixbuf_copy (icon); - } - - if (pixbuf == NULL) - pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, - TRUE, 8, - PREVIEW_SIZE, - PREVIEW_SIZE); - - cc->preview_image = gtk_image_new_from_pixbuf (pixbuf); - g_object_unref (pixbuf); - - gtk_button_set_relief (GTK_BUTTON (cc->preview_button), GTK_RELIEF_NONE); - gtk_widget_show (cc->preview_image); - - gtk_container_add (GTK_CONTAINER (cc->preview_button), cc->preview_image); - g_signal_connect (cc->preview_button, "clicked", - G_CALLBACK (preview_clicked), cc); - - color_table_setup (cc, no_color_label, color_group); - - gtk_widget_show_all (cc->preview_button); - - mygal_combo_box_construct (MYGAL_COMBO_BOX (cc), - cc->preview_button, - GTK_WIDGET (cc->palette)); - - mygal_combo_box_set_tearable (MYGAL_COMBO_BOX (cc), FALSE); - - color = color_palette_get_current_color (cc->palette, NULL); - color_combo_set_color_internal (cc, color); - if (color) gdk_color_free (color); -} - -/* color_combo_get_color: - * - * Return current color, result must be freed with gdk_color_free ! - */ -GdkColor * -color_combo_get_color (ColorCombo *cc, gboolean *is_default) -{ - return color_palette_get_current_color (cc->palette, is_default); -} - -/** - * color_combo_set_color - * @cc The combo - * @color The color - * - * Set the color of the combo to the given color. Causes the color_changed - * signal to be emitted. - */ -void -color_combo_set_color (ColorCombo *cc, GdkColor *color) -{ - /* This will change the color on the palette than it will invoke - * cb_palette_color_changed which will call emit_color_changed and - * set_color_internal which will change the color on our preview and - * will let the users of the combo know that the current color has - * changed - */ - if (color != NULL) - gdk_rgb_find_color (gtk_widget_get_colormap (GTK_WIDGET (cc)), color); - color_palette_set_current_color (cc->palette, color); -} - -/** - * color_combo_set_color_to_default - * @cc The combo - * - * Set the color of the combo to the default color. Causes the color_changed - * signal to be emitted. - */ -void -color_combo_set_color_to_default (ColorCombo *cc) -{ - color_palette_set_color_to_default (cc->palette); -} - -/** - * color_combo_new : - * icon : optionally NULL. - * , const char *no_color_label, - * Default constructor. Pass an optional icon and an optional label for the - * no/auto color button. - */ -GtkWidget * -color_combo_new (GdkPixbuf *icon, char const *no_color_label, - GdkColor *default_color, - ColorGroup *color_group) -{ - ColorCombo *cc; - - cc = g_object_new (COLOR_COMBO_TYPE, NULL); - - cc->default_color = default_color; - - color_combo_construct (cc, icon, no_color_label, color_group); - - return GTK_WIDGET (cc); -} diff --git a/glabels2/src/mygal/widget-color-combo.h b/glabels2/src/mygal/widget-color-combo.h deleted file mode 100644 index 3fb283c7..00000000 --- a/glabels2/src/mygal/widget-color-combo.h +++ /dev/null @@ -1,86 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * widget-color-combo.h - A color selector combo box - * Copyright 2000, 2001, Ximian, Inc. - * - * Authors: - * Miguel de Icaza (miguel@kernel.org) - * Dom Lachowicz (dominicl@seas.upenn.edu) - * - * Reworked and split up into a separate ColorPalette object: - * Michael Levy (mlevy@genoscope.cns.fr) - * - * And later revised and polished by: - * Almer S. Tigelaar (almer@gnome.org) - * - * Modified for gLabels by: - * Jim Evins - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public - * License, version 2, as published by the Free Software Foundation. - * - * This library is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA - * 02111-1307, USA. - */ - -#ifndef GNUMERIC_WIDGET_COLOR_COMBO_H -#define GNUMERIC_WIDGET_COLOR_COMBO_H - -#include -#include "mygal-combo-box.h" -#include "color-palette.h" - -G_BEGIN_DECLS - -typedef struct _ColorCombo { - MygalComboBox combo_box; - - /* - * GtkImage where we display - */ - GtkWidget *preview_button; - GtkWidget *preview_image; - gboolean preview_is_icon; - - ColorPalette *palette; - - GdkColor *default_color; - gboolean trigger; -} ColorCombo; - -typedef struct { - MygalComboBoxClass parent_class; - - /* Signals emited by this widget */ - void (* color_changed) (ColorCombo *color_combo, GdkColor *color, - gboolean custom, gboolean by_user, gboolean is_default); -} ColorComboClass; - -#define COLOR_COMBO_TYPE (color_combo_get_type ()) -#define COLOR_COMBO(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), COLOR_COMBO_TYPE, ColorCombo)) -#define COLOR_COMBO_CLASS(k) (G_TYPE_CHECK_CLASS_CAST(k), COLOR_COMBO_TYPE) -#define IS_COLOR_COMBO(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), COLOR_COMBO_TYPE)) - -GtkType color_combo_get_type (void); -GtkWidget *color_combo_new (GdkPixbuf *icon, - char const *no_color_label, - GdkColor *default_color, - ColorGroup *color_group); -void color_combo_set_color (ColorCombo *cc, - GdkColor *color); -void color_combo_set_color_to_default (ColorCombo *cc); -GdkColor *color_combo_get_color (ColorCombo *cc, gboolean *is_default); - -void color_combo_box_set_preview_relief (ColorCombo *cc, GtkReliefStyle relief); - -G_END_DECLS - -#endif /* GNUMERIC_WIDGET_COLOR_COMBO_H */ diff --git a/glabels2/src/object-editor-bc-page.c b/glabels2/src/object-editor-bc-page.c index 464029e0..38c6a197 100644 --- a/glabels2/src/object-editor-bc-page.c +++ b/glabels2/src/object-editor-bc-page.c @@ -33,7 +33,7 @@ #include #include "prefs.h" -#include "mygal/widget-color-combo.h" +#include "color-combo.h" #include "color.h" #include "util.h" @@ -322,8 +322,6 @@ gl_object_editor_set_bc_color (glObjectEditor *editor, gboolean merge_flag, glColorNode *color_node) { - GdkColor *gdk_color; - gl_debug (DEBUG_EDITOR, "START"); editor->priv->stop_signals = TRUE; @@ -332,14 +330,12 @@ gl_object_editor_set_bc_color (glObjectEditor *editor, if ( color_node->color == GL_COLOR_NONE ) { - color_combo_set_color_to_default (COLOR_COMBO(editor->priv->bc_color_combo)); + gl_color_combo_set_to_default (GL_COLOR_COMBO(editor->priv->bc_color_combo)); } else { - gdk_color = gl_color_to_gdk_color (color_node->color); - color_combo_set_color (COLOR_COMBO(editor->priv->bc_color_combo), - gdk_color); - g_free (gdk_color); + gl_color_combo_set_color (GL_COLOR_COMBO(editor->priv->bc_color_combo), + color_node->color); } if (!color_node->field_flag) { @@ -369,7 +365,7 @@ gl_object_editor_set_bc_color (glObjectEditor *editor, glColorNode* gl_object_editor_get_bc_color (glObjectEditor *editor) { - GdkColor *gdk_color; + guint color; glColorNode *color_node; gboolean is_default; @@ -385,13 +381,13 @@ gl_object_editor_get_bc_color (glObjectEditor *editor) } else { color_node->field_flag = FALSE; color_node->key = NULL; - gdk_color = color_combo_get_color (COLOR_COMBO(editor->priv->bc_color_combo), - &is_default); + color = gl_color_combo_get_color (GL_COLOR_COMBO(editor->priv->bc_color_combo), + &is_default); if (is_default) { color_node->color = gl_prefs->default_line_color; } else { - color_node->color = gl_color_from_gdk_color (gdk_color); + color_node->color = color; } } diff --git a/glabels2/src/object-editor-edit-page.c b/glabels2/src/object-editor-edit-page.c index 5f2ff035..f7d3bf0d 100644 --- a/glabels2/src/object-editor-edit-page.c +++ b/glabels2/src/object-editor-edit-page.c @@ -31,7 +31,6 @@ #include #include "prefs.h" -#include "mygal/widget-color-combo.h" #include "color.h" #include "wdgt-merge-menu.h" #include "util.h" diff --git a/glabels2/src/object-editor-fill-page.c b/glabels2/src/object-editor-fill-page.c index c40f8a17..8ff5b4a2 100644 --- a/glabels2/src/object-editor-fill-page.c +++ b/glabels2/src/object-editor-fill-page.c @@ -31,7 +31,7 @@ #include #include "prefs.h" -#include "mygal/widget-color-combo.h" +#include "color-combo.h" #include "color.h" #include "util.h" @@ -64,8 +64,6 @@ static void fill_radio_toggled_cb (glObjectEditor *editor) void gl_object_editor_prepare_fill_page (glObjectEditor *editor) { - GdkColor *gdk_color; - gl_debug (DEBUG_EDITOR, "START"); /* Extract widgets from XML tree. */ @@ -87,9 +85,8 @@ gl_object_editor_prepare_fill_page (glObjectEditor *editor) gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (editor->priv->fill_color_radio), TRUE); gtk_widget_set_sensitive (editor->priv->fill_color_combo, TRUE); gtk_widget_set_sensitive (editor->priv->fill_key_combo, FALSE); - gdk_color = gl_color_to_gdk_color (gl_prefs->default_fill_color); - color_combo_set_color (COLOR_COMBO(editor->priv->fill_color_combo), gdk_color); - g_free (gdk_color); + gl_color_combo_set_color (GL_COLOR_COMBO(editor->priv->fill_color_combo), + gl_prefs->default_fill_color); /* Un-hide */ gtk_widget_show_all (editor->priv->fill_page_vbox); @@ -122,8 +119,6 @@ gl_object_editor_set_fill_color (glObjectEditor *editor, gboolean merge_flag, glColorNode *color_node) { - GdkColor *gdk_color; - gl_debug (DEBUG_EDITOR, "START"); editor->priv->stop_signals = TRUE; @@ -132,14 +127,12 @@ gl_object_editor_set_fill_color (glObjectEditor *editor, if ( color_node->color == GL_COLOR_NONE ) { - color_combo_set_color_to_default (COLOR_COMBO(editor->priv->fill_color_combo)); + gl_color_combo_set_to_default (GL_COLOR_COMBO(editor->priv->fill_color_combo)); } else { - gdk_color = gl_color_to_gdk_color (color_node->color); - color_combo_set_color (COLOR_COMBO(editor->priv->fill_color_combo), - gdk_color); - g_free (gdk_color); + gl_color_combo_set_color (GL_COLOR_COMBO(editor->priv->fill_color_combo), + color_node->color); } @@ -170,7 +163,7 @@ gl_object_editor_set_fill_color (glObjectEditor *editor, glColorNode* gl_object_editor_get_fill_color (glObjectEditor *editor) { - GdkColor *gdk_color; + guint color; gboolean is_default; glColorNode *color_node; @@ -182,15 +175,15 @@ gl_object_editor_get_fill_color (glObjectEditor *editor) color_node->field_flag = TRUE; color_node->key = gtk_combo_box_get_active_text (GTK_COMBO_BOX (editor->priv->fill_key_combo)); - } else { + } else { color_node->field_flag = FALSE; color_node->key = NULL; - gdk_color = color_combo_get_color (COLOR_COMBO(editor->priv->fill_color_combo), - &is_default); + color = gl_color_combo_get_color (GL_COLOR_COMBO(editor->priv->fill_color_combo), + &is_default); if (!is_default) { - color_node->color = gl_color_from_gdk_color (gdk_color); - } + color_node->color = color; + } } gl_debug (DEBUG_EDITOR, "END"); diff --git a/glabels2/src/object-editor-line-page.c b/glabels2/src/object-editor-line-page.c index a9daf766..40f96bb0 100644 --- a/glabels2/src/object-editor-line-page.c +++ b/glabels2/src/object-editor-line-page.c @@ -33,7 +33,7 @@ #include #include "prefs.h" -#include "mygal/widget-color-combo.h" +#include "color-combo.h" #include "color.h" #include "util.h" @@ -65,8 +65,6 @@ static void line_radio_toggled_cb (glObjectEditor *editor); void gl_object_editor_prepare_line_page (glObjectEditor *editor) { - GdkColor *gdk_color; - gl_debug (DEBUG_EDITOR, "START"); /* Extract widgets from XML tree. */ @@ -91,9 +89,8 @@ gl_object_editor_prepare_line_page (glObjectEditor *editor) gtk_widget_set_sensitive (editor->priv->line_key_combo, FALSE); gtk_spin_button_set_value (GTK_SPIN_BUTTON (editor->priv->line_width_spin), gl_prefs->default_line_width); - gdk_color = gl_color_to_gdk_color (gl_prefs->default_line_color); - color_combo_set_color (COLOR_COMBO(editor->priv->line_color_combo), gdk_color); - g_free (gdk_color); + gl_color_combo_set_color (GL_COLOR_COMBO(editor->priv->line_color_combo), + gl_prefs->default_line_color); /* Un-hide */ gtk_widget_show_all (editor->priv->line_page_vbox); @@ -168,8 +165,6 @@ gl_object_editor_set_line_color (glObjectEditor *editor, gboolean merge_flag, glColorNode *color_node) { - GdkColor *gdk_color; - gl_debug (DEBUG_EDITOR, "START"); editor->priv->stop_signals = TRUE; @@ -179,14 +174,12 @@ gl_object_editor_set_line_color (glObjectEditor *editor, if ( color_node->color == GL_COLOR_NONE ) { - color_combo_set_color_to_default (COLOR_COMBO(editor->priv->line_color_combo)); + gl_color_combo_set_to_default (GL_COLOR_COMBO(editor->priv->line_color_combo)); } else { - gdk_color = gl_color_to_gdk_color (color_node->color); - color_combo_set_color (COLOR_COMBO(editor->priv->line_color_combo), - gdk_color); - g_free (gdk_color); + gl_color_combo_set_color (GL_COLOR_COMBO(editor->priv->line_color_combo), + color_node->color); } @@ -217,7 +210,7 @@ gl_object_editor_set_line_color (glObjectEditor *editor, glColorNode* gl_object_editor_get_line_color (glObjectEditor *editor) { - GdkColor *gdk_color; + guint color; gboolean is_default; glColorNode *color_node; @@ -229,15 +222,15 @@ gl_object_editor_get_line_color (glObjectEditor *editor) color_node->field_flag = TRUE; color_node->key = gtk_combo_box_get_active_text (GTK_COMBO_BOX (editor->priv->line_key_combo)); - } else { + } else { color_node->field_flag = FALSE; color_node->key = NULL; - gdk_color = color_combo_get_color (COLOR_COMBO(editor->priv->line_color_combo), - &is_default); + color = gl_color_combo_get_color (GL_COLOR_COMBO(editor->priv->line_color_combo), + &is_default); if (!is_default) { - color_node->color = gl_color_from_gdk_color (gdk_color); - } + color_node->color = color; + } } gl_debug (DEBUG_EDITOR, "END"); diff --git a/glabels2/src/object-editor-shadow-page.c b/glabels2/src/object-editor-shadow-page.c index 4be309e9..c2e73571 100644 --- a/glabels2/src/object-editor-shadow-page.c +++ b/glabels2/src/object-editor-shadow-page.c @@ -33,7 +33,7 @@ #include #include "prefs.h" -#include "mygal/widget-color-combo.h" +#include "color-combo.h" #include "color.h" #include "util.h" @@ -210,8 +210,6 @@ gl_object_editor_set_shadow_color (glObjectEditor *editor, gboolean merge_flag, glColorNode *color_node) { - GdkColor *gdk_color; - gl_debug (DEBUG_EDITOR, "START"); editor->priv->stop_signals = TRUE; @@ -220,14 +218,12 @@ gl_object_editor_set_shadow_color (glObjectEditor *editor, if ( color_node->color == GL_COLOR_NONE ) { - color_combo_set_color_to_default (COLOR_COMBO(editor->priv->shadow_color_combo)); + gl_color_combo_set_to_default (GL_COLOR_COMBO(editor->priv->shadow_color_combo)); } else { - gdk_color = gl_color_to_gdk_color (color_node->color); - color_combo_set_color (COLOR_COMBO(editor->priv->shadow_color_combo), - gdk_color); - g_free (gdk_color); + gl_color_combo_set_color (GL_COLOR_COMBO(editor->priv->shadow_color_combo), + color_node->color); } @@ -355,7 +351,7 @@ gl_object_editor_get_shadow_offset (glObjectEditor *editor, glColorNode* gl_object_editor_get_shadow_color (glObjectEditor *editor) { - GdkColor *gdk_color; + guint color; gboolean is_default; glColorNode *color_node; @@ -367,15 +363,15 @@ gl_object_editor_get_shadow_color (glObjectEditor *editor) color_node->field_flag = TRUE; color_node->key = gtk_combo_box_get_active_text (GTK_COMBO_BOX (editor->priv->shadow_key_combo)); - } else { + } else { color_node->field_flag = FALSE; color_node->key = NULL; - gdk_color = color_combo_get_color (COLOR_COMBO(editor->priv->shadow_color_combo), - &is_default); + color = gl_color_combo_get_color (GL_COLOR_COMBO(editor->priv->shadow_color_combo), + &is_default); if (!is_default) { - color_node->color = gl_color_from_gdk_color (gdk_color); - } + color_node->color = color; + } } gl_debug (DEBUG_EDITOR, "END"); diff --git a/glabels2/src/object-editor-text-page.c b/glabels2/src/object-editor-text-page.c index 93aad0a4..a242661c 100644 --- a/glabels2/src/object-editor-text-page.c +++ b/glabels2/src/object-editor-text-page.c @@ -32,7 +32,7 @@ #include #include "prefs.h" -#include "mygal/widget-color-combo.h" +#include "color-combo.h" #include "color.h" #include "util.h" @@ -448,8 +448,6 @@ gl_object_editor_set_text_color (glObjectEditor *editor, gboolean merge_flag, glColorNode *text_color_node) { - GdkColor *gdk_color; - gl_debug (DEBUG_EDITOR, "START"); editor->priv->stop_signals = TRUE; @@ -460,13 +458,12 @@ gl_object_editor_set_text_color (glObjectEditor *editor, if ( text_color_node->color == GL_COLOR_NONE ) { - color_combo_set_color_to_default (COLOR_COMBO(editor->priv->text_color_combo)); + gl_color_combo_set_to_default (GL_COLOR_COMBO(editor->priv->text_color_combo)); } else { - gdk_color = gl_color_to_gdk_color (text_color_node->color); - color_combo_set_color (COLOR_COMBO(editor->priv->text_color_combo), gdk_color); - g_free (gdk_color); + gl_color_combo_set_color (GL_COLOR_COMBO(editor->priv->text_color_combo), + text_color_node->color); } if (!text_color_node->field_flag) { @@ -498,7 +495,7 @@ gl_object_editor_set_text_color (glObjectEditor *editor, glColorNode* gl_object_editor_get_text_color (glObjectEditor *editor) { - GdkColor *gdk_color; + guint color; glColorNode *color_node; gboolean is_default; @@ -514,13 +511,13 @@ gl_object_editor_get_text_color (glObjectEditor *editor) } else { color_node->field_flag = FALSE; color_node->key = NULL; - gdk_color = color_combo_get_color (COLOR_COMBO(editor->priv->text_color_combo), - &is_default); + color = gl_color_combo_get_color (GL_COLOR_COMBO(editor->priv->text_color_combo), + &is_default); if (is_default) { color_node->color = gl_prefs->default_text_color; } else { - color_node->color = gl_color_from_gdk_color (gdk_color); + color_node->color = color; } } diff --git a/glabels2/src/object-editor.c b/glabels2/src/object-editor.c index e02abaf0..ddaf6f90 100644 --- a/glabels2/src/object-editor.c +++ b/glabels2/src/object-editor.c @@ -35,7 +35,7 @@ #include #include "prefs.h" -#include "mygal/widget-color-combo.h" +#include "color-combo.h" #include "color.h" #include "wdgt-chain-button.h" #include "wdgt-merge-menu.h" @@ -568,47 +568,37 @@ gl_object_editor_construct_color_combo (gchar *name, gint int2) { GtkWidget *color_combo; - ColorGroup *cg; - gchar *cg_name; guint color; - GdkColor *gdk_color; gchar *no_color; switch (int1) { case 3: - cg_name = "shadow_color_group"; color = GL_COLOR_SHADOW_DEFAULT; no_color = _("Default"); break; case 2: - cg_name = "text_color_group"; color = gl_prefs->default_text_color; no_color = _("Default"); break; case 1: - cg_name = "line_color_group"; color = gl_prefs->default_line_color; no_color = _("No line"); break; case 0: default: - cg_name = "fill_color_group"; color = gl_prefs->default_fill_color; no_color = _("No fill"); break; } - cg = color_group_fetch (cg_name, NULL); - gdk_color = gl_color_to_gdk_color (color); - color_combo = color_combo_new (NULL, no_color, gdk_color, cg); - g_free (gdk_color); + color_combo = gl_color_combo_new (NULL, no_color, color, color); - color_combo_box_set_preview_relief (COLOR_COMBO(color_combo), GTK_RELIEF_NORMAL); + gl_color_combo_set_relief (GL_COLOR_COMBO(color_combo), GTK_RELIEF_NORMAL); return color_combo; } diff --git a/glabels2/src/prefs-dialog.c b/glabels2/src/prefs-dialog.c index 683926fb..3c15ac71 100644 --- a/glabels2/src/prefs-dialog.c +++ b/glabels2/src/prefs-dialog.c @@ -34,7 +34,7 @@ #include "prefs.h" #include "hig.h" -#include "mygal/widget-color-combo.h" +#include "color-combo.h" #include "color.h" #include "util.h" @@ -498,7 +498,6 @@ update_object_page_from_prefs (glPrefsDialog *dialog) { GList *family_names; gchar *good_font_family; - GdkColor *gdk_color; dialog->priv->stop_signals = TRUE; @@ -536,9 +535,8 @@ update_object_page_from_prefs (glPrefsDialog *dialog) gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->priv->text_italic_toggle), gl_prefs->default_font_italic_flag); - gdk_color = gl_color_to_gdk_color (gl_prefs->default_text_color); - color_combo_set_color (COLOR_COMBO(dialog->priv->text_color_combo), gdk_color); - g_free (gdk_color); + gl_color_combo_set_color (GL_COLOR_COMBO(dialog->priv->text_color_combo), + gl_prefs->default_text_color); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->priv->text_left_toggle), (gl_prefs->default_text_alignment == GTK_JUSTIFY_LEFT)); @@ -553,14 +551,12 @@ update_object_page_from_prefs (glPrefsDialog *dialog) gtk_spin_button_set_value (GTK_SPIN_BUTTON (dialog->priv->line_width_spin), gl_prefs->default_line_width); - gdk_color = gl_color_to_gdk_color (gl_prefs->default_line_color); - color_combo_set_color (COLOR_COMBO(dialog->priv->line_color_combo), gdk_color); - g_free (gdk_color); + gl_color_combo_set_color (GL_COLOR_COMBO(dialog->priv->line_color_combo), + gl_prefs->default_line_color); - gdk_color = gl_color_to_gdk_color (gl_prefs->default_fill_color); - color_combo_set_color (COLOR_COMBO(dialog->priv->fill_color_combo), gdk_color); - g_free (gdk_color); + gl_color_combo_set_color (GL_COLOR_COMBO(dialog->priv->fill_color_combo), + gl_prefs->default_fill_color); dialog->priv->stop_signals = FALSE; @@ -612,7 +608,7 @@ update_prefs_from_locale_page (glPrefsDialog *dialog) static void update_prefs_from_object_page (glPrefsDialog *dialog) { - GdkColor *gdk_color; + guint color; gboolean is_default; if (dialog->priv->stop_signals) return; @@ -637,11 +633,11 @@ update_prefs_from_object_page (glPrefsDialog *dialog) gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (dialog->priv->text_italic_toggle)); - gdk_color = color_combo_get_color (COLOR_COMBO(dialog->priv->text_color_combo), - &is_default); + color = gl_color_combo_get_color (GL_COLOR_COMBO(dialog->priv->text_color_combo), + &is_default); if (!is_default) { - gl_prefs->default_text_color = gl_color_from_gdk_color (gdk_color); + gl_prefs->default_text_color = color; } if (gtk_toggle_button_get_active @@ -672,19 +668,19 @@ update_prefs_from_object_page (glPrefsDialog *dialog) gl_prefs->default_line_width = gtk_spin_button_get_value (GTK_SPIN_BUTTON(dialog->priv->line_width_spin)); - gdk_color = color_combo_get_color (COLOR_COMBO(dialog->priv->line_color_combo), - &is_default); + color = gl_color_combo_get_color (GL_COLOR_COMBO(dialog->priv->line_color_combo), + &is_default); if (!is_default) { - gl_prefs->default_line_color = gl_color_from_gdk_color (gdk_color); + gl_prefs->default_line_color = color; } - gdk_color = color_combo_get_color (COLOR_COMBO(dialog->priv->fill_color_combo), - &is_default); + color = gl_color_combo_get_color (GL_COLOR_COMBO(dialog->priv->fill_color_combo), + &is_default); if (!is_default) { - gl_prefs->default_fill_color = gl_color_from_gdk_color (gdk_color); + gl_prefs->default_fill_color = color; } gl_prefs_model_save_settings (gl_prefs); diff --git a/glabels2/src/ui-property-bar.c b/glabels2/src/ui-property-bar.c index ea2d10a4..891aeacb 100644 --- a/glabels2/src/ui-property-bar.c +++ b/glabels2/src/ui-property-bar.c @@ -36,7 +36,7 @@ #include #include "util.h" -#include "mygal/widget-color-combo.h" +#include "color-combo.h" #include "stock-pixmaps/stockpixbufs.h" #include "prefs.h" #include "color.h" @@ -103,24 +103,18 @@ static void font_family_changed_cb (GtkComboBox *combo, static void font_size_changed_cb (GtkSpinButton *spin, glUIPropertyBar *property_bar); -static void text_color_changed_cb (ColorCombo *cc, - GdkColor *gdk_color, - gboolean custom, - gboolean by_user, +static void text_color_changed_cb (glColorCombo *cc, + guint color, gboolean is_default, glUIPropertyBar *property_bar); -static void fill_color_changed_cb (ColorCombo *cc, - GdkColor *gdk_color, - gboolean custom, - gboolean by_user, +static void fill_color_changed_cb (glColorCombo *cc, + guint color, gboolean is_default, glUIPropertyBar *property_bar); -static void line_color_changed_cb (ColorCombo *cc, - GdkColor *gdk_color, - gboolean custom, - gboolean by_user, +static void line_color_changed_cb (glColorCombo *cc, + guint color, gboolean is_default, glUIPropertyBar *property_bar); @@ -234,7 +228,6 @@ gl_ui_property_bar_construct (glUIPropertyBar *property_bar) GladeXML *gui; GList *family_names = NULL; GList *family_node; - GdkColor *gdk_color; gl_debug (DEBUG_PROPERTY_BAR, "START"); @@ -340,25 +333,19 @@ gl_ui_property_bar_construct (glUIPropertyBar *property_bar) "toggled", G_CALLBACK (text_align_toggled_cb), property_bar); /* Text color widget */ - gdk_color = gl_color_to_gdk_color (gl_prefs->default_text_color); - color_combo_set_color (COLOR_COMBO (property_bar->priv->text_color_combo), gdk_color); - g_free (gdk_color); + gl_color_combo_set_color (GL_COLOR_COMBO (property_bar->priv->text_color_combo), gl_prefs->default_text_color); g_signal_connect (G_OBJECT (property_bar->priv->text_color_combo), "color_changed", G_CALLBACK (text_color_changed_cb), property_bar); /* Fill color widget */ - gdk_color = gl_color_to_gdk_color (gl_prefs->default_fill_color); - color_combo_set_color (COLOR_COMBO (property_bar->priv->fill_color_combo), gdk_color); - g_free (gdk_color); + gl_color_combo_set_color (GL_COLOR_COMBO (property_bar->priv->fill_color_combo), gl_prefs->default_fill_color); g_signal_connect (G_OBJECT (property_bar->priv->fill_color_combo), "color_changed", G_CALLBACK (fill_color_changed_cb), property_bar); /* Line color widget */ - gdk_color = gl_color_to_gdk_color (gl_prefs->default_line_color); - color_combo_set_color (COLOR_COMBO (property_bar->priv->line_color_combo), gdk_color); - g_free (gdk_color); + gl_color_combo_set_color (GL_COLOR_COMBO (property_bar->priv->line_color_combo), gl_prefs->default_line_color); g_signal_connect (G_OBJECT (property_bar->priv->line_color_combo), "color_changed", G_CALLBACK (line_color_changed_cb), property_bar); @@ -382,7 +369,6 @@ reset_to_default_properties (glView *view, { GList *family_names; gchar *good_font_family; - GdkColor *gdk_color; /* Make sure we have a valid font. if not provide a good default. */ family_names = gl_util_get_font_family_list (); @@ -423,17 +409,11 @@ reset_to_default_properties (glView *view, gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (property_bar->priv->text_align_right_radio), (view->default_text_alignment == PANGO_ALIGN_RIGHT)); - gdk_color = gl_color_to_gdk_color (view->default_text_color); - color_combo_set_color (COLOR_COMBO(property_bar->priv->text_color_combo), gdk_color); - g_free (gdk_color); + gl_color_combo_set_color (GL_COLOR_COMBO(property_bar->priv->text_color_combo), view->default_text_color); - gdk_color = gl_color_to_gdk_color (view->default_fill_color); - color_combo_set_color (COLOR_COMBO(property_bar->priv->fill_color_combo), gdk_color); - g_free (gdk_color); + gl_color_combo_set_color (GL_COLOR_COMBO(property_bar->priv->fill_color_combo), view->default_fill_color); - gdk_color = gl_color_to_gdk_color (view->default_line_color); - color_combo_set_color (COLOR_COMBO(property_bar->priv->line_color_combo), gdk_color); - g_free (gdk_color); + gl_color_combo_set_color (GL_COLOR_COMBO(property_bar->priv->line_color_combo), view->default_line_color); gtk_spin_button_set_value (GTK_SPIN_BUTTON(property_bar->priv->line_width_spin), view->default_line_width); @@ -518,7 +498,6 @@ update_text_properties (glView *view, gboolean selection_is_italic, is_italic; gboolean selection_is_bold, is_bold; PangoAlignment selection_align, align; - GdkColor *gdk_color; can_text = gl_view_can_selection_text (view); set_text_items_sensitive (property_bar, can_text); @@ -630,10 +609,8 @@ update_text_properties (glView *view, if (is_same_text_color) { gl_debug (DEBUG_PROPERTY_BAR, "same text color = %08x", selection_text_color); - gdk_color = gl_color_to_gdk_color (selection_text_color); - color_combo_set_color (COLOR_COMBO (property_bar->priv->text_color_combo), - gdk_color); - g_free (gdk_color); + gl_color_combo_set_color (GL_COLOR_COMBO (property_bar->priv->text_color_combo), + selection_text_color); } if (is_same_is_italic) @@ -674,7 +651,6 @@ update_fill_color (glView *view, GList *p; glLabelObject *object; guint selection_fill_color, fill_color; - GdkColor *gdk_color; glColorNode *fill_color_node; can = gl_view_can_selection_fill (view); @@ -724,10 +700,8 @@ update_fill_color (glView *view, if (is_same_fill_color) { gl_debug (DEBUG_PROPERTY_BAR, "same fill color = %08x", selection_fill_color); - gdk_color = gl_color_to_gdk_color (selection_fill_color); - color_combo_set_color (COLOR_COMBO (property_bar->priv->fill_color_combo), - gdk_color); - g_free (gdk_color); + gl_color_combo_set_color (GL_COLOR_COMBO (property_bar->priv->fill_color_combo), + selection_fill_color); } } @@ -741,7 +715,6 @@ update_line_color (glView *view, glLabelObject *object; guint selection_line_color, line_color; glColorNode *line_color_node; - GdkColor *gdk_color; can = gl_view_can_selection_line_color (view); set_line_color_items_sensitive (property_bar, can); @@ -790,10 +763,8 @@ update_line_color (glView *view, if (is_same_line_color) { gl_debug (DEBUG_PROPERTY_BAR, "same line color = %08x", selection_line_color); - gdk_color = gl_color_to_gdk_color (selection_line_color); - color_combo_set_color (COLOR_COMBO (property_bar->priv->line_color_combo), - gdk_color); - g_free (gdk_color); + gl_color_combo_set_color (GL_COLOR_COMBO (property_bar->priv->line_color_combo), + selection_line_color); } } @@ -943,10 +914,8 @@ font_size_changed_cb (GtkSpinButton *spin, /* PRIVATE. Text color combo changed. */ /*--------------------------------------------------------------------------*/ static void -text_color_changed_cb (ColorCombo *cc, - GdkColor *gdk_color, - gboolean custom, - gboolean by_user, +text_color_changed_cb (glColorCombo *cc, + guint color, gboolean is_default, glUIPropertyBar *property_bar) { @@ -960,10 +929,10 @@ text_color_changed_cb (ColorCombo *cc, gl_debug (DEBUG_PROPERTY_BAR, "START"); text_color_node = gl_color_node_new_default (); - text_color_node->color = gl_color_from_gdk_color (gdk_color); + text_color_node->color = color; - gl_debug (DEBUG_PROPERTY_BAR, "Color=%08x, Custom=%d, By_User=%d, Is_default=%d", - text_color_node->color, custom, by_user, is_default); + gl_debug (DEBUG_PROPERTY_BAR, "Color=%08x, Is_default=%d", + color, is_default); if (is_default) { @@ -992,10 +961,8 @@ text_color_changed_cb (ColorCombo *cc, /* PRIVATE. Fill color combo changed. */ /*--------------------------------------------------------------------------*/ static void -fill_color_changed_cb (ColorCombo *cc, - GdkColor *gdk_color, - gboolean custom, - gboolean by_user, +fill_color_changed_cb (glColorCombo *cc, + guint color, gboolean is_default, glUIPropertyBar *property_bar) { @@ -1010,10 +977,10 @@ fill_color_changed_cb (ColorCombo *cc, fill_color_node = gl_color_node_new_default (); - fill_color_node->color = gl_color_from_gdk_color (gdk_color); + fill_color_node->color = color; - gl_debug (DEBUG_PROPERTY_BAR, "Color=%08x, Custom=%d, By_User=%d, Is_default=%d", - fill_color_node->color, custom, by_user, is_default); + gl_debug (DEBUG_PROPERTY_BAR, "Color=%08x, Is_default=%d", + color, is_default); if (is_default) { @@ -1042,10 +1009,8 @@ fill_color_changed_cb (ColorCombo *cc, /* PRIVATE. Line color combo changed. */ /*--------------------------------------------------------------------------*/ static void -line_color_changed_cb (ColorCombo *cc, - GdkColor *gdk_color, - gboolean custom, - gboolean by_user, +line_color_changed_cb (glColorCombo *cc, + guint color, gboolean is_default, glUIPropertyBar *property_bar) { @@ -1059,10 +1024,10 @@ line_color_changed_cb (ColorCombo *cc, gl_debug (DEBUG_PROPERTY_BAR, "START"); line_color_node = gl_color_node_new_default (); - line_color_node->color = gl_color_from_gdk_color (gdk_color); + line_color_node->color = color; - gl_debug (DEBUG_PROPERTY_BAR, "Color=%08x, Custom=%d, By_User=%d, Is_default=%d", - line_color_node->color, custom, by_user, is_default); + gl_debug (DEBUG_PROPERTY_BAR, "Color=%08x, Is_default=%d", + color, is_default); if (is_default) { @@ -1220,24 +1185,19 @@ gl_ui_property_bar_construct_color_combo (gchar *name, gint int2) { GtkWidget *color_combo; - ColorGroup *cg; - gchar *cg_name; guint color; - GdkColor *gdk_color; gchar *no_color; GdkPixbuf *pixbuf = NULL; switch (int1) { case 0: - cg_name = "text_color_group"; color = gl_prefs->default_text_color; no_color = _("Default"); pixbuf = gdk_pixbuf_new_from_inline (-1, stock_text_24, FALSE, NULL); break; case 2: - cg_name = "line_color_group"; color = gl_prefs->default_line_color; no_color = _("No line"); pixbuf = gdk_pixbuf_new_from_inline (-1, stock_pencil_24, FALSE, NULL); @@ -1245,7 +1205,6 @@ gl_ui_property_bar_construct_color_combo (gchar *name, case 1: default: - cg_name = "fill_color_group"; color = gl_prefs->default_fill_color; no_color = _("No fill"); pixbuf = gdk_pixbuf_new_from_inline (-1, stock_bucket_fill_24, FALSE, NULL); @@ -1253,12 +1212,10 @@ gl_ui_property_bar_construct_color_combo (gchar *name, } - cg = color_group_fetch (cg_name, NULL); - gdk_color = gl_color_to_gdk_color (color); - color_combo = color_combo_new (pixbuf, no_color, gdk_color, cg); - g_free (gdk_color); + color_combo = gl_color_combo_new (pixbuf, no_color, color, color); - color_combo_box_set_preview_relief (COLOR_COMBO(color_combo), GTK_RELIEF_NORMAL); + gl_color_combo_set_relief (GL_COLOR_COMBO(color_combo), + GTK_RELIEF_NONE); g_object_unref (G_OBJECT (pixbuf)); diff --git a/glabels2/src/util.c b/glabels2/src/util.c index ee9151bf..c0e1ac0f 100644 --- a/glabels2/src/util.c +++ b/glabels2/src/util.c @@ -305,6 +305,7 @@ gl_util_combo_box_add_text_model (GtkComboBox *combo) NULL); } + /****************************************************************************/ /* Get list of available font families. */ /****************************************************************************/ @@ -355,3 +356,71 @@ void gl_util_font_family_list_free (GList *list) } +/****************************************************************************/ +/* Convert cairo surface to GdkPixbuf. */ +/* from http://davyd.livejournal.com/240469.html */ +/****************************************************************************/ +static inline guint8 +convert_color_channel (guint8 src, guint8 alpha) +{ + return alpha ? ((src << 8) - src) / alpha : 0; +} + +/** + * gl_util_cairo_convert_to_pixbuf: + * Converts from a Cairo image surface to a GdkPixbuf. Why does GTK+ not + * implement this? + */ +GdkPixbuf * +gl_util_cairo_convert_to_pixbuf (cairo_surface_t *surface) +{ + GdkPixbuf *pixbuf; + int width, height; + int srcstride, dststride; + guchar *srcpixels, *dstpixels; + guchar *srcpixel, *dstpixel; + int n_channels; + int x, y; + + switch (cairo_image_surface_get_format (surface)) + { + case CAIRO_FORMAT_ARGB32: + case CAIRO_FORMAT_RGB24: + break; + + default: + g_critical ("This Cairo surface format not supported"); + return NULL; + break; + } + + width = cairo_image_surface_get_width (surface); + height = cairo_image_surface_get_height (surface); + srcstride = cairo_image_surface_get_stride (surface); + srcpixels = cairo_image_surface_get_data (surface); + + pixbuf = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, + width, height); + dststride = gdk_pixbuf_get_rowstride (pixbuf); + dstpixels = gdk_pixbuf_get_pixels (pixbuf); + n_channels = gdk_pixbuf_get_n_channels (pixbuf); + + for (y = 0; y < height; y++) + { + for (x = 0; x < width; x++) + { + srcpixel = srcpixels + y * srcstride + x * 4; + dstpixel = dstpixels + y * dststride + x * n_channels; + + dstpixel[0] = convert_color_channel (srcpixel[2], + srcpixel[3]); + dstpixel[1] = convert_color_channel (srcpixel[1], + srcpixel[3]); + dstpixel[2] = convert_color_channel (srcpixel[0], + srcpixel[3]); + dstpixel[3] = srcpixel[3]; + } + } + + return pixbuf; +} diff --git a/glabels2/src/util.h b/glabels2/src/util.h index aa0ff25e..71ac2111 100644 --- a/glabels2/src/util.h +++ b/glabels2/src/util.h @@ -53,6 +53,8 @@ void gl_util_combo_box_add_text_model (GtkComboBox *combo); GList *gl_util_get_font_family_list (void); void gl_util_font_family_list_free (GList *list); +GdkPixbuf *gl_util_cairo_convert_to_pixbuf (cairo_surface_t *surface); + G_END_DECLS #endif /* __UTIL_H__ */