Code

rearrange code to make rubberband a bit more interruptibility-proof
[inkscape.git] / src / ui / previewholder.cpp
index f48cc1ca0dceacf9b626d7b12e7bbcab7b7e3593..5d87eb4f5665cbaa83ad77fa6096c9c2601d3f90 100644 (file)
@@ -36,7 +36,8 @@ PreviewHolder::PreviewHolder() :
     _updatesFrozen(false),
     _anchor(Gtk::ANCHOR_CENTER),
     _baseSize(Inkscape::ICON_SIZE_MENU),
-    _view(VIEW_TYPE_LIST)
+    _view(VIEW_TYPE_LIST),
+    _wrap(false)
 {
     _scroller = manage(new Gtk::ScrolledWindow());
     _insides = manage(new Gtk::Table( 1, 2 ));
@@ -142,7 +143,7 @@ void PreviewHolder::setOrientation( Gtk::AnchorType how )
             case Gtk::ANCHOR_NORTH:
             case Gtk::ANCHOR_SOUTH:
             {
-                dynamic_cast<Gtk::ScrolledWindow*>(_scroller)->set_policy( Gtk::POLICY_ALWAYS, Gtk::POLICY_AUTOMATIC );
+                dynamic_cast<Gtk::ScrolledWindow*>(_scroller)->set_policy( Gtk::POLICY_ALWAYS, _wrap ? Gtk::POLICY_AUTOMATIC : Gtk::POLICY_NEVER );
             }
             break;
 
@@ -162,6 +163,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<Gtk::ScrolledWindow*>(_scroller)->set_policy( Gtk::POLICY_ALWAYS, _wrap ? Gtk::POLICY_AUTOMATIC : Gtk::POLICY_NEVER );
+            }
+            break;
+            default:
+            {
+                (void)0;
+                // do nothing;
+            }
+        }
+        rebuildUI();
+    }
+}
+
 void PreviewHolder::setColumnPref( int cols )
 {
     _prefCols = cols;
@@ -208,8 +231,8 @@ void PreviewHolder::calcGridSize( const Gtk::Widget* thing, int itemCount, int&
         Gtk::Requisition req2;
         const_cast<Gtk::Widget*>(thing)->size_request(req2);
 
-        int h2 = req.height / req2.height;
-        int w2 = req.width / req2.width;
+        int h2 = ((req2.height > 0) && (req.height > req2.height)) ? (req.height / req2.height) : 1;
+        int w2 = ((req2.width > 0) && (req.width > req2.width)) ? (req.width / req2.width) : 1;
         width = (itemCount + (h2 - 1)) / h2;
         if ( width < w2 ) {
             width = w2;