sp-color-notebook.cpp revision 99f8079bc0a32aef279e4af06de4cbf4bd853563
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm#define __SP_COLOR_NOTEBOOK_C__
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm/*
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm * A notebook with RGB, CMYK, CMS, HSL, and Wheel pages
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm *
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm * Author:
5c45bb188ab729e501e48732842cb9de6a9813beAlex Valavanis * Lauris Kaplinski <lauris@kaplinski.com>
eb4caa8f4cdc2955b58dcd2de06fe770533414c8Jon A. Cruz * bulia byak <buliabyak@users.sf.net>
eb4caa8f4cdc2955b58dcd2de06fe770533414c8Jon A. Cruz *
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm * Copyright (C) 2001-2002 Lauris Kaplinski
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm *
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm * This code is in public domain
d431763a9ec8059aa4962688de8144319969fb0fjohanengelen */
3329addad9a304f9237837ad03dd9db329151b96Jabiertxof
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm#undef SPCS_PREVIEW
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm#define noDUMP_CHANGE_INFO
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm#ifdef HAVE_CONFIG_H
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm# include "config.h"
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm#endif
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm#include <cstring>
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm#include <string>
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm#include <cstdlib>
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm#include <gtk/gtk.h>
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm#include <glibmm/i18n.h>
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm#include "../dialogs/dialog-events.h"
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm#include "../preferences.h"
b5a129ca7cf5c8e074b39ea5dbc2cc978187078bjohanengelen#include "sp-color-notebook.h"
b5a129ca7cf5c8e074b39ea5dbc2cc978187078bjohanengelen#include "spw-utilities.h"
b5a129ca7cf5c8e074b39ea5dbc2cc978187078bjohanengelen#include "sp-color-scales.h"
b5a129ca7cf5c8e074b39ea5dbc2cc978187078bjohanengelen#include "sp-color-icc-selector.h"
cc618cb0faf84b6f5ab2cc9802b29d03f6a22f97Jon A. Cruz#include "sp-color-wheel-selector.h"
b5a129ca7cf5c8e074b39ea5dbc2cc978187078bjohanengelen#include "svg/svg-icc-color.h"
cc618cb0faf84b6f5ab2cc9802b29d03f6a22f97Jon A. Cruz#include "../inkscape.h"
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm#include "../document.h"
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm#include "../profile-manager.h"
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
0903335a0099bd7ee779925f43a15a2216a0e863johanengelenstruct SPColorNotebookTracker {
0903335a0099bd7ee779925f43a15a2216a0e863johanengelen const gchar* name;
0903335a0099bd7ee779925f43a15a2216a0e863johanengelen const gchar* className;
0903335a0099bd7ee779925f43a15a2216a0e863johanengelen GType type;
0903335a0099bd7ee779925f43a15a2216a0e863johanengelen guint submode;
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm gboolean enabledFull;
cef9e2c431b417aea98429860c6021849f099fcfKris De Gussem gboolean enabledBrief;
cef9e2c431b417aea98429860c6021849f099fcfKris De Gussem SPColorNotebook *backPointer;
cef9e2c431b417aea98429860c6021849f099fcfKris De Gussem};
cef9e2c431b417aea98429860c6021849f099fcfKris De Gussem
cef9e2c431b417aea98429860c6021849f099fcfKris De Gussemstatic void sp_color_notebook_class_init (SPColorNotebookClass *klass);
cef9e2c431b417aea98429860c6021849f099fcfKris De Gussemstatic void sp_color_notebook_init (SPColorNotebook *colorbook);
c11199b2b0b6b7fbfe61f562566e0cd15604cc43Liam P. Whitestatic void sp_color_notebook_destroy (GtkObject *object);
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrmstatic void sp_color_notebook_show_all (GtkWidget *widget);
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrmstatic void sp_color_notebook_hide_all (GtkWidget *widget);
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrmstatic SPColorSelectorClass *parent_class;
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
b5a129ca7cf5c8e074b39ea5dbc2cc978187078bjohanengelen#define XPAD 4
b5a129ca7cf5c8e074b39ea5dbc2cc978187078bjohanengelen#define YPAD 1
c11199b2b0b6b7fbfe61f562566e0cd15604cc43Liam P. White
c11199b2b0b6b7fbfe61f562566e0cd15604cc43Liam P. WhiteGType sp_color_notebook_get_type(void)
b5a129ca7cf5c8e074b39ea5dbc2cc978187078bjohanengelen{
b5a129ca7cf5c8e074b39ea5dbc2cc978187078bjohanengelen static GtkType type = 0;
b5a129ca7cf5c8e074b39ea5dbc2cc978187078bjohanengelen if (!type) {
b5a129ca7cf5c8e074b39ea5dbc2cc978187078bjohanengelen GTypeInfo info = {
ea3e4fdbdbf0a48ae887b096d301549da77d5707Johan Engelen sizeof(SPColorNotebookClass),
ea3e4fdbdbf0a48ae887b096d301549da77d5707Johan Engelen 0, // base_init
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm 0, // base_finalize
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm (GClassInitFunc)sp_color_notebook_class_init,
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm 0, // class_finalize
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm 0, // class_data
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm sizeof(SPColorNotebook),
106bf69f0520ef3b349214008cc1f91c68e69daaJabiertxof 0, // n_preallocs
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm (GInstanceInitFunc)sp_color_notebook_init,
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm 0 // value_table
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm };
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm type = g_type_register_static(SP_TYPE_COLOR_SELECTOR, "SPColorNotebook", &info, static_cast<GTypeFlags>(0));
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm }
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm return type;
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm}
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrmstatic void
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrmsp_color_notebook_class_init (SPColorNotebookClass *klass)
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm{
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm GtkObjectClass *object_class;
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm GtkWidgetClass *widget_class;
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm SPColorSelectorClass *selector_class;
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
79291918d036d77d586b6eba265d8d2ac0a7fee5cilix object_class = (GtkObjectClass *) klass;
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm widget_class = (GtkWidgetClass *) klass;
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm selector_class = SP_COLOR_SELECTOR_CLASS (klass);
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm parent_class = SP_COLOR_SELECTOR_CLASS (g_type_class_peek_parent (klass));
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm object_class->destroy = sp_color_notebook_destroy;
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm widget_class->show_all = sp_color_notebook_show_all;
eaa9bdc7bf7b73397e536edd47490d84e4420bd8bryce widget_class->hide_all = sp_color_notebook_hide_all;
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm}
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrmstatic void
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrmsp_color_notebook_switch_page(GtkNotebook *notebook,
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm GtkNotebookPage *page,
eaa9bdc7bf7b73397e536edd47490d84e4420bd8bryce guint page_num,
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm SPColorNotebook *colorbook)
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm{
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm if ( colorbook )
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm {
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm ColorNotebook* nb = (ColorNotebook*)(SP_COLOR_SELECTOR(colorbook)->base);
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm nb->switchPage( notebook, page, page_num );
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm // remember the page we seitched to
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm Inkscape::Preferences *prefs = Inkscape::Preferences::get();
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm prefs->setInt("/colorselector/page", page_num);
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm }
eaa9bdc7bf7b73397e536edd47490d84e4420bd8bryce}
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f83dd38ed9c631b7644b7c82c821fa9fbbb82352Liam P. Whitevoid ColorNotebook::switchPage(GtkNotebook*,
f83dd38ed9c631b7644b7c82c821fa9fbbb82352Liam P. White GtkNotebookPage*,
f83dd38ed9c631b7644b7c82c821fa9fbbb82352Liam P. White guint page_num)
f83dd38ed9c631b7644b7c82c821fa9fbbb82352Liam P. White{
f83dd38ed9c631b7644b7c82c821fa9fbbb82352Liam P. White SPColorSelector* csel;
f83dd38ed9c631b7644b7c82c821fa9fbbb82352Liam P. White GtkWidget* widget;
f83dd38ed9c631b7644b7c82c821fa9fbbb82352Liam P. White
f83dd38ed9c631b7644b7c82c821fa9fbbb82352Liam P. White if ( gtk_notebook_get_current_page (GTK_NOTEBOOK (_book)) >= 0 )
f83dd38ed9c631b7644b7c82c821fa9fbbb82352Liam P. White {
f83dd38ed9c631b7644b7c82c821fa9fbbb82352Liam P. White csel = getCurrentSelector();
f83dd38ed9c631b7644b7c82c821fa9fbbb82352Liam P. White csel->base->getColorAlpha(_color, _alpha);
f83dd38ed9c631b7644b7c82c821fa9fbbb82352Liam P. White }
f83dd38ed9c631b7644b7c82c821fa9fbbb82352Liam P. White widget = gtk_notebook_get_nth_page (GTK_NOTEBOOK (_book), page_num);
f83dd38ed9c631b7644b7c82c821fa9fbbb82352Liam P. White if ( widget && SP_IS_COLOR_SELECTOR (widget) )
f83dd38ed9c631b7644b7c82c821fa9fbbb82352Liam P. White {
f83dd38ed9c631b7644b7c82c821fa9fbbb82352Liam P. White csel = SP_COLOR_SELECTOR (widget);
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm csel->base->setColorAlpha( _color, _alpha );
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm // Temporary workaround to undo a spurious GRABBED
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm _released();
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm }
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm}
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrmstatic gint sp_color_notebook_menu_handler( GtkWidget *widget, GdkEvent *event )
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm{
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm if (event->type == GDK_BUTTON_PRESS)
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm {
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm SPColorSelector* csel = SP_COLOR_SELECTOR(widget);
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm ((ColorNotebook*)(csel->base))->menuHandler( event );
106bf69f0520ef3b349214008cc1f91c68e69daaJabiertxof
106bf69f0520ef3b349214008cc1f91c68e69daaJabiertxof /* Tell calling code that we have handled this event; the buck
106bf69f0520ef3b349214008cc1f91c68e69daaJabiertxof * stops here. */
106bf69f0520ef3b349214008cc1f91c68e69daaJabiertxof return TRUE;
106bf69f0520ef3b349214008cc1f91c68e69daaJabiertxof }
106bf69f0520ef3b349214008cc1f91c68e69daaJabiertxof
106bf69f0520ef3b349214008cc1f91c68e69daaJabiertxof /* Tell calling code that we have not handled this event; pass it on. */
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm return FALSE;
5cf332777b4c27336d64c273ac63bce3ee27a53dAlex Valavanis}
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
c2057a738f9ea8cb7acdeb1feb69cef5b0d4bc56johanengelengint ColorNotebook::menuHandler( GdkEvent* event )
c2057a738f9ea8cb7acdeb1feb69cef5b0d4bc56johanengelen{
c2057a738f9ea8cb7acdeb1feb69cef5b0d4bc56johanengelen GdkEventButton *bevent = (GdkEventButton *) event;
c2057a738f9ea8cb7acdeb1feb69cef5b0d4bc56johanengelen gtk_menu_popup (GTK_MENU( _popup ), NULL, NULL, NULL, NULL,
c2057a738f9ea8cb7acdeb1feb69cef5b0d4bc56johanengelen bevent->button, bevent->time);
c2057a738f9ea8cb7acdeb1feb69cef5b0d4bc56johanengelen return TRUE;
c2057a738f9ea8cb7acdeb1feb69cef5b0d4bc56johanengelen}
b5c827e288e4b88df2ddfeb6bce119a17338d669johanengelen
ea3e4fdbdbf0a48ae887b096d301549da77d5707Johan Engelenstatic void sp_color_notebook_menuitem_response (GtkMenuItem *menuitem, gpointer user_data)
ea3e4fdbdbf0a48ae887b096d301549da77d5707Johan Engelen{
ea3e4fdbdbf0a48ae887b096d301549da77d5707Johan Engelen gboolean active = FALSE;
c2057a738f9ea8cb7acdeb1feb69cef5b0d4bc56johanengelen
c2057a738f9ea8cb7acdeb1feb69cef5b0d4bc56johanengelen active = gtk_check_menu_item_get_active (GTK_CHECK_MENU_ITEM (menuitem));
106bf69f0520ef3b349214008cc1f91c68e69daaJabiertxof SPColorNotebookTracker *entry = reinterpret_cast< SPColorNotebookTracker* > (user_data);
c2057a738f9ea8cb7acdeb1feb69cef5b0d4bc56johanengelen if ( entry )
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm {
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm if ( active )
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm {
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm ((ColorNotebook*)(SP_COLOR_SELECTOR(entry->backPointer)->base))->addPage(entry->type, entry->submode);
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm }
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm else
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm {
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm ((ColorNotebook*)(SP_COLOR_SELECTOR(entry->backPointer)->base))->removePage(entry->type, entry->submode);
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm }
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm }
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm}
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrmstatic void
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrmsp_color_notebook_init (SPColorNotebook *colorbook)
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm{
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm SP_COLOR_SELECTOR(colorbook)->base = new ColorNotebook( SP_COLOR_SELECTOR(colorbook) );
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm if ( SP_COLOR_SELECTOR(colorbook)->base )
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm {
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm SP_COLOR_SELECTOR(colorbook)->base->init();
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm }
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm}
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrmvoid ColorNotebook::init()
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm{
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm GtkWidget* table = 0;
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm guint row = 0;
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm guint i = 0;
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm guint j = 0;
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm GType *selector_types = 0;
f07bfd5a05d43a6d11f7cd442f085149092dea88pjrm guint selector_type_count = 0;
GtkTooltips *tt = gtk_tooltips_new ();
/* tempory hardcoding to get types loaded */
SP_TYPE_COLOR_SCALES;
SP_TYPE_COLOR_WHEEL_SELECTOR;
#if ENABLE_LCMS
SP_TYPE_COLOR_ICC_SELECTOR;
#endif // ENABLE_LCMS
/* REJON: Comment out the next line to not use the normal GTK Color
wheel. */
// SP_TYPE_COLOR_GTKSELECTOR;
_updating = FALSE;
_updatingrgba = FALSE;
_btn = 0;
_popup = 0;
_trackerList = g_ptr_array_new ();
_book = gtk_notebook_new ();
gtk_widget_show (_book);
selector_types = g_type_children (SP_TYPE_COLOR_SELECTOR, &selector_type_count);
for ( i = 0; i < selector_type_count; i++ )
{
if (!g_type_is_a (selector_types[i], SP_TYPE_COLOR_NOTEBOOK))
{
guint howmany = 1;
gpointer klass = gtk_type_class (selector_types[i]);
if ( klass && SP_IS_COLOR_SELECTOR_CLASS (klass) )
{
SPColorSelectorClass *ck = SP_COLOR_SELECTOR_CLASS (klass);
howmany = MAX (1, ck->submode_count);
for ( j = 0; j < howmany; j++ )
{
SPColorNotebookTracker *entry = reinterpret_cast< SPColorNotebookTracker* > (malloc(sizeof(SPColorNotebookTracker)));
if ( entry )
{
memset( entry, 0, sizeof(SPColorNotebookTracker) );
entry->name = ck->name[j];
entry->type = selector_types[i];
entry->submode = j;
entry->enabledFull = TRUE;
entry->enabledBrief = TRUE;
entry->backPointer = SP_COLOR_NOTEBOOK(_csel);
g_ptr_array_add (_trackerList, entry);
}
}
}
}
}
for ( i = 0; i < _trackerList->len; i++ )
{
SPColorNotebookTracker *entry =
reinterpret_cast< SPColorNotebookTracker* > (g_ptr_array_index (_trackerList, i));
if ( entry )
{
addPage(entry->type, entry->submode);
}
}
table = gtk_table_new (2, 3, FALSE);
gtk_widget_show (table);
gtk_box_pack_start (GTK_BOX (_csel), table, TRUE, TRUE, 0);
gtk_table_attach (GTK_TABLE (table), _book, 0, 2, row, row + 1,
static_cast<GtkAttachOptions>(GTK_EXPAND|GTK_FILL),
static_cast<GtkAttachOptions>(GTK_EXPAND|GTK_FILL),
XPAD, YPAD);
// restore the last active page
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
gtk_notebook_set_current_page (GTK_NOTEBOOK (_book), prefs->getInt("/colorselector/page", 0));
{
gboolean found = FALSE;
_popup = gtk_menu_new();
GtkMenu *menu = GTK_MENU (_popup);
for ( i = 0; i < _trackerList->len; i++ )
{
SPColorNotebookTracker *entry = reinterpret_cast< SPColorNotebookTracker* > (g_ptr_array_index (_trackerList, i));
if ( entry )
{
GtkWidget *item = gtk_check_menu_item_new_with_label (_(entry->name));
gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item), entry->enabledFull);
gtk_widget_show (item);
gtk_menu_append (menu, item);
g_signal_connect (G_OBJECT (item), "activate",
G_CALLBACK (sp_color_notebook_menuitem_response),
reinterpret_cast< gpointer > (entry) );
found = TRUE;
}
}
GtkWidget *arrow = gtk_arrow_new(GTK_ARROW_RIGHT, GTK_SHADOW_NONE);
gtk_widget_show (arrow);
_btn = gtk_button_new ();
gtk_widget_show (_btn);
gtk_container_add (GTK_CONTAINER (_btn), arrow);
GtkWidget *align = gtk_alignment_new (1.0, 0.0, 0.0, 0.0);
gtk_widget_show (align);
gtk_container_add (GTK_CONTAINER (align), _btn);
// uncomment to reenable the "show/hide modes" menu,
// but first fix it so it remembers its settings in prefs and does not take that much space (entire vertical column!)
//gtk_table_attach (GTK_TABLE (table), align, 2, 3, row, row + 1, GTK_FILL, GTK_FILL, XPAD, YPAD);
gtk_signal_connect_object(GTK_OBJECT(_btn), "event", GTK_SIGNAL_FUNC (sp_color_notebook_menu_handler), GTK_OBJECT(_csel));
if ( !found )
{
gtk_widget_set_sensitive (_btn, FALSE);
}
}
row++;
GtkWidget *rgbabox = gtk_hbox_new (FALSE, 0);
#if ENABLE_LCMS
/* Create color management icons */
_box_colormanaged = gtk_event_box_new ();
GtkWidget *colormanaged = gtk_image_new_from_icon_name ("color-management-icon", GTK_ICON_SIZE_SMALL_TOOLBAR);
gtk_container_add (GTK_CONTAINER (_box_colormanaged), colormanaged);
GtkTooltips *tooltips_colormanaged = gtk_tooltips_new ();
gtk_tooltips_set_tip (tooltips_colormanaged, _box_colormanaged, _("Color Managed"), "");
gtk_widget_set_sensitive (_box_colormanaged, false);
gtk_box_pack_start(GTK_BOX(rgbabox), _box_colormanaged, FALSE, FALSE, 2);
_box_outofgamut = gtk_event_box_new ();
GtkWidget *outofgamut = gtk_image_new_from_icon_name ("out-of-gamut-icon", GTK_ICON_SIZE_SMALL_TOOLBAR);
gtk_container_add (GTK_CONTAINER (_box_outofgamut), outofgamut);
GtkTooltips *tooltips_outofgamut = gtk_tooltips_new ();
gtk_tooltips_set_tip (tooltips_outofgamut, _box_outofgamut, _("Out of gamut!"), "");
gtk_widget_set_sensitive (_box_outofgamut, false);
gtk_box_pack_start(GTK_BOX(rgbabox), _box_outofgamut, FALSE, FALSE, 2);
_box_toomuchink = gtk_event_box_new ();
GtkWidget *toomuchink = gtk_image_new_from_icon_name ("too-much-ink-icon", GTK_ICON_SIZE_SMALL_TOOLBAR);
gtk_container_add (GTK_CONTAINER (_box_toomuchink), toomuchink);
GtkTooltips *tooltips_toomuchink = gtk_tooltips_new ();
gtk_tooltips_set_tip (tooltips_toomuchink, _box_toomuchink, _("Too much ink!"), "");
gtk_widget_set_sensitive (_box_toomuchink, false);
gtk_box_pack_start(GTK_BOX(rgbabox), _box_toomuchink, FALSE, FALSE, 2);
#endif //ENABLE_LCMS
/* Create RGBA entry and color preview */
_rgbal = gtk_label_new_with_mnemonic (_("RGBA_:"));
gtk_misc_set_alignment (GTK_MISC (_rgbal), 1.0, 0.5);
gtk_box_pack_start(GTK_BOX(rgbabox), _rgbal, TRUE, TRUE, 2);
_rgbae = gtk_entry_new ();
sp_dialog_defocus_on_enter (_rgbae);
gtk_entry_set_max_length (GTK_ENTRY (_rgbae), 8);
gtk_entry_set_width_chars (GTK_ENTRY (_rgbae), 8);
gtk_tooltips_set_tip (tt, _rgbae, _("Hexadecimal RGBA value of the color"), NULL);
gtk_box_pack_start(GTK_BOX(rgbabox), _rgbae, FALSE, FALSE, 0);
gtk_label_set_mnemonic_widget (GTK_LABEL(_rgbal), _rgbae);
sp_set_font_size_smaller (rgbabox);
gtk_widget_show_all (rgbabox);
#if ENABLE_LCMS
//the "too much ink" icon is initially hidden
gtk_widget_hide(GTK_WIDGET(_box_toomuchink));
#endif //ENABLE_LCMS
gtk_table_attach (GTK_TABLE (table), rgbabox, 0, 2, row, row + 1, GTK_FILL, GTK_SHRINK, XPAD, YPAD);
#ifdef SPCS_PREVIEW
_p = sp_color_preview_new (0xffffffff);
gtk_widget_show (_p);
gtk_table_attach (GTK_TABLE (table), _p, 2, 3, row, row + 1, GTK_FILL, GTK_FILL, XPAD, YPAD);
#endif
_switchId = g_signal_connect(GTK_OBJECT (_book), "switch-page",
GTK_SIGNAL_FUNC (sp_color_notebook_switch_page), SP_COLOR_NOTEBOOK(_csel));
_entryId = gtk_signal_connect (GTK_OBJECT (_rgbae), "changed", GTK_SIGNAL_FUNC (ColorNotebook::_rgbaEntryChangedHook), _csel);
}
static void
sp_color_notebook_destroy (GtkObject *object)
{
if (((GtkObjectClass *) (parent_class))->destroy)
(* ((GtkObjectClass *) (parent_class))->destroy) (object);
}
ColorNotebook::~ColorNotebook()
{
if ( _trackerList )
{
g_ptr_array_free (_trackerList, TRUE);
_trackerList = 0;
}
if ( _switchId )
{
if ( _book )
{
g_signal_handler_disconnect (_book, _switchId);
_switchId = 0;
}
}
}
static void
sp_color_notebook_show_all (GtkWidget *widget)
{
gtk_widget_show (widget);
}
static void
sp_color_notebook_hide_all (GtkWidget *widget)
{
gtk_widget_hide (widget);
}
GtkWidget *
sp_color_notebook_new (void)
{
SPColorNotebook *colorbook;
colorbook = (SPColorNotebook*)gtk_type_new (SP_TYPE_COLOR_NOTEBOOK);
return GTK_WIDGET (colorbook);
}
ColorNotebook::ColorNotebook( SPColorSelector* csel )
: ColorSelector( csel )
{
}
SPColorSelector* ColorNotebook::getCurrentSelector()
{
SPColorSelector* csel = NULL;
gint current_page = gtk_notebook_get_current_page (GTK_NOTEBOOK (_book));
if ( current_page >= 0 )
{
GtkWidget* widget = gtk_notebook_get_nth_page (GTK_NOTEBOOK (_book), current_page);
if ( SP_IS_COLOR_SELECTOR (widget) )
{
csel = SP_COLOR_SELECTOR (widget);
}
}
return csel;
}
void ColorNotebook::_colorChanged()
{
SPColorSelector* cselPage = getCurrentSelector();
if ( cselPage )
{
cselPage->base->setColorAlpha( _color, _alpha );
}
_updateRgbaEntry( _color, _alpha );
}
void ColorNotebook::_rgbaEntryChangedHook(GtkEntry *entry, SPColorNotebook *colorbook)
{
((ColorNotebook*)(SP_COLOR_SELECTOR(colorbook)->base))->_rgbaEntryChanged( entry );
}
void ColorNotebook::_rgbaEntryChanged(GtkEntry* entry)
{
if (_updating) return;
if (_updatingrgba) return;
const gchar *t = gtk_entry_get_text( entry );
if (t) {
Glib::ustring text = t;
bool changed = false;
if (!text.empty() && text[0] == '#') {
changed = true;
text.erase(0,1);
if (text.size() == 6) {
// it was a standard RGB hex
unsigned int alph = SP_COLOR_F_TO_U(_alpha);
gchar* tmp = g_strdup_printf("%02x", alph);
text += tmp;
g_free(tmp);
}
}
gchar* str = g_strdup(text.c_str());
gchar* end = 0;
guint64 rgba = g_ascii_strtoull( str, &end, 16 );
if ( end != str ) {
ptrdiff_t len = end - str;
if ( len < 8 ) {
rgba = rgba << ( 4 * ( 8 - len ) );
}
_updatingrgba = TRUE;
if ( changed ) {
gtk_entry_set_text( entry, str );
}
SPColor color( rgba );
setColorAlpha( color, SP_RGBA32_A_F(rgba), true );
_updatingrgba = FALSE;
}
g_free(str);
}
}
void ColorNotebook::_updateRgbaEntry( const SPColor& color, gfloat alpha )
{
g_return_if_fail( ( 0.0 <= alpha ) && ( alpha <= 1.0 ) );
#if ENABLE_LCMS
/* update color management icon*/
gtk_widget_set_sensitive (_box_colormanaged, color.icc != NULL);
/* update out-of-gamut icon */
gtk_widget_set_sensitive (_box_outofgamut, false);
if (color.icc){
Inkscape::ColorProfile* target_profile = SP_ACTIVE_DOCUMENT->profileManager->find(color.icc->colorProfile.c_str());
if ( target_profile )
gtk_widget_set_sensitive (_box_outofgamut, target_profile->GamutCheck(color));
}
/* update too-much-ink icon */
gtk_widget_set_sensitive (_box_toomuchink, false);
if (color.icc){
Inkscape::ColorProfile* prof = SP_ACTIVE_DOCUMENT->profileManager->find(color.icc->colorProfile.c_str());
if (prof->getColorSpace() == icSigCmykData || prof->getColorSpace() == icSigCmyData){
gtk_widget_show(GTK_WIDGET(_box_toomuchink));
double ink_sum = 0;
for (unsigned int i=0; i<color.icc->colors.size(); i++){
ink_sum += color.icc->colors[i];
}
/* Some literature states that when the sum of paint values exceed 320%, it is considered to be a satured color,
which means the paper can get too wet due to an excessive ammount of ink. This may lead to several issues
such as misalignment and poor quality of printing in general.*/
if ( ink_sum > 3.2 )
gtk_widget_set_sensitive (_box_toomuchink, true);
} else {
gtk_widget_hide(GTK_WIDGET(_box_toomuchink));
}
}
#endif //ENABLE_LCMS
if ( !_updatingrgba )
{
gchar s[32];
guint32 rgba;
/* Update RGBA entry */
rgba = color.toRGBA32( alpha );
g_snprintf (s, 32, "%08x", rgba);
const gchar* oldText = gtk_entry_get_text( GTK_ENTRY( _rgbae ) );
if ( strcmp( oldText, s ) != 0 )
{
g_signal_handler_block( _rgbae, _entryId );
gtk_entry_set_text( GTK_ENTRY(_rgbae), s );
g_signal_handler_unblock( _rgbae, _entryId );
}
}
}
void ColorNotebook::_entryGrabbed (SPColorSelector *, SPColorNotebook *colorbook)
{
ColorNotebook* nb = (ColorNotebook*)(SP_COLOR_SELECTOR(colorbook)->base);
nb->_grabbed();
}
void ColorNotebook::_entryDragged (SPColorSelector *csel, SPColorNotebook *colorbook)
{
gboolean oldState;
ColorNotebook* nb = (ColorNotebook*)(SP_COLOR_SELECTOR(colorbook)->base);
oldState = nb->_dragging;
nb->_dragging = TRUE;
nb->_entryModified( csel, colorbook );
nb->_dragging = oldState;
}
void ColorNotebook::_entryReleased (SPColorSelector *, SPColorNotebook *colorbook)
{
ColorNotebook* nb = (ColorNotebook*)(SP_COLOR_SELECTOR(colorbook)->base);
nb->_released();
}
void ColorNotebook::_entryChanged (SPColorSelector *csel, SPColorNotebook *colorbook)
{
gboolean oldState;
ColorNotebook* nb = (ColorNotebook*)(SP_COLOR_SELECTOR(colorbook)->base);
oldState = nb->_dragging;
nb->_dragging = FALSE;
nb->_entryModified( csel, colorbook );
nb->_dragging = oldState;
}
void ColorNotebook::_entryModified (SPColorSelector *csel, SPColorNotebook *colorbook)
{
g_return_if_fail (colorbook != NULL);
g_return_if_fail (SP_IS_COLOR_NOTEBOOK (colorbook));
g_return_if_fail (csel != NULL);
g_return_if_fail (SP_IS_COLOR_SELECTOR (csel));
ColorNotebook* nb = (ColorNotebook*)(SP_COLOR_SELECTOR(colorbook)->base);
SPColor color;
gfloat alpha = 1.0;
csel->base->getColorAlpha( color, alpha );
nb->_updateRgbaEntry( color, alpha );
nb->_updateInternals( color, alpha, nb->_dragging );
}
GtkWidget* ColorNotebook::addPage(GType page_type, guint submode)
{
GtkWidget *page;
page = sp_color_selector_new( page_type );
if ( page )
{
GtkWidget* tab_label = 0;
SPColorSelector* csel;
csel = SP_COLOR_SELECTOR (page);
if ( submode > 0 )
{
csel->base->setSubmode( submode );
}
gtk_widget_show (page);
int index = csel->base ? csel->base->getSubmode() : 0;
const gchar* str = _(SP_COLOR_SELECTOR_GET_CLASS (csel)->name[index]);
// g_message( "Hitting up for tab for '%s'", str );
tab_label = gtk_label_new(_(str));
gtk_notebook_append_page( GTK_NOTEBOOK (_book), page, tab_label );
gtk_signal_connect (GTK_OBJECT (page), "grabbed", GTK_SIGNAL_FUNC (_entryGrabbed), _csel);
gtk_signal_connect (GTK_OBJECT (page), "dragged", GTK_SIGNAL_FUNC (_entryDragged), _csel);
gtk_signal_connect (GTK_OBJECT (page), "released", GTK_SIGNAL_FUNC (_entryReleased), _csel);
gtk_signal_connect (GTK_OBJECT (page), "changed", GTK_SIGNAL_FUNC (_entryChanged), _csel);
}
return page;
}
GtkWidget* ColorNotebook::getPage(GType page_type, guint submode)
{
gint count = 0;
gint i = 0;
GtkWidget* page = 0;
// count = gtk_notebook_get_n_pages (_book);
count = 200;
for ( i = 0; i < count && !page; i++ )
{
page = gtk_notebook_get_nth_page (GTK_NOTEBOOK (_book), i);
if ( page )
{
SPColorSelector* csel;
guint pagemode;
csel = SP_COLOR_SELECTOR (page);
pagemode = csel->base->getSubmode();
if ( G_TYPE_FROM_INSTANCE (page) == page_type
&& pagemode == submode )
{
// found it.
break;
}
else
{
page = 0;
}
}
else
{
break;
}
}
return page;
}
void ColorNotebook::removePage( GType page_type, guint submode )
{
GtkWidget *page = 0;
page = getPage(page_type, submode);
if ( page )
{
gint where = gtk_notebook_page_num (GTK_NOTEBOOK (_book), page);
if ( where >= 0 )
{
if ( gtk_notebook_get_current_page (GTK_NOTEBOOK (_book)) == where )
{
// getColorAlpha(_color, &_alpha);
}
gtk_notebook_remove_page (GTK_NOTEBOOK (_book), where);
}
}
}
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :