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
)
380 IRunnableObject
* runnable
= NULL
;
381 HRESULT hr
= QueryInterface(
382 IID_IRunnableObject
, (void**)(& runnable
));
385 runnable
->LockRunning(TRUE
, FALSE
);
388 OleLockRunning(m_window
->m_ActiveX
, TRUE
, FALSE
);
391 (*pfNoRedraw
) = FALSE
;
395 HRESULT STDMETHODCALLTYPE
OnInPlaceDeactivateEx(BOOL
)
398 IRunnableObject
* runnable
= NULL
;
399 HRESULT hr
= QueryInterface(
400 IID_IRunnableObject
, (void**)(& runnable
));
403 runnable
->LockRunning(FALSE
, FALSE
);
406 OleLockRunning(m_window
->m_ActiveX
, FALSE
, FALSE
);
410 STDMETHOD(RequestUIActivate
)(){ return S_OK
;}
411 //*************************IOleClientSite**************************
412 HRESULT STDMETHODCALLTYPE
SaveObject(){return S_OK
;}
413 const char *OleGetMonikerToStr(DWORD dwAssign
)
417 case OLEGETMONIKER_ONLYIFTHERE
: return "OLEGETMONIKER_ONLYIFTHERE";
418 case OLEGETMONIKER_FORCEASSIGN
: return "OLEGETMONIKER_FORCEASSIGN";
419 case OLEGETMONIKER_UNASSIGN
: return "OLEGETMONIKER_UNASSIGN";
420 case OLEGETMONIKER_TEMPFORUSER
: return "OLEGETMONIKER_TEMPFORUSER";
421 default : return "Bad Enum";
425 const char *OleGetWhicMonikerStr(DWORD dwWhichMoniker
)
427 switch(dwWhichMoniker
)
429 case OLEWHICHMK_CONTAINER
: return "OLEWHICHMK_CONTAINER";
430 case OLEWHICHMK_OBJREL
: return "OLEWHICHMK_OBJREL";
431 case OLEWHICHMK_OBJFULL
: return "OLEWHICHMK_OBJFULL";
432 default : return "Bad Enum";
435 STDMETHOD(GetMoniker
)(DWORD
, DWORD
, IMoniker
**){return E_FAIL
;}
436 HRESULT STDMETHODCALLTYPE
GetContainer(LPOLECONTAINER
* ppContainer
)
438 if (ppContainer
== NULL
)
440 HRESULT hr
= QueryInterface(
441 IID_IOleContainer
, (void**)(ppContainer
));
442 wxASSERT(SUCCEEDED(hr
));
445 HRESULT STDMETHODCALLTYPE
ShowObject()
447 if (m_window
->m_oleObjectHWND
)
448 ::ShowWindow(m_window
->m_oleObjectHWND
, SW_SHOW
);
451 STDMETHOD(OnShowWindow
)(BOOL
){return S_OK
;}
452 STDMETHOD(RequestNewObjectLayout
)(){return E_NOTIMPL
;}
453 //********************IParseDisplayName***************************
454 HRESULT STDMETHODCALLTYPE
ParseDisplayName(
455 IBindCtx
*, LPOLESTR
, ULONG
*, IMoniker
**){return E_NOTIMPL
;}
456 //********************IOleContainer*******************************
457 STDMETHOD(EnumObjects
)(DWORD
, IEnumUnknown
**){return E_NOTIMPL
;}
458 HRESULT STDMETHODCALLTYPE
LockContainer(BOOL
){return S_OK
;}
459 //********************IOleItemContainer***************************
460 HRESULT STDMETHODCALLTYPE
461 #if defined(__WXWINCE__)
463 #elif defined(_UNICODE)
468 (LPOLESTR pszItem
, DWORD
, IBindCtx
*, REFIID
, void ** ppvObject
)
470 if (pszItem
== NULL
|| ppvObject
== NULL
)
473 return MK_E_NOOBJECT
;
475 HRESULT STDMETHODCALLTYPE
GetObjectStorage(
476 LPOLESTR pszItem
, IBindCtx
* , REFIID
, void ** ppvStorage
)
478 if (pszItem
== NULL
|| ppvStorage
== NULL
)
481 return MK_E_NOOBJECT
;
483 HRESULT STDMETHODCALLTYPE
IsRunning(LPOLESTR pszItem
)
487 return MK_E_NOOBJECT
;
489 //***********************IOleControlSite*****************************
490 HRESULT STDMETHODCALLTYPE
OnControlInfoChanged()
492 HRESULT STDMETHODCALLTYPE
LockInPlaceActive(BOOL fLock
)
494 m_bInPlaceLocked
= (fLock
) ? true : false;
497 HRESULT STDMETHODCALLTYPE
GetExtendedControl(IDispatch
**)
499 HRESULT STDMETHODCALLTYPE
TransformCoords(
500 POINTL
* pPtlHimetric
, POINTF
* pPtfContainer
, DWORD
)
502 if (pPtlHimetric
== NULL
|| pPtfContainer
== NULL
)
506 HRESULT STDMETHODCALLTYPE
TranslateAccelerator(LPMSG
, DWORD
)
508 HRESULT STDMETHODCALLTYPE
OnFocus(BOOL
){return S_OK
;}
509 HRESULT STDMETHODCALLTYPE
ShowPropertyFrame(){return E_NOTIMPL
;}
510 //**************************IOleCommandTarget***********************
511 HRESULT STDMETHODCALLTYPE
QueryStatus(const GUID
*, ULONG cCmds
,
512 OLECMD prgCmds
[], OLECMDTEXT
*)
514 if (prgCmds
== NULL
) return E_INVALIDARG
;
515 for (ULONG nCmd
= 0; nCmd
< cCmds
; nCmd
++)
517 // unsupported by default
518 prgCmds
[nCmd
].cmdf
= 0;
520 return OLECMDERR_E_UNKNOWNGROUP
;
523 HRESULT STDMETHODCALLTYPE
Exec(const GUID
*, DWORD
,
524 DWORD
, VARIANTARG
*, VARIANTARG
*)
525 {return OLECMDERR_E_NOTSUPPORTED
;}
527 //**********************IAdviseSink************************************
528 void STDMETHODCALLTYPE
OnDataChange(FORMATETC
*, STGMEDIUM
*) {}
529 void STDMETHODCALLTYPE
OnViewChange(DWORD
, LONG
) {}
530 void STDMETHODCALLTYPE
OnRename(IMoniker
*){}
531 void STDMETHODCALLTYPE
OnSave(){}
532 void STDMETHODCALLTYPE
OnClose(){}
534 //**********************IOleDocumentSite***************************
535 HRESULT STDMETHODCALLTYPE
ActivateMe(
536 IOleDocumentView __RPC_FAR
*pViewToActivate
)
538 wxAutoIOleInPlaceSite
inPlaceSite(
539 IID_IOleInPlaceSite
, (IDispatch
*) this);
540 if (!inPlaceSite
.Ok())
545 m_window
->m_docView
= pViewToActivate
;
546 m_window
->m_docView
->SetInPlaceSite(inPlaceSite
);
550 wxAutoIOleDocument
oleDoc(
551 IID_IOleDocument
, m_window
->m_oleObject
);
555 HRESULT hr
= oleDoc
->CreateView(inPlaceSite
, NULL
,
556 0, m_window
->m_docView
.GetRef());
560 m_window
->m_docView
->SetInPlaceSite(inPlaceSite
);
563 m_window
->m_docView
->UIActivate(TRUE
);
569 wxActiveXContainer
* m_window
;
574 bool m_bSupportsWindowlessActivation
;
575 bool m_bInPlaceLocked
;
576 bool m_bInPlaceActive
;
580 LCID m_nAmbientLocale
;
581 COLORREF m_clrAmbientForeColor
;
582 COLORREF m_clrAmbientBackColor
;
583 bool m_bAmbientShowHatching
;
584 bool m_bAmbientShowGrabHandles
;
585 bool m_bAmbientAppearance
;
588 DEFINE_OLE_TABLE(FrameSite
)
589 OLE_INTERFACE(IID_IUnknown
, IOleClientSite
)
590 OLE_IINTERFACE(IOleClientSite
)
591 OLE_INTERFACE(IID_IOleWindow
, IOleInPlaceSite
)
592 OLE_IINTERFACE(IOleInPlaceSite
)
593 OLE_IINTERFACE(IOleInPlaceSiteEx
)
594 OLE_IINTERFACE(IOleInPlaceUIWindow
)
595 OLE_IINTERFACE(IOleInPlaceFrame
)
596 OLE_IINTERFACE(IParseDisplayName
)
597 OLE_IINTERFACE(IOleContainer
)
598 OLE_IINTERFACE(IOleItemContainer
)
599 OLE_IINTERFACE(IDispatch
)
600 OLE_IINTERFACE(IOleCommandTarget
)
601 OLE_IINTERFACE(IOleDocumentSite
)
602 OLE_IINTERFACE(IAdviseSink
)
603 OLE_IINTERFACE(IOleControlSite
)
607 wxActiveXContainer::wxActiveXContainer(wxWindow
* parent
, REFIID iid
, IUnknown
* pUnk
)
608 : m_realparent(parent
)
610 m_bAmbientUserMode
= true;
611 m_docAdviseCookie
= 0;
612 CreateActiveX(iid
, pUnk
);
615 wxActiveXContainer::~wxActiveXContainer()
617 // disconnect connection points
618 if (m_oleInPlaceObject
.Ok())
620 m_oleInPlaceObject
->InPlaceDeactivate();
621 m_oleInPlaceObject
->UIDeactivate();
624 if (m_oleObject
.Ok())
626 if (m_docAdviseCookie
!= 0)
627 m_oleObject
->Unadvise(m_docAdviseCookie
);
630 OLEIVERB_HIDE
, NULL
, m_clientSite
, 0, (HWND
) GetHWND(), NULL
);
631 m_oleObject
->Close(OLECLOSE_NOSAVE
);
632 m_oleObject
->SetClientSite(NULL
);
636 void wxActiveXContainer::CreateActiveX(REFIID iid
, IUnknown
* pUnk
)
639 hret
= m_ActiveX
.QueryInterface(iid
, pUnk
);
640 wxASSERT(SUCCEEDED(hret
));
643 FrameSite
*frame
= new FrameSite(m_realparent
, this);
645 hret
= m_clientSite
.QueryInterface(
646 IID_IOleClientSite
, (IDispatch
*) frame
);
647 wxASSERT(SUCCEEDED(hret
));
649 wxAutoIAdviseSink
adviseSink(IID_IAdviseSink
, (IDispatch
*) frame
);
650 wxASSERT(adviseSink
.Ok());
652 // Get Dispatch interface
653 hret
= m_Dispatch
.QueryInterface(IID_IDispatch
, m_ActiveX
);
655 // Get IOleObject interface
656 hret
= m_oleObject
.QueryInterface(IID_IOleObject
, m_ActiveX
);
657 wxASSERT(SUCCEEDED(hret
));
659 // get IViewObject Interface
660 hret
= m_viewObject
.QueryInterface(IID_IViewObject
, m_ActiveX
);
661 wxASSERT(SUCCEEDED(hret
));
664 m_docAdviseCookie
= 0;
665 hret
= m_oleObject
->Advise(adviseSink
, &m_docAdviseCookie
);
666 m_oleObject
->SetHostNames(L
"wxActiveXContainer", NULL
);
667 OleSetContainedObject(m_oleObject
, TRUE
);
671 // Get IOleInPlaceObject interface
672 hret
= m_oleInPlaceObject
.QueryInterface(
673 IID_IOleInPlaceObject
, m_ActiveX
);
674 wxASSERT(SUCCEEDED(hret
));
678 m_oleObject
->GetMiscStatus(DVASPECT_CONTENT
, &dwMiscStatus
);
679 wxASSERT(SUCCEEDED(hret
));
681 // set client site first ?
682 if (dwMiscStatus
& OLEMISC_SETCLIENTSITEFIRST
)
683 m_oleObject
->SetClientSite(m_clientSite
);
687 wxAutoIPersistStreamInit
688 pPersistStreamInit(IID_IPersistStreamInit
, m_oleObject
);
690 if (pPersistStreamInit
.Ok())
692 hret
= pPersistStreamInit
->InitNew();
695 if (! (dwMiscStatus
& OLEMISC_SETCLIENTSITEFIRST
))
696 m_oleObject
->SetClientSite(m_clientSite
);
700 ::GetClientRect((HWND
)m_realparent
->GetHWND(), &posRect
);
704 if (m_oleInPlaceObject
.Ok())
706 hret
= m_oleInPlaceObject
->GetWindow(&m_oleObjectHWND
);
708 ::SetActiveWindow(m_oleObjectHWND
);
712 if (! (dwMiscStatus
& OLEMISC_INVISIBLEATRUNTIME
))
714 if (posRect
.right
> 0 && posRect
.bottom
> 0 &&
715 m_oleInPlaceObject
.Ok())
716 m_oleInPlaceObject
->SetObjectRects(&posRect
, &posRect
);
718 hret
= m_oleObject
->DoVerb(OLEIVERB_INPLACEACTIVATE
, NULL
,
719 m_clientSite
, 0, (HWND
)m_realparent
->GetHWND(), &posRect
);
720 hret
= m_oleObject
->DoVerb(OLEIVERB_SHOW
, 0, m_clientSite
, 0,
721 (HWND
)m_realparent
->GetHWND(), &posRect
);
724 if (! m_oleObjectHWND
&& m_oleInPlaceObject
.Ok())
726 hret
= m_oleInPlaceObject
->GetWindow(&m_oleObjectHWND
);
731 ::SetActiveWindow(m_oleObjectHWND
);
732 ::ShowWindow(m_oleObjectHWND
, SW_SHOW
);
734 this->AssociateHandle(m_oleObjectHWND
);
735 this->Reparent(m_realparent
);
737 wxWindow
* pWnd
= m_realparent
;
738 int id
= m_realparent
->GetId();
740 pWnd
->Connect(id
, wxEVT_SIZE
,
741 wxSizeEventHandler(wxActiveXContainer::OnSize
), 0, this);
742 pWnd
->Connect(id
, wxEVT_SET_FOCUS
,
743 wxFocusEventHandler(wxActiveXContainer::OnSetFocus
), 0, this);
744 pWnd
->Connect(id
, wxEVT_KILL_FOCUS
,
745 wxFocusEventHandler(wxActiveXContainer::OnKillFocus
), 0, this);
749 #define HIMETRIC_PER_INCH 2540
750 #define MAP_PIX_TO_LOGHIM(x,ppli) MulDiv(HIMETRIC_PER_INCH, (x), (ppli))
752 static void PixelsToHimetric(SIZEL
&sz
)
760 HDC dc
= GetDC(NULL
);
761 logX
= GetDeviceCaps(dc
, LOGPIXELSX
);
762 logY
= GetDeviceCaps(dc
, LOGPIXELSY
);
766 #define HIMETRIC_INCH 2540
767 #define CONVERT(x, logpixels) wxMulDivInt32(HIMETRIC_INCH, (x), (logpixels))
769 sz
.cx
= CONVERT(sz
.cx
, logX
);
770 sz
.cy
= CONVERT(sz
.cy
, logY
);
777 void wxActiveXContainer::OnSize(wxSizeEvent
& event
)
780 GetParent()->GetClientSize(&w
, &h
);
788 if (w
<= 0 && h
<= 0)
791 // extents are in HIMETRIC units
792 if (m_oleObject
.Ok())
795 PixelsToHimetric(sz
);
799 m_oleObject
->GetExtent(DVASPECT_CONTENT
, &sz2
);
800 if (sz2
.cx
!= sz
.cx
|| sz
.cy
!= sz2
.cy
)
801 m_oleObject
->SetExtent(DVASPECT_CONTENT
, &sz
);
804 if (m_oleInPlaceObject
.Ok())
805 m_oleInPlaceObject
->SetObjectRects(&posRect
, &posRect
);
810 void wxActiveXContainer::OnPaint(wxPaintEvent
& WXUNUSED(event
))
813 // Draw only when control is windowless or deactivated
818 GetParent()->GetSize(&w
, &h
);
825 #if defined(_WIN32_WCE) && _WIN32_WCE < 400
826 ::InvalidateRect(m_oleObjectHWND
, NULL
, false);
828 ::RedrawWindow(m_oleObjectHWND
, NULL
, NULL
, RDW_INTERNALPAINT
);
830 RECTL
*prcBounds
= (RECTL
*) &posRect
;
831 m_viewObject
->Draw(DVASPECT_CONTENT
, -1, NULL
, NULL
, NULL
,
832 (HDC
)dc
.GetHDC(), prcBounds
, NULL
, NULL
, 0);
837 // We've got this one I think
841 void wxActiveXContainer::OnSetFocus(wxFocusEvent
& event
)
843 if (m_oleInPlaceActiveObject
.Ok())
844 m_oleInPlaceActiveObject
->OnFrameWindowActivate(TRUE
);
849 void wxActiveXContainer::OnKillFocus(wxFocusEvent
& event
)
851 if (m_oleInPlaceActiveObject
.Ok())
852 m_oleInPlaceActiveObject
->OnFrameWindowActivate(FALSE
);