X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Fui%2Fpreviewholder.cpp;h=ba0b6a7efa31f9aa822b0c17bf2cc1d062d85c1a;hb=877345db2877c63364e8aa4dfa89cfd1a85ea41a;hp=bcb4d0282c6f8e7510187af44c4a7e011740f5d4;hpb=2af58f480cb8b6c3c80e28f6d22b0dc99c0d0fa9;p=inkscape.git diff --git a/src/ui/previewholder.cpp b/src/ui/previewholder.cpp index bcb4d0282..ba0b6a7ef 100644 --- a/src/ui/previewholder.cpp +++ b/src/ui/previewholder.cpp @@ -35,8 +35,10 @@ PreviewHolder::PreviewHolder() : _prefCols(0), _updatesFrozen(false), _anchor(Gtk::ANCHOR_CENTER), - _baseSize(Inkscape::ICON_SIZE_MENU), - _view(VIEW_TYPE_LIST) + _baseSize(PREVIEW_SIZE_SMALL), + _ratio(100), + _view(VIEW_TYPE_LIST), + _wrap(false) { _scroller = manage(new Gtk::ScrolledWindow()); _insides = manage(new Gtk::Table( 1, 2 )); @@ -60,6 +62,10 @@ void PreviewHolder::clear() { items.clear(); _prefCols = 0; + // Kludge to restore scrollbars + if ( !_wrap && (_view != VIEW_TYPE_LIST) && (_anchor == Gtk::ANCHOR_NORTH || _anchor == Gtk::ANCHOR_SOUTH) ) { + dynamic_cast(_scroller)->set_policy( Gtk::POLICY_AUTOMATIC, Gtk::POLICY_NEVER ); + } rebuildUI(); } @@ -71,13 +77,13 @@ void PreviewHolder::addPreview( Previewable* 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)); + Gtk::Widget* label = manage(preview->getPreview(PREVIEW_STYLE_BLURB, VIEW_TYPE_LIST, _baseSize, _ratio)); + Gtk::Widget* thing = manage(preview->getPreview(PREVIEW_STYLE_PREVIEW, VIEW_TYPE_LIST, _baseSize, _ratio)); _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)); + Gtk::Widget* thing = manage(items[i]->getPreview(PREVIEW_STYLE_PREVIEW, VIEW_TYPE_GRID, _baseSize, _ratio)); int width = 1; int height = 1; @@ -123,11 +129,16 @@ void PreviewHolder::thawUpdates() rebuildUI(); } -void PreviewHolder::setStyle( Inkscape::IconSize size, ViewType view ) +void PreviewHolder::setStyle( ::PreviewSize size, ViewType view, guint ratio ) { - if ( size != _baseSize || view != _view ) { + if ( size != _baseSize || view != _view || ratio != _ratio ) { _baseSize = size; _view = view; + _ratio = ratio; + // Kludge to restore scrollbars + if ( !_wrap && (_view != VIEW_TYPE_LIST) && (_anchor == Gtk::ANCHOR_NORTH || _anchor == Gtk::ANCHOR_SOUTH) ) { + dynamic_cast(_scroller)->set_policy( Gtk::POLICY_AUTOMATIC, Gtk::POLICY_NEVER ); + } rebuildUI(); } } @@ -142,7 +153,7 @@ void PreviewHolder::setOrientation( Gtk::AnchorType how ) case Gtk::ANCHOR_NORTH: case Gtk::ANCHOR_SOUTH: { - dynamic_cast(_scroller)->set_policy( Gtk::POLICY_ALWAYS, Gtk::POLICY_AUTOMATIC ); + dynamic_cast(_scroller)->set_policy( Gtk::POLICY_AUTOMATIC, _wrap ? Gtk::POLICY_AUTOMATIC : Gtk::POLICY_NEVER ); } break; @@ -162,6 +173,28 @@ void PreviewHolder::setOrientation( Gtk::AnchorType how ) } } +void PreviewHolder::setWrap( bool b ) +{ + if ( b != _wrap ) { + _wrap = b; + switch ( _anchor ) + { + case Gtk::ANCHOR_NORTH: + case Gtk::ANCHOR_SOUTH: + { + dynamic_cast(_scroller)->set_policy( Gtk::POLICY_AUTOMATIC, _wrap ? Gtk::POLICY_AUTOMATIC : Gtk::POLICY_NEVER ); + } + break; + default: + { + (void)0; + // do nothing; + } + } + rebuildUI(); + } +} + void PreviewHolder::setColumnPref( int cols ) { _prefCols = cols; @@ -172,6 +205,18 @@ void PreviewHolder::on_size_allocate( Gtk::Allocation& allocation ) // g_message( "on_size_allocate(%d, %d) (%d, %d)", allocation.get_x(), allocation.get_y(), allocation.get_width(), allocation.get_height() ); // g_message(" anchor:%d", _anchor); Gtk::VBox::on_size_allocate( allocation ); + + if ( _insides && !_wrap && (_view != VIEW_TYPE_LIST) && (_anchor == Gtk::ANCHOR_NORTH || _anchor == Gtk::ANCHOR_SOUTH) ) { + Gtk::Requisition req; + _insides->size_request(req); + gint delta = allocation.get_width() - req.width; + + if ( (delta > 4) && req.height < allocation.get_height() ) { + dynamic_cast(_scroller)->set_policy( Gtk::POLICY_NEVER, Gtk::POLICY_NEVER ); + } else { + dynamic_cast(_scroller)->set_policy( Gtk::POLICY_AUTOMATIC, Gtk::POLICY_NEVER ); + } + } } void PreviewHolder::on_size_request( Gtk::Requisition* requisition ) @@ -215,7 +260,7 @@ void PreviewHolder::calcGridSize( const Gtk::Widget* thing, int itemCount, int& width = w2; } } else { - width = (_baseSize == Inkscape::ICON_SIZE_MENU || _baseSize == Inkscape::ICON_SIZE_DECORATION) ? COLUMNS_FOR_SMALL : COLUMNS_FOR_LARGE; + width = (_baseSize == PREVIEW_SIZE_SMALL || _baseSize == PREVIEW_SIZE_TINY) ? COLUMNS_FOR_SMALL : COLUMNS_FOR_LARGE; if ( _prefCols > 0 ) { width = _prefCols; } @@ -236,10 +281,10 @@ void PreviewHolder::rebuildUI() _insides->set_col_spacings( 8 ); for ( unsigned int i = 0; i < items.size(); i++ ) { - Gtk::Widget* label = manage(items[i]->getPreview(PREVIEW_STYLE_BLURB, _view, _baseSize)); + Gtk::Widget* label = manage(items[i]->getPreview(PREVIEW_STYLE_BLURB, _view, _baseSize, _ratio)); //label->set_alignment(Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER); - Gtk::Widget* thing = manage(items[i]->getPreview(PREVIEW_STYLE_PREVIEW, _view, _baseSize)); + Gtk::Widget* thing = manage(items[i]->getPreview(PREVIEW_STYLE_PREVIEW, _view, _baseSize, _ratio)); _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 ); @@ -252,7 +297,7 @@ void PreviewHolder::rebuildUI() int height = 1; for ( unsigned int i = 0; i < items.size(); i++ ) { - Gtk::Widget* thing = manage(items[i]->getPreview(PREVIEW_STYLE_PREVIEW, _view, _baseSize)); + Gtk::Widget* thing = manage(items[i]->getPreview(PREVIEW_STYLE_PREVIEW, _view, _baseSize, _ratio)); if ( !_insides ) { calcGridSize( thing, items.size(), width, height );