swatches.cpp revision 839598cdda20adbc1a3b5d0982c13558440d1fcb
/** @file
* @brief Color swatches dialog
*/
/* Authors:
* Jon A. Cruz
* John Bintz
*
* Copyright (C) 2005 Jon A. Cruz
* Copyright (C) 2008 John Bintz
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#include <errno.h>
#include <map>
#include <gtk/gtkmenuitem.h>
#include <gtk/gtkseparatormenuitem.h>
#include "desktop.h"
#include "desktop-handles.h"
#include "desktop-style.h"
#include "document.h"
#include "document-private.h"
#include "inkscape.h"
#include "inkscape.h"
#include "io/resource.h"
#include "message-context.h"
#include "path-prefix.h"
#include "preferences.h"
#include "sp-item.h"
#include "svg/svg-color.h"
#include "sp-gradient-fns.h"
#include "sp-gradient.h"
#include "sp-gradient-vector.h"
#include "swatches.h"
#include "style.h"
#include "widgets/gradient-vector.h"
#include "widgets/eek-preview.h"
#include "display/nr-plain-stuff.h"
#include "sp-gradient-reference.h"
#define USE_DOCUMENT_PALETTE 1
namespace Inkscape {
namespace UI {
namespace Dialogs {
#define VBLOCK 16
/**
* The color swatch you see on screen as a clickable box.
*/
{
public:
ColorItem( unsigned int r, unsigned int g, unsigned int b,
virtual ~ColorItem();
::PreviewSize size,
void buttonClicked(bool secondary = false);
void* ptr;
private:
static void _wireMagicColors( void* p );
static void _colorDefChanged(void* data);
bool _isFill;
bool _isStroke;
bool _isLive;
bool _linkIsTone;
int _linkPercent;
int _linkGray;
};
ptr(0),
_isFill(false),
_isStroke(false),
_isLive(false),
_linkIsTone(false),
_linkPercent(0),
_linkGray(0),
_linkSrc(0)
{
}
ptr(0),
_isFill(false),
_isStroke(false),
_isLive(false),
_linkIsTone(false),
_linkPercent(0),
_linkGray(0),
_linkSrc(0)
{
}
{
}
{
if ( this != &other ) {
*this = other;
}
}
{
if ( this != &other ) {
// TODO - correct linkage
g_message("Erk!");
}
return *this;
}
{
if ( _isFill ) {
val |= PREVIEW_FILL;
}
if ( _isStroke ) {
val |= PREVIEW_STROKE;
}
}
}
}
}
class JustForNow
{
public:
JustForNow() : _prefWidth(0) {}
int _prefWidth;
};
GdkDragContext */*drag_context*/,
guint /*time*/,
{
} else {
}
char* tmp = 0;
int len = 0;
int format = 0;
if ( tmp ) {
delete[] tmp;
}
}
}
{
if ( item )
{
int width = 32;
int height = 24;
gsize bytesWritten = 0;
-1,
&error);
} else {
Glib::RefPtr<Gdk::Pixbuf> thumb = Gdk::Pixbuf::create( Gdk::COLORSPACE_RGB, false, 8, width, height );
} else {
0, // add delete function
0 );
}
}
}
}
//"drag-drop"
// gboolean dragDropColorData( GtkWidget *widget,
// GdkDragContext *drag_context,
// gint x,
// gint y,
// guint time,
// gpointer user_data)
// {
// // TODO finish
// return TRUE;
// }
if ( item ) {
item->buttonClicked(false);
}
}
if ( item ) {
item->buttonClicked(true);
}
}
static gboolean handleEnterNotify( GtkWidget* /*widget*/, GdkEventCrossing* /*event*/, gpointer callback_data ) {
if ( item ) {
if ( desktop ) {
gchar* msg = g_strdup_printf(_("Color: <b>%s</b>; <b>Click</b> to set fill, <b>Shift+click</b> to set stroke"),
}
}
return FALSE;
}
static gboolean handleLeaveNotify( GtkWidget* /*widget*/, GdkEventCrossing* /*event*/, gpointer callback_data ) {
if ( item ) {
if ( desktop ) {
}
}
return FALSE;
}
static ColorItem* bounceTarget = 0;
{
if ( bounceTarget ) {
}
}
{
if ( bounceTarget ) {
}
}
{
if ( gr ) {
}
}
{
if ( bounceTarget ) {
if (doc) {
editGradientImpl( grad );
break;
}
}
}
}
}
{
if ( bounceTarget ) {
if (doc) {
editGradientImpl( gr );
// Work-around for timing of gradient addition change. Must follow edit.
if ( swp ) {
}
}
}
}
#endif // USE_DOCUMENT_PALETTE
static gboolean handleButtonPress( GtkWidget* /*widget*/, GdkEventButton* event, gpointer user_data)
{
if ( !popupMenu ) {
popupMenu = gtk_menu_new();
//TRANSLATORS: An item in context menu on a colour in the swatches
"activate",
//TRANSLATORS: An item in context menu on a colour in the swatches
"activate",
"activate",
user_data );
//popupExtras.push_back(child);
"activate",
user_data );
//popupExtras.push_back(child);
#endif // USE_DOCUMENT_PALETTE
}
if ( item ) {
}
bounceTarget = item;
if ( popupMenu ) {
}
}
}
return handled;
}
{
}
#include "color.h" // for SP_RGBA32_U_COMPOSE
GdkDragContext */*drag_context*/,
GtkSelectionData */*data*/,
guint /*info*/,
guint /*event_time*/,
gpointer /*user_data*/)
{
}
static bool bruteForce( SPDocument* document, Inkscape::XML::Node* node, Glib::ustring const& match, int r, int g, int b )
{
bool changed = false;
if ( node ) {
gchar c[64] = {0};
changed = true;
}
gchar c[64] = {0};
changed = true;
}
}
return changed;
}
{
if ( item ) {
for ( std::vector<Gtk::Widget*>::iterator it = item->_previews.begin(); it != item->_previews.end(); ++it ) {
widget->queue_draw();
}
}
for ( std::vector<ColorItem*>::iterator it = item->_listeners.begin(); it != item->_listeners.end(); ++it ) {
if ( (*it)->_linkIsTone ) {
} else {
}
}
// Look for objects using this color
{
if ( desktop ) {
if ( rroot ) {
// Find where this thing came from
bool found = false;
int index = 0;
for ( std::vector<JustForNow*>::iterator it2 = possible.begin(); it2 != possible.end() && !found; ++it2 ) {
index = 0;
for ( std::vector<ColorItem*>::iterator zz = curr->_colors.begin(); zz != curr->_colors.end(); ++zz ) {
found = true;
break;
} else {
index++;
}
}
}
if ( !paletteName.empty() ) {
str = 0;
if ( bruteForce( document, rroot, paletteName, item->def.getR(), item->def.getG(), item->def.getB() ) ) {
_("Change color definition"));
}
}
}
}
}
}
}
Gtk::Widget* ColorItem::getPreview(PreviewStyle style, ViewType view, ::PreviewSize size, guint ratio)
{
if ( style == PREVIEW_STYLE_BLURB) {
} else {
// Glib::ustring blank(" ");
// if ( size == Inkscape::ICON_SIZE_MENU || size == Inkscape::ICON_SIZE_DECORATION ) {
// blank = " ";
// }
} else {
int width = 128;
int height = 16;
0, // add delete function
0 );
}
gsize bytesWritten = 0;
-1,
&error);
if (!pixbuf) {
}
}
eek_preview_set_details( preview, (::PreviewStyle)style, (::ViewType)view, (::PreviewSize)size, ratio );
| (_isLive ? PREVIEW_LINK_OTHER:0)) );
/*
Gtk::Button *btn = new Gtk::Button(blank);
Gdk::Color color;
color.set_rgb((_r << 8)|_r, (_g << 8)|_g, (_b << 8)|_b);
btn->modify_bg(Gtk::STATE_NORMAL, color);
btn->modify_bg(Gtk::STATE_ACTIVE, color);
btn->modify_bg(Gtk::STATE_PRELIGHT, color);
btn->modify_bg(Gtk::STATE_SELECTED, color);
Gtk::Widget* newBlot = btn;
*/
/*
newBlot->signal_clicked().connect( sigc::mem_fun(*this, &ColorItem::buttonClicked) );
sigc::signal<void> type_signal_something;
*/
"clicked",
this);
"alt-clicked",
this);
"button-press-event",
this);
{
// these next lines are order-dependent:
}
curr++;
}
for ( int i = 0; i < entryCount; i++ ) {
}
delete[] entries;
}
"drag-data-get",
this);
"drag-begin",
this );
"enter-notify-event",
this);
"leave-notify-event",
this);
// g_signal_connect( G_OBJECT(newBlot->gobj()),
// "drag-drop",
// G_CALLBACK(dragDropColorData),
// this);
if ( def.isEditable() )
{
// gtk_drag_dest_set( GTK_WIDGET(newBlot->gobj()),
// GTK_DEST_DEFAULT_ALL,
// destColorTargets,
// G_N_ELEMENTS(destColorTargets),
// GdkDragAction(GDK_ACTION_COPY | GDK_ACTION_MOVE) );
// g_signal_connect( G_OBJECT(newBlot->gobj()),
// "drag-data-received",
// G_CALLBACK(_dropDataIn),
// this );
}
"destroy",
this);
}
return widget;
}
{
if (desktop) {
// TODO actually make this clear
break;
}
break;
}
gchar c[64];
sp_svg_write_color(c, sizeof(c), rgba);
colorspec = c;
} else {
colorspec = "url(#";
colorspec += ")";
}
break;
}
}
}
}
str++;
}
while ( *str ) {
str++;
}
str--;
*str-- = 0;
}
return ret;
}
void skipWhitespace( char*& str ) {
str++;
}
}
val = 0;
str++;
}
return retval;
}
{
bool good = false;
{
good = true;
}
}
}
return good;
}
{
bool good = false;
}
// overflow
// failed conversion
} else {
good = true;
}
}
return good;
}
void ColorItem::_wireMagicColors( void* p )
{
if ( onceMore )
{
for ( std::vector<ColorItem*>::iterator it = onceMore->_colors.begin(); it != onceMore->_colors.end(); ++it )
{
{
{
//g_message("FOUND MAGIC at '%s'", (*it)->def.descr.c_str());
//g_message(" '%s'", subby.c_str());
{
}
{
}
// Tint. index + 1 more val.
guint64 colorIndex = 0;
}
}
}
guint64 colorIndex = 0;
grayLevel = 0;
}
}
}
}
}
}
}
}
}
{
if ( !_linkSrc )
{
_linkIsTone = false;
if ( _linkPercent > 100 )
_linkPercent = 100;
if ( _linkPercent < 0 )
_linkPercent = 0;
_linkGray = 0;
}
}
{
if ( !_linkSrc )
{
_linkIsTone = true;
if ( _linkPercent > 100 )
_linkPercent = 100;
if ( _linkPercent < 0 )
_linkPercent = 0;
}
}
{
char block[1024];
if ( f ) {
if ( result ) {
bool inHeader = true;
bool hasErr = false;
do {
if ( result ) {
if ( block[0] == '#' ) {
// ignore comment
} else {
// very simple check for header versus entry
ptr++;
}
// blank line. skip it.
// should be an entry link
inHeader = false;
int r = 0;
int g = 0;
int b = 0;
if ( *ptr ) {
if ( !hasErr ) {
}
if ( !hasErr ) {
}
if (n != NULL) {
name = n;
}
}
if ( !hasErr ) {
// Add the entry now
}
} else {
hasErr = true;
}
} else {
if ( !inHeader ) {
// Hmmm... probably bad. Not quite the format we want?
hasErr = true;
} else {
if ( sep ) {
*sep = 0;
if ( *name ) {
{
}
{
// overflow
// failed conversion
} else {
}
}
} else {
// error
hasErr = true;
}
} else {
// error
hasErr = true;
}
}
}
}
}
if ( !hasErr ) {
#endif // ENABLE_MAGIC_COLORS
} else {
delete onceMore;
}
}
}
fclose(f);
}
}
static void loadEmUp()
{
static bool beenHere = false;
if ( !beenHere ) {
beenHere = true;
// Use this loop to iterate through a list of possible document locations.
if (!directory) {
} else {
// if ( g_str_has_suffix(lower, ".gpl") ) {
}
// }
}
}
}
// toss the dirname
}
}
}
{
return *new SwatchesPanel();
}
/**
* Constructor
*/
_holder(0),
_clear(0),
_remove(0),
_currentIndex(0),
_currentDesktop(0),
_currentDocument(0),
_ptr(0)
{
_holder = new PreviewHolder();
{
_ptr = docPalette;
}
#endif // USE_DOCUMENT_PALETTE
loadEmUp();
JustForNow* first = 0;
int index = 0;
if ( !_prefs_path.empty() ) {
if (!targetName.empty()) {
for ( std::vector<JustForNow*>::iterator iter = possible.begin(); iter != possible.end(); ++iter ) {
break;
}
index++;
}
}
}
if ( !first ) {
_currentIndex = 0;
} else {
}
_rebuild();
int i = 0;
}
i++;
}
}
if ( hotItem ) {
hotItem->set_active();
}
}
{
if ( _clear ) {
delete _clear;
}
if ( _remove ) {
delete _remove;
}
if ( _holder ) {
delete _holder;
}
}
{
// Must call the parent class or bad things might happen
if ( _holder )
{
}
}
{
if ( desktop != _currentDesktop ) {
if ( _currentDesktop ) {
}
if ( desktop ) {
sigc::bound_mem_functor1<void, Inkscape::UI::Dialogs::SwatchesPanel, SPDocument*> first = sigc::mem_fun(*this, &SwatchesPanel::_setDocument);
} else {
_setDocument(0);
}
}
}
{
if ( document != _currentDocument ) {
if ( _currentDocument ) {
}
if ( _currentDocument ) {
"gradient",
}
}
}
void SwatchesPanel::handleGradientsChange()
{
}
}
if ( _ptr ) {
// TODO delete pointed to objects
{
// At the moment we can't trust the count of 1 vs 2 stops.
// Treat as solid-color
unsigned int r = SP_RGBA32_R_U(together);
unsigned int g = SP_RGBA32_G_U(together);
unsigned int b = SP_RGBA32_B_U(together);
} else {
// Treat as gradient
unsigned int r = SP_RGBA32_R_U(together);
unsigned int g = SP_RGBA32_G_U(together);
unsigned int b = SP_RGBA32_B_U(together);
}
}
}
}
if (curr == docPalette) {
_rebuild();
}
}
#endif // USE_DOCUMENT_PALETTE
}
void SwatchesPanel::_updateFromSelection()
{
if ( _ptr ) {
switch (result) {
case QUERY_STYLE_SINGLE:
{
if ( SP_IS_GRADIENT(server) ) {
SPGradient* target = 0;
}
}
if ( target ) {
if ( id ) {
}
}
}
}
break;
}
}
switch (result) {
case QUERY_STYLE_SINGLE:
{
if ( SP_IS_GRADIENT(server) ) {
SPGradient* target = 0;
}
}
if ( target ) {
if ( id ) {
}
}
}
}
break;
}
}
for ( std::vector<ColorItem*>::iterator it = docPalette->_colors.begin(); it != docPalette->_colors.end(); ++it ) {
}
}
#endif // USE_DOCUMENT_PALETTE
}
{
switch( setId ) {
case 3:
{
if ( !_prefs_path.empty() ) {
}
_rebuild();
}
}
break;
}
}
void SwatchesPanel::_rebuild()
{
if ( curr->_prefWidth > 0 ) {
}
_holder->freezeUpdates();
// TODO restore once 'clear' works _holder->addPreview(_clear);
for ( std::vector<ColorItem*>::iterator it = curr->_colors.begin(); it != curr->_colors.end(); it++ ) {
}
_holder->thawUpdates();
}
} //namespace Dialogs
} //namespace UI
} //namespace Inkscape
/*
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 :