*****************************************************************************/
#include <math.h>
+#include "../utils/var_bool.hpp"
#include "ctrl_tree.hpp"
#include "../src/os_factory.hpp"
#include "../src/os_graphics.hpp"
uint32_t bgColor2,
uint32_t selColor,
const UString &rHelp,
- VarBool *pVisible ):
+ VarBool *pVisible,
+ VarBool *pFlat ):
CtrlGeneric( pIntf,rHelp, pVisible), m_rTree( rTree), m_rFont( rFont ),
m_pBgBitmap( pBgBitmap ), m_pItemBitmap( pItemBitmap ),
m_pOpenBitmap( pOpenBitmap ), m_pClosedBitmap( pClosedBitmap ),
m_rTree.addObserver( this );
m_rTree.getPositionVar().addObserver( this );
- m_firstPos = m_rTree.begin();
+ m_flat = pFlat->get();
+
+ m_firstPos = m_flat ? m_rTree.firstLeaf() : m_rTree.begin();
makeImage();
}
int CtrlTree::itemHeight()
{
int itemHeight = m_rFont.getSize();
- if( m_pClosedBitmap )
- {
- itemHeight = __MAX( m_pClosedBitmap->getHeight(), itemHeight );
- }
- if( m_pOpenBitmap )
+ if( !m_flat )
{
- itemHeight = __MAX( m_pOpenBitmap->getHeight(), itemHeight );
+ if( m_pClosedBitmap )
+ {
+ itemHeight = __MAX( m_pClosedBitmap->getHeight(), itemHeight );
+ }
+ if( m_pOpenBitmap )
+ {
+ itemHeight = __MAX( m_pOpenBitmap->getHeight(), itemHeight );
+ }
}
if( m_pItemBitmap )
{
int CtrlTree::itemImageWidth()
{
int bitmapWidth = 5;
- if( m_pClosedBitmap )
- {
- bitmapWidth = __MAX( m_pClosedBitmap->getWidth(), bitmapWidth );
- }
- if( m_pOpenBitmap )
+ if( !m_flat )
{
- bitmapWidth = __MAX( m_pOpenBitmap->getWidth(), bitmapWidth );
+ if( m_pClosedBitmap )
+ {
+ bitmapWidth = __MAX( m_pClosedBitmap->getWidth(), bitmapWidth );
+ }
+ if( m_pOpenBitmap )
+ {
+ bitmapWidth = __MAX( m_pOpenBitmap->getWidth(), bitmapWidth );
+ }
}
if( m_pItemBitmap )
{
/// \todo handle delete in a more clever way
else if ( arg->i_type == 1 ) // Global change or deletion
{
- m_firstPos = m_rTree.begin();
+ m_firstPos = m_flat ? m_rTree.firstLeaf() : m_rTree.begin();
makeImage();
}
else if ( arg->i_type == 2 ) // Item-append
{
+ if( m_flat && m_firstPos->size() )
+ m_firstPos = m_rTree.getNextLeaf( m_firstPos );
/// \todo Check if the item is really visible in the view
// (we only check if it in the document)
if( arg->b_visible == true )
/* Make sure firstPos and lastSelected are still valid */
while( m_firstPos->m_deleted && m_firstPos != m_rTree.root()->begin() )
{
- m_firstPos = m_rTree.getPrevVisibleItem( m_firstPos );
+ m_firstPos = m_flat ? m_rTree.getPrevLeaf( m_firstPos )
+ : m_rTree.getPrevVisibleItem( m_firstPos );
}
- if( m_firstPos->m_deleted ) m_firstPos = m_rTree.root()->begin();
+ if( m_firstPos->m_deleted )
+ m_firstPos = m_flat ? m_rTree.firstLeaf()
+ : m_rTree.root()->begin();
if( arg->b_visible == true )
{
void CtrlTree::onUpdate( Subject<VarPercent, void*> &rPercent, void* arg)
{
// Determine what is the first item to display
- VarTree::Iterator it = m_rTree.begin();
+ VarTree::Iterator it = m_flat ? m_rTree.firstLeaf() : m_rTree.begin();
if( m_dontMove ) return;
- int excessItems = m_rTree.visibleItems() - maxItems();
+ int excessItems;
+ if( m_flat )
+ excessItems = m_rTree.countLeafs() - maxItems();
+ else
+ excessItems = m_rTree.visibleItems() - maxItems();
if( excessItems > 0)
{
#ifdef _MSC_VER
# define lrint (int)
#endif
- it = m_rTree.getVisibleItem(lrint( (1.0 - rVarPos.get()) * (double)excessItems ) + 1);
+ if( m_flat )
+ it = m_rTree.getLeaf(lrint( (1.0 - rVarPos.get()) * (double)excessItems ) + 1 );
+ else
+ it = m_rTree.getVisibleItem(lrint( (1.0 - rVarPos.get()) * (double)excessItems ) + 1 );
}
if( m_firstPos != it )
{
void CtrlTree::onResize()
{
// Determine what is the first item to display
- VarTree::Iterator it = m_rTree.begin();
+ VarTree::Iterator it = m_flat ? m_rTree.firstLeaf() : m_rTree.begin();
- int excessItems = m_rTree.visibleItems() - maxItems();
+ int excessItems;
+ if( m_flat )
+ excessItems = m_rTree.countLeafs() - maxItems();
+ else
+ excessItems = m_rTree.visibleItems() - maxItems();
if( excessItems > 0)
{
#ifdef _MSC_VER
# define lrint (int)
#endif
- it = m_rTree.getVisibleItem(lrint( (1.0 - rVarPos.get()) * (double)excessItems ) + 1);
+ if( m_flat )
+ it = m_rTree.getLeaf(lrint( (1.0 - rVarPos.get()) * (double)excessItems ) + 1 );
+ else
+ it = m_rTree.getVisibleItem(lrint( (1.0 - rVarPos.get()) * (double)excessItems ) + 1 );
}
// Redraw the control if the position has changed
m_firstPos = it;
if( key == KEY_DELETE )
{
/* Find first non selected item before m_pLastSelected */
- VarTree::Iterator it_sel = m_rTree.begin();
- for( it = m_rTree.begin(); it != m_rTree.end();
- it = m_rTree.getNextVisibleItem( it ) )
+ VarTree::Iterator it_sel = m_flat ? m_rTree.firstLeaf()
+ : m_rTree.begin();
+ for( it = m_flat ? m_rTree.firstLeaf() : m_rTree.begin();
+ it != m_rTree.end();
+ it = m_flat ? m_rTree.getNextLeaf( it )
+ : m_rTree.getNextVisibleItem( it ) )
{
if( &*it == m_pLastSelected ) break;
if( !it->m_selected ) it_sel = it;
while( i >= 0 )
{
VarTree::Iterator it_old = it;
- it = m_rTree.getNextVisibleItem( it );
+ it = m_flat ? m_rTree.getNextLeaf( it )
+ : m_rTree.getNextVisibleItem( it );
/* End is already visible, dont' scroll */
if( it == m_rTree.end() )
{
int i = maxItems();
while( i >= maxItems()/2 )
{
- it = m_rTree.getPrevVisibleItem( it );
+ it = m_flat ? m_rTree.getPrevLeaf( it )
+ : m_rTree.getPrevVisibleItem( it );
/* End is already visible, dont' scroll */
- if( it == m_rTree.begin() )
+ if( it == ( m_flat ? m_rTree.firstLeaf() : m_rTree.begin() ) )
{
break;
}
}
- for( it = m_rTree.begin(); it != m_rTree.end();
- it = m_rTree.getNextVisibleItem( it ) )
+ for( it = m_flat ? m_rTree.firstLeaf() : m_rTree.begin();
+ it != m_rTree.end();
+ it = m_flat ? m_rTree.getNextLeaf( it )
+ : m_rTree.getNextVisibleItem( it ) )
{
- VarTree::Iterator next = m_rTree.getNextVisibleItem( it );
+ VarTree::Iterator next = m_flat ? m_rTree.getNextLeaf( it )
+ : m_rTree.getNextVisibleItem( it );
if( key == KEY_UP )
{
// Scroll up one item
}
// Fix last tree item selection
- if( m_rTree.getNextVisibleItem( it ) == m_rTree.end()
+ if( ( m_flat ? m_rTree.getNextLeaf( it )
+ : m_rTree.getNextVisibleItem( it ) ) == m_rTree.end()
&& &*it == m_pLastSelected )
{
(*it).m_selected = true;
VarTree::Iterator itClicked = findItemAtPos( yPos );
// Flag to know if the current item must be selected
bool select = false;
- for( it = m_rTree.begin(); it != m_rTree.end();
- it = m_rTree.getNextVisibleItem( it ) )
+ for( it = m_flat ? m_rTree.firstLeaf() : m_rTree.begin();
+ it != m_rTree.end();
+ it = m_flat ? m_rTree.getNextLeaf( it )
+ : m_rTree.getNextVisibleItem( it ) )
{
bool nextSelect = select;
if( it == itClicked || &*it == m_pLastSelected )
VarTree::Iterator itClicked = findItemAtPos( yPos );
// Flag to know if the current item must be selected
bool select = false;
- for( it = m_rTree.begin(); it != m_rTree.end();
- it = m_rTree.getNextVisibleItem( it ) )
+ for( it = m_flat ? m_rTree.firstLeaf() : m_rTree.begin();
+ it != m_rTree.end();
+ it = m_flat ? m_rTree.getNextLeaf( it )
+ : m_rTree.getNextVisibleItem( it ) )
{
bool nextSelect = select;
if( it == itClicked || &*it == m_pLastSelected )
it = findItemAtPos(yPos);
if( it != m_rTree.end() )
{
- if( it->size() && xPos > (it->depth() - 1) * itemImageWidth()
- && xPos < it->depth() * itemImageWidth() )
+ if( ( it->size() && xPos > (it->depth() - 1) * itemImageWidth()
+ && xPos < it->depth() * itemImageWidth() )
+ && !m_flat )
{
// Fold/unfold the item
it->m_expanded = !it->m_expanded;
{
// Unselect any previously selected item
VarTree::Iterator it2;
- for( it2 = m_rTree.begin(); it2 != m_rTree.end();
- it2 = m_rTree.getNextVisibleItem( it2 ) )
+ for( it2 = m_flat ? m_rTree.firstLeaf() : m_rTree.begin();
+ it2 != m_rTree.end();
+ it2 = m_flat ? m_rTree.getNextLeaf( it2 )
+ : m_rTree.getNextVisibleItem( it2 ) )
{
it2->m_selected = false;
}
int direction = ((EvtScroll&)rEvent).getDirection();
double percentage = m_rTree.getPositionVar().get();
- double step = 2.0 / (double)m_rTree.visibleItems();
+ double step = 2.0 / (double)( m_flat ? m_rTree.countLeafs()
+ : m_rTree.visibleItems() );
if( direction == EvtScroll::kUp )
{
percentage += step;
VarTree::Iterator it;
int i = 0;
int iFirst = 0;
- for( it = m_rTree.begin(); it != m_rTree.end();
- it = m_rTree.getNextVisibleItem( it ) )
+ for( it = m_flat ? m_rTree.firstLeaf() : m_rTree.begin();
+ it != m_rTree.end();
+ it = m_flat ? m_rTree.getNextLeaf( it )
+ : m_rTree.getNextVisibleItem( it ) )
{
i++;
if( it == m_firstPos )
}
}
iFirst += maxItems();
- if( iFirst >= m_rTree.visibleItems() ) iFirst = m_rTree.visibleItems();
- float f_new = (float)iFirst / (float)m_rTree.visibleItems();
+ if( iFirst >= m_flat ? m_rTree.countLeafs() : m_rTree.visibleItems() )
+ iFirst = m_flat ? m_rTree.countLeafs() : m_rTree.visibleItems();
+ float f_new = (float)iFirst / (float)( m_flat ? m_rTree.countLeafs()
+ :m_rTree.visibleItems() );
m_dontMove = true;
m_rTree.getPositionVar().set( 1.0 - f_new );
m_dontMove = false;
m_rTree.ensureExpanded( item );
- for( it = m_rTree.begin(); it != m_rTree.end();
- it = m_rTree.getNextVisibleItem( it ) )
+ for( it = m_flat ? m_rTree.firstLeaf() : m_rTree.begin();
+ it != m_rTree.end();
+ it = m_flat ? m_rTree.getNextLeaf( it )
+ : m_rTree.getNextVisibleItem( it ) )
{
if( it->m_id == item->m_id ) break;
focusItemIndex++;
// Find m_firstPos
VarTree::Iterator it;
int firstPosIndex = 0;
- for( it = m_rTree.begin(); it != m_rTree.end();
- it = m_rTree.getNextVisibleItem( it ) )
+ for( it = m_flat ? m_rTree.firstLeaf() : m_rTree.begin();
+ it != m_rTree.end();
+ it = m_flat ? m_rTree.getNextLeaf( it )
+ : m_rTree.getNextVisibleItem( it ) )
{
if( it == m_firstPos ) break;
firstPosIndex++;
// Scroll to have the wanted stream visible
VarPercent &rVarPos = m_rTree.getPositionVar();
rVarPos.set( 1.0 - (double)focusItemIndex /
- (double)m_rTree.visibleItems() );
+ (double)( m_flat ? m_rTree.countLeafs()
+ : m_rTree.visibleItems() ) );
return true;
}
return false;
int playIndex = 0;
VarTree::Iterator it;
- for( it = m_rTree.begin(); it != m_rTree.end();
- it = m_rTree.getNextItem( it ) )
+ for( it = m_flat ? m_rTree.firstLeaf() : m_rTree.begin();
+ it != m_rTree.end();
+ it = m_flat ? m_rTree.getNextLeaf( it )
+ : m_rTree.getNextItem( it ) )
{
if( it->m_playing )
{
break;
}
}
- for( it = m_rTree.begin(); it != m_rTree.end();
- it = m_rTree.getNextVisibleItem( it ) )
+ for( it = m_flat ? m_rTree.firstLeaf() : m_rTree.begin();
+ it != m_rTree.end();
+ it = m_flat ? m_rTree.getNextLeaf( it )
+ : m_rTree.getNextVisibleItem( it ) )
{
if( it->m_playing )
break;
}
do
{
- it = m_rTree.getNextVisibleItem( it );
+ it = m_flat ? m_rTree.getNextLeaf( it )
+ : m_rTree.getNextVisibleItem( it );
} while( it->m_deleted );
}
}
m_pImage->fillRect( 0, yPos, width, rectHeight, color );
do
{
- it = m_rTree.getNextVisibleItem( it );
+ it = m_flat ? m_rTree.getNextLeaf( it )
+ : m_rTree.getNextVisibleItem( it );
} while( it->m_deleted );
}
else
// Draw the text
if( pStr != NULL )
{
- int depth = it->depth();
+ int depth = m_flat ? 1 : it->depth();
GenericBitmap *pText = m_rFont.drawString( *pStr, color, width - bitmapWidth * depth );
if( !pText )
{
delete pText;
}
do {
- it = m_rTree.getNextVisibleItem( it );
+ it = m_flat ? m_rTree.getNextLeaf( it )
+ : m_rTree.getNextVisibleItem( it );
} while( it->m_deleted );
}
stats_TimerStop( getIntf(), STATS_TIMER_SKINS_PLAYTREE_IMAGE );
// We decrement pos as we try the other items, until pos == 0.
VarTree::Iterator it;
for( it = m_firstPos; it != m_rTree.end() && pos != 0;
- it = m_rTree.getNextVisibleItem( it ) )
+ it = m_flat ? m_rTree.getNextLeaf( it )
+ : m_rTree.getNextVisibleItem( it ) )
{
pos--;
}
/// Type definition
struct Tree
{
- Tree( const string & id, int xPos, int yPos, const string & visible, int width, int height, const string & leftTop, const string & rightBottom, const string & fontId, const string & var, const string & bgImageId, const string & itemImageId, const string & openImageId, const string & closedImageId, uint32_t fgColor, uint32_t playColor, uint32_t bgColor1, uint32_t bgColor2, uint32_t selColor, const string & help, int layer, const string & windowId, const string & layoutId ):
-m_id( id ), m_xPos( xPos ), m_yPos( yPos ), m_visible( visible ), m_width( width ), m_height( height ), m_leftTop( leftTop ), m_rightBottom( rightBottom ), m_fontId( fontId ), m_var( var ), m_bgImageId( bgImageId ), m_itemImageId( itemImageId ), m_openImageId( openImageId ), m_closedImageId( closedImageId ), m_fgColor( fgColor ), m_playColor( playColor ), m_bgColor1( bgColor1 ), m_bgColor2( bgColor2 ), m_selColor( selColor ), m_help( help ), m_layer( layer ), m_windowId( windowId ), m_layoutId( layoutId ) {}
+ Tree( const string & id, int xPos, int yPos, const string & visible, const string & flat, int width, int height, const string & leftTop, const string & rightBottom, const string & fontId, const string & var, const string & bgImageId, const string & itemImageId, const string & openImageId, const string & closedImageId, uint32_t fgColor, uint32_t playColor, uint32_t bgColor1, uint32_t bgColor2, uint32_t selColor, const string & help, int layer, const string & windowId, const string & layoutId ):
+m_id( id ), m_xPos( xPos ), m_yPos( yPos ), m_visible( visible ), m_flat( flat ), m_width( width ), m_height( height ), m_leftTop( leftTop ), m_rightBottom( rightBottom ), m_fontId( fontId ), m_var( var ), m_bgImageId( bgImageId ), m_itemImageId( itemImageId ), m_openImageId( openImageId ), m_closedImageId( closedImageId ), m_fgColor( fgColor ), m_playColor( playColor ), m_bgColor1( bgColor1 ), m_bgColor2( bgColor2 ), m_selColor( selColor ), m_help( help ), m_layer( layer ), m_windowId( windowId ), m_layoutId( layoutId ) {}
string m_id;
int m_xPos;
int m_yPos;
string m_visible;
+ string m_flat;
int m_width;
int m_height;
string m_leftTop;