//////////////////////////////////////////////////////////////////////
// Класс АктивИксКонтрол
// Разработчик: Рыбальченко Степан aka Steban
// Контакты: e-mail: steban@mail.ru, ICQ: 81707670
//////////////////////////////////////////////////////////////////////
// AXControl.h: interface for the CAXControl class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_AXCONTROL_H__D8FD4B9A_02B0_4E5B_8669_103A3172B113__INCLUDED_)
#define AFX_AXCONTROL_H__D8FD4B9A_02B0_4E5B_8669_103A3172B113__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "mycontextbase.h"
#include "V7Control.h"
//#include <..\src\occimpl.h>

#define IMPLTYPE_MASK (IMPLTYPEFLAG_FDEFAULT|IMPLTYPEFLAG_FSOURCE|\
   IMPLTYPEFLAG_FRESTRICTED)
#define IMPLTYPE_DEFAULTSOURCE (IMPLTYPEFLAG_FDEFAULT|IMPLTYPEFLAG_FSOURCE)
#define HOSTING_CONTROL_TYPE 1

class CAXControl;

class CBLMyEx:public CBLExportContext
{
public:
	long DispParamToValueEx(CValue** ppVal, DISPPARAMS* pDisp,unsigned int* pUI)
	{
		return DispParamToValue(ppVal, pDisp,pUI);
	}
	int  TryReturnByRefEx(CValue ** ppVal,DISPPARAMS* pDisp)
	{
		return TryReturnByRef(ppVal,pDisp);
	}
	int  ValueToVariantEx(CValue& Val,tagVARIANT * pVariant){
		return ValueToVariant(Val,pVariant);
	}
};

struct EventInfo
{
	DWORD procid;
	DWORD argNum;
};

typedef CMap<DISPID,DISPID,EventInfo,EventInfo> CDispIdToProcIdMap ;

class CAXControlWnd : public CWnd
{
	CAXControlWnd();
	friend class CAXControl;
	BOOL m_iEventProcessing;
	CGetDoc7* m_pDoc;
	CBLModule* m_pComponentBLModule;
	CString m_ControlID;
	virtual BOOL OnCmdMsg(UINT nID, int nCode, void* pExtra,
		AFX_CMDHANDLERINFO* pHandlerInfo);
private:
	CDispIdToProcIdMap *m_EventHandlers;
	CDispIdToProcIdMap *m_ComponentEventHandlers;
	void SetupEventHandlers(void);
	void CallEventHandler(EventInfo ei, CValue** lArray, CBLModule7* pModule);
};

class CAXControl : public CMyContextBase, public CV7Control
{
	DECLARE_DYNCREATE(CAXControl);
public:
	BOOL SetPropEventProcessing(CValue const& Value) {if(m_pCtrlWnd) m_pCtrlWnd->m_iEventProcessing=Value.GetNumeric();return TRUE;};
	BOOL GetPropEventProcessing(CValue& Value) const {if(m_pCtrlWnd) Value=m_pCtrlWnd->m_iEventProcessing; return TRUE;};
	BOOL SetPropObject(CValue const& Value);
	BOOL GetPropObject(CValue& Value) const;
	BOOL methDestroy(CValue** params);
	BOOL methSetFocus(CValue** params);
	BOOL methAssignAttrib(CValue** params);
	BOOL methCreateControl(CValue& RetVal, CValue **params);
	CAXControl();
	virtual ~CAXControl();
    //static BOOL CreateControl(CWnd* pFrame, CGetDoc7* pDoc, CGetField* pGetField, CValue& vControl);
    //CV7Control
    virtual BOOL CreateControlWnd(CWnd* pParent, CGetDoc7* pDoc, CGetField* pGetField, CBLContext* pUDC);
    virtual BOOL _Create(CValue** ppValue);

    DECLARE_MY_CONTEXT()
private:
	CFormAllCtrlsContext *m_Form;
	CAXControlWnd *m_pCtrlWnd;
	CWnd *m_pParentWnd;
};

#endif // !defined(AFX_AXCONTROL_H__D8FD4B9A_02B0_4E5B_8669_103A3172B113__INCLUDED_)
