// IMED.H
//
// Copyright (c) 1998 Symbian Ltd.  All rights reserved. 
//

// MODULE - Internet mail Message editor

#if !defined(__IMED_H__)
#define __IMED_H__

#if !defined(__MSGED_H__)
#include <msged.h>
#endif

#if !defined(__EIKLBO_H__)
#include <EIKLBO.H>
#endif 

#if !defined(__IMEDADDR_H__)
#include "IMEDADDR.H"
#endif 

// Forward references
class CEikRichTextEditor;
class CAttachmentListBox;
class CImHeader;
//


////////////////////////////////////////////
//			  CMsgEditorForm              //
////////////////////////////////////////////
//	Concrete scrolling for class which    //
//	encapsulates the behaviour of		  //
//  the internet mail editor. Used by the //
//  class CInternetMailEditorControl,	  //
//	which acts as a container and client  //
//	API.                                  //
////////////////////////////////////////////
class CInternetMailEditorForm : public CMsgEditorForm, public MEikListBoxObserver
	{
public:
	// --- Construction / destruction
	static CMsgEditorForm* NewL(const CCoeControl& aParent, MCoeControlObserver* aObserver, TInt aResourceId, CMsvSession& aSession, TMsvId aMsgId, TInt aFlags, MMsgEditorObserver* aObs);
	virtual ~CInternetMailEditorForm();
	void Cancel();		// "Exit, lose changes"
	//
	// --- Accessors
	inline TBool NewMail() const;
	inline TBool Responding() const;
	void SetReplyToSender();
	void SetReplyToAll();
	void SetForward();
	inline TBool CorporateMail() const;

	//
	// --- Status ---
	inline TBool CanEditBodyText();
	//
	// --- Attachments ---
	TInt NumberOfAttachments() const;
	void DeleteAttachmentL();
	void ViewAttachmentL();
	void SaveAttachmentL();
	void AddAttachmentL();
	//
	// --- Commands ---
	void LaunchPreferencesDialogL();
	void DisplayWordCountL() const;
	void AddAddressToContactsL();
	void FindL(TInt aCommand);
	void SetEmailAccountL();
	void AddressMessageL();
	void DeleteMessageL();
	void SpellCheckL();
	void SelectAllL();
	void IrdaReceiveL();
	void IrdaSendL();
	void UndoL();
	void SetMsgReadL();

	//
	// --- Body ---
	CRichText* PrintTextLC() const;
	void ChangeBodyTextFontL();

private: 
	
	// Accessors
	inline TBool ReplyingToSender() const;
	inline TBool ReplyingToAll() const;
	inline TBool Forwarding() const;

	// --- CInternetMailEditorForm ---
	CInternetMailEditorForm(CMsvSession& aSession, TInt aFlags, MMsgEditorObserver* aObs);

private: 
	// --- From CEikForm ---
	virtual SEikControlInfo CreateCustomControlL(TInt aControlType);

private: 
	// --- From CMsgEditorForm ---
	virtual void ConstructL(const CCoeControl& aParent, MCoeControlObserver* aObserver, TInt aResourceId, TMsvId aMsgId);
	virtual TKeyResponse OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType);
	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);
	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 AtBottomOfLineL(const CEikCaptionedControl& aLine) const;
	virtual TBool AtTopOfLineL(const CEikCaptionedControl& aLine) const;
	virtual TRect CursorRectOfControlL(TInt aLine);
	//	
	// --- Utility ---
	CInternetMsgAddressControl& AddressControl(TInt aRid) const;
	CCoeControl& EmbeddedControl(TInt anId) const;
	CEikGlobalTextEditor& BodyTextEditor() const;
	void FocusOnErrorInEdwinL(TInt aControlIndex, TInt aStartOfError, TInt aEndOfError);
	CGlobalText& ReplaceEdwinTextL() const;
	//
	// --- Message handling ---
	void SeedHeaderAndEntryLC(TMsvEntry& aEntry, CImHeader& aHeader) const;
	void MoveEntryToL(TMsvId aDestinationFolder, TBool aRemoveOriginal);
	TMsvId CreateRespondMessageLC(TMsvId aOriginalId) const;
	TMsvId CreateNewMessageLC() const;
	void DoSaveMessageL();
	void RestoreHeaderDetailsL();
	void RestoreGenericDetailsL();
	void SetResponding();
	//
	// --- Text handling ---
	void SwitchToBodyTextL();
	void RestoreBodyTextL();
	//
	// --- Closure of editor ---
	void DoCancelL();			
	//
	// --- Attachment handling ---
	TBool ResizeAttachListToFitInfoL();
	CAttachmentListBox* AttachmentListBox() const;
	//
	// --- from MEikListBoxObserver (i.e. attachment list box observer) ---
	virtual void HandleListBoxEventL(CEikListBox* aListBox, TListBoxEvent aEventType);

private:
	TUid											iUidMsgType;	// Normally SMTP, except when EMsgCorporate flag used.

protected: 
	// --- Data ---
	TMsvId											iNewAccount;
	};


////////////////////////////////////////////
//            CMsgEditorControl           //
////////////////////////////////////////////
//	Concrete internet mail editing class  //
////////////////////////////////////////////
class CInternetMailEditorControl : public CMsgEditorControl
	{
public:
	IMPORT_C static CInternetMailEditorControl* NewL(TInt aResourceId, CMsvSession& aSession, TMsvId anId, TInt aFlags, MMsgEditorObserver* aObs);
	//
	// --- Accessor ---
	inline CInternetMailEditorForm* Form() const;

protected:
	CInternetMailEditorControl();

private:
	virtual CEikScrollableForm* CreateFormL(TInt aResourceId, CMsvSession& aSession, TMsvId anId, TInt aFlags, MMsgEditorObserver* aObs);
	};

#define iInternetMsgEditorForm		(STATIC_CAST(CInternetMailEditorForm*, iScrollableForm))

#include "imed.inl"

#endif // __IMED_H__
