// EIKRNGED.H
//
// Copyright (c) 1997-1999 Symbian Ltd.  All rights reserved.
//

#if !defined(__EIKRNGED_H__)
#define __EIKRNGED_H__

#if !defined(__BACELL_H__)
#include <bacell.h>
#endif

#if !defined(__EIKMFNE_H__)
#include <eikmfne.h>
#endif

class CEikMfneCellRef : public CEikMfneField
	{
public:
	enum
		{
		EPreserveOldWidthBeforeEditing	=0x1,
		EPublicallySettableFlags		=EPreserveOldWidthBeforeEditing
		};
private:
	enum
		{
		EIsBeingEditedWithCursor		=0x2
		};
private:
	CEikMfneCellRef(const TCellRef& aMinimumCellRef, const TCellRef& aMaximumCellRef, TUint32 aFlags);
public:
	IMPORT_C virtual ~CEikMfneCellRef();
	IMPORT_C static CEikMfneCellRef* NewL(const CFont& aFont, TResourceReader& aResourceReader);
	IMPORT_C static CEikMfneCellRef* NewL(const CFont& aFont, const TCellRef& aMinimumCellRef, const TCellRef& aMaximumCellRef, const TCellRef& aInitialCellRef, TUint32 aFlags);
	IMPORT_C void SetMinimumAndMaximum(const TCellRef& aMinimumCellRef, const TCellRef& aMaximumCellRef, const CFont& aFont); // only values inside the initial minimum and maximum are permitted
	IMPORT_C void GetMinimumAndMaximum(TCellRef& aMinimumCellRef, TCellRef& aMaximumCellRef) const;
	IMPORT_C void SetCellRef(const TCellRef& aCellRef, const CFont& aFont);
	IMPORT_C TCellRef CellRef() const;
private: // framework
	virtual TInt MaximumWidthInPixels(const CFont& aFont, TBool aShrinkToMinimumSize);
	virtual TBool IsEditable() const;
	virtual THighlightType HighlightType() const;
	virtual void HandleKey(const CFont& aFont, const TKeyEvent& aKeyEvent, TBool aInterpretLeftAndRightAsEarEvents, TBool& aDataAltered, TInt& aHighlightIncrement);
	virtual void HandleDeHighlight(const CFont& aFont, CEikonEnv& aEikonEnv, TBool& aDataAltered, TBool& aError);
	virtual const TDesC& Text() const;
private:
	TInt MaximumNumberOfLetters(TBool aUseMinimumAndMaximumCateredForInFieldWidth) const;
	TInt MaximumNumberOfDigits(TBool aUseMinimumAndMaximumCateredForInFieldWidth) const;
	TInt NumberOfLetters() const;
	TInt NumberOfDigits() const;
	void SetTextToCellRef(const TCellRef& aCellRef, const CFont& aFont);
	TCellRef CellRefFromText() const;
	TInt RowFromText() const;
	TInt ColumnFromText() const;
private:
	enum {ENumLetters=26}; //!! assumes 26 letters in the alphabet
private:
	TCellRef iMinimumCellRef;
	TCellRef iMaximumCellRef;
	TCellRef iMinimumCellRefCateredForInFieldWidth;
	TCellRef iMaximumCellRefCateredForInFieldWidth;
	TUint32 iFlags;
	HBufC* iText;
	};

class CEikRangeRefEditor : public CEikMfne
	{
public:
	// miscellaneous functions
	IMPORT_C CEikRangeRefEditor();
	// ConstructL to be called by container only if not constructed from resource, also ownership of aSeparatorText is transferred when everything that can leave has successfully been done
	IMPORT_C void ConstructL(const TCellRef& aMinimumCellRef, const TCellRef& aMaximumCellRef, const TRangeRef& aInitialRangeRef, HBufC* aSeparatorText);
	IMPORT_C void SetMinimumAndMaximum(const TCellRef& aMinimumCellRef, const TCellRef& aMaximumCellRef); // only values inside the initial minimum and maximum are permitted
	IMPORT_C void GetMinimumAndMaximum(TCellRef& aMinimumCellRef, TCellRef& aMaximumCellRef) const;
	IMPORT_C void SetRangeRef(const TRangeRef& aRangeRef);
	IMPORT_C TRangeRef RangeRef() const; // can only be called if PrepareForFocusLossL() succeeded
	// framework
	IMPORT_C virtual void ConstructFromResourceL(TResourceReader& aResourceReader);
private:
	virtual void FieldIsAboutToBeDeHighlighted(CEikMfneField* aField, TBool& aDrawAllFields);
private:
	// none of these pointers owns anything
	CEikMfneCellRef* iFrom;
	CEikMfneCellRef* iTo;
	};
#endif
