scrsaver/scrsaverplugins/BmpAnimScrPlugin/src/CBmpAnimModel.cpp
changeset 14 8a173132b0aa
parent 2 058b1fc1663a
equal deleted inserted replaced
2:058b1fc1663a 14:8a173132b0aa
     1 /*
       
     2 * Copyright (c) 2003 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:     Takes care of storing and serving the bitmaps
       
    15 *               to be animated along with their properties
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 #include "CBmpAnimModel.h"
       
    24 
       
    25 
       
    26 // C'tor
       
    27 CBmpAnimModel::CBmpAnimModel()
       
    28     {
       
    29     }
       
    30 
       
    31     
       
    32 // D'tor
       
    33 CBmpAnimModel::~CBmpAnimModel()
       
    34     {
       
    35     // Delete item array
       
    36     if (iItems)
       
    37         {
       
    38         iItems->ResetAndDestroy();
       
    39         }
       
    40     delete iItems;
       
    41     }
       
    42 
       
    43     
       
    44 // Two-phase constructor, initialises member arrays and stuff
       
    45 void CBmpAnimModel::ConstructL(CBmpAnimSettings* aSettings)
       
    46     {
       
    47     // Create item array
       
    48     iItems = new(ELeave) CArrayPtrFlat<CBmpAnimItem>(
       
    49         KBmpAnimItemArrayGranularity);
       
    50 
       
    51     iSettings = aSettings;
       
    52     }
       
    53 
       
    54 
       
    55 // Number of items query
       
    56 TInt CBmpAnimModel::NumberOfItems() const
       
    57     {
       
    58     return iItems ? iItems->Count() : 0;
       
    59     }
       
    60     
       
    61   
       
    62 // Add an item to the end of the array
       
    63 void CBmpAnimModel::AppendItemL(CBmpAnimItem* aItem)
       
    64     {
       
    65     // Sanity check
       
    66     if (!iItems)
       
    67         {
       
    68         ASSERT(EFalse);
       
    69         return;
       
    70         }
       
    71 
       
    72     // Stash it in
       
    73     iItems->AppendL(aItem);
       
    74     }
       
    75 
       
    76     
       
    77 // Insert an item at <aIndex>. Space must be reserved.
       
    78 void CBmpAnimModel::InsertItemL(TInt aIndex, CBmpAnimItem* aItem)
       
    79     {
       
    80     if ((iItems) && (aIndex >= 0) && (aIndex <= NumberOfItems()))
       
    81         {
       
    82         // Squeeze it in
       
    83         iItems->InsertL(aIndex, aItem);
       
    84         }
       
    85     else
       
    86         {
       
    87         ASSERT(EFalse);
       
    88         }
       
    89     }
       
    90     
       
    91 
       
    92 // Delete item at <aIndex>
       
    93 void CBmpAnimModel::DeleteItemL(TInt aIndex)
       
    94     {
       
    95     if ((iItems) && (aIndex >= 0) && (aIndex <= NumberOfItems()))
       
    96         {
       
    97         // Grab hold of the item for deletion, remove from array
       
    98         // and compress the array
       
    99         CBmpAnimItem* ptr = iItems->At(aIndex);
       
   100         iItems->Delete(aIndex);
       
   101         delete ptr;
       
   102         iItems->Compress();
       
   103         }
       
   104     else
       
   105         {
       
   106         ASSERT(EFalse);
       
   107         }
       
   108     }
       
   109 
       
   110 
       
   111 // Delete all Items
       
   112 void CBmpAnimModel::DeleteAll()
       
   113     {
       
   114     if (iItems)
       
   115         {
       
   116         iItems->ResetAndDestroy();
       
   117         }
       
   118     }
       
   119 
       
   120     
       
   121 // Get item at position <aIndex>
       
   122 CBmpAnimItem* CBmpAnimModel::ItemAt(TInt aIndex) const
       
   123     {
       
   124     if ((iItems) && (aIndex >= 0) && (aIndex < NumberOfItems()))
       
   125         {
       
   126         return iItems->At(aIndex);
       
   127         }
       
   128     else
       
   129         {
       
   130         return NULL;
       
   131         }
       
   132     }
       
   133 
       
   134 
       
   135 // Get next item in animation sequence. Returns NULL at the end of the
       
   136 // sequence (or if there are no items at all), and wraps around to the
       
   137 // beginning, so that next call again returns an item.
       
   138 CBmpAnimItem* CBmpAnimModel::NextItem(TBool& aWrapped)
       
   139     {
       
   140     CBmpAnimItem* pItem = ItemAt(iCurrentItem++);
       
   141 
       
   142     if (pItem)
       
   143         {
       
   144         aWrapped = EFalse;
       
   145         }
       
   146     else
       
   147         {
       
   148         // Apparently there are no more items - wrap around and set indicator
       
   149         iCurrentItem = 0;
       
   150         aWrapped = ETrue;
       
   151 
       
   152         pItem = ItemAt(iCurrentItem++);
       
   153         }
       
   154 
       
   155     return pItem;
       
   156     }
       
   157 
       
   158     
       
   159 // Reserve space for <aCount> Items
       
   160 void CBmpAnimModel::SetReserveL(TInt aCount)
       
   161     {
       
   162     if ((iItems) && (aCount >= NumberOfItems()))
       
   163         {
       
   164         iItems->SetReserveL(aCount);
       
   165         }
       
   166     }
       
   167 
       
   168     
       
   169 // --- private functions ---
       
   170 //  End of File