// VRECUR.H
//
// Copyright (c) 1997-1999 Symbian Ltd.  All rights reserved.
//
 
#if !defined(__VRECUR_H__)
#define __VRECUR_H_

#if !defined(__VERSIT_H__)
#include "versit.h"
#endif

//
// CWeekDayArray
//

class CWeekDayArray : public CBase
	{
public:
	IMPORT_C CWeekDayArray();
	IMPORT_C ~CWeekDayArray();
	IMPORT_C void ExternalizeL(RWriteStream& aStream);
public:	
	CArrayFix<TDay>* iArray;
	};

//
// CVersitRecurrence
//

class CVersitRecurrence : public CBase
	{
public:
	IMPORT_C CVersitRecurrence(TInt aInterval,TInt aDuration,TVersitDateTime* aEndDate);
	IMPORT_C ~CVersitRecurrence();
	IMPORT_C virtual void ExternalizeOccurenceListsL(RWriteStream& aStream) const=0;
	enum TType
		{
		EDaily=1,		// i,e. repeat every x days 
		EWeekly,		// i.e.	repeat every x weeks on days Monday and Thursday with Tuesday as the first day of the week
		EMonthlyByPos,// i.e. repeat every x months on the 3rd, 5th and 9th
		EMonthlyByDay,	// i.e. repeat every x months on Tuesday of the 1st week of the month and Wednesday of the 3rd week
		EYearlyByMonth,	// i.e. repeat every year on the 3rd of October
		EYearlyByDay	// i.e. repeat every year on Wednesday of the 4th week of November
		};
public:
	TType iRepeatType;
	TInt iInterval;
	TInt iDuration; //0 indicates forever
	TVersitDateTime* iEndDate;
	};

//
// CVersitRecurrenceDaily
//

class CVersitRecurrenceDaily : public CVersitRecurrence
	{
public:
	IMPORT_C CVersitRecurrenceDaily(TInt aInterval,TInt aDuration,TVersitDateTime* aEndDate);
public: //framework
	IMPORT_C void ExternalizeOccurenceListsL(RWriteStream& /*aStream*/) const;
	};

//
//	CVersitRecurrenceWeekly
//

class CVersitRecurrenceWeekly : public CVersitRecurrence
	{
public:
	IMPORT_C CVersitRecurrenceWeekly(TInt aInterval,TInt aDuration,TVersitDateTime* aEndDate,CWeekDayArray* aArrayOfWeekDayOccurences);
	IMPORT_C ~CVersitRecurrenceWeekly();
public: //framework
	IMPORT_C void ExternalizeOccurenceListsL(RWriteStream& aStream) const;
public:
	CWeekDayArray* iArrayOfWeekDayOccurences;		//Mon-Sun
	};

//
// CVersitRecurrenceMonthlyByPos
//

class CVersitRecurrenceMonthlyByPos : public CVersitRecurrence
	{
public:
	class CMonthPosition : public CBase
		{
	public:
		IMPORT_C ~CMonthPosition();
	public:
		enum TSign {EWeeksFromStartOfMonth,EWeeksFromEndOfMonth};
	public:
		TSign iSign;
		TInt iWeekNo; //1-5
		CWeekDayArray* iArrayOfWeekDays;
		};
	IMPORT_C CVersitRecurrenceMonthlyByPos(TInt aInterval,TInt aDuration,TVersitDateTime* aEndDate,CArrayPtrFlat<CMonthPosition>* aMonthPositions);
	IMPORT_C ~CVersitRecurrenceMonthlyByPos();
public: //framework
	IMPORT_C void ExternalizeOccurenceListsL(RWriteStream& aStream) const;
public:
	CArrayPtrFlat<CMonthPosition>* iMonthPositions;
	};

//
// CVersitRecurrenceMonthlyByDay
//

class CVersitRecurrenceMonthlyByDay : public CVersitRecurrence
	{
public:
	IMPORT_C CVersitRecurrenceMonthlyByDay(TInt aInterval,TInt aDuration,TVersitDateTime* aEndDate,	CArrayFix<TInt>* aArrayOfOccurencesInDaysFromStartOfMonth
		,CArrayFix<TInt>* aArrayOfOccurencesInDaysFromEndOfMonth,TBool aLastDay);
	IMPORT_C ~CVersitRecurrenceMonthlyByDay();
public: //framework
	IMPORT_C void ExternalizeOccurenceListsL(RWriteStream& aStream) const;
public:
	CArrayFix<TInt>* iArrayOfOccurencesInDaysFromStartOfMonth; //1-31
	CArrayFix<TInt>* iArrayOfOccurencesInDaysFromEndOfMonth; //1-31
	TBool iLastDay;
	};

//
// CVersitRecurrenceYearlyByMonth
//

class CVersitRecurrenceYearlyByMonth : public CVersitRecurrence
	{
public:
	IMPORT_C CVersitRecurrenceYearlyByMonth(TInt aInterval,TInt aDuration,TVersitDateTime* aEndDate,CArrayFix<TMonth>* aArrayOfMonthsInYearOccurences);
	IMPORT_C ~CVersitRecurrenceYearlyByMonth();
public: //framework
	IMPORT_C void ExternalizeOccurenceListsL(RWriteStream& aStream) const;
public:
	CArrayFix<TMonth>* iArrayOfMonthsInYearOccurences; //Jan-Dec
	};

//
// CVersitRecurrenceYearlyByDay
//

class CVersitRecurrenceYearlyByDay : public CVersitRecurrence
	{
public:
	IMPORT_C CVersitRecurrenceYearlyByDay(TInt aInterval,TInt aDuration,TVersitDateTime* aEndDate,CArrayFix<TInt>* aArrayOfDaysInYearOccurences);
	IMPORT_C ~CVersitRecurrenceYearlyByDay();
public: //framework
	IMPORT_C void ExternalizeOccurenceListsL(RWriteStream& aStream) const;
public:
	CArrayFix<TInt>* iArrayOfDaysInYearOccurences; //1-366
	};

//
// CParserPropertyValueRecurrence
//

class CParserPropertyValueRecurrence : public CParserTimePropertyValue
	{
public:
	IMPORT_C CParserPropertyValueRecurrence(CVersitRecurrence* aValue);
	IMPORT_C ~CParserPropertyValueRecurrence();
	inline CVersitRecurrence* Value() const;
public: //framework
	IMPORT_C void ConvertAllDateTimesToUTCL(const TTimeIntervalSeconds& aIncrement,const CVersitDaylight* aDaylight);
	IMPORT_C void ConvertAllUTCDateTimesToMachineLocalL(const TTimeIntervalSeconds& aIncrement);
public: // from CParserPropertyValue
	IMPORT_C void ExternalizeL(RWriteStream& aStream,const TUid& /*aEncodingUid*/);
protected:
	CVersitRecurrence* iValue;
	};

//
// CRecurrenceParser
//

class CRecurrenceParser : public CVersitParser
	{
public:
	IMPORT_C CRecurrenceParser(TBool aHasVersion);
	IMPORT_C CParserPropertyValue* MakePropertyValueRecurrenceL();
private:	
	static void ResetAndDestroyArrayOfMonthPositions(TAny* aObject);	
	void GetFrequencyAndIntervalL(CVersitRecurrence::TType& aFrequency,TInt& aInterval);
	CVersitRecurrence* GetFrequencyModifiersL(const CVersitRecurrence::TType& aRepeatType,TInt aInterval);
	CWeekDayArray* GetListOfWeekDayOccurencesL();
	};

inline CVersitRecurrence* CParserPropertyValueRecurrence::Value() const
	{return iValue;}

#endif