+ ReleaseActor( iter->first, iter->second );
+ }
+ mItemPool.clear();
+
+ DoRefresh(GetCurrentLayoutPosition(0), true);
+}
+
+void ItemView::DoRefresh(float currentLayoutPosition, bool cacheExtra)
+{
+ if (mActiveLayout)
+ {
+ ItemRange range = GetItemRange(*mActiveLayout, mActiveLayoutTargetSize, currentLayoutPosition, cacheExtra/*reserve extra*/);
+ RemoveActorsOutsideRange( range );
+ AddActorsWithinRange( range, Self().GetCurrentSize() );
+
+ mScrollUpdatedSignal.Emit( Vector2(0.0f, currentLayoutPosition) );
+ }
+}
+
+void ItemView::SetMinimumSwipeSpeed(float speed)
+{
+ mMinimumSwipeSpeed = speed;
+}
+
+float ItemView::GetMinimumSwipeSpeed() const
+{
+ return mMinimumSwipeSpeed;
+}
+
+void ItemView::SetMinimumSwipeDistance(float distance)
+{
+ mMinimumSwipeDistance = distance;
+}
+
+float ItemView::GetMinimumSwipeDistance() const
+{
+ return mMinimumSwipeDistance;
+}
+
+void ItemView::SetWheelScrollDistanceStep(float step)
+{
+ mWheelScrollDistanceStep = step;
+}
+
+float ItemView::GetWheelScrollDistanceStep() const
+{
+ return mWheelScrollDistanceStep;
+}
+
+void ItemView::SetAnchoring(bool enabled)
+{
+ mAnchoringEnabled = enabled;
+}
+
+bool ItemView::GetAnchoring() const
+{
+ return mAnchoringEnabled;
+}
+
+void ItemView::SetAnchoringDuration(float durationSeconds)
+{
+ mAnchoringDuration = durationSeconds;
+}
+
+float ItemView::GetAnchoringDuration() const
+{
+ return mAnchoringDuration;
+}
+
+void ItemView::SetRefreshInterval(float intervalLayoutPositions)
+{
+ if( !Equals(mRefreshIntervalLayoutPositions, intervalLayoutPositions) )
+ {
+ mRefreshIntervalLayoutPositions = intervalLayoutPositions;
+
+ Actor self = Self();
+ if(mRefreshNotification)
+ {
+ self.RemovePropertyNotification(mRefreshNotification);
+ }
+ mRefreshNotification = self.AddPropertyNotification( Toolkit::ItemView::Property::LAYOUT_POSITION, StepCondition(mRefreshIntervalLayoutPositions, 0.0f) );
+ mRefreshNotification.NotifySignal().Connect( this, &ItemView::OnRefreshNotification );
+ }
+}
+
+float ItemView::GetRefreshInterval() const
+{
+ return mRefreshIntervalLayoutPositions;
+}
+
+void ItemView::SetRefreshEnabled(bool enabled)
+{
+ mRefreshEnabled = enabled;
+}
+
+Actor ItemView::GetItem(unsigned int itemId) const
+{
+ Actor actor;
+
+ ConstItemPoolIter iter = mItemPool.find( itemId );
+ if( iter != mItemPool.end() )
+ {
+ actor = iter->second;
+ }
+
+ return actor;
+}
+
+unsigned int ItemView::GetItemId( Actor actor ) const
+{
+ unsigned int itemId( 0 );
+
+ for ( ConstItemPoolIter iter = mItemPool.begin(); iter != mItemPool.end(); ++iter )
+ {
+ if( iter->second == actor )
+ {
+ itemId = iter->first;
+ break;
+ }
+ }
+
+ return itemId;
+}
+
+void ItemView::InsertItem( Item newItem, float durationSeconds )
+{
+ mAddingItems = true;
+ Vector3 layoutSize = Self().GetCurrentSize();
+
+ Actor displacedActor;
+ ItemPoolIter afterDisplacedIter = mItemPool.end();
+
+ ItemPoolIter foundIter = mItemPool.find( newItem.first );
+ if( mItemPool.end() != foundIter )
+ {
+ SetupActor( newItem, layoutSize );
+ Self().Add( newItem.second );
+
+ displacedActor = foundIter->second;
+ foundIter->second = newItem.second;
+
+ afterDisplacedIter = ++foundIter;
+ }
+ else
+ {
+ // Inserting before the existing item range?
+ ItemPoolIter iter = mItemPool.begin();
+ if( iter != mItemPool.end() &&
+ iter->first > newItem.first )
+ {
+ displacedActor = iter->second;
+ mItemPool.erase( iter++ ); // iter is still valid after the erase
+
+ afterDisplacedIter = iter;
+ }
+ }
+
+ if( displacedActor )
+ {
+ // Move the existing actors to make room
+ for( ItemPoolIter iter = afterDisplacedIter; mItemPool.end() != iter; ++iter )
+ {
+ Actor temp = iter->second;
+ iter->second = displacedActor;
+ displacedActor = temp;
+
+ iter->second.RemoveConstraints();
+ mActiveLayout->ApplyConstraints( iter->second, iter->first, layoutSize, Self() );
+ }
+
+ // Create last item
+ ItemPool::reverse_iterator lastIter = mItemPool.rbegin();
+ if ( lastIter != mItemPool.rend() )
+ {
+ ItemId lastId = lastIter->first;
+ Item lastItem( lastId + 1, displacedActor );
+ mItemPool.insert( lastItem );
+
+ lastItem.second.RemoveConstraints();
+ mActiveLayout->ApplyConstraints( lastItem.second, lastItem.first, layoutSize, Self() );
+ }
+ }
+
+ CalculateDomainSize( layoutSize );
+
+ mAddingItems = false;
+}
+
+void ItemView::InsertItems( const ItemContainer& newItems, float durationSeconds )
+{
+ mAddingItems = true;
+ Vector3 layoutSize = Self().GetCurrentSize();
+
+ // Insert from lowest id to highest
+ std::set<Item> sortedItems;
+ for( ConstItemIter iter = newItems.begin(); newItems.end() != iter; ++iter )
+ {
+ sortedItems.insert( *iter );
+ }
+
+ for( std::set<Item>::iterator iter = sortedItems.begin(); sortedItems.end() != iter; ++iter )
+ {
+ Self().Add( iter->second );
+
+ ItemPoolIter foundIter = mItemPool.find( iter->first );
+ if( mItemPool.end() != foundIter )
+ {
+ Actor moveMe = foundIter->second;
+ foundIter->second = iter->second;
+
+ // Move the existing actors to make room
+ for( ItemPoolIter iter = ++foundIter; mItemPool.end() != iter; ++iter )
+ {
+ Actor temp = iter->second;
+ iter->second = moveMe;
+ moveMe = temp;
+ }
+
+ // Create last item
+ ItemId lastId = mItemPool.rbegin()->first;
+ Item lastItem( lastId + 1, moveMe );
+ mItemPool.insert( lastItem );
+ }
+ else
+ {
+ mItemPool.insert( *iter );
+ }
+ }
+
+ // Relayout everything
+ for (ItemPoolIter iter = mItemPool.begin(); iter != mItemPool.end(); ++iter)
+ {
+ // If newly inserted
+ if( FindById( newItems, iter->first ) )
+ {
+ SetupActor( *iter, layoutSize );
+ }
+ else
+ {
+ iter->second.RemoveConstraints();
+ mActiveLayout->ApplyConstraints( iter->second, iter->first, layoutSize, Self() );
+ }