// EIKLBX.H
//
// Copyright (c) 1997-1999 Symbian Ltd.  All rights reserved.
//

   
#if !defined(__EIKLBX_H__)
#define __EIKLBX_H__

#if !defined(__GDI_H__)
#include <gdi.h>
#endif

#if !defined(__EIKBCTRL_H__)
#include <eikbctrl.h>
#endif

#if !defined(__EIKLBO_H__)
#include <eiklbo.h>
#endif

#if !defined(__EIKSBFRM_H__)
#include <eiksbfrm.h>
#endif

#if !defined(__EIKLBM_H__)
#include <eiklbm.h>
#endif

#if !defined(__EIKLBV_H__)
#include <eiklbv.h>
#endif

#if !defined(__EIKBORDR_H__)
#include <eikbordr.h>
#endif

enum TKeyCode;
class RIncrMatcherBase;
class CListItemDrawer;
class CEikScrollBarFrame;
class CEikButtonBase;
class CMatchBuffer;
class CListBoxExt;

class CEikListBox : public CEikBorderedControl, public MEikScrollBarObserver
	{
public:
	enum TFlags
		{
		EMultipleSelection			= 0x0001,
		ENoExtendedSelection		= 0x0002,
		EIncrementalMatching		= 0x0004,
		EPopout						= 0x0008,
		ELeftDownInViewRect			= 0x0010,
		EItemDoubleClicked			= 0x0020,
		EKeepModel					= 0x0040,
		EScrollBarSizeExcluded		= 0x0080,
		EStateChanged				= 0x0100,
		ECreateOwnWindow			= 0x0200,
		ENoFirstLetterMatching		= 0x0400
		};
	enum {KEikMaxMatchingBufferLength = 22};
public:
	// construction/initialization
	IMPORT_C ~CEikListBox();
	IMPORT_C CEikListBox();
	IMPORT_C void ConstructL(MListBoxModel* aListBoxModel,CListItemDrawer* aListItemDrawer,const CCoeControl* aParent,TInt aFlags = 0);
	IMPORT_C void ConstructL(MListBoxModel* aListBoxModel,CListItemDrawer* aListItemDrawer,const CCoeControl* aParent, TEikBorder aBorder, TInt aFlags = 0);

	IMPORT_C virtual TKeyResponse OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType);
	IMPORT_C virtual void HandlePointerEventL(const TPointerEvent& aPointerEvent);
	IMPORT_C virtual void SetContainerWindowL(const CCoeControl& aContainer);
	IMPORT_C virtual TSize MinimumSize();
	IMPORT_C virtual void SetDimmed(TBool aDimmed);

	IMPORT_C virtual void HandleScrollEventL(CEikScrollBar* aScrollBar, TEikScrollEvent aEventType);

	// model/view access functions 
	IMPORT_C MListBoxModel* Model() const;
	IMPORT_C CListBoxView* View() const;

	// functions for accessing top/current/bottom item index
	IMPORT_C TInt TopItemIndex() const;	 
	IMPORT_C virtual void SetTopItemIndex(TInt aItemIndex) const;
	IMPORT_C TInt BottomItemIndex() const;
	IMPORT_C TInt CurrentItemIndex() const;	  
	IMPORT_C void SetCurrentItemIndex(TInt aItemIndex) const;
	IMPORT_C void SetCurrentItemIndexAndDraw(TInt aItemIndex) const;

	// functions for dealing with the selection state
	IMPORT_C const CListBoxView::CSelectionIndexArray* SelectionIndexes() const;
	IMPORT_C void SetSelectionIndexesL(CListBoxView::CSelectionIndexArray* aArrayOfSelectionIndexes);
	IMPORT_C void ClearSelection();	

	// functions for updating a listbox's internal state after its model has been updated
	IMPORT_C void HandleItemAdditionL();
	IMPORT_C void HandleItemRemovalL();
	IMPORT_C void Reset();

	// functions for accessing the item height
	IMPORT_C virtual void SetItemHeightL(TInt aHeight);
	IMPORT_C TInt ItemHeight() const;

	// functions for scrollbars
	IMPORT_C CEikScrollBarFrame* CreateScrollBarFrameL(TBool aPreAlloc=EFalse);
	IMPORT_C CEikScrollBarFrame* const ScrollBarFrame();
	IMPORT_C void UpdateScrollBarsL();

	// construction support functions
	IMPORT_C void CalculatePopoutRect(TInt aTargetItemIndex, TInt aTargetYPos, TRect& aListBoxRect, TInt aMinHeightInNumOfItems = 1);
	IMPORT_C TSize CalcSizeInPixels(TInt aWidthAsNumOfChars, TInt aHeightAsNumOfItems) const;
	IMPORT_C TInt CalcWidthBasedOnNumOfChars(TInt aNumOfChars) const;
	IMPORT_C TInt CalcHeightBasedOnNumOfItems(TInt aNumOfItems) const;
	IMPORT_C TInt CalcWidthBasedOnRequiredItemWidth(TInt aTextWidthInPixels) const;

	// drawing/scrolling functions
	IMPORT_C void DrawItem(TInt aItemIndex) const;
	IMPORT_C void ScrollToMakeItemVisible(TInt aItemIndex) const;

	// observer support
	IMPORT_C void SetListBoxObserver(MEikListBoxObserver* aObserver);

	IMPORT_C TInt VerticalInterItemGap() const;

	// popouts only
	IMPORT_C void SetLaunchingButton(CEikButtonBase* aButton);
