meetingrequest/mrgui/mrfieldbuilderplugin/src/cesmrviewerlocationfield.cpp
branchRCL_3
changeset 12 4ce476e64c59
parent 0 8466d47a6819
child 13 8592a65ad3fb
equal deleted inserted replaced
11:0396474f30f5 12:4ce476e64c59
     1 /*
     1 /*
     2 * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). 
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    13 *
    13 *
    14 * Description:  Meeting request location field
    14 * Description:  Meeting request location field
    15  *
    15  *
    16 */
    16 */
    17 
    17 
       
    18 #include "cesmrviewerlocationfield.h"
       
    19 #include "cesmrrichtextviewer.h"
       
    20 #include "mesmrlistobserver.h"
       
    21 #include "nmrlayoutmanager.h"
       
    22 #include "cmrimage.h"
       
    23 #include "cesmrfeaturesettings.h"
       
    24 #include "emailtrace.h"
       
    25 #include "cesmrglobalnote.h"
       
    26 #include "cmrbutton.h"
       
    27 
    18 #include <calentry.h>
    28 #include <calentry.h>
    19 #include <esmrgui.rsg>
    29 #include <esmrgui.rsg>
    20 #include <data_caging_path_literals.hrh>
    30 #include <data_caging_path_literals.hrh>
    21 #include <AknLayout2ScalableDef.h>
    31 #include <aknlayout2scalabledef.h>
    22 
    32 #include <gulicon.h>
    23 #include "cesmrviewerlocationfield.h"
    33 #include <stringloader.h>
    24 #include "cesmrrichtextviewer.h"
    34 
    25 #include "mesmrlistobserver.h"
    35 // LOCAL DEFINITIONS
    26 #include "cesmrfeaturesettings.h"
       
    27 #include "nmrlayoutmanager.h"
       
    28 #include "cmrimage.h"
       
    29 
       
    30 
    36 
    31 // ======== MEMBER FUNCTIONS ========
    37 // ======== MEMBER FUNCTIONS ========
    32 
    38 
    33 // ---------------------------------------------------------------------------
    39 // ---------------------------------------------------------------------------
    34 // CESMRViewerLocationField::NewL
    40 // CESMRViewerLocationField::NewL
    47 // CESMRViewerLocationField::CESMRViewerLocationField
    53 // CESMRViewerLocationField::CESMRViewerLocationField
    48 // ---------------------------------------------------------------------------
    54 // ---------------------------------------------------------------------------
    49 //
    55 //
    50 CESMRViewerLocationField::~CESMRViewerLocationField()
    56 CESMRViewerLocationField::~CESMRViewerLocationField()
    51     {
    57     {
    52     iObserver = NULL;
    58     delete iFieldButton;
    53     delete iFieldIcon;
    59     delete iWaypointIcon;
    54     delete iRichTextViewer;
       
    55     delete iFeatures;
    60     delete iFeatures;
    56     }
    61     }
    57 
    62 
    58 // ---------------------------------------------------------------------------
    63 // ---------------------------------------------------------------------------
    59 // CESMRViewerLocationField::MinimumSize
    64 // CESMRViewerLocationField::MinimumSize
    60 // ---------------------------------------------------------------------------
    65 // ---------------------------------------------------------------------------
    61 //
    66 //
    62 TSize CESMRViewerLocationField::MinimumSize()
    67 TSize CESMRViewerLocationField::MinimumSize()
    63     {
    68     {
    64     // Let's calculate the required rect of the iRichTextViewer.
    69     TRect parentRect( Parent()->Rect() );
    65     // We will not use directly the iRichTextViewer height, because it might
    70 
    66     // not exist, or the height of the viewer might still be incorrect
    71     TRect fieldRect =
    67     TRect richTextViewerRect = RichTextViewerRect();
    72        NMRLayoutManager::GetFieldLayoutRect( parentRect, 1 ).Rect();
    68 
    73 
    69     // We will use as minimum size the parents width 
    74     TRect viewerRect( NMRLayoutManager::GetLayoutText(
    70     // but the calculated iRichTextViewers height 
    75        fieldRect,
    71     return TSize( Parent()->Size().iWidth, richTextViewerRect.Height() );
    76        NMRLayoutManager::EMRTextLayoutTextEditor ).TextRect() );
       
    77 
       
    78     // Adjust field size so that there's room for expandable editor.
       
    79     fieldRect.Resize( 0, iSize.iHeight - viewerRect.Height() );
       
    80 
       
    81     return fieldRect.Size();
    72     }
    82     }
    73 
    83 
    74 
    84 
    75 // ---------------------------------------------------------------------------
    85 // ---------------------------------------------------------------------------
    76 // CESMRViewerLocationField::InitializeL
    86 // CESMRViewerLocationField::InitializeL
    77 // ---------------------------------------------------------------------------
    87 // ---------------------------------------------------------------------------
    78 //
    88 //
    79 void CESMRViewerLocationField::InitializeL()
    89 void CESMRViewerLocationField::InitializeL()
    80     {
    90     {
    81     // Setting Font for the rich text viewer
    91     // Setting Font for the rich text viewer
    82     TAknLayoutText text = NMRLayoutManager::GetLayoutText( 
    92     TAknLayoutText text = NMRLayoutManager::GetLayoutText(
    83             Rect(), 
    93             Rect(),
    84             NMRLayoutManager::EMRTextLayoutTextEditor );
    94             NMRLayoutManager::EMRTextLayoutTextEditor );
    85     
    95 
    86     iRichTextViewer->SetFontL( text.Font(), iLayout );
    96     iRichTextViewer->SetFontL( text.Font() );
       
    97     iRichTextViewer->ApplyLayoutChangesL();
    87 
    98 
    88     // This is called so that theme changes will apply when changing theme "on the fly"
    99     // This is called so that theme changes will apply when changing theme "on the fly"
    89     if ( IsFocused() )
   100     if ( IsFocused() )
    90         {
   101         {
    91         iRichTextViewer->FocusChanged( EDrawNow );
   102         iRichTextViewer->FocusChanged( EDrawNow );
    92         }
   103         }
       
   104     iRichTextViewer->SetEventQueue( iEventQueue );
    93     }
   105     }
    94 
   106 
    95 // ---------------------------------------------------------------------------
   107 // ---------------------------------------------------------------------------
    96 // CESMRViewerLocationField::InternalizeL()
   108 // CESMRViewerLocationField::InternalizeL()
    97 // ---------------------------------------------------------------------------
   109 // ---------------------------------------------------------------------------
    98 //
   110 //
    99 void CESMRViewerLocationField::InternalizeL( MESMRCalEntry& aEntry )
   111 void CESMRViewerLocationField::InternalizeL( MESMRCalEntry& aEntry )
   100     {
   112     {
   101     TPtrC text = aEntry.Entry().LocationL( );
   113     TPtrC text = aEntry.Entry().LocationL( );
   102     
   114 
   103     // Hide this field if location is not set
   115     // Hide this field if location is not set
   104     if( text.Length() == 0 )
   116     if( text.Length() == 0 )
   105         {
   117         {
   106         iObserver->RemoveControl( FieldId() );
   118         iObserver->HideControl( FieldId() );
   107         }
   119         }
   108     else
   120     else
   109         {
   121         {
   110         iRichTextViewer->SetTextL( &text, ETrue );
   122         iRichTextViewer->SetTextL( &text, ETrue );
   111         // After setting the text, the viewer line count is known
   123         }
   112         iLineCount = iRichTextViewer->LineCount();
   124 
   113         }
   125     // If the geo value has set, the waypoint icon has to be shown on right
   114     iDisableRedraw = ETrue;
   126     // side of the location field
       
   127     CCalGeoValue* geoValue = aEntry.Entry().GeoValueL();
       
   128     TReal dummy;
       
   129     if( !iLocked )
       
   130     	{
       
   131     	if( geoValue && geoValue->GetLatLong( dummy, dummy ) )
       
   132     		{
       
   133     		iWaypointIcon =
       
   134     		CMRImage::NewL( NMRBitmapManager::EMRBitmapLocationWaypoint, ETrue );
       
   135     		iWaypointIcon->SetParent( this );
       
   136     		}
       
   137     	}    
   115     }
   138     }
   116 
   139 
   117 // ---------------------------------------------------------------------------
   140 // ---------------------------------------------------------------------------
   118 // CESMRViewerLocationField::OfferKeyEventL()
   141 // CESMRViewerLocationField::OfferKeyEventL()
   119 // ---------------------------------------------------------------------------
   142 // ---------------------------------------------------------------------------
   131 //
   154 //
   132 TBool CESMRViewerLocationField::HandleEdwinSizeEventL( CEikEdwin* aEdwin,
   155 TBool CESMRViewerLocationField::HandleEdwinSizeEventL( CEikEdwin* aEdwin,
   133         TEdwinSizeEvent /*aType*/, TSize aSize )
   156         TEdwinSizeEvent /*aType*/, TSize aSize )
   134     {
   157     {
   135     TBool reDraw( EFalse );
   158     TBool reDraw( EFalse );
   136     
   159 
   137     // Let's save the required size for the iRichTextViewer
   160     // Let's save the required size for the iRichTextViewer
   138     iSize = aSize;
   161     iSize = aSize;
   139 
   162 
   140     if ( iObserver && aEdwin == iRichTextViewer )
   163     if ( iObserver && aEdwin == iRichTextViewer )
   141         {
   164         {
   151 // ---------------------------------------------------------------------------
   174 // ---------------------------------------------------------------------------
   152 //
   175 //
   153 CESMRViewerLocationField::CESMRViewerLocationField()
   176 CESMRViewerLocationField::CESMRViewerLocationField()
   154     {
   177     {
   155     SetFieldId( EESMRFieldLocation );
   178     SetFieldId( EESMRFieldLocation );
       
   179     SetFocusType( EESMRHighlightFocus );
   156     }
   180     }
   157 
   181 
   158 // ---------------------------------------------------------------------------
   182 // ---------------------------------------------------------------------------
   159 // CESMRViewerLocationField::ConstructL()
   183 // CESMRViewerLocationField::ConstructL()
   160 // ---------------------------------------------------------------------------
   184 // ---------------------------------------------------------------------------
   161 //
   185 //
   162 void CESMRViewerLocationField::ConstructL( )
   186 void CESMRViewerLocationField::ConstructL( )
   163     {
   187     {
   164     SetFocusType( EESMRHighlightFocus );
   188 	iFieldButton = CMRButton::NewL( NMRBitmapManager::EMRBitmapLocation );
   165    
   189     iFieldButton->SetParent( this );
   166     iFieldIcon = CMRImage::NewL( KAknsIIDQgnMeetReqIndiLocation );
   190     iFieldButton->SetObserver(this);
   167     iFieldIcon->SetParent( this );
   191 
   168     
       
   169     iRichTextViewer = CESMRRichTextViewer::NewL( this );
   192     iRichTextViewer = CESMRRichTextViewer::NewL( this );
       
   193     CESMRField::ConstructL( iRichTextViewer ); // ownership transfered
   170     iRichTextViewer->SetEdwinSizeObserver( this );
   194     iRichTextViewer->SetEdwinSizeObserver( this );
   171     iRichTextViewer->SetParent( this );
   195     iRichTextViewer->SetParent( this );
       
   196 
       
   197     iFeatures = CESMRFeatureSettings::NewL();
   172     }
   198     }
   173 
   199 
   174 // ---------------------------------------------------------------------------
   200 // ---------------------------------------------------------------------------
   175 // CESMRViewerLocationField::ListObserverSet
   201 // CESMRViewerLocationField::ListObserverSet
   176 // ---------------------------------------------------------------------------
   202 // ---------------------------------------------------------------------------
   182 
   208 
   183 // ---------------------------------------------------------------------------
   209 // ---------------------------------------------------------------------------
   184 // CESMRViewerLocationField::ExecuteGenericCommandL()
   210 // CESMRViewerLocationField::ExecuteGenericCommandL()
   185 // ---------------------------------------------------------------------------
   211 // ---------------------------------------------------------------------------
   186 //
   212 //
   187 void CESMRViewerLocationField::ExecuteGenericCommandL( TInt aCommand )
   213 TBool CESMRViewerLocationField::ExecuteGenericCommandL( TInt aCommand )
   188     {
   214     {
       
   215     TBool isUsed( EFalse );
   189     switch ( aCommand )
   216     switch ( aCommand )
   190         {
   217         {
   191         case EESMRCmdClipboardCopy:
   218         case EESMRCmdClipboardCopy:
   192         {
   219             {
   193         iRichTextViewer->CopyCurrentLinkToClipBoardL();
   220             iRichTextViewer->CopyCurrentLinkToClipBoardL();
   194         break;
   221             isUsed = ETrue;
       
   222             break;
   195             }
   223             }
   196         case EESMRCmdDisableWaypointIcon:
   224         case EESMRCmdDisableWaypointIcon:
   197         case EESMRCmdEnableWaypointIcon:
   225         case EESMRCmdEnableWaypointIcon:
   198             {
   226             {
   199             SetWaypointIconL( aCommand == EESMRCmdEnableWaypointIcon );
   227             SetWaypointIconL( aCommand == EESMRCmdEnableWaypointIcon );
       
   228             isUsed = ETrue;
   200             break;
   229             break;
   201             }
   230             }
   202         case EAknSoftkeySelect:
   231         case EAknSoftkeySelect:
   203             {
   232             {
   204             iRichTextViewer->LinkSelectedL();
   233             iRichTextViewer->LinkSelectedL();
       
   234             isUsed = ETrue;
       
   235 
   205             break;
   236             break;
   206             }
   237             }
       
   238         case EAknCmdOpen:
       
   239             {
       
   240             // Open command is handled only when field is locked
       
   241             if ( IsLocked() )
       
   242             	{
       
   243 				HandleTactileFeedbackL();
       
   244 
       
   245             	CESMRGlobalNote::ExecuteL(
       
   246             			CESMRGlobalNote::EESMRUnableToEdit );
       
   247             	isUsed = ETrue;
       
   248             	}
       
   249             break;
       
   250             }
   207         default:
   251         default:
   208             {
   252             {
   209             break;
   253             break;
   210             }
   254             }
   211         }
   255         }
       
   256     return isUsed;
   212     }
   257     }
   213 
   258 
   214 // ---------------------------------------------------------------------------
   259 // ---------------------------------------------------------------------------
   215 // CESMRViewerLocationField::SetOutlineFocusL()
   260 // CESMRViewerLocationField::SetOutlineFocusL()
   216 // ---------------------------------------------------------------------------
   261 // ---------------------------------------------------------------------------
   217 //
   262 //
   218 void CESMRViewerLocationField::SetOutlineFocusL( TBool aFocus )
   263 void CESMRViewerLocationField::SetOutlineFocusL( TBool aFocus )
   219     {
   264     {
   220     CESMRField::SetOutlineFocusL( aFocus );
   265     CESMRField::SetOutlineFocusL( aFocus );
   221     
   266 
   222     iRichTextViewer->SetFocus( aFocus );
   267     if ( aFocus )
   223 
   268        {
   224     if ( FeaturesL().FeatureSupported(
   269        ChangeMiddleSoftKeyL( EAknSoftkeyContextOptions, R_QTN_MSK_OPEN );
   225             CESMRFeatureSettings::EESMRUILocationFeatures ) )
   270        }
   226         {
   271    else
   227 
   272        {
   228         if ( aFocus )
   273        //need to tell action menu that focus has changed
   229             {
   274        iRichTextViewer->ResetActionMenuL();
   230             //Store MSK function before changing it
   275        }
   231             CEikButtonGroupContainer* cba = CEikButtonGroupContainer::Current();
   276     }
   232             if ( cba->PositionById( EESMRCmdEdit ) ==
   277 
   233                  CEikButtonGroupContainer::EMiddleSoftkeyPosition )
   278 // ---------------------------------------------------------------------------
   234                 {
   279 // CESMRViewerLocationField::SetWaypointIconL
   235                 iMskCommandId = EESMRCmdEdit;
   280 // ---------------------------------------------------------------------------
   236         
   281 //
   237                 }
   282 void CESMRViewerLocationField::SetWaypointIconL( TBool aEnabled )
   238             else if ( cba->PositionById( EESMRCmdEditLocal ) ==
   283     {
   239                       CEikButtonGroupContainer::EMiddleSoftkeyPosition )
   284     delete iWaypointIcon;
   240                 {
   285     iWaypointIcon = NULL;
   241                 iMskCommandId = EESMRCmdEditLocal;
   286 
   242                 }
   287     if ( aEnabled )
   243             else if ( cba->PositionById( EESMRCmdCalEntryUIEdit ) ==
   288         {
   244                       CEikButtonGroupContainer::EMiddleSoftkeyPosition )
   289         iWaypointIcon = CMRImage::NewL( NMRBitmapManager::EMRBitmapLocationWaypoint, ETrue );
   245                 {
   290         iWaypointIcon->SetParent( this );
   246                 iMskCommandId = EESMRCmdCalEntryUIEdit;
   291         }
   247                 }
   292 
   248             
   293     // Relayout
   249             ChangeMiddleSoftKeyL( EAknSoftkeyContextOptions, R_QTN_MSK_OPEN );
   294     SizeChanged();
   250             }
       
   251         else
       
   252             {
       
   253             switch ( iMskCommandId )
       
   254                 {
       
   255                 case EESMRCmdEdit:
       
   256                 case EESMRCmdEditLocal:
       
   257                 case EESMRCmdCalEntryUIEdit:
       
   258                     {
       
   259                     ChangeMiddleSoftKeyL( iMskCommandId, R_QTN_MSK_EDIT );
       
   260                     break;
       
   261                     }
       
   262                 default:
       
   263                     {
       
   264                     CEikButtonGroupContainer* cba =
       
   265                         CEikButtonGroupContainer::Current();
       
   266                     cba->SetCommandL(
       
   267                             CEikButtonGroupContainer::EMiddleSoftkeyPosition,
       
   268                             R_MR_SELECT_SOFTKEY );
       
   269                     cba->DrawNow();
       
   270                     break;
       
   271                     }
       
   272                 }
       
   273             
       
   274             //need to tell action menu that focus has changed
       
   275             iRichTextViewer->ResetActionMenuL();
       
   276             }
       
   277         }
       
   278     }
       
   279 
       
   280 // ---------------------------------------------------------------------------
       
   281 // CESMRViewerLocationField::FeaturesL()
       
   282 // ---------------------------------------------------------------------------
       
   283 //
       
   284 CESMRFeatureSettings& CESMRViewerLocationField::FeaturesL()
       
   285     {
       
   286     if ( !iFeatures )
       
   287         {
       
   288         iFeatures = CESMRFeatureSettings::NewL();
       
   289         }
       
   290     return *iFeatures;
       
   291     }
       
   292 
       
   293 // ---------------------------------------------------------------------------
       
   294 // CESMRCheckbox::SetWaypointIconL
       
   295 // ---------------------------------------------------------------------------
       
   296 //
       
   297 void CESMRViewerLocationField::SetWaypointIconL( TBool /*aEnabled*/ )
       
   298     {
       
   299     }
   295     }
   300 
   296 
   301 // ---------------------------------------------------------------------------
   297 // ---------------------------------------------------------------------------
   302 // CESMRViewerLocationField::CountComponentControls
   298 // CESMRViewerLocationField::CountComponentControls
   303 // ---------------------------------------------------------------------------
   299 // ---------------------------------------------------------------------------
   304 //
   300 //
   305 TInt CESMRViewerLocationField::CountComponentControls() const
   301 TInt CESMRViewerLocationField::CountComponentControls() const
   306     {
   302     {
   307     TInt count( 0 );
   303     TInt count( 0 );
   308     if ( iFieldIcon )
   304     if ( iFieldButton )
   309         {
   305         {
   310         ++count;
   306         ++count;
   311         }
   307         }
   312 
   308 
   313     if ( iRichTextViewer )
   309     if ( iRichTextViewer )
   314         {
   310         {
   315         ++count;
   311         ++count;
   316         }
   312         }
       
   313 
       
   314     if( iWaypointIcon )
       
   315         {
       
   316         ++count;
       
   317         }
   317     return count;
   318     return count;
   318     }
   319     }
   319 
   320 
   320 // ---------------------------------------------------------------------------
   321 // ---------------------------------------------------------------------------
   321 // CESMRViewerLocationField::ComponentControl
   322 // CESMRViewerLocationField::ComponentControl
   324 CCoeControl* CESMRViewerLocationField::ComponentControl( TInt aIndex ) const
   325 CCoeControl* CESMRViewerLocationField::ComponentControl( TInt aIndex ) const
   325     {
   326     {
   326     switch ( aIndex )
   327     switch ( aIndex )
   327         {
   328         {
   328         case 0:
   329         case 0:
   329             return iFieldIcon;
   330             return iFieldButton;
   330         case 1:
   331         case 1:
   331             return iRichTextViewer;
   332             return iRichTextViewer;
       
   333         case 2:
       
   334             return iWaypointIcon;
   332         default:
   335         default:
   333             return NULL;
   336             return NULL;
   334         }
   337         }
   335     }
   338     }
   336 
   339 
   338 // CESMRViewerLocationField::SizeChanged
   341 // CESMRViewerLocationField::SizeChanged
   339 // ---------------------------------------------------------------------------
   342 // ---------------------------------------------------------------------------
   340 //
   343 //
   341 void CESMRViewerLocationField::SizeChanged( )
   344 void CESMRViewerLocationField::SizeChanged( )
   342     {
   345     {
   343     TRect rect = Rect();
   346     TRect rect( Rect() );
   344 
   347 
   345     // LAYOUTING FIELD ICON
   348     TAknLayoutRect rowLayoutRect(
   346     if( iFieldIcon )
   349             NMRLayoutManager::GetFieldRowLayoutRect( rect, 1 ) );
   347         {
   350     TRect rowRect( rowLayoutRect.Rect() );
   348         TAknWindowComponentLayout iconLayout = 
   351 
   349             NMRLayoutManager::GetWindowComponentLayout( NMRLayoutManager::EMRLayoutTextEditorIcon );
   352     // Layouting field icon
   350         AknLayoutUtils::LayoutImage( iFieldIcon, rect, iconLayout );
   353     if( iFieldButton )
   351         }
   354         {
   352 
   355         TAknWindowComponentLayout iconLayout(
   353     // LAYOUTING FIELD BACKGROUND
   356             NMRLayoutManager::GetWindowComponentLayout(
   354     TAknLayoutRect bgLayoutRect =
   357                     NMRLayoutManager::EMRLayoutSingleRowAColumnGraphic ) );
   355         NMRLayoutManager::GetLayoutRect( rect, NMRLayoutManager::EMRLayoutTextEditorBg );
   358         AknLayoutUtils::LayoutControl( iFieldButton, rowRect, iconLayout );
   356     TRect bgRect( bgLayoutRect.Rect() );
   359         }
   357     // Move focus rect so that it's relative to field's position
   360 
       
   361     // Layouting waypoint icon
       
   362     if( iWaypointIcon )
       
   363         {
       
   364         TAknWindowComponentLayout iconLayout(
       
   365                 NMRLayoutManager::GetWindowComponentLayout(
       
   366                     NMRLayoutManager::EMRLayoutSingleRowDColumnGraphic ) );
       
   367         AknLayoutUtils::LayoutImage( iWaypointIcon, rowRect, iconLayout );
       
   368         }
       
   369 
       
   370     TAknLayoutText viewerLayoutText;
       
   371 
       
   372     if( iWaypointIcon )
       
   373         {
       
   374         viewerLayoutText = NMRLayoutManager::GetLayoutText( rowRect,
       
   375                     NMRLayoutManager::EMRTextLayoutSingleRowEditorText );
       
   376         }
       
   377     else
       
   378         {
       
   379         viewerLayoutText = NMRLayoutManager::GetLayoutText( rowRect,
       
   380                     NMRLayoutManager::EMRTextLayoutTextEditor );
       
   381         }
       
   382 
       
   383     // Layouting viewer field
       
   384     TRect viewerRect( viewerLayoutText.TextRect() );
       
   385 
       
   386     // Resize height according to actual height required by edwin.
       
   387     viewerRect.Resize( 0, iSize.iHeight - viewerRect.Height() );
       
   388     iRichTextViewer->SetRect( viewerRect );
       
   389 
       
   390     // Layouting focus
       
   391     TRect bgRect( viewerRect );
       
   392 
       
   393     // Move focus rect so that it's relative to field's position.
   358     bgRect.Move( -Position() );
   394     bgRect.Move( -Position() );
   359     SetFocusRect( bgRect );
   395     SetFocusRect( bgRect );
   360     
   396     
   361     // LAYOUTING FIELD TEXT VIEWER
   397     // Failures are ignored.
   362     if( iRichTextViewer )
   398     TRAP_IGNORE(
   363         {
   399     		// Try setting font
   364         iRichTextViewer->SetRect( RichTextViewerRect() );
   400     		iRichTextViewer->SetFontL( viewerLayoutText.Font() );
   365         }
   401     		// Try applying changes
       
   402     		iRichTextViewer->ApplyLayoutChangesL();
       
   403 				);
   366     }
   404     }
   367 
   405 
   368 // ---------------------------------------------------------------------------
   406 // ---------------------------------------------------------------------------
   369 // CESMRViewerLocationField::SetContainerWindowL
   407 // CESMRViewerLocationField::SetContainerWindowL
   370 // ---------------------------------------------------------------------------
   408 // ---------------------------------------------------------------------------
   371 //
   409 //
   372 void CESMRViewerLocationField::SetContainerWindowL( const CCoeControl& aContainer )
   410 void CESMRViewerLocationField::SetContainerWindowL(
       
   411         const CCoeControl& aContainer )
   373     {
   412     {
   374     CCoeControl::SetContainerWindowL( aContainer );
   413     CCoeControl::SetContainerWindowL( aContainer );
   375     iRichTextViewer->SetContainerWindowL( aContainer );
   414     iRichTextViewer->SetContainerWindowL( aContainer );
   376     }
   415     iRichTextViewer->SetParent( this );
   377 
   416     iFieldButton->SetContainerWindowL( aContainer );
   378 // ---------------------------------------------------------------------------
   417     iFieldButton->SetParent( this );
   379 // CESMRViewerLocationField::RichTextViewerRect
   418     }
   380 // ---------------------------------------------------------------------------
   419 
   381 //
   420 // ---------------------------------------------------------------------------
   382 TRect CESMRViewerLocationField::RichTextViewerRect()
   421 // CESMRViewerLocationField::HandleLongtapEventL
   383     {
   422 // ---------------------------------------------------------------------------
   384     TRect rect = Rect();
   423 //
   385     
   424 void CESMRViewerLocationField::HandleLongtapEventL(
   386     TAknTextComponentLayout edwinLayout = NMRLayoutManager::GetTextComponentLayout( 
   425         const TPoint& aPosition )
   387             NMRLayoutManager::EMRTextLayoutTextEditor );
   426     {
   388 
   427     if ( !iRichTextViewer->LinkSelectedL() )
   389     // Text layout rect for one line viewer
   428         {
   390     TAknLayoutText textLayout;
   429         HandleTapEventL( aPosition );
   391     textLayout.LayoutText( rect, edwinLayout );
   430         }
   392     TRect textLayoutRect = textLayout.TextRect();
       
   393 
       
   394     TRect viewerRect = textLayoutRect;
       
   395     
       
   396     // If iRichTextViewer has lines and iSize has been set, 
       
   397     // we will use iSize.iHeight as the viewers height
       
   398     if( iLineCount > 0 && iSize.iHeight > 0 )
       
   399         {
       
   400         viewerRect.SetHeight( iSize.iHeight );
       
   401         }
       
   402     // Otherwise we will use one row height as the height of the 
       
   403     // iRichTextViewer
       
   404     else
   431     else
   405         {
   432         {
   406         TAknLayoutRect rowLayoutRect = 
   433         // Reset action menu after link selection
   407             NMRLayoutManager::GetFieldRowLayoutRect( rect, 1 );
   434         iRichTextViewer->ResetActionMenuL();
   408         viewerRect.SetHeight( rowLayoutRect.Rect().Height() );
   435         }
   409         }
   436     }
   410    
   437 
   411     return viewerRect;
   438 // ---------------------------------------------------------------------------
   412     }
   439 // CESMRViewerLocationField::DynInitMenuPaneL
       
   440 // ---------------------------------------------------------------------------
       
   441 //
       
   442 void CESMRViewerLocationField::DynInitMenuPaneL(
       
   443         TInt aResourceId,
       
   444         CEikMenuPane* aMenuPane )
       
   445     {
       
   446     if ( aResourceId == R_MR_VIEWER_MENU ||
       
   447          aResourceId == R_MR_VIEWER_LOCATION_MENU )
       
   448         {
       
   449         TBool showOnMap( EFalse );
       
   450 
       
   451         if ( iWaypointIcon )
       
   452             {
       
   453             showOnMap = ETrue;
       
   454             }
       
   455 
       
   456         TBool searchFromMap = !showOnMap;
       
   457 
       
   458         if ( !iFeatures->FeatureSupported(
       
   459                 CESMRFeatureSettings::EESMRUIMnFwIntegration ) )
       
   460             {
       
   461             // Maps disabled
       
   462             showOnMap = EFalse;
       
   463             searchFromMap = EFalse;
       
   464             }
       
   465 
       
   466         aMenuPane->SetItemDimmed( EESMRCmdShowOnMap, !showOnMap );
       
   467         aMenuPane->SetItemDimmed( EESMRCmdSearchFromMap, !searchFromMap );
       
   468         }
       
   469     }
       
   470 
       
   471 // ---------------------------------------------------------------------------
       
   472 // CESMRViewerLocationField::LockL
       
   473 // ---------------------------------------------------------------------------
       
   474 //
       
   475 void CESMRViewerLocationField::LockL()
       
   476 	{
       
   477 	FUNC_LOG;
       
   478 	if( IsLocked() )
       
   479 		{
       
   480 		return;
       
   481 		}
       
   482 	
       
   483 	CESMRField::LockL();
       
   484 
       
   485 	delete iWaypointIcon;
       
   486 	iWaypointIcon = NULL;
       
   487 	iWaypointIcon = CMRImage::NewL( NMRBitmapManager::EMRBitmapLockField, ETrue );
       
   488 
       
   489 	iWaypointIcon->SetParent( this );
       
   490 	iWaypointIcon->SetObserver( this );	 
       
   491 	}
       
   492 
       
   493 // ---------------------------------------------------------------------------
       
   494 // CESMRViewerLocationField::GetCursorLineVerticalPos
       
   495 // ---------------------------------------------------------------------------
       
   496 //
       
   497 void CESMRViewerLocationField::GetCursorLineVerticalPos(
       
   498         TInt& aUpper, TInt& aLower)
       
   499     {
       
   500     aLower = iRichTextViewer->CurrentLineNumber() * iRichTextViewer->RowHeight();
       
   501     aUpper = aLower - iRichTextViewer->RowHeight();
       
   502     }
       
   503 
       
   504 // ---------------------------------------------------------------------------
       
   505 // CESMRViewerLocationField::HandleControlEventL
       
   506 // ---------------------------------------------------------------------------
       
   507 //
       
   508 
       
   509 void CESMRViewerLocationField::HandleControlEventL(
       
   510         CCoeControl* aControl,TCoeEvent aEventType )
       
   511     {
       
   512     if ( aControl == iFieldButton )
       
   513         {
       
   514         if( iLocked )
       
   515         	{
       
   516         	//if field is locked, iFieldButton can't be used.
       
   517         	return;
       
   518         	}
       
   519         switch ( aEventType )
       
   520             {
       
   521             // Button state changed (button was pressed)
       
   522             case EEventRequestFocus:
       
   523                 {
       
   524                 // Clear viewer selection
       
   525                 iRichTextViewer->ClearSelectionL();
       
   526                 iRichTextViewer->DrawDeferred();
       
   527         		
       
   528                 // Show context menu
       
   529                 HandleTactileFeedbackL();
       
   530                 NotifyEventL( EAknSoftkeyContextOptions );
       
   531                 }
       
   532 
       
   533             default:
       
   534                 break;
       
   535             }
       
   536         }
       
   537     }
       
   538 
       
   539 // ---------------------------------------------------------------------------
       
   540 // CESMRViewerLocationField::HandleSingletapEventL
       
   541 // ---------------------------------------------------------------------------
       
   542 //
       
   543 TBool CESMRViewerLocationField::HandleSingletapEventL( const TPoint& aPosition )
       
   544 	{
       
   545 	return HandleTapEventL( aPosition );
       
   546 	}
       
   547 
       
   548 // ---------------------------------------------------------------------------
       
   549 // CESMRViewerLocationField::HandletapEventL
       
   550 // ---------------------------------------------------------------------------
       
   551 //
       
   552 TBool CESMRViewerLocationField::HandleTapEventL( const TPoint& aPosition )
       
   553 	{
       
   554 	TBool ret( EFalse );
       
   555 
       
   556 	if( iLocked )
       
   557 		{
       
   558 		HandleTactileFeedbackL();
       
   559 
       
   560 		CESMRGlobalNote::ExecuteL(
       
   561 			CESMRGlobalNote::EESMRUnableToEdit );
       
   562 
       
   563 		// Field locked, let's consume the event
       
   564 		ret = ETrue;
       
   565 		}
       
   566 	else
       
   567 		{
       
   568 		// Button events are handled by HandleControlEvent.
       
   569 		// Tap on link is handled by rich text viewer.
       
   570 		if ( !iFieldButton->Rect().Contains( aPosition )
       
   571 		     && !iRichTextViewer->GetSelectedLink() )
       
   572 			{
       
   573 			NotifyEventL( EAknSoftkeyContextOptions );
       
   574 
       
   575 			ret = ETrue;
       
   576 
       
   577 			HandleTactileFeedbackL();
       
   578 			}
       
   579 		}
       
   580 
       
   581     return ret;
       
   582 	}
   413 
   583 
   414 //EOF
   584 //EOF