meetingrequest/mrgui/mrfieldbuilderpluginextension/src/cesmrviewerfromfield.cpp
branchRCL_3
changeset 12 4ce476e64c59
parent 1 12c456ceeff2
child 16 b5fbb9b25d57
equal deleted inserted replaced
11:0396474f30f5 12:4ce476e64c59
     1 /*
     1 /*
     2 * Copyright (c) 2003-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".
    18 #include "cesmrviewerfromfield.h"
    18 #include "cesmrviewerfromfield.h"
    19 #include "cesmrrichtextviewer.h"
    19 #include "cesmrrichtextviewer.h"
    20 #include "cesmrrichtextlink.h"
    20 #include "cesmrrichtextlink.h"
    21 #include "mesmrlistobserver.h"
    21 #include "mesmrlistobserver.h"
    22 #include "esmrfieldbuilderdef.h"
    22 #include "esmrfieldbuilderdef.h"
    23 #include "cesmrlayoutmgr.h"
       
    24 #include "nmrlayoutmanager.h"
    23 #include "nmrlayoutmanager.h"
    25 #include "cmrlabel.h"
    24 #include "cmrlabel.h"
    26 
    25 
    27 #include <calentry.h>
    26 #include <calentry.h>
    28 #include <caluser.h>
    27 #include <caluser.h>
    29 #include <StringLoader.h>
    28 #include <stringloader.h>
    30 #include <eikenv.h>
    29 #include <eikenv.h>
    31 #include <avkon.hrh>
    30 #include <avkon.hrh>
    32 #include <AknUtils.h>
    31 #include <aknutils.h>
    33 #include <esmrgui.rsg>
    32 #include <esmrgui.rsg>
    34 
    33 
    35 // DEBUG
    34 // DEBUG
    36 #include "emailtrace.h"
    35 #include "emailtrace.h"
    37 
    36 
    38 /// Unnamed namespace for local definitions
       
    39 namespace { // codescanner::namespace
       
    40 
       
    41 const TInt KMargin = 5;
       
    42 
       
    43 } // namespace
       
    44 
       
    45 using namespace ESMRLayout;
       
    46 
    37 
    47 // ======== MEMBER FUNCTIONS ========
    38 // ======== MEMBER FUNCTIONS ========
    48 
    39 
    49 // ---------------------------------------------------------------------------
    40 // ---------------------------------------------------------------------------
    50 // CESMRViewerFromField::NewL()
    41 // CESMRViewerFromField::NewL()
    66 //
    57 //
    67 CESMRViewerFromField::~CESMRViewerFromField( )
    58 CESMRViewerFromField::~CESMRViewerFromField( )
    68     {
    59     {
    69     FUNC_LOG;
    60     FUNC_LOG;
    70     delete iFieldTopic;
    61     delete iFieldTopic;
    71     delete iRichTextViewer;
       
    72     }
    62     }
    73 
    63 
    74 // ---------------------------------------------------------------------------
    64 // ---------------------------------------------------------------------------
    75 // CESMRViewerFromField::InitializeL()
    65 // CESMRViewerFromField::InitializeL()
    76 // ---------------------------------------------------------------------------
    66 // ---------------------------------------------------------------------------
    77 //
    67 //
    78 void CESMRViewerFromField::InitializeL()
    68 void CESMRViewerFromField::InitializeL()
    79     {
    69     {
    80     FUNC_LOG;
    70     FUNC_LOG;
    81     TAknLayoutText editorRect = 
    71     TAknLayoutText editorRect =
    82     NMRLayoutManager::GetLayoutText( 
    72     NMRLayoutManager::GetLayoutText(
    83             Rect(), NMRLayoutManager::EMRTextLayoutMultiRowTextEditor );
    73             Rect(), NMRLayoutManager::EMRTextLayoutMultiRowTextEditor );
    84     iRichTextViewer->SetFontL( editorRect.Font(), iLayout );
    74     iRichTextViewer->SetFontL( editorRect.Font() );
    85     const CFont* topicFont = 
    75     iRichTextViewer->ApplyLayoutChangesL();
       
    76     
       
    77     const CFont* topicFont =
    86         AknLayoutUtils::FontFromId( EAknLogicalFontPrimaryFont, NULL );
    78         AknLayoutUtils::FontFromId( EAknLogicalFontPrimaryFont, NULL );
    87     iFieldTopic->SetFont( topicFont );
    79     iFieldTopic->SetFont( topicFont );
       
    80     iRichTextViewer->SetEventQueue( iEventQueue );
    88     }
    81     }
    89 
    82 
    90 // ---------------------------------------------------------------------------
    83 // ---------------------------------------------------------------------------
    91 // CESMRViewerFromField::InternalizeL()
    84 // CESMRViewerFromField::InternalizeL()
    92 // ---------------------------------------------------------------------------
    85 // ---------------------------------------------------------------------------
   101         if (text.Length() == 0 )
    94         if (text.Length() == 0 )
   102             {
    95             {
   103             text.Set (organizer->Address() );
    96             text.Set (organizer->Address() );
   104             }
    97             }
   105         iRichTextViewer->SetTextL( &text );
    98         iRichTextViewer->SetTextL( &text );
   106         iRichTextViewer->SetMargins( KMargin );
       
   107 
    99 
   108         TPtrC address = organizer->Address();
   100         TPtrC address = organizer->Address();
   109         if ( address.Length() > 0 )
   101         if ( address.Length() > 0 )
   110             {
   102             {
   111             CESMRRichTextLink* link = CESMRRichTextLink::NewL( 0,
   103             CESMRRichTextLink* link = CESMRRichTextLink::NewL( 0,
   115             iRichTextViewer->AddLinkL( link );
   107             iRichTextViewer->AddLinkL( link );
   116             CleanupStack::Pop( link );
   108             CleanupStack::Pop( link );
   117             }
   109             }
   118 
   110 
   119         // Set the topic text
   111         // Set the topic text
   120         HBufC* stringholder = 
   112         HBufC* stringholder =
   121             StringLoader::LoadLC( R_QTN_MEET_REQ_LABEL_FROM, iEikonEnv );
   113             StringLoader::LoadLC( R_QTN_MEET_REQ_LABEL_FROM, iEikonEnv );
   122         iFieldTopic->SetTextL( *stringholder );
   114         iFieldTopic->SetTextL( *stringholder );
   123         CleanupStack::PopAndDestroy( stringholder );
   115         CleanupStack::PopAndDestroy( stringholder );
   124 
   116 
   125         //wake up current contact menu selection by calling this
   117         //wake up current contact menu selection by calling this
   126         iRichTextViewer->FocusChanged( ENoDrawNow );
   118         iRichTextViewer->FocusChanged( ENoDrawNow );
   127         SizeChanged( );
       
   128         }
   119         }
   129     iDisableRedraw = ETrue;
   120     iDisableRedraw = ETrue;
   130     }
   121     }
   131 
   122 
   132 // ---------------------------------------------------------------------------
   123 // ---------------------------------------------------------------------------
   135 //
   126 //
   136 void CESMRViewerFromField::SizeChanged( )
   127 void CESMRViewerFromField::SizeChanged( )
   137     {
   128     {
   138     FUNC_LOG;
   129     FUNC_LOG;
   139     TRect rect( Rect() );
   130     TRect rect( Rect() );
   140     
   131 
   141     TAknLayoutRect row1LayoutRect =
   132     TAknLayoutRect row1LayoutRect =
   142         NMRLayoutManager::GetFieldRowLayoutRect( rect, 1 );
   133         NMRLayoutManager::GetFieldRowLayoutRect( rect, 1 );
   143     rect = row1LayoutRect.Rect();
   134     rect = row1LayoutRect.Rect();
   144     
   135 
   145     TAknTextComponentLayout labelLayout =
   136     TAknTextComponentLayout labelLayout =
   146         NMRLayoutManager::GetTextComponentLayout( 
   137         NMRLayoutManager::GetTextComponentLayout(
   147                 NMRLayoutManager::EMRTextLayoutText );
   138                 NMRLayoutManager::EMRTextLayoutText );
   148     AknLayoutUtils::LayoutLabel( iFieldTopic, rect, labelLayout );
   139     AknLayoutUtils::LayoutLabel( iFieldTopic, rect, labelLayout );
   149     // Color should be overrided after layouting
       
   150     // If this function leaves we'll have to use default color
       
   151     TRAP_IGNORE( AknLayoutUtils::OverrideControlColorL( 
       
   152                                 *iFieldTopic, 
       
   153                                 EColorLabelText,
       
   154                                 KRgbBlack ));    
       
   155 
   140 
   156     rect = Rect();
   141     rect = Rect();
   157     TAknLayoutRect row2LayoutRect =
   142     TAknLayoutRect row2LayoutRect =
   158         NMRLayoutManager::GetFieldRowLayoutRect( rect, 2 );
   143         NMRLayoutManager::GetFieldRowLayoutRect( rect, 2 );
   159     rect = row2LayoutRect.Rect();
   144     rect = row2LayoutRect.Rect();
   160 
   145 
   161     // Move the iY down the height of the title field
   146     // Move the iY down the height of the title field
   162     TInt moveHeight = row1LayoutRect.Rect().Height();
   147     TInt moveHeight = row1LayoutRect.Rect().Height();
   163     rect.Move( 0, moveHeight );
   148     rect.Move( 0, moveHeight );
   164 
   149 
   165     TAknLayoutText editorRect = 
   150     TAknLayoutText editorRect =
   166         NMRLayoutManager::GetLayoutText( 
   151         NMRLayoutManager::GetLayoutText(
   167                 rect, NMRLayoutManager::EMRTextLayoutMultiRowTextEditor );
   152                 rect, NMRLayoutManager::EMRTextLayoutMultiRowTextEditor );
   168     // Count the rect for the richtextviewer. It will be placed into the 
   153     // Count the rect for the richtextviewer. It will be placed into the
   169     // top left corner of the editorRect and size is calculated from 
   154     // top left corner of the editorRect and size is calculated from
   170     // viewer's real size iExpandedSize and editorRect's width.
   155     // viewer's real size iExpandedSize and editorRect's width.
   171     TPoint tlPoint( 
   156     TPoint tlPoint(
   172             editorRect.TextRect().iTl.iX, editorRect.TextRect().iTl.iY );
   157             editorRect.TextRect().iTl.iX, editorRect.TextRect().iTl.iY );
   173     TSize prefSize( editorRect.TextRect().Width(), iExpandedSize.iHeight );
   158     TSize prefSize( editorRect.TextRect().Width(), iExpandedSize.iHeight );
   174     TRect viewerRect( tlPoint, prefSize );
   159     TRect viewerRect( tlPoint, prefSize );
       
   160     // Failures are ignored. 
       
   161     TRAP_IGNORE( 
       
   162             // Try setting font 
       
   163             iRichTextViewer->SetFontL( editorRect.Font() );
       
   164             // Try applying changes
       
   165             iRichTextViewer->ApplyLayoutChangesL();
       
   166             );
   175     iRichTextViewer->SetRect( viewerRect );
   167     iRichTextViewer->SetRect( viewerRect );
       
   168 
       
   169     TRect bgRect( viewerRect );
       
   170     // Move focus rect so that it's relative to field's position.
       
   171     bgRect.Move( -Position() );
       
   172     SetFocusRect( bgRect );
   176     }
   173     }
   177 
   174 
   178 // ---------------------------------------------------------------------------
   175 // ---------------------------------------------------------------------------
   179 // CESMRViewerFromField::MinimumSize()
   176 // CESMRViewerFromField::MinimumSize()
   180 // ---------------------------------------------------------------------------
   177 // ---------------------------------------------------------------------------
   181 //
   178 //
   182 TSize CESMRViewerFromField::MinimumSize()
   179 TSize CESMRViewerFromField::MinimumSize()
   183     {    
   180     {
   184     // Minimum size ->  Height: TitleRow + Editor size + Margin
   181     // Minimum size ->  Height: TitleRow + Editor size + Margin
   185     //                  Width: Parent's Width 
   182     //                  Width: Parent's Width
   186     //                   (so the content pane that holds all the fields)     
   183     //                   (so the content pane that holds all the fields)
   187     TRect rect = Rect();
   184     TRect rect = Rect();
   188     TAknLayoutRect row1LayoutRect =
   185     TAknLayoutRect row1LayoutRect =
   189         NMRLayoutManager::GetFieldRowLayoutRect( rect, 1 );
   186         NMRLayoutManager::GetFieldRowLayoutRect( rect, 1 );
   190     TInt titleHeight = row1LayoutRect.Rect().Height();
   187     TInt titleHeight = row1LayoutRect.Rect().Height();
   191     // Add title field height
   188     // Add title field height
   192     TInt totalHeight = titleHeight;
   189     TInt totalHeight = titleHeight;
   193     
   190 
   194     TAknLayoutRect row2LayoutRect =
   191     TAknLayoutRect row2LayoutRect =
   195         NMRLayoutManager::GetFieldRowLayoutRect( rect, 2 );
   192         NMRLayoutManager::GetFieldRowLayoutRect( rect, 2 );
   196     TInt editorRowHeight = row2LayoutRect.Rect().Height();
   193     TInt editorRowHeight = row2LayoutRect.Rect().Height();
   197     
   194 
   198     TAknTextComponentLayout editorLayout =
   195     TAknTextComponentLayout editorLayout =
   199         NMRLayoutManager::GetTextComponentLayout( 
   196         NMRLayoutManager::GetTextComponentLayout(
   200                 NMRLayoutManager::EMRTextLayoutMultiRowTextEditor );
   197                 NMRLayoutManager::EMRTextLayoutMultiRowTextEditor );
   201     // Editor height from Layout data
   198     // Editor height from Layout data
   202     TInt editorHeight = editorLayout.H();
   199     TInt editorHeight = editorLayout.H();
   203     // Margin is the outer row's height - editor's layout height
   200     // Margin is the outer row's height - editor's layout height
   204     TInt margin = editorRowHeight - editorHeight;
   201     TInt margin = editorRowHeight - editorHeight;
   225         }
   222         }
   226     if ( iRichTextViewer )
   223     if ( iRichTextViewer )
   227         {
   224         {
   228         count++;
   225         count++;
   229         }
   226         }
   230     
   227 
   231     return count;
   228     return count;
   232     }
   229     }
   233 
   230 
   234 // ---------------------------------------------------------------------------
   231 // ---------------------------------------------------------------------------
   235 // CESMRViewerFromField::ComponentControl()
   232 // CESMRViewerFromField::ComponentControl()
   281 // ---------------------------------------------------------------------------
   278 // ---------------------------------------------------------------------------
   282 //
   279 //
   283 CESMRViewerFromField::CESMRViewerFromField( )
   280 CESMRViewerFromField::CESMRViewerFromField( )
   284     {
   281     {
   285     FUNC_LOG;
   282     FUNC_LOG;
   286     //do nothing
   283     SetFocusType( EESMRHighlightFocus );
   287     }
   284     }
   288 
   285 
   289 // ---------------------------------------------------------------------------
   286 // ---------------------------------------------------------------------------
   290 // CESMRViewerFromField::ConstructL()
   287 // CESMRViewerFromField::ConstructL()
   291 // ---------------------------------------------------------------------------
   288 // ---------------------------------------------------------------------------
   297 
   294 
   298     iFieldTopic = CMRLabel::NewL();
   295     iFieldTopic = CMRLabel::NewL();
   299     iFieldTopic->SetTextL( KNullDesC() );
   296     iFieldTopic->SetTextL( KNullDesC() );
   300 
   297 
   301     iRichTextViewer = CESMRRichTextViewer::NewL ( this );
   298     iRichTextViewer = CESMRRichTextViewer::NewL ( this );
       
   299     CESMRField::ConstructL( iRichTextViewer ); // ownership transferred
   302     iRichTextViewer->SetEdwinSizeObserver ( this );
   300     iRichTextViewer->SetEdwinSizeObserver ( this );
       
   301     iRichTextViewer->SetParent( this );
   303     }
   302     }
   304 
   303 
   305 // ---------------------------------------------------------------------------
   304 // ---------------------------------------------------------------------------
   306 // CESMRViewerFromField::ExecuteGenericCommandL()
   305 // CESMRViewerFromField::ExecuteGenericCommandL()
   307 // ---------------------------------------------------------------------------
   306 // ---------------------------------------------------------------------------
   308 //
   307 //
   309 void CESMRViewerFromField::ExecuteGenericCommandL( TInt aCommand )
   308 TBool CESMRViewerFromField::ExecuteGenericCommandL( TInt aCommand )
   310     {
   309     {
   311     FUNC_LOG;
   310     FUNC_LOG;
       
   311     TBool isUsed( EFalse );
   312     if (aCommand == EESMRCmdClipboardCopy)
   312     if (aCommand == EESMRCmdClipboardCopy)
   313         {
   313         {
   314         iRichTextViewer->CopyCurrentLinkValueToClipBoardL();
   314         iRichTextViewer->CopyCurrentLinkToClipBoardL();
       
   315         isUsed = ETrue;
   315         }
   316         }
   316     if ( aCommand == EAknSoftkeySelect )
   317     if ( aCommand == EAknSoftkeySelect )
   317         {
   318         {
   318         iRichTextViewer->LinkSelectedL();
   319         iRichTextViewer->LinkSelectedL();
   319         }
   320         isUsed = ETrue;
   320     }
   321         }
   321 
   322     return isUsed;
   322 // ---------------------------------------------------------------------------
   323     }
   323 // CESMRViewerFromField::ExecuteGenericCommandL()
   324 
       
   325 // ---------------------------------------------------------------------------
       
   326 // CESMRViewerFromField::SetOutlineFocusL
   324 // ---------------------------------------------------------------------------
   327 // ---------------------------------------------------------------------------
   325 //
   328 //
   326 void CESMRViewerFromField::SetOutlineFocusL( TBool aFocus )
   329 void CESMRViewerFromField::SetOutlineFocusL( TBool aFocus )
   327     {
   330     {
   328     FUNC_LOG;
   331     FUNC_LOG;
   329     CESMRField::SetOutlineFocusL ( aFocus );
   332     CESMRField::SetOutlineFocusL ( aFocus );
   330     if ( iRichTextViewer )
   333     if ( iRichTextViewer )
   331         {
   334         {
   332         iRichTextViewer->SetFocus( aFocus );
   335         iRichTextViewer->SetFocus( aFocus );
       
   336         }
       
   337     if ( aFocus )
       
   338         {
       
   339         SetMiddleSoftKeyVisible( ETrue );
       
   340         }
       
   341     else if( iRichTextViewer )
       
   342         {
       
   343         //need to tell action menu that focus has changed
       
   344         iRichTextViewer->ResetActionMenuL();
       
   345         }
       
   346     }
       
   347 
       
   348 // ---------------------------------------------------------------------------
       
   349 // CESMRViewerFromField::HandleLongtapEventL
       
   350 // ---------------------------------------------------------------------------
       
   351 //
       
   352 void CESMRViewerFromField::HandleLongtapEventL( const TPoint& aPosition )
       
   353     {
       
   354     FUNC_LOG;
   333     
   355     
   334 		if ( aFocus )
   356     if ( iRichTextViewer->Rect().Contains( aPosition ) )
   335 			{
   357         {
   336 			SetMiddleSoftKeyVisible( ETrue );
   358         iRichTextViewer->LinkSelectedL();
   337 			}
   359 		HandleTactileFeedbackL();
   338 		else
   360         }
   339 			{
       
   340 			//need to tell action menu that focus has changed
       
   341 			iRichTextViewer->ResetActionMenuL();
       
   342 			}
       
   343         }    
       
   344     }
   361     }
   345 
   362 
   346 // ---------------------------------------------------------------------------
   363 // ---------------------------------------------------------------------------
   347 // CESMRViewerFromField::SetContainerWindowL()
   364 // CESMRViewerFromField::SetContainerWindowL()
   348 // ---------------------------------------------------------------------------
   365 // ---------------------------------------------------------------------------
   352     FUNC_LOG;
   369     FUNC_LOG;
   353     CESMRField::SetContainerWindowL( aContainer );
   370     CESMRField::SetContainerWindowL( aContainer );
   354     if ( iRichTextViewer )
   371     if ( iRichTextViewer )
   355         {
   372         {
   356         iRichTextViewer->SetContainerWindowL( aContainer );
   373         iRichTextViewer->SetContainerWindowL( aContainer );
   357         }
   374         iRichTextViewer->SetParent( this );
   358     }
   375         }
   359 // -----------------------------------------------------------------------------
   376     }
   360 // CESMRViewerFromField::HandlePointerEventL
   377 
   361 // -----------------------------------------------------------------------------
       
   362 //
       
   363 void CESMRViewerFromField::HandlePointerEventL(const TPointerEvent& aPointerEvent)
       
   364     {
       
   365     CCoeControl::HandlePointerEventL(aPointerEvent);
       
   366 
       
   367     if ( aPointerEvent.iType == TPointerEvent::EButton1Down )
       
   368         {
       
   369         iRichTextViewer->SetFocus( ETrue );
       
   370         }
       
   371     }
       
   372 //EOF
   378 //EOF
   373 
   379