meetingrequest/mrgui/mrfieldbuilderplugin/src/cesmrviewerrecurrencefield.cpp
changeset 0 8466d47a6819
child 12 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:  Recurrence field for viewers
       
    15  *
       
    16 */
       
    17 
       
    18 #include "cesmrviewerrecurrencefield.h"
       
    19 #include "nmrlayoutmanager.h"
       
    20 #include "cmrlabel.h"
       
    21 #include "cmrimage.h"
       
    22 #include "mesmrlistobserver.h"
       
    23 
       
    24 #include <caluser.h>
       
    25 #include <calalarm.h>
       
    26 #include <avkon.rsg>
       
    27 #include <calentry.h>
       
    28 #include <eikenv.h>
       
    29 #include <eikedwin.h>
       
    30 #include <StringLoader.h>
       
    31 #include <AknsConstants.h>
       
    32 #include <esmrgui.rsg>
       
    33 
       
    34 // DEBUG
       
    35 #include "emailtrace.h"
       
    36 
       
    37 // ======== LOCAL FUNCTIONS ========
       
    38 namespace // codescanner::namespace
       
    39     {
       
    40     const TInt KComponentCount( 2 );
       
    41     }
       
    42 
       
    43 // ======== MEMBER FUNCTIONS ========
       
    44 
       
    45 // -----------------------------------------------------------------------------
       
    46 // CESMRViewerRecurrenceField::NewL()
       
    47 // -----------------------------------------------------------------------------
       
    48 //
       
    49 CESMRViewerRecurrenceField* CESMRViewerRecurrenceField::NewL()
       
    50     {
       
    51     FUNC_LOG;
       
    52     CESMRViewerRecurrenceField* self = new (ELeave) CESMRViewerRecurrenceField();
       
    53     CleanupStack::PushL( self );
       
    54     self->ConstructL();
       
    55     CleanupStack::Pop( self );
       
    56     return self;
       
    57     }
       
    58 
       
    59 // -----------------------------------------------------------------------------
       
    60 // CESMRViewerRecurrenceField::~CESMRViewerRecurrenceField()
       
    61 // -----------------------------------------------------------------------------
       
    62 //
       
    63 CESMRViewerRecurrenceField::~CESMRViewerRecurrenceField()
       
    64     {
       
    65     FUNC_LOG;
       
    66     delete iIcon;
       
    67     delete iLabel;
       
    68     }
       
    69 
       
    70 // -----------------------------------------------------------------------------
       
    71 // CESMRViewerRecurrenceField::CESMRViewerRecurrenceField()
       
    72 // -----------------------------------------------------------------------------
       
    73 //
       
    74 CESMRViewerRecurrenceField::CESMRViewerRecurrenceField()
       
    75     {
       
    76     FUNC_LOG;
       
    77     SetFieldId( EESMRFieldRecurrence );
       
    78     }
       
    79 
       
    80 // -----------------------------------------------------------------------------
       
    81 // CESMRViewerRecurrenceField::ConstructL()
       
    82 // -----------------------------------------------------------------------------
       
    83 //
       
    84 void CESMRViewerRecurrenceField::ConstructL()
       
    85     {
       
    86     FUNC_LOG;
       
    87     iLabel = CMRLabel::NewL();
       
    88     iLabel->SetParent( this );
       
    89     iIcon = CMRImage::NewL( KAknsIIDQgnFscalIndiRecurrence );
       
    90     iIcon->SetParent( this );
       
    91     
       
    92     SetFocusType( EESMRHighlightFocus );    
       
    93     }
       
    94 
       
    95 // -----------------------------------------------------------------------------
       
    96 // CESMRViewerRecurrenceField::InitializeL()
       
    97 // -----------------------------------------------------------------------------
       
    98 //
       
    99 void CESMRViewerRecurrenceField::InitializeL()
       
   100     {
       
   101     FUNC_LOG;
       
   102     // Setting Font for the rich text viewer
       
   103     TAknLayoutText text = NMRLayoutManager::GetLayoutText( 
       
   104             Rect(), 
       
   105             NMRLayoutManager::EMRTextLayoutTextEditor );
       
   106     
       
   107     iLabel->SetFont( text.Font() );
       
   108         
       
   109     // This is called so theme changes will apply when changing theme "on the fly"
       
   110     if ( IsFocused() )
       
   111         {
       
   112         iLabel->FocusChanged( EDrawNow );
       
   113         }
       
   114 
       
   115     AknLayoutUtils::OverrideControlColorL ( *iLabel, EColorLabelText,
       
   116                                              KRgbBlack );
       
   117     }
       
   118 
       
   119 // -----------------------------------------------------------------------------
       
   120 // CESMRViewerRecurrenceField::InternalizeL()
       
   121 // -----------------------------------------------------------------------------
       
   122 //
       
   123 void CESMRViewerRecurrenceField::InternalizeL( MESMRCalEntry& aEntry )
       
   124     {
       
   125     FUNC_LOG;
       
   126     TESMRRecurrenceValue recValue;
       
   127     TTime recTime;
       
   128     // Get recurrence
       
   129     aEntry.GetRecurrenceL( recValue, recTime );
       
   130 
       
   131     HBufC* recHolder = NULL;
       
   132     switch( recValue )
       
   133         {
       
   134         case ERecurrenceDaily:
       
   135             {
       
   136             recHolder = StringLoader::LoadLC( R_QTN_MEET_REQ_RECURRING_DAILY,
       
   137                                               iEikonEnv );
       
   138             break;
       
   139             }
       
   140         case ERecurrenceWeekly:
       
   141             {
       
   142             recHolder = StringLoader::LoadLC( R_QTN_MEET_REQ_RECURRING_WEEKLY,
       
   143                                               iEikonEnv );
       
   144             break;
       
   145             }
       
   146         case ERecurrenceEverySecondWeek:
       
   147             {
       
   148             recHolder =
       
   149                 StringLoader::LoadLC( R_QTN_MEET_REQ_RECURRING_SEC_WEEK,
       
   150                                       iEikonEnv );
       
   151             break;
       
   152             }
       
   153         case ERecurrenceMonthly:
       
   154             {
       
   155             recHolder = StringLoader::LoadLC( R_QTN_MEET_REQ_RECURRING_MONTHLY,
       
   156                                               iEikonEnv );
       
   157             break;
       
   158             }
       
   159         case ERecurrenceYearly:
       
   160             {
       
   161             recHolder = StringLoader::LoadLC( R_QTN_MEET_REQ_RECURRING_YEARLY,
       
   162                                               iEikonEnv );
       
   163             break;
       
   164             }
       
   165         case ERecurrenceUnknown:
       
   166             {
       
   167             recHolder = StringLoader::LoadLC( R_QTN_MEET_REQ_RECURRENCE_EVENT,
       
   168                                               iEikonEnv );
       
   169             break;
       
   170             }
       
   171         case ERecurrenceNot:
       
   172         default:
       
   173             {
       
   174             // Hide the field if there is no recurrence
       
   175             iObserver->RemoveControl( iFieldId );
       
   176             break;
       
   177             }
       
   178         }
       
   179     if ( recHolder )
       
   180         {
       
   181         iLabel->SetTextL( *recHolder );
       
   182         CleanupStack::PopAndDestroy( recHolder );
       
   183         }
       
   184     }
       
   185 
       
   186 // -----------------------------------------------------------------------------
       
   187 // CESMRViewerRecurrenceField::SizeChanged()
       
   188 // -----------------------------------------------------------------------------
       
   189 //
       
   190 void CESMRViewerRecurrenceField::SizeChanged()
       
   191     {
       
   192     TRect rect = Rect();
       
   193     TAknLayoutRect rowLayoutRect =
       
   194         NMRLayoutManager::GetFieldRowLayoutRect( rect, 1 );
       
   195     rect = rowLayoutRect.Rect();
       
   196     
       
   197     TAknWindowComponentLayout iconLayout =
       
   198         NMRLayoutManager::GetWindowComponentLayout( 
       
   199                 NMRLayoutManager::EMRLayoutTextEditorIcon );
       
   200     AknLayoutUtils::LayoutImage( iIcon, rect, iconLayout );
       
   201     
       
   202     TAknLayoutRect bgLayoutRect =
       
   203         NMRLayoutManager::GetLayoutRect( 
       
   204                 rect, NMRLayoutManager::EMRLayoutTextEditorBg );
       
   205     TRect bgRect( bgLayoutRect.Rect() );
       
   206     // Move focus rect so that it's relative to field's position.
       
   207     bgRect.Move( -Position() );
       
   208     SetFocusRect( bgRect );
       
   209     
       
   210     TAknLayoutText labelLayout = 
       
   211         NMRLayoutManager::GetLayoutText( 
       
   212                 rect, NMRLayoutManager::EMRTextLayoutTextEditor );
       
   213     iLabel->SetRect( labelLayout.TextRect() );  
       
   214     }
       
   215 
       
   216 // -----------------------------------------------------------------------------
       
   217 // CESMRViewerRecurrenceField::CountComponentControls()
       
   218 // -----------------------------------------------------------------------------
       
   219 //
       
   220 TInt CESMRViewerRecurrenceField::CountComponentControls() const
       
   221     {
       
   222     return KComponentCount;
       
   223     }
       
   224 
       
   225 // -----------------------------------------------------------------------------
       
   226 // CESMRViewerRecurrenceField::ComponentControl()
       
   227 // -----------------------------------------------------------------------------
       
   228 //
       
   229 CCoeControl* CESMRViewerRecurrenceField::ComponentControl( TInt aIndex ) const
       
   230     {
       
   231     switch ( aIndex )
       
   232         {
       
   233         case 0:
       
   234             return iIcon;
       
   235         case 1:
       
   236             return iLabel;
       
   237         default:
       
   238             return NULL;
       
   239         }
       
   240     }
       
   241 
       
   242 // ---------------------------------------------------------------------------
       
   243 // CESMRViewerRecurrenceField::SetOutlineFocusL()
       
   244 // ---------------------------------------------------------------------------
       
   245 //
       
   246 void CESMRViewerRecurrenceField::SetOutlineFocusL( TBool aFocus )
       
   247     {
       
   248     FUNC_LOG;
       
   249     CESMRField::SetOutlineFocusL ( aFocus );
       
   250     
       
   251     iLabel->SetFocus( aFocus );    
       
   252 
       
   253     if ( !aFocus )
       
   254         {
       
   255         AknLayoutUtils::OverrideControlColorL ( *iLabel, EColorLabelText,
       
   256                                                  KRgbBlack );
       
   257         }
       
   258     }
       
   259 // EOF
       
   260