calendarui/views/src/caleneventviewcontainer.cpp
branchRCL_3
changeset 30 bd7edf625bdd
child 31 97232defd20e
equal deleted inserted replaced
29:12af337248b1 30:bd7edf625bdd
       
     1 /*
       
     2 * Copyright (c) 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:   event view's container implementation
       
    15 *
       
    16 */
       
    17 
       
    18 // system includes
       
    19 #include <AknLayoutFont.h>
       
    20 #include <aknnavide.h>      // CAknNavigationDecorator
       
    21 #include <AknsBasicBackgroundControlContext.h>
       
    22 #include <AknBidiTextUtils.h>
       
    23 #include <AknsDrawUtils.h>
       
    24 #include <calrrule.h>
       
    25 #include <calalarm.h>
       
    26 #include <calentry.h>
       
    27 #include <calinstance.h>
       
    28 #include <NpdApi.h>
       
    29 #include <eikappui.h>
       
    30 #include <eikdef.h>
       
    31 #include <eikedwin.h>
       
    32 #include <eikenv.h>
       
    33 #include <eikmenup.h>   // CEikMenuPane
       
    34 #include <eikmfne.h>
       
    35 #include <featmgr.h>    // FeatureManager
       
    36 #include <eikrted.h>    // CEikRichTextEditor
       
    37 #include <finditemdialog.h>
       
    38 #include <StringLoader.h>
       
    39 #include <txtrich.h>    // CRichText
       
    40 #include <gdi.h>
       
    41 #include <ItemFinder.h> //Autofinder 
       
    42 #include <finditemmenu.h>
       
    43 #include <finditem.hrh>
       
    44 #include <centralrepository.h>
       
    45 #include <cenrepnotifyhandler.h>
       
    46 #include <CommonUiInternalCRKeys.h>
       
    47 #include <calsession.h>
       
    48 #include <calencommonui.rsg>
       
    49 #include <AknUtils.h>
       
    50 #include <avkon.hrh>    // EAknCmdHelp
       
    51 #include <avkon.mbg>
       
    52 #include <avkon.rsg>
       
    53 #include <aknlayoutscalable_apps.cdl.h>
       
    54 #include <aknnotewrappers.h>
       
    55 #include <csxhelp/cale.hlp.hrh>
       
    56 #include <calendateutils.h>
       
    57 #include <calenagendautils.h>
       
    58 #include <CalenInterimUtils2.h>
       
    59 #include <calentryview.h>
       
    60 #include <calattachment.h>
       
    61 #include <calcommon.h>
       
    62 #include <calendar.mbg>
       
    63 #include <Calendar.rsg>
       
    64 #include <centralrepository.h>
       
    65 #include <calencommands.hrh>            // Calendar commands
       
    66 #include <calencontext.h>
       
    67 #include <caleninstanceid.h>            // TCalenInstanceId
       
    68 #include <calenservices.h>
       
    69 #include <calentoolbar.h>
       
    70 #include <calcalendarinfo.h>
       
    71 #include <DocumentHandler.h>
       
    72 
       
    73 // user includes
       
    74 #include "caleneventviewcontainer.h"
       
    75 #include "caleneventview.h"
       
    76 #include "calennativeview.h"
       
    77 #include "calendarui_debug.h"
       
    78 #include "calenicondrawer.h"
       
    79 #include "calennotedatautil.h"
       
    80 #include "calendar.hrh"
       
    81 #include "calenentryutil.h"
       
    82 #include "CalenUid.h"   // KUidCalendar
       
    83 #include <calenlocationutil.h>
       
    84 #include "CalendarPrivateCRKeys.h"
       
    85 #include "calenattachmentutils.h"
       
    86 #include "calenglobaldata.h"
       
    87 #include "CleanupResetAndDestroy.h"
       
    88 
       
    89 // LOCAL CONSTANTS AND MACROS
       
    90 _LIT( KWesternSummaryMarker, "\x200E" );
       
    91 _LIT( KArabicSummaryMarker , "\x200F" );
       
    92 _LIT(KSpace, " ");
       
    93 _LIT(KYearFormatString,"%F%Y");
       
    94 _LIT(KAttachmentSeparator,"; ");
       
    95 _LIT8( KNotePadTextDataType, "text/plain" );
       
    96 
       
    97 const TInt KDefaultRightMargin=0;
       
    98 const TInt KScrollViewerUp = 1;
       
    99 const TInt KScrollViewerDown = -1;
       
   100 const TInt KMaxDateLength = 32;
       
   101 
       
   102 //PANIC CODE
       
   103 enum TPanicCode
       
   104     {   
       
   105     EPanicArrayOfSizeZero=2,
       
   106     };
       
   107 
       
   108 // ================= MEMBER FUNCTIONS =========================================
       
   109 
       
   110 // ----------------------------------------------------------------------------
       
   111 // CCalenEventViewContainer::CCalenEventViewContainer
       
   112 // C++ constructor.
       
   113 // ----------------------------------------------------------------------------
       
   114 //
       
   115 CCalenEventViewContainer::CCalenEventViewContainer(CCalenNativeView* aView,
       
   116                               MCalenServices& aServices  )
       
   117     : CCalenContainer( aView, aServices ),
       
   118     					  iEntry(NULL),
       
   119 						  iEmbeddedFileOpened(EFalse)
       
   120     {
       
   121 	TRACE_ENTRY_POINT;
       
   122 	iLocaleChanged = EFalse;
       
   123 	TRACE_EXIT_POINT;
       
   124     }
       
   125  
       
   126 // ----------------------------------------------------------------------------
       
   127 // CCalenEventViewContainer::~CCalenEventViewContainer
       
   128 // Destructor
       
   129 // ----------------------------------------------------------------------------
       
   130 //
       
   131 CCalenEventViewContainer::~CCalenEventViewContainer()
       
   132 	{
       
   133 	TRACE_ENTRY_POINT;
       
   134 	
       
   135 	if(iEntry)
       
   136 		{
       
   137 		delete iEntry;
       
   138 		}
       
   139 	
       
   140 	iFetchedEntries.ResetAndDestroy();
       
   141 	
       
   142 	delete iParaFormat;	
       
   143 	delete iSearchBuf;
       
   144 	delete iEventViewData;
       
   145 	delete iTextEditor;
       
   146 	delete iBgContext;
       
   147     delete iTimeFormat;
       
   148     delete iDateFormat;
       
   149     delete iDocHandler;
       
   150     delete iFindMenu;
       
   151     
       
   152     if( iNotifier )
       
   153         {
       
   154         iNotifier->StopListening();
       
   155         delete iNotifier;        
       
   156         };
       
   157         
       
   158     delete iCenRepSession;	
       
   159     
       
   160     //Reset the attachment posiitons array
       
   161     iAttachmentPosInfoArray.Reset();
       
   162     
       
   163 	TRACE_EXIT_POINT;
       
   164 	}
       
   165 
       
   166 // ----------------------------------------------------------------------------
       
   167 // CCalenEventViewContainer::ConstructImplL
       
   168 // Third phase constructor.
       
   169 // This function was called CCalenNativeView::ConstructL().
       
   170 // (other items were commented in a header).
       
   171 // ----------------------------------------------------------------------------
       
   172 //
       
   173 void CCalenEventViewContainer::ConstructImplL()
       
   174 	{
       
   175 	TRACE_ENTRY_POINT;
       
   176 	
       
   177 	iTimeFormat = StringLoader::LoadL( R_QTN_TIME_USUAL_WITH_ZERO, CEikonEnv::Static() );
       
   178     iDateFormat = StringLoader::LoadL( R_QTN_DATE_USUAL_WITH_ZERO, CEikonEnv::Static() );
       
   179 	
       
   180     iBgContext = CAknsBasicBackgroundControlContext::NewL( KAknsIIDQsnBgAreaMain,
       
   181                                                            Rect(),
       
   182                                                            ETrue );
       
   183     
       
   184     iDocHandler = CDocumentHandler::NewL( iEikonEnv->Process() );
       
   185     
       
   186     iFindMenu = CFindItemMenu::NewL( EFindItemMenuPlaceHolder );
       
   187     iFindMenu->AttachItemFinderMenuL(0);
       
   188    
       
   189     
       
   190     iParaFormat = CParaFormat::NewL();
       
   191 
       
   192 	
       
   193 	iTextEditor = new (ELeave) CEikRichTextEditor;
       
   194     iTextEditor->ConstructL(this, 0, 0, CEikEdwin::EReadOnly | CEikEdwin::EAvkonDisableCursor | 
       
   195     									CEikEdwin::ENoAutoSelection|CEikEdwin::EAvkonEditor);
       
   196     iTextEditor->SetMopParent(this);
       
   197     iTextEditor->SetRect( Rect() );
       
   198 	
       
   199         
       
   200     iDocHandler->SetExitObserver( this );
       
   201     iTextEditor->EnableKineticScrollingL(ETrue);
       
   202 	TRACE_EXIT_POINT;
       
   203 	}
       
   204 
       
   205 // ----------------------------------------------------------------------------
       
   206 // CCalenEventViewContainer::UpdateSize
       
   207 // Do layout changes after calendar settings are
       
   208 // changed.  No necessary actions for this view.
       
   209 // ----------------------------------------------------------------------------
       
   210 //
       
   211 void CCalenEventViewContainer::UpdateSize()
       
   212 	{
       
   213 	TRACE_ENTRY_POINT;
       
   214 	
       
   215 	TRACE_EXIT_POINT;
       
   216 	}
       
   217 
       
   218 // ----------------------------------------------------------------------------
       
   219 // CCalenEventViewContainer::CreateIconIndicesL
       
   220 // Second and final stage of population.
       
   221 // (other items were commented in a header).
       
   222 // ----------------------------------------------------------------------------
       
   223 //
       
   224 void CCalenEventViewContainer::CreateIconIndicesL( RArray<MCalenServices::TCalenIcons>& /*aIndexArray*/ )
       
   225     {
       
   226     TRACE_ENTRY_POINT;
       
   227 
       
   228     TRACE_EXIT_POINT;
       
   229     }
       
   230 
       
   231 // ----------------------------------------------------------------------------
       
   232 // CCalenEventViewContainer::CompletePopulationL
       
   233 // Complete population
       
   234 // (other items were commented in a header).
       
   235 // ----------------------------------------------------------------------------
       
   236 //
       
   237 void CCalenEventViewContainer::CompletePopulationL()
       
   238 	{
       
   239     TRACE_ENTRY_POINT;
       
   240     
       
   241     iTextEditor->SetFocus(ETrue);
       
   242     ActivateL();
       
   243     AddToStackAndMakeVisibleL();
       
   244     DrawDeferred();
       
   245     if(iSelectedText.iCursorPos > 0 || iSelectedText.iAnchorPos > 0)
       
   246         {
       
   247         //Set the text selection existed before layout change  
       
   248         iTextEditor->SetCursorPosL(iSelectedText.iCursorPos, EFalse);
       
   249         iTextEditor->SetSelectionL(iSelectedText.iCursorPos,iSelectedText.iAnchorPos);
       
   250         }
       
   251     TRACE_EXIT_POINT;
       
   252 	}
       
   253 
       
   254 // ----------------------------------------------------------------------------
       
   255 // CCalenEventViewContainer::HandleNaviDecoratorEventL
       
   256 // ?implementation_description
       
   257 // (other items were commented in a header).
       
   258 // ----------------------------------------------------------------------------
       
   259 //
       
   260 void CCalenEventViewContainer::HandleNaviDecoratorEventL( TInt /*aEventID*/ )
       
   261 	{
       
   262 	TRACE_ENTRY_POINT;
       
   263 	
       
   264 	TRACE_EXIT_POINT;	
       
   265 	}
       
   266 
       
   267 // ----------------------------------------------------------------------------
       
   268 // CCalenEventViewContainer::HandleLongTapEventL
       
   269 // processing of a long tap event
       
   270 // (other items were commented in a header).
       
   271 // ----------------------------------------------------------------------------
       
   272 //
       
   273 void CCalenEventViewContainer::HandleLongTapEventL( const TPoint& /*aPenEventLocation*/,
       
   274                                               const TPoint& /*aPenEventScreenLocation*/ )
       
   275     {
       
   276     TRACE_ENTRY_POINT;
       
   277 
       
   278     TRACE_EXIT_POINT;
       
   279     }
       
   280 
       
   281 // ----------------------------------------------------------------------------
       
   282 // CCalenEventViewContainer::Draw
       
   283 // (other items were commented in a header).
       
   284 // ----------------------------------------------------------------------------
       
   285 //
       
   286 void CCalenEventViewContainer::Draw(const TRect& /*aRect*/) const
       
   287 	{
       
   288 	TRACE_ENTRY_POINT;
       
   289 	
       
   290 	CWindowGc& gc = SystemGc();
       
   291         
       
   292     TRect mainPane;
       
   293     AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane, mainPane );
       
   294     TRect bgContextRect( TPoint(0, 0), mainPane.Size() );
       
   295     iBgContext->SetRect( bgContextRect);
       
   296     iBgContext->SetParentPos(mainPane.iTl);
       
   297     AknsDrawUtils::Background( AknsUtils::SkinInstance(), iBgContext, this, gc, Rect());
       
   298 
       
   299 	
       
   300 	TRACE_EXIT_POINT;
       
   301 	}
       
   302 
       
   303 // ----------------------------------------------------------------------------
       
   304 // CCalenEventViewContainer::Sizechanged
       
   305 // Child control was resized.
       
   306 // (other items were commented in a header)
       
   307 // ----------------------------------------------------------------------------
       
   308 //
       
   309 void CCalenEventViewContainer::SizeChanged()
       
   310     {
       
   311     TRACE_ENTRY_POINT;
       
   312     
       
   313     SetLayoutFromLookAndFeelL();
       
   314 
       
   315      if (iTextEditor)
       
   316         {
       
   317      	TRAPD(error,iTextEditor->HandleTextChangedL() );
       
   318 		if(error!=KErrNone)
       
   319 	    	{
       
   320 	    	// Do nothing to avoid warning
       
   321 	    	}
       
   322    	    }
       
   323     
       
   324     TRACE_EXIT_POINT;    
       
   325     }
       
   326     
       
   327 // ----------------------------------------------------------------------------
       
   328 // CCalenEventViewContainer::CountComponentControls
       
   329 // Return child control count.
       
   330 // (other items were commented in a header).
       
   331 // ----------------------------------------------------------------------------
       
   332 //
       
   333 TInt CCalenEventViewContainer::CountComponentControls() const
       
   334     {
       
   335     TRACE_ENTRY_POINT;
       
   336     TRACE_EXIT_POINT;
       
   337     return 1;
       
   338     }
       
   339 
       
   340 // ----------------------------------------------------------------------------
       
   341 // CCalenEventViewContainer::ComponentControl
       
   342 // Return child control pointer.
       
   343 // (other items were commented in a header).
       
   344 // ----------------------------------------------------------------------------
       
   345 //
       
   346 CCoeControl* CCalenEventViewContainer::ComponentControl(TInt aIndex) const     // Child control index
       
   347     {
       
   348     TRACE_ENTRY_POINT;
       
   349     CCoeControl* control ( NULL );
       
   350     switch(aIndex)
       
   351         {
       
   352         case 0:
       
   353             control = iTextEditor;
       
   354             break;
       
   355             
       
   356         default:
       
   357             __ASSERT_DEBUG( 0, User::Invariant() );
       
   358             break;
       
   359         }
       
   360     TRACE_EXIT_POINT;
       
   361     
       
   362     return control;
       
   363     }
       
   364 
       
   365 // ----------------------------------------------------------------------------
       
   366 // CCalenEventViewContainer::OfferKeyEventL
       
   367 // Process key event.
       
   368 // (other items were commented in a header).
       
   369 // ----------------------------------------------------------------------------
       
   370 //
       
   371 TKeyResponse CCalenEventViewContainer::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType)
       
   372     {
       
   373     TRACE_ENTRY_POINT;
       
   374 
       
   375     TKeyResponse keyResponse(EKeyWasNotConsumed);
       
   376 
       
   377     if (aType == EEventKey)
       
   378         {
       
   379         switch (aKeyEvent.iCode)
       
   380             {
       
   381             case EKeyUpArrow:
       
   382                 {
       
   383                 // Scroll the text view up by one line
       
   384                 iTextEditor->MakeVisible(EFalse);
       
   385                 TInt scrollLines = KScrollViewerUp;
       
   386                 iTextEditor->TextView()->ScrollDisplayLinesL(scrollLines);
       
   387                 iTextEditor->UpdateScrollBarsL();
       
   388                 iTextEditor->MakeVisible(ETrue);
       
   389                 //Set focus immediately for highlight of auto find text
       
   390                 iTextEditor->SetFocus(ETrue);
       
   391                 keyResponse = EKeyWasConsumed;
       
   392                 }
       
   393                 break;
       
   394 
       
   395             case EKeyDownArrow:
       
   396                 {
       
   397                 // Scroll the text view down by one line
       
   398                 iTextEditor->MakeVisible(EFalse);
       
   399                 TInt scrollLines = KScrollViewerDown;
       
   400                 //text should not be scrolled out of the border
       
   401 		//introduced based on suggestion from texteditor team 
       
   402 		//to avoid scrolling to invalid lines
       
   403                 iTextEditor->TextLayout()->RestrictScrollToTopsOfLines(ETrue);
       
   404                 iTextEditor->TextView()->ScrollDisplayLinesL(scrollLines);
       
   405                 iTextEditor->TextLayout()->RestrictScrollToTopsOfLines(EFalse);
       
   406                 iTextEditor->UpdateScrollBarsL();
       
   407                 iTextEditor->MakeVisible(ETrue);
       
   408                 //Set focus immediately for highlight of auto find text
       
   409                 iTextEditor->SetFocus(ETrue);
       
   410                 keyResponse = EKeyWasConsumed;
       
   411                 }
       
   412                 break;
       
   413                 
       
   414             case EKeyOK:
       
   415             	{            	
       
   416               	iView->HandleCommandL(ECalenCmdPromptThenEdit);
       
   417                 keyResponse = EKeyWasConsumed;
       
   418             	}
       
   419                 break;
       
   420             case EKeyEscape:
       
   421             	{
       
   422             	// Calendar relaunched from cmd line - close viewer
       
   423                 iView->HandleCommandL(EAknSoftkeyBack);
       
   424                 keyResponse = EKeyWasConsumed;
       
   425             	}
       
   426                 break;
       
   427             case EKeyBackspace:  /* fall through... */
       
   428             case EKeyDelete:
       
   429             	{            
       
   430                 CCalenEventView* eventView = static_cast<CCalenEventView*>( iView );
       
   431             	if( !( eventView->IsAlarmActiveInViewer() ) )
       
   432             	    {
       
   433             	    iView->HandleCommandL( ECalenDeleteCurrentEntry );      
       
   434             	    }            	
       
   435             	}
       
   436                 break;
       
   437             default:
       
   438                 break;
       
   439             }
       
   440         }
       
   441 	// For handling geokeys on corolla hardware
       
   442 	// For Add location hard key
       
   443 	if( aKeyEvent.iScanCode == EStdKeyApplication1C && aType == EEventKeyUp )
       
   444 		{
       
   445 		if(CCalenLocationUtil::IsMapProviderAvailableL())	
       
   446 			{
       
   447 			CCalEntry::TType entryType = iEntry->EntryTypeL();
       
   448 			if(entryType == CCalEntry::EAppt)
       
   449 				{
       
   450 				iServices.IssueCommandL(ECalenGetLocationAndSave);
       
   451 				}
       
   452 			keyResponse = EKeyWasConsumed;		
       
   453 			}
       
   454 		}
       
   455 	// For Show location hard key
       
   456 	else if( aKeyEvent.iScanCode == EStdKeyApplication1B && aType == EEventKeyUp )
       
   457 		{
       
   458 		if(CCalenLocationUtil::IsMapProviderAvailableL())
       
   459 			{
       
   460 			CCalEntry::TType entryType = iEntry->EntryTypeL();
       
   461 			if(entryType == CCalEntry::EAppt)
       
   462 				{
       
   463 				TPtrC location = iEntry->LocationL();
       
   464 				if(iEntry->GeoValueL())
       
   465 					{
       
   466 						iServices.IssueCommandL(ECalenShowLocation);
       
   467 						keyResponse = EKeyWasConsumed;	
       
   468 					}
       
   469 				else if(location.Length())
       
   470 					{
       
   471 					iServices.IssueCommandL(ECalenGetLocationAndReplace);
       
   472 					}
       
   473 				else
       
   474 					{
       
   475 					iServices.IssueCommandL(ECalenShowLocationQuery);
       
   476 					}
       
   477 				keyResponse = EKeyWasConsumed;
       
   478 				}
       
   479 			}
       
   480 		}
       
   481     // Swallow all other keyevents to prevent the active container processing them.
       
   482     keyResponse = EKeyWasConsumed;
       
   483 
       
   484     TRACE_EXIT_POINT;
       
   485     return keyResponse;
       
   486 
       
   487  
       
   488     }
       
   489 
       
   490 
       
   491 // ----------------------------------------------------------------------------
       
   492 // CCalenEventViewContainer::HandlePointerEventL
       
   493 // Process pointer event.
       
   494 // (other items were commented in a header).
       
   495 // ----------------------------------------------------------------------------
       
   496 //
       
   497 void CCalenEventViewContainer::HandlePointerEventL(const TPointerEvent& aPointerEvent)
       
   498     {
       
   499     TRACE_ENTRY_POINT;
       
   500     
       
   501     if(!AknLayoutUtils::PenEnabled())
       
   502 	 {
       
   503 	 	return;
       
   504 	 }
       
   505     CCalenContainer::HandlePointerEventL( aPointerEvent );
       
   506     
       
   507     if(iTextEditor->Rect().Contains(aPointerEvent.iPosition))
       
   508     	{
       
   509     	switch(aPointerEvent.iType)
       
   510     		{
       
   511     		case TPointerEvent::EButton1Down:
       
   512     			{
       
   513     			iTextEditor->SetFocus(ETrue);
       
   514     			CCalenEventView* eventView = static_cast<CCalenEventView*>( iView );
       
   515     			if(!( eventView->IsAlarmActiveInViewer() ) )
       
   516     			    {
       
   517     			// TODO: Uncomment this when enabling attachment support
       
   518                     if(iEventViewData && !iEmbeddedFileOpened)
       
   519                         {
       
   520                         if(iEventViewData->AttachmentCount())
       
   521                             {
       
   522                             CTextView *textView = iTextEditor->TextView();
       
   523                         
       
   524                             TTmPosInfo2 *posInfo = new(ELeave) TTmPosInfo2;
       
   525                             textView->FindXyPosL(aPointerEvent.iPosition,*posInfo);
       
   526                         
       
   527                             // Check if it is tapped on any attachment name, if yes then open that attachment
       
   528                             CheckAndOpenTappedAttachmentL(posInfo);
       
   529                             delete posInfo;
       
   530                             }
       
   531                         }
       
   532     			    }
       
   533     				break;
       
   534     			}
       
   535     		case TPointerEvent::EDrag:
       
   536     			{
       
   537     			iTextEditor->SetFocus(ETrue);
       
   538     			break;
       
   539     			}
       
   540     		case TPointerEvent::EButton1Up:
       
   541     			{
       
   542     			iTextEditor->SetFocus(ETrue);
       
   543     			TInt curPos = iTextEditor->CursorPos();	
       
   544 		        TRect rect = iTextEditor->Rect();  
       
   545 		       	
       
   546     			break;	
       
   547     			}
       
   548     		default:
       
   549     			{
       
   550     			break;	
       
   551     			}	
       
   552     		}
       
   553      }
       
   554        	
       
   555     TRACE_EXIT_POINT;
       
   556     }
       
   557     
       
   558 // ----------------------------------------------------------------------------
       
   559 // CCalenEventViewContainer::GetHelpContext
       
   560 // Get help context.
       
   561 // (other items were commented in a header).
       
   562 // ----------------------------------------------------------------------------
       
   563 //
       
   564 void CCalenEventViewContainer::GetHelpContext(TCoeHelpContext& aContext) const
       
   565     {
       
   566     TRACE_ENTRY_POINT;
       
   567     
       
   568     aContext.iMajor = KUidCalendar;
       
   569     aContext.iContext = KCALE_HLP_NOTE_VIEWER; // need to change	
       
   570 	
       
   571     TRACE_EXIT_POINT;
       
   572     }
       
   573 
       
   574 // ----------------------------------------------------------------------------
       
   575 // CCalenEventViewContainer::HandleResourceChange
       
   576 // Handles a resource relative event.
       
   577 // (other items were commented in a header).
       
   578 // ----------------------------------------------------------------------------
       
   579 //
       
   580 void CCalenEventViewContainer::HandleResourceChange(TInt aType)
       
   581     {
       
   582     TRACE_ENTRY_POINT; 
       
   583 
       
   584     CCalenContainer::HandleResourceChange( aType );
       
   585 
       
   586     if( ( aType == KUidValueCoeColorSchemeChangeEvent ) ||
       
   587             ( aType == KUidValueCoeZoomChangeEvent ) ||
       
   588             ( aType == KUidValueCoeFontChangeEvent ) )
       
   589         {
       
   590 //        CEikAppUi* appUi = static_cast<CEikAppUi*>( ControlEnv()->AppUi() );
       
   591 //        SetRect( appUi->ClientRect() );
       
   592         TRect mainPane;
       
   593         AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane, mainPane );
       
   594         SetRect( mainPane );
       
   595         }
       
   596 
       
   597     if( KAknsMessageSkinChange == aType || 
       
   598             KEikDynamicLayoutVariantSwitch == aType )
       
   599         {
       
   600 	    SizeChanged();
       
   601 	    SetupFontL();
       
   602 	    if(iTextEditor->ScrollBarFrame())
       
   603 	        {
       
   604 	        // make the scrollbars invisible
       
   605 	        iTextEditor->ScrollBarFrame()->SetScrollBarVisibilityL( CEikScrollBarFrame::EOff,
       
   606 	                                                                CEikScrollBarFrame::EOff);
       
   607 	        }
       
   608 	    
       
   609         // refresh
       
   610         TRAPD( error, iView->BeginRepopulationL() );
       
   611         if( KErrNone != error )
       
   612             {
       
   613             // To avoid warning.
       
   614             } 
       
   615         }
       
   616 
       
   617     // Allow the coecontrol to handle the changes if any.
       
   618     CCoeControl::HandleResourceChange( aType );
       
   619     
       
   620     TRACE_EXIT_POINT;
       
   621     }
       
   622 
       
   623 // ----------------------------------------------------------------------------
       
   624 // CCalenEventViewContainer::BuildTextEditorL
       
   625 // Build text editor
       
   626 // (other items were commented in a header).
       
   627 // ----------------------------------------------------------------------------
       
   628 //
       
   629 void CCalenEventViewContainer::BuildTextEditorL()
       
   630 	{
       
   631 	TRACE_ENTRY_POINT; 
       
   632         
       
   633     iTextEditor->SetFocus(EFalse);    
       
   634     iTextEditor->SetRect( Rect() );
       
   635     iTextEditor->SetCursorPosL(0,EFalse);
       
   636     iTextEditor->RichText()->Reset();
       
   637     
       
   638     // Create the scroll bars.
       
   639     iTextEditor->CreateScrollBarFrameL();
       
   640     iTextEditor->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto);
       
   641     iTextEditor->SetAknEditorFlags(EAknEditorFlagEnableScrollBars);
       
   642     iTextEditor->ScrollBarFrame()->VerticalScrollBar()->SetMopParent(this);
       
   643     
       
   644     iTextEditor->ScrollBarFrame()->SetScrollBarFrameObserver(this);
       
   645     
       
   646     TEikScrollBarModel h,v;
       
   647     TEikScrollBarFrameLayout lay;
       
   648     CEikAppUi* appUi = static_cast<CEikAppUi*>( ControlEnv()->AppUi() );
       
   649     TRect rec = appUi->ClientRect();
       
   650  //   ASSERT( iTextEditor->ScrollBarFrame()->TileL( &h, &v, rec, rec, lay) );
       
   651     
       
   652     SetLayoutFromLookAndFeelL();
       
   653     
       
   654     SetupFontL();
       
   655     
       
   656     TRACE_EXIT_POINT;
       
   657 	}
       
   658 
       
   659 // ----------------------------------------------------------------------------
       
   660 // CCalenEventViewContainer::SetIconsL
       
   661 // Set the icons
       
   662 // (other items were commented in a header).
       
   663 // ----------------------------------------------------------------------------
       
   664 //
       
   665 void CCalenEventViewContainer::SetIconsL(CCalenIconDrawer* aIconDrawer)
       
   666 	{
       
   667     // Create a TPictureHeader to insert our icons into the viewer
       
   668     TPictureHeader header;
       
   669     header.iPicture = TSwizzle<CPicture>(aIconDrawer);
       
   670 
       
   671     // Insert the icon drawer into the Rich Text Editor.  This takes
       
   672     // ownership of the icon drawer.
       
   673     // Insert at index 0 in the document to cause the icons to be drawn when
       
   674     // the first line is visible.  The icons will not be drawn at position 0,
       
   675     // but this position must be on the screen for the icons to be drawn.
       
   676     iTextEditor->RichText()->InsertL( 0, header );
       
   677 
       
   678     // Tell the text editor that it has been updated.  This will cause
       
   679     // a redraw.
       
   680     iTextEditor->HandleTextChangedL();
       
   681 	}
       
   682 
       
   683 // ----------------------------------------------------------------------------
       
   684 // CCalenEventViewContainer::CreateAndInitializeIconsDrawerL
       
   685 // Cretaes the CCalenIconDrawer object for the container and returns it
       
   686 // (other items were commented in a header).
       
   687 // ----------------------------------------------------------------------------
       
   688 //
       
   689 CCalenIconDrawer* CCalenEventViewContainer::CreateAndInitializeIconsDrawerL()
       
   690     {
       
   691     // Create and populate the icon drawer.  We need to do this first to prevent a long
       
   692     // summary text being drawn over the icons
       
   693     // Ownership of icon drawer transferred to rich text editor
       
   694     CCalenIconDrawer* iconDrawer = CCalenIconDrawer::NewL( iServices );
       
   695     PopulateIconDrawerL(*iconDrawer);
       
   696     return iconDrawer;
       
   697     }
       
   698 // ----------------------------------------------------------------------------
       
   699 // CCalenEventViewContainer::RequestInstanceViewL
       
   700 // Request for instance view
       
   701 // (other items were commented in a header).
       
   702 // ----------------------------------------------------------------------------
       
   703 //
       
   704 TInt CCalenEventViewContainer::RequestInstanceViewL()
       
   705 	{
       
   706 	TRACE_ENTRY_POINT; 
       
   707 
       
   708     MCalenContext& context = iServices.Context();
       
   709     TCalenInstanceId instanceId = context.InstanceId();
       
   710     TCalLocalUid entryLocalUid = instanceId.iEntryLocalUid;
       
   711     TTime instanceStartTime = context.InstanceId().iInstanceTime;
       
   712 
       
   713     if(iEntry)
       
   714         {
       
   715         delete iEntry;
       
   716         iEntry = NULL;
       
   717         }
       
   718     //If the timezone is changed after opening the viewer
       
   719     //We need to use the new instance time and need to update the context later
       
   720     // Get the active collection ids.
       
   721     RArray<TInt> colIdArray;
       
   722     CCalenNativeView::GetActiveCollectionidsL( iServices, colIdArray );
       
   723     
       
   724     CCalInstanceView* instanceView = NULL;
       
   725     if(iLocaleChanged)
       
   726         {
       
   727         instanceView = iServices.InstanceViewL(colIdArray);
       
   728         CCalInstance* instance = FindPossibleInstanceL( instanceId,*instanceView );
       
   729         if(instance)
       
   730             {
       
   731             instanceStartTime = instance->StartTimeL().TimeLocalL();
       
   732             }
       
   733         }
       
   734     colIdArray.Reset();
       
   735     
       
   736     iEntry = iServices.EntryViewL(context.InstanceId().iColId)->FetchL(entryLocalUid);
       
   737 	
       
   738 	TCalTime instanceDateTime;
       
   739 	instanceDateTime.SetTimeLocalL( context.InstanceId().iInstanceTime );
       
   740     
       
   741    if(!iEntry)
       
   742 		{
       
   743 		// If the entry is not let's not further proceed.
       
   744 		// The entry has been removed by some other app eg. Synch.
       
   745 		return KErrNotFound;
       
   746 		}
       
   747 		
       
   748     if(iEventViewData)
       
   749     	{
       
   750     	delete iEventViewData;
       
   751     	iEventViewData = NULL;
       
   752     	}
       
   753     iEventViewData = CCalenEntryUtil::NewL( *iEntry, instanceDateTime );
       
   754     
       
   755     //If timezone is changed after opening the entry in the viewer
       
   756     //we need to update the instance id to the context
       
   757     if(iLocaleChanged)
       
   758         {
       
   759         iLocaleChanged = EFalse;
       
   760         instanceId.iInstanceTime = instanceStartTime;
       
   761         context.SetFocusDateAndTimeAndInstanceL( instanceDateTime,instanceId,TVwsViewId( KUidCalendar, KUidCalenEventView ) );
       
   762         }
       
   763     TRACE_EXIT_POINT;
       
   764 	return KErrNone;
       
   765 	}
       
   766 
       
   767 // ----------------------------------------------------------------------------
       
   768 // CCalenEventViewContainer::AddFieldsL
       
   769 // Add the data fields
       
   770 // (other items were commented in a header).
       
   771 // ----------------------------------------------------------------------------
       
   772 //
       
   773 void CCalenEventViewContainer::AddFieldsL()
       
   774 	{
       
   775 	TRACE_ENTRY_POINT;
       
   776 	// Initialize icon drawer
       
   777 	CCalenIconDrawer* iconDrawer = CreateAndInitializeIconsDrawerL();
       
   778 	
       
   779 	// add subject field
       
   780 	AddSubjectFieldL();	
       
   781 	
       
   782 	switch ( iEntry->EntryTypeL() )
       
   783         {
       
   784         case CCalEntry::EReminder:
       
   785         case CCalEntry::EAppt:
       
   786         	{
       
   787         	// start time
       
   788 		    AddTimeFieldL();
       
   789 
       
   790 		    // location
       
   791 		    AddLocationFieldL();
       
   792 
       
   793             // Adds empty line
       
   794 		    AddEmptyLineL();
       
   795 
       
   796 		    // alarm
       
   797 		    AddAlarmDateTimeFieldL();
       
   798 
       
   799 		    // We want to show the repeat fields for repeating parent entries or 
       
   800 		    // child entries.  If the entry is a child then the repeat information from the
       
   801 		    // parent will be shown
       
   802 		    //if ((iEventViewData->IsRepeating()) || (Handler().Edited()->Entry().RecurrenceIdL().TimeUtcL() != Time::NullTTime()))
       
   803 		    if ((iEventViewData->IsRepeating()) || (iEntry->RecurrenceIdL().TimeUtcL() != Time::NullTTime()))
       
   804 		        {
       
   805 		        AddRepeatFieldL();
       
   806 		        }
       
   807 		    
       
   808             iTitleTextId = R_CALEN_EVENT_VIEW_MEETING_TITLE;          
       
   809 		   	}
       
   810             break;
       
   811 
       
   812         case CCalEntry::EAnniv:
       
   813             {
       
   814             // date field
       
   815             AddDateFieldL(iEventViewData->StartDateTime());
       
   816             
       
   817             // against the location field in the viewer
       
   818             iTimeFieldLines = 1;
       
   819             // location
       
   820             AddLocationFieldL();
       
   821     		
       
   822             // Adds empty line
       
   823             AddEmptyLineL();
       
   824             
       
   825     		// alarm
       
   826     		AddAlarmDateTimeFieldL();
       
   827 
       
   828     		// Add the 'since' field.
       
   829     		AddSinceFieldL();
       
   830 
       
   831 		    iTitleTextId = R_CALEN_EVENT_VIEW_ANNIV_TITLE;      		
       
   832 	        }
       
   833             break;
       
   834  
       
   835         case CCalEntry::EEvent:
       
   836  			{
       
   837 		 	// If the start time is on the same day as the end time, just show the date.
       
   838 			// Otherwise, show "start date - end date".
       
   839 			TTime startTime = iEventViewData->StartDateTime();
       
   840 			TTime endTime = iEventViewData->EndDateTime();
       
   841 			
       
   842 	        // For allday (1 day) event Eg. "Start:- 12:00am, 15-08-2010 &  End:-12:00am, 16-08-2010"
       
   843 	        // In viewer it should be displayed as "StartDate: 15-08-2010 & EndDate:15-08-2010" 
       
   844 	        // No time filed is displayed.
       
   845             endTime -= TTimeIntervalDays( 1 );
       
   846 
       
   847             // Set title to 'ALL DAY'
       
   848             iTitleTextId = R_CALEN_EVENT_VIEW_ALLDAY_TITLE;           
       
   849 
       
   850 			if( CalenDateUtils::OnSameDay(startTime, endTime) )
       
   851 				{
       
   852 				AddDateFieldL( startTime );
       
   853 				}
       
   854 			else
       
   855 				{
       
   856 				AddDateDateFieldL( startTime, endTime );
       
   857 				}
       
   858 
       
   859 			// Increment the time filed count to 1 so that maps icon is placed
       
   860 			// against the location field in the viewer
       
   861                     iTimeFieldLines = 1;
       
   862 			
       
   863 			// location
       
   864                     AddLocationFieldL();
       
   865             
       
   866 		    // extra empty line between primary and secondary information
       
   867 		    AddEmptyLineL();
       
   868 		    
       
   869 		    // alarm    
       
   870 		    AddAlarmDateTimeFieldL();
       
   871 		    
       
   872 		    // Currently it's not possible to create a repeating day note in the UI.
       
   873 		    // However, it is possible to import one from an iCalendar file or create
       
   874 		    // one in code. Therefore the repeat properties of day notes are shown
       
   875 		    // if they exist. If the entry is modified (in the editor), the repeat
       
   876 		    // properties will be lost.
       
   877 		    if(iEventViewData->IsRepeating())
       
   878 		        {
       
   879 		        AddRepeatFieldL();
       
   880 		        }
       
   881 		        
       
   882  			}
       
   883             break;
       
   884 
       
   885         case CCalEntry::ETodo:
       
   886             {
       
   887 		    // extra empty line between primary and secondary information
       
   888 		    AddEmptyLineL();
       
   889 
       
   890 			// Due date
       
   891 			TTime dueDate = iEventViewData->EventDateTime();
       
   892 		    AddDateFieldL(R_QTN_CALE_EVENT_VIEW_DUE_DATE, dueDate);
       
   893 		    // Adds empty line
       
   894 		    AddEmptyLineL();
       
   895 		    
       
   896             //Adds calendar info field to the viewer
       
   897            //AddCalendarInfoFieldL();
       
   898 
       
   899             // Adds empty line
       
   900             //AddEmptyLineL();
       
   901 
       
   902 		    // Alarm is only shown if the todo is not complete.
       
   903 		    //if (Handler().Entry().StatusL() != CCalEntry::ETodoCompleted)
       
   904 			if (iEntry->StatusL() != CCalEntry::ETodoCompleted)
       
   905 		        {
       
   906 		        AddAlarmDateTimeFieldL();
       
   907 		        }
       
   908 
       
   909 		    // Show completion date if complete
       
   910 		    else
       
   911 		        {
       
   912 		        AddDateFieldL(R_QTN_CALE_EVENT_VIEW_COMPLETED, iEntry->CompletedTimeL().TimeLocalL());
       
   913 		        }
       
   914 
       
   915 		    // Priority
       
   916 		    AddPriorityFieldL();
       
   917 		    
       
   918 		    // Repeat rules.  Supporting repeating todos sounds like asking for trouble to me.
       
   919 		    if (iEventViewData->IsRepeating())
       
   920 		        {
       
   921 		        AddRepeatFieldL();
       
   922 		        }
       
   923 		        
       
   924 		    iTitleTextId = R_CALEN_EVENT_VIEW_TODO_TITLE;  			
       
   925             }
       
   926             break;
       
   927 
       
   928         default:
       
   929             __ASSERT_DEBUG(EFalse, User::Invariant());
       
   930             break;
       
   931         }
       
   932 	if(IsEventHasMapLocationL())
       
   933         {
       
   934         // Update iNumOfLinesBeforeLocField
       
   935         
       
   936         // Add map icon to the icon drawer
       
   937         iconDrawer->AddIconL( MCalenServices::ECalenMapIcon );
       
   938                
       
   939         // Set the icon sizes
       
   940         iconDrawer->SetIconSizesFromLayout();       
       
   941         }
       
   942 	SetIconsL(iconDrawer);
       
   943 
       
   944 	// Add Description
       
   945     AddDescriptionFieldL();
       
   946     
       
   947     // Add attachment field
       
   948     // TODO: Uncomment this when enabling attachment support
       
   949     
       
   950     if(iEventViewData->AttachmentCount())
       
   951         {
       
   952         AddAttachmentFieldL();
       
   953         }
       
   954     
       
   955 	TRACE_EXIT_POINT;
       
   956 	}
       
   957 
       
   958 // ----------------------------------------------------------------------------
       
   959 // CCalenEventViewContainer::SetLayoutFromLookAndFeelL
       
   960 // Set the layout data
       
   961 // (other items were commented in a header).
       
   962 // ----------------------------------------------------------------------------
       
   963 //
       
   964 void CCalenEventViewContainer::SetLayoutFromLookAndFeelL()
       
   965 	{
       
   966     TRACE_ENTRY_POINT;
       
   967 
       
   968     iParaFormat->Reset();
       
   969     iParaFormatMask.ClearAll();
       
   970     iCharFormatMask.ClearAll();
       
   971 
       
   972     iParaFormatMask.SetAttrib(EAttLeftMargin);
       
   973     iParaFormatMask.SetAttrib(EAttRightMargin);
       
   974 
       
   975     // Get the main pane
       
   976     TSize main_pane_size;
       
   977     AknLayoutUtils::LayoutMetricsSize (AknLayoutUtils::EMainPane, main_pane_size);
       
   978     TRect main_pane(main_pane_size);
       
   979 
       
   980     // Get main_cale_event_viewer_pane with main_pane as parent
       
   981     TAknLayoutRect main_cale_event_viewer_pane;
       
   982     main_cale_event_viewer_pane.LayoutRect(main_pane, AknLayoutScalable_Apps::main_cale_event_viewer_pane().LayoutLine() );
       
   983 
       
   984     // Get listscroll_cale_event_viewer_pane with main_cale_event_viewer_pane as parent
       
   985     TAknLayoutRect listscroll_cale_event_viewer_pane;
       
   986     listscroll_cale_event_viewer_pane.LayoutRect(main_cale_event_viewer_pane.Rect(), AknLayoutScalable_Apps::listscroll_cale_event_viewer_pane().LayoutLine() );
       
   987 
       
   988     // Get list_cale_ev2_pane with listscroll_cale_event_viewer_pane as parent
       
   989     TAknLayoutRect list_cale_ev2_pane;
       
   990     list_cale_ev2_pane.LayoutRect(listscroll_cale_event_viewer_pane.Rect(), AknLayoutScalable_Apps::list_cale_ev2_pane().LayoutLine() );
       
   991     
       
   992      // Get the main pane
       
   993      TAknLayoutRect main_cale_day_pane;
       
   994      main_cale_day_pane.LayoutRect( Rect(), 
       
   995              AknLayoutScalable_Apps::main_cale_day_pane().LayoutLine() );
       
   996          
       
   997      TAknLayoutRect listscroll_cale_day_pane;
       
   998      listscroll_cale_day_pane.LayoutRect( main_cale_day_pane.Rect(), 
       
   999              AknLayoutScalable_Apps::listscroll_cale_day_pane( 0 ).LayoutLine() );
       
  1000 
       
  1001    
       
  1002       // Listbox layout
       
  1003       TAknLayoutRect list_cale_pane;
       
  1004       list_cale_pane.LayoutRect( main_cale_day_pane.Rect(), AknLayoutScalable_Apps::list_cale_pane( 3 ).LayoutLine() );
       
  1005  
       
  1006       // Adjust the rect to show the map icon if necessary
       
  1007       TRect temp_list_cale_ev2_pane = list_cale_pane.Rect();
       
  1008    
       
  1009      
       
  1010     iTextEditor->SetRect(temp_list_cale_ev2_pane);
       
  1011     
       
  1012     // Scrollbar layout
       
  1013     AknLayoutUtils::LayoutVerticalScrollBar( iTextEditor->ScrollBarFrame(),
       
  1014                                              listscroll_cale_day_pane.Rect(),
       
  1015                                              AknLayoutScalable_Apps::scroll_pane_cp09( 3 ).LayoutLine() );
       
  1016     
       
  1017     // Get field_cale_ev2_pane with list_cale_ev2_pane as parent
       
  1018     TAknLayoutRect field_cale_ev2_pane;
       
  1019     field_cale_ev2_pane.LayoutRect(list_cale_ev2_pane.Rect(), AknLayoutScalable_Apps::field_cale_ev2_pane(0).LayoutLine() );
       
  1020 
       
  1021     // Get field_cale_ev2_pane_t1
       
  1022     TAknTextLineLayout field_cale_ev2_pane_t1 = AknLayoutScalable_Apps::field_cale_ev2_pane_t1(0).LayoutLine();
       
  1023 
       
  1024     // Get heading layout properties from field_cale_ev2_pane_t1 with list_cale_ev2_pane as parent
       
  1025     TAknLayoutText headingTextLayout;
       
  1026     headingTextLayout.LayoutText(list_cale_ev2_pane.Rect(), field_cale_ev2_pane_t1);
       
  1027 
       
  1028     // Set heading indenting and font
       
  1029     if (!AknLayoutUtils::LayoutMirrored())
       
  1030         {
       
  1031         // Normal L-R layout.
       
  1032         // Heading indent is heading text layout rect left x pos -
       
  1033         // text editor rect left xpos.  The heading text layout rect gives us an absolute
       
  1034         // screen position, but the value that we need should be relative to
       
  1035         // the text editor itself
       
  1036         TInt headingIndentPixels =  headingTextLayout.TextRect().iTl.iX -
       
  1037                                     list_cale_ev2_pane.Rect().iTl.iX;
       
  1038         iHeadingIndent    = PixelsToTwips(headingIndentPixels);
       
  1039         }
       
  1040     else
       
  1041         {
       
  1042         // Mirrored, R-L layout.
       
  1043         // Heading indent is the text editor rect right x pos -
       
  1044         // the heading text layout rect right x pos
       
  1045         TInt headingIndentPixels =  list_cale_ev2_pane.Rect().iBr.iX -
       
  1046                                     headingTextLayout.TextRect().iBr.iX;
       
  1047         iHeadingIndent    = PixelsToTwips(headingIndentPixels);
       
  1048         }
       
  1049 
       
  1050     iHeadingFontSpec  = headingTextLayout.Font()->FontSpecInTwips();
       
  1051     iHeadingFontSpec.iFontStyle.SetStrokeWeight(EStrokeWeightBold);
       
  1052     iEmptyLineHeight  = PixelsToTwips(headingTextLayout.TextRect().Height() / 2);
       
  1053     iHeadingFont = headingTextLayout.Font();
       
  1054 
       
  1055     // Get field_cale_ev2_pane_t2
       
  1056     TAknTextLineLayout field_cale_ev2_pane_t2 = AknLayoutScalable_Apps::field_cale_ev2_pane_t2(1).LayoutLine();
       
  1057 
       
  1058     // Get body layout properties from field_cale_ev2_pane_t2 // with field_ev_content_pane as parent
       
  1059     TAknLayoutText bodyTextLayout;
       
  1060     bodyTextLayout.LayoutText(list_cale_ev2_pane.Rect(), field_cale_ev2_pane_t2);
       
  1061     iMaxWidth = bodyTextLayout.TextRect().Width();
       
  1062 
       
  1063     // Set body indenting and font
       
  1064     if (!AknLayoutUtils::LayoutMirrored())
       
  1065         {
       
  1066         // Normal L-R layout.
       
  1067         // Body text indent is body text layout rect left x pos -
       
  1068         // text editor rect left xpos.  The heading text layout rect gives us an absolute
       
  1069         // screen position, but the value that we need should be relative to
       
  1070         // the text editor itself
       
  1071         TInt bodyIndentPixels = bodyTextLayout.TextRect().iTl.iX -
       
  1072                                 list_cale_ev2_pane.Rect().iTl.iX;
       
  1073         iBodyIndent    = PixelsToTwips(bodyIndentPixels);
       
  1074         }
       
  1075     else
       
  1076         {
       
  1077         // Mirrored, R-L layout.
       
  1078         // Body indent is the text editor rect right x pos -
       
  1079         // the body text layout rect right x pos
       
  1080         TInt bodyIndentPixels = list_cale_ev2_pane.Rect().iBr.iX -
       
  1081                                 bodyTextLayout.TextRect().iBr.iX;
       
  1082         iBodyIndent = PixelsToTwips(bodyIndentPixels);
       
  1083         }
       
  1084 
       
  1085     iBodyFontSpec = bodyTextLayout.Font()->FontSpecInTwips();
       
  1086     iBodyFont = bodyTextLayout.Font(); // Used for TryToFitL	
       
  1087 	
       
  1088 	TRACE_EXIT_POINT;
       
  1089 	}		
       
  1090 
       
  1091 // ----------------------------------------------------------------------------
       
  1092 // CCalenEventViewContainer::SetupFontL
       
  1093 // Set the font colour, and set default para/char format layers to the
       
  1094 // rich text editor.
       
  1095 // (other items were commented in a header).
       
  1096 // ----------------------------------------------------------------------------
       
  1097 //
       
  1098 void CCalenEventViewContainer::SetupFontL()	
       
  1099 	{
       
  1100     TRACE_ENTRY_POINT;
       
  1101 
       
  1102     // Set desired character formatting attributes. Gets sensible text colour based on theme.
       
  1103     TRgb textColourFromSkin(255,0,0);					 // If you see bright red text, the skins api is broken!
       
  1104     MAknsSkinInstance* skin = AknsUtils::SkinInstance(); // Does not transfer ownership.
       
  1105     AknsUtils::GetCachedColor(skin, textColourFromSkin, KAknsIIDQsnTextColors, EAknsCIQsnTextColorsCG6);
       
  1106 
       
  1107     TCharFormat charFormat;
       
  1108     TCharFormatMask charFormatMask;
       
  1109     // Set the text colour we found.
       
  1110     charFormat.iFontPresentation.iTextColor = TLogicalRgb(textColourFromSkin);
       
  1111     charFormatMask.SetAttrib(EAttColor);
       
  1112 
       
  1113     // Set up our paragraph formatting attributes.
       
  1114     CParaFormat* paraFormat = CParaFormat::NewLC();
       
  1115     TParaFormatMask paraFormatMask;
       
  1116 
       
  1117     // Set up the default font so it's the same as the body text used.
       
  1118     // This means we can do without setting the para/char format layers
       
  1119     // when adding body text.
       
  1120     paraFormat->iLeftMarginInTwips = iBodyIndent;
       
  1121     paraFormatMask.SetAttrib(EAttLeftMargin);
       
  1122     paraFormatMask.SetAttrib(EAttRightMargin);
       
  1123 
       
  1124     charFormat.iFontSpec = iBodyFontSpec;
       
  1125     charFormatMask.SetAttrib(EAttFontHeight);
       
  1126     charFormatMask.SetAttrib(EAttFontTypeface);
       
  1127     charFormatMask.SetAttrib(EAttFontStrokeWeight);
       
  1128 
       
  1129     // Create some format layers based on the attributes we specified above.
       
  1130     // The underlying Edwin will take ownership of the format objects created below, so don't need to delete.
       
  1131     CParaFormatLayer* paraFormatLayer = CParaFormatLayer::NewL(paraFormat, paraFormatMask);
       
  1132     CleanupStack::PushL(paraFormatLayer);
       
  1133     CCharFormatLayer* charFormatLayer = CCharFormatLayer::NewL(charFormat, charFormatMask);
       
  1134     CleanupStack::Pop(paraFormatLayer);
       
  1135 
       
  1136     // Set the format layers.
       
  1137     iTextEditor->SetParaFormatLayer(paraFormatLayer);
       
  1138     iTextEditor->SetCharFormatLayer(charFormatLayer);
       
  1139 
       
  1140     // And get rid of paraFormat. All other allocations are owned by the CEikRichTextEditor.
       
  1141     CleanupStack::PopAndDestroy(paraFormat);	
       
  1142 
       
  1143 	TRACE_EXIT_POINT;
       
  1144 	}		
       
  1145 
       
  1146 // -----------------------------------------------------------------------------
       
  1147 // CCalenViewerBase::PopulateIconDrawerL
       
  1148 // Ask IconDrawer to prepare icons that are going to be drawn
       
  1149 // (other items were commented in a header).
       
  1150 // -----------------------------------------------------------------------------
       
  1151 //
       
  1152 void CCalenEventViewContainer::PopulateIconDrawerL(CCalenIconDrawer& aIconDrawer)
       
  1153     {
       
  1154     TRACE_ENTRY_POINT;
       
  1155 
       
  1156     // Alarm icon?
       
  1157     if( iEventViewData->IsAlarmActivated() )
       
  1158         {
       
  1159         // For todos, only add the alarm icon if it's not completed.
       
  1160         if ( iEventViewData->EntryType() == CCalEntry::ETodo )
       
  1161             {
       
  1162           //  if(iEditedCalEntry.StatusL() != CCalEntry::ETodoCompleted)
       
  1163           	if(iEntry->StatusL() != CCalEntry::ETodoCompleted)	
       
  1164                 {
       
  1165                 aIconDrawer.AddIconL( MCalenServices::ECalenAlarmIcon );
       
  1166                 }
       
  1167             }
       
  1168         else
       
  1169             {
       
  1170             aIconDrawer.AddIconL( MCalenServices::ECalenAlarmIcon );
       
  1171             }
       
  1172         }
       
  1173 
       
  1174     // Repeat / exception icon?
       
  1175     if (iEventViewData->IsRepeating())
       
  1176         {
       
  1177         aIconDrawer.AddIconL( MCalenServices::ECalenRepeatIcon );
       
  1178         }
       
  1179     else
       
  1180         {
       
  1181         if (iEntry->RecurrenceIdL().TimeUtcL() != Time::NullTTime())
       
  1182             {
       
  1183             aIconDrawer.AddIconL( MCalenServices::ECalenRepeatExceptionIcon );
       
  1184             }
       
  1185         }
       
  1186 
       
  1187     // Todo priority icon?
       
  1188     if (iEventViewData->EntryType() == CCalEntry::ETodo)
       
  1189         {
       
  1190         CCalenEntryUtil::TTodoPriority priority = iEventViewData->Priority();
       
  1191         if (priority == CCalenEntryUtil::ETodoPriorityHigh)
       
  1192             {
       
  1193             aIconDrawer.AddIconL( MCalenServices::ECalenNotePriorityHigh );
       
  1194             }
       
  1195         else if (priority == CCalenEntryUtil::ETodoPriorityLow)
       
  1196             {
       
  1197             aIconDrawer.AddIconL( MCalenServices::ECalenNotePriorityLow );
       
  1198             }
       
  1199         else
       
  1200             {
       
  1201             // nothing
       
  1202             }
       
  1203         }
       
  1204     // Set the icon sizes
       
  1205     aIconDrawer.SetIconSizesFromLayout(); 
       
  1206 
       
  1207     // Get the icon drawer width
       
  1208     iIconDrawerWidthInPixels = aIconDrawer.WidthInPixels();
       
  1209 
       
  1210     TRACE_EXIT_POINT;
       
  1211     }
       
  1212 
       
  1213 // -----------------------------------------------------------------------------
       
  1214 // CCalenEventViewContainer::SetFormatAndAddHeadingL
       
  1215 // 
       
  1216 // -----------------------------------------------------------------------------
       
  1217 //
       
  1218 void CCalenEventViewContainer::SetFormatAndAddHeadingL(const TDesC& aHeading)
       
  1219     {
       
  1220 	TRACE_ENTRY_POINT;
       
  1221 
       
  1222     iCharFormatMask.ClearAll();
       
  1223     iParaFormat->iLeftMarginInTwips = iHeadingIndent;
       
  1224     iCharFormat.iFontSpec = iHeadingFontSpec;
       
  1225     iCharFormatMask.SetAttrib( EAttFontHeight );
       
  1226     iCharFormatMask.SetAttrib( EAttFontTypeface );
       
  1227     iCharFormatMask.SetAttrib( EAttFontStrokeWeight );
       
  1228     AddFormattedTextL( aHeading );
       
  1229 	
       
  1230 	TRACE_EXIT_POINT;
       
  1231     }
       
  1232 
       
  1233 // -----------------------------------------------------------------------------
       
  1234 // CCalenEventViewContainer::SetFormatAndAddBodyL
       
  1235 // 
       
  1236 // -----------------------------------------------------------------------------
       
  1237 //
       
  1238 void CCalenEventViewContainer::SetFormatAndAddBodyL(const TDesC& aBody)
       
  1239     {
       
  1240     TRACE_ENTRY_POINT;
       
  1241 
       
  1242     iCharFormatMask.ClearAll();
       
  1243     iParaFormat->iLeftMarginInTwips = iBodyIndent;
       
  1244     iCharFormat.iFontSpec = iBodyFontSpec;
       
  1245     iCharFormatMask.SetAttrib( EAttFontHeight );
       
  1246     iCharFormatMask.SetAttrib( EAttFontTypeface );
       
  1247     iCharFormatMask.SetAttrib( EAttFontStrokeWeight );
       
  1248     AddFormattedTextL( aBody );
       
  1249 
       
  1250     TRACE_EXIT_POINT;
       
  1251     }
       
  1252 
       
  1253 // -----------------------------------------------------------------------------
       
  1254 // CCalenEventViewContainer::AddEmptyLineL
       
  1255 // 
       
  1256 // -----------------------------------------------------------------------------
       
  1257 //
       
  1258 void CCalenEventViewContainer::AddEmptyLineL()
       
  1259     {
       
  1260    	TRACE_ENTRY_POINT; 
       
  1261 
       
  1262     CParaFormat* paraFormat = CParaFormat::NewLC();
       
  1263     TParaFormatMask paraFormatMask;
       
  1264     paraFormat->iLineSpacingControl = CParaFormat::ELineSpacingExactlyInTwips;
       
  1265     paraFormatMask.SetAttrib(EAttLineSpacingControl);
       
  1266     paraFormat->iLineSpacingInTwips = iEmptyLineHeight;
       
  1267     paraFormatMask.SetAttrib(EAttLineSpacing);
       
  1268     paraFormatMask.SetAttrib(EAttFontHighlightColor);
       
  1269 
       
  1270     CRichText* richText = iTextEditor->RichText();
       
  1271     TInt startPos = richText->DocumentLength();
       
  1272     richText->InsertL(richText->DocumentLength(), CEditableText::EParagraphDelimiter);
       
  1273     TInt endPos = richText->DocumentLength();
       
  1274 
       
  1275     richText->ApplyParaFormatL(paraFormat, paraFormatMask, startPos, endPos - startPos);
       
  1276 
       
  1277     CleanupStack::PopAndDestroy(paraFormat);
       
  1278 
       
  1279 	TRACE_EXIT_POINT;    
       
  1280     }
       
  1281 
       
  1282 // -----------------------------------------------------------------------------
       
  1283 // CCalenEventViewContainer::AddFormattedTextL
       
  1284 // Add a string to the view.
       
  1285 // (other items were commented in a header).
       
  1286 // -----------------------------------------------------------------------------
       
  1287 //
       
  1288 void CCalenEventViewContainer::AddFormattedTextL(const TDesC& aText)
       
  1289     {
       
  1290     TRACE_ENTRY_POINT;
       
  1291 
       
  1292     CRichText* richText = iTextEditor->RichText();
       
  1293     TInt startPos = richText->DocumentLength();
       
  1294     HBufC* text = HBufC::NewLC( aText.Length() + 10);
       
  1295     TPtr target = text->Des();
       
  1296     if(AknLayoutUtils::LayoutMirrored())
       
  1297     	{
       
  1298         target.Append(KArabicSummaryMarker);    
       
  1299     	}
       
  1300     else
       
  1301     	{
       
  1302         target.Append(KWesternSummaryMarker);
       
  1303     	}
       
  1304     target.Append(aText);
       
  1305     
       
  1306     richText->InsertL(startPos, target);
       
  1307     richText->InsertL(richText->DocumentLength(), CEditableText::EParagraphDelimiter);
       
  1308     TInt endPos = richText->DocumentLength();
       
  1309 
       
  1310     richText->ApplyCharFormatL(iCharFormat, iCharFormatMask, startPos, endPos - startPos);
       
  1311     ++startPos;  // Without this the previous paragraph is formatted as well, ie no indent
       
  1312     richText->ApplyParaFormatL(iParaFormat, iParaFormatMask, startPos, endPos - startPos);
       
  1313     CleanupStack::PopAndDestroy(text);
       
  1314 
       
  1315     TRACE_EXIT_POINT;
       
  1316     }
       
  1317 
       
  1318 // -----------------------------------------------------------------------------
       
  1319 // CCalenEventViewContainer::AddDescriptionFieldL
       
  1320 // Add a description field to the view.
       
  1321 // (other items were commented in a header).
       
  1322 // -----------------------------------------------------------------------------
       
  1323 //
       
  1324 void CCalenEventViewContainer::AddDescriptionFieldL()
       
  1325     {
       
  1326     TRACE_ENTRY_POINT;
       
  1327     //Add description
       
  1328     if (iEventViewData->Description() != KNullDesC)
       
  1329         {
       
  1330         AddTextFieldL(R_QTN_CALE_EVENT_VIEW_DESC, iEventViewData->Description());
       
  1331         // Add in a paragraph delimeter character
       
  1332         // Without this, long descriptions get cut off half way down the last line.
       
  1333         CRichText* richText = iTextEditor->RichText();
       
  1334         richText->InsertL(richText->DocumentLength(), CEditableText::EParagraphDelimiter);
       
  1335         }
       
  1336     TRACE_EXIT_POINT;
       
  1337     }
       
  1338 
       
  1339 // -----------------------------------------------------------------------------
       
  1340 // CCalenEventViewContainer::AddSinceFieldL
       
  1341 // Add a since field to the view.
       
  1342 // (other items were commented in a header).
       
  1343 // -----------------------------------------------------------------------------
       
  1344 //
       
  1345 void CCalenEventViewContainer::AddSinceFieldL()
       
  1346     {
       
  1347     TRACE_ENTRY_POINT;
       
  1348 
       
  1349     // Add since field, if the since year is different from the year of the instance opened.
       
  1350 	//    TInt instanceYear = Handler().Original().StartDateTime().DateTime().Year();
       
  1351 	TInt instanceYear = iEventViewData->StartDateTime().DateTime().Year();
       
  1352     TTime seriesTime = ParentEntryL().StartTimeL().TimeLocalL();
       
  1353     TInt seriesYear = seriesTime.DateTime().Year();
       
  1354 
       
  1355     if( seriesYear != instanceYear )
       
  1356         {
       
  1357         TBuf<32> formattedYear;
       
  1358         seriesTime.FormatL(formattedYear, KYearFormatString);
       
  1359         AknTextUtils::DisplayTextLanguageSpecificNumberConversion(formattedYear);
       
  1360         AddTextFieldL(R_QTN_CALE_EVENT_VIEW_SINCE, formattedYear);
       
  1361         }
       
  1362     TRACE_EXIT_POINT;
       
  1363     }
       
  1364 
       
  1365 // -----------------------------------------------------------------------------
       
  1366 // CCalenEventViewContainer::AddTextFieldL
       
  1367 // Add a text field to the view.
       
  1368 // (other items were commented in a header).
       
  1369 // -----------------------------------------------------------------------------
       
  1370 //
       
  1371 void CCalenEventViewContainer::AddTextFieldL(TInt aHeadingResource, TInt aBodyResource)
       
  1372     {
       
  1373     TRACE_ENTRY_POINT;
       
  1374     HBufC* textHeading = StringLoader::LoadLC(aHeadingResource);
       
  1375     SetFormatAndAddHeadingL(*textHeading);
       
  1376     CleanupStack::PopAndDestroy(textHeading);
       
  1377 
       
  1378     HBufC* textBody = StringLoader::LoadLC(aBodyResource);
       
  1379     SetFormatAndAddBodyL(*textBody);
       
  1380     CleanupStack::PopAndDestroy(textBody);
       
  1381     TRACE_EXIT_POINT;
       
  1382     }
       
  1383 
       
  1384 // -----------------------------------------------------------------------------
       
  1385 // CCalenEventViewContainer::AddTextFieldL
       
  1386 // Add a text field to the view.
       
  1387 // (other items were commented in a header).
       
  1388 // -----------------------------------------------------------------------------
       
  1389 //
       
  1390 void CCalenEventViewContainer::AddTextFieldL(TInt aHeadingResource, const TDesC& aBody)
       
  1391     {
       
  1392     TRACE_ENTRY_POINT;
       
  1393 
       
  1394     HBufC* textHeading = StringLoader::LoadLC(aHeadingResource);
       
  1395     SetFormatAndAddHeadingL(*textHeading);
       
  1396     CleanupStack::PopAndDestroy(textHeading);
       
  1397 
       
  1398     // If the value is empty, put a space in the output so we don't compress the empty line.
       
  1399     if( CalenAgendaUtils::IsEmptyText(aBody) )
       
  1400         {
       
  1401         SetFormatAndAddBodyL(KSpace);
       
  1402         }
       
  1403     else
       
  1404         {
       
  1405         SetFormatAndAddBodyL(aBody);
       
  1406         }
       
  1407     TRACE_EXIT_POINT;
       
  1408     }
       
  1409 
       
  1410 // -----------------------------------------------------------------------------
       
  1411 // CCalenEventViewContainer::AddSubjectFieldL
       
  1412 // Adds the entry's subject to the view.
       
  1413 // (other items were commented in a header).
       
  1414 // -----------------------------------------------------------------------------
       
  1415 //
       
  1416 void CCalenEventViewContainer::AddSubjectFieldL()
       
  1417     {
       
  1418     TRACE_ENTRY_POINT;
       
  1419 
       
  1420     iParaFormat->iRightMarginInTwips = PixelsToTwips(iIconDrawerWidthInPixels);
       
  1421     if (iEventViewData->Summary() != KNullDesC)
       
  1422         {
       
  1423         SetFormatAndAddHeadingL(iEventViewData->Summary());
       
  1424         }
       
  1425     else
       
  1426         {
       
  1427         HBufC* untitled = StringLoader::LoadLC(R_QTN_CALE_EVENT_VIEW_EMPTY_SUBJECT);
       
  1428         SetFormatAndAddHeadingL(*untitled);
       
  1429         CleanupStack::PopAndDestroy(untitled);
       
  1430         }
       
  1431     iParaFormat->iRightMarginInTwips = KDefaultRightMargin;
       
  1432 
       
  1433     TRACE_EXIT_POINT;
       
  1434     }
       
  1435 
       
  1436 // -----------------------------------------------------------------------------
       
  1437 // CCalenEventViewContainer::AddLocationFieldL
       
  1438 // Adds the entry's location to the view.
       
  1439 // (other items were commented in a header).
       
  1440 // -----------------------------------------------------------------------------
       
  1441 //
       
  1442 void CCalenEventViewContainer::AddLocationFieldL()
       
  1443     {
       
  1444     TRACE_ENTRY_POINT;
       
  1445     
       
  1446    
       
  1447     
       
  1448     iParaFormat->iRightMarginInTwips = PixelsToTwips(20);
       
  1449     if (iEventViewData->Location() != KNullDesC )
       
  1450         {
       
  1451         SetFormatAndAddBodyL(iEventViewData->Location());
       
  1452         }
       
  1453     iParaFormat->iRightMarginInTwips = KDefaultRightMargin;
       
  1454     TRACE_EXIT_POINT;
       
  1455     }
       
  1456 
       
  1457 // -----------------------------------------------------------------------------
       
  1458 // CCalenEventViewContainer::AddPriorityFieldL
       
  1459 // Reads the priority from the entry and adds a field to the form accordingly.
       
  1460 // (other items were commented in a header).
       
  1461 // -----------------------------------------------------------------------------
       
  1462 //
       
  1463 void CCalenEventViewContainer::AddPriorityFieldL()
       
  1464     {
       
  1465     TRACE_ENTRY_POINT;
       
  1466 
       
  1467     CCalenEntryUtil::TTodoPriority priority = iEventViewData->Priority();
       
  1468 
       
  1469     // Don't add the priority field if it's normal priority.
       
  1470     if( priority != CCalenEntryUtil::ETodoPriorityNormal )
       
  1471         {
       
  1472         CDesCArrayFlat* priorities = ControlEnv()->ReadDesCArrayResourceL(R_CALE_EVENT_VIEW_TODO_PRIORITY);
       
  1473         CleanupStack::PushL(priorities);
       
  1474         const TDesC& priorityText = (*priorities)[CalendarPriorityToFormPriority(priority)];
       
  1475         AddTextFieldL(R_QTN_CALE_EVENT_VIEW_PRIO, priorityText);
       
  1476         CleanupStack::PopAndDestroy(); // priorities
       
  1477         }
       
  1478     TRACE_EXIT_POINT;
       
  1479     }
       
  1480 
       
  1481 
       
  1482 // -----------------------------------------------------------------------------
       
  1483 // CCalenEventViewContainer::AddTimeFieldL
       
  1484 // Add a time field to the form.
       
  1485 // (other items were commented in a header).
       
  1486 // -----------------------------------------------------------------------------
       
  1487 //
       
  1488 void CCalenEventViewContainer::AddTimeFieldL(TInt aLabelResource, const TTime& aTime)
       
  1489     {
       
  1490     TRACE_ENTRY_POINT;
       
  1491 
       
  1492     TBuf<32> formattedTime;
       
  1493     aTime.FormatL(formattedTime, *iTimeFormat);
       
  1494     AknTextUtils::DisplayTextLanguageSpecificNumberConversion(formattedTime);
       
  1495     AddTextFieldL(aLabelResource, formattedTime);
       
  1496 
       
  1497     TRACE_EXIT_POINT;
       
  1498     }
       
  1499 
       
  1500 // -----------------------------------------------------------------------------
       
  1501 // CCalenEventViewContainer::AddDateFieldL
       
  1502 // Add a date field to the form.
       
  1503 // (other items were commented in a header).
       
  1504 // -----------------------------------------------------------------------------
       
  1505 //
       
  1506 void CCalenEventViewContainer::AddDateFieldL(const TTime& aDate)
       
  1507     {
       
  1508     TRACE_ENTRY_POINT;
       
  1509 
       
  1510     TBuf<32> formattedDate;
       
  1511     aDate.FormatL(formattedDate, *iDateFormat);
       
  1512     AknTextUtils::DisplayTextLanguageSpecificNumberConversion(formattedDate);
       
  1513     SetFormatAndAddBodyL(formattedDate);
       
  1514 
       
  1515     TRACE_EXIT_POINT;
       
  1516     }
       
  1517 
       
  1518 // -----------------------------------------------------------------------------
       
  1519 // CCalenEventViewContainer::AddDateFieldL
       
  1520 // Add a date field to the form.
       
  1521 // (other items were commented in a header).
       
  1522 // -----------------------------------------------------------------------------
       
  1523 //
       
  1524 void CCalenEventViewContainer::AddDateFieldL(TInt aHeadingResource, const TTime& aDate)
       
  1525     {
       
  1526     TRACE_ENTRY_POINT;
       
  1527     
       
  1528     HBufC* textHeading = StringLoader::LoadLC(aHeadingResource);
       
  1529     SetFormatAndAddHeadingL(*textHeading);
       
  1530     CleanupStack::PopAndDestroy(textHeading);
       
  1531     AddDateFieldL(aDate);
       
  1532 
       
  1533     TRACE_EXIT_POINT;
       
  1534     }
       
  1535 // -----------------------------------------------------------------------------
       
  1536 // CCalenEventViewContainer::AddDateFieldL
       
  1537 // Add a field to the form in the format "DATE - DATE".
       
  1538 // (other items were commented in a header).
       
  1539 // -----------------------------------------------------------------------------
       
  1540 //
       
  1541 void CCalenEventViewContainer::AddDateDateFieldL(const TTime& aStartDate, const TTime& aEndDate)
       
  1542     {
       
  1543     TRACE_ENTRY_POINT;
       
  1544 
       
  1545     CDesCArrayFlat* strings = new CDesCArrayFlat( 2 );
       
  1546     CleanupStack::PushL( strings );
       
  1547 
       
  1548     TBuf<KMaxDateLength> firstDate;
       
  1549     aStartDate.FormatL( firstDate, *iDateFormat );
       
  1550     AknTextUtils::DisplayTextLanguageSpecificNumberConversion(firstDate);
       
  1551     strings->AppendL( firstDate );
       
  1552 
       
  1553     TBuf<KMaxDateLength> secondDate;
       
  1554     aEndDate.FormatL( secondDate, *iDateFormat );
       
  1555     AknTextUtils::DisplayTextLanguageSpecificNumberConversion(secondDate);
       
  1556     strings->AppendL( secondDate );
       
  1557 
       
  1558     HBufC* stringholder = StringLoader::LoadL( R_QTN_CALE_EVENT_VIEW_VALID_LIMITED, *strings );
       
  1559     CleanupStack::PopAndDestroy( strings );
       
  1560     CleanupStack::PushL( stringholder );
       
  1561 
       
  1562     SetFormatAndAddBodyL(*stringholder);
       
  1563     CleanupStack::PopAndDestroy(stringholder);
       
  1564 
       
  1565     TRACE_EXIT_POINT;
       
  1566     }
       
  1567 
       
  1568 // -----------------------------------------------------------------------------
       
  1569 // CCalenEventViewContainer::AddAlarmDateAndTimeFieldL
       
  1570 // Add a date and time field to the form, in the ordering according to
       
  1571 // localisation (date followed by the time).
       
  1572 // (other items were commented in a header).
       
  1573 // -----------------------------------------------------------------------------
       
  1574 //
       
  1575 void CCalenEventViewContainer::AddAlarmDateAndTimeFieldL( const TTime& aTime )
       
  1576     {
       
  1577     TRACE_ENTRY_POINT;
       
  1578 
       
  1579     CDesCArrayFlat* strings = new CDesCArrayFlat( 2 );
       
  1580     CleanupStack::PushL( strings );
       
  1581 
       
  1582     TBuf<KMaxDateLength> formattedTime;
       
  1583     aTime.FormatL( formattedTime, *iTimeFormat );
       
  1584     AknTextUtils::DisplayTextLanguageSpecificNumberConversion(formattedTime);
       
  1585     strings->AppendL( formattedTime );
       
  1586 
       
  1587     TBuf<KMaxDateLength> formattedDate;
       
  1588     aTime.FormatL( formattedDate, *iDateFormat );
       
  1589     AknTextUtils::DisplayTextLanguageSpecificNumberConversion(formattedDate);
       
  1590     strings->AppendL( formattedDate );
       
  1591 
       
  1592     HBufC* stringholder = StringLoader::LoadL( R_QTN_CALE_EVENT_VIEW_ALARM_TIME, *strings );
       
  1593     CleanupStack::PopAndDestroy( strings );
       
  1594     CleanupStack::PushL( stringholder );
       
  1595 
       
  1596     AddTextFieldL( R_QTN_CALE_EVENT_VIEW_ALARM, *stringholder );
       
  1597     CleanupStack::PopAndDestroy( stringholder );
       
  1598 
       
  1599     TRACE_EXIT_POINT;
       
  1600     }
       
  1601 
       
  1602 // -----------------------------------------------------------------------------
       
  1603 // CCalenEventViewContainer::AddAlarmDateTimeFieldL
       
  1604 // Reads the alarm from the entry and add a field containing its date-time.
       
  1605 // If the alarm is on the same day as the entry, only the time is shown.
       
  1606 // If no alarm is present, the field is not shown
       
  1607 // (other items were commented in a header).
       
  1608 // -----------------------------------------------------------------------------
       
  1609 //
       
  1610 void CCalenEventViewContainer::AddAlarmDateTimeFieldL()
       
  1611     {
       
  1612     TRACE_ENTRY_POINT;
       
  1613     if( iEventViewData->IsAlarmActivated() )
       
  1614         {
       
  1615         TTime alarmTime = iEventViewData->AlarmDateTime();
       
  1616         alarmTime = CalenDateUtils::LimitToValidTime( alarmTime );
       
  1617 
       
  1618         // If alarm is on the same day as the entry, AND the meeting only lasts one day,
       
  1619         // just show the alarm time and not the date.
       
  1620         if( CalenDateUtils::OnSameDay( alarmTime, iEventViewData->StartDateTime() ) &&
       
  1621             CalenDateUtils::OnSameDay( iEventViewData->StartDateTime(), iEventViewData->EndDateTime() ) )
       
  1622             {
       
  1623             // On same day, only show time.
       
  1624             AddTimeFieldL( R_QTN_CALE_EVENT_VIEW_ALARM, alarmTime );
       
  1625             }
       
  1626         else
       
  1627             {
       
  1628             // Different days, show both date and time.
       
  1629             AddAlarmDateAndTimeFieldL( alarmTime );
       
  1630             }
       
  1631         }
       
  1632     TRACE_EXIT_POINT;
       
  1633     }
       
  1634 
       
  1635 // -----------------------------------------------------------------------------
       
  1636 // CCalenEventViewContainer::GetMinAndMaxTimesL
       
  1637 // Find the maximum and minimum times from the given array.
       
  1638 // (other items were commented in a header).
       
  1639 // -----------------------------------------------------------------------------
       
  1640 //
       
  1641 void CCalenEventViewContainer::GetMinAndMaxTimesL( RArray<TCalTime>& aTimes,
       
  1642                                                                TCalTime& aMinTime,
       
  1643                                                                TCalTime& aMaxTime )
       
  1644     {
       
  1645     TRACE_ENTRY_POINT;
       
  1646 
       
  1647     TInt minIndex=0;
       
  1648     TInt maxIndex=0;
       
  1649 
       
  1650     for( TInt i=1; i<aTimes.Count(); ++i )
       
  1651         {
       
  1652         if( aTimes[i].TimeUtcL() > aTimes[maxIndex].TimeUtcL() )
       
  1653             {
       
  1654             maxIndex = i;
       
  1655             }
       
  1656         else
       
  1657             {
       
  1658             if( aTimes[i].TimeUtcL() < aTimes[minIndex].TimeUtcL() )
       
  1659                 {
       
  1660                 minIndex = i;
       
  1661                 }
       
  1662             }
       
  1663         }
       
  1664 
       
  1665     aMinTime = aTimes[minIndex];
       
  1666     aMaxTime = aTimes[maxIndex];
       
  1667 
       
  1668     TRACE_EXIT_POINT;
       
  1669     }
       
  1670 // -----------------------------------------------------------------------------
       
  1671 // CCalenEventViewContainer::RemoveDuplicateTimesL
       
  1672 // If there is more than one time at the same time, leave only one in the array.
       
  1673 // (other items were commented in a header).
       
  1674 // -----------------------------------------------------------------------------
       
  1675 //
       
  1676 void CCalenEventViewContainer::RemoveDuplicateTimesL( RArray<TCalTime>& aTimes )
       
  1677     {
       
  1678     TRACE_ENTRY_POINT;
       
  1679 
       
  1680     for( TInt i=0; i<aTimes.Count(); ++i )
       
  1681         {
       
  1682         for( TInt j=aTimes.Count()-1; j>i; --j )
       
  1683             {
       
  1684             if( aTimes[i].TimeUtcL() == aTimes[j].TimeUtcL() )
       
  1685                 {
       
  1686                 aTimes.Remove( j );
       
  1687                 }
       
  1688             }
       
  1689         }
       
  1690 
       
  1691     TRACE_EXIT_POINT;
       
  1692     }
       
  1693 
       
  1694 // -----------------------------------------------------------------------------
       
  1695 // CCalenEventViewContainer::RemoveExcludedTimesL
       
  1696 // From the given array of start dates, remove any which match up with an
       
  1697 // exception date and also have no child associated with them.
       
  1698 // (other items were commented in a header).
       
  1699 // -----------------------------------------------------------------------------
       
  1700 //
       
  1701 void CCalenEventViewContainer::RemoveExcludedTimesL( RArray<TCalTime>& aStartDates,
       
  1702                                                                  RArray<TCalTime>& aExDates,
       
  1703                                                                  RPointerArray<CCalEntry>& aChildEntries )
       
  1704     {
       
  1705     TRACE_ENTRY_POINT;
       
  1706 
       
  1707     for( TInt i=0; i<aExDates.Count(); ++i )
       
  1708         {
       
  1709         for( TInt j=aStartDates.Count()-1; j>=0; --j )
       
  1710             {
       
  1711             if( aStartDates[j].TimeUtcL() == aExDates[i].TimeUtcL() )
       
  1712                 {
       
  1713                 TBool hasChild = EFalse;
       
  1714                 for( TInt k=0; k<aChildEntries.Count(); ++k )
       
  1715                     {
       
  1716                     if( aChildEntries[k]->RecurrenceIdL().TimeUtcL() == aStartDates[j].TimeUtcL() )
       
  1717                         {
       
  1718                         hasChild = ETrue;
       
  1719                         break;
       
  1720                         }
       
  1721                     }
       
  1722 
       
  1723                 if( !hasChild )
       
  1724                     {
       
  1725                     aStartDates.Remove( j );
       
  1726                     break;
       
  1727                     }
       
  1728                 }
       
  1729             }
       
  1730         }
       
  1731 
       
  1732     TRACE_EXIT_POINT;
       
  1733     }
       
  1734 
       
  1735 // ----------------------------------------------------
       
  1736 // CCalenEventViewContainer::CalendaryPriorityToFormPriority
       
  1737 // Convert replication to confidentiality
       
  1738 // (other items were commented in a header).
       
  1739 // ----------------------------------------------------
       
  1740 //
       
  1741 TInt CCalenEventViewContainer::CalendarPriorityToFormPriority(CCalenEntryUtil::TTodoPriority aCalPriority)
       
  1742     {
       
  1743     TRACE_ENTRY_POINT;
       
  1744     // Calendar priority is in same order as resource, starting from one number lower.
       
  1745     TRACE_EXIT_POINT;
       
  1746     return aCalPriority-1;
       
  1747     }
       
  1748 
       
  1749 // -----------------------------------------------------------------------------
       
  1750 // CCalenEventViewContainer::TryToFitL
       
  1751 // Returns ETrue if the given string fits into aMaxWidth, 
       
  1752 // using the font aFont - EFalse otherwise
       
  1753 // (other items were commented in a header).
       
  1754 // -----------------------------------------------------------------------------
       
  1755 //
       
  1756 TBool CCalenEventViewContainer::TryToFitL( const TDesC& aStr, TInt aMaxWidth, const CFont& aFont )
       
  1757     {
       
  1758     TRACE_ENTRY_POINT;
       
  1759 
       
  1760     TInt width = aFont.TextWidthInPixels(aStr);
       
  1761     // We add one because it seems the edwin wrapping doesn't quite agree with CFont's width.
       
  1762     ++width;
       
  1763 
       
  1764     TRACE_EXIT_POINT;
       
  1765     return width < aMaxWidth;
       
  1766     }
       
  1767 
       
  1768 // -----------------------------------------------------------------------------
       
  1769 // CCalenEventViewContainer::PixelsToTwips
       
  1770 // Convert pixels to twips
       
  1771 // (other items were commented in a header).
       
  1772 // -----------------------------------------------------------------------------
       
  1773 //
       
  1774 TInt CCalenEventViewContainer::PixelsToTwips(TInt aPixels)
       
  1775     {
       
  1776     TRACE_ENTRY_POINT;
       
  1777 
       
  1778     CWindowGc& windowGc = ControlEnv()->SystemGc();
       
  1779     TInt twips = windowGc.Device()->HorizontalPixelsToTwips(aPixels);
       
  1780 
       
  1781     TRACE_EXIT_POINT;
       
  1782     return twips;
       
  1783     }
       
  1784     
       
  1785 // -----------------------------------------------------------------------------
       
  1786 // CCalenEventViewContainer::GetSeriesRepeatInformationL
       
  1787 // Attempts to calculate the start and end dates of the series by looking at the
       
  1788 // given entry's RDates and RRule. If these dates have successfully been
       
  1789 // calculated, the function returns ETrue, or EFalse otherwise.
       
  1790 // (other items were commented in a header).
       
  1791 // -----------------------------------------------------------------------------
       
  1792 //
       
  1793 TBool CCalenEventViewContainer::GetSeriesRepeatInformationL( CCalEntry& aEntry,
       
  1794                                                      TCalenRepeatIndex& aRepeatIndex,
       
  1795                                                      TTime& aSeriesStart,
       
  1796                                                      TTime& aSeriesEnd )
       
  1797     {
       
  1798     TRACE_ENTRY_POINT;
       
  1799 
       
  1800     TBool success;
       
  1801 
       
  1802     RArray<TCalTime> rdates;
       
  1803     CleanupClosePushL( rdates );
       
  1804 
       
  1805     aEntry.GetRDatesL(rdates);
       
  1806 
       
  1807     if( rdates.Count() )
       
  1808         {
       
  1809         // Calculate the start and end dates from the RDates.
       
  1810 
       
  1811         // We need to expand the RDates. This involves getting all the instance start dates,
       
  1812         // then removing any start date with an exdate but no modifying child for that instance.
       
  1813         // Include the entry start date in this, as that counts as part of the series.
       
  1814         rdates.AppendL( aEntry.StartTimeL() );
       
  1815 
       
  1816         RemoveDuplicateTimesL( rdates );
       
  1817 
       
  1818         RArray<TCalTime> exdates;
       
  1819         CleanupClosePushL( exdates );
       
  1820         aEntry.GetExceptionDatesL( exdates );
       
  1821         if( exdates.Count() )
       
  1822             {
       
  1823             RemoveExcludedTimesL( rdates, exdates, AllInstancesL() );
       
  1824             }
       
  1825         CleanupStack::PopAndDestroy( &exdates );
       
  1826 
       
  1827         TCalRRule rrule;
       
  1828         if( iEntry->GetRRuleL(rrule) )
       
  1829             {
       
  1830             // Hopefully no UI would create an entry with an RRule as well as RDates.
       
  1831             // Although the spec says it's possible, Calendar certainly can't.
       
  1832             // We have a vague go at including the RRule in the min/max date but
       
  1833             // don't bother removing exdates from it as we would then need to expand
       
  1834             // every instance of the RRule.
       
  1835             rdates.AppendL( rrule.DtStart() );
       
  1836             rdates.AppendL( rrule.Until() );
       
  1837             RemoveDuplicateTimesL( rdates );
       
  1838             }
       
  1839 
       
  1840         // The true instance dates should be in the 'rdates' array. Now we just need
       
  1841         // the minimum and maximum times from here.
       
  1842         TCalTime min, max;
       
  1843         GetMinAndMaxTimesL( rdates, min, max );
       
  1844         aSeriesStart = min.TimeLocalL();
       
  1845         aSeriesEnd = max.TimeLocalL();
       
  1846 
       
  1847         // Set the repeat type to "Other" for rdates.
       
  1848         aRepeatIndex = ERepeatOther;
       
  1849         success = ETrue;
       
  1850         }
       
  1851     else
       
  1852         {
       
  1853         TCalRRule rrule;
       
  1854         if( aEntry.GetRRuleL( rrule ) )
       
  1855             {
       
  1856             // This 'switch' differs slightly from CalenNoteDataUtil::RepeatIndex in
       
  1857             // that we are a bit more generous in awarding repeat types instead of
       
  1858             // falling back to 'other' repeat type.
       
  1859             aRepeatIndex = ERepeatOther;
       
  1860             switch( rrule.Type() )
       
  1861                 {
       
  1862                 case TCalRRule::EDaily:
       
  1863                     {
       
  1864                     if( rrule.Interval() == 1 )
       
  1865                         {
       
  1866                         aRepeatIndex = ERepeatDaily;
       
  1867                         }
       
  1868                     else if( rrule.Interval() == 7 )
       
  1869                         {
       
  1870                         aRepeatIndex = ERepeatWeekly;
       
  1871                         }
       
  1872                     else if( rrule.Interval() == 14 )
       
  1873                         {
       
  1874                         aRepeatIndex = ERepeatBiWeekly;
       
  1875                         }
       
  1876                     else
       
  1877                         {
       
  1878                         // nothing
       
  1879                         }
       
  1880                     }
       
  1881                     break;
       
  1882 
       
  1883                 case TCalRRule::EWeekly:
       
  1884                     {
       
  1885                     TInt repeatInterval( rrule.Interval() );
       
  1886                     TBool status;
       
  1887                     status = CalenNoteDataUtil::IsWorkdaysRepeatingL( rrule );
       
  1888                     if(status)
       
  1889                         {
       
  1890                         aRepeatIndex = ERepeatWorkdays ;
       
  1891                         }
       
  1892                     else
       
  1893                         {
       
  1894                         switch( repeatInterval )
       
  1895                             {
       
  1896                             case 1: aRepeatIndex = ERepeatWeekly; 
       
  1897                                 break;
       
  1898                             case 2: aRepeatIndex = ERepeatBiWeekly;
       
  1899                                 break;
       
  1900                             default:break;
       
  1901                             }
       
  1902                        }
       
  1903                     }
       
  1904                     break;
       
  1905 
       
  1906                 case TCalRRule::EMonthly:
       
  1907                     {
       
  1908                     if( rrule.Interval() == 1 )
       
  1909                         {
       
  1910                         aRepeatIndex = ERepeatMonthly;
       
  1911                         }
       
  1912                     }
       
  1913                     break;
       
  1914                 
       
  1915                 case TCalRRule::EYearly:
       
  1916                     {
       
  1917                     if( rrule.Interval() == 1 )
       
  1918                         {
       
  1919                         aRepeatIndex = ERepeatYearly;
       
  1920                         }
       
  1921                     }
       
  1922                     break;
       
  1923                 default:
       
  1924                     break;
       
  1925                 }
       
  1926 
       
  1927             aSeriesStart = rrule.DtStart().TimeLocalL();
       
  1928             aSeriesEnd = rrule.Until().TimeLocalL();
       
  1929             success = ETrue;
       
  1930             }
       
  1931         else
       
  1932             {
       
  1933             // No repeat information.
       
  1934             success = EFalse;
       
  1935             }
       
  1936         }
       
  1937 
       
  1938     CleanupStack::PopAndDestroy( &rdates );
       
  1939 
       
  1940     return success;
       
  1941 
       
  1942     TRACE_EXIT_POINT;
       
  1943     }
       
  1944 
       
  1945 // -----------------------------------------------------------------------------
       
  1946 // CCalenEventViewContainer::AddRepeatFieldL
       
  1947 // Add repeat text field to the 
       
  1948 // (other items were commented in a header).
       
  1949 // -----------------------------------------------------------------------------
       
  1950 //
       
  1951 void CCalenEventViewContainer::AddRepeatFieldL()
       
  1952     {
       
  1953     TRACE_ENTRY_POINT;
       
  1954     // Get the repeat rule from the entry.  If this is a child entry,
       
  1955     // find the parent and get the repeat rule from that.
       
  1956     TCalRRule rrule;
       
  1957     TCalenRepeatIndex repeatIndex;
       
  1958     // 'start' is the start time of the series, not the start time of the instance we are viewing
       
  1959     TTime start;
       
  1960     TTime until;
       
  1961 
       
  1962     if( !GetSeriesRepeatInformationL( *iEntry, repeatIndex, start, until ) )
       
  1963         {
       
  1964         // An entry with no RDates or RRule but a non-null recurrence id.
       
  1965         // This entry is a child. We have to get the parent to see the repeat information.
       
  1966         // We assert here - a parent really should have some form of repeat information.
       
  1967         __ASSERT_ALWAYS( GetSeriesRepeatInformationL( ParentEntryL(), repeatIndex, start, until ),
       
  1968                          User::Invariant() );
       
  1969         }
       
  1970 
       
  1971     // Set repIndex to be the resource used for the heading.
       
  1972     // This will be "Repeats daily", "Repeats weekly" etc.
       
  1973     TInt repIndex = -1;
       
  1974 
       
  1975     switch(repeatIndex)
       
  1976         {
       
  1977         case ERepeatDaily:
       
  1978             repIndex = R_QTN_CALE_EVENT_VIEW_REPEAT_DAILY;
       
  1979             break;
       
  1980         case ERepeatWeekly:
       
  1981             repIndex = R_QTN_CALE_EVENT_VIEW_REPEAT_WEEKLY;
       
  1982             break;
       
  1983         case ERepeatBiWeekly:
       
  1984             repIndex = R_QTN_CALE_EVENT_VIEW_REPEAT_FORTNIGHTLY;
       
  1985             break;
       
  1986         case ERepeatMonthly:
       
  1987             repIndex = R_QTN_CALE_EVENT_VIEW_REPEAT_MONTHLY;
       
  1988             break;
       
  1989         case ERepeatYearly:
       
  1990             repIndex = R_QTN_CALE_EVENT_VIEW_REPEAT_YEARLY;
       
  1991             break;
       
  1992         case ERepeatWorkdays:
       
  1993             repIndex = R_QTN_CALE_EVENT_VIEW_REPEAT_WORKDAYS;
       
  1994             break;
       
  1995         case ERepeatOther:
       
  1996             repIndex = R_QTN_CALE_EVENT_VIEW_REPEAT_OTHER;
       
  1997             break;
       
  1998         default:
       
  1999             ASSERT(EFalse);
       
  2000             break;
       
  2001         }
       
  2002 
       
  2003     TBuf<64> dateString;
       
  2004 
       
  2005     // Infinite repeat if repeat until is on or after the max time, or if repeat until is null.
       
  2006     TBool finiteRepeat = until < CalenDateUtils::BeginningOfDay( CalenDateUtils::MaxTime() )
       
  2007                          && until != Time::NullTTime();
       
  2008 
       
  2009     if( finiteRepeat )
       
  2010         {
       
  2011         // Finite repeat, string (e.g.) "17/01/2006 - 27/01/2006"
       
  2012         CDesCArrayFlat* strings = new CDesCArrayFlat( 2 );
       
  2013         CleanupStack::PushL( strings );
       
  2014 
       
  2015         TBuf<KMaxDateLength> formattedTime;
       
  2016         start.FormatL( formattedTime, *iDateFormat );
       
  2017         AknTextUtils::DisplayTextLanguageSpecificNumberConversion(formattedTime);
       
  2018         strings->AppendL( formattedTime );
       
  2019 
       
  2020         TBuf<KMaxDateLength> formattedDate;
       
  2021         until.FormatL( formattedDate, *iDateFormat );
       
  2022         AknTextUtils::DisplayTextLanguageSpecificNumberConversion(formattedDate);
       
  2023         strings->AppendL( formattedDate );
       
  2024 
       
  2025         HBufC* stringholder = StringLoader::LoadL( R_QTN_CALE_EVENT_VIEW_VALID_LIMITED, *strings );
       
  2026         CleanupStack::PopAndDestroy( strings );
       
  2027         CleanupStack::PushL( stringholder );
       
  2028 
       
  2029         AddTextFieldL( repIndex, *stringholder );
       
  2030         CleanupStack::PopAndDestroy( stringholder );
       
  2031         }
       
  2032     else
       
  2033         {
       
  2034         // Repeats forever, string (e.g.) "From 17/01/2006"
       
  2035         CDesCArrayFlat* strings = new CDesCArrayFlat( 1 );
       
  2036         CleanupStack::PushL( strings );
       
  2037 
       
  2038         TBuf<KMaxDateLength> formattedTime;
       
  2039         start.FormatL( formattedTime, *iDateFormat );
       
  2040         AknTextUtils::DisplayTextLanguageSpecificNumberConversion(formattedTime);
       
  2041         strings->AppendL( formattedTime );
       
  2042 
       
  2043         HBufC* stringholder = StringLoader::LoadL( R_QTN_CALE_EVENT_VIEW_VALID_FOREVER, *strings );
       
  2044         CleanupStack::PopAndDestroy( strings );
       
  2045         CleanupStack::PushL( stringholder );
       
  2046 
       
  2047         AddTextFieldL( repIndex, *stringholder );
       
  2048         CleanupStack::PopAndDestroy( stringholder );
       
  2049         }
       
  2050 
       
  2051     TRACE_EXIT_POINT;
       
  2052     }
       
  2053 
       
  2054 // -----------------------------------------------------------------------------
       
  2055 // CCalenEventViewContainer::AddTimeFieldL
       
  2056 // Add entry time field text to the 
       
  2057 // (other items were commented in a header).
       
  2058 // -----------------------------------------------------------------------------
       
  2059 //
       
  2060 void CCalenEventViewContainer::AddTimeFieldL()
       
  2061     {
       
  2062     TRACE_ENTRY_POINT;
       
  2063     
       
  2064     // If the start time is on the same day as the end time, just show the date.
       
  2065     // Otherwise, show "start date - end date".
       
  2066     TTime startTime = iEventViewData->StartDateTime();
       
  2067     TTime endTime = iEventViewData->EndDateTime();
       
  2068     iTimeFieldLines = 1; // Increment the value to be considered while drawing the map icon
       
  2069     TBuf<64> concatString;
       
  2070 
       
  2071     if( CalenDateUtils::OnSameDay(startTime, endTime) )
       
  2072         {
       
  2073         // String looks like (e.g.) "14:00 - 16:00 17/01/2006"
       
  2074         CDesCArrayFlat* strings = new CDesCArrayFlat( 3 );
       
  2075         CleanupStack::PushL( strings );
       
  2076 
       
  2077         TBuf<KMaxDateLength> formattedStartTime;
       
  2078         startTime.FormatL( formattedStartTime, *iTimeFormat );
       
  2079         AknTextUtils::DisplayTextLanguageSpecificNumberConversion(formattedStartTime);
       
  2080         strings->AppendL( formattedStartTime );
       
  2081 
       
  2082         TBuf<KMaxDateLength> formattedEndTime;
       
  2083         endTime.FormatL( formattedEndTime, *iTimeFormat );
       
  2084         AknTextUtils::DisplayTextLanguageSpecificNumberConversion(formattedEndTime);
       
  2085         strings->AppendL( formattedEndTime );
       
  2086 
       
  2087         TBuf<KMaxDateLength> formattedStartDate;
       
  2088         startTime.FormatL( formattedStartDate, *iDateFormat );
       
  2089         AknTextUtils::DisplayTextLanguageSpecificNumberConversion(formattedStartDate);
       
  2090         strings->AppendL( formattedStartDate );
       
  2091 
       
  2092         HBufC* stringholder = StringLoader::LoadLC( R_QTN_CALE_EVENT_VIEW_TIME_DAY, *strings );
       
  2093 
       
  2094         TBool fits = TryToFitL(*stringholder, iMaxWidth, *iBodyFont);
       
  2095         if (fits)
       
  2096             {
       
  2097             SetFormatAndAddBodyL(*stringholder);
       
  2098             }
       
  2099         else
       
  2100             {
       
  2101             iTimeFieldLines++; // Increment the value to be considered while drawing the map icon
       
  2102             HBufC* wrappedStringholder = StringLoader::LoadLC( R_QTN_CALE_EVENT_VIEW_TIME_DAY_WRAPPED, *strings );
       
  2103             SetFormatAndAddBodyL(*wrappedStringholder);
       
  2104             CleanupStack::PopAndDestroy(wrappedStringholder);
       
  2105             }
       
  2106 
       
  2107         CleanupStack::PopAndDestroy( stringholder );
       
  2108         CleanupStack::PopAndDestroy( strings );
       
  2109         }
       
  2110     else
       
  2111         {
       
  2112         // String looks like (e.g.) "14:00 16/01/2006 - 16:00 19/01/2006"
       
  2113         CDesCArrayFlat* strings = new CDesCArrayFlat( 3 );
       
  2114         CleanupStack::PushL( strings );
       
  2115 
       
  2116         TBuf<KMaxDateLength> formattedStartTime;
       
  2117         startTime.FormatL( formattedStartTime, *iTimeFormat );
       
  2118         AknTextUtils::DisplayTextLanguageSpecificNumberConversion(formattedStartTime);
       
  2119         strings->AppendL( formattedStartTime );
       
  2120 
       
  2121         TBuf<KMaxDateLength> formattedStartDate;
       
  2122         startTime.FormatL( formattedStartDate, *iDateFormat );
       
  2123         AknTextUtils::DisplayTextLanguageSpecificNumberConversion(formattedStartDate);
       
  2124         strings->AppendL( formattedStartDate );
       
  2125 
       
  2126         TBuf<KMaxDateLength> formattedEndTime;
       
  2127         endTime.FormatL( formattedEndTime, *iTimeFormat );
       
  2128         AknTextUtils::DisplayTextLanguageSpecificNumberConversion(formattedEndTime);
       
  2129         strings->AppendL( formattedEndTime );
       
  2130 
       
  2131         TBuf<KMaxDateLength> formattedEndDate;
       
  2132         endTime.FormatL( formattedEndDate, *iDateFormat );
       
  2133         AknTextUtils::DisplayTextLanguageSpecificNumberConversion(formattedEndDate);
       
  2134         strings->AppendL( formattedEndDate );
       
  2135 
       
  2136         HBufC* stringholder = StringLoader::LoadLC( R_QTN_CALE_EVENT_VIEW_TIME_DAYS, *strings );
       
  2137 
       
  2138         TBool fits = TryToFitL(*stringholder, iMaxWidth, *iBodyFont);
       
  2139         if (fits)
       
  2140             {
       
  2141             SetFormatAndAddBodyL(*stringholder);
       
  2142             }
       
  2143         else
       
  2144             {
       
  2145             iTimeFieldLines++;
       
  2146             HBufC* wrappedStringholder = StringLoader::LoadLC( R_QTN_CALE_EVENT_VIEW_TIME_DAYS_WRAPPED, *strings );
       
  2147             SetFormatAndAddBodyL(*wrappedStringholder);
       
  2148             CleanupStack::PopAndDestroy(wrappedStringholder);
       
  2149             }
       
  2150 
       
  2151         CleanupStack::PopAndDestroy( stringholder );
       
  2152         CleanupStack::PopAndDestroy( strings );
       
  2153         }
       
  2154 
       
  2155     TRACE_EXIT_POINT;
       
  2156     }
       
  2157 
       
  2158 // -----------------------------------------------------------------------------
       
  2159 // CCalenEventViewContainer::MopSupplyObject
       
  2160 // Pass the skin information
       
  2161 // (other items were commented in a header).
       
  2162 // -----------------------------------------------------------------------------
       
  2163 //
       
  2164 TTypeUid::Ptr CCalenEventViewContainer::MopSupplyObject( TTypeUid aId )
       
  2165     {
       
  2166     return MAknsControlContext::SupplyMopObject( aId, iBgContext );
       
  2167     }    
       
  2168 
       
  2169 
       
  2170 // -----------------------------------------------------------------------------
       
  2171 // CCalenEventViewContainer::BuildSearchBufferL
       
  2172 // Generate the text string to use for text searches
       
  2173 // (other items were commented in a header).
       
  2174 // -----------------------------------------------------------------------------
       
  2175 //
       
  2176 void CCalenEventViewContainer::BuildSearchBufferL()
       
  2177     {
       
  2178     TRACE_ENTRY_POINT;
       
  2179 
       
  2180     // Get the full text from the form to use for search API.
       
  2181     TInt textLength = iTextEditor->RichText()->DocumentLength();
       
  2182 
       
  2183     // Delete any existing search buffer
       
  2184     if (iSearchBuf)
       
  2185         {
       
  2186         delete iSearchBuf;
       
  2187         iSearchBuf = NULL;
       
  2188         }
       
  2189 
       
  2190     // Text searched is currently summary , location and description
       
  2191     iSearchBuf = HBufC::NewL(textLength);
       
  2192     TPtr searchPtr = iSearchBuf->Des();
       
  2193     GetTextFieldsFromFormL(searchPtr);
       
  2194 
       
  2195     TRACE_EXIT_POINT;
       
  2196     } 
       
  2197 
       
  2198 // -----------------------------------------------------------------------------
       
  2199 // CCalenEventViewContainer::GetTextFieldsFromFormL
       
  2200 // Gets the text fields from the form into a descriptor for
       
  2201 // the find api to use.
       
  2202 // Currently uses subject, location and description only
       
  2203 // (other items were commented in a header).
       
  2204 // -----------------------------------------------------------------------------
       
  2205 //
       
  2206 void CCalenEventViewContainer::GetTextFieldsFromFormL(TDes& aDesc)
       
  2207     {
       
  2208     TRACE_ENTRY_POINT;
       
  2209 
       
  2210     aDesc.Append(iEventViewData->Summary());
       
  2211     aDesc.Append(_L(" \r\n"));
       
  2212     aDesc.Append(iEventViewData->Location());
       
  2213     aDesc.Append(_L(" \r\n"));
       
  2214     aDesc.Append(iEventViewData->Description());
       
  2215     aDesc.Append(_L(" \r\n"));
       
  2216 
       
  2217     TRACE_EXIT_POINT;
       
  2218     }
       
  2219 
       
  2220 // -----------------------------------------------------------------------------
       
  2221 // CCalenEventViewContainer::GetTitleTextId
       
  2222 // Gets the title text resource
       
  2223 // -----------------------------------------------------------------------------
       
  2224 //
       
  2225 TInt CCalenEventViewContainer::GetTitleTextId()
       
  2226 	{
       
  2227 	TRACE_ENTRY_POINT;
       
  2228 	TRACE_EXIT_POINT;
       
  2229 	return iTitleTextId;
       
  2230 	}
       
  2231 	
       
  2232 // -----------------------------------------------------------------------------
       
  2233 // CCalenEventViewContainer::ParentEntryL
       
  2234 // Returns the parent entry of the entry being edited.
       
  2235 // (other items were commented in a header).
       
  2236 // -----------------------------------------------------------------------------
       
  2237 //
       
  2238 CCalEntry& CCalenEventViewContainer::ParentEntryL()
       
  2239     {
       
  2240     TRACE_ENTRY_POINT;
       
  2241     MCalenContext& context = iServices.Context();
       
  2242 
       
  2243     if(iFetchedEntries.Count() == 0)
       
  2244         {
       
  2245         iServices.EntryViewL(context.InstanceId().iColId)->FetchL( iEntry->UidL(), iFetchedEntries );
       
  2246         }
       
  2247     __ASSERT_ALWAYS( iFetchedEntries.Count() > 0, User::Panic(_L("CCalenEventViewContainer::ParentEntryL"),EPanicArrayOfSizeZero));
       
  2248 
       
  2249     TRACE_EXIT_POINT;
       
  2250     return *iFetchedEntries[0];
       
  2251     }
       
  2252 
       
  2253 // -----------------------------------------------------------------------------
       
  2254 // CCalenEventViewContainer::AllInstancesL
       
  2255 // Returns all the instances associated with the entry being edited.
       
  2256 // (other items were commented in a header).
       
  2257 // -----------------------------------------------------------------------------
       
  2258 //
       
  2259 RPointerArray<CCalEntry>& CCalenEventViewContainer::AllInstancesL()
       
  2260     {
       
  2261     TRACE_ENTRY_POINT;
       
  2262     MCalenContext& context = iServices.Context();
       
  2263 
       
  2264     if(iFetchedEntries.Count() == 0)
       
  2265         {
       
  2266         iServices.EntryViewL(context.InstanceId().iColId)->FetchL( iEntry->UidL(), iFetchedEntries );
       
  2267         }
       
  2268 
       
  2269     TRACE_EXIT_POINT;
       
  2270     return iFetchedEntries;
       
  2271     }
       
  2272 
       
  2273 // -----------------------------------------------------------------------------
       
  2274 // CCalenEventViewContainer::GetEventViewData
       
  2275 // Gets the Event View Data
       
  2276 // -----------------------------------------------------------------------------
       
  2277 //	
       
  2278 CCalenEntryUtil* CCalenEventViewContainer::GetEventViewData()
       
  2279 	{
       
  2280 	TRACE_ENTRY_POINT;
       
  2281 	TRACE_EXIT_POINT;
       
  2282 	return iEventViewData;	
       
  2283 	}
       
  2284 
       
  2285 
       
  2286 // -----------------------------------------------------------------------------
       
  2287 // CCalenEventViewContainer::HandleNotifyError
       
  2288 // From MCenRepNotifyHandlerCallback
       
  2289 // -----------------------------------------------------------------------------
       
  2290 //	
       
  2291 void CCalenEventViewContainer::HandleNotifyError( TUint32 /*aId*/,TInt /*aError*/,
       
  2292 												CCenRepNotifyHandler* /*aHandler*/ )
       
  2293 	{
       
  2294 	TRACE_ENTRY_POINT;
       
  2295 	
       
  2296 	if( iNotifier )
       
  2297         {
       
  2298         iNotifier->StopListening();       
       
  2299         delete iNotifier;
       
  2300         iNotifier = NULL;
       
  2301         }
       
  2302         
       
  2303     delete iCenRepSession;    
       
  2304     iCenRepSession = NULL;
       
  2305 	
       
  2306 	TRACE_EXIT_POINT;
       
  2307 	}
       
  2308 
       
  2309 
       
  2310 
       
  2311 
       
  2312 // -----------------------------------------------------------------------------
       
  2313 // CCalenEventViewContainer::GetFindItemMenu
       
  2314 // -----------------------------------------------------------------------------
       
  2315 //
       
  2316 CFindItemMenu* CCalenEventViewContainer::GetFindItemMenu()
       
  2317 	{
       
  2318 	TRACE_ENTRY_POINT;
       
  2319 	TRACE_EXIT_POINT;
       
  2320 	
       
  2321 	return iFindMenu;
       
  2322 	}
       
  2323 
       
  2324 // -----------------------------------------------------------------------------
       
  2325 //  CCalenEventViewContainer::HandleScrollEventL
       
  2326 //  Handles scroll events
       
  2327 // -----------------------------------------------------------------------------
       
  2328 //   
       
  2329 void CCalenEventViewContainer::HandleScrollEventL(CEikScrollBar* aScrollBar, 
       
  2330                                           TEikScrollEvent aEventType)
       
  2331     {
       
  2332     TRACE_ENTRY_POINT;
       
  2333 
       
  2334     iTextEditor->HandleScrollEventL(aScrollBar,aEventType);
       
  2335     
       
  2336     TRACE_EXIT_POINT;    
       
  2337     } 
       
  2338 	
       
  2339 // -----------------------------------------------------------------------------
       
  2340 //  CCalenEventViewContainer::HandleStopCommandL
       
  2341 //  Handles scroll events
       
  2342 // -----------------------------------------------------------------------------
       
  2343 //   
       
  2344 void CCalenEventViewContainer::HandleStopCommandL()
       
  2345     {
       
  2346     TRACE_ENTRY_POINT;
       
  2347 
       
  2348     CCalenEventView* eventView = static_cast<CCalenEventView*>( iView );
       
  2349     
       
  2350    eventView->HandleCommandL( ECalenStopAlarm );
       
  2351     
       
  2352     TRACE_EXIT_POINT;    
       
  2353     } 
       
  2354 
       
  2355 // ----------------------------------------------------------------------------
       
  2356 // CCalenEventViewContainer::IsEventHasMapLocationOrNoLocationTextL
       
  2357 // Stores the necessary information in the context
       
  2358 // and returns ETrue if event has geo coordinates else EFalse
       
  2359 // ----------------------------------------------------------------------------
       
  2360 TBool CCalenEventViewContainer::IsEventHasMapLocationL()
       
  2361 	{
       
  2362     if(iEntry)
       
  2363         {
       
  2364         CCalGeoValue* geoValue = iEntry->GeoValueL();
       
  2365         if(geoValue)
       
  2366             {
       
  2367             delete geoValue; 
       
  2368             return 	ETrue;
       
  2369             }
       
  2370         else
       
  2371             {
       
  2372             return 	EFalse;
       
  2373             }
       
  2374         }
       
  2375     else
       
  2376         {
       
  2377         return EFalse;
       
  2378         }
       
  2379 	}
       
  2380 
       
  2381 // ----------------------------------------------------------------------------
       
  2382 // CCalenEventViewContainer::IsEventHasNoLocationTextL
       
  2383 // Returns ETrue if event has location text else EFalse
       
  2384 // ----------------------------------------------------------------------------
       
  2385 TBool CCalenEventViewContainer::IsEventHasNoLocationTextL()
       
  2386 	{
       
  2387     if(iEntry)
       
  2388         {
       
  2389         TPtrC location = iEntry->LocationL();
       
  2390         if(!location.Length())
       
  2391             {
       
  2392             return ETrue;
       
  2393             }
       
  2394         else
       
  2395             {
       
  2396             return EFalse;
       
  2397             }
       
  2398         }
       
  2399     else
       
  2400         {
       
  2401         return EFalse;
       
  2402         }
       
  2403 	}
       
  2404 	
       
  2405 // ----------------------------------------------------------------------------
       
  2406 // CCalenEventView::OnLocaleChangedL
       
  2407 // (other items were commented in a header).
       
  2408 // ----------------------------------------------------------------------------
       
  2409 //
       
  2410 void CCalenEventViewContainer::HandleLocaleChangedL(/* TInt aReason */)
       
  2411     {
       
  2412     TRACE_ENTRY_POINT;
       
  2413 
       
  2414     iLocaleChanged = ETrue;
       
  2415 
       
  2416     TRACE_EXIT_POINT;
       
  2417     }	
       
  2418 
       
  2419 // -----------------------------------------------------------------------------
       
  2420 // CCalenEventViewContainer::AddCalendarInfoFieldL
       
  2421 // Adds calendar info field to the viewer
       
  2422 // -----------------------------------------------------------------------------
       
  2423 //
       
  2424 void CCalenEventViewContainer::AddCalendarInfoFieldL()
       
  2425     {
       
  2426     TRACE_ENTRY_POINT;
       
  2427     TCalCollectionId colId = iServices.Context().InstanceId().iColId;
       
  2428     
       
  2429     RPointerArray<CCalCalendarInfo> calendarInfoList;
       
  2430     iServices.GetAllCalendarInfoL(calendarInfoList);
       
  2431     CleanupClosePushL(calendarInfoList);
       
  2432     
       
  2433     HBufC* calendarFileName = iServices.GetCalFileNameForCollectionId(colId).AllocLC();
       
  2434     TInt index = calendarInfoList.Find( *calendarFileName, 
       
  2435             CCalenEventViewContainer::CalendarInfoIdentifierL);
       
  2436     CleanupStack::PopAndDestroy(calendarFileName);
       
  2437     if(index != KErrNotFound)
       
  2438         {
       
  2439         // add the calendar info's text field
       
  2440         AddTextFieldL(
       
  2441                 R_CALE_VIEWER_CALENDAR_INFO, calendarInfoList[index]->NameL());
       
  2442         }
       
  2443     CleanupStack::PopAndDestroy(&calendarInfoList);
       
  2444     TRACE_EXIT_POINT;
       
  2445     }
       
  2446 
       
  2447 // -----------------------------------------------------------------------------
       
  2448 // CCalenEventViewContainer::CalendarInfoIdentifierL
       
  2449 // Searches for the index in calendar info list based on calendar file name
       
  2450 // -----------------------------------------------------------------------------
       
  2451 //
       
  2452 TBool CCalenEventViewContainer::CalendarInfoIdentifierL( const HBufC* aName,
       
  2453                                         const CCalCalendarInfo& aCalendarInfo)
       
  2454     {
       
  2455     TRACE_ENTRY_POINT;
       
  2456     TBool retVal = EFalse;
       
  2457     HBufC* calendarFileName = aCalendarInfo.FileNameL().AllocLC();
       
  2458     retVal = calendarFileName->CompareF(*aName);
       
  2459     CleanupStack::PopAndDestroy(calendarFileName);          
       
  2460     TRACE_EXIT_POINT;
       
  2461     return (!retVal);
       
  2462     }
       
  2463 
       
  2464 // ----------------------------------------------------------------------------
       
  2465 // ----------------------------------------------------------------------------
       
  2466 // CCalenEventViewContainer::AddAttachmentFieldL
       
  2467 // Adds attachment field
       
  2468 // ----------------------------------------------------------------------------
       
  2469 //
       
  2470 void CCalenEventViewContainer::AddAttachmentFieldL()
       
  2471     {
       
  2472     TRACE_ENTRY_POINT;
       
  2473     
       
  2474     // format and add heading "Attachment:"
       
  2475     HBufC* textHeading = StringLoader::LoadLC(R_CALE_EVENT_VIEW_ATTACHMENT_INFO);
       
  2476     SetFormatAndAddHeadingL(*textHeading);
       
  2477     CleanupStack::PopAndDestroy(textHeading);
       
  2478     
       
  2479     
       
  2480     
       
  2481     RPointerArray<HBufC> attachmentNames;
       
  2482     
       
  2483     iEventViewData->AttachmentNamesL(attachmentNames);
       
  2484     TInt attachmentsCount = attachmentNames.Count();
       
  2485     
       
  2486     //Reset the attachment posiitons array before addign them
       
  2487     iAttachmentPosInfoArray.Reset();
       
  2488     
       
  2489     for(TInt i = 0; i < attachmentsCount; i++)
       
  2490         {
       
  2491          AddAttachmentNameL(*attachmentNames[i]);
       
  2492         }
       
  2493     // Add in a paragraph delimeter character
       
  2494     // Without this, long descriptions get cut off half way down the last line.
       
  2495     CRichText* richText = iTextEditor->RichText();
       
  2496     richText->InsertL(richText->DocumentLength(), CEditableText::EParagraphDelimiter);
       
  2497     attachmentNames.ResetAndDestroy();
       
  2498     
       
  2499     TRACE_EXIT_POINT;
       
  2500     }
       
  2501 
       
  2502 // -----------------------------------------------------------------------------
       
  2503 // CCalenEventViewContainer::AddFormattedTextL
       
  2504 // Add a string to the view.
       
  2505 // (other items were commented in a header).
       
  2506 // -----------------------------------------------------------------------------
       
  2507 //
       
  2508 void CCalenEventViewContainer::AddAttachmentNameL(const TDesC& aText)
       
  2509     {
       
  2510     TRACE_ENTRY_POINT;
       
  2511     
       
  2512     // Set the charatcer formats and paragraph formats
       
  2513     iCharFormatMask.ClearAll();
       
  2514     iParaFormat->iLeftMarginInTwips = iBodyIndent;
       
  2515     iCharFormat.iFontSpec = iBodyFontSpec;
       
  2516     iCharFormat.iFontPresentation.iUnderline = EUnderlineOn;
       
  2517     iCharFormatMask.SetAttrib(EAttFontUnderline);
       
  2518     iCharFormatMask.SetAttrib(EAttFontHeight);
       
  2519     iCharFormatMask.SetAttrib(EAttFontTypeface) ;
       
  2520     iCharFormatMask.SetAttrib(EAttFontStrokeWeight);
       
  2521     
       
  2522     // Add the text into the richtext document
       
  2523     CRichText* richText = iTextEditor->RichText();
       
  2524     TInt startPos = richText->DocumentLength();
       
  2525     HBufC* text = HBufC::NewLC( aText.Length() + 10);
       
  2526     TPtr target = text->Des();
       
  2527     if(AknLayoutUtils::LayoutMirrored())
       
  2528         {
       
  2529         target.Append(KArabicSummaryMarker);    
       
  2530         }
       
  2531     else
       
  2532         {
       
  2533         target.Append(KWesternSummaryMarker);
       
  2534         }
       
  2535     target.Append(aText);
       
  2536     target.Append(KAttachmentSeparator); // Append the attachment seperator
       
  2537     TTextPos posInfo;
       
  2538     posInfo.iDocStart = richText->DocumentLength();
       
  2539     richText->InsertL(startPos, target);
       
  2540     posInfo.iDocEnd = richText->DocumentLength();
       
  2541     iAttachmentPosInfoArray.Append(posInfo);
       
  2542     TInt endPos = richText->DocumentLength();
       
  2543     richText->ApplyCharFormatL(iCharFormat, iCharFormatMask, startPos, (endPos - startPos - 1));
       
  2544     ++startPos;  // Without this the previous paragraph is formatted as well, ie no indent
       
  2545     richText->ApplyParaFormatL(iParaFormat, iParaFormatMask, startPos, (endPos - startPos - 1));
       
  2546     CleanupStack::PopAndDestroy(text);
       
  2547 	
       
  2548     TRACE_EXIT_POINT;
       
  2549     }
       
  2550 	
       
  2551 	// ----------------------------------------------------------------------------
       
  2552 // CCalenEventViewContainer::OpenViewerL()
       
  2553 // Opens the attachment in the Viewer
       
  2554 // ----------------------------------------------------------------------------
       
  2555 //
       
  2556 void CCalenEventViewContainer::OpenViewerL(TInt attachmentToBeOpened)
       
  2557     {
       
  2558     // Update the Attahcment model with the attahcments of the current entry
       
  2559     iServices.GetAttachmentData()->CheckForExistingAttachmentsL(iEntry);
       
  2560     
       
  2561     // Get the file handler
       
  2562     RFile file = iServices.GetAttachmentData()->GetAttachmentFileL( attachmentToBeOpened );
       
  2563     CleanupClosePushL(file);
       
  2564     // Hide the toolbar before opening the attachment
       
  2565     MCalenToolbar* toolbar = iServices.ToolbarOrNull();
       
  2566     if(toolbar && toolbar->IsVisible())
       
  2567         {
       
  2568         toolbar->SetToolbarVisibilityL(EFalse);
       
  2569         }
       
  2570     
       
  2571     CCalenEventView* eventView = static_cast<CCalenEventView*>( iView );
       
  2572     eventView->HideNaviPane();
       
  2573     //open the attachment
       
  2574     OpenAttachmentViewerL(file, *this);
       
  2575     if(!iEmbeddedFileOpened)
       
  2576         {
       
  2577         eventView->RedrawStatusPaneL();
       
  2578         }
       
  2579     CleanupStack::PopAndDestroy(&file);
       
  2580 
       
  2581     
       
  2582     // Unhide the toolbar after coming back
       
  2583     if(toolbar)
       
  2584         {
       
  2585         toolbar->SetToolbarVisibilityL(ETrue);
       
  2586         }
       
  2587     }
       
  2588 
       
  2589 // ----------------------------------------------------------------------------
       
  2590 // CCalenEventViewContainer::HandleServerAppExit
       
  2591 // (other items were commented in a header).
       
  2592 // ----------------------------------------------------------------------------
       
  2593 //
       
  2594 void CCalenEventViewContainer::HandleServerAppExit( TInt aReason)
       
  2595     {
       
  2596     TRACE_ENTRY_POINT;
       
  2597     
       
  2598     iEmbeddedFileOpened = EFalse;
       
  2599     iServices.GetAttachmentData()->AttachmentOpen(iEmbeddedFileOpened);  
       
  2600     if (aReason == EAknCmdExit)
       
  2601         {
       
  2602         //issue this notification, which will be handled by attachmentui.
       
  2603         }
       
  2604     
       
  2605     TRACE_EXIT_POINT;
       
  2606     }
       
  2607 
       
  2608 // ----------------------------------------------------------------------------
       
  2609 // CCalenEventViewContainer::CheckAndOpenTappedAttachment
       
  2610 // Checks if it is tapped on any attachment, if yes, then opens that attachment
       
  2611 // (other items were commented in a header).
       
  2612 // ----------------------------------------------------------------------------
       
  2613 //
       
  2614 void CCalenEventViewContainer::CheckAndOpenTappedAttachmentL(TTmPosInfo2* posInfo)
       
  2615     {
       
  2616     // iterate through iAttachmentPosInfoArray to see if posInfo falls in any of the range
       
  2617     TInt attachmentToBeOpened = -1;
       
  2618     for(TInt i = 0; i < iAttachmentPosInfoArray.Count(); i++)
       
  2619         {
       
  2620         if( (posInfo->iDocPos.iPos >= iAttachmentPosInfoArray[i].iDocStart) && ( posInfo->iDocPos.iPos < iAttachmentPosInfoArray[i].iDocEnd  ))
       
  2621             {
       
  2622             attachmentToBeOpened = i;
       
  2623             break;
       
  2624             }
       
  2625         }
       
  2626     if(attachmentToBeOpened != -1)
       
  2627         {
       
  2628         OpenViewerL(attachmentToBeOpened);
       
  2629         }
       
  2630     }
       
  2631 
       
  2632 // -----------------------------------------------------------------------------
       
  2633 // CCalenCommonUI::FindPossibleInstanceL
       
  2634 // Finds an instance with the given instance id and instance view.
       
  2635 // (other items were commented in a header).
       
  2636 // -----------------------------------------------------------------------------
       
  2637 //
       
  2638 CCalInstance* CCalenEventViewContainer::FindPossibleInstanceL(
       
  2639                                                                 const TCalenInstanceId& aId,
       
  2640                                                                 CCalInstanceView& aInstanceView )
       
  2641     {
       
  2642     TRACE_ENTRY_POINT;
       
  2643 
       
  2644     RPointerArray<CCalInstance> instances;
       
  2645     CleanupResetAndDestroyPushL( instances );
       
  2646 
       
  2647     //If timezone is changed we need to read the latest instance time
       
  2648     //SO we are reading all the instances in the timerange of past 24 hrs ans next 24 hrs minus
       
  2649     //a minute so that instanceid shouldnt match with daily repeat meeting
       
  2650     TCalTime momentStart, momentEnd;
       
  2651     momentStart.SetTimeLocalL( (aId.iInstanceTime - TTimeIntervalDays(1)) + TTimeIntervalMinutes(1));
       
  2652     momentEnd.SetTimeLocalL( (aId.iInstanceTime + TTimeIntervalDays(1)) - TTimeIntervalMinutes(1));
       
  2653     CalCommon::TCalTimeRange range( momentStart, momentEnd );
       
  2654     aInstanceView.FindInstanceL( instances, CalCommon::EIncludeAll, range );
       
  2655 
       
  2656     CCalInstance* result = NULL;
       
  2657 
       
  2658     // For instances finishing the next day (now possible with unified DateTime editor),
       
  2659     // we have to do our best to match the instance time exactly - otherwise we could
       
  2660     // match the LocalUid to the incorrect instance in a series.
       
  2661     for ( TInt i=0; i < instances.Count() && !result; ++i )
       
  2662         {
       
  2663         if( instances[i]->Entry().LocalUidL() == aId.iEntryLocalUid )
       
  2664             {
       
  2665             // Check the instance time matches.
       
  2666             if( instances[i]->StartTimeL().TimeLocalL() == aId.iInstanceTime )
       
  2667                 {
       
  2668                 result = instances[i];
       
  2669                 instances.Remove(i);
       
  2670                 }
       
  2671             }
       
  2672         }
       
  2673 
       
  2674     if( !result )
       
  2675         {
       
  2676         // Couldn't match the instance time exactly - just use the instance
       
  2677         // with the same LocalUid as the one we're looking for.
       
  2678         for ( TInt i=0; i < instances.Count() && !result; ++i )
       
  2679             {
       
  2680             if( instances[i]->Entry().LocalUidL() == aId.iEntryLocalUid )
       
  2681                 {
       
  2682                 result = instances[i];
       
  2683                 instances.Remove(i);
       
  2684                 }
       
  2685             }
       
  2686         }
       
  2687 
       
  2688     CleanupStack::PopAndDestroy( &instances );
       
  2689 
       
  2690     TRACE_EXIT_POINT;
       
  2691     return result;
       
  2692     }	
       
  2693 
       
  2694 // -----------------------------------------------------------------------------
       
  2695 // CCalenEventViewContainer::OpenAttachmentL
       
  2696 // Opens a particular attachment
       
  2697 // -----------------------------------------------------------------------------
       
  2698 //
       
  2699 void CCalenEventViewContainer::OpenAttachmentViewerL(RFile& aFile, MAknServerAppExitObserver& /*aExitObserver*/)
       
  2700     {
       
  2701     TRACE_ENTRY_POINT;
       
  2702     
       
  2703     TBuf<250> fileName;
       
  2704     aFile.FullName(fileName);
       
  2705     TDataType datatype( CCalenAttachmentUtils::GetMimeType(aFile) );
       
  2706 
       
  2707     TInt ret = KErrNone;
       
  2708     
       
  2709     if(datatype == KNotePadTextDataType())
       
  2710         {
       
  2711         if(iEmbeddedFileOpened)
       
  2712             {
       
  2713             return;
       
  2714             }
       
  2715         iEmbeddedFileOpened = ETrue; 
       
  2716         const TDesC& notepadTitle = _L("NotePad");
       
  2717         ret = CNotepadApi::ExecFileViewerL( aFile, 
       
  2718                                            &notepadTitle,
       
  2719                                            ETrue,
       
  2720                                            ETrue,
       
  2721                                            KCharacterSetIdentifierIso88591 );
       
  2722         iEmbeddedFileOpened = EFalse;
       
  2723         
       
  2724         }
       
  2725     else
       
  2726         {
       
  2727         //doc handler will open the other files (other than text file).
       
  2728         TRAP( ret, iDocHandler->OpenFileEmbeddedL( aFile, datatype ) );
       
  2729         
       
  2730         if(ret == KErrNone)
       
  2731             {
       
  2732             iEmbeddedFileOpened = ETrue;
       
  2733             }
       
  2734         }
       
  2735     iServices.GetAttachmentData()->AttachmentOpen(iEmbeddedFileOpened);
       
  2736     
       
  2737     switch(ret)
       
  2738         {
       
  2739         case KErrNone:
       
  2740             break;
       
  2741         default:
       
  2742             {
       
  2743             CAknInformationNote* note = new ( ELeave ) CAknInformationNote;
       
  2744             HBufC* cannotOpen = StringLoader::LoadLC( 
       
  2745                     R_QTN_CALEN_INFO_CANNOT_OPEN, CEikonEnv::Static() );
       
  2746             note->ExecuteLD( *cannotOpen );
       
  2747             CleanupStack::PopAndDestroy();
       
  2748             }
       
  2749             break;
       
  2750         }
       
  2751     TRACE_EXIT_POINT
       
  2752     }  
       
  2753 
       
  2754 // -----------------------------------------------------------------------------
       
  2755 // OnCmdFindPhoneNumL
       
  2756 // Find phone numbers in the form.
       
  2757 // (other items were commented in a header).
       
  2758 // -----------------------------------------------------------------------------
       
  2759 //
       
  2760 void CCalenEventViewContainer::OnCmdFindPhoneNumL()
       
  2761     {
       
  2762     TRACE_ENTRY_POINT;
       
  2763     BuildSearchBufferL();
       
  2764     MCalenToolbar* toolbar = iServices.ToolbarOrNull();
       
  2765     CFindItemDialog* finder = CFindItemDialog::NewL( *iSearchBuf, CFindItemEngine::EFindItemSearchPhoneNumberBin);
       
  2766     finder->EnableSingleClick(ETrue);
       
  2767     toolbar->SetToolbarVisibilityL(EFalse);
       
  2768     finder->ExecuteLD();
       
  2769     toolbar->SetToolbarVisibilityL(ETrue);
       
  2770     
       
  2771     TRACE_EXIT_POINT;
       
  2772     }
       
  2773 
       
  2774 // -----------------------------------------------------------------------------
       
  2775 // OnCmdFindUrlL
       
  2776 // Find urls in the form.
       
  2777 // (other items were commented in a header).
       
  2778 // -----------------------------------------------------------------------------
       
  2779 //
       
  2780 void CCalenEventViewContainer::OnCmdFindUrlL()
       
  2781     {
       
  2782     TRACE_ENTRY_POINT;
       
  2783     BuildSearchBufferL();
       
  2784     MCalenToolbar* toolbar = iServices.ToolbarOrNull();
       
  2785     CFindItemDialog* finder = CFindItemDialog::NewL( *iSearchBuf, CFindItemEngine::EFindItemSearchURLBin);
       
  2786     finder->EnableSingleClick(ETrue);
       
  2787     toolbar->SetToolbarVisibilityL(EFalse);
       
  2788     finder->ExecuteLD();
       
  2789     toolbar->SetToolbarVisibilityL(ETrue);
       
  2790     TRACE_EXIT_POINT;
       
  2791     }
       
  2792 
       
  2793 // -----------------------------------------------------------------------------
       
  2794 // OnCmdFindEmailL
       
  2795 // Find email addresses in the form.
       
  2796 // (other items were commented in a header).
       
  2797 // -----------------------------------------------------------------------------
       
  2798 //
       
  2799 void CCalenEventViewContainer::OnCmdFindEmailL()
       
  2800     {
       
  2801     TRACE_ENTRY_POINT;
       
  2802     BuildSearchBufferL();
       
  2803     MCalenToolbar* toolbar = iServices.ToolbarOrNull();
       
  2804     CFindItemDialog* finder = CFindItemDialog::NewL( *iSearchBuf, CFindItemEngine::EFindItemSearchMailAddressBin);
       
  2805     finder->EnableSingleClick(ETrue);
       
  2806     toolbar->SetToolbarVisibilityL(EFalse);
       
  2807     finder->ExecuteLD();
       
  2808     toolbar->SetToolbarVisibilityL(ETrue);
       
  2809     TRACE_EXIT_POINT;
       
  2810     }
       
  2811 
       
  2812 // end of file
       
  2813