8#ifndef ATLACTIVEXCONTAINER_HPP
9#define ATLACTIVEXCONTAINER_HPP
12 #include <atl.mini/SComCli.h>
58 virtual HRESULT
OnAxGetDC(LPCRECT pRect, DWORD grfFlags, HDC* phDC) = 0;
80 public IOleControlSite,
81 public IOleInPlaceSiteWindowless,
91 : m_pAxHostDelegate(NULL)
93 , m_bInplaceActive(false)
96 , m_dwViewObjectType(0)
101 memset(&m_rcPos, 0,
sizeof(m_rcPos));
118 m_pAxHostDelegate = pAxHost;
127 m_spDocHostUIHandler = pUiHandler;
145 m_spControl = pControl;
146 m_spOleObject = pControl;
147 m_spInPlaceObject = pControl;
155 if (m_spControl != NULL)
157 if (m_spViewObject != NULL)
159 m_spViewObject->SetAdvise(DVASPECT_CONTENT, 0, NULL);
160 m_spViewObject.Release();
162 m_spOleObjectWindowless.Release();
163 if (m_spInPlaceObject != NULL)
165 if (m_bInplaceActive)
167 m_spInPlaceObject->InPlaceDeactivate();
168 m_bInplaceActive =
false;
170 m_spInPlaceObject.Release();
172 if (m_spOleObject != NULL)
174 m_spOleObject->Unadvise(m_dwOleObjSink);
175 m_spOleObject->SetClientSite(NULL);
176 m_spOleObject->Close(OLECLOSE_NOSAVE);
177 m_spOleObject.Release();
190 if (m_spControl == 0)
return E_NOINTERFACE;
191 HRESULT hr = E_POINTER;
192 SComQIPtr<IPersistStreamInit> spPSI(m_spControl);
196 hr = spPSI->Load(pStream);
198 hr = spPSI->InitNew();
202 SComQIPtr<IPersistStream> spPS(m_spOleObject);
204 hr = spPS->Load(pStream);
216 if (m_spOleObject == 0)
return E_UNEXPECTED;
220 hr = m_spOleObject->GetMiscStatus(DVASPECT_CONTENT, &m_dwMiscStatus);
221 if (m_dwMiscStatus & OLEMISC_SETCLIENTSITEFIRST) {
222 hr = m_spOleObject->SetClientSite(
static_cast<IOleClientSite*
>(
this));
223 if (FAILED(hr))
return hr;
229 if (m_dwMiscStatus & OLEMISC_SETCLIENTSITEFIRST)
230 m_spOleObject->SetClientSite(NULL);
234 if (0 == (m_dwMiscStatus & OLEMISC_SETCLIENTSITEFIRST)) {
235 hr = m_spOleObject->SetClientSite(
static_cast<IOleClientSite*
>(
this));
236 if (FAILED(hr))
return hr;
250 if (m_spViewObject != NULL && m_dwViewObjectType == 7) {
251 DWORD dwHitResult = HITRESULT_OUTSIDE;
252 m_spViewObject->QueryHitPoint(DVASPECT_CONTENT, &m_rcPos, pt, 0, &dwHitResult);
253 return (dwHitResult == HITRESULT_HIT);
256 return (::PtInRect(&m_rcPos, pt) != FALSE);
267 const POINT* pts = (
const POINT*)(&m_rcPos);
268 const POINT* ptc = (
const POINT*)(&rcClip);
269 return (::PtInRect(&rcClip, pts[0]) || ::PtInRect(&rcClip, pts[1]) ||
270 ::PtInRect(&m_rcPos, ptc[0]) || ::PtInRect(&m_rcPos, ptc[1]));
281 if ((m_dwMiscStatus & (OLEMISC_INVISIBLEATRUNTIME | OLEMISC_NOUIACTIVATE)) != 0)
285 else if (m_spOleObject != NULL)
287 hr = m_spOleObject->DoVerb(verb, NULL,
static_cast<IOleClientSite*
>(
this), 0, m_pAxHostDelegate->GetAxHostWindow(), &m_rcPos);
288 if (verb == OLEIVERB_INPLACEACTIVATE && SUCCEEDED(hr))
290 m_bInplaceActive =
true;
305 LRESULT
Draw(HDC hDC, LPCRECT lpClipRect)
307 LRESULT lResult = S_FALSE;
311 if (m_bVisible && m_spViewObject != NULL) {
312 RECTL rcPos = { m_rcPos.left,m_rcPos.top,m_rcPos.right,m_rcPos.bottom };
313 lResult = m_spViewObject->Draw(DVASPECT_CONTENT, -1, NULL, NULL, NULL, hDC,
314 &rcPos, NULL, NULL, 0);
327 SComQIPtr<IOleControl, &__uuidof(IOleControl)> spOleControl(m_spControl);
328 if (spOleControl != NULL)
329 hr = spOleControl->OnAmbientPropertyChange(dispChanged);
343 if (m_bInplaceActive && m_spOleObjectWindowless != NULL)
345 m_spOleObjectWindowless->OnWindowMessage(uMsg, wParam, lParam, &lResult);
360 if (iid == IID_IOleClientSite) {
361 *
object =
static_cast<IOleClientSite*
>(
this);
363 else if (iid == IID_IOleControlSite) {
364 *
object =
static_cast<IOleControlSite*
>(
this);
366 else if (iid == IID_IOleInPlaceSite) {
367 *
object =
static_cast<IOleInPlaceSite*
>(
this);
369 else if (iid == IID_IOleInPlaceSiteEx) {
370 *
object =
static_cast<IOleInPlaceSiteEx*
>(
this);
372 else if (iid == IID_IOleInPlaceSiteWindowless) {
373 *
object =
static_cast<IOleInPlaceSiteWindowless*
>(
this);
375 else if (iid == IID_IAdviseSink) {
376 *
object =
static_cast<IAdviseSink*
>(
this);
378 else if (iid == IID_IDocHostUIHandler && m_spDocHostUIHandler) {
379 *
object = m_spDocHostUIHandler;
393 ATLTRACENOTIMPL(_T(
"ActiveXSite::SaveObject\n"));
403 STDMETHOD(
GetMoniker)(DWORD , DWORD dwWhichMoniker, IMoniker** ppmk)
415 HRESULT hr = E_POINTER;
416 if (ppContainer != NULL) {
417 hr =
static_cast<T*
>(
this)->QueryInterface(__uuidof(IOleContainer),
reinterpret_cast<void**
>(ppContainer));
428 HWND hWnd = m_pAxHostDelegate->GetAxHostWindow();
430 if (::IsWindow(hWnd) && ::IsRectEmpty(&m_rcPos) == FALSE)
433 if (m_bInplaceActive)
435 m_pAxHostDelegate->OnAxInvalidate(&m_rcPos, TRUE);
449 m_bVisible = (fShow != FALSE);
459 ATLTRACENOTIMPL(_T(
"ActiveXSite::RequestNewObjectLayout\n"));
478 ATLTRACENOTIMPL(_T(
"ActiveXSite::LockInPlaceActive\n"));
488 ATLTRACENOTIMPL(_T(
"ActiveXSite::GetExtendedControl\n"));
500 ATLTRACENOTIMPL(_T(
"ActiveXSite::TransformCoords\n"));
511 ATLTRACENOTIMPL(_T(
"ActiveXSite::TranslateAccelerator\n"));
531 ATLTRACENOTIMPL(_T(
"ActiveXSite::ShowPropertyFrame\n"));
549 HRESULT hr = m_bCaptured ? S_OK : S_FALSE;
560 if (fCapture != m_bCaptured)
562 m_bCaptured = fCapture;
563 m_pAxHostDelegate->OnAxSetCapture(fCapture);
574 return m_bFocused ? S_OK : S_FALSE;
584 if (m_bFocused != fFocus)
600 STDMETHOD(
GetDC)(LPCRECT pRect, DWORD grfFlags, HDC* phDC)
602 return m_pAxHostDelegate->OnAxGetDC(pRect, grfFlags, phDC);
612 return m_pAxHostDelegate->OnAxReleaseDC(hDC);
625 if (pRect == NULL) pRect = &m_rcPos;
626 m_pAxHostDelegate->OnAxInvalidate(pRect, fErase);
651 ATLTRACENOTIMPL(_T(
"ActiveXSite::ScrollRect\n"));
661 ATLTRACENOTIMPL(_T(
"ActiveXSite::AdjustRect\n"));
674 *plResult = DefWindowProc(m_pAxHostDelegate->GetAxHostWindow(), msg, wParam, lParam);
687 HRESULT hr = S_FALSE;
688 OleLockRunning(m_spOleObject, TRUE, FALSE);
693 if ((dwFlags & ACTIVATE_WINDOWLESS) != 0) {
694 m_spOleObjectWindowless = m_spControl;
696 if (m_spOleObjectWindowless != NULL) {
697 m_bInplaceActive =
true;
703 m_bInplaceActive =
false;
715 m_bInplaceActive =
false;
766 IOleInPlaceUIWindow** ppDoc,
769 LPOLEINPLACEFRAMEINFO lpFrameInfo)
778 memcpy(lprcPosRect, &m_rcPos,
sizeof(m_rcPos));
781 memcpy(lprcClipRect, &m_rcPos,
sizeof(m_rcPos));
784 lpFrameInfo->fMDIApp = FALSE;
785 lpFrameInfo->hwndFrame = m_pAxHostDelegate->GetAxHostWindow();
786 lpFrameInfo->haccel = NULL;
787 lpFrameInfo->cAccelEntries = 0;
799 ATLTRACENOTIMPL(_T(
"ActiveXSite::Scroll\n"));
827 ATLTRACENOTIMPL(_T(
"ActiveXSite::DiscardUndoState"));
836 ATLTRACENOTIMPL(_T(
"ActiveXSite::DeactivateAndUndo"));
846 HRESULT hr = E_UNEXPECTED;
848 if (lprcPosRect && memcmp(&m_rcPos, lprcPosRect,
sizeof(m_rcPos)) != 0)
850 if (m_spInPlaceObject)
852 memcpy(&m_rcPos, lprcPosRect,
sizeof(m_rcPos));
853 hr = m_spInPlaceObject->SetObjectRects(&m_rcPos, &m_rcPos);
857 hr =
SetExtent(m_rcPos.right - m_rcPos.left, m_rcPos.bottom - m_rcPos.top);
871 *phwnd = m_pAxHostDelegate->GetAxHostWindow();
882 ATLTRACENOTIMPL(_T(
"ActiveXSite::ContextSensitiveHelp\n"));
935 HRESULT hr = E_UNEXPECTED;
936 if (m_spOleObject != NULL)
938 SIZEL pxsize = { width, height };
939 SIZEL hmsize = { 0 };
940 SPixelToHiMetric(&pxsize, &hmsize);
941 hr = m_spOleObject->SetExtent(DVASPECT_CONTENT, &hmsize);
942 hr = m_spOleObject->GetExtent(DVASPECT_CONTENT, &hmsize);
943 SHiMetricToPixel(&hmsize, &pxsize);
944 m_rcPos.right = m_rcPos.left + pxsize.cx;
945 m_rcPos.bottom = m_rcPos.top + pxsize.cy;
957 m_pAxHostDelegate->OnAxActivate(m_spControl);
958 m_dwViewObjectType = 0;
959 hr = m_spOleObject->QueryInterface(__uuidof(IViewObjectEx),
reinterpret_cast<void**
>(&m_spViewObject));
962 hr = m_spOleObject->QueryInterface(__uuidof(IViewObject2),
reinterpret_cast<void**
>(&m_spViewObject));
964 m_dwViewObjectType = 3;
967 m_dwViewObjectType = 7;
972 hr = m_spOleObject->QueryInterface(__uuidof(IViewObject),
reinterpret_cast<void**
>(&m_spViewObject));
974 m_dwViewObjectType = 1;
976 SComQIPtr<IAdviseSink> advise_sink(m_spControl);
977 m_spOleObject->Advise(advise_sink, &m_dwOleObjSink);
979 hr = m_spViewObject->SetAdvise(DVASPECT_CONTENT, 0, advise_sink);
980 m_spOleObject->SetHostNames(OLESTR(
"SOUIAXWIN"), NULL);
983 hr =
DoVerb(OLEIVERB_INPLACEACTIVATE);
989 bool m_bInplaceActive;
992 DWORD m_dwMiscStatus;
993 DWORD m_dwViewObjectType;
994 DWORD m_dwOleObjSink;
998 SComPtr<IUnknown> m_spControl;
999 SComPtr<IViewObjectEx> m_spViewObject;
1000 SComQIPtr<IOleObject> m_spOleObject;
1001 SComQIPtr<IOleInPlaceObject> m_spInPlaceObject;
1002 SComQIPtr<IOleInPlaceObjectWindowless> m_spOleObjectWindowless;
1003 SComPtr<IDocHostUIHandler> m_spDocHostUIHandler;
1015 public IServiceProvider,
1049 ATLTRACENOTIMPL(_T(
"ActiveXContainerImpl::EnumObjects\n"));
1059 ATLTRACENOTIMPL(_T(
"ActiveXContainerImpl::LockContainer\n"));
1073 ULONG* , IMoniker** )
1075 ATLTRACENOTIMPL(_T(
"ActiveXContainerImpl::ParseDisplayName\n"));
1090 IMoniker** ppmk, DWORD dwReserved);
1102 IBindStatusCallback* pBSC, REFIID riid,
void** ppvObj);
1114 IBindStatusCallback* pBSC, REFIID riid,
void** ppvObj);
1126 STDMETHOD(
QueryService)(REFGUID guidService, REFIID riid,
void** ppvObject);
STDMETHOD ReleaseDC(HDC hDC)
Release a previously obtained device context.
STDMETHOD ScrollRect(INT, INT, LPCRECT, LPCRECT)
Scroll a rectangle of the control.
STDMETHOD InvalidateRect(LPCRECT pRect, BOOL fErase)
Invalidate a rectangle of the control.
HRESULT ActivateAx(IStream *pStream=NULL)
Activate the ActiveX control.
LRESULT OnWindowMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
Handle a window message for the ActiveX control.
STDMETHOD InvalidateRgn(HRGN, BOOL fErase)
Invalidate a region of the control.
void SetAxHost(IAxHostDelegate *pAxHost)
Set the delegate for ActiveX host operations.
STDMETHOD CanWindowlessActivate(void)
Check if the control supports windowless activation.
STDMETHOD ShowPropertyFrame(void)
Show the property frame for the control.
STDMETHOD ShowObject(void)
Show the object.
STDMETHOD OnInPlaceDeactivateEx(BOOL)
Deactivate the control in-place with extended options.
void OnViewChange(DWORD, LONG)
Handle a change in view.
STDMETHOD LockInPlaceActive(BOOL)
Lock the control in place active state.
STDMETHOD OnFocus(BOOL fGotFocus)
Notify the control of focus change.
STDMETHOD RequestNewObjectLayout(void)
Request a new object layout.
void OnSave(void)
Handle a save operation.
STDMETHOD Scroll(SIZE)
Scroll the control.
void OnDataChange(FORMATETC *, STGMEDIUM *)
Handle a change in data.
void OnClose(void)
Handle a close operation.
STDMETHOD GetCapture(void)
Check if the control currently has the mouse capture.
STDMETHOD OnShowWindow(BOOL fShow)
Notify the container of a show window event.
HRESULT FireAmbientPropertyChange(DISPID dispChanged)
Fire an ambient property change notification.
STDMETHOD CanInPlaceActivate(void)
Check if the control can be activated in-place.
STDMETHOD AdjustRect(LPRECT)
Adjust a rectangle for the control.
STDMETHOD OnPosRectChange(LPCRECT lprcPosRect)
Handle a change in the position rectangle of the control.
STDMETHOD OnControlInfoChanged(void)
Notify the control that its info has changed.
STDMETHOD OnInPlaceActivate(void)
Activate the control in-place.
void Init(IUnknown *pControl)
Initialize the ActiveX control.
STDMETHOD GetDC(LPCRECT pRect, DWORD grfFlags, HDC *phDC)
Get a device context for the control.
void SetExternalUIHandler(IDocHostUIHandler *pUiHandler)
Set the external UI handler for the ActiveX control.
STDMETHOD SetFocus(BOOL fFocus)
Set or release focus for the control.
STDMETHOD RequestUIActivate(void)
Request UI activation for the control.
STDMETHOD GetContainer(IOleContainer **ppContainer)
Get the container for the object.
void Clear()
Clear the ActiveX control and release resources.
STDMETHOD OnInPlaceDeactivate(void)
Deactivate the control in-place.
STDMETHOD DeactivateAndUndo(void)
Deactivate and undo the control.
STDMETHOD OnUIActivate(void)
Activate the control's user interface.
HRESULT DoInplaceActivate()
Perform in-place activation of the control.
bool HitTest(const POINT &pt) const
Check if a point is within the ActiveX control.
STDMETHOD ContextSensitiveHelp(BOOL)
Handle context-sensitive help for the control.
HRESULT SetExtent(int width, int height)
Set the extent (size) of the control.
virtual ~ActiveXSite()
Destructor for ActiveXSite.
STDMETHOD DiscardUndoState(void)
Discard the undo state of the control.
STDMETHOD GetMoniker(DWORD, DWORD dwWhichMoniker, IMoniker **ppmk)
Get the moniker for the object.
STDMETHOD GetExtendedControl(IDispatch **)
Get the extended control.
ActiveXSite()
Constructor for ActiveXSite.
HRESULT DoVerb(long verb)
Perform a verb on the ActiveX control.
STDMETHOD OnInPlaceActivateEx(BOOL *pfNoRedraw, DWORD dwFlags)
Activate the control in-place with extended options.
STDMETHOD QueryInterface2(REFIID iid, void **object)
Query for an interface.
STDMETHOD TranslateAccelerator(MSG *, DWORD)
Translate an accelerator key.
STDMETHOD GetFocus(void)
Check if the control currently has focus.
STDMETHOD OnDefWindowMessage(UINT msg, WPARAM wParam, LPARAM lParam, LRESULT *plResult)
Handle a default window message for the control.
bool InsideClippingRegion(const RECT &rcClip) const
Check if the control intersects with a clipping region.
STDMETHOD SetCapture(BOOL fCapture)
Set or release the mouse capture for the control.
LRESULT Draw(HDC hDC, LPCRECT lpClipRect)
Draw the ActiveX control.
HRESULT InitControl(IStream *pStream=NULL)
Initialize the ActiveX control from a stream.
STDMETHOD TransformCoords(POINTL *, POINTF *, DWORD)
Transform coordinates between container and control.
IUnknown * GetActiveXControl()
Get the ActiveX control.
STDMETHOD GetWindow(HWND *phwnd)
Get the window handle for the control.
STDMETHOD SaveObject(void)
Save the object.
STDMETHOD OnUIDeactivate(BOOL)
Deactivate the control's user interface.
void OnRename(IMoniker *)
Handle a rename of the object.
STDMETHOD GetWindowContext(IOleInPlaceFrame **ppFrame, IOleInPlaceUIWindow **ppDoc, LPRECT lprcPosRect, LPRECT lprcClipRect, LPOLEINPLACEFRAMEINFO lpFrameInfo)
Get the window context for the control.
ULONG AddRef()
Increment the reference count.
ULONG Release()
Decrement the reference count.
BOOL CreateControl(REFGUID guid, DWORD dwClsCtx=CLSCTX_INPROC_SERVER)
Create an ActiveX control.
STDMETHOD LockContainer(BOOL)
Lock or unlock the container.
SAxContainer()
Constructor for SAxContainer.
STDMETHOD ParseDisplayName(IBindCtx *, LPOLESTR, ULONG *, IMoniker **)
Parse a display name into a moniker.
STDMETHOD MonikerBindToObject(IMoniker *pMk, IBindCtx *pBC, IBindStatusCallback *pBSC, REFIID riid, void **ppvObj)
Bind a moniker to an object.
STDMETHOD CreateMoniker(LPOLESTR szName, IBindCtx *pBC, IMoniker **ppmk, DWORD dwReserved)
Create a moniker from a display name.
STDMETHOD EnumObjects(DWORD, IEnumUnknown **)
Enumerate objects in the container.
STDMETHOD QueryService(REFGUID guidService, REFIID riid, void **ppvObject)
Query for a service.
STDMETHOD MonikerBindToStorage(IMoniker *pMk, IBindCtx *pBC, IBindStatusCallback *pBSC, REFIID riid, void **ppvObj)
Bind a moniker to a storage object.
virtual ~SAxContainer()
Destructor for SAxContainer.
STDMETHOD QueryInterface(REFIID iid, void **object)
Query for an interface.
Delegate interface for ActiveX host operations.
virtual void OnAxInvalidate(LPCRECT pRect, BOOL bErase)=0
Notify the host that the ActiveX control needs to be invalidated.
virtual void OnAxSetCapture(BOOL fCapture)=0
Notify the host to set or release the mouse capture.
virtual void OnAxActivate(IUnknown *pCtrl)=0
Notify the host that the ActiveX control is being activated.
virtual HRESULT OnAxGetDC(LPCRECT pRect, DWORD grfFlags, HDC *phDC)=0
Get a device context for the ActiveX control.
virtual HWND GetAxHostWindow() const =0
Get the window handle of the ActiveX host.
virtual HRESULT OnAxReleaseDC(HDC hdc)=0
Release a previously obtained device context.