
/*	Copyright (C) G. Jespersen
	See Licence.txt.*/

#if !defined(AFX_DSLAVTREEVIEW_H__9DE701C0_B9B6_4EE1_B8CA_FEDEFCBA3711__INCLUDED_)
#define AFX_DSLAVTREEVIEW_H__9DE701C0_B9B6_4EE1_B8CA_FEDEFCBA3711__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// DsLavTreeView.h : header file
//

#include "DsLavSplitterView.h"
#include <afxcview.h> // CtreeView

// Foreward
class CDsLavListView;

/////////////////////////////////////////////////////////////////////////////
// CDsLavTreeView view

class CDsLavTreeView : public CTreeView
{
protected:
	CDsLavTreeView();           // protected constructor used by dynamic creation
	DECLARE_DYNCREATE(CDsLavTreeView)

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CDsLavTreeView)
	public:
	virtual void OnInitialUpdate();
	protected:
	virtual void OnDraw(CDC* pDC);      // overridden to draw this view
	virtual void OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint);
	//}}AFX_VIRTUAL


	// Generated message map functions
	//{{AFX_MSG(CDsLavTreeView)
	afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
	afx_msg void OnItemexpanding(NMHDR* pNMHDR, LRESULT* pResult);
	afx_msg void OnSelchanged(NMHDR* pNMHDR, LRESULT* pResult);
	afx_msg void OnBegindrag(NMHDR* pNMHDR, LRESULT* pResult);
	afx_msg void OnMouseMove(UINT nFlags, CPoint point);
	afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
	afx_msg void OnTimer(UINT nIDEvent);
	afx_msg void OnContextMenu(CWnd* pWnd, CPoint point);
	afx_msg void OnRclick(NMHDR* pNMHDR, LRESULT* pResult);
	afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
	afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
	//}}AFX_MSG

	//afx_msg void OnBeginDrag(NMHDR* pnmhdr, LRESULT* pResult); mfcdrag
	DECLARE_MESSAGE_MAP()

// Attributes
public:
	BOOL m_bInitialized;

	// See DsLavSplitter
	CDsLavDoc* GetDocument();

protected:
	CDsLavListView * GetListViewPtr();

	// Drag and Drop:
	int		m_nDelayInterval;
	int		m_nScrollMargin;
	int		m_nScrollInterval;
	BOOL		m_bDragging;
	CImageList  m_imageList;
	CImageList* m_pImageList;
	HTREEITEM	m_hDragItem;
	MOVE_TYPE	m_moveType;		// 9/22-1

	// Move Up-Down.
	BOOL		m_bMoving;
	BOOL		m_bDrawAfter;
	BOOL		m_bSkipMouse;
	HTREEITEM	m_hItemMoveSrc;
	HTREEITEM	m_hItemMoveDest;

	// Deleted topic's expanded parent. 
	CNodeArray m_expParentNodeAr;

private:
	// Control calls to OnItemexpanding();
	BOOL m_manualExpand;

// Operations
protected:
	// Tree handling
	BOOL AddRootTopics();
	BOOL GetTopicNodesFromItem(HTREEITEM hItem, CNodeArray & nodesAr);
	void DeleteFirstChild(HTREEITEM hItem);
	int	 DeleteAllChildren(HTREEITEM hItem);

	// Dvd, drives etc,
	int AddDrives();
	void UpdateDrives(CString drive, BOOL inserted);
	BOOL AddDriveItem(CString & strDrive);
	BOOL SetButtonState(HTREEITEM hItem, CString strDrivePath);
	BOOL IsDrive(HTREEITEM hItem);
	BOOL IsDrive(CString strPath);
	BOOL IsDrive(CNodeArray & nodesAr);
	int	 AddDriveDirectories(HTREEITEM hItem, CString strDrivePath);
	CStringArray m_driveStrings;

	// Find - Select.
	HTREEITEM SelectTopic(const CString & strTopic);
	HTREEITEM SelectTopic(const CStringArray & nodeAr);
	HTREEITEM SelectTopic(const CNodeArray & nodeAr);
private:
	HTREEITEM SelectChildTopic(const CString & strTopic, HTREEITEM hParentItem);
	HTREEITEM SelectChildTopic(HTREEITEM hParentItem, 
							   const CStringArray & nodeAr, int iNode);
	// Drag and Drop:
	//  See: TreeDemo - MSDN, August 1998 Prosise
protected:
	HTREEITEM HighlightDropTarget(CPoint point);
	BOOL		IsItemExpanded(HTREEITEM hItem);
	void		CopyChildren (HTREEITEM hDest, HTREEITEM hSrc);
	void		MoveTreeItems(HTREEITEM hDest, HTREEITEM hSrc);
	void		CopyTree(HTREEITEM hDest, HTREEITEM hSrc);
	BOOL		IsChildOf(HTREEITEM hItem1, HTREEITEM hItem2);

	// Drop from list ListView.
public:
	void ListViewDropMediaItem(int iSrcListIndex, HTREEITEM hDestTreeItem);
	void ListViewDropMediaItemMulti(CDWordArray & iSrcListIndexAr, HTREEITEM hDestTreeItem);

private:
	// Moving up or down.
	BOOL MoveBeforeFirstSibling(HTREEITEM hItem, CPoint ptScreen);
	void MoveTopicKeyboard(UINT nChar); 
	void MoveTopicKeyboardFinish();
	void MoveTopicCancel();
	void MoveTopicSetInitialMark();

public:
	CFont m_font;

// Implementation
protected:
	virtual ~CDsLavTreeView();
#ifdef _DEBUG
	virtual void AssertValid() const;
	virtual void Dump(CDumpContext& dc) const;
#endif
};

// See CDsLavTreeView
#ifndef _DEBUG  // debug version in DsLavTreeView.cpp
inline CDsLavDoc* CDsLavTreeView::GetDocument()
   { return (CDsLavDoc*)m_pDocument; }
#endif

///////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_DSLAVTREEVIEW_H__9DE701C0_B9B6_4EE1_B8CA_FEDEFCBA3711__INCLUDED_)
