meetingrequest/mrgui/mrfieldbuilderplugin/src/cesmrviewerdescriptionfield.cpp
changeset 0 8466d47a6819
child 1 12c456ceeff2
equal deleted inserted replaced
-1:000000000000 0:8466d47a6819
       
     1 /*
       
     2 * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Meeting request description field
       
    15  *
       
    16 */
       
    17 
       
    18 #include "cesmrviewerdescriptionfield.h"
       
    19 
       
    20 #include "esmrfieldbuilderdef.h"
       
    21 #include "cesmrrichtextviewer.h"
       
    22 #include "cesmrrichtextlink.h"
       
    23 #include "mesmrlistobserver.h"
       
    24 #include "cesmrlocationplugin.h"
       
    25 #include "esmrconfig.hrh"
       
    26 #include "cesmrfeaturesettings.h"
       
    27 #include "cesmrfieldcommandevent.h"
       
    28 #include "nmrlayoutmanager.h"
       
    29 
       
    30 //<cmail>
       
    31 #include "cesmrurlparserplugin.h"
       
    32 //</cmail>
       
    33 #include <calentry.h>
       
    34 #include <AknUtils.h>
       
    35 #include <StringLoader.h>
       
    36 #include <esmrgui.rsg>
       
    37 #include <avkon.rsg>
       
    38 #include <txtrich.h>
       
    39 
       
    40 #include "emailtrace.h"
       
    41 
       
    42 // Unnamed namespace for local definitions and functions
       
    43 namespace { // codescanner::namespace
       
    44 
       
    45 const TInt KMargin (5);
       
    46 
       
    47 }//namespace
       
    48 
       
    49 // ======== MEMBER FUNCTIONS ========
       
    50 
       
    51 // ---------------------------------------------------------------------------
       
    52 // CESMRViewerDescriptionField::NewL()
       
    53 // ---------------------------------------------------------------------------
       
    54 //
       
    55 CESMRViewerDescriptionField* CESMRViewerDescriptionField::NewL( )
       
    56     {
       
    57     FUNC_LOG;
       
    58     CESMRViewerDescriptionField* self = new (ELeave) CESMRViewerDescriptionField;
       
    59     CleanupStack::PushL (self );
       
    60     self->ConstructL ( );
       
    61     CleanupStack::Pop (self );
       
    62     return self;
       
    63     }
       
    64 
       
    65 // ---------------------------------------------------------------------------
       
    66 // CESMRViewerDescriptionField::~CESMRViewerDescriptionField()
       
    67 // ---------------------------------------------------------------------------
       
    68 //
       
    69 CESMRViewerDescriptionField::~CESMRViewerDescriptionField( )
       
    70     {
       
    71     FUNC_LOG;
       
    72     delete iLocationPlugin;
       
    73     delete iFeatures;
       
    74     }
       
    75 
       
    76 // ---------------------------------------------------------------------------
       
    77 // CESMRViewerDescriptionField::InitializeL()
       
    78 // ---------------------------------------------------------------------------
       
    79 //
       
    80 void CESMRViewerDescriptionField::InitializeL()
       
    81     {
       
    82     FUNC_LOG;
       
    83     TAknLayoutText layoutText =
       
    84         NMRLayoutManager::GetLayoutText( Rect(), NMRLayoutManager::EMRTextLayoutMultiRowTextEditor );
       
    85     iRichTextViewer->SetFontL ( layoutText.Font(), iLayout );
       
    86     if ( IsFocused() )
       
    87         {
       
    88         iRichTextViewer->FocusChanged( EDrawNow );
       
    89         }
       
    90 
       
    91     iRichTextViewer->HandleTextChangedL();
       
    92     }
       
    93 
       
    94 // ---------------------------------------------------------------------------
       
    95 // CESMRViewerDescriptionField::InternalizeL()
       
    96 // ---------------------------------------------------------------------------
       
    97 //
       
    98 void CESMRViewerDescriptionField::InternalizeL( MESMRCalEntry& aEntry )
       
    99     {
       
   100     FUNC_LOG;
       
   101     TPtrC text = aEntry.Entry().DescriptionL ( );
       
   102     if( text.Length() == 0 )
       
   103         {
       
   104         iObserver->RemoveControl( FieldId() );
       
   105         }
       
   106     else if ( FeaturesL().FeatureSupported(
       
   107                 CESMRFeatureSettings::EESMRUIMnFwIntegration ) )
       
   108         {
       
   109         AddShowOnMapLinkL( aEntry );
       
   110         }
       
   111     else
       
   112         {
       
   113         iRichTextViewer->SetTextL( &text, ETrue );
       
   114         iRichTextViewer->SetMargins( KMargin );
       
   115         }
       
   116     iDisableRedraw = ETrue;
       
   117     }
       
   118 
       
   119 // ---------------------------------------------------------------------------
       
   120 // CESMRViewerDescriptionField::OfferKeyEventL()
       
   121 // ---------------------------------------------------------------------------
       
   122 //
       
   123 TKeyResponse CESMRViewerDescriptionField::OfferKeyEventL(
       
   124         const TKeyEvent& aEvent, TEventCode aType )
       
   125     {
       
   126     FUNC_LOG;
       
   127     TKeyResponse response = EKeyWasNotConsumed;
       
   128     response = iRichTextViewer->OfferKeyEventL ( aEvent, aType );
       
   129     
       
   130     //track up and down events to change MSK
       
   131     if ( aType == EEventKey )
       
   132         {
       
   133         if ( aEvent.iCode == EKeyUpArrow || aEvent.iCode == EKeyDownArrow )
       
   134             {
       
   135             if ( FeaturesL().FeatureSupported(
       
   136                     CESMRFeatureSettings::EESMRUIMnFwIntegration ) )
       
   137                 {
       
   138                 SetShowOnMapLinkMiddleSoftKeyL();
       
   139                 }
       
   140             else
       
   141                 {
       
   142                 if ( iRichTextViewer->GetSelectedLink() )
       
   143                     {
       
   144                     SetMiddleSoftKeyVisible( ETrue );
       
   145                     }
       
   146                 else
       
   147                     {
       
   148                     RestoreMiddleSoftKeyL();
       
   149                     }
       
   150                 }
       
   151             }
       
   152         }    
       
   153     return response;
       
   154     }
       
   155 
       
   156 // ---------------------------------------------------------------------------
       
   157 // CESMRViewerDescriptionField::SetContainerWindowL()
       
   158 // ---------------------------------------------------------------------------
       
   159 //
       
   160 void CESMRViewerDescriptionField::SetContainerWindowL( const CCoeControl& aContainer )
       
   161     {
       
   162     CESMRField::SetContainerWindowL( aContainer );
       
   163     iRichTextViewer->SetContainerWindowL( aContainer );
       
   164     }
       
   165 
       
   166 // ---------------------------------------------------------------------------
       
   167 // CESMRViewerDescriptionField::MinimumSize()
       
   168 // ---------------------------------------------------------------------------
       
   169 //
       
   170 TSize CESMRViewerDescriptionField::MinimumSize()
       
   171     {
       
   172     TRect rect( Parent()->Rect() );
       
   173     TRect listRect =
       
   174         NMRLayoutManager::GetLayoutRect( rect, NMRLayoutManager::EMRLayoutListArea ).Rect();
       
   175     TRect fieldRect =
       
   176         NMRLayoutManager::GetFieldLayoutRect( listRect, 1 ).Rect();
       
   177     TRect rowRect =
       
   178         NMRLayoutManager::GetFieldRowLayoutRect( fieldRect, 1 ).Rect();
       
   179     TRect viewerRect =
       
   180         NMRLayoutManager::GetLayoutText( rowRect, NMRLayoutManager::EMRTextLayoutMultiRowTextEditor ).TextRect();
       
   181     
       
   182     fieldRect.Resize( 0, iSize.iHeight - viewerRect.Height() );
       
   183     fieldRect.SetWidth( Parent()->Rect().Width() );
       
   184     return fieldRect.Size();
       
   185     }
       
   186 
       
   187 // ---------------------------------------------------------------------------
       
   188 // CESMRViewerDescriptionField::SizeChanged()
       
   189 // ---------------------------------------------------------------------------
       
   190 //
       
   191 void CESMRViewerDescriptionField::SizeChanged()
       
   192     {
       
   193     TRect rect( Rect() );
       
   194     rect = NMRLayoutManager::GetFieldRowLayoutRect( rect, 1 ).Rect();
       
   195     
       
   196     TRect viewerRect =
       
   197         NMRLayoutManager::GetLayoutText( 
       
   198                 rect, 
       
   199                 NMRLayoutManager::EMRTextLayoutMultiRowTextEditor ).TextRect();
       
   200     
       
   201     iRichTextViewer->SetRect( 
       
   202             TRect( viewerRect.iTl, 
       
   203                     TSize( viewerRect.Width(), iSize.iHeight ) ) );
       
   204     }
       
   205 
       
   206 // ---------------------------------------------------------------------------
       
   207 // CESMRViewerDescriptionField::CountComponentControls()
       
   208 // ---------------------------------------------------------------------------
       
   209 //
       
   210 TInt CESMRViewerDescriptionField::CountComponentControls() const
       
   211     {
       
   212     return 1;
       
   213     }
       
   214 
       
   215 // ---------------------------------------------------------------------------
       
   216 // CESMRViewerDescriptionField::ComponentControl()
       
   217 // ---------------------------------------------------------------------------
       
   218 //
       
   219 CCoeControl* CESMRViewerDescriptionField::ComponentControl( TInt aIndex ) const
       
   220     {
       
   221     switch ( aIndex )
       
   222         {
       
   223         case 0:
       
   224             return iRichTextViewer;
       
   225         default:
       
   226             return NULL;
       
   227         }
       
   228     }
       
   229 
       
   230 // ---------------------------------------------------------------------------
       
   231 // CESMRViewerDescriptionField::HandleEdwinSizeEventL()
       
   232 // ---------------------------------------------------------------------------
       
   233 //
       
   234 TBool CESMRViewerDescriptionField::HandleEdwinSizeEventL(CEikEdwin* /*aEdwin*/,
       
   235         TEdwinSizeEvent /*aType*/, TSize aSize )
       
   236     {
       
   237     FUNC_LOG;
       
   238     iSize = aSize;
       
   239     
       
   240     if ( iObserver && iDisableRedraw )
       
   241         {
       
   242         iObserver->ControlSizeChanged ( this );
       
   243         }
       
   244 
       
   245     return iDisableRedraw;
       
   246     }
       
   247 
       
   248 // ---------------------------------------------------------------------------
       
   249 // CESMRViewerDescriptionField::CESMRViewerDescriptionField()
       
   250 // ---------------------------------------------------------------------------
       
   251 //
       
   252 CESMRViewerDescriptionField::CESMRViewerDescriptionField( )
       
   253     {
       
   254     FUNC_LOG;
       
   255     //do nothing
       
   256     }
       
   257 
       
   258 // ---------------------------------------------------------------------------
       
   259 // CESMRViewerDescriptionField::ConstructL()
       
   260 // ---------------------------------------------------------------------------
       
   261 //
       
   262 void CESMRViewerDescriptionField::ConstructL( )
       
   263     {
       
   264     FUNC_LOG;
       
   265     iRichTextViewer = CESMRRichTextViewer::NewL( this );
       
   266     iRichTextViewer->SetEdwinSizeObserver( this );
       
   267     iRichTextViewer->SetParent( this );
       
   268     
       
   269     SetFieldId( EESMRFieldDescription );
       
   270     }
       
   271 
       
   272 // ---------------------------------------------------------------------------
       
   273 // CESMRViewerDescriptionField::GetMinimumVisibleVerticalArea()
       
   274 // ---------------------------------------------------------------------------
       
   275 //
       
   276 void CESMRViewerDescriptionField::GetMinimumVisibleVerticalArea(TInt& aUpper, TInt& aLower)
       
   277     {
       
   278     FUNC_LOG;
       
   279     aLower = iRichTextViewer->CurrentLineNumber() * iRichTextViewer->RowHeight();
       
   280     aUpper = aLower - iRichTextViewer->RowHeight();
       
   281     }
       
   282 
       
   283 // ---------------------------------------------------------------------------
       
   284 // CESMRViewerDescriptionField::ListObserverSet
       
   285 // ---------------------------------------------------------------------------
       
   286 //
       
   287 void CESMRViewerDescriptionField::ListObserverSet()
       
   288     {
       
   289     FUNC_LOG;
       
   290     iRichTextViewer->SetListObserver( iObserver );
       
   291     }
       
   292 
       
   293 // ---------------------------------------------------------------------------
       
   294 // CESMRViewerDescriptionField::ExecuteGenericCommandL()
       
   295 // ---------------------------------------------------------------------------
       
   296 //
       
   297 void CESMRViewerDescriptionField::ExecuteGenericCommandL( TInt aCommand )
       
   298     {
       
   299     FUNC_LOG;
       
   300     switch ( aCommand )
       
   301         {
       
   302         case EESMRCmdClipboardCopy:
       
   303             {
       
   304             iRichTextViewer->CopyCurrentLinkToClipBoardL();
       
   305             break;
       
   306             }
       
   307         case EESMRCmdShowOnMap:
       
   308             {
       
   309             if ( FeaturesL().FeatureSupported(
       
   310                  CESMRFeatureSettings::EESMRUIMnFwIntegration ) )
       
   311                 {
       
   312                 const CESMRRichTextLink* link =
       
   313                     iRichTextViewer->GetSelectedLink();
       
   314                 LocationPluginL().ShowOnMapL( link->Value() );
       
   315                 }
       
   316             break;
       
   317             }
       
   318         case EAknSoftkeySelect:
       
   319             {
       
   320             iRichTextViewer->LinkSelectedL();
       
   321             break;
       
   322             }
       
   323         default:
       
   324             {
       
   325             break;
       
   326             }
       
   327         }
       
   328     }
       
   329 
       
   330 // ---------------------------------------------------------------------------
       
   331 // CESMRDescriptionField::SetOutlineFocusL
       
   332 // ---------------------------------------------------------------------------
       
   333 //
       
   334 void CESMRViewerDescriptionField::SetOutlineFocusL( TBool aFocus )
       
   335     {
       
   336     FUNC_LOG;
       
   337     CESMRField::SetOutlineFocusL ( aFocus );
       
   338     
       
   339     iRichTextViewer->SetFocus( aFocus );
       
   340     
       
   341     if ( FeaturesL().FeatureSupported(
       
   342             CESMRFeatureSettings::EESMRUIMnFwIntegration ) )
       
   343         {
       
   344         if ( aFocus )
       
   345             {
       
   346             SetShowOnMapLinkMiddleSoftKeyL();
       
   347             }
       
   348         }
       
   349     
       
   350     if ( !aFocus )
       
   351         {
       
   352         //need to tell action menu that focus has changed
       
   353         iRichTextViewer->ResetActionMenuL();
       
   354         }
       
   355     }
       
   356 
       
   357 // ---------------------------------------------------------------------------
       
   358 // CESMRViewerDescriptionField::AddShowOnMapLinkL
       
   359 // ---------------------------------------------------------------------------
       
   360 //
       
   361 void CESMRViewerDescriptionField::AddShowOnMapLinkL( MESMRCalEntry& aEntry )
       
   362     {
       
   363     FUNC_LOG;
       
   364     TInt command( EESMRCmdDisableWaypointIcon );
       
   365     CESMRUrlParserPlugin* urlParser = CESMRUrlParserPlugin::NewL();
       
   366     CleanupStack::PushL( urlParser );
       
   367     TPtrC urlPointer;
       
   368     TInt position;
       
   369     position = urlParser->FindLocationUrl( aEntry.Entry().DescriptionL(), 
       
   370                                            urlPointer );
       
   371     CleanupStack::PopAndDestroy( urlParser );
       
   372     // Location url is found and need to be replaced with show on map link
       
   373     if ( position >= KErrNone )
       
   374         {
       
   375         HBufC* showOnMapBuf =
       
   376             StringLoader::LoadLC( R_MEET_REQ_LINK_SHOW_ON_MAP,
       
   377                                   iCoeEnv );
       
   378         HBufC* description =
       
   379             HBufC::NewL( aEntry.Entry().DescriptionL().Length() + 1);
       
   380         CleanupStack::PushL( description );
       
   381         TPtr descriptionPointer( description->Des() );
       
   382         descriptionPointer.Append( aEntry.Entry().DescriptionL() );
       
   383         descriptionPointer.Replace( position,
       
   384                                     urlPointer.Length(),
       
   385                                     *showOnMapBuf );
       
   386         CESMRRichTextLink* showOnMapLink = CESMRRichTextLink::NewL( position, 
       
   387                                              showOnMapBuf->Length(), 
       
   388                                              urlPointer,
       
   389                                              CESMRRichTextLink::ETypeLocationUrl,
       
   390                                              CESMRRichTextLink::ETriggerKeyOk );
       
   391         CleanupStack::PushL( showOnMapLink );
       
   392         iRichTextViewer->SetTextL( description, ETrue );
       
   393         iRichTextViewer->InsertLinkL( showOnMapLink, 0 ); 
       
   394         CleanupStack::Pop( showOnMapLink );                
       
   395         iRichTextViewer->HandleTextChangedL();
       
   396         CleanupStack::PopAndDestroy( description );
       
   397         CleanupStack::PopAndDestroy( showOnMapBuf );
       
   398         command = EESMRCmdEnableWaypointIcon;
       
   399         }
       
   400     // No location url found. Other description text is added to field.
       
   401     else
       
   402         {
       
   403         TPtrC text = aEntry.Entry().DescriptionL();
       
   404         iRichTextViewer->SetTextL( &text, ETrue );
       
   405         }
       
   406     
       
   407     iRichTextViewer->SetMargins( KMargin );
       
   408     NotifyEventL( command );
       
   409     }
       
   410 
       
   411 // ---------------------------------------------------------------------------
       
   412 // CESMRViewerDescriptionField::SetShowOnMapLinkMiddleSoftKeyL
       
   413 // ---------------------------------------------------------------------------
       
   414 //
       
   415 void CESMRViewerDescriptionField::SetShowOnMapLinkMiddleSoftKeyL()
       
   416     {
       
   417     FUNC_LOG;
       
   418     const CESMRRichTextLink* link = iRichTextViewer->GetSelectedLink();
       
   419     if( link )
       
   420         {
       
   421         if ( link->Type() == CESMRRichTextLink::ETypeLocationUrl )
       
   422             {
       
   423             ChangeMiddleSoftKeyL(EESMRCmdShowOnMap, R_QTN_MSK_OPEN );
       
   424             }
       
   425         else
       
   426             {
       
   427             RestoreMiddleSoftKeyL();
       
   428             }
       
   429         
       
   430         SetMiddleSoftKeyVisible( ETrue );
       
   431         }
       
   432     else
       
   433         {
       
   434         RestoreMiddleSoftKeyL();
       
   435         }
       
   436     }
       
   437 
       
   438 // ---------------------------------------------------------------------------
       
   439 // CESMRViewerDescriptionField::FeaturesL
       
   440 // ---------------------------------------------------------------------------
       
   441 //
       
   442 CESMRFeatureSettings& CESMRViewerDescriptionField::FeaturesL()
       
   443     {
       
   444     FUNC_LOG;
       
   445     if ( !iFeatures )
       
   446         {
       
   447         iFeatures = CESMRFeatureSettings::NewL();
       
   448         }
       
   449     
       
   450     return *iFeatures;
       
   451     }
       
   452 
       
   453 // ---------------------------------------------------------------------------
       
   454 // CESMRViewerDescriptionField::LocationPluginL
       
   455 // ---------------------------------------------------------------------------
       
   456 //
       
   457 CESMRLocationPlugin& CESMRViewerDescriptionField::LocationPluginL()
       
   458     {
       
   459     FUNC_LOG;
       
   460     if ( !iLocationPlugin )
       
   461         {
       
   462         iLocationPlugin = CESMRLocationPlugin::NewL();
       
   463         }
       
   464     
       
   465     return *iLocationPlugin;
       
   466     }
       
   467 
       
   468 //EOF
       
   469