#if !defined(AFX_TIMEFRAME_H__CE016E2E_D389_4C15_8732_8CE58363E9E3__INCLUDED_)
#define AFX_TIMEFRAME_H__CE016E2E_D389_4C15_8732_8CE58363E9E3__INCLUDED_

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

#include "timetoolbar.h"
#include "idcontainer.h"

class CGosViewDoc;
#include "ZoomDialog.h"

/////////////////////////////////////////////////////////////////////////////
// CTimeFrame frame

class CTimeFrame : public CMDIChildWnd
{
	DECLARE_DYNCREATE(CTimeFrame)
protected:

	CSplitterWnd	m_wndSplitter;
	CReBar			m_wndReBar;

	CZoomDialog		m_wndZoomDialog;
	CComboBox *		m_pZoomUnits;
	// CSliderCtrl *	m_pZoomSlider;

	CTimeFrame();           // protected constructor used by dynamic creation

// Attributes
public:

	int m_nNumRowsVisible;
	int m_nTopVisibleRow;
	double m_rRowHeight;
	int m_nNumBandColors;
	int m_nNumEnabledBands;
	CBrush *m_pBandColor;
	bool m_fChildrenReady;
	CGosViewDoc *m_pDoc;
	_int64 m_tVisibleStart;
	_int64 m_tVisibleEnd;
	bool m_fAlphaSort;			// sort by name (not ID)
	bool m_fFullNames;




	void AddId( DWORD id );
	void UpdateAllIds();
	CReBar *ReBar() { return &m_wndReBar; }

	struct TagNode
	{
		DWORD	id;
		DWORD	idParent;
		DWORD	idChild;
		DWORD	idSibling;
		bool	expand;
		bool	onScreen;
		bool	independent;	// false means this is shown in parent's slot
		int		screenY;
		int		indent;			// 0 = no parents, 1=1 parent,..
		DWORD	idNextEnabled;	// this is the linked list in the order of visibility
		// Used for stats:

		int		countEntry;
		_int64	sumTicks;
		TagNode *pAssignTo;		// pointer to tag to accumulate these events
	};

	IDContainer<TagNode>	m_TagList;		// these have 1:1 relationship with Doc's m_TagInfo
	IDContainer<TagNode>	m_ParentList;	// these are for dummy parents created for treeview
	DWORD					m_FirstID;		// id (or 0) of first tag whose parent id is 0
	int						m_nNumParentNames;	// number of entries in m_aParentName
	char					m_aParentName[400][80];
	DWORD					m_aParentID[400];	// TBD - fix these consts !!
	int						m_nOldParentNames;
	char					m_aOldParentName[400][80];
	bool					m_aOldParentExpand[400];	// TBD - fix these consts !!

	int						m_VScrollPos;	// VScroll position maintained by trace pane
	
	void ProcessNewLog();
	void DetermineVisibleTags();
	void AnalyzeTagNodes();

	CZoomDialog *ZoomDialog() { return &m_wndZoomDialog; }

	void CTimeFrame::SortAndAddParents();
	void AddToChildrenOf( DWORD idParent, char *pName, DWORD id, TagNode *pNode );
	char *AnyIDToName( DWORD id );
	TagNode *AnyIDToTag( DWORD id );
	DWORD IDFindOrAddParent( DWORD idParent, char *pName );

	void SetDocument( CGosViewDoc *pDoc ) { m_pDoc = pDoc; }

	int CompareID( char *pName, DWORD id, DWORD oldID );



// Operations
public:

// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CTimeFrame)
	protected:
	virtual BOOL OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext);
	virtual BOOL OnNotify(WPARAM wParam, LPARAM lParam, LRESULT* pResult);
	//}}AFX_VIRTUAL

// Implementation
protected:
	virtual ~CTimeFrame();

	// Generated message map functions
	//{{AFX_MSG(CTimeFrame)
	afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
	afx_msg void OnSetFocus(CWnd* pOldWnd);
	afx_msg void OnSize(UINT nType, int cx, int cy);
	afx_msg void OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
	afx_msg void OnButton1();
	afx_msg void OnAlphaSort();
	afx_msg void OnUpdateAlphaSort(CCmdUI* pCmdUI);
	afx_msg void OnNumSort();
	afx_msg void OnUpdateNumSort(CCmdUI* pCmdUI);
	afx_msg void OnFullNames();
	afx_msg void OnUpdateFullNames(CCmdUI* pCmdUI);
	afx_msg void OnPartNames();
	afx_msg void OnUpdatePartNames(CCmdUI* pCmdUI);
	afx_msg void OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

/////////////////////////////////////////////////////////////////////////////

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

#endif // !defined(AFX_TIMEFRAME_H__CE016E2E_D389_4C15_8732_8CE58363E9E3__INCLUDED_)
