From: joncruz Date: Tue, 28 Feb 2006 07:47:09 +0000 (+0000) Subject: Cleanup of embedded swatches palette switching. X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=58b0fdbb47df7c2b1bae121cca7add1ca916f952;p=inkscape.git Cleanup of embedded swatches palette switching. --- diff --git a/ChangeLog b/ChangeLog index fd15483e7..13dd31e7b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2006-02-27 Jon A. Cruz + * src/dialogs/swatches.cpp, src/ui/previewfillable.h, + src/ui/previewholder.h, src/ui/previewholder.cpp: + + Finished cleanup of embedded swatches when switching palettes. + 2006-02-26 Jon A. Cruz * src/dialogs/swatches.cpp, src/ui/previewholder.h, src/ui/previewholder.cpp: diff --git a/src/dialogs/swatches.cpp b/src/dialogs/swatches.cpp index e6d1ac2b5..7da1b5694 100644 --- a/src/dialogs/swatches.cpp +++ b/src/dialogs/swatches.cpp @@ -475,9 +475,11 @@ SwatchesPanel::SwatchesPanel() : if ( first->_prefWidth > 0 ) { _holder->setColumnPref( first->_prefWidth ); } + _holder->freezeUpdates(); for ( std::vector::iterator it = first->_colors.begin(); it != first->_colors.end(); it++ ) { _holder->addPreview(*it); } + _holder->thawUpdates(); Gtk::RadioMenuItem::Group groupOne; int i = 0; @@ -525,9 +527,11 @@ void SwatchesPanel::_handleAction( int setId, int itemId ) if ( curr->_prefWidth > 0 ) { _holder->setColumnPref( curr->_prefWidth ); } + _holder->freezeUpdates(); for ( std::vector::iterator it = curr->_colors.begin(); it != curr->_colors.end(); it++ ) { _holder->addPreview(*it); } + _holder->thawUpdates(); } } break; diff --git a/src/ui/previewfillable.h b/src/ui/previewfillable.h index b62ab6b99..f4a67887e 100644 --- a/src/ui/previewfillable.h +++ b/src/ui/previewfillable.h @@ -25,6 +25,8 @@ public: virtual ~PreviewFillable() {} virtual void clear() = 0; virtual void addPreview( Previewable* preview ) = 0; + virtual void freezeUpdates() = 0; + virtual void thawUpdates() = 0; virtual void setStyle(Gtk::BuiltinIconSize size, ViewType type) = 0; virtual void setOrientation( Gtk::AnchorType how ) = 0; virtual Gtk::BuiltinIconSize getPreviewSize() const = 0; diff --git a/src/ui/previewholder.cpp b/src/ui/previewholder.cpp index cc2339c9c..c2bc13327 100644 --- a/src/ui/previewholder.cpp +++ b/src/ui/previewholder.cpp @@ -31,6 +31,9 @@ PreviewHolder::PreviewHolder() : VBox(), PreviewFillable(), _scroller(0), + _insides(0), + _prefCols(0), + _updatesFrozen(false), _anchor(Gtk::ANCHOR_CENTER), _baseSize(Gtk::ICON_SIZE_MENU), _view(VIEW_TYPE_LIST) @@ -63,38 +66,61 @@ void PreviewHolder::clear() void PreviewHolder::addPreview( Previewable* preview ) { items.push_back(preview); - int i = items.size() - 1; - - if ( _view == VIEW_TYPE_LIST ) { - Gtk::Widget* label = manage(preview->getPreview(PREVIEW_STYLE_BLURB, VIEW_TYPE_LIST, _baseSize)); - Gtk::Widget* thing = manage(preview->getPreview(PREVIEW_STYLE_PREVIEW, VIEW_TYPE_LIST, _baseSize)); - - _insides->attach( *thing, 0, 1, i, i+1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND ); - _insides->attach( *label, 1, 2, i, i+1, Gtk::FILL|Gtk::EXPAND, Gtk::SHRINK ); - } else { - Gtk::Widget* thing = manage(items[i]->getPreview(PREVIEW_STYLE_PREVIEW, VIEW_TYPE_GRID, _baseSize)); + if ( !_updatesFrozen ) + { + int i = items.size() - 1; - int width = 1; - int height = 1; - calcGridSize( thing, items.size(), width, height ); - int col = i % width; - int row = i / width; + if ( _view == VIEW_TYPE_LIST ) { + Gtk::Widget* label = manage(preview->getPreview(PREVIEW_STYLE_BLURB, VIEW_TYPE_LIST, _baseSize)); + Gtk::Widget* thing = manage(preview->getPreview(PREVIEW_STYLE_PREVIEW, VIEW_TYPE_LIST, _baseSize)); - if ( i < 10 ) { - g_message( "i:%d width:%d height:%d prop cols:%d", i, width, height, (int)_insides->property_n_columns() ); + _insides->attach( *thing, 0, 1, i, i+1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND ); + _insides->attach( *label, 1, 2, i, i+1, Gtk::FILL|Gtk::EXPAND, Gtk::SHRINK ); + } else { + Gtk::Widget* thing = manage(items[i]->getPreview(PREVIEW_STYLE_PREVIEW, VIEW_TYPE_GRID, _baseSize)); + + int width = 1; + int height = 1; + calcGridSize( thing, items.size(), width, height ); + int col = i % width; + int row = i / width; + + if ( _insides && width > (int)_insides->property_n_columns() ) { + std::vectorkids = _insides->get_children(); + int oldWidth = (int)_insides->property_n_columns(); + int childCount = (int)kids.size(); +// g_message(" %3d resize from %d to %d (r:%d, c:%d) with %d children", i, oldWidth, width, row, col, childCount ); + _insides->resize( height, width ); + + for ( int j = oldWidth; j < childCount; j++ ) { + Gtk::Widget* target = kids[childCount - (j + 1)]; + int col2 = j % width; + int row2 = j / width; + Glib::RefPtr handle(target); + _insides->remove( *target ); + _insides->attach( *target, col2, col2+1, row2, row2+1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND ); + } + } else if ( col == 0 ) { + // we just started a new row + _insides->resize( row + 1, width ); + } + _insides->attach( *thing, col, col+1, row, row+1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND ); } - if ( col == 0 ) { - // we just started a new row - _insides->resize( row + 1, width ); - } else if ( _insides && width > (int)_insides->property_n_columns() ) { - _insides->resize( height, width ); - } - _insides->attach( *thing, col, col+1, row, row+1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND ); + _scroller->show_all_children(); + _scroller->queue_draw(); } +} - _scroller->show_all_children(); - _scroller->queue_draw(); +void PreviewHolder::freezeUpdates() +{ + _updatesFrozen = true; +} + +void PreviewHolder::thawUpdates() +{ + _updatesFrozen = false; + rebuildUI(); } void PreviewHolder::setStyle(Gtk::BuiltinIconSize size, ViewType view) diff --git a/src/ui/previewholder.h b/src/ui/previewholder.h index d165e5bf9..53ffd5f05 100644 --- a/src/ui/previewholder.h +++ b/src/ui/previewholder.h @@ -29,6 +29,8 @@ public: virtual void clear(); virtual void addPreview( Previewable* preview ); + virtual void freezeUpdates(); + virtual void thawUpdates(); virtual void setStyle(Gtk::BuiltinIconSize size, ViewType view); virtual void setOrientation( Gtk::AnchorType how ); virtual int getColumnPref() const { return _prefCols; } @@ -49,6 +51,7 @@ private: Gtk::Bin *_scroller; Gtk::Table *_insides; int _prefCols; + bool _updatesFrozen; Gtk::AnchorType _anchor; Gtk::BuiltinIconSize _baseSize; ViewType _view;