meetingrequest/mrgui/mrfieldbuilderplugin/src/cesmrvieweralarmtimefield.cpp
branchRCL_3
changeset 33 da5135c61bad
parent 0 8466d47a6819
child 24 b5fbb9b25d57
equal deleted inserted replaced
32:a3a1ae9acec6 33:da5135c61bad
     1 /*
     1 /*
     2 * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). 
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    14 * Description:  ESMR UI Container class
    14 * Description:  ESMR UI Container class
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 #include "cesmrvieweralarmtimefield.h"
    18 #include "cesmrvieweralarmtimefield.h"
       
    19 
    19 #include "cesmreditor.h"
    20 #include "cesmreditor.h"
    20 #include "mesmrlistobserver.h"
    21 #include "mesmrlistobserver.h"
    21 #include "nmrbitmapmanager.h"
    22 #include "esmrfieldbuilderdef.h"
       
    23 #include "cmrimage.h"
       
    24 #include "cmrlabel.h"
    22 #include "nmrlayoutmanager.h"
    25 #include "nmrlayoutmanager.h"
    23 #include "cmrlabel.h"
    26 #include "cesmrglobalnote.h"
    24 #include "cmrimage.h"
    27 
    25 
       
    26 #include <eiklabel.h>
       
    27 #include <caluser.h>
    28 #include <caluser.h>
    28 #include <calalarm.h>
    29 #include <calalarm.h>
    29 #include <avkon.rsg>
    30 #include <avkon.rsg>
    30 #include <calentry.h>
    31 #include <calentry.h>
    31 #include <eikenv.h>
    32 #include <eikenv.h>
    32 #include <eikedwin.h>
    33 
    33 #include <StringLoader.h>
    34 #include "emailtrace.h"
    34 #include <AknsConstants.h>
       
    35 #include <AknUtils.h>
       
    36 #include <AknLayout2ScalableDef.h>
       
    37 
       
    38 #include <esmrgui.rsg>
       
    39 
       
    40 //unnamed namespace for local constants functions
       
    41 namespace{ // codescanner::namespace
       
    42 
       
    43 const TInt KComponentCount( 2 ); // icon and label
       
    44 const TInt KMaxTimeBuffer( 50 ); // buffer for time formatting
       
    45 
       
    46 }//namespace
       
    47 
    35 
    48 // ======== MEMBER FUNCTIONS ========
    36 // ======== MEMBER FUNCTIONS ========
    49 
    37 
    50 // ---------------------------------------------------------------------------
    38 // ---------------------------------------------------------------------------
    51 // CESMRViewerAlarmTimeField::CESMRViewerAlarmTimeField()
    39 // CESMRViewerAlarmTimeField::CESMRViewerAlarmTimeField()
    52 // ---------------------------------------------------------------------------
    40 // ---------------------------------------------------------------------------
    53 //
    41 //
       
    42 CESMRViewerAlarmTimeField::CESMRViewerAlarmTimeField()
       
    43     {
       
    44     FUNC_LOG;
       
    45     SetFieldId ( EESMRFieldAlarmTime );
       
    46     SetFocusType( EESMRHighlightFocus );
       
    47     }
       
    48 
       
    49 // ---------------------------------------------------------------------------
       
    50 // CESMRViewerAlarmTimeField::~CESMRViewerAlarmTimeField()
       
    51 // ---------------------------------------------------------------------------
       
    52 //
       
    53 CESMRViewerAlarmTimeField::~CESMRViewerAlarmTimeField()
       
    54     {
       
    55     FUNC_LOG;
       
    56     delete iIcon;
       
    57     delete iLockIcon;
       
    58     }
       
    59 
       
    60 // ---------------------------------------------------------------------------
       
    61 // CESMRViewerAlarmTimeField::NewL
       
    62 // ---------------------------------------------------------------------------
       
    63 //
    54 CESMRViewerAlarmTimeField* CESMRViewerAlarmTimeField::NewL()
    64 CESMRViewerAlarmTimeField* CESMRViewerAlarmTimeField::NewL()
    55     {
    65     {
       
    66     FUNC_LOG;
    56     CESMRViewerAlarmTimeField* self = new (ELeave) CESMRViewerAlarmTimeField();
    67     CESMRViewerAlarmTimeField* self = new (ELeave) CESMRViewerAlarmTimeField();
    57     CleanupStack::PushL( self );
    68     CleanupStack::PushL( self );
    58     self->ConstructL();
    69     self->ConstructL();
    59     CleanupStack::Pop( self );
    70     CleanupStack::Pop( self );
    60     return self;
    71     return self;
    61     }
    72     }
    62 
    73 
    63 // ---------------------------------------------------------------------------
    74 // ---------------------------------------------------------------------------
    64 // CESMRViewerAlarmTimeField::~CESMRViewerAlarmTimeField()
       
    65 // ---------------------------------------------------------------------------
       
    66 //
       
    67 CESMRViewerAlarmTimeField::~CESMRViewerAlarmTimeField()
       
    68     {
       
    69     delete iIcon;
       
    70     delete iLabel;
       
    71     }
       
    72 
       
    73 // ---------------------------------------------------------------------------
       
    74 // CESMRViewerAlarmTimeField::CESMRViewerAlarmTimeField()
       
    75 // ---------------------------------------------------------------------------
       
    76 //
       
    77 CESMRViewerAlarmTimeField::CESMRViewerAlarmTimeField()
       
    78     {
       
    79     SetFieldId ( EESMRFieldAlarmTime );
       
    80     SetFocusType( EESMRHighlightFocus );
       
    81     }
       
    82 
       
    83 // ---------------------------------------------------------------------------
       
    84 // CESMRViewerAlarmTimeField::ConstructL()
    75 // CESMRViewerAlarmTimeField::ConstructL()
    85 // ---------------------------------------------------------------------------
    76 // ---------------------------------------------------------------------------
    86 //
    77 //
    87 void CESMRViewerAlarmTimeField::ConstructL()
    78 void CESMRViewerAlarmTimeField::ConstructL()
    88     {
    79     {
       
    80     FUNC_LOG;
    89     iLabel = CMRLabel::NewL();
    81     iLabel = CMRLabel::NewL();
    90     iLabel->SetParent( this );
    82     iLabel->SetParent( this );
    91     iIcon = CMRImage::NewL( NMRBitmapManager::EMRBitmapAlarmTime );
    83     CESMRField::ConstructL( iLabel ); // ownership transfered
       
    84 
       
    85     iIcon = CMRImage::NewL( NMRBitmapManager::EMRBitmapAlarmClock ); //TODO: Is this correct icon
    92     iIcon->SetParent( this );
    86     iIcon->SetParent( this );
    93     }
    87     }
    94 
    88 
    95 // ---------------------------------------------------------------------------
    89 // ---------------------------------------------------------------------------
    96 // CESMRViewerAlarmTimeField::InitializeL()
       
    97 // ---------------------------------------------------------------------------
       
    98 //
       
    99 void CESMRViewerAlarmTimeField::InitializeL()
       
   100     {
       
   101     TAknLayoutText text = NMRLayoutManager::GetLayoutText( 
       
   102             Rect(), 
       
   103             NMRLayoutManager::EMRTextLayoutTextEditor );
       
   104     
       
   105     iLabel->SetFont( text.Font() );
       
   106     // This is called so that theme changes will apply when changing theme "on the fly"
       
   107     if ( IsFocused() )
       
   108         {
       
   109         iLabel->FocusChanged( EDrawNow );
       
   110         }
       
   111 
       
   112     AknLayoutUtils::OverrideControlColorL ( *iLabel, EColorLabelText,
       
   113                                              KRgbBlack );
       
   114     }
       
   115 
       
   116 // ---------------------------------------------------------------------------
       
   117 // CESMRViewerAlarmTimeField::InternalizeL()
    90 // CESMRViewerAlarmTimeField::InternalizeL()
   118 // ---------------------------------------------------------------------------
    91 // ---------------------------------------------------------------------------
   119 //
    92 //
   120 void CESMRViewerAlarmTimeField::InternalizeL( MESMRCalEntry& aEntry )
    93 void CESMRViewerAlarmTimeField::InternalizeL( MESMRCalEntry& aEntry )
   121     {
    94     {
       
    95     FUNC_LOG;
   122     MESMRCalEntry::TESMRAlarmType alarmType;
    96     MESMRCalEntry::TESMRAlarmType alarmType;
   123     TTime alarmTime;
    97     aEntry.GetAlarmL( alarmType, iAlarmTime );
   124 
       
   125     aEntry.GetAlarmL( alarmType, alarmTime );
       
   126 
    98 
   127     if( alarmType == MESMRCalEntry::EESMRAlarmAbsolute )
    99     if( alarmType == MESMRCalEntry::EESMRAlarmAbsolute )
   128         {
   100         {
   129         // Read format string from AVKON resource
   101         FormatAlarmTimeL();
   130         HBufC* dateFormatString =
       
   131             iEikonEnv->AllocReadResourceLC( R_QTN_TIME_USUAL_WITH_ZERO );
       
   132         TBuf<KMaxTimeBuffer> buf;
       
   133             
       
   134         alarmTime.FormatL( buf, *dateFormatString );
       
   135         AknTextUtils::DisplayTextLanguageSpecificNumberConversion( buf );
       
   136         iLabel->SetTextL( buf );
       
   137         CleanupStack::PopAndDestroy( dateFormatString );
       
   138         }
   102         }
   139     else // Remove the alarm fields
   103     else // Remove the alarm fields
   140         {
   104         {
   141         CCoeControl::MakeVisible( EFalse );
   105         CCoeControl::MakeVisible( EFalse );
   142         iObserver->RemoveControl( EESMRFieldAlarmTime );
   106         iObserver->HideControl( EESMRFieldAlarmTime );
   143         }
   107         }
   144     }
   108     }
   145 
   109 
   146 // ---------------------------------------------------------------------------
   110 // ---------------------------------------------------------------------------
   147 // CESMRViewerAlarmTimeField::SizeChanged()
   111 // CESMRViewerAlarmTimeField::SizeChanged()
   148 // ---------------------------------------------------------------------------
   112 // ---------------------------------------------------------------------------
   149 //
   113 //
   150 void CESMRViewerAlarmTimeField::SizeChanged()
   114 void CESMRViewerAlarmTimeField::SizeChanged()
   151     {
   115     {
       
   116     FUNC_LOG;
   152     TRect rect = Rect();
   117     TRect rect = Rect();
   153     TAknLayoutRect rowLayoutRect =
   118     TAknLayoutRect rowLayoutRect =
   154         NMRLayoutManager::GetFieldRowLayoutRect( rect, 1 );
   119         NMRLayoutManager::GetFieldRowLayoutRect( rect, 1 );
   155     rect = rowLayoutRect.Rect();
   120     rect = rowLayoutRect.Rect();
   156     
   121 
   157     TAknWindowComponentLayout iconLayout =
   122     TAknWindowComponentLayout iconLayout =
   158         NMRLayoutManager::GetWindowComponentLayout( 
   123         NMRLayoutManager::GetWindowComponentLayout(
   159                 NMRLayoutManager::EMRLayoutTextEditorIcon );
   124                 NMRLayoutManager::EMRLayoutTextEditorIcon );
   160     AknLayoutUtils::LayoutImage( iIcon, rect, iconLayout );
   125     AknLayoutUtils::LayoutImage( iIcon, rect, iconLayout );
   161     
   126 
   162     TAknLayoutRect bgLayoutRect =
   127     // Layouting lock icon
   163         NMRLayoutManager::GetLayoutRect( 
   128     if( iLockIcon )
   164                 rect, NMRLayoutManager::EMRLayoutTextEditorBg );
   129     	{
   165     TRect bgRect( bgLayoutRect.Rect() );
   130     	TAknWindowComponentLayout iconLayout( 
       
   131     			NMRLayoutManager::GetWindowComponentLayout( 
       
   132     					NMRLayoutManager::EMRLayoutSingleRowDColumnGraphic ) );
       
   133     	AknLayoutUtils::LayoutImage( iLockIcon, rect, iconLayout );
       
   134     	}
       
   135 
       
   136     // Layouting label
       
   137     TAknLayoutText viewerLayoutText;
       
   138     if( iLockIcon )
       
   139     	{
       
   140     	viewerLayoutText = NMRLayoutManager::GetLayoutText( rect, 
       
   141     			NMRLayoutManager::EMRTextLayoutSingleRowEditorText );
       
   142     	}
       
   143     else
       
   144     	{
       
   145     	viewerLayoutText = NMRLayoutManager::GetLayoutText( rect, 
       
   146     			NMRLayoutManager::EMRTextLayoutTextEditor );
       
   147     	}
       
   148 
       
   149     TRect viewerRect( viewerLayoutText.TextRect() );    
       
   150     iLabel->SetRect( viewerRect );
       
   151 
   166     // Move focus rect so that it's relative to field's position.
   152     // Move focus rect so that it's relative to field's position.
   167     bgRect.Move( -Position() );
   153     viewerRect.Move( -Position() );
   168     SetFocusRect( bgRect );
   154     SetFocusRect( viewerRect );
   169     
   155 
   170     TAknLayoutText labelLayout = 
   156     // Setting font also for the label
   171         NMRLayoutManager::GetLayoutText( 
   157     iLabel->SetFont( viewerLayoutText.Font() );
   172                 rect, NMRLayoutManager::EMRTextLayoutTextEditor );
       
   173     iLabel->SetRect( labelLayout.TextRect() );
       
   174     }
   158     }
   175 
   159 
   176 // ---------------------------------------------------------------------------
   160 // ---------------------------------------------------------------------------
   177 // CESMRViewerAlarmTimeField::CountComponentControls()
   161 // CESMRViewerAlarmTimeField::CountComponentControls()
   178 // ---------------------------------------------------------------------------
   162 // ---------------------------------------------------------------------------
   179 //
   163 //
   180 TInt CESMRViewerAlarmTimeField::CountComponentControls() const
   164 TInt CESMRViewerAlarmTimeField::CountComponentControls() const
   181     {
   165     {
   182     TInt count( KComponentCount );
   166     FUNC_LOG;
       
   167     TInt count( 0 );
       
   168     if ( iIcon )
       
   169         {
       
   170         ++count;
       
   171         }
       
   172 
       
   173     if ( iLabel )
       
   174         {
       
   175         ++count;
       
   176         }
       
   177     
       
   178     if ( iLockIcon )
       
   179     	{
       
   180     	++count;
       
   181     	}
   183     return count;
   182     return count;
   184     }
   183     }
   185 
   184 
   186 // ---------------------------------------------------------------------------
   185 // ---------------------------------------------------------------------------
   187 // CESMRViewerAlarmTimeField::ComponentControl()
   186 // CESMRViewerAlarmTimeField::ComponentControl()
   188 // ---------------------------------------------------------------------------
   187 // ---------------------------------------------------------------------------
   189 //
   188 //
   190 CCoeControl* CESMRViewerAlarmTimeField::ComponentControl( TInt aIndex ) const
   189 CCoeControl* CESMRViewerAlarmTimeField::ComponentControl( TInt aIndex ) const
   191     {
   190     {
       
   191     FUNC_LOG;
   192     switch ( aIndex )
   192     switch ( aIndex )
   193         {
   193         {
   194         case 0:
   194         case 0:
   195             return iIcon;
   195             return iIcon;
   196         case 1:
   196         case 1:
   197             return iLabel;
   197             return iLabel;
       
   198         case 2:
       
   199         	return iLockIcon;
   198         default:
   200         default:
   199             return NULL;
   201             return NULL;
   200         }
   202         }
   201     }
   203     }
   202 
   204 
   204 // CESMRViewerAlarmTimeField::SetOutlineFocusL()
   206 // CESMRViewerAlarmTimeField::SetOutlineFocusL()
   205 // ---------------------------------------------------------------------------
   207 // ---------------------------------------------------------------------------
   206 //
   208 //
   207 void CESMRViewerAlarmTimeField::SetOutlineFocusL( TBool aFocus )
   209 void CESMRViewerAlarmTimeField::SetOutlineFocusL( TBool aFocus )
   208     {
   210     {
       
   211     FUNC_LOG;
   209     CESMRField::SetOutlineFocusL ( aFocus );
   212     CESMRField::SetOutlineFocusL ( aFocus );
   210     iLabel->SetFocus( aFocus );    
   213 
   211 
   214     iLabel->SetFocus( aFocus );
   212     if ( !aFocus )
   215     }
   213         {
   216 
   214         AknLayoutUtils::OverrideControlColorL ( *iLabel, EColorLabelText,
   217 // ---------------------------------------------------------------------------
   215                                                  KRgbBlack );
   218 // CESMRViewerAlarmTimeField::ExecuteGenericCommandL()
   216         }
   219 // ---------------------------------------------------------------------------
       
   220 //
       
   221 TBool CESMRViewerAlarmTimeField::ExecuteGenericCommandL( TInt aCommand )
       
   222     {
       
   223     FUNC_LOG;
       
   224     
       
   225     TBool retValue( EFalse );
       
   226     
       
   227     if( (aCommand == EAknCmdOpen) && IsLocked()  )
       
   228     	{
       
   229 		HandleTactileFeedbackL();
       
   230     	
       
   231 		CESMRGlobalNote::ExecuteL(
       
   232     	                    CESMRGlobalNote::EESMRUnableToEdit );
       
   233     	retValue = ETrue;
       
   234     	}
       
   235     
       
   236     if ( EMRCmdDoEnvironmentChange == aCommand )
       
   237         {
       
   238         FormatAlarmTimeL();
       
   239         retValue = ETrue;
       
   240         }
       
   241     
       
   242     return retValue;
       
   243     }
       
   244 
       
   245 // ---------------------------------------------------------------------------
       
   246 // CESMRViewerAlarmTimeField::LockL()
       
   247 // ---------------------------------------------------------------------------
       
   248 //
       
   249 void CESMRViewerAlarmTimeField::LockL()
       
   250 	{
       
   251 	FUNC_LOG;
       
   252 	if( IsLocked() )
       
   253 		{
       
   254 		return;
       
   255 		}
       
   256 	
       
   257 	CESMRField::LockL();
       
   258 	
       
   259 	delete iLockIcon;
       
   260 	iLockIcon = NULL;
       
   261 	iLockIcon = CMRImage::NewL( NMRBitmapManager::EMRBitmapLockField, ETrue );
       
   262 	iLockIcon->SetParent( this );
       
   263 	}
       
   264 
       
   265 // ---------------------------------------------------------------------------
       
   266 // CESMRViewerAlarmTimeField::FormatAlarmTimeL
       
   267 // ---------------------------------------------------------------------------
       
   268 //
       
   269 void CESMRViewerAlarmTimeField::FormatAlarmTimeL()
       
   270     {
       
   271     FUNC_LOG;
       
   272     
       
   273     // Read format string from AVKON resource
       
   274     HBufC* dateFormatString =
       
   275         iEikonEnv->AllocReadResourceLC( R_QTN_TIME_USUAL_WITH_ZERO );
       
   276     HBufC* buf = HBufC::NewLC( KBufferLength );
       
   277     TPtr ptr( buf->Des() );
       
   278 
       
   279     iAlarmTime.FormatL( ptr, *dateFormatString );
       
   280     AknTextUtils::DisplayTextLanguageSpecificNumberConversion( ptr );
       
   281     iLabel->SetTextL( ptr );
       
   282     CleanupStack::PopAndDestroy( 2, dateFormatString );    
   217     }
   283     }
   218 // EOF
   284 // EOF
   219 
   285