messagingapp/msgutils/unidatautils/unidatamodel/src/UniSmilSlide.cpp
changeset 25 84d9eb65b26f
equal deleted inserted replaced
23:238255e8b033 25:84d9eb65b26f
       
     1 /*
       
     2 * Copyright (c) 2005 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: 
       
    15 *       Provides MMS SMIL Slide methods.
       
    16 *
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 // ========== INCLUDE FILES ================================
       
    22 
       
    23 #include <e32def.h>
       
    24 #include <eikenv.h>
       
    25 #include <msvids.h>
       
    26 #include <msvstd.h>
       
    27 
       
    28 #include <MsgMedia.hrh>
       
    29 #include <MsgMediaInfo.h>
       
    30 
       
    31 #include "UniModelConst.h"
       
    32 #include "UniObject.h"    
       
    33 #include "UniSmilSlide.h"
       
    34 
       
    35 // ========== LOCAL CONSTANTS AND MACROS ===================
       
    36 
       
    37 const TUint KMaxObjectPerSlide( 3 );
       
    38 
       
    39 // ========== MEMBER FUNCTIONS =============================
       
    40 
       
    41 CUniSmilSlide* CUniSmilSlide::NewLC( TUniLayout aLayout )
       
    42     {
       
    43     CUniSmilSlide* self = new ( ELeave ) CUniSmilSlide( aLayout );
       
    44 
       
    45     CleanupStack::PushL( self );
       
    46     self->ConstructL();
       
    47 
       
    48     return self;
       
    49     }
       
    50 
       
    51 // ---------------------------------------------------------
       
    52 // CUniSmilSlide::NewL
       
    53 //
       
    54 // Factory method.
       
    55 // ---------------------------------------------------------
       
    56 //
       
    57 CUniSmilSlide* CUniSmilSlide::NewL( TUniLayout aLayout )
       
    58     {
       
    59     CUniSmilSlide* self = NewLC( aLayout );
       
    60     CleanupStack::Pop( self );
       
    61     return self;
       
    62     }
       
    63 
       
    64 
       
    65 // ---------------------------------------------------------
       
    66 // CUniSmilSlide::CUniSmilSlide
       
    67 //
       
    68 // Constructor.
       
    69 // ---------------------------------------------------------
       
    70 //
       
    71 CUniSmilSlide::CUniSmilSlide( TUniLayout aLayout ) :
       
    72     iLayout( aLayout )
       
    73     {
       
    74     }
       
    75 
       
    76 // ---------------------------------------------------------
       
    77 // CUniSmilSlide::CUniSmilSlide
       
    78 //
       
    79 // Destructor.
       
    80 // ---------------------------------------------------------
       
    81 //
       
    82  CUniSmilSlide::~CUniSmilSlide()
       
    83     {
       
    84     //Objects not owned by slide!!
       
    85     //->ResetAndDestroy() not called.
       
    86     delete iObjectArray;
       
    87     }
       
    88 
       
    89 
       
    90 // ---------------------------------------------------------
       
    91 // CUniSmilSlide::AddObjectL
       
    92 //
       
    93 // Object should be valid for addition at this point ie 
       
    94 // should be checked that it can be added to slide.
       
    95 // Takes ownership of the aObject.
       
    96 // ---------------------------------------------------------
       
    97 //  
       
    98 void CUniSmilSlide::AddObjectL( CUniObject* aObject )
       
    99     {
       
   100     TUniRegion region = EUniRegionUnresolved;
       
   101     switch ( aObject->MediaType() )
       
   102         {
       
   103         case EMsgMediaText:
       
   104         case EMsgMediaXhtml:
       
   105             {
       
   106             region = EUniRegionText;
       
   107             }
       
   108             break;
       
   109         case EMsgMediaAudio:
       
   110             {
       
   111             region = EUniRegionAudio;
       
   112             }
       
   113             break;
       
   114 #ifdef RD_SVGT_IN_MESSAGING
       
   115         case EMsgMediaSvg:
       
   116 #endif
       
   117         case EMsgMediaImage:
       
   118         case EMsgMediaVideo:
       
   119             {
       
   120             region = EUniRegionImage;
       
   121             }
       
   122             break;
       
   123         default:
       
   124             {
       
   125             User::Leave( KErrNotSupported );
       
   126             }
       
   127         }
       
   128     AddObjectL( aObject, region );
       
   129     }
       
   130 
       
   131 
       
   132 // ---------------------------------------------------------
       
   133 // CUniSmilSlide::AddObjectL
       
   134 //
       
   135 // Object should be valid for addition at this point ie 
       
   136 // should be checked that it can be added to slide.
       
   137 // Takes ownership of the aObject.
       
   138 // ---------------------------------------------------------
       
   139 //  
       
   140 void CUniSmilSlide::AddObjectL( CUniObject* aObject, TUniRegion aRegion )
       
   141     {
       
   142     for ( TInt i = 0; i < iObjectArray->Count(); ++i)
       
   143         {
       
   144         if ( iObjectArray->At( i )->Region() == aRegion )
       
   145             {
       
   146             User::Leave( KErrAlreadyExists );
       
   147             }
       
   148         }
       
   149     aObject->SetReferenceCount( aObject->ReferenceCount() + 1 );
       
   150     aObject->SetRegion( aRegion );
       
   151     if ( aRegion == EUniRegionAudio )
       
   152         {
       
   153         //always put audio region last...
       
   154         iObjectArray->AppendL( aObject );
       
   155         }
       
   156     else
       
   157         {
       
   158         //...and other regions first...
       
   159         iObjectArray->InsertL( 0, aObject );
       
   160         //...and update layout when needed
       
   161         UpdateLayoutL(); // does not leave, really.
       
   162         }
       
   163     }
       
   164 
       
   165 
       
   166 // ---------------------------------------------------------
       
   167 // CUniSmilSlide::RemoveObject
       
   168 //
       
   169 // 
       
   170 // ---------------------------------------------------------
       
   171 //
       
   172 void CUniSmilSlide::RemoveObject( CUniObject* aObject )
       
   173     {
       
   174     TInt index( -1 );  // Initialize to impossible index.
       
   175 
       
   176     for ( TInt i = 0; i < iObjectArray->Count(); ++i )
       
   177         {
       
   178         if ( iObjectArray->At( i ) == aObject )
       
   179             {
       
   180             index = i;
       
   181             }
       
   182         }
       
   183     if ( index != -1 )
       
   184         {
       
   185         // Found
       
   186         iObjectArray->Delete( index );
       
   187         aObject->SetReferenceCount( aObject->ReferenceCount() - 1 );
       
   188         }
       
   189     }
       
   190 
       
   191 // ---------------------------------------------------------
       
   192 // CUniSmilSlide::GetObject
       
   193 //
       
   194 // Accessor. 
       
   195 // ---------------------------------------------------------
       
   196 //
       
   197 CUniObject* CUniSmilSlide::GetObject( TUniRegion aRegion ) const 
       
   198     {
       
   199     TInt cnt = iObjectArray->Count();
       
   200 
       
   201     for ( TInt i = 0; i < cnt; ++i )
       
   202         {
       
   203         if ( iObjectArray->At( i )->Region() == aRegion )
       
   204             {
       
   205             return iObjectArray->At( i );
       
   206             }
       
   207         }
       
   208     return NULL;
       
   209     }
       
   210 
       
   211 // ---------------------------------------------------------
       
   212 // CUniSmilSlide::GetObject
       
   213 //
       
   214 // Accessor. 
       
   215 // ---------------------------------------------------------
       
   216 //
       
   217 CUniObject* CUniSmilSlide::GetObjectByIndex( TInt aObjNum ) const 
       
   218     {
       
   219     if ( aObjNum >= 0 &&
       
   220         aObjNum < iObjectArray->Count() )
       
   221         {
       
   222         return iObjectArray->At( aObjNum );
       
   223         }
       
   224     return NULL;
       
   225     }
       
   226 
       
   227 // ---------------------------------------------------------
       
   228 // CUniSmilSlide::IsObject
       
   229 //
       
   230 //  
       
   231 // ---------------------------------------------------------
       
   232 //
       
   233 TBool CUniSmilSlide::IsObject( CUniObject* aObject ) const
       
   234     {
       
   235     TInt cnt = iObjectArray->Count();
       
   236 
       
   237     for ( TInt i = 0; i < cnt; ++i )
       
   238         {
       
   239         if ( iObjectArray->At( i ) == aObject )
       
   240             {
       
   241             return ETrue;
       
   242             }
       
   243         }
       
   244     return EFalse;
       
   245     }
       
   246 
       
   247 // ---------------------------------------------------------
       
   248 // CUniSmilSlide::ObjectCount
       
   249 //
       
   250 // Accessor
       
   251 // ---------------------------------------------------------
       
   252 //
       
   253 TInt CUniSmilSlide::ObjectCount() const
       
   254     {
       
   255     return iObjectArray->Count();
       
   256     }
       
   257 
       
   258 
       
   259 // ---------------------------------------------------------
       
   260 // CUniSmilSlide::UpdateLayoutL
       
   261 //
       
   262 // 
       
   263 // ---------------------------------------------------------
       
   264 // 
       
   265 void CUniSmilSlide::UpdateLayoutL( TUniLayout aNewLayout )
       
   266     {
       
   267     // Only need to do something if slide has text & image.
       
   268     // If only other or neither -> do nothing.
       
   269     iLayout = aNewLayout;
       
   270     UpdateLayoutL();
       
   271     }
       
   272 
       
   273 // ---------------------------------------------------------
       
   274 // CUniSmilSlide::UpdateLayoutL
       
   275 //
       
   276 // 
       
   277 // ---------------------------------------------------------
       
   278 // 
       
   279 void CUniSmilSlide::UpdateLayoutL()
       
   280     {
       
   281     if ( iLayout == EUniImageFirst ||
       
   282         iLayout == EUniTextFirst )
       
   283         {
       
   284         CUniObject* image = GetObject( EUniRegionImage );
       
   285         CUniObject* text = GetObject( EUniRegionText );
       
   286         if ( image && text )
       
   287             {
       
   288             TInt imageRef = image->ReferenceCount();
       
   289             TInt textRef = text->ReferenceCount();
       
   290             RemoveObject( image );
       
   291             RemoveObject( text );
       
   292             if ( iLayout == EUniImageFirst )
       
   293                 {
       
   294                 iObjectArray->InsertL( 0, text );
       
   295                 iObjectArray->InsertL( 0, image );
       
   296                 }
       
   297             else
       
   298                 {
       
   299                 iObjectArray->InsertL( 0, image );
       
   300                 iObjectArray->InsertL( 0, text );
       
   301                 }
       
   302             image->SetReferenceCount( imageRef );
       
   303             text->SetReferenceCount( textRef );
       
   304             }
       
   305         }
       
   306     }
       
   307 
       
   308 // ---------------------------------------------------------
       
   309 // CUniSmilSlide::ConstructL
       
   310 //
       
   311 // 2nd phase Constructor.
       
   312 // ---------------------------------------------------------
       
   313 //
       
   314 void CUniSmilSlide::ConstructL()
       
   315     {
       
   316     iObjectArray = new ( ELeave ) CSmilObjectArray( KMaxObjectPerSlide );
       
   317     }
       
   318 
       
   319 // End of file