protected:

	IMPORT_C virtual void FocusChanged(TDrawNow aDrawNow);
	IMPORT_C virtual void SizeChangedL();
	IMPORT_C virtual void HandleViewRectSizeChangeL();
	IMPORT_C virtual TInt CountComponentControls() const;
	IMPORT_C virtual CCoeControl* ComponentControl(TInt aIndex) const;

	// functions that implement first letter and incremental matching
	IMPORT_C void CreateMatchBufferL();  // utility function called from RestoreL() of subclasses such as CEikStandardListBox
	IMPORT_C void ClearMatchBuffer() const;
	IMPORT_C void MatchTypedCharL(TUint aCode);
	IMPORT_C void UndoLastChar();

	// functions needed for supporting scrollbars
	IMPORT_C void UpdateScrollBarThumbs() const;
	IMPORT_C virtual TInt HorizScrollGranularityInPixels() const;
	IMPORT_C virtual TInt HorizontalNudgeValue() const;
	IMPORT_C virtual void AdjustTopItemIndex() const;

	// navigation support functions
	IMPORT_C void SimulateArrowKeyEventL(TKeyCode aKeyCode);
	IMPORT_C virtual void HandleLeftArrowKeyL(CListBoxView::TSelectionMode aSelectionMode);
	IMPORT_C virtual void HandleRightArrowKeyL(CListBoxView::TSelectionMode aSelectionMode);

	// construction support functions
	IMPORT_C void RestoreCommonListBoxPropertiesL(TResourceReader& aReader); // utility function called from RestoreL() of subclasses such as CEikStandardListBox
	IMPORT_C void ConstructL(const CCoeControl* aParent,TInt aFlags = 0);
	IMPORT_C virtual void CreateViewL();
	IMPORT_C virtual CListBoxView* MakeViewClassInstanceL();
	IMPORT_C void SetViewRectFromClientRect(const TRect& aClientRect);
	IMPORT_C virtual void RestoreClientRectFromViewRect(TRect& aClientRect) const;
	IMPORT_C virtual TInt AdjustRectHeightToWholeNumberOfItems(TRect& aRect) const;

	// various accessors for private data members
	IMPORT_C TInt HorizontalMargin() const;
	IMPORT_C TInt VerticalMargin() const;
	IMPORT_C void SetHorizontalMargin(TInt aMargin);
	IMPORT_C void SetVerticalMargin(TInt aMargin);
	IMPORT_C RIncrMatcherBase* MatchBuffer() const;
	IMPORT_C TInt ViewRectHeightAdjustment() const;
	IMPORT_C TRgb BackColor() const;

	// misc functions
	IMPORT_C virtual void ReportListBoxEventL(MEikListBoxObserver::TListBoxEvent aEvent);
	IMPORT_C virtual void Draw(const TRect& aRect) const;
	IMPORT_C void ClearMargins() const;
	IMPORT_C virtual void UpdateCurrentItem(TInt aItemIndex) const;
	IMPORT_C virtual void HandleDragEventL(TPoint aPointerPos);
	IMPORT_C TBool ItemExists(TInt aItemIndex) const;
	IMPORT_C void DrawMatcherCursor() const;

	TBool IsMatchBuffer() const;
	void CheckCreateExtensionL();
	TBool CheckCreateExtension();
	void CheckCreateBufferL();
	CMatchBuffer* Buffer() const;
private: // from CCoeControl
	IMPORT_C void Reserved_1();
	IMPORT_C void Reserved_2();
private:
	IMPORT_C virtual void Reserved_3(); // listbox use only
	void HorizontalScroll(TInt aScrollAmountInPixels);
	void CreateScrollBarFrameLayout(TEikScrollBarFrameLayout& aLayout) const;
protected:
	enum {KEikListBoxInterItemGap = 2};
	TInt iListBoxFlags;
	CListBoxView* iView;
	CListItemDrawer* iItemDrawer;
	MListBoxModel* iModel;
	TInt iItemHeight; 	
	CEikScrollBarFrame* iSBFrame;
	TInt iRequiredHeightInNumOfItems;
	CEikButtonBase* iLaunchingButton; // only used by popouts
	MEikListBoxObserver* iListBoxObserver;
private:
	TRgb iBackColor;
	TInt iHorizontalMargin;
	TInt iVerticalMargin;
	CListBoxExt* iListBoxExt;
	TInt iViewRectHeightAdjustment;
	};


class CEikSnakingListBox : public CEikListBox  
	{
public:
	IMPORT_C CEikSnakingListBox();
	IMPORT_C ~CEikSnakingListBox();
	IMPORT_C virtual CListBoxView* MakeViewClassInstanceL();
	IMPORT_C virtual void SetTopItemIndex(TInt aItemIndex) const;
   	IMPORT_C TInt ColumnWidth() const;
	IMPORT_C void SetColumnWidth(TInt aColumnWidth);
protected:
	IMPORT_C virtual void SizeChangedL();
	IMPORT_C virtual void HandleViewRectSizeChangeL();
	IMPORT_C virtual void HandleLeftArrowKeyL(CListBoxView::TSelectionMode aSelectionMode);
	IMPORT_C virtual void HandleRightArrowKeyL(CListBoxView::TSelectionMode aSelectionMode);
	IMPORT_C virtual TInt HorizontalNudgeValue() const;
	IMPORT_C virtual TInt HorizScrollGranularityInPixels() const;
	IMPORT_C virtual void AdjustTopItemIndex() const;
	IMPORT_C virtual void HandleDragEventL(TPoint aPointerPos);
	IMPORT_C virtual void RestoreClientRectFromViewRect(TRect& aClientRect) const;
	IMPORT_C virtual TInt AdjustRectHeightToWholeNumberOfItems(TRect& aRect) const;
	IMPORT_C void MoveToNextOrPreviousItemL(TPoint aPoint);
private: // from CCoeControl
	IMPORT_C void Reserved_1();
	IMPORT_C void Reserved_2();
private: // from CEikListBox
	IMPORT_C void Reserved_3(); // listbox use only
	};


#endif




