meetingrequest/mrgui/mrfieldbuilderplugin/src/cesmrsubjectfield.cpp
changeset 0 8466d47a6819
child 16 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 subject field implementation
       
    15  *
       
    16 */
       
    17 
       
    18 #include "emailtrace.h"
       
    19 #include "cesmrsubjectfield.h"
       
    20 
       
    21 #include <calentry.h>
       
    22 #include <StringLoader.h>
       
    23 #include <gulfont.h>
       
    24 #include <AknsConstants.h>
       
    25 #include <AknUtils.h>
       
    26 #include <AknsDrawUtils.h>
       
    27 #include <AknsFrameBackgroundControlContext.h>
       
    28 #include "esmrfieldbuilderdef.h"
       
    29 
       
    30 #include <esmrgui.rsg>
       
    31 
       
    32 #include "cesmreditor.h"
       
    33 #include "mesmrtitlepaneobserver.h"
       
    34 #include "cesmrglobalnote.h"
       
    35 
       
    36 // ======== MEMBER FUNCTIONS ========
       
    37 
       
    38 // ---------------------------------------------------------------------------
       
    39 // CESMRSubjectField::CESMRSubjectField
       
    40 // ---------------------------------------------------------------------------
       
    41 //
       
    42 CESMRSubjectField::CESMRSubjectField( )
       
    43 :   CESMRIconField()
       
    44     {
       
    45     FUNC_LOG;
       
    46     //do nothing
       
    47     }
       
    48 
       
    49 // ---------------------------------------------------------------------------
       
    50 // CESMRSubjectField::~CESMRSubjectField
       
    51 // ---------------------------------------------------------------------------
       
    52 //
       
    53 CESMRSubjectField::~CESMRSubjectField( )
       
    54     {
       
    55     FUNC_LOG;
       
    56     delete iFrameBgContext;
       
    57     }
       
    58 
       
    59 // ---------------------------------------------------------------------------
       
    60 // CESMRSubjectField::ConstructL
       
    61 // ---------------------------------------------------------------------------
       
    62 //
       
    63 void CESMRSubjectField::ConstructL( TESMREntryFieldId aId, TInt aTextId,
       
    64         TAknsItemID aIconID )
       
    65     {
       
    66     FUNC_LOG;
       
    67     SetFieldId ( aId );
       
    68     SetExpandable ( );
       
    69 
       
    70     iSubject = CESMREditor::NewL ( this, 1, KMaxTextLength,
       
    71             CEikEdwin::EResizable | CEikEdwin::EAvkonEditor | EAknEditorFlagNoLRNavigation);
       
    72     iSubject->SetEdwinSizeObserver ( this );
       
    73     iSubject->SetEdwinObserver( this );
       
    74 
       
    75     HBufC* buf = StringLoader::LoadLC ( aTextId );
       
    76     iSubject->SetDefaultTextL( buf ); // ownership transferred
       
    77     CleanupStack::Pop( buf );
       
    78 
       
    79     iBackground = AknsDrawUtils::ControlContext( this );
       
    80 
       
    81     CESMRIconField::ConstructL ( aIconID, iSubject );
       
    82     }
       
    83 
       
    84 // ---------------------------------------------------------------------------
       
    85 // CESMRSubjectField::NewL
       
    86 // ---------------------------------------------------------------------------
       
    87 //
       
    88 CESMRSubjectField* CESMRSubjectField::NewL( TFieldType aType )
       
    89     {
       
    90     FUNC_LOG;
       
    91     CESMRSubjectField* self = new (ELeave) CESMRSubjectField;
       
    92     CleanupStack::PushL ( self );
       
    93     if ( aType == ETypeSubject )
       
    94         {
       
    95         self->ConstructL (EESMRFieldSubject,
       
    96         R_QTN_MEET_REQ_SUBJECT_FIELD,
       
    97         KAknsIIDQgnFscalIndiSubject );
       
    98         }
       
    99     else
       
   100         {
       
   101         self->ConstructL (EESMRFieldOccasion,
       
   102         R_QTN_CALENDAR_ANNIVERSARY_TYPE_OCCASION,
       
   103         KAknsIIDQgnFscalIndiOccasion );
       
   104         }
       
   105     CleanupStack::Pop ( self );
       
   106     return self;
       
   107     }
       
   108 
       
   109 // ---------------------------------------------------------------------------
       
   110 // CESMRSubjectField::InitializeL
       
   111 // ---------------------------------------------------------------------------
       
   112 //
       
   113 void CESMRSubjectField::InitializeL()
       
   114     {
       
   115     FUNC_LOG;
       
   116     iSubject->SetFontL( iLayout->Font( iCoeEnv, iFieldId ), iLayout );
       
   117     }
       
   118 
       
   119 // ---------------------------------------------------------------------------
       
   120 // CESMRSubjectField::InternalizeL
       
   121 // ---------------------------------------------------------------------------
       
   122 //
       
   123 void CESMRSubjectField::InternalizeL( MESMRCalEntry& aEntry )
       
   124     {
       
   125     FUNC_LOG;
       
   126     CCalEntry& entry = aEntry.Entry ( );
       
   127     HBufC* subject = entry.SummaryL().AllocLC ( );
       
   128 
       
   129     // if there is no text available, don't overwrite the default text
       
   130     // with empty descriptor.
       
   131     if ( subject->Length ( )> 0 )
       
   132         {
       
   133         iSubject->ClearSelectionAndSetTextL ( *subject );
       
   134         if ( iTitlePaneObserver )
       
   135             {
       
   136             iTitlePaneObserver->UpdateTitlePaneTextL( *subject );
       
   137             }
       
   138         }
       
   139 
       
   140     // this is needed to be re-called here, otherwise the CEikEdwin
       
   141     // does not get correctly instantiated with default text
       
   142     iSubject->FocusChanged(EDrawNow);
       
   143 
       
   144     CleanupStack::PopAndDestroy ( subject );
       
   145     }
       
   146 
       
   147 // ---------------------------------------------------------------------------
       
   148 // CESMRSubjectField::ExternalizeL
       
   149 // ---------------------------------------------------------------------------
       
   150 //
       
   151 void CESMRSubjectField::ExternalizeL( MESMRCalEntry& aEntry )
       
   152     {
       
   153     FUNC_LOG;
       
   154     HBufC* subject = iSubject->GetTextInHBufL ( );
       
   155 
       
   156     if ( subject )
       
   157         {
       
   158         CleanupStack::PushL ( subject );
       
   159 
       
   160         // externalize the text only if it differs from the
       
   161         // default text. In other words, default text is not
       
   162         // externalized.
       
   163 
       
   164        if ( iSubject->DefaultText().Compare (*subject )!= 0 )
       
   165             {
       
   166             CCalEntry& entry = aEntry.Entry ( );
       
   167             entry.SetSummaryL ( *subject );
       
   168             }
       
   169 
       
   170        CleanupStack::PopAndDestroy ( subject );
       
   171         }
       
   172     else
       
   173         {
       
   174         CCalEntry& entry = aEntry.Entry ( );
       
   175         entry.SetSummaryL( KNullDesC );
       
   176         }
       
   177     }
       
   178 
       
   179 // ---------------------------------------------------------------------------
       
   180 // CESMRSubjectField::SetOutlineFocusL
       
   181 // ---------------------------------------------------------------------------
       
   182 //
       
   183 void CESMRSubjectField::SetOutlineFocusL( TBool aFocus )
       
   184     {
       
   185     FUNC_LOG;
       
   186     CESMRField::SetOutlineFocusL ( aFocus );
       
   187 
       
   188     if (aFocus) //Focus is gained on the field
       
   189         {
       
   190         ChangeMiddleSoftKeyL(EESMRCmdSaveMR,R_QTN_MSK_SAVE);
       
   191         }
       
   192     }
       
   193 
       
   194 // ---------------------------------------------------------------------------
       
   195 // CESMRSubjectField::ExpandedHeight
       
   196 // ---------------------------------------------------------------------------
       
   197 //
       
   198 TInt CESMRSubjectField::ExpandedHeight( ) const
       
   199     {
       
   200     FUNC_LOG;
       
   201     TInt height = iLayout->FieldSize( FieldId() ).iHeight;
       
   202     if( iSize.iHeight < height )
       
   203         {
       
   204         return height - KEditorDifference;
       
   205         }
       
   206     else
       
   207         {
       
   208         return iSize.iHeight;
       
   209         }
       
   210     }
       
   211 
       
   212 // ---------------------------------------------------------------------------
       
   213 // CESMRSubjectField::HandleEdwinSizeEventL
       
   214 // ---------------------------------------------------------------------------
       
   215 //
       
   216 TBool CESMRSubjectField::HandleEdwinSizeEventL(CEikEdwin* /*aEdwin*/,
       
   217         TEdwinSizeEvent /*aType*/, TSize aSize )
       
   218     {
       
   219     FUNC_LOG;
       
   220     iSize = aSize;
       
   221     iSize.iHeight -= KEditorDifference;
       
   222 
       
   223     if (iLayout->CurrentFontZoom() == EAknUiZoomSmall ||
       
   224         iLayout->CurrentFontZoom() == EAknUiZoomVerySmall)
       
   225         {
       
   226         iSize.iHeight -= KEditorDifference;
       
   227         }
       
   228 
       
   229     if ( iObserver )
       
   230         {
       
   231         iObserver->ControlSizeChanged ( this );
       
   232         }
       
   233 
       
   234     if( iFrameBgContext )
       
   235         {
       
   236         TRect visibleRect = CalculateVisibleRect( iSubject->Rect() );
       
   237         iFrameBgContext->SetFrameRects( visibleRect, visibleRect );
       
   238         }
       
   239 
       
   240     return ETrue;
       
   241     }
       
   242 
       
   243 // ---------------------------------------------------------------------------
       
   244 // CESMRSubjectField::HandleEdwinEventL
       
   245 // ---------------------------------------------------------------------------
       
   246 //
       
   247 void CESMRSubjectField::HandleEdwinEventL( CEikEdwin *aEdwin, TEdwinEvent aEventType )
       
   248     {
       
   249     FUNC_LOG;
       
   250     if ( iTitlePaneObserver &&
       
   251          aEdwin == iSubject &&
       
   252          aEventType == EEventTextUpdate )
       
   253         {
       
   254         HBufC* text = iSubject->GetTextInHBufL();
       
   255         if ( text )
       
   256             {
       
   257             CleanupStack::PushL( text );
       
   258             
       
   259             iTitlePaneObserver->UpdateTitlePaneTextL( *text );
       
   260             
       
   261             TInt textLength( text->Length() );
       
   262             if ( iSubject->GetLimitLength() <= textLength )
       
   263             	{
       
   264             	NotifyEventAsyncL( EESMRCmdSizeExceeded );
       
   265             	}  
       
   266             
       
   267             CleanupStack::PopAndDestroy( text );
       
   268             }
       
   269         else
       
   270             {
       
   271             iTitlePaneObserver->UpdateTitlePaneTextL( KNullDesC );
       
   272             }
       
   273         }
       
   274     }
       
   275 
       
   276 // ---------------------------------------------------------------------------
       
   277 // CESMRSubjectField::SetTitlePaneObserver
       
   278 // ---------------------------------------------------------------------------
       
   279 //
       
   280 void CESMRSubjectField::SetTitlePaneObserver( MESMRTitlePaneObserver* aObserver )
       
   281     {
       
   282     FUNC_LOG;
       
   283     iTitlePaneObserver = aObserver;
       
   284     }
       
   285 
       
   286 // ---------------------------------------------------------------------------
       
   287 // CESMRSubjectField::PositionChanged()
       
   288 // ---------------------------------------------------------------------------
       
   289 //
       
   290 void CESMRSubjectField::PositionChanged()
       
   291     {
       
   292     FUNC_LOG;
       
   293     CCoeControl::PositionChanged();
       
   294     if( iFrameBgContext )
       
   295         {
       
   296         TRect visibleRect = CalculateVisibleRect( iSubject->Rect() );
       
   297         iFrameBgContext->SetFrameRects( visibleRect, visibleRect );
       
   298         }
       
   299     }
       
   300 
       
   301 // ---------------------------------------------------------------------------
       
   302 // CESMRSubjectField::GetVerticalFocusPosition
       
   303 // ---------------------------------------------------------------------------
       
   304 //
       
   305 void CESMRSubjectField::GetMinimumVisibleVerticalArea(TInt& aUpper, TInt& aLower)
       
   306     {
       
   307     FUNC_LOG;
       
   308     aLower = iSubject->CurrentLineNumber() * iSubject->RowHeight();
       
   309     aUpper = aLower - iSubject->RowHeight();
       
   310     }
       
   311 // ---------------------------------------------------------------------------
       
   312 // CESMRSubjectField::ActivateL
       
   313 // ---------------------------------------------------------------------------
       
   314 //
       
   315 void CESMRSubjectField::ActivateL()
       
   316     {
       
   317     FUNC_LOG;
       
   318     CCoeControl::ActivateL();
       
   319     TRect rect(TPoint(iSubject->Position()), iSubject->Size());
       
   320     TRect inner(rect);
       
   321     TRect outer(rect);
       
   322 
       
   323     iSubject->SetSize( TSize( iSubject->Size().iWidth, iLayout->FieldSize( FieldId() ).iHeight ));
       
   324 
       
   325     delete iFrameBgContext;
       
   326     iFrameBgContext = NULL;
       
   327     iFrameBgContext = CAknsFrameBackgroundControlContext::NewL( KAknsIIDQsnFrInput, outer, inner, EFalse ) ;
       
   328 
       
   329     iFrameBgContext->SetParentContext( iBackground );
       
   330     iSubject->SetSkinBackgroundControlContextL(iFrameBgContext);
       
   331 
       
   332     // update base class rects and redraw:
       
   333     SizeChanged();
       
   334     }
       
   335 
       
   336 // ---------------------------------------------------------------------------
       
   337 // CESMRSubjectField::ListObserverSet
       
   338 // ---------------------------------------------------------------------------
       
   339 //
       
   340 void CESMRSubjectField::ListObserverSet()
       
   341     {
       
   342     FUNC_LOG;
       
   343     iSubject->SetListObserver( iObserver );
       
   344     }
       
   345 
       
   346 // ---------------------------------------------------------------------------
       
   347 // CESMRSubjectField::ExecuteGenericCommandL
       
   348 // ---------------------------------------------------------------------------
       
   349 //
       
   350 void CESMRSubjectField::ExecuteGenericCommandL( 
       
   351 		TInt aCommand )
       
   352 	{
       
   353     FUNC_LOG;
       
   354 	if ( EESMRCmdSizeExceeded == aCommand )
       
   355 		{
       
   356 		CESMRGlobalNote::ExecuteL ( 
       
   357 				CESMRGlobalNote::EESMRCannotDisplayMuchMore );
       
   358 
       
   359 		HBufC* text = iSubject->GetTextInHBufL();
       
   360 		CleanupDeletePushL( text );
       
   361 		if ( text )
       
   362 			{    
       
   363 	    	TInt curPos = iSubject->CursorPos();    	
       
   364 	    	if( curPos > iSubject->GetLimitLength() - 1 )
       
   365 	    		curPos = iSubject->GetLimitLength() - 1;
       
   366 	    	HBufC* newText = 
       
   367 	    		text->Des().Mid( 0, iSubject->GetLimitLength() - 1 ).AllocLC();    	
       
   368 	    	
       
   369 	    	iSubject->SetTextL ( newText );
       
   370 	    	CleanupStack::PopAndDestroy( newText );
       
   371 	    	newText = NULL;
       
   372 	    	
       
   373 	    	iSubject->SetCursorPosL (curPos, EFalse );
       
   374 	    	iSubject->HandleTextChangedL();
       
   375 	    	iSubject->UpdateScrollBarsL();
       
   376 	    	SetFocus(ETrue);
       
   377 			}
       
   378 		CleanupStack::PopAndDestroy( text );	
       
   379 		}
       
   380 	}
       
   381 // EOF