swatches.cpp revision 57d4715f4806f2a8caac4bca519d878381a3356c
/** @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 <gtk/gtkmenuitem.h>
#include <gtk/gtkseparatormenuitem.h>
#include "inkscape.h"
#include "desktop.h"
#include "message-context.h"
#include "document.h"
#include "desktop-handles.h"
#include "inkscape.h"
#include "svg/svg-color.h"
#include "desktop-style.h"
#include "path-prefix.h"
#include "swatches.h"
#include "sp-item.h"
#include "preferences.h"
#include "eek-preview.h"
namespace Inkscape {
namespace UI {
namespace Dialogs {
_isRemove(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;
}
class JustForNow
{
public:
JustForNow() : _prefWidth(0) {}
int _prefWidth;
};
typedef enum {
APP_X_INKY_COLOR_ID = 0,
APP_X_INKY_COLOR = 0,
static const GtkTargetEntry sourceColorEntries[] = {
// {(gchar*) "application/x-inkscape-color-id", GTK_TARGET_SAME_APP, APP_X_INKY_COLOR_ID},
#endif // ENABLE_MAGIC_COLORS
};
{
(void)widget;
(void)drag_context;
(void)time;
gchar* tmp = g_strdup_printf("#%02x%02x%02x", item->def.getR(), item->def.getG(), item->def.getB() );
8, // format
tmp = 0;
} else if ( info == APP_X_INKY_COLOR ) {
// Find where this thing came from
bool found = false;
int index = 0;
for ( std::vector<JustForNow*>::iterator it = possible.begin(); it != possible.end() && !found; ++it ) {
index = 0;
for ( std::vector<ColorItem*>::iterator zz = curr->_colors.begin(); zz != curr->_colors.end(); ++zz ) {
found = true;
break;
} else {
index++;
}
}
}
// if ( found ) {
// g_message("Found the color at entry %d in palette '%s'", index, paletteName.c_str() );
// } else {
// g_message("Unable to find the color");
// }
for ( unsigned int i = 0; i < paletteName.length(); i++ ) {
}
16, // format
itemCount * 2);
delete[] tmp;
} else {
16, // format
(3+1) * 2);
}
}
{
(void)widget;
if ( item )
{
gsize bytesWritten = 0;
-1,
&error);
return;
}
}
}
//"drag-drop"
// gboolean dragDropColorData( GtkWidget *widget,
// GdkDragContext *drag_context,
// gint x,
// gint y,
// guint time,
// gpointer user_data)
// {
// // TODO finish
// return TRUE;
// }
(void)widget;
if ( item ) {
item->buttonClicked(false);
}
}
(void)widget;
(void)arg1;
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;
{
(void)user_data;
if ( bounceTarget ) {
}
}
{
(void)user_data;
if ( bounceTarget ) {
}
}
{
(void)widget;
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",
}
if ( item ) {
bounceTarget = item;
if ( popupMenu ) {
}
}
}
return handled;
}
{
}
static const GtkTargetEntry destColorTargets[] = {
// {(gchar*) "application/x-inkscape-color-id", GTK_TARGET_SAME_APP, APP_X_INKY_COLOR_ID},
#endif // ENABLE_MAGIC_COLORS
};
#include "color.h" // for SP_RGBA32_U_COMPOSE
{
(void)widget;
(void)drag_context;
(void)x;
(void)y;
(void)event_time;
// g_message(" droppy droppy %d", info);
switch (info) {
case APP_X_INKY_COLOR:
{
// Careful about endian issues.
if ( user_data ) {
// Shove on in the new value
item->def.setRGB( 0x0ff & (dataVals[0] >> 8), 0x0ff & (dataVals[1] >> 8), 0x0ff & (dataVals[2] >> 8) );
}
}
}
break;
}
case APP_X_COLOR:
{
// Careful about endian issues.
// {
// gchar c[64] = {0};
// sp_svg_write_color( c, 64,
// SP_RGBA32_U_COMPOSE(
// 0x0ff & (dataVals[0] >> 8),
// 0x0ff & (dataVals[1] >> 8),
// 0x0ff & (dataVals[2] >> 8),
// 0xff // can't have transparency in the color itself
// //0x0ff & (data->data[3] >> 8),
// ));
// }
if ( user_data ) {
// Shove on in the new value
item->def.setRGB( 0x0ff & (dataVals[0] >> 8), 0x0ff & (dataVals[1] >> 8), 0x0ff & (dataVals[2] >> 8) );
}
}
}
break;
}
default:
g_message("unknown drop type");
}
}
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 = " ";
// }
eek_preview_set_color( preview, (def.getR() << 8) | def.getR(), (def.getG() << 8) | def.getG(), (def.getB() << 8) | def.getB());
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);
"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() )
{
"drag-data-received",
this );
}
"destroy",
this);
}
return widget;
}
{
if (!desktop) return;
gchar c[64];
if (!_isRemove){
sp_svg_write_color(c, sizeof(c), rgba);
}
if (_isRemove){
} else {
}
}
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)
{
_holder = new PreviewHolder();
loadEmUp();
JustForNow* first = 0;
if ( !_prefs_path.empty() ) {
if (!targetName.empty()) {
for ( std::vector<JustForNow*>::iterator iter = possible.begin(); iter != possible.end(); ++iter ) {
break;
}
}
}
}
if ( !first ) {
}
if ( first->_prefWidth > 0 ) {
}
_holder->freezeUpdates();
for ( std::vector<ColorItem*>::iterator it = first->_colors.begin(); it != first->_colors.end(); it++ ) {
}
_holder->thawUpdates();
int i = 0;
}
i++;
}
}
if ( hotItem ) {
hotItem->set_active();
}
}
{
}
{
// Must call the parent class or bad things might happen
if ( _holder )
{
}
}
{
switch( setId ) {
case 3:
{
if ( !_prefs_path.empty() ) {
}
if ( curr->_prefWidth > 0 ) {
}
_holder->freezeUpdates();
for ( std::vector<ColorItem*>::iterator it = curr->_colors.begin(); it != curr->_colors.end(); it++ ) {
}
_holder->thawUpdates();
}
}
break;
}
}
} //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 :