previewholder.cpp revision a1c83ca671ae9b97c6a30901ee3542faf93defb4
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy/*
c869993e79c1eafbec61a56bf6cea848fe754c71xy * A simple interface for previewing representations.
c869993e79c1eafbec61a56bf6cea848fe754c71xy *
c869993e79c1eafbec61a56bf6cea848fe754c71xy * Authors:
c869993e79c1eafbec61a56bf6cea848fe754c71xy * Jon A. Cruz
c869993e79c1eafbec61a56bf6cea848fe754c71xy *
c869993e79c1eafbec61a56bf6cea848fe754c71xy * Copyright (C) 2005 Jon A. Cruz
c869993e79c1eafbec61a56bf6cea848fe754c71xy *
c869993e79c1eafbec61a56bf6cea848fe754c71xy * Released under GNU GPL, read the file 'COPYING' for more information
c869993e79c1eafbec61a56bf6cea848fe754c71xy */
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy#include "previewholder.h"
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy#include <gtkmm/scrolledwindow.h>
c869993e79c1eafbec61a56bf6cea848fe754c71xy#include <gtkmm/sizegroup.h>
c869993e79c1eafbec61a56bf6cea848fe754c71xy#include <gtkmm/scrollbar.h>
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy#define COLUMNS_FOR_SMALL 16
c869993e79c1eafbec61a56bf6cea848fe754c71xy#define COLUMNS_FOR_LARGE 8
c869993e79c1eafbec61a56bf6cea848fe754c71xy//#define COLUMNS_FOR_SMALL 48
c869993e79c1eafbec61a56bf6cea848fe754c71xy//#define COLUMNS_FOR_LARGE 32
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xynamespace Inkscape {
c869993e79c1eafbec61a56bf6cea848fe754c71xynamespace UI {
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xyPreviewHolder::PreviewHolder() :
c869993e79c1eafbec61a56bf6cea848fe754c71xy VBox(),
c869993e79c1eafbec61a56bf6cea848fe754c71xy PreviewFillable(),
fa25784ca4b51c206177d891a654f1d36a25d41fxy _scroller(0),
c869993e79c1eafbec61a56bf6cea848fe754c71xy _insides(0),
c869993e79c1eafbec61a56bf6cea848fe754c71xy _prefCols(0),
c869993e79c1eafbec61a56bf6cea848fe754c71xy _updatesFrozen(false),
c869993e79c1eafbec61a56bf6cea848fe754c71xy _anchor(SP_ANCHOR_CENTER),
c869993e79c1eafbec61a56bf6cea848fe754c71xy _baseSize(PREVIEW_SIZE_SMALL),
c869993e79c1eafbec61a56bf6cea848fe754c71xy _ratio(100),
c869993e79c1eafbec61a56bf6cea848fe754c71xy _view(VIEW_TYPE_LIST),
c869993e79c1eafbec61a56bf6cea848fe754c71xy _wrap(false)
c869993e79c1eafbec61a56bf6cea848fe754c71xy{
c869993e79c1eafbec61a56bf6cea848fe754c71xy _scroller = manage(new Gtk::ScrolledWindow());
c869993e79c1eafbec61a56bf6cea848fe754c71xy _insides = manage(new Gtk::Table( 1, 2 ));
c869993e79c1eafbec61a56bf6cea848fe754c71xy _insides->set_col_spacings( 8 );
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy // Add a container with the scroller and a spacer
c869993e79c1eafbec61a56bf6cea848fe754c71xy Gtk::Table* spaceHolder = manage( new Gtk::Table(1, 2) );
c869993e79c1eafbec61a56bf6cea848fe754c71xy _scroller->add( *_insides );
c869993e79c1eafbec61a56bf6cea848fe754c71xy spaceHolder->attach( *_scroller, 0, 1, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND );
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy pack_start(*spaceHolder, Gtk::PACK_EXPAND_WIDGET);
c869993e79c1eafbec61a56bf6cea848fe754c71xy}
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xyPreviewHolder::~PreviewHolder()
c869993e79c1eafbec61a56bf6cea848fe754c71xy{
c869993e79c1eafbec61a56bf6cea848fe754c71xy}
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xyvoid PreviewHolder::clear()
c869993e79c1eafbec61a56bf6cea848fe754c71xy{
c869993e79c1eafbec61a56bf6cea848fe754c71xy items.clear();
c869993e79c1eafbec61a56bf6cea848fe754c71xy _prefCols = 0;
c869993e79c1eafbec61a56bf6cea848fe754c71xy // Kludge to restore scrollbars
c869993e79c1eafbec61a56bf6cea848fe754c71xy if ( !_wrap && (_view != VIEW_TYPE_LIST) && (_anchor == SP_ANCHOR_NORTH || _anchor == SP_ANCHOR_SOUTH) ) {
c869993e79c1eafbec61a56bf6cea848fe754c71xy dynamic_cast<Gtk::ScrolledWindow*>(_scroller)->set_policy( Gtk::POLICY_AUTOMATIC, Gtk::POLICY_NEVER );
c869993e79c1eafbec61a56bf6cea848fe754c71xy }
c869993e79c1eafbec61a56bf6cea848fe754c71xy rebuildUI();
c869993e79c1eafbec61a56bf6cea848fe754c71xy}
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xyvoid PreviewHolder::addPreview( Previewable* preview )
c869993e79c1eafbec61a56bf6cea848fe754c71xy{
c869993e79c1eafbec61a56bf6cea848fe754c71xy items.push_back(preview);
c869993e79c1eafbec61a56bf6cea848fe754c71xy if ( !_updatesFrozen )
c869993e79c1eafbec61a56bf6cea848fe754c71xy {
c869993e79c1eafbec61a56bf6cea848fe754c71xy int i = items.size() - 1;
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy if ( _view == VIEW_TYPE_LIST ) {
c869993e79c1eafbec61a56bf6cea848fe754c71xy Gtk::Widget* label = manage(preview->getPreview(PREVIEW_STYLE_BLURB, VIEW_TYPE_LIST, _baseSize, _ratio));
c869993e79c1eafbec61a56bf6cea848fe754c71xy Gtk::Widget* thing = manage(preview->getPreview(PREVIEW_STYLE_PREVIEW, VIEW_TYPE_LIST, _baseSize, _ratio));
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy _insides->attach( *thing, 0, 1, i, i+1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND );
c869993e79c1eafbec61a56bf6cea848fe754c71xy _insides->attach( *label, 1, 2, i, i+1, Gtk::FILL|Gtk::EXPAND, Gtk::SHRINK );
fa25784ca4b51c206177d891a654f1d36a25d41fxy } else {
c869993e79c1eafbec61a56bf6cea848fe754c71xy Gtk::Widget* thing = manage(items[i]->getPreview(PREVIEW_STYLE_PREVIEW, VIEW_TYPE_GRID, _baseSize, _ratio));
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy int width = 1;
c869993e79c1eafbec61a56bf6cea848fe754c71xy int height = 1;
c869993e79c1eafbec61a56bf6cea848fe754c71xy calcGridSize( thing, items.size(), width, height );
c869993e79c1eafbec61a56bf6cea848fe754c71xy int col = i % width;
c869993e79c1eafbec61a56bf6cea848fe754c71xy int row = i / width;
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy if ( _insides && width > (int)_insides->property_n_columns() ) {
c869993e79c1eafbec61a56bf6cea848fe754c71xy std::vector<Gtk::Widget*>kids = _insides->get_children();
c869993e79c1eafbec61a56bf6cea848fe754c71xy int oldWidth = (int)_insides->property_n_columns();
c869993e79c1eafbec61a56bf6cea848fe754c71xy int childCount = (int)kids.size();
c869993e79c1eafbec61a56bf6cea848fe754c71xy// g_message(" %3d resize from %d to %d (r:%d, c:%d) with %d children", i, oldWidth, width, row, col, childCount );
c869993e79c1eafbec61a56bf6cea848fe754c71xy _insides->resize( height, width );
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy for ( int j = oldWidth; j < childCount; j++ ) {
c869993e79c1eafbec61a56bf6cea848fe754c71xy Gtk::Widget* target = kids[childCount - (j + 1)];
c869993e79c1eafbec61a56bf6cea848fe754c71xy int col2 = j % width;
c869993e79c1eafbec61a56bf6cea848fe754c71xy int row2 = j / width;
c869993e79c1eafbec61a56bf6cea848fe754c71xy Glib::RefPtr<Gtk::Widget> handle(target);
c869993e79c1eafbec61a56bf6cea848fe754c71xy _insides->remove( *target );
8bb4b220fdb894543e41a5f9037898cf3c3f312bgl _insides->attach( *target, col2, col2+1, row2, row2+1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND );
8bb4b220fdb894543e41a5f9037898cf3c3f312bgl }
8bb4b220fdb894543e41a5f9037898cf3c3f312bgl } else if ( col == 0 ) {
8bb4b220fdb894543e41a5f9037898cf3c3f312bgl // we just started a new row
8bb4b220fdb894543e41a5f9037898cf3c3f312bgl _insides->resize( row + 1, width );
c869993e79c1eafbec61a56bf6cea848fe754c71xy }
c869993e79c1eafbec61a56bf6cea848fe754c71xy _insides->attach( *thing, col, col+1, row, row+1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND );
c869993e79c1eafbec61a56bf6cea848fe754c71xy }
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy _scroller->show_all_children();
c869993e79c1eafbec61a56bf6cea848fe754c71xy _scroller->queue_draw();
c869993e79c1eafbec61a56bf6cea848fe754c71xy }
c869993e79c1eafbec61a56bf6cea848fe754c71xy}
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xyvoid PreviewHolder::freezeUpdates()
c869993e79c1eafbec61a56bf6cea848fe754c71xy{
c869993e79c1eafbec61a56bf6cea848fe754c71xy _updatesFrozen = true;
c869993e79c1eafbec61a56bf6cea848fe754c71xy}
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xyvoid PreviewHolder::thawUpdates()
c869993e79c1eafbec61a56bf6cea848fe754c71xy{
c869993e79c1eafbec61a56bf6cea848fe754c71xy _updatesFrozen = false;
c869993e79c1eafbec61a56bf6cea848fe754c71xy rebuildUI();
c869993e79c1eafbec61a56bf6cea848fe754c71xy}
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xyvoid PreviewHolder::setStyle( ::PreviewSize size, ViewType view, guint ratio )
c869993e79c1eafbec61a56bf6cea848fe754c71xy{
c869993e79c1eafbec61a56bf6cea848fe754c71xy if ( size != _baseSize || view != _view || ratio != _ratio ) {
c869993e79c1eafbec61a56bf6cea848fe754c71xy _baseSize = size;
c869993e79c1eafbec61a56bf6cea848fe754c71xy _view = view;
c869993e79c1eafbec61a56bf6cea848fe754c71xy _ratio = ratio;
c869993e79c1eafbec61a56bf6cea848fe754c71xy // Kludge to restore scrollbars
c869993e79c1eafbec61a56bf6cea848fe754c71xy if ( !_wrap && (_view != VIEW_TYPE_LIST) && (_anchor == SP_ANCHOR_NORTH || _anchor == SP_ANCHOR_SOUTH) ) {
c869993e79c1eafbec61a56bf6cea848fe754c71xy dynamic_cast<Gtk::ScrolledWindow*>(_scroller)->set_policy( Gtk::POLICY_AUTOMATIC, Gtk::POLICY_NEVER );
c869993e79c1eafbec61a56bf6cea848fe754c71xy }
c869993e79c1eafbec61a56bf6cea848fe754c71xy rebuildUI();
c869993e79c1eafbec61a56bf6cea848fe754c71xy }
c869993e79c1eafbec61a56bf6cea848fe754c71xy}
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xyvoid PreviewHolder::setOrientation(SPAnchorType how)
c869993e79c1eafbec61a56bf6cea848fe754c71xy{
c869993e79c1eafbec61a56bf6cea848fe754c71xy if ( _anchor != how )
c869993e79c1eafbec61a56bf6cea848fe754c71xy {
c869993e79c1eafbec61a56bf6cea848fe754c71xy _anchor = how;
c869993e79c1eafbec61a56bf6cea848fe754c71xy switch ( _anchor )
c869993e79c1eafbec61a56bf6cea848fe754c71xy {
c869993e79c1eafbec61a56bf6cea848fe754c71xy case SP_ANCHOR_NORTH:
c869993e79c1eafbec61a56bf6cea848fe754c71xy case SP_ANCHOR_SOUTH:
c869993e79c1eafbec61a56bf6cea848fe754c71xy {
c869993e79c1eafbec61a56bf6cea848fe754c71xy dynamic_cast<Gtk::ScrolledWindow*>(_scroller)->set_policy( Gtk::POLICY_AUTOMATIC, _wrap ? Gtk::POLICY_AUTOMATIC : Gtk::POLICY_NEVER );
c869993e79c1eafbec61a56bf6cea848fe754c71xy }
c869993e79c1eafbec61a56bf6cea848fe754c71xy break;
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy case SP_ANCHOR_EAST:
c869993e79c1eafbec61a56bf6cea848fe754c71xy case SP_ANCHOR_WEST:
c869993e79c1eafbec61a56bf6cea848fe754c71xy {
8bb4b220fdb894543e41a5f9037898cf3c3f312bgl dynamic_cast<Gtk::ScrolledWindow*>(_scroller)->set_policy( Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC );
c869993e79c1eafbec61a56bf6cea848fe754c71xy }
c869993e79c1eafbec61a56bf6cea848fe754c71xy break;
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy default:
c869993e79c1eafbec61a56bf6cea848fe754c71xy {
c869993e79c1eafbec61a56bf6cea848fe754c71xy dynamic_cast<Gtk::ScrolledWindow*>(_scroller)->set_policy( Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC );
c869993e79c1eafbec61a56bf6cea848fe754c71xy }
c869993e79c1eafbec61a56bf6cea848fe754c71xy }
c869993e79c1eafbec61a56bf6cea848fe754c71xy rebuildUI();
c869993e79c1eafbec61a56bf6cea848fe754c71xy }
c869993e79c1eafbec61a56bf6cea848fe754c71xy}
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xyvoid PreviewHolder::setWrap( bool b )
c869993e79c1eafbec61a56bf6cea848fe754c71xy{
c869993e79c1eafbec61a56bf6cea848fe754c71xy if ( b != _wrap ) {
c869993e79c1eafbec61a56bf6cea848fe754c71xy _wrap = b;
c869993e79c1eafbec61a56bf6cea848fe754c71xy switch ( _anchor )
c869993e79c1eafbec61a56bf6cea848fe754c71xy {
c869993e79c1eafbec61a56bf6cea848fe754c71xy case SP_ANCHOR_NORTH:
c869993e79c1eafbec61a56bf6cea848fe754c71xy case SP_ANCHOR_SOUTH:
c869993e79c1eafbec61a56bf6cea848fe754c71xy {
c869993e79c1eafbec61a56bf6cea848fe754c71xy dynamic_cast<Gtk::ScrolledWindow*>(_scroller)->set_policy( Gtk::POLICY_AUTOMATIC, _wrap ? Gtk::POLICY_AUTOMATIC : Gtk::POLICY_NEVER );
c869993e79c1eafbec61a56bf6cea848fe754c71xy }
c869993e79c1eafbec61a56bf6cea848fe754c71xy break;
c869993e79c1eafbec61a56bf6cea848fe754c71xy default:
c869993e79c1eafbec61a56bf6cea848fe754c71xy {
c869993e79c1eafbec61a56bf6cea848fe754c71xy (void)0;
c869993e79c1eafbec61a56bf6cea848fe754c71xy // do nothing;
c869993e79c1eafbec61a56bf6cea848fe754c71xy }
c869993e79c1eafbec61a56bf6cea848fe754c71xy }
c869993e79c1eafbec61a56bf6cea848fe754c71xy rebuildUI();
c869993e79c1eafbec61a56bf6cea848fe754c71xy }
c869993e79c1eafbec61a56bf6cea848fe754c71xy}
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xyvoid PreviewHolder::setColumnPref( int cols )
c869993e79c1eafbec61a56bf6cea848fe754c71xy{
c869993e79c1eafbec61a56bf6cea848fe754c71xy _prefCols = cols;
c869993e79c1eafbec61a56bf6cea848fe754c71xy}
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xyvoid PreviewHolder::on_size_allocate( Gtk::Allocation& allocation )
c869993e79c1eafbec61a56bf6cea848fe754c71xy{
c869993e79c1eafbec61a56bf6cea848fe754c71xy// g_message( "on_size_allocate(%d, %d) (%d, %d)", allocation.get_x(), allocation.get_y(), allocation.get_width(), allocation.get_height() );
c869993e79c1eafbec61a56bf6cea848fe754c71xy// g_message(" anchor:%d", _anchor);
c869993e79c1eafbec61a56bf6cea848fe754c71xy Gtk::VBox::on_size_allocate( allocation );
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy if ( _insides && !_wrap && (_view != VIEW_TYPE_LIST) && (_anchor == SP_ANCHOR_NORTH || _anchor == SP_ANCHOR_SOUTH) ) {
c869993e79c1eafbec61a56bf6cea848fe754c71xy Gtk::Requisition req;
c869993e79c1eafbec61a56bf6cea848fe754c71xy#if WITH_GTKMM_3_0
c869993e79c1eafbec61a56bf6cea848fe754c71xy _insides->get_preferred_size(&req, NULL);
c869993e79c1eafbec61a56bf6cea848fe754c71xy#else
c869993e79c1eafbec61a56bf6cea848fe754c71xy req = _insides->size_request();
c869993e79c1eafbec61a56bf6cea848fe754c71xy#endif
c869993e79c1eafbec61a56bf6cea848fe754c71xy gint delta = allocation.get_width() - req.width;
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy if ( (delta > 4) && req.height < allocation.get_height() ) {
c869993e79c1eafbec61a56bf6cea848fe754c71xy dynamic_cast<Gtk::ScrolledWindow*>(_scroller)->set_policy( Gtk::POLICY_NEVER, Gtk::POLICY_NEVER );
c869993e79c1eafbec61a56bf6cea848fe754c71xy } else {
c869993e79c1eafbec61a56bf6cea848fe754c71xy dynamic_cast<Gtk::ScrolledWindow*>(_scroller)->set_policy( Gtk::POLICY_AUTOMATIC, Gtk::POLICY_NEVER );
c869993e79c1eafbec61a56bf6cea848fe754c71xy }
c869993e79c1eafbec61a56bf6cea848fe754c71xy }
c869993e79c1eafbec61a56bf6cea848fe754c71xy}
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xyvoid PreviewHolder::on_size_request( Gtk::Requisition* requisition )
c869993e79c1eafbec61a56bf6cea848fe754c71xy{
c869993e79c1eafbec61a56bf6cea848fe754c71xy// g_message( "on_size_request(%d, %d)", requisition->width, requisition->height );
c869993e79c1eafbec61a56bf6cea848fe754c71xy Gtk::VBox::on_size_request( requisition );
c869993e79c1eafbec61a56bf6cea848fe754c71xy// g_message( " super (%d, %d)", requisition->width, requisition->height );
c869993e79c1eafbec61a56bf6cea848fe754c71xy// g_message(" anchor:%d", _anchor);
c869993e79c1eafbec61a56bf6cea848fe754c71xy// g_message(" items:%d", (int)items.size());
c869993e79c1eafbec61a56bf6cea848fe754c71xy}
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xyvoid PreviewHolder::calcGridSize( const Gtk::Widget* thing, int itemCount, int& width, int& height )
c869993e79c1eafbec61a56bf6cea848fe754c71xy{
c869993e79c1eafbec61a56bf6cea848fe754c71xy width = itemCount;
c869993e79c1eafbec61a56bf6cea848fe754c71xy height = 1;
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy if ( _anchor == SP_ANCHOR_SOUTH || _anchor == SP_ANCHOR_NORTH ) {
c869993e79c1eafbec61a56bf6cea848fe754c71xy Gtk::Requisition req;
c869993e79c1eafbec61a56bf6cea848fe754c71xy#if WITH_GTKMM_3_0
c869993e79c1eafbec61a56bf6cea848fe754c71xy _scroller->get_preferred_size(&req, NULL);
c869993e79c1eafbec61a56bf6cea848fe754c71xy#else
c869993e79c1eafbec61a56bf6cea848fe754c71xy req = _scroller->size_request();
c869993e79c1eafbec61a56bf6cea848fe754c71xy#endif
c869993e79c1eafbec61a56bf6cea848fe754c71xy int currW = _scroller->get_width();
c869993e79c1eafbec61a56bf6cea848fe754c71xy if ( currW > req.width ) {
c869993e79c1eafbec61a56bf6cea848fe754c71xy req.width = currW;
c869993e79c1eafbec61a56bf6cea848fe754c71xy }
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy Gtk::HScrollbar* hs = dynamic_cast<Gtk::ScrolledWindow*>(_scroller)->get_hscrollbar();
c869993e79c1eafbec61a56bf6cea848fe754c71xy if ( hs ) {
c869993e79c1eafbec61a56bf6cea848fe754c71xy Gtk::Requisition scrollReq;
c869993e79c1eafbec61a56bf6cea848fe754c71xy#if WITH_GTKMM_3_0
c869993e79c1eafbec61a56bf6cea848fe754c71xy hs->get_preferred_size(&req, NULL);
c869993e79c1eafbec61a56bf6cea848fe754c71xy#else
c869993e79c1eafbec61a56bf6cea848fe754c71xy req = hs->size_request();
c869993e79c1eafbec61a56bf6cea848fe754c71xy#endif
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy // the +8 is a temporary hack
c869993e79c1eafbec61a56bf6cea848fe754c71xy req.height -= scrollReq.height + 8;
c869993e79c1eafbec61a56bf6cea848fe754c71xy }
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy Gtk::Requisition req2;
c869993e79c1eafbec61a56bf6cea848fe754c71xy#if WITH_GTKMM_3_0
c869993e79c1eafbec61a56bf6cea848fe754c71xy const_cast<Gtk::Widget*>(thing)->get_preferred_size(&req, NULL);
c869993e79c1eafbec61a56bf6cea848fe754c71xy#else
c869993e79c1eafbec61a56bf6cea848fe754c71xy req = const_cast<Gtk::Widget*>(thing)->size_request();
c869993e79c1eafbec61a56bf6cea848fe754c71xy#endif
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy int h2 = ((req2.height > 0) && (req.height > req2.height)) ? (req.height / req2.height) : 1;
c869993e79c1eafbec61a56bf6cea848fe754c71xy int w2 = ((req2.width > 0) && (req.width > req2.width)) ? (req.width / req2.width) : 1;
c869993e79c1eafbec61a56bf6cea848fe754c71xy width = (itemCount + (h2 - 1)) / h2;
c869993e79c1eafbec61a56bf6cea848fe754c71xy if ( width < w2 ) {
c869993e79c1eafbec61a56bf6cea848fe754c71xy width = w2;
c869993e79c1eafbec61a56bf6cea848fe754c71xy }
c869993e79c1eafbec61a56bf6cea848fe754c71xy } else {
c869993e79c1eafbec61a56bf6cea848fe754c71xy width = (_baseSize == PREVIEW_SIZE_SMALL || _baseSize == PREVIEW_SIZE_TINY) ? COLUMNS_FOR_SMALL : COLUMNS_FOR_LARGE;
c869993e79c1eafbec61a56bf6cea848fe754c71xy if ( _prefCols > 0 ) {
c869993e79c1eafbec61a56bf6cea848fe754c71xy width = _prefCols;
8bb4b220fdb894543e41a5f9037898cf3c3f312bgl }
8bb4b220fdb894543e41a5f9037898cf3c3f312bgl height = (itemCount + (width - 1)) / width;
8bb4b220fdb894543e41a5f9037898cf3c3f312bgl if ( height < 1 ) {
8bb4b220fdb894543e41a5f9037898cf3c3f312bgl height = 1;
8bb4b220fdb894543e41a5f9037898cf3c3f312bgl }
8bb4b220fdb894543e41a5f9037898cf3c3f312bgl }
8bb4b220fdb894543e41a5f9037898cf3c3f312bgl}
8bb4b220fdb894543e41a5f9037898cf3c3f312bgl
8bb4b220fdb894543e41a5f9037898cf3c3f312bglvoid PreviewHolder::rebuildUI()
c869993e79c1eafbec61a56bf6cea848fe754c71xy{
c869993e79c1eafbec61a56bf6cea848fe754c71xy _scroller->remove();
c869993e79c1eafbec61a56bf6cea848fe754c71xy _insides = 0; // remove() call should have deleted the Gtk::Table.
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy if ( _view == VIEW_TYPE_LIST ) {
c869993e79c1eafbec61a56bf6cea848fe754c71xy _insides = manage(new Gtk::Table( 1, 2 ));
c869993e79c1eafbec61a56bf6cea848fe754c71xy _insides->set_col_spacings( 8 );
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy for ( unsigned int i = 0; i < items.size(); i++ ) {
c869993e79c1eafbec61a56bf6cea848fe754c71xy Gtk::Widget* label = manage(items[i]->getPreview(PREVIEW_STYLE_BLURB, _view, _baseSize, _ratio));
c869993e79c1eafbec61a56bf6cea848fe754c71xy //label->set_alignment(Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER);
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy Gtk::Widget* thing = manage(items[i]->getPreview(PREVIEW_STYLE_PREVIEW, _view, _baseSize, _ratio));
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy _insides->attach( *thing, 0, 1, i, i+1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND );
c869993e79c1eafbec61a56bf6cea848fe754c71xy _insides->attach( *label, 1, 2, i, i+1, Gtk::FILL|Gtk::EXPAND, Gtk::SHRINK );
c869993e79c1eafbec61a56bf6cea848fe754c71xy }
c869993e79c1eafbec61a56bf6cea848fe754c71xy _scroller->add( *_insides );
c869993e79c1eafbec61a56bf6cea848fe754c71xy } else {
c869993e79c1eafbec61a56bf6cea848fe754c71xy int col = 0;
c869993e79c1eafbec61a56bf6cea848fe754c71xy int row = 0;
c869993e79c1eafbec61a56bf6cea848fe754c71xy int width = 2;
c869993e79c1eafbec61a56bf6cea848fe754c71xy int height = 1;
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy for ( unsigned int i = 0; i < items.size(); i++ ) {
c869993e79c1eafbec61a56bf6cea848fe754c71xy Gtk::Widget* thing = manage(items[i]->getPreview(PREVIEW_STYLE_PREVIEW, _view, _baseSize, _ratio));
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy if ( !_insides ) {
c869993e79c1eafbec61a56bf6cea848fe754c71xy calcGridSize( thing, items.size(), width, height );
c869993e79c1eafbec61a56bf6cea848fe754c71xy _insides = manage(new Gtk::Table( height, width ));
c869993e79c1eafbec61a56bf6cea848fe754c71xy }
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy _insides->attach( *thing, col, col+1, row, row+1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND );
c869993e79c1eafbec61a56bf6cea848fe754c71xy if ( ++col >= width ) {
c869993e79c1eafbec61a56bf6cea848fe754c71xy col = 0;
c869993e79c1eafbec61a56bf6cea848fe754c71xy row++;
c869993e79c1eafbec61a56bf6cea848fe754c71xy }
c869993e79c1eafbec61a56bf6cea848fe754c71xy }
c869993e79c1eafbec61a56bf6cea848fe754c71xy if ( !_insides ) {
c869993e79c1eafbec61a56bf6cea848fe754c71xy _insides = manage(new Gtk::Table( 1, 2 ));
c869993e79c1eafbec61a56bf6cea848fe754c71xy }
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy _scroller->add( *_insides );
c869993e79c1eafbec61a56bf6cea848fe754c71xy }
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy _scroller->show_all_children();
c869993e79c1eafbec61a56bf6cea848fe754c71xy _scroller->queue_draw();
c869993e79c1eafbec61a56bf6cea848fe754c71xy}
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy} //namespace UI
c869993e79c1eafbec61a56bf6cea848fe754c71xy} //namespace Inkscape
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy
c869993e79c1eafbec61a56bf6cea848fe754c71xy/*
c869993e79c1eafbec61a56bf6cea848fe754c71xy Local Variables:
c869993e79c1eafbec61a56bf6cea848fe754c71xy mode:c++
c869993e79c1eafbec61a56bf6cea848fe754c71xy c-file-style:"stroustrup"
c869993e79c1eafbec61a56bf6cea848fe754c71xy c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
c869993e79c1eafbec61a56bf6cea848fe754c71xy indent-tabs-mode:nil
c869993e79c1eafbec61a56bf6cea848fe754c71xy fill-column:99
c869993e79c1eafbec61a56bf6cea848fe754c71xy End:
c869993e79c1eafbec61a56bf6cea848fe754c71xy*/
c869993e79c1eafbec61a56bf6cea848fe754c71xy// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
c869993e79c1eafbec61a56bf6cea848fe754c71xy