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
);
258 m_bestSize
= GetSize();
261 wxActiveX::wxActiveX(wxWindow
* parent
, const wxString
& progId
, wxWindowID id
,
265 const wxString
& name
) :
266 wxWindow(parent
, id
, pos
, size
, style
, name
)
268 m_bAmbientUserMode
= true;
269 m_docAdviseCookie
= 0;
270 CreateActiveX((LPOLESTR
) (const wchar_t *) progId
.wc_str(wxConvUTF8
));
271 m_bestSize
= GetSize();
274 wxActiveX::~wxActiveX()
276 // disconnect connection points
277 wxOleConnectionArray::iterator it
= m_connections
.begin();
278 while (it
!= m_connections
.end())
280 wxOleConnectionPoint
& cp
= it
->first
;
281 cp
->Unadvise(it
->second
);
285 m_connections
.clear();
287 if (m_oleInPlaceObject
.Ok())
289 m_oleInPlaceObject
->InPlaceDeactivate();
290 m_oleInPlaceObject
->UIDeactivate();
294 if (m_oleObject
.Ok())
296 if (m_docAdviseCookie
!= 0)
297 m_oleObject
->Unadvise(m_docAdviseCookie
);
299 m_oleObject
->DoVerb(OLEIVERB_HIDE
, NULL
, m_clientSite
, 0, (HWND
) GetHWND(), NULL
);
300 m_oleObject
->Close(OLECLOSE_NOSAVE
);
301 m_oleObject
->SetClientSite(NULL
);
305 void wxActiveX::CreateActiveX(REFCLSID clsid
)
311 ////////////////////////////////////////////////////////
313 FrameSite
*frame
= new FrameSite(this);
315 hret
= m_clientSite
.QueryInterface(IID_IOleClientSite
, (IDispatch
*) frame
);
316 wxCHECK_RET(SUCCEEDED(hret
), _T("m_clientSite.QueryInterface failed"));
318 wxAutoOleInterface
<IAdviseSink
> adviseSink(IID_IAdviseSink
, (IDispatch
*) frame
);
319 wxCHECK_RET(adviseSink
.Ok(), _T("adviseSink not Ok"));
322 // // Create Object, get IUnknown interface
323 m_ActiveX
.CreateInstance(clsid
, IID_IUnknown
);
324 wxCHECK_RET(m_ActiveX
.Ok(), _T("m_ActiveX.CreateInstance failed"));
326 // Get Dispatch interface
327 hret
= m_Dispatch
.QueryInterface(IID_IDispatch
, m_ActiveX
);
328 WXOLE_WARN(hret
, "Unable to get dispatch interface");
333 // Get IOleObject interface
334 hret
= m_oleObject
.QueryInterface(IID_IOleObject
, m_ActiveX
);
335 wxCHECK_RET(SUCCEEDED(hret
), _("Unable to get IOleObject interface"));
337 // get IViewObject Interface
338 hret
= m_viewObject
.QueryInterface(IID_IViewObject
, m_ActiveX
);
339 wxCHECK_RET(SUCCEEDED(hret
), _T("Unable to get IViewObject Interface"));
342 m_docAdviseCookie
= 0;
343 hret
= m_oleObject
->Advise(adviseSink
, &m_docAdviseCookie
);
344 WXOLE_WARN(hret
, "m_oleObject->Advise(adviseSink, &m_docAdviseCookie),\"Advise\")");
345 m_oleObject
->SetHostNames(L
"wxActiveXContainer", NULL
);
346 OleSetContainedObject(m_oleObject
, TRUE
);
350 // Get IOleInPlaceObject interface
351 hret
= m_oleInPlaceObject
.QueryInterface(IID_IOleInPlaceObject
, m_ActiveX
);
352 wxCHECK_RET(SUCCEEDED(hret
), _T("Unable to get IOleInPlaceObject interface"));
356 m_oleObject
->GetMiscStatus(DVASPECT_CONTENT
, &dwMiscStatus
);
357 wxCHECK_RET(SUCCEEDED(hret
), _T("Unable to get oleObject status"));
359 // set client site first ?
360 if (dwMiscStatus
& OLEMISC_SETCLIENTSITEFIRST
)
361 m_oleObject
->SetClientSite(m_clientSite
);
365 wxAutoOleInterface
<IPersistStreamInit
>
366 pPersistStreamInit(IID_IPersistStreamInit
, m_oleObject
);
368 if (pPersistStreamInit
.Ok())
370 hret
= pPersistStreamInit
->InitNew();
371 WXOLE_WARN(hret
, "CreateActiveX::pPersistStreamInit->InitNew()");
374 if (! (dwMiscStatus
& OLEMISC_SETCLIENTSITEFIRST
))
375 m_oleObject
->SetClientSite(m_clientSite
);
379 GetClientSize(&w
, &h
);
388 if (m_oleInPlaceObject
.Ok())
390 hret
= m_oleInPlaceObject
->GetWindow(&m_oleObjectHWND
);
391 WXOLE_WARN(hret
, "m_oleInPlaceObject->GetWindow(&m_oleObjectHWND)");
393 ::SetActiveWindow(m_oleObjectHWND
);
397 if (! (dwMiscStatus
& OLEMISC_INVISIBLEATRUNTIME
))
399 if (w
> 0 && h
> 0 && m_oleInPlaceObject
.Ok())
400 m_oleInPlaceObject
->SetObjectRects(&posRect
, &posRect
);
402 hret
= m_oleObject
->DoVerb(OLEIVERB_INPLACEACTIVATE
, NULL
, m_clientSite
, 0, (HWND
)GetHWND(), &posRect
);
403 hret
= m_oleObject
->DoVerb(OLEIVERB_SHOW
, 0, m_clientSite
, 0, (HWND
)GetHWND(), &posRect
);
406 if (! m_oleObjectHWND
&& m_oleInPlaceObject
.Ok())
408 hret
= m_oleInPlaceObject
->GetWindow(&m_oleObjectHWND
);
409 WXOLE_WARN(hret
, "m_oleInPlaceObject->GetWindow(&m_oleObjectHWND)");
414 ::SetActiveWindow(m_oleObjectHWND
);
415 ::ShowWindow(m_oleObjectHWND
, SW_SHOW
);
417 // Update by GBR to resize older controls
419 szEvent
.m_size
= wxSize(w
, h
) ;
420 AddPendingEvent(szEvent
);
424 void wxActiveX::CreateActiveX(LPOLESTR progId
)
427 if (CLSIDFromProgID(progId
, &clsid
) != S_OK
)
430 CreateActiveX(clsid
);
433 ////////////////////////////////////////////////////////////////////////////////////////////////////////////
434 // Case Insensitive Map of Event names to eventTypes
435 // created dynamically at run time in:
436 // EVT_ACTIVEX(eventName, id, fn)
437 // we map the pointer to them so that:
438 // const wxEventType& RegisterActiveXEvent(wxString eventName);
439 // can return a const reference, which is neccessary for event tables
440 // probably should use a wxWindows hash table here, but I'm lazy ...
441 typedef map
<wxString
, wxEventType
*, NS_wxActiveX::less_wxStringI
> ActiveXNamedEventMap
;
442 static ActiveXNamedEventMap sg_NamedEventMap
;
444 const wxEventType
& RegisterActiveXEvent(const wxChar
*eventName
)
446 wxString ev
= eventName
;
447 ActiveXNamedEventMap::iterator it
= sg_NamedEventMap
.find(ev
);
448 if (it
== sg_NamedEventMap
.end())
450 wxEventType
*et
= new wxEventType(wxNewEventType());
451 sg_NamedEventMap
[ev
] = et
;
456 return *(it
->second
);
460 ////////////////////////////////////////////////////////////////////////////////////////////////////////////
461 // Map of Event DISPID's to eventTypes
462 // created dynamically at run time in:
463 // EVT_ACTIVEX(eventName, id, fn)
464 // we map the pointer to them so that:
465 // const wxEventType& RegisterActiveXEvent(wxString eventName);
466 // can return a const reference, which is neccessary for event tables
468 typedef map
<DISPID
, wxEventType
*> ActiveXDISPIDEventMap
;
469 static ActiveXDISPIDEventMap sg_dispIdEventMap
;
471 const wxEventType
& RegisterActiveXEvent(DISPID event
)
473 ActiveXDISPIDEventMap::iterator it
= sg_dispIdEventMap
.find(event
);
474 if (it
== sg_dispIdEventMap
.end())
476 wxEventType
*et
= new wxEventType(wxNewEventType());
477 sg_dispIdEventMap
[event
] = et
;
482 return *(it
->second
);
485 // one off class for automatic freeing of activeX eventtypes
486 class ActiveXEventMapFlusher
489 ~ActiveXEventMapFlusher()
492 ActiveXNamedEventMap::iterator it
= sg_NamedEventMap
.end();
493 while (it
!= sg_NamedEventMap
.end())
498 sg_NamedEventMap
.clear();
501 ActiveXDISPIDEventMap::iterator dit
= sg_dispIdEventMap
.end();
502 while (dit
!= sg_dispIdEventMap
.end())
507 sg_dispIdEventMap
.clear();
511 static ActiveXEventMapFlusher s_dummyActiveXEventMapFlusher
;
514 //////////////////////////////////////////////////////
515 VARTYPE
wxTypeToVType(const wxVariant
& v
)
517 wxString type
= v
.GetType();
518 if (type
== wxT("bool"))
520 else if (type
== wxT("char"))
522 else if (type
== wxT("datetime"))
524 else if (type
== wxT("double"))
526 else if (type
== wxT("list"))
528 else if (type
== wxT("long"))
530 else if (type
== wxT("string"))
532 else if (type
== wxT("stringlist"))
534 else if (type
== wxT("date"))
536 else if (type
== wxT("time"))
538 else if (type
== wxT("void*"))
539 return VT_VOID
| VT_BYREF
;
544 bool wxDateTimeToDATE(wxDateTime dt
, DATE
& d
)
547 memset(&st
, 0, sizeof(st
));
549 st
.wYear
= dt
.GetYear();
550 st
.wMonth
= dt
.GetMonth() + 1;
551 st
.wDay
= dt
.GetDay();
552 st
.wHour
= dt
.GetHour();
553 st
.wMinute
= dt
.GetMinute();
554 st
.wSecond
= dt
.GetSecond();
555 st
.wMilliseconds
= dt
.GetMillisecond();
556 return SystemTimeToVariantTime(&st
, &d
) != FALSE
;
559 bool wxDateTimeToVariant(wxDateTime dt
, VARIANTARG
& va
)
561 return wxDateTimeToDATE(dt
, va
.date
);
564 bool DATEToWxDateTime(DATE date
, wxDateTime
& dt
)
567 if (! VariantTimeToSystemTime(date
, &st
))
572 wxDateTime::Month(int(wxDateTime::Jan
) + st
.wMonth
- 1),
574 st
.wHour
, st
.wMinute
, st
.wSecond
, st
.wMilliseconds
);
579 bool VariantToWxDateTime(VARIANTARG va
, wxDateTime
& dt
)
581 HRESULT hr
= VariantChangeType(&va
, &va
, 0, VT_DATE
);
585 return DATEToWxDateTime(va
.date
, dt
);
588 bool MSWVariantToVariant(VARIANTARG
& va
, wxVariant
& vx
)
594 return false; // don't support arrays yet
607 return MSWVariantToVariant(*va
.pvarVal
, vx
);
611 VariantChangeType(&tmp
, &tmp
, 0, wxTypeToVType(vx
));
612 bool rc
= MSWVariantToVariant(tmp
, vx
);
621 vx
= (char) *va
.pbVal
;
630 vx
= (long) *va
.puiVal
;
632 vx
= (long) va
.uiVal
;
642 vx
= (long) *va
.pulVal
;
644 vx
= (long) va
.ulVal
;
666 vx
= (*va
.pboolVal
? true : false);
668 vx
= (va
.boolVal
? true : false);
673 return false; // what the hell is a CY ?
680 hr
= VarR8FromDec(va
.pdecVal
, &d
);
682 hr
= VarR8FromDec(&va
.decVal
, &d
);
685 return SUCCEEDED(hr
);
693 rc
= DATEToWxDateTime(*va
.pdate
, dt
);
695 rc
= VariantToWxDateTime(va
, dt
);
702 vx
= wxString(*va
.pbstrVal
);
704 vx
= wxString(va
.bstrVal
);
707 case VT_UNKNOWN
: // should do a custom wxVariantData for this
709 vx
= (void *) *va
.ppunkVal
;
711 vx
= (void *) va
.punkVal
;
714 case VT_DISPATCH
: // should do a custom wxVariantData for this
716 vx
= (void *) *va
.ppdispVal
;
718 vx
= (void *) va
.pdispVal
;
727 bool VariantToMSWVariant(const wxVariant
& vx
, VARIANTARG
& va
)
733 return false; // don't support arrays yet
745 return VariantToMSWVariant(vx
, *va
.pvarVal
);
748 va
.vt
= wxTypeToVType(vx
);
749 return VariantToMSWVariant(vx
, va
);
756 *va
.pbVal
= (char) vx
;
765 *va
.puiVal
= (long) vx
;
767 va
.uiVal
= (long) vx
;
777 *va
.pulVal
= (long) vx
;
779 va
.ulVal
= (long) vx
;
786 *va
.pfltVal
= (double) vx
;
788 va
.fltVal
= (double) vx
;
794 *va
.pdblVal
= (double) vx
;
796 va
.dblVal
= (double) vx
;
801 *va
.pboolVal
= ((bool) vx
) ? TRUE
: FALSE
;
803 va
.boolVal
= ((bool) vx
) ? TRUE
: FALSE
;
807 return false; // what the hell is a CY ?
811 return SUCCEEDED(VarDecFromR8(vx
, va
.pdecVal
));
813 return SUCCEEDED(VarDecFromR8(vx
, &va
.decVal
));
817 return wxDateTimeToDATE(vx
, *va
.pdate
);
819 return wxDateTimeToVariant(vx
,va
);
823 *va
.pbstrVal
= SysAllocString(vx
.GetString().wc_str(wxConvUTF8
));
825 va
.bstrVal
= SysAllocString(vx
.GetString().wc_str(wxConvUTF8
));
828 case VT_UNKNOWN
: // should do a custom wxVariantData for this
830 *va
.ppunkVal
= (IUnknown
*) (void *) vx
;
832 va
.punkVal
= (IUnknown
*) (void *) vx
;
835 case VT_DISPATCH
: // should do a custom wxVariantData for this
837 *va
.ppdispVal
= (IDispatch
*) (void *) vx
;
839 va
.pdispVal
= (IDispatch
*) (void *) vx
;
847 IMPLEMENT_CLASS(wxActiveXEvent
, wxCommandEvent
)
849 class wxActiveXEvents
: public IDispatch
852 DECLARE_OLE_UNKNOWN(wxActiveXEvents
);
855 wxActiveX
*m_activeX
;
859 friend bool wxActiveXEventsInterface(wxActiveXEvents
*self
, REFIID iid
, void **_interface
, const char *&desc
);
862 wxActiveXEvents(wxActiveX
*ax
) : m_activeX(ax
), m_haveCustomId(false) {}
863 wxActiveXEvents(wxActiveX
*ax
, REFIID iid
) : m_activeX(ax
), m_haveCustomId(true), m_customId(iid
) {}
864 virtual ~wxActiveXEvents()
869 STDMETHODIMP
GetIDsOfNames(REFIID r
, OLECHAR
** o
, unsigned int i
, LCID l
, DISPID
* d
)
874 STDMETHODIMP
GetTypeInfo(unsigned int i
, LCID l
, ITypeInfo
** t
)
879 STDMETHODIMP
GetTypeInfoCount(unsigned int* i
)
885 void DispatchEvent(wxActiveX::FuncX
&func
, const wxEventType
& eventType
, DISPPARAMS
* pDispParams
)
887 wxActiveXEvent event
;
888 event
.SetId(m_activeX
->GetId());
889 event
.SetEventType(eventType
);
890 event
.m_params
.NullList();
891 event
.m_params
.SetName(func
.name
);
897 // sometimes the pDispParams does not match the param info for a activex control
898 int nArg
= min(func
.params
.size(), pDispParams
->cArgs
);
899 for (int i
= nArg
- 1; i
>= 0; i
--)
901 VARIANTARG
& va
= pDispParams
->rgvarg
[i
];
902 wxActiveX::ParamX
&px
= func
.params
[nArg
- i
- 1];
906 MSWVariantToVariant(va
, vx
);
907 event
.m_params
.Append(vx
);
913 int nArg
= min(func
.params
.size(), pDispParams
->cArgs
);
914 m_activeX
->GetParent()->ProcessEvent(event
);
915 for (int i
= 0; i
< nArg
; i
++)
917 VARIANTARG
& va
= pDispParams
->rgvarg
[i
];
918 wxActiveX::ParamX
&px
= func
.params
[nArg
- i
- 1];
922 wxVariant
& vx
= event
.m_params
[nArg
- i
- 1];
924 VariantToMSWVariant(vx
, va
);
929 m_activeX
->GetParent()->AddPendingEvent(event
);
933 STDMETHODIMP
Invoke(DISPID dispIdMember
, REFIID riid
, LCID lcid
,
934 WORD wFlags
, DISPPARAMS
* pDispParams
,
935 VARIANT
* pVarResult
, EXCEPINFO
* pExcepInfo
,
936 unsigned int * puArgErr
)
938 if (wFlags
& (DISPATCH_PROPERTYGET
| DISPATCH_PROPERTYPUT
| DISPATCH_PROPERTYPUTREF
))
943 // find event for dispid
944 wxActiveX::MemberIdMap::iterator mit
= m_activeX
->m_eventMemberIds
.find((MEMBERID
) dispIdMember
);
945 if (mit
== m_activeX
->m_eventMemberIds
.end())
949 int midx
= mit
->second
;
950 if (midx
< 0 || midx
>= m_activeX
->GetEventCount())
953 wxActiveX::FuncX
&func
= m_activeX
->m_events
[midx
];
956 // try to find dispid event
957 ActiveXDISPIDEventMap::iterator dit
= sg_dispIdEventMap
.find(dispIdMember
);
958 if (dit
!= sg_dispIdEventMap
.end())
961 DispatchEvent(func
, *(dit
->second
), pDispParams
);
966 ActiveXNamedEventMap::iterator nit
= sg_NamedEventMap
.find(func
.name
);
967 if (nit
== sg_NamedEventMap
.end())
971 DispatchEvent(func
, *(nit
->second
), pDispParams
);
976 bool wxActiveXEventsInterface(wxActiveXEvents
*self
, REFIID iid
, void **_interface
, const char *&desc
)
978 if (self
->m_haveCustomId
&& IsEqualIID(iid
, self
->m_customId
))
980 WXOLE_TRACE("Found Custom Dispatch Interface");
981 *_interface
= (IUnknown
*) (IDispatch
*) self
;
982 desc
= "Custom Dispatch Interface";
989 DEFINE_OLE_TABLE(wxActiveXEvents
)
990 OLE_IINTERFACE(IUnknown
)
991 OLE_INTERFACE(IID_IDispatch
, IDispatch
)
992 OLE_INTERFACE_CUSTOM(wxActiveXEventsInterface
)
995 wxString
wxActiveXEvent::EventName()
997 return m_params
.GetName();
1000 int wxActiveXEvent::ParamCount() const
1002 return m_params
.GetCount();
1005 wxString
wxActiveXEvent::ParamType(int idx
)
1007 wxASSERT(idx
>= 0 && idx
< m_params
.GetCount());
1009 return m_params
[idx
].GetType();
1012 wxString
wxActiveXEvent::ParamName(int idx
)
1014 wxASSERT(idx
>= 0 && idx
< m_params
.GetCount());
1016 return m_params
[idx
].GetName();
1019 static wxVariant nullVar
;
1021 wxVariant
& wxActiveXEvent::operator[] (int idx
)
1023 wxASSERT(idx
>= 0 && idx
< ParamCount());
1025 return m_params
[idx
];
1028 wxVariant
& wxActiveXEvent::operator[] (wxString name
)
1030 for (int i
= 0; i
< m_params
.GetCount(); i
++)
1032 if (name
.CmpNoCase(m_params
[i
].GetName()) == 0)
1036 wxString err
= _T("wxActiveXEvent::operator[] invalid name <") + name
+ _T(">");
1037 err
+= _T("\r\nValid Names = :\r\n");
1038 for (i
= 0; i
< m_params
.GetCount(); i
++)
1040 err
+= m_params
[i
].GetName();
1044 wxASSERT_MSG(false, err
);
1049 void wxActiveX::GetTypeInfo()
1052 We are currently only interested in the IDispatch interface
1053 to the control. For dual interfaces (TypeKind = TKIND_INTERFACE)
1054 we should drill down through the inheritance
1055 (using TYPEATTR->cImplTypes) and GetRefTypeOfImplType(n)
1056 and retrieve all the func names etc that way, then generate a C++
1059 But we don't do this and probably never will, so if we have a DUAL
1060 interface then we query for the IDispatch
1061 via GetRefTypeOfImplType(-1).
1066 // get type info via class info
1067 wxAutoOleInterface
<IProvideClassInfo
> classInfo(IID_IProvideClassInfo
, m_ActiveX
);
1068 if (! classInfo
.Ok())
1072 wxAutoOleInterface
<ITypeInfo
> typeInfo
;
1073 hret
= classInfo
->GetClassInfo(typeInfo
.GetRef());
1074 if (! typeInfo
.Ok())
1078 TYPEATTR
*ta
= NULL
;
1079 hret
= typeInfo
->GetTypeAttr(&ta
);
1083 // this should be a TKIND_COCLASS
1084 wxASSERT(ta
->typekind
== TKIND_COCLASS
);
1086 // iterate contained interfaces
1087 for (int i
= 0; i
< ta
->cImplTypes
; i
++)
1091 // get dispatch type info handle
1092 hret
= typeInfo
->GetRefTypeOfImplType(i
, &rt
);
1093 if (! SUCCEEDED(hret
))
1096 // get dispatch type info interface
1097 wxAutoOleInterface
<ITypeInfo
> ti
;
1098 hret
= typeInfo
->GetRefTypeInfo(rt
, ti
.GetRef());
1102 // check if default event sink
1103 bool defInterface
= false;
1104 bool defEventSink
= false;
1105 int impTypeFlags
= 0;
1106 typeInfo
->GetImplTypeFlags(i
, &impTypeFlags
);
1108 if (impTypeFlags
& IMPLTYPEFLAG_FDEFAULT
)
1110 if (impTypeFlags
& IMPLTYPEFLAG_FSOURCE
)
1112 WXOLE_TRACEOUT("Default Event Sink");
1113 defEventSink
= true;
1114 if (impTypeFlags
& IMPLTYPEFLAG_FDEFAULTVTABLE
)
1116 WXOLE_TRACEOUT("*ERROR* - Default Event Sink is via vTable");
1117 defEventSink
= false;
1122 WXOLE_TRACEOUT("Default Interface");
1123 defInterface
= true;
1129 GetTypeInfo(ti
, defInterface
, defEventSink
);
1134 typeInfo
->ReleaseTypeAttr(ta
);
1137 void ElemDescToParam(const ELEMDESC
& ed
, wxActiveX::ParamX
& param
)
1139 param
.flags
= ed
.idldesc
.wIDLFlags
;
1140 param
.vt
= ed
.tdesc
.vt
;
1141 param
.isPtr
= (param
.vt
== VT_PTR
);
1142 param
.isSafeArray
= (param
.vt
== VT_SAFEARRAY
);
1143 if (param
.isPtr
|| param
.isSafeArray
)
1144 param
.vt
= ed
.tdesc
.lptdesc
->vt
;
1147 void wxActiveX::GetTypeInfo(ITypeInfo
*ti
, bool defInterface
, bool defEventSink
)
1149 // wxAutoOleInterface<> assumes a ref has already been added
1151 wxAutoOleInterface
<ITypeInfo
> typeInfo(ti
);
1154 TYPEATTR
*ta
= NULL
;
1155 HRESULT hret
= typeInfo
->GetTypeAttr(&ta
);
1159 if (ta
->typekind
== TKIND_DISPATCH
)
1161 WXOLE_TRACEOUT("GUID = " << GetIIDName(ta
->guid
).c_str());
1165 wxActiveXEvents
*disp
= new wxActiveXEvents(this, ta
->guid
);
1166 ConnectAdvise(ta
->guid
, disp
);
1170 // Get Function Names
1171 for (int i
= 0; i
< ta
->cFuncs
; i
++)
1173 FUNCDESC FAR
*fd
= NULL
;
1175 hret
= typeInfo
->GetFuncDesc(i
, &fd
);
1179 BSTR anames
[1] = {NULL
};
1182 hret
= typeInfo
->GetNames(fd
->memid
, anames
, 1, &n
);
1186 wxString name
= anames
[0];
1188 WXOLE_TRACEOUT("Name " << i
<< " = " << name
.c_str());
1189 SysFreeString(anames
[0]);
1191 if (defInterface
|| defEventSink
)
1195 func
.memid
= fd
->memid
;
1196 func
.hasOut
= false;
1199 unsigned int maxPNames
= fd
->cParams
+ 1;
1200 unsigned int nPNames
= 0;
1201 BSTR
*pnames
= new BSTR
[maxPNames
];
1203 hret
= typeInfo
->GetNames(fd
->memid
, pnames
, maxPNames
, &nPNames
);
1206 if (fd
->cParams
< int(nPNames
))
1209 SysFreeString(pnames
[0]);
1213 ElemDescToParam(fd
->elemdescFunc
, func
.retType
);
1214 for (int p
= 0; p
< fd
->cParams
; p
++)
1218 ElemDescToParam(fd
->lprgelemdescParam
[p
], param
);
1220 param
.name
= pnames
[pbase
+ p
];
1221 SysFreeString(pnames
[pbase
+ p
]);
1223 param
.isOptional
= (p
> fd
->cParams
- fd
->cParamsOpt
);
1225 func
.hasOut
|= (param
.IsOut() || param
.isPtr
);
1226 func
.params
.push_back(param
);
1232 m_events
.push_back(func
);
1233 m_eventMemberIds
[fd
->memid
] = m_events
.size() - 1;
1237 if (fd
->invkind
== INVOKE_FUNC
)
1239 m_methods
.push_back(func
);
1240 m_methodNames
[func
.name
] = m_methods
.size() - 1;
1244 NameMap::iterator it
= m_propNames
.find(func
.name
);
1246 if (it
== m_propNames
.end())
1248 m_props
.push_back(PropX());
1249 idx
= m_props
.size() - 1;
1250 m_propNames
[func
.name
] = idx
;
1251 m_props
[idx
].name
= func
.name
;
1252 m_props
[idx
].memid
= func
.memid
;
1258 if (fd
->invkind
== INVOKE_PROPERTYGET
)
1259 m_props
[idx
].type
= func
.retType
;
1260 else if (func
.params
.size() > 0)
1262 m_props
[idx
].arg
= func
.params
[0];
1263 m_props
[idx
].putByRef
= (fd
->invkind
== INVOKE_PROPERTYPUTREF
);
1270 typeInfo
->ReleaseFuncDesc(fd
);
1274 typeInfo
->ReleaseTypeAttr(ta
);
1277 ///////////////////////////////////////////////
1278 // Type Info exposure
1279 const wxActiveX::FuncX
& wxActiveX::GetEventDesc(int idx
) const
1281 wxASSERT(idx
>= 0 && idx
< GetEventCount());
1283 return m_events
[idx
];
1286 const wxActiveX::PropX
& wxActiveX::GetPropDesc(int idx
) const
1288 if (idx
< 0 || idx
>= GetPropCount())
1289 throw exception("Property index out of bounds");
1291 return m_props
[idx
];
1294 const wxActiveX::PropX
& wxActiveX::GetPropDesc(const wxString
& name
) const
1296 NameMap::const_iterator it
= m_propNames
.find(name
);
1297 if (it
== m_propNames
.end())
1300 s
<< _T("property <") << name
<< _T("> not found");
1301 throw exception(s
.mb_str());
1304 return GetPropDesc(it
->second
);
1307 const wxActiveX::FuncX
& wxActiveX::GetMethodDesc(int idx
) const
1309 if (idx
< 0 || idx
>= GetMethodCount())
1310 throw exception("Method index out of bounds");
1313 return m_methods
[idx
];
1317 const wxActiveX::FuncX
& wxActiveX::GetMethodDesc(const wxString
& name
) const
1319 NameMap::const_iterator it
= m_methodNames
.find(name
);
1320 if (it
== m_methodNames
.end())
1323 s
<< _T("method <") << name
<< _T("> not found");
1324 throw exception(s
.mb_str());
1327 return GetMethodDesc(it
->second
);
1331 void wxActiveX::SetProp(MEMBERID name
, VARIANTARG
& value
)
1333 DISPID pids
[1] = {DISPID_PROPERTYPUT
};
1334 DISPPARAMS params
= {&value
, pids
, 1, 1};
1337 memset(&x
, 0, sizeof(x
));
1338 unsigned int argErr
= 0;
1340 HRESULT hr
= m_Dispatch
->Invoke(
1342 IID_NULL
, LOCALE_USER_DEFAULT
, DISPATCH_PROPERTYPUT
,
1343 ¶ms
, NULL
, &x
, &argErr
);
1345 WXOLE_WARN(hr
, "Invoke Prop(...)");
1348 void wxActiveX::SetProp(const wxString
&name
, const wxVariant
&value
)
1350 const PropX
& prop
= GetPropDesc(name
);
1351 if (! prop
.CanSet())
1354 s
<< _T("property <") << name
<< _T("> is readonly");
1355 throw exception(s
.mb_str());
1358 VARIANT v
= {prop
.arg
.vt
};
1359 VariantToMSWVariant(value
, v
);
1360 SetProp(prop
.memid
, v
);
1361 VariantClear(&v
); // this releases any BSTR's etc
1364 VARIANT
wxActiveX::GetPropAsVariant(MEMBERID name
)
1369 DISPPARAMS params
= {NULL
, NULL
, 0, 0};
1372 memset(&x
, 0, sizeof(x
));
1373 unsigned int argErr
= 0;
1375 HRESULT hr
= m_Dispatch
->Invoke(
1377 IID_NULL
, LOCALE_USER_DEFAULT
, DISPATCH_PROPERTYGET
,
1378 ¶ms
, &v
, &x
, &argErr
);
1380 WXOLE_WARN(hr
, "Invoke Prop(...)");
1385 VARIANT
wxActiveX::GetPropAsVariant(const wxString
& name
)
1387 const PropX
& prop
= GetPropDesc(name
);
1388 if (! prop
.CanGet())
1391 s
<< _T("property <") << name
<< _T("> is writeonly");
1392 throw exception(s
.mb_str());
1395 return GetPropAsVariant(prop
.memid
);
1398 wxVariant
wxActiveX::GetPropAsWxVariant(const wxString
& name
)
1400 VARIANT v
= GetPropAsVariant(name
);
1401 HRESULT hr
= VariantChangeType(&v
, &v
, 0, VT_BSTR
);
1402 if (! SUCCEEDED(hr
))
1403 throw exception("Unable to convert variant");
1406 MSWVariantToVariant(v
, wv
);
1413 wxString
wxActiveX::GetPropAsString(const wxString
& name
)
1415 VARIANT v
= GetPropAsVariant(name
);
1416 HRESULT hr
= VariantChangeType(&v
, &v
, 0, VT_BSTR
);
1417 if (! SUCCEEDED(hr
))
1418 throw exception("Unable to convert variant");
1420 wxString s
= v
.bstrVal
;
1426 char wxActiveX::GetPropAsChar(const wxString
& name
)
1428 VARIANT v
= GetPropAsVariant(name
);
1429 HRESULT hr
= VariantChangeType(&v
, &v
, 0, VT_I1
);
1430 if (! SUCCEEDED(hr
))
1431 throw exception("Unable to convert variant");
1436 long wxActiveX::GetPropAsLong(const wxString
& name
)
1438 VARIANT v
= GetPropAsVariant(name
);
1439 HRESULT hr
= VariantChangeType(&v
, &v
, 0, VT_I4
);
1440 if (! SUCCEEDED(hr
))
1441 throw exception("Unable to convert variant");
1446 bool wxActiveX::GetPropAsBool(const wxString
& name
)
1448 VARIANT v
= GetPropAsVariant(name
);
1449 HRESULT hr
= VariantChangeType(&v
, &v
, 0, VT_BOOL
);
1450 if (! SUCCEEDED(hr
))
1451 throw exception("Unable to convert variant");
1453 return v
.boolVal
!= 0;
1456 double wxActiveX::GetPropAsDouble(const wxString
& name
)
1458 VARIANT v
= GetPropAsVariant(name
);
1459 HRESULT hr
= VariantChangeType(&v
, &v
, 0, VT_R8
);
1460 if (! SUCCEEDED(hr
))
1461 throw exception("Unable to convert variant");
1466 wxDateTime
wxActiveX::GetPropAsDateTime(const wxString
& name
)
1469 VARIANT v
= GetPropAsVariant(name
);
1471 if (! VariantToWxDateTime(v
, dt
))
1472 throw exception("Unable to convert variant to wxDateTime");
1477 void *wxActiveX::GetPropAsPointer(const wxString
& name
)
1479 VARIANT v
= GetPropAsVariant(name
);
1480 HRESULT hr
= VariantChangeType(&v
, &v
, 0, VT_BYREF
);
1481 if (! SUCCEEDED(hr
))
1482 throw exception("Unable to convert variant");
1490 VARIANT
wxActiveX::CallMethod(MEMBERID name
, VARIANTARG args
[], int argc
)
1492 DISPPARAMS pargs
= {args
, NULL
, argc
, 0};
1494 VariantInit(&retVal
);
1497 memset(&x
, 0, sizeof(x
));
1498 unsigned int argErr
= 0;
1500 HRESULT hr
= m_Dispatch
->Invoke(
1502 IID_NULL
, LOCALE_USER_DEFAULT
, DISPATCH_METHOD
,
1503 &pargs
, &retVal
, &x
, &argErr
);
1505 WXOLE_WARN(hr
, "Invoke Method(...)");
1509 VARIANT
wxActiveX::CallMethod(const wxString
& name
, VARIANTARG args
[], int argc
)
1511 const FuncX
& func
= GetMethodDesc(name
);
1513 argc
= func
.params
.size();
1515 return CallMethod(func
.memid
, args
, argc
);
1519 wxVariant
wxActiveX::CallMethod(const wxString
& name
, wxVariant args
[], int nargs
)
1521 const FuncX
& func
= GetMethodDesc(name
);
1526 VARIANTARG
*vargs
= NULL
;
1528 nargs
= func
.params
.size();
1531 vargs
= new VARIANTARG
[nargs
];
1535 // init type of vargs
1536 for (int i
= 0; i
< nargs
; i
++)
1537 vargs
[nargs
- i
- 1].vt
= func
.params
[i
].vt
;
1540 for (i
= 0; i
< nargs
; i
++)
1541 VariantToMSWVariant(args
[i
], vargs
[nargs
- i
- 1]);
1544 VARIANT rv
= CallMethod(func
.memid
, vargs
, nargs
);
1546 // process any by ref params
1549 for (int i
= 0; i
< nargs
; i
++)
1551 VARIANTARG
& va
= vargs
[nargs
- i
- 1];
1552 const wxActiveX::ParamX
&px
= func
.params
[i
];
1556 wxVariant
& vx
= args
[i
];
1558 MSWVariantToVariant(va
, vx
);
1565 for (int i
= 0; i
< nargs
; i
++)
1566 VariantClear(&vargs
[i
]);
1572 MSWVariantToVariant(rv
, ret
);
1579 ///////////////////////////////////////////////
1581 HRESULT
wxActiveX::ConnectAdvise(REFIID riid
, IUnknown
*events
)
1583 wxOleConnectionPoint cp
;
1584 DWORD adviseCookie
= 0;
1586 wxAutoOleInterface
<IConnectionPointContainer
> cpContainer(IID_IConnectionPointContainer
, m_ActiveX
);
1587 if (! cpContainer
.Ok())
1590 HRESULT hret
= cpContainer
->FindConnectionPoint(riid
, cp
.GetRef());
1591 if (! SUCCEEDED(hret
))
1594 hret
= cp
->Advise(events
, &adviseCookie
);
1596 if (SUCCEEDED(hret
))
1597 m_connections
.push_back(wxOleConnection(cp
, adviseCookie
));
1600 WXOLE_WARN(hret
, "ConnectAdvise");
1606 HRESULT
wxActiveX::AmbientPropertyChanged(DISPID dispid
)
1608 wxAutoOleInterface
<IOleControl
> oleControl(IID_IOleControl
, m_oleObject
);
1610 if (oleControl
.Ok())
1611 return oleControl
->OnAmbientPropertyChange(dispid
);
1616 #define HIMETRIC_PER_INCH 2540
1617 #define MAP_PIX_TO_LOGHIM(x,ppli) MulDiv(HIMETRIC_PER_INCH, (x), (ppli))
1619 static void PixelsToHimetric(SIZEL
&sz
)
1621 static int logX
= 0;
1622 static int logY
= 0;
1627 HDC dc
= GetDC(NULL
);
1628 logX
= GetDeviceCaps(dc
, LOGPIXELSX
);
1629 logY
= GetDeviceCaps(dc
, LOGPIXELSY
);
1630 ReleaseDC(NULL
, dc
);
1633 #define HIMETRIC_INCH 2540
1634 #define CONVERT(x, logpixels) MulDiv(HIMETRIC_INCH, (x), (logpixels))
1636 sz
.cx
= CONVERT(sz
.cx
, logX
);
1637 sz
.cy
= CONVERT(sz
.cy
, logY
);
1640 #undef HIMETRIC_INCH
1644 void wxActiveX::OnSize(wxSizeEvent
& event
)
1647 GetClientSize(&w
, &h
);
1655 if (w
<= 0 && h
<= 0)
1658 // extents are in HIMETRIC units
1659 if (m_oleObject
.Ok())
1662 PixelsToHimetric(sz
);
1666 m_oleObject
->GetExtent(DVASPECT_CONTENT
, &sz2
);
1667 if (sz2
.cx
!= sz
.cx
|| sz
.cy
!= sz2
.cy
)
1668 m_oleObject
->SetExtent(DVASPECT_CONTENT
, &sz
);
1671 if (m_oleInPlaceObject
.Ok())
1672 m_oleInPlaceObject
->SetObjectRects(&posRect
, &posRect
);
1675 void wxActiveX::OnPaint(wxPaintEvent
& event
)
1677 wxLogTrace(wxT(""),wxT("repainting activex win"));
1688 // Draw only when control is windowless or deactivated
1691 ::RedrawWindow(m_oleObjectHWND
, NULL
, NULL
, RDW_INTERNALPAINT
);
1693 RECTL
*prcBounds
= (RECTL
*) &posRect
;
1694 m_viewObject
->Draw(DVASPECT_CONTENT
, -1, NULL
, NULL
, NULL
,
1695 (HDC
)dc
.GetHDC(), prcBounds
, NULL
, NULL
, 0);
1700 dc
.SetBrush(*wxRED_BRUSH
);
1701 dc
.DrawRectangle(0, 0, w
, h
);
1702 dc
.SetBrush(wxNullBrush
);
1708 void wxActiveX::OnMouse(wxMouseEvent
& event
)
1710 if (m_oleObjectHWND
== NULL
)
1712 wxLogTrace(wxT(""),wxT("no oleInPlaceObject"));
1717 wxLogTrace(wxT(""),wxT("mouse event"));
1721 LRESULT lResult
= 0;
1723 if (event
.m_metaDown
)
1724 wParam
|= MK_CONTROL
;
1725 if (event
.m_shiftDown
)
1727 if (event
.m_leftDown
)
1728 wParam
|= MK_LBUTTON
;
1729 if (event
.m_middleDown
)
1730 wParam
|= MK_MBUTTON
;
1731 if (event
.m_rightDown
)
1732 wParam
|= MK_RBUTTON
;
1733 lParam
= event
.m_x
<< 16;
1734 lParam
|= event
.m_y
;
1736 if (event
.LeftDown())
1737 msg
= WM_LBUTTONDOWN
;
1738 else if (event
.LeftDClick())
1739 msg
= WM_LBUTTONDBLCLK
;
1740 else if (event
.LeftUp())
1742 else if (event
.MiddleDown())
1743 msg
= WM_MBUTTONDOWN
;
1744 else if (event
.MiddleDClick())
1745 msg
= WM_MBUTTONDBLCLK
;
1746 else if (event
.MiddleUp())
1748 else if (event
.RightDown())
1749 msg
= WM_RBUTTONDOWN
;
1750 else if (event
.RightDClick())
1751 msg
= WM_RBUTTONDBLCLK
;
1752 else if (event
.RightUp())
1754 else if (event
.Moving() || event
.Dragging())
1760 wxLogTrace(wxT(""),wxT("no message"));
1761 event
.Skip(); return;
1764 if (!::SendMessage(m_oleObjectHWND
, msg
, wParam
, lParam
))
1766 wxLogTrace(wxT(""),wxT("msg not delivered"));
1771 wxLogTrace(wxT(""),wxT("msg sent"));
1774 long wxActiveX::MSWWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
1776 if (m_oleObjectHWND
== NULL
)
1777 return wxWindow::MSWWindowProc(nMsg
, wParam
, lParam
);
1786 case WM_SYSDEADCHAR
:
1789 PostMessage(m_oleObjectHWND
, nMsg
, wParam
, lParam
);
1792 return wxWindow::MSWWindowProc(nMsg
, wParam
, lParam
);
1796 void wxActiveX::OnSetFocus(wxFocusEvent
& event
)
1798 if (m_oleInPlaceActiveObject
.Ok())
1799 m_oleInPlaceActiveObject
->OnFrameWindowActivate(TRUE
);
1802 void wxActiveX::OnKillFocus(wxFocusEvent
& event
)
1804 if (m_oleInPlaceActiveObject
.Ok())
1805 m_oleInPlaceActiveObject
->OnFrameWindowActivate(FALSE
);
1809 FrameSite::FrameSite(wxActiveX
* win
)
1812 m_bSupportsWindowlessActivation
= true;
1813 m_bInPlaceLocked
= false;
1814 m_bUIActive
= false;
1815 m_bInPlaceActive
= false;
1816 m_bWindowless
= false;
1818 m_nAmbientLocale
= 0;
1819 m_clrAmbientForeColor
= ::GetSysColor(COLOR_WINDOWTEXT
);
1820 m_clrAmbientBackColor
= ::GetSysColor(COLOR_WINDOW
);
1821 m_bAmbientShowHatching
= true;
1822 m_bAmbientShowGrabHandles
= true;
1823 m_bAmbientAppearance
= true;
1826 m_hWndParent
= (HWND
)m_window
->GetHWND();
1829 FrameSite::~FrameSite()
1836 HRESULT
FrameSite::GetIDsOfNames(REFIID riid
, OLECHAR
** rgszNames
, unsigned int cNames
,
1837 LCID lcid
, DISPID
* rgDispId
)
1839 WXOLE_TRACE("IDispatch::GetIDsOfNames");
1843 HRESULT
FrameSite::GetTypeInfo(unsigned int iTInfo
, LCID lcid
, ITypeInfo
** ppTInfo
)
1845 WXOLE_TRACE("IDispatch::GetTypeInfo");
1849 HRESULT
FrameSite::GetTypeInfoCount(unsigned int * pcTInfo
)
1851 WXOLE_TRACE("IDispatch::GetTypeInfoCount");
1855 HRESULT
FrameSite::Invoke(DISPID dispIdMember
, REFIID riid
, LCID lcid
,
1856 WORD wFlags
, DISPPARAMS
* pDispParams
,
1857 VARIANT
* pVarResult
, EXCEPINFO
* pExcepInfo
,
1858 unsigned int * puArgErr
)
1860 WXOLE_TRACE("IDispatch::Invoke");
1862 if (!(wFlags
& DISPATCH_PROPERTYGET
))
1867 if (pVarResult
== NULL
)
1868 return E_INVALIDARG
;
1870 //The most common case is boolean, use as an initial type
1871 V_VT(pVarResult
) = VT_BOOL
;
1873 switch (dispIdMember
)
1875 case DISPID_AMBIENT_MESSAGEREFLECT
:
1876 WXOLE_TRACE("Invoke::DISPID_AMBIENT_MESSAGEREFLECT");
1877 V_BOOL(pVarResult
)= FALSE
;
1880 case DISPID_AMBIENT_DISPLAYASDEFAULT
:
1881 WXOLE_TRACE("Invoke::DISPID_AMBIENT_DISPLAYASDEFAULT");
1882 V_BOOL(pVarResult
)= TRUE
;
1885 case DISPID_AMBIENT_OFFLINEIFNOTCONNECTED
:
1886 WXOLE_TRACE("Invoke::DISPID_AMBIENT_OFFLINEIFNOTCONNECTED");
1887 V_BOOL(pVarResult
) = TRUE
;
1891 case DISPID_AMBIENT_SILENT
:
1892 WXOLE_TRACE("Invoke::DISPID_AMBIENT_SILENT");
1893 V_BOOL(pVarResult
)= TRUE
;
1896 case DISPID_AMBIENT_APPEARANCE
:
1897 pVarResult
->vt
= VT_BOOL
;
1898 pVarResult
->boolVal
= m_bAmbientAppearance
;
1901 case DISPID_AMBIENT_FORECOLOR
:
1902 pVarResult
->vt
= VT_I4
;
1903 pVarResult
->lVal
= (long) m_clrAmbientForeColor
;
1906 case DISPID_AMBIENT_BACKCOLOR
:
1907 pVarResult
->vt
= VT_I4
;
1908 pVarResult
->lVal
= (long) m_clrAmbientBackColor
;
1911 case DISPID_AMBIENT_LOCALEID
:
1912 pVarResult
->vt
= VT_I4
;
1913 pVarResult
->lVal
= (long) m_nAmbientLocale
;
1916 case DISPID_AMBIENT_USERMODE
:
1917 pVarResult
->vt
= VT_BOOL
;
1918 pVarResult
->boolVal
= m_window
->m_bAmbientUserMode
;
1921 case DISPID_AMBIENT_SHOWGRABHANDLES
:
1922 pVarResult
->vt
= VT_BOOL
;
1923 pVarResult
->boolVal
= m_bAmbientShowGrabHandles
;
1926 case DISPID_AMBIENT_SHOWHATCHING
:
1927 pVarResult
->vt
= VT_BOOL
;
1928 pVarResult
->boolVal
= m_bAmbientShowHatching
;
1932 return DISP_E_MEMBERNOTFOUND
;
1940 HRESULT
FrameSite::GetWindow(HWND
* phwnd
)
1942 WXOLE_TRACE("IOleWindow::GetWindow");
1944 return E_INVALIDARG
;
1945 (*phwnd
) = m_hWndParent
;
1949 HRESULT
FrameSite::ContextSensitiveHelp(BOOL fEnterMode
)
1951 WXOLE_TRACE("IOleWindow::ContextSensitiveHelp");
1955 //IOleInPlaceUIWindow
1957 HRESULT
FrameSite::GetBorder(LPRECT lprectBorder
)
1959 WXOLE_TRACE("IOleInPlaceUIWindow::GetBorder");
1960 if (lprectBorder
== NULL
)
1961 return E_INVALIDARG
;
1962 return INPLACE_E_NOTOOLSPACE
;
1965 HRESULT
FrameSite::RequestBorderSpace(LPCBORDERWIDTHS pborderwidths
)
1967 WXOLE_TRACE("IOleInPlaceUIWindow::RequestBorderSpace");
1968 if (pborderwidths
== NULL
)
1969 return E_INVALIDARG
;
1970 return INPLACE_E_NOTOOLSPACE
;
1973 HRESULT
FrameSite::SetBorderSpace(LPCBORDERWIDTHS pborderwidths
)
1975 WXOLE_TRACE("IOleInPlaceUIWindow::SetBorderSpace");
1979 HRESULT
FrameSite::SetActiveObject(IOleInPlaceActiveObject
*pActiveObject
, LPCOLESTR pszObjName
)
1981 WXOLE_TRACE("IOleInPlaceUIWindow::SetActiveObject");
1984 pActiveObject
->AddRef();
1986 m_window
->m_oleInPlaceActiveObject
= pActiveObject
;
1992 HRESULT
FrameSite::InsertMenus(HMENU hmenuShared
, LPOLEMENUGROUPWIDTHS lpMenuWidths
)
1994 WXOLE_TRACE("IOleInPlaceFrame::InsertMenus");
1998 HRESULT
FrameSite::SetMenu(HMENU hmenuShared
, HOLEMENU holemenu
, HWND hwndActiveObject
)
2000 WXOLE_TRACE("IOleInPlaceFrame::SetMenu");
2004 HRESULT
FrameSite::RemoveMenus(HMENU hmenuShared
)
2006 WXOLE_TRACE("IOleInPlaceFrame::RemoveMenus");
2010 HRESULT
FrameSite::SetStatusText(LPCOLESTR pszStatusText
)
2012 WXOLE_TRACE("IOleInPlaceFrame::SetStatusText");
2013 //((wxFrame*)wxGetApp().GetTopWindow())->GetStatusBar()->SetStatusText(pszStatusText);
2017 HRESULT
FrameSite::EnableModeless(BOOL fEnable
)
2019 WXOLE_TRACE("IOleInPlaceFrame::EnableModeless");
2023 HRESULT
FrameSite::TranslateAccelerator(LPMSG lpmsg
, WORD wID
)
2025 WXOLE_TRACE("IOleInPlaceFrame::TranslateAccelerator");
2026 // TODO: send an event with this id
2027 if (m_window
->m_oleInPlaceActiveObject
.Ok())
2028 m_window
->m_oleInPlaceActiveObject
->TranslateAccelerator(lpmsg
);
2035 HRESULT
FrameSite::CanInPlaceActivate()
2037 WXOLE_TRACE("IOleInPlaceSite::CanInPlaceActivate");
2041 HRESULT
FrameSite::OnInPlaceActivate()
2043 WXOLE_TRACE("IOleInPlaceSite::OnInPlaceActivate");
2044 m_bInPlaceActive
= true;
2048 HRESULT
FrameSite::OnUIActivate()
2050 WXOLE_TRACE("IOleInPlaceSite::OnUIActivate");
2055 HRESULT
FrameSite::GetWindowContext(IOleInPlaceFrame
**ppFrame
,
2056 IOleInPlaceUIWindow
**ppDoc
,
2058 LPRECT lprcClipRect
,
2059 LPOLEINPLACEFRAMEINFO lpFrameInfo
)
2061 WXOLE_TRACE("IOleInPlaceSite::GetWindowContext");
2062 if (ppFrame
== NULL
|| ppDoc
== NULL
|| lprcPosRect
== NULL
||
2063 lprcClipRect
== NULL
|| lpFrameInfo
== NULL
)
2065 if (ppFrame
!= NULL
)
2069 return E_INVALIDARG
;
2072 HRESULT hr
= QueryInterface(IID_IOleInPlaceFrame
, (void **) ppFrame
);
2073 if (! SUCCEEDED(hr
))
2075 WXOLE_TRACE("IOleInPlaceSite::IOleInPlaceFrame Error !");
2076 return E_UNEXPECTED
;
2079 hr
= QueryInterface(IID_IOleInPlaceUIWindow
, (void **) ppDoc
);
2080 if (! SUCCEEDED(hr
))
2082 WXOLE_TRACE("IOleInPlaceSite::IOleInPlaceUIWindow Error !");
2083 (*ppFrame
)->Release();
2085 return E_UNEXPECTED
;
2089 m_window
->GetClientSize(&w
, &h
);
2092 lprcPosRect
->left
= lprcPosRect
->top
= 0;
2093 lprcPosRect
->right
= w
;
2094 lprcPosRect
->bottom
= h
;
2098 lprcClipRect
->left
= lprcClipRect
->top
= 0;
2099 lprcClipRect
->right
= w
;
2100 lprcClipRect
->bottom
= h
;
2103 memset(lpFrameInfo
, 0, sizeof(OLEINPLACEFRAMEINFO
));
2104 lpFrameInfo
->cb
= sizeof(OLEINPLACEFRAMEINFO
);
2105 lpFrameInfo
->hwndFrame
= m_hWndParent
;
2110 HRESULT
FrameSite::Scroll(SIZE scrollExtent
)
2112 WXOLE_TRACE("IOleInPlaceSite::Scroll");
2116 HRESULT
FrameSite::OnUIDeactivate(BOOL fUndoable
)
2118 WXOLE_TRACE("IOleInPlaceSite::OnUIDeactivate");
2119 m_bUIActive
= false;
2123 HRESULT
FrameSite::OnInPlaceDeactivate()
2125 WXOLE_TRACE("IOleInPlaceSite::OnInPlaceDeactivate");
2126 m_bInPlaceActive
= false;
2130 HRESULT
FrameSite::DiscardUndoState()
2132 WXOLE_TRACE("IOleInPlaceSite::DiscardUndoState");
2136 HRESULT
FrameSite::DeactivateAndUndo()
2138 WXOLE_TRACE("IOleInPlaceSite::DeactivateAndUndo");
2142 HRESULT
FrameSite::OnPosRectChange(LPCRECT lprcPosRect
)
2144 WXOLE_TRACE("IOleInPlaceSite::OnPosRectChange");
2145 if (m_window
->m_oleInPlaceObject
.Ok() && lprcPosRect
)
2146 m_window
->m_oleInPlaceObject
->SetObjectRects(lprcPosRect
, lprcPosRect
);
2153 HRESULT
FrameSite::OnInPlaceActivateEx(BOOL
* pfNoRedraw
, DWORD dwFlags
)
2155 WXOLE_TRACE("IOleInPlaceSiteEx::OnInPlaceActivateEx");
2156 OleLockRunning(m_window
->m_ActiveX
, TRUE
, FALSE
);
2158 (*pfNoRedraw
) = FALSE
;
2162 HRESULT
FrameSite::OnInPlaceDeactivateEx(BOOL fNoRedraw
)
2164 WXOLE_TRACE("IOleInPlaceSiteEx::OnInPlaceDeactivateEx");
2165 OleLockRunning(m_window
->m_ActiveX
, FALSE
, FALSE
);
2169 HRESULT
FrameSite::RequestUIActivate()
2171 WXOLE_TRACE("IOleInPlaceSiteEx::RequestUIActivate");
2178 HRESULT
FrameSite::SaveObject()
2180 WXOLE_TRACE("IOleClientSite::SaveObject");
2184 const char *OleGetMonikerToStr(DWORD dwAssign
)
2188 case OLEGETMONIKER_ONLYIFTHERE
: return "OLEGETMONIKER_ONLYIFTHERE";
2189 case OLEGETMONIKER_FORCEASSIGN
: return "OLEGETMONIKER_FORCEASSIGN";
2190 case OLEGETMONIKER_UNASSIGN
: return "OLEGETMONIKER_UNASSIGN";
2191 case OLEGETMONIKER_TEMPFORUSER
: return "OLEGETMONIKER_TEMPFORUSER";
2192 default : return "Bad Enum";
2196 const char *OleGetWhicMonikerStr(DWORD dwWhichMoniker
)
2198 switch(dwWhichMoniker
)
2200 case OLEWHICHMK_CONTAINER
: return "OLEWHICHMK_CONTAINER";
2201 case OLEWHICHMK_OBJREL
: return "OLEWHICHMK_OBJREL";
2202 case OLEWHICHMK_OBJFULL
: return "OLEWHICHMK_OBJFULL";
2203 default : return "Bad Enum";
2207 HRESULT
FrameSite::GetMoniker(DWORD dwAssign
, DWORD dwWhichMoniker
,
2210 WXOLE_TRACEOUT("IOleClientSite::GetMoniker(" << OleGetMonikerToStr(dwAssign
) << ", " << OleGetWhicMonikerStr(dwWhichMoniker
) << ")");
2217 HRESULT hr = CreateFileMoniker(L"e:\\dev\\wxie\\bug-zap.swf", ppmk);
2226 HRESULT
FrameSite::GetContainer(LPOLECONTAINER
* ppContainer
)
2228 WXOLE_TRACE("IOleClientSite::GetContainer");
2229 if (ppContainer
== NULL
)
2230 return E_INVALIDARG
;
2232 HRESULT hr
= QueryInterface(IID_IOleContainer
, (void**)(ppContainer
));
2233 wxASSERT(SUCCEEDED(hr
));
2238 HRESULT
FrameSite::ShowObject()
2240 WXOLE_TRACE("IOleClientSite::ShowObject");
2241 if (m_window
->m_oleObjectHWND
)
2242 ::ShowWindow(m_window
->m_oleObjectHWND
, SW_SHOW
);
2246 HRESULT
FrameSite::OnShowWindow(BOOL fShow
)
2248 WXOLE_TRACE("IOleClientSite::OnShowWindow");
2252 HRESULT
FrameSite::RequestNewObjectLayout()
2254 WXOLE_TRACE("IOleClientSite::RequestNewObjectLayout");
2258 // IParseDisplayName
2260 HRESULT
FrameSite::ParseDisplayName(IBindCtx
*pbc
, LPOLESTR pszDisplayName
,
2261 ULONG
*pchEaten
, IMoniker
**ppmkOut
)
2263 WXOLE_TRACE("IParseDisplayName::ParseDisplayName");
2269 HRESULT
FrameSite::EnumObjects(DWORD grfFlags
, IEnumUnknown
**ppenum
)
2271 WXOLE_TRACE("IOleContainer::EnumObjects");
2275 HRESULT
FrameSite::LockContainer(BOOL fLock
)
2277 WXOLE_TRACE("IOleContainer::LockContainer");
2284 HRESULT
FrameSite::GetObject(LPOLESTR pszItem
, DWORD dwSpeedNeeded
,
2285 IBindCtx
* pbc
, REFIID riid
, void ** ppvObject
)
2287 WXOLE_TRACE("IOleItemContainer::GetObject");
2288 if (pszItem
== NULL
)
2289 return E_INVALIDARG
;
2290 if (ppvObject
== NULL
)
2291 return E_INVALIDARG
;
2294 return MK_E_NOOBJECT
;
2297 HRESULT
FrameSite::GetObjectStorage(LPOLESTR pszItem
, IBindCtx
* pbc
,
2298 REFIID riid
, void ** ppvStorage
)
2300 WXOLE_TRACE("IOleItemContainer::GetObjectStorage");
2301 if (pszItem
== NULL
)
2302 return E_INVALIDARG
;
2303 if (ppvStorage
== NULL
)
2304 return E_INVALIDARG
;
2307 return MK_E_NOOBJECT
;
2310 HRESULT
FrameSite::IsRunning(LPOLESTR pszItem
)
2312 WXOLE_TRACE("IOleItemContainer::IsRunning");
2313 if (pszItem
== NULL
)
2314 return E_INVALIDARG
;
2316 return MK_E_NOOBJECT
;
2323 HRESULT
FrameSite::OnControlInfoChanged()
2325 WXOLE_TRACE("IOleControlSite::OnControlInfoChanged");
2329 HRESULT
FrameSite::LockInPlaceActive(BOOL fLock
)
2331 WXOLE_TRACE("IOleControlSite::LockInPlaceActive");
2332 m_bInPlaceLocked
= (fLock
) ? true : false;
2336 HRESULT
FrameSite::GetExtendedControl(IDispatch
** ppDisp
)
2338 WXOLE_TRACE("IOleControlSite::GetExtendedControl");
2342 HRESULT
FrameSite::TransformCoords(POINTL
* pPtlHimetric
, POINTF
* pPtfContainer
, DWORD dwFlags
)
2344 WXOLE_TRACE("IOleControlSite::TransformCoords");
2347 if (pPtlHimetric
== NULL
)
2348 return E_INVALIDARG
;
2350 if (pPtfContainer
== NULL
)
2351 return E_INVALIDARG
;
2357 HRESULT
FrameSite::TranslateAccelerator(LPMSG pMsg
, DWORD grfModifiers
)
2359 WXOLE_TRACE("IOleControlSite::TranslateAccelerator");
2360 // TODO: send an event with this id
2364 HRESULT
FrameSite::OnFocus(BOOL fGotFocus
)
2366 WXOLE_TRACE("IOleControlSite::OnFocus");
2370 HRESULT
FrameSite::ShowPropertyFrame()
2372 WXOLE_TRACE("IOleControlSite::ShowPropertyFrame");
2378 HRESULT
FrameSite::QueryStatus(const GUID
* pguidCmdGroup
, ULONG cCmds
,
2379 OLECMD
* prgCmds
, OLECMDTEXT
* pCmdTet
)
2381 WXOLE_TRACE("IOleCommandTarget::QueryStatus");
2382 if (prgCmds
== NULL
) return E_INVALIDARG
;
2383 bool bCmdGroupFound
= false;
2385 for (ULONG nCmd
= 0; nCmd
< cCmds
; nCmd
++)
2387 // unsupported by default
2388 prgCmds
[nCmd
].cmdf
= 0;
2393 if (!bCmdGroupFound
) { OLECMDERR_E_UNKNOWNGROUP
; }
2397 HRESULT
FrameSite::Exec(const GUID
* pguidCmdGroup
, DWORD nCmdID
,
2398 DWORD nCmdExecOpt
, VARIANTARG
* pVaIn
,
2399 VARIANTARG
* pVaOut
)
2401 WXOLE_TRACE("IOleCommandTarget::Exec");
2402 bool bCmdGroupFound
= false;
2404 if (!bCmdGroupFound
) { OLECMDERR_E_UNKNOWNGROUP
; }
2405 return OLECMDERR_E_NOTSUPPORTED
;
2410 void STDMETHODCALLTYPE
FrameSite::OnDataChange(FORMATETC
* pFormatEtc
, STGMEDIUM
* pgStgMed
)
2412 WXOLE_TRACE("IAdviseSink::OnDataChange");
2415 void STDMETHODCALLTYPE
FrameSite::OnViewChange(DWORD dwAspect
, LONG lIndex
)
2417 WXOLE_TRACE("IAdviseSink::OnViewChange");
2418 // redraw the control
2421 void STDMETHODCALLTYPE
FrameSite::OnRename(IMoniker
* pmk
)
2423 WXOLE_TRACE("IAdviseSink::OnRename");
2426 void STDMETHODCALLTYPE
FrameSite::OnSave()
2428 WXOLE_TRACE("IAdviseSink::OnSave");
2431 void STDMETHODCALLTYPE
FrameSite::OnClose()
2433 WXOLE_TRACE("IAdviseSink::OnClose");
2436 /////////////////////////////////////////////
2438 HRESULT STDMETHODCALLTYPE
FrameSite::ActivateMe(
2439 /* [in] */ IOleDocumentView __RPC_FAR
*pViewToActivate
)
2441 wxAutoOleInterface
<IOleInPlaceSite
> inPlaceSite(IID_IOleInPlaceSite
, (IDispatch
*) this);
2442 if (!inPlaceSite
.Ok())
2445 if (pViewToActivate
)
2447 m_window
->m_docView
= pViewToActivate
;
2448 m_window
->m_docView
->SetInPlaceSite(inPlaceSite
);
2452 wxAutoOleInterface
<IOleDocument
> oleDoc(IID_IOleDocument
, m_window
->m_oleObject
);
2456 HRESULT hr
= oleDoc
->CreateView(inPlaceSite
, NULL
, 0, m_window
->m_docView
.GetRef());
2460 m_window
->m_docView
->SetInPlaceSite(inPlaceSite
);
2463 m_window
->m_docView
->UIActivate(TRUE
);
2469 static IMalloc
*iMalloc
= NULL
;
2471 IMalloc
*wxOleInit::GetIMalloc()
2477 wxOleInit::wxOleInit()
2479 if (OleInitialize(NULL
) == S_OK
&& iMalloc
== NULL
)
2480 CoGetMalloc(1, &iMalloc
);
2485 wxOleInit::~wxOleInit()
2489 if (iMalloc
->Release() == 0)
2496 bool GetSysErrMessage(int err
, wxString
& s
)
2500 FORMAT_MESSAGE_FROM_SYSTEM
, NULL
,
2501 err
,0, buf
, sizeof(buf
), NULL
) == 0)
2504 buf
[sizeof(buf
) - 1] = 0;
2509 wxString
OLEHResultToString(HRESULT hr
)
2511 // try formatmessage
2513 if (GetSysErrMessage(hr
, err
))
2519 return wxEmptyString
;
2521 case CONNECT_E_CANNOTCONNECT
:
2522 return _T("Cannot connect to event interface (maybe not there ?) - see MSDN");
2524 case DISP_E_MEMBERNOTFOUND
:
2525 return _T("The requested member does not exist, or the call to Invoke tried to set the value of a read-only property.");
2527 case DISP_E_BADVARTYPE
:
2528 return _T("One of the parameters in rgvarg is not a valid variant type.");
2530 case DISP_E_BADPARAMCOUNT
:
2531 return _T("The number of elements provided to DISPPARAMS is different from the number of parameters accepted by the method or property");
2533 case DISP_E_EXCEPTION
:
2534 return _T("The application needs to raise an exception. In this case, the structure passed in pExcepInfo should be filled in.");
2536 case DISP_E_TYPEMISMATCH
:
2537 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.");
2539 case DISP_E_PARAMNOTOPTIONAL
:
2540 return _T("A required parameter was omitted.");
2542 case DISP_E_PARAMNOTFOUND
:
2543 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.");
2545 case OLECMDERR_E_UNKNOWNGROUP
:
2546 return _T("The pguidCmdGroup parameter is not NULL but does not specify a recognized command group.");
2548 case OLECMDERR_E_NOTSUPPORTED
:
2549 return _T("The nCmdID parameter is not a valid command in the group identified by pguidCmdGroup.");
2551 case OLECMDERR_E_DISABLED
:
2552 return _T("The command identified by nCmdID is currently disabled and cannot be executed.");
2554 case OLECMDERR_E_NOHELP
:
2555 return _T("The caller has asked for help on the command identified by nCmdID, but no help is available.");
2557 case OLECMDERR_E_CANCELED
:
2558 return _T("The user canceled the execution of the command.");
2561 return _T("E_INVALIDARG");
2564 return _T("E_OUTOFMEMORY");
2567 return _T("E_NOINTERFACE");
2570 return _T("E_UNEXPECTED");
2572 case STG_E_INVALIDFLAG
:
2573 return _T("STG_E_INVALIDFLAG");
2576 return _T("E_FAIL");
2579 return _T("E_NOTIMPL");
2584 buf
.Printf(_T("Unknown - 0x%X"), hr
);
2590 // borrowed from src/msw/ole/oleutils.cpp
2591 wxString
GetIIDName(REFIID riid
)
2593 // an association between symbolic name and numeric value of an IID
2597 const wxChar
*szName
;
2600 // construct the table containing all known interfaces
2601 #define ADD_KNOWN_IID(name) { &IID_I##name, _T(#name) }
2602 #define ADD_KNOWN_GUID(name) { &name, _T(#name) }
2604 static const KNOWN_IID aKnownIids
[] =
2606 ADD_KNOWN_IID(ServiceProvider
),
2607 ADD_KNOWN_IID(AdviseSink
),
2608 ADD_KNOWN_IID(AdviseSink2
),
2609 ADD_KNOWN_IID(BindCtx
),
2610 ADD_KNOWN_IID(ClassFactory
),
2611 #if ( !defined( __VISUALC__) || (__VISUALC__!=1010) ) && !defined(__MWERKS__)
2612 ADD_KNOWN_IID(ContinueCallback
),
2613 ADD_KNOWN_IID(EnumOleDocumentViews
),
2614 ADD_KNOWN_IID(OleCommandTarget
),
2615 ADD_KNOWN_IID(OleDocument
),
2616 ADD_KNOWN_IID(OleDocumentSite
),
2617 ADD_KNOWN_IID(OleDocumentView
),
2618 ADD_KNOWN_IID(Print
),
2620 ADD_KNOWN_IID(DataAdviseHolder
),
2621 ADD_KNOWN_IID(DataObject
),
2622 ADD_KNOWN_IID(Debug
),
2623 ADD_KNOWN_IID(DebugStream
),
2624 ADD_KNOWN_IID(DfReserved1
),
2625 ADD_KNOWN_IID(DfReserved2
),
2626 ADD_KNOWN_IID(DfReserved3
),
2627 ADD_KNOWN_IID(Dispatch
),
2628 ADD_KNOWN_IID(DropSource
),
2629 ADD_KNOWN_IID(DropTarget
),
2630 ADD_KNOWN_IID(EnumCallback
),
2631 ADD_KNOWN_IID(EnumFORMATETC
),
2632 ADD_KNOWN_IID(EnumGeneric
),
2633 ADD_KNOWN_IID(EnumHolder
),
2634 ADD_KNOWN_IID(EnumMoniker
),
2635 ADD_KNOWN_IID(EnumOLEVERB
),
2636 ADD_KNOWN_IID(EnumSTATDATA
),
2637 ADD_KNOWN_IID(EnumSTATSTG
),
2638 ADD_KNOWN_IID(EnumString
),
2639 ADD_KNOWN_IID(EnumUnknown
),
2640 ADD_KNOWN_IID(EnumVARIANT
),
2641 ADD_KNOWN_IID(ExternalConnection
),
2642 ADD_KNOWN_IID(InternalMoniker
),
2643 ADD_KNOWN_IID(LockBytes
),
2644 ADD_KNOWN_IID(Malloc
),
2645 ADD_KNOWN_IID(Marshal
),
2646 ADD_KNOWN_IID(MessageFilter
),
2647 ADD_KNOWN_IID(Moniker
),
2648 ADD_KNOWN_IID(OleAdviseHolder
),
2649 ADD_KNOWN_IID(OleCache
),
2650 ADD_KNOWN_IID(OleCache2
),
2651 ADD_KNOWN_IID(OleCacheControl
),
2652 ADD_KNOWN_IID(OleClientSite
),
2653 ADD_KNOWN_IID(OleContainer
),
2654 ADD_KNOWN_IID(OleInPlaceActiveObject
),
2655 ADD_KNOWN_IID(OleInPlaceFrame
),
2656 ADD_KNOWN_IID(OleInPlaceObject
),
2657 ADD_KNOWN_IID(OleInPlaceSite
),
2658 ADD_KNOWN_IID(OleInPlaceUIWindow
),
2659 ADD_KNOWN_IID(OleItemContainer
),
2660 ADD_KNOWN_IID(OleLink
),
2661 ADD_KNOWN_IID(OleManager
),
2662 ADD_KNOWN_IID(OleObject
),
2663 ADD_KNOWN_IID(OlePresObj
),
2664 ADD_KNOWN_IID(OleWindow
),
2665 ADD_KNOWN_IID(PSFactory
),
2666 ADD_KNOWN_IID(ParseDisplayName
),
2667 ADD_KNOWN_IID(Persist
),
2668 ADD_KNOWN_IID(PersistFile
),
2669 ADD_KNOWN_IID(PersistStorage
),
2670 ADD_KNOWN_IID(PersistStream
),
2671 ADD_KNOWN_IID(ProxyManager
),
2672 ADD_KNOWN_IID(RootStorage
),
2673 ADD_KNOWN_IID(RpcChannel
),
2674 ADD_KNOWN_IID(RpcProxy
),
2675 ADD_KNOWN_IID(RpcStub
),
2676 ADD_KNOWN_IID(RunnableObject
),
2677 ADD_KNOWN_IID(RunningObjectTable
),
2678 ADD_KNOWN_IID(StdMarshalInfo
),
2679 ADD_KNOWN_IID(Storage
),
2680 ADD_KNOWN_IID(Stream
),
2681 ADD_KNOWN_IID(StubManager
),
2682 ADD_KNOWN_IID(Unknown
),
2683 ADD_KNOWN_IID(ViewObject
),
2684 ADD_KNOWN_IID(ViewObject2
),
2685 ADD_KNOWN_GUID(IID_IDispatch
),
2686 ADD_KNOWN_GUID(IID_IWebBrowser
),
2687 ADD_KNOWN_GUID(IID_IWebBrowserApp
),
2688 ADD_KNOWN_GUID(IID_IWebBrowser2
),
2689 ADD_KNOWN_GUID(IID_IWebBrowser
),
2690 ADD_KNOWN_GUID(DIID_DWebBrowserEvents2
),
2691 ADD_KNOWN_GUID(DIID_DWebBrowserEvents
),
2694 // don't clobber preprocessor name space
2695 #undef ADD_KNOWN_IID
2696 #undef ADD_KNOWN_GUID
2698 // try to find the interface in the table
2699 for ( size_t ui
= 0; ui
< WXSIZEOF(aKnownIids
); ui
++ )
2701 if ( riid
== *aKnownIids
[ui
].pIid
)
2703 return aKnownIids
[ui
].szName
;
2707 // unknown IID, just transform to string
2708 LPOLESTR str
= NULL
;
2709 StringFromIID(riid
, &str
);
2717 return _T("StringFromIID() error");