
#pragma once

#include "ViewTree.h"

#include "P2PeerTarget.h"
#include "P2PmsgTreeCtrl.h"

class CFileViewToolBar : public CMFCToolBar
{
	virtual void OnUpdateCmdUI(CFrameWnd* /*pTarget*/, BOOL bDisableIfNoHndler)
	{
		CMFCToolBar::OnUpdateCmdUI((CFrameWnd*) GetOwner(), bDisableIfNoHndler);
	}

	virtual BOOL AllowShowOnList() const { return FALSE; }
};

class CFileView : public CDockablePane, public P2PeerTarget
{
// Construction
public:
	CFileView();

	void AdjustLayout();
	void OnChangeVisualStyle();

    // Attributes
    protected:
	    CP2PmsgTreeCtrl    m_wndP2PmsgTreeCtrl;
      //CViewTree          m_wndFileView;
	    CImageList         m_FileViewImages;
	    CFileViewToolBar   m_wndToolBar;

protected:
	void FillFileView();

// Implementation
public:
	virtual ~CFileView();

    // Operations
    public:
      void
        ClearViewContents ( );
      void
        RefreshView ( );
      void
        PostSQLSelect ( LPCTSTR lpszMsgReply, LPCTSTR lpszSQLstmt
                      , P3PmsgField *pMsgRepyTag = 0 );
      void
        QueryVisuals ( HTREEITEM hItem, BOOL bEoD );
      void
        QueryDatabases ( P3PmsgNode& oDatabases );
      void
        QueryTables ( P3PmsgNode& oTables );
      void
        QueryTable ( P3PmsgNode& oTable );
      void
        QueryColumns ( P3PmsgNode& oColumns );
      void
        QueryViews ( P3PmsgNode& oViews );
      void
        QueryView ( P3PmsgNode& oView );
      void
        QueryVColumns ( P3PmsgNode& oVColumns );
      void
        QueryStoredProcs ( P3PmsgNode& oStoredProcs );
      void
        QueryFunctions ( P3PmsgNode& oFunctions );

    // Attributes
    protected:
      P2Pos  m_nP2PosDatabases;

    // P2PeerMsg_MAP handlers
    // NOTES: Placemarker for map
    protected:
	  DECLARE_P2PeerMsg_MAP()
      msgRESULT
        On_SQLselectServerProperty ( P2PeerMsg *pMsg );
      msgRESULT
        On_SQLselectCatch ( P2PeerMsg *pMsg );
      msgRESULT
        On_SQLselectDatabaseItem ( P2PeerMsg *pMsg );
      msgRESULT
        On_SQLselectTableListItem ( P2PeerMsg *pMsg );
      msgRESULT
        On_SQLselectColumnListItem ( P2PeerMsg *pMsg );
      msgRESULT
        On_SQLselectViewListItem ( P2PeerMsg *pMsg );
      msgRESULT
        On_SQLselectViewColumnListItem ( P2PeerMsg *pMsg );
      msgRESULT
        On_SQLselectStoredProcListItem ( P2PeerMsg *pMsg );
      msgRESULT
        On_SQLselectFunctionListItem ( P2PeerMsg *pMsg );

    // MFC message map
    protected:
      afx_msg int
        OnCreate ( LPCREATESTRUCT lpCreateStruct );
      afx_msg void
        OnSize ( UINT nType, int cx, int cy );
      afx_msg void
        OnContextMenu ( CWnd* pWnd, CPoint point );

      afx_msg LRESULT
        OnConnectSQLserver ( WPARAM wParam, LPARAM lParam );
      afx_msg LRESULT
        OnDisconnectSQLserver ( WPARAM wParam, LPARAM lParam );

      afx_msg void
        OnTvnItemExpanding ( NMHDR *pNMHDR, LRESULT *pResult );
      afx_msg void
        OnTvnGetDispInfo ( NMHDR *pNMHDR, LRESULT *pResult );

	afx_msg void OnProperties();
	afx_msg void OnFileOpen();
	afx_msg void OnFileOpenWith();
	afx_msg void OnDummyCompile();
	afx_msg void OnEditCut();
	afx_msg void OnEditCopy();
	afx_msg void OnEditClear();
	afx_msg void OnPaint();
	afx_msg void OnSetFocus(CWnd* pOldWnd);

	DECLARE_MESSAGE_MAP()
public:
      afx_msg void
        OnTableSelectTop1000rows ( );
      afx_msg void
        OnViewSelectTop1000rows ( );
      afx_msg void
        OnUpdateTableSelectTop1000rows(CCmdUI *pCmdUI);
      afx_msg void
        OnItemRefresh ( );
      afx_msg UINT OnNotifyFormat(CWnd *pWnd, UINT nCommand);
};

