swatches.cpp revision bdd77920088d5498d22675b0ed6c1cdb843bc51b
/**
* @file
* Color swatches dialog.
*/
/* Authors:
* Jon A. Cruz
* John Bintz
* Abhishek Sharma
*
* 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 <algorithm>
#include <set>
#include "swatches.h"
#include <gtkmm/radiomenuitem.h>
#include "color-item.h"
#include "desktop.h"
#include "desktop-handles.h"
#include "desktop-style.h"
#include "document.h"
#include "document-private.h"
#include "document-undo.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 "sp-gradient.h"
#include "sp-gradient-vector.h"
#include "style.h"
#include "ui/previewholder.h"
#include "widgets/desktop-widget.h"
#include "widgets/gradient-vector.h"
#include "widgets/eek-preview.h"
#include "display/cairo-utils.h"
#include "sp-gradient-reference.h"
#include "dialog-manager.h"
#include "selection.h"
#include "verbs.h"
#include "gradient-chemistry.h"
#include "helper/action-context.h"
namespace Inkscape {
namespace UI {
namespace Dialogs {
#define VBLOCK 16
#define PREVIEW_PIXBUF_WIDTH 128
class SwatchesPanelHook : public SwatchesPanel
{
public:
};
if ( item ) {
item->buttonClicked(false);
}
}
if ( item ) {
item->buttonClicked(true);
}
}
static GtkWidget *popupSubHolder = 0;
static ColorItem* bounceTarget = 0;
static SwatchesPanel* bouncePanel = 0;
{
if ( bounceTarget ) {
}
}
{
if ( bounceTarget ) {
}
}
{
if ( gr ) {
bool shown = false;
if (items) {
// could be pertinent
if ( SP_IS_GRADIENT(server) ) {
shown = true;
}
}
}
}
}
}
if (!shown) {
// Legacy gradient dialog
} else {
// Invoke the gradient tool
if ( verb ) {
SPAction *action = verb->get_action( Inkscape::ActionContext( ( Inkscape::UI::View::View * ) SP_ACTIVE_DESKTOP ) );
if ( action ) {
}
}
}
}
}
}
{
if ( bounceTarget ) {
if (doc) {
break;
}
}
}
}
}
{
if ( bounceTarget ) {
_("Add gradient stop"));
break;
}
}
}
}
}
{
if ( bounceTarget ) {
}
}
{
SwatchesPanel *swp = 0;
for (std::map<SwatchesPanel*, SPDocument*>::iterator it = docPerPanel.begin(); it != docPerPanel.end(); ++it) {
}
}
}
return swp;
}
{
}
/* extern'ed from colot-item.cpp */
gboolean colorItemHandleButtonPress( 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 );
"activate",
user_data );
//popupExtras.push_back(child);
//gtk_widget_set_sensitive( child, FALSE );
{
popupSub = gtk_menu_new();
}
}
if ( user_data ) {
}
bounceTarget = item;
bouncePanel = swp;
popupItems.clear();
if ( popupMenu ) {
bool processed = false;
if ( wdgt ) {
// Pick up all gradients with vectors
//gl = g_slist_prepend(gl, curr->data);
processed = true;
"activate",
GINT_TO_POINTER(index) );
index++;
}
}
}
}
}
}
}
return handled;
}
str++;
}
while ( *str ) {
str++;
}
str--;
*str-- = 0;
}
return ret;
}
static void skipWhitespace( char*& str ) {
str++;
}
}
val = 0;
str++;
}
return retval;
}
{
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;
if ( *ptr ) {
int r = 0;
int g = 0;
int b = 0;
if ( !hasErr ) {
}
if ( !hasErr ) {
}
if (n != NULL) {
}
}
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 ) {
if (user)
else
#endif // ENABLE_MAGIC_COLORS
} else {
delete onceMore;
}
}
}
fclose(f);
}
}
static bool
}
static void loadEmUp()
{
static bool beenHere = false;
gboolean userPalete = true;
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
userPalete = false;
}
}
}
{
return *new SwatchesPanel();
}
/**
* Constructor
*/
_holder(0),
_clear(0),
_remove(0),
_currentIndex(0),
_currentDesktop(0),
{
_holder = new PreviewHolder();
if (docPalettes.empty()) {
docPalettes[0] = docPalette;
}
loadEmUp();
if ( !systemSwatchPages.empty() ) {
SwatchPage* first = 0;
int index = 0;
if ( !_prefs_path.empty() ) {
if (!targetName.empty()) {
if (targetName == "Auto") {
first = docPalettes[0];
} else {
//index++;
break;
}
index++;
}
}
}
}
if ( !first ) {
first = docPalettes[0];
_currentIndex = 0;
} else {
}
_rebuild();
int i = 0;
}
i++;
}
}
#if WITH_GTKMM_3_0
#else
sreq = size_request();
#endif
int minHeight = 60;
}
}
if ( hotItem ) {
hotItem->set_active();
}
}
{
_trackDocument( this, 0 );
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);
}
}
}
class DocTrack
{
public:
DocTrack(SPDocument *doc, sigc::connection &docDestroy, sigc::connection &gradientRsrcChanged, sigc::connection &defsChanged, sigc::connection &defsModified) :
updatePending(false),
lastGradientUpdate(0.0),
{
if ( !timer ) {
}
}
~DocTrack()
{
if ( timerRefCount <= 0 ) {
timerRefCount = 0;
if ( timer ) {
delete timer;
timer = 0;
}
}
if (doc) {
}
}
static bool handleTimerCB();
/**
* Checks if update should be queued or executed immediately.
*
* @return true if the update was queued and should not be immediately executed.
*/
static int timerRefCount;
bool updatePending;
double lastGradientUpdate;
private:
};
int DocTrack::timerRefCount = 0;
static const double DOC_UPDATE_THREASHOLD = 0.090;
bool DocTrack::handleTimerCB()
{
}
}
if ( std::find(docTrackings.begin(), docTrackings.end(), track) != docTrackings.end() ) { // Just in case one gets deleted while we are looping
// Note: calling handleDefsModified will call queueUpdateIfNeeded and thus update the time and flag.
}
}
return true;
}
{
bool deferProcessing = false;
if ( elapsed < DOC_UPDATE_THREASHOLD ) {
deferProcessing = true;
track->updatePending = true;
} else {
track->updatePending = false;
}
break;
}
}
return deferProcessing;
}
{
if (!oldDoc) {
}
}
if (oldDoc) {
bool found = false;
for (std::map<SwatchesPanel*, SPDocument*>::iterator it = docPerPanel.begin(); (it != docPerPanel.end()) && !found; ++it) {
}
if (!found) {
delete *it;
break;
}
}
}
}
if (document) {
bool found = false;
for (std::map<SwatchesPanel*, SPDocument*>::iterator it = docPerPanel.begin(); (it != docPerPanel.end()) && !found; ++it) {
}
if (!found) {
sigc::connection conn0 = document->connectDestroy(sigc::bind(sigc::ptr_fun(&SwatchesPanel::handleDocumentDestroy), document));
sigc::connection conn1 = document->connectResourcesChanged( "gradient", sigc::bind(sigc::ptr_fun(&SwatchesPanel::handleGradientsChange), document) );
sigc::connection conn2 = document->getDefs()->connectRelease( sigc::hide(sigc::bind(sigc::ptr_fun(&SwatchesPanel::handleDefsModified), document)) );
sigc::connection conn3 = document->getDefs()->connectModified( sigc::hide(sigc::hide(sigc::bind(sigc::ptr_fun(&SwatchesPanel::handleDefsModified), document))) );
}
}
}
}
}
{
if ( document != _currentDocument ) {
_trackDocument(this, document);
}
}
{
if (doc) {
}
}
}
{
}
}
}
{
if (document) {
delete *it;
break;
}
}
}
for (std::map<SwatchesPanel*, SPDocument*>::iterator it = docPerPanel.begin(); it != docPerPanel.end(); ++it) {
{
}
break;
}
}
}
}
{
SwatchPage *docPalette = (docPalettes.find(document) != docPalettes.end()) ? docPalettes[document] : 0;
if (docPalette) {
for (std::map<ColorItem*, cairo_pattern_t*>::iterator it = tmpPrevs.begin(); it != tmpPrevs.end(); ++it) {
}
for (std::map<ColorItem*, SPGradient*>::iterator it = tmpGrads.begin(); it != tmpGrads.end(); ++it) {
}
// Figure out which SwatchesPanel instances are affected and update them.
for (std::map<SwatchesPanel*, SPDocument*>::iterator it = docPerPanel.begin(); it != docPerPanel.end(); ++it) {
if (curr == docPalette) {
}
}
}
}
}
{
SwatchPage *docPalette = (docPalettes.find(document) != docPalettes.end()) ? docPalettes[document] : 0;
} else {
for (int i = 0; i < cap; i++) {
}
}
}
}
}
for (std::map<ColorItem*, cairo_pattern_t*>::iterator it = tmpPrevs.begin(); it != tmpPrevs.end(); ++it) {
}
}
}
{
}
return tmp;
}
void SwatchesPanel::_updateFromSelection()
{
SwatchPage *docPalette = (docPalettes.find(_currentDocument) != docPalettes.end()) ? docPalettes[_currentDocument] : 0;
if ( docPalette ) {
switch (result) {
case QUERY_STYLE_SINGLE:
{
if ( SP_IS_GRADIENT(server) ) {
SPGradient* target = 0;
}
}
if ( target ) {
//XML Tree being used directly here while it shouldn't be
if ( id ) {
}
}
}
}
break;
}
}
switch (result) {
case QUERY_STYLE_SINGLE:
{
if ( SP_IS_GRADIENT(server) ) {
SPGradient* target = 0;
}
}
if ( target ) {
//XML Tree being used directly here while it shouldn't be
if ( id ) {
}
}
}
}
break;
}
}
for ( boost::ptr_vector<ColorItem>::iterator it = docPalette->_colors.begin(); it != docPalette->_colors.end(); ++it ) {
}
}
}
{
switch( setId ) {
case 3:
{
}
break;
}
}
{
if ( !_prefs_path.empty() ) {
}
_rebuild();
}
}
void SwatchesPanel::_rebuild()
{
if ( curr->_prefWidth > 0 ) {
}
_holder->freezeUpdates();
// TODO restore once 'clear' works _holder->addPreview(_clear);
for ( boost::ptr_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:fileencoding=utf-8:textwidth=99 :