1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/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"
28 #include "wx/msw/ole/activex.h"
31 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
35 //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
37 #define DECLARE_OLE_UNKNOWN(cls)\
43 TAutoInitInt() : l(0) {}\
45 TAutoInitInt refCount, lockCount;\
46 static void _GetInterface(cls *self, REFIID iid, void **_interface, const char *&desc);\
49 HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, void ** ppvObject);\
50 ULONG STDMETHODCALLTYPE AddRef();\
51 ULONG STDMETHODCALLTYPE Release();\
52 ULONG STDMETHODCALLTYPE AddLock();\
53 ULONG STDMETHODCALLTYPE ReleaseLock()
55 #define DEFINE_OLE_TABLE(cls)\
56 LONG cls::GetRefCount() {return refCount.l;}\
57 HRESULT STDMETHODCALLTYPE cls::QueryInterface(REFIID iid, void ** ppvObject)\
63 const char *desc = NULL;\
64 cls::_GetInterface(this, iid, ppvObject, desc);\
67 return E_NOINTERFACE;\
69 ((IUnknown * )(*ppvObject))->AddRef();\
72 ULONG STDMETHODCALLTYPE cls::AddRef()\
74 InterlockedIncrement(&refCount.l);\
77 ULONG STDMETHODCALLTYPE cls::Release()\
81 InterlockedDecrement(&refCount.l);\
92 ULONG STDMETHODCALLTYPE cls::AddLock()\
94 InterlockedIncrement(&lockCount.l);\
97 ULONG STDMETHODCALLTYPE cls::ReleaseLock()\
101 InterlockedDecrement(&lockCount.l);\
109 #define DEFINE_OLE_BASE(cls)\
110 void cls::_GetInterface(cls *self, REFIID iid, void **_interface, const char *&desc)\
115 #define OLE_INTERFACE(_iid, _type)\
116 if (IsEqualIID(iid, _iid))\
118 *_interface = (IUnknown *) (_type *) self;\
123 #define OLE_IINTERFACE(_face) OLE_INTERFACE(IID_##_face, _face)
125 #define OLE_INTERFACE_CUSTOM(func)\
126 if (func(self, iid, _interface, desc))\
131 #define END_OLE_TABLE\
136 public IOleClientSite
,
137 public IOleInPlaceSiteEx
,
138 public IOleInPlaceFrame
,
139 public IOleItemContainer
,
141 public IOleCommandTarget
,
142 public IOleDocumentSite
,
144 public IOleControlSite
147 DECLARE_OLE_UNKNOWN(FrameSite
);
150 FrameSite(wxWindow
* win
, wxActiveXContainer
* win2
)
153 m_bSupportsWindowlessActivation
= true;
154 m_bInPlaceLocked
= false;
156 m_bInPlaceActive
= false;
157 m_bWindowless
= false;
159 m_nAmbientLocale
= 0;
160 m_clrAmbientForeColor
= ::GetSysColor(COLOR_WINDOWTEXT
);
161 m_clrAmbientBackColor
= ::GetSysColor(COLOR_WINDOW
);
162 m_bAmbientShowHatching
= true;
163 m_bAmbientShowGrabHandles
= true;
164 m_bAmbientAppearance
= true;
167 m_hWndParent
= (HWND
)win
->GetHWND();
169 virtual ~FrameSite(){}
170 //***************************IDispatch*****************************
171 HRESULT STDMETHODCALLTYPE
GetIDsOfNames(REFIID
, OLECHAR
** ,
172 unsigned int , LCID
,
174 { return E_NOTIMPL
; }
175 STDMETHOD(GetTypeInfo
)(unsigned int, LCID
, ITypeInfo
**)
176 { return E_NOTIMPL
; }
177 HRESULT STDMETHODCALLTYPE
GetTypeInfoCount(unsigned int *)
178 { return E_NOTIMPL
; }
179 HRESULT STDMETHODCALLTYPE
Invoke(DISPID dispIdMember
, REFIID
, LCID
,
180 WORD wFlags
, DISPPARAMS
*,
181 VARIANT
* pVarResult
, EXCEPINFO
*,
184 if (!(wFlags
& DISPATCH_PROPERTYGET
))
187 if (pVarResult
== NULL
)
190 //The most common case is boolean, use as an initial type
191 V_VT(pVarResult
) = VT_BOOL
;
193 switch (dispIdMember
)
195 case DISPID_AMBIENT_MESSAGEREFLECT
:
196 V_BOOL(pVarResult
)= FALSE
;
199 case DISPID_AMBIENT_DISPLAYASDEFAULT
:
200 V_BOOL(pVarResult
)= TRUE
;
203 case DISPID_AMBIENT_OFFLINEIFNOTCONNECTED
:
204 V_BOOL(pVarResult
) = TRUE
;
207 case DISPID_AMBIENT_SILENT
:
208 V_BOOL(pVarResult
)= TRUE
;
211 case DISPID_AMBIENT_APPEARANCE
:
212 pVarResult
->vt
= VT_BOOL
;
213 pVarResult
->boolVal
= m_bAmbientAppearance
;
216 case DISPID_AMBIENT_FORECOLOR
:
217 pVarResult
->vt
= VT_I4
;
218 pVarResult
->lVal
= (long) m_clrAmbientForeColor
;
221 case DISPID_AMBIENT_BACKCOLOR
:
222 pVarResult
->vt
= VT_I4
;
223 pVarResult
->lVal
= (long) m_clrAmbientBackColor
;
226 case DISPID_AMBIENT_LOCALEID
:
227 pVarResult
->vt
= VT_I4
;
228 pVarResult
->lVal
= (long) m_nAmbientLocale
;
231 case DISPID_AMBIENT_USERMODE
:
232 pVarResult
->vt
= VT_BOOL
;
233 pVarResult
->boolVal
= m_window
->m_bAmbientUserMode
;
236 case DISPID_AMBIENT_SHOWGRABHANDLES
:
237 pVarResult
->vt
= VT_BOOL
;
238 pVarResult
->boolVal
= m_bAmbientShowGrabHandles
;
241 case DISPID_AMBIENT_SHOWHATCHING
:
242 pVarResult
->vt
= VT_BOOL
;
243 pVarResult
->boolVal
= m_bAmbientShowHatching
;
247 return DISP_E_MEMBERNOTFOUND
;
253 //**************************IOleWindow***************************
254 HRESULT STDMETHODCALLTYPE
GetWindow(HWND
* phwnd
)
258 (*phwnd
) = m_hWndParent
;
261 HRESULT STDMETHODCALLTYPE
ContextSensitiveHelp(BOOL
)
263 //**************************IOleInPlaceUIWindow*****************
264 HRESULT STDMETHODCALLTYPE
GetBorder(LPRECT lprectBorder
)
266 if (lprectBorder
== NULL
)
268 return INPLACE_E_NOTOOLSPACE
;
270 HRESULT STDMETHODCALLTYPE
RequestBorderSpace(LPCBORDERWIDTHS pborderwidths
)
272 if (pborderwidths
== NULL
)
274 return INPLACE_E_NOTOOLSPACE
;
276 HRESULT STDMETHODCALLTYPE
SetBorderSpace(LPCBORDERWIDTHS
)
278 HRESULT STDMETHODCALLTYPE
SetActiveObject(
279 IOleInPlaceActiveObject
*pActiveObject
, LPCOLESTR
)
282 pActiveObject
->AddRef();
284 m_window
->m_oleInPlaceActiveObject
= pActiveObject
;
288 //********************IOleInPlaceFrame************************
290 STDMETHOD(InsertMenus
)(HMENU
, LPOLEMENUGROUPWIDTHS
){return S_OK
;}
291 STDMETHOD(SetMenu
)(HMENU
, HOLEMENU
, HWND
){ return S_OK
;}
292 STDMETHOD(RemoveMenus
)(HMENU
){return S_OK
;}
293 STDMETHOD(SetStatusText
)(LPCOLESTR
){ return S_OK
;}
294 HRESULT STDMETHODCALLTYPE
EnableModeless(BOOL
){return S_OK
;}
295 HRESULT STDMETHODCALLTYPE
TranslateAccelerator(LPMSG lpmsg
, WORD
)
297 // TODO: send an event with this id
298 if (m_window
->m_oleInPlaceActiveObject
.Ok())
299 m_window
->m_oleInPlaceActiveObject
->TranslateAccelerator(lpmsg
);
303 //*******************IOleInPlaceSite**************************
304 HRESULT STDMETHODCALLTYPE
CanInPlaceActivate(){return S_OK
;}
305 HRESULT STDMETHODCALLTYPE
OnInPlaceActivate()
306 { m_bInPlaceActive
= true; return S_OK
; }
307 HRESULT STDMETHODCALLTYPE
OnUIActivate()
308 { m_bUIActive
= true; return S_OK
; }
309 HRESULT STDMETHODCALLTYPE
GetWindowContext(IOleInPlaceFrame
**ppFrame
,
310 IOleInPlaceUIWindow
**ppDoc
,
313 LPOLEINPLACEFRAMEINFO lpFrameInfo
)
315 if (ppFrame
== NULL
|| ppDoc
== NULL
|| lprcPosRect
== NULL
||
316 lprcClipRect
== NULL
|| lpFrameInfo
== NULL
)
325 HRESULT hr
= QueryInterface(IID_IOleInPlaceFrame
, (void **) ppFrame
);
331 hr
= QueryInterface(IID_IOleInPlaceUIWindow
, (void **) ppDoc
);
334 (*ppFrame
)->Release();
340 ::GetClientRect(m_hWndParent
, &rect
);
343 lprcPosRect
->left
= lprcPosRect
->top
= 0;
344 lprcPosRect
->right
= rect
.right
;
345 lprcPosRect
->bottom
= rect
.bottom
;
349 lprcClipRect
->left
= lprcClipRect
->top
= 0;
350 lprcClipRect
->right
= rect
.right
;
351 lprcClipRect
->bottom
= rect
.bottom
;
354 memset(lpFrameInfo
, 0, sizeof(OLEINPLACEFRAMEINFO
));
355 lpFrameInfo
->cb
= sizeof(OLEINPLACEFRAMEINFO
);
356 lpFrameInfo
->hwndFrame
= m_hWndParent
;
360 HRESULT STDMETHODCALLTYPE
Scroll(SIZE
){return S_OK
;}
361 HRESULT STDMETHODCALLTYPE
OnUIDeactivate(BOOL
)
362 { m_bUIActive
= false; return S_OK
; }
363 HRESULT STDMETHODCALLTYPE
OnInPlaceDeactivate()
364 { m_bInPlaceActive
= false; return S_OK
; }
365 HRESULT STDMETHODCALLTYPE
DiscardUndoState(){return S_OK
;}
366 HRESULT STDMETHODCALLTYPE
DeactivateAndUndo(){return S_OK
; }
367 HRESULT STDMETHODCALLTYPE
OnPosRectChange(LPCRECT lprcPosRect
)
369 if (m_window
->m_oleInPlaceObject
.Ok() && lprcPosRect
)
371 m_window
->m_oleInPlaceObject
->SetObjectRects(
372 lprcPosRect
, lprcPosRect
);
376 //*************************IOleInPlaceSiteEx***********************
377 HRESULT STDMETHODCALLTYPE
OnInPlaceActivateEx(BOOL
* pfNoRedraw
, DWORD
)
379 OleLockRunning(m_window
->m_ActiveX
, TRUE
, FALSE
);
381 (*pfNoRedraw
) = FALSE
;
385 HRESULT STDMETHODCALLTYPE
OnInPlaceDeactivateEx(BOOL
)
387 OleLockRunning(m_window
->m_ActiveX
, FALSE
, FALSE
);
390 STDMETHOD(RequestUIActivate
)(){ return S_OK
;}
391 //*************************IOleClientSite**************************
392 HRESULT STDMETHODCALLTYPE
SaveObject(){return S_OK
;}
393 const char *OleGetMonikerToStr(DWORD dwAssign
)
397 case OLEGETMONIKER_ONLYIFTHERE
: return "OLEGETMONIKER_ONLYIFTHERE";
398 case OLEGETMONIKER_FORCEASSIGN
: return "OLEGETMONIKER_FORCEASSIGN";
399 case OLEGETMONIKER_UNASSIGN
: return "OLEGETMONIKER_UNASSIGN";
400 case OLEGETMONIKER_TEMPFORUSER
: return "OLEGETMONIKER_TEMPFORUSER";
401 default : return "Bad Enum";
405 const char *OleGetWhicMonikerStr(DWORD dwWhichMoniker
)
407 switch(dwWhichMoniker
)
409 case OLEWHICHMK_CONTAINER
: return "OLEWHICHMK_CONTAINER";
410 case OLEWHICHMK_OBJREL
: return "OLEWHICHMK_OBJREL";
411 case OLEWHICHMK_OBJFULL
: return "OLEWHICHMK_OBJFULL";
412 default : return "Bad Enum";
415 STDMETHOD(GetMoniker
)(DWORD
, DWORD
, IMoniker
**){return E_FAIL
;}
416 HRESULT STDMETHODCALLTYPE
GetContainer(LPOLECONTAINER
* ppContainer
)
418 if (ppContainer
== NULL
)
420 HRESULT hr
= QueryInterface(
421 IID_IOleContainer
, (void**)(ppContainer
));
422 wxASSERT(SUCCEEDED(hr
));
425 HRESULT STDMETHODCALLTYPE
ShowObject()
427 if (m_window
->m_oleObjectHWND
)
428 ::ShowWindow(m_window
->m_oleObjectHWND
, SW_SHOW
);
431 STDMETHOD(OnShowWindow
)(BOOL
){return S_OK
;}
432 STDMETHOD(RequestNewObjectLayout
)(){return E_NOTIMPL
;}
433 //********************IParseDisplayName***************************
434 HRESULT STDMETHODCALLTYPE
ParseDisplayName(
435 IBindCtx
*, LPOLESTR
, ULONG
*, IMoniker
**){return E_NOTIMPL
;}
436 //********************IOleContainer*******************************
437 STDMETHOD(EnumObjects
)(DWORD
, IEnumUnknown
**){return E_NOTIMPL
;}
438 HRESULT STDMETHODCALLTYPE
LockContainer(BOOL
){return S_OK
;}
439 //********************IOleItemContainer***************************
440 HRESULT STDMETHODCALLTYPE
441 #if defined(__WXWINCE__)
443 #elif defined(_UNICODE)
448 (LPOLESTR pszItem
, DWORD
, IBindCtx
*, REFIID
, void ** ppvObject
)
450 if (pszItem
== NULL
|| ppvObject
== NULL
)
453 return MK_E_NOOBJECT
;
455 HRESULT STDMETHODCALLTYPE
GetObjectStorage(
456 LPOLESTR pszItem
, IBindCtx
* , REFIID
, void ** ppvStorage
)
458 if (pszItem
== NULL
|| ppvStorage
== NULL
)
461 return MK_E_NOOBJECT
;
463 HRESULT STDMETHODCALLTYPE
IsRunning(LPOLESTR pszItem
)
467 return MK_E_NOOBJECT
;
469 //***********************IOleControlSite*****************************
470 HRESULT STDMETHODCALLTYPE
OnControlInfoChanged()
472 HRESULT STDMETHODCALLTYPE
LockInPlaceActive(BOOL fLock
)
474 m_bInPlaceLocked
= (fLock
) ? true : false;
477 HRESULT STDMETHODCALLTYPE
GetExtendedControl(IDispatch
**)
479 HRESULT STDMETHODCALLTYPE
TransformCoords(
480 POINTL
* pPtlHimetric
, POINTF
* pPtfContainer
, DWORD
)
482 if (pPtlHimetric
== NULL
|| pPtfContainer
== NULL
)
486 HRESULT STDMETHODCALLTYPE
TranslateAccelerator(LPMSG
, DWORD
)
488 HRESULT STDMETHODCALLTYPE
OnFocus(BOOL
){return S_OK
;}
489 HRESULT STDMETHODCALLTYPE
ShowPropertyFrame(){return E_NOTIMPL
;}
490 //**************************IOleCommandTarget***********************
491 HRESULT STDMETHODCALLTYPE
QueryStatus(const GUID
*, ULONG cCmds
,
492 OLECMD prgCmds
[], OLECMDTEXT
*)
494 if (prgCmds
== NULL
) return E_INVALIDARG
;
495 for (ULONG nCmd
= 0; nCmd
< cCmds
; nCmd
++)
497 // unsupported by default
498 prgCmds
[nCmd
].cmdf
= 0;
500 return OLECMDERR_E_UNKNOWNGROUP
;
503 HRESULT STDMETHODCALLTYPE
Exec(const GUID
*, DWORD
,
504 DWORD
, VARIANTARG
*, VARIANTARG
*)
505 {return OLECMDERR_E_NOTSUPPORTED
;}
507 //**********************IAdviseSink************************************
508 void STDMETHODCALLTYPE
OnDataChange(FORMATETC
*, STGMEDIUM
*) {}
509 void STDMETHODCALLTYPE
OnViewChange(DWORD
, LONG
) {}
510 void STDMETHODCALLTYPE
OnRename(IMoniker
*){}
511 void STDMETHODCALLTYPE
OnSave(){}
512 void STDMETHODCALLTYPE
OnClose(){}
514 //**********************IOleDocumentSite***************************
515 HRESULT STDMETHODCALLTYPE
ActivateMe(
516 IOleDocumentView __RPC_FAR
*pViewToActivate
)
518 wxAutoIOleInPlaceSite
inPlaceSite(
519 IID_IOleInPlaceSite
, (IDispatch
*) this);
520 if (!inPlaceSite
.Ok())
525 m_window
->m_docView
= pViewToActivate
;
526 m_window
->m_docView
->SetInPlaceSite(inPlaceSite
);
530 wxAutoIOleDocument
oleDoc(
531 IID_IOleDocument
, m_window
->m_oleObject
);
535 HRESULT hr
= oleDoc
->CreateView(inPlaceSite
, NULL
,
536 0, m_window
->m_docView
.GetRef());
540 m_window
->m_docView
->SetInPlaceSite(inPlaceSite
);
543 m_window
->m_docView
->UIActivate(TRUE
);
549 wxActiveXContainer
* m_window
;
554 bool m_bSupportsWindowlessActivation
;
555 bool m_bInPlaceLocked
;
556 bool m_bInPlaceActive
;
560 LCID m_nAmbientLocale
;
561 COLORREF m_clrAmbientForeColor
;
562 COLORREF m_clrAmbientBackColor
;
563 bool m_bAmbientShowHatching
;
564 bool m_bAmbientShowGrabHandles
;
565 bool m_bAmbientAppearance
;
568 DEFINE_OLE_TABLE(FrameSite
)
569 OLE_INTERFACE(IID_IUnknown
, IOleClientSite
)
570 OLE_IINTERFACE(IOleClientSite
)
571 OLE_INTERFACE(IID_IOleWindow
, IOleInPlaceSite
)
572 OLE_IINTERFACE(IOleInPlaceSite
)
573 OLE_IINTERFACE(IOleInPlaceSiteEx
)
574 OLE_IINTERFACE(IOleInPlaceUIWindow
)
575 OLE_IINTERFACE(IOleInPlaceFrame
)
576 OLE_IINTERFACE(IParseDisplayName
)
577 OLE_IINTERFACE(IOleContainer
)
578 OLE_IINTERFACE(IOleItemContainer
)
579 OLE_IINTERFACE(IDispatch
)
580 OLE_IINTERFACE(IOleCommandTarget
)
581 OLE_IINTERFACE(IOleDocumentSite
)
582 OLE_IINTERFACE(IAdviseSink
)
583 OLE_IINTERFACE(IOleControlSite
)
587 wxActiveXContainer::wxActiveXContainer(wxWindow
* parent
, REFIID iid
, IUnknown
* pUnk
)
588 : m_realparent(parent
)
590 m_bAmbientUserMode
= true;
591 m_docAdviseCookie
= 0;
592 CreateActiveX(iid
, pUnk
);
595 wxActiveXContainer::~wxActiveXContainer()
597 // disconnect connection points
598 if (m_oleInPlaceObject
.Ok())
600 m_oleInPlaceObject
->InPlaceDeactivate();
601 m_oleInPlaceObject
->UIDeactivate();
604 if (m_oleObject
.Ok())
606 if (m_docAdviseCookie
!= 0)
607 m_oleObject
->Unadvise(m_docAdviseCookie
);
610 OLEIVERB_HIDE
, NULL
, m_clientSite
, 0, (HWND
) GetHWND(), NULL
);
611 m_oleObject
->Close(OLECLOSE_NOSAVE
);
612 m_oleObject
->SetClientSite(NULL
);
616 void wxActiveXContainer::CreateActiveX(REFIID iid
, IUnknown
* pUnk
)
619 hret
= m_ActiveX
.QueryInterface(iid
, pUnk
);
620 wxASSERT(SUCCEEDED(hret
));
623 FrameSite
*frame
= new FrameSite(m_realparent
, this);
625 hret
= m_clientSite
.QueryInterface(
626 IID_IOleClientSite
, (IDispatch
*) frame
);
627 wxASSERT(SUCCEEDED(hret
));
629 wxAutoIAdviseSink
adviseSink(IID_IAdviseSink
, (IDispatch
*) frame
);
630 wxASSERT(adviseSink
.Ok());
632 // Get Dispatch interface
633 hret
= m_Dispatch
.QueryInterface(IID_IDispatch
, m_ActiveX
);
635 // Get IOleObject interface
636 hret
= m_oleObject
.QueryInterface(IID_IOleObject
, m_ActiveX
);
637 wxASSERT(SUCCEEDED(hret
));
639 // get IViewObject Interface
640 hret
= m_viewObject
.QueryInterface(IID_IViewObject
, m_ActiveX
);
641 wxASSERT(SUCCEEDED(hret
));
644 m_docAdviseCookie
= 0;
645 hret
= m_oleObject
->Advise(adviseSink
, &m_docAdviseCookie
);
646 m_oleObject
->SetHostNames(L
"wxActiveXContainer", NULL
);
647 OleSetContainedObject(m_oleObject
, TRUE
);
651 // Get IOleInPlaceObject interface
652 hret
= m_oleInPlaceObject
.QueryInterface(
653 IID_IOleInPlaceObject
, m_ActiveX
);
654 wxASSERT(SUCCEEDED(hret
));
658 m_oleObject
->GetMiscStatus(DVASPECT_CONTENT
, &dwMiscStatus
);
659 wxASSERT(SUCCEEDED(hret
));
661 // set client site first ?
662 if (dwMiscStatus
& OLEMISC_SETCLIENTSITEFIRST
)
663 m_oleObject
->SetClientSite(m_clientSite
);
667 wxAutoIPersistStreamInit
668 pPersistStreamInit(IID_IPersistStreamInit
, m_oleObject
);
670 if (pPersistStreamInit
.Ok())
672 hret
= pPersistStreamInit
->InitNew();
675 if (! (dwMiscStatus
& OLEMISC_SETCLIENTSITEFIRST
))
676 m_oleObject
->SetClientSite(m_clientSite
);
680 ::GetClientRect((HWND
)m_realparent
->GetHWND(), &posRect
);
684 if (m_oleInPlaceObject
.Ok())
686 hret
= m_oleInPlaceObject
->GetWindow(&m_oleObjectHWND
);
688 ::SetActiveWindow(m_oleObjectHWND
);
692 if (! (dwMiscStatus
& OLEMISC_INVISIBLEATRUNTIME
))
694 if (posRect
.right
> 0 && posRect
.bottom
> 0 &&
695 m_oleInPlaceObject
.Ok())
696 m_oleInPlaceObject
->SetObjectRects(&posRect
, &posRect
);
698 hret
= m_oleObject
->DoVerb(OLEIVERB_INPLACEACTIVATE
, NULL
,
699 m_clientSite
, 0, (HWND
)m_realparent
->GetHWND(), &posRect
);
700 hret
= m_oleObject
->DoVerb(OLEIVERB_SHOW
, 0, m_clientSite
, 0,
701 (HWND
)m_realparent
->GetHWND(), &posRect
);
704 if (! m_oleObjectHWND
&& m_oleInPlaceObject
.Ok())
706 hret
= m_oleInPlaceObject
->GetWindow(&m_oleObjectHWND
);
711 ::SetActiveWindow(m_oleObjectHWND
);
712 ::ShowWindow(m_oleObjectHWND
, SW_SHOW
);
716 this->AssociateHandle(m_oleObjectHWND
);
718 this->Reparent(m_realparent
);
720 wxWindow
* pWnd
= m_realparent
;
721 int id
= m_realparent
->GetId();
723 pWnd
->Connect(id
, wxEVT_SIZE
,
724 wxSizeEventHandler(wxActiveXContainer::OnSize
), 0, this);
725 pWnd
->Connect(id
, wxEVT_SET_FOCUS
,
726 wxFocusEventHandler(wxActiveXContainer::OnSetFocus
), 0, this);
727 pWnd
->Connect(id
, wxEVT_KILL_FOCUS
,
728 wxFocusEventHandler(wxActiveXContainer::OnKillFocus
), 0, this);
732 #define HIMETRIC_PER_INCH 2540
733 #define MAP_PIX_TO_LOGHIM(x,ppli) MulDiv(HIMETRIC_PER_INCH, (x), (ppli))
735 static void PixelsToHimetric(SIZEL
&sz
)
743 HDC dc
= GetDC(NULL
);
744 logX
= GetDeviceCaps(dc
, LOGPIXELSX
);
745 logY
= GetDeviceCaps(dc
, LOGPIXELSY
);
749 #define HIMETRIC_INCH 2540
750 #define CONVERT(x, logpixels) wxMulDivInt32(HIMETRIC_INCH, (x), (logpixels))
752 sz
.cx
= CONVERT(sz
.cx
, logX
);
753 sz
.cy
= CONVERT(sz
.cy
, logY
);
760 void wxActiveXContainer::OnSize(wxSizeEvent
& event
)
763 GetParent()->GetClientSize(&w
, &h
);
771 if (w
<= 0 && h
<= 0)
774 // extents are in HIMETRIC units
775 if (m_oleObject
.Ok())
778 PixelsToHimetric(sz
);
782 m_oleObject
->GetExtent(DVASPECT_CONTENT
, &sz2
);
783 if (sz2
.cx
!= sz
.cx
|| sz
.cy
!= sz2
.cy
)
784 m_oleObject
->SetExtent(DVASPECT_CONTENT
, &sz
);
787 if (m_oleInPlaceObject
.Ok())
788 m_oleInPlaceObject
->SetObjectRects(&posRect
, &posRect
);
793 void wxActiveXContainer::OnPaint(wxPaintEvent
& WXUNUSED(event
))
796 // Draw only when control is windowless or deactivated
801 GetParent()->GetSize(&w
, &h
);
808 #if defined(_WIN32_WCE) && _WIN32_WCE < 400
809 ::InvalidateRect(m_oleObjectHWND
, NULL
, false);
811 ::RedrawWindow(m_oleObjectHWND
, NULL
, NULL
, RDW_INTERNALPAINT
);
813 RECTL
*prcBounds
= (RECTL
*) &posRect
;
814 m_viewObject
->Draw(DVASPECT_CONTENT
, -1, NULL
, NULL
, NULL
,
815 (HDC
)dc
.GetHDC(), prcBounds
, NULL
, NULL
, 0);
820 // We've got this one I think
824 void wxActiveXContainer::OnSetFocus(wxFocusEvent
& event
)
826 if (m_oleInPlaceActiveObject
.Ok())
827 m_oleInPlaceActiveObject
->OnFrameWindowActivate(TRUE
);
832 void wxActiveXContainer::OnKillFocus(wxFocusEvent
& event
)
834 if (m_oleInPlaceActiveObject
.Ok())
835 m_oleInPlaceActiveObject
->OnFrameWindowActivate(FALSE
);