Click here to Skip to main content
15,860,972 members
Articles / Desktop Programming / WTL

Form Designer

26 Jul 2021CPOL24 min read 349.8K   82.5K   230  
Component for adding scriptable forms capabilities to an application.
// Script.h : Declaration of the CScript
//
// Author : David Shepherd
//			Copyright (c) 2002, DaeDoe-Software
//
/////////////////////////////////////////////////////////////////////////////

#ifndef __SCRIPT_H_
#define __SCRIPT_H_

#include "resource.h"       // main symbols

/////////////////////////////////////////////////////////////////////////////
// CScriptEditorLock
class CScriptEditorLock
{
private:
	CComQIPtr<IScriptBuffer> m_p;
public:
	CScriptEditorLock(const CComPtr<IUnknown> &p);
	virtual ~CScriptEditorLock();
};

/////////////////////////////////////////////////////////////////////////////
// CScript
class ATL_NO_VTABLE CScript :
	public CComObjectRootEx<CComSingleThreadModel>,
	public CComCoClass<CScript, &CLSID_Script>,
	public IDispatchImpl<IScript2, &IID_IScript2, &LIBID_DDFORMSLib, TlbVerMaj, TlbVerMin>
{
private:
	// script editor
	CComPtr<IUnknown> m_spEditor;

	// creates the event handler name
	std::wstring CreateEventHandlerName(
		const std::wstring &Source,const std::wstring &Event) const;
	// creates the event handler start locator name
	std::wstring CreateEventHandlerStartLocatorName(
		const std::wstring &Source,const std::wstring &Event) const;
	// creates the event handler finish locator name
	std::wstring CreateEventHandlerFinishLocatorName(
		const std::wstring &Source,const std::wstring &Event) const;
	// creates the event handler block
	std::list<std::wstring> CreateEventHandlerBlock(
		const std::wstring &Source,const std::wstring &Event,
		const std::wstring &Parameters,const std::wstring &Body) const;

public:
	CScript()
	{
	}

DECLARE_NO_REGISTRY()

DECLARE_PROTECT_FINAL_CONSTRUCT()

BEGIN_COM_MAP(CScript)
	COM_INTERFACE_ENTRY(IScript2)
	COM_INTERFACE_ENTRY(IScript)
	COM_INTERFACE_ENTRY(IDispatch)
END_COM_MAP()

// IScript
public:
	STDMETHOD(AddEventHandler)(
		/*[in]*/ BSTR Source,
		/*[in]*/ BSTR Event,
		/*[in]*/ BSTR Parameters);
	STDMETHOD(IsEventHandled)(
		/*[in]*/ BSTR Source,
		/*[in]*/ BSTR Event,
		/*[out, retval]*/ VARIANT_BOOL *pRet);
	STDMETHOD(EditEventHandler)(
		/*[in]*/ BSTR Source,
		/*[in]*/ BSTR Event);
	STDMETHOD(EditLine)(/*[in]*/ long Line);
	STDMETHOD(Reset)();
	STDMETHOD(LoadFromStream)(
		/*[in]*/ IUnknown *pUnknown,
		/*[in]*/ long StreamVersion);
	STDMETHOD(SaveToStream)(/*[in]*/ IUnknown *pUnknown);
	STDMETHOD(get_Text)(/*[out, retval]*/ BSTR *pVal);
	STDMETHOD(put_Text)(/*[in]*/ BSTR newVal);
	STDMETHOD(get_Editor)(/*[out, retval]*/ IUnknown **ppUnknown);
	STDMETHOD(put_Editor)(/*[in]*/ IUnknown *pUnknown);

// IScript2
	STDMETHOD(AddEventHandlerEx)(
		/*[in]*/ BSTR Source,
		/*[in]*/ BSTR Event,
		/*[in]*/ BSTR Parameters,
		/*[in]*/ BSTR Body);
};

#endif //__SCRIPT_H_

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
United Kingdom United Kingdom
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions