Code

Adding clear-color swatch to complement no-color.
authorjoncruz <joncruz@users.sourceforge.net>
Thu, 5 Mar 2009 08:11:54 +0000 (08:11 +0000)
committerjoncruz <joncruz@users.sourceforge.net>
Thu, 5 Mar 2009 08:11:54 +0000 (08:11 +0000)
src/interface.cpp
src/ui/dialog/swatches.cpp
src/ui/dialog/swatches.h
src/widgets/eek-color-def.cpp
src/widgets/eek-color-def.h

index e7a3d6f28399c88c5986a24933ec5c947d70d7ac..f03df2917cfccddb08b4f7c8100e9fea0ab1a828 100644 (file)
@@ -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;
index 1a5ef85210a085192d3020346f4b833275261ad5..5cd357673b4bf68b7a5e443b8fc8d60f9e21a32f 100644 (file)
@@ -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<const guchar*>(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<ColorItem*>::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<ColorItem*>::iterator it = curr->_colors.begin(); it != curr->_colors.end(); it++ ) {
                     _holder->addPreview(*it);
index 17081733d8912fd391c3a5d3760d2d50c6f336b0..560719ed243a4c36b105dbc2e90ebd830a38bd48 100644 (file)
@@ -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;
 };
 
index d7cb41b38970ae3b7f15f08bfa9444406b272988..6334061c2d80e3d3b2da3afe1ebdac2c049a850f 100644 (file)
@@ -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),
index 764a28b12a105c70344ba5fed91c7eecadcfaefc..7e54182d6d8743f7c36ccd83b886e9c91fbad9e7 100644 (file)
@@ -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();