summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJon A. Cruz <jon@joncruz.org>2006-02-28 07:47:09 +0000
committerjoncruz <joncruz@users.sourceforge.net>2006-02-28 07:47:09 +0000
commit88baf53b0441d9c011655e2d4975728d4ee01d89 (patch)
tree24dbe7865557d710598ce933ebc02e868143d0ca /src
parentRefactoring layout when switching palettes (diff)
downloadinkscape-88baf53b0441d9c011655e2d4975728d4ee01d89.tar.gz
inkscape-88baf53b0441d9c011655e2d4975728d4ee01d89.zip
Cleanup of embedded swatches palette switching.
(bzr r188)
Diffstat (limited to 'src')
-rw-r--r--src/dialogs/swatches.cpp4
-rw-r--r--src/ui/previewfillable.h2
-rw-r--r--src/ui/previewholder.cpp78
-rw-r--r--src/ui/previewholder.h3
4 files changed, 61 insertions, 26 deletions
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<ColorItem*>::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<ColorItem*>::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::vector<Gtk::Widget*>kids = _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<Gtk::Widget> 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;