// EIKEDWIN.H
//
// Copyright (c) 1997-1999 Symbian Ltd.  All rights reserved.
//
 
#if !defined(__EIKEDWIN_H__)
#define __EIKEDWIN_H__

#if !defined(__COEMAIN_H__)
#include <coemain.h>
#endif

#if !defined(__EIKBCTRL_H__)
#include <eikbctrl.h>
#endif

#if !defined(__EIKSBFRM_H__)
#include <eiksbfrm.h>
#endif

#if !defined(__FRMTVIEW_H__)
#include <frmtview.h>
#endif

#if !defined(__EIKEDWOB_H__)
#include <eikedwob.h>
#endif

#if !defined(__EIKIROBS_H__)
#include <eikirobs.h>
#endif

#if !defined(__EIKDUTIL_H__)
#include <eikdutil.h>
#endif

#if !defined(__S32MEM_H__)
#include <s32mem.h>
#endif

#if !defined(__S32STD_H__)
#include <s32std.h>
#endif

#if !defined(__GDI_H__)
#include <gdi.h>
#endif

#if !defined(__FEPBASE_H__)
#include <fepbase.h>
#endif

class CPlainText;
class CGlobalText;
class CParaFormatLayer;
class CCharFormatLayer;
class MLayDoc;
class CEikRubberBand;
class MEikEdwinObserver;
class CBeamingStore;
class CEikIrMain;
class CEikEdwinFepSupport;
class CEikEdwinExtra;
struct SEdwinFindModel;

class CEikEdwin : public CEikBorderedControl, public MEikScrollBarObserver
	{
private:
	class CUndoBuffer;
public:
	enum TFlags
		{ // user flags
		EKeepDocument			=0x00000001,
		ESegmentedStorage		=0x00000002,
		EWidthInPixels			=0x00000004,
		ENoAutoSelection		=0x00000008,
		EJustAutoCurEnd			=0x00000010,
		ENoWrap					=0x00000020,
		ELineCursor				=0x00000040, 
		ENoHorizScrolling		=0x00000080, 
		EInclusiveSizeFixed		=0x00000100, 
		EUserSuppliedText		=0x00000200,
		EOwnsWindow				=0x00000400,
		EDisplayOnly			=0x00000800,
		EAlwaysShowSelection	=0x00001000,
		EReadOnly				=0x00002000,
		EAllowPictures			=0x00004000,
		EAllowUndo				=0x00008000,
		ENoLineOrParaBreaks		=0x00010000
		};
	enum TClipboardFunc
		{
		ENoClipboard,
		ECut,
		ECopy,
		EPaste
		};
	enum TFindFlags
		{
		EFindDirectionUp	=0x01,
		EFindWholeWord		=0x02,
		EFindCaseSensitive	=0x04,
		EFindAgain			=0x08,
		ENoBusyMessage		=0x10
		};
	enum TSetContent
		{
		EUseText,
		ECopyText
		};
	enum TOwnershipType
		{
		EOwnsText,
		EDoesNotOwnText
		};
public: // construction and destruction
	IMPORT_C ~CEikEdwin();
	IMPORT_C CEikEdwin();
	IMPORT_C CEikEdwin(const TEikBorder& aBorder);
	IMPORT_C void ConstructL(TInt aEdwinFlags=0,TInt aWidthInChars=0,TInt aTextLimit=0,TInt aNumberOfLines=0);
	IMPORT_C void SetEdwinObserver(MEikEdwinObserver* aEdwinObserver);
	IMPORT_C void SetContainerWindowL();
	IMPORT_C void SetDocumentContentL(CGlobalText& aText,TSetContent aContent=CEikEdwin::ECopyText);
public: // from CCoeControl
	IMPORT_C TKeyResponse OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType);
	IMPORT_C void FocusChanged(TDrawNow aDrawNow);
	IMPORT_C void ActivateL();
	IMPORT_C void ConstructFromResourceL(TResourceReader& aReader);
	IMPORT_C void HandlePointerEventL(const TPointerEvent& aPointerEvent);
	IMPORT_C TSize MinimumSize();
	IMPORT_C void Draw(const TRect& aRect) const;
	IMPORT_C void SetDimmed(TBool aDimmed);
	IMPORT_C void SetContainerWindowL(const CCoeControl& aParent);
