1 /////////////////////////////////////////////////////////////////////////////
2 // Name: msw/ole/activex.cpp
3 // Purpose: wxActiveXContainer implementation
4 // Author: Ryan Norton <wxprojects@comcast.net>, Lindsay Mathieson <???>
8 // Copyright: (c) 2003 Lindsay Mathieson, (c) 2005 Ryan Norton
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 #include "wx/wxprec.h"
26 #include "wx/dcclient.h"
27 #include "wx/msw/ole/activex.h"
30 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
34 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
36 #define DECLARE_OLE_UNKNOWN(cls)\
42 TAutoInitInt() : l(0) {}\
44 TAutoInitInt refCount, lockCount;\
45 static void _GetInterface(cls *self, REFIID iid, void **_interface, const char *&desc);\
48 HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, void ** ppvObject);\
49 ULONG STDMETHODCALLTYPE AddRef();\
50 ULONG STDMETHODCALLTYPE Release();\
51 ULONG STDMETHODCALLTYPE AddLock();\
52 ULONG STDMETHODCALLTYPE ReleaseLock()
54 #define DEFINE_OLE_TABLE(cls)\
55 LONG cls::GetRefCount() {return refCount.l;}\
56 HRESULT STDMETHODCALLTYPE cls::QueryInterface(REFIID iid, void ** ppvObject)\
62 const char *desc = NULL;\
63 cls::_GetInterface(this, iid, ppvObject, desc);\
66 return E_NOINTERFACE;\
68 ((IUnknown * )(*ppvObject))->AddRef();\
71 ULONG STDMETHODCALLTYPE cls::AddRef()\
73 InterlockedIncrement(&refCount.l);\
76 ULONG STDMETHODCALLTYPE cls::Release()\
80 InterlockedDecrement(&refCount.l);\
91 ULONG STDMETHODCALLTYPE cls::AddLock()\
93 InterlockedIncrement(&lockCount.l);\
96 ULONG STDMETHODCALLTYPE cls::ReleaseLock()\
100 InterlockedDecrement(&lockCount.l);\
108 #define DEFINE_OLE_BASE(cls)\
109 void cls::_GetInterface(cls *self, REFIID iid, void **_interface, const char *&desc)\
114 #define OLE_INTERFACE(_iid, _type)\
115 if (IsEqualIID(iid, _iid))\
117 *_interface = (IUnknown *) (_type *) self;\
122 #define OLE_IINTERFACE(_face) OLE_INTERFACE(IID_##_face, _face)
124 #define OLE_INTERFACE_CUSTOM(func)\
125 if (func(self, iid, _interface, desc))\
130 #define END_OLE_TABLE\
135 public IOleClientSite
,
136 public IOleInPlaceSiteEx
,
137 public IOleInPlaceFrame
,
138 public IOleItemContainer
,
140 public IOleCommandTarget
,
141 public IOleDocumentSite
,
143 public IOleControlSite
146 DECLARE_OLE_UNKNOWN(FrameSite
);
149 FrameSite(wxWindow
* win
, wxActiveXContainer
* win2
)
152 m_bSupportsWindowlessActivation
= true;
153 m_bInPlaceLocked
= false;
155 m_bInPlaceActive
= false;
156 m_bWindowless
= false;
158 m_nAmbientLocale
= 0;
159 m_clrAmbientForeColor
= ::GetSysColor(COLOR_WINDOWTEXT
);
160 m_clrAmbientBackColor
= ::GetSysColor(COLOR_WINDOW
);
161 m_bAmbientShowHatching
= true;
162 m_bAmbientShowGrabHandles
= true;
163 m_bAmbientAppearance
= true;
166 m_hWndParent
= (HWND
)win
->GetHWND();
168 virtual ~FrameSite(){}
169 //***************************IDispatch*****************************
170 HRESULT STDMETHODCALLTYPE
GetIDsOfNames(REFIID
, OLECHAR
** ,
171 unsigned int , LCID
,
173 { return E_NOTIMPL
; }
174 STDMETHOD(GetTypeInfo
)(unsigned int, LCID
, ITypeInfo
**)
175 { return E_NOTIMPL
; }
176 HRESULT STDMETHODCALLTYPE
GetTypeInfoCount(unsigned int *)
177 { return E_NOTIMPL
; }
178 HRESULT STDMETHODCALLTYPE
Invoke(DISPID dispIdMember
, REFIID
, LCID
,
179 WORD wFlags
, DISPPARAMS
*,
180 VARIANT
* pVarResult
, EXCEPINFO
*,
183 if (!(wFlags
& DISPATCH_PROPERTYGET
))
186 if (pVarResult
== NULL
)
189 //The most common case is boolean, use as an initial type
190 V_VT(pVarResult
) = VT_BOOL
;
192 switch (dispIdMember
)
194 case DISPID_AMBIENT_MESSAGEREFLECT
:
195 V_BOOL(pVarResult
)= FALSE
;
198 case DISPID_AMBIENT_DISPLAYASDEFAULT
:
199 V_BOOL(pVarResult
)= TRUE
;
202 case DISPID_AMBIENT_OFFLINEIFNOTCONNECTED
:
203 V_BOOL(pVarResult
) = TRUE
;
206 case DISPID_AMBIENT_SILENT
:
207 V_BOOL(pVarResult
)= TRUE
;
210 case DISPID_AMBIENT_APPEARANCE
:
211 pVarResult
->vt
= VT_BOOL
;
212 pVarResult
->boolVal
= m_bAmbientAppearance
;
215 case DISPID_AMBIENT_FORECOLOR
:
216 pVarResult
->vt
= VT_I4
;
217 pVarResult
->lVal
= (long) m_clrAmbientForeColor
;
220 case DISPID_AMBIENT_BACKCOLOR
:
221 pVarResult
->vt
= VT_I4
;
222 pVarResult
->lVal
= (long) m_clrAmbientBackColor
;
225 case DISPID_AMBIENT_LOCALEID
:
226 pVarResult
->vt
= VT_I4
;
227 pVarResult
->lVal
= (long) m_nAmbientLocale
;
230 case DISPID_AMBIENT_USERMODE
:
231 pVarResult
->vt
= VT_BOOL
;
232 pVarResult
->boolVal
= m_window
->m_bAmbientUserMode
;
235 case DISPID_AMBIENT_SHOWGRABHANDLES
:
236 pVarResult
->vt
= VT_BOOL
;
237 pVarResult
->boolVal
= m_bAmbientShowGrabHandles
;
240 case DISPID_AMBIENT_SHOWHATCHING
:
241 pVarResult
->vt
= VT_BOOL
;
242 pVarResult
->boolVal
= m_bAmbientShowHatching
;
246 return DISP_E_MEMBERNOTFOUND
;
252 //**************************IOleWindow***************************
253 HRESULT STDMETHODCALLTYPE
GetWindow(HWND
* phwnd
)
257 (*phwnd
) = m_hWndParent
;
260 HRESULT STDMETHODCALLTYPE
ContextSensitiveHelp(BOOL
)
262 //**************************IOleInPlaceUIWindow*****************
263 HRESULT STDMETHODCALLTYPE
GetBorder(LPRECT lprectBorder
)
265 if (lprectBorder
== NULL
)
267 return INPLACE_E_NOTOOLSPACE
;
269 HRESULT STDMETHODCALLTYPE
RequestBorderSpace(LPCBORDERWIDTHS pborderwidths
)
271 if (pborderwidths
== NULL
)
273 return INPLACE_E_NOTOOLSPACE
;
275 HRESULT STDMETHODCALLTYPE
SetBorderSpace(LPCBORDERWIDTHS
)
277 HRESULT STDMETHODCALLTYPE
SetActiveObject(
278 IOleInPlaceActiveObject
*pActiveObject
, LPCOLESTR
)
281 pActiveObject
->AddRef();
283 m_window
->m_oleInPlaceActiveObject
= pActiveObject
;
287 //********************IOleInPlaceFrame************************
289 STDMETHOD(InsertMenus
)(HMENU
, LPOLEMENUGROUPWIDTHS
){return S_OK
;}
290 STDMETHOD(SetMenu
)(HMENU
, HOLEMENU
, HWND
){ return S_OK
;}
291 STDMETHOD(RemoveMenus
)(HMENU
){return S_OK
;}
292 STDMETHOD(SetStatusText
)(LPCOLESTR
){ return S_OK
;}
293 HRESULT STDMETHODCALLTYPE
EnableModeless(BOOL
){return S_OK
;}
294 HRESULT STDMETHODCALLTYPE
TranslateAccelerator(LPMSG lpmsg
, WORD
)
296 // TODO: send an event with this id
297 if (m_window
->m_oleInPlaceActiveObject
.Ok())
298 m_window
->m_oleInPlaceActiveObject
->TranslateAccelerator(lpmsg
);
302 //*******************IOleInPlaceSite**************************
303 HRESULT STDMETHODCALLTYPE
CanInPlaceActivate(){return S_OK
;}
304 HRESULT STDMETHODCALLTYPE
OnInPlaceActivate()
305 { m_bInPlaceActive
= true; return S_OK
; }
306 HRESULT STDMETHODCALLTYPE
OnUIActivate()
307 { m_bUIActive
= true; return S_OK
; }
308 HRESULT STDMETHODCALLTYPE
GetWindowContext(IOleInPlaceFrame
**ppFrame
,
309 IOleInPlaceUIWindow
**ppDoc
,
312 LPOLEINPLACEFRAMEINFO lpFrameInfo
)
314 if (ppFrame
== NULL
|| ppDoc
== NULL
|| lprcPosRect
== NULL
||
315 lprcClipRect
== NULL
|| lpFrameInfo
== NULL
)
324 HRESULT hr
= QueryInterface(IID_IOleInPlaceFrame
, (void **) ppFrame
);
330 hr
= QueryInterface(IID_IOleInPlaceUIWindow
, (void **) ppDoc
);
333 (*ppFrame
)->Release();
339 ::GetClientRect(m_hWndParent
, &rect
);
342 lprcPosRect
->left
= lprcPosRect
->top
= 0;
343 lprcPosRect
->right
= rect
.right
;
344 lprcPosRect
->bottom
= rect
.bottom
;
348 lprcClipRect
->left
= lprcClipRect
->top
= 0;
349 lprcClipRect
->right
= rect
.right
;
350 lprcClipRect
->bottom
= rect
.bottom
;
353 memset(lpFrameInfo
, 0, sizeof(OLEINPLACEFRAMEINFO
));
354 lpFrameInfo
->cb
= sizeof(OLEINPLACEFRAMEINFO
);
355 lpFrameInfo
->hwndFrame
= m_hWndParent
;
359 HRESULT STDMETHODCALLTYPE
Scroll(SIZE
){return S_OK
;}
360 HRESULT STDMETHODCALLTYPE
OnUIDeactivate(BOOL
)
361 { m_bUIActive
= false; return S_OK
; }
362 HRESULT STDMETHODCALLTYPE
OnInPlaceDeactivate()
363 { m_bInPlaceActive
= false; return S_OK
; }
364 HRESULT STDMETHODCALLTYPE
DiscardUndoState(){return S_OK
;}
365 HRESULT STDMETHODCALLTYPE
DeactivateAndUndo(){return S_OK
; }
366 HRESULT STDMETHODCALLTYPE
OnPosRectChange(LPCRECT lprcPosRect
)
368 if (m_window
->m_oleInPlaceObject
.Ok() && lprcPosRect
)
370 m_window
->m_oleInPlaceObject
->SetObjectRects(
371 lprcPosRect
, lprcPosRect
);
375 //*************************IOleInPlaceSiteEx***********************
376 HRESULT STDMETHODCALLTYPE
OnInPlaceActivateEx(BOOL
* pfNoRedraw
, DWORD
)
378 OleLockRunning(m_window
->m_ActiveX
, TRUE
, FALSE
);
380 (*pfNoRedraw
) = FALSE
;
384 HRESULT STDMETHODCALLTYPE
OnInPlaceDeactivateEx(BOOL
)
386 OleLockRunning(m_window
->m_ActiveX
, FALSE
, FALSE
);
389 STDMETHOD(RequestUIActivate
)(){ return S_OK
;}
390 //*************************IOleClientSite**************************
391 HRESULT STDMETHODCALLTYPE
SaveObject(){return S_OK
;}
392 const char *OleGetMonikerToStr(DWORD dwAssign
)
396 case OLEGETMONIKER_ONLYIFTHERE
: return "OLEGETMONIKER_ONLYIFTHERE";
397 case OLEGETMONIKER_FORCEASSIGN
: return "OLEGETMONIKER_FORCEASSIGN";
398 case OLEGETMONIKER_UNASSIGN
: return "OLEGETMONIKER_UNASSIGN";
399 case OLEGETMONIKER_TEMPFORUSER
: return "OLEGETMONIKER_TEMPFORUSER";
400 default : return "Bad Enum";
404 const char *OleGetWhicMonikerStr(DWORD dwWhichMoniker
)
406 switch(dwWhichMoniker
)
408 case OLEWHICHMK_CONTAINER
: return "OLEWHICHMK_CONTAINER";
409 case OLEWHICHMK_OBJREL
: return "OLEWHICHMK_OBJREL";
410 case OLEWHICHMK_OBJFULL
: return "OLEWHICHMK_OBJFULL";
411 default : return "Bad Enum";
414 STDMETHOD(GetMoniker
)(DWORD
, DWORD
, IMoniker
**){return E_FAIL
;}
415 HRESULT STDMETHODCALLTYPE
GetContainer(LPOLECONTAINER
* ppContainer
)
417 if (ppContainer
== NULL
)
419 HRESULT hr
= QueryInterface(
420 IID_IOleContainer
, (void**)(ppContainer
));
421 wxASSERT(SUCCEEDED(hr
));
424 HRESULT STDMETHODCALLTYPE
ShowObject()
426 if (m_window
->m_oleObjectHWND
)
427 ::ShowWindow(m_window
->m_oleObjectHWND
, SW_SHOW
);
430 STDMETHOD(OnShowWindow
)(BOOL
){return S_OK
;}
431 STDMETHOD(RequestNewObjectLayout
)(){return E_NOTIMPL
;}
432 //********************IParseDisplayName***************************
433 HRESULT STDMETHODCALLTYPE
ParseDisplayName(
434 IBindCtx
*, LPOLESTR
, ULONG
*, IMoniker
**){return E_NOTIMPL
;}
435 //********************IOleContainer*******************************
436 STDMETHOD(EnumObjects
)(DWORD
, IEnumUnknown
**){return E_NOTIMPL
;}
437 HRESULT STDMETHODCALLTYPE
LockContainer(BOOL
){return S_OK
;}
438 //********************IOleItemContainer***************************
439 HRESULT STDMETHODCALLTYPE
445 (LPOLESTR pszItem
, DWORD
, IBindCtx
*, REFIID
, void ** ppvObject
)
447 if (pszItem
== NULL
|| ppvObject
== NULL
)
450 return MK_E_NOOBJECT
;
452 HRESULT STDMETHODCALLTYPE
GetObjectStorage(
453 LPOLESTR pszItem
, IBindCtx
* , REFIID
, void ** ppvStorage
)
455 if (pszItem
== NULL
|| ppvStorage
== NULL
)
458 return MK_E_NOOBJECT
;
460 HRESULT STDMETHODCALLTYPE
IsRunning(LPOLESTR pszItem
)
464 return MK_E_NOOBJECT
;
466 //***********************IOleControlSite*****************************
467 HRESULT STDMETHODCALLTYPE
OnControlInfoChanged()
469 HRESULT STDMETHODCALLTYPE
LockInPlaceActive(BOOL fLock
)
471 m_bInPlaceLocked
= (fLock
) ? true : false;
474 HRESULT STDMETHODCALLTYPE
GetExtendedControl(IDispatch
**)
476 HRESULT STDMETHODCALLTYPE
TransformCoords(
477 POINTL
* pPtlHimetric
, POINTF
* pPtfContainer
, DWORD
)
479 if (pPtlHimetric
== NULL
|| pPtfContainer
== NULL
)
483 HRESULT STDMETHODCALLTYPE
TranslateAccelerator(LPMSG
, DWORD
)
485 HRESULT STDMETHODCALLTYPE
OnFocus(BOOL
){return S_OK
;}
486 HRESULT STDMETHODCALLTYPE
ShowPropertyFrame(){return E_NOTIMPL
;}
487 //**************************IOleCommandTarget***********************
488 HRESULT STDMETHODCALLTYPE
QueryStatus(const GUID
*, ULONG cCmds
,
489 OLECMD prgCmds
[], OLECMDTEXT
*)
491 if (prgCmds
== NULL
) return E_INVALIDARG
;
492 for (ULONG nCmd
= 0; nCmd
< cCmds
; nCmd
++)
494 // unsupported by default
495 prgCmds
[nCmd
].cmdf
= 0;
497 return OLECMDERR_E_UNKNOWNGROUP
;
500 HRESULT STDMETHODCALLTYPE
Exec(const GUID
*, DWORD
,
501 DWORD
, VARIANTARG
*, VARIANTARG
*)
502 {return OLECMDERR_E_NOTSUPPORTED
;}
504 //**********************IAdviseSink************************************
505 void STDMETHODCALLTYPE
OnDataChange(FORMATETC
*, STGMEDIUM
*) {}
506 void STDMETHODCALLTYPE
OnViewChange(DWORD
, LONG
) {}
507 void STDMETHODCALLTYPE
OnRename(IMoniker
*){}
508 void STDMETHODCALLTYPE
OnSave(){}
509 void STDMETHODCALLTYPE
OnClose(){}
511 //**********************IOleDocumentSite***************************
512 HRESULT STDMETHODCALLTYPE
ActivateMe(
513 IOleDocumentView __RPC_FAR
*pViewToActivate
)
515 wxAutoIOleInPlaceSite
inPlaceSite(
516 IID_IOleInPlaceSite
, (IDispatch
*) this);
517 if (!inPlaceSite
.Ok())
522 m_window
->m_docView
= pViewToActivate
;
523 m_window
->m_docView
->SetInPlaceSite(inPlaceSite
);
527 wxAutoIOleDocument
oleDoc(
528 IID_IOleDocument
, m_window
->m_oleObject
);
532 HRESULT hr
= oleDoc
->CreateView(inPlaceSite
, NULL
,
533 0, m_window
->m_docView
.GetRef());
537 m_window
->m_docView
->SetInPlaceSite(inPlaceSite
);
540 m_window
->m_docView
->UIActivate(TRUE
);
546 wxActiveXContainer
* m_window
;
551 bool m_bSupportsWindowlessActivation
;
552 bool m_bInPlaceLocked
;
553 bool m_bInPlaceActive
;
557 LCID m_nAmbientLocale
;
558 COLORREF m_clrAmbientForeColor
;
559 COLORREF m_clrAmbientBackColor
;
560 bool m_bAmbientShowHatching
;
561 bool m_bAmbientShowGrabHandles
;
562 bool m_bAmbientAppearance
;
565 DEFINE_OLE_TABLE(FrameSite
)
566 OLE_INTERFACE(IID_IUnknown
, IOleClientSite
)
567 OLE_IINTERFACE(IOleClientSite
)
568 OLE_INTERFACE(IID_IOleWindow
, IOleInPlaceSite
)
569 OLE_IINTERFACE(IOleInPlaceSite
)
570 OLE_IINTERFACE(IOleInPlaceSiteEx
)
571 OLE_IINTERFACE(IOleInPlaceUIWindow
)
572 OLE_IINTERFACE(IOleInPlaceFrame
)
573 OLE_IINTERFACE(IParseDisplayName
)
574 OLE_IINTERFACE(IOleContainer
)
575 OLE_IINTERFACE(IOleItemContainer
)
576 OLE_IINTERFACE(IDispatch
)
577 OLE_IINTERFACE(IOleCommandTarget
)
578 OLE_IINTERFACE(IOleDocumentSite
)
579 OLE_IINTERFACE(IAdviseSink
)
580 OLE_IINTERFACE(IOleControlSite
)
584 wxActiveXContainer::wxActiveXContainer(wxWindow
* parent
, REFIID iid
, IUnknown
* pUnk
)
585 : m_realparent(parent
)
587 m_bAmbientUserMode
= true;
588 m_docAdviseCookie
= 0;
589 CreateActiveX(iid
, pUnk
);
592 wxActiveXContainer::~wxActiveXContainer()
594 // disconnect connection points
595 if (m_oleInPlaceObject
.Ok())
597 m_oleInPlaceObject
->InPlaceDeactivate();
598 m_oleInPlaceObject
->UIDeactivate();
601 if (m_oleObject
.Ok())
603 if (m_docAdviseCookie
!= 0)
604 m_oleObject
->Unadvise(m_docAdviseCookie
);
607 OLEIVERB_HIDE
, NULL
, m_clientSite
, 0, (HWND
) GetHWND(), NULL
);
608 m_oleObject
->Close(OLECLOSE_NOSAVE
);
609 m_oleObject
->SetClientSite(NULL
);
613 void wxActiveXContainer::CreateActiveX(REFIID iid
, IUnknown
* pUnk
)
616 hret
= m_ActiveX
.QueryInterface(iid
, pUnk
);
617 wxASSERT(SUCCEEDED(hret
));
620 FrameSite
*frame
= new FrameSite(m_realparent
, this);
622 hret
= m_clientSite
.QueryInterface(
623 IID_IOleClientSite
, (IDispatch
*) frame
);
624 wxASSERT(SUCCEEDED(hret
));
626 wxAutoIAdviseSink
adviseSink(IID_IAdviseSink
, (IDispatch
*) frame
);
627 wxASSERT(adviseSink
.Ok());
629 // Get Dispatch interface
630 hret
= m_Dispatch
.QueryInterface(IID_IDispatch
, m_ActiveX
);
632 // Get IOleObject interface
633 hret
= m_oleObject
.QueryInterface(IID_IOleObject
, m_ActiveX
);
634 wxASSERT(SUCCEEDED(hret
));
636 // get IViewObject Interface
637 hret
= m_viewObject
.QueryInterface(IID_IViewObject
, m_ActiveX
);
638 wxASSERT(SUCCEEDED(hret
));
641 m_docAdviseCookie
= 0;
642 hret
= m_oleObject
->Advise(adviseSink
, &m_docAdviseCookie
);
643 m_oleObject
->SetHostNames(L
"wxActiveXContainer", NULL
);
644 OleSetContainedObject(m_oleObject
, TRUE
);
648 // Get IOleInPlaceObject interface
649 hret
= m_oleInPlaceObject
.QueryInterface(
650 IID_IOleInPlaceObject
, m_ActiveX
);
651 wxASSERT(SUCCEEDED(hret
));
655 m_oleObject
->GetMiscStatus(DVASPECT_CONTENT
, &dwMiscStatus
);
656 wxASSERT(SUCCEEDED(hret
));
658 // set client site first ?
659 if (dwMiscStatus
& OLEMISC_SETCLIENTSITEFIRST
)
660 m_oleObject
->SetClientSite(m_clientSite
);
664 wxAutoIPersistStreamInit
665 pPersistStreamInit(IID_IPersistStreamInit
, m_oleObject
);
667 if (pPersistStreamInit
.Ok())
669 hret
= pPersistStreamInit
->InitNew();
672 if (! (dwMiscStatus
& OLEMISC_SETCLIENTSITEFIRST
))
673 m_oleObject
->SetClientSite(m_clientSite
);
677 ::GetClientRect((HWND
)m_realparent
->GetHWND(), &posRect
);
681 if (m_oleInPlaceObject
.Ok())
683 hret
= m_oleInPlaceObject
->GetWindow(&m_oleObjectHWND
);
685 ::SetActiveWindow(m_oleObjectHWND
);
689 if (! (dwMiscStatus
& OLEMISC_INVISIBLEATRUNTIME
))
691 if (posRect
.right
> 0 && posRect
.bottom
> 0 &&
692 m_oleInPlaceObject
.Ok())
693 m_oleInPlaceObject
->SetObjectRects(&posRect
, &posRect
);
695 hret
= m_oleObject
->DoVerb(OLEIVERB_INPLACEACTIVATE
, NULL
,
696 m_clientSite
, 0, (HWND
)m_realparent
->GetHWND(), &posRect
);
697 hret
= m_oleObject
->DoVerb(OLEIVERB_SHOW
, 0, m_clientSite
, 0,
698 (HWND
)m_realparent
->GetHWND(), &posRect
);
701 if (! m_oleObjectHWND
&& m_oleInPlaceObject
.Ok())
703 hret
= m_oleInPlaceObject
->GetWindow(&m_oleObjectHWND
);
708 ::SetActiveWindow(m_oleObjectHWND
);
709 ::ShowWindow(m_oleObjectHWND
, SW_SHOW
);
711 this->AssociateHandle(m_oleObjectHWND
);
712 this->Reparent(m_realparent
);
714 wxWindow
* pWnd
= m_realparent
;
715 int id
= m_realparent
->GetId();
717 pWnd
->Connect(id
, wxEVT_SIZE
,
718 wxSizeEventHandler(wxActiveXContainer::OnSize
), 0, this);
719 pWnd
->Connect(id
, wxEVT_SET_FOCUS
,
720 wxFocusEventHandler(wxActiveXContainer::OnSetFocus
), 0, this);
721 pWnd
->Connect(id
, wxEVT_KILL_FOCUS
,
722 wxFocusEventHandler(wxActiveXContainer::OnKillFocus
), 0, this);
726 #define HIMETRIC_PER_INCH 2540
727 #define MAP_PIX_TO_LOGHIM(x,ppli) MulDiv(HIMETRIC_PER_INCH, (x), (ppli))
729 static void PixelsToHimetric(SIZEL
&sz
)
737 HDC dc
= GetDC(NULL
);
738 logX
= GetDeviceCaps(dc
, LOGPIXELSX
);
739 logY
= GetDeviceCaps(dc
, LOGPIXELSY
);
743 #define HIMETRIC_INCH 2540
744 #define CONVERT(x, logpixels) MulDiv(HIMETRIC_INCH, (x), (logpixels))
746 sz
.cx
= CONVERT(sz
.cx
, logX
);
747 sz
.cy
= CONVERT(sz
.cy
, logY
);
754 void wxActiveXContainer::OnSize(wxSizeEvent
& event
)
757 GetParent()->GetClientSize(&w
, &h
);
765 if (w
<= 0 && h
<= 0)
768 // extents are in HIMETRIC units
769 if (m_oleObject
.Ok())
772 PixelsToHimetric(sz
);
776 m_oleObject
->GetExtent(DVASPECT_CONTENT
, &sz2
);
777 if (sz2
.cx
!= sz
.cx
|| sz
.cy
!= sz2
.cy
)
778 m_oleObject
->SetExtent(DVASPECT_CONTENT
, &sz
);
781 if (m_oleInPlaceObject
.Ok())
782 m_oleInPlaceObject
->SetObjectRects(&posRect
, &posRect
);
787 void wxActiveXContainer::OnPaint(wxPaintEvent
& WXUNUSED(event
))
790 // Draw only when control is windowless or deactivated
795 GetParent()->GetSize(&w
, &h
);
802 ::RedrawWindow(m_oleObjectHWND
, NULL
, NULL
, RDW_INTERNALPAINT
);
803 RECTL
*prcBounds
= (RECTL
*) &posRect
;
804 m_viewObject
->Draw(DVASPECT_CONTENT
, -1, NULL
, NULL
, NULL
,
805 (HDC
)dc
.GetHDC(), prcBounds
, NULL
, NULL
, 0);
810 // We've got this one I think
814 void wxActiveXContainer::OnSetFocus(wxFocusEvent
& event
)
816 if (m_oleInPlaceActiveObject
.Ok())
817 m_oleInPlaceActiveObject
->OnFrameWindowActivate(TRUE
);
822 void wxActiveXContainer::OnKillFocus(wxFocusEvent
& event
)
824 if (m_oleInPlaceActiveObject
.Ok())
825 m_oleInPlaceActiveObject
->OnFrameWindowActivate(FALSE
);