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