meetingrequest/mrgui/mrfieldbuilderplugin/src/cesmrcheckbox.cpp
changeset 0 8466d47a6819
child 12 4ce476e64c59
equal deleted inserted replaced
-1:000000000000 0:8466d47a6819
       
     1 /*
       
     2 * Copyright (c) 2007-2009 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:  ESMR All day event checkbox field implementation
       
    15  *
       
    16 */
       
    17 
       
    18 #include "emailtrace.h"
       
    19 #include "cesmrcheckbox.h"
       
    20 
       
    21 #include <eiklabel.h>
       
    22 #include <AknIconUtils.h>
       
    23 #include <fbs.h>
       
    24 #include <eikimage.h>
       
    25 #include <StringLoader.h>
       
    26 #include <avkon.hrh>
       
    27 #include <AknUtils.h>
       
    28 #include <AknsUtils.h>
       
    29 #include <data_caging_path_literals.hrh>
       
    30 
       
    31 #include <esmrgui.rsg>
       
    32 #include "cesmrborderlayer.h"
       
    33 #include "mesmrlistobserver.h"
       
    34 #include "mesmrmeetingrequestentry.h"
       
    35 #include "mesmrfieldvalidator.h"
       
    36 #include "esmrconfig.hrh"
       
    37 #include "cesmriconfield.h"
       
    38 #include "esmrhelper.h"
       
    39 #include "cesmrlayoutmgr.h"
       
    40 
       
    41 using namespace ESMRLayout;
       
    42 
       
    43 // ======== MEMBER FUNCTIONS ========
       
    44 
       
    45 // ---------------------------------------------------------------------------
       
    46 // CESMRCheckbox::NewL
       
    47 // ---------------------------------------------------------------------------
       
    48 //
       
    49 CESMRCheckBox* CESMRCheckBox::NewL( MESMRFieldValidator* aValidator )
       
    50     {
       
    51     FUNC_LOG;
       
    52     CESMRCheckBox* self = new (ELeave) CESMRCheckBox( aValidator );
       
    53     CleanupStack::PushL ( self );
       
    54     self->ConstructL ( );
       
    55     CleanupStack::Pop ( self );
       
    56     return self;
       
    57     }
       
    58 
       
    59 // ---------------------------------------------------------------------------
       
    60 // CESMRCheckbox::~CESMRCheckbox
       
    61 // ---------------------------------------------------------------------------
       
    62 //
       
    63 CESMRCheckBox::~CESMRCheckBox( )
       
    64     {
       
    65     FUNC_LOG;
       
    66     delete iIcon;
       
    67     delete iBitmap;
       
    68     delete iBitmapMask;
       
    69     }
       
    70 
       
    71 // ---------------------------------------------------------------------------
       
    72 // CESMRCheckbox::SetOutlineFocusL
       
    73 // ---------------------------------------------------------------------------
       
    74 //
       
    75 void CESMRCheckBox::SetOutlineFocusL( TBool aFocus )
       
    76     {
       
    77     FUNC_LOG;
       
    78     CESMRField::SetOutlineFocusL ( aFocus );
       
    79 
       
    80     //Focus gained
       
    81     if ( aFocus )
       
    82         {
       
    83         SwitchMSKLabelL();
       
    84         }
       
    85     }
       
    86 
       
    87 // ---------------------------------------------------------------------------
       
    88 // CESMRCheckbox::ExecuteGenericCommandL
       
    89 // ---------------------------------------------------------------------------
       
    90 //
       
    91 void CESMRCheckBox::ExecuteGenericCommandL( TInt aCommand )
       
    92     {
       
    93     FUNC_LOG;
       
    94     if(aCommand == EESMRCmdCheckEvent)
       
    95         {
       
    96         HandleCheckEventL();
       
    97         SwitchMSKLabelL();
       
    98         }
       
    99     }
       
   100 
       
   101 // ---------------------------------------------------------------------------
       
   102 // CESMRCheckbox::OfferKeyEventL
       
   103 // ---------------------------------------------------------------------------
       
   104 //
       
   105 TKeyResponse CESMRCheckBox::OfferKeyEventL(const TKeyEvent& aEvent,
       
   106         TEventCode aType )
       
   107     {
       
   108     FUNC_LOG;
       
   109     TKeyResponse response( EKeyWasNotConsumed);
       
   110     if ( aType == EEventKey )
       
   111         {
       
   112         if ( aEvent.iScanCode == EStdKeyDevice3 )
       
   113             {
       
   114             HandleCheckEventL ( );
       
   115             SwitchMSKLabelL();
       
   116             response = EKeyWasConsumed;
       
   117             }
       
   118         }
       
   119     return response;
       
   120     }
       
   121 
       
   122 // ---------------------------------------------------------------------------
       
   123 // CESMRCheckbox::CountComponentControls
       
   124 // ---------------------------------------------------------------------------
       
   125 //
       
   126 TInt CESMRCheckBox::CountComponentControls( ) const
       
   127     {
       
   128     FUNC_LOG;
       
   129     TInt count = CESMRField::CountComponentControls ( );
       
   130     if ( iIcon )
       
   131         {
       
   132         ++count;
       
   133         }
       
   134     return count;
       
   135     }
       
   136 
       
   137 // ---------------------------------------------------------------------------
       
   138 // CESMRCheckbox::ComponentControl
       
   139 // ---------------------------------------------------------------------------
       
   140 //
       
   141 CCoeControl* CESMRCheckBox::ComponentControl( TInt aInd ) const
       
   142     {
       
   143     FUNC_LOG;
       
   144     if ( aInd == 0 )
       
   145         {
       
   146         return iIcon;
       
   147         }
       
   148     return CESMRField::ComponentControl ( aInd );
       
   149     }
       
   150 
       
   151 // ---------------------------------------------------------------------------
       
   152 // CESMRCheckbox::SizeChanged
       
   153 // ---------------------------------------------------------------------------
       
   154 //
       
   155 void CESMRCheckBox::SizeChanged( )
       
   156     {
       
   157     FUNC_LOG;
       
   158     TRect rect = Rect ( );
       
   159 
       
   160     TInt iconTopMargin = ( rect.Height() - KIconSize.iHeight ) / 2;
       
   161 
       
   162     TPoint iconPos( rect.iTl.iX + KIconSize.iWidth + KIconBorderMargin,
       
   163                     rect.iTl.iY + iconTopMargin );
       
   164 
       
   165 
       
   166     TPoint borderPos( iconPos.iX + KIconSize.iWidth + KIconBorderMargin,
       
   167                       rect.iTl.iY);
       
   168 
       
   169     TSize borderSize( rect.Width() -
       
   170                       (2 * KIconSize.iWidth + 2 * KIconBorderMargin ),
       
   171                       rect.Height ( ));
       
   172 
       
   173     if ( CESMRLayoutManager::IsMirrored ( ) )
       
   174         {
       
   175         iconPos.iX = rect.iBr.iX - ( 2 * KIconSize.iWidth );
       
   176         borderPos.iX = iconPos.iX - borderSize.iWidth - KIconBorderMargin;
       
   177         }
       
   178 
       
   179     if ( iIcon )
       
   180         {
       
   181         iIcon->SetPosition ( iconPos );
       
   182         iIcon->SetSize ( KIconSize );
       
   183         }
       
   184 
       
   185     if ( iBorder )
       
   186         {
       
   187         iBorder->SetPosition ( borderPos );
       
   188         iBorder->SetSize ( borderSize );
       
   189         }
       
   190     }
       
   191 
       
   192 // ---------------------------------------------------------------------------
       
   193 // CESMRCheckbox::InitializeL
       
   194 // ---------------------------------------------------------------------------
       
   195 //
       
   196 void CESMRCheckBox::InitializeL()
       
   197     {
       
   198     FUNC_LOG;
       
   199     iLabel->SetFont( iLayout->Font( iCoeEnv, iFieldId ) );
       
   200     AknLayoutUtils::OverrideControlColorL(
       
   201             *iLabel,
       
   202             EColorLabelText,
       
   203             iLayout->GeneralListAreaTextColor() );
       
   204     }
       
   205 
       
   206 // ---------------------------------------------------------------------------
       
   207 // CESMRCheckbox::InternalizeL
       
   208 // ---------------------------------------------------------------------------
       
   209 //
       
   210 void CESMRCheckBox::InternalizeL( MESMRCalEntry& aEntry )
       
   211     {
       
   212     FUNC_LOG;
       
   213     TBool alldayEvent( aEntry.IsAllDayEventL() );
       
   214 
       
   215     // Update the validator
       
   216     iValidator->SetAllDayEventL(  alldayEvent );
       
   217 
       
   218     // if this is all day event and not checked
       
   219     if ( alldayEvent && !iChecked )
       
   220         {
       
   221         HandleCheckEventL();
       
   222         }
       
   223     SetIconL( iChecked );
       
   224     }
       
   225 
       
   226 // ---------------------------------------------------------------------------
       
   227 // CESMRCheckbox::ExternalizeL
       
   228 // ---------------------------------------------------------------------------
       
   229 //
       
   230 void CESMRCheckBox::ExternalizeL( MESMRCalEntry& /*aEntry*/)
       
   231     {
       
   232     FUNC_LOG;
       
   233     iValidator->SetAllDayEventL( iChecked );
       
   234     }
       
   235 
       
   236 // ---------------------------------------------------------------------------
       
   237 // CESMRCheckbox::SetIconL
       
   238 // ---------------------------------------------------------------------------
       
   239 //
       
   240 void CESMRCheckBox::SetIconL( TBool aChecked )
       
   241     {
       
   242     FUNC_LOG;
       
   243     delete iIcon;
       
   244     iIcon = NULL;
       
   245     delete iBitmap;
       
   246     iBitmap = NULL;
       
   247     delete iBitmapMask;
       
   248     iBitmapMask = NULL;
       
   249 
       
   250     TAknsItemID iconID;
       
   251     TInt fileIndex(KErrNotFound);
       
   252     TInt fileMaskIndex(KErrNotFound);
       
   253 
       
   254     if( aChecked )
       
   255         {
       
   256         iconID = KAknsIIDQgnMeetReqIndiCheckboxMark;
       
   257         }
       
   258     else
       
   259         {
       
   260         iconID = KAknsIIDQgnMeetReqIndiCheckboxUnmark;
       
   261         }
       
   262 
       
   263     CESMRLayoutManager::SetBitmapFallback( iconID, fileIndex, fileMaskIndex );
       
   264 
       
   265     TFileName bitmapFilePath;
       
   266     ESMRHelper::LocateResourceFile(
       
   267             KESMRMifFile,
       
   268             KDC_APP_BITMAP_DIR,
       
   269             bitmapFilePath);
       
   270 
       
   271     TRAPD( err, AknsUtils::CreateIconL( AknsUtils::SkinInstance(),
       
   272                             iconID,
       
   273                             iBitmap,
       
   274                             iBitmapMask,
       
   275                             bitmapFilePath,
       
   276                             fileIndex,
       
   277                             fileMaskIndex
       
   278                             ) );
       
   279 
       
   280     if (err == KErrNotFound)
       
   281         {
       
   282         User::Leave(KErrNotFound);
       
   283         }
       
   284 
       
   285     // Even if creating mask failed, bitmap can be used (background is just not displayed correctly)
       
   286     if( iBitmap )
       
   287         {
       
   288         AknIconUtils::SetSize( iBitmap, KIconSize, EAspectRatioPreserved );
       
   289         iIcon = new (ELeave) CEikImage;
       
   290         iIcon->SetPictureOwnedExternally(ETrue);
       
   291         iIcon->SetPicture( iBitmap, iBitmapMask );
       
   292         }
       
   293     }
       
   294 
       
   295 // ---------------------------------------------------------------------------
       
   296 // CESMRCheckbox::HandleCheckEventL
       
   297 // ---------------------------------------------------------------------------
       
   298 //
       
   299 void CESMRCheckBox::HandleCheckEventL( )
       
   300     {
       
   301     FUNC_LOG;
       
   302     /*
       
   303      * Change check status
       
   304      */
       
   305     iChecked = !iChecked; // change status
       
   306     SetIconL ( iChecked ); // set icon for the status
       
   307 
       
   308     // update validator status:
       
   309     iValidator->SetAllDayEventL ( iChecked );
       
   310 
       
   311     /*
       
   312      * Add / remove new fields to list
       
   313      */
       
   314     if ( iChecked )
       
   315         {
       
   316         // start - end time should be removed
       
   317         // relateive alarm should be removed
       
   318         iObserver->RemoveControl ( EESMRFieldMeetingTime );
       
   319         iObserver->RemoveControl ( EESMRFieldAlarm );
       
   320         // absolute alarm should be inserted
       
   321         iObserver->InsertControl ( EESMRFieldAlarmOnOff );
       
   322         }
       
   323     else
       
   324         {
       
   325         iObserver->InsertControl ( EESMRFieldMeetingTime );
       
   326         iObserver->InsertControl ( EESMRFieldAlarm );
       
   327         iObserver->RemoveControl ( EESMRFieldAlarmOnOff );
       
   328         iObserver->RemoveControl ( EESMRFieldAlarmTime );
       
   329         iObserver->RemoveControl ( EESMRFieldAlarmDate );
       
   330         }
       
   331     }
       
   332 
       
   333 // ---------------------------------------------------------------------------
       
   334 // CESMRCheckbox::SwitchMSKLabelL
       
   335 // ---------------------------------------------------------------------------
       
   336 //
       
   337 void CESMRCheckBox::SwitchMSKLabelL()
       
   338     {
       
   339     FUNC_LOG;
       
   340     if(iChecked)
       
   341         {
       
   342         ChangeMiddleSoftKeyL(EESMRCmdCheckEvent, R_QTN_MSK_UNMARK);
       
   343         }
       
   344     else
       
   345         {
       
   346         ChangeMiddleSoftKeyL(EESMRCmdCheckEvent, R_QTN_MSK_MARK);
       
   347         }
       
   348     }
       
   349 
       
   350 // ---------------------------------------------------------------------------
       
   351 // CESMRCheckbox::CESMRCheckbox
       
   352 // ---------------------------------------------------------------------------
       
   353 //
       
   354 CESMRCheckBox::CESMRCheckBox( MESMRFieldValidator* aValidator ) :
       
   355     iValidator( aValidator), iChecked( EFalse)
       
   356     {
       
   357     FUNC_LOG;
       
   358     //do nothing
       
   359     }
       
   360 
       
   361 // ---------------------------------------------------------------------------
       
   362 // CESMRCheckbox::ConstructL
       
   363 // ---------------------------------------------------------------------------
       
   364 //
       
   365 void CESMRCheckBox::ConstructL( )
       
   366     {
       
   367     FUNC_LOG;
       
   368     SetFieldId( EESMRFieldAllDayEvent );
       
   369     iLabel = new (ELeave) CEikLabel;
       
   370     iLabel->SetLabelAlignment( CESMRLayoutManager::IsMirrored()
       
   371                                ? ELayoutAlignRight : ELayoutAlignLeft );
       
   372 
       
   373     HBufC* txt = StringLoader::LoadLC ( R_QTN_MEET_REQ_ALL_DAY_EVENT );
       
   374     iLabel->SetTextL( *txt );
       
   375     CleanupStack::PopAndDestroy( txt );
       
   376 
       
   377     iIcon = new (ELeave) CEikImage;
       
   378 
       
   379     CESMRField::ConstructL( iLabel );
       
   380     }
       
   381 
       
   382 // EOF
       
   383