public: // from MEikScrollBarObserver
	IMPORT_C void HandleScrollEventL(CEikScrollBar* aScrollBar, TEikScrollEvent aEventType); // from MEilScrollBarObserver
public:
	IMPORT_C TInt TextLength() const;
	IMPORT_C TInt CursorPos() const;
	IMPORT_C TInt SelectionLength() const;
	IMPORT_C TCursorSelection Selection() const;
	IMPORT_C void ClearSelectionL();
	IMPORT_C void SetSelectionL(TInt aCursorPos,TInt aAnchorPos);
	IMPORT_C void SetCursorPosL(TInt aCursorPos,TBool aSelect);
	IMPORT_C void SelectAllL();
	IMPORT_C void CalculateWidth(TInt aWidthInChars);
	IMPORT_C void GetText(TDes& aDes) const;
	IMPORT_C HBufC* GetTextInHBufL() const;
	IMPORT_C void SetTextL(const TDesC* aDes);
	IMPORT_C void ClipboardL(TClipboardFunc aClipboardFunc);
	IMPORT_C void InsertFieldL(CTextField* aField,TUid aFieldType);
	IMPORT_C void UpdateAllFieldsL();
	IMPORT_C void UpdateCurrentFieldL();
	IMPORT_C TInt CountWords();
	IMPORT_C void InsertFromTextFileL(const TFileName &aFileName,const CPlainText::TTextOrganisation aTextOrganisation=CPlainText::EOrganiseByLine);
	IMPORT_C static TInt IdleL(TAny *aPtr);
	IMPORT_C CPlainText* Text() const;
	IMPORT_C CTextView* TextView() const;
	IMPORT_C CTextLayout* TextLayout() const;
	IMPORT_C void CancelFepTransaction(); // this is particularly important for when the front-end processor is inline-editing a CEikEdwin
	IMPORT_C void HandleTextChangedL();
	IMPORT_C TInt LayoutWidth() const;
	IMPORT_C void NotifyNewDocumentL();
	IMPORT_C void NotifyNewFormatL();
	IMPORT_C TBool FindL(const TDesC* aFindText,TInt aFindFlags=0);
	IMPORT_C TInt FindTextL(const TDesC* aFindText,TInt aPos,TInt aFindFlags);
	IMPORT_C void ReplaceL(SEdwinFindModel* aFindModel);
	IMPORT_C void ReplaceAllL(SEdwinFindModel* aFindModel);
	IMPORT_C void GetFindText(TDes* aFindText);
	IMPORT_C void UpdateScrollBarsL();
	IMPORT_C CEikScrollBarFrame* CreateScrollBarFrameL();
	inline CEikScrollBarFrame* ScrollBarFrame();
	IMPORT_C void SetWordWrapL(TBool aWrapIsOn);
	IMPORT_C virtual TInt LineCursorWidth() const;
	IMPORT_C void SetZoomFactorL(TZoomFactor* aZoomFactor);
	IMPORT_C void SetBackgroundColorL(TRgb aBackground);
	IMPORT_C void SetWysiwygModeOn(TInt aLayoutWidth,MGraphicsDeviceMap* aDevice);
	IMPORT_C void SetWysiwygModeOff();
	IMPORT_C void UpdateLayoutWidth(TInt aLayoutWidth); // for use in wysiwyg mode only
	IMPORT_C void CreateTextViewL();
	IMPORT_C void SendDataOverIrL();
	IMPORT_C void ReceiveDataOverIrL();
	IMPORT_C void SetAmountToFormatL(TBool aIsNewDoc=EFalse);
	IMPORT_C void PasteFromStoreL(CStreamStore& aStore, CStreamDictionary& aDict);
	IMPORT_C void CopyToStoreL(CStreamStore& aStore, CStreamDictionary& aDict);
	IMPORT_C void SetBorderViewMargins(TMargins8 aMargins);
	IMPORT_C void ForceScrollBarUpdateL();
	IMPORT_C void SetDocumentOwnership(TOwnershipType aOwner);
	IMPORT_C void SetTextLimit(TInt aLimit);
	IMPORT_C void RunCharMapDialogL();
	IMPORT_C TMargins8 Margins() const;
	IMPORT_C TInt UpperFullFormattingLength() const;
	IMPORT_C TInt LowerPartialFormattingLength() const;
	IMPORT_C void SetReadOnly(TBool aReadOnly);
	IMPORT_C TBool IsReadOnly() const;
	IMPORT_C void CheckNotReadOnlyL();
	IMPORT_C void SetAllowPictures(TBool aAllow);
	IMPORT_C void CheckRemovePictures(TInt aStartPos,TInt aLength);
	IMPORT_C void SetRightWrapGutter(TInt aGap);
	IMPORT_C void UndoL();
	IMPORT_C void ClearUndo();
	IMPORT_C TBool SetUndoBufferL(const TCursorSelection& aSelection);
	IMPORT_C void SetAllowUndo(TBool aAllow);
	IMPORT_C TBool SupportsUndo() const;
	IMPORT_C TBool CanUndo() const;
	IMPORT_C void SetUndoableText(const TCursorSelection& aSelection);
	IMPORT_C void SetWordDelimiters(TBool aPicture,TBool aPunctuation);
	IMPORT_C void GetWordInfo(TInt aCurrentPos,TInt& aStartPos,TInt& aLength) const;
	IMPORT_C void MoveCursorL(TCursorPosition::TMovementType aMovement,TBool aSelect);
	IMPORT_C void MoveDisplayL(TCursorPosition::TMovementType aMovement);
	inline TInt AvgLinesInViewRect() const;
	inline TInt AvgCharsPerLine() const;
	inline void SetAvgLinesInViewRect(TInt aAvgLines);
	inline void SetAvgCharsPerLine(TInt aAvgChars);
