// EIKSCRLB.H
//
// Copyright (c) 1997-1999 Symbian Ltd.  All rights reserved.
//
	 	
#if !defined(__EIKSCRLB_H__)
#define __EIKSCRLB_H__

#if !defined(__EIKBCTRL_H__)
#include <eikbctrl.h>
#endif

#if !defined(__EIKSBOBS_H__)
#include <eiksbobs.h>
#endif

#if !defined(__EIKSCBUT_H__)
#include <eikscbut.h>
#endif

const TInt KEikScrollEventFromVBar=0;
const TInt KEikScrollEventFromHBar=0x01;
const TInt KEikScrollEventBarMask=0x01;


const TInt KButtonPositionMask=0xc0; // sets all bits in EButtonsXxx range
const TInt KDisplayComponentsMask=0x1f; // sets all bits in determining which components exist

//
// TEikScrollBarModel class
//

class TEikScrollBarModel
	{
public:
	inline TEikScrollBarModel();
	IMPORT_C TEikScrollBarModel(TInt aScrollSpan,TInt aThumbSpan=0,TInt aThumbPosition=0);
	// operators
	IMPORT_C TBool operator==(const TEikScrollBarModel aModel) const;
	inline TBool operator!=(const TEikScrollBarModel aModel) const; 
public:
	IMPORT_C TBool ScrollBarUseful() const;
	IMPORT_C TInt MaxThumbPos() const;
	IMPORT_C void CheckBounds();
public:
	TInt iScrollSpan;
	TInt iThumbSpan;
	TInt iThumbPosition;		
	};

inline TEikScrollBarModel::TEikScrollBarModel() {}
inline TBool TEikScrollBarModel::operator!=(const TEikScrollBarModel aModel) const { return !(*this==aModel); }

//
// CEikScrollBar class
//

class CEikScrollButton;
class CEikScrollThumb;
  
