// EIKFBROW.H
//
// Copyright (c) 1997-1999 Symbian Ltd.  All rights reserved.
//

#if !defined(__EIKFBROW_H__)
#define __EIKFBROW_H__

#if !defined(__EIKLBO_H__)
#include <eiklbo.h>
#endif

#if !defined(__EIKBCTRL_H__)
#include <eikbctrl.h>
#endif

#if !defined(__COECOBS_H__)
#include <coecobs.h>
#endif

#if !defined(__COECCNTX_H__)
#include <coeccntx.h>
#endif

#if !defined(__EIKDIALG_H__)
#include <eikdialg.h>
#endif

#if !defined(__EIKDCLBM_H__)
#include <eikdclbm.h>
#endif

class CEikButtonPanel;
class CEikCaptionedControl;
class CEikDirectoryTreeListBox;
class CEikDirContentsListBox;
class MDesCArray;

class CEikFileBrowser : public CEikBorderedControl, private MCoeControlObserver, private MEikListBoxObserver
    {
private:
	class CFileUpdateReporter;
friend class CFileUpdateReporter;
friend class CEikFileBrowserDialog;
public:
	enum
		{
		EHideRom		=0x0001,
		EOwnsWindow		=0x0002
		};
	enum TContent
		{
		EShowSystem		=0x0020,
		EShowHidden		=0x0040
		};
public:
	IMPORT_C CEikFileBrowser();
	IMPORT_C CEikFileBrowser(const TDesC& aDefaultPath);
	IMPORT_C ~CEikFileBrowser();
	IMPORT_C void ConstructL(TUint aFlags,TInt aNumVisibleItems,TInt aDirTreeWidthInPixels,TInt iDirContentsWidthInPixels);
	IMPORT_C TFileName CurrentPath() const;
	IMPORT_C void SetCurrentPathL(const TDesC& aPath);
	IMPORT_C void UpdateL();
	IMPORT_C void HandleErrorFromFileServerL(TInt aErrorCode);
	IMPORT_C CEikDirectoryTreeListBox* DirTreeList() const;
	IMPORT_C CEikDirContentsListBox* DirContentsList() const;
	IMPORT_C void SetSortOrder(CDirContentsListBoxModel::TSortOrder aOrder);
	IMPORT_C CDirContentsListBoxModel::TSortOrder SortOrder() const;
public: // from CCoeControl
    IMPORT_C TKeyResponse OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType);
	IMPORT_C void ConstructFromResourceL(TResourceReader& aReader);
	IMPORT_C TSize MinimumSize();
	IMPORT_C void ActivateL();
private: // from MCoeControlObserver
    IMPORT_C void HandleControlEventL(CCoeControl* aControl,TCoeEvent aEventType);
private: // from MEikListBoxObserver
	IMPORT_C void HandleListBoxEventL(CEikListBox* aListBox,TListBoxEvent aEventType);
private: // from CCoeControl
    IMPORT_C void Draw(const TRect& aRect) const;
	IMPORT_C TInt CountComponentControls() const;
	IMPORT_C CCoeControl* ComponentControl(TInt aIndex) const;
	IMPORT_C void FocusChanged(TDrawNow aDrawNow);
	IMPORT_C void SizeChangedL();
	IMPORT_C void Reserved_1();
	IMPORT_C void Reserved_2();
private:
	void CreateDrivesListL();
	void CreateListOfAvailableDrivesL();
	void CreateDirTreeListBoxL(TInt aNumVisibleItems,TInt aWidthInPixels);
	void CreateDirContentsListBoxL(TInt aNumVisibleItems,TInt aWidthInPixels);
	void CreateSortOrderButtonsL();
	void UpdateDirContentsListBoxL();
	void HandleChangeInDirTreeSelection();
	void SwitchFocusTo(CCoeControl* aControl);
	void SetDriveSelectorState(const TDesC& aDriveLetter);
	TBuf<1> CurrentDrive() const;
	void PopulateListsL();
	void ClearListsL();
	void StartUpdateTimer();
	static TInt IdleL(TAny *aPtr);
	static TInt UpdateTimerCallBackL(TAny* aThis);
	static TInt PopulateListsCallBackL(TAny* aThis);
	void LayoutControlsL(const TSize& aSize,const TPoint& aStartPos);
	void CreateDrivesOpButGroupL();
	void HandleChangeInDirContentsCurrentPathL();
	void HandleDriveChangedL();
	void HandleSortOrderChangedL();
	void DoSetCurrentPathL(const TDesC& aPath,TBool aExpandAll);
private:
	enum TFlags
		{ EUpdateOnFocus		=0x0080 };
	enum TSortOrder
		{
		EOrderByName	=0x0000,
		EOrderBySize	=0x0004,
		EOrderByDate	=0x0008,
		EOrderByType	=0x0010
		};
private:
	CEikDirectoryTreeListBox* iDirTreeListBox;
	CEikDirContentsListBox* iDirContentsListBox;
	CEikCaptionedControl* iDrivesList;
	CEikCaptionedControl* iSortOrderButtons;
	TEikButtonCoordinator iButCoord;
	CCoeControl* iFocusControl;
	MDesCArray* iDriveNames;
	CFileUpdateReporter* iFileUpdateReporter;
	CIdle* iFileListPopulate;
	CIdle* iFileListUpdate;
	CPeriodic* iUpdateTimer;
	CIdle* iIdle;
	TTime iLastUnhandledErrorTime;
	TFileName iDefaultPath;
	TUint iFileSelFlags;
	RFs iFsSession;
	TInt iDirTreeWidth;
	TInt iDirContentsWidth;
	TInt iNumVisibleItems;
	MCoeControlBrushContext iBrushContext;
	};

class CEikFileBrowserDialog : public CEikDialog
	{
public:
	enum TFlags
		{
		EHideRom				=0x0001,
		EShowSystem				=0x0020,
		EShowHidden				=0x0040,
		EAllowFolderCreation	=0x0100
		};
public:
	IMPORT_C CEikFileBrowserDialog(TDes& aPath,TUint aFlags,CDirContentsListBoxModel::TSortOrder& aOrder);
private: // from CEikDialog
	void PreLayoutDynInitL();
	TBool OkToExitL(TInt aButtonId);
private:
	void LaunchCreateFolderDialogL();
	void UpdateForNewFolderL(TDes& aNewFolderPath);
private:
	TDes& iPath;
	TUint iBrowseFlags;
	CDirContentsListBoxModel::TSortOrder& iSortOrder;
	};

class CEikNewFolderDialog : public CEikDialog
	{
public:
	IMPORT_C CEikNewFolderDialog(TFileName& aPath);
private: // from CEikDialog
	void PreLayoutDynInitL();
	TBool OkToExitL(TInt aButtonId);
private:
	TFileName& iPath;
	};

#endif
