// MSGED.H
//
// Copyright (c) 1998 Symbian Ltd.  All rights reserved. 
//

// MODULE - Message editor base class

#if !defined(__MSGED_H__)
#define __MSGED_H__

#if !defined(__EIKSFORM_H__)
#include <eiksform.h>
#endif

#if !defined(__EIKEDWOB_H__)
#include <eikedwob.h>
#endif

#if !defined(__EIKEDWIN_H__)
#include <eikedwin.h>
#endif

#if !defined(__MSVSTD_H__)
#include <msvstd.h>
#endif

#if !defined(__MSVAPI_H__)
#include <msvapi.h>
#endif

#if !defined(__EDITPARA_H__)
#include "editpara.h"
#endif

#if !defined(__EDITFLAG_H__)
#include "editflag.h"
#endif

// Forward references
class TMsgEditorControlDocumentAndZoomManager;
class MMsgEditorBodyControlManager;
class TMailEditorPreferences;
//

enum TClipboardCommand { ECut, ECopy, EPaste };

class MMsgEditorObserver
	{
public:
	virtual CDictionaryStore* OpenIniFileLC() = 0;
	virtual void CloseEditorNoQueryL() = 0;
	virtual void CloseEditorL() = 0;
	};

//////////////////////////////////////
//          CMsgEditorForm          //
//////////////////////////////////////
// The class which encapsulates the //
// main user interface to editors.  //
// Isn't used by clients (they use  //
// the thin API/contained class     //
// CMsgEditorControl).              //
//////////////////////////////////////
// Designed to be sub-classed to    //
// provide message type specific    //
// behaviour in the editor          //
//////////////////////////////////////
// Derived classes must ensure that //
// iCurrentLine is set to the	    //
// appropriate line in the form.    //
//////////////////////////////////////
class CMsgEditorForm : public CEikScrollableForm, public MEikEdwinObserver
	{
public:
	// --- Destruction ---
	IMPORT_C virtual ~CMsgEditorForm();
	//
	// --- Message methods ---
	virtual void SaveMessageL(TMsvId aDestinationFolder, TBool aRemoveOriginal) = 0;
	IMPORT_C virtual TBool ValidateMessageL();// Returns EFalse if message was not valid
	IMPORT_C const CMsvEntry& MessageEntry() const;
	IMPORT_C void CloseStore();
	//
	// --- Enquiry ---
	inline TBool IsReadOnly() const;
	IMPORT_C void StorePreferencesL() const;
	IMPORT_C TMailEditorPreferences& Preferences() const;
	inline TBool HasChanged() const;
	//
	// --- Scrolling ---
	TBool SetScrollBarModelL(TEikScrollBarModel& aModel) const;
	void SetPixelPositionInDocumentL(TInt aPixelPosition);
	void SetLinePositionInDocumentL(TInt aLine);
	void StepScrollDownL(TBool aWholeScreen);
	void StepScrollUpL(TBool aWholeScreen);
	// 
	// --- Command handling ---
	IMPORT_C void ZoomOutL();
	IMPORT_C void ZoomInL();
	IMPORT_C void ClipboardL(TClipboardCommand aCommand);

protected: 
	// --- from MCoeControlObserver, via CEikForm ---
	IMPORT_C virtual void HandleControlEventL(CCoeControl* aControl, TCoeEvent aEventType);
	//
	// from MEikEdwinObserver
	IMPORT_C virtual void HandleEdwinEventL(CEikEdwin* aEdwin, TEdwinEvent aEventType);
	//
	// --- from CCoeControl ---
	IMPORT_C virtual TKeyResponse OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType);
	IMPORT_C virtual void SizeChangedL();
	//
	// --- from CEikForm ---
	IMPORT_C virtual SEikControlInfo CreateCustomControlL(TInt aControlType);
	IMPORT_C void ConstructFromResourceL(TResourceReader& aReader);

