previewholder.cpp revision a1c83ca671ae9b97c6a30901ee3542faf93defb4
c869993e79c1eafbec61a56bf6cea848fe754c71xy * A simple interface for previewing representations.
c869993e79c1eafbec61a56bf6cea848fe754c71xy * Authors:
c869993e79c1eafbec61a56bf6cea848fe754c71xy * Jon A. Cruz
c869993e79c1eafbec61a56bf6cea848fe754c71xy * Copyright (C) 2005 Jon A. Cruz
c869993e79c1eafbec61a56bf6cea848fe754c71xy * Released under GNU GPL, read the file 'COPYING' for more information
c869993e79c1eafbec61a56bf6cea848fe754c71xy//#define COLUMNS_FOR_SMALL 48
c869993e79c1eafbec61a56bf6cea848fe754c71xy//#define COLUMNS_FOR_LARGE 32
c869993e79c1eafbec61a56bf6cea848fe754c71xynamespace UI {
c869993e79c1eafbec61a56bf6cea848fe754c71xy // Add a container with the scroller and a spacer
c869993e79c1eafbec61a56bf6cea848fe754c71xy Gtk::Table* spaceHolder = manage( new Gtk::Table(1, 2) );
c869993e79c1eafbec61a56bf6cea848fe754c71xy spaceHolder->attach( *_scroller, 0, 1, 0, 1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND );
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 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 _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 Gtk::Widget* thing = manage(items[i]->getPreview(PREVIEW_STYLE_PREVIEW, VIEW_TYPE_GRID, _baseSize, _ratio));
c869993e79c1eafbec61a56bf6cea848fe754c71xy if ( _insides && width > (int)_insides->property_n_columns() ) {
c869993e79c1eafbec61a56bf6cea848fe754c71xy std::vector<Gtk::Widget*>kids = _insides->get_children();
c869993e79c1eafbec61a56bf6cea848fe754c71xy// g_message(" %3d resize from %d to %d (r:%d, c:%d) with %d children", i, oldWidth, width, row, col, childCount );
8bb4b220fdb894543e41a5f9037898cf3c3f312bgl _insides->attach( *target, col2, col2+1, row2, row2+1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND );
8bb4b220fdb894543e41a5f9037898cf3c3f312bgl } else if ( col == 0 ) {
8bb4b220fdb894543e41a5f9037898cf3c3f312bgl // we just started a new row
c869993e79c1eafbec61a56bf6cea848fe754c71xy _insides->attach( *thing, col, col+1, row, row+1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND );
c869993e79c1eafbec61a56bf6cea848fe754c71xyvoid PreviewHolder::setStyle( ::PreviewSize size, ViewType view, guint ratio )
c869993e79c1eafbec61a56bf6cea848fe754c71xy if ( size != _baseSize || view != _view || 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 dynamic_cast<Gtk::ScrolledWindow*>(_scroller)->set_policy( Gtk::POLICY_AUTOMATIC, _wrap ? Gtk::POLICY_AUTOMATIC : Gtk::POLICY_NEVER );
8bb4b220fdb894543e41a5f9037898cf3c3f312bgl dynamic_cast<Gtk::ScrolledWindow*>(_scroller)->set_policy( Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC );
c869993e79c1eafbec61a56bf6cea848fe754c71xy dynamic_cast<Gtk::ScrolledWindow*>(_scroller)->set_policy( Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC );
c869993e79c1eafbec61a56bf6cea848fe754c71xy if ( b != _wrap ) {
c869993e79c1eafbec61a56bf6cea848fe754c71xy dynamic_cast<Gtk::ScrolledWindow*>(_scroller)->set_policy( Gtk::POLICY_AUTOMATIC, _wrap ? Gtk::POLICY_AUTOMATIC : Gtk::POLICY_NEVER );
c869993e79c1eafbec61a56bf6cea848fe754c71xy // do nothing;
c869993e79c1eafbec61a56bf6cea848fe754c71xyvoid PreviewHolder::on_size_allocate( Gtk::Allocation& allocation )
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 if ( _insides && !_wrap && (_view != VIEW_TYPE_LIST) && (_anchor == SP_ANCHOR_NORTH || _anchor == SP_ANCHOR_SOUTH) ) {
c869993e79c1eafbec61a56bf6cea848fe754c71xy if ( (delta > 4) && req.height < allocation.get_height() ) {
c869993e79c1eafbec61a56bf6cea848fe754c71xy dynamic_cast<Gtk::ScrolledWindow*>(_scroller)->set_policy( Gtk::POLICY_NEVER, Gtk::POLICY_NEVER );
c869993e79c1eafbec61a56bf6cea848fe754c71xy dynamic_cast<Gtk::ScrolledWindow*>(_scroller)->set_policy( Gtk::POLICY_AUTOMATIC, Gtk::POLICY_NEVER );
c869993e79c1eafbec61a56bf6cea848fe754c71xyvoid PreviewHolder::on_size_request( Gtk::Requisition* requisition )
c869993e79c1eafbec61a56bf6cea848fe754c71xy// g_message( "on_size_request(%d, %d)", requisition->width, requisition->height );
c869993e79c1eafbec61a56bf6cea848fe754c71xy// g_message( " super (%d, %d)", requisition->width, requisition->height );
c869993e79c1eafbec61a56bf6cea848fe754c71xy// g_message(" anchor:%d", _anchor);
c869993e79c1eafbec61a56bf6cea848fe754c71xy// g_message(" items:%d", (int)items.size());
c869993e79c1eafbec61a56bf6cea848fe754c71xyvoid PreviewHolder::calcGridSize( const Gtk::Widget* thing, int itemCount, int& width, int& height )
c869993e79c1eafbec61a56bf6cea848fe754c71xy if ( _anchor == SP_ANCHOR_SOUTH || _anchor == SP_ANCHOR_NORTH ) {
c869993e79c1eafbec61a56bf6cea848fe754c71xy Gtk::HScrollbar* hs = dynamic_cast<Gtk::ScrolledWindow*>(_scroller)->get_hscrollbar();
c869993e79c1eafbec61a56bf6cea848fe754c71xy // the +8 is a temporary hack
c869993e79c1eafbec61a56bf6cea848fe754c71xy const_cast<Gtk::Widget*>(thing)->get_preferred_size(&req, NULL);
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 = (_baseSize == PREVIEW_SIZE_SMALL || _baseSize == PREVIEW_SIZE_TINY) ? COLUMNS_FOR_SMALL : COLUMNS_FOR_LARGE;
c869993e79c1eafbec61a56bf6cea848fe754c71xy if ( _prefCols > 0 ) {
c869993e79c1eafbec61a56bf6cea848fe754c71xy _insides = 0; // remove() call should have deleted the Gtk::Table.
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 Gtk::Widget* thing = manage(items[i]->getPreview(PREVIEW_STYLE_PREVIEW, _view, _baseSize, _ratio));
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 Gtk::Widget* thing = manage(items[i]->getPreview(PREVIEW_STYLE_PREVIEW, _view, _baseSize, _ratio));
c869993e79c1eafbec61a56bf6cea848fe754c71xy _insides->attach( *thing, col, col+1, row, row+1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND );
c869993e79c1eafbec61a56bf6cea848fe754c71xy} //namespace UI
c869993e79c1eafbec61a56bf6cea848fe754c71xy} //namespace Inkscape
c869993e79c1eafbec61a56bf6cea848fe754c71xy Local Variables:
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// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :