// Panel.h : Declaration of the cPanel

#ifndef __PANEL_H_
#define __PANEL_H_

#include "resource.h"       // main symbols

#include "SinkImpl.h"

#define BUTTON_CLOSE 1

/////////////////////////////////////////////////////////////////////////////
// cPanel
class ATL_NO_VTABLE cPanel : 
	public CComObjectRootEx<CComMultiThreadModel>,
   public ILayerRenderImpl,
   public ILayerImpl< cPanel >,
   	public ILayerMouseImpl,
   public ICommandEventsImpl< BUTTON_CLOSE, cPanel >,
   public cNoEventsImpl,
	public IPanel
{
public:
	cPanel();

   _bstr_t m_strTitle;
   long m_nIcon, m_nIconModule;

   long m_nActiveView;

   CComPtr< IImageCache > m_pBorder;
   CComPtr< IImageCache > m_pBackground;
   CComPtr< IFontCache > m_pTitle;
   CComPtr< IPanelSink > m_pSink;

   long m_nTop;
   long m_nLeft;
   long m_nHeight;
   long m_nWidth;
	
   long m_DeltaX;
   long m_DeltaY;

   bool m_bDragging;

   void hideView();

   void onCreate();
   void onDestroy();

BEGIN_COM_MAP(cPanel)
   COM_INTERFACE_ENTRY(ILayer)
   COM_INTERFACE_ENTRY(ILayerRender)
	COM_INTERFACE_ENTRY(IPanel)
		COM_INTERFACE_ENTRY(ILayerMouse)
END_COM_MAP()

BEGIN_SINK_MAP( cPanel )
   SINK_ENTRY_EX( BUTTON_CLOSE, DIID_ICommandEvents, DISPID_ACCEPTED, onCloseAccepted )
END_SINK_MAP()

// IPanel
public:
	STDMETHOD(LoadView)(long nPlugin, IView *pView, IUnknown *pSchema);
	STDMETHOD(get_ActiveView)(/*[out, retval]*/ long *pVal);
	STDMETHOD(AddView)(long nPluginID, ILayer *pLayer);
	STDMETHOD(RemoveView)(long nID);
	STDMETHOD(ActivateView)(long nViewID, ViewParams *pParams);
	STDMETHOD(Deactivate)();
	STDMETHOD(putref_Sink)(/*[in]*/ IPanelSink* newVal);

   // ILayerRender Methods
   STDMETHOD(Render)(ICanvas *);
   STDMETHOD(Reformat)();

   // ICommandEvents Methods
	void __stdcall onCloseAccepted(long nID);

	// ILayerMouse Methods
	STDMETHOD(MouseEnter)(struct MouseState *);
	STDMETHOD(MouseExit)(struct MouseState *);
	STDMETHOD(MouseDown)(struct MouseState *pMS);
	STDMETHOD(MouseUp)(struct MouseState *);
	STDMETHOD(MouseMove)(struct MouseState *pMS);
	STDMETHOD(MouseEvent)(long nMsg, long wParam, long lParam);
};

#endif //__PANEL_H_
