meetingrequest/mrgui/mrfieldbuilderplugin/src/cesmrcheckbox.cpp
branchRCL_3
changeset 16 4ce476e64c59
parent 0 8466d47a6819
child 17 8592a65ad3fb
--- a/meetingrequest/mrgui/mrfieldbuilderplugin/src/cesmrcheckbox.cpp	Mon Mar 15 12:39:10 2010 +0200
+++ b/meetingrequest/mrgui/mrfieldbuilderplugin/src/cesmrcheckbox.cpp	Wed Mar 31 21:08:33 2010 +0300
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). 
+* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
 * All rights reserved.
 * This component and the accompanying materials are made available
 * under the terms of "Eclipse Public License v1.0"
@@ -15,30 +15,26 @@
  *
 */
 
-#include "emailtrace.h"
 #include "cesmrcheckbox.h"
-
-#include <eiklabel.h>
-#include <AknIconUtils.h>
-#include <fbs.h>
-#include <eikimage.h>
-#include <StringLoader.h>
-#include <avkon.hrh>
-#include <AknUtils.h>
-#include <AknsUtils.h>
-#include <data_caging_path_literals.hrh>
-
-#include <esmrgui.rsg>
-#include "cesmrborderlayer.h"
 #include "mesmrlistobserver.h"
 #include "mesmrmeetingrequestentry.h"
 #include "mesmrfieldvalidator.h"
 #include "esmrconfig.hrh"
-#include "cesmriconfield.h"
 #include "esmrhelper.h"
-#include "cesmrlayoutmgr.h"
+#include "nmrbitmapmanager.h"
+#include "cmrimage.h"
+#include "cmrlabel.h"
+#include "nmrlayoutmanager.h"
+#include "mesmrfieldeventqueue.h"
+#include "cesmrgenericfieldevent.h"
 
-using namespace ESMRLayout;
+#include <esmrgui.rsg>
+#include <stringloader.h>
+#include <data_caging_path_literals.hrh>
+
+// DEBUG
+#include "emailtrace.h"
+
 
 // ======== MEMBER FUNCTIONS ========
 
@@ -49,23 +45,56 @@
 CESMRCheckBox* CESMRCheckBox::NewL( MESMRFieldValidator* aValidator )
     {
     FUNC_LOG;
-    CESMRCheckBox* self = new (ELeave) CESMRCheckBox( aValidator );
-    CleanupStack::PushL ( self );
-    self->ConstructL ( );
-    CleanupStack::Pop ( self );
+    CESMRCheckBox* self = new( ELeave )CESMRCheckBox( aValidator );
+    CleanupStack::PushL( self );
+    self->ConstructL();
+    CleanupStack::Pop( self );
     return self;
     }
 
 // ---------------------------------------------------------------------------
+// CESMRCheckbox::CESMRCheckbox
+// ---------------------------------------------------------------------------
+//
+CESMRCheckBox::CESMRCheckBox( MESMRFieldValidator* aValidator ) 
+: iChecked( EFalse )
+    {
+    FUNC_LOG;
+    
+    iValidator = aValidator;
+    
+    SetFieldId( EESMRFieldAllDayEvent );
+    SetFocusType ( EESMRHighlightFocus );
+    }
+
+// ---------------------------------------------------------------------------
+// CESMRCheckbox::ConstructL
+// ---------------------------------------------------------------------------
+//
+void CESMRCheckBox::ConstructL()
+    {
+    FUNC_LOG;
+    iLabel = CMRLabel::NewL();
+    iLabel->SetParent( this );
+    
+    CESMRField::ConstructL( iLabel ); //ownership transfered
+    
+    HBufC* txt = StringLoader::LoadLC ( R_QTN_MEET_REQ_ALL_DAY_EVENT );
+    iLabel->SetTextL( *txt );
+    CleanupStack::PopAndDestroy( txt );
+
+    // Creating field icon
+    SetIconL ( iChecked );    
+    }
+
+// ---------------------------------------------------------------------------
 // CESMRCheckbox::~CESMRCheckbox
 // ---------------------------------------------------------------------------
 //
 CESMRCheckBox::~CESMRCheckBox( )
     {
     FUNC_LOG;
-    delete iIcon;
-    delete iBitmap;
-    delete iBitmapMask;
+    delete iFieldIcon;
     }
 
 // ---------------------------------------------------------------------------
