// SMED.H
//
// Copyright (c) 1998 Symbian Ltd.  All rights reserved.
//

#if !defined(__SMED_H__)
#define __SMED_H__

#if !defined(__MSGED_H__)
#include <msged.h>
#endif

#if !defined(__SMEDDATE_H__)
#include "smeddate.h"
#endif

#if !defined(__SMUTHDR_H__)
#include <smuthdr.h>
#endif

#if !defined(__CNTDBOBS_H__)
#include <CNTDBOBS.H>
#endif

class CContactDatabase;	//	(for contacts)
class CFieldUidArray;
class CContactIdArray;
class CContactItem;
class CContactItemFieldSet;
class CContactChangeNotifier;

class CSmsHeader;
class CEikRichTextEditor;

class CSmsEditorForm : public CMsgEditorForm, public MContactDbObserver
	{
public:
	// Construction / destructions
	IMPORT_C static CSmsEditorForm* NewL(const CCoeControl& aParent, MCoeControlObserver* aObserver,
		TInt aResourceId, CMsvSession& aSession, TMsvId aMsgId, TInt aFlags, MMsgEditorObserver* aObs);
	~CSmsEditorForm();


private:
	enum 	{ENameMaxLength=60};
	CSmsEditorForm(CMsvSession& aSession, TInt aFlags, MMsgEditorObserver* aObs);

	// From CEikForm
	virtual SEikControlInfo CreateCustomControlL(TInt aControlType);

	// From CMsgEditorForm
	virtual TKeyResponse OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType);
	virtual void ClipboardOperationL(CEikEdwin::TClipboardFunc aFunc);
	virtual void ConstructL(const CCoeControl& aParent, MCoeControlObserver* aObserver, 
		TInt aResourceId, TMsvId aMsgId);
	virtual void OfferKeyToLineL(const CEikCaptionedControl& aControl, const TKeyEvent& aKeyEvent,
		TEventCode aType);
	virtual void SizeChangedOnControlL(CEikCaptionedControl& aControl, TSize aCurrentSize, TInt aMaxCaptionWidth);

	virtual void SaveMessageL(TMsvId aDestinationFolder, TBool aRemoveOriginal = EFalse);
	void DoSaveMessageL();	//	added by DS
	virtual void HandleControlEventL(CCoeControl* aControl, TCoeEvent aEventType);
	virtual MMsgEditorBodyControlManager* CreateBodyDocumentControlL() const;
	virtual TBool HandleControlConfirmationInteractionL(TInt aLine);
	virtual TBool ValidateMessageL();
	virtual void SeedFormFromMessageL();
	virtual void ZoomControlL(CEikCaptionedControl& aLine);
	virtual TBool AtBotomOfLineL(const CEikCaptionedControl& aLine) const;
	virtual TBool AtTopOfLineL(const CEikCaptionedControl& aLine) const;
	virtual TRect CursorRectOfControlL(TInt aLine);


// Utilities
	CEikGlobalTextEditor& BodyTextEditor() const;
	CMsgDateSizeLineControl& DateSizeControl() const;
	CEikEdwin* TelephoneNumberTo() const;
	CEikEdwin* TelephoneNumberFrom() const;

	TSmsSettings GetDefaultServiceSettingsL();
	
	void SwitchToBodyTextL();
	void ChangeBodyTextFontL();	
	void SetTrailerL(const TDesC& aTrailText, TInt aControlId);
	TBool IsBlankTrailer() const;
	CEikLabel& ToTrailer() const;
	void BlankTrailerL();

// Contacts
	void HandleDatabaseEventL(TContactDbObserverEvent aEvent);
	void CloseContactsLink();
	CWsBitmap* ContactsBitmapL() const;
	void SetContactL(const TDesC& aDes, const CContactItem& aContact);
	void GetContactName(const CContactItemFieldSet& aFieldSet, TBuf<ENameMaxLength>& aName) const;
	void TriggerContactsInteractionL();
	CFieldUidArray* PreferredSelectionContactsFieldsLC() const;
	CContactItem* ContactsTemplateLC2() const;
	void SetupContactsLinkL();
	void AddContactEntriesL(CContactIdArray* aSelection);
	void SetSmsNumberL(const TDesC& aDes);
	void GetSmsNumber(TDes& aNumber);
	void SetFromNumberL(const TDesC& aDes);
	void GetFromNumber(TDes& aNumber);
	void SetTextSize();
	TInt SelectAddressFromContactL(const CDesCArray& aAddressArray, const CContactItemFieldSet& aFieldSet) const;

	void MoveEntryToL(TMsvId aDestinationFolder, TBool aRemoveOriginal);
	CMsvEntry* RespondToMessageL(TInt aRespondType);


public:
// Command handling
	void DeleteMessageL();
	void SelectAllL();
	void UndoL();
	void AddressMessageL();
	void FindL(TInt aCommand);
	void SpellCheckL();
	void DisplayWordCountL();
	void IrdaReceiveL();
	void IrdaSendL();
	void LaunchPreferencesDialogL();
	void LaunchMessageSettingsDialogL();
	void SetMsgReadL();
	CMsvEntry* ReplyToMessageL();
	CMsvEntry* ForwardMessageL();
	CRichText* PrintTextLC() const;


	inline TBool NewSMS() const;	//	Accessor (added by DS)
	inline TBool Responding() const;
	inline TBool Replying() const;
	inline TBool Forwarding() const;


private:	// private data
	CSmsHeader*			iSmsHeader;
	CContactDatabase*	iContactsDatabase;			//	Contacts integration
	TInt				iContactsResourceHandle;
	TInt				iContactsCacheHandle;
	CContactChangeNotifier*		iChangeNotifier;
	TBuf<32>					iRollBackButtonText;
};


class CSmsEditorControl : public CMsgEditorControl
	{
public:
	IMPORT_C static CSmsEditorControl* NewL(TInt aResourceId, CMsvSession& aSession, TMsvId anId, 
		TInt aFlags, MMsgEditorObserver* aObs);
	virtual ~CSmsEditorControl();
	// Accessor
	inline CSmsEditorForm* Form() const;

protected:
	CSmsEditorControl();

private:
	CEikScrollableForm* CreateFormL(TInt aResourceId, CMsvSession& aSession, TMsvId anId, TInt aFlags,
		MMsgEditorObserver* aObs);


	};

#define iSmsEditorForm		(STATIC_CAST(CSmsEditorForm*, iScrollableForm))

#include "smed.inl"


/*

protected:
	MMsgEditorBodyControlManager* CreateBodyDocumentControlL() const;
	void SeedFormFromMessageL();

private: 
	CSmsEditorForm(CMsvSession& aSession, TInt aFlags);
	void ConstructL(const CCoeControl& aParent, MCoeControlObserver* aObserver, TInt aResourceId, TMsvId aMsgId);

	CEikRichTextEditor& BodyTextEditor() const;
	CCoeControl& EmbeddedControl(TInt anId) const;
	void SetAddressInHeaderL() const;

protected: 
	CSmsHeader* iSmsHeader;
//	CMsgFileRecognizer*								iFileRecognizer;// Required for attachment icon recognition
//	TMsgAttachmentPictureFactory*					iPictureFactory;// Specialised factory for in-line attachment icons
	};
*/


#endif // __SMED_H__
