meetingrequest/mrgui/mrfieldbuilderplugin/src/cesmrlocationfield.cpp
branchRCL_3
changeset 64 3533d4323edc
equal deleted inserted replaced
63:d189ee25cf9d 64: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 location field implementation
       
    15  *  Version     : %version: e002sa32#53.1.3 %
       
    16  *
       
    17  */
       
    18 
       
    19 
       
    20 #include "cesmrlocationfield.h"
       
    21 #include "esmrfieldbuilderdef.h"
       
    22 #include "cesmreditor.h"
       
    23 #include "cesmrfeaturesettings.h"
       
    24 #include "esmrhelper.h"
       
    25 #include "mesmrfieldevent.h"
       
    26 #include "cesmrgenericfieldevent.h"
       
    27 #include "cesmrglobalnote.h"
       
    28 #include "cmrbutton.h"
       
    29 #include "cmrlabel.h"
       
    30 #include "cmrimage.h"
       
    31 #include "nmrlayoutmanager.h"
       
    32 #include "nmrbitmapmanager.h"
       
    33 #include "cmrstyluspopupmenu.h"
       
    34 #include "mesmrlistobserver.h"
       
    35 
       
    36 #include <calentry.h>
       
    37 #include <StringLoader.h>
       
    38 #include <esmrgui.rsg>
       
    39 #include <data_caging_path_literals.hrh>
       
    40 #include <AknsBasicBackgroundControlContext.h>
       
    41 #include <eikmfne.h>
       
    42 #include <aknbutton.h>
       
    43 
       
    44 #include "emailtrace.h"
       
    45 #include "esmrconfig.hrh"
       
    46 
       
    47 // ======== MEMBER FUNCTIONS ========
       
    48 
       
    49 // ---------------------------------------------------------------------------
       
    50 // CESMRLocationField::NewL
       
    51 // ---------------------------------------------------------------------------
       
    52 //
       
    53 CESMRLocationField* CESMRLocationField::NewL()
       
    54     {
       
    55     FUNC_LOG;
       
    56     CESMRLocationField* self = new (ELeave) CESMRLocationField;
       
    57     CleanupStack::PushL( self );
       
    58     self->ConstructL();
       
    59     CleanupStack::Pop( self );
       
    60     return self;
       
    61     }
       
    62 
       
    63 // ---------------------------------------------------------------------------
       
    64 // CESMRLocationField::CESMRLocationField
       
    65 // ---------------------------------------------------------------------------
       
    66 //
       
    67 CESMRLocationField::CESMRLocationField()
       
    68     {
       
    69     FUNC_LOG;
       
    70     SetFieldId( EESMRFieldLocation );
       
    71     SetFocusType( EESMRHighlightFocus );
       
    72     }
       
    73 
       
    74 // ---------------------------------------------------------------------------
       
    75 // CESMRLocationField::ConstructL
       
    76 // ---------------------------------------------------------------------------
       
    77 //
       
    78 void CESMRLocationField::ConstructL()
       
    79     {
       
    80     FUNC_LOG;
       
    81 
       
    82     iFieldButton = CMRButton::NewL( NMRBitmapManager::EMRBitmapLocation );
       
    83     iFieldButton->SetParent( this );
       
    84 
       
    85     iTitle = CMRLabel::NewL();
       
    86     iTitle->SetParent( this );
       
    87     HBufC* title = StringLoader::LoadLC(
       
    88             R_MEET_REQ_OPTIONS_ADD_LOCATION,
       
    89             iCoeEnv );
       
    90     iTitle->SetTextL( *title );
       
    91     CleanupStack::PopAndDestroy( title );
       
    92 
       
    93     iLocation = CESMREditor::NewL( this,
       
    94                                    1,
       
    95                                    KMaxTextLength, //from ICAL spec.
       
    96                                    // do not change. other text fields do not
       
    97                                    // have this limitation
       
    98                                    CEikEdwin::EResizable |
       
    99                                    CEikEdwin::EAvkonEditor );
       
   100 
       
   101     CESMRField::ConstructL( iLocation ); //ownership transfered
       
   102 
       
   103     iLocation->SetEdwinSizeObserver( this );
       
   104     iLocation->SetEdwinObserver( this );
       
   105     iLocation->SetParent( this );
       
   106 
       
   107     HBufC* buf = StringLoader::LoadLC( R_QTN_MEET_REQ_LOCATION_FIELD, iCoeEnv );
       
   108     iLocation->SetDefaultTextL( buf ); // ownership is transferred
       
   109     CleanupStack::Pop( buf );
       
   110 
       
   111     // Setting background instead of theme skin
       
   112     NMRBitmapManager::TMRBitmapStruct bitmapStruct;
       
   113     bitmapStruct = NMRBitmapManager::GetBitmapStruct( NMRBitmapManager::EMRBitmapInputCenter );
       
   114 
       
   115     TRect initialisationRect( 0, 0, 0, 0 );
       
   116     iBgControlContext = CAknsBasicBackgroundControlContext::NewL(
       
   117                 bitmapStruct.iItemId,
       
   118                 initialisationRect,
       
   119                 EFalse );
       
   120 
       
   121     iLocation->SetSkinBackgroundControlContextL( iBgControlContext );
       
   122     }
       
   123 
       
   124 
       
   125 // ---------------------------------------------------------------------------
       
   126 // CESMRLocationField::~CESMRLocationField
       
   127 // ---------------------------------------------------------------------------
       
   128 //
       
   129 CESMRLocationField::~CESMRLocationField()
       
   130     {
       
   131     FUNC_LOG;
       
   132     delete iFieldButton;
       
   133     delete iWaypointIcon;
       
   134     delete iFeatures;
       
   135     delete iLocationText;
       
   136     delete iBgControlContext;
       
   137     delete iMenu;
       
   138     delete iTitle;
       
   139     }
       
   140 
       
   141 // ---------------------------------------------------------------------------
       
   142 // CESMRLocationField::MinimumSize
       
   143 // ---------------------------------------------------------------------------
       
   144 //
       
   145 TSize CESMRLocationField::MinimumSize()
       
   146     {
       
   147     TRect parentRect( Parent()->Rect() );
       
   148 
       
   149     TRect richTextRect =
       
   150        NMRLayoutManager::GetFieldLayoutRect( parentRect, 1 ).Rect();
       
   151 
       
   152     TRect textRect( NMRLayoutManager::GetLayoutText(
       
   153             richTextRect,
       
   154        NMRLayoutManager::EMRTextLayoutTextEditor ).TextRect() );
       
   155 
       
   156     // Adjust field size so that there's room for expandable editor.
       
   157     richTextRect.Resize( 0, iSize.iHeight - textRect.Height() );
       
   158 
       
   159     // Add title area to the required size
       
   160     TSize titleSize( CESMRField::MinimumSize() );
       
   161 
       
   162     TSize completeFieldSize( titleSize );
       
   163     completeFieldSize.iHeight += richTextRect.Height();
       
   164 
       
   165     return completeFieldSize;
       
   166     }
       
   167 
       
   168 // ---------------------------------------------------------------------------
       
   169 // CESMRLocationField::InitializeL
       
   170 // ---------------------------------------------------------------------------
       
   171 //
       
   172 void CESMRLocationField::InitializeL()
       
   173     {
       
   174     FUNC_LOG;
       
   175     // Do nothing
       
   176     }
       
   177 
       
   178 // ---------------------------------------------------------------------------
       
   179 // CESMRLocationField::InternalizeL
       
   180 // ---------------------------------------------------------------------------
       
   181 //
       
   182 void CESMRLocationField::InternalizeL( MESMRCalEntry& aEntry )
       
   183     {
       
   184     FUNC_LOG;
       
   185     CCalEntry& entry = aEntry.Entry();
       
   186     HBufC* location = entry.LocationL().AllocLC();
       
   187 
       
   188     // if there is no text available, don't overwrite the default text
       
   189     // with empty descriptor.
       
   190     if ( location->Length() > 0 )
       
   191         {
       
   192         iLocation->ClearSelectionAndSetTextL( *location );
       
   193         }
       
   194 
       
   195     CleanupStack::PopAndDestroy( location );
       
   196 
       
   197     // If the geo value has been set, the waypoint icon has to be shown on right
       
   198     // side of the location field
       
   199     CCalGeoValue* geoValue = aEntry.Entry().GeoValueL();
       
   200     TReal dummy;
       
   201     SetWaypointIconL( geoValue && geoValue->GetLatLong( dummy, dummy ) );
       
   202 
       
   203     // this is needed to be re-called here, otherwise the CEikEdwin
       
   204     // does not get correctly instantiated with default text
       
   205     iLocation->FocusChanged( EDrawNow );
       
   206     }
       
   207 
       
   208 // ---------------------------------------------------------------------------
       
   209 // CESMRLocationField::ExternalizeL
       
   210 // ---------------------------------------------------------------------------
       
   211 //
       
   212 void CESMRLocationField::ExternalizeL( MESMRCalEntry& aEntry )
       
   213     {
       
   214     FUNC_LOG;
       
   215     HBufC* loc = iLocation->GetTextInHBufL( );
       
   216 
       
   217     if ( loc )
       
   218         {
       
   219         CleanupStack::PushL( loc );
       
   220 
       
   221         // externalize the text only if it differs from the
       
   222         // default text. In other words, default text is not
       
   223         // externalized.
       
   224         HBufC* defaultText = StringLoader::LoadLC(
       
   225                 R_QTN_MEET_REQ_LOCATION_FIELD,
       
   226                 iCoeEnv );
       
   227         if ( defaultText->Compare( *loc ) != 0 )
       
   228             {
       
   229             CCalEntry& entry = aEntry.Entry();
       
   230             entry.SetLocationL( *loc );
       
   231             }
       
   232         else if ( !iWaypointIcon )
       
   233             {
       
   234             aEntry.Entry().ClearGeoValueL();
       
   235             }
       
   236 
       
   237         CleanupStack::PopAndDestroy( defaultText );
       
   238         CleanupStack::PopAndDestroy( loc );
       
   239         }
       
   240     else
       
   241         {
       
   242         CCalEntry& entry = aEntry.Entry();
       
   243         entry.SetLocationL( KNullDesC );
       
   244         entry.ClearGeoValueL();
       
   245         }
       
   246     }
       
   247 
       
   248 // ---------------------------------------------------------------------------
       
   249 // CESMRLocationField::SetOutlineFocusL
       
   250 // ---------------------------------------------------------------------------
       
   251 //
       
   252 void CESMRLocationField::SetOutlineFocusL( TBool aFocus )
       
   253     {
       
   254     FUNC_LOG;
       
   255     CESMRField::SetOutlineFocusL ( aFocus );
       
   256 
       
   257     if ( FeaturesL().FeatureSupported(
       
   258             CESMRFeatureSettings::EESMRUILocationFeatures ) )
       
   259         {
       
   260         if ( aFocus )
       
   261             {
       
   262             ChangeMiddleSoftKeyL( EAknSoftkeyContextOptions, R_QTN_MSK_OPEN );
       
   263             }
       
   264         else
       
   265             {
       
   266             if ( iLocationText )
       
   267                 {
       
   268                 delete iLocationText;
       
   269                 iLocationText = NULL;
       
   270                 }
       
   271             iLocationText = iLocation->GetTextInHBufL();
       
   272 
       
   273             HBufC* defaultText = StringLoader::LoadLC(
       
   274                     R_QTN_MEET_REQ_LOCATION_FIELD,
       
   275                     iCoeEnv );
       
   276 
       
   277             if ( iLocationText && iLocationText->Compare( *defaultText ) != 0 )
       
   278                 {
       
   279                 // Create field change event
       
   280                 CESMRGenericFieldEvent* event = CESMRGenericFieldEvent::NewLC(
       
   281                         this,
       
   282                         MESMRFieldEvent::EESMRFieldChangeEvent );
       
   283 
       
   284                 // Add this field as parameter
       
   285                 TInt fieldId = iFieldId;
       
   286                 CESMRFieldEventValue* field = CESMRFieldEventValue::NewLC(
       
   287                         MESMRFieldEventValue::EESMRInteger,
       
   288                         &fieldId );
       
   289                 event->AddParamL( field );
       
   290                 CleanupStack::Pop( field );
       
   291 
       
   292                 // Add new value as parameter
       
   293                 CESMRFieldEventValue* value = CESMRFieldEventValue::NewLC(
       
   294                         CESMRFieldEventValue::EESMRString,
       
   295                         iLocationText );
       
   296                 iLocationText = NULL; // Ownership transferred to value
       
   297                 // Encapsulate value, so receiver gets the field value type
       
   298                 event->AddParamL( value, ETrue );
       
   299                 CleanupStack::Pop( value );
       
   300 
       
   301                 // Send event
       
   302                 NotifyEventAsyncL( event );
       
   303                 CleanupStack::Pop( event );
       
   304                 }
       
   305             CleanupStack::PopAndDestroy( defaultText );
       
   306             }
       
   307         }
       
   308     }
       
   309 
       
   310 // ---------------------------------------------------------------------------
       
   311 // CESMRLocationField::HandleEdwinSizeEventL
       
   312 // ---------------------------------------------------------------------------
       
   313 //
       
   314 TBool CESMRLocationField::HandleEdwinSizeEventL( CEikEdwin* aEdwin,
       
   315         TEdwinSizeEvent /*aType*/, TSize aSize )
       
   316     {
       
   317     FUNC_LOG;
       
   318     TBool reDraw( EFalse );
       
   319 
       
   320     if( iSize != aSize )
       
   321         {
       
   322         // Let's save the required size for the iLocation
       
   323         iSize = aSize;
       
   324 
       
   325         if ( iObserver && aEdwin == iLocation )
       
   326            {
       
   327            iObserver->ControlSizeChanged( this );
       
   328            reDraw = ETrue;
       
   329            }
       
   330 
       
   331         if( iLocation->LineCount() != iLineCount )
       
   332             {
       
   333             // Line count has changed, the whole component needs
       
   334             // to be redrawn
       
   335             DrawDeferred();
       
   336             iLineCount = iLocation->LineCount();
       
   337             }
       
   338         }
       
   339 
       
   340     return reDraw;
       
   341     }
       
   342 
       
   343 // ---------------------------------------------------------------------------
       
   344 // CESMRLocationField::HandleEdwinEventL
       
   345 // ---------------------------------------------------------------------------
       
   346 //
       
   347 void CESMRLocationField::HandleEdwinEventL(CEikEdwin* aEdwin, TEdwinEvent aEventType)
       
   348     {
       
   349     FUNC_LOG;
       
   350     if ( aEdwin == iLocation && aEventType == EEventTextUpdate )
       
   351         {
       
   352         TInt textLength( iLocation->TextLength() );
       
   353 
       
   354         if ( iLocation->GetLimitLength() <= textLength )
       
   355             {
       
   356             NotifyEventAsyncL( EESMRCmdSizeExceeded );
       
   357             }
       
   358         else if ( iWaypointIcon && textLength == 0 )
       
   359             {
       
   360             SetWaypointIconL( EFalse );
       
   361             NotifyEventL( EESMRCmdDisableWaypointIcon );
       
   362             }
       
   363         }
       
   364     }
       
   365 
       
   366 // ---------------------------------------------------------------------------
       
   367 // CESMRLocationField::GetCursorLineVerticalPos
       
   368 // ---------------------------------------------------------------------------
       
   369 //
       
   370 void CESMRLocationField::GetCursorLineVerticalPos(TInt& aUpper, TInt& aLower)
       
   371     {
       
   372     aLower = iLocation->CurrentLineNumber() * iLocation->RowHeight();
       
   373     aUpper = aLower - iLocation->RowHeight();
       
   374     }
       
   375 
       
   376 // ---------------------------------------------------------------------------
       
   377 // CESMRLocationField::ListObserverSet
       
   378 // ---------------------------------------------------------------------------
       
   379 //
       
   380 void CESMRLocationField::ListObserverSet()
       
   381     {
       
   382     FUNC_LOG;
       
   383     iLocation->SetListObserver( iObserver );
       
   384     }
       
   385 
       
   386 // ---------------------------------------------------------------------------
       
   387 // CESMRLocationField::ListObserverSet
       
   388 // ---------------------------------------------------------------------------
       
   389 //
       
   390 CESMRFeatureSettings& CESMRLocationField::FeaturesL()
       
   391     {
       
   392     FUNC_LOG;
       
   393     if ( !iFeatures )
       
   394         {
       
   395         iFeatures = CESMRFeatureSettings::NewL();
       
   396         }
       
   397 
       
   398     return *iFeatures;
       
   399     }
       
   400 
       
   401 // ---------------------------------------------------------------------------
       
   402 // CESMRLocationField::SetWaypointIconL
       
   403 // ---------------------------------------------------------------------------
       
   404 //
       
   405 void CESMRLocationField::SetWaypointIconL( TBool aEnabled )
       
   406     {
       
   407     delete iWaypointIcon;
       
   408     iWaypointIcon = NULL;
       
   409 
       
   410     if ( aEnabled )
       
   411         {
       
   412         iWaypointIcon = CMRImage::NewL(
       
   413                 NMRBitmapManager::EMRBitmapLocationWaypoint,
       
   414                 this,
       
   415                 ETrue );
       
   416         }
       
   417 
       
   418     SizeChanged();
       
   419     }
       
   420 
       
   421 // ---------------------------------------------------------------------------
       
   422 // CESMRLocationField::CountComponentControls
       
   423 // ---------------------------------------------------------------------------
       
   424 //
       
   425 TInt CESMRLocationField::CountComponentControls( ) const
       
   426     {
       
   427     FUNC_LOG;
       
   428     TInt count( 0 );
       
   429     if( iFieldButton )
       
   430         {
       
   431         ++count;
       
   432         }
       
   433 
       
   434     if ( iTitle )
       
   435         {
       
   436         ++count;
       
   437         }
       
   438 
       
   439     if( iLocation )
       
   440         {
       
   441         ++count;
       
   442         }
       
   443 
       
   444     if( iWaypointIcon )
       
   445         {
       
   446         ++count;
       
   447         }
       
   448 
       
   449     return count;
       
   450     }
       
   451 
       
   452 // ---------------------------------------------------------------------------
       
   453 // CESMRLocationField::ComponentControl
       
   454 // ---------------------------------------------------------------------------
       
   455 //
       
   456 CCoeControl* CESMRLocationField::ComponentControl( TInt aInd ) const
       
   457     {
       
   458     FUNC_LOG;
       
   459 
       
   460     switch ( aInd )
       
   461         {
       
   462         case 0:
       
   463             return iFieldButton;
       
   464         case 1:
       
   465             return iTitle;
       
   466         case 2:
       
   467             return iLocation;
       
   468         case 3:
       
   469             return iWaypointIcon;
       
   470         default:
       
   471             return NULL;
       
   472         }
       
   473     }
       
   474 
       
   475 // ---------------------------------------------------------------------------
       
   476 // CESMRLocationField::SizeChanged
       
   477 // ---------------------------------------------------------------------------
       
   478 //
       
   479 void CESMRLocationField::SizeChanged()
       
   480     {
       
   481     FUNC_LOG;
       
   482     TRect rect( Rect() );
       
   483 
       
   484     TAknLayoutRect firstRowLayoutRect(
       
   485             NMRLayoutManager::GetFieldRowLayoutRect( rect, 1 ) );
       
   486     TRect firstRowRect( firstRowLayoutRect.Rect() );
       
   487 
       
   488     TRect secondRowRect( firstRowRect );
       
   489     secondRowRect.Move( 0, firstRowRect.Height() );
       
   490 
       
   491     // Layout field button
       
   492     if( iFieldButton )
       
   493         {
       
   494         TAknWindowComponentLayout buttonLayout(
       
   495                 NMRLayoutManager::GetWindowComponentLayout(
       
   496                     NMRLayoutManager::EMRLayoutTextEditorIcon ) );
       
   497         AknLayoutUtils::LayoutControl(
       
   498                 iFieldButton, firstRowRect, buttonLayout );
       
   499         }
       
   500 
       
   501     // Layout field title
       
   502     if( iTitle )
       
   503         {
       
   504         TAknTextComponentLayout editorLayout =
       
   505                 NMRLayoutManager::GetTextComponentLayout(
       
   506                         NMRLayoutManager::EMRTextLayoutTextEditor );
       
   507 
       
   508         AknLayoutUtils::LayoutLabel( iTitle, firstRowRect, editorLayout );
       
   509         }
       
   510 
       
   511     TRect editorRect( 0, 0, 0, 0 );
       
   512 
       
   513     // Layout field editor
       
   514     if( iLocation )
       
   515         {
       
   516         TAknLayoutText editorLayoutText;
       
   517 
       
   518         if( iWaypointIcon )
       
   519            {
       
   520            editorLayoutText = NMRLayoutManager::GetLayoutText(
       
   521                    secondRowRect,
       
   522                    NMRLayoutManager::EMRTextLayoutSingleRowEditorText );
       
   523            }
       
   524         else
       
   525            {
       
   526            editorLayoutText = NMRLayoutManager::GetLayoutText(
       
   527                    secondRowRect,
       
   528                    NMRLayoutManager::EMRTextLayoutTextEditor );
       
   529            }
       
   530 
       
   531         editorRect = editorLayoutText.TextRect();
       
   532 
       
   533         // Resize height according to actual height required by edwin.
       
   534         editorRect.Resize( 0, iSize.iHeight - editorRect.Height() );
       
   535 
       
   536         iLocation->SetRect( editorRect );
       
   537 
       
   538         // Try setting font. Failures are ignored.
       
   539         TRAP_IGNORE( iLocation->SetFontL( editorLayoutText.Font() ) );
       
   540         }
       
   541 
       
   542     // Layout the waypoint icon
       
   543     if ( iWaypointIcon )
       
   544         {
       
   545         TAknWindowComponentLayout iconLayout(
       
   546                 NMRLayoutManager::GetWindowComponentLayout(
       
   547                     NMRLayoutManager::EMRLayoutSingleRowDColumnGraphic ) );
       
   548         AknLayoutUtils::LayoutImage( iWaypointIcon, secondRowRect, iconLayout );
       
   549         }
       
   550 
       
   551     // Layout field focus
       
   552     if( iLocation )
       
   553         {
       
   554         // Layouting focus for rich text editor area
       
   555         TRect bgRect( iLocation->Rect() );
       
   556 
       
   557         // Move focus rect so that it's relative to field's position.
       
   558         bgRect.Move( -Position() );
       
   559         SetFocusRect( bgRect );
       
   560         }
       
   561     }
       
   562 
       
   563 // ---------------------------------------------------------------------------
       
   564 // CESMRLocationField::HandleFieldEventL
       
   565 // ---------------------------------------------------------------------------
       
   566 //
       
   567 void CESMRLocationField::HandleFieldEventL( const MESMRFieldEvent& aEvent )
       
   568     {
       
   569     FUNC_LOG;
       
   570     if ( aEvent.Type() == MESMRFieldEvent::EESMRFieldCommandEvent )
       
   571         {
       
   572         TInt* command = static_cast< TInt* >( aEvent.Param( 0 ) );
       
   573 
       
   574         switch ( *command )
       
   575             {
       
   576             case EESMRCmdDisableWaypointIcon:
       
   577             case EESMRCmdEnableWaypointIcon:
       
   578                 {
       
   579                 SetWaypointIconL( *command == EESMRCmdEnableWaypointIcon );
       
   580                 break;
       
   581                 }
       
   582             default:
       
   583                 {
       
   584                 break;
       
   585                 }
       
   586             }
       
   587         }
       
   588     }
       
   589 
       
   590 // ---------------------------------------------------------------------------
       
   591 // CESMRLocationField::ExecuteGenericCommandL
       
   592 // ---------------------------------------------------------------------------
       
   593 //
       
   594 TBool CESMRLocationField::ExecuteGenericCommandL(
       
   595         TInt aCommand )
       
   596     {
       
   597     FUNC_LOG;
       
   598     TBool isUsed( EFalse );
       
   599     switch(aCommand)
       
   600         {
       
   601         case EESMRCmdSizeExceeded:
       
   602             {
       
   603             CESMRGlobalNote::ExecuteL(
       
   604                     CESMRGlobalNote::EESMRCannotDisplayMuchMore );
       
   605 
       
   606             HBufC* text = iLocation->GetTextInHBufL();
       
   607             CleanupDeletePushL( text );
       
   608             if ( text )
       
   609                 {
       
   610                 TInt curPos = iLocation->CursorPos();
       
   611                 if ( curPos > iLocation->GetLimitLength() - 1 )
       
   612                     curPos = iLocation->GetLimitLength() - 1;
       
   613                 HBufC* newText =
       
   614                     text->Mid( 0, iLocation->GetLimitLength() - 1 ).AllocLC();
       
   615 
       
   616                 iLocation->SetTextL ( newText );
       
   617                 CleanupStack::PopAndDestroy( newText );
       
   618                 newText = NULL;
       
   619 
       
   620                 iLocation->SetCursorPosL( curPos, EFalse );
       
   621                 iLocation->HandleTextChangedL();
       
   622                 iLocation->UpdateScrollBarsL();
       
   623                 SetFocus( ETrue );
       
   624                 }
       
   625             CleanupStack::PopAndDestroy( text );
       
   626             isUsed = ETrue;
       
   627             break;
       
   628             }
       
   629         default:
       
   630             break;
       
   631         }
       
   632     return isUsed;
       
   633     }
       
   634 
       
   635 
       
   636 // ---------------------------------------------------------------------------
       
   637 // CESMRLocationField::HandleSingletapEventL
       
   638 // ---------------------------------------------------------------------------
       
   639 //
       
   640 TBool CESMRLocationField::HandleSingletapEventL( const TPoint& aPosition )
       
   641     {
       
   642     FUNC_LOG;
       
   643     TBool ret( EFalse );
       
   644 
       
   645     if( iTitle->Rect().Contains( aPosition ) ||
       
   646             iFieldButton->Rect().Contains( aPosition ) )
       
   647         {
       
   648 		HandleTactileFeedbackL();
       
   649         NotifyEventL( EAknSoftkeyContextOptions );
       
   650         ret = ETrue;
       
   651         }
       
   652 
       
   653     return ret;
       
   654     }
       
   655 
       
   656 // ---------------------------------------------------------------------------
       
   657 // CESMRLocationField::HandleLongtapEventL
       
   658 // ---------------------------------------------------------------------------
       
   659 //
       
   660 void CESMRLocationField::HandleLongtapEventL( const TPoint& aPosition )
       
   661     {
       
   662     FUNC_LOG;
       
   663 
       
   664     if ( iLocation->Rect().Contains( aPosition ) )
       
   665         {
       
   666         if ( !iMenu )
       
   667             {
       
   668             iMenu = CMRStylusPopupMenu::NewL( *this );
       
   669             }
       
   670         RArray<CMRStylusPopupMenu::TMenuItem> items;
       
   671         CleanupClosePushL( items );
       
   672 
       
   673         HBufC* maps= NULL;
       
   674         HBufC* myLocations = NULL;
       
   675 
       
   676         if ( FeaturesL().FeatureSupported(
       
   677                 CESMRFeatureSettings::EESMRUIMnFwIntegration ) )
       
   678             {
       
   679             maps = StringLoader::LoadLC(
       
   680                     R_MEET_REQ_OPTIONS_ASSIGN_FROM_MAP,
       
   681                     iCoeEnv );
       
   682             CMRStylusPopupMenu::TMenuItem mapsItem(
       
   683                     *maps,
       
   684                     EESMRCmdAssignFromMap );
       
   685             items.AppendL( mapsItem );
       
   686             }
       
   687 
       
   688 //#ifdef RD_USE_MYLOCATIONUI
       
   689 
       
   690         myLocations = StringLoader::LoadLC(
       
   691                 R_MEET_REQ_OPTIONS_MY_LOCATIONS,
       
   692                 iCoeEnv );
       
   693 
       
   694         CMRStylusPopupMenu::TMenuItem myLocationsItem(
       
   695                 *myLocations,
       
   696                 EMRCommandMyLocations );
       
   697 
       
   698         items.AppendL( myLocationsItem );
       
   699 
       
   700 //#endif //RD_USE_MYLOCATIONUI
       
   701 
       
   702         if ( items.Count() == 1 )
       
   703             {
       
   704             // Only one option. Issue command directly
       
   705             NotifyEventL( items[ 0 ].iCommandId );
       
   706             }
       
   707         else if ( items.Count() > 1 )
       
   708             {
       
   709             iMenu->LaunchPopupL( items.Array(), aPosition );
       
   710             iMenuIsShown = ETrue;
       
   711             }
       
   712 
       
   713         if (myLocations )
       
   714             {
       
   715             CleanupStack::PopAndDestroy( myLocations );
       
   716             }
       
   717 
       
   718         if ( maps )
       
   719             {
       
   720             CleanupStack::PopAndDestroy( maps );
       
   721             }
       
   722 
       
   723         CleanupStack::PopAndDestroy( &items );
       
   724         }
       
   725 
       
   726     if( iTitle->Rect().Contains( aPosition ) ||
       
   727             iFieldButton->Rect().Contains( aPosition ) )
       
   728         {
       
   729 		HandleTactileFeedbackL();
       
   730         NotifyEventL( EAknSoftkeyContextOptions );
       
   731         }
       
   732     }
       
   733 
       
   734 // ---------------------------------------------------------------------------
       
   735 // CESMRLocationField::DynInitMenuPaneL
       
   736 // ---------------------------------------------------------------------------
       
   737 //
       
   738 void CESMRLocationField::DynInitMenuPaneL(
       
   739         TInt aResourceId,
       
   740         CEikMenuPane* aMenuPane )
       
   741     {
       
   742     FUNC_LOG;
       
   743 
       
   744     if ( aResourceId == R_MR_EDITOR_ORGANIZER_MENU)
       
   745         {
       
   746         // Init assign options
       
   747         TInt numOptions( 1 ); // My Locations
       
   748 
       
   749         if ( FeaturesL().FeatureSupported(
       
   750                 CESMRFeatureSettings::EESMRUIMnFwIntegration ) )
       
   751             {
       
   752             ++numOptions;
       
   753             }
       
   754 
       
   755         #ifndef RD_USE_MYLOCATIONUI
       
   756         // Disable My Locations
       
   757         --numOptions;
       
   758         #endif // RD_USE_MYLOCATIONUI
       
   759 
       
   760         switch ( numOptions )
       
   761             {
       
   762             case 0:
       
   763                 {
       
   764                 aMenuPane->SetItemDimmed( EESMRCmdAddLocation, ETrue );
       
   765                 break;
       
   766                 }
       
   767 
       
   768             case 1:
       
   769                 {
       
   770                 // Replace Add location with actual command
       
   771                 TInt pos( 0 );
       
   772                 CEikMenuPaneItem* item =
       
   773                         aMenuPane->ItemAndPos( EESMRCmdAddLocation, pos );
       
   774 
       
   775                 item->iData.iCascadeId = 0;
       
   776 
       
   777                 if ( FeaturesL().FeatureSupported(
       
   778                         CESMRFeatureSettings::EESMRUIMnFwIntegration ) )
       
   779                     {
       
   780                     item->iData.iCommandId = EESMRCmdAssignFromMap;
       
   781                     StringLoader::Load(item->iData.iText,
       
   782                             R_MEET_REQ_OPTIONS_ASSIGN_FROM_MAP, iCoeEnv );
       
   783                     }
       
   784 
       
   785 #ifdef RD_USE_MYLOCATIONUI
       
   786                 else
       
   787                     {
       
   788                     item->iData.iCommandId = EMRCommandMyLocations;
       
   789                     StringLoader::Load( item->iData.iText,
       
   790                             R_MEET_REQ_OPTIONS_MY_LOCATIONS, iCoeEnv );
       
   791                     }
       
   792 #endif //RD_USE_MYLOCATIONUI
       
   793 
       
   794                 aMenuPane->SetItemDimmed( item->iData.iCommandId, EFalse );
       
   795                 break;
       
   796                 }
       
   797             default:
       
   798                 {
       
   799                 aMenuPane->SetItemDimmed( EESMRCmdAddLocation, EFalse );
       
   800                 break;
       
   801                 }
       
   802             }
       
   803         // Init Show/Search options
       
   804         TBool showOnMap( EFalse );
       
   805         TBool searchFromMap( EFalse );
       
   806 
       
   807         if ( iWaypointIcon )
       
   808             {
       
   809             // Coordinates available -> show on map
       
   810             showOnMap = ETrue;
       
   811             }
       
   812         else
       
   813             {
       
   814             HBufC* text = iLocation->GetTextInHBufL();
       
   815             if ( text && *text != iLocation->DefaultText() )
       
   816                 {
       
   817                 // Edited text in field -> enable search from map
       
   818                 searchFromMap = ETrue;
       
   819                 }
       
   820             delete text;
       
   821             }
       
   822 
       
   823         aMenuPane->SetItemDimmed( EESMRCmdShowOnMap, !showOnMap );
       
   824         aMenuPane->SetItemDimmed( EESMRCmdSearchFromMap, !searchFromMap );
       
   825         }
       
   826     else if ( aResourceId == R_MR_EDITOR_LOCATION_MENU )
       
   827         {
       
   828         if ( !FeaturesL().FeatureSupported(
       
   829                 CESMRFeatureSettings::EESMRUIMnFwIntegration ) )
       
   830             {
       
   831             aMenuPane->SetItemDimmed( EESMRCmdAssignFromMap, ETrue );
       
   832             }
       
   833 #ifndef RD_USE_MYLOCATIONUI
       
   834         aMenuPane->SetItemDimmed( EMRCommandMyLocations, ETrue );
       
   835 #endif //RD_USE_MYLOCATIONUI
       
   836         }
       
   837     }
       
   838 
       
   839 // ---------------------------------------------------------------------------
       
   840 // CESMRLocationField::SetContainerWindowL
       
   841 // ---------------------------------------------------------------------------
       
   842 //
       
   843 void CESMRLocationField::SetContainerWindowL(
       
   844         const CCoeControl& aContainer )
       
   845     {
       
   846     FUNC_LOG;
       
   847     CCoeControl::SetContainerWindowL( aContainer );
       
   848 
       
   849     iLocation->SetContainerWindowL( aContainer );
       
   850     iLocation->SetParent( this );
       
   851 
       
   852     iTitle->SetContainerWindowL( aContainer );
       
   853     iTitle->SetParent( this );
       
   854 
       
   855     iFieldButton->SetContainerWindowL(aContainer);
       
   856     iFieldButton->SetParent(this);
       
   857     }
       
   858 
       
   859 // ---------------------------------------------------------------------------
       
   860 // CESMRLocationField::OfferKeyEventL()
       
   861 // ---------------------------------------------------------------------------
       
   862 //
       
   863 TKeyResponse CESMRLocationField::OfferKeyEventL(
       
   864         const TKeyEvent& aEvent,
       
   865         TEventCode aType )
       
   866     {
       
   867     FUNC_LOG;
       
   868     TKeyResponse response( EKeyWasNotConsumed );
       
   869     response = iLocation->OfferKeyEventL ( aEvent, aType );
       
   870 
       
   871     if ( aType == EEventKey &&
       
   872          ( aEvent.iScanCode != EStdKeyUpArrow &&
       
   873            aEvent.iScanCode != EStdKeyDownArrow ))
       
   874         {
       
   875         iLocation->DrawDeferred();
       
   876         }
       
   877 
       
   878     return response;
       
   879     }
       
   880 
       
   881 // ---------------------------------------------------------------------------
       
   882 // CESMRLocationField::HandlePointerEventL
       
   883 // ---------------------------------------------------------------------------
       
   884 //
       
   885 TBool CESMRLocationField::HandleRawPointerEventL( const TPointerEvent &aPointerEvent )
       
   886     {
       
   887     if ( !iMenuIsShown )
       
   888         {
       
   889         CCoeControl::HandlePointerEventL( aPointerEvent );
       
   890         }
       
   891 
       
   892     return ETrue;
       
   893     }
       
   894 
       
   895 // ---------------------------------------------------------------------------
       
   896 // CESMRLocationField::ProcessCommandL
       
   897 // ---------------------------------------------------------------------------
       
   898 //
       
   899 void CESMRLocationField::ProcessCommandL( TInt aCommandId )
       
   900     {
       
   901     NotifyEventL( aCommandId );
       
   902 
       
   903     iMenuIsShown = EFalse;
       
   904     }
       
   905 // EOF