previewholder.cpp revision 3523f35cff7c5ccce074e6e18d8eb75877443c1d
/*
* A simple interface for previewing representations.
*
* Authors:
* Jon A. Cruz
*
* Copyright (C) 2005 Jon A. Cruz
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#include "previewholder.h"
#include "preferences.h"
#include <gtkmm/scrolledwindow.h>
#include <gtkmm/sizegroup.h>
#include <gtkmm/scrollbar.h>
#include <gtkmm/adjustment.h>
#if WITH_GTKMM_3_0
#else
#endif
#define COLUMNS_FOR_SMALL 16
#define COLUMNS_FOR_LARGE 8
//#define COLUMNS_FOR_SMALL 48
//#define COLUMNS_FOR_LARGE 32
namespace Inkscape {
namespace UI {
VBox(),
_scroller(0),
_insides(0),
_prefCols(0),
_updatesFrozen(false),
_ratio(100),
_wrap(false),
{
#if WITH_GTKMM_3_0
// Add a container with the scroller and a spacer
_scroller->set_hexpand();
_scroller->set_vexpand();
#else
// Add a container with the scroller and a spacer
#endif
#if WITH_GTKMM_3_0
#else
#endif
}
{
}
{
// Scroll horizontally by page on mouse wheel
#if WITH_GTKMM_3_0
Glib::RefPtr<Gtk::Adjustment> adj = dynamic_cast<Gtk::ScrolledWindow*>(_scroller)->get_hadjustment();
#else
#endif
if (!adj) {
return FALSE;
}
return FALSE;
}
void PreviewHolder::clear()
{
_prefCols = 0;
// Kludge to restore scrollbars
if ( !_wrap && (_view != VIEW_TYPE_LIST) && (_anchor == SP_ANCHOR_NORTH || _anchor == SP_ANCHOR_SOUTH) ) {
dynamic_cast<Gtk::ScrolledWindow*>(_scroller)->set_policy( Gtk::POLICY_AUTOMATIC, Gtk::POLICY_NEVER );
}
rebuildUI();
}
/**
* Add a Previewable item to the PreviewHolder
*
* \param[in] preview The Previewable item to add
*/
{
if ( !_updatesFrozen )
{
switch(_view) {
case VIEW_TYPE_LIST:
{
Gtk::Widget* label = Gtk::manage(preview->getPreview(PREVIEW_STYLE_BLURB, VIEW_TYPE_LIST, _baseSize, _ratio, _border));
Gtk::Widget* thing = Gtk::manage(preview->getPreview(PREVIEW_STYLE_PREVIEW, VIEW_TYPE_LIST, _baseSize, _ratio, _border));
#if WITH_GTKMM_3_0
thing->set_hexpand();
thing->set_vexpand();
label->set_hexpand();
#else
#endif
}
break;
case VIEW_TYPE_GRID:
{
Gtk::Widget* thing = Gtk::manage(items[i]->getPreview(PREVIEW_STYLE_PREVIEW, VIEW_TYPE_GRID, _baseSize, _ratio, _border));
int width = 1;
int height = 1;
// Column and row for the new widget
#if !WITH_GTKMM_3_0
// If the existing grid isn't wide enough, we need to resize
// it and re-pack the existing widgets
#endif
// g_message(" %3d resize from %d to %d (r:%d, c:%d) with %d children", i, oldWidth, width, row, col, childCount );
// Loop through the existing widgets and move them to new location
for ( int j = 1; j < childCount; j++ ) {
#if WITH_GTKMM_3_0
target->set_hexpand();
target->set_vexpand();
#else
_insides->attach( *target, col2, col2+1, row2, row2+1, Gtk::FILL|Gtk::EXPAND, Gtk::FILL|Gtk::EXPAND );
#endif
}
#if WITH_GTKMM_3_0
thing->set_hexpand();
thing->set_vexpand();
#else
} else if ( col == 0 ) {
// we just started a new row
}
#endif
}
}
_scroller->queue_draw();
}
}
void PreviewHolder::freezeUpdates()
{
_updatesFrozen = true;
}
void PreviewHolder::thawUpdates()
{
_updatesFrozen = false;
rebuildUI();
}
void PreviewHolder::setStyle( ::PreviewSize size, ViewType view, guint ratio, ::BorderStyle border )
{
// Kludge to restore scrollbars
if ( !_wrap && (_view != VIEW_TYPE_LIST) && (_anchor == SP_ANCHOR_NORTH || _anchor == SP_ANCHOR_SOUTH) ) {
dynamic_cast<Gtk::ScrolledWindow*>(_scroller)->set_policy( Gtk::POLICY_AUTOMATIC, Gtk::POLICY_NEVER );
}
rebuildUI();
}
}
{
{
switch ( _anchor )
{
case SP_ANCHOR_NORTH:
case SP_ANCHOR_SOUTH:
{
dynamic_cast<Gtk::ScrolledWindow*>(_scroller)->set_policy( Gtk::POLICY_AUTOMATIC, _wrap ? Gtk::POLICY_AUTOMATIC : Gtk::POLICY_NEVER );
}
break;
case SP_ANCHOR_EAST:
case SP_ANCHOR_WEST:
{
dynamic_cast<Gtk::ScrolledWindow*>(_scroller)->set_policy( Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC );
}
break;
default:
{
dynamic_cast<Gtk::ScrolledWindow*>(_scroller)->set_policy( Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC );
}
}
rebuildUI();
}
}
void PreviewHolder::setWrap( bool b )
{
if ( b != _wrap ) {
_wrap = b;
switch ( _anchor )
{
case SP_ANCHOR_NORTH:
case SP_ANCHOR_SOUTH:
{
dynamic_cast<Gtk::ScrolledWindow*>(_scroller)->set_policy( Gtk::POLICY_AUTOMATIC, _wrap ? Gtk::POLICY_AUTOMATIC : Gtk::POLICY_NEVER );
}
break;
default:
{
(void)0;
// do nothing;
}
}
rebuildUI();
}
}
{
}
{
// 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);
if ( _insides && !_wrap && (_view != VIEW_TYPE_LIST) && (_anchor == SP_ANCHOR_NORTH || _anchor == SP_ANCHOR_SOUTH) ) {
#if GTK_CHECK_VERSION(3,0,0)
#else
#endif
} else {
dynamic_cast<Gtk::ScrolledWindow*>(_scroller)->set_policy( Gtk::POLICY_AUTOMATIC, Gtk::POLICY_NEVER );
}
}
}
//void PreviewHolder::on_size_request( Gtk::Requisition* requisition )
//{
// g_message( "on_size_request(%d, %d)", requisition->width, requisition->height );
// Gtk::VBox::on_size_request( requisition );
// g_message( " super (%d, %d)", requisition->width, requisition->height );
// g_message(" anchor:%d", _anchor);
// g_message(" items:%d", (int)items.size());
//}
/**
* Calculate the grid side of a preview holder
*
* \param[in] thing
* \param[in] itemCount The number of items to pack into the grid
* \param[out] width The width of the grid
* \param[out] height The height of the grid
*/
void PreviewHolder::calcGridSize( const Gtk::Widget* thing, int itemCount, int& width, int& height )
{
// Initially set all items in a horizontal row
height = 1;
// Disable overlay scrolling as the scrollbar covers up swatches.
// For some reason this also makes the height 55px.
#endif
#if GTK_CHECK_VERSION(3,0,0)
#else
#endif
}
#if GTK_CHECK_VERSION(3,0,0)
#else
#endif
if ( hs ) {
#if GTK_CHECK_VERSION(3,0,0)
#else
#endif
// the +8 is a temporary hack
}
#if GTK_CHECK_VERSION(3,0,0)
#else
#endif
}
} else {
width = (_baseSize == PREVIEW_SIZE_SMALL || _baseSize == PREVIEW_SIZE_TINY) ? COLUMNS_FOR_SMALL : COLUMNS_FOR_LARGE;
if ( _prefCols > 0 ) {
}
if ( height < 1 ) {
height = 1;
}
}
}
void PreviewHolder::rebuildUI()
{
_insides = 0; // remove() call should have deleted the Gtk::Table.
switch(_view) {
case VIEW_TYPE_LIST:
{
#if WITH_GTKMM_3_0
#else
#endif
if (_border == BORDER_WIDE) {
#if WITH_GTKMM_3_0
#else
#endif
}
Gtk::Widget* label = Gtk::manage(items[i]->getPreview(PREVIEW_STYLE_BLURB, _view, _baseSize, _ratio, _border));
//label->set_alignment(Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER);
Gtk::Widget* thing = Gtk::manage(items[i]->getPreview(PREVIEW_STYLE_PREVIEW, _view, _baseSize, _ratio, _border));
#if WITH_GTKMM_3_0
thing->set_hexpand();
thing->set_vexpand();
label->set_hexpand();
#else
#endif
}
}
break;
case VIEW_TYPE_GRID:
{
int col = 0;
int row = 0;
int width = 2;
int height = 1;
// If this is the last row, flag so the previews can draw a bottom
::BorderStyle border = ((row == height -1) && (_border == BORDER_SOLID)) ? BORDER_SOLID_LAST_ROW : _border;
Gtk::Widget* thing = Gtk::manage(items[i]->getPreview(PREVIEW_STYLE_PREVIEW, _view, _baseSize, _ratio, border));
if ( !_insides ) {
#if WITH_GTKMM_3_0
if (_border == BORDER_WIDE) {
}
#else
if (_border == BORDER_WIDE) {
}
#endif
}
#if WITH_GTKMM_3_0
thing->set_hexpand();
thing->set_vexpand();
#else
#endif
col = 0;
row++;
}
}
if ( !_insides ) {
#if WITH_GTKMM_3_0
#else
#endif
}
}
}
_scroller->queue_draw();
}
} //namespace UI
} //namespace Inkscape
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :