meetingrequest/mrgui/src/cesmrtitlepane.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:  Class is responsible of showing the title for current "view"
       
    15 *
       
    16 */
       
    17 
       
    18 #include "cesmrtitlepane.h"
       
    19 #include "nmrlayoutmanager.h"
       
    20 #include "cmrlabel.h"
       
    21 #include "cmrimage.h"
       
    22 //<cmail>
       
    23 #include "esmrdef.h"
       
    24 //</cmail>
       
    25 #include <AknIconUtils.h>
       
    26 #include <gulcolor.h>
       
    27 #include <AknUtils.h>
       
    28 #include <AknsConstants.h>
       
    29 #include <aknsconstants.hrh>
       
    30 #include <AknsUtils.h>
       
    31 #include <data_caging_path_literals.hrh>
       
    32 #include <AknLayout2ScalableDef.h>
       
    33 
       
    34 #include "emailtrace.h"
       
    35 
       
    36 /// Unnamed namespace for local definitions
       
    37 namespace { // codescanner::namespace
       
    38 
       
    39 /**
       
    40  * KReplaceWhitespaceChars contains some characters that should be replaced by space
       
    41  * in Calendar popup, day view etc.
       
    42  * Following characters are replaced with space
       
    43  * \x0009 horizontal tab
       
    44  * \x000a new line
       
    45  * \x000b line tabulation (vertical
       
    46  * \x000c form feed
       
    47  * \x000d carriage return
       
    48  * \x2028 line separator
       
    49  * \x2029 paragraph separator
       
    50  */
       
    51 _LIT( KReplaceWhitespaceChars, "\x0009\x000A\x000B\x000C\x000D\x2028\x2029" );
       
    52 
       
    53 #ifdef _DEBUG
       
    54 
       
    55 // Definition for panic text
       
    56 _LIT( KESMRPanicTxt, "CESMRTitlePane" );
       
    57 
       
    58 /**
       
    59  * ES MR Entry panic codes
       
    60  */
       
    61 enum TESMRPanicCodes
       
    62     {
       
    63     EESMREntryTypeNotSet = 1, // Entry does not exist
       
    64     };
       
    65 
       
    66 /**
       
    67  * Raises panic.
       
    68  * @param aPanic Panic code
       
    69  */
       
    70 void Panic(TESMRPanicCodes aPanic)
       
    71     {
       
    72     User::Panic( KESMRPanicTxt, aPanic);
       
    73     }
       
    74 
       
    75 #endif // _DEBUG
       
    76 
       
    77 }  // namespace
       
    78 
       
    79 // ======== MEMBER FUNCTIONS ========
       
    80 
       
    81 // ---------------------------------------------------------------------------
       
    82 // CESMRTitlePane::NewL()
       
    83 // ---------------------------------------------------------------------------
       
    84 //
       
    85 CESMRTitlePane* CESMRTitlePane::NewL()
       
    86     {
       
    87     FUNC_LOG;
       
    88     CESMRTitlePane* self = CESMRTitlePane::NewLC();
       
    89     CleanupStack::Pop( self );
       
    90     return self;
       
    91     }
       
    92 
       
    93 // ---------------------------------------------------------------------------
       
    94 // CESMRTitlePane::NewLC()
       
    95 // ---------------------------------------------------------------------------
       
    96 //
       
    97 CESMRTitlePane* CESMRTitlePane::NewLC()
       
    98     {
       
    99     FUNC_LOG;
       
   100     CESMRTitlePane* self = new (ELeave) CESMRTitlePane();
       
   101     CleanupStack::PushL( self );
       
   102     self->ConstructL();
       
   103     return self;
       
   104     }
       
   105 
       
   106 // ---------------------------------------------------------------------------
       
   107 // CESMRTitlePane::~CESMRTitlePane()
       
   108 // ---------------------------------------------------------------------------
       
   109 //
       
   110 CESMRTitlePane::~CESMRTitlePane()
       
   111     {
       
   112     FUNC_LOG;
       
   113     delete iTitle;
       
   114     delete iIcon;
       
   115     }
       
   116 
       
   117 // ---------------------------------------------------------------------------
       
   118 // CESMRTitlePane::CESMRTitlePane()
       
   119 // ---------------------------------------------------------------------------
       
   120 //
       
   121 CESMRTitlePane::CESMRTitlePane()
       
   122     {
       
   123     FUNC_LOG;
       
   124     // Do nothing
       
   125     }
       
   126 
       
   127 // ---------------------------------------------------------------------------
       
   128 // CESMRTitlePane::ConstructL()
       
   129 // ---------------------------------------------------------------------------
       
   130 //
       
   131 void CESMRTitlePane::ConstructL()
       
   132     {
       
   133     FUNC_LOG;
       
   134     iEntryType = MESMRCalEntry::EESMRCalEntryNotSupported;
       
   135 
       
   136     iTitle = CMRLabel::NewL();
       
   137     iTitle->SetParent( this );
       
   138     iTitle->SetTextL( KNullDesC );
       
   139     }
       
   140 
       
   141 // ---------------------------------------------------------------------------
       
   142 // CESMRTitlePane::SizeChanged()
       
   143 // ---------------------------------------------------------------------------
       
   144 //
       
   145 void CESMRTitlePane::SizeChanged()
       
   146     {
       
   147     FUNC_LOG;
       
   148     TRect rect = Rect();
       
   149 
       
   150     TAknTextComponentLayout labelLayout = 
       
   151         NMRLayoutManager::GetTextComponentLayout( 
       
   152                 NMRLayoutManager::EMRLayoutCtrlBarTitle );
       
   153     AknLayoutUtils::LayoutLabel( iTitle, rect, labelLayout );
       
   154     
       
   155     iTitle->SetAlignment(EHCenterVCenter);
       
   156     
       
   157     TRgb color;
       
   158     AknsUtils::GetCachedColor( AknsUtils::SkinInstance(),
       
   159                                         color,
       
   160                                         KAknsIIDQsnTextColors,
       
   161                                         EAknsCIQsnTextColorsCG2 );
       
   162     // If this leaves we'll have to use the default color
       
   163     TRAP_IGNORE( AknLayoutUtils::OverrideControlColorL( 
       
   164                                 *iTitle, 
       
   165                                 EColorLabelText,
       
   166                                 color ) );     
       
   167 
       
   168     if( iIcon )
       
   169         {
       
   170         TAknWindowComponentLayout iconLayout = 
       
   171             NMRLayoutManager::GetWindowComponentLayout( 
       
   172                     NMRLayoutManager::EMRLayoutCtrlBarGraphics );
       
   173         AknLayoutUtils::LayoutImage( iIcon, rect, iconLayout );
       
   174         }
       
   175     }
       
   176 
       
   177 // ---------------------------------------------------------------------------
       
   178 // CESMRTitlePane::CountComponentControls()
       
   179 // ---------------------------------------------------------------------------
       
   180 //
       
   181 TInt CESMRTitlePane::CountComponentControls() const
       
   182     {
       
   183     FUNC_LOG;
       
   184     TInt count( 0 );
       
   185 
       
   186     if ( iTitle )
       
   187         ++count;
       
   188 
       
   189     if ( iIcon )
       
   190         ++count;
       
   191 
       
   192     return count;
       
   193     }
       
   194 
       
   195 // ---------------------------------------------------------------------------
       
   196 // CESMRTitlePane::ComponentControl()
       
   197 // ---------------------------------------------------------------------------
       
   198 //
       
   199 CCoeControl* CESMRTitlePane::ComponentControl( TInt aInd ) const
       
   200     {
       
   201     FUNC_LOG;
       
   202     switch( aInd )
       
   203     	{
       
   204     	case 0:
       
   205     		{
       
   206     		return iTitle;
       
   207     		}
       
   208     	case 1:
       
   209     		{
       
   210     		return iIcon;
       
   211     		}
       
   212     	default:
       
   213     		return NULL;
       
   214     	}
       
   215     }
       
   216 
       
   217 // ---------------------------------------------------------------------------
       
   218 // CESMRTitlePane::HandleSetPriorityCmdL()
       
   219 // ---------------------------------------------------------------------------
       
   220 //
       
   221 void CESMRTitlePane::HandleSetPriorityCmdL( TInt aPriority )
       
   222     {
       
   223     FUNC_LOG;
       
   224 
       
   225     __ASSERT_DEBUG( iEntryType != MESMRCalEntry::EESMRCalEntryNotSupported, 
       
   226     		Panic(EESMREntryTypeNotSet ) );
       
   227 
       
   228     switch ( aPriority )
       
   229         {
       
   230         case EESMRCmdPriorityHigh:
       
   231             {
       
   232             if ( iEntryType == MESMRCalEntry::EESMRCalEntryTodo )
       
   233                 {
       
   234                 SetPriorityL(EFSCalenTodoPriorityHigh);
       
   235                 }
       
   236             else
       
   237                 {
       
   238                 SetPriorityL(EFSCalenMRPriorityHigh);
       
   239                 }
       
   240             break;
       
   241             }
       
   242         case EESMRCmdPriorityLow:
       
   243             {
       
   244             if ( iEntryType == MESMRCalEntry::EESMRCalEntryTodo )
       
   245                 {
       
   246                 SetPriorityL(EFSCalenTodoPriorityLow);
       
   247                 }
       
   248             else
       
   249                 {
       
   250                 SetPriorityL(EFSCalenMRPriorityLow);
       
   251                 }
       
   252             break;
       
   253             }
       
   254         case EESMRCmdPriorityNormal:
       
   255             {
       
   256             if ( iEntryType == MESMRCalEntry::EESMRCalEntryTodo )
       
   257                 {
       
   258                 SetPriorityL(EFSCalenTodoPriorityNormal);
       
   259                 }
       
   260             else
       
   261                 {
       
   262                 SetPriorityL(EFSCalenMRPriorityNormal);
       
   263                 }
       
   264             break;
       
   265             }
       
   266         default:
       
   267         	break;
       
   268         }
       
   269     }
       
   270 
       
   271 // ---------------------------------------------------------------------------
       
   272 // CESMRTitlePane::SetPriorityL()
       
   273 // ---------------------------------------------------------------------------
       
   274 //
       
   275 void CESMRTitlePane::SetPriorityL(TUint aPriority )
       
   276     {
       
   277     FUNC_LOG;
       
   278     __ASSERT_DEBUG( iEntryType != MESMRCalEntry::EESMRCalEntryNotSupported, 
       
   279     		Panic(EESMREntryTypeNotSet ) );
       
   280 
       
   281     iPriority = aPriority;
       
   282 
       
   283     // icon added to MR-title only if the default icon is set and
       
   284     // the priority is neither high or low (the possible high/low
       
   285     // importance icons are currently only shown in navi pane).
       
   286     delete iIcon;
       
   287     iIcon = NULL;
       
   288     if ( iDefaultIcon &&
       
   289          iEntryType != MESMRCalEntry::EESMRCalEntryTodo && 
       
   290          aPriority != EFSCalenMRPriorityHigh &&
       
   291          aPriority != EFSCalenMRPriorityLow )
       
   292         {
       
   293         CreateIconL( KAknsIIDQgnFscalIndiSubject );
       
   294         }
       
   295     
       
   296     SizeChanged();
       
   297     DrawDeferred();
       
   298     }
       
   299 
       
   300 // ---------------------------------------------------------------------------
       
   301 // CESMRTitlePane::CreateIconL()
       
   302 // ---------------------------------------------------------------------------
       
   303 //
       
   304 void CESMRTitlePane::CreateIconL( TAknsItemID aIconID  )
       
   305     {
       
   306     FUNC_LOG;
       
   307     delete iIcon;
       
   308     iIcon = NULL;
       
   309 
       
   310     iIcon = CMRImage::NewL( aIconID );
       
   311     iIcon->SetParent( this );
       
   312     }
       
   313 
       
   314 // ---------------------------------------------------------------------------
       
   315 // CESMRTitlePane::SetTextL()
       
   316 // ---------------------------------------------------------------------------
       
   317 //
       
   318 void CESMRTitlePane::SetTextL( const TDesC& aText )
       
   319     {
       
   320     FUNC_LOG;
       
   321     // Create new string buffer for trimming the text,
       
   322     // remove all linefeed/break etc.
       
   323 
       
   324     HBufC* titleForTrimming = aText.AllocLC();
       
   325     TPtr ptr = titleForTrimming->Des();
       
   326     AknTextUtils::ReplaceCharacters( ptr,
       
   327                                      KReplaceWhitespaceChars,
       
   328                                      TChar(' ') );
       
   329 
       
   330     titleForTrimming->Des().TrimAll();
       
   331 
       
   332     iTitle->SetTextL( *titleForTrimming );
       
   333 
       
   334     CleanupStack::PopAndDestroy( titleForTrimming );
       
   335     iTitle->CropText();
       
   336     DrawDeferred();
       
   337     }
       
   338 
       
   339 // ---------------------------------------------------------------------------
       
   340 // CESMRTitlePane::InternalizeL()
       
   341 // ---------------------------------------------------------------------------
       
   342 //
       
   343 void CESMRTitlePane::InternalizeL( MESMRCalEntry& aEntry )
       
   344     {
       
   345     FUNC_LOG;
       
   346     iEntryType = aEntry.Type();
       
   347     SetPriorityL( aEntry.GetPriorityL() );
       
   348     }
       
   349 
       
   350 // ---------------------------------------------------------------------------
       
   351 // CESMRTitlePane::SetDefaultIcon()
       
   352 // ---------------------------------------------------------------------------
       
   353 //
       
   354 void CESMRTitlePane::SetDefaultIcon( TBool aDefault )
       
   355     {
       
   356     FUNC_LOG;
       
   357     iDefaultIcon = aDefault;
       
   358     }
       
   359 
       
   360 // ---------------------------------------------------------------------------
       
   361 // CESMRTitlePane::ExternalizeL()
       
   362 // ---------------------------------------------------------------------------
       
   363 //
       
   364 void CESMRTitlePane::ExternalizeL( MESMRCalEntry& aEntry )
       
   365     {
       
   366     FUNC_LOG;
       
   367     if ( aEntry.Type() == MESMRCalEntry::EESMRCalEntryMeetingRequest ||
       
   368          aEntry.Type() == MESMRCalEntry::EESMRCalEntryMeeting )
       
   369         {
       
   370         aEntry.SetPriorityL( iPriority );
       
   371         }
       
   372     }
       
   373 
       
   374 // EOF