uifw/AvKon/src/AknSmileyModel.cpp
branchRCL_3
changeset 55 aecbbf00d063
parent 51 fcdfafb36fe7
child 56 d48ab3b357f1
equal deleted inserted replaced
51:fcdfafb36fe7 55:aecbbf00d063
    13 *
    13 *
    14 * Description: 
    14 * Description: 
    15 *
    15 *
    16 */
    16 */
    17 
    17 
       
    18 
    18 #include <barsread.h>
    19 #include <barsread.h>
    19 #include <AknUtils.h>
    20 #include <AknUtils.h>
    20 #include <aknlayoutscalable_avkon.cdl.h>
    21 #include <aknlayoutscalable_avkon.cdl.h>
    21 
    22 
    22 #include <centralrepository.h>
    23 #include <centralrepository.h>
    23 #include <AvkonInternalCRKeys.h>
    24 #include <AvkonInternalCRKeys.h>
    24 
    25 
    25 #include <AknBidiTextUtils.h>
       
    26 #include <AknPanic.h>
       
    27 
       
    28 #include <smiley.rsg>
    26 #include <smiley.rsg>
    29 #include <smiley.mbg>
    27 #include <smiley.mbg>
    30 
    28 
    31 #include "AknSmileyModel.h"
    29 #include "AknSmileyModel.h"
    32 #include "AknSmileyImage.h"
    30 #include "AknSmileyImage.h"
    33 #include "akntrace.h"
    31 
    34 
    32 
    35 ///////////////////////////////////////////////////////////////////////////////////////////////
    33 ///////////////////////////////////////////////////////////////////////////////////////////////
    36 // TSmileyIconInfo
    34 // TSmileyIconInfo
    37 ///////////////////////////////////////////////////////////////////////////////////////////////
    35 ///////////////////////////////////////////////////////////////////////////////////////////////
    38 
    36 
    40     {
    38     {
    41     Reset();
    39     Reset();
    42     }
    40     }
    43 
    41 
    44 TSmileyIconInfo::TSmileyIconInfo(const TSmileyIconInfo& aInfo) : 
    42 TSmileyIconInfo::TSmileyIconInfo(const TSmileyIconInfo& aInfo) : 
       
    43 iName(aInfo.iName), 
       
    44 iId(aInfo.iId), 
    45 iSkinItemID(aInfo.iSkinItemID), 
    45 iSkinItemID(aInfo.iSkinItemID), 
    46 iDefaultStillImageID(aInfo.iDefaultStillImageID), 
    46 iDefaultThumbnailID(aInfo.iDefaultThumbnailID), 
    47 iDefaultAnimationImageID(aInfo.iDefaultAnimationImageID)
    47 iDefaultAnimationID(aInfo.iDefaultAnimationID)
    48     {
    48     {
    49     }
    49     }
    50 
    50 
    51 void TSmileyIconInfo::Reset()
    51 void TSmileyIconInfo::Reset()
    52     {
    52     {
       
    53     iName.Zero();
       
    54     iId = 0;
    53     iSkinItemID.Set(0, 0);
    55     iSkinItemID.Set(0, 0);
    54     iDefaultStillImageID = 0;
    56     iDefaultThumbnailID = 0;
    55     iDefaultAnimationImageID = 0;
    57     iDefaultAnimationID = 0;
    56     }
    58     }
    57 
    59 
    58 
    60 
    59 
    61 
    60 ///////////////////////////////////////////////////////////////////////////////////////////////
    62 ///////////////////////////////////////////////////////////////////////////////////////////////
    61 // CSmileyIcon
    63 // CSmileyIcon
    62 ///////////////////////////////////////////////////////////////////////////////////////////////
    64 ///////////////////////////////////////////////////////////////////////////////////////////////
    63 
    65 
    64 CSmileyIcon* CSmileyIcon::NewL(const TSmileyIconInfo& aInfo, MAknSmileyObserver* aObserver)
    66 CSmileyIcon* CSmileyIcon::NewL(const TSmileyIconInfo& aInfo, MSmileyIconObserver* aObserver)
    65     {
    67     {
    66     CSmileyIcon* self = new (ELeave) CSmileyIcon(aObserver);
    68     CSmileyIcon* self = new (ELeave) CSmileyIcon(aInfo, aObserver);
    67     CleanupStack::PushL(self);
    69     CleanupStack::PushL(self);
    68     self->ConstructL(aInfo);
    70     self->ConstructL();
    69     CleanupStack::Pop(); // self;
    71     CleanupStack::Pop(); // self;
    70     return self;
    72     return self;
    71     }
    73     }
    72 
    74 
    73 void CSmileyIcon::ConstructL(const TSmileyIconInfo& aInfo)
    75 void CSmileyIcon::ConstructL()
    74     {
    76     {
    75     iIndex = aInfo.iIndex;
    77     iThumbnailImage = CSmileyImage::NewL(iInfo.iSkinItemID, iInfo.iDefaultThumbnailID, FALSE, this);
    76     
    78     
    77     iStillImage = CSmileyImage::NewL(aInfo.iSkinItemID, aInfo.iDefaultStillImageID, EFalse, this);
    79     if(iInfo.iSkinItemID.iMinor==0 && iInfo.iDefaultAnimationID>0)
    78     
    80         {
    79     if(aInfo.iSkinItemID.iMinor==0 && aInfo.iDefaultAnimationImageID>0)
    81         iAnimationImage = CSmileyImage::NewL(iInfo.iSkinItemID, iInfo.iDefaultAnimationID, TRUE, this);
    80         {
    82         }
    81         TAknsItemID nullID;
    83     }
    82         nullID.Set(0, 0);
    84 
    83         iAnimationImage = CSmileyImage::NewL(nullID, aInfo.iDefaultAnimationImageID, ETrue, this);
    85 CSmileyIcon::CSmileyIcon(const TSmileyIconInfo& aInfo, MSmileyIconObserver* aObserver) : 
    84         }
    86 iInfo(aInfo), iSmileyIconObserver(aObserver)
    85     }
       
    86 
       
    87 CSmileyIcon::CSmileyIcon(MAknSmileyObserver* aObserver) : iSmileyIconObserver(aObserver)
       
    88     {
    87     {
    89     }
    88     }
    90 
    89 
    91 CSmileyIcon::~CSmileyIcon()
    90 CSmileyIcon::~CSmileyIcon()
    92     {
    91     {
    93     delete iStillImage;
    92     delete iThumbnailImage;
    94     delete iAnimationImage;
    93     delete iAnimationImage;
    95     
    94     }
    96     iTextArray.Close();
    95 
    97     iCodeArray.Close();
    96 TBool CSmileyIcon::ReadyToDraw() const
       
    97     {
       
    98     TBool thumbnailCanDraw = iThumbnailImage->ReadyToDraw();
       
    99     TBool animationCanDraw = iAnimationImage ? iAnimationImage->ReadyToDraw() : FALSE;
       
   100     
       
   101     return (thumbnailCanDraw || animationCanDraw);
    98     }
   102     }
    99 
   103 
   100 const CFbsBitmap* CSmileyIcon::Image() const
   104 const CFbsBitmap* CSmileyIcon::Image() const
   101     {
   105     {
   102     if(AnimationImageIsReadyToDraw())
   106     if(ShouldShowAnimation())
   103         {
   107         {
   104         return iAnimationImage->Image();
   108         return iAnimationImage->Image();
   105         }
   109         }
   106     else
   110     else
   107         {
   111         {
   108         return iStillImage->Image();
   112         return iThumbnailImage->Image();
   109         }
   113         }
   110     }
   114     }
   111 
   115 
   112 const CFbsBitmap* CSmileyIcon::Mask() const
   116 const CFbsBitmap* CSmileyIcon::Mask() const
   113     {
   117     {
   114     if(AnimationImageIsReadyToDraw())
   118     if(ShouldShowAnimation())
   115         {
   119         {
   116         return iAnimationImage->Mask();
   120         return iAnimationImage->Mask();
   117         }
   121         }
   118     else
   122     else
   119         {
   123         {
   120         return iStillImage->Mask();
   124         return iThumbnailImage->Mask();
   121         }
   125         }
   122     }
   126     }
   123 
   127 
   124 TBool CSmileyIcon::ReadyToDraw() const
   128 void CSmileyIcon::LoadThumbnailL()
   125     {
   129     {
   126     return StillImageIsReadyToDraw() || AnimationImageIsReadyToDraw();
   130     iThumbnailImage->LoadL();
       
   131     }
       
   132 
       
   133 TBool CSmileyIcon::ThumbnailReady() const
       
   134     {
       
   135     return iThumbnailImage->ReadyToDraw();
       
   136     }
       
   137 
       
   138 void CSmileyIcon::PlayAnimationL(TInt aRepeat, TInt aDelay)
       
   139     {
       
   140     if(iAnimationImage)
       
   141         {
       
   142         iAnimationImage->LoadL(aRepeat, aDelay);
       
   143         }
       
   144     }
       
   145 
       
   146 void CSmileyIcon::StopAnimation()
       
   147     {
       
   148     if(iAnimationImage)
       
   149         {
       
   150         iAnimationImage->Release();
       
   151         }
   127     }
   152     }
   128 
   153 
   129 void CSmileyIcon::SetSize(const TSize& aSize)
   154 void CSmileyIcon::SetSize(const TSize& aSize)
   130     {
   155     {
   131     iStillImage->SetSize(aSize);
   156     iThumbnailImage->SetSize(aSize);
   132     
   157     
   133     if(iAnimationImage)
   158     if(iAnimationImage)
   134         {
   159         {
   135         iAnimationImage->SetSize(aSize);
   160         iAnimationImage->SetSize(aSize);
   136         }
   161         }
   137     }
   162     }
   138 
   163 
   139 const TSize& CSmileyIcon::Size() const
   164 const TSize& CSmileyIcon::Size() const
   140     {
   165     {
   141     return iStillImage->Size();
   166     return iThumbnailImage->Size();
   142     }
       
   143 
       
   144 void CSmileyIcon::PlayAnimationL(TInt aRepeat, TInt aDelay)
       
   145     {
       
   146     if(iAnimationImage)
       
   147         {
       
   148         iAnimationImage->LoadL(aRepeat, aDelay);
       
   149         }
       
   150     }
       
   151 
       
   152 void CSmileyIcon::StopAnimation()
       
   153     {
       
   154     if(iAnimationImage)
       
   155         {
       
   156         iAnimationImage->Release();
       
   157         }
       
   158     }
   167     }
   159 
   168 
   160 void CSmileyIcon::BitmapChanged(CSmileyImage* aSmileyImage, CFbsBitmap* /*aBitmap*/)
   169 void CSmileyIcon::BitmapChanged(CSmileyImage* aSmileyImage, CFbsBitmap* /*aBitmap*/)
   161     {
   170     {
   162     if(aSmileyImage == iStillImage)
   171     if(aSmileyImage == iThumbnailImage)
   163         {
   172         {
   164         if(iSmileyIconObserver) iSmileyIconObserver->SmileyStillImageLoaded(this);
   173         if(iSmileyIconObserver) iSmileyIconObserver->ThumbnailLoaded(this);
   165         }
   174         }
   166     else
   175     else
   167         {
   176         {
   168         if(iSmileyIconObserver) iSmileyIconObserver->SmileyAnimationChanged(this);
   177         if(iSmileyIconObserver) iSmileyIconObserver->AnimationChanged(this);
   169         }
   178         }
   170     }
   179     }
   171 
   180 
   172 TInt CSmileyIcon::Index() const
   181 TBool CSmileyIcon::ShouldShowAnimation() const
   173     {
       
   174     return iIndex;
       
   175     }
       
   176 
       
   177 void CSmileyIcon::LoadStillImageL(TInt aDelay)
       
   178     {
       
   179     iStillImage->LoadL(0, aDelay);
       
   180     }
       
   181 
       
   182 TBool CSmileyIcon::StillImageIsReadyToDraw() const
       
   183     {
       
   184     return iStillImage->ReadyToDraw();
       
   185     }
       
   186 
       
   187 TBool CSmileyIcon::AnimationImageIsReadyToDraw() const
       
   188     {
   182     {
   189     return (iAnimationImage && iAnimationImage->ReadyToDraw());
   183     return (iAnimationImage && iAnimationImage->ReadyToDraw());
   190     }
   184     }
   191 
   185 
   192 void CSmileyIcon::AddVariant(const TDesC& aText, TChar aBaseCode)
       
   193     {
       
   194     TPtrC ptr(aText);
       
   195     TUint16 baseCode = aBaseCode;
       
   196 
       
   197     while(ptr.Length())
       
   198         {
       
   199         TInt left = ptr.Find(_L(" "));
       
   200         TInt right = ptr.Length() - left - 1;
       
   201         if(left == KErrNotFound)
       
   202             {
       
   203             left = ptr.Length();
       
   204             right = 0;
       
   205             }
       
   206 
       
   207         iTextArray.Append(ptr.Left(left));
       
   208         ptr.Set(ptr.Right(right));
       
   209         iCodeArray.Append(baseCode++);
       
   210         }
       
   211     }
       
   212 
       
   213 TInt CSmileyIcon::VariantCount() const
       
   214     {
       
   215     return iTextArray.Count();
       
   216     }
       
   217 const TDesC& CSmileyIcon::Text(TInt aVariant) const
       
   218     {
       
   219     if(aVariant>=0 && aVariant<VariantCount())
       
   220         {
       
   221         return iTextArray[aVariant];
       
   222         }
       
   223     else
       
   224         {
       
   225         return KNullDesC;
       
   226         }
       
   227     }
       
   228 
       
   229 TChar CSmileyIcon::Code(TInt aVariant) const
       
   230     {
       
   231     if(aVariant>=0 && aVariant<VariantCount())
       
   232         {
       
   233         return iCodeArray[aVariant];
       
   234     }
       
   235     else
       
   236         {
       
   237         return 0;
       
   238         }
       
   239     }
       
   240 
   186 
   241 
   187 
   242 ///////////////////////////////////////////////////////////////////////////////////////////////
   188 ///////////////////////////////////////////////////////////////////////////////////////////////
   243 // CSmileyTnumbnailAsynLoader
   189 // CSmileyTnumbnailAsynLoader
   244 ///////////////////////////////////////////////////////////////////////////////////////////////
   190 ///////////////////////////////////////////////////////////////////////////////////////////////
   248     
   194     
   249     }
   195     }
   250 
   196 
   251 CSmileyTnumbnailAsynLoader::~CSmileyTnumbnailAsynLoader()
   197 CSmileyTnumbnailAsynLoader::~CSmileyTnumbnailAsynLoader()
   252     {
   198     {
   253     iLoadingTaskArray.Close();
   199     iTaskArray.Close();
   254     }
   200     }
   255 
   201 
   256 void CSmileyTnumbnailAsynLoader::AddTaskL(CSmileyIcon* aSmileyIcon)
   202 void CSmileyTnumbnailAsynLoader::AddTaskL(CSmileyIcon* aSmileyIcon)
   257     {
   203     {
   258     if(aSmileyIcon)
   204     if(aSmileyIcon)
   259         {
   205         {
   260         TBool isIdel = (TaskCount() == 0);
   206         iTaskArray.Append(aSmileyIcon);
   261         iLoadingTaskArray.Append(aSmileyIcon);
   207         if(!iIsLoading)
   262         if(isIdel)
       
   263             {
   208             {
   264             DoNextTaskL();
   209             DoNextTaskL();
   265             }
   210             }
   266         }
   211         }
   267     }
   212     }
   268 
   213 
   269 void CSmileyTnumbnailAsynLoader::DiscardAll()
   214 void CSmileyTnumbnailAsynLoader::DiscardAll()
   270     {
   215     {
   271     iLoadingTaskArray.Reset();
   216     iTaskArray.Reset();
   272     }
   217     }
   273 
   218 
   274 TInt CSmileyTnumbnailAsynLoader::TaskCount() const
   219 TInt CSmileyTnumbnailAsynLoader::TaskCount() const
   275     {
   220     {
   276     return iLoadingTaskArray.Count();
   221     return iTaskArray.Count();
   277     }
   222     }
   278 
   223 
   279 void CSmileyTnumbnailAsynLoader::DoNextTaskL()
   224 void CSmileyTnumbnailAsynLoader::DoNextTaskL()
   280     {
   225     {
   281     if(TaskCount() > 0)
   226     TInt count = TaskCount();
   282         {
   227     if(count > 0)
   283         CSmileyIcon* icon = iLoadingTaskArray[0];
   228         {
   284         iLoadingTaskArray.Remove(0);
   229         CSmileyIcon* icon = iTaskArray[0];
   285         
   230         iTaskArray.Remove(0);
   286         if(icon->StillImageIsReadyToDraw())
   231         
       
   232         if(icon->ThumbnailReady())
   287             {
   233             {
   288             DoNextTaskL();
   234             DoNextTaskL();
   289             }
   235             }
   290         else
   236         else
   291             {
   237             {
   292             icon->LoadStillImageL();
   238             icon->LoadThumbnailL();
   293             }
   239             iIsLoading = TRUE;
   294         }
   240             }
   295     }
   241         }
   296 
   242     else
   297 
   243         {
   298 
   244         iIsLoading = FALSE;
   299 ///////////////////////////////////////////////////////////////////////////////////////////////
   245         }
   300 // CSmileyTextTreeNode
       
   301 ///////////////////////////////////////////////////////////////////////////////////////////////
       
   302 
       
   303 NONSHARABLE_CLASS(CSmileyTextTreeNode) : public CBase
       
   304     {
       
   305 public:
       
   306     CSmileyTextTreeNode(TChar aChar);
       
   307     ~CSmileyTextTreeNode();
       
   308 
       
   309     TChar Char() const;
       
   310 
       
   311     CSmileyTextTreeNode* AddTreeL(const TDesC& aText, TChar aCode);
       
   312     TInt ChildCount() const;
       
   313     CSmileyTextTreeNode* Child(TInt aIndex) const;
       
   314     CSmileyTextTreeNode* Child(TChar aChar) const;
       
   315     
       
   316 private:
       
   317     CSmileyTextTreeNode* AddChildAscendingL(TChar aChar);
       
   318     
       
   319 private:
       
   320     TChar   iChar;
       
   321     
       
   322     typedef CArrayPtrFlat<CSmileyTextTreeNode> CSmileyTextTreeNodeArrayPtrFlat;
       
   323     CSmileyTextTreeNodeArrayPtrFlat* iChildArray;
       
   324     
       
   325     };
       
   326 
       
   327 
       
   328 CSmileyTextTreeNode::CSmileyTextTreeNode(TChar aChar) : iChar(aChar)
       
   329     {
       
   330     }
       
   331 
       
   332 CSmileyTextTreeNode::~CSmileyTextTreeNode()
       
   333     {
       
   334     if(iChildArray)
       
   335         {
       
   336         iChildArray->ResetAndDestroy();
       
   337         delete iChildArray;
       
   338         }
       
   339     }
       
   340 
       
   341 TChar CSmileyTextTreeNode::Char() const
       
   342     {
       
   343     return iChar;
       
   344     }
       
   345 
       
   346 
       
   347 
       
   348 CSmileyTextTreeNode* CSmileyTextTreeNode::AddTreeL(const TDesC& aText, TChar aCode)
       
   349     {
       
   350     TInt length = aText.Length();
       
   351     if(length > 0)
       
   352         {
       
   353         CSmileyTextTreeNode* node = AddChildAscendingL(aText[0]);
       
   354         return node->AddTreeL(aText.Right(length-1), aCode);
       
   355         }
       
   356     else
       
   357         {
       
   358         return AddChildAscendingL(aCode);
       
   359         }
       
   360     }
       
   361 
       
   362 TInt CSmileyTextTreeNode::ChildCount() const
       
   363     {
       
   364     if(iChildArray)
       
   365         {
       
   366         return iChildArray->Count();
       
   367         }
       
   368     else
       
   369         {
       
   370         return 0;
       
   371         }
       
   372     }
       
   373 
       
   374 CSmileyTextTreeNode* CSmileyTextTreeNode::Child(TInt aIndex) const
       
   375     {
       
   376     if(aIndex>=0 && aIndex<ChildCount())
       
   377         {
       
   378         return iChildArray->At(aIndex);
       
   379         }
       
   380     else
       
   381         {
       
   382         return NULL;
       
   383         }
       
   384     }
       
   385 
       
   386 CSmileyTextTreeNode* CSmileyTextTreeNode::Child(TChar aChar) const
       
   387     {
       
   388     if(iChildArray)
       
   389         {
       
   390         const TInt KFirstPos = 0;
       
   391         const TInt KEndPos = iChildArray->Count() - 1;
       
   392         if(aChar<iChildArray->At(KFirstPos)->Char() || aChar>iChildArray->At(KEndPos)->Char())
       
   393             {
       
   394             return NULL;
       
   395             }
       
   396         for(TInt i=KEndPos; i>=KFirstPos; i--)
       
   397             {
       
   398             CSmileyTextTreeNode* node = iChildArray->At(i);
       
   399             if(node->Char() == aChar)
       
   400                 {
       
   401                 return node;
       
   402                 }
       
   403             }
       
   404         }
       
   405     
       
   406     return NULL;
       
   407     }
       
   408 
       
   409 CSmileyTextTreeNode* CSmileyTextTreeNode::AddChildAscendingL(TChar aChar)
       
   410     {
       
   411     // new
       
   412     if(!iChildArray)
       
   413         {
       
   414         iChildArray = new (ELeave) CSmileyTextTreeNodeArrayPtrFlat(1);
       
   415         }
       
   416     
       
   417     // sequential search
       
   418     TInt pos = 0;
       
   419     for(; pos<iChildArray->Count(); pos++)
       
   420         {
       
   421         CSmileyTextTreeNode* node = iChildArray->At(pos);
       
   422         TChar character = node->Char();
       
   423         if(aChar == character)
       
   424             {
       
   425             return node;
       
   426             }
       
   427         else if(aChar < character)
       
   428             {
       
   429             break;
       
   430             }
       
   431         }
       
   432     
       
   433     CSmileyTextTreeNode* node = new (ELeave) CSmileyTextTreeNode(aChar);
       
   434     iChildArray->InsertL(pos, node);
       
   435     return node;
       
   436     }
   246     }
   437 
   247 
   438 
   248 
   439 
   249 
   440 ///////////////////////////////////////////////////////////////////////////////////////////////
   250 ///////////////////////////////////////////////////////////////////////////////////////////////
   441 // CSmileyModel
   251 // CSmileyModel
   442 ///////////////////////////////////////////////////////////////////////////////////////////////
   252 ///////////////////////////////////////////////////////////////////////////////////////////////
   443 
   253 
   444 const TUint16 KBaseCode = 0xf880;
   254 CSmileyModel::CSmileyModel(MSmileyIconObserver* aObserver) : iSmileyIconObserver(aObserver)
   445 //const TUint16 KBaseCodeOff = 0x7FFF;
       
   446 _LIT(KPlaceHolder, "\xf880i");
       
   447 
       
   448 CSmileyModel::CSmileyModel(MAknSmileyObserver* aObserver) : iSmileyIconObserver(aObserver)
       
   449     {
   255     {
   450     }
   256     }
   451 
   257 
   452 CSmileyModel::~CSmileyModel()
   258 CSmileyModel::~CSmileyModel()
   453     {
   259     {
   454     ReleaseResource();
   260     ReleaseResource();
   455     
   261     
   456     iSmileyIconArray.Close();
   262     iSmileyIconArray.Close();
   457     iSmileyCodeIndexArray.Close();
       
   458     }
   263     }
   459 
   264 
   460 void CSmileyModel::LoadResourceL()
   265 void CSmileyModel::LoadResourceL()
   461     {
   266     {
   462     if(Count() > 0) return;
   267     if(Count() > 0) return;
       
   268     
       
   269     // append sct & smiley switch icon
       
   270         {
       
   271         TSmileyIconInfo info;
       
   272         info.iSkinItemID = KAknsIIDQgnIndiSwitchSmiley2;
       
   273         info.iDefaultThumbnailID = EMbmSmileyQgn_indi_switch_smiley2;
       
   274         iSmileyIconArray.Append(CSmileyIcon::NewL(info, this));
       
   275         
       
   276         info.iSkinItemID = KAknsIIDQgnIndiSwitchSct2;
       
   277         info.iDefaultThumbnailID = EMbmSmileyQgn_indi_switch_sct2;
       
   278         iSmileyIconArray.Append(CSmileyIcon::NewL(info, this));
       
   279         }
   463 
   280 
   464     // append image resourece
   281     // append image resourece
   465     TResourceReader reader;
   282     TResourceReader reader;
   466     TFileName smileyRscName;
   283     TFileName smileyRscName;
   467     SmileyUtils::GetCustomizableResPath(smileyRscName, KSmileyRsc);
   284     SmileyUtils::GetCustomizableResPath(smileyRscName, KSmileyRsc);
   468     TInt offset = CCoeEnv::Static()->AddResourceFileL(smileyRscName);
   285     TInt offset = CCoeEnv::Static()->AddResourceFileL(smileyRscName);
   469     CCoeEnv::Static()->CreateResourceReaderLC(reader, R_SMILEY_ICONS_INFO);
   286     CCoeEnv::Static()->CreateResourceReaderLC(reader, R_SMILEY_ICONS_INFO);
   470 
   287 
   471     TUint16 codeRef = KBaseCode;
       
   472     TInt index = 0;
       
   473     
       
   474     iTextSearchTree = new (ELeave) CSmileyTextTreeNode(0);
       
   475     
       
   476     TInt count(reader.ReadInt16());
   288     TInt count(reader.ReadInt16());
   477     for(TInt i(0); i<count; i++)
   289     for(TInt id(1); id<=count; id++)
   478         {
   290         {
   479         TSmileyIconInfo info;
   291         TSmileyIconInfo info;
   480 
   292         
       
   293         info.iId = id; // id
       
   294         
   481         TBool isAnimation = (reader.ReadInt16() == 1);
   295         TBool isAnimation = (reader.ReadInt16() == 1);
   482         TInt16 code = reader.ReadInt16();
   296         TInt16 code = reader.ReadInt16();
   483         TInt bmpId1 = reader.ReadInt32();
   297         TInt bmpId1 = reader.ReadInt32();
   484         TInt maskId1 = reader.ReadInt32();
   298         TInt maskId1 = reader.ReadInt32();
   485         TInt bmpId2 = reader.ReadInt32();
   299         TInt bmpId2 = reader.ReadInt32();
   486         TInt maskId2 = reader.ReadInt32();
   300         TInt maskId2 = reader.ReadInt32();
   487         
   301         
   488         
       
   489         info.iIndex = index++;
       
   490 
       
   491         if(bmpId2 > 0)
   302         if(bmpId2 > 0)
   492             {
   303             {
   493             info.iDefaultStillImageID = bmpId2;
   304             info.iDefaultThumbnailID = bmpId2;
   494             info.iDefaultAnimationImageID = bmpId1;
   305             info.iDefaultAnimationID = bmpId1;
   495             }
   306             }
   496         else
   307         else
   497             {
   308             {
   498             info.iDefaultStillImageID = bmpId1;
   309             info.iDefaultThumbnailID = bmpId1;
   499             info.iDefaultAnimationImageID = 0;
   310             info.iDefaultAnimationID = 0;
   500             }
   311             }
   501 
   312 
   502         TBuf<64> smileyName = reader.ReadTPtrC(); // strings
   313         TBuf<64> smileyName = reader.ReadTPtrC(); // strings
   503         
   314         TInt pos = smileyName.Find(_L(" "));
   504         CSmileyIcon* icon = CSmileyIcon::NewL(info, this);
   315         if(pos > 0) smileyName.SetLength(pos);
   505         icon->AddVariant(smileyName, codeRef);
   316         info.iName = smileyName;
   506         iSmileyIconArray.Append(icon);
   317 
   507         
   318         iSmileyIconArray.Append(CSmileyIcon::NewL(info, this));
   508         // build text search tree
       
   509         for(TInt j=0; j<icon->VariantCount(); j++)
       
   510             {
       
   511             iTextSearchTree->AddTreeL(icon->Text(j), codeRef++);
       
   512             iSmileyCodeIndexArray.Append(TSmileyCodeIndex(icon,j));
       
   513             }
       
   514         }
   319         }
   515     
   320     
   516     CCoeEnv::Static()->DeleteResourceFile(offset);
   321     CCoeEnv::Static()->DeleteResourceFile(offset);
   517     CleanupStack::PopAndDestroy(); // reader
   322     CleanupStack::PopAndDestroy(); // reader
   518     
       
   519     // sct & smiley switch icon
       
   520     TSmileyIconInfo info;
       
   521     info.iIndex = index++;
       
   522     info.iSkinItemID = KAknsIIDQgnIndiSwitchSmiley2;
       
   523     info.iDefaultStillImageID = EMbmSmileyQgn_indi_switch_smiley2;
       
   524     CSmileyIcon* switchSmileyIcon = CSmileyIcon::NewL(info, this);
       
   525     iSmileyIconArray.Append(switchSmileyIcon);
       
   526     iSmileyCodeIndexArray.Append(TSmileyCodeIndex(switchSmileyIcon));
       
   527 
       
   528     info.iIndex = index++;
       
   529     info.iSkinItemID = KAknsIIDQgnIndiSwitchSct2;
       
   530     info.iDefaultStillImageID = EMbmSmileyQgn_indi_switch_sct2;
       
   531     CSmileyIcon* switchSctIcon = CSmileyIcon::NewL(info,this);
       
   532     iSmileyIconArray.Append(switchSctIcon);
       
   533     iSmileyCodeIndexArray.Append(TSmileyCodeIndex(switchSctIcon));
       
   534 
   323 
   535     }
   324     }
   536 
   325 
   537 void CSmileyModel::ReleaseResource()
   326 void CSmileyModel::ReleaseResource()
   538     {
   327     {
   539     if(Count() == 0) return;
       
   540 
       
   541     // reset array
   328     // reset array
   542     for(TInt i(0); i<ArrayCount(); i++)
   329     for(TInt i(0); i<Count(); i++)
   543         {
   330         {
   544         delete iSmileyIconArray[i];
   331         delete iSmileyIconArray[i];
   545         iSmileyIconArray[i] = NULL;
   332         iSmileyIconArray[i] = NULL;
   546         }
   333         }
   547     iSmileyIconArray.Reset();
   334     iSmileyIconArray.Reset();
   548     
   335     
   549     iSmileyCodeIndexArray.Reset();
       
   550     // reset task loader
   336     // reset task loader
   551     iSmileyLoader.DiscardAll();
   337     iSmileyThumbnailLoader.DiscardAll();
   552     
   338     }
   553     delete iTextSearchTree;
   339 
   554     iTextSearchTree = NULL;
   340 void CSmileyModel::LoadThumbnailAsyn(TInt aIndex)
   555     
   341     {
   556     }
   342     TRAP_IGNORE(iSmileyThumbnailLoader.AddTaskL((*this)[aIndex]));
   557 
       
   558 TInt CSmileyModel::ConvertCodesToTextL(TDes& aText)
       
   559     {
       
   560     TInt converted = 0;
       
   561     iConvertBuffer.Zero();
       
   562     
       
   563     // deal all
       
   564     TInt pos = 0;
       
   565     while(pos < aText.Length())
       
   566         {
       
   567         TChar character = aText[pos++];
       
   568         if(IsSmiley(character))
       
   569             {
       
   570             converted++;
       
   571             pos++; // jump the 'i'
       
   572             iConvertBuffer.Append(Text(character));
       
   573             }
       
   574         else
       
   575             {
       
   576             iConvertBuffer.Append(character);
       
   577             }
       
   578         }
       
   579     
       
   580     // replace
       
   581     if(converted)
       
   582         {
       
   583         aText.Copy(iConvertBuffer);
       
   584         }
       
   585 
       
   586     return converted;
       
   587     }
       
   588 
       
   589 TInt CSmileyModel::ConvertTextToCodesL(TDes& aText)
       
   590     {
       
   591     _AKNTRACE_FUNC_ENTER;
       
   592     TInt converted = 0;
       
   593     iConvertBuffer.Zero();
       
   594 
       
   595     CSmileyTextTreeNode* node = iTextSearchTree;
       
   596     TInt matchedLength = 0;
       
   597 
       
   598     // deal all
       
   599     TInt pos = 0;
       
   600     while(pos < aText.Length())
       
   601         {
       
   602         TChar character = aText[pos++];
       
   603         iConvertBuffer.Append(character);
       
   604 
       
   605             CSmileyTextTreeNode* find = node->Child(character);
       
   606             if(find)
       
   607                 {
       
   608                 matchedLength++; // character is mathed
       
   609                 
       
   610                 CSmileyTextTreeNode* child = find->Child(0);
       
   611             TBool notFinished = (child && child->ChildCount());
       
   612             if(notFinished) // not ended
       
   613                     {
       
   614                 node = find; // match next 
       
   615                 continue;
       
   616                 }
       
   617             else if(child) // whole combination is matched and ended
       
   618                 {
       
   619                     TChar code = child->Char();
       
   620 
       
   621                     // replace with code
       
   622                     iConvertBuffer.SetLength(iConvertBuffer.Length() - matchedLength);
       
   623                     iConvertBuffer.Append(code);
       
   624                     iConvertBuffer.Append('i');
       
   625                 converted++; // returned value added
       
   626                     // load thumnail
       
   627                     LoadStillImageL(code);
       
   628 
       
   629                     // restart
       
   630                     matchedLength = 0;
       
   631                     node = iTextSearchTree;
       
   632                 continue;
       
   633                     }
       
   634             else // in this case matchedLength already increased by 1
       
   635                 {
       
   636                 matchedLength--;
       
   637                 }
       
   638             }
       
   639         
       
   640         // matching failed
       
   641         if(matchedLength)
       
   642             {
       
   643             // back to the 2nd char
       
   644             TInt rollBack = matchedLength;
       
   645             iConvertBuffer.SetLength(iConvertBuffer.Length() - rollBack);
       
   646             pos -= rollBack;
       
   647 
       
   648             // reset matching context
       
   649             matchedLength = 0;
       
   650             node = iTextSearchTree;
       
   651             }
       
   652         }
       
   653     
       
   654     // replace
       
   655     if(converted)
       
   656         {
       
   657         aText.Copy(iConvertBuffer);
       
   658         }
       
   659 
       
   660     _AKNTRACE_FUNC_EXIT;
       
   661     return converted;
       
   662     }
       
   663 
       
   664 TBool CSmileyModel::IsSmiley(TChar aCode) const
       
   665     {
       
   666     TInt smileyCodeIndex = (TUint16)aCode - KBaseCode;
       
   667     return (smileyCodeIndex>=0 && smileyCodeIndex<iSmileyCodeIndexArray.Count());
       
   668     }
       
   669 
       
   670 const TDesC& CSmileyModel::Text(TChar aCode) const
       
   671     {
       
   672     if(IsSmiley(aCode))
       
   673         {
       
   674         TInt smileyCodeIndex = (TUint16)aCode - KBaseCode;
       
   675         return iSmileyCodeIndexArray[smileyCodeIndex].Text();
       
   676         }
       
   677     else
       
   678         {
       
   679         return KNullDesC;
       
   680         }
       
   681     }
   343     }
   682 
   344 
   683 void CSmileyModel::SetSize(const TSize& aSize)
   345 void CSmileyModel::SetSize(const TSize& aSize)
   684     {
   346     {
   685     if(ArrayCount() && iSmileyIconArray[0]->Size()!=aSize)
   347     for(TInt i(0); i<Count(); i++)
   686         {
   348         {
   687         for(TInt i(0); i<ArrayCount(); i++)
   349         iSmileyIconArray[i]->SetSize(aSize);
   688             {
   350         }
   689             iSmileyIconArray[i]->SetSize(aSize);
   351     }
   690             }
   352 
   691         }
   353 CSmileyIcon* CSmileyModel::operator[](TInt aIndex) const
   692     }
   354     {
   693 
   355     if(aIndex>=0 && aIndex<Count())
   694 void CSmileyModel::SetSizeByFont(const CFont* aFont)
   356         {
   695     {
   357         return iSmileyIconArray[aIndex];
   696     TSize size(aFont->TextWidthInPixels(KPlaceHolder),aFont->HeightInPixels());
       
   697     SetSize(size);
       
   698     }
       
   699 
       
   700 void CSmileyModel::DrawText(CWindowGc& aGc, const TDesC& aText, const CFont* aFont, const TPoint& aPosition) const
       
   701     {
       
   702     TPtrC ptr = aText;
       
   703     TPoint pos = aPosition;
       
   704     
       
   705     aGc.UseFont(aFont);
       
   706     
       
   707     TBool metSmileyNotReady = EFalse;
       
   708  
       
   709     while(ptr.Length())
       
   710         {
       
   711         TInt i = 0;
       
   712         for(; i<ptr.Length(); i++) // find next smiley code
       
   713             {
       
   714             if(IsSmiley(ptr[i]))
       
   715                 {
       
   716                 break;
       
   717                 }
       
   718             }
       
   719         
       
   720         if(i > 0) // have text
       
   721             {
       
   722             TPtrC txt = ptr.Left(i);
       
   723             aGc.DrawText(txt, pos);
       
   724             pos += TPoint(aFont->TextWidthInPixels(txt),0);
       
   725 
       
   726             ptr.Set(ptr.Right(ptr.Length()-i));
       
   727             i = 0;
       
   728             }
       
   729         
       
   730         if(ptr.Length()) // breaked by smiley code
       
   731             {
       
   732             CAknSmileyIcon* icon = Smiley(ptr[i]);
       
   733             if(icon)
       
   734                 {
       
   735                 TSize size = icon->Size();
       
   736                 TPoint tl = pos;
       
   737                 tl.iY = tl.iY - (size.iHeight + aFont->HeightInPixels()) / 2;
       
   738                 if(!metSmileyNotReady && icon->ReadyToDraw())
       
   739                     {
       
   740                     aGc.BitBltMasked(tl, icon->Image(), TRect(size), icon->Mask(), EFalse);
       
   741                     }
       
   742                 else
       
   743                     {
       
   744                     metSmileyNotReady = ETrue;
       
   745                     }
       
   746                 pos += TPoint(aFont->TextWidthInPixels(ptr.Left(2)),0);
       
   747                 }
       
   748             
       
   749             ptr.Set(ptr.Right(ptr.Length()-2));
       
   750             }
       
   751         }
       
   752     }
       
   753 
       
   754 void CSmileyModel::DrawText(CWindowGc& aGc, const TDesC& aText, const TAknLayoutText& aLayout, TBool aUseLogicalToVisualConversion) const
       
   755     {
       
   756     _AKNTRACE_FUNC_ENTER;
       
   757     // adapter variables
       
   758     const CFont* font = aLayout.Font();
       
   759     TRect textRect = aLayout.TextRect();
       
   760     TInt offset = aLayout.BaselineOffset();
       
   761     CGraphicsContext::TTextAlign align = aLayout.Align();
       
   762     
       
   763     // belows are all from 
       
   764     // void TAknLayoutText::DrawText(CGraphicsContext& aGc,const TDesC& aText,TBool aUseLogicalToVisualConversion, const TRgb &aColor) const
       
   765     
       
   766     __ASSERT_DEBUG(font, Panic(EAknPanicLayoutTextNotCalled));
       
   767     
       
   768     //aGc.UseFont( font );
       
   769     //aGc.SetPenColor( aColor );
       
   770     if ( aText.Length() )
       
   771         {
       
   772         HBufC* visualBuf = NULL;
       
   773         TPtrC text( aText );
       
   774         
       
   775         if ( aUseLogicalToVisualConversion )
       
   776             {
       
   777             visualBuf = HBufC::New( aText.Length() + KAknBidiExtraSpacePerLine );
       
   778             
       
   779             // In OOM, logical to visual conversion is not performed...
       
   780             
       
   781             if ( visualBuf )
       
   782                 {
       
   783                 *visualBuf = aText; // copy
       
   784                 TPtr ptr = visualBuf->Des();
       
   785                 
       
   786                 TInt maxWidth = textRect.Size().iWidth;
       
   787                 // Logical to visual conversion.
       
   788                 AknBidiTextUtils::ConvertToVisualAndClip(
       
   789                     aText,
       
   790                     ptr,
       
   791                     *font,
       
   792                     maxWidth,
       
   793                     maxWidth );
       
   794                 // for smiley begin
       
   795                 const TInt length = ptr.Length();
       
   796                 if(length>1 && IsSmiley(ptr[length-2]))
       
   797                     {
       
   798                     if(ptr[length-1] != 'i')
       
   799                         {
       
   800                         // smiley is clipped for visual, del this smiley
       
   801                         ptr.Delete(length-2, 1);
       
   802                         }
       
   803                     }
       
   804                 // for smiley end
       
   805 
       
   806                 text.Set( ptr );
       
   807                 }
       
   808             }
       
   809         
       
   810         // Calculate x-offset based on the used alignment
       
   811         TInt margin = 0;
       
   812         if ( align != CGraphicsContext::ELeft )
       
   813             {
       
   814             // Measure the full width of the text (ie. what DrawText needs)
       
   815             TInt textWidth = AknBidiTextUtils::MeasureTextBoundsWidth( *font, text,CFont::TMeasureTextInput::EFVisualOrder );
       
   816             
       
   817             const TInt extraWidth = textRect.Width() - textWidth;
       
   818             if ( align == CGraphicsContext::ECenter )
       
   819                 {
       
   820                 margin = extraWidth / 2;
       
   821                 }
       
   822             else // right aligned
       
   823                 {
       
   824                 margin = extraWidth;
       
   825                 }
       
   826             }
       
   827 
       
   828         // Need to make the drawing rectangle bigger to account for underlines
       
   829         TRect drawRect(textRect);
       
   830         TInt height = drawRect.Height();
       
   831         // The underline position is not available from the GC. The following code imitates what Symbian CFbsBitGC implements.
       
   832         // (height-offset) is the part below the baseline. Check if it sufficient
       
   833         TInt extraHeightForUnderlining =   1 + Max(1, height/10)-(height-offset);
       
   834         if ( extraHeightForUnderlining > 0 )
       
   835             drawRect.iBr.iY += extraHeightForUnderlining;
       
   836 
       
   837         // for smiley
       
   838         //aGc.DrawText( text, drawRect, offset, CGraphicsContext::ELeft, margin );
       
   839         DrawText(aGc, text, font, drawRect, offset, CGraphicsContext::ELeft, margin);
       
   840         
       
   841         delete visualBuf;
       
   842         }
       
   843     
       
   844     //aGc.DiscardFont(); // Release the font cache
       
   845     _AKNTRACE_FUNC_EXIT;
       
   846     }
       
   847 
       
   848 void CSmileyModel::DrawText(CWindowGc& aGc, const TDesC& aText, const CFont* aFont, const TRect& aBox, TInt aBaselineOffset, 
       
   849                             CGraphicsContext::TTextAlign aAlignment, TInt aLeftMargin) const
       
   850     {
       
   851     TInt boxWidth = aBox.Width();
       
   852     TInt textWidth = aFont->TextWidthInPixels(aText);
       
   853     
       
   854     TPoint offset;
       
   855     offset.iY = aBaselineOffset;
       
   856     
       
   857     switch(aAlignment)
       
   858         {
       
   859         case CGraphicsContext::ELeft:
       
   860             offset.iX = aLeftMargin;
       
   861             break;
       
   862             
       
   863         case CGraphicsContext::ERight:
       
   864             offset.iX = boxWidth - textWidth - aLeftMargin;
       
   865             break;
       
   866             
       
   867         case CGraphicsContext::ECenter:
       
   868             offset.iX = (boxWidth - textWidth) / 2;
       
   869             break;
       
   870             
       
   871         default:
       
   872             break;
       
   873         }
       
   874     
       
   875     DrawText(aGc, aText, aFont, aBox, offset);
       
   876     }
       
   877 
       
   878 void CSmileyModel::DrawText(CWindowGc& aGc, const TDesC& aText, const CFont* aFont, const TRect& aBox, const TPoint& aOffset) const
       
   879     {
       
   880     TPtrC ptr = aText;
       
   881     TPoint offset = aOffset;
       
   882     
       
   883     aGc.UseFont(aFont);
       
   884     
       
   885     TInt fontH = aFont->FontMaxHeight();
       
   886     
       
   887     TBool metSmileyNotReady = EFalse;
       
   888  
       
   889     while(ptr.Length())
       
   890         {
       
   891         TInt i = 0;
       
   892         for(; i<ptr.Length(); i++) // find next smiley code
       
   893             {
       
   894             if(IsSmiley(ptr[i]))
       
   895                 {
       
   896                 break;
       
   897                 }
       
   898             }
       
   899         
       
   900         if(i > 0) // have text
       
   901             {
       
   902             TPtrC txt = ptr.Left(i);
       
   903             aGc.DrawText(txt, aBox, offset.iY, CGraphicsContext::ELeft, offset.iX);
       
   904             offset.iX += aFont->TextWidthInPixels(txt);
       
   905 
       
   906             ptr.Set(ptr.Right(ptr.Length()-i));
       
   907             i = 0;
       
   908             }
       
   909         
       
   910         if(ptr.Length()) // breaked by smiley code
       
   911             {
       
   912             CAknSmileyIcon* icon = Smiley(ptr[i]);
       
   913             if(icon)
       
   914                 {
       
   915                 TSize size = icon->Size();
       
   916                 TPoint tl = aBox.iTl;
       
   917                 tl.iX += offset.iX;
       
   918                 //tl.iY = tl.iY - size.iHeight/*(size.iHeight + fontH) / 2*/;
       
   919                 TRect imgWindow(tl, size);
       
   920                 imgWindow.Intersection(aBox);
       
   921                 if(!imgWindow.IsEmpty())
       
   922                     {
       
   923                     TRect innerRect = TRect(imgWindow.iTl-tl,imgWindow.Size());
       
   924                     if(!metSmileyNotReady && icon->ReadyToDraw())
       
   925                         {
       
   926                         aGc.BitBltMasked(imgWindow.iTl, icon->Image(), innerRect, icon->Mask(), EFalse);
       
   927                         }
       
   928                     else
       
   929                         {
       
   930                         metSmileyNotReady = ETrue;
       
   931                         }
       
   932                     }
       
   933 
       
   934                 //offset += TPoint(aFont->TextWidthInPixels(ptr.Left(2)),0);
       
   935                 offset.iX += size.iWidth;
       
   936                 }
       
   937             
       
   938             ptr.Set(ptr.Right(ptr.Length()-2));
       
   939             }
       
   940         }
       
   941     }
       
   942 
       
   943 CAknSmileyIcon* CSmileyModel::Smiley(TChar aCode) const
       
   944     {
       
   945     if(IsSmiley(aCode))
       
   946         {
       
   947         TInt smileyCodeIndex = (TUint16)aCode - KBaseCode;
       
   948         return iSmileyCodeIndexArray[smileyCodeIndex].Smiley();
       
   949         }
   358         }
   950     else
   359     else
   951         {
   360         {
   952         return NULL;
   361         return NULL;
   953         }
   362         }
   954     }
   363     }
   955 
   364 
   956 CAknSmileyIcon* CSmileyModel::operator[](TInt aIndex) const
       
   957     {
       
   958     if(aIndex>=0 && aIndex<ArrayCount())
       
   959         {
       
   960         return iSmileyIconArray[aIndex];
       
   961         }
       
   962     else
       
   963         {
       
   964         return NULL;
       
   965         }
       
   966     }
       
   967 
       
   968 TInt CSmileyModel::Count() const
   365 TInt CSmileyModel::Count() const
   969     {
   366     {
   970     return iSmileyIconArray.Count() - 2;
       
   971     }
       
   972 
       
   973 CAknSmileyIcon* CSmileyModel::SwitchToSmileyIcon() const
       
   974     {
       
   975     return (*this)[Count()];
       
   976     }
       
   977 
       
   978 CAknSmileyIcon* CSmileyModel::SwitchToSctIcon() const
       
   979     {
       
   980     return (*this)[Count()+1];
       
   981     }
       
   982 
       
   983 TChar CSmileyModel::SwitchToSmileyCode() const
       
   984     {
       
   985     return SmileyCode(Count());
       
   986     }
       
   987 
       
   988 TChar CSmileyModel::SwitchToSctCode() const
       
   989     {
       
   990     return SmileyCode(Count()+1);
       
   991     }
       
   992 
       
   993 TChar CSmileyModel::SmileyCode(TInt aIndex, TInt aVariant) const
       
   994     {
       
   995     const CAknSmileyIcon* iconWrapper = (*this)[aIndex];
       
   996     const CSmileyIcon* icon = static_cast<const CSmileyIcon*>(iconWrapper);
       
   997     if(icon)
       
   998         {
       
   999         return icon->Code(aVariant);
       
  1000         }
       
  1001     else
       
  1002         {
       
  1003         return 0;
       
  1004         }
       
  1005     }
       
  1006 
       
  1007 TChar CSmileyModel::SmileyCode(const CAknSmileyIcon* aSmileyIcon) const
       
  1008     {
       
  1009     if(aSmileyIcon)
       
  1010         {
       
  1011         const CSmileyIcon* icon = static_cast<const CSmileyIcon*>(aSmileyIcon);
       
  1012         return icon->Code();
       
  1013         }
       
  1014     else
       
  1015         {
       
  1016         return 0;
       
  1017         }
       
  1018     }
       
  1019 
       
  1020 void CSmileyModel::LoadStillImagesL(const TDesC& aText)
       
  1021     {
       
  1022     for(TInt i(0); i<aText.Length(); i++)
       
  1023         {
       
  1024         LoadStillImageL(aText[i]);
       
  1025         }
       
  1026     }
       
  1027 
       
  1028 void CSmileyModel::PlayAnimationL(const TDesC& aText, TInt aRepeat, TInt aDelay)
       
  1029     {
       
  1030     for(TInt i(0); i<aText.Length(); i++)
       
  1031         {
       
  1032         PlayAnimationL(aText[i], aRepeat, aDelay);
       
  1033         }
       
  1034     }
       
  1035 
       
  1036 void CSmileyModel::StopAnimation(const TDesC& aText)
       
  1037     {
       
  1038     for(TInt i(0); i<aText.Length(); i++)
       
  1039         {
       
  1040         StopAnimation(aText[i]);
       
  1041         }
       
  1042     }
       
  1043 
       
  1044 void CSmileyModel::LoadStillImageL(TChar aChar)
       
  1045     {
       
  1046     CSmileyIcon* icon = static_cast<CSmileyIcon*>(Smiley(aChar));
       
  1047     iSmileyLoader.AddTaskL(icon);
       
  1048     }
       
  1049 
       
  1050 void CSmileyModel::PlayAnimationL(TChar aChar, TInt aRepeat, TInt aDelay)
       
  1051     {
       
  1052     CSmileyIcon* icon = static_cast<CSmileyIcon*>(Smiley(aChar));
       
  1053     if(icon) icon->PlayAnimationL(aRepeat, aDelay);
       
  1054     }
       
  1055 
       
  1056 void CSmileyModel::StopAnimation(TChar aChar)
       
  1057     {
       
  1058     CSmileyIcon* icon = static_cast<CSmileyIcon*>(Smiley(aChar));
       
  1059     if(icon) icon->StopAnimation();
       
  1060     }
       
  1061 
       
  1062 const TDesC& CSmileyModel::Text(TInt aIndex, TInt aVariant) const
       
  1063     {
       
  1064     CSmileyIcon* icon = static_cast<CSmileyIcon*>((*this)[aIndex]);
       
  1065     if(icon)
       
  1066         {
       
  1067         return icon->Text(aVariant);
       
  1068         }
       
  1069     else
       
  1070         {
       
  1071         return KNullDesC;
       
  1072         }
       
  1073     }
       
  1074 
       
  1075 TInt CSmileyModel::ArrayCount() const
       
  1076     {
       
  1077     return iSmileyIconArray.Count();
   367     return iSmileyIconArray.Count();
  1078 
   368     }
  1079 
   369 
  1080 
   370 void CSmileyModel::ThumbnailLoaded(CSmileyIcon* aSmileyIcon)
  1081     }
   371     {
  1082 
   372     TRAP_IGNORE(iSmileyThumbnailLoader.DoNextTaskL());
  1083 void CSmileyModel::SmileyStillImageLoaded(CAknSmileyIcon* aSmileyIcon)
   373 
  1084     {
   374     if(iSmileyIconObserver) iSmileyIconObserver->ThumbnailLoaded(aSmileyIcon);
  1085     TRAP_IGNORE(iSmileyLoader.DoNextTaskL());
   375     }
  1086 
   376 
  1087     if(iSmileyIconObserver) iSmileyIconObserver->SmileyStillImageLoaded(aSmileyIcon);
   377 void CSmileyModel::AnimationChanged(CSmileyIcon* aSmileyIcon)
  1088     }
   378     {
  1089 
   379     if(iSmileyIconObserver) iSmileyIconObserver->AnimationChanged(aSmileyIcon);
  1090 void CSmileyModel::SmileyAnimationChanged(CAknSmileyIcon* aSmileyIcon)
       
  1091     {
       
  1092     if(iSmileyIconObserver) iSmileyIconObserver->SmileyAnimationChanged(aSmileyIcon);
       
  1093     }
   380     }
  1094 
   381 
  1095 
   382 
  1096 // end of file
   383 // end of file
  1097 
   384