diff options
| author | Stefano Facchini <stefano.facchini@gmail.com> | 2017-10-22 18:10:41 +0000 |
|---|---|---|
| committer | Tavmjong Bah <tavmjong@free.fr> | 2018-01-18 13:12:18 +0000 |
| commit | 5219c13e20a4aa3ba155ea4f3f4ecd5aab0a9d4e (patch) | |
| tree | a48a960be706a52f3e1735abbc47750cc5c5e88f /src/ui | |
| parent | Remove unused abstract class PreviewFillable (diff) | |
| download | inkscape-5219c13e20a4aa3ba155ea4f3f4ecd5aab0a9d4e.tar.gz inkscape-5219c13e20a4aa3ba155ea4f3f4ecd5aab0a9d4e.zip | |
PreviewHolder: derive from Gtk::Bin
Also, remove an intermediate container between the bin and the scrolled
window.
Diffstat (limited to 'src/ui')
| -rw-r--r-- | src/ui/previewholder.cpp | 57 | ||||
| -rw-r--r-- | src/ui/previewholder.h | 5 |
2 files changed, 20 insertions, 42 deletions
diff --git a/src/ui/previewholder.cpp b/src/ui/previewholder.cpp index 4a16e64a9..dfe75c0b7 100644 --- a/src/ui/previewholder.cpp +++ b/src/ui/previewholder.cpp @@ -1,4 +1,3 @@ - /* * A simple interface for previewing representations. * @@ -31,7 +30,7 @@ namespace UI { PreviewHolder::PreviewHolder() : - Box(), + Bin(), _scroller(0), _insides(0), _prefCols(0), @@ -45,7 +44,7 @@ PreviewHolder::PreviewHolder() : { set_name( "PreviewHolder" ); _scroller = Gtk::manage(new Gtk::ScrolledWindow()); - _scroller->set_name( "PreviewHolderScrolledWindow" ); + _scroller->set_name( "PreviewHolderScroller" ); _scroller->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); _insides = Gtk::manage(new Gtk::Grid()); @@ -56,12 +55,17 @@ PreviewHolder::PreviewHolder() : _scroller->set_vexpand(); _scroller->add( *_insides ); - pack_start(*_scroller, Gtk::PACK_EXPAND_WIDGET); +#if GTK_CHECK_VERSION(3,16,0) + // Disable overlay scrolling as the scrollbar covers up swatches. + // For some reason this also makes the height 55px. + _scroller->set_overlay_scrolling(false); +#endif + + add(*_scroller); } PreviewHolder::~PreviewHolder() { - } bool PreviewHolder::on_scroll_event(GdkEventScroll *event) @@ -162,7 +166,6 @@ void PreviewHolder::addPreview( Previewable* preview ) } _scroller->show_all_children(); - _scroller->queue_draw(); } } @@ -249,32 +252,6 @@ void PreviewHolder::setColumnPref( int cols ) _prefCols = cols; } -void PreviewHolder::get_preferred_height_vfunc(int& minimum_height, int& natural_height) const -{ - // If we have a child (swatch), use that to get it's height. - auto children = _insides->get_children(); - int minimum_height_child = 0; - int natural_height_child = 0; - if (children.size() > 0) { - children[0]->get_preferred_height(minimum_height_child, natural_height_child); - } - - if (_wrap) { - // If wrapped, make height three times child height (seems reasonable). - minimum_height = 3 * minimum_height_child; - natural_height = 3 * natural_height_child; - } else { - // If not wrapped, height is sum of child height and scrollbar height. - - // Get horizontal scrollbar height. - int minimum_height_scrollbar = 0; - int natural_height_scrollbar = 0; - _scroller->get_hscrollbar()->get_preferred_height(minimum_height_scrollbar, natural_height_scrollbar); - - minimum_height = minimum_height_child + minimum_height_scrollbar; - natural_height = natural_height_child + natural_height_scrollbar; - } -} /** * Calculate the grid side of a preview holder @@ -290,13 +267,16 @@ void PreviewHolder::calcGridSize( const Gtk::Widget* item, int itemCount, int& n ncols = itemCount; nrows = 1; -#if GTK_CHECK_VERSION(3,16,0) - // Disable overlay scrolling as the scrollbar covers up swatches. - _scroller->set_overlay_scrolling(false); -#endif - if ( _anchor == SP_ANCHOR_SOUTH || _anchor == SP_ANCHOR_NORTH ) { - // Horizontal layout, long bar. + Gtk::Requisition req; + Gtk::Requisition req_natural; + _scroller->get_preferred_size(req, req_natural); + int currW = _scroller->get_width(); + if ( currW > req.width ) { + req.width = currW; + } + + auto hs = _scroller->get_hscrollbar(); if (_wrap && item != NULL) { @@ -407,7 +387,6 @@ void PreviewHolder::rebuildUI() } _scroller->show_all_children(); - _scroller->queue_draw(); } diff --git a/src/ui/previewholder.h b/src/ui/previewholder.h index 1aeec476d..b12bd466e 100644 --- a/src/ui/previewholder.h +++ b/src/ui/previewholder.h @@ -17,7 +17,7 @@ # include "config.h" #endif -#include <gtkmm/box.h> +#include <gtkmm/bin.h> namespace Gtk { class Grid; @@ -32,7 +32,7 @@ namespace UI { class Previewable; -class PreviewHolder : public Gtk::Box +class PreviewHolder : public Gtk::Bin { public: PreviewHolder(); @@ -54,7 +54,6 @@ public: virtual bool getWrap() const { return _wrap; } protected: - virtual void get_preferred_height_vfunc(int& minimum_height, int& natural_height) const override; virtual bool on_scroll_event(GdkEventScroll*); private: |
