summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 5a931dc)
raw | patch | inline | side by side (parent: 5a931dc)
author | Jon A. Cruz <jon@joncruz.org> | |
Tue, 16 Mar 2010 07:24:31 +0000 (00:24 -0700) | ||
committer | Jon A. Cruz <jon@joncruz.org> | |
Tue, 16 Mar 2010 07:24:31 +0000 (00:24 -0700) |
src/ui/dialog/color-item.cpp | patch | blob | history | |
src/ui/dialog/color-item.h | patch | blob | history | |
src/ui/dialog/swatches.cpp | patch | blob | history | |
src/ui/dialog/swatches.h | patch | blob | history |
index f0f98a347213bd7acd8f591adb7be317bd7bfeb4..8eed4e4ac54ce55ed8212a40b277288aba06ee1b 100644 (file)
static std::map<std::string, guint> mimeToInt;
+#if ENABLE_MAGIC_COLORS
// TODO remove this soon:
-extern std::vector<JustForNow*> possible;
+extern std::vector<SwatchPage*> possible;
+#endif // ENABLE_MAGIC_COLORS
+#if ENABLE_MAGIC_COLORS
static bool bruteForce( SPDocument* document, Inkscape::XML::Node* node, Glib::ustring const& match, int r, int g, int b )
{
bool changed = false;
return changed;
}
+#endif // ENABLE_MAGIC_COLORS
static void handleClick( GtkWidget* /*widget*/, gpointer callback_data ) {
ColorItem* item = reinterpret_cast<ColorItem*>(callback_data);
@@ -246,21 +250,21 @@ static void colorItemDragBegin( GtkWidget */*widget*/, GdkDragContext* dc, gpoin
// }
-JustForNow::JustForNow() :
+SwatchPage::SwatchPage() :
_name(),
_prefWidth(0),
_colors()
{
}
-JustForNow::~JustForNow()
+SwatchPage::~SwatchPage()
{
}
ColorItem::ColorItem(ege::PaintDef::ColorType type) :
+ Previewable(),
def(type),
- ptr(0),
tips(),
_previews(),
_isFill(false),
_linkPercent(0),
_linkGray(0),
_linkSrc(0),
+ _grad(0),
_pixData(0),
_pixWidth(0),
_pixHeight(0),
}
ColorItem::ColorItem( unsigned int r, unsigned int g, unsigned int b, Glib::ustring& name ) :
+ Previewable(),
def( r, g, b, name ),
- ptr(0),
tips(),
_previews(),
_isFill(false),
@@ -289,6 +294,7 @@ ColorItem::ColorItem( unsigned int r, unsigned int g, unsigned int b, Glib::ustr
_linkPercent(0),
_linkGray(0),
_linkSrc(0),
+ _grad(0),
_pixData(0),
_pixWidth(0),
_pixHeight(0),
}
+#if ENABLE_MAGIC_COLORS
// Look for objects using this color
{
SPDesktop *desktop = SP_ACTIVE_DESKTOP;
Glib::ustring paletteName;
bool found = false;
int index = 0;
- for ( std::vector<JustForNow*>::iterator it2 = possible.begin(); it2 != possible.end() && !found; ++it2 ) {
- JustForNow* curr = *it2;
+ for ( std::vector<SwatchPage*>::iterator it2 = possible.begin(); it2 != possible.end() && !found; ++it2 ) {
+ SwatchPage* curr = *it2;
index = 0;
for ( std::vector<ColorItem*>::iterator zz = curr->_colors.begin(); zz != curr->_colors.end(); ++zz ) {
if ( this == *zz ) {
}
}
}
+#endif // ENABLE_MAGIC_COLORS
}
}
}
-void ColorItem::_wireMagicColors( JustForNow *colorSet )
+void ColorItem::_wireMagicColors( SwatchPage *colorSet )
{
if ( colorSet )
{
index a7599964e66126dc1207d57fb5c3c2d354831aac..4aac86a3074f44898a247e998963887310648dc7 100644 (file)
class ColorItem;
-class JustForNow
+class SwatchPage
{
public:
- JustForNow();
- ~JustForNow();
+ SwatchPage();
+ ~SwatchPage();
Glib::ustring _name;
int _prefWidth;
bool isStroke() { return _isStroke; }
ege::PaintDef def;
- void* ptr;
private:
+
static void _dropDataIn( GtkWidget *widget,
GdkDragContext *drag_context,
gint x, gint y,
guint time,
gpointer user_data);
- static void _wireMagicColors( JustForNow *colorSet );
+ static void _wireMagicColors( SwatchPage *colorSet );
static void _colorDefChanged(void* data);
void _updatePreviews();
index b330012cae418f27012564b1b1817f370f002e5d..76ceb1514dd072afbbf3cf2f1ef831edf56d22bc 100644 (file)
+
/** @file
* @brief Color swatches dialog
*/
#include "display/nr-plain-stuff.h"
#include "sp-gradient-reference.h"
-#define USE_DOCUMENT_PALETTE 1
namespace Inkscape {
namespace UI {
void _loadPaletteFile( gchar const *filename );
+class DocTrack;
+
+std::vector<SwatchPage*> possible;
+static std::map<SPDocument*, SwatchPage*> docPalettes;
+static std::vector<DocTrack*> docTrackings;
+static std::map<SwatchesPanel*, SPDocument*> docPerPanel;
-std::vector<JustForNow*> possible;
static void handleClick( GtkWidget* /*widget*/, gpointer callback_data ) {
static GtkWidget* popupMenu = 0;
static std::vector<GtkWidget*> popupExtras;
static ColorItem* bounceTarget = 0;
+static SwatchesPanel* bouncePanel = 0;
static void redirClick( GtkMenuItem *menuitem, gpointer /*user_data*/ )
{
}
}
-#if USE_DOCUMENT_PALETTE
static void editGradientImpl( SPGradient* gr )
{
if ( gr ) {
static void editGradient( GtkMenuItem */*menuitem*/, gpointer /*user_data*/ )
{
if ( bounceTarget ) {
- SwatchesPanel* swp = bounceTarget->ptr ? reinterpret_cast<SwatchesPanel*>(bounceTarget->ptr) : 0;
+ SwatchesPanel* swp = bouncePanel;
SPDesktop* desktop = swp ? swp->getDesktop() : 0;
SPDocument *doc = desktop ? desktop->doc() : 0;
if (doc) {
static void addNewGradient( GtkMenuItem */*menuitem*/, gpointer /*user_data*/ )
{
if ( bounceTarget ) {
- SwatchesPanel* swp = bounceTarget->ptr ? reinterpret_cast<SwatchesPanel*>(bounceTarget->ptr) : 0;
+ SwatchesPanel* swp = bouncePanel;
SPDesktop* desktop = swp ? swp->getDesktop() : 0;
SPDocument *doc = desktop ? desktop->doc() : 0;
if (doc) {
@@ -150,20 +155,35 @@ static void addNewGradient( GtkMenuItem */*menuitem*/, gpointer /*user_data*/ )
editGradientImpl( gr );
- // Work-around for timing of gradient addition change. Must follow edit.
- if ( swp ) {
- swp->handleGradientsChange();
- }
}
}
}
-#endif // USE_DOCUMENT_PALETTE
-gboolean colorItemHandleButtonPress( GtkWidget* /*widget*/, GdkEventButton* event, gpointer user_data)
+static SwatchesPanel* findContainingPanel( GtkWidget *widget )
+{
+ SwatchesPanel *swp = 0;
+
+ std::map<GtkWidget*, SwatchesPanel*> rawObjects;
+ for (std::map<SwatchesPanel*, SPDocument*>::iterator it = docPerPanel.begin(); it != docPerPanel.end(); ++it) {
+ rawObjects[GTK_WIDGET(it->first->gobj())] = it->first;
+ }
+
+ for (GtkWidget* curr = widget; curr && !swp; curr = gtk_widget_get_parent(curr)) {
+ if (rawObjects.find(curr) != rawObjects.end()) {
+ swp = rawObjects[curr];
+ }
+ }
+
+ return swp;
+}
+
+gboolean colorItemHandleButtonPress( GtkWidget* widget, GdkEventButton* event, gpointer user_data)
{
gboolean handled = FALSE;
if ( (event->button == 3) && (event->type == GDK_BUTTON_PRESS) ) {
+ SwatchesPanel* swp = findContainingPanel( widget );
+
if ( !popupMenu ) {
popupMenu = gtk_menu_new();
GtkWidget* child = 0;
@@ -185,7 +205,6 @@ gboolean colorItemHandleButtonPress( GtkWidget* /*widget*/, GdkEventButton* even
user_data);
gtk_menu_shell_append(GTK_MENU_SHELL(popupMenu), child);
-#if USE_DOCUMENT_PALETTE
child = gtk_separator_menu_item_new();
gtk_menu_shell_append(GTK_MENU_SHELL(popupMenu), child);
popupExtras.push_back(child);
@@ -219,20 +238,19 @@ gboolean colorItemHandleButtonPress( GtkWidget* /*widget*/, GdkEventButton* even
gtk_menu_shell_append(GTK_MENU_SHELL(popupMenu), child);
//popupExtras.push_back(child);
gtk_widget_set_sensitive( child, FALSE );
-#endif // USE_DOCUMENT_PALETTE
gtk_widget_show_all(popupMenu);
}
ColorItem* item = reinterpret_cast<ColorItem*>(user_data);
if ( item ) {
- SwatchesPanel* swp = item->ptr ? reinterpret_cast<SwatchesPanel*>(item->ptr) : 0;
bool show = swp && (swp->getSelectedIndex() == 0);
for ( std::vector<GtkWidget*>::iterator it = popupExtras.begin(); it != popupExtras.end(); ++ it) {
gtk_widget_set_sensitive(*it, show);
}
bounceTarget = item;
+ bouncePanel = swp;
if ( popupMenu ) {
gtk_menu_popup(GTK_MENU(popupMenu), NULL, NULL, NULL, NULL, event->button, event->time);
handled = TRUE;
bool inHeader = true;
bool hasErr = false;
- JustForNow *onceMore = new JustForNow();
+ SwatchPage *onceMore = new SwatchPage();
do {
result = fgets( block, sizeof(block), f );
_remove(0),
_currentIndex(0),
_currentDesktop(0),
- _currentDocument(0),
- _ptr(0)
+ _currentDocument(0)
{
Gtk::RadioMenuItem* hotItem = 0;
_holder = new PreviewHolder();
_clear = new ColorItem( ege::PaintDef::CLEAR );
- _clear->ptr = this;
_remove = new ColorItem( ege::PaintDef::NONE );
- _remove->ptr = this;
-#if USE_DOCUMENT_PALETTE
- {
- JustForNow *docPalette = new JustForNow();
+ if (docPalettes.empty()) {
+ SwatchPage *docPalette = new SwatchPage();
docPalette->_name = "Auto";
- possible.push_back(docPalette);
-
- _ptr = docPalette;
+ docPalettes[0] = docPalette;
}
-#endif // USE_DOCUMENT_PALETTE
+
loadEmUp();
if ( !possible.empty() ) {
- JustForNow* first = 0;
+ SwatchPage* first = 0;
int index = 0;
Glib::ustring targetName;
if ( !_prefs_path.empty() ) {
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
targetName = prefs->getString(_prefs_path + "/palette");
if (!targetName.empty()) {
- for ( std::vector<JustForNow*>::iterator iter = possible.begin(); iter != possible.end(); ++iter ) {
- if ( (*iter)->_name == targetName ) {
- first = *iter;
- break;
- }
+ if (targetName == "Auto") {
+ first = docPalettes[0];
+ } else {
index++;
+ for ( std::vector<SwatchPage*>::iterator iter = possible.begin(); iter != possible.end(); ++iter ) {
+ if ( (*iter)->_name == targetName ) {
+ first = *iter;
+ break;
+ }
+ index++;
+ }
}
}
}
if ( !first ) {
- first = possible.front();
+ first = docPalettes[0];
_currentIndex = 0;
} else {
_currentIndex = index;
Gtk::RadioMenuItem::Group groupOne;
int i = 0;
- for ( std::vector<JustForNow*>::iterator it = possible.begin(); it != possible.end(); it++ ) {
- JustForNow* curr = *it;
+ std::vector<SwatchPage*> swatchSets = _getSwatchSets();
+ for ( std::vector<SwatchPage*>::iterator it = swatchSets.begin(); it != swatchSets.end(); it++ ) {
+ SwatchPage* curr = *it;
Gtk::RadioMenuItem* single = manage(new Gtk::RadioMenuItem(groupOne, curr->_name));
if ( curr == first ) {
hotItem = single;
SwatchesPanel::~SwatchesPanel()
{
+ _trackDocument( this, 0 );
+
_documentConnection.disconnect();
- _resourceConnection.disconnect();
_selChanged.disconnect();
- _setModified.disconnect();
- _subselChanged.disconnect();
- _defsChanged.disconnect();
- _defsModified.disconnect();
if ( _clear ) {
delete _clear;
if ( _currentDesktop ) {
_documentConnection.disconnect();
_selChanged.disconnect();
- _setModified.disconnect();
- _subselChanged.disconnect();
}
_currentDesktop = desktop;
_documentConnection = desktop->connectDocumentReplaced( slot2 );
_setDocument( desktop->doc() );
+ handleGradientsChange( desktop->doc() );
} else {
_setDocument(0);
}
}
}
-void SwatchesPanel::_setDocument( SPDocument *document )
+
+class DocTrack
{
- if ( document != _currentDocument ) {
- if ( _currentDocument ) {
- _resourceConnection.disconnect();
- _defsChanged.disconnect();
- _defsModified.disconnect();
+public:
+ DocTrack(SPDocument *doc, sigc::connection &gradientRsrcChanged, sigc::connection &defsChanged, sigc::connection &defsModified) :
+ doc(doc),
+ gradientRsrcChanged(gradientRsrcChanged),
+ defsChanged(defsChanged),
+ defsModified(defsModified)
+ {
+ }
+
+ ~DocTrack()
+ {
+ if (doc) {
+ gradientRsrcChanged.disconnect();
+ defsChanged.disconnect();
+ defsModified.disconnect();
}
- _currentDocument = document;
- if ( _currentDocument ) {
- _resourceConnection = sp_document_resources_changed_connect(document,
- "gradient",
- sigc::mem_fun(*this, &SwatchesPanel::handleGradientsChange));
-
- // connect to release and modified signals of the defs (i.e. when someone changes gradient)
- _defsChanged = SP_DOCUMENT_DEFS(document)->connectRelease(sigc::hide(sigc::mem_fun(*this, &SwatchesPanel::handleDefsModified)));
- _defsModified = SP_DOCUMENT_DEFS(document)->connectModified(sigc::hide(sigc::hide(sigc::mem_fun(*this, &SwatchesPanel::handleDefsModified))));
+ }
+
+ SPDocument *doc;
+ sigc::connection gradientRsrcChanged;
+ sigc::connection defsChanged;
+ sigc::connection defsModified;
+
+private:
+ DocTrack(DocTrack const &); // no copy
+ DocTrack &operator=(DocTrack const &); // no assign
+};
+
+void SwatchesPanel::_trackDocument( SwatchesPanel *panel, SPDocument *document )
+{
+ SPDocument *oldDoc = 0;
+ if (docPerPanel.find(panel) != docPerPanel.end()) {
+ oldDoc = docPerPanel[panel];
+ if (!oldDoc) {
+ docPerPanel.erase(panel); // Should not be needed, but clean up just in case.
+ }
+ }
+ if (oldDoc != document) {
+ if (oldDoc) {
+ docPerPanel[panel] = 0;
+ bool found = false;
+ for (std::map<SwatchesPanel*, SPDocument*>::iterator it = docPerPanel.begin(); (it != docPerPanel.end()) && !found; ++it) {
+ found = (it->second == document);
+ }
+ if (!found) {
+ for (std::vector<DocTrack*>::iterator it = docTrackings.begin(); it != docTrackings.end(); ++it){
+ if ((*it)->doc == oldDoc) {
+ delete *it;
+ docTrackings.erase(it);
+ break;
+ }
+ }
+ }
+ }
+
+ if (document) {
+ bool found = false;
+ for (std::map<SwatchesPanel*, SPDocument*>::iterator it = docPerPanel.begin(); (it != docPerPanel.end()) && !found; ++it) {
+ found = (it->second == document);
+ }
+ docPerPanel[panel] = document;
+ if (!found) {
+ sigc::connection conn1 = sp_document_resources_changed_connect( document, "gradient", sigc::bind(sigc::ptr_fun(&SwatchesPanel::handleGradientsChange), document) );
+ sigc::connection conn2 = SP_DOCUMENT_DEFS(document)->connectRelease( sigc::hide(sigc::bind(sigc::ptr_fun(&SwatchesPanel::handleDefsModified), document)) );
+ sigc::connection conn3 = SP_DOCUMENT_DEFS(document)->connectModified( sigc::hide(sigc::hide(sigc::bind(sigc::ptr_fun(&SwatchesPanel::handleDefsModified), document))) );
+
+ DocTrack *dt = new DocTrack(document, conn1, conn2, conn3);
+ docTrackings.push_back(dt);
+
+ if (docPalettes.find(document) == docPalettes.end()) {
+ SwatchPage *docPalette = new SwatchPage();
+ docPalette->_name = "Auto";
+ docPalettes[document] = docPalette;
+ }
+ }
}
+ }
- handleGradientsChange();
+ std::set<SPDocument*> docs;
+ for (std::map<SwatchesPanel*, SPDocument*>::iterator it = docPerPanel.begin(); it != docPerPanel.end(); ++it) {
+ docs.insert(it->second);
+ }
+}
+
+void SwatchesPanel::_setDocument( SPDocument *document )
+{
+ if ( document != _currentDocument ) {
+ _trackDocument(this, document);
+ _currentDocument = document;
}
}
-#if USE_DOCUMENT_PALETTE
static void recalcSwatchContents(SPDocument* doc,
std::vector<ColorItem*> &tmpColors,
std::map<ColorItem*, guchar*> &previewMappings,
- std::map<ColorItem*, SPGradient*> &gradMappings,
- void* ptr)
+ std::map<ColorItem*, SPGradient*> &gradMappings)
{
std::vector<SPGradient*> newList;
unsigned int g = SP_RGBA32_G_U(together);
unsigned int b = SP_RGBA32_B_U(together);
ColorItem* item = new ColorItem( r, g, b, name );
- item->ptr = ptr;
gint width = PREVIEW_PIXBUF_WIDTH;
gint height = VBLOCK;
}
}
}
-#endif // USE_DOCUMENT_PALETTE
-void SwatchesPanel::handleGradientsChange()
+void SwatchesPanel::handleGradientsChange(SPDocument *document)
{
-// Invoked when the list of gradients itself changes due to additions, removals, etc.
-#if USE_DOCUMENT_PALETTE
- if ( _ptr ) {
- JustForNow *docPalette = reinterpret_cast<JustForNow *>(_ptr);
- if (docPalette) {
- std::vector<ColorItem*> tmpColors;
- std::map<ColorItem*, guchar*> tmpPrevs;
- std::map<ColorItem*, SPGradient*> tmpGrads;
- recalcSwatchContents(_currentDocument, tmpColors, tmpPrevs, tmpGrads, this);
-
- for (std::map<ColorItem*, guchar*>::iterator it = tmpPrevs.begin(); it != tmpPrevs.end(); ++it) {
- it->first->setPixData(it->second, PREVIEW_PIXBUF_WIDTH, VBLOCK);
- }
+ SwatchPage *docPalette = (docPalettes.find(document) != docPalettes.end()) ? docPalettes[document] : 0;
+ if (docPalette) {
+ std::vector<ColorItem*> tmpColors;
+ std::map<ColorItem*, guchar*> tmpPrevs;
+ std::map<ColorItem*, SPGradient*> tmpGrads;
+ recalcSwatchContents(document, tmpColors, tmpPrevs, tmpGrads);
+
+ for (std::map<ColorItem*, guchar*>::iterator it = tmpPrevs.begin(); it != tmpPrevs.end(); ++it) {
+ it->first->setPixData(it->second, PREVIEW_PIXBUF_WIDTH, VBLOCK);
+ }
- for (std::map<ColorItem*, SPGradient*>::iterator it = tmpGrads.begin(); it != tmpGrads.end(); ++it) {
- it->first->setGradient(it->second);
- }
+ for (std::map<ColorItem*, SPGradient*>::iterator it = tmpGrads.begin(); it != tmpGrads.end(); ++it) {
+ it->first->setGradient(it->second);
+ }
- docPalette->_colors.swap(tmpColors);
- for (std::vector<ColorItem*>::iterator it = tmpColors.begin(); it != tmpColors.end(); ++it) {
- delete *it;
- }
+ docPalette->_colors.swap(tmpColors);
+ for (std::vector<ColorItem*>::iterator it = tmpColors.begin(); it != tmpColors.end(); ++it) {
+ delete *it;
+ }
- JustForNow* curr = possible[_currentIndex];
- if (curr == docPalette) {
- _rebuild();
+
+ // Figure out which SwatchesPanel instances are affected and update them.
+
+ for (std::map<SwatchesPanel*, SPDocument*>::iterator it = docPerPanel.begin(); it != docPerPanel.end(); ++it) {
+ if (it->second == document) {
+ SwatchesPanel* swp = it->first;
+ std::vector<SwatchPage*> pages = swp->_getSwatchSets();
+ SwatchPage* curr = pages[swp->_currentIndex];
+ if (curr == docPalette) {
+ swp->_rebuild();
+ }
}
}
}
-#endif // USE_DOCUMENT_PALETTE
}
-void SwatchesPanel::handleDefsModified()
+void SwatchesPanel::handleDefsModified(SPDocument *document)
{
-#if USE_DOCUMENT_PALETTE
- if ( _ptr ) {
- JustForNow *docPalette = reinterpret_cast<JustForNow *>(_ptr);
- if (docPalette) {
- std::vector<ColorItem*> tmpColors;
- std::map<ColorItem*, guchar*> tmpPrevs;
- std::map<ColorItem*, SPGradient*> tmpGrads;
- recalcSwatchContents(_currentDocument, tmpColors, tmpPrevs, tmpGrads, this);
-
- int cap = std::min(docPalette->_colors.size(), tmpColors.size());
- for (int i = 0; i < cap; i++) {
- ColorItem* newColor = tmpColors[i];
- ColorItem* oldColor = docPalette->_colors[i];
- if ( (newColor->def.getType() != oldColor->def.getType()) ||
- (newColor->def.getR() != oldColor->def.getR()) ||
- (newColor->def.getG() != oldColor->def.getG()) ||
- (newColor->def.getB() != oldColor->def.getB()) ) {
- oldColor->def.setRGB(newColor->def.getR(), newColor->def.getG(), newColor->def.getB());
- }
- if (tmpGrads.find(newColor) != tmpGrads.end()) {
- oldColor->setGradient(tmpGrads[newColor]);
- }
- if ( tmpPrevs.find(newColor) != tmpPrevs.end() ) {
- oldColor->setPixData(tmpPrevs[newColor], PREVIEW_PIXBUF_WIDTH, VBLOCK);
- }
+ SwatchPage *docPalette = (docPalettes.find(document) != docPalettes.end()) ? docPalettes[document] : 0;
+ if (docPalette) {
+ std::vector<ColorItem*> tmpColors;
+ std::map<ColorItem*, guchar*> tmpPrevs;
+ std::map<ColorItem*, SPGradient*> tmpGrads;
+ recalcSwatchContents(document, tmpColors, tmpPrevs, tmpGrads);
+
+ int cap = std::min(docPalette->_colors.size(), tmpColors.size());
+ for (int i = 0; i < cap; i++) {
+ ColorItem* newColor = tmpColors[i];
+ ColorItem* oldColor = docPalette->_colors[i];
+ if ( (newColor->def.getType() != oldColor->def.getType()) ||
+ (newColor->def.getR() != oldColor->def.getR()) ||
+ (newColor->def.getG() != oldColor->def.getG()) ||
+ (newColor->def.getB() != oldColor->def.getB()) ) {
+ oldColor->def.setRGB(newColor->def.getR(), newColor->def.getG(), newColor->def.getB());
+ }
+ if (tmpGrads.find(newColor) != tmpGrads.end()) {
+ oldColor->setGradient(tmpGrads[newColor]);
+ }
+ if ( tmpPrevs.find(newColor) != tmpPrevs.end() ) {
+ oldColor->setPixData(tmpPrevs[newColor], PREVIEW_PIXBUF_WIDTH, VBLOCK);
}
}
}
-#endif // USE_DOCUMENT_PALETTE
}
-void SwatchesPanel::_updateFromSelection()
+std::vector<SwatchPage*> SwatchesPanel::_getSwatchSets() const
{
-#if USE_DOCUMENT_PALETTE
- if ( _ptr ) {
- JustForNow *docPalette = reinterpret_cast<JustForNow *>(_ptr);
+ std::vector<SwatchPage*> tmp;
+ if (docPalettes.find(_currentDocument) != docPalettes.end()) {
+ tmp.push_back(docPalettes[_currentDocument]);
+ }
+
+ tmp.insert(tmp.end(), possible.begin(), possible.end());
+ return tmp;
+}
+
+void SwatchesPanel::_updateFromSelection()
+{
+ SwatchPage *docPalette = (docPalettes.find(_currentDocument) != docPalettes.end()) ? docPalettes[_currentDocument] : 0;
+ if ( docPalette ) {
Glib::ustring fillId;
Glib::ustring strokeId;
item->setState( isFill, isStroke );
}
}
-#endif // USE_DOCUMENT_PALETTE
}
void SwatchesPanel::_handleAction( int setId, int itemId )
switch( setId ) {
case 3:
{
- if ( itemId >= 0 && itemId < static_cast<int>(possible.size()) ) {
+ std::vector<SwatchPage*> pages = _getSwatchSets();
+ if ( itemId >= 0 && itemId < static_cast<int>(pages.size()) ) {
_currentIndex = itemId;
if ( !_prefs_path.empty() ) {
Inkscape::Preferences *prefs = Inkscape::Preferences::get();
- prefs->setString(_prefs_path + "/palette", possible[_currentIndex]->_name);
+ prefs->setString(_prefs_path + "/palette", pages[_currentIndex]->_name);
}
_rebuild();
void SwatchesPanel::_rebuild()
{
- JustForNow* curr = possible[_currentIndex];
+ std::vector<SwatchPage*> pages = _getSwatchSets();
+ SwatchPage* curr = pages[_currentIndex];
_holder->clear();
if ( curr->_prefWidth > 0 ) {
index 9dcf0303b42931d664d99c02599bd72b68171701..b18fd6cadcb6b80d82ec7d55d7ade30ad47cefb4 100644 (file)
--- a/src/ui/dialog/swatches.h
+++ b/src/ui/dialog/swatches.h
namespace Dialogs {
class ColorItem;
-
+class SwatchPage;
/**
* A panel that displays paint swatches.
virtual SPDesktop* getDesktop() {return _currentDesktop;}
virtual int getSelectedIndex() {return _currentIndex;} // temporary
- virtual void handleGradientsChange(); // temporary
- virtual void handleDefsModified();
protected:
virtual void _updateFromSelection();
virtual void _setDocument( SPDocument *document );
virtual void _rebuild();
+ virtual std::vector<SwatchPage*> _getSwatchSets() const;
+
private:
SwatchesPanel(SwatchesPanel const &); // no copy
SwatchesPanel &operator=(SwatchesPanel const &); // no assign
+ static void _trackDocument( SwatchesPanel *panel, SPDocument *document );
+ static void handleGradientsChange(SPDocument *document);
+ static void handleDefsModified(SPDocument *document);
+
PreviewHolder* _holder;
ColorItem* _clear;
ColorItem* _remove;
int _currentIndex;
SPDesktop* _currentDesktop;
SPDocument* _currentDocument;
- void* _ptr;
sigc::connection _documentConnection;
- sigc::connection _resourceConnection;
sigc::connection _selChanged;
- sigc::connection _setModified;
- sigc::connection _subselChanged;
- sigc::connection _defsChanged;
- sigc::connection _defsModified;
};
} //namespace Dialogs