@@ -88,14 +117,21 @@
 // CESMRCheckbox::ExecuteGenericCommandL
 // ---------------------------------------------------------------------------
 //
-void CESMRCheckBox::ExecuteGenericCommandL( TInt aCommand )
+TBool CESMRCheckBox::ExecuteGenericCommandL( TInt aCommand )
     {
     FUNC_LOG;
-    if(aCommand == EESMRCmdCheckEvent)
+    TBool isUsed( EFalse );
+    // EAknCmdOpen is added for the Pointer events, see ListPane
+    if( aCommand == EESMRCmdCheckEvent || aCommand == EAknCmdOpen )
         {
         HandleCheckEventL();
         SwitchMSKLabelL();
+        SendFieldChangeEventL( EESMRFieldAllDayEvent );
+        isUsed = ETrue;
+        
+        HandleTactileFeedbackL();
         }
+    return isUsed;
     }
 
 // ---------------------------------------------------------------------------
@@ -111,8 +147,9 @@
         {
         if ( aEvent.iScanCode == EStdKeyDevice3 )
             {
-            HandleCheckEventL ( );
+            HandleCheckEventL();
             SwitchMSKLabelL();
+            SendFieldChangeEventL( EESMRFieldAllDayEvent );
             response = EKeyWasConsumed;
             }
         }
