meetingrequest/mrgui/mrfieldbuilderpluginextension/src/cesmrresponseitem.cpp
branchRCL_3
changeset 12 4ce476e64c59
parent 0 8466d47a6819
child 20 efd4f1afd43e
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".
    15 *
    15 *
    16 */
    16 */
    17 #include "cesmrresponseitem.h"
    17 #include "cesmrresponseitem.h"
    18 #include "nmrlayoutmanager.h"
    18 #include "nmrlayoutmanager.h"
    19 #include "nmrbitmapmanager.h"
    19 #include "nmrbitmapmanager.h"
    20 #include "cesmrlayoutmgr.h"
    20 #include "nmrcolormanager.h"
    21 #include "cmrimage.h"
    21 #include "cmrimage.h"
    22 #include "cmrlabel.h"
    22 #include "cmrlabel.h"
    23 
    23 
    24 #include <esmrgui.rsg>
    24 #include <esmrgui.rsg>
    25 
    25 
   110 // -----------------------------------------------------------------------------
   110 // -----------------------------------------------------------------------------
   111 //
   111 //
   112 void CESMRResponseItem::Draw( const TRect& aRect ) const
   112 void CESMRResponseItem::Draw( const TRect& aRect ) const
   113     {
   113     {
   114     FUNC_LOG;
   114     FUNC_LOG;
   115     //switch font color to unhighlighted, leave can be ignored
   115     NMRColorManager::SetColor( *iSelectionLabel, 
   116     //since it's just a color change
   116                                NMRColorManager::EMRMainAreaTextColor );
   117     TRAP_IGNORE(AknLayoutUtils::OverrideControlColorL(
   117     
   118             *iSelectionLabel,
       
   119             EColorLabelText,
       
   120             KRgbBlack ));
       
   121     if( iHighlighted )
   118     if( iHighlighted )
   122         {
   119         {
   123         //switch font color to highlighted, leave can be ignored
       
   124         //since it's just a color change
       
   125         TRAP_IGNORE(AknLayoutUtils::OverrideControlColorL(
       
   126                 *iSelectionLabel,
       
   127                 EColorLabelText,
       
   128                 iLayout->ViewerListAreaHighlightedTextColor() ));
       
   129 
       
   130         CWindowGc& gc = SystemGc();
   120         CWindowGc& gc = SystemGc();
   131         TRect rect = aRect;
   121         TRect rect = aRect;
   132         TBool enableEdges(ETrue);
   122         TBool enableEdges(ETrue);
   133 
   123 
   134         CFbsBitmap* selector = NULL;
   124         CFbsBitmap* selector = NULL;
   300         {
   290         {
   301         TAknTextComponentLayout labelLayout =
   291         TAknTextComponentLayout labelLayout =
   302             NMRLayoutManager::GetTextComponentLayout( 
   292             NMRLayoutManager::GetTextComponentLayout( 
   303                     NMRLayoutManager::EMRTextLayoutText );
   293                     NMRLayoutManager::EMRTextLayoutText );
   304         AknLayoutUtils::LayoutLabel( iSelectionLabel, rect, labelLayout );
   294         AknLayoutUtils::LayoutLabel( iSelectionLabel, rect, labelLayout );
   305         }
   295         // SizeChange() is called when rect for ResponseItem is ready to be used.
   306 
   296         // If setting text to response topic label fails, no need to catch it.
   307 
   297         TRAP_IGNORE(SetTextToLabelL());
       
   298         }
   308     }
   299     }
   309 
   300 
   310 // -----------------------------------------------------------------------------
   301 // -----------------------------------------------------------------------------
   311 // CESMRResponseItem::IconL
   302 // CESMRResponseItem::IconL
   312 // -----------------------------------------------------------------------------
   303 // -----------------------------------------------------------------------------
   364 //
   355 //
   365 void CESMRResponseItem::SetFont( const CFont* aFont )
   356 void CESMRResponseItem::SetFont( const CFont* aFont )
   366     {
   357     {
   367     FUNC_LOG;
   358     FUNC_LOG;
   368     iSelectionLabel->SetFont( aFont );
   359     iSelectionLabel->SetFont( aFont );
   369     // Leave case can be ignored here because there is nothing to do about it
   360 
   370     TRAP_IGNORE(AknLayoutUtils::OverrideControlColorL(
   361     NMRColorManager::SetColor( *iSelectionLabel, 
   371                                       *iSelectionLabel,
   362                                NMRColorManager::EMRMainAreaTextColor );
   372                                       EColorLabelText,
       
   373                                       KRgbBlack ) );
       
   374     }
   363     }
   375 
   364 
   376 // -----------------------------------------------------------------------------
   365 // -----------------------------------------------------------------------------
   377 // CESMRResponseItem::SetTextL
   366 // CESMRResponseItem::SetTextL
   378 // -----------------------------------------------------------------------------
   367 // -----------------------------------------------------------------------------
   390         iItemText = HBufC::NewL( aItemText.Length() );
   379         iItemText = HBufC::NewL( aItemText.Length() );
   391         *iItemText = aItemText;
   380         *iItemText = aItemText;
   392         }
   381         }
   393     else if( !iItemText &&  aItemText.Length() <= 0 )
   382     else if( !iItemText &&  aItemText.Length() <= 0 )
   394         {
   383         {
   395         // if there is no text yet, there is nothing to do here.
   384         // if there is no new text yet, there is nothing to do here.
   396         return;
   385         return;
   397         }
   386         }
   398 
   387     SetTextToLabelL();
   399     TInt lineCount = 1; // Default line count.
   388     }
   400     // If this item has no icon, it may use two lines for the text
   389 
   401     if( !iIcon )
   390 // -----------------------------------------------------------------------------
   402         {
   391 // CESMRResponseItem::SetTextToLabelL
   403         lineCount = KMaxLinesInResponseTopicItem;
   392 // -----------------------------------------------------------------------------
   404         }
   393 //
   405     // Text wrapping
   394 void CESMRResponseItem::SetTextToLabelL()
   406     CArrayFixFlat<TInt>* widthArray =
   395 	{
   407                         new (ELeave) CArrayFixFlat<TInt>( lineCount );
   396 	if( iItemText )
   408     CleanupStack::PushL( widthArray );
   397 		{
   409     for ( TInt i(0); i < lineCount; i++ )
   398 		TInt lineCount = 1; // Default line count.
   410         {
   399 		// If this item has no icon, it may use two lines for the text
   411         // If this item has no icon, all the space is for text
   400 		if( !iIcon )
   412         if( !iIcon )
   401 			{
   413             {
   402 			lineCount = KMaxLinesInResponseTopicItem;
   414             TAknLayoutText layout = NMRLayoutManager::GetLayoutText( Rect(), NMRLayoutManager::EMRTextLayoutText );            
   403 			}
   415             widthArray->AppendL( layout.TextRect().Width() );
   404 		
   416             }
   405 		// Text wrapping
   417         else
   406 		CArrayFixFlat<TInt>* widthArray =
   418             {
   407 							new (ELeave) CArrayFixFlat<TInt>( lineCount );
   419             widthArray->AppendL( iLayout->ResponseAreaAnswerTextSize().iWidth );
   408 		CleanupStack::PushL( widthArray );
   420             }
   409 		
   421         }
   410 		for ( TInt i(0); i < lineCount; i++ )
   422 
   411 			{
   423     HBufC* wrappedText;
   412 			// If this item has no icon, all the space is for text
   424     // Set the font for the text
   413 			if( !iIcon )
   425     const CFont* font = iSelectionLabel->Font();
   414 				{
   426     RBuf buffer; // codescanner::resourcenotoncleanupstack
   415 				TAknLayoutText layout = NMRLayoutManager::GetLayoutText( 
   427     buffer.CreateL( iOriginalTextLength + widthArray->Count() );
   416 						Rect(), NMRLayoutManager::EMRTextLayoutText );            
   428     buffer.CleanupClosePushL();
   417 				widthArray->AppendL( layout.TextRect().Width() );
   429 
   418 				}
   430     // Wrap the text
   419 			else
   431     AknTextUtils::WrapToStringAndClipL( iItemText->Des(), *widthArray, *font, buffer );
   420 				{
   432     wrappedText = buffer.AllocLC();
   421 				// This layout leaves space for the icon to the left side
   433 
   422 				TAknLayoutText layout = NMRLayoutManager::GetLayoutText( 
   434     // Set the text to label
   423 						Rect(), NMRLayoutManager::EMRTextLayoutTextEditor ); 	
   435     iSelectionLabel->SetTextL( *wrappedText );
   424 				widthArray->AppendL( layout.TextRect().Width() );
   436     CleanupStack::PopAndDestroy(3); // widthArray, wrappedText, buffer
   425 				}
   437     }
   426 			}
   438 
   427 
   439 // -----------------------------------------------------------------------------
   428 		HBufC* wrappedText;
   440 // CESMRResponseItem::SetLayoutManager
   429 		// Set the font for the text
   441 // -----------------------------------------------------------------------------
   430 		const CFont* font = iSelectionLabel->Font();
   442 //
   431 		RBuf buffer; // codescanner::resourcenotoncleanupstack
   443 void CESMRResponseItem::SetLayoutManager( CESMRLayoutManager* aLayout )
   432 		buffer.CreateL( iOriginalTextLength + widthArray->Count() );
   444     {
   433 		buffer.CleanupClosePushL();
   445     FUNC_LOG;
   434 
   446     iLayout = aLayout;
   435 		// Wrap the text
   447     }
   436 		AknTextUtils::WrapToStringAndClipL( *iItemText, *widthArray, *font, buffer );
       
   437 		wrappedText = buffer.AllocLC();
       
   438 
       
   439 		// Set the text to label
       
   440 		iSelectionLabel->SetTextL( *wrappedText );
       
   441 		CleanupStack::PopAndDestroy(3); // widthArray, wrappedText, buffer		
       
   442 		}
       
   443 	}
   448 
   444 
   449 // -----------------------------------------------------------------------------
   445 // -----------------------------------------------------------------------------
   450 // CESMRResponseItem::ItemTextLineCount
   446 // CESMRResponseItem::ItemTextLineCount
   451 // -----------------------------------------------------------------------------
   447 // -----------------------------------------------------------------------------
   452 //
   448 //
   469     {
   465     {
   470     FUNC_LOG;
   466     FUNC_LOG;
   471     return iCmd;
   467     return iCmd;
   472     }
   468     }
   473 
   469 
       
   470 // -----------------------------------------------------------------------------
       
   471 // CESMRResponseItem::SetUnderlineL
       
   472 // -----------------------------------------------------------------------------
       
   473 //
       
   474 void CESMRResponseItem::SetUnderlineL( TBool aUndreline )
       
   475     {
       
   476     iSelectionLabel->SetUnderlining( aUndreline );
       
   477     }
       
   478