|         |      1 /* | 
|         |      2 * Copyright (c) 2005-2006 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 *       MsgEditor svgt UI control - a Message Editor Base control. | 
|         |     16 * | 
|         |     17 */ | 
|         |     18  | 
|         |     19   | 
|         |     20  | 
|         |     21 // INCLUDE FILES | 
|         |     22 #include "MsgSvgControl.h" | 
|         |     23  | 
|         |     24 #include <gdi.h> | 
|         |     25 #include <AknDialog.h> | 
|         |     26 #include <aknlayoutscalable_apps.cdl.h> | 
|         |     27  | 
|         |     28 #include <AknUtils.h> | 
|         |     29 #include <msgsvgutils.h> | 
|         |     30 #include <AknsDrawUtils.h> | 
|         |     31  | 
|         |     32 #include <gulicon.h> | 
|         |     33 #include <MsgEditorCommon.h> | 
|         |     34  | 
|         |     35 #include "MsgFrameControl.h" | 
|         |     36 #include "MsgIconControl.h" | 
|         |     37  | 
|         |     38 #include "MsgMediaControlLogging.h" | 
|         |     39  | 
|         |     40 // ========================================================== | 
|         |     41  | 
|         |     42 // EXTERNAL DATA STRUCTURES | 
|         |     43  | 
|         |     44 // EXTERNAL FUNCTION PROTOTYPES | 
|         |     45  | 
|         |     46 // CONSTANTS | 
|         |     47  | 
|         |     48 // MACROS | 
|         |     49  | 
|         |     50 // LOCAL CONSTANTS AND MACROS | 
|         |     51  | 
|         |     52 // MODULE DATA STRUCTURES | 
|         |     53  | 
|         |     54 // LOCAL FUNCTION PROTOTYPES | 
|         |     55  | 
|         |     56 // ================= MEMBER FUNCTIONS ======================= | 
|         |     57  | 
|         |     58 // --------------------------------------------------------- | 
|         |     59 // CMsgSvgControl::CMsgSvgControl | 
|         |     60 // | 
|         |     61 // Constructor. | 
|         |     62 // --------------------------------------------------------- | 
|         |     63 // | 
|         |     64 CMsgSvgControl::CMsgSvgControl( MMsgBaseControlObserver& aBaseControlObserver ) :  | 
|         |     65     CMsgMediaControl( aBaseControlObserver, EMsgComponentIdSvg, EMsgSvgControl ) | 
|         |     66     { | 
|         |     67     } | 
|         |     68  | 
|         |     69 // --------------------------------------------------------- | 
|         |     70 // CMsgSvgControl::ConstructL | 
|         |     71 // | 
|         |     72 // --------------------------------------------------------- | 
|         |     73 // | 
|         |     74 void CMsgSvgControl::ConstructL( CMsgEditorView& aParent, MMsgAsyncControlObserver* aObserver ) | 
|         |     75     { | 
|         |     76     BaseConstructL( aParent, aObserver );     | 
|         |     77 	 | 
|         |     78 	SetSize( CalculateControlSize( MsgEditorCommons::MsgDataPane().Size() ) ); | 
|         |     79 	 | 
|         |     80 	iSvgUtils = new( ELeave ) CMsgSvgUtils; | 
|         |     81     } | 
|         |     82  | 
|         |     83 // --------------------------------------------------------- | 
|         |     84 // CMsgSvgControl::NewL | 
|         |     85 // | 
|         |     86 // Two-phased constructor. | 
|         |     87 // --------------------------------------------------------- | 
|         |     88 // | 
|         |     89 #ifdef RD_SVGT_IN_MESSAGING | 
|         |     90 EXPORT_C CMsgSvgControl* CMsgSvgControl::NewL( CMsgEditorView& aParent, | 
|         |     91                                                    MMsgAsyncControlObserver* aObserver ) | 
|         |     92     { | 
|         |     93  | 
|         |     94     CMsgSvgControl* self = new( ELeave ) CMsgSvgControl( aParent ); | 
|         |     95      | 
|         |     96     CleanupStack::PushL( self ); | 
|         |     97     self->ConstructL( aParent, aObserver ); | 
|         |     98     CleanupStack::Pop( self ); | 
|         |     99      | 
|         |    100     return self; | 
|         |    101     } | 
|         |    102 #else | 
|         |    103 EXPORT_C CMsgSvgControl* CMsgSvgControl::NewL( CMsgEditorView& /*aParent*/, | 
|         |    104                                                MMsgAsyncControlObserver* /*aObserver*/ ) | 
|         |    105     { | 
|         |    106     User::Leave( KErrNotSupported ); | 
|         |    107     return NULL; //getting rid of warning | 
|         |    108     } | 
|         |    109 #endif         | 
|         |    110  | 
|         |    111 // --------------------------------------------------------- | 
|         |    112 // CMsgSvgControl::~CMsgSvgControl | 
|         |    113 // | 
|         |    114 // Destructor | 
|         |    115 // --------------------------------------------------------- | 
|         |    116 // | 
|         |    117 CMsgSvgControl::~CMsgSvgControl() | 
|         |    118     { | 
|         |    119     delete iSvgIndicator; | 
|         |    120     delete iSvgUtils; | 
|         |    121      | 
|         |    122     iFileHandle.Close(); | 
|         |    123     } | 
|         |    124  | 
|         |    125  | 
|         |    126 // --------------------------------------------------------- | 
|         |    127 // CMsgSvgControl::LoadL | 
|         |    128 // | 
|         |    129 // --------------------------------------------------------- | 
|         |    130 // | 
|         |    131 void CMsgSvgControl::LoadL( RFile& aFileHandle ) | 
|         |    132     { | 
|         |    133     iFileHandle.Close(); | 
|         |    134     User::LeaveIfError( iFileHandle.Duplicate( aFileHandle ) ); | 
|         |    135      | 
|         |    136     DoLoadL();     | 
|         |    137     } | 
|         |    138  | 
|         |    139 // --------------------------------------------------------- | 
|         |    140 // CMsgSvgControl::DoLoadL | 
|         |    141 // | 
|         |    142 // --------------------------------------------------------- | 
|         |    143 // | 
|         |    144 void CMsgSvgControl::DoLoadL() | 
|         |    145     {         | 
|         |    146     TSize thumbnailSize( Size() ); | 
|         |    147     thumbnailSize = TSize( Max( 0, thumbnailSize.iWidth - iFrame->FrameBorderSize().iWidth ), | 
|         |    148 		                   Max( 0, thumbnailSize.iHeight - iFrame->FrameBorderSize().iHeight ) ); | 
|         |    149 		                    | 
|         |    150     // Use svgt thumbnail creation directly  | 
|         |    151     CFbsBitmap* thumbnailBitmap = new ( ELeave ) CFbsBitmap; | 
|         |    152     CleanupStack::PushL( thumbnailBitmap ); | 
|         |    153     TDisplayMode DisplayMode = iCoeEnv->ScreenDevice()->DisplayMode(); | 
|         |    154     //if DisplayMode is EColor16MAP then change to EColor16MA   | 
|         |    155     //EColor16MAP is not supported by SVG Engine. | 
|         |    156     if ( DisplayMode == EColor16MAP ) | 
|         |    157         DisplayMode = EColor16MA; | 
|         |    158      | 
|         |    159     User::LeaveIfError( thumbnailBitmap->Create( thumbnailSize, DisplayMode ) ); | 
|         |    160                                                    | 
|         |    161     CFbsBitmap* thumbnailMask = new ( ELeave ) CFbsBitmap; | 
|         |    162     CleanupStack::PushL( thumbnailMask ); | 
|         |    163      | 
|         |    164     User::LeaveIfError( thumbnailMask->Create( thumbnailSize, | 
|         |    165                                                EGray256 ) ); | 
|         |    166 	                                             | 
|         |    167     CGulIcon* thumbnailIcon = CGulIcon::NewL( thumbnailBitmap, thumbnailMask ); | 
|         |    168     CleanupStack::Pop( 2, thumbnailBitmap ); | 
|         |    169      | 
|         |    170     iIconControl->SetIcon( thumbnailIcon ); | 
|         |    171      | 
|         |    172     // Incase this is not fulfilling the requirements, it might be an | 
|         |    173     // option to go and check for GenerateThumbnailL() in the msgcommonutils | 
|         |    174  | 
|         |    175     iSvgUtils->GenerateThumbnailL( iFileHandle, | 
|         |    176                                    thumbnailIcon->Bitmap(), | 
|         |    177                                    thumbnailIcon->Mask(), | 
|         |    178                                    EFalse, | 
|         |    179                                    thumbnailSize ); | 
|         |    180  | 
|         |    181     // Resize bitmaps to actual content size. | 
|         |    182     thumbnailBitmap->Resize( thumbnailSize ); | 
|         |    183     thumbnailMask->Resize( thumbnailSize ); | 
|         |    184          | 
|         |    185     iIconControl->SetSize( thumbnailSize ); | 
|         |    186     iIconControl->MakeVisible( ETrue ); | 
|         |    187      | 
|         |    188     iFrame->SetImageSize( thumbnailSize ); | 
|         |    189      | 
|         |    190     if ( iSvgIndicator ) | 
|         |    191         { | 
|         |    192         iSvgIndicator->MakeVisible( ETrue ); | 
|         |    193         }     | 
|         |    194      | 
|         |    195     SetState( EMsgAsyncControlStateReady ); | 
|         |    196     } | 
|         |    197  | 
|         |    198 // --------------------------------------------------------- | 
|         |    199 // CMsgSvgControl::Cancel | 
|         |    200 // --------------------------------------------------------- | 
|         |    201 // | 
|         |    202 void CMsgSvgControl::Cancel() | 
|         |    203     { | 
|         |    204     } | 
|         |    205  | 
|         |    206 // --------------------------------------------------------- | 
|         |    207 // CMsgSvgControl::LoadIndicatorIconL | 
|         |    208 // --------------------------------------------------------- | 
|         |    209 // | 
|         |    210 EXPORT_C void CMsgSvgControl::LoadIndicatorIconL( const TAknsItemID& aId, | 
|         |    211                                                   const TDesC& aFileName, | 
|         |    212                                                   const TInt aFileBitmapId, | 
|         |    213                                                   const TInt aFileMaskId ) | 
|         |    214     { | 
|         |    215     delete iSvgIndicator; | 
|         |    216     iSvgIndicator = NULL; | 
|         |    217      | 
|         |    218     iSvgIndicator = CMsgIconControl::NewL( *this ); | 
|         |    219     iSvgIndicator->LoadIconL( aId, | 
|         |    220                               aFileName, | 
|         |    221                               aFileBitmapId, | 
|         |    222                               aFileMaskId );     | 
|         |    223  | 
|         |    224     TAknLayoutRect indicatorRect; | 
|         |    225     indicatorRect.LayoutRect( MsgEditorCommons::MsgDataPane(),  | 
|         |    226                               AknLayoutScalable_Apps::msg_data_pane_g7().LayoutLine() ); | 
|         |    227      | 
|         |    228     iSvgIndicator->SetBitmapSizeL( indicatorRect.Rect().Size() ); | 
|         |    229      | 
|         |    230     if ( iIconControl && | 
|         |    231          iIconControl->IsVisible() ) | 
|         |    232         { | 
|         |    233         iSvgIndicator->MakeVisible( ETrue ); | 
|         |    234         } | 
|         |    235     } | 
|         |    236  | 
|         |    237 // --------------------------------------------------------- | 
|         |    238 // CMsgSvgControl::SetIconExtent | 
|         |    239 // | 
|         |    240 // Updates the icon position & size. Icon control is centered | 
|         |    241 // to the control area. | 
|         |    242 // --------------------------------------------------------- | 
|         |    243 // | 
|         |    244 void CMsgSvgControl::SetIconExtent() | 
|         |    245     { | 
|         |    246     if ( iSvgIndicator ) | 
|         |    247         { | 
|         |    248         TSize size = iSvgIndicator->BitmapSize(); | 
|         |    249          | 
|         |    250         TPoint position( iIconControl->Position() ); | 
|         |    251         position.iY += iIconControl->Size().iHeight; | 
|         |    252         position.iY -= size.iHeight; | 
|         |    253      | 
|         |    254         iSvgIndicator->SetExtent( position, size ); | 
|         |    255         } | 
|         |    256     } | 
|         |    257  | 
|         |    258 // --------------------------------------------------------- | 
|         |    259 // CMsgSvgControl::SizeChanged | 
|         |    260 // --------------------------------------------------------- | 
|         |    261 // | 
|         |    262 void CMsgSvgControl::SizeChanged() | 
|         |    263     {   | 
|         |    264     CMsgMediaControl::SizeChanged(); | 
|         |    265      | 
|         |    266     SetIconExtent();        | 
|         |    267     } | 
|         |    268          | 
|         |    269 // --------------------------------------------------------- | 
|         |    270 // CMsgSvgControl::ComponentControl | 
|         |    271 // --------------------------------------------------------- | 
|         |    272 // | 
|         |    273 CCoeControl* CMsgSvgControl::ComponentControl( TInt aIndex ) const | 
|         |    274     { | 
|         |    275     CCoeControl* result = NULL; | 
|         |    276      | 
|         |    277     switch ( aIndex ) | 
|         |    278         { | 
|         |    279         case 0: | 
|         |    280             { | 
|         |    281             result = iFrame; | 
|         |    282             break; | 
|         |    283             } | 
|         |    284         case 1: | 
|         |    285             { | 
|         |    286             result = iIconControl; | 
|         |    287             break; | 
|         |    288             }    | 
|         |    289         case 2: | 
|         |    290             { | 
|         |    291             result = iSvgIndicator; | 
|         |    292             break; | 
|         |    293             } | 
|         |    294         default: | 
|         |    295             { | 
|         |    296             break; | 
|         |    297             } | 
|         |    298         } | 
|         |    299          | 
|         |    300     return result;             | 
|         |    301     } | 
|         |    302  | 
|         |    303 // --------------------------------------------------------- | 
|         |    304 // CMsgSvgControl::CountComponentControls | 
|         |    305 // | 
|         |    306 // --------------------------------------------------------- | 
|         |    307 // | 
|         |    308 TInt CMsgSvgControl::CountComponentControls() const | 
|         |    309     { | 
|         |    310     TInt result( 2 ); | 
|         |    311     if ( iSvgIndicator ) | 
|         |    312         { | 
|         |    313         result++; | 
|         |    314         } | 
|         |    315          | 
|         |    316     return result; | 
|         |    317     } | 
|         |    318  | 
|         |    319  | 
|         |    320 // --------------------------------------------------------- | 
|         |    321 // CMsgSvgControl::Draw | 
|         |    322 // | 
|         |    323 // --------------------------------------------------------- | 
|         |    324 // | 
|         |    325 void CMsgSvgControl::Draw( const TRect& aRect ) const | 
|         |    326     { | 
|         |    327     if ( iSvgIndicator ) | 
|         |    328         { | 
|         |    329         CWindowGc& gc = SystemGc(); | 
|         |    330          | 
|         |    331         if ( !AknsDrawUtils::BackgroundBetweenRects( AknsUtils::SkinInstance(),  | 
|         |    332                                                      AknsDrawUtils::ControlContext( this ),  | 
|         |    333                                                      this,  | 
|         |    334                                                      gc,  | 
|         |    335                                                      aRect, | 
|         |    336                                                      iIconControl->Rect() ) ) | 
|         |    337             { | 
|         |    338             gc.SetBrushColor( AKN_LAF_COLOR( 0 ) ); | 
|         |    339             gc.SetBrushStyle( CGraphicsContext::ESolidBrush ); | 
|         |    340             gc.SetPenStyle( CGraphicsContext::ENullPen ); | 
|         |    341             gc.DrawRect( aRect ); | 
|         |    342             } | 
|         |    343          | 
|         |    344         gc.SetBrushColor( KRgbWhite.Value() ); | 
|         |    345         gc.SetPenStyle( CGraphicsContext::ENullPen ); | 
|         |    346 	    gc.SetBrushStyle( CGraphicsContext::ESolidBrush ); | 
|         |    347 	    gc.DrawRect( iIconControl->Rect() ); | 
|         |    348         } | 
|         |    349     else | 
|         |    350         { | 
|         |    351         CMsgMediaControl::Draw( aRect ); | 
|         |    352         } | 
|         |    353     } | 
|         |    354  | 
|         |    355 // --------------------------------------------------------- | 
|         |    356 // CMsgSvgControl::Close | 
|         |    357 // --------------------------------------------------------- | 
|         |    358 // | 
|         |    359 void CMsgSvgControl::Close() | 
|         |    360     { | 
|         |    361     SetState( EMsgAsyncControlStateIdle ); | 
|         |    362     } | 
|         |    363  | 
|         |    364 // --------------------------------------------------------- | 
|         |    365 // CMsgSvgControl::SetAndGetSizeL | 
|         |    366 // | 
|         |    367 // Calculates and sets the size of the control and returns new size as | 
|         |    368 // reference aSize. | 
|         |    369 // --------------------------------------------------------- | 
|         |    370 // | 
|         |    371 void CMsgSvgControl::SetAndGetSizeL( TSize& aSize ) | 
|         |    372     { | 
|         |    373     aSize = CalculateControlSize( aSize ); | 
|         |    374     SetSize( aSize ); | 
|         |    375     } | 
|         |    376  | 
|         |    377 // --------------------------------------------------------- | 
|         |    378 // CMsgSvgControl::HandleResourceChange | 
|         |    379 // --------------------------------------------------------- | 
|         |    380 // | 
|         |    381 void CMsgSvgControl::HandleResourceChange( TInt aType ) | 
|         |    382     { | 
|         |    383     CMsgMediaControl::HandleResourceChange( aType );  | 
|         |    384      | 
|         |    385     if ( aType == KEikDynamicLayoutVariantSwitch ) | 
|         |    386         { | 
|         |    387         SetSize( CalculateControlSize( MsgEditorCommons::MsgDataPane().Size() ) ); | 
|         |    388          | 
|         |    389         TRAP_IGNORE( DoLoadL() ); | 
|         |    390         } | 
|         |    391     } | 
|         |    392  | 
|         |    393  | 
|         |    394 // --------------------------------------------------------- | 
|         |    395 // CMsgSvgControl::PlayL | 
|         |    396 // --------------------------------------------------------- | 
|         |    397 //     | 
|         |    398 void CMsgSvgControl::PlayL() | 
|         |    399     {    | 
|         |    400     } | 
|         |    401    | 
|         |    402 // --------------------------------------------------------- | 
|         |    403 // CMsgSvgControl::Stop | 
|         |    404 // --------------------------------------------------------- | 
|         |    405 //     | 
|         |    406 void CMsgSvgControl::Stop() | 
|         |    407     { | 
|         |    408     } | 
|         |    409      | 
|         |    410 // --------------------------------------------------------- | 
|         |    411 // CMsgSvgControl::PauseL | 
|         |    412 // --------------------------------------------------------- | 
|         |    413 //     | 
|         |    414 void CMsgSvgControl::PauseL() | 
|         |    415     { | 
|         |    416     } | 
|         |    417  | 
|         |    418 // --------------------------------------------------------- | 
|         |    419 // CMsgSvgControl::CalculateControlSize | 
|         |    420 // --------------------------------------------------------- | 
|         |    421 //     | 
|         |    422 TSize CMsgSvgControl::CalculateControlSize( TSize aProposedSize ) const | 
|         |    423     { | 
|         |    424     TAknLayoutRect controLayout; | 
|         |    425     controLayout.LayoutRect( MsgEditorCommons::MsgDataPane(), | 
|         |    426                              AknLayoutScalable_Apps::msg_data_pane_g1().LayoutLine() ); | 
|         |    427      | 
|         |    428     TSize controlSize = controLayout.Rect().Size(); | 
|         |    429      | 
|         |    430     // Make sure controlSize is multiple of iBaseLine | 
|         |    431     controlSize.iHeight = iBaseLine * ( controlSize.iHeight / iBaseLine ); | 
|         |    432 		                  | 
|         |    433     if ( controlSize.iHeight > aProposedSize.iHeight ) | 
|         |    434         { | 
|         |    435         controlSize.iHeight = aProposedSize.iHeight; | 
|         |    436         } | 
|         |    437      | 
|         |    438     if ( controlSize.iWidth > aProposedSize.iWidth ) | 
|         |    439         { | 
|         |    440         controlSize.iWidth = aProposedSize.iWidth; | 
|         |    441         } | 
|         |    442      | 
|         |    443     return controlSize; | 
|         |    444     } | 
|         |    445  | 
|         |    446 //  End of File | 
|         |    447  |