meetingrequest/mrgui/mrfieldbuilderplugin/src/cesmrviewerstopdatefield.cpp
branchRCL_3
changeset 12 4ce476e64c59
parent 0 8466d47a6819
child 16 b5fbb9b25d57
equal deleted inserted replaced
11:0396474f30f5 12:4ce476e64c59
     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".
    16 */
    16 */
    17 
    17 
    18 #include "cesmrviewerstopdatefield.h"
    18 #include "cesmrviewerstopdatefield.h"
    19 #include "cesmreditor.h"
    19 #include "cesmreditor.h"
    20 #include "mesmrlistobserver.h"
    20 #include "mesmrlistobserver.h"
    21 #include "emailtrace.h"
       
    22 #include "nmrlayoutmanager.h"
    21 #include "nmrlayoutmanager.h"
    23 #include "cmrlabel.h"
    22 #include "cmrlabel.h"
    24 #include "cmrimage.h"
    23 #include "cmrimage.h"
    25 #include "nmrbitmapmanager.h"
    24 #include "nmrbitmapmanager.h"
       
    25 #include "emailtrace.h"
       
    26 #include "cesmrglobalnote.h"
    26 
    27 
    27 #include <esmrgui.rsg>
    28 #include <esmrgui.rsg>
    28 #include <AknUtils.h>
    29 #include <aknutils.h>
    29 #include <eiklabel.h>
    30 #include <eiklabel.h>
    30 #include <caluser.h>
    31 #include <caluser.h>
    31 #include <calalarm.h>
    32 #include <calalarm.h>
    32 #include <avkon.rsg>
    33 #include <avkon.rsg>
    33 #include <calentry.h>
    34 #include <calentry.h>
    34 #include <eikenv.h>
    35 #include <eikenv.h>
    35 #include <eikedwin.h>
    36 #include <eikedwin.h>
    36 #include <StringLoader.h>
    37 #include <stringloader.h>
    37 #include <AknsConstants.h>
    38 #include <aknsconstants.h>
    38 #include "esmrfieldbuilderdef.h"
    39 #include "esmrfieldbuilderdef.h"
    39 
    40 
    40 // ======== LOCAL FUNCTIONS ========
    41 // ======== LOCAL FUNCTIONS ========
    41 namespace // codescanner::namespace
    42 namespace
    42     {
    43     { // codescanner::namespace
    43     const TInt KComponentCount( 2 ); // icon and label
    44 
       
    45 const TInt KComponentCount( 2 ); // icon and label
       
    46 const TInt KMaxTimeBuffer( 32 ); // buffer for date formatting    
       
    47 
    44     } // unnamed namespace
    48     } // unnamed namespace
    45 
    49 
    46 // ======== MEMBER FUNCTIONS ========
    50 // ======== MEMBER FUNCTIONS ========
    47 
    51 
    48 // ---------------------------------------------------------------------------
    52 // ---------------------------------------------------------------------------
    51 //
    55 //
    52 CESMRViewerStopDateField::CESMRViewerStopDateField()
    56 CESMRViewerStopDateField::CESMRViewerStopDateField()
    53     {
    57     {
    54     FUNC_LOG;
    58     FUNC_LOG;
    55     SetFieldId ( EESMRFieldStopDate );
    59     SetFieldId ( EESMRFieldStopDate );
    56     SetFocusType( EESMRHighlightFocus );     
    60     SetFocusType( EESMRHighlightFocus );
    57     }
    61     }
    58 
    62 
    59 // ---------------------------------------------------------------------------
    63 // ---------------------------------------------------------------------------
    60 // CESMRViewerStopDateField::~CESMRViewerStopDateField
    64 // CESMRViewerStopDateField::~CESMRViewerStopDateField
    61 // ---------------------------------------------------------------------------
    65 // ---------------------------------------------------------------------------
    62 //
    66 //
    63 CESMRViewerStopDateField::~CESMRViewerStopDateField()
    67 CESMRViewerStopDateField::~CESMRViewerStopDateField()
    64     {
    68     {
    65     FUNC_LOG;
    69     FUNC_LOG;
    66     delete iLabel;
       
    67     delete iIcon;
    70     delete iIcon;
       
    71     delete iLockIcon;
    68     }
    72     }
    69 
    73 
    70 // ---------------------------------------------------------------------------
    74 // ---------------------------------------------------------------------------
    71 // CESMRViewerStopDateField::NewL
    75 // CESMRViewerStopDateField::NewL
    72 // ---------------------------------------------------------------------------
    76 // ---------------------------------------------------------------------------
    88 //
    92 //
    89 void CESMRViewerStopDateField::ConstructL()
    93 void CESMRViewerStopDateField::ConstructL()
    90     {
    94     {
    91     iLabel = CMRLabel::NewL();
    95     iLabel = CMRLabel::NewL();
    92     iLabel->SetParent( this );
    96     iLabel->SetParent( this );
       
    97     CESMRField::ConstructL( iLabel ); // ownership transfered
       
    98 
    93     iIcon = CMRImage::NewL( NMRBitmapManager::EMRBitmapDateEnd );
    99     iIcon = CMRImage::NewL( NMRBitmapManager::EMRBitmapDateEnd );
    94     iIcon->SetParent( this );    
   100     iIcon->SetParent( this );
    95     }
   101     }
    96 
   102 
    97 // ---------------------------------------------------------------------------
   103 // ---------------------------------------------------------------------------
    98 // CESMRViewerStartDateField::InitializeL()
   104 // CESMRViewerStartDateField::InitializeL()
    99 // ---------------------------------------------------------------------------
   105 // ---------------------------------------------------------------------------
   100 //
   106 //
   101 void CESMRViewerStopDateField::InitializeL()
   107 void CESMRViewerStopDateField::InitializeL()
   102     {
   108     {
   103     TAknLayoutText text = NMRLayoutManager::GetLayoutText( 
   109     TAknLayoutText text = NMRLayoutManager::GetLayoutText(
   104             Rect(), 
   110             Rect(),
   105             NMRLayoutManager::EMRTextLayoutTextEditor );
   111             NMRLayoutManager::EMRTextLayoutTextEditor );
   106     
   112 
   107     iLabel->SetFont( text.Font() );
   113     iLabel->SetFont( text.Font() );
   108     // This is called so that theme changes will apply when changing theme "on the fly"
   114     // This is called so that theme changes will apply when changing theme "on the fly"
   109     if ( IsFocused() )
   115     if ( IsFocused() )
   110         {
   116         {
   111         iLabel->FocusChanged( EDrawNow );
   117         iLabel->FocusChanged( EDrawNow );
   112         }
   118         }
   113 
       
   114     AknLayoutUtils::OverrideControlColorL ( *iLabel, EColorLabelText,
       
   115                                              KRgbBlack );
       
   116 }
   119 }
   117 
   120 
   118 // ---------------------------------------------------------------------------
   121 // ---------------------------------------------------------------------------
   119 // CESMRViewerStopDateField::InternalizeL
   122 // CESMRViewerStopDateField::InternalizeL
   120 // ---------------------------------------------------------------------------
   123 // ---------------------------------------------------------------------------
   143     	  (aEntry.Entry().EntryTypeL() == CCalEntry::EEvent ) )&&
   146     	  (aEntry.Entry().EntryTypeL() == CCalEntry::EEvent ) )&&
   144         ( startDate.Year() == endDate.Year() ) &&
   147         ( startDate.Year() == endDate.Year() ) &&
   145         ( startDate.Month() == endDate.Month() ) &&
   148         ( startDate.Month() == endDate.Month() ) &&
   146         ( startDate.Day() == endDate.Day() ) )
   149         ( startDate.Day() == endDate.Day() ) )
   147         {
   150         {
   148         iObserver->RemoveControl( FieldId() );
   151         iObserver->HideControl( FieldId() );
   149         }
   152         }
   150     else // else set the text for end time label
   153     else // else set the text for end time label
   151         {
   154         {
   152         // Read format string from AVKON resource
   155         // Read format string from AVKON resource
   153         HBufC* dateFormatString =
   156         iStopTime = endTime;
   154             iEikonEnv->AllocReadResourceLC( R_QTN_DATE_USUAL_WITH_ZERO );
   157         FormatDateStringL();
   155         HBufC* buf = HBufC::NewLC( KBufferLength );
       
   156         TPtr ptr( buf->Des() );
       
   157 
       
   158         endTime.FormatL( ptr, *dateFormatString );
       
   159         AknTextUtils::DisplayTextLanguageSpecificNumberConversion( ptr );
       
   160         iLabel->SetTextL( ptr );
       
   161         CleanupStack::PopAndDestroy( 2, dateFormatString );
       
   162         }
   158         }
   163     }
   159     }
   164 // ---------------------------------------------------------------------------
   160 // ---------------------------------------------------------------------------
   165 // CESMRViewerStopDateField::SizeChanged()
   161 // CESMRViewerStopDateField::SizeChanged()
   166 // ---------------------------------------------------------------------------
   162 // ---------------------------------------------------------------------------
   169     {
   165     {
   170     TRect rect = Rect();
   166     TRect rect = Rect();
   171     TAknLayoutRect rowLayoutRect =
   167     TAknLayoutRect rowLayoutRect =
   172         NMRLayoutManager::GetFieldRowLayoutRect( rect, 1 );
   168         NMRLayoutManager::GetFieldRowLayoutRect( rect, 1 );
   173     rect = rowLayoutRect.Rect();
   169     rect = rowLayoutRect.Rect();
   174     
   170 
   175     TAknWindowComponentLayout iconLayout =
   171     TAknWindowComponentLayout iconLayout =
   176         NMRLayoutManager::GetWindowComponentLayout( 
   172         NMRLayoutManager::GetWindowComponentLayout(
   177                 NMRLayoutManager::EMRLayoutTextEditorIcon );
   173                 NMRLayoutManager::EMRLayoutTextEditorIcon );
   178     AknLayoutUtils::LayoutImage( iIcon, rect, iconLayout );
   174     AknLayoutUtils::LayoutImage( iIcon, rect, iconLayout );
   179     
   175 
   180     TAknLayoutRect bgLayoutRect = NMRLayoutManager::GetLayoutRect( rect, NMRLayoutManager::EMRLayoutTextEditorBg );
   176     // Layouting lock icon
   181     TRect bgRect( bgLayoutRect.Rect() );
   177     if( iLockIcon )
       
   178     	{
       
   179     	TAknWindowComponentLayout iconLayout( 
       
   180     			NMRLayoutManager::GetWindowComponentLayout( 
       
   181     					NMRLayoutManager::EMRLayoutSingleRowDColumnGraphic ) );
       
   182     	AknLayoutUtils::LayoutImage( iLockIcon, rect, iconLayout );
       
   183     	}
       
   184         
       
   185     // Layouting label
       
   186     TAknLayoutText viewerLayoutText;
       
   187     if( iLockIcon )
       
   188     	{
       
   189     	viewerLayoutText = NMRLayoutManager::GetLayoutText( rect, 
       
   190     			NMRLayoutManager::EMRTextLayoutSingleRowEditorText );
       
   191     	}
       
   192     else
       
   193     	{
       
   194     	viewerLayoutText = NMRLayoutManager::GetLayoutText( rect, 
       
   195     			NMRLayoutManager::EMRTextLayoutTextEditor );
       
   196     	}
       
   197 
       
   198     TRect viewerRect( viewerLayoutText.TextRect() );    
       
   199     iLabel->SetRect( viewerRect );
       
   200 
   182     // Move focus rect so that it's relative to field's position.
   201     // Move focus rect so that it's relative to field's position.
   183     bgRect.Move( -Position() );
   202     viewerRect.Move( -Position() );
   184     SetFocusRect( bgRect );
   203     SetFocusRect( viewerRect );
   185        
   204 
   186     TAknLayoutText labelLayout = 
   205     // Setting font also for the label
   187         NMRLayoutManager::GetLayoutText( 
   206     iLabel->SetFont( viewerLayoutText.Font() );
   188                 rect, NMRLayoutManager::EMRTextLayoutTextEditor );
       
   189     iLabel->SetRect( labelLayout.TextRect() );
       
   190     }
   207     }
   191 
   208 
   192 // ---------------------------------------------------------------------------
   209 // ---------------------------------------------------------------------------
   193 // CESMRViewerStopDateField::CountComponentControls()
   210 // CESMRViewerStopDateField::CountComponentControls()
   194 // ---------------------------------------------------------------------------
   211 // ---------------------------------------------------------------------------
   195 //
   212 //
   196 TInt CESMRViewerStopDateField::CountComponentControls() const
   213 TInt CESMRViewerStopDateField::CountComponentControls() const
   197     {
   214     {
   198     TInt count( KComponentCount );
   215     TInt count( KComponentCount );
       
   216     if( iLockIcon )
       
   217     	{
       
   218     	++count;
       
   219     	}
   199     return count;
   220     return count;
   200     }
   221     }
   201 
   222 
   202 // ---------------------------------------------------------------------------
   223 // ---------------------------------------------------------------------------
   203 // CESMRViewerStopDateField::ComponentControl()
   224 // CESMRViewerStopDateField::ComponentControl()
   209         {
   230         {
   210         case 0:
   231         case 0:
   211             return iIcon;
   232             return iIcon;
   212         case 1:
   233         case 1:
   213             return iLabel;
   234             return iLabel;
       
   235         case 2:
       
   236         	return iLockIcon;
   214         default:
   237         default:
   215             return NULL;
   238             return NULL;
   216         }
   239         }
   217     }
   240     }
   218 
   241 
   221 // ---------------------------------------------------------------------------
   244 // ---------------------------------------------------------------------------
   222 //
   245 //
   223 void CESMRViewerStopDateField::SetOutlineFocusL( TBool aFocus )
   246 void CESMRViewerStopDateField::SetOutlineFocusL( TBool aFocus )
   224     {
   247     {
   225     CESMRField::SetOutlineFocusL ( aFocus );
   248     CESMRField::SetOutlineFocusL ( aFocus );
   226     
   249 
   227     iLabel->SetFocus( aFocus );    
   250     iLabel->SetFocus( aFocus );
   228 
   251     }
   229     if ( !aFocus )
   252 
   230         {
   253 // ---------------------------------------------------------------------------
   231         AknLayoutUtils::OverrideControlColorL ( *iLabel, EColorLabelText,
   254 // CESMRViewerStopDateField::ExecuteGenericCommandL()
   232                                                  KRgbBlack );
   255 // ---------------------------------------------------------------------------
   233         }
   256 //
   234     }
   257 TBool CESMRViewerStopDateField::ExecuteGenericCommandL( TInt aCommand )
       
   258     {
       
   259     FUNC_LOG;
       
   260     
       
   261     TBool retValue( EFalse );
       
   262     
       
   263     if( (aCommand == EAknCmdOpen) && IsLocked()  )
       
   264     	{
       
   265 		HandleTactileFeedbackL();
       
   266 		
       
   267     	CESMRGlobalNote::ExecuteL(
       
   268     			CESMRGlobalNote::EESMRUnableToEdit );
       
   269     	retValue = ETrue;
       
   270     	}
       
   271     
       
   272     if ( EMRCmdDoEnvironmentChange == aCommand )
       
   273         {
       
   274         FormatDateStringL();
       
   275         retValue = ETrue;
       
   276         }
       
   277     
       
   278     return retValue;
       
   279     }
       
   280 
       
   281 // ---------------------------------------------------------------------------
       
   282 // CESMRViewerStopDateField::LockL()
       
   283 // ---------------------------------------------------------------------------
       
   284 //
       
   285 void CESMRViewerStopDateField::LockL()
       
   286 	{
       
   287 	FUNC_LOG;
       
   288 	if( IsLocked() )
       
   289 		{
       
   290 		return;
       
   291 		}
       
   292 	
       
   293 	CESMRField::LockL();
       
   294 	
       
   295 	delete iLockIcon;
       
   296 	iLockIcon = NULL;
       
   297 	iLockIcon = CMRImage::NewL( NMRBitmapManager::EMRBitmapLockField, ETrue );
       
   298 	iLockIcon->SetParent( this );
       
   299 	}
       
   300 
       
   301 // ---------------------------------------------------------------------------
       
   302 // CESMRViewerStopDateField::FormatDateStringL()
       
   303 // ---------------------------------------------------------------------------
       
   304 //
       
   305 void CESMRViewerStopDateField::FormatDateStringL()
       
   306     {
       
   307     FUNC_LOG;
       
   308     
       
   309     // Read format string from AVKON resource
       
   310     HBufC* dateFormatString = 
       
   311             iEikonEnv->AllocReadResourceLC(
       
   312                     R_QTN_DATE_USUAL_WITH_ZERO);
       
   313     
       
   314     TBuf<KMaxTimeBuffer> buf;
       
   315     iStopTime.FormatL(buf, *dateFormatString);
       
   316 
       
   317     AknTextUtils::DisplayTextLanguageSpecificNumberConversion( buf );
       
   318     iLabel->SetTextL( buf );
       
   319     CleanupStack::PopAndDestroy( dateFormatString );    
       
   320     }
       
   321 
   235 // EOF
   322 // EOF
   236