2 wxActiveX Library Licence, Version 3
3 ====================================
5 Copyright (C) 2003 Lindsay Mathieson [, ...]
7 Everyone is permitted to copy and distribute verbatim copies
8 of this licence document, but changing it is not allowed.
10 wxActiveX LIBRARY LICENCE
11 TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
13 This library is free software; you can redistribute it and/or modify it
14 under the terms of the GNU Library General Public Licence as published by
15 the Free Software Foundation; either version 2 of the Licence, or (at
16 your option) any later version.
18 This library is distributed in the hope that it will be useful, but
19 WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library
21 General Public Licence for more details.
23 You should have received a copy of the GNU Library General Public Licence
24 along with this software, usually in a file named COPYING.LIB. If not,
25 write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
26 Boston, MA 02111-1307 USA.
30 1. As a special exception, the copyright holders of this library give
31 permission for additional uses of the text contained in this release of
32 the library as licenced under the wxActiveX Library Licence, applying
33 either version 3 of the Licence, or (at your option) any later version of
34 the Licence as published by the copyright holders of version 3 of the
37 2. The exception is that you may use, copy, link, modify and distribute
38 under the user's own terms, binary object code versions of works based
41 3. If you copy code from files distributed under the terms of the GNU
42 General Public Licence or the GNU Library General Public Licence into a
43 copy of this library, as this licence permits, the exception does not
44 apply to the code that you add in this way. To avoid misleading anyone as
45 to the status of such modified files, you must delete this exception
46 notice from such code and/or adjust the licensing conditions notice
49 4. If you write modifications of your own for this library, it is your
50 choice whether to permit this exception to apply to your modifications.
51 If you do not wish that, you must delete the exception notice from such
52 code and/or adjust the licensing conditions notice accordingly.
55 #include "wxActiveX.h"
56 #include <wx/strconv.h>
58 #include <wx/string.h>
59 #include <wx/datetime.h>
67 // Depending on compilation mode, the wx headers may have undef'd
68 // this, but in this case we need it so the virtual method in
69 // FrameSite will match what is in oleidl.h.
72 #define GetObject GetObjectW
74 #define GetObject GetObjectA
79 //////////////////////////////////////////////////////////////////////
80 BEGIN_EVENT_TABLE(wxActiveX
, wxWindow
)
81 EVT_SIZE(wxActiveX::OnSize
)
82 EVT_PAINT(wxActiveX::OnPaint
)
83 EVT_MOUSE_EVENTS(wxActiveX::OnMouse
)
84 EVT_SET_FOCUS(wxActiveX::OnSetFocus
)
85 EVT_KILL_FOCUS(wxActiveX::OnKillFocus
)
88 IMPLEMENT_CLASS(wxActiveX
, wxWindow
)
93 public IOleClientSite
,
94 public IOleInPlaceSiteEx
,
95 public IOleInPlaceFrame
,
96 public IOleItemContainer
,
98 public IOleCommandTarget
,
99 public IOleDocumentSite
,
101 public IOleControlSite
104 DECLARE_OLE_UNKNOWN(FrameSite
);
107 FrameSite(wxActiveX
* win
);
108 virtual ~FrameSite();
111 STDMETHODIMP
GetWindow(HWND
*);
112 STDMETHODIMP
ContextSensitiveHelp(BOOL
);
114 //IOleInPlaceUIWindow
115 STDMETHODIMP
GetBorder(LPRECT
);
116 STDMETHODIMP
RequestBorderSpace(LPCBORDERWIDTHS
);
117 STDMETHODIMP
SetBorderSpace(LPCBORDERWIDTHS
);
118 STDMETHODIMP
SetActiveObject(IOleInPlaceActiveObject
*, LPCOLESTR
);
121 STDMETHODIMP
InsertMenus(HMENU
, LPOLEMENUGROUPWIDTHS
);
122 STDMETHODIMP
SetMenu(HMENU
, HOLEMENU
, HWND
);
123 STDMETHODIMP
RemoveMenus(HMENU
);
124 STDMETHODIMP
SetStatusText(LPCOLESTR
);
125 STDMETHODIMP
EnableModeless(BOOL
);
126 STDMETHODIMP
TranslateAccelerator(LPMSG
, WORD
);
129 STDMETHODIMP
CanInPlaceActivate();
130 STDMETHODIMP
OnInPlaceActivate();
131 STDMETHODIMP
OnUIActivate();
132 STDMETHODIMP
GetWindowContext(IOleInPlaceFrame
**, IOleInPlaceUIWindow
**,
133 LPRECT
, LPRECT
, LPOLEINPLACEFRAMEINFO
);
134 STDMETHODIMP
Scroll(SIZE
);
135 STDMETHODIMP
OnUIDeactivate(BOOL
);
136 STDMETHODIMP
OnInPlaceDeactivate();
137 STDMETHODIMP
DiscardUndoState();
138 STDMETHODIMP
DeactivateAndUndo();
139 STDMETHODIMP
OnPosRectChange(LPCRECT
);
142 STDMETHODIMP
OnInPlaceActivateEx(BOOL
*, DWORD
);
143 STDMETHODIMP
OnInPlaceDeactivateEx(BOOL
);
144 STDMETHODIMP
RequestUIActivate();
147 STDMETHODIMP
SaveObject();
148 STDMETHODIMP
GetMoniker(DWORD
, DWORD
, IMoniker
**);
149 STDMETHODIMP
GetContainer(LPOLECONTAINER FAR
*);
150 STDMETHODIMP
ShowObject();
151 STDMETHODIMP
OnShowWindow(BOOL
);
152 STDMETHODIMP
RequestNewObjectLayout();
155 STDMETHODIMP
OnControlInfoChanged();
156 STDMETHODIMP
LockInPlaceActive(BOOL
);
157 STDMETHODIMP
GetExtendedControl(IDispatch
**);
158 STDMETHODIMP
TransformCoords(POINTL
*, POINTF
*, DWORD
);
159 STDMETHODIMP
TranslateAccelerator(LPMSG
, DWORD
);
160 STDMETHODIMP
OnFocus(BOOL
);
161 STDMETHODIMP
ShowPropertyFrame();
164 STDMETHODIMP
QueryStatus(const GUID
*, ULONG
, OLECMD
[], OLECMDTEXT
*);
165 STDMETHODIMP
Exec(const GUID
*, DWORD
, DWORD
, VARIANTARG
*, VARIANTARG
*);
168 STDMETHODIMP
ParseDisplayName(IBindCtx
*, LPOLESTR
, ULONG
*, IMoniker
**);
171 STDMETHODIMP
EnumObjects(DWORD
, IEnumUnknown
**);
172 STDMETHODIMP
LockContainer(BOOL
);
175 STDMETHODIMP
GetObject(LPOLESTR
, DWORD
, IBindCtx
*, REFIID
, void**);
176 STDMETHODIMP
GetObjectStorage(LPOLESTR
, IBindCtx
*, REFIID
, void**);
177 STDMETHODIMP
IsRunning(LPOLESTR
);
180 STDMETHODIMP
GetIDsOfNames(REFIID
, OLECHAR
**, unsigned int, LCID
, DISPID
*);
181 STDMETHODIMP
GetTypeInfo(unsigned int, LCID
, ITypeInfo
**);
182 STDMETHODIMP
GetTypeInfoCount(unsigned int*);
183 STDMETHODIMP
Invoke(DISPID
, REFIID
, LCID
, WORD
, DISPPARAMS
*, VARIANT
*, EXCEPINFO
*, UINT
*);
186 void STDMETHODCALLTYPE
OnDataChange(FORMATETC
*, STGMEDIUM
*);
187 void STDMETHODCALLTYPE
OnViewChange(DWORD
, LONG
);
188 void STDMETHODCALLTYPE
OnRename(IMoniker
*);
189 void STDMETHODCALLTYPE
OnSave();
190 void STDMETHODCALLTYPE
OnClose();
193 HRESULT STDMETHODCALLTYPE
ActivateMe(IOleDocumentView __RPC_FAR
*pViewToActivate
);
197 wxActiveX
* m_window
;
202 bool m_bSupportsWindowlessActivation
;
203 bool m_bInPlaceLocked
;
204 bool m_bInPlaceActive
;
210 LCID m_nAmbientLocale
;
211 COLORREF m_clrAmbientForeColor
;
212 COLORREF m_clrAmbientBackColor
;
213 bool m_bAmbientShowHatching
;
214 bool m_bAmbientShowGrabHandles
;
215 bool m_bAmbientAppearance
;
218 DEFINE_OLE_TABLE(FrameSite
)
219 OLE_INTERFACE(IID_IUnknown
, IOleClientSite
)
221 OLE_IINTERFACE(IOleClientSite
)
223 OLE_INTERFACE(IID_IOleWindow
, IOleInPlaceSite
)
224 OLE_IINTERFACE(IOleInPlaceSite
)
225 OLE_IINTERFACE(IOleInPlaceSiteEx
)
227 //OLE_IINTERFACE(IOleWindow)
228 OLE_IINTERFACE(IOleInPlaceUIWindow
)
229 OLE_IINTERFACE(IOleInPlaceFrame
)
231 OLE_IINTERFACE(IParseDisplayName
)
232 OLE_IINTERFACE(IOleContainer
)
233 OLE_IINTERFACE(IOleItemContainer
)
235 OLE_IINTERFACE(IDispatch
)
237 OLE_IINTERFACE(IOleCommandTarget
)
239 OLE_IINTERFACE(IOleDocumentSite
)
241 OLE_IINTERFACE(IAdviseSink
)
243 OLE_IINTERFACE(IOleControlSite
)
248 wxActiveX::wxActiveX(wxWindow
* parent
, REFCLSID clsid
, wxWindowID id
,
252 const wxString
& name
) :
253 wxWindow(parent
, id
, pos
, size
, style
, name
)
255 m_bAmbientUserMode
= true;
256 m_docAdviseCookie
= 0;
257 CreateActiveX(clsid
);
260 wxActiveX::wxActiveX(wxWindow
* parent
, const wxString
& progId
, wxWindowID id
,
264 const wxString
& name
) :
265 wxWindow(parent
, id
, pos
, size
, style
, name
)
267 m_bAmbientUserMode
= true;
268 m_docAdviseCookie
= 0;
269 CreateActiveX((LPOLESTR
) (const wchar_t *) progId
.wc_str(wxConvUTF8
));
272 wxActiveX::~wxActiveX()
274 // disconnect connection points
275 wxOleConnectionArray::iterator it
= m_connections
.begin();
276 while (it
!= m_connections
.end())
278 wxOleConnectionPoint
& cp
= it
->first
;
279 cp
->Unadvise(it
->second
);
283 m_connections
.clear();
285 if (m_oleInPlaceObject
.Ok())
287 m_oleInPlaceObject
->InPlaceDeactivate();
288 m_oleInPlaceObject
->UIDeactivate();
292 if (m_oleObject
.Ok())
294 if (m_docAdviseCookie
!= 0)
295 m_oleObject
->Unadvise(m_docAdviseCookie
);
297 m_oleObject
->DoVerb(OLEIVERB_HIDE
, NULL
, m_clientSite
, 0, (HWND
) GetHWND(), NULL
);
298 m_oleObject
->Close(OLECLOSE_NOSAVE
);
299 m_oleObject
->SetClientSite(NULL
);
302 // Unregister object as active
303 RevokeActiveObject(m_pdwRegister
, NULL
);
306 void wxActiveX::CreateActiveX(REFCLSID clsid
)
310 ////////////////////////////////////////////////////////
312 FrameSite
*frame
= new FrameSite(this);
314 hret
= m_clientSite
.QueryInterface(IID_IOleClientSite
, (IDispatch
*) frame
);
315 wxCHECK_RET(SUCCEEDED(hret
), _T("m_clientSite.QueryInterface failed"));
317 wxAutoOleInterface
<IAdviseSink
> adviseSink(IID_IAdviseSink
, (IDispatch
*) frame
);
318 wxCHECK_RET(adviseSink
.Ok(), _T("adviseSink not Ok"));
321 // Create Object, get IUnknown interface
322 m_ActiveX
.CreateInstance(clsid
, IID_IUnknown
);
323 wxCHECK_RET(m_ActiveX
.Ok(), _T("m_ActiveX.CreateInstance failed"));
325 // Register object as active
326 unsigned long pdwRegister
;
327 hret
= RegisterActiveObject(m_ActiveX
, clsid
, ACTIVEOBJECT_WEAK
, &m_pdwRegister
);
328 WXOLE_WARN(hret
, "Unable to register object as active");
330 // Get Dispatch interface
331 hret
= m_Dispatch
.QueryInterface(IID_IDispatch
, m_ActiveX
);
332 WXOLE_WARN(hret
, "Unable to get dispatch interface");
337 // Get IOleObject interface
338 hret
= m_oleObject
.QueryInterface(IID_IOleObject
, m_ActiveX
);
339 wxCHECK_RET(SUCCEEDED(hret
), _("Unable to get IOleObject interface"));
341 // get IViewObject Interface
342 hret
= m_viewObject
.QueryInterface(IID_IViewObject
, m_ActiveX
);
343 wxCHECK_RET(SUCCEEDED(hret
), _T("Unable to get IViewObject Interface"));
346 m_docAdviseCookie
= 0;
347 hret
= m_oleObject
->Advise(adviseSink
, &m_docAdviseCookie
);
348 WXOLE_WARN(hret
, "m_oleObject->Advise(adviseSink, &m_docAdviseCookie),\"Advise\")");
349 m_oleObject
->SetHostNames(L
"wxActiveXContainer", NULL
);
350 OleSetContainedObject(m_oleObject
, TRUE
);
354 // Get IOleInPlaceObject interface
355 hret
= m_oleInPlaceObject
.QueryInterface(IID_IOleInPlaceObject
, m_ActiveX
);
356 wxCHECK_RET(SUCCEEDED(hret
), _T("Unable to get IOleInPlaceObject interface"));
360 m_oleObject
->GetMiscStatus(DVASPECT_CONTENT
, &dwMiscStatus
);
361 wxCHECK_RET(SUCCEEDED(hret
), _T("Unable to get oleObject status"));
363 // set client site first ?
364 if (dwMiscStatus
& OLEMISC_SETCLIENTSITEFIRST
)
365 m_oleObject
->SetClientSite(m_clientSite
);
369 wxAutoOleInterface
<IPersistStreamInit
>
370 pPersistStreamInit(IID_IPersistStreamInit
, m_oleObject
);
372 if (pPersistStreamInit
.Ok())
374 hret
= pPersistStreamInit
->InitNew();
375 WXOLE_WARN(hret
, "CreateActiveX::pPersistStreamInit->InitNew()");
378 if (! (dwMiscStatus
& OLEMISC_SETCLIENTSITEFIRST
))
379 m_oleObject
->SetClientSite(m_clientSite
);
383 GetClientSize(&w
, &h
);
392 if (m_oleInPlaceObject
.Ok())
394 hret
= m_oleInPlaceObject
->GetWindow(&m_oleObjectHWND
);
395 WXOLE_WARN(hret
, "m_oleInPlaceObject->GetWindow(&m_oleObjectHWND)");
397 ::SetActiveWindow(m_oleObjectHWND
);
401 if (! (dwMiscStatus
& OLEMISC_INVISIBLEATRUNTIME
))
403 if (w
> 0 && h
> 0 && m_oleInPlaceObject
.Ok())
404 m_oleInPlaceObject
->SetObjectRects(&posRect
, &posRect
);
406 hret
= m_oleObject
->DoVerb(OLEIVERB_INPLACEACTIVATE
, NULL
, m_clientSite
, 0, (HWND
)GetHWND(), &posRect
);
407 hret
= m_oleObject
->DoVerb(OLEIVERB_SHOW
, 0, m_clientSite
, 0, (HWND
)GetHWND(), &posRect
);
410 if (! m_oleObjectHWND
&& m_oleInPlaceObject
.Ok())
412 hret
= m_oleInPlaceObject
->GetWindow(&m_oleObjectHWND
);
413 WXOLE_WARN(hret
, "m_oleInPlaceObject->GetWindow(&m_oleObjectHWND)");
418 ::SetActiveWindow(m_oleObjectHWND
);
419 ::ShowWindow(m_oleObjectHWND
, SW_SHOW
);
421 // Update by GBR to resize older controls
423 szEvent
.m_size
= wxSize(w
, h
) ;
424 GetEventHandler()->AddPendingEvent(szEvent
);
428 void wxActiveX::CreateActiveX(LPOLESTR progId
)
431 if (CLSIDFromProgID(progId
, &clsid
) != S_OK
)
434 CreateActiveX(clsid
);
437 ////////////////////////////////////////////////////////////////////////////////////////////////////////////
438 // Case Insensitive Map of Event names to eventTypes
439 // created dynamically at run time in:
440 // EVT_ACTIVEX(eventName, id, fn)
441 // we map the pointer to them so that:
442 // const wxEventType& RegisterActiveXEvent(wxString eventName);
443 // can return a const reference, which is neccessary for event tables
444 // probably should use a wxWindows hash table here, but I'm lazy ...
445 typedef map
<wxString
, wxEventType
*, NS_wxActiveX::less_wxStringI
> ActiveXNamedEventMap
;
446 static ActiveXNamedEventMap sg_NamedEventMap
;
448 const wxEventType
& RegisterActiveXEvent(const wxChar
*eventName
)
450 wxString ev
= eventName
;
451 ActiveXNamedEventMap::iterator it
= sg_NamedEventMap
.find(ev
);
452 if (it
== sg_NamedEventMap
.end())
454 wxEventType
*et
= new wxEventType(wxNewEventType());
455 sg_NamedEventMap
[ev
] = et
;
460 return *(it
->second
);
464 ////////////////////////////////////////////////////////////////////////////////////////////////////////////
465 // Map of Event DISPID's to eventTypes
466 // created dynamically at run time in:
467 // EVT_ACTIVEX(eventName, id, fn)
468 // we map the pointer to them so that:
469 // const wxEventType& RegisterActiveXEvent(wxString eventName);
470 // can return a const reference, which is neccessary for event tables
472 typedef map
<DISPID
, wxEventType
*> ActiveXDISPIDEventMap
;
473 static ActiveXDISPIDEventMap sg_dispIdEventMap
;
475 const wxEventType
& RegisterActiveXEvent(DISPID event
)
477 ActiveXDISPIDEventMap::iterator it
= sg_dispIdEventMap
.find(event
);
478 if (it
== sg_dispIdEventMap
.end())
480 wxEventType
*et
= new wxEventType(wxNewEventType());
481 sg_dispIdEventMap
[event
] = et
;
486 return *(it
->second
);
489 // one off class for automatic freeing of activeX eventtypes
490 class ActiveXEventMapFlusher
493 ~ActiveXEventMapFlusher()
496 ActiveXNamedEventMap::iterator it
= sg_NamedEventMap
.end();
497 while (it
!= sg_NamedEventMap
.end())
502 sg_NamedEventMap
.clear();
505 ActiveXDISPIDEventMap::iterator dit
= sg_dispIdEventMap
.end();
506 while (dit
!= sg_dispIdEventMap
.end())
511 sg_dispIdEventMap
.clear();
515 static ActiveXEventMapFlusher s_dummyActiveXEventMapFlusher
;
518 //////////////////////////////////////////////////////
519 VARTYPE
wxTypeToVType(const wxVariant
& v
)
521 wxString type
= v
.GetType();
522 if (type
== wxT("bool"))
524 else if (type
== wxT("char"))
526 else if (type
== wxT("datetime"))
528 else if (type
== wxT("double"))
530 else if (type
== wxT("list"))
532 else if (type
== wxT("long"))
534 else if (type
== wxT("string"))
536 else if (type
== wxT("stringlist"))
538 else if (type
== wxT("date"))
540 else if (type
== wxT("time"))
542 else if (type
== wxT("void*"))
543 return VT_VOID
| VT_BYREF
;
548 bool wxDateTimeToDATE(wxDateTime dt
, DATE
& d
)
551 memset(&st
, 0, sizeof(st
));
553 st
.wYear
= dt
.GetYear();
554 st
.wMonth
= dt
.GetMonth() + 1;
555 st
.wDay
= dt
.GetDay();
556 st
.wHour
= dt
.GetHour();
557 st
.wMinute
= dt
.GetMinute();
558 st
.wSecond
= dt
.GetSecond();
559 st
.wMilliseconds
= dt
.GetMillisecond();
560 return SystemTimeToVariantTime(&st
, &d
) != FALSE
;
563 bool wxDateTimeToVariant(wxDateTime dt
, VARIANTARG
& va
)
565 return wxDateTimeToDATE(dt
, va
.date
);
568 bool DATEToWxDateTime(DATE date
, wxDateTime
& dt
)
571 if (! VariantTimeToSystemTime(date
, &st
))
576 wxDateTime::Month(int(wxDateTime::Jan
) + st
.wMonth
- 1),
578 st
.wHour
, st
.wMinute
, st
.wSecond
, st
.wMilliseconds
);
583 bool VariantToWxDateTime(VARIANTARG va
, wxDateTime
& dt
)
585 HRESULT hr
= VariantChangeType(&va
, &va
, 0, VT_DATE
);
589 return DATEToWxDateTime(va
.date
, dt
);
592 bool MSWVariantToVariant(VARIANTARG
& va
, wxVariant
& vx
)
598 return false; // don't support arrays yet
611 return MSWVariantToVariant(*va
.pvarVal
, vx
);
615 VariantChangeType(&tmp
, &tmp
, 0, wxTypeToVType(vx
));
616 bool rc
= MSWVariantToVariant(tmp
, vx
);
625 vx
= (char) *va
.pbVal
;
634 vx
= (long) *va
.puiVal
;
636 vx
= (long) va
.uiVal
;
646 vx
= (long) *va
.pulVal
;
648 vx
= (long) va
.ulVal
;
670 vx
= (*va
.pboolVal
? true : false);
672 vx
= (va
.boolVal
? true : false);
677 return false; // what the hell is a CY ?
684 hr
= VarR8FromDec(va
.pdecVal
, &d
);
686 hr
= VarR8FromDec(&va
.decVal
, &d
);
689 return SUCCEEDED(hr
);
697 rc
= DATEToWxDateTime(*va
.pdate
, dt
);
699 rc
= VariantToWxDateTime(va
, dt
);
706 vx
= wxString(*va
.pbstrVal
);
708 vx
= wxString(va
.bstrVal
);
711 case VT_UNKNOWN
: // should do a custom wxVariantData for this
713 vx
= (void *) *va
.ppunkVal
;
715 vx
= (void *) va
.punkVal
;
718 case VT_DISPATCH
: // should do a custom wxVariantData for this
720 vx
= (void *) *va
.ppdispVal
;
722 vx
= (void *) va
.pdispVal
;
731 bool VariantToMSWVariant(const wxVariant
& vx
, VARIANTARG
& va
)
737 return false; // don't support arrays yet
749 return VariantToMSWVariant(vx
, *va
.pvarVal
);
752 va
.vt
= wxTypeToVType(vx
);
753 return VariantToMSWVariant(vx
, va
);
760 *va
.pbVal
= (char) vx
;
769 *va
.puiVal
= (long) vx
;
771 va
.uiVal
= (long) vx
;
781 *va
.pulVal
= (long) vx
;
783 va
.ulVal
= (long) vx
;
790 *va
.pfltVal
= (double) vx
;
792 va
.fltVal
= (double) vx
;
798 *va
.pdblVal
= (double) vx
;
800 va
.dblVal
= (double) vx
;
805 *va
.pboolVal
= ((bool) vx
) ? TRUE
: FALSE
;
807 va
.boolVal
= ((bool) vx
) ? TRUE
: FALSE
;
811 return false; // what the hell is a CY ?
815 return SUCCEEDED(VarDecFromR8(vx
, va
.pdecVal
));
817 return SUCCEEDED(VarDecFromR8(vx
, &va
.decVal
));
821 return wxDateTimeToDATE(vx
, *va
.pdate
);
823 return wxDateTimeToVariant(vx
,va
);
827 *va
.pbstrVal
= SysAllocString(vx
.GetString().wc_str(wxConvUTF8
));
829 va
.bstrVal
= SysAllocString(vx
.GetString().wc_str(wxConvUTF8
));
832 case VT_UNKNOWN
: // should do a custom wxVariantData for this
834 *va
.ppunkVal
= (IUnknown
*) (void *) vx
;
836 va
.punkVal
= (IUnknown
*) (void *) vx
;
839 case VT_DISPATCH
: // should do a custom wxVariantData for this
841 *va
.ppdispVal
= (IDispatch
*) (void *) vx
;
843 va
.pdispVal
= (IDispatch
*) (void *) vx
;
851 IMPLEMENT_CLASS(wxActiveXEvent
, wxCommandEvent
)
853 class wxActiveXEvents
: public IDispatch
856 DECLARE_OLE_UNKNOWN(wxActiveXEvents
);
859 wxActiveX
*m_activeX
;
863 friend bool wxActiveXEventsInterface(wxActiveXEvents
*self
, REFIID iid
, void **_interface
, const char *&desc
);
866 wxActiveXEvents(wxActiveX
*ax
) : m_activeX(ax
), m_haveCustomId(false) {}
867 wxActiveXEvents(wxActiveX
*ax
, REFIID iid
) : m_activeX(ax
), m_haveCustomId(true), m_customId(iid
) {}
868 virtual ~wxActiveXEvents()
873 STDMETHODIMP
GetIDsOfNames(REFIID r
, OLECHAR
** o
, unsigned int i
, LCID l
, DISPID
* d
)
878 STDMETHODIMP
GetTypeInfo(unsigned int i
, LCID l
, ITypeInfo
** t
)
883 STDMETHODIMP
GetTypeInfoCount(unsigned int* i
)
889 void DispatchEvent(wxActiveX::FuncX
&func
, const wxEventType
& eventType
, DISPPARAMS
* pDispParams
)
891 wxActiveXEvent event
;
892 event
.SetId(m_activeX
->GetId());
893 event
.SetEventType(eventType
);
894 event
.m_params
.NullList();
895 event
.m_params
.SetName(func
.name
);
901 // sometimes the pDispParams does not match the param info for a activex control
902 int nArg
= wxMin(func
.params
.size(), pDispParams
->cArgs
);
903 for (int i
= nArg
- 1; i
>= 0; i
--)
905 VARIANTARG
& va
= pDispParams
->rgvarg
[i
];
906 wxActiveX::ParamX
&px
= func
.params
[nArg
- i
- 1];
910 MSWVariantToVariant(va
, vx
);
911 event
.m_params
.Append(vx
);
917 int nArg
= wxMin(func
.params
.size(), pDispParams
->cArgs
);
918 m_activeX
->GetEventHandler()->ProcessEvent(event
);
919 for (int i
= 0; i
< nArg
; i
++)
921 VARIANTARG
& va
= pDispParams
->rgvarg
[i
];
922 wxActiveX::ParamX
&px
= func
.params
[nArg
- i
- 1];
926 wxVariant
& vx
= event
.m_params
[nArg
- i
- 1];
928 VariantToMSWVariant(vx
, va
);
933 m_activeX
->GetEventHandler()->AddPendingEvent(event
);
937 STDMETHODIMP
Invoke(DISPID dispIdMember
, REFIID riid
, LCID lcid
,
938 WORD wFlags
, DISPPARAMS
* pDispParams
,
939 VARIANT
* pVarResult
, EXCEPINFO
* pExcepInfo
,
940 unsigned int * puArgErr
)
942 if (wFlags
& (DISPATCH_PROPERTYGET
| DISPATCH_PROPERTYPUT
| DISPATCH_PROPERTYPUTREF
))
947 // find event for dispid
948 wxActiveX::MemberIdMap::iterator mit
= m_activeX
->m_eventMemberIds
.find((MEMBERID
) dispIdMember
);
949 if (mit
== m_activeX
->m_eventMemberIds
.end())
953 int midx
= mit
->second
;
954 if (midx
< 0 || midx
>= m_activeX
->GetEventCount())
957 wxActiveX::FuncX
&func
= m_activeX
->m_events
[midx
];
960 // try to find dispid event
961 ActiveXDISPIDEventMap::iterator dit
= sg_dispIdEventMap
.find(dispIdMember
);
962 if (dit
!= sg_dispIdEventMap
.end())
965 DispatchEvent(func
, *(dit
->second
), pDispParams
);
970 ActiveXNamedEventMap::iterator nit
= sg_NamedEventMap
.find(func
.name
);
971 if (nit
== sg_NamedEventMap
.end())
975 DispatchEvent(func
, *(nit
->second
), pDispParams
);
980 bool wxActiveXEventsInterface(wxActiveXEvents
*self
, REFIID iid
, void **_interface
, const char *&desc
)
982 if (self
->m_haveCustomId
&& IsEqualIID(iid
, self
->m_customId
))
984 WXOLE_TRACE("Found Custom Dispatch Interface");
985 *_interface
= (IUnknown
*) (IDispatch
*) self
;
986 desc
= "Custom Dispatch Interface";
993 DEFINE_OLE_TABLE(wxActiveXEvents
)
994 OLE_IINTERFACE(IUnknown
)
995 OLE_INTERFACE(IID_IDispatch
, IDispatch
)
996 OLE_INTERFACE_CUSTOM(wxActiveXEventsInterface
)
999 wxString
wxActiveXEvent::EventName()
1001 return m_params
.GetName();
1004 int wxActiveXEvent::ParamCount() const
1006 return m_params
.GetCount();
1009 wxString
wxActiveXEvent::ParamType(int idx
)
1011 wxASSERT(idx
>= 0 && idx
< m_params
.GetCount());
1013 return m_params
[idx
].GetType();
1016 wxString
wxActiveXEvent::ParamName(int idx
)
1018 wxASSERT(idx
>= 0 && idx
< m_params
.GetCount());
1020 return m_params
[idx
].GetName();
1023 static wxVariant nullVar
;
1025 wxVariant
& wxActiveXEvent::operator[] (int idx
)
1027 wxASSERT(idx
>= 0 && idx
< ParamCount());
1029 return m_params
[idx
];
1032 wxVariant
& wxActiveXEvent::operator[] (wxString name
)
1034 for (int i
= 0; i
< m_params
.GetCount(); i
++)
1036 if (name
.CmpNoCase(m_params
[i
].GetName()) == 0)
1040 wxString err
= _T("wxActiveXEvent::operator[] invalid name <") + name
+ _T(">");
1041 err
+= _T("\r\nValid Names = :\r\n");
1042 for (i
= 0; i
< m_params
.GetCount(); i
++)
1044 err
+= m_params
[i
].GetName();
1048 wxASSERT_MSG(false, err
);
1053 void wxActiveX::GetTypeInfo()
1056 We are currently only interested in the IDispatch interface
1057 to the control. For dual interfaces (TypeKind = TKIND_INTERFACE)
1058 we should drill down through the inheritance
1059 (using TYPEATTR->cImplTypes) and GetRefTypeOfImplType(n)
1060 and retrieve all the func names etc that way, then generate a C++
1063 But we don't do this and probably never will, so if we have a DUAL
1064 interface then we query for the IDispatch
1065 via GetRefTypeOfImplType(-1).
1070 // get type info via class info
1071 wxAutoOleInterface
<IProvideClassInfo
> classInfo(IID_IProvideClassInfo
, m_ActiveX
);
1072 if (! classInfo
.Ok())
1076 wxAutoOleInterface
<ITypeInfo
> typeInfo
;
1077 hret
= classInfo
->GetClassInfo(typeInfo
.GetRef());
1078 if (! typeInfo
.Ok())
1082 TYPEATTR
*ta
= NULL
;
1083 hret
= typeInfo
->GetTypeAttr(&ta
);
1087 // this should be a TKIND_COCLASS
1088 wxASSERT(ta
->typekind
== TKIND_COCLASS
);
1090 // iterate contained interfaces
1091 for (int i
= 0; i
< ta
->cImplTypes
; i
++)
1095 // get dispatch type info handle
1096 hret
= typeInfo
->GetRefTypeOfImplType(i
, &rt
);
1097 if (! SUCCEEDED(hret
))
1100 // get dispatch type info interface
1101 wxAutoOleInterface
<ITypeInfo
> ti
;
1102 hret
= typeInfo
->GetRefTypeInfo(rt
, ti
.GetRef());
1106 // check if default event sink
1107 bool defInterface
= false;
1108 bool defEventSink
= false;
1109 int impTypeFlags
= 0;
1110 typeInfo
->GetImplTypeFlags(i
, &impTypeFlags
);
1112 if (impTypeFlags
& IMPLTYPEFLAG_FDEFAULT
)
1114 if (impTypeFlags
& IMPLTYPEFLAG_FSOURCE
)
1116 WXOLE_TRACEOUT("Default Event Sink");
1117 defEventSink
= true;
1118 if (impTypeFlags
& IMPLTYPEFLAG_FDEFAULTVTABLE
)
1120 WXOLE_TRACEOUT("*ERROR* - Default Event Sink is via vTable");
1121 defEventSink
= false;
1126 WXOLE_TRACEOUT("Default Interface");
1127 defInterface
= true;
1133 GetTypeInfo(ti
, defInterface
, defEventSink
);
1138 typeInfo
->ReleaseTypeAttr(ta
);
1141 void ElemDescToParam(const ELEMDESC
& ed
, wxActiveX::ParamX
& param
)
1143 param
.flags
= ed
.idldesc
.wIDLFlags
;
1144 param
.vt
= ed
.tdesc
.vt
;
1145 param
.isPtr
= (param
.vt
== VT_PTR
);
1146 param
.isSafeArray
= (param
.vt
== VT_SAFEARRAY
);
1147 if (param
.isPtr
|| param
.isSafeArray
)
1148 param
.vt
= ed
.tdesc
.lptdesc
->vt
;
1151 void wxActiveX::GetTypeInfo(ITypeInfo
*ti
, bool defInterface
, bool defEventSink
)
1153 // wxAutoOleInterface<> assumes a ref has already been added
1155 wxAutoOleInterface
<ITypeInfo
> typeInfo(ti
);
1158 TYPEATTR
*ta
= NULL
;
1159 HRESULT hret
= typeInfo
->GetTypeAttr(&ta
);
1163 if (ta
->typekind
== TKIND_DISPATCH
)
1165 WXOLE_TRACEOUT("GUID = " << GetIIDName(ta
->guid
).c_str());
1169 wxActiveXEvents
*disp
= new wxActiveXEvents(this, ta
->guid
);
1170 ConnectAdvise(ta
->guid
, disp
);
1174 // Get Function Names
1175 for (int i
= 0; i
< ta
->cFuncs
; i
++)
1177 FUNCDESC FAR
*fd
= NULL
;
1179 hret
= typeInfo
->GetFuncDesc(i
, &fd
);
1183 BSTR anames
[1] = {NULL
};
1186 hret
= typeInfo
->GetNames(fd
->memid
, anames
, 1, &n
);
1190 wxString name
= anames
[0];
1192 WXOLE_TRACEOUT("Name " << i
<< " = " << name
.c_str());
1193 SysFreeString(anames
[0]);
1195 if (defInterface
|| defEventSink
)
1199 func
.memid
= fd
->memid
;
1200 func
.hasOut
= false;
1203 unsigned int maxPNames
= fd
->cParams
+ 1;
1204 unsigned int nPNames
= 0;
1205 BSTR
*pnames
= new BSTR
[maxPNames
];
1207 hret
= typeInfo
->GetNames(fd
->memid
, pnames
, maxPNames
, &nPNames
);
1210 if (fd
->cParams
< int(nPNames
))
1213 SysFreeString(pnames
[0]);
1217 ElemDescToParam(fd
->elemdescFunc
, func
.retType
);
1218 for (int p
= 0; p
< fd
->cParams
; p
++)
1222 ElemDescToParam(fd
->lprgelemdescParam
[p
], param
);
1224 param
.name
= pnames
[pbase
+ p
];
1225 SysFreeString(pnames
[pbase
+ p
]);
1227 param
.isOptional
= (p
> fd
->cParams
- fd
->cParamsOpt
);
1229 func
.hasOut
|= (param
.IsOut() || param
.isPtr
);
1230 func
.params
.push_back(param
);
1236 m_events
.push_back(func
);
1237 m_eventMemberIds
[fd
->memid
] = m_events
.size() - 1;
1241 if (fd
->invkind
== INVOKE_FUNC
)
1243 m_methods
.push_back(func
);
1244 m_methodNames
[func
.name
] = m_methods
.size() - 1;
1248 NameMap::iterator it
= m_propNames
.find(func
.name
);
1250 if (it
== m_propNames
.end())
1252 m_props
.push_back(PropX());
1253 idx
= m_props
.size() - 1;
1254 m_propNames
[func
.name
] = idx
;
1255 m_props
[idx
].name
= func
.name
;
1256 m_props
[idx
].memid
= func
.memid
;
1262 if (fd
->invkind
== INVOKE_PROPERTYGET
)
1263 m_props
[idx
].type
= func
.retType
;
1264 else if (func
.params
.size() > 0)
1266 m_props
[idx
].arg
= func
.params
[0];
1267 m_props
[idx
].putByRef
= (fd
->invkind
== INVOKE_PROPERTYPUTREF
);
1274 typeInfo
->ReleaseFuncDesc(fd
);
1278 typeInfo
->ReleaseTypeAttr(ta
);
1281 ///////////////////////////////////////////////
1282 // Type Info exposure
1283 const wxActiveX::FuncX
& wxActiveX::GetEventDesc(int idx
) const
1285 wxASSERT(idx
>= 0 && idx
< GetEventCount());
1287 return m_events
[idx
];
1290 const wxActiveX::PropX
& wxActiveX::GetPropDesc(int idx
) const
1292 if (idx
< 0 || idx
>= GetPropCount())
1293 throw exception("Property index out of bounds");
1295 return m_props
[idx
];
1298 const wxActiveX::PropX
& wxActiveX::GetPropDesc(const wxString
& name
) const
1300 NameMap::const_iterator it
= m_propNames
.find(name
);
1301 if (it
== m_propNames
.end())
1304 s
<< _T("property <") << name
<< _T("> not found");
1305 throw exception(s
.mb_str());
1308 return GetPropDesc(it
->second
);
1311 const wxActiveX::FuncX
& wxActiveX::GetMethodDesc(int idx
) const
1313 if (idx
< 0 || idx
>= GetMethodCount())
1314 throw exception("Method index out of bounds");
1317 return m_methods
[idx
];
1321 const wxActiveX::FuncX
& wxActiveX::GetMethodDesc(const wxString
& name
) const
1323 NameMap::const_iterator it
= m_methodNames
.find(name
);
1324 if (it
== m_methodNames
.end())
1327 s
<< _T("method <") << name
<< _T("> not found");
1328 throw exception(s
.mb_str());
1331 return GetMethodDesc(it
->second
);
1335 void wxActiveX::SetProp(MEMBERID name
, VARIANTARG
& value
)
1337 DISPID pids
[1] = {DISPID_PROPERTYPUT
};
1338 DISPPARAMS params
= {&value
, pids
, 1, 1};
1341 memset(&x
, 0, sizeof(x
));
1342 unsigned int argErr
= 0;
1344 HRESULT hr
= m_Dispatch
->Invoke(
1346 IID_NULL
, LOCALE_USER_DEFAULT
, DISPATCH_PROPERTYPUT
,
1347 ¶ms
, NULL
, &x
, &argErr
);
1349 WXOLE_WARN(hr
, "Invoke Prop(...)");
1352 void wxActiveX::SetProp(const wxString
&name
, const wxVariant
&value
)
1354 const PropX
& prop
= GetPropDesc(name
);
1355 if (! prop
.CanSet())
1358 s
<< _T("property <") << name
<< _T("> is readonly");
1359 throw exception(s
.mb_str());
1362 VARIANT v
= {prop
.arg
.vt
};
1363 VariantToMSWVariant(value
, v
);
1364 SetProp(prop
.memid
, v
);
1365 VariantClear(&v
); // this releases any BSTR's etc
1368 VARIANT
wxActiveX::GetPropAsVariant(MEMBERID name
)
1373 DISPPARAMS params
= {NULL
, NULL
, 0, 0};
1376 memset(&x
, 0, sizeof(x
));
1377 unsigned int argErr
= 0;
1379 HRESULT hr
= m_Dispatch
->Invoke(
1381 IID_NULL
, LOCALE_USER_DEFAULT
, DISPATCH_PROPERTYGET
,
1382 ¶ms
, &v
, &x
, &argErr
);
1384 WXOLE_WARN(hr
, "Invoke Prop(...)");
1389 VARIANT
wxActiveX::GetPropAsVariant(const wxString
& name
)
1391 const PropX
& prop
= GetPropDesc(name
);
1392 if (! prop
.CanGet())
1395 s
<< _T("property <") << name
<< _T("> is writeonly");
1396 throw exception(s
.mb_str());
1399 return GetPropAsVariant(prop
.memid
);
1402 wxVariant
wxActiveX::GetPropAsWxVariant(const wxString
& name
)
1404 VARIANT v
= GetPropAsVariant(name
);
1405 HRESULT hr
= VariantChangeType(&v
, &v
, 0, VT_BSTR
);
1406 if (! SUCCEEDED(hr
))
1407 throw exception("Unable to convert variant");
1410 MSWVariantToVariant(v
, wv
);
1417 wxString
wxActiveX::GetPropAsString(const wxString
& name
)
1419 VARIANT v
= GetPropAsVariant(name
);
1420 HRESULT hr
= VariantChangeType(&v
, &v
, 0, VT_BSTR
);
1421 if (! SUCCEEDED(hr
))
1422 throw exception("Unable to convert variant");
1424 wxString s
= v
.bstrVal
;
1430 char wxActiveX::GetPropAsChar(const wxString
& name
)
1432 VARIANT v
= GetPropAsVariant(name
);
1433 HRESULT hr
= VariantChangeType(&v
, &v
, 0, VT_I1
);
1434 if (! SUCCEEDED(hr
))
1435 throw exception("Unable to convert variant");
1440 long wxActiveX::GetPropAsLong(const wxString
& name
)
1442 VARIANT v
= GetPropAsVariant(name
);
1443 HRESULT hr
= VariantChangeType(&v
, &v
, 0, VT_I4
);
1444 if (! SUCCEEDED(hr
))
1445 throw exception("Unable to convert variant");
1450 bool wxActiveX::GetPropAsBool(const wxString
& name
)
1452 VARIANT v
= GetPropAsVariant(name
);
1453 HRESULT hr
= VariantChangeType(&v
, &v
, 0, VT_BOOL
);
1454 if (! SUCCEEDED(hr
))
1455 throw exception("Unable to convert variant");
1457 return v
.boolVal
!= 0;
1460 double wxActiveX::GetPropAsDouble(const wxString
& name
)
1462 VARIANT v
= GetPropAsVariant(name
);
1463 HRESULT hr
= VariantChangeType(&v
, &v
, 0, VT_R8
);
1464 if (! SUCCEEDED(hr
))
1465 throw exception("Unable to convert variant");
1470 wxDateTime
wxActiveX::GetPropAsDateTime(const wxString
& name
)
1473 VARIANT v
= GetPropAsVariant(name
);
1475 if (! VariantToWxDateTime(v
, dt
))
1476 throw exception("Unable to convert variant to wxDateTime");
1481 void *wxActiveX::GetPropAsPointer(const wxString
& name
)
1483 VARIANT v
= GetPropAsVariant(name
);
1484 HRESULT hr
= VariantChangeType(&v
, &v
, 0, VT_BYREF
);
1485 if (! SUCCEEDED(hr
))
1486 throw exception("Unable to convert variant");
1494 VARIANT
wxActiveX::CallMethod(MEMBERID name
, VARIANTARG args
[], int argc
)
1496 DISPPARAMS pargs
= {args
, NULL
, argc
, 0};
1498 VariantInit(&retVal
);
1501 memset(&x
, 0, sizeof(x
));
1502 unsigned int argErr
= 0;
1504 HRESULT hr
= m_Dispatch
->Invoke(
1506 IID_NULL
, LOCALE_USER_DEFAULT
, DISPATCH_METHOD
,
1507 &pargs
, &retVal
, &x
, &argErr
);
1509 WXOLE_WARN(hr
, "Invoke Method(...)");
1513 VARIANT
wxActiveX::CallMethod(const wxString
& name
, VARIANTARG args
[], int argc
)
1515 const FuncX
& func
= GetMethodDesc(name
);
1517 argc
= func
.params
.size();
1519 return CallMethod(func
.memid
, args
, argc
);
1523 wxVariant
wxActiveX::CallMethod(const wxString
& name
, wxVariant args
[], int nargs
)
1525 const FuncX
& func
= GetMethodDesc(name
);
1530 VARIANTARG
*vargs
= NULL
;
1532 nargs
= func
.params
.size();
1535 vargs
= new VARIANTARG
[nargs
];
1539 // init type of vargs
1540 for (int i
= 0; i
< nargs
; i
++)
1541 vargs
[nargs
- i
- 1].vt
= func
.params
[i
].vt
;
1544 for (i
= 0; i
< nargs
; i
++)
1545 VariantToMSWVariant(args
[i
], vargs
[nargs
- i
- 1]);
1548 VARIANT rv
= CallMethod(func
.memid
, vargs
, nargs
);
1550 // process any by ref params
1553 for (int i
= 0; i
< nargs
; i
++)
1555 VARIANTARG
& va
= vargs
[nargs
- i
- 1];
1556 const wxActiveX::ParamX
&px
= func
.params
[i
];
1560 wxVariant
& vx
= args
[i
];
1562 MSWVariantToVariant(va
, vx
);
1569 for (int i
= 0; i
< nargs
; i
++)
1570 VariantClear(&vargs
[i
]);
1576 MSWVariantToVariant(rv
, ret
);
1583 ///////////////////////////////////////////////
1585 HRESULT
wxActiveX::ConnectAdvise(REFIID riid
, IUnknown
*events
)
1587 wxOleConnectionPoint cp
;
1588 DWORD adviseCookie
= 0;
1590 wxAutoOleInterface
<IConnectionPointContainer
> cpContainer(IID_IConnectionPointContainer
, m_ActiveX
);
1591 if (! cpContainer
.Ok())
1594 HRESULT hret
= cpContainer
->FindConnectionPoint(riid
, cp
.GetRef());
1595 if (! SUCCEEDED(hret
))
1598 hret
= cp
->Advise(events
, &adviseCookie
);
1600 if (SUCCEEDED(hret
))
1601 m_connections
.push_back(wxOleConnection(cp
, adviseCookie
));
1604 WXOLE_WARN(hret
, "ConnectAdvise");
1610 HRESULT
wxActiveX::AmbientPropertyChanged(DISPID dispid
)
1612 wxAutoOleInterface
<IOleControl
> oleControl(IID_IOleControl
, m_oleObject
);
1614 if (oleControl
.Ok())
1615 return oleControl
->OnAmbientPropertyChange(dispid
);
1620 #define HIMETRIC_PER_INCH 2540
1621 #define MAP_PIX_TO_LOGHIM(x,ppli) MulDiv(HIMETRIC_PER_INCH, (x), (ppli))
1623 static void PixelsToHimetric(SIZEL
&sz
)
1625 static int logX
= 0;
1626 static int logY
= 0;
1631 HDC dc
= GetDC(NULL
);
1632 logX
= GetDeviceCaps(dc
, LOGPIXELSX
);
1633 logY
= GetDeviceCaps(dc
, LOGPIXELSY
);
1634 ReleaseDC(NULL
, dc
);
1637 #define HIMETRIC_INCH 2540
1638 #define CONVERT(x, logpixels) MulDiv(HIMETRIC_INCH, (x), (logpixels))
1640 sz
.cx
= CONVERT(sz
.cx
, logX
);
1641 sz
.cy
= CONVERT(sz
.cy
, logY
);
1644 #undef HIMETRIC_INCH
1648 void wxActiveX::OnSize(wxSizeEvent
& event
)
1651 GetClientSize(&w
, &h
);
1659 if (w
<= 0 && h
<= 0)
1662 // extents are in HIMETRIC units
1663 if (m_oleObject
.Ok())
1666 PixelsToHimetric(sz
);
1670 m_oleObject
->GetExtent(DVASPECT_CONTENT
, &sz2
);
1671 if (sz2
.cx
!= sz
.cx
|| sz
.cy
!= sz2
.cy
)
1672 m_oleObject
->SetExtent(DVASPECT_CONTENT
, &sz
);
1675 if (m_oleInPlaceObject
.Ok())
1676 m_oleInPlaceObject
->SetObjectRects(&posRect
, &posRect
);
1679 void wxActiveX::OnPaint(wxPaintEvent
& event
)
1681 wxLogTrace(wxT(""),wxT("repainting activex win"));
1692 // Draw only when control is windowless or deactivated
1695 ::RedrawWindow(m_oleObjectHWND
, NULL
, NULL
, RDW_INTERNALPAINT
);
1697 RECTL
*prcBounds
= (RECTL
*) &posRect
;
1698 m_viewObject
->Draw(DVASPECT_CONTENT
, -1, NULL
, NULL
, NULL
,
1699 (HDC
)dc
.GetHDC(), prcBounds
, NULL
, NULL
, 0);
1704 dc
.SetBrush(*wxRED_BRUSH
);
1705 dc
.DrawRectangle(0, 0, w
, h
);
1706 dc
.SetBrush(wxNullBrush
);
1712 void wxActiveX::OnMouse(wxMouseEvent
& event
)
1714 if (m_oleObjectHWND
== NULL
)
1716 wxLogTrace(wxT(""),wxT("no oleInPlaceObject"));
1721 wxLogTrace(wxT(""),wxT("mouse event"));
1725 LRESULT lResult
= 0;
1727 if (event
.m_metaDown
)
1728 wParam
|= MK_CONTROL
;
1729 if (event
.m_shiftDown
)
1731 if (event
.m_leftDown
)
1732 wParam
|= MK_LBUTTON
;
1733 if (event
.m_middleDown
)
1734 wParam
|= MK_MBUTTON
;
1735 if (event
.m_rightDown
)
1736 wParam
|= MK_RBUTTON
;
1737 lParam
= event
.m_x
<< 16;
1738 lParam
|= event
.m_y
;
1740 if (event
.LeftDown())
1741 msg
= WM_LBUTTONDOWN
;
1742 else if (event
.LeftDClick())
1743 msg
= WM_LBUTTONDBLCLK
;
1744 else if (event
.LeftUp())
1746 else if (event
.MiddleDown())
1747 msg
= WM_MBUTTONDOWN
;
1748 else if (event
.MiddleDClick())
1749 msg
= WM_MBUTTONDBLCLK
;
1750 else if (event
.MiddleUp())
1752 else if (event
.RightDown())
1753 msg
= WM_RBUTTONDOWN
;
1754 else if (event
.RightDClick())
1755 msg
= WM_RBUTTONDBLCLK
;
1756 else if (event
.RightUp())
1758 else if (event
.Moving() || event
.Dragging())
1764 wxLogTrace(wxT(""),wxT("no message"));
1765 event
.Skip(); return;
1768 if (!::SendMessage(m_oleObjectHWND
, msg
, wParam
, lParam
))
1770 wxLogTrace(wxT(""),wxT("msg not delivered"));
1775 wxLogTrace(wxT(""),wxT("msg sent"));
1778 bool wxActiveX::MSWTranslateMessage(WXMSG
*msg
){
1780 if (msg
->message
== WM_KEYDOWN
){
1781 HRESULT result
= m_oleInPlaceActiveObject
->TranslateAccelerator(msg
);
1782 return (result
== S_OK
);
1785 return wxWindow::MSWTranslateMessage(msg
);
1788 long wxActiveX::MSWWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
1790 if (m_oleObjectHWND
== NULL
)
1791 return wxWindow::MSWWindowProc(nMsg
, wParam
, lParam
);
1800 case WM_SYSDEADCHAR
:
1803 PostMessage(m_oleObjectHWND
, nMsg
, wParam
, lParam
);
1806 return wxWindow::MSWWindowProc(nMsg
, wParam
, lParam
);
1810 void wxActiveX::OnSetFocus(wxFocusEvent
& event
)
1812 if (m_oleInPlaceActiveObject
.Ok())
1813 m_oleInPlaceActiveObject
->OnFrameWindowActivate(TRUE
);
1816 void wxActiveX::OnKillFocus(wxFocusEvent
& event
)
1818 if (m_oleInPlaceActiveObject
.Ok())
1819 m_oleInPlaceActiveObject
->OnFrameWindowActivate(FALSE
);
1823 FrameSite::FrameSite(wxActiveX
* win
)
1826 m_bSupportsWindowlessActivation
= true;
1827 m_bInPlaceLocked
= false;
1828 m_bUIActive
= false;
1829 m_bInPlaceActive
= false;
1830 m_bWindowless
= false;
1832 m_nAmbientLocale
= 0;
1833 m_clrAmbientForeColor
= ::GetSysColor(COLOR_WINDOWTEXT
);
1834 m_clrAmbientBackColor
= ::GetSysColor(COLOR_WINDOW
);
1835 m_bAmbientShowHatching
= true;
1836 m_bAmbientShowGrabHandles
= true;
1837 m_bAmbientAppearance
= true;
1840 m_hWndParent
= (HWND
)m_window
->GetHWND();
1843 FrameSite::~FrameSite()
1850 HRESULT
FrameSite::GetIDsOfNames(REFIID riid
, OLECHAR
** rgszNames
, unsigned int cNames
,
1851 LCID lcid
, DISPID
* rgDispId
)
1853 WXOLE_TRACE("IDispatch::GetIDsOfNames");
1857 HRESULT
FrameSite::GetTypeInfo(unsigned int iTInfo
, LCID lcid
, ITypeInfo
** ppTInfo
)
1859 WXOLE_TRACE("IDispatch::GetTypeInfo");
1863 HRESULT
FrameSite::GetTypeInfoCount(unsigned int * pcTInfo
)
1865 WXOLE_TRACE("IDispatch::GetTypeInfoCount");
1869 HRESULT
FrameSite::Invoke(DISPID dispIdMember
, REFIID riid
, LCID lcid
,
1870 WORD wFlags
, DISPPARAMS
* pDispParams
,
1871 VARIANT
* pVarResult
, EXCEPINFO
* pExcepInfo
,
1872 unsigned int * puArgErr
)
1874 WXOLE_TRACE("IDispatch::Invoke");
1876 if (!(wFlags
& DISPATCH_PROPERTYGET
))
1881 if (pVarResult
== NULL
)
1882 return E_INVALIDARG
;
1884 //The most common case is boolean, use as an initial type
1885 V_VT(pVarResult
) = VT_BOOL
;
1887 switch (dispIdMember
)
1889 case DISPID_AMBIENT_MESSAGEREFLECT
:
1890 WXOLE_TRACE("Invoke::DISPID_AMBIENT_MESSAGEREFLECT");
1891 V_BOOL(pVarResult
)= FALSE
;
1894 case DISPID_AMBIENT_DISPLAYASDEFAULT
:
1895 WXOLE_TRACE("Invoke::DISPID_AMBIENT_DISPLAYASDEFAULT");
1896 V_BOOL(pVarResult
)= TRUE
;
1899 case DISPID_AMBIENT_OFFLINEIFNOTCONNECTED
:
1900 WXOLE_TRACE("Invoke::DISPID_AMBIENT_OFFLINEIFNOTCONNECTED");
1901 V_BOOL(pVarResult
) = TRUE
;
1905 case DISPID_AMBIENT_SILENT
:
1906 WXOLE_TRACE("Invoke::DISPID_AMBIENT_SILENT");
1907 V_BOOL(pVarResult
)= TRUE
;
1910 case DISPID_AMBIENT_APPEARANCE
:
1911 pVarResult
->vt
= VT_BOOL
;
1912 pVarResult
->boolVal
= m_bAmbientAppearance
;
1915 case DISPID_AMBIENT_FORECOLOR
:
1916 pVarResult
->vt
= VT_I4
;
1917 pVarResult
->lVal
= (long) m_clrAmbientForeColor
;
1920 case DISPID_AMBIENT_BACKCOLOR
:
1921 pVarResult
->vt
= VT_I4
;
1922 pVarResult
->lVal
= (long) m_clrAmbientBackColor
;
1925 case DISPID_AMBIENT_LOCALEID
:
1926 pVarResult
->vt
= VT_I4
;
1927 pVarResult
->lVal
= (long) m_nAmbientLocale
;
1930 case DISPID_AMBIENT_USERMODE
:
1931 pVarResult
->vt
= VT_BOOL
;
1932 pVarResult
->boolVal
= m_window
->m_bAmbientUserMode
;
1935 case DISPID_AMBIENT_SHOWGRABHANDLES
:
1936 pVarResult
->vt
= VT_BOOL
;
1937 pVarResult
->boolVal
= m_bAmbientShowGrabHandles
;
1940 case DISPID_AMBIENT_SHOWHATCHING
:
1941 pVarResult
->vt
= VT_BOOL
;
1942 pVarResult
->boolVal
= m_bAmbientShowHatching
;
1946 return DISP_E_MEMBERNOTFOUND
;
1954 HRESULT
FrameSite::GetWindow(HWND
* phwnd
)
1956 WXOLE_TRACE("IOleWindow::GetWindow");
1958 return E_INVALIDARG
;
1959 (*phwnd
) = m_hWndParent
;
1963 HRESULT
FrameSite::ContextSensitiveHelp(BOOL fEnterMode
)
1965 WXOLE_TRACE("IOleWindow::ContextSensitiveHelp");
1969 //IOleInPlaceUIWindow
1971 HRESULT
FrameSite::GetBorder(LPRECT lprectBorder
)
1973 WXOLE_TRACE("IOleInPlaceUIWindow::GetBorder");
1974 if (lprectBorder
== NULL
)
1975 return E_INVALIDARG
;
1976 return INPLACE_E_NOTOOLSPACE
;
1979 HRESULT
FrameSite::RequestBorderSpace(LPCBORDERWIDTHS pborderwidths
)
1981 WXOLE_TRACE("IOleInPlaceUIWindow::RequestBorderSpace");
1982 if (pborderwidths
== NULL
)
1983 return E_INVALIDARG
;
1984 return INPLACE_E_NOTOOLSPACE
;
1987 HRESULT
FrameSite::SetBorderSpace(LPCBORDERWIDTHS pborderwidths
)
1989 WXOLE_TRACE("IOleInPlaceUIWindow::SetBorderSpace");
1993 HRESULT
FrameSite::SetActiveObject(IOleInPlaceActiveObject
*pActiveObject
, LPCOLESTR pszObjName
)
1995 WXOLE_TRACE("IOleInPlaceUIWindow::SetActiveObject");
1998 pActiveObject
->AddRef();
2000 m_window
->m_oleInPlaceActiveObject
= pActiveObject
;
2006 HRESULT
FrameSite::InsertMenus(HMENU hmenuShared
, LPOLEMENUGROUPWIDTHS lpMenuWidths
)
2008 WXOLE_TRACE("IOleInPlaceFrame::InsertMenus");
2012 HRESULT
FrameSite::SetMenu(HMENU hmenuShared
, HOLEMENU holemenu
, HWND hwndActiveObject
)
2014 WXOLE_TRACE("IOleInPlaceFrame::SetMenu");
2018 HRESULT
FrameSite::RemoveMenus(HMENU hmenuShared
)
2020 WXOLE_TRACE("IOleInPlaceFrame::RemoveMenus");
2024 HRESULT
FrameSite::SetStatusText(LPCOLESTR pszStatusText
)
2026 WXOLE_TRACE("IOleInPlaceFrame::SetStatusText");
2027 //((wxFrame*)wxGetApp().GetTopWindow())->GetStatusBar()->SetStatusText(pszStatusText);
2031 HRESULT
FrameSite::EnableModeless(BOOL fEnable
)
2033 WXOLE_TRACE("IOleInPlaceFrame::EnableModeless");
2037 HRESULT
FrameSite::TranslateAccelerator(LPMSG lpmsg
, WORD wID
)
2039 WXOLE_TRACE("IOleInPlaceFrame::TranslateAccelerator");
2040 // TODO: send an event with this id
2041 if (m_window
->m_oleInPlaceActiveObject
.Ok())
2042 m_window
->m_oleInPlaceActiveObject
->TranslateAccelerator(lpmsg
);
2049 HRESULT
FrameSite::CanInPlaceActivate()
2051 WXOLE_TRACE("IOleInPlaceSite::CanInPlaceActivate");
2055 HRESULT
FrameSite::OnInPlaceActivate()
2057 WXOLE_TRACE("IOleInPlaceSite::OnInPlaceActivate");
2058 m_bInPlaceActive
= true;
2062 HRESULT
FrameSite::OnUIActivate()
2064 WXOLE_TRACE("IOleInPlaceSite::OnUIActivate");
2069 HRESULT
FrameSite::GetWindowContext(IOleInPlaceFrame
**ppFrame
,
2070 IOleInPlaceUIWindow
**ppDoc
,
2072 LPRECT lprcClipRect
,
2073 LPOLEINPLACEFRAMEINFO lpFrameInfo
)
2075 WXOLE_TRACE("IOleInPlaceSite::GetWindowContext");
2076 if (ppFrame
== NULL
|| ppDoc
== NULL
|| lprcPosRect
== NULL
||
2077 lprcClipRect
== NULL
|| lpFrameInfo
== NULL
)
2079 if (ppFrame
!= NULL
)
2083 return E_INVALIDARG
;
2086 HRESULT hr
= QueryInterface(IID_IOleInPlaceFrame
, (void **) ppFrame
);
2087 if (! SUCCEEDED(hr
))
2089 WXOLE_TRACE("IOleInPlaceSite::IOleInPlaceFrame Error !");
2090 return E_UNEXPECTED
;
2093 hr
= QueryInterface(IID_IOleInPlaceUIWindow
, (void **) ppDoc
);
2094 if (! SUCCEEDED(hr
))
2096 WXOLE_TRACE("IOleInPlaceSite::IOleInPlaceUIWindow Error !");
2097 (*ppFrame
)->Release();
2099 return E_UNEXPECTED
;
2103 m_window
->GetClientSize(&w
, &h
);
2106 lprcPosRect
->left
= lprcPosRect
->top
= 0;
2107 lprcPosRect
->right
= w
;
2108 lprcPosRect
->bottom
= h
;
2112 lprcClipRect
->left
= lprcClipRect
->top
= 0;
2113 lprcClipRect
->right
= w
;
2114 lprcClipRect
->bottom
= h
;
2117 memset(lpFrameInfo
, 0, sizeof(OLEINPLACEFRAMEINFO
));
2118 lpFrameInfo
->cb
= sizeof(OLEINPLACEFRAMEINFO
);
2119 lpFrameInfo
->hwndFrame
= m_hWndParent
;
2124 HRESULT
FrameSite::Scroll(SIZE scrollExtent
)
2126 WXOLE_TRACE("IOleInPlaceSite::Scroll");
2130 HRESULT
FrameSite::OnUIDeactivate(BOOL fUndoable
)
2132 WXOLE_TRACE("IOleInPlaceSite::OnUIDeactivate");
2133 m_bUIActive
= false;
2137 HRESULT
FrameSite::OnInPlaceDeactivate()
2139 WXOLE_TRACE("IOleInPlaceSite::OnInPlaceDeactivate");
2140 m_bInPlaceActive
= false;
2144 HRESULT
FrameSite::DiscardUndoState()
2146 WXOLE_TRACE("IOleInPlaceSite::DiscardUndoState");
2150 HRESULT
FrameSite::DeactivateAndUndo()
2152 WXOLE_TRACE("IOleInPlaceSite::DeactivateAndUndo");
2156 HRESULT
FrameSite::OnPosRectChange(LPCRECT lprcPosRect
)
2158 WXOLE_TRACE("IOleInPlaceSite::OnPosRectChange");
2159 if (m_window
->m_oleInPlaceObject
.Ok() && lprcPosRect
)
2160 m_window
->m_oleInPlaceObject
->SetObjectRects(lprcPosRect
, lprcPosRect
);
2167 HRESULT
FrameSite::OnInPlaceActivateEx(BOOL
* pfNoRedraw
, DWORD dwFlags
)
2169 WXOLE_TRACE("IOleInPlaceSiteEx::OnInPlaceActivateEx");
2170 OleLockRunning(m_window
->m_ActiveX
, TRUE
, FALSE
);
2172 (*pfNoRedraw
) = FALSE
;
2176 HRESULT
FrameSite::OnInPlaceDeactivateEx(BOOL fNoRedraw
)
2178 WXOLE_TRACE("IOleInPlaceSiteEx::OnInPlaceDeactivateEx");
2179 OleLockRunning(m_window
->m_ActiveX
, FALSE
, FALSE
);
2183 HRESULT
FrameSite::RequestUIActivate()
2185 WXOLE_TRACE("IOleInPlaceSiteEx::RequestUIActivate");
2192 HRESULT
FrameSite::SaveObject()
2194 WXOLE_TRACE("IOleClientSite::SaveObject");
2198 const char *OleGetMonikerToStr(DWORD dwAssign
)
2202 case OLEGETMONIKER_ONLYIFTHERE
: return "OLEGETMONIKER_ONLYIFTHERE";
2203 case OLEGETMONIKER_FORCEASSIGN
: return "OLEGETMONIKER_FORCEASSIGN";
2204 case OLEGETMONIKER_UNASSIGN
: return "OLEGETMONIKER_UNASSIGN";
2205 case OLEGETMONIKER_TEMPFORUSER
: return "OLEGETMONIKER_TEMPFORUSER";
2206 default : return "Bad Enum";
2210 const char *OleGetWhicMonikerStr(DWORD dwWhichMoniker
)
2212 switch(dwWhichMoniker
)
2214 case OLEWHICHMK_CONTAINER
: return "OLEWHICHMK_CONTAINER";
2215 case OLEWHICHMK_OBJREL
: return "OLEWHICHMK_OBJREL";
2216 case OLEWHICHMK_OBJFULL
: return "OLEWHICHMK_OBJFULL";
2217 default : return "Bad Enum";
2221 HRESULT
FrameSite::GetMoniker(DWORD dwAssign
, DWORD dwWhichMoniker
,
2224 WXOLE_TRACEOUT("IOleClientSite::GetMoniker(" << OleGetMonikerToStr(dwAssign
) << ", " << OleGetWhicMonikerStr(dwWhichMoniker
) << ")");
2231 HRESULT hr = CreateFileMoniker(L"e:\\dev\\wxie\\bug-zap.swf", ppmk);
2240 HRESULT
FrameSite::GetContainer(LPOLECONTAINER
* ppContainer
)
2242 WXOLE_TRACE("IOleClientSite::GetContainer");
2243 if (ppContainer
== NULL
)
2244 return E_INVALIDARG
;
2246 HRESULT hr
= QueryInterface(IID_IOleContainer
, (void**)(ppContainer
));
2247 wxASSERT(SUCCEEDED(hr
));
2252 HRESULT
FrameSite::ShowObject()
2254 WXOLE_TRACE("IOleClientSite::ShowObject");
2255 if (m_window
->m_oleObjectHWND
)
2256 ::ShowWindow(m_window
->m_oleObjectHWND
, SW_SHOW
);
2260 HRESULT
FrameSite::OnShowWindow(BOOL fShow
)
2262 WXOLE_TRACE("IOleClientSite::OnShowWindow");
2266 HRESULT
FrameSite::RequestNewObjectLayout()
2268 WXOLE_TRACE("IOleClientSite::RequestNewObjectLayout");
2272 // IParseDisplayName
2274 HRESULT
FrameSite::ParseDisplayName(IBindCtx
*pbc
, LPOLESTR pszDisplayName
,
2275 ULONG
*pchEaten
, IMoniker
**ppmkOut
)
2277 WXOLE_TRACE("IParseDisplayName::ParseDisplayName");
2283 HRESULT
FrameSite::EnumObjects(DWORD grfFlags
, IEnumUnknown
**ppenum
)
2285 WXOLE_TRACE("IOleContainer::EnumObjects");
2289 HRESULT
FrameSite::LockContainer(BOOL fLock
)
2291 WXOLE_TRACE("IOleContainer::LockContainer");
2298 HRESULT
FrameSite::GetObject(LPOLESTR pszItem
, DWORD dwSpeedNeeded
,
2299 IBindCtx
* pbc
, REFIID riid
, void ** ppvObject
)
2301 WXOLE_TRACE("IOleItemContainer::GetObject");
2302 if (pszItem
== NULL
)
2303 return E_INVALIDARG
;
2304 if (ppvObject
== NULL
)
2305 return E_INVALIDARG
;
2308 return MK_E_NOOBJECT
;
2311 HRESULT
FrameSite::GetObjectStorage(LPOLESTR pszItem
, IBindCtx
* pbc
,
2312 REFIID riid
, void ** ppvStorage
)
2314 WXOLE_TRACE("IOleItemContainer::GetObjectStorage");
2315 if (pszItem
== NULL
)
2316 return E_INVALIDARG
;
2317 if (ppvStorage
== NULL
)
2318 return E_INVALIDARG
;
2321 return MK_E_NOOBJECT
;
2324 HRESULT
FrameSite::IsRunning(LPOLESTR pszItem
)
2326 WXOLE_TRACE("IOleItemContainer::IsRunning");
2327 if (pszItem
== NULL
)
2328 return E_INVALIDARG
;
2330 return MK_E_NOOBJECT
;
2337 HRESULT
FrameSite::OnControlInfoChanged()
2339 WXOLE_TRACE("IOleControlSite::OnControlInfoChanged");
2343 HRESULT
FrameSite::LockInPlaceActive(BOOL fLock
)
2345 WXOLE_TRACE("IOleControlSite::LockInPlaceActive");
2346 m_bInPlaceLocked
= (fLock
) ? true : false;
2350 HRESULT
FrameSite::GetExtendedControl(IDispatch
** ppDisp
)
2352 WXOLE_TRACE("IOleControlSite::GetExtendedControl");
2356 HRESULT
FrameSite::TransformCoords(POINTL
* pPtlHimetric
, POINTF
* pPtfContainer
, DWORD dwFlags
)
2358 WXOLE_TRACE("IOleControlSite::TransformCoords");
2361 if (pPtlHimetric
== NULL
)
2362 return E_INVALIDARG
;
2364 if (pPtfContainer
== NULL
)
2365 return E_INVALIDARG
;
2371 HRESULT
FrameSite::TranslateAccelerator(LPMSG pMsg
, DWORD grfModifiers
)
2373 WXOLE_TRACE("IOleControlSite::TranslateAccelerator");
2374 // TODO: send an event with this id
2378 HRESULT
FrameSite::OnFocus(BOOL fGotFocus
)
2380 WXOLE_TRACE("IOleControlSite::OnFocus");
2384 HRESULT
FrameSite::ShowPropertyFrame()
2386 WXOLE_TRACE("IOleControlSite::ShowPropertyFrame");
2392 HRESULT
FrameSite::QueryStatus(const GUID
* pguidCmdGroup
, ULONG cCmds
,
2393 OLECMD
* prgCmds
, OLECMDTEXT
* pCmdTet
)
2395 WXOLE_TRACE("IOleCommandTarget::QueryStatus");
2396 if (prgCmds
== NULL
) return E_INVALIDARG
;
2397 bool bCmdGroupFound
= false;
2399 for (ULONG nCmd
= 0; nCmd
< cCmds
; nCmd
++)
2401 // unsupported by default
2402 prgCmds
[nCmd
].cmdf
= 0;
2407 if (!bCmdGroupFound
) { OLECMDERR_E_UNKNOWNGROUP
; }
2411 HRESULT
FrameSite::Exec(const GUID
* pguidCmdGroup
, DWORD nCmdID
,
2412 DWORD nCmdExecOpt
, VARIANTARG
* pVaIn
,
2413 VARIANTARG
* pVaOut
)
2415 WXOLE_TRACE("IOleCommandTarget::Exec");
2416 bool bCmdGroupFound
= false;
2418 if (!bCmdGroupFound
) { OLECMDERR_E_UNKNOWNGROUP
; }
2419 return OLECMDERR_E_NOTSUPPORTED
;
2424 void STDMETHODCALLTYPE
FrameSite::OnDataChange(FORMATETC
* pFormatEtc
, STGMEDIUM
* pgStgMed
)
2426 WXOLE_TRACE("IAdviseSink::OnDataChange");
2429 void STDMETHODCALLTYPE
FrameSite::OnViewChange(DWORD dwAspect
, LONG lIndex
)
2431 WXOLE_TRACE("IAdviseSink::OnViewChange");
2432 // redraw the control
2435 void STDMETHODCALLTYPE
FrameSite::OnRename(IMoniker
* pmk
)
2437 WXOLE_TRACE("IAdviseSink::OnRename");
2440 void STDMETHODCALLTYPE
FrameSite::OnSave()
2442 WXOLE_TRACE("IAdviseSink::OnSave");
2445 void STDMETHODCALLTYPE
FrameSite::OnClose()
2447 WXOLE_TRACE("IAdviseSink::OnClose");
2450 /////////////////////////////////////////////
2452 HRESULT STDMETHODCALLTYPE
FrameSite::ActivateMe(
2453 /* [in] */ IOleDocumentView __RPC_FAR
*pViewToActivate
)
2455 wxAutoOleInterface
<IOleInPlaceSite
> inPlaceSite(IID_IOleInPlaceSite
, (IDispatch
*) this);
2456 if (!inPlaceSite
.Ok())
2459 if (pViewToActivate
)
2461 m_window
->m_docView
= pViewToActivate
;
2462 m_window
->m_docView
->SetInPlaceSite(inPlaceSite
);
2466 wxAutoOleInterface
<IOleDocument
> oleDoc(IID_IOleDocument
, m_window
->m_oleObject
);
2470 HRESULT hr
= oleDoc
->CreateView(inPlaceSite
, NULL
, 0, m_window
->m_docView
.GetRef());
2474 m_window
->m_docView
->SetInPlaceSite(inPlaceSite
);
2477 m_window
->m_docView
->UIActivate(TRUE
);
2483 static IMalloc
*iMalloc
= NULL
;
2485 IMalloc
*wxOleInit::GetIMalloc()
2491 wxOleInit::wxOleInit()
2493 if (OleInitialize(NULL
) == S_OK
&& iMalloc
== NULL
)
2494 CoGetMalloc(1, &iMalloc
);
2499 wxOleInit::~wxOleInit()
2503 if (iMalloc
->Release() == 0)
2510 bool GetSysErrMessage(int err
, wxString
& s
)
2514 FORMAT_MESSAGE_FROM_SYSTEM
, NULL
,
2515 err
,0, buf
, sizeof(buf
), NULL
) == 0)
2518 buf
[sizeof(buf
) - 1] = 0;
2523 wxString
OLEHResultToString(HRESULT hr
)
2525 // try formatmessage
2527 if (GetSysErrMessage(hr
, err
))
2533 return wxEmptyString
;
2535 case CONNECT_E_CANNOTCONNECT
:
2536 return _T("Cannot connect to event interface (maybe not there ?) - see MSDN");
2538 case DISP_E_MEMBERNOTFOUND
:
2539 return _T("The requested member does not exist, or the call to Invoke tried to set the value of a read-only property.");
2541 case DISP_E_BADVARTYPE
:
2542 return _T("One of the parameters in rgvarg is not a valid variant type.");
2544 case DISP_E_BADPARAMCOUNT
:
2545 return _T("The number of elements provided to DISPPARAMS is different from the number of parameters accepted by the method or property");
2547 case DISP_E_EXCEPTION
:
2548 return _T("The application needs to raise an exception. In this case, the structure passed in pExcepInfo should be filled in.");
2550 case DISP_E_TYPEMISMATCH
:
2551 return _T("One or more of the parameters could not be coerced. The index within rgvarg of the first parameter with the incorrect type is returned in the puArgErr parameter.");
2553 case DISP_E_PARAMNOTOPTIONAL
:
2554 return _T("A required parameter was omitted.");
2556 case DISP_E_PARAMNOTFOUND
:
2557 return _T("One of the parameter DISPIDs does not correspond to a parameter on the method. In this case, puArgErr should be set to the first parameter that contains the error.");
2559 case OLECMDERR_E_UNKNOWNGROUP
:
2560 return _T("The pguidCmdGroup parameter is not NULL but does not specify a recognized command group.");
2562 case OLECMDERR_E_NOTSUPPORTED
:
2563 return _T("The nCmdID parameter is not a valid command in the group identified by pguidCmdGroup.");
2565 case OLECMDERR_E_DISABLED
:
2566 return _T("The command identified by nCmdID is currently disabled and cannot be executed.");
2568 case OLECMDERR_E_NOHELP
:
2569 return _T("The caller has asked for help on the command identified by nCmdID, but no help is available.");
2571 case OLECMDERR_E_CANCELED
:
2572 return _T("The user canceled the execution of the command.");
2575 return _T("E_INVALIDARG");
2578 return _T("E_OUTOFMEMORY");
2581 return _T("E_NOINTERFACE");
2584 return _T("E_UNEXPECTED");
2586 case STG_E_INVALIDFLAG
:
2587 return _T("STG_E_INVALIDFLAG");
2590 return _T("E_FAIL");
2593 return _T("E_NOTIMPL");
2598 buf
.Printf(_T("Unknown - 0x%X"), hr
);
2604 // borrowed from src/msw/ole/oleutils.cpp
2605 wxString
GetIIDName(REFIID riid
)
2607 // an association between symbolic name and numeric value of an IID
2611 const wxChar
*szName
;
2614 // construct the table containing all known interfaces
2615 #define ADD_KNOWN_IID(name) { &IID_I##name, _T(#name) }
2616 #define ADD_KNOWN_GUID(name) { &name, _T(#name) }
2618 static const KNOWN_IID aKnownIids
[] =
2620 ADD_KNOWN_IID(ServiceProvider
),
2621 ADD_KNOWN_IID(AdviseSink
),
2622 ADD_KNOWN_IID(AdviseSink2
),
2623 ADD_KNOWN_IID(BindCtx
),
2624 ADD_KNOWN_IID(ClassFactory
),
2625 #if ( !defined( __VISUALC__) || (__VISUALC__!=1010) ) && !defined(__MWERKS__)
2626 ADD_KNOWN_IID(ContinueCallback
),
2627 ADD_KNOWN_IID(EnumOleDocumentViews
),
2628 ADD_KNOWN_IID(OleCommandTarget
),
2629 ADD_KNOWN_IID(OleDocument
),
2630 ADD_KNOWN_IID(OleDocumentSite
),
2631 ADD_KNOWN_IID(OleDocumentView
),
2632 ADD_KNOWN_IID(Print
),
2634 ADD_KNOWN_IID(DataAdviseHolder
),
2635 ADD_KNOWN_IID(DataObject
),
2636 ADD_KNOWN_IID(Debug
),
2637 ADD_KNOWN_IID(DebugStream
),
2638 ADD_KNOWN_IID(DfReserved1
),
2639 ADD_KNOWN_IID(DfReserved2
),
2640 ADD_KNOWN_IID(DfReserved3
),
2641 ADD_KNOWN_IID(Dispatch
),
2642 ADD_KNOWN_IID(DropSource
),
2643 ADD_KNOWN_IID(DropTarget
),
2644 ADD_KNOWN_IID(EnumCallback
),
2645 ADD_KNOWN_IID(EnumFORMATETC
),
2646 ADD_KNOWN_IID(EnumGeneric
),
2647 ADD_KNOWN_IID(EnumHolder
),
2648 ADD_KNOWN_IID(EnumMoniker
),
2649 ADD_KNOWN_IID(EnumOLEVERB
),
2650 ADD_KNOWN_IID(EnumSTATDATA
),
2651 ADD_KNOWN_IID(EnumSTATSTG
),
2652 ADD_KNOWN_IID(EnumString
),
2653 ADD_KNOWN_IID(EnumUnknown
),
2654 ADD_KNOWN_IID(EnumVARIANT
),
2655 ADD_KNOWN_IID(ExternalConnection
),
2656 ADD_KNOWN_IID(InternalMoniker
),
2657 ADD_KNOWN_IID(LockBytes
),
2658 ADD_KNOWN_IID(Malloc
),
2659 ADD_KNOWN_IID(Marshal
),
2660 ADD_KNOWN_IID(MessageFilter
),
2661 ADD_KNOWN_IID(Moniker
),
2662 ADD_KNOWN_IID(OleAdviseHolder
),
2663 ADD_KNOWN_IID(OleCache
),
2664 ADD_KNOWN_IID(OleCache2
),
2665 ADD_KNOWN_IID(OleCacheControl
),
2666 ADD_KNOWN_IID(OleClientSite
),
2667 ADD_KNOWN_IID(OleContainer
),
2668 ADD_KNOWN_IID(OleInPlaceActiveObject
),
2669 ADD_KNOWN_IID(OleInPlaceFrame
),
2670 ADD_KNOWN_IID(OleInPlaceObject
),
2671 ADD_KNOWN_IID(OleInPlaceSite
),
2672 ADD_KNOWN_IID(OleInPlaceUIWindow
),
2673 ADD_KNOWN_IID(OleItemContainer
),
2674 ADD_KNOWN_IID(OleLink
),
2675 ADD_KNOWN_IID(OleManager
),
2676 ADD_KNOWN_IID(OleObject
),
2677 ADD_KNOWN_IID(OlePresObj
),
2678 ADD_KNOWN_IID(OleWindow
),
2679 ADD_KNOWN_IID(PSFactory
),
2680 ADD_KNOWN_IID(ParseDisplayName
),
2681 ADD_KNOWN_IID(Persist
),
2682 ADD_KNOWN_IID(PersistFile
),
2683 ADD_KNOWN_IID(PersistStorage
),
2684 ADD_KNOWN_IID(PersistStream
),
2685 ADD_KNOWN_IID(ProxyManager
),
2686 ADD_KNOWN_IID(RootStorage
),
2687 ADD_KNOWN_IID(RpcChannel
),
2688 ADD_KNOWN_IID(RpcProxy
),
2689 ADD_KNOWN_IID(RpcStub
),
2690 ADD_KNOWN_IID(RunnableObject
),
2691 ADD_KNOWN_IID(RunningObjectTable
),
2692 ADD_KNOWN_IID(StdMarshalInfo
),
2693 ADD_KNOWN_IID(Storage
),
2694 ADD_KNOWN_IID(Stream
),
2695 ADD_KNOWN_IID(StubManager
),
2696 ADD_KNOWN_IID(Unknown
),
2697 ADD_KNOWN_IID(ViewObject
),
2698 ADD_KNOWN_IID(ViewObject2
),
2699 ADD_KNOWN_GUID(IID_IDispatch
),
2700 ADD_KNOWN_GUID(IID_IWebBrowser
),
2701 ADD_KNOWN_GUID(IID_IWebBrowserApp
),
2702 ADD_KNOWN_GUID(IID_IWebBrowser2
),
2703 ADD_KNOWN_GUID(IID_IWebBrowser
),
2704 ADD_KNOWN_GUID(DIID_DWebBrowserEvents2
),
2705 ADD_KNOWN_GUID(DIID_DWebBrowserEvents
),
2708 // don't clobber preprocessor name space
2709 #undef ADD_KNOWN_IID
2710 #undef ADD_KNOWN_GUID
2712 // try to find the interface in the table
2713 for ( size_t ui
= 0; ui
< WXSIZEOF(aKnownIids
); ui
++ )
2715 if ( riid
== *aKnownIids
[ui
].pIid
)
2717 return aKnownIids
[ui
].szName
;
2721 // unknown IID, just transform to string
2722 LPOLESTR str
= NULL
;
2723 StringFromIID(riid
, &str
);
2731 return _T("StringFromIID() error");