// RsTemplateWindow.h : Declaration of the CRsTemplateWindow

#pragma once
#include "resource.h"       // main symbols
#include "RsTemplateRenderData.h"

#include "atlcontrols.h"
using namespace ATLControls;

#if defined(_WIN32_WCE) && !defined(_CE_DCOM) && !defined(_CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA)
#error "Single-threaded COM objects are not properly supported on Windows CE platform, such as the Windows Mobile platforms that do not include full DCOM support. Define _CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA to force ATL to support creating single-thread COM object's and allow use of it's single-threaded COM object implementations. The threading model in your rgs file was set to 'Free' as that is the only threading model supported in non DCOM Windows CE platforms."
#endif


#define EDIT_CTRL_HEIGHT		16

// controls
#define NODE_NAME_CTRL			1
#define CON_DESCRIPTORS_CTRL	2



// IRsTemplateWindow
[
	object,
	uuid("2D9CBD27-373A-4168-8852-E3B9991632BD"),
	helpstring("IRsTemplateWindow Interface"),
	pointer_default(unique)
]
__interface IRsTemplateWindow : IUnknown
{
 
};


// CRsTemplateWindow

class ATL_NO_VTABLE CRsTemplateWindow : 
	public CComObjectRootEx<CComGlobalsThreadModel>,
    public CWindowImpl<CRsTemplateWindow, CWindow, CControlWinTraits>,
	public IRsGenView,
  	public IRsTemplateWindow
{
private:

	/// owner view node
	CComPtr<IRsNode>            m_spViewNode;
	/// cached data used for rendering
	CComQIPtr<IRsTemplateRenderData>	m_spRenderData;
	/// list view control displays connector info
	CContainedWindowT<CListViewCtrl, CWinTraitsOR<LVS_REPORT | LVS_EX_GRIDLINES | LVS_NOSORTHEADER | LVS_SINGLESEL, 0/*WS_EX_CLIENTEDGE*/> > m_listCtrl;
	/// edit control displays object name
	CContainedWindowT<CEdit, CWinTraits<> > m_editCtrl;

private:
	
	// update controls with new render data
	HRESULT UpdateControls(IRsTemplateRenderData* pRenderData);
	// fill  descriptor line in the list view control
	HRESULT AddDescriptorItem(int nItem, IRsConDescriptor* pConDesc);
	
	

public:
    
	CRsTemplateWindow()
	{
	}

	HRESULT FinalConstruct()
	{
		return S_OK;
	}
	
	void FinalRelease() 
	{
	}

	/**@name methods IRsGenView */
    //@{
	STDMETHOD(CreateView)(HWND hWndParent, RECT* pRect, DWORD dwStyle, DWORD dwExStyle);
	STDMETHOD(DestroyView)(void);
	STDMETHOD(GetHandle)(HWND* phWnd);
	STDMETHOD(InitializeControl)(IRsNode* pViewNode);
	STDMETHOD(Update)(IRsViewRenderData* pRenderData);
	//@}

	    
    // Macros are reason of problems for Doc++ so they should be out of
    // scope of Doc++ comments

    // IRsObject
    RS_DECLARE_IRS_OBJECT(IRsTemplateWindow, L"RsTemplateWindow")

    BEGIN_COM_MAP(CRsTemplateWindow)
        COM_INTERFACE_ENTRY(IRsTemplateWindow)
		COM_INTERFACE_ENTRY(IRsGenView)
        COM_INTERFACE_ENTRY2(IUnknown, IRsTemplateWindow)
    END_COM_MAP()

	DECLARE_GET_CONTROLLING_UNKNOWN()
    DECLARE_PROTECT_FINAL_CONSTRUCT()

	DECLARE_WND_CLASS(L"tS7TemplateWindow") 

	BEGIN_MSG_MAP(CRsTemplateWindow)
		MESSAGE_HANDLER(WM_CREATE, OnCreate)
		MESSAGE_HANDLER(WM_DESTROY, OnDestroy)
		MESSAGE_HANDLER(WM_SIZE, OnSize)
	ALT_MSG_MAP(NODE_NAME_CTRL)
	ALT_MSG_MAP(CON_DESCRIPTORS_CTRL)
	END_MSG_MAP()

// Handler prototypes:
//  LRESULT MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
//  LRESULT CommandHandler(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);
//  LRESULT NotifyHandler(int idCtrl, LPNMHDR pnmh, BOOL& bHandled);

	LRESULT OnSize(UINT /*uMsg*/, WPARAM wParam, LPARAM lParam, BOOL& /*bHandled*/);
	LRESULT OnCreate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
	LRESULT OnDestroy(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);

};