class CEikScrollBar : public CEikBorderedControl
	{
public:
	enum TOrientation
		{
		EVertical,
		EHorizontal
		};
	enum 
		{
		EScrollbarWidth=23,
		};
public: // inherited
	IMPORT_C ~CEikScrollBar();
	IMPORT_C CEikScrollBar();
	IMPORT_C virtual void HandlePointerEventL(const TPointerEvent& aPointerEvent);
	IMPORT_C virtual void Draw(const TRect& aRect) const;
	IMPORT_C virtual void ActivateL();
	IMPORT_C virtual void SetDimmed(TBool aDimmed);
public:
	// second phase construction
	IMPORT_C void ConstructL(MEikScrollBarObserver* aScrollBarObserver,const CCoeControl* aParent,
				TOrientation aOrientaion,TInt aLength,TInt aScrollBarFlags);

	// set state functions
	IMPORT_C void SetLengthL(TInt aLength);
	IMPORT_C void SetModelL(const TEikScrollBarModel* aModel);
	IMPORT_C void SetLengthAndModelL(TInt aLength,const TEikScrollBarModel* aModel);
	IMPORT_C void SetModelThumbPosition(TInt aThumbPos);

	// information retreival functions
	inline const TEikScrollBarModel* Model() const {return &iModel;}
	IMPORT_C TInt ThumbPosition() const;
	IMPORT_C TInt ScrollBarBreadth() const;
	IMPORT_C static TInt MinVisibleLength(const TInt aScrollBarFlags);

	// Button dimming functions
	IMPORT_C void SetDecreaseButtonsDimmed(TBool aDimmed);
	IMPORT_C void SetIncreaseButtonsDimmed(TBool aDimmed);
	IMPORT_C void SetAllButtonsDimmed(TBool aDimmed);
private: // virtual - reserved from CCoeControl
	IMPORT_C virtual void Reserved_1();
	IMPORT_C virtual void Reserved_2();
private:
	friend class CEikScrollBarFrame;
	// enums
	enum TPrivateScrollBarFlags
		{
		ENoComponentsToDisplay		=0x10000,
		EIncreaseButtonsDimmed		=0x20000,
		EDecreaseButtonsDimmed		=0x40000
		};
	enum TPointerDownOn
		{
		ENone,
		EHomeButton,
		EDecreasePageButton,
		EDecreaseNudgeButton,
		EDecreaseShaft,
		EThumb,
		EIncreaseShaft,
		EIncreaseNudgeButton,
		EIncreasePageButton,
		EEndButton
		};
	enum TShaftRedrawRequired
		{
		ENoRedrawRequired,
		ERedrawShaft
		};
	enum TWhichButtons
		{
		EIncreaseOnly,
		EDecreaseOnly,
		EAll
		};
	enum {EMinThumbLength=0x10};
	struct SEikScrollBarButtons
		{
		CEikScrollButton* iHome;
		CEikScrollButton* iDecreasePage;
		CEikScrollButton* iDecreaseNudge;
		CEikScrollButton* iIncreaseNudge;
		CEikScrollButton* iIncreasePage;
		CEikScrollButton* iEnd;
		};
public:
	enum TEikScrollBarFlags
		{
		EEikScrollBarNoNudgeButtons		=0x01,
		EEikScrollBarHasPageButtons		=0x02,
		EEikScrollBarHasHomeEndButtons	=0x04,
		EEikScrollBarNoShaftOrThumb		=0x08,
		EEikScrollBarShaftButNoThumb	=0x10,	// Default is ShaftAndThumb
		EButtonsAtStartOfShaft			=0x40,
		EButtonsAtEndOfShaft			=0x80,
		EButtonsEitherSideOfShaft		=EButtonsAtStartOfShaft|EButtonsAtEndOfShaft,
		ENoAutoDimming		=0x100
		};
private:

	// construction/destruction
	void CreateRequiredComponentsL();
	void CreateButtonL(CEikScrollButton*& aButton,CEikScrollButton::TType aType);
	void DestroyButton(CEikScrollButton*& aButton);

	// pointer event functions
	void HandleShaftEventL(const TPointerEvent& aPointerEvent, TPointerDownOn aLastPointerDownOn);
	void HandleButtonEventL(const TPointerEvent& aPointerEvent, CEikScrollButton* aButton);

	// drawing functions
	void DrawButtons(TWhichButtons aWhich) const;
	void DrawButtonsNow(TWhichButtons aWhich) const;
	void DrawShaft(CWindowGc& aGc) const;
	void DrawShaftNow() const;
	void DrawThumbInShaft(CWindowGc& aGc) const;
	void DrawThumbInShaftNow() const;
	void RedrawShaft(const TRect& aRect) const;

	// set state functions
	void MoveResizeThumbL(TShaftRedrawRequired aShaftRedrawRequired=ENoRedrawRequired);
	void NewThumbAtPixelL();
	void MoveThumbToPixel(TInt aPos);
	void UpdateThumbL();
	void UpdateButtonsL();
	void SetButtonPositionL(CEikScrollButton* aButton);
	void SetButtonAdjacency(CEikScrollButton* aButton);
	void DoSetLengthL(TInt aLength);
	void DoSetModel(const TEikScrollBarModel* aModel);
	void SetLayoutL();

	// calculation
	TInt CalcThumbPixelPos() const;
	TInt CalcThumbModelPos() const;
	TInt MinReqLengthToDisplay() const;
	void CalcDisplayFlags();
	void AddShaftIfPossible(TInt aExcessSpace);
 	void CheckModelBounds();

	// misc
	TInt NumberOfButtonPairs(TBool aUseDisplayFlags=EFalse) const;
	void GetShaftRect(TRect& aRect) const; 
	void CheckAutoButtonDimming(TDrawNow aDrawNow=EDrawNow);
	TPointerDownOn ResolveButtonPress(TInt aPos);
	TPointerDownOn GeneralizeButtonType(CEikScrollButton::TType aType) const;
	void ReportScrollEventL(TEikScrollEvent aEvent);
private:
	MEikScrollBarObserver* iScrollBarObserver;
	CEikScrollThumb* iThumb;
	SEikScrollBarButtons iButtons;
	TEikScrollBarModel iModel;
	TPointerDownOn iPointerDownOn;
	TOrientation iOrientation;
	TInt iScrollBarFlags;
	TInt iScrollBarDisplayFlags;
	// following quantities all in pixels
	TInt iLength;
	TInt iThumbLength;
	TInt iThumbPos;
	TInt iShaftStart;
	TInt iShaftEnd;
	TInt iDecreaseButtonsStart;
	TInt iIncreaseButtonsStart;
	TInt iDecreaseButtonsEnd;
	TInt iIncreaseButtonsEnd;
	TInt iPointerOffsetFromThumb;
	};


#endif