protected:
	enum TEnd
		{
		EStart,
		EEnd   
		};
	enum TChunkSize
		{
		EChunkWord,
		EChunkPara
		};
	enum TEikEdwinFlags
		{ // internal flags
		ERichText           =0x00000001,
		EDragDouble			=0x00000002,
		ELeftDownInViewRect =0x00000004,
		ENumericCharacters	=0x00000008 // only used to calculate initial width
		};
	enum TEdwinHotKeys // order of hotkeys defined in resource file.  Not all applicable to plain text editors
		{
		EHotKeyCut,
		EHotKeyCopy,
		EHotKeyPaste,
		EHotKeyUndo,
		EHotKeyFind,
		EHotKeyInsertChar,
		EHotKeyBold,
		EHotKeyItalic,
		EHotKeyUnderline,
		EHotKeyFont,
		EHotKeyInsertObject,
		EHotKeyEditObject,
		EHotKeyFormatObject
		};
protected:
	IMPORT_C void TrappedDraw(const TRect& aRect) const;
	IMPORT_C void DrawContents();
	IMPORT_C void BaseConstructL();
	IMPORT_C void FormatTextL();
	IMPORT_C TInt DeleteHighlightL(TBool& aChanged,TBool aIsBackSpace=EFalse,TBool aPromptConfirmation=ETrue);
	IMPORT_C TBool OkToDeleteSelectionL();
	IMPORT_C void DeleteL(TBool& aChanged,const TCursorSelection& aSelection,TBool aIsBackSpace=EFalse,TBool aAllowUndo=ETrue);
	IMPORT_C void TrappedSizeChanged();
	IMPORT_C void HandleSizeChangedL();
	IMPORT_C void CancelSelectionL(TEnd aEndOfSelectionToLeaveCursor);
	IMPORT_C void MoveCursorToChunkStartL(TBool aSelect,TChunkSize aChunkSize,TEnd aEndScanningTowards);
	IMPORT_C void CancelInsertCharFormat();
	IMPORT_C void PlaceDataOnClipboardL();
	IMPORT_C void CreateLayoutL(MLayDoc* aLayDoc);
	IMPORT_C void CreateTextAndLayoutL(CParaFormatLayer* aParaFormatLayer,CCharFormatLayer* aCharFormatLayer);
	IMPORT_C void ReportEdwinEventL(MEikEdwinObserver::TEdwinEvent aEventType);
	IMPORT_C void SetLineCursorDetailsL();
	IMPORT_C virtual void CopyDocumentContentL(CGlobalText& aInText,CGlobalText& aOutText);
	IMPORT_C void DisplayFindTextNotFound(TDes& aFindText);
	IMPORT_C virtual void HandleTextPastedL(TInt aStartPos,TInt& aLength);
