2 #include <wx/strconv.h>
13 // Depending on compilation mode, the wx headers may have undef'd
14 // this, but in this case we need it so the virtual method in
15 // FrameSite will match what is in oleidl.h.
18 #define GetObject GetObjectW
20 #define GetObject GetObjectA
25 //////////////////////////////////////////////////////////////////////
26 BEGIN_EVENT_TABLE(wxActiveX
, wxWindow
)
27 EVT_SIZE(wxActiveX::OnSize
)
28 EVT_PAINT(wxActiveX::OnPaint
)
29 EVT_MOUSE_EVENTS(wxActiveX::OnMouse
)
30 EVT_SET_FOCUS(wxActiveX::OnSetFocus
)
31 EVT_KILL_FOCUS(wxActiveX::OnKillFocus
)
37 public IOleClientSite
,
38 public IOleInPlaceSiteEx
,
39 public IOleInPlaceFrame
,
40 public IOleItemContainer
,
42 public IOleCommandTarget
,
43 public IOleDocumentSite
,
45 public IOleControlSite
48 DECLARE_OLE_UNKNOWN(FrameSite
);
51 FrameSite(wxActiveX
* win
);
55 STDMETHODIMP
GetWindow(HWND
*);
56 STDMETHODIMP
ContextSensitiveHelp(BOOL
);
59 STDMETHODIMP
GetBorder(LPRECT
);
60 STDMETHODIMP
RequestBorderSpace(LPCBORDERWIDTHS
);
61 STDMETHODIMP
SetBorderSpace(LPCBORDERWIDTHS
);
62 STDMETHODIMP
SetActiveObject(IOleInPlaceActiveObject
*, LPCOLESTR
);
65 STDMETHODIMP
InsertMenus(HMENU
, LPOLEMENUGROUPWIDTHS
);
66 STDMETHODIMP
SetMenu(HMENU
, HOLEMENU
, HWND
);
67 STDMETHODIMP
RemoveMenus(HMENU
);
68 STDMETHODIMP
SetStatusText(LPCOLESTR
);
69 STDMETHODIMP
EnableModeless(BOOL
);
70 STDMETHODIMP
TranslateAccelerator(LPMSG
, WORD
);
73 STDMETHODIMP
CanInPlaceActivate();
74 STDMETHODIMP
OnInPlaceActivate();
75 STDMETHODIMP
OnUIActivate();
76 STDMETHODIMP
GetWindowContext(IOleInPlaceFrame
**, IOleInPlaceUIWindow
**,
77 LPRECT
, LPRECT
, LPOLEINPLACEFRAMEINFO
);
78 STDMETHODIMP
Scroll(SIZE
);
79 STDMETHODIMP
OnUIDeactivate(BOOL
);
80 STDMETHODIMP
OnInPlaceDeactivate();
81 STDMETHODIMP
DiscardUndoState();
82 STDMETHODIMP
DeactivateAndUndo();
83 STDMETHODIMP
OnPosRectChange(LPCRECT
);
86 STDMETHODIMP
OnInPlaceActivateEx(BOOL
*, DWORD
);
87 STDMETHODIMP
OnInPlaceDeactivateEx(BOOL
);
88 STDMETHODIMP
RequestUIActivate();
91 STDMETHODIMP
SaveObject();
92 STDMETHODIMP
GetMoniker(DWORD
, DWORD
, IMoniker
**);
93 STDMETHODIMP
GetContainer(LPOLECONTAINER FAR
*);
94 STDMETHODIMP
ShowObject();
95 STDMETHODIMP
OnShowWindow(BOOL
);
96 STDMETHODIMP
RequestNewObjectLayout();
99 STDMETHODIMP
OnControlInfoChanged();
100 STDMETHODIMP
LockInPlaceActive(BOOL
);
101 STDMETHODIMP
GetExtendedControl(IDispatch
**);
102 STDMETHODIMP
TransformCoords(POINTL
*, POINTF
*, DWORD
);
103 STDMETHODIMP
TranslateAccelerator(LPMSG
, DWORD
);
104 STDMETHODIMP
OnFocus(BOOL
);
105 STDMETHODIMP
ShowPropertyFrame();
108 STDMETHODIMP
QueryStatus(const GUID
*, ULONG
, OLECMD
[], OLECMDTEXT
*);
109 STDMETHODIMP
Exec(const GUID
*, DWORD
, DWORD
, VARIANTARG
*, VARIANTARG
*);
112 STDMETHODIMP
ParseDisplayName(IBindCtx
*, LPOLESTR
, ULONG
*, IMoniker
**);
115 STDMETHODIMP
EnumObjects(DWORD
, IEnumUnknown
**);
116 STDMETHODIMP
LockContainer(BOOL
);
119 STDMETHODIMP
GetObject(LPOLESTR
, DWORD
, IBindCtx
*, REFIID
, void**);
120 STDMETHODIMP
GetObjectStorage(LPOLESTR
, IBindCtx
*, REFIID
, void**);
121 STDMETHODIMP
IsRunning(LPOLESTR
);
124 STDMETHODIMP
GetIDsOfNames(REFIID
, OLECHAR
**, unsigned int, LCID
, DISPID
*);
125 STDMETHODIMP
GetTypeInfo(unsigned int, LCID
, ITypeInfo
**);
126 STDMETHODIMP
GetTypeInfoCount(unsigned int*);
127 STDMETHODIMP
Invoke(DISPID
, REFIID
, LCID
, WORD
, DISPPARAMS
*, VARIANT
*, EXCEPINFO
*, UINT
*);
130 void STDMETHODCALLTYPE
OnDataChange(FORMATETC
*, STGMEDIUM
*);
131 void STDMETHODCALLTYPE
OnViewChange(DWORD
, LONG
);
132 void STDMETHODCALLTYPE
OnRename(IMoniker
*);
133 void STDMETHODCALLTYPE
OnSave();
134 void STDMETHODCALLTYPE
OnClose();
137 HRESULT STDMETHODCALLTYPE
ActivateMe(IOleDocumentView __RPC_FAR
*pViewToActivate
);
141 wxActiveX
* m_window
;
146 bool m_bSupportsWindowlessActivation
;
147 bool m_bInPlaceLocked
;
148 bool m_bInPlaceActive
;
154 LCID m_nAmbientLocale
;
155 COLORREF m_clrAmbientForeColor
;
156 COLORREF m_clrAmbientBackColor
;
157 bool m_bAmbientShowHatching
;
158 bool m_bAmbientShowGrabHandles
;
159 bool m_bAmbientAppearance
;
162 DEFINE_OLE_TABLE(FrameSite
)
163 OLE_INTERFACE(IID_IUnknown
, IOleClientSite
)
165 OLE_IINTERFACE(IOleClientSite
)
167 OLE_INTERFACE(IID_IOleWindow
, IOleInPlaceSite
)
168 OLE_IINTERFACE(IOleInPlaceSite
)
169 OLE_IINTERFACE(IOleInPlaceSiteEx
)
171 //OLE_IINTERFACE(IOleWindow)
172 OLE_IINTERFACE(IOleInPlaceUIWindow
)
173 OLE_IINTERFACE(IOleInPlaceFrame
)
175 OLE_IINTERFACE(IParseDisplayName
)
176 OLE_IINTERFACE(IOleContainer
)
177 OLE_IINTERFACE(IOleItemContainer
)
179 OLE_IINTERFACE(IDispatch
)
181 OLE_IINTERFACE(IOleCommandTarget
)
183 OLE_IINTERFACE(IOleDocumentSite
)
185 OLE_IINTERFACE(IAdviseSink
)
187 OLE_IINTERFACE(IOleControlSite
)
191 wxActiveX::wxActiveX(wxWindow
* parent
, REFCLSID clsid
, wxWindowID id
,
195 const wxString
& name
) :
196 wxWindow(parent
, id
, pos
, size
, style
, name
)
198 m_bAmbientUserMode
= true;
199 m_docAdviseCookie
= 0;
200 CreateActiveX(clsid
);
203 wxActiveX::wxActiveX(wxWindow
* parent
, wxString progId
, wxWindowID id
,
207 const wxString
& name
) :
208 wxWindow(parent
, id
, pos
, size
, style
, name
)
210 m_bAmbientUserMode
= true;
211 m_docAdviseCookie
= 0;
212 CreateActiveX((LPOLESTR
) (const wchar_t *) progId
.wc_str(wxConvUTF8
));
215 wxActiveX::~wxActiveX()
217 // disconnect connection points
218 wxOleConnectionArray::iterator it
= m_connections
.begin();
219 while (it
!= m_connections
.end())
221 wxOleConnectionPoint
& cp
= it
->first
;
222 cp
->Unadvise(it
->second
);
226 m_connections
.clear();
228 if (m_oleInPlaceObject
.Ok())
230 m_oleInPlaceObject
->InPlaceDeactivate();
231 m_oleInPlaceObject
->UIDeactivate();
235 if (m_oleObject
.Ok())
237 if (m_docAdviseCookie
!= 0)
238 m_oleObject
->Unadvise(m_docAdviseCookie
);
240 m_oleObject
->DoVerb(OLEIVERB_HIDE
, NULL
, m_clientSite
, 0, (HWND
) GetHWND(), NULL
);
241 m_oleObject
->Close(OLECLOSE_NOSAVE
);
242 m_oleObject
->SetClientSite(NULL
);
246 void wxActiveX::CreateActiveX(REFCLSID clsid
)
252 ////////////////////////////////////////////////////////
254 FrameSite
*frame
= new FrameSite(this);
256 hret
= m_clientSite
.QueryInterface(IID_IOleClientSite
, (IDispatch
*) frame
);
257 wxASSERT(SUCCEEDED(hret
));
259 wxAutoOleInterface
<IAdviseSink
> adviseSink(IID_IAdviseSink
, (IDispatch
*) frame
);
260 wxASSERT(adviseSink
.Ok());
263 // // Create Object, get IUnknown interface
264 m_ActiveX
.CreateInstance(clsid
, IID_IUnknown
);
265 wxASSERT(m_ActiveX
.Ok());
270 // Get IOleObject interface
271 hret
= m_oleObject
.QueryInterface(IID_IOleObject
, m_ActiveX
);
272 wxASSERT(SUCCEEDED(hret
));
274 // get IViewObject Interface
275 hret
= m_viewObject
.QueryInterface(IID_IViewObject
, m_ActiveX
);
276 wxASSERT(SUCCEEDED(hret
));
279 m_docAdviseCookie
= 0;
280 hret
= m_oleObject
->Advise(adviseSink
, &m_docAdviseCookie
);
281 WXOLE_WARN(hret
, "m_oleObject->Advise(adviseSink, &m_docAdviseCookie),\"Advise\")");
282 m_oleObject
->SetHostNames(L
"wxActiveXContainer", NULL
);
283 OleSetContainedObject(m_oleObject
, TRUE
);
287 // Get IOleInPlaceObject interface
288 hret
= m_oleInPlaceObject
.QueryInterface(IID_IOleInPlaceObject
, m_ActiveX
);
289 wxASSERT(SUCCEEDED(hret
));
293 m_oleObject
->GetMiscStatus(DVASPECT_CONTENT
, &dwMiscStatus
);
294 wxASSERT(SUCCEEDED(hret
));
296 // set client site first ?
297 if (dwMiscStatus
& OLEMISC_SETCLIENTSITEFIRST
)
298 m_oleObject
->SetClientSite(m_clientSite
);
302 wxAutoOleInterface
<IPersistStreamInit
>
303 pPersistStreamInit(IID_IPersistStreamInit
, m_oleObject
);
305 if (pPersistStreamInit
.Ok())
307 hret
= pPersistStreamInit
->InitNew();
308 WXOLE_WARN(hret
, "CreateActiveX::pPersistStreamInit->InitNew()");
311 if (! (dwMiscStatus
& OLEMISC_SETCLIENTSITEFIRST
))
312 m_oleObject
->SetClientSite(m_clientSite
);
316 GetClientSize(&w
, &h
);
325 if (m_oleInPlaceObject
.Ok())
327 hret
= m_oleInPlaceObject
->GetWindow(&m_oleObjectHWND
);
328 WXOLE_WARN(hret
, "m_oleInPlaceObject->GetWindow(&m_oleObjectHWND)");
330 ::SetActiveWindow(m_oleObjectHWND
);
334 if (! (dwMiscStatus
& OLEMISC_INVISIBLEATRUNTIME
))
336 if (w
> 0 && h
> 0 && m_oleInPlaceObject
.Ok())
337 m_oleInPlaceObject
->SetObjectRects(&posRect
, &posRect
);
339 hret
= m_oleObject
->DoVerb(OLEIVERB_INPLACEACTIVATE
, NULL
, m_clientSite
, 0, (HWND
)GetHWND(), &posRect
);
340 hret
= m_oleObject
->DoVerb(OLEIVERB_SHOW
, 0, m_clientSite
, 0, (HWND
)GetHWND(), &posRect
);
343 if (! m_oleObjectHWND
&& m_oleInPlaceObject
.Ok())
345 hret
= m_oleInPlaceObject
->GetWindow(&m_oleObjectHWND
);
346 WXOLE_WARN(hret
, "m_oleInPlaceObject->GetWindow(&m_oleObjectHWND)");
351 ::SetActiveWindow(m_oleObjectHWND
);
352 ::ShowWindow(m_oleObjectHWND
, SW_SHOW
);
356 void wxActiveX::CreateActiveX(LPOLESTR progId
)
359 if (CLSIDFromProgID(progId
, &clsid
) != S_OK
)
362 CreateActiveX(clsid
);
365 ////////////////////////////////////////////////////////////////////////////////////////////////////////////
366 // Case Insensitive Map of Event names to eventTypes
367 // created dynamically at run time in:
368 // EVT_ACTIVEX(eventName, id, fn)
369 // we map the pointer to them so that:
370 // const wxEventType& RegisterActiveXEvent(wxString eventName);
371 // can return a const reference, which is neccessary for event tables
372 // probably should use a wxWindows hash table here, but I'm lazy ...
373 struct less_wxStringI
375 bool operator()(const wxString
& x
, const wxString
& y
) const
377 return x
.CmpNoCase(y
) < 0;
381 typedef map
<wxString
, wxEventType
*, less_wxStringI
> ActiveXNamedEventMap
;
382 static ActiveXNamedEventMap sg_NamedEventMap
;
384 const wxEventType
& RegisterActiveXEvent(const wxChar
*eventName
)
386 wxString ev
= eventName
;
387 ActiveXNamedEventMap::iterator it
= sg_NamedEventMap
.find(ev
);
388 if (it
== sg_NamedEventMap
.end())
390 wxEventType
*et
= new wxEventType(wxNewEventType());
391 sg_NamedEventMap
[ev
] = et
;
396 return *(it
->second
);
400 ////////////////////////////////////////////////////////////////////////////////////////////////////////////
401 // Map of Event DISPID's to eventTypes
402 // created dynamically at run time in:
403 // EVT_ACTIVEX(eventName, id, fn)
404 // we map the pointer to them so that:
405 // const wxEventType& RegisterActiveXEvent(wxString eventName);
406 // can return a const reference, which is neccessary for event tables
408 typedef map
<DISPID
, wxEventType
*> ActiveXDISPIDEventMap
;
409 static ActiveXDISPIDEventMap sg_dispIdEventMap
;
411 const wxEventType
& RegisterActiveXEvent(DISPID event
)
413 ActiveXDISPIDEventMap::iterator it
= sg_dispIdEventMap
.find(event
);
414 if (it
== sg_dispIdEventMap
.end())
416 wxEventType
*et
= new wxEventType(wxNewEventType());
417 sg_dispIdEventMap
[event
] = et
;
422 return *(it
->second
);
425 // one off class for automatic freeing of activeX eventtypes
426 class ActiveXEventMapFlusher
429 ~ActiveXEventMapFlusher()
432 ActiveXNamedEventMap::iterator it
= sg_NamedEventMap
.end();
433 while (it
!= sg_NamedEventMap
.end())
440 ActiveXDISPIDEventMap::iterator dit
= sg_dispIdEventMap
.end();
441 while (dit
!= sg_dispIdEventMap
.end())
449 static ActiveXEventMapFlusher s_dummyActiveXEventMapFlusher
;
452 //////////////////////////////////////////////////////
453 bool MSWVariantToVariant(VARIANTARG
& va
, wxVariant
& vx
)
457 case VT_VARIANT
| VT_BYREF
:
458 return MSWVariantToVariant(*va
.pvarVal
, vx
);
465 case VT_I2
| VT_BYREF
:
466 case VT_I4
| VT_BYREF
:
467 vx
= (long) *va
.piVal
;
471 vx
= wxString(va
.bstrVal
);
474 case VT_BSTR
| VT_BYREF
:
475 vx
= wxString(*va
.pbstrVal
);
479 vx
= (va
.boolVal
!= FALSE
);
482 case VT_BOOL
| VT_BYREF
:
483 vx
= (*va
.pboolVal
!= FALSE
);
492 bool VariantToMSWVariant(wxVariant
& vx
, VARIANTARG
& va
)
496 case VT_VARIANT
| VT_BYREF
:
497 return VariantToMSWVariant(vx
, va
);
504 case VT_I2
| VT_BYREF
:
505 case VT_I4
| VT_BYREF
:
506 *va
.piVal
= (long) vx
;
510 va
.boolVal
= ((bool) vx
) ? TRUE
: FALSE
;
513 case VT_BOOL
| VT_BYREF
:
514 *va
.pboolVal
= ((bool) vx
) ? TRUE
: FALSE
;
522 class wxActiveXEvents
: public IDispatch
525 DECLARE_OLE_UNKNOWN(wxActiveXEvents
);
528 wxActiveX
*m_activeX
;
531 wxActiveXEvents(wxActiveX
*ax
) : m_activeX(ax
) {}
532 virtual ~wxActiveXEvents()
537 STDMETHODIMP
GetIDsOfNames(REFIID r
, OLECHAR
** o
, unsigned int i
, LCID l
, DISPID
* d
)
542 STDMETHODIMP
GetTypeInfo(unsigned int i
, LCID l
, ITypeInfo
** t
)
547 STDMETHODIMP
GetTypeInfoCount(unsigned int* i
)
553 void DispatchEvent(int eventIdx
, const wxEventType
& eventType
, DISPPARAMS
* pDispParams
)
555 wxASSERT(eventIdx
>= 0 && eventIdx
< int(m_activeX
->m_events
.size()));
556 wxActiveX::FuncX
&func
= m_activeX
->m_events
[eventIdx
];
558 wxActiveXEvent event
;
559 event
.SetId(m_activeX
->GetId());
560 event
.SetEventType(eventType
);
561 event
.m_params
.NullList();
562 event
.m_params
.SetName(func
.name
);
568 // sometimes the pDispParams does not match the param info for a activex control
569 int nArg
= min(func
.params
.size(), pDispParams
->cArgs
);
570 for (int i
= nArg
- 1; i
>= 0; i
--)
572 VARIANTARG
& va
= pDispParams
->rgvarg
[i
];
573 wxActiveX::ParamX
&px
= func
.params
[nArg
- i
- 1];
577 MSWVariantToVariant(va
, vx
);
578 event
.m_params
.Append(vx
);
584 int nArg
= min(func
.params
.size(), pDispParams
->cArgs
);
585 m_activeX
->GetParent()->ProcessEvent(event
);
586 for (int i
= 0; i
< nArg
; i
++)
588 VARIANTARG
& va
= pDispParams
->rgvarg
[i
];
589 wxActiveX::ParamX
&px
= func
.params
[nArg
- i
- 1];
593 wxVariant
& vx
= event
.m_params
[nArg
- i
- 1];
595 VariantToMSWVariant(vx
, va
);
600 m_activeX
->GetParent()->AddPendingEvent(event
);
604 STDMETHODIMP
Invoke(DISPID dispIdMember
, REFIID riid
, LCID lcid
,
605 WORD wFlags
, DISPPARAMS
* pDispParams
,
606 VARIANT
* pVarResult
, EXCEPINFO
* pExcepInfo
,
607 unsigned int * puArgErr
)
609 if (wFlags
& (DISPATCH_PROPERTYGET
| DISPATCH_PROPERTYPUT
| DISPATCH_PROPERTYPUTREF
))
614 // map dispid to m_eventsIdx
615 wxActiveX::MemberIdList::iterator mid
= m_activeX
->m_eventsIdx
.find((MEMBERID
) dispIdMember
);
616 if (mid
== m_activeX
->m_eventsIdx
.end())
619 int funcIdx
= mid
->second
;
620 wxActiveX::FuncX
&func
= m_activeX
->m_events
[funcIdx
];
623 // try to find dispid event
624 ActiveXDISPIDEventMap::iterator dit
= sg_dispIdEventMap
.find(dispIdMember
);
625 if (dit
!= sg_dispIdEventMap
.end())
628 DispatchEvent(funcIdx
, *(dit
->second
), pDispParams
);
633 ActiveXNamedEventMap::iterator nit
= sg_NamedEventMap
.find(func
.name
);
634 if (nit
== sg_NamedEventMap
.end())
638 DispatchEvent(funcIdx
, *(nit
->second
), pDispParams
);
644 DEFINE_OLE_TABLE(wxActiveXEvents
)
645 OLE_IINTERFACE(IUnknown
)
646 OLE_INTERFACE(IID_IDispatch
, IDispatch
)
649 wxString
wxActiveXEvent::EventName()
651 return m_params
.GetName();
654 int wxActiveXEvent::ParamCount() const
656 return m_params
.GetCount();
659 wxString
wxActiveXEvent::ParamType(int idx
)
661 wxASSERT(idx
>= 0 && idx
< m_params
.GetCount());
663 return m_params
[idx
].GetType();
666 wxString
wxActiveXEvent::ParamName(int idx
)
668 wxASSERT(idx
>= 0 && idx
< m_params
.GetCount());
670 return m_params
[idx
].GetName();
673 static wxVariant nullVar
;
675 wxVariant
wxActiveXEvent::operator[] (int idx
) const
677 return (wxVariant
&) operator[] (idx
);
680 wxVariant
& wxActiveXEvent::operator[] (int idx
)
682 wxASSERT(idx
>= 0 && idx
< ParamCount());
684 return m_params
[idx
];
687 wxVariant
wxActiveXEvent::operator[] (wxString name
) const
689 return (wxVariant
&) operator[] (name
);
692 wxVariant
& wxActiveXEvent::operator[] (wxString name
)
694 for (int i
= 0; i
< m_params
.GetCount(); i
++)
696 if (name
.CmpNoCase(m_params
[i
].GetName()) == 0)
700 wxString err
= wxT("wxActiveXEvent::operator[] invalid name <") + name
+ wxT(">");
701 err
+= wxT("\r\nValid Names = :\r\n");
702 for (i
= 0; i
< m_params
.GetCount(); i
++)
704 err
+= m_params
[i
].GetName();
708 wxASSERT_MSG(false, err
);
713 void wxActiveX::GetTypeInfo()
716 We are currently only interested in the IDispatch interface
717 to the control. For dual interfaces (TypeKind = TKIND_INTERFACE)
718 we should drill down through the inheritance
719 (using TYPEATTR->cImplTypes) and GetRefTypeOfImplType(n)
720 and retrieve all the func names etc that way, then generate a C++
723 But we don't do this and probably never will, so if we have a DUAL
724 interface then we query for the IDispatch
725 via GetRefTypeOfImplType(-1).
730 // get type info via class info
731 wxAutoOleInterface
<IProvideClassInfo
> classInfo(IID_IProvideClassInfo
, m_ActiveX
);
732 if (! classInfo
.Ok())
736 wxAutoOleInterface
<ITypeInfo
> typeInfo
;
737 hret
= classInfo
->GetClassInfo(typeInfo
.GetRef());
743 hret
= typeInfo
->GetTypeAttr(&ta
);
747 // this should be a TKIND_COCLASS
748 wxASSERT(ta
->typekind
== TKIND_COCLASS
);
750 // iterate contained interfaces
751 for (int i
= 0; i
< ta
->cImplTypes
; i
++)
755 // get dispatch type info handle
756 hret
= typeInfo
->GetRefTypeOfImplType(i
, &rt
);
757 if (! SUCCEEDED(hret
))
760 // get dispatch type info interface
761 wxAutoOleInterface
<ITypeInfo
> ti
;
762 hret
= typeInfo
->GetRefTypeInfo(rt
, ti
.GetRef());
766 // check if default event sink
767 bool defEventSink
= false;
768 int impTypeFlags
= 0;
769 typeInfo
->GetImplTypeFlags(i
, &impTypeFlags
);
771 if (impTypeFlags
& IMPLTYPEFLAG_FDEFAULT
)
773 if (impTypeFlags
& IMPLTYPEFLAG_FSOURCE
)
775 WXOLE_TRACEOUT(wxT("Default Event Sink"));
780 WXOLE_TRACEOUT(wxT("Default Interface"));
786 GetTypeInfo(ti
, defEventSink
);
791 typeInfo
->ReleaseTypeAttr(ta
);
794 void wxActiveX::GetTypeInfo(ITypeInfo
*ti
, bool defEventSink
)
797 wxAutoOleInterface
<ITypeInfo
> typeInfo(ti
);
801 HRESULT hret
= typeInfo
->GetTypeAttr(&ta
);
805 if (ta
->typekind
== TKIND_DISPATCH
)
807 WXOLE_TRACEOUT(wxT("GUID = ") << GetIIDName(ta
->guid
).c_str());
811 wxActiveXEvents
*disp
= new wxActiveXEvents(this);
812 ConnectAdvise(ta
->guid
, disp
);
816 // Get Function Names
817 for (int i
= 0; i
< ta
->cFuncs
; i
++)
819 FUNCDESC FAR
*fd
= NULL
;
821 hret
= typeInfo
->GetFuncDesc(i
, &fd
);
825 BSTR anames
[1] = {NULL
};
828 hret
= typeInfo
->GetNames(fd
->memid
, anames
, 1, &n
);
832 wxString name
= anames
[0];
834 WXOLE_TRACEOUT(wxT("Name ") << i
<< wxT(" = ") << name
.c_str());
835 SysFreeString(anames
[0]);
841 func
.memid
= fd
->memid
;
845 unsigned int maxPNames
= fd
->cParams
+ 1;
846 unsigned int nPNames
= 0;
847 BSTR
*pnames
= new BSTR
[maxPNames
];
849 hret
= typeInfo
->GetNames(fd
->memid
, pnames
, maxPNames
, &nPNames
);
850 wxASSERT(int(nPNames
) >= fd
->cParams
+ 1);
852 SysFreeString(pnames
[0]);
854 for (int p
= 0; p
< fd
->cParams
; p
++)
858 param
.flags
= fd
->lprgelemdescParam
[p
].idldesc
.wIDLFlags
;
859 param
.vt
= fd
->lprgelemdescParam
[p
].tdesc
.vt
;
860 param
.isPtr
= (param
.vt
== VT_PTR
);
861 param
.isSafeArray
= (param
.vt
== VT_SAFEARRAY
);
862 if (param
.isPtr
|| param
.isSafeArray
)
863 param
.vt
= fd
->lprgelemdescParam
[p
].tdesc
.lptdesc
->vt
;
865 param
.name
= pnames
[p
+ 1];
866 SysFreeString(pnames
[p
+ 1]);
868 func
.hasOut
|= (param
.IsOut() || param
.isPtr
);
869 func
.params
.push_back(param
);
873 m_events
.push_back(func
);
874 m_eventsIdx
[fd
->memid
] = m_events
.size() - 1;
878 typeInfo
->ReleaseFuncDesc(fd
);
882 typeInfo
->ReleaseTypeAttr(ta
);
885 ///////////////////////////////////////////////
886 // Type Info exposure
887 const wxActiveX::FuncX
& wxActiveX::GetEvent(int idx
) const
889 wxASSERT(idx
>= 0 && idx
< GetEventCount());
891 return m_events
[idx
];
894 ///////////////////////////////////////////////
896 HRESULT
wxActiveX::ConnectAdvise(REFIID riid
, IUnknown
*events
)
898 wxOleConnectionPoint cp
;
899 DWORD adviseCookie
= 0;
901 wxAutoOleInterface
<IConnectionPointContainer
> cpContainer(IID_IConnectionPointContainer
, m_ActiveX
);
902 if (! cpContainer
.Ok())
905 HRESULT hret
= cpContainer
->FindConnectionPoint(riid
, cp
.GetRef());
906 if (! SUCCEEDED(hret
))
909 hret
= cp
->Advise(events
, &adviseCookie
);
912 m_connections
.push_back(wxOleConnection(cp
, adviseCookie
));
917 HRESULT
wxActiveX::AmbientPropertyChanged(DISPID dispid
)
919 wxAutoOleInterface
<IOleControl
> oleControl(IID_IOleControl
, m_oleObject
);
922 return oleControl
->OnAmbientPropertyChange(dispid
);
927 #define HIMETRIC_PER_INCH 2540
928 #define MAP_PIX_TO_LOGHIM(x,ppli) MulDiv(HIMETRIC_PER_INCH, (x), (ppli))
930 static void PixelsToHimetric(SIZEL
&sz
)
938 HDC dc
= GetDC(NULL
);
939 logX
= GetDeviceCaps(dc
, LOGPIXELSX
);
940 logY
= GetDeviceCaps(dc
, LOGPIXELSY
);
944 #define HIMETRIC_INCH 2540
945 #define CONVERT(x, logpixels) MulDiv(HIMETRIC_INCH, (x), (logpixels))
947 sz
.cx
= CONVERT(sz
.cx
, logX
);
948 sz
.cy
= CONVERT(sz
.cy
, logY
);
955 void wxActiveX::OnSize(wxSizeEvent
& event
)
958 GetClientSize(&w
, &h
);
966 if (w
<= 0 && h
<= 0)
969 // extents are in HIMETRIC units
970 if (m_oleObject
.Ok())
973 PixelsToHimetric(sz
);
977 m_oleObject
->GetExtent(DVASPECT_CONTENT
, &sz2
);
978 if (sz2
.cx
!= sz
.cx
|| sz
.cy
!= sz2
.cy
)
979 m_oleObject
->SetExtent(DVASPECT_CONTENT
, &sz
);
982 if (m_oleInPlaceObject
.Ok())
983 m_oleInPlaceObject
->SetObjectRects(&posRect
, &posRect
);
986 void wxActiveX::OnPaint(wxPaintEvent
& event
)
988 // wxLogTrace(wxT("repainting activex win"));
999 // Draw only when control is windowless or deactivated
1002 ::RedrawWindow(m_oleObjectHWND
, NULL
, NULL
, RDW_INTERNALPAINT
);
1004 RECTL
*prcBounds
= (RECTL
*) &posRect
;
1005 m_viewObject
->Draw(DVASPECT_CONTENT
, -1, NULL
, NULL
, NULL
,
1006 (HDC
)dc
.GetHDC(), prcBounds
, NULL
, NULL
, 0);
1011 dc
.SetBrush(*wxRED_BRUSH
);
1012 dc
.DrawRectangle(0, 0, w
, h
);
1013 dc
.SetBrush(wxNullBrush
);
1019 void wxActiveX::OnMouse(wxMouseEvent
& event
)
1021 if (m_oleObjectHWND
== NULL
)
1023 // wxLogTrace(wxT("no oleInPlaceObject"));
1028 // wxLogTrace(wxT("mouse event"));
1032 LRESULT lResult
= 0;
1034 if (event
.m_metaDown
)
1035 wParam
|= MK_CONTROL
;
1036 if (event
.m_shiftDown
)
1038 if (event
.m_leftDown
)
1039 wParam
|= MK_LBUTTON
;
1040 if (event
.m_middleDown
)
1041 wParam
|= MK_MBUTTON
;
1042 if (event
.m_rightDown
)
1043 wParam
|= MK_RBUTTON
;
1044 lParam
= event
.m_x
<< 16;
1045 lParam
|= event
.m_y
;
1047 if (event
.LeftDown())
1048 msg
= WM_LBUTTONDOWN
;
1049 else if (event
.LeftDClick())
1050 msg
= WM_LBUTTONDBLCLK
;
1051 else if (event
.LeftUp())
1053 else if (event
.MiddleDown())
1054 msg
= WM_MBUTTONDOWN
;
1055 else if (event
.MiddleDClick())
1056 msg
= WM_MBUTTONDBLCLK
;
1057 else if (event
.MiddleUp())
1059 else if (event
.RightDown())
1060 msg
= WM_RBUTTONDOWN
;
1061 else if (event
.RightDClick())
1062 msg
= WM_RBUTTONDBLCLK
;
1063 else if (event
.RightUp())
1065 else if (event
.Moving() || event
.Dragging())
1071 // wxLogTrace(wxT("no message"));
1072 event
.Skip(); return;
1075 if (!::SendMessage(m_oleObjectHWND
, msg
, wParam
, lParam
))
1077 // wxLogTrace(wxT("msg not delivered"));
1082 // wxLogTrace(wxT("msg sent"));
1085 WXLRESULT
wxActiveX::MSWWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
1087 if (m_oleObjectHWND
== NULL
)
1088 return wxWindow::MSWWindowProc(nMsg
, wParam
, lParam
);
1097 case WM_SYSDEADCHAR
:
1100 PostMessage(m_oleObjectHWND
, nMsg
, wParam
, lParam
);
1103 return wxWindow::MSWWindowProc(nMsg
, wParam
, lParam
);
1107 void wxActiveX::OnSetFocus(wxFocusEvent
& event
)
1109 if (m_oleInPlaceActiveObject
.Ok())
1110 m_oleInPlaceActiveObject
->OnFrameWindowActivate(TRUE
);
1113 void wxActiveX::OnKillFocus(wxFocusEvent
& event
)
1115 if (m_oleInPlaceActiveObject
.Ok())
1116 m_oleInPlaceActiveObject
->OnFrameWindowActivate(FALSE
);
1120 FrameSite::FrameSite(wxActiveX
* win
)
1123 m_bSupportsWindowlessActivation
= true;
1124 m_bInPlaceLocked
= false;
1125 m_bUIActive
= false;
1126 m_bInPlaceActive
= false;
1127 m_bWindowless
= false;
1129 m_nAmbientLocale
= 0;
1130 m_clrAmbientForeColor
= ::GetSysColor(COLOR_WINDOWTEXT
);
1131 m_clrAmbientBackColor
= ::GetSysColor(COLOR_WINDOW
);
1132 m_bAmbientShowHatching
= true;
1133 m_bAmbientShowGrabHandles
= true;
1134 m_bAmbientAppearance
= true;
1137 m_hWndParent
= (HWND
)m_window
->GetHWND();
1140 FrameSite::~FrameSite()
1147 HRESULT
FrameSite::GetIDsOfNames(REFIID riid
, OLECHAR
** rgszNames
, unsigned int cNames
,
1148 LCID lcid
, DISPID
* rgDispId
)
1150 WXOLE_TRACE("IDispatch::GetIDsOfNames");
1154 HRESULT
FrameSite::GetTypeInfo(unsigned int iTInfo
, LCID lcid
, ITypeInfo
** ppTInfo
)
1156 WXOLE_TRACE("IDispatch::GetTypeInfo");
1160 HRESULT
FrameSite::GetTypeInfoCount(unsigned int * pcTInfo
)
1162 WXOLE_TRACE("IDispatch::GetTypeInfoCount");
1166 HRESULT
FrameSite::Invoke(DISPID dispIdMember
, REFIID riid
, LCID lcid
,
1167 WORD wFlags
, DISPPARAMS
* pDispParams
,
1168 VARIANT
* pVarResult
, EXCEPINFO
* pExcepInfo
,
1169 unsigned int * puArgErr
)
1171 WXOLE_TRACE("IDispatch::Invoke");
1173 if (!(wFlags
& DISPATCH_PROPERTYGET
))
1178 if (pVarResult
== NULL
)
1179 return E_INVALIDARG
;
1181 //The most common case is boolean, use as an initial type
1182 V_VT(pVarResult
) = VT_BOOL
;
1184 switch (dispIdMember
)
1186 case DISPID_AMBIENT_MESSAGEREFLECT
:
1187 WXOLE_TRACE("Invoke::DISPID_AMBIENT_MESSAGEREFLECT");
1188 V_BOOL(pVarResult
)= FALSE
;
1191 case DISPID_AMBIENT_DISPLAYASDEFAULT
:
1192 WXOLE_TRACE("Invoke::DISPID_AMBIENT_DISPLAYASDEFAULT");
1193 V_BOOL(pVarResult
)= TRUE
;
1196 case DISPID_AMBIENT_OFFLINEIFNOTCONNECTED
:
1197 WXOLE_TRACE("Invoke::DISPID_AMBIENT_OFFLINEIFNOTCONNECTED");
1198 V_BOOL(pVarResult
) = TRUE
;
1202 case DISPID_AMBIENT_SILENT
:
1203 WXOLE_TRACE("Invoke::DISPID_AMBIENT_SILENT");
1204 V_BOOL(pVarResult
)= TRUE
;
1207 case DISPID_AMBIENT_APPEARANCE
:
1208 pVarResult
->vt
= VT_BOOL
;
1209 pVarResult
->boolVal
= m_bAmbientAppearance
;
1212 case DISPID_AMBIENT_FORECOLOR
:
1213 pVarResult
->vt
= VT_I4
;
1214 pVarResult
->lVal
= (long) m_clrAmbientForeColor
;
1217 case DISPID_AMBIENT_BACKCOLOR
:
1218 pVarResult
->vt
= VT_I4
;
1219 pVarResult
->lVal
= (long) m_clrAmbientBackColor
;
1222 case DISPID_AMBIENT_LOCALEID
:
1223 pVarResult
->vt
= VT_I4
;
1224 pVarResult
->lVal
= (long) m_nAmbientLocale
;
1227 case DISPID_AMBIENT_USERMODE
:
1228 pVarResult
->vt
= VT_BOOL
;
1229 pVarResult
->boolVal
= m_window
->m_bAmbientUserMode
;
1232 case DISPID_AMBIENT_SHOWGRABHANDLES
:
1233 pVarResult
->vt
= VT_BOOL
;
1234 pVarResult
->boolVal
= m_bAmbientShowGrabHandles
;
1237 case DISPID_AMBIENT_SHOWHATCHING
:
1238 pVarResult
->vt
= VT_BOOL
;
1239 pVarResult
->boolVal
= m_bAmbientShowHatching
;
1243 return DISP_E_MEMBERNOTFOUND
;
1251 HRESULT
FrameSite::GetWindow(HWND
* phwnd
)
1253 WXOLE_TRACE("IOleWindow::GetWindow");
1255 return E_INVALIDARG
;
1256 (*phwnd
) = m_hWndParent
;
1260 HRESULT
FrameSite::ContextSensitiveHelp(BOOL fEnterMode
)
1262 WXOLE_TRACE("IOleWindow::ContextSensitiveHelp");
1266 //IOleInPlaceUIWindow
1268 HRESULT
FrameSite::GetBorder(LPRECT lprectBorder
)
1270 WXOLE_TRACE("IOleInPlaceUIWindow::GetBorder");
1271 if (lprectBorder
== NULL
)
1272 return E_INVALIDARG
;
1273 return INPLACE_E_NOTOOLSPACE
;
1276 HRESULT
FrameSite::RequestBorderSpace(LPCBORDERWIDTHS pborderwidths
)
1278 WXOLE_TRACE("IOleInPlaceUIWindow::RequestBorderSpace");
1279 if (pborderwidths
== NULL
)
1280 return E_INVALIDARG
;
1281 return INPLACE_E_NOTOOLSPACE
;
1284 HRESULT
FrameSite::SetBorderSpace(LPCBORDERWIDTHS pborderwidths
)
1286 WXOLE_TRACE("IOleInPlaceUIWindow::SetBorderSpace");
1290 HRESULT
FrameSite::SetActiveObject(IOleInPlaceActiveObject
*pActiveObject
, LPCOLESTR pszObjName
)
1292 WXOLE_TRACE("IOleInPlaceUIWindow::SetActiveObject");
1295 pActiveObject
->AddRef();
1297 m_window
->m_oleInPlaceActiveObject
= pActiveObject
;
1303 HRESULT
FrameSite::InsertMenus(HMENU hmenuShared
, LPOLEMENUGROUPWIDTHS lpMenuWidths
)
1305 WXOLE_TRACE("IOleInPlaceFrame::InsertMenus");
1309 HRESULT
FrameSite::SetMenu(HMENU hmenuShared
, HOLEMENU holemenu
, HWND hwndActiveObject
)
1311 WXOLE_TRACE("IOleInPlaceFrame::SetMenu");
1315 HRESULT
FrameSite::RemoveMenus(HMENU hmenuShared
)
1317 WXOLE_TRACE("IOleInPlaceFrame::RemoveMenus");
1321 HRESULT
FrameSite::SetStatusText(LPCOLESTR pszStatusText
)
1323 WXOLE_TRACE("IOleInPlaceFrame::SetStatusText");
1324 //((wxFrame*)wxGetApp().GetTopWindow())->GetStatusBar()->SetStatusText(pszStatusText);
1328 HRESULT
FrameSite::EnableModeless(BOOL fEnable
)
1330 WXOLE_TRACE("IOleInPlaceFrame::EnableModeless");
1334 HRESULT
FrameSite::TranslateAccelerator(LPMSG lpmsg
, WORD wID
)
1336 WXOLE_TRACE("IOleInPlaceFrame::TranslateAccelerator");
1337 // TODO: send an event with this id
1338 if (m_window
->m_oleInPlaceActiveObject
.Ok())
1339 m_window
->m_oleInPlaceActiveObject
->TranslateAccelerator(lpmsg
);
1346 HRESULT
FrameSite::CanInPlaceActivate()
1348 WXOLE_TRACE("IOleInPlaceSite::CanInPlaceActivate");
1352 HRESULT
FrameSite::OnInPlaceActivate()
1354 WXOLE_TRACE("IOleInPlaceSite::OnInPlaceActivate");
1355 m_bInPlaceActive
= true;
1359 HRESULT
FrameSite::OnUIActivate()
1361 WXOLE_TRACE("IOleInPlaceSite::OnUIActivate");
1366 HRESULT
FrameSite::GetWindowContext(IOleInPlaceFrame
**ppFrame
,
1367 IOleInPlaceUIWindow
**ppDoc
,
1369 LPRECT lprcClipRect
,
1370 LPOLEINPLACEFRAMEINFO lpFrameInfo
)
1372 WXOLE_TRACE("IOleInPlaceSite::GetWindowContext");
1373 if (ppFrame
== NULL
|| ppDoc
== NULL
|| lprcPosRect
== NULL
||
1374 lprcClipRect
== NULL
|| lpFrameInfo
== NULL
)
1376 if (ppFrame
!= NULL
)
1380 return E_INVALIDARG
;
1383 HRESULT hr
= QueryInterface(IID_IOleInPlaceFrame
, (void **) ppFrame
);
1384 if (! SUCCEEDED(hr
))
1386 WXOLE_TRACE("IOleInPlaceSite::IOleInPlaceFrame Error !");
1387 return E_UNEXPECTED
;
1390 hr
= QueryInterface(IID_IOleInPlaceUIWindow
, (void **) ppDoc
);
1391 if (! SUCCEEDED(hr
))
1393 WXOLE_TRACE("IOleInPlaceSite::IOleInPlaceUIWindow Error !");
1394 (*ppFrame
)->Release();
1396 return E_UNEXPECTED
;
1400 m_window
->GetClientSize(&w
, &h
);
1403 lprcPosRect
->left
= lprcPosRect
->top
= 0;
1404 lprcPosRect
->right
= w
;
1405 lprcPosRect
->bottom
= h
;
1409 lprcClipRect
->left
= lprcClipRect
->top
= 0;
1410 lprcClipRect
->right
= w
;
1411 lprcClipRect
->bottom
= h
;
1414 memset(lpFrameInfo
, 0, sizeof(OLEINPLACEFRAMEINFO
));
1415 lpFrameInfo
->cb
= sizeof(OLEINPLACEFRAMEINFO
);
1416 lpFrameInfo
->hwndFrame
= m_hWndParent
;
1421 HRESULT
FrameSite::Scroll(SIZE scrollExtent
)
1423 WXOLE_TRACE("IOleInPlaceSite::Scroll");
1427 HRESULT
FrameSite::OnUIDeactivate(BOOL fUndoable
)
1429 WXOLE_TRACE("IOleInPlaceSite::OnUIDeactivate");
1430 m_bUIActive
= false;
1434 HRESULT
FrameSite::OnInPlaceDeactivate()
1436 WXOLE_TRACE("IOleInPlaceSite::OnInPlaceDeactivate");
1437 m_bInPlaceActive
= false;
1441 HRESULT
FrameSite::DiscardUndoState()
1443 WXOLE_TRACE("IOleInPlaceSite::DiscardUndoState");
1447 HRESULT
FrameSite::DeactivateAndUndo()
1449 WXOLE_TRACE("IOleInPlaceSite::DeactivateAndUndo");
1453 HRESULT
FrameSite::OnPosRectChange(LPCRECT lprcPosRect
)
1455 WXOLE_TRACE("IOleInPlaceSite::OnPosRectChange");
1456 if (m_window
->m_oleInPlaceObject
.Ok() && lprcPosRect
)
1457 m_window
->m_oleInPlaceObject
->SetObjectRects(lprcPosRect
, lprcPosRect
);
1464 HRESULT
FrameSite::OnInPlaceActivateEx(BOOL
* pfNoRedraw
, DWORD dwFlags
)
1466 WXOLE_TRACE("IOleInPlaceSiteEx::OnInPlaceActivateEx");
1467 OleLockRunning(m_window
->m_ActiveX
, TRUE
, FALSE
);
1469 (*pfNoRedraw
) = FALSE
;
1473 HRESULT
FrameSite::OnInPlaceDeactivateEx(BOOL fNoRedraw
)
1475 WXOLE_TRACE("IOleInPlaceSiteEx::OnInPlaceDeactivateEx");
1476 OleLockRunning(m_window
->m_ActiveX
, FALSE
, FALSE
);
1480 HRESULT
FrameSite::RequestUIActivate()
1482 WXOLE_TRACE("IOleInPlaceSiteEx::RequestUIActivate");
1489 HRESULT
FrameSite::SaveObject()
1491 WXOLE_TRACE("IOleClientSite::SaveObject");
1495 HRESULT
FrameSite::GetMoniker(DWORD dwAssign
, DWORD dwWhichMoniker
,
1498 WXOLE_TRACE("IOleClientSite::GetMoniker");
1502 HRESULT
FrameSite::GetContainer(LPOLECONTAINER
* ppContainer
)
1504 WXOLE_TRACE("IOleClientSite::GetContainer");
1505 if (ppContainer
== NULL
)
1506 return E_INVALIDARG
;
1508 HRESULT hr
= QueryInterface(IID_IOleContainer
, (void**)(ppContainer
));
1509 wxASSERT(SUCCEEDED(hr
));
1514 HRESULT
FrameSite::ShowObject()
1516 WXOLE_TRACE("IOleClientSite::ShowObject");
1517 if (m_window
->m_oleObjectHWND
)
1518 ::ShowWindow(m_window
->m_oleObjectHWND
, SW_SHOW
);
1522 HRESULT
FrameSite::OnShowWindow(BOOL fShow
)
1524 WXOLE_TRACE("IOleClientSite::OnShowWindow");
1528 HRESULT
FrameSite::RequestNewObjectLayout()
1530 WXOLE_TRACE("IOleClientSite::RequestNewObjectLayout");
1534 // IParseDisplayName
1536 HRESULT
FrameSite::ParseDisplayName(IBindCtx
*pbc
, LPOLESTR pszDisplayName
,
1537 ULONG
*pchEaten
, IMoniker
**ppmkOut
)
1539 WXOLE_TRACE("IParseDisplayName::ParseDisplayName");
1545 HRESULT
FrameSite::EnumObjects(DWORD grfFlags
, IEnumUnknown
**ppenum
)
1547 WXOLE_TRACE("IOleContainer::EnumObjects");
1551 HRESULT
FrameSite::LockContainer(BOOL fLock
)
1553 WXOLE_TRACE("IOleContainer::LockContainer");
1560 HRESULT
FrameSite::GetObject(LPOLESTR pszItem
, DWORD dwSpeedNeeded
,
1561 IBindCtx
* pbc
, REFIID riid
, void ** ppvObject
)
1563 WXOLE_TRACE("IOleItemContainer::GetObject");
1564 if (pszItem
== NULL
)
1565 return E_INVALIDARG
;
1566 if (ppvObject
== NULL
)
1567 return E_INVALIDARG
;
1570 return MK_E_NOOBJECT
;
1573 HRESULT
FrameSite::GetObjectStorage(LPOLESTR pszItem
, IBindCtx
* pbc
,
1574 REFIID riid
, void ** ppvStorage
)
1576 WXOLE_TRACE("IOleItemContainer::GetObjectStorage");
1577 if (pszItem
== NULL
)
1578 return E_INVALIDARG
;
1579 if (ppvStorage
== NULL
)
1580 return E_INVALIDARG
;
1583 return MK_E_NOOBJECT
;
1586 HRESULT
FrameSite::IsRunning(LPOLESTR pszItem
)
1588 WXOLE_TRACE("IOleItemContainer::IsRunning");
1589 if (pszItem
== NULL
)
1590 return E_INVALIDARG
;
1592 return MK_E_NOOBJECT
;
1599 HRESULT
FrameSite::OnControlInfoChanged()
1601 WXOLE_TRACE("IOleControlSite::OnControlInfoChanged");
1605 HRESULT
FrameSite::LockInPlaceActive(BOOL fLock
)
1607 WXOLE_TRACE("IOleControlSite::LockInPlaceActive");
1608 m_bInPlaceLocked
= (fLock
) ? true : false;
1612 HRESULT
FrameSite::GetExtendedControl(IDispatch
** ppDisp
)
1614 WXOLE_TRACE("IOleControlSite::GetExtendedControl");
1618 HRESULT
FrameSite::TransformCoords(POINTL
* pPtlHimetric
, POINTF
* pPtfContainer
, DWORD dwFlags
)
1620 WXOLE_TRACE("IOleControlSite::TransformCoords");
1623 if (pPtlHimetric
== NULL
)
1624 return E_INVALIDARG
;
1626 if (pPtfContainer
== NULL
)
1627 return E_INVALIDARG
;
1633 HRESULT
FrameSite::TranslateAccelerator(LPMSG pMsg
, DWORD grfModifiers
)
1635 WXOLE_TRACE("IOleControlSite::TranslateAccelerator");
1636 // TODO: send an event with this id
1640 HRESULT
FrameSite::OnFocus(BOOL fGotFocus
)
1642 WXOLE_TRACE("IOleControlSite::OnFocus");
1646 HRESULT
FrameSite::ShowPropertyFrame()
1648 WXOLE_TRACE("IOleControlSite::ShowPropertyFrame");
1654 HRESULT
FrameSite::QueryStatus(const GUID
* pguidCmdGroup
, ULONG cCmds
,
1655 OLECMD
* prgCmds
, OLECMDTEXT
* pCmdTet
)
1657 WXOLE_TRACE("IOleCommandTarget::QueryStatus");
1658 if (prgCmds
== NULL
) return E_INVALIDARG
;
1659 bool bCmdGroupFound
= false;
1661 for (ULONG nCmd
= 0; nCmd
< cCmds
; nCmd
++)
1663 // unsupported by default
1664 prgCmds
[nCmd
].cmdf
= 0;
1669 if (!bCmdGroupFound
) { OLECMDERR_E_UNKNOWNGROUP
; }
1673 HRESULT
FrameSite::Exec(const GUID
* pguidCmdGroup
, DWORD nCmdID
,
1674 DWORD nCmdExecOpt
, VARIANTARG
* pVaIn
,
1675 VARIANTARG
* pVaOut
)
1677 WXOLE_TRACE("IOleCommandTarget::Exec");
1678 bool bCmdGroupFound
= false;
1680 if (!bCmdGroupFound
) { OLECMDERR_E_UNKNOWNGROUP
; }
1681 return OLECMDERR_E_NOTSUPPORTED
;
1686 void STDMETHODCALLTYPE
FrameSite::OnDataChange(FORMATETC
* pFormatEtc
, STGMEDIUM
* pgStgMed
)
1688 WXOLE_TRACE("IAdviseSink::OnDataChange");
1691 void STDMETHODCALLTYPE
FrameSite::OnViewChange(DWORD dwAspect
, LONG lIndex
)
1693 WXOLE_TRACE("IAdviseSink::OnViewChange");
1694 // redraw the control
1697 void STDMETHODCALLTYPE
FrameSite::OnRename(IMoniker
* pmk
)
1699 WXOLE_TRACE("IAdviseSink::OnRename");
1702 void STDMETHODCALLTYPE
FrameSite::OnSave()
1704 WXOLE_TRACE("IAdviseSink::OnSave");
1707 void STDMETHODCALLTYPE
FrameSite::OnClose()
1709 WXOLE_TRACE("IAdviseSink::OnClose");
1712 /////////////////////////////////////////////
1714 HRESULT STDMETHODCALLTYPE
FrameSite::ActivateMe(
1715 /* [in] */ IOleDocumentView __RPC_FAR
*pViewToActivate
)
1717 wxAutoOleInterface
<IOleInPlaceSite
> inPlaceSite(IID_IOleInPlaceSite
, (IDispatch
*) this);
1718 if (!inPlaceSite
.Ok())
1721 if (pViewToActivate
)
1723 m_window
->m_docView
= pViewToActivate
;
1724 m_window
->m_docView
->SetInPlaceSite(inPlaceSite
);
1728 wxAutoOleInterface
<IOleDocument
> oleDoc(IID_IOleDocument
, m_window
->m_oleObject
);
1732 HRESULT hr
= oleDoc
->CreateView(inPlaceSite
, NULL
, 0, m_window
->m_docView
.GetRef());
1736 m_window
->m_docView
->SetInPlaceSite(inPlaceSite
);
1739 m_window
->m_docView
->UIActivate(TRUE
);
1746 static IMalloc
*iMalloc
= NULL
;
1748 IMalloc
*wxOleInit::GetIMalloc()
1754 wxOleInit::wxOleInit()
1756 if (OleInitialize(NULL
) == S_OK
&& iMalloc
== NULL
)
1757 CoGetMalloc(1, &iMalloc
);
1762 wxOleInit::~wxOleInit()
1766 if (iMalloc
->Release() == 0)
1773 wxString
OLEHResultToString(HRESULT hr
)
1778 return wxEmptyString
;
1780 case OLECMDERR_E_UNKNOWNGROUP
:
1781 return wxT("The pguidCmdGroup parameter is not NULL but does not specify a recognized command group.");
1783 case OLECMDERR_E_NOTSUPPORTED
:
1784 return wxT("The nCmdID parameter is not a valid command in the group identified by pguidCmdGroup.");
1786 case OLECMDERR_E_DISABLED
:
1787 return wxT("The command identified by nCmdID is currently disabled and cannot be executed.");
1789 case OLECMDERR_E_NOHELP
:
1790 return wxT("The caller has asked for help on the command identified by nCmdID, but no help is available.");
1792 case OLECMDERR_E_CANCELED
:
1793 return wxT("The user canceled the execution of the command.");
1796 return wxT("E_INVALIDARG");
1799 return wxT("E_OUTOFMEMORY");
1802 return wxT("E_NOINTERFACE");
1805 return wxT("E_UNEXPECTED");
1807 case STG_E_INVALIDFLAG
:
1808 return wxT("STG_E_INVALIDFLAG");
1811 return wxT("E_FAIL");
1814 return wxT("E_NOTIMPL");
1819 buf
.Printf(wxT("Unknown - 0x%X"), hr
);
1825 // borrowed from src/msw/ole/oleutils.cpp
1826 wxString
GetIIDName(REFIID riid
)
1828 // an association between symbolic name and numeric value of an IID
1832 const wxChar
*szName
;
1835 // construct the table containing all known interfaces
1836 #define ADD_KNOWN_IID(name) { &IID_I##name, _T(#name) }
1837 #define ADD_KNOWN_GUID(name) { &name, _T(#name) }
1839 static const KNOWN_IID aKnownIids
[] =
1841 ADD_KNOWN_IID(AdviseSink
),
1842 ADD_KNOWN_IID(AdviseSink2
),
1843 ADD_KNOWN_IID(BindCtx
),
1844 ADD_KNOWN_IID(ClassFactory
),
1845 #if ( !defined( __VISUALC__) || (__VISUALC__!=1010) ) && !defined(__MWERKS__)
1846 ADD_KNOWN_IID(ContinueCallback
),
1847 ADD_KNOWN_IID(EnumOleDocumentViews
),
1848 ADD_KNOWN_IID(OleCommandTarget
),
1849 ADD_KNOWN_IID(OleDocument
),
1850 ADD_KNOWN_IID(OleDocumentSite
),
1851 ADD_KNOWN_IID(OleDocumentView
),
1852 ADD_KNOWN_IID(Print
),
1854 ADD_KNOWN_IID(DataAdviseHolder
),
1855 ADD_KNOWN_IID(DataObject
),
1856 ADD_KNOWN_IID(Debug
),
1857 ADD_KNOWN_IID(DebugStream
),
1858 ADD_KNOWN_IID(DfReserved1
),
1859 ADD_KNOWN_IID(DfReserved2
),
1860 ADD_KNOWN_IID(DfReserved3
),
1861 ADD_KNOWN_IID(Dispatch
),
1862 ADD_KNOWN_IID(DropSource
),
1863 ADD_KNOWN_IID(DropTarget
),
1864 ADD_KNOWN_IID(EnumCallback
),
1865 ADD_KNOWN_IID(EnumFORMATETC
),
1866 ADD_KNOWN_IID(EnumGeneric
),
1867 ADD_KNOWN_IID(EnumHolder
),
1868 ADD_KNOWN_IID(EnumMoniker
),
1869 ADD_KNOWN_IID(EnumOLEVERB
),
1870 ADD_KNOWN_IID(EnumSTATDATA
),
1871 ADD_KNOWN_IID(EnumSTATSTG
),
1872 ADD_KNOWN_IID(EnumString
),
1873 ADD_KNOWN_IID(EnumUnknown
),
1874 ADD_KNOWN_IID(EnumVARIANT
),
1875 ADD_KNOWN_IID(ExternalConnection
),
1876 ADD_KNOWN_IID(InternalMoniker
),
1877 ADD_KNOWN_IID(LockBytes
),
1878 ADD_KNOWN_IID(Malloc
),
1879 ADD_KNOWN_IID(Marshal
),
1880 ADD_KNOWN_IID(MessageFilter
),
1881 ADD_KNOWN_IID(Moniker
),
1882 ADD_KNOWN_IID(OleAdviseHolder
),
1883 ADD_KNOWN_IID(OleCache
),
1884 ADD_KNOWN_IID(OleCache2
),
1885 ADD_KNOWN_IID(OleCacheControl
),
1886 ADD_KNOWN_IID(OleClientSite
),
1887 ADD_KNOWN_IID(OleContainer
),
1888 ADD_KNOWN_IID(OleInPlaceActiveObject
),
1889 ADD_KNOWN_IID(OleInPlaceFrame
),
1890 ADD_KNOWN_IID(OleInPlaceObject
),
1891 ADD_KNOWN_IID(OleInPlaceSite
),
1892 ADD_KNOWN_IID(OleInPlaceUIWindow
),
1893 ADD_KNOWN_IID(OleItemContainer
),
1894 ADD_KNOWN_IID(OleLink
),
1895 ADD_KNOWN_IID(OleManager
),
1896 ADD_KNOWN_IID(OleObject
),
1897 ADD_KNOWN_IID(OlePresObj
),
1898 ADD_KNOWN_IID(OleWindow
),
1899 ADD_KNOWN_IID(PSFactory
),
1900 ADD_KNOWN_IID(ParseDisplayName
),
1901 ADD_KNOWN_IID(Persist
),
1902 ADD_KNOWN_IID(PersistFile
),
1903 ADD_KNOWN_IID(PersistStorage
),
1904 ADD_KNOWN_IID(PersistStream
),
1905 ADD_KNOWN_IID(ProxyManager
),
1906 ADD_KNOWN_IID(RootStorage
),
1907 ADD_KNOWN_IID(RpcChannel
),
1908 ADD_KNOWN_IID(RpcProxy
),
1909 ADD_KNOWN_IID(RpcStub
),
1910 ADD_KNOWN_IID(RunnableObject
),
1911 ADD_KNOWN_IID(RunningObjectTable
),
1912 ADD_KNOWN_IID(StdMarshalInfo
),
1913 ADD_KNOWN_IID(Storage
),
1914 ADD_KNOWN_IID(Stream
),
1915 ADD_KNOWN_IID(StubManager
),
1916 ADD_KNOWN_IID(Unknown
),
1917 ADD_KNOWN_IID(ViewObject
),
1918 ADD_KNOWN_IID(ViewObject2
),
1919 ADD_KNOWN_GUID(IID_IDispatch
),
1920 ADD_KNOWN_GUID(IID_IWebBrowser
),
1921 ADD_KNOWN_GUID(IID_IWebBrowserApp
),
1922 ADD_KNOWN_GUID(IID_IWebBrowser2
),
1923 ADD_KNOWN_GUID(IID_IWebBrowser
),
1924 ADD_KNOWN_GUID(DIID_DWebBrowserEvents2
),
1925 ADD_KNOWN_GUID(DIID_DWebBrowserEvents
),
1928 // don't clobber preprocessor name space
1929 #undef ADD_KNOWN_IID
1930 #undef ADD_KNOWN_GUID
1932 // try to find the interface in the table
1933 for ( size_t ui
= 0; ui
< WXSIZEOF(aKnownIids
); ui
++ )
1935 if ( riid
== *aKnownIids
[ui
].pIid
)
1937 return aKnownIids
[ui
].szName
;
1941 // unknown IID, just transform to string
1942 LPOLESTR str
= NULL
;
1943 StringFromIID(riid
, &str
);
1951 return wxT("StringFromIID() error");