meetingrequest/mrgui/mrfieldbuildercommon/src/cesmrfield.cpp
branchRCL_3
changeset 25 3533d4323edc
equal deleted inserted replaced
24:d189ee25cf9d 25:3533d4323edc
       
     1 /*
       
     2 * Copyright (c) 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 policy implementation
       
    15 *
       
    16 */
       
    17 
       
    18 #include "cesmrfield.h"
       
    19 
       
    20 #include "esmrcommands.h"
       
    21 #include "nmrlayoutmanager.h"
       
    22 #include "mesmrfieldeventqueue.h"
       
    23 #include "cesmrfieldcommandevent.h"
       
    24 #include "cmrbackground.h"
       
    25 #include "esmrcommands.h"
       
    26 #include "cmrrecordinggc.h"
       
    27 
       
    28 #include "emailtrace.h"
       
    29 
       
    30 #include <txtrich.h>
       
    31 #include <eikenv.h>
       
    32 #include <baclipb.h>
       
    33 #include <eikbtgpc.h>
       
    34 #include <StringLoader.h>
       
    35 #include <AknUtils.h>
       
    36 #include <touchfeedback.h>
       
    37 
       
    38 namespace
       
    39 {
       
    40 // Off-screen x coordinate for fields
       
    41 const TInt KOffScreenPositionX = 1000;
       
    42 }
       
    43 
       
    44 // ======== MEMBER FUNCTIONS ========
       
    45 
       
    46 // ---------------------------------------------------------------------------
       
    47 // CESMRField::CESMRField
       
    48 // ---------------------------------------------------------------------------
       
    49 //
       
    50 EXPORT_C CESMRField::CESMRField()
       
    51     : iCustomMsk( EFalse ),
       
    52       iDisableRedraw( EFalse ),
       
    53       iDefaultMskVisible( EFalse ),
       
    54       iMskVisible( EFalse ),
       
    55       iLocked( EFalse )
       
    56     {
       
    57     FUNC_LOG;
       
    58     // do nothing
       
    59     }
       
    60 
       
    61 
       
    62 // ---------------------------------------------------------------------------
       
    63 // CESMRField::~CESMRField
       
    64 // ---------------------------------------------------------------------------
       
    65 //
       
    66 EXPORT_C CESMRField::~CESMRField()
       
    67     {
       
    68     FUNC_LOG;
       
    69     delete iExtControl;
       
    70     if ( iEventQueue )
       
    71         {
       
    72         iEventQueue->RemoveObserver( this );
       
    73         }
       
    74     delete iBackground;
       
    75     delete iRecordingGc;
       
    76     }
       
    77 
       
    78 // ---------------------------------------------------------------------------
       
    79 // CESMRField::ConstructL
       
    80 // ---------------------------------------------------------------------------
       
    81 //
       
    82 EXPORT_C void CESMRField::ConstructL(
       
    83         CCoeControl* aControl )
       
    84     {
       
    85     FUNC_LOG;
       
    86     iExtControl = aControl;
       
    87 
       
    88     iBackground = CMRBackground::NewL();
       
    89     this->SetBackground( iBackground );
       
    90     iRecordingGc = new( ELeave ) CMRRecordingGc( SystemGc() );
       
    91     }
       
    92 
       
    93 // ---------------------------------------------------------------------------
       
    94 // CESMRField::InitializeL
       
    95 // ---------------------------------------------------------------------------
       
    96 //
       
    97 EXPORT_C void CESMRField::InitializeL()
       
    98     {
       
    99     FUNC_LOG;
       
   100     /* Empty implementation, subclasses should overwrite */
       
   101     }
       
   102 
       
   103 // ---------------------------------------------------------------------------
       
   104 // CESMRField::FontChangedL
       
   105 // ---------------------------------------------------------------------------
       
   106 //
       
   107 EXPORT_C void CESMRField::FontChangedL()
       
   108     {
       
   109     FUNC_LOG;
       
   110     // This method re-initializes field
       
   111     InitializeL();
       
   112     }
       
   113 
       
   114 // ---------------------------------------------------------------------------
       
   115 // CESMRField::SetFieldId
       
   116 // ---------------------------------------------------------------------------
       
   117 //
       
   118 EXPORT_C void CESMRField::SetFieldId( TESMREntryFieldId aFieldId )
       
   119     {
       
   120     FUNC_LOG;
       
   121     iFieldId = aFieldId;
       
   122     }
       
   123 
       
   124 
       
   125 // ---------------------------------------------------------------------------
       
   126 // CESMRField::SetPreItemIndex
       
   127 // ---------------------------------------------------------------------------
       
   128 //
       
   129 EXPORT_C void CESMRField::SetPreItemIndex( TInt aPreItemIndex )
       
   130     {
       
   131     FUNC_LOG;
       
   132     iPreItemIndex = aPreItemIndex;
       
   133     }
       
   134 
       
   135 
       
   136 // ---------------------------------------------------------------------------
       
   137 // CESMRField::SetCurrentItemIndex
       
   138 // ---------------------------------------------------------------------------
       
   139 //
       
   140 EXPORT_C void CESMRField::SetCurrentItemIndex( TInt aCurrentItemIndex )
       
   141     {
       
   142     FUNC_LOG;
       
   143     iCurrentItemIndex = aCurrentItemIndex;
       
   144     }
       
   145 
       
   146 // ---------------------------------------------------------------------------
       
   147 // CESMRField::FieldId
       
   148 // ---------------------------------------------------------------------------
       
   149 //
       
   150 EXPORT_C TESMREntryFieldId CESMRField::FieldId() const
       
   151     {
       
   152     FUNC_LOG;
       
   153     return iFieldId;
       
   154     }
       
   155 
       
   156 // ---------------------------------------------------------------------------
       
   157 // CESMRField::PreItemIndex
       
   158 // ---------------------------------------------------------------------------
       
   159 //
       
   160 EXPORT_C TInt CESMRField::PreItemIndex() const
       
   161     {
       
   162     FUNC_LOG;
       
   163     return iPreItemIndex;
       
   164     }
       
   165 
       
   166 // ---------------------------------------------------------------------------
       
   167 // CESMRField::CurrentItemIndex
       
   168 // ---------------------------------------------------------------------------
       
   169 //
       
   170 EXPORT_C TInt CESMRField::CurrentItemIndex() const
       
   171     {
       
   172     FUNC_LOG;
       
   173     return iCurrentItemIndex;
       
   174     }
       
   175 
       
   176 // ---------------------------------------------------------------------------
       
   177 // CESMRField::SizeChanged
       
   178 // ---------------------------------------------------------------------------
       
   179 //
       
   180 EXPORT_C void CESMRField::SizeChanged()
       
   181     {
       
   182     FUNC_LOG;
       
   183     TRect rect( Rect() );
       
   184     if ( iExtControl )
       
   185         {
       
   186         iExtControl->SetRect( rect );
       
   187         }
       
   188     }
       
   189 
       
   190 // ---------------------------------------------------------------------------
       
   191 // CESMRField::CountComponentControls
       
   192 // ---------------------------------------------------------------------------
       
   193 //
       
   194 EXPORT_C TInt CESMRField::CountComponentControls() const
       
   195     {
       
   196     FUNC_LOG;
       
   197     TInt count( 0 );
       
   198     if ( iExtControl )
       
   199     	{
       
   200         ++count;
       
   201     	}
       
   202 
       
   203     return count;
       
   204     }
       
   205 
       
   206 // ---------------------------------------------------------------------------
       
   207 // CESMRField::ComponentControl
       
   208 // ---------------------------------------------------------------------------
       
   209 //
       
   210 EXPORT_C CCoeControl* CESMRField::ComponentControl( TInt /*aInd*/ ) const
       
   211     {
       
   212     FUNC_LOG;
       
   213     return iExtControl;
       
   214     }
       
   215 
       
   216 // ---------------------------------------------------------------------------
       
   217 // CESMRField::MinimumSize
       
   218 // ---------------------------------------------------------------------------
       
   219 //
       
   220 EXPORT_C TSize CESMRField::MinimumSize()
       
   221     {
       
   222     TRect parentRect( Parent()->Rect() );
       
   223     TAknLayoutRect listareaLayoutRect =
       
   224         NMRLayoutManager::GetLayoutRect( parentRect, NMRLayoutManager::EMRLayoutListArea );
       
   225     TAknLayoutRect fieldLayoutRect =
       
   226         NMRLayoutManager::GetFieldLayoutRect( listareaLayoutRect.Rect(), 1 );
       
   227     return TSize( Parent()->Size().iWidth, fieldLayoutRect.Rect().Height() );
       
   228     }
       
   229 
       
   230 // ---------------------------------------------------------------------------
       
   231 // CESMRField::Draw
       
   232 // ---------------------------------------------------------------------------
       
   233 //
       
   234 EXPORT_C void CESMRField::Draw( const TRect& aRect ) const
       
   235     {
       
   236     FUNC_LOG;
       
   237 
       
   238     // Draw only if field is not on screen
       
   239     if ( Position().iX != Parent()->Position().iX )
       
   240         {
       
   241         // Flush cached drawing commands from custom graphics context
       
   242         iRecordingGc->FlushBuffer( aRect );
       
   243         }
       
   244 
       
   245     }
       
   246 
       
   247 // ---------------------------------------------------------------------------
       
   248 // CESMRField::HandlePointerEventL
       
   249 // ---------------------------------------------------------------------------
       
   250 //
       
   251 EXPORT_C void CESMRField::HandlePointerEventL(
       
   252         const TPointerEvent& aPointerEvent )
       
   253     {
       
   254     FUNC_LOG;
       
   255     // Sanity check that pointer event occurs in field area
       
   256     if ( Rect().Contains( aPointerEvent.iPosition ) )
       
   257         {
       
   258         if ( aPointerEvent.iType == TPointerEvent::EButton1Up )
       
   259             {
       
   260             if ( !HandleSingletapEventL( aPointerEvent.iPosition ) )
       
   261                 {
       
   262                 // Provide raw pointer event to field
       
   263                 HandleRawPointerEventL( aPointerEvent );
       
   264                 }
       
   265             }
       
   266         else // Provide other pointer events to fields
       
   267             {
       
   268             if ( !HandleRawPointerEventL( aPointerEvent ) )
       
   269                 {
       
   270                 // Provide pointer events to child components if field
       
   271                 // did not already consume the event
       
   272                 CCoeControl::HandlePointerEventL( aPointerEvent );
       
   273                 }
       
   274             }
       
   275         }
       
   276     }
       
   277 
       
   278 // ---------------------------------------------------------------------------
       
   279 // CESMRField::SetContainerWindowL
       
   280 // ---------------------------------------------------------------------------
       
   281 //
       
   282 EXPORT_C void CESMRField::SetContainerWindowL(const CCoeControl& aContainer)
       
   283     {
       
   284     FUNC_LOG;
       
   285 
       
   286     // Use container window from aContainer
       
   287     // This will set also aContainer as MOP parent and CCoeControl parent
       
   288     CCoeControl::SetContainerWindowL( aContainer );
       
   289 
       
   290     // Set this same window and this as parent for component controls
       
   291     TInt count( CountComponentControls() );
       
   292 
       
   293     for ( TInt i = 0; i < count; ++i )
       
   294         {
       
   295         ComponentControl( i )->SetContainerWindowL( *this );
       
   296         }
       
   297     }
       
   298 
       
   299 // ---------------------------------------------------------------------------
       
   300 // CESMRField::SetListObserver
       
   301 // ---------------------------------------------------------------------------
       
   302 //
       
   303 EXPORT_C void CESMRField::SetListObserver( MESMRListObserver* aObserver )
       
   304     {
       
   305     FUNC_LOG;
       
   306     iObserver = aObserver;
       
   307     ListObserverSet();
       
   308     }
       
   309 
       
   310 // ---------------------------------------------------------------------------
       
   311 // CESMRField::ListObserverSet
       
   312 // ---------------------------------------------------------------------------
       
   313 //
       
   314 EXPORT_C void CESMRField::ListObserverSet()
       
   315     {
       
   316     FUNC_LOG;
       
   317     // default implementation.
       
   318     }
       
   319 
       
   320 // ---------------------------------------------------------------------------
       
   321 // CESMRField::OfferKeyEventL
       
   322 // ---------------------------------------------------------------------------
       
   323 //
       
   324 EXPORT_C TKeyResponse CESMRField::OfferKeyEventL(
       
   325 		const TKeyEvent& aEvent, TEventCode aType )
       
   326     {
       
   327     FUNC_LOG;
       
   328 
       
   329     TKeyResponse response( EKeyWasNotConsumed );
       
   330 
       
   331     if ( iExtControl )
       
   332         {
       
   333         response = iExtControl->OfferKeyEventL( aEvent, aType );
       
   334         }
       
   335 
       
   336     // If key event was not consumed, and it is the Enter,
       
   337     // let's execute generic command Open
       
   338     if ( response == EKeyWasNotConsumed
       
   339          && aType == EEventKey
       
   340          && ( aEvent.iCode == EKeyEnter
       
   341               || aEvent.iScanCode == EStdKeyEnter ) )
       
   342         {
       
   343         ExecuteGenericCommandL( EAknCmdOpen );
       
   344         }
       
   345 
       
   346     return response;
       
   347     }
       
   348 
       
   349 // ---------------------------------------------------------------------------
       
   350 // CESMRField::SetOutlineFocusL
       
   351 // ---------------------------------------------------------------------------
       
   352 //
       
   353 EXPORT_C void CESMRField::SetOutlineFocusL( TBool aFocus )
       
   354     {
       
   355     FUNC_LOG;
       
   356     iOutlineFocus = aFocus;
       
   357 
       
   358     if ( iExtControl )
       
   359         {
       
   360         iExtControl->SetFocus( aFocus );
       
   361         }
       
   362     if ( aFocus )
       
   363         {
       
   364         CEikButtonGroupContainer* cba = CEikButtonGroupContainer::Current();
       
   365         if ( cba )
       
   366             {
       
   367             iDefaultMskVisible = cba->IsCommandVisibleByPosition(
       
   368                     CEikButtonGroupContainer::EMiddleSoftkeyPosition );
       
   369             iMskVisible = iDefaultMskVisible;
       
   370             }
       
   371         }
       
   372     else
       
   373         {
       
   374         RestoreMiddleSoftKeyL();
       
   375         }
       
   376     }
       
   377 
       
   378 // ---------------------------------------------------------------------------
       
   379 // CESMRField::OkToLoseFocusL
       
   380 // ---------------------------------------------------------------------------
       
   381 //
       
   382 EXPORT_C TBool CESMRField::OkToLoseFocusL( // codescanner::LFunctionCantLeave
       
   383         TESMREntryFieldId /*aNextItem*/ )
       
   384     {
       
   385     FUNC_LOG;
       
   386     return ETrue;
       
   387     }
       
   388 
       
   389 // ---------------------------------------------------------------------------
       
   390 // CESMRField::GetMinimumVisibleVerticalArea
       
   391 // ---------------------------------------------------------------------------
       
   392 //
       
   393 EXPORT_C void CESMRField::GetMinimumVisibleVerticalArea(
       
   394 		TInt& aUpper, TInt& aLower)
       
   395     {
       
   396     FUNC_LOG;
       
   397     aUpper = 0;
       
   398     aLower = Rect().iBr.iY - Rect().iTl.iY;
       
   399     }
       
   400 
       
   401 // ---------------------------------------------------------------------------
       
   402 // CESMRField::GetCursorLineVerticalPos
       
   403 // ---------------------------------------------------------------------------
       
   404 //
       
   405 EXPORT_C void CESMRField::GetCursorLineVerticalPos(TInt& aUpper, TInt& aLower)
       
   406     {
       
   407     FUNC_LOG;
       
   408     aUpper = 0;
       
   409     aLower = Rect().iBr.iY - Rect().iTl.iY;
       
   410     }
       
   411 
       
   412 // ---------------------------------------------------------------------------
       
   413 // CESMRField::InternalizeL
       
   414 // ---------------------------------------------------------------------------
       
   415 //
       
   416 EXPORT_C void CESMRField::InternalizeL( // codescanner::LFunctionCantLeave
       
   417         MESMRCalEntry& /*aEntry*/ )
       
   418     {
       
   419     FUNC_LOG;
       
   420     /* Empty implementation, subclasses should overwrite */
       
   421     }
       
   422 
       
   423 // ---------------------------------------------------------------------------
       
   424 // CESMRField::ExternalizeL
       
   425 // ---------------------------------------------------------------------------
       
   426 //
       
   427 EXPORT_C void CESMRField::ExternalizeL( // codescanner::LFunctionCantLeave
       
   428         MESMRCalEntry& /*aEntry*/ )
       
   429     {
       
   430     FUNC_LOG;
       
   431     /* Empty implementation, subclasses should overwrite */
       
   432     }
       
   433 
       
   434 // ---------------------------------------------------------------------------
       
   435 // CESMRField::ExecuteGenericCommandL
       
   436 // ---------------------------------------------------------------------------
       
   437 //
       
   438 EXPORT_C TBool CESMRField::ExecuteGenericCommandL( TInt /*aCommand*/ )
       
   439     {
       
   440     FUNC_LOG;
       
   441     return EFalse;
       
   442     /* Subclasses should overwrite */
       
   443     }
       
   444 
       
   445 // ---------------------------------------------------------------------------
       
   446 // CESMRField::LongtapDetectedL
       
   447 // ---------------------------------------------------------------------------
       
   448 //
       
   449 EXPORT_C void CESMRField::LongtapDetectedL( const TPoint& aPosition )
       
   450     {
       
   451     FUNC_LOG;
       
   452 
       
   453     HandleLongtapEventL( aPosition );
       
   454     }
       
   455 
       
   456 // ---------------------------------------------------------------------------
       
   457 // CESMRField::SetTitlePaneObserver
       
   458 // ---------------------------------------------------------------------------
       
   459 //
       
   460 EXPORT_C void CESMRField::SetTitlePaneObserver(
       
   461 		MESMRTitlePaneObserver* /*aObserver*/ )
       
   462     {
       
   463     FUNC_LOG;
       
   464     /* Empty implementation, subclasses should overwrite */
       
   465     }
       
   466 
       
   467 // ---------------------------------------------------------------------------
       
   468 // CESMRField::ChangeMiddleSoftKeyL
       
   469 // ---------------------------------------------------------------------------
       
   470 //
       
   471 EXPORT_C void CESMRField::ChangeMiddleSoftKeyL(
       
   472         TInt aCommandId,
       
   473         TInt aResourceId )
       
   474     {
       
   475     FUNC_LOG;
       
   476 
       
   477     if ( AknLayoutUtils::MSKEnabled() )
       
   478         {
       
   479         CEikButtonGroupContainer* cba = CEikButtonGroupContainer::Current();
       
   480         if ( cba )
       
   481             {
       
   482             HBufC* middleSKText = StringLoader::LoadLC( aResourceId,
       
   483                                                         iCoeEnv );
       
   484             cba->SetCommandL(
       
   485                     CEikButtonGroupContainer::EMiddleSoftkeyPosition,
       
   486                     aCommandId, *middleSKText );
       
   487             CleanupStack::PopAndDestroy( middleSKText );
       
   488             if ( !iMskVisible )
       
   489                 {
       
   490                 cba->MakeCommandVisibleByPosition(
       
   491                         CEikButtonGroupContainer::EMiddleSoftkeyPosition,
       
   492                         ETrue );
       
   493                 iMskVisible = ETrue;
       
   494                 }
       
   495             cba->DrawDeferred();
       
   496             iCustomMsk = ETrue;
       
   497             }
       
   498         }
       
   499     }
       
   500 
       
   501 // ---------------------------------------------------------------------------
       
   502 // CESMRField::SetValidatorL
       
   503 // ---------------------------------------------------------------------------
       
   504 //
       
   505 EXPORT_C void CESMRField::SetValidatorL( MESMRFieldValidator* aValidator )
       
   506     {
       
   507     FUNC_LOG;
       
   508 
       
   509     iValidator = aValidator;
       
   510     }
       
   511 
       
   512 // ---------------------------------------------------------------------------
       
   513 // CESMRField::IsFieldActivated
       
   514 // ---------------------------------------------------------------------------
       
   515 //
       
   516 EXPORT_C TBool CESMRField::IsFieldActivated() const
       
   517     {
       
   518     FUNC_LOG;
       
   519 
       
   520     return IsActivated();
       
   521     }
       
   522 
       
   523 // ---------------------------------------------------------------------------
       
   524 // CESMRField::DynInitMenuPaneL
       
   525 // ---------------------------------------------------------------------------
       
   526 //
       
   527 EXPORT_C void CESMRField::DynInitMenuPaneL(
       
   528         TInt /*aResourceId*/,
       
   529         CEikMenuPane* /*aMenuPane*/ )
       
   530     {
       
   531     FUNC_LOG;
       
   532     }
       
   533 
       
   534 // ---------------------------------------------------------------------------
       
   535 // CESMRField::ChangeMiddleSoftKeyL
       
   536 // ---------------------------------------------------------------------------
       
   537 //
       
   538 EXPORT_C void CESMRField::ChangeMiddleSoftKeyL( TInt aResourceId )
       
   539     {
       
   540     FUNC_LOG;
       
   541 
       
   542     if ( AknLayoutUtils::MSKEnabled() )
       
   543         {
       
   544         CEikButtonGroupContainer* cba = CEikButtonGroupContainer::Current();
       
   545         if ( cba )
       
   546             {
       
   547             cba->SetCommandL(
       
   548                     CEikButtonGroupContainer::EMiddleSoftkeyPosition,
       
   549                     aResourceId );
       
   550             if ( !iMskVisible )
       
   551                 {
       
   552                 cba->MakeCommandVisibleByPosition(
       
   553                         CEikButtonGroupContainer::EMiddleSoftkeyPosition,
       
   554                         ETrue );
       
   555                 iMskVisible = ETrue;
       
   556                 }
       
   557             cba->DrawDeferred();
       
   558             iCustomMsk = ETrue;
       
   559             }
       
   560         }
       
   561     }
       
   562 
       
   563 // ---------------------------------------------------------------------------
       
   564 // CESMRField::SetEventQueueL
       
   565 // ---------------------------------------------------------------------------
       
   566 //
       
   567 EXPORT_C void CESMRField::SetEventQueueL( MESMRFieldEventQueue* aEventQueue )
       
   568     {
       
   569     FUNC_LOG;
       
   570     if ( aEventQueue != iEventQueue )
       
   571         {
       
   572         if ( aEventQueue )
       
   573             {
       
   574             // Add self to new queue
       
   575             aEventQueue->AddObserverL( this );
       
   576             }
       
   577 
       
   578         if ( iEventQueue )
       
   579             {
       
   580             // Remove self from old queue
       
   581             iEventQueue->RemoveObserver( this );
       
   582             }
       
   583 
       
   584         iEventQueue = aEventQueue;
       
   585         }
       
   586     }
       
   587 
       
   588 // ---------------------------------------------------------------------------
       
   589 // CESMRField::HasOutlineFocus
       
   590 // ---------------------------------------------------------------------------
       
   591 //
       
   592 EXPORT_C TBool CESMRField::HasOutlineFocus() const
       
   593     {
       
   594     FUNC_LOG;
       
   595     return iOutlineFocus;
       
   596     }
       
   597 
       
   598 // ---------------------------------------------------------------------------
       
   599 // CESMRField::GetFocusRect
       
   600 // ---------------------------------------------------------------------------
       
   601 //
       
   602 EXPORT_C TRect CESMRField::GetFocusRect() const
       
   603     {
       
   604     FUNC_LOG;
       
   605     return iFocusRect;
       
   606     }
       
   607 
       
   608 // ---------------------------------------------------------------------------
       
   609 // CESMRField::SetFocusRect
       
   610 // ---------------------------------------------------------------------------
       
   611 //
       
   612 EXPORT_C void CESMRField::SetFocusRect( const TRect& aFocusRect )
       
   613     {
       
   614     FUNC_LOG;
       
   615     iFocusRect = aFocusRect;
       
   616     }
       
   617 
       
   618 // ---------------------------------------------------------------------------
       
   619 // CESMRField::GetFocusType
       
   620 // ---------------------------------------------------------------------------
       
   621 //
       
   622 EXPORT_C TESMRFieldFocusType CESMRField::GetFocusType() const
       
   623     {
       
   624     FUNC_LOG;
       
   625     return iFocusType;
       
   626     }
       
   627 
       
   628 // ---------------------------------------------------------------------------
       
   629 // CESMRField::SetFocusType
       
   630 // ---------------------------------------------------------------------------
       
   631 //
       
   632 EXPORT_C void CESMRField::SetFocusType( TESMRFieldFocusType aFocusType )
       
   633     {
       
   634     FUNC_LOG;
       
   635     iFocusType = aFocusType;
       
   636     }
       
   637 
       
   638 // ---------------------------------------------------------------------------
       
   639 // CESMRField::NotifyEventL
       
   640 // ---------------------------------------------------------------------------
       
   641 //
       
   642 EXPORT_C void CESMRField::NotifyEventL( const MESMRFieldEvent& aEvent )
       
   643     {
       
   644     FUNC_LOG;
       
   645     if ( iEventQueue )
       
   646         {
       
   647         iEventQueue->NotifyEventL( aEvent );
       
   648         }
       
   649     }
       
   650 
       
   651 // ---------------------------------------------------------------------------
       
   652 // CESMRField::NotifyEventL
       
   653 // ---------------------------------------------------------------------------
       
   654 //
       
   655 EXPORT_C void CESMRField::NotifyEventL( TInt aCommand )
       
   656     {
       
   657     FUNC_LOG;
       
   658     CESMRFieldCommandEvent* event = CESMRFieldCommandEvent::NewLC( this,
       
   659                                                                    aCommand );
       
   660     NotifyEventL( *event );
       
   661     CleanupStack::PopAndDestroy( event );
       
   662     }
       
   663 
       
   664 // ---------------------------------------------------------------------------
       
   665 // CESMRField::NotifyEventAsyncL
       
   666 // ---------------------------------------------------------------------------
       
   667 //
       
   668 EXPORT_C void CESMRField::NotifyEventAsyncL( MESMRFieldEvent* aEvent )
       
   669     {
       
   670     FUNC_LOG;
       
   671     if ( iEventQueue )
       
   672         {
       
   673         iEventQueue->NotifyEventAsyncL( aEvent );
       
   674         }
       
   675     }
       
   676 
       
   677 // ---------------------------------------------------------------------------
       
   678 // CESMRField::NotifyEventAsyncL
       
   679 // ---------------------------------------------------------------------------
       
   680 //
       
   681 EXPORT_C void CESMRField::NotifyEventAsyncL( TInt aCommand )
       
   682     {
       
   683     FUNC_LOG;
       
   684     CESMRFieldCommandEvent* event = CESMRFieldCommandEvent::NewLC( this,
       
   685                                                                    aCommand );
       
   686     NotifyEventAsyncL( event );
       
   687     CleanupStack::Pop( event );
       
   688     }
       
   689 
       
   690 // ---------------------------------------------------------------------------
       
   691 // CESMRField::RestoreMiddleSoftKeyL
       
   692 // ---------------------------------------------------------------------------
       
   693 //
       
   694 EXPORT_C void CESMRField::RestoreMiddleSoftKeyL()
       
   695     {
       
   696     FUNC_LOG;
       
   697     if ( AknLayoutUtils::MSKEnabled() )
       
   698         {
       
   699         if ( iMskVisible != iDefaultMskVisible )
       
   700             {
       
   701             SetMiddleSoftKeyVisible( iDefaultMskVisible );
       
   702             }
       
   703 
       
   704         if ( iCustomMsk )
       
   705             {
       
   706             NotifyEventL( EESMRCmdRestoreMiddleSoftKey );
       
   707             iCustomMsk = EFalse;
       
   708             }
       
   709         }
       
   710     }
       
   711 
       
   712 // ---------------------------------------------------------------------------
       
   713 // CESMRField::SetMiddleSoftKeyVisible
       
   714 // ---------------------------------------------------------------------------
       
   715 //
       
   716 EXPORT_C void CESMRField::SetMiddleSoftKeyVisible( TBool aVisible )
       
   717     {
       
   718     FUNC_LOG;
       
   719     if ( AknLayoutUtils::MSKEnabled() )
       
   720         {
       
   721         if ( iMskVisible != aVisible )
       
   722             {
       
   723             CEikButtonGroupContainer* cba = CEikButtonGroupContainer::Current();
       
   724             if ( cba )
       
   725                 {
       
   726                 cba->MakeCommandVisibleByPosition(
       
   727                         CEikButtonGroupContainer::EMiddleSoftkeyPosition,
       
   728                         aVisible );
       
   729                 iMskVisible = aVisible; // Visibility has been changed
       
   730                 }
       
   731             }
       
   732 
       
   733         iCustomMsk = ETrue; // Field has modified editor default MSK
       
   734         }
       
   735     }
       
   736 
       
   737 // ---------------------------------------------------------------------------
       
   738 // CESMRField::HandleLongtapEventL
       
   739 // ---------------------------------------------------------------------------
       
   740 //
       
   741 EXPORT_C void CESMRField::HandleLongtapEventL( const TPoint& /*aPosition*/ )
       
   742     {
       
   743     FUNC_LOG;
       
   744     // Default action for long tap event.
       
   745     ExecuteGenericCommandL( EESMRCmdLongtapDetected );
       
   746     }
       
   747 
       
   748 // ---------------------------------------------------------------------------
       
   749 // CESMRField::HandleSingletapEventL
       
   750 // ---------------------------------------------------------------------------
       
   751 //
       
   752 EXPORT_C TBool CESMRField::HandleSingletapEventL( const TPoint& /*aPosition*/ )
       
   753     {
       
   754     FUNC_LOG;
       
   755     // Subclasses may override for field specific actions
       
   756     return EFalse;
       
   757     }
       
   758 
       
   759 // ---------------------------------------------------------------------------
       
   760 // CESMRField::HandleRawPointerEventL
       
   761 // Default implementation for pointer event handling in field
       
   762 // ---------------------------------------------------------------------------
       
   763 //
       
   764 EXPORT_C TBool CESMRField::HandleRawPointerEventL(
       
   765         const TPointerEvent& aPointerEvent )
       
   766     {
       
   767     FUNC_LOG;
       
   768 
       
   769     if ( aPointerEvent.iType == TPointerEvent::EButton1Up )
       
   770         {
       
   771 		// Default action for touch release
       
   772 		if ( !ExecuteGenericCommandL( EAknCmdOpen ) )
       
   773 			{
       
   774 			// If the base class implementation does not use the command
       
   775 			// then the pointer event is propagated to children.
       
   776 			CCoeControl::HandlePointerEventL( aPointerEvent );
       
   777 			}
       
   778         }
       
   779     else
       
   780         {
       
   781         // Propagate the pointer event to child components
       
   782         CCoeControl::HandlePointerEventL( aPointerEvent );
       
   783         }
       
   784 
       
   785     return ETrue;
       
   786     }
       
   787 
       
   788 // ---------------------------------------------------------------------------
       
   789 // CESMRField::HandleFieldEventL
       
   790 // ---------------------------------------------------------------------------
       
   791 //
       
   792 EXPORT_C void CESMRField::HandleFieldEventL( const MESMRFieldEvent& aEvent )
       
   793     {
       
   794     FUNC_LOG;
       
   795     if ( aEvent.Type() == MESMRFieldEvent::EESMRFieldCommandEvent )
       
   796         {
       
   797         TInt* command = static_cast<TInt*>( aEvent.Param( 0 ) );
       
   798         if ( EESMRCmdSizeExceeded != *command )
       
   799         	{
       
   800             ExecuteGenericCommandL( *command );
       
   801             }
       
   802         }
       
   803     }
       
   804 
       
   805 // ---------------------------------------------------------------------------
       
   806 // CESMRField::EventObserver
       
   807 // ---------------------------------------------------------------------------
       
   808 //
       
   809 EXPORT_C MESMRFieldEventObserver* CESMRField::EventObserver() const
       
   810     {
       
   811     FUNC_LOG;
       
   812     return const_cast< CESMRField* >( this );
       
   813     }
       
   814 
       
   815 // ---------------------------------------------------------------------------
       
   816 // CESMRField::SetFieldMode
       
   817 // ---------------------------------------------------------------------------
       
   818 //
       
   819 EXPORT_C void CESMRField::SetFieldMode( TESMRFieldMode aMode )
       
   820     {
       
   821     FUNC_LOG;
       
   822     iFieldMode = aMode;
       
   823     }
       
   824 
       
   825 // ---------------------------------------------------------------------------
       
   826 // CESMRField::FieldMode
       
   827 // ---------------------------------------------------------------------------
       
   828 //
       
   829 EXPORT_C TESMRFieldMode CESMRField::FieldMode() const
       
   830     {
       
   831     FUNC_LOG;
       
   832     return iFieldMode;
       
   833     }
       
   834 
       
   835 // ---------------------------------------------------------------------------
       
   836 // CESMRField::SetFieldViewMode
       
   837 // ---------------------------------------------------------------------------
       
   838 //
       
   839 EXPORT_C void CESMRField::SetFieldViewMode( TESMRFieldType aViewMode )
       
   840     {
       
   841     FUNC_LOG;
       
   842     iFieldViewMode = aViewMode;
       
   843     }
       
   844 
       
   845 // ---------------------------------------------------------------------------
       
   846 // CESMRField::FieldViewMode
       
   847 // ---------------------------------------------------------------------------
       
   848 //
       
   849 EXPORT_C TESMRFieldType CESMRField::FieldViewMode() const
       
   850     {
       
   851     FUNC_LOG;
       
   852     return iFieldViewMode;
       
   853     }
       
   854 
       
   855 // ---------------------------------------------------------------------------
       
   856 // CESMRField::UpdateExtControlL
       
   857 // ---------------------------------------------------------------------------
       
   858 //
       
   859 EXPORT_C void CESMRField::UpdateExtControlL(
       
   860              CCoeControl* aControl )
       
   861     {
       
   862     FUNC_LOG;
       
   863     delete iExtControl;
       
   864     iExtControl = aControl;
       
   865 
       
   866     // Set also container window
       
   867     iExtControl->SetContainerWindowL( *this );
       
   868     }
       
   869 
       
   870 // ---------------------------------------------------------------------------
       
   871 // CESMRField::Lock
       
   872 // ---------------------------------------------------------------------------
       
   873 //
       
   874 EXPORT_C void CESMRField::LockL()
       
   875 	{
       
   876     FUNC_LOG;
       
   877 	iLocked = ETrue;
       
   878 	}
       
   879 
       
   880 // ---------------------------------------------------------------------------
       
   881 // CESMRField::IsLocked
       
   882 // ---------------------------------------------------------------------------
       
   883 //
       
   884 EXPORT_C TBool CESMRField::IsLocked()
       
   885 	{
       
   886     FUNC_LOG;
       
   887 	return iLocked;
       
   888 	}
       
   889 
       
   890 // ---------------------------------------------------------------------------
       
   891 // CESMRField::SupportsLongTapFunctionalityL
       
   892 // ---------------------------------------------------------------------------
       
   893 //
       
   894 EXPORT_C TBool CESMRField::SupportsLongTapFunctionalityL(
       
   895 		const TPointerEvent& /*aPointerEvent*/ )
       
   896 	{
       
   897     FUNC_LOG;
       
   898     // Subclasses may override for field specific actions
       
   899 	return EFalse;
       
   900 	}
       
   901 
       
   902 // ---------------------------------------------------------------------------
       
   903 // CESMRField::MoveToScreen
       
   904 // ---------------------------------------------------------------------------
       
   905 //
       
   906 EXPORT_C void CESMRField::MoveToScreen( TBool aVisible )
       
   907     {
       
   908     FUNC_LOG
       
   909 
       
   910     // Check that field is activated
       
   911     if ( IsActivated() )
       
   912         {
       
   913         TPoint pos( Position() );
       
   914 
       
   915         if ( aVisible )
       
   916             {
       
   917             // Set x coordinate to parent (field container) x coordinate
       
   918             pos.iX = Parent()->Position().iX;
       
   919             }
       
   920         else
       
   921             {
       
   922             // Move field outside screen
       
   923             pos.iX = KOffScreenPositionX;
       
   924             // Record field drawing commands
       
   925             RecordField();
       
   926             }
       
   927 
       
   928         if ( pos != Position() )
       
   929             {
       
   930             // Set new position only if it different from current one
       
   931             // Setting new position potentially causes relayout in field
       
   932             SetPosition( pos );
       
   933             }
       
   934         }
       
   935     }
       
   936 
       
   937 // ---------------------------------------------------------------------------
       
   938 // CESMRField::HandleTactileFeedbackL
       
   939 // ---------------------------------------------------------------------------
       
   940 //
       
   941 EXPORT_C void CESMRField::HandleTactileFeedbackL()
       
   942     {
       
   943     FUNC_LOG;
       
   944 
       
   945     AquireTactileFeedback();
       
   946 
       
   947     if ( iTactileFeedback && iTactileFeedback->FeedbackEnabledForThisApp() )
       
   948         {
       
   949         iTactileFeedback->InstantFeedback( ETouchFeedbackBasic );
       
   950         }
       
   951     }
       
   952 
       
   953 // ---------------------------------------------------------------------------
       
   954 // CESMRField::AquireTactileFeedback
       
   955 // ---------------------------------------------------------------------------
       
   956 //
       
   957 void CESMRField::AquireTactileFeedback()
       
   958     {
       
   959 	if( !iTactileFeedback )
       
   960 		{
       
   961 		// Aquire tactile feedback pointer from TLS
       
   962 		iTactileFeedback = MTouchFeedback::Instance();
       
   963 		}
       
   964     }
       
   965 
       
   966 // ---------------------------------------------------------------------------
       
   967 // CESMRField::RecordField
       
   968 // ---------------------------------------------------------------------------
       
   969 //
       
   970 EXPORT_C void CESMRField::RecordField()
       
   971     {
       
   972     FUNC_LOG;
       
   973 
       
   974     // Record only activated field
       
   975     if ( IsActivated() )
       
   976         {
       
   977         // Purge old draw commands
       
   978         iRecordingGc->PurgeBuffer();
       
   979 
       
   980         // Set recording graphics context to be used for drawing
       
   981         SetCustomGc( iRecordingGc );
       
   982 
       
   983         // Set gc origin to point (-x,-y)
       
   984         // This will cause drawing commands to be relative to point (0,0)
       
   985         iRecordingGc->SetOrigin( -iPosition );
       
   986 
       
   987         // Draw custom background if available
       
   988         const MCoeControlBackground* bg = Background();
       
   989         if ( bg )
       
   990             {
       
   991             bg->Draw( *iRecordingGc, *this, Rect() );
       
   992             }
       
   993 
       
   994         // Draw child controls
       
   995         DrawControl( this );
       
   996 
       
   997         // Reset custom gc
       
   998         SetCustomGc( NULL );
       
   999         }
       
  1000     }
       
  1001 
       
  1002 // ---------------------------------------------------------------------------
       
  1003 // CESMRField::DrawControl
       
  1004 // ---------------------------------------------------------------------------
       
  1005 //
       
  1006 void CESMRField::DrawControl( CCoeControl* aControl ) const
       
  1007     {
       
  1008     TInt count( aControl->CountComponentControls() );
       
  1009 
       
  1010     for ( TInt i = 0; i < count; ++i )
       
  1011         {
       
  1012         CCoeControl* control = aControl->ComponentControl( i );
       
  1013 
       
  1014         // Draw only non-window owning children
       
  1015         if ( !control->OwnsWindow() )
       
  1016             {
       
  1017             TRect rect( control->Rect() );
       
  1018 
       
  1019             // Draw control background if available
       
  1020             const MCoeControlBackground* bg = control->Background();
       
  1021             if ( bg )
       
  1022                 {
       
  1023                 bg->Draw( *iRecordingGc, *control, rect );
       
  1024                 }
       
  1025 
       
  1026             // Draw control foreground
       
  1027             control->DrawForeground( rect );
       
  1028 
       
  1029             // Draw child components
       
  1030             DrawControl( control );
       
  1031             }
       
  1032         }
       
  1033     }
       
  1034 
       
  1035 // EOF
       
  1036