@@ -126,8 +163,12 @@
 TInt CESMRCheckBox::CountComponentControls( ) const
     {
     FUNC_LOG;
-    TInt count = CESMRField::CountComponentControls ( );
-    if ( iIcon )
+    TInt count( 0 );
+    if ( iFieldIcon )
+        {
+        ++count;
+        }
+    if ( iLabel )
         {
         ++count;
         }
@@ -141,66 +182,50 @@
 CCoeControl* CESMRCheckBox::ComponentControl( TInt aInd ) const
     {
     FUNC_LOG;
-    if ( aInd == 0 )
+    switch ( aInd )
         {
-        return iIcon;
+        case 0:
+            return iFieldIcon;
+        case 1:
+            return iLabel;
+        default:
+            return NULL;
         }
-    return CESMRField::ComponentControl ( aInd );
     }
 
 // ---------------------------------------------------------------------------
 // CESMRCheckbox::SizeChanged
 // ---------------------------------------------------------------------------
 //
-void CESMRCheckBox::SizeChanged( )
+void CESMRCheckBox::SizeChanged()
     {
     FUNC_LOG;
-    TRect rect = Rect ( );
-
-    TInt iconTopMargin = ( rect.Height() - KIconSize.iHeight ) / 2;
-
-    TPoint iconPos( rect.iTl.iX + KIconSize.iWidth + KIconBorderMargin,
-                    rect.iTl.iY + iconTopMargin );
-
-
-    TPoint borderPos( iconPos.iX + KIconSize.iWidth + KIconBorderMargin,
-                      rect.iTl.iY);
-
-    TSize borderSize( rect.Width() -
-                      (2 * KIconSize.iWidth + 2 * KIconBorderMargin ),
-                      rect.Height ( ));
-
-    if ( CESMRLayoutManager::IsMirrored ( ) )
-        {
-        iconPos.iX = rect.iBr.iX - ( 2 * KIconSize.iWidth );
-        borderPos.iX = iconPos.iX - borderSize.iWidth - KIconBorderMargin;
-        }
-
-    if ( iIcon )
-        {
-        iIcon->SetPosition ( iconPos );
-        iIcon->SetSize ( KIconSize );
-        }
-
-    if ( iBorder )
-        {
-        iBorder->SetPosition ( borderPos );
-        iBorder->SetSize ( borderSize );
-        }
-    }
-
-// ---------------------------------------------------------------------------
-// CESMRCheckbox::InitializeL
-// ---------------------------------------------------------------------------
-//
-void CESMRCheckBox::InitializeL()
-    {
-    FUNC_LOG;
-    iLabel->SetFont( iLayout->Font( iCoeEnv, iFieldId ) );
-    AknLayoutUtils::OverrideControlColorL(
-            *iLabel,
-            EColorLabelText,
-            iLayout->GeneralListAreaTextColor() );
+    TRect rect = Rect();
+    
+    TAknLayoutRect rowLayoutRect =
+     NMRLayoutManager::GetFieldRowLayoutRect( rect, 1 );
+    rect = rowLayoutRect.Rect();
+    
+    TAknWindowComponentLayout iconLayout =
+     NMRLayoutManager::GetWindowComponentLayout( 
+             NMRLayoutManager::EMRLayoutTextEditorIcon );
+    AknLayoutUtils::LayoutImage( iFieldIcon, rect, iconLayout );
+    
+    TAknLayoutRect bgLayoutRect =
+     NMRLayoutManager::GetLayoutRect( 
+             rect, NMRLayoutManager::EMRLayoutTextEditorBg );
+    TRect bgRect( bgLayoutRect.Rect() );
+    // Move focus rect so that it's relative to field's position.
+    bgRect.Move( -Position() );
+    SetFocusRect( bgRect );
+    
+    TAknLayoutText labelLayout = 
+     NMRLayoutManager::GetLayoutText( 
+             rect, NMRLayoutManager::EMRTextLayoutTextEditor );
+    iLabel->SetRect( labelLayout.TextRect() );
+        
+    // Setting font also for the label
+    iLabel->SetFont( labelLayout.Font() );
     }
 
 // ---------------------------------------------------------------------------
@@ -213,7 +238,7 @@
     TBool alldayEvent( aEntry.IsAllDayEventL() );
 
     // Update the validator
-    iValidator->SetAllDayEventL(  alldayEvent );
+    iValidator->SetAllDayEventL( alldayEvent );
 
     // if this is all day event and not checked
     if ( alldayEvent && !iChecked )
@@ -240,56 +265,23 @@
 void CESMRCheckBox::SetIconL( TBool aChecked )
     {
     FUNC_LOG;
-    delete iIcon;
-    iIcon = NULL;
-    delete iBitmap;
-    iBitmap = NULL;
-    delete iBitmapMask;
-    iBitmapMask = NULL;
-
-    TAknsItemID iconID;
-    TInt fileIndex(KErrNotFound);
-    TInt fileMaskIndex(KErrNotFound);
-
+    delete iFieldIcon;
+    iFieldIcon = NULL;
+    
+    NMRBitmapManager::TMRBitmapId iconID;
     if( aChecked )
         {
-        iconID = KAknsIIDQgnMeetReqIndiCheckboxMark;
+        iconID = NMRBitmapManager::EMRBitmapCheckBoxOn;
         }
     else
         {
-        iconID = KAknsIIDQgnMeetReqIndiCheckboxUnmark;
+        iconID = NMRBitmapManager::EMRBitmapCheckBoxOff;
         }
-
-    CESMRLayoutManager::SetBitmapFallback( iconID, fileIndex, fileMaskIndex );
-
-    TFileName bitmapFilePath;
-    ESMRHelper::LocateResourceFile(
-            KESMRMifFile,
-            KDC_APP_BITMAP_DIR,
-            bitmapFilePath);
+    
+    iFieldIcon = CMRImage::NewL( iconID );
+    iFieldIcon->SetParent( this );
 
-    TRAPD( err, AknsUtils::CreateIconL( AknsUtils::SkinInstance(),
-                            iconID,
-                            iBitmap,
-                            iBitmapMask,
-                            bitmapFilePath,
-                            fileIndex,
-                            fileMaskIndex
-                            ) );
-
-    if (err == KErrNotFound)
-        {
-        User::Leave(KErrNotFound);
-        }
-
-    // Even if creating mask failed, bitmap can be used (background is just not displayed correctly)
-    if( iBitmap )
-        {
-        AknIconUtils::SetSize( iBitmap, KIconSize, EAspectRatioPreserved );
-        iIcon = new (ELeave) CEikImage;
-        iIcon->SetPictureOwnedExternally(ETrue);
-        iIcon->SetPicture( iBitmap, iBitmapMask );
-        }
+    SizeChanged();
     }
 
 // ---------------------------------------------------------------------------
@@ -315,18 +307,18 @@
         {
         // start - end time should be removed
         // relateive alarm should be removed
-        iObserver->RemoveControl ( EESMRFieldMeetingTime );
-        iObserver->RemoveControl ( EESMRFieldAlarm );
+        iObserver->HideControl ( EESMRFieldMeetingTime );
+        iObserver->HideControl ( EESMRFieldAlarm );
         // absolute alarm should be inserted
-        iObserver->InsertControl ( EESMRFieldAlarmOnOff );
+        iObserver->ShowControl ( EESMRFieldAlarmOnOff );
         }
     else
         {
-        iObserver->InsertControl ( EESMRFieldMeetingTime );
-        iObserver->InsertControl ( EESMRFieldAlarm );
-        iObserver->RemoveControl ( EESMRFieldAlarmOnOff );
-        iObserver->RemoveControl ( EESMRFieldAlarmTime );
-        iObserver->RemoveControl ( EESMRFieldAlarmDate );
+        iObserver->ShowControl ( EESMRFieldMeetingTime );
+        iObserver->ShowControl ( EESMRFieldAlarm );
+        iObserver->HideControl ( EESMRFieldAlarmOnOff );
+        iObserver->HideControl ( EESMRFieldAlarmTime );
+        iObserver->HideControl ( EESMRFieldAlarmDate );
         }
     }
 
