From ed9c3b01658f0292ee709631fa276c2e174ce451 Mon Sep 17 00:00:00 2001 From: joncruz Date: Thu, 5 Mar 2009 08:11:54 +0000 Subject: [PATCH] Adding clear-color swatch to complement no-color. --- src/interface.cpp | 5 ++++- src/ui/dialog/swatches.cpp | 38 ++++++++++++++++++++++++++--------- src/ui/dialog/swatches.h | 3 ++- src/widgets/eek-color-def.cpp | 21 +++++++++++++++++++ src/widgets/eek-color-def.h | 1 + 5 files changed, 56 insertions(+), 12 deletions(-) diff --git a/src/interface.cpp b/src/interface.cpp index e7a3d6f28..f03df2917 100644 --- a/src/interface.cpp +++ b/src/interface.cpp @@ -77,7 +77,8 @@ typedef enum { IMAGE_DATA, APP_X_INKY_COLOR, APP_X_COLOR, - APP_X_NOCOLOR + APP_X_NOCOLOR, + APP_X_XCOLOR } ui_drop_target_info; static GtkTargetEntry ui_drop_target_entries [] = { @@ -90,6 +91,7 @@ static GtkTargetEntry ui_drop_target_entries [] = { {(gchar *)"application/x-inkscape-color", 0, APP_X_INKY_COLOR}, #endif // ENABLE_MAGIC_COLORS {(gchar *)"application/x-inkscape-nocolor", 0, APP_X_NOCOLOR }, + {(gchar *)"application/x-inkscape-xcolor", 0, APP_X_XCOLOR }, {(gchar *)"application/x-color", 0, APP_X_COLOR } }; @@ -1236,6 +1238,7 @@ sp_ui_drag_data_received(GtkWidget *widget, break; case APP_X_NOCOLOR: + case APP_X_XCOLOR: { gchar* c = g_strdup("none"); // temp int destX = 0; diff --git a/src/ui/dialog/swatches.cpp b/src/ui/dialog/swatches.cpp index 1a5ef8521..5cd357673 100644 --- a/src/ui/dialog/swatches.cpp +++ b/src/ui/dialog/swatches.cpp @@ -41,9 +41,8 @@ namespace Inkscape { namespace UI { namespace Dialogs { -// create a None color swatch -ColorItem::ColorItem() : - def(), +ColorItem::ColorItem(eek::ColorDef::ColorType type) : + def(type), _isLive(false), _linkIsTone(false), _linkPercent(0), @@ -106,6 +105,7 @@ typedef enum { APP_X_INKY_COLOR = 0, APP_X_COLOR, APP_X_NOCOLOR, + APP_X_XCOLOR, TEXT_DATA } colorFlavorType; @@ -130,6 +130,12 @@ static const GtkTargetEntry sourceNoColorEntries[] = { {"text/plain", 0, TEXT_DATA}, }; +static const GtkTargetEntry sourceClearColorEntries[] = { + {"application/x-inkscape-xcolor", 0, APP_X_XCOLOR}, + {"application/x-color", 0, APP_X_COLOR}, + {"text/plain", 0, TEXT_DATA}, +}; + void ColorItem::_dragGetColorData( GtkWidget */*widget*/, GdkDragContext */*drag_context*/, GtkSelectionData *data, @@ -196,7 +202,7 @@ void ColorItem::_dragGetColorData( GtkWidget */*widget*/, reinterpret_cast(tmp), itemCount * 2); delete[] tmp; - } else if ( info == APP_X_NOCOLOR ) { + } else if ( (info == APP_X_NOCOLOR) || (info == APP_X_XCOLOR) ) { Glib::ustring paletteName; // Find where this thing came from @@ -445,6 +451,7 @@ void ColorItem::_dropDataIn( GtkWidget */*widget*/, break; } case APP_X_NOCOLOR: + case APP_X_XCOLOR: { // g_message("APP_X_NOCOLOR dropping through to x-color"); } @@ -695,9 +702,10 @@ Gtk::Widget* ColorItem::getPreview(PreviewStyle style, ViewType view, ::PreviewS gtk_drag_source_set( GTK_WIDGET(newBlot->gobj()), GDK_BUTTON1_MASK, - (def.getType() != eek::ColorDef::RGB) ? sourceNoColorEntries : - sourceColorEntries, - (def.getType() != eek::ColorDef::RGB) ? G_N_ELEMENTS(sourceNoColorEntries) : + (def.getType() == eek::ColorDef::CLEAR) ? sourceClearColorEntries : + (def.getType() == eek::ColorDef::NONE) ? sourceNoColorEntries : sourceColorEntries, + (def.getType() == eek::ColorDef::CLEAR) ? G_N_ELEMENTS(sourceClearColorEntries) : + (def.getType() == eek::ColorDef::NONE) ? G_N_ELEMENTS(sourceNoColorEntries) : G_N_ELEMENTS(sourceColorEntries), GdkDragAction(GDK_ACTION_MOVE | GDK_ACTION_COPY) ); @@ -1154,7 +1162,8 @@ SwatchesPanel::SwatchesPanel(gchar const* prefsPath) : { Gtk::RadioMenuItem* hotItem = 0; _holder = new PreviewHolder(); - _remove = new ColorItem(); + _clear = new ColorItem( eek::ColorDef::CLEAR ); + _remove = new ColorItem( eek::ColorDef::NONE ); loadEmUp(); if ( !possible.empty() ) { JustForNow* first = 0; @@ -1180,6 +1189,7 @@ SwatchesPanel::SwatchesPanel(gchar const* prefsPath) : _holder->setColumnPref( first->_prefWidth ); } _holder->freezeUpdates(); + // TODO restore once 'clear' works _holder->addPreview(_clear); _holder->addPreview(_remove); for ( std::vector::iterator it = first->_colors.begin(); it != first->_colors.end(); it++ ) { _holder->addPreview(*it); @@ -1214,8 +1224,15 @@ SwatchesPanel::SwatchesPanel(gchar const* prefsPath) : SwatchesPanel::~SwatchesPanel() { - if (_remove) delete _remove; - if (_holder) delete _holder; + if ( _clear ) { + delete _clear; + } + if ( _remove ) { + delete _remove; + } + if ( _holder ) { + delete _holder; + } } void SwatchesPanel::setOrientation( Gtk::AnchorType how ) @@ -1247,6 +1264,7 @@ void SwatchesPanel::_handleAction( int setId, int itemId ) _holder->setColumnPref( curr->_prefWidth ); } _holder->freezeUpdates(); + _holder->addPreview(_clear); _holder->addPreview(_remove); for ( std::vector::iterator it = curr->_colors.begin(); it != curr->_colors.end(); it++ ) { _holder->addPreview(*it); diff --git a/src/ui/dialog/swatches.h b/src/ui/dialog/swatches.h index 17081733d..560719ed2 100644 --- a/src/ui/dialog/swatches.h +++ b/src/ui/dialog/swatches.h @@ -31,7 +31,7 @@ class ColorItem : public Inkscape::UI::Previewable { friend void _loadPaletteFile( gchar const *filename ); public: - ColorItem(); + ColorItem( eek::ColorDef::ColorType type ); ColorItem( unsigned int r, unsigned int g, unsigned int b, Glib::ustring& name ); virtual ~ColorItem(); @@ -101,6 +101,7 @@ private: static SwatchesPanel* instance; PreviewHolder* _holder; + ColorItem* _clear; ColorItem* _remove; }; diff --git a/src/widgets/eek-color-def.cpp b/src/widgets/eek-color-def.cpp index d7cb41b38..6334061c2 100644 --- a/src/widgets/eek-color-def.cpp +++ b/src/widgets/eek-color-def.cpp @@ -62,6 +62,27 @@ ColorDef::ColorDef() : { } +ColorDef::ColorDef( ColorType type ) : + descr(), + type(type), + r(0), + g(0), + b(0), + editable(false) +{ + switch (type) { + case CLEAR: + descr = _("remove"); + break; + case NONE: + descr = _("none"); + break; + case RGB: + descr = ""; + break; + } +} + ColorDef::ColorDef( unsigned int r, unsigned int g, unsigned int b, const std::string& description ) : descr(description), type(RGB), diff --git a/src/widgets/eek-color-def.h b/src/widgets/eek-color-def.h index 764a28b12..7e54182d6 100644 --- a/src/widgets/eek-color-def.h +++ b/src/widgets/eek-color-def.h @@ -55,6 +55,7 @@ public: enum ColorType{CLEAR, NONE, RGB}; ColorDef(); + ColorDef(ColorType type); ColorDef( unsigned int r, unsigned int g, unsigned int b, const std::string& description ); virtual ~ColorDef(); -- 2.30.2