protected: 
	// --- Construction ---
	IMPORT_C virtual void ConstructL(const CCoeControl& aParent, MCoeControlObserver* aObserver, TInt aResourceId, TMsvId aMsgId);
	virtual MMsgEditorBodyControlManager* CreateBodyDocumentControlL() const = 0;
	IMPORT_C CMsgEditorForm(CMsvSession& aSession, TInt aFlags, MMsgEditorObserver* aObs);
	//
	// --- Store handling ---
	IMPORT_C CMsvStore* GetStoreL() const;
	//
	// --- Control handling - Virtual methods ---
	IMPORT_C virtual void OfferKeyToLineL(const CEikCaptionedControl& aControl, const TKeyEvent& aKeyEvent, TEventCode aType);
	IMPORT_C virtual TBool AtBottomOfLineL(const CEikCaptionedControl& aLine) const;
	IMPORT_C virtual TBool AtTopOfLineL(const CEikCaptionedControl& aLine) const;
	IMPORT_C virtual TBool HandleControlConfirmationInteractionL(TInt aLine);
	IMPORT_C virtual void ZoomControlL(CEikCaptionedControl& aLine);
	IMPORT_C virtual TRect CursorRectOfControlL(TInt aLine);
	//
	// --- Control handling - Non-virtual methods ---
	IMPORT_C void EdwinCursorAttributesL(const CEikEdwin& aEdwin, TPoint& aCursorPos, TPoint& aZeroPos, TPoint& aEndPos) const;
	IMPORT_C TBool ResizeEdwinToFitTextL(CEikEdwin& aEdwin, TBool aMaintainMinimumSize, TDrawNow aDrawNow=ENoDrawNow);
	IMPORT_C TInt MaxHeightOfControl(CCoeControl* aControl) const;
	IMPORT_C TBool IsBodyControlAtViewTop() const;
	IMPORT_C TInt BodyControlIndex() const;
	IMPORT_C void EnsureCursorVisibleL(TInt aLine);
	//
	// --- Form handling ---
	IMPORT_C virtual void SizeChangedOnControlL(CEikCaptionedControl& aControl, TSize aCurrentSize, TInt aMaxCaptionWidth);
	IMPORT_C virtual void ClipboardOperationL(CEikEdwin::TClipboardFunc aFunc);
	IMPORT_C virtual void MoveFocusByL(TInt aFocusChange);
	IMPORT_C void SetHasChanged();
	//
	// --- Message handling ---
	virtual void SeedFormFromMessageL() = 0;
	//
	// --- Text handling ---
	IMPORT_C void InsertEdwinTextIntoPlainTextL(CPlainText& aText, TInt aEdwinRid, TInt aPrefixRid=0) const;
	IMPORT_C void InsertResourceIntoTextL(CPlainText& aBodyText, TInt aResourceId) const;
	IMPORT_C void RunSpellCheckerL(CEikEdwin& aEdwin);
	IMPORT_C CRichText* CopyGlobalTextToRichTextLC(const CGlobalText& aSource) const;
	IMPORT_C void DoCopyTextToTextL(const CPlainText& aSource, CPlainText& aDestination) const;

private:
	//
	// --- Control handling ---
	void FocusLostFromControlL(TInt aIndexOfControl);
	//
	// --- Form handling ---
	void SetDataPositionWithinBounds(TInt aPos);
	void SetZoomL(TInt aZoomSize);

protected: 
	// --- Data ---
	MMsgEditorBodyControlManager*					iBodyDocumentControl;
	TInt											iMessageFormFlags;
	TZoomFactor*									iZoomFactor;
	TMailEditorPreferences*							iPreferences;
	MMsgEditorObserver*								iEditorObserver;
	//
	// --- Message data ---
	CMsvSession&									iMsvSession;
	CMsvEntry*										iEntry;

private:
	CMsvStore*										iStore;
	};


/////////////////////////////////////////
//          CMsgEditorControl          //
/////////////////////////////////////////
// This class is the container for the //
// real message editor functionality,  //
// and also constitutes the interface  //
// through which clients interact with //
// editors (clients do not interact    //
// with CMsgEditorForm                 //
/////////////////////////////////////////
class CMsgEditorControl : public CEikScrollableFormContainer, public MCoeControlObserver,	public MCoeControlBrushContext
	{
public:// new to CMsgEditorControl
	IMPORT_C virtual ~CMsgEditorControl();
	IMPORT_C void SaveMessageL(TMsvId aDestinationFolder, TBool aRemoveOriginal=EFalse);
	IMPORT_C TBool ValidateMessageL() ;// Returns EFalse if message was not valid
	inline CMsgEditorForm* Form() const;

public:// from CCoeControl
	IMPORT_C virtual TSize MinimumSize();

protected:
	IMPORT_C CMsgEditorControl();
	IMPORT_C virtual void ConstructL(TInt aResourceId, CMsvSession& aSession, TMsvId anId, TInt aFlags, MMsgEditorObserver* aObs);
	void MsgEditorUpdateScrollBarL();

protected:// from MCoeControlObserver
	IMPORT_C virtual void HandleControlEventL(CCoeControl* aControl, TCoeEvent aEventType);
	IMPORT_C virtual void HandleScrollEventL(CEikScrollBar* aScrollBar,TEikScrollEvent aEventType);

protected:// from CCoeControl
	IMPORT_C virtual void SizeChangedL();
	IMPORT_C virtual void FocusChanged(TDrawNow aDrawNow);
	IMPORT_C virtual TKeyResponse OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType);

protected:
	virtual CEikScrollableForm* CreateFormL(TInt aResourceId, CMsvSession& aSession, TMsvId anId, TInt aFlags, MMsgEditorObserver* aObs) = 0;
	};

#define iMsgEditorForm		(STATIC_CAST(CMsgEditorForm*, iScrollableForm))

#include "msged.inl"

#endif

