// SimpleScriptEditor.h : Declaration of the CSimpleScriptEditor
//
// Author : David Shepherd
// Copyright (c) 2002, DaeDoe-Software
//
/////////////////////////////////////////////////////////////////////////////
#ifndef __SIMPLESCRIPTEDITOR_H_
#define __SIMPLESCRIPTEDITOR_H_
#include "resource.h" // main symbols
#include <atlctl.h>
#include "DDFormsCP.h"
// the edit control id
#define IDC_EDIT 0x1000
namespace AxSimpleScriptEditor {
/////////////////////////////////////////////////////////////////////////////
// CSimpleScriptEditor
class ATL_NO_VTABLE CSimpleScriptEditor :
public CComObjectRootEx<CComSingleThreadModel>,
public IDispatchImpl<ISimpleScriptEditor, &IID_ISimpleScriptEditor, &LIBID_DDFORMSLib, TlbVerMaj, TlbVerMin>,
public CComControl<CSimpleScriptEditor>,
public IPersistStreamInitImpl<CSimpleScriptEditor>,
public IOleControlImpl<CSimpleScriptEditor>,
public IOleObjectImpl<CSimpleScriptEditor>,
public IOleInPlaceActiveObjectImpl<CSimpleScriptEditor>,
public IViewObjectExImpl<CSimpleScriptEditor>,
public IOleInPlaceObjectWindowlessImpl<CSimpleScriptEditor>,
public IConnectionPointContainerImpl<CSimpleScriptEditor>,
public IPersistStorageImpl<CSimpleScriptEditor>,
public IPersistPropertyBagImpl<CSimpleScriptEditor>,
public ISpecifyPropertyPagesImpl<CSimpleScriptEditor>,
public IQuickActivateImpl<CSimpleScriptEditor>,
public IDataObjectImpl<CSimpleScriptEditor>,
public IProvideClassInfo2Impl<&CLSID_SimpleScriptEditor, &DIID__ISimpleScriptEditorEvents, &LIBID_DDFORMSLib, TlbVerMaj, TlbVerMin>,
public IPropertyNotifySinkCP<CSimpleScriptEditor>,
public CComCoClass<CSimpleScriptEditor, &CLSID_SimpleScriptEditor>,
public CProxy_ISimpleScriptEditorEvents<CSimpleScriptEditor>,
public IScriptBuffer,
public IScriptNavigation,
public IScriptState
{
private:
// the edit control
// this is represented by both a contained window and an edit control wrapper
CContainedWindow m_ContainedEdit;
CEdit m_Edit;
// edit control accelerators
HACCEL m_hAccel;
// while this is greater than zero the edit control will be read only
DWORD m_LockCount;
// the modified flag
BOOL m_Modified;
// properties
// border visible
VARIANT_BOOL m_BorderVisible;
// background color
OLE_COLOR m_BackColor;
// foreground color
OLE_COLOR m_ForeColor;
// font
CComPtr<IFontDisp> m_spFontDisp;
// brush used to paint the edit control background
HBRUSH m_BackBrush;
// sets the modified flag
void SetModified(BOOL Modified);
// creates the edit control background brush
void CreateBackgroundBrush(OLE_COLOR BackColor);
// sets the edit control font
void SetFont(const CComPtr<IFontDisp> &pFontDisp);
// determines the length of the longest line in the edit control
DWORD GetLongestLineLength();
public:
CSimpleScriptEditor();
virtual ~CSimpleScriptEditor();
DECLARE_REGISTRY_RESOURCEID(IDR_SIMPLESCRIPTEDITOR)
DECLARE_PROTECT_FINAL_CONSTRUCT()
BEGIN_COM_MAP(CSimpleScriptEditor)
COM_INTERFACE_ENTRY(ISimpleScriptEditor)
COM_INTERFACE_ENTRY(IDispatch)
COM_INTERFACE_ENTRY(IViewObjectEx)
COM_INTERFACE_ENTRY(IViewObject2)
COM_INTERFACE_ENTRY(IViewObject)
COM_INTERFACE_ENTRY(IOleInPlaceObjectWindowless)
COM_INTERFACE_ENTRY(IOleInPlaceObject)
COM_INTERFACE_ENTRY2(IOleWindow, IOleInPlaceObjectWindowless)
COM_INTERFACE_ENTRY(IOleInPlaceActiveObject)
COM_INTERFACE_ENTRY(IOleControl)
COM_INTERFACE_ENTRY(IOleObject)
COM_INTERFACE_ENTRY(IPersistStreamInit)
COM_INTERFACE_ENTRY2(IPersist, IPersistStreamInit)
COM_INTERFACE_ENTRY(IConnectionPointContainer)
COM_INTERFACE_ENTRY(ISpecifyPropertyPages)
COM_INTERFACE_ENTRY(IQuickActivate)
COM_INTERFACE_ENTRY(IPersistStorage)
COM_INTERFACE_ENTRY(IPersistPropertyBag)
COM_INTERFACE_ENTRY(IDataObject)
COM_INTERFACE_ENTRY(IProvideClassInfo)
COM_INTERFACE_ENTRY(IProvideClassInfo2)
COM_INTERFACE_ENTRY_IMPL(IConnectionPointContainer)
COM_INTERFACE_ENTRY(IScriptBuffer)
COM_INTERFACE_ENTRY(IScriptNavigation)
COM_INTERFACE_ENTRY(IScriptState)
END_COM_MAP()
BEGIN_PROP_MAP(CSimpleScriptEditor)
PROP_DATA_ENTRY("_cx", m_sizeExtent.cx, VT_UI4)
PROP_DATA_ENTRY("_cy", m_sizeExtent.cy, VT_UI4)
PROP_ENTRY("BorderVisible", DISPID_BORDERVISIBLE, CLSID_PropPageSimpleScriptEditor)
PROP_ENTRY("BackColor", DISPID_BACKCOLOR, CLSID_StockColorPage)
PROP_ENTRY("ForeColor", DISPID_FORECOLOR, CLSID_StockColorPage)
PROP_ENTRY("Font", DISPID_FONT, CLSID_StockFontPage)
// Example entries
// PROP_ENTRY("Property Description", dispid, clsid)
// PROP_PAGE(CLSID_StockColorPage)
END_PROP_MAP()
BEGIN_CONNECTION_POINT_MAP(CSimpleScriptEditor)
CONNECTION_POINT_ENTRY(IID_IPropertyNotifySink)
CONNECTION_POINT_ENTRY(DIID__ISimpleScriptEditorEvents)
END_CONNECTION_POINT_MAP()
BEGIN_MSG_MAP(CSimpleScriptEditor)
MESSAGE_HANDLER(WM_CREATE, OnCreate)
MESSAGE_HANDLER(WM_SETFOCUS, OnSetFocus)
MESSAGE_HANDLER(WM_CTLCOLOREDIT, OnCtlColorEdit)
MESSAGE_HANDLER(WM_CTLCOLORSTATIC, OnCtlColorEdit) // disabled edit control
MESSAGE_HANDLER(WM_ERASEBKGND, OnEraseBkgnd)
COMMAND_HANDLER(IDC_EDIT, EN_CHANGE, OnEditChanged)
COMMAND_ID_HANDLER(ID_CUT, OnCut)
COMMAND_ID_HANDLER(ID_COPY, OnCopy)
COMMAND_ID_HANDLER(ID_PASTE, OnPaste)
COMMAND_ID_HANDLER(ID_UNDO, OnUndo)
CHAIN_MSG_MAP(CComControl<CSimpleScriptEditor>)
ALT_MSG_MAP(1)
// Replace this with message map entries for superclassed Edit
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);
// base class overrides
HRESULT FinalConstruct();
HRESULT OnDraw(ATL_DRAWINFO &di);
// persistance
STDMETHOD(put_BorderVisible)(VARIANT_BOOL newVal);
STDMETHOD(get_BorderVisible)(VARIANT_BOOL *pVal);
STDMETHOD(put_BackColor)(OLE_COLOR newVal);
STDMETHOD(get_BackColor)(OLE_COLOR *pVal);
STDMETHOD(put_ForeColor)(OLE_COLOR newVal);
STDMETHOD(get_ForeColor)(OLE_COLOR *pVal);
STDMETHOD(putref_Font)(IFontDisp *pFontDisp);
STDMETHOD(put_Font)(IFontDisp *pFontDisp);
STDMETHOD(get_Font)(IFontDisp **ppFontDisp);
// IPersistStreamInit
STDMETHOD(InitNew)();
// IOleControl
STDMETHOD(OnAmbientPropertyChange)(DISPID dispid);
// IOleInPlaceObject
STDMETHOD(SetObjectRects)(LPCRECT prcPos, LPCRECT prcClip);
// IViewObjectEx
DECLARE_VIEW_STATUS(VIEWSTATUS_SOLIDBKGND | VIEWSTATUS_OPAQUE)
// message handlers
BOOL PreTranslateAccelerator(LPMSG pMsg, HRESULT& hRet);
LRESULT OnSetFocus(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
LRESULT OnCtlColorEdit(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
LRESULT OnEraseBkgnd(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
LRESULT OnEditChanged(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);
LRESULT OnCut(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);
LRESULT OnCopy(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);
LRESULT OnPaste(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);
LRESULT OnUndo(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);
// ISimpleScriptEditor
public:
STDMETHOD(About)();
STDMETHOD(Cut)();
STDMETHOD(Copy)();
STDMETHOD(Paste)();
STDMETHOD(Undo)();
STDMETHOD(RefreshModifiedState)();
STDMETHOD(get_Modified)(/*[out, retval]*/ VARIANT_BOOL *pVal);
STDMETHOD(put_Modified)(/*[in]*/ VARIANT_BOOL newVal);
// IScriptBuffer
STDMETHOD(LockExternal)(/*[in]*/ BOOL Lock);
STDMETHOD(GetLineCount)(/*[out]*/ DWORD *pCount);
STDMETHOD(FindText)(
/*[in]*/ DWORD Start,
/*[in]*/ LPCOLESTR pText,
/*[out]*/ BOOL *pFound,
/*[out]*/ DWORD *pLine);
STDMETHOD(InsertLines)(
/*[in]*/ DWORD Start,
/*[in]*/ DWORD Count,
/*[in, size_is(Count)]*/ LPCOLESTR *pLines);
STDMETHOD(GetLines)(
/*[in]*/ DWORD Start,
/*[in]*/ DWORD Count,
/*[out, size_is(,Count)]*/ LPOLESTR **ppLines);
STDMETHOD(DeleteLines)(
/*[in]*/ DWORD Start,
/*[in]*/ DWORD Count);
STDMETHOD(ModifyLines)(
/*[in]*/ DWORD Start,
/*[in]*/ DWORD End,
/*[in]*/ DWORD Count,
/*[in, size_is(Count)]*/ LPCOLESTR *pLines);
// IScriptNavigation
STDMETHOD(GoToLine)(/*[in]*/ DWORD Line);
// IScriptState
};
} // namespace AxSimpleScriptEditor
#endif //__SIMPLESCRIPTEDITOR_H_