@@ -337,7 +329,7 @@
 void CESMRCheckBox::SwitchMSKLabelL()
     {
     FUNC_LOG;
-    if(iChecked)
+    if( iChecked )
         {
         ChangeMiddleSoftKeyL(EESMRCmdCheckEvent, R_QTN_MSK_UNMARK);
         }
@@ -348,36 +340,40 @@
     }
 
 // ---------------------------------------------------------------------------
-// CESMRCheckbox::CESMRCheckbox
+// CESMRCheckbox::SetContainerWindowL
 // ---------------------------------------------------------------------------
 //
-CESMRCheckBox::CESMRCheckBox( MESMRFieldValidator* aValidator ) :
-    iValidator( aValidator), iChecked( EFalse)
+void CESMRCheckBox::SetContainerWindowL( 
+        const CCoeControl& aContainer )
     {
-    FUNC_LOG;
-    //do nothing
+    CCoeControl::SetContainerWindowL( aContainer );
+    iLabel->SetContainerWindowL( aContainer );
+    iLabel->SetParent( this );
     }
-
 // ---------------------------------------------------------------------------
-// CESMRCheckbox::ConstructL
+// CESMRCheckBox::SendFieldChangeEventL
 // ---------------------------------------------------------------------------
 //
-void CESMRCheckBox::ConstructL( )
+void CESMRCheckBox::SendFieldChangeEventL(
+        TESMREntryFieldId aFieldId )
     {
     FUNC_LOG;
-    SetFieldId( EESMRFieldAllDayEvent );
-    iLabel = new (ELeave) CEikLabel;
-    iLabel->SetLabelAlignment( CESMRLayoutManager::IsMirrored()
-                               ? ELayoutAlignRight : ELayoutAlignLeft );
-
-    HBufC* txt = StringLoader::LoadLC ( R_QTN_MEET_REQ_ALL_DAY_EVENT );
-    iLabel->SetTextL( *txt );
-    CleanupStack::PopAndDestroy( txt );
-
-    iIcon = new (ELeave) CEikImage;
-
-    CESMRField::ConstructL( iLabel );
+    if ( iEventQueue )
+        {
+        CESMRGenericFieldEvent* event =
+            CESMRGenericFieldEvent::NewLC( NULL,
+                                           MESMRFieldEvent::EESMRFieldChangeEvent );
+        TInt fieldId = aFieldId;
+        CESMRFieldEventValue* field = CESMRFieldEventValue::NewLC(
+                CESMRFieldEventValue::EESMRInteger, &fieldId );
+        event->AddParamL( field );
+        CleanupStack::Pop( field );
+        CESMRFieldEventValue* checked = CESMRFieldEventValue::NewLC(
+                CESMRFieldEventValue::EESMRInteger, &iChecked );
+        event->AddParamL( checked );
+        CleanupStack::Pop( checked );     
+        iEventQueue->NotifyEventL( *event );
+        CleanupStack::PopAndDestroy( event );
+        }
     }
-
 // EOF
-