ui/uiengine/medialists/src/glxmedialistiterator.cpp
changeset 29 2c833fc9e98f
parent 24 99ad1390cd33
equal deleted inserted replaced
26:c499df2dbb33 29:2c833fc9e98f
  1210         {
  1210         {
  1211         // Looping case: |----L      F----|
  1211         // Looping case: |----L      F----|
  1212         return aIndex <= lastInRange || aIndex >= firstInRange;
  1212         return aIndex <= lastInRange || aIndex >= firstInRange;
  1213         }
  1213         }
  1214     }
  1214     }
       
  1215 
       
  1216 // -----------------------------------------------------------------------------
       
  1217 // Constructor
       
  1218 // -----------------------------------------------------------------------------
       
  1219 //
       
  1220 EXPORT_C TGlxScrollingDirectionIterator::TGlxScrollingDirectionIterator( )
       
  1221     {
       
  1222     TRACER("TGlxScrollingDirectionIterator::TGlxScrollingDirectionIterator");
       
  1223     iMovingDirection = EForward;
       
  1224     iExVisindex = 0;
       
  1225     iDefaultVisItems = GlxListUtils::VisibleItemsGranularityL();       
       
  1226     iCurrentItem = 0;
       
  1227     iFrontOffset = 4 * iDefaultVisItems;
       
  1228     iRearOffset = 2 * iDefaultVisItems;  // Rear Is Not Handled Yet, We Need To ?
       
  1229     iList = NULL;
       
  1230   }
       
  1231     
       
  1232 // -----------------------------------------------------------------------------
       
  1233 // Destructor
       
  1234 // -----------------------------------------------------------------------------
       
  1235 //
       
  1236 EXPORT_C TGlxScrollingDirectionIterator::~TGlxScrollingDirectionIterator()
       
  1237     {
       
  1238     TRACER("TGlxScrollingDirectionIterator::~TGlxScrollingDirectionIterator");
       
  1239     
       
  1240     } 
       
  1241 
       
  1242 // ----------------------------------------------------------------------------
       
  1243 // Set range offsets
       
  1244 // ----------------------------------------------------------------------------
       
  1245 //
       
  1246 EXPORT_C void TGlxScrollingDirectionIterator::SetRangeOffsets(TInt aRearOffset,
       
  1247     TInt aFrontOffset)
       
  1248     { 
       
  1249     TRACER("TGlxScrollingDirectionIterator::SetRangeOffsets");
       
  1250     
       
  1251     __ASSERT_DEBUG(aRearOffset >= 0 && aFrontOffset >= 0, Panic(EGlxPanicIllegalArgument)); 
       
  1252     iFrontOffset = Max(aFrontOffset, iDefaultVisItems );
       
  1253     iRearOffset = Max(aRearOffset, iDefaultVisItems );
       
  1254     }
       
  1255 
       
  1256 // -----------------------------------------------------------------------------
       
  1257 // Set to first item
       
  1258 // -----------------------------------------------------------------------------
       
  1259 //
       
  1260 void TGlxScrollingDirectionIterator::SetToFirst(const MGlxMediaList* aList) 
       
  1261     {
       
  1262     TRACER("TGlxScrollingDirectionIterator::SetToFirst");
       
  1263     __ASSERT_DEBUG(aList != NULL, Panic(EGlxPanicNullPointer));
       
  1264 
       
  1265     iList = aList;
       
  1266     iCurrentItem = 0;
       
  1267     }
       
  1268 
       
  1269 // -----------------------------------------------------------------------------
       
  1270 // Return the item index or KErrNotFound, and goes to next
       
  1271 // -----------------------------------------------------------------------------
       
  1272 //
       
  1273 TInt TGlxScrollingDirectionIterator::operator++(TInt) 
       
  1274     {
       
  1275     TRACER("TGlxScrollingDirectionIterator::operator++");
       
  1276     __ASSERT_DEBUG(iList != NULL, Panic(EGlxPanicNullPointer));
       
  1277 
       
  1278     TInt listCount = iList->Count();
       
  1279     TInt index = iList->VisibleWindowIndex();
       
  1280     __ASSERT_ALWAYS( index >= 0 && index <= listCount, Panic( EGlxPanicIllegalState ) );
       
  1281     
       
  1282     if (listCount <= 0 || iFrontOffset + iRearOffset < iCurrentItem || listCount <= iCurrentItem)
       
  1283         {
       
  1284         return KErrNotFound;
       
  1285         }
       
  1286   
       
  1287     if(iExVisindex < index)
       
  1288         {
       
  1289         iMovingDirection = EForward;
       
  1290         iExVisindex = index;
       
  1291         }
       
  1292     else if(iExVisindex > index)
       
  1293         {
       
  1294         iMovingDirection = EBackward;
       
  1295         iExVisindex = index;
       
  1296         }
       
  1297     
       
  1298     if(EForward == iMovingDirection)
       
  1299         {
       
  1300         if ((index + iCurrentItem  < index + iFrontOffset) && (index + iCurrentItem  < listCount))
       
  1301             {
       
  1302             index += iCurrentItem;
       
  1303             }
       
  1304         else
       
  1305             {
       
  1306             return KErrNotFound;
       
  1307             }
       
  1308         }
       
  1309     else
       
  1310         {
       
  1311         if((index + iDefaultVisItems - iCurrentItem > index + iDefaultVisItems - iFrontOffset) && (index + iDefaultVisItems - iCurrentItem < listCount))
       
  1312             {
       
  1313             index += iDefaultVisItems - iCurrentItem;
       
  1314             }
       
  1315         else
       
  1316             {
       
  1317             return KErrNotFound;
       
  1318             }
       
  1319         }
       
  1320 
       
  1321       iCurrentItem++;
       
  1322     
       
  1323       // The index may be below 0 or above count. Normalise back to list indexes.
       
  1324       return GlxListUtils::NormalizedIndex(index, listCount); 
       
  1325       } 
       
  1326   
       
  1327 // -----------------------------------------------------------------------------
       
  1328 // Return ETrue if index is within range, EFalse otherwise,
       
  1329 // -----------------------------------------------------------------------------
       
  1330 //
       
  1331 TBool TGlxScrollingDirectionIterator::InRange(TInt aIndex) const
       
  1332     {
       
  1333     TRACER("TGlxScrollingDirectionIterator::InRange");
       
  1334     
       
  1335     // Rear Window is Not Handled yet , Still We include Rear window in Consideration for Garbage Collection
       
  1336     // Need to Re-Visit
       
  1337     TInt count = iList->Count();
       
  1338   
       
  1339     // Handle the case where range is longer than count separately, because looping will
       
  1340     // confuse otherwise
       
  1341     if (count <= iRearOffset + iFrontOffset) 
       
  1342         {
       
  1343         // Range is longer than count, must be in range
       
  1344         return ETrue;
       
  1345         }
       
  1346   
       
  1347     TInt index = iList->VisibleWindowIndex();
       
  1348     __ASSERT_ALWAYS( index >= 0 && index < iList->Count(), Panic( EGlxPanicIllegalState ) );
       
  1349     
       
  1350     TInt firstInRange = GlxListUtils::NormalizedIndex(index - iRearOffset, count);
       
  1351     TInt lastInRange = GlxListUtils::NormalizedIndex(index + iFrontOffset, count);
       
  1352   
       
  1353     if (firstInRange <= lastInRange)
       
  1354         {
       
  1355         // Normal case:  |    F-------L   |
       
  1356         return aIndex >= firstInRange && aIndex <= lastInRange;
       
  1357         }
       
  1358     else 
       
  1359         {
       
  1360         // Looping case: |----L      F----|
       
  1361         return aIndex <= lastInRange || aIndex >= firstInRange;
       
  1362         }
       
  1363     }