meetingrequest/mrgui/mrfieldbuilderpluginextension/src/cesmrresponseitem.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:  Meeting Request viewer response field implementation
       
    15 *
       
    16 */
       
    17 #include "cesmrresponseitem.h"
       
    18 #include "nmrlayoutmanager.h"
       
    19 #include "nmrbitmapmanager.h"
       
    20 #include "cesmrlayoutmgr.h"
       
    21 #include "cmrimage.h"
       
    22 #include "cmrlabel.h"
       
    23 
       
    24 #include <esmrgui.rsg>
       
    25 
       
    26 // DEBUG
       
    27 #include "emailtrace.h"
       
    28 
       
    29 namespace // codescanner::namespace
       
    30     {
       
    31     const TInt KMaxLinesInResponseTopicItem( 2 );
       
    32     const TInt KEdge(8);
       
    33     } // unnamed namespace
       
    34 // ======== MEMBER FUNCTIONS ========
       
    35 
       
    36 // -----------------------------------------------------------------------------
       
    37 // CESMRResponseItem::NewL
       
    38 // -----------------------------------------------------------------------------
       
    39 //
       
    40 CESMRResponseItem* CESMRResponseItem::NewL( TESMRCommand aCmd,
       
    41                                             const TDesC& aItemText,
       
    42                                             TBool aHasIcon )
       
    43     {
       
    44     FUNC_LOG;
       
    45     CESMRResponseItem* self = CESMRResponseItem::NewLC( aCmd,
       
    46                                                         aItemText,
       
    47                                                         aHasIcon );
       
    48     CleanupStack::Pop( self );
       
    49     return self;
       
    50     }
       
    51 
       
    52 // -----------------------------------------------------------------------------
       
    53 // CESMRResponseItem::NewL
       
    54 // -----------------------------------------------------------------------------
       
    55 //
       
    56 CESMRResponseItem* CESMRResponseItem::NewLC( TESMRCommand aCmd,
       
    57                                              const TDesC& aItemText,
       
    58                                              TBool aHasIcon )
       
    59     {
       
    60     FUNC_LOG;
       
    61     CESMRResponseItem* self = new (ELeave) CESMRResponseItem( aCmd );
       
    62     CleanupStack::PushL( self );
       
    63     self->ConstructL( aItemText, aHasIcon );
       
    64     return self;
       
    65     }
       
    66 
       
    67 // -----------------------------------------------------------------------------
       
    68 // CESMRResponseItem::~CESMRResponseItem
       
    69 // -----------------------------------------------------------------------------
       
    70 //
       
    71 CESMRResponseItem::~CESMRResponseItem()
       
    72     {
       
    73     FUNC_LOG;
       
    74     delete iSelectionLabel;
       
    75     delete iIcon;
       
    76     delete iItemText;
       
    77     }
       
    78 
       
    79 // -----------------------------------------------------------------------------
       
    80 // CESMRResponseItem::CESMRResponseItem
       
    81 // -----------------------------------------------------------------------------
       
    82 //
       
    83 CESMRResponseItem::CESMRResponseItem(TESMRCommand aCmd)
       
    84 : iCmd (aCmd)
       
    85     {
       
    86     FUNC_LOG;
       
    87     //do nothing
       
    88     }
       
    89 
       
    90 // -----------------------------------------------------------------------------
       
    91 // CESMRResponseItem::ConstructL
       
    92 // -----------------------------------------------------------------------------
       
    93 //
       
    94 void CESMRResponseItem::ConstructL( const TDesC& aItemText, TBool aHasIcon )
       
    95     {
       
    96     FUNC_LOG;
       
    97     iSelectionLabel = CMRLabel::NewL();
       
    98     iSelectionLabel->SetTextL( aItemText );
       
    99 
       
   100     // Response item might not have icon. e.g. topic line
       
   101     iHasIcon = aHasIcon;
       
   102     if( aHasIcon )
       
   103         {
       
   104         iIcon = IconL( EFalse );
       
   105         }
       
   106     }
       
   107 
       
   108 // -----------------------------------------------------------------------------
       
   109 // CESMRResponseItem::Draw
       
   110 // -----------------------------------------------------------------------------
       
   111 //
       
   112 void CESMRResponseItem::Draw( const TRect& aRect ) const
       
   113     {
       
   114     FUNC_LOG;
       
   115     //switch font color to unhighlighted, leave can be ignored
       
   116     //since it's just a color change
       
   117     TRAP_IGNORE(AknLayoutUtils::OverrideControlColorL(
       
   118             *iSelectionLabel,
       
   119             EColorLabelText,
       
   120             KRgbBlack ));
       
   121     if( iHighlighted )
       
   122         {
       
   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();
       
   131         TRect rect = aRect;
       
   132         TBool enableEdges(ETrue);
       
   133 
       
   134         CFbsBitmap* selector = NULL;
       
   135         CFbsBitmap* selectorMask = NULL;
       
   136         
       
   137         TSize corner(KEdge, KEdge);
       
   138         NMRBitmapManager::GetSkinBasedBitmap( 
       
   139                 NMRBitmapManager::EMRBitmapListTopLeft, 
       
   140                 selector, selectorMask, corner );
       
   141 
       
   142         if( selector && selectorMask && enableEdges)
       
   143             {
       
   144             //corner TL
       
   145             gc.BitBltMasked( rect.iTl, selector, corner, selectorMask, EFalse );
       
   146 
       
   147             //side L
       
   148             TSize side(KEdge, (rect.Height() - 2 * KEdge) );
       
   149             NMRBitmapManager::GetSkinBasedBitmap( 
       
   150                     NMRBitmapManager::EMRBitmapListLeft, 
       
   151                     selector, selectorMask, side );
       
   152             gc.BitBltMasked( TPoint(rect.iTl.iX, rect.iTl.iY + KEdge),
       
   153                              selector, side, selectorMask, EFalse );
       
   154 
       
   155             //corner BL
       
   156             NMRBitmapManager::GetSkinBasedBitmap( 
       
   157                     NMRBitmapManager::EMRBitmapListBottomLeft, 
       
   158                     selector, selectorMask, corner );
       
   159             gc.BitBltMasked( TPoint(rect.iTl.iX, 
       
   160                             rect.iTl.iY + KEdge + side.iHeight),
       
   161                             selector, corner, selectorMask, EFalse );
       
   162 
       
   163             //top
       
   164             TSize top( (rect.Width() - 2 * KEdge) , KEdge);
       
   165             NMRBitmapManager::GetSkinBasedBitmap( 
       
   166                     NMRBitmapManager::EMRBitmapListTop, 
       
   167                     selector, selectorMask, top );
       
   168             gc.BitBltMasked( TPoint(rect.iTl.iX + KEdge, rect.iTl.iY),
       
   169                              selector, top, selectorMask, EFalse );
       
   170 
       
   171             //center
       
   172             TSize center( top.iWidth, side.iHeight);
       
   173             NMRBitmapManager::GetSkinBasedBitmap( 
       
   174                     NMRBitmapManager::EMRBitmapListCenter, 
       
   175                     selector, selectorMask, center );
       
   176             gc.BitBltMasked( TPoint(rect.iTl.iX + KEdge, rect.iTl.iY + KEdge),
       
   177                              selector, center, selectorMask, EFalse );
       
   178 
       
   179             //bottom
       
   180             NMRBitmapManager::GetSkinBasedBitmap( 
       
   181                     NMRBitmapManager::EMRBitmapListBottom, 
       
   182                     selector, selectorMask, top );
       
   183             gc.BitBltMasked( TPoint(rect.iTl.iX + KEdge, 
       
   184                             rect.iTl.iY + side.iHeight + KEdge),
       
   185                             selector, top, selectorMask, EFalse );
       
   186 
       
   187             //corner TR
       
   188             NMRBitmapManager::GetSkinBasedBitmap( 
       
   189                     NMRBitmapManager::EMRBitmapListTopRight, 
       
   190                     selector, selectorMask, corner );
       
   191             gc.BitBltMasked( TPoint(rect.iTl.iX + KEdge + top.iWidth, 
       
   192                             rect.iTl.iY),
       
   193                             selector, corner, selectorMask, EFalse );
       
   194 
       
   195             //side R
       
   196             NMRBitmapManager::GetSkinBasedBitmap( 
       
   197                     NMRBitmapManager::EMRBitmapListRight, 
       
   198                     selector, selectorMask, side );
       
   199             gc.BitBltMasked( TPoint(rect.iTl.iX + KEdge + top.iWidth, 
       
   200                             rect.iTl.iY + KEdge),
       
   201                             selector, side, selectorMask, EFalse );
       
   202 
       
   203             //corner Br
       
   204             NMRBitmapManager::GetSkinBasedBitmap( 
       
   205                     NMRBitmapManager::EMRBitmapListBottomRight, 
       
   206                     selector, selectorMask, corner );
       
   207             gc.BitBltMasked( TPoint(rect.iTl.iX + KEdge + top.iWidth, 
       
   208                             rect.iTl.iY + KEdge + side.iHeight),
       
   209                             selector, corner, selectorMask, EFalse );
       
   210             }
       
   211         else if(!enableEdges)
       
   212             {
       
   213             //center
       
   214             TSize center( rect.Width(), rect.Height() );
       
   215             NMRBitmapManager::GetSkinBasedBitmap( 
       
   216                     NMRBitmapManager::EMRBitmapListCenter, 
       
   217                     selector, selectorMask, center );
       
   218             gc.BitBltMasked( TPoint(rect.iTl.iX, rect.iTl.iY), 
       
   219                     selector, center, selectorMask, EFalse );
       
   220             }
       
   221         else // This should NOT be called ever.
       
   222             {
       
   223             gc.SetBrushStyle( CGraphicsContext::ESolidBrush );
       
   224             gc.SetPenStyle( CGraphicsContext::ENullPen );
       
   225             gc.SetBrushColor( KRgbGreen );
       
   226             rect.SetSize( TSize(rect.Size().iWidth - 1,
       
   227                                 rect.Size().iHeight ) );
       
   228             gc.DrawRect( rect );
       
   229             }
       
   230 
       
   231         delete selector;
       
   232         delete selectorMask;
       
   233         }
       
   234     }
       
   235 
       
   236 // -----------------------------------------------------------------------------
       
   237 // CESMRResponseItem::CountComponentControls
       
   238 // -----------------------------------------------------------------------------
       
   239 //
       
   240 TInt CESMRResponseItem::CountComponentControls() const
       
   241     {
       
   242     FUNC_LOG;
       
   243     TInt itemCount = 0;
       
   244     if( iSelectionLabel )
       
   245         {
       
   246         itemCount++;
       
   247         }
       
   248     if( iIcon )
       
   249         {
       
   250         itemCount++;
       
   251         }
       
   252 
       
   253     return itemCount;
       
   254     }
       
   255 
       
   256 // -----------------------------------------------------------------------------
       
   257 // CESMRResponseItem::ComponentControl
       
   258 // -----------------------------------------------------------------------------
       
   259 //
       
   260 CCoeControl* CESMRResponseItem::ComponentControl( TInt aInd ) const
       
   261     {
       
   262     FUNC_LOG;
       
   263     CCoeControl* control = NULL;
       
   264     if ( aInd == 0 )
       
   265         {
       
   266         control = iSelectionLabel;
       
   267         }
       
   268 
       
   269     if ( aInd == 1 )
       
   270         {
       
   271         control = iIcon;
       
   272         }
       
   273     return control;
       
   274     }
       
   275 
       
   276 // -----------------------------------------------------------------------------
       
   277 // CESMRResponseItem::SizeChanged
       
   278 // -----------------------------------------------------------------------------
       
   279 //
       
   280 void CESMRResponseItem::SizeChanged()
       
   281     {
       
   282     FUNC_LOG;
       
   283     TRect rect( this->Rect() );
       
   284 
       
   285     // Icon exists, this is answer item ( accept / tentative / decline )
       
   286     if( iIcon )
       
   287         {
       
   288         // Icon
       
   289         TAknWindowComponentLayout iconLayout = 
       
   290             NMRLayoutManager::GetWindowComponentLayout( 
       
   291                     NMRLayoutManager::EMRLayoutCheckboxIcon );
       
   292         AknLayoutUtils::LayoutImage( iIcon, rect, iconLayout );
       
   293         // Label 
       
   294         TAknTextComponentLayout labelLayout =
       
   295             NMRLayoutManager::GetTextComponentLayout( 
       
   296                     NMRLayoutManager::EMRTextLayoutCheckboxEditor );
       
   297         AknLayoutUtils::LayoutLabel( iSelectionLabel, rect, labelLayout );
       
   298         }
       
   299     else // There is no icon (this is the topic item)
       
   300         {
       
   301         TAknTextComponentLayout labelLayout =
       
   302             NMRLayoutManager::GetTextComponentLayout( 
       
   303                     NMRLayoutManager::EMRTextLayoutText );
       
   304         AknLayoutUtils::LayoutLabel( iSelectionLabel, rect, labelLayout );
       
   305         }
       
   306 
       
   307 
       
   308     }
       
   309 
       
   310 // -----------------------------------------------------------------------------
       
   311 // CESMRResponseItem::IconL
       
   312 // -----------------------------------------------------------------------------
       
   313 //
       
   314 CMRImage* CESMRResponseItem::IconL( TBool aChecked )
       
   315     {
       
   316     FUNC_LOG;
       
   317     NMRBitmapManager::TMRBitmapId iconID( 
       
   318             NMRBitmapManager::EMRBitmapCheckBoxOff );
       
   319 
       
   320     if( aChecked )
       
   321         {
       
   322         iconID = NMRBitmapManager::EMRBitmapCheckBoxOn;
       
   323         }
       
   324     CMRImage* icon = CMRImage::NewL( iconID );
       
   325     return icon;
       
   326     }
       
   327 
       
   328 // -----------------------------------------------------------------------------
       
   329 // CESMRResponseItem::SetHighlight
       
   330 // -----------------------------------------------------------------------------
       
   331 //
       
   332 void CESMRResponseItem::SetHighlight()
       
   333     {
       
   334     FUNC_LOG;
       
   335     iHighlighted = ETrue;
       
   336     }
       
   337 
       
   338 // -----------------------------------------------------------------------------
       
   339 // CESMRResponseItem::RemoveHighlight
       
   340 // -----------------------------------------------------------------------------
       
   341 //
       
   342 void CESMRResponseItem::RemoveHighlight()
       
   343     {
       
   344     FUNC_LOG;
       
   345     iHighlighted = EFalse;
       
   346     }
       
   347 
       
   348 // -----------------------------------------------------------------------------
       
   349 // CESMRResponseItem::ChangeIconL
       
   350 // -----------------------------------------------------------------------------
       
   351 //
       
   352 void CESMRResponseItem::ChangeIconL( TBool aChecked )
       
   353     {
       
   354     FUNC_LOG;
       
   355     delete iIcon;
       
   356     iIcon = NULL;
       
   357     iIcon = IconL( aChecked );
       
   358     SizeChanged();
       
   359     }
       
   360 
       
   361 // -----------------------------------------------------------------------------
       
   362 // CESMRResponseItem::SetFont
       
   363 // -----------------------------------------------------------------------------
       
   364 //
       
   365 void CESMRResponseItem::SetFont( const CFont* aFont )
       
   366     {
       
   367     FUNC_LOG;
       
   368     iSelectionLabel->SetFont( aFont );
       
   369     // Leave case can be ignored here because there is nothing to do about it
       
   370     TRAP_IGNORE(AknLayoutUtils::OverrideControlColorL(
       
   371                                       *iSelectionLabel,
       
   372                                       EColorLabelText,
       
   373                                       KRgbBlack ) );
       
   374     }
       
   375 
       
   376 // -----------------------------------------------------------------------------
       
   377 // CESMRResponseItem::SetTextL
       
   378 // -----------------------------------------------------------------------------
       
   379 //
       
   380 void CESMRResponseItem::SetTextL( const TDesC& aItemText )
       
   381     {
       
   382     FUNC_LOG;
       
   383     // When this method is called for the first time(with valid text)
       
   384     // text is stored to member variable. This is done because
       
   385     // text needs to be wrapped again (orientation might have
       
   386     // changed) when SizeChanged() gets called.
       
   387     if( !iItemText &&  aItemText.Length() > 0 )
       
   388         {
       
   389         iOriginalTextLength = aItemText.Length();
       
   390         iItemText = HBufC::NewL( aItemText.Length() );
       
   391         *iItemText = aItemText;
       
   392         }
       
   393     else if( !iItemText &&  aItemText.Length() <= 0 )
       
   394         {
       
   395         // if there is no text yet, there is nothing to do here.
       
   396         return;
       
   397         }
       
   398 
       
   399     TInt lineCount = 1; // Default line count.
       
   400     // If this item has no icon, it may use two lines for the text
       
   401     if( !iIcon )
       
   402         {
       
   403         lineCount = KMaxLinesInResponseTopicItem;
       
   404         }
       
   405     // Text wrapping
       
   406     CArrayFixFlat<TInt>* widthArray =
       
   407                         new (ELeave) CArrayFixFlat<TInt>( lineCount );
       
   408     CleanupStack::PushL( widthArray );
       
   409     for ( TInt i(0); i < lineCount; i++ )
       
   410         {
       
   411         // If this item has no icon, all the space is for text
       
   412         if( !iIcon )
       
   413             {
       
   414             TAknLayoutText layout = NMRLayoutManager::GetLayoutText( Rect(), NMRLayoutManager::EMRTextLayoutText );            
       
   415             widthArray->AppendL( layout.TextRect().Width() );
       
   416             }
       
   417         else
       
   418             {
       
   419             widthArray->AppendL( iLayout->ResponseAreaAnswerTextSize().iWidth );
       
   420             }
       
   421         }
       
   422 
       
   423     HBufC* wrappedText;
       
   424     // Set the font for the text
       
   425     const CFont* font = iSelectionLabel->Font();
       
   426     RBuf buffer; // codescanner::resourcenotoncleanupstack
       
   427     buffer.CreateL( iOriginalTextLength + widthArray->Count() );
       
   428     buffer.CleanupClosePushL();
       
   429 
       
   430     // Wrap the text
       
   431     AknTextUtils::WrapToStringAndClipL( iItemText->Des(), *widthArray, *font, buffer );
       
   432     wrappedText = buffer.AllocLC();
       
   433 
       
   434     // Set the text to label
       
   435     iSelectionLabel->SetTextL( *wrappedText );
       
   436     CleanupStack::PopAndDestroy(3); // widthArray, wrappedText, buffer
       
   437     }
       
   438 
       
   439 // -----------------------------------------------------------------------------
       
   440 // CESMRResponseItem::SetLayoutManager
       
   441 // -----------------------------------------------------------------------------
       
   442 //
       
   443 void CESMRResponseItem::SetLayoutManager( CESMRLayoutManager* aLayout )
       
   444     {
       
   445     FUNC_LOG;
       
   446     iLayout = aLayout;
       
   447     }
       
   448 
       
   449 // -----------------------------------------------------------------------------
       
   450 // CESMRResponseItem::ItemTextLineCount
       
   451 // -----------------------------------------------------------------------------
       
   452 //
       
   453 TInt CESMRResponseItem::ItemTextLineCount()
       
   454     {
       
   455     FUNC_LOG;
       
   456     TInt retValue( KErrNotFound );
       
   457     if( iSelectionLabel )
       
   458         {
       
   459         retValue = iSelectionLabel->NumberOfLines();
       
   460         }
       
   461     return retValue;
       
   462     }
       
   463 
       
   464 // -----------------------------------------------------------------------------
       
   465 // CESMRResponseItem::CommandId
       
   466 // -----------------------------------------------------------------------------
       
   467 //
       
   468 TESMRCommand CESMRResponseItem::CommandId() const
       
   469     {
       
   470     FUNC_LOG;
       
   471     return iCmd;
       
   472     }
       
   473