meetingrequest/mrgui/mrfieldbuilderplugin/src/cesmrviewerdetailedsubjectfield.cpp
changeset 0 8466d47a6819
child 16 4ce476e64c59
equal deleted inserted replaced
-1:000000000000 0:8466d47a6819
       
     1 /*
       
     2 * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Detailed subject field
       
    15  *
       
    16 */
       
    17 
       
    18 #include "cesmrviewerdetailedsubjectfield.h"
       
    19 #include "cesmrrichtextviewer.h"
       
    20 #include "cesmrrichtextlink.h"
       
    21 #include "mesmrlistobserver.h"
       
    22 #include "mesmrtitlepaneobserver.h"
       
    23 #include "mesmrmeetingrequestentry.h"
       
    24 #include "cmrimage.h"
       
    25 #include "nmrlayoutmanager.h"
       
    26 
       
    27 #include <esmrgui.rsg>
       
    28 #include <StringLoader.h>
       
    29 #include <calentry.h>
       
    30 #include <AknLayout2ScalableDef.h>
       
    31 
       
    32 // DEBUG
       
    33 #include "emailtrace.h"
       
    34 
       
    35 // Unnamed namespace for local definitions and functions
       
    36 namespace { // codescanner::namespace
       
    37 /**
       
    38  * Adds forward prefix to calendar (meeting request) entry.
       
    39  * @param aEntry Reference to calendar entry.
       
    40  */
       
    41 void AddForwardPrefixToEntryL(
       
    42         CCalEntry& aEntry )
       
    43     {
       
    44     TPtrC summary( aEntry.SummaryL() );
       
    45 
       
    46     // loading 'FW:' prefix from resource
       
    47     HBufC* fwPrefix =
       
    48             StringLoader::LoadLC(
       
    49                     R_QTN_MEET_REQ_PLAIN_TEXT_FORWARDED );
       
    50 
       
    51     HBufC* subjectBuffer = HBufC::NewLC(
       
    52                     fwPrefix->Length() + summary.Length() );
       
    53     TPtr subject( subjectBuffer->Des() );
       
    54 
       
    55     // Construc 'Fw: <summary>'
       
    56     subject.Copy( *fwPrefix );
       
    57     subject.Append( summary );
       
    58 
       
    59     aEntry.SetSummaryL( subject );
       
    60 
       
    61     CleanupStack::PopAndDestroy( subjectBuffer );
       
    62     subjectBuffer = NULL;
       
    63 
       
    64     CleanupStack::PopAndDestroy( fwPrefix );
       
    65     fwPrefix = NULL;
       
    66     }
       
    67 
       
    68 }//namespace
       
    69 
       
    70 // ======== MEMBER FUNCTIONS ========
       
    71 
       
    72 // ---------------------------------------------------------------------------
       
    73 // CESMRViewerDetailedSubjectField::CESMRViewerDetailedSubjectField()
       
    74 // ---------------------------------------------------------------------------
       
    75 //
       
    76 CESMRViewerDetailedSubjectField::CESMRViewerDetailedSubjectField()
       
    77     {
       
    78     FUNC_LOG;
       
    79     SetFieldId ( EESMRFieldDetailedSubject );
       
    80     }
       
    81 
       
    82 // ---------------------------------------------------------------------------
       
    83 // CESMRViewerDetailedSubjectField::~CESMRViewerDetailedSubjectField()
       
    84 // ---------------------------------------------------------------------------
       
    85 //
       
    86 CESMRViewerDetailedSubjectField::~CESMRViewerDetailedSubjectField()
       
    87     {
       
    88     FUNC_LOG;
       
    89     iObserver = NULL;
       
    90     delete iRichTextViewer;
       
    91     delete iFieldIcon;
       
    92     }
       
    93 
       
    94 // ---------------------------------------------------------------------------
       
    95 // CESMRViewerDetailedSubjectField::NewL()
       
    96 // ---------------------------------------------------------------------------
       
    97 //
       
    98 CESMRViewerDetailedSubjectField* CESMRViewerDetailedSubjectField::NewL()
       
    99     {
       
   100     FUNC_LOG;
       
   101     CESMRViewerDetailedSubjectField* self =
       
   102             new( ELeave )CESMRViewerDetailedSubjectField;
       
   103     CleanupStack::PushL( self );
       
   104     self->ConstructL();
       
   105     CleanupStack::Pop( self );
       
   106     return self;
       
   107     }
       
   108 
       
   109 // ---------------------------------------------------------------------------
       
   110 // CESMRViewerDetailedSubjectField::ConstructL()
       
   111 // ---------------------------------------------------------------------------
       
   112 //
       
   113 void CESMRViewerDetailedSubjectField::ConstructL()
       
   114     {
       
   115     FUNC_LOG;
       
   116     SetFocusType( EESMRHighlightFocus );
       
   117     
       
   118     iFieldIcon = CMRImage::NewL( KAknsIIDQgnFscalIndiOccasion );
       
   119     iFieldIcon->SetParent( this );
       
   120     
       
   121     iRichTextViewer = CESMRRichTextViewer::NewL( this );
       
   122     iRichTextViewer->SetEdwinSizeObserver( this );
       
   123     iRichTextViewer->SetParent( this );
       
   124     }
       
   125 
       
   126 // ---------------------------------------------------------------------------
       
   127 // CESMRViewerDetailedSubjectField::SetTitlePaneObserver
       
   128 // ---------------------------------------------------------------------------
       
   129 //
       
   130 void CESMRViewerDetailedSubjectField::SetTitlePaneObserver(
       
   131         MESMRTitlePaneObserver* aObserver )
       
   132     {
       
   133     FUNC_LOG;
       
   134     iTitlePaneObserver = aObserver;
       
   135     }
       
   136 
       
   137 // ---------------------------------------------------------------------------
       
   138 // CESMRViewerDetailedSubjectField::MinimumSize
       
   139 // ---------------------------------------------------------------------------
       
   140 //
       
   141 TSize CESMRViewerDetailedSubjectField::MinimumSize()
       
   142     {
       
   143     // Let's calculate the required rect of the iRichTextViewer.
       
   144     // We will not use directly the iRichTextViewer height, because it might
       
   145     // not exist, or the height of the viewer might still be incorrect
       
   146     TRect richTextViewerRect = RichTextViewerRect();
       
   147 
       
   148     // We will use as minimum size the parents width 
       
   149     // but the calculated iRichTextViewers height 
       
   150     return TSize( Parent()->Size().iWidth, richTextViewerRect.Height() );
       
   151     }
       
   152 
       
   153 
       
   154 // ---------------------------------------------------------------------------
       
   155 // CESMRViewerDetailedSubjectField::InitializeL()
       
   156 // ---------------------------------------------------------------------------
       
   157 //
       
   158 void CESMRViewerDetailedSubjectField::InitializeL()
       
   159     {
       
   160     FUNC_LOG;
       
   161     // Setting Font for the rich text viewer
       
   162     TAknLayoutText text = NMRLayoutManager::GetLayoutText( 
       
   163             Rect(), 
       
   164             NMRLayoutManager::EMRTextLayoutTextEditor );
       
   165     
       
   166     iRichTextViewer->SetFontL( text.Font(), iLayout );
       
   167         
       
   168     // This is called so theme changes will apply when changing theme "on the fly"
       
   169     if ( IsFocused() )
       
   170         {
       
   171         iRichTextViewer->FocusChanged( EDrawNow );
       
   172         }
       
   173     }
       
   174 
       
   175 // ---------------------------------------------------------------------------
       
   176 // CESMRViewerDetailedSubjectField::InternalizeL()
       
   177 // ---------------------------------------------------------------------------
       
   178 //
       
   179 void CESMRViewerDetailedSubjectField::InternalizeL(
       
   180         MESMRCalEntry& aEntry )
       
   181     {
       
   182     FUNC_LOG;
       
   183     MESMRCalEntry::TESMRCalEntryType entryType(
       
   184             aEntry.Type() );
       
   185 
       
   186     CCalEntry& entry = aEntry.Entry();
       
   187 
       
   188     if ( MESMRCalEntry::EESMRCalEntryMeetingRequest == entryType )
       
   189         {
       
   190         MESMRMeetingRequestEntry* mrEntry =
       
   191                 static_cast<MESMRMeetingRequestEntry*>(&aEntry);
       
   192 
       
   193         if ( mrEntry->IsForwardedL() )
       
   194             {
       
   195             AddForwardPrefixToEntryL( entry );
       
   196 
       
   197             if ( iTitlePaneObserver )
       
   198                 {
       
   199                 iTitlePaneObserver->UpdateTitlePaneTextL(
       
   200                         entry.SummaryL() );
       
   201                 }
       
   202             }
       
   203         }
       
   204 
       
   205     HBufC* unnamed = StringLoader::LoadLC( R_QTN_MEET_REQ_CONFLICT_UNNAMED );
       
   206 
       
   207     TPtrC summary( entry.SummaryL() );
       
   208     HBufC* subject = summary.AllocLC();
       
   209 
       
   210     if ( summary.Length() )
       
   211         {
       
   212         iRichTextViewer->SetTextL( subject, ETrue );
       
   213         // After setting the text, the viewer line count is known
       
   214         iLineCount = iRichTextViewer->LineCount();
       
   215         }
       
   216     else
       
   217         {
       
   218         iRichTextViewer->SetTextL( unnamed, ETrue );
       
   219         // After setting the text, the viewer line count is known
       
   220         iLineCount = iRichTextViewer->LineCount();
       
   221         }
       
   222     CleanupStack::PopAndDestroy( subject );
       
   223     subject = NULL;
       
   224 
       
   225     if ( iTitlePaneObserver && aEntry.IsStoredL() )
       
   226         {
       
   227         if ( summary.Length() )
       
   228             {
       
   229             iTitlePaneObserver->UpdateTitlePaneTextL( summary );
       
   230             }
       
   231         else
       
   232             {
       
   233             iTitlePaneObserver->UpdateTitlePaneTextL( *unnamed );
       
   234             }
       
   235         }
       
   236 
       
   237     CleanupStack::PopAndDestroy( unnamed );
       
   238     unnamed = NULL;
       
   239 
       
   240     // if the entry is anniversary let's change the icon.
       
   241     if ( CCalEntry::EAnniv  != aEntry.Entry().EntryTypeL() )
       
   242         {
       
   243         delete iFieldIcon;
       
   244         iFieldIcon = NULL;
       
   245         
       
   246         iFieldIcon = CMRImage::NewL( KAknsIIDQgnFscalIndiSubject );
       
   247         iFieldIcon->SetParent( this );
       
   248         
       
   249         DrawDeferred();
       
   250         }
       
   251     iDisableRedraw = ETrue;
       
   252     }
       
   253 
       
   254 // ---------------------------------------------------------------------------
       
   255 // CESMRViewerDetailedSubjectField::OfferKeyEventL()
       
   256 // ---------------------------------------------------------------------------
       
   257 //
       
   258 TKeyResponse CESMRViewerDetailedSubjectField::OfferKeyEventL(
       
   259         const TKeyEvent& aEvent,
       
   260         TEventCode aType )
       
   261     {
       
   262     FUNC_LOG;
       
   263     return iRichTextViewer->OfferKeyEventL ( aEvent, aType );
       
   264     }
       
   265 
       
   266 // ---------------------------------------------------------------------------
       
   267 // CESMRViewerDetailedSubjectField::HandleEdwinSizeEventL()
       
   268 // ---------------------------------------------------------------------------
       
   269 //
       
   270 TBool CESMRViewerDetailedSubjectField::HandleEdwinSizeEventL(
       
   271         CEikEdwin* aEdwin, 
       
   272         TEdwinSizeEvent /*aType*/, 
       
   273         TSize aSize )
       
   274     {
       
   275     FUNC_LOG;
       
   276     TBool reDraw( EFalse );
       
   277        
       
   278     // Let's save the required size for the iRichTextViewer
       
   279     iSize = aSize;
       
   280     
       
   281     if ( iObserver && aEdwin == iRichTextViewer )
       
   282        {
       
   283        iObserver->ControlSizeChanged( this );
       
   284        reDraw = ETrue;
       
   285        }
       
   286     
       
   287     return reDraw;
       
   288     }
       
   289 
       
   290 // ---------------------------------------------------------------------------
       
   291 // CESMRViewerDetailedSubjectField::ListObserverSet
       
   292 // ---------------------------------------------------------------------------
       
   293 //
       
   294 void CESMRViewerDetailedSubjectField::ListObserverSet()
       
   295     {
       
   296     FUNC_LOG;
       
   297     iRichTextViewer->SetListObserver( iObserver );
       
   298     }
       
   299 
       
   300 // ---------------------------------------------------------------------------
       
   301 // CESMRViewerDetailedSubjectField::ExecuteGenericCommandL()
       
   302 // ---------------------------------------------------------------------------
       
   303 //
       
   304 void CESMRViewerDetailedSubjectField::ExecuteGenericCommandL( TInt aCommand )
       
   305     {
       
   306     FUNC_LOG;
       
   307     if (aCommand == EESMRCmdClipboardCopy)
       
   308         {
       
   309         iRichTextViewer->CopyCurrentLinkToClipBoardL();
       
   310         }
       
   311     else if ( aCommand == EAknSoftkeySelect )
       
   312         {
       
   313         iRichTextViewer->LinkSelectedL();
       
   314         }        
       
   315     }
       
   316 
       
   317 // ---------------------------------------------------------------------------
       
   318 // CESMRViewerDetailedSubjectField::SetOutlineFocusL()
       
   319 // ---------------------------------------------------------------------------
       
   320 //
       
   321 void CESMRViewerDetailedSubjectField::SetOutlineFocusL( TBool aFocus )
       
   322     {
       
   323     FUNC_LOG;
       
   324     CESMRField::SetOutlineFocusL ( aFocus );
       
   325     
       
   326     iRichTextViewer->SetFocus( aFocus );
       
   327     if ( !aFocus )
       
   328         {
       
   329         //need to tell action menu that focus has changed
       
   330         iRichTextViewer->ResetActionMenuL();
       
   331         }
       
   332     }
       
   333 
       
   334 // ---------------------------------------------------------------------------
       
   335 // CESMRViewerDetailedSubjectField::CountComponentControls
       
   336 // ---------------------------------------------------------------------------
       
   337 //
       
   338 TInt CESMRViewerDetailedSubjectField::CountComponentControls() const
       
   339     {
       
   340     TInt count( 0 );
       
   341     if ( iFieldIcon )
       
   342         {
       
   343         ++count;
       
   344         }
       
   345 
       
   346     if ( iRichTextViewer )
       
   347         {
       
   348         ++count;
       
   349         }
       
   350     return count;
       
   351     }
       
   352 
       
   353 // ---------------------------------------------------------------------------
       
   354 // CESMRViewerDetailedSubjectField::ComponentControl
       
   355 // ---------------------------------------------------------------------------
       
   356 //
       
   357 CCoeControl* CESMRViewerDetailedSubjectField::ComponentControl( 
       
   358         TInt aIndex ) const
       
   359     {
       
   360     switch ( aIndex )
       
   361         {
       
   362         case 0:
       
   363             return iFieldIcon;
       
   364         case 1:
       
   365             return iRichTextViewer;
       
   366         default:
       
   367             return NULL;
       
   368         }
       
   369     }
       
   370 
       
   371 // ---------------------------------------------------------------------------
       
   372 // CESMRViewerDetailedSubjectField::SizeChanged
       
   373 // ---------------------------------------------------------------------------
       
   374 //
       
   375 void CESMRViewerDetailedSubjectField::SizeChanged( )
       
   376     {
       
   377     TRect rect = Rect();
       
   378 
       
   379     // LAYOUTING FIELD ICON
       
   380     if( iFieldIcon )
       
   381         {
       
   382         TAknWindowComponentLayout iconLayout = 
       
   383             NMRLayoutManager::GetWindowComponentLayout( 
       
   384                     NMRLayoutManager::EMRLayoutTextEditorIcon );
       
   385         AknLayoutUtils::LayoutImage( iFieldIcon, rect, iconLayout );
       
   386         }
       
   387 
       
   388     // LAYOUTING FIELD BACKGROUND
       
   389     TAknLayoutRect bgLayoutRect =
       
   390         NMRLayoutManager::GetLayoutRect( 
       
   391                 rect, NMRLayoutManager::EMRLayoutTextEditorBg );
       
   392     TRect bgRect( bgLayoutRect.Rect() );
       
   393     // Move focus rect so that it's relative to field's position
       
   394     bgRect.Move( -Position() );
       
   395     SetFocusRect( bgRect );
       
   396     
       
   397     
       
   398     // LAYOUTING FIELD TEXT VIEWER
       
   399     if( iRichTextViewer )
       
   400         {
       
   401         iRichTextViewer->SetRect( RichTextViewerRect() );
       
   402         }
       
   403     }
       
   404 
       
   405 // ---------------------------------------------------------------------------
       
   406 // CESMRViewerDetailedSubjectField::SetContainerWindowL
       
   407 // ---------------------------------------------------------------------------
       
   408 //
       
   409 void CESMRViewerDetailedSubjectField::SetContainerWindowL( 
       
   410         const CCoeControl& aContainer )
       
   411     {
       
   412     CCoeControl::SetContainerWindowL( aContainer );
       
   413     iRichTextViewer->SetContainerWindowL( aContainer );
       
   414     }
       
   415 
       
   416 // ---------------------------------------------------------------------------
       
   417 // CESMRViewerDetailedSubjectField::RichTextViewerRect
       
   418 // ---------------------------------------------------------------------------
       
   419 //
       
   420 TRect CESMRViewerDetailedSubjectField::RichTextViewerRect()
       
   421     {
       
   422     TRect rect = Rect();
       
   423     
       
   424     TAknTextComponentLayout edwinLayout = NMRLayoutManager::GetTextComponentLayout( 
       
   425             NMRLayoutManager::EMRTextLayoutTextEditor );
       
   426 
       
   427     // Text layout rect for one line viewer
       
   428     TAknLayoutText textLayout;
       
   429     textLayout.LayoutText( rect, edwinLayout );
       
   430     TRect textLayoutRect = textLayout.TextRect();
       
   431 
       
   432     TRect viewerRect = textLayoutRect;
       
   433     
       
   434     // If iRichTextViewer has lines and iSize has been set, 
       
   435     // we will use iSize.iHeight as the viewers height
       
   436     if( iLineCount > 0 && iSize.iHeight > 0 )
       
   437         {
       
   438         viewerRect.SetHeight( iSize.iHeight );
       
   439         }
       
   440     // Otherwise we will use one row height as the height of the 
       
   441     // iRichTextViewer
       
   442     else
       
   443         {
       
   444         TAknLayoutRect rowLayoutRect = 
       
   445             NMRLayoutManager::GetFieldRowLayoutRect( rect, 1 );
       
   446         viewerRect.SetHeight( rowLayoutRect.Rect().Height() );
       
   447         }
       
   448    
       
   449     return viewerRect;
       
   450     }
       
   451 
       
   452 //EOF