private:
	enum
		{ // internal flags
		EWysiwygOn						=0x00000010,
		EUnderOneScreenFormattedText	=0x00000020,
		EPictureDelimits				=0x00000040,
		EPunctuationDelimits			=0x00000080,
		EPasteFromIrStore				=0x00000100,
		ELockScrollBarState				=0x00000200
		};
private: // from CCoeControl
	IMPORT_C void SizeChangedL();
	IMPORT_C TInt CountComponentControls() const;
	IMPORT_C CCoeControl* ComponentControl(TInt aIndex) const;
	IMPORT_C void Reserved_1();
	IMPORT_C void Reserved_2();
private:
	IMPORT_C virtual void Reserved_3();
	IMPORT_C virtual void NotifyInvalidOperationOnReadOnlyL();
	void CalcHeightForNumOfLinesL(CGlobalText& aText);
	void ApplyAutoSelectionL();
	void SetScrollBarsL();
	void SetVertScrollBarModelByCharactersL(TEikScrollBarModel& aVertModel) const;
	void RetrieveDataFromClipboardL();
	void SetCursorVisibilityL(TBool aEmphasis);
	TBool OwnsScrollBars() const;
	void CreateScrollBarFrameLayout(TEikScrollBarFrameLayout& aLayout) const;
	void UpdateHorizScrollBarThumb();
	void UpdateVertScrollBarThumbL();
	void DoSetUndoBufferL(const TCursorSelection& aSelection);
	void DoPasteFromStoreL(const CStreamStore& aStore,const CStreamDictionary& aDict);
	void DoReplaceAllL(SEdwinFindModel* aModel,TBool& aTextFound,TBool& aReplaced);
	void SetPasteFromIrStore(TBool aPasteFromIrStore);
	void DeleteExtraParasL(TInt aStartPos,TInt aLength);
	TInt LocateChar(TChar aChar,TInt aStartPos,TInt aLength);
protected:
	TUint32 iEdwinUserFlags;
	TUint32 iEdwinInternalFlags;
	CPlainText* iText;
	CTextView* iTextView;
	CTextLayout* iLayout;
	TInt iTextLimit;
	TInt iNumberOfLines;
	MGraphicsDeviceMap* iZoomFactor;
	TInt iLastPointerDocPos;
	TMargins8 iMargins;
private:
	friend class CEikEdwinBeamer;
	friend class CEikEdwinFepSupport;
	CIdle* iSetScrollBar;
	CEikScrollBarFrame* iSBFrame;
	CEikEdwinExtra* iExtra;
	CUndoBuffer* iUndoStore;
	TRgb iBackground;
	TInt iAvgLinesInViewRect;
	TInt iAvgCharsPerLine;
	TInt iRightWrapGutter;
	TInt iLayoutWidth;
	};

inline CEikScrollBarFrame* CEikEdwin::ScrollBarFrame()
	{ return ((CEikScrollBarFrame* const)iSBFrame); }
inline TInt CEikEdwin::AvgLinesInViewRect() const
	{ return iAvgLinesInViewRect; }
inline TInt CEikEdwin::AvgCharsPerLine() const
	{ return iAvgCharsPerLine;}
inline void CEikEdwin::SetAvgLinesInViewRect(TInt aAvgLines)
	{ iAvgLinesInViewRect=aAvgLines; }
inline void CEikEdwin::SetAvgCharsPerLine(TInt aAvgChars)
	{ iAvgCharsPerLine=aAvgChars; }

//
// class CEikEdwinBeamer
//

class CEikEdwinBeamer : public CBase, public MEikIrObserver
	{
public:
	inline CEikEdwinBeamer(CEikEdwin* aEdwin);
	~CEikEdwinBeamer();
	TInt SendLD();
	void ReceiveLD();
public: // virtual framework
	IMPORT_C virtual void HandleIrEventL(CEikIrMain* aIrMain, TEikIrEvent aEvent);
private:
	enum TType { ESender, EReceiver };
private:
	TType iType;
	CBeamingStore* iBs;
	CEikEdwin* iEdwin;
	};

inline CEikEdwinBeamer::CEikEdwinBeamer(CEikEdwin* aEdwin) : iEdwin(aEdwin) { }

#endif
