// SchemeView.h : interface of the CSchemeView class
//


#pragma once

#define WM_UPDATEVIEW	WM_USER + 5

#include <set>
#include <map>
#include "SchemeDoc.h"
#include "ViewersDoc.h"
#include "..\\global\\iviewer.h"

class IViewer;

class CSchemeView : public CView
{
protected: // create from serialization only
	CSchemeView();
	DECLARE_DYNCREATE(CSchemeView)

// Attributes
public:
	CSchemeDoc* GetDocument() const;

// Operations
public:

// Overrides
public:
	virtual void OnDraw(CDC* pDC);  // overridden to draw this view
	virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
protected:

// Implementation
public:
	virtual ~CSchemeView();
#ifdef _DEBUG
	virtual void AssertValid() const;
	virtual void Dump(CDumpContext& dc) const;
#endif

protected:

// Generated message map functions
protected:
	DECLARE_MESSAGE_MAP()
public:
//	afx_msg void OnViewBlockstoolbar();
//	afx_msg void OnUpdateViewBlockstoolbar(CCmdUI *pCmdUI);
	virtual void OnInitialUpdate();

private:
	COleDropTarget m_oleDropTgt;
	UINT m_nClipboardFormat;
	CBlockItem_Virtual* m_pThisBlock;
	struct
	{
		DWORD dwState;
		Point selPoint;
		Size selSize;
		BOOL bMoved;
		BOOL bSelectOnBtnRls;
		CBlockItem *pConFrom;
		CBlockItem *pConTo;
		DWORD dwPortFrom;
		DWORD dwPortTo;
		std::set<CBlockItem*> setSelection;
		std::map<CBlockItem*, POINTF> mapMoveData;
	}m_sUserData;

	inline BOOL DrawBlock(CDC* pDC, CBlockItem* ptr, DWORD dwState = 0);
	inline BOOL DrawWires(CDC* pDC, CBlockItem* ptr);
	inline BOOL GetPortRect(CBlockItem* ptr, DWORD dwPort, Rect *rc, BOOL bOutput);
	inline BOOL GetPortRect(CBlockItem* ptr, DWORD dwPort, CRect *rc, BOOL bOutput);
	inline Point GetPortCenter(CBlockItem* ptr, DWORD dwPort, BOOL bOutput);
	inline BOOL DrawSelection(CDC* pDC);
	inline BOOL GetBlockRect(CBlockItem* ptr, LPRECT pRcTgt);
	inline BOOL UpdateSelection();
	CBlockItem* GetBlockOnPos(CPoint p);
	BOOL IsPortOnPos(CPoint p, CBlockItem* ptr, LPDWORD pdwPort, LPBOOL pbOutput);
public:
	virtual DROPEFFECT OnDragEnter(COleDataObject* pDataObject, DWORD dwKeyState, CPoint point);
	virtual void OnDragLeave();
	virtual DROPEFFECT OnDragOver(COleDataObject* pDataObject, DWORD dwKeyState, CPoint point);
	virtual BOOL OnDrop(COleDataObject* pDataObject, DROPEFFECT dropEffect, CPoint point);
	CBlockItem_Virtual* GetThisBlock();
	BOOL SetThisBlock(CBlockItem_Virtual* ptr);
	BOOL RefreshAllViewers(DWORD dwType);
protected:
	virtual void OnUpdate(CView* /*pSender*/, LPARAM /*lHint*/, CObject* /*pHint*/);
public:
	afx_msg BOOL OnEraseBkgnd(CDC* pDC);
	afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
	afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
	afx_msg void OnMouseMove(UINT nFlags, CPoint point);
//	afx_msg void OnMButtonDblClk(UINT nFlags, CPoint point);
	afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);

	friend class CSchemeTreeView;
	afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
	afx_msg void OnUpdatePopup1Propertie(CCmdUI *pCmdUI);
	afx_msg void OnPopup1Propertie();
	afx_msg void OnUpdatePopup1Delete(CCmdUI *pCmdUI);
	afx_msg void OnPopup1Delete();
	afx_msg void OnPopup1Executewhenprocess();
	afx_msg void OnUpdatePopup1Executewhenprocess(CCmdUI *pCmdUI);
	afx_msg void OnPopup1Haveowntrigger();
	afx_msg void OnUpdatePopup1Haveowntrigger(CCmdUI *pCmdUI);
	afx_msg LRESULT OnUpdateView(WPARAM wParam, LPARAM lParam);
//	afx_msg void OnUpdateProcessStart(CCmdUI *pCmdUI);
//	afx_msg void OnProcessStart();
//	afx_msg void OnProcessStop();
//	afx_msg void OnUpdateProcessStop(CCmdUI *pCmdUI);
};

#ifndef _DEBUG  // debug version in SchemeView.cpp
inline CSchemeDoc* CSchemeView::GetDocument() const
   { return reinterpret_cast<CSchemeDoc*>(m_pDocument); }
#endif

