Code

Fix for mssing error incoude
[inkscape.git] / src / dialogs / swatches.cpp
index c01217fe6cee529d3520385bb7d19aa85d7ebddc..e6d1ac2b57107159b8e6eff731f01a712260f46b 100644 (file)
@@ -12,6 +12,8 @@
 # include <config.h>
 #endif
 
+#include <errno.h>
+
 #include <gtk/gtkdialog.h> //for GTK_RESPONSE* types
 #include <gtk/gtkdnd.h>
 
@@ -276,7 +278,10 @@ bool parseNum( char*& str, int& val ) {
 class JustForNow
 {
 public:
+    JustForNow() : _prefWidth(0) {}
+
     Glib::ustring _name;
+    int _prefWidth;
     std::vector<ColorItem*> _colors;
 };
 
@@ -354,9 +359,22 @@ static void loadPaletteFile( gchar const *filename )
                                         char* val = trim(sep + 1);
                                         char* name = trim(result);
                                         if ( *name ) {
-                                            if ( strcmp( "Name", name ) == 0 ) {
+                                            if ( strcmp( "Name", name ) == 0 )
+                                            {
                                                 onceMore->_name = val;
                                             }
+                                            else if ( strcmp( "Columns", name ) == 0 )
+                                            {
+                                                gchar* endPtr = 0;
+                                                guint64 numVal = g_ascii_strtoull( val, &endPtr, 10 );
+                                                if ( (numVal == G_MAXUINT64) && (ERANGE == errno) ) {
+                                                    // overflow
+                                                } else if ( (numVal == 0) && (endPtr == val) ) {
+                                                    // failed conversion
+                                                } else {
+                                                    onceMore->_prefWidth = numVal;
+                                                }
+                                            }
                                         } else {
                                             // error
                                             hasErr = true;
@@ -454,6 +472,9 @@ SwatchesPanel::SwatchesPanel() :
 
     if ( !possible.empty() ) {
         JustForNow* first = possible.front();
+        if ( first->_prefWidth > 0 ) {
+            _holder->setColumnPref( first->_prefWidth );
+        }
         for ( std::vector<ColorItem*>::iterator it = first->_colors.begin(); it != first->_colors.end(); it++ ) {
             _holder->addPreview(*it);
         }
@@ -470,7 +491,7 @@ SwatchesPanel::SwatchesPanel() :
     }
 
 
-    pack_start(*_holder, Gtk::PACK_EXPAND_WIDGET);
+    _getContents()->pack_start(*_holder, Gtk::PACK_EXPAND_WIDGET);
     _setTargetFillable(_holder);
 
     show_all_children();
@@ -501,6 +522,9 @@ void SwatchesPanel::_handleAction( int setId, int itemId )
             if ( itemId >= 0 && itemId < static_cast<int>(possible.size()) ) {
                 _holder->clear();
                 JustForNow* curr = possible[itemId];
+                if ( curr->_prefWidth > 0 ) {
+                    _holder->setColumnPref( curr->_prefWidth );
+                }
                 for ( std::vector<ColorItem*>::iterator it = curr->_colors.begin(); it != curr->_colors.end(); it++ ) {
                     _holder->addPreview(*it);
                 }