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
)
91 public IOleClientSite
,
92 public IOleInPlaceSiteEx
,
93 public IOleInPlaceFrame
,
94 public IOleItemContainer
,
96 public IOleCommandTarget
,
97 public IOleDocumentSite
,
99 public IOleControlSite
102 DECLARE_OLE_UNKNOWN(FrameSite
);
105 FrameSite(wxActiveX
* win
);
106 virtual ~FrameSite();
109 STDMETHODIMP
GetWindow(HWND
*);
110 STDMETHODIMP
ContextSensitiveHelp(BOOL
);
112 //IOleInPlaceUIWindow
113 STDMETHODIMP
GetBorder(LPRECT
);
114 STDMETHODIMP
RequestBorderSpace(LPCBORDERWIDTHS
);
115 STDMETHODIMP
SetBorderSpace(LPCBORDERWIDTHS
);
116 STDMETHODIMP
SetActiveObject(IOleInPlaceActiveObject
*, LPCOLESTR
);
119 STDMETHODIMP
InsertMenus(HMENU
, LPOLEMENUGROUPWIDTHS
);
120 STDMETHODIMP
SetMenu(HMENU
, HOLEMENU
, HWND
);
121 STDMETHODIMP
RemoveMenus(HMENU
);
122 STDMETHODIMP
SetStatusText(LPCOLESTR
);
123 STDMETHODIMP
EnableModeless(BOOL
);
124 STDMETHODIMP
TranslateAccelerator(LPMSG
, WORD
);
127 STDMETHODIMP
CanInPlaceActivate();
128 STDMETHODIMP
OnInPlaceActivate();
129 STDMETHODIMP
OnUIActivate();
130 STDMETHODIMP
GetWindowContext(IOleInPlaceFrame
**, IOleInPlaceUIWindow
**,
131 LPRECT
, LPRECT
, LPOLEINPLACEFRAMEINFO
);
132 STDMETHODIMP
Scroll(SIZE
);
133 STDMETHODIMP
OnUIDeactivate(BOOL
);
134 STDMETHODIMP
OnInPlaceDeactivate();
135 STDMETHODIMP
DiscardUndoState();
136 STDMETHODIMP
DeactivateAndUndo();
137 STDMETHODIMP
OnPosRectChange(LPCRECT
);
140 STDMETHODIMP
OnInPlaceActivateEx(BOOL
*, DWORD
);
141 STDMETHODIMP
OnInPlaceDeactivateEx(BOOL
);
142 STDMETHODIMP
RequestUIActivate();
145 STDMETHODIMP
SaveObject();
146 STDMETHODIMP
GetMoniker(DWORD
, DWORD
, IMoniker
**);
147 STDMETHODIMP
GetContainer(LPOLECONTAINER FAR
*);
148 STDMETHODIMP
ShowObject();
149 STDMETHODIMP
OnShowWindow(BOOL
);
150 STDMETHODIMP
RequestNewObjectLayout();
153 STDMETHODIMP
OnControlInfoChanged();
154 STDMETHODIMP
LockInPlaceActive(BOOL
);
155 STDMETHODIMP
GetExtendedControl(IDispatch
**);
156 STDMETHODIMP
TransformCoords(POINTL
*, POINTF
*, DWORD
);
157 STDMETHODIMP
TranslateAccelerator(LPMSG
, DWORD
);
158 STDMETHODIMP
OnFocus(BOOL
);
159 STDMETHODIMP
ShowPropertyFrame();
162 STDMETHODIMP
QueryStatus(const GUID
*, ULONG
, OLECMD
[], OLECMDTEXT
*);
163 STDMETHODIMP
Exec(const GUID
*, DWORD
, DWORD
, VARIANTARG
*, VARIANTARG
*);
166 STDMETHODIMP
ParseDisplayName(IBindCtx
*, LPOLESTR
, ULONG
*, IMoniker
**);
169 STDMETHODIMP
EnumObjects(DWORD
, IEnumUnknown
**);
170 STDMETHODIMP
LockContainer(BOOL
);
173 STDMETHODIMP
GetObject(LPOLESTR
, DWORD
, IBindCtx
*, REFIID
, void**);
174 STDMETHODIMP
GetObjectStorage(LPOLESTR
, IBindCtx
*, REFIID
, void**);
175 STDMETHODIMP
IsRunning(LPOLESTR
);
178 STDMETHODIMP
GetIDsOfNames(REFIID
, OLECHAR
**, unsigned int, LCID
, DISPID
*);
179 STDMETHODIMP
GetTypeInfo(unsigned int, LCID
, ITypeInfo
**);
180 STDMETHODIMP
GetTypeInfoCount(unsigned int*);
181 STDMETHODIMP
Invoke(DISPID
, REFIID
, LCID
, WORD
, DISPPARAMS
*, VARIANT
*, EXCEPINFO
*, UINT
*);
184 void STDMETHODCALLTYPE
OnDataChange(FORMATETC
*, STGMEDIUM
*);
185 void STDMETHODCALLTYPE
OnViewChange(DWORD
, LONG
);
186 void STDMETHODCALLTYPE
OnRename(IMoniker
*);
187 void STDMETHODCALLTYPE
OnSave();
188 void STDMETHODCALLTYPE
OnClose();
191 HRESULT STDMETHODCALLTYPE
ActivateMe(IOleDocumentView __RPC_FAR
*pViewToActivate
);
195 wxActiveX
* m_window
;
200 bool m_bSupportsWindowlessActivation
;
201 bool m_bInPlaceLocked
;
202 bool m_bInPlaceActive
;
208 LCID m_nAmbientLocale
;
209 COLORREF m_clrAmbientForeColor
;
210 COLORREF m_clrAmbientBackColor
;
211 bool m_bAmbientShowHatching
;
212 bool m_bAmbientShowGrabHandles
;
213 bool m_bAmbientAppearance
;
216 DEFINE_OLE_TABLE(FrameSite
)
217 OLE_INTERFACE(IID_IUnknown
, IOleClientSite
)
219 OLE_IINTERFACE(IOleClientSite
)
221 OLE_INTERFACE(IID_IOleWindow
, IOleInPlaceSite
)
222 OLE_IINTERFACE(IOleInPlaceSite
)
223 OLE_IINTERFACE(IOleInPlaceSiteEx
)
225 //OLE_IINTERFACE(IOleWindow)
226 OLE_IINTERFACE(IOleInPlaceUIWindow
)
227 OLE_IINTERFACE(IOleInPlaceFrame
)
229 OLE_IINTERFACE(IParseDisplayName
)
230 OLE_IINTERFACE(IOleContainer
)
231 OLE_IINTERFACE(IOleItemContainer
)
233 OLE_IINTERFACE(IDispatch
)
235 OLE_IINTERFACE(IOleCommandTarget
)
237 OLE_IINTERFACE(IOleDocumentSite
)
239 OLE_IINTERFACE(IAdviseSink
)
241 OLE_IINTERFACE(IOleControlSite
)
246 wxActiveX::wxActiveX(wxWindow
* parent
, REFCLSID clsid
, wxWindowID id
,
250 const wxString
& name
) :
251 wxWindow(parent
, id
, pos
, size
, style
, name
)
253 m_bAmbientUserMode
= true;
254 m_docAdviseCookie
= 0;
255 CreateActiveX(clsid
);
258 wxActiveX::wxActiveX(wxWindow
* parent
, const wxString
& progId
, wxWindowID id
,
262 const wxString
& name
) :
263 wxWindow(parent
, id
, pos
, size
, style
, name
)
265 m_bAmbientUserMode
= true;
266 m_docAdviseCookie
= 0;
267 CreateActiveX((LPOLESTR
) (const wchar_t *) progId
.wc_str(wxConvUTF8
));
270 wxActiveX::~wxActiveX()
272 // disconnect connection points
273 wxOleConnectionArray::iterator it
= m_connections
.begin();
274 while (it
!= m_connections
.end())
276 wxOleConnectionPoint
& cp
= it
->first
;
277 cp
->Unadvise(it
->second
);
281 m_connections
.clear();
283 if (m_oleInPlaceObject
.Ok())
285 m_oleInPlaceObject
->InPlaceDeactivate();
286 m_oleInPlaceObject
->UIDeactivate();
290 if (m_oleObject
.Ok())
292 if (m_docAdviseCookie
!= 0)
293 m_oleObject
->Unadvise(m_docAdviseCookie
);
295 m_oleObject
->DoVerb(OLEIVERB_HIDE
, NULL
, m_clientSite
, 0, (HWND
) GetHWND(), NULL
);
296 m_oleObject
->Close(OLECLOSE_NOSAVE
);
297 m_oleObject
->SetClientSite(NULL
);
301 void wxActiveX::CreateActiveX(REFCLSID clsid
)
307 ////////////////////////////////////////////////////////
309 FrameSite
*frame
= new FrameSite(this);
311 hret
= m_clientSite
.QueryInterface(IID_IOleClientSite
, (IDispatch
*) frame
);
312 wxCHECK_RET(SUCCEEDED(hret
), _T("m_clientSite.QueryInterface failed"));
314 wxAutoOleInterface
<IAdviseSink
> adviseSink(IID_IAdviseSink
, (IDispatch
*) frame
);
315 wxCHECK_RET(adviseSink
.Ok(), _T("adviseSink not Ok"));
318 // // Create Object, get IUnknown interface
319 m_ActiveX
.CreateInstance(clsid
, IID_IUnknown
);
320 wxCHECK_RET(m_ActiveX
.Ok(), _T("m_ActiveX.CreateInstance failed"));
322 // Get Dispatch interface
323 hret
= m_Dispatch
.QueryInterface(IID_IDispatch
, m_ActiveX
);
324 WXOLE_WARN(hret
, "Unable to get dispatch interface");
329 // Get IOleObject interface
330 hret
= m_oleObject
.QueryInterface(IID_IOleObject
, m_ActiveX
);
331 wxCHECK_RET(SUCCEEDED(hret
), _("Unable to get IOleObject interface"));
333 // get IViewObject Interface
334 hret
= m_viewObject
.QueryInterface(IID_IViewObject
, m_ActiveX
);
335 wxCHECK_RET(SUCCEEDED(hret
), _T("Unable to get IViewObject Interface"));
338 m_docAdviseCookie
= 0;
339 hret
= m_oleObject
->Advise(adviseSink
, &m_docAdviseCookie
);
340 WXOLE_WARN(hret
, "m_oleObject->Advise(adviseSink, &m_docAdviseCookie),\"Advise\")");
341 m_oleObject
->SetHostNames(L
"wxActiveXContainer", NULL
);
342 OleSetContainedObject(m_oleObject
, TRUE
);
346 // Get IOleInPlaceObject interface
347 hret
= m_oleInPlaceObject
.QueryInterface(IID_IOleInPlaceObject
, m_ActiveX
);
348 wxCHECK_RET(SUCCEEDED(hret
), _T("Unable to get IOleInPlaceObject interface"));
352 m_oleObject
->GetMiscStatus(DVASPECT_CONTENT
, &dwMiscStatus
);
353 wxCHECK_RET(SUCCEEDED(hret
), _T("Unable to get oleObject status"));
355 // set client site first ?
356 if (dwMiscStatus
& OLEMISC_SETCLIENTSITEFIRST
)
357 m_oleObject
->SetClientSite(m_clientSite
);
361 wxAutoOleInterface
<IPersistStreamInit
>
362 pPersistStreamInit(IID_IPersistStreamInit
, m_oleObject
);
364 if (pPersistStreamInit
.Ok())
366 hret
= pPersistStreamInit
->InitNew();
367 WXOLE_WARN(hret
, "CreateActiveX::pPersistStreamInit->InitNew()");
370 if (! (dwMiscStatus
& OLEMISC_SETCLIENTSITEFIRST
))
371 m_oleObject
->SetClientSite(m_clientSite
);
375 GetClientSize(&w
, &h
);
384 if (m_oleInPlaceObject
.Ok())
386 hret
= m_oleInPlaceObject
->GetWindow(&m_oleObjectHWND
);
387 WXOLE_WARN(hret
, "m_oleInPlaceObject->GetWindow(&m_oleObjectHWND)");
389 ::SetActiveWindow(m_oleObjectHWND
);
393 if (! (dwMiscStatus
& OLEMISC_INVISIBLEATRUNTIME
))
395 if (w
> 0 && h
> 0 && m_oleInPlaceObject
.Ok())
396 m_oleInPlaceObject
->SetObjectRects(&posRect
, &posRect
);
398 hret
= m_oleObject
->DoVerb(OLEIVERB_INPLACEACTIVATE
, NULL
, m_clientSite
, 0, (HWND
)GetHWND(), &posRect
);
399 hret
= m_oleObject
->DoVerb(OLEIVERB_SHOW
, 0, m_clientSite
, 0, (HWND
)GetHWND(), &posRect
);
402 if (! m_oleObjectHWND
&& m_oleInPlaceObject
.Ok())
404 hret
= m_oleInPlaceObject
->GetWindow(&m_oleObjectHWND
);
405 WXOLE_WARN(hret
, "m_oleInPlaceObject->GetWindow(&m_oleObjectHWND)");
410 ::SetActiveWindow(m_oleObjectHWND
);
411 ::ShowWindow(m_oleObjectHWND
, SW_SHOW
);
413 // Update by GBR to resize older controls
415 szEvent
.m_size
= wxSize(w
, h
) ;
416 AddPendingEvent(szEvent
);
420 void wxActiveX::CreateActiveX(LPOLESTR progId
)
423 if (CLSIDFromProgID(progId
, &clsid
) != S_OK
)
426 CreateActiveX(clsid
);
429 ////////////////////////////////////////////////////////////////////////////////////////////////////////////
430 // Case Insensitive Map of Event names to eventTypes
431 // created dynamically at run time in:
432 // EVT_ACTIVEX(eventName, id, fn)
433 // we map the pointer to them so that:
434 // const wxEventType& RegisterActiveXEvent(wxString eventName);
435 // can return a const reference, which is neccessary for event tables
436 // probably should use a wxWindows hash table here, but I'm lazy ...
437 typedef map
<wxString
, wxEventType
*, NS_wxActiveX::less_wxStringI
> ActiveXNamedEventMap
;
438 static ActiveXNamedEventMap sg_NamedEventMap
;
440 const wxEventType
& RegisterActiveXEvent(const wxChar
*eventName
)
442 wxString ev
= eventName
;
443 ActiveXNamedEventMap::iterator it
= sg_NamedEventMap
.find(ev
);
444 if (it
== sg_NamedEventMap
.end())
446 wxEventType
*et
= new wxEventType(wxNewEventType());
447 sg_NamedEventMap
[ev
] = et
;
452 return *(it
->second
);
456 ////////////////////////////////////////////////////////////////////////////////////////////////////////////
457 // Map of Event DISPID's to eventTypes
458 // created dynamically at run time in:
459 // EVT_ACTIVEX(eventName, id, fn)
460 // we map the pointer to them so that:
461 // const wxEventType& RegisterActiveXEvent(wxString eventName);
462 // can return a const reference, which is neccessary for event tables
464 typedef map
<DISPID
, wxEventType
*> ActiveXDISPIDEventMap
;
465 static ActiveXDISPIDEventMap sg_dispIdEventMap
;
467 const wxEventType
& RegisterActiveXEvent(DISPID event
)
469 ActiveXDISPIDEventMap::iterator it
= sg_dispIdEventMap
.find(event
);
470 if (it
== sg_dispIdEventMap
.end())
472 wxEventType
*et
= new wxEventType(wxNewEventType());
473 sg_dispIdEventMap
[event
] = et
;
478 return *(it
->second
);
481 // one off class for automatic freeing of activeX eventtypes
482 class ActiveXEventMapFlusher
485 ~ActiveXEventMapFlusher()
488 ActiveXNamedEventMap::iterator it
= sg_NamedEventMap
.end();
489 while (it
!= sg_NamedEventMap
.end())
494 sg_NamedEventMap
.clear();
497 ActiveXDISPIDEventMap::iterator dit
= sg_dispIdEventMap
.end();
498 while (dit
!= sg_dispIdEventMap
.end())
503 sg_dispIdEventMap
.clear();
507 static ActiveXEventMapFlusher s_dummyActiveXEventMapFlusher
;
510 //////////////////////////////////////////////////////
511 VARTYPE
wxTypeToVType(const wxVariant
& v
)
513 wxString type
= v
.GetType();
514 if (type
== wxT("bool"))
516 else if (type
== wxT("char"))
518 else if (type
== wxT("datetime"))
520 else if (type
== wxT("double"))
522 else if (type
== wxT("list"))
524 else if (type
== wxT("long"))
526 else if (type
== wxT("string"))
528 else if (type
== wxT("stringlist"))
530 else if (type
== wxT("date"))
532 else if (type
== wxT("time"))
534 else if (type
== wxT("void*"))
535 return VT_VOID
| VT_BYREF
;
540 bool wxDateTimeToDATE(wxDateTime dt
, DATE
& d
)
543 memset(&st
, 0, sizeof(st
));
545 st
.wYear
= dt
.GetYear();
546 st
.wMonth
= dt
.GetMonth() + 1;
547 st
.wDay
= dt
.GetDay();
548 st
.wHour
= dt
.GetHour();
549 st
.wMinute
= dt
.GetMinute();
550 st
.wSecond
= dt
.GetSecond();
551 st
.wMilliseconds
= dt
.GetMillisecond();
552 return SystemTimeToVariantTime(&st
, &d
) != FALSE
;
555 bool wxDateTimeToVariant(wxDateTime dt
, VARIANTARG
& va
)
557 return wxDateTimeToDATE(dt
, va
.date
);
560 bool DATEToWxDateTime(DATE date
, wxDateTime
& dt
)
563 if (! VariantTimeToSystemTime(date
, &st
))
568 wxDateTime::Month(int(wxDateTime::Jan
) + st
.wMonth
- 1),
570 st
.wHour
, st
.wMinute
, st
.wSecond
, st
.wMilliseconds
);
575 bool VariantToWxDateTime(VARIANTARG va
, wxDateTime
& dt
)
577 HRESULT hr
= VariantChangeType(&va
, &va
, 0, VT_DATE
);
581 return DATEToWxDateTime(va
.date
, dt
);
584 bool MSWVariantToVariant(VARIANTARG
& va
, wxVariant
& vx
)
590 return false; // don't support arrays yet
603 return MSWVariantToVariant(*va
.pvarVal
, vx
);
607 VariantChangeType(&tmp
, &tmp
, 0, wxTypeToVType(vx
));
608 bool rc
= MSWVariantToVariant(tmp
, vx
);
617 vx
= (char) *va
.pbVal
;
626 vx
= (long) *va
.puiVal
;
628 vx
= (long) va
.uiVal
;
638 vx
= (long) *va
.pulVal
;
640 vx
= (long) va
.ulVal
;
662 vx
= (*va
.pboolVal
? true : false);
664 vx
= (va
.boolVal
? true : false);
669 return false; // what the hell is a CY ?
676 hr
= VarR8FromDec(va
.pdecVal
, &d
);
678 hr
= VarR8FromDec(&va
.decVal
, &d
);
681 return SUCCEEDED(hr
);
689 rc
= DATEToWxDateTime(*va
.pdate
, dt
);
691 rc
= VariantToWxDateTime(va
, dt
);
698 vx
= wxString(*va
.pbstrVal
);
700 vx
= wxString(va
.bstrVal
);
703 case VT_UNKNOWN
: // should do a custom wxVariantData for this
705 vx
= (void *) *va
.ppunkVal
;
707 vx
= (void *) va
.punkVal
;
710 case VT_DISPATCH
: // should do a custom wxVariantData for this
712 vx
= (void *) *va
.ppdispVal
;
714 vx
= (void *) va
.pdispVal
;
723 bool VariantToMSWVariant(const wxVariant
& vx
, VARIANTARG
& va
)
729 return false; // don't support arrays yet
741 return VariantToMSWVariant(vx
, *va
.pvarVal
);
744 va
.vt
= wxTypeToVType(vx
);
745 return VariantToMSWVariant(vx
, va
);
752 *va
.pbVal
= (char) vx
;
761 *va
.puiVal
= (long) vx
;
763 va
.uiVal
= (long) vx
;
773 *va
.pulVal
= (long) vx
;
775 va
.ulVal
= (long) vx
;
782 *va
.pfltVal
= (double) vx
;
784 va
.fltVal
= (double) vx
;
790 *va
.pdblVal
= (double) vx
;
792 va
.dblVal
= (double) vx
;
797 *va
.pboolVal
= ((bool) vx
) ? TRUE
: FALSE
;
799 va
.boolVal
= ((bool) vx
) ? TRUE
: FALSE
;
803 return false; // what the hell is a CY ?
807 return SUCCEEDED(VarDecFromR8(vx
, va
.pdecVal
));
809 return SUCCEEDED(VarDecFromR8(vx
, &va
.decVal
));
813 return wxDateTimeToDATE(vx
, *va
.pdate
);
815 return wxDateTimeToVariant(vx
,va
);
819 *va
.pbstrVal
= SysAllocString(vx
.GetString().wc_str(wxConvUTF8
));
821 va
.bstrVal
= SysAllocString(vx
.GetString().wc_str(wxConvUTF8
));
824 case VT_UNKNOWN
: // should do a custom wxVariantData for this
826 *va
.ppunkVal
= (IUnknown
*) (void *) vx
;
828 va
.punkVal
= (IUnknown
*) (void *) vx
;
831 case VT_DISPATCH
: // should do a custom wxVariantData for this
833 *va
.ppdispVal
= (IDispatch
*) (void *) vx
;
835 va
.pdispVal
= (IDispatch
*) (void *) vx
;
843 IMPLEMENT_CLASS(wxActiveXEvent
, wxCommandEvent
)
845 class wxActiveXEvents
: public IDispatch
848 DECLARE_OLE_UNKNOWN(wxActiveXEvents
);
851 wxActiveX
*m_activeX
;
855 friend bool wxActiveXEventsInterface(wxActiveXEvents
*self
, REFIID iid
, void **_interface
, const char *&desc
);
858 wxActiveXEvents(wxActiveX
*ax
) : m_activeX(ax
), m_haveCustomId(false) {}
859 wxActiveXEvents(wxActiveX
*ax
, REFIID iid
) : m_activeX(ax
), m_haveCustomId(true), m_customId(iid
) {}
860 virtual ~wxActiveXEvents()
865 STDMETHODIMP
GetIDsOfNames(REFIID r
, OLECHAR
** o
, unsigned int i
, LCID l
, DISPID
* d
)
870 STDMETHODIMP
GetTypeInfo(unsigned int i
, LCID l
, ITypeInfo
** t
)
875 STDMETHODIMP
GetTypeInfoCount(unsigned int* i
)
881 void DispatchEvent(wxActiveX::FuncX
&func
, const wxEventType
& eventType
, DISPPARAMS
* pDispParams
)
883 wxActiveXEvent event
;
884 event
.SetId(m_activeX
->GetId());
885 event
.SetEventType(eventType
);
886 event
.m_params
.NullList();
887 event
.m_params
.SetName(func
.name
);
893 // sometimes the pDispParams does not match the param info for a activex control
894 int nArg
= min(func
.params
.size(), pDispParams
->cArgs
);
895 for (int i
= nArg
- 1; i
>= 0; i
--)
897 VARIANTARG
& va
= pDispParams
->rgvarg
[i
];
898 wxActiveX::ParamX
&px
= func
.params
[nArg
- i
- 1];
902 MSWVariantToVariant(va
, vx
);
903 event
.m_params
.Append(vx
);
909 int nArg
= min(func
.params
.size(), pDispParams
->cArgs
);
910 m_activeX
->GetParent()->ProcessEvent(event
);
911 for (int i
= 0; i
< nArg
; i
++)
913 VARIANTARG
& va
= pDispParams
->rgvarg
[i
];
914 wxActiveX::ParamX
&px
= func
.params
[nArg
- i
- 1];
918 wxVariant
& vx
= event
.m_params
[nArg
- i
- 1];
920 VariantToMSWVariant(vx
, va
);
925 m_activeX
->GetParent()->AddPendingEvent(event
);
929 STDMETHODIMP
Invoke(DISPID dispIdMember
, REFIID riid
, LCID lcid
,
930 WORD wFlags
, DISPPARAMS
* pDispParams
,
931 VARIANT
* pVarResult
, EXCEPINFO
* pExcepInfo
,
932 unsigned int * puArgErr
)
934 if (wFlags
& (DISPATCH_PROPERTYGET
| DISPATCH_PROPERTYPUT
| DISPATCH_PROPERTYPUTREF
))
939 // find event for dispid
940 wxActiveX::MemberIdMap::iterator mit
= m_activeX
->m_eventMemberIds
.find((MEMBERID
) dispIdMember
);
941 if (mit
== m_activeX
->m_eventMemberIds
.end())
945 int midx
= mit
->second
;
946 if (midx
< 0 || midx
>= m_activeX
->GetEventCount())
949 wxActiveX::FuncX
&func
= m_activeX
->m_events
[midx
];
952 // try to find dispid event
953 ActiveXDISPIDEventMap::iterator dit
= sg_dispIdEventMap
.find(dispIdMember
);
954 if (dit
!= sg_dispIdEventMap
.end())
957 DispatchEvent(func
, *(dit
->second
), pDispParams
);
962 ActiveXNamedEventMap::iterator nit
= sg_NamedEventMap
.find(func
.name
);
963 if (nit
== sg_NamedEventMap
.end())
967 DispatchEvent(func
, *(nit
->second
), pDispParams
);
972 bool wxActiveXEventsInterface(wxActiveXEvents
*self
, REFIID iid
, void **_interface
, const char *&desc
)
974 if (self
->m_haveCustomId
&& IsEqualIID(iid
, self
->m_customId
))
976 WXOLE_TRACE("Found Custom Dispatch Interface");
977 *_interface
= (IUnknown
*) (IDispatch
*) self
;
978 desc
= "Custom Dispatch Interface";
985 DEFINE_OLE_TABLE(wxActiveXEvents
)
986 OLE_IINTERFACE(IUnknown
)
987 OLE_INTERFACE(IID_IDispatch
, IDispatch
)
988 OLE_INTERFACE_CUSTOM(wxActiveXEventsInterface
)
991 wxString
wxActiveXEvent::EventName()
993 return m_params
.GetName();
996 int wxActiveXEvent::ParamCount() const
998 return m_params
.GetCount();
1001 wxString
wxActiveXEvent::ParamType(int idx
)
1003 wxASSERT(idx
>= 0 && idx
< m_params
.GetCount());
1005 return m_params
[idx
].GetType();
1008 wxString
wxActiveXEvent::ParamName(int idx
)
1010 wxASSERT(idx
>= 0 && idx
< m_params
.GetCount());
1012 return m_params
[idx
].GetName();
1015 static wxVariant nullVar
;
1017 wxVariant
& wxActiveXEvent::operator[] (int idx
)
1019 wxASSERT(idx
>= 0 && idx
< ParamCount());
1021 return m_params
[idx
];
1024 wxVariant
& wxActiveXEvent::operator[] (wxString name
)
1026 for (int i
= 0; i
< m_params
.GetCount(); i
++)
1028 if (name
.CmpNoCase(m_params
[i
].GetName()) == 0)
1032 wxString err
= _T("wxActiveXEvent::operator[] invalid name <") + name
+ _T(">");
1033 err
+= _T("\r\nValid Names = :\r\n");
1034 for (i
= 0; i
< m_params
.GetCount(); i
++)
1036 err
+= m_params
[i
].GetName();
1040 wxASSERT_MSG(false, err
);
1045 void wxActiveX::GetTypeInfo()
1048 We are currently only interested in the IDispatch interface
1049 to the control. For dual interfaces (TypeKind = TKIND_INTERFACE)
1050 we should drill down through the inheritance
1051 (using TYPEATTR->cImplTypes) and GetRefTypeOfImplType(n)
1052 and retrieve all the func names etc that way, then generate a C++
1055 But we don't do this and probably never will, so if we have a DUAL
1056 interface then we query for the IDispatch
1057 via GetRefTypeOfImplType(-1).
1062 // get type info via class info
1063 wxAutoOleInterface
<IProvideClassInfo
> classInfo(IID_IProvideClassInfo
, m_ActiveX
);
1064 if (! classInfo
.Ok())
1068 wxAutoOleInterface
<ITypeInfo
> typeInfo
;
1069 hret
= classInfo
->GetClassInfo(typeInfo
.GetRef());
1070 if (! typeInfo
.Ok())
1074 TYPEATTR
*ta
= NULL
;
1075 hret
= typeInfo
->GetTypeAttr(&ta
);
1079 // this should be a TKIND_COCLASS
1080 wxASSERT(ta
->typekind
== TKIND_COCLASS
);
1082 // iterate contained interfaces
1083 for (int i
= 0; i
< ta
->cImplTypes
; i
++)
1087 // get dispatch type info handle
1088 hret
= typeInfo
->GetRefTypeOfImplType(i
, &rt
);
1089 if (! SUCCEEDED(hret
))
1092 // get dispatch type info interface
1093 wxAutoOleInterface
<ITypeInfo
> ti
;
1094 hret
= typeInfo
->GetRefTypeInfo(rt
, ti
.GetRef());
1098 // check if default event sink
1099 bool defInterface
= false;
1100 bool defEventSink
= false;
1101 int impTypeFlags
= 0;
1102 typeInfo
->GetImplTypeFlags(i
, &impTypeFlags
);
1104 if (impTypeFlags
& IMPLTYPEFLAG_FDEFAULT
)
1106 if (impTypeFlags
& IMPLTYPEFLAG_FSOURCE
)
1108 WXOLE_TRACEOUT("Default Event Sink");
1109 defEventSink
= true;
1110 if (impTypeFlags
& IMPLTYPEFLAG_FDEFAULTVTABLE
)
1112 WXOLE_TRACEOUT("*ERROR* - Default Event Sink is via vTable");
1113 defEventSink
= false;
1118 WXOLE_TRACEOUT("Default Interface");
1119 defInterface
= true;
1125 GetTypeInfo(ti
, defInterface
, defEventSink
);
1130 typeInfo
->ReleaseTypeAttr(ta
);
1133 void ElemDescToParam(const ELEMDESC
& ed
, wxActiveX::ParamX
& param
)
1135 param
.flags
= ed
.idldesc
.wIDLFlags
;
1136 param
.vt
= ed
.tdesc
.vt
;
1137 param
.isPtr
= (param
.vt
== VT_PTR
);
1138 param
.isSafeArray
= (param
.vt
== VT_SAFEARRAY
);
1139 if (param
.isPtr
|| param
.isSafeArray
)
1140 param
.vt
= ed
.tdesc
.lptdesc
->vt
;
1143 void wxActiveX::GetTypeInfo(ITypeInfo
*ti
, bool defInterface
, bool defEventSink
)
1145 // wxAutoOleInterface<> assumes a ref has already been added
1147 wxAutoOleInterface
<ITypeInfo
> typeInfo(ti
);
1150 TYPEATTR
*ta
= NULL
;
1151 HRESULT hret
= typeInfo
->GetTypeAttr(&ta
);
1155 if (ta
->typekind
== TKIND_DISPATCH
)
1157 WXOLE_TRACEOUT("GUID = " << GetIIDName(ta
->guid
).c_str());
1161 wxActiveXEvents
*disp
= new wxActiveXEvents(this, ta
->guid
);
1162 ConnectAdvise(ta
->guid
, disp
);
1166 // Get Function Names
1167 for (int i
= 0; i
< ta
->cFuncs
; i
++)
1169 FUNCDESC FAR
*fd
= NULL
;
1171 hret
= typeInfo
->GetFuncDesc(i
, &fd
);
1175 BSTR anames
[1] = {NULL
};
1178 hret
= typeInfo
->GetNames(fd
->memid
, anames
, 1, &n
);
1182 wxString name
= anames
[0];
1184 WXOLE_TRACEOUT("Name " << i
<< " = " << name
.c_str());
1185 SysFreeString(anames
[0]);
1187 if (defInterface
|| defEventSink
)
1191 func
.memid
= fd
->memid
;
1192 func
.hasOut
= false;
1195 unsigned int maxPNames
= fd
->cParams
+ 1;
1196 unsigned int nPNames
= 0;
1197 BSTR
*pnames
= new BSTR
[maxPNames
];
1199 hret
= typeInfo
->GetNames(fd
->memid
, pnames
, maxPNames
, &nPNames
);
1202 if (fd
->cParams
< int(nPNames
))
1205 SysFreeString(pnames
[0]);
1209 ElemDescToParam(fd
->elemdescFunc
, func
.retType
);
1210 for (int p
= 0; p
< fd
->cParams
; p
++)
1214 ElemDescToParam(fd
->lprgelemdescParam
[p
], param
);
1216 param
.name
= pnames
[pbase
+ p
];
1217 SysFreeString(pnames
[pbase
+ p
]);
1219 param
.isOptional
= (p
> fd
->cParams
- fd
->cParamsOpt
);
1221 func
.hasOut
|= (param
.IsOut() || param
.isPtr
);
1222 func
.params
.push_back(param
);
1228 m_events
.push_back(func
);
1229 m_eventMemberIds
[fd
->memid
] = m_events
.size() - 1;
1233 if (fd
->invkind
== INVOKE_FUNC
)
1235 m_methods
.push_back(func
);
1236 m_methodNames
[func
.name
] = m_methods
.size() - 1;
1240 NameMap::iterator it
= m_propNames
.find(func
.name
);
1242 if (it
== m_propNames
.end())
1244 m_props
.push_back(PropX());
1245 idx
= m_props
.size() - 1;
1246 m_propNames
[func
.name
] = idx
;
1247 m_props
[idx
].name
= func
.name
;
1248 m_props
[idx
].memid
= func
.memid
;
1254 if (fd
->invkind
== INVOKE_PROPERTYGET
)
1255 m_props
[idx
].type
= func
.retType
;
1256 else if (func
.params
.size() > 0)
1258 m_props
[idx
].arg
= func
.params
[0];
1259 m_props
[idx
].putByRef
= (fd
->invkind
== INVOKE_PROPERTYPUTREF
);
1266 typeInfo
->ReleaseFuncDesc(fd
);
1270 typeInfo
->ReleaseTypeAttr(ta
);
1273 ///////////////////////////////////////////////
1274 // Type Info exposure
1275 const wxActiveX::FuncX
& wxActiveX::GetEventDesc(int idx
) const
1277 wxASSERT(idx
>= 0 && idx
< GetEventCount());
1279 return m_events
[idx
];
1282 const wxActiveX::PropX
& wxActiveX::GetPropDesc(int idx
) const
1284 if (idx
< 0 || idx
>= GetPropCount())
1285 throw exception("Property index out of bounds");
1287 return m_props
[idx
];
1290 const wxActiveX::PropX
& wxActiveX::GetPropDesc(const wxString
& name
) const
1292 NameMap::const_iterator it
= m_propNames
.find(name
);
1293 if (it
== m_propNames
.end())
1296 s
<< _T("property <") << name
<< _T("> not found");
1297 throw exception(s
.mb_str());
1300 return GetPropDesc(it
->second
);
1303 const wxActiveX::FuncX
& wxActiveX::GetMethodDesc(int idx
) const
1305 if (idx
< 0 || idx
>= GetMethodCount())
1306 throw exception("Method index out of bounds");
1309 return m_methods
[idx
];
1313 const wxActiveX::FuncX
& wxActiveX::GetMethodDesc(const wxString
& name
) const
1315 NameMap::const_iterator it
= m_methodNames
.find(name
);
1316 if (it
== m_methodNames
.end())
1319 s
<< _T("method <") << name
<< _T("> not found");
1320 throw exception(s
.mb_str());
1323 return GetMethodDesc(it
->second
);
1327 void wxActiveX::SetProp(MEMBERID name
, VARIANTARG
& value
)
1329 DISPID pids
[1] = {DISPID_PROPERTYPUT
};
1330 DISPPARAMS params
= {&value
, pids
, 1, 1};
1333 memset(&x
, 0, sizeof(x
));
1334 unsigned int argErr
= 0;
1336 HRESULT hr
= m_Dispatch
->Invoke(
1338 IID_NULL
, LOCALE_USER_DEFAULT
, DISPATCH_PROPERTYPUT
,
1339 ¶ms
, NULL
, &x
, &argErr
);
1341 WXOLE_WARN(hr
, "Invoke Prop(...)");
1344 void wxActiveX::SetProp(const wxString
&name
, const wxVariant
&value
)
1346 const PropX
& prop
= GetPropDesc(name
);
1347 if (! prop
.CanSet())
1350 s
<< _T("property <") << name
<< _T("> is readonly");
1351 throw exception(s
.mb_str());
1354 VARIANT v
= {prop
.arg
.vt
};
1355 VariantToMSWVariant(value
, v
);
1356 SetProp(prop
.memid
, v
);
1357 VariantClear(&v
); // this releases any BSTR's etc
1360 VARIANT
wxActiveX::GetPropAsVariant(MEMBERID name
)
1365 DISPPARAMS params
= {NULL
, NULL
, 0, 0};
1368 memset(&x
, 0, sizeof(x
));
1369 unsigned int argErr
= 0;
1371 HRESULT hr
= m_Dispatch
->Invoke(
1373 IID_NULL
, LOCALE_USER_DEFAULT
, DISPATCH_PROPERTYGET
,
1374 ¶ms
, &v
, &x
, &argErr
);
1376 WXOLE_WARN(hr
, "Invoke Prop(...)");
1381 VARIANT
wxActiveX::GetPropAsVariant(const wxString
& name
)
1383 const PropX
& prop
= GetPropDesc(name
);
1384 if (! prop
.CanGet())
1387 s
<< _T("property <") << name
<< _T("> is writeonly");
1388 throw exception(s
.mb_str());
1391 return GetPropAsVariant(prop
.memid
);
1394 wxVariant
wxActiveX::GetPropAsWxVariant(const wxString
& name
)
1396 VARIANT v
= GetPropAsVariant(name
);
1397 HRESULT hr
= VariantChangeType(&v
, &v
, 0, VT_BSTR
);
1398 if (! SUCCEEDED(hr
))
1399 throw exception("Unable to convert variant");
1402 MSWVariantToVariant(v
, wv
);
1409 wxString
wxActiveX::GetPropAsString(const wxString
& name
)
1411 VARIANT v
= GetPropAsVariant(name
);
1412 HRESULT hr
= VariantChangeType(&v
, &v
, 0, VT_BSTR
);
1413 if (! SUCCEEDED(hr
))
1414 throw exception("Unable to convert variant");
1416 wxString s
= v
.bstrVal
;
1422 char wxActiveX::GetPropAsChar(const wxString
& name
)
1424 VARIANT v
= GetPropAsVariant(name
);
1425 HRESULT hr
= VariantChangeType(&v
, &v
, 0, VT_I1
);
1426 if (! SUCCEEDED(hr
))
1427 throw exception("Unable to convert variant");
1432 long wxActiveX::GetPropAsLong(const wxString
& name
)
1434 VARIANT v
= GetPropAsVariant(name
);
1435 HRESULT hr
= VariantChangeType(&v
, &v
, 0, VT_I4
);
1436 if (! SUCCEEDED(hr
))
1437 throw exception("Unable to convert variant");
1442 bool wxActiveX::GetPropAsBool(const wxString
& name
)
1444 VARIANT v
= GetPropAsVariant(name
);
1445 HRESULT hr
= VariantChangeType(&v
, &v
, 0, VT_BOOL
);
1446 if (! SUCCEEDED(hr
))
1447 throw exception("Unable to convert variant");
1449 return v
.boolVal
!= 0;
1452 double wxActiveX::GetPropAsDouble(const wxString
& name
)
1454 VARIANT v
= GetPropAsVariant(name
);
1455 HRESULT hr
= VariantChangeType(&v
, &v
, 0, VT_R8
);
1456 if (! SUCCEEDED(hr
))
1457 throw exception("Unable to convert variant");
1462 wxDateTime
wxActiveX::GetPropAsDateTime(const wxString
& name
)
1465 VARIANT v
= GetPropAsVariant(name
);
1467 if (! VariantToWxDateTime(v
, dt
))
1468 throw exception("Unable to convert variant to wxDateTime");
1473 void *wxActiveX::GetPropAsPointer(const wxString
& name
)
1475 VARIANT v
= GetPropAsVariant(name
);
1476 HRESULT hr
= VariantChangeType(&v
, &v
, 0, VT_BYREF
);
1477 if (! SUCCEEDED(hr
))
1478 throw exception("Unable to convert variant");
1486 VARIANT
wxActiveX::CallMethod(MEMBERID name
, VARIANTARG args
[], int argc
)
1488 DISPPARAMS pargs
= {args
, NULL
, argc
, 0};
1490 VariantInit(&retVal
);
1493 memset(&x
, 0, sizeof(x
));
1494 unsigned int argErr
= 0;
1496 HRESULT hr
= m_Dispatch
->Invoke(
1498 IID_NULL
, LOCALE_USER_DEFAULT
, DISPATCH_METHOD
,
1499 &pargs
, &retVal
, &x
, &argErr
);
1501 WXOLE_WARN(hr
, "Invoke Method(...)");
1505 VARIANT
wxActiveX::CallMethod(const wxString
& name
, VARIANTARG args
[], int argc
)
1507 const FuncX
& func
= GetMethodDesc(name
);
1509 argc
= func
.params
.size();
1511 return CallMethod(func
.memid
, args
, argc
);
1515 wxVariant
wxActiveX::CallMethod(const wxString
& name
, wxVariant args
[], int nargs
)
1517 const FuncX
& func
= GetMethodDesc(name
);
1522 VARIANTARG
*vargs
= NULL
;
1524 nargs
= func
.params
.size();
1527 vargs
= new VARIANTARG
[nargs
];
1531 // init type of vargs
1532 for (int i
= 0; i
< nargs
; i
++)
1533 vargs
[nargs
- i
- 1].vt
= func
.params
[i
].vt
;
1536 for (i
= 0; i
< nargs
; i
++)
1537 VariantToMSWVariant(args
[i
], vargs
[nargs
- i
- 1]);
1540 VARIANT rv
= CallMethod(func
.memid
, vargs
, nargs
);
1542 // process any by ref params
1545 for (int i
= 0; i
< nargs
; i
++)
1547 VARIANTARG
& va
= vargs
[nargs
- i
- 1];
1548 const wxActiveX::ParamX
&px
= func
.params
[i
];
1552 wxVariant
& vx
= args
[i
];
1554 MSWVariantToVariant(va
, vx
);
1561 for (int i
= 0; i
< nargs
; i
++)
1562 VariantClear(&vargs
[i
]);
1568 MSWVariantToVariant(rv
, ret
);
1575 ///////////////////////////////////////////////
1577 HRESULT
wxActiveX::ConnectAdvise(REFIID riid
, IUnknown
*events
)
1579 wxOleConnectionPoint cp
;
1580 DWORD adviseCookie
= 0;
1582 wxAutoOleInterface
<IConnectionPointContainer
> cpContainer(IID_IConnectionPointContainer
, m_ActiveX
);
1583 if (! cpContainer
.Ok())
1586 HRESULT hret
= cpContainer
->FindConnectionPoint(riid
, cp
.GetRef());
1587 if (! SUCCEEDED(hret
))
1590 hret
= cp
->Advise(events
, &adviseCookie
);
1592 if (SUCCEEDED(hret
))
1593 m_connections
.push_back(wxOleConnection(cp
, adviseCookie
));
1596 WXOLE_WARN(hret
, "ConnectAdvise");
1602 HRESULT
wxActiveX::AmbientPropertyChanged(DISPID dispid
)
1604 wxAutoOleInterface
<IOleControl
> oleControl(IID_IOleControl
, m_oleObject
);
1606 if (oleControl
.Ok())
1607 return oleControl
->OnAmbientPropertyChange(dispid
);
1612 #define HIMETRIC_PER_INCH 2540
1613 #define MAP_PIX_TO_LOGHIM(x,ppli) MulDiv(HIMETRIC_PER_INCH, (x), (ppli))
1615 static void PixelsToHimetric(SIZEL
&sz
)
1617 static int logX
= 0;
1618 static int logY
= 0;
1623 HDC dc
= GetDC(NULL
);
1624 logX
= GetDeviceCaps(dc
, LOGPIXELSX
);
1625 logY
= GetDeviceCaps(dc
, LOGPIXELSY
);
1626 ReleaseDC(NULL
, dc
);
1629 #define HIMETRIC_INCH 2540
1630 #define CONVERT(x, logpixels) MulDiv(HIMETRIC_INCH, (x), (logpixels))
1632 sz
.cx
= CONVERT(sz
.cx
, logX
);
1633 sz
.cy
= CONVERT(sz
.cy
, logY
);
1636 #undef HIMETRIC_INCH
1640 void wxActiveX::OnSize(wxSizeEvent
& event
)
1643 GetClientSize(&w
, &h
);
1651 if (w
<= 0 && h
<= 0)
1654 // extents are in HIMETRIC units
1655 if (m_oleObject
.Ok())
1658 PixelsToHimetric(sz
);
1662 m_oleObject
->GetExtent(DVASPECT_CONTENT
, &sz2
);
1663 if (sz2
.cx
!= sz
.cx
|| sz
.cy
!= sz2
.cy
)
1664 m_oleObject
->SetExtent(DVASPECT_CONTENT
, &sz
);
1667 if (m_oleInPlaceObject
.Ok())
1668 m_oleInPlaceObject
->SetObjectRects(&posRect
, &posRect
);
1671 void wxActiveX::OnPaint(wxPaintEvent
& event
)
1673 wxLogTrace(wxT(""),wxT("repainting activex win"));
1684 // Draw only when control is windowless or deactivated
1687 ::RedrawWindow(m_oleObjectHWND
, NULL
, NULL
, RDW_INTERNALPAINT
);
1689 RECTL
*prcBounds
= (RECTL
*) &posRect
;
1690 m_viewObject
->Draw(DVASPECT_CONTENT
, -1, NULL
, NULL
, NULL
,
1691 (HDC
)dc
.GetHDC(), prcBounds
, NULL
, NULL
, 0);
1696 dc
.SetBrush(*wxRED_BRUSH
);
1697 dc
.DrawRectangle(0, 0, w
, h
);
1698 dc
.SetBrush(wxNullBrush
);
1704 void wxActiveX::OnMouse(wxMouseEvent
& event
)
1706 if (m_oleObjectHWND
== NULL
)
1708 wxLogTrace(wxT(""),wxT("no oleInPlaceObject"));
1713 wxLogTrace(wxT(""),wxT("mouse event"));
1717 LRESULT lResult
= 0;
1719 if (event
.m_metaDown
)
1720 wParam
|= MK_CONTROL
;
1721 if (event
.m_shiftDown
)
1723 if (event
.m_leftDown
)
1724 wParam
|= MK_LBUTTON
;
1725 if (event
.m_middleDown
)
1726 wParam
|= MK_MBUTTON
;
1727 if (event
.m_rightDown
)
1728 wParam
|= MK_RBUTTON
;
1729 lParam
= event
.m_x
<< 16;
1730 lParam
|= event
.m_y
;
1732 if (event
.LeftDown())
1733 msg
= WM_LBUTTONDOWN
;
1734 else if (event
.LeftDClick())
1735 msg
= WM_LBUTTONDBLCLK
;
1736 else if (event
.LeftUp())
1738 else if (event
.MiddleDown())
1739 msg
= WM_MBUTTONDOWN
;
1740 else if (event
.MiddleDClick())
1741 msg
= WM_MBUTTONDBLCLK
;
1742 else if (event
.MiddleUp())
1744 else if (event
.RightDown())
1745 msg
= WM_RBUTTONDOWN
;
1746 else if (event
.RightDClick())
1747 msg
= WM_RBUTTONDBLCLK
;
1748 else if (event
.RightUp())
1750 else if (event
.Moving() || event
.Dragging())
1756 wxLogTrace(wxT(""),wxT("no message"));
1757 event
.Skip(); return;
1760 if (!::SendMessage(m_oleObjectHWND
, msg
, wParam
, lParam
))
1762 wxLogTrace(wxT(""),wxT("msg not delivered"));
1767 wxLogTrace(wxT(""),wxT("msg sent"));
1770 long wxActiveX::MSWWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
1772 if (m_oleObjectHWND
== NULL
)
1773 return wxWindow::MSWWindowProc(nMsg
, wParam
, lParam
);
1782 case WM_SYSDEADCHAR
:
1785 PostMessage(m_oleObjectHWND
, nMsg
, wParam
, lParam
);
1788 return wxWindow::MSWWindowProc(nMsg
, wParam
, lParam
);
1792 void wxActiveX::OnSetFocus(wxFocusEvent
& event
)
1794 if (m_oleInPlaceActiveObject
.Ok())
1795 m_oleInPlaceActiveObject
->OnFrameWindowActivate(TRUE
);
1798 void wxActiveX::OnKillFocus(wxFocusEvent
& event
)
1800 if (m_oleInPlaceActiveObject
.Ok())
1801 m_oleInPlaceActiveObject
->OnFrameWindowActivate(FALSE
);
1805 FrameSite::FrameSite(wxActiveX
* win
)
1808 m_bSupportsWindowlessActivation
= true;
1809 m_bInPlaceLocked
= false;
1810 m_bUIActive
= false;
1811 m_bInPlaceActive
= false;
1812 m_bWindowless
= false;
1814 m_nAmbientLocale
= 0;
1815 m_clrAmbientForeColor
= ::GetSysColor(COLOR_WINDOWTEXT
);
1816 m_clrAmbientBackColor
= ::GetSysColor(COLOR_WINDOW
);
1817 m_bAmbientShowHatching
= true;
1818 m_bAmbientShowGrabHandles
= true;
1819 m_bAmbientAppearance
= true;
1822 m_hWndParent
= (HWND
)m_window
->GetHWND();
1825 FrameSite::~FrameSite()
1832 HRESULT
FrameSite::GetIDsOfNames(REFIID riid
, OLECHAR
** rgszNames
, unsigned int cNames
,
1833 LCID lcid
, DISPID
* rgDispId
)
1835 WXOLE_TRACE("IDispatch::GetIDsOfNames");
1839 HRESULT
FrameSite::GetTypeInfo(unsigned int iTInfo
, LCID lcid
, ITypeInfo
** ppTInfo
)
1841 WXOLE_TRACE("IDispatch::GetTypeInfo");
1845 HRESULT
FrameSite::GetTypeInfoCount(unsigned int * pcTInfo
)
1847 WXOLE_TRACE("IDispatch::GetTypeInfoCount");
1851 HRESULT
FrameSite::Invoke(DISPID dispIdMember
, REFIID riid
, LCID lcid
,
1852 WORD wFlags
, DISPPARAMS
* pDispParams
,
1853 VARIANT
* pVarResult
, EXCEPINFO
* pExcepInfo
,
1854 unsigned int * puArgErr
)
1856 WXOLE_TRACE("IDispatch::Invoke");
1858 if (!(wFlags
& DISPATCH_PROPERTYGET
))
1863 if (pVarResult
== NULL
)
1864 return E_INVALIDARG
;
1866 //The most common case is boolean, use as an initial type
1867 V_VT(pVarResult
) = VT_BOOL
;
1869 switch (dispIdMember
)
1871 case DISPID_AMBIENT_MESSAGEREFLECT
:
1872 WXOLE_TRACE("Invoke::DISPID_AMBIENT_MESSAGEREFLECT");
1873 V_BOOL(pVarResult
)= FALSE
;
1876 case DISPID_AMBIENT_DISPLAYASDEFAULT
:
1877 WXOLE_TRACE("Invoke::DISPID_AMBIENT_DISPLAYASDEFAULT");
1878 V_BOOL(pVarResult
)= TRUE
;
1881 case DISPID_AMBIENT_OFFLINEIFNOTCONNECTED
:
1882 WXOLE_TRACE("Invoke::DISPID_AMBIENT_OFFLINEIFNOTCONNECTED");
1883 V_BOOL(pVarResult
) = TRUE
;
1887 case DISPID_AMBIENT_SILENT
:
1888 WXOLE_TRACE("Invoke::DISPID_AMBIENT_SILENT");
1889 V_BOOL(pVarResult
)= TRUE
;
1892 case DISPID_AMBIENT_APPEARANCE
:
1893 pVarResult
->vt
= VT_BOOL
;
1894 pVarResult
->boolVal
= m_bAmbientAppearance
;
1897 case DISPID_AMBIENT_FORECOLOR
:
1898 pVarResult
->vt
= VT_I4
;
1899 pVarResult
->lVal
= (long) m_clrAmbientForeColor
;
1902 case DISPID_AMBIENT_BACKCOLOR
:
1903 pVarResult
->vt
= VT_I4
;
1904 pVarResult
->lVal
= (long) m_clrAmbientBackColor
;
1907 case DISPID_AMBIENT_LOCALEID
:
1908 pVarResult
->vt
= VT_I4
;
1909 pVarResult
->lVal
= (long) m_nAmbientLocale
;
1912 case DISPID_AMBIENT_USERMODE
:
1913 pVarResult
->vt
= VT_BOOL
;
1914 pVarResult
->boolVal
= m_window
->m_bAmbientUserMode
;
1917 case DISPID_AMBIENT_SHOWGRABHANDLES
:
1918 pVarResult
->vt
= VT_BOOL
;
1919 pVarResult
->boolVal
= m_bAmbientShowGrabHandles
;
1922 case DISPID_AMBIENT_SHOWHATCHING
:
1923 pVarResult
->vt
= VT_BOOL
;
1924 pVarResult
->boolVal
= m_bAmbientShowHatching
;
1928 return DISP_E_MEMBERNOTFOUND
;
1936 HRESULT
FrameSite::GetWindow(HWND
* phwnd
)
1938 WXOLE_TRACE("IOleWindow::GetWindow");
1940 return E_INVALIDARG
;
1941 (*phwnd
) = m_hWndParent
;
1945 HRESULT
FrameSite::ContextSensitiveHelp(BOOL fEnterMode
)
1947 WXOLE_TRACE("IOleWindow::ContextSensitiveHelp");
1951 //IOleInPlaceUIWindow
1953 HRESULT
FrameSite::GetBorder(LPRECT lprectBorder
)
1955 WXOLE_TRACE("IOleInPlaceUIWindow::GetBorder");
1956 if (lprectBorder
== NULL
)
1957 return E_INVALIDARG
;
1958 return INPLACE_E_NOTOOLSPACE
;
1961 HRESULT
FrameSite::RequestBorderSpace(LPCBORDERWIDTHS pborderwidths
)
1963 WXOLE_TRACE("IOleInPlaceUIWindow::RequestBorderSpace");
1964 if (pborderwidths
== NULL
)
1965 return E_INVALIDARG
;
1966 return INPLACE_E_NOTOOLSPACE
;
1969 HRESULT
FrameSite::SetBorderSpace(LPCBORDERWIDTHS pborderwidths
)
1971 WXOLE_TRACE("IOleInPlaceUIWindow::SetBorderSpace");
1975 HRESULT
FrameSite::SetActiveObject(IOleInPlaceActiveObject
*pActiveObject
, LPCOLESTR pszObjName
)
1977 WXOLE_TRACE("IOleInPlaceUIWindow::SetActiveObject");
1980 pActiveObject
->AddRef();
1982 m_window
->m_oleInPlaceActiveObject
= pActiveObject
;
1988 HRESULT
FrameSite::InsertMenus(HMENU hmenuShared
, LPOLEMENUGROUPWIDTHS lpMenuWidths
)
1990 WXOLE_TRACE("IOleInPlaceFrame::InsertMenus");
1994 HRESULT
FrameSite::SetMenu(HMENU hmenuShared
, HOLEMENU holemenu
, HWND hwndActiveObject
)
1996 WXOLE_TRACE("IOleInPlaceFrame::SetMenu");
2000 HRESULT
FrameSite::RemoveMenus(HMENU hmenuShared
)
2002 WXOLE_TRACE("IOleInPlaceFrame::RemoveMenus");
2006 HRESULT
FrameSite::SetStatusText(LPCOLESTR pszStatusText
)
2008 WXOLE_TRACE("IOleInPlaceFrame::SetStatusText");
2009 //((wxFrame*)wxGetApp().GetTopWindow())->GetStatusBar()->SetStatusText(pszStatusText);
2013 HRESULT
FrameSite::EnableModeless(BOOL fEnable
)
2015 WXOLE_TRACE("IOleInPlaceFrame::EnableModeless");
2019 HRESULT
FrameSite::TranslateAccelerator(LPMSG lpmsg
, WORD wID
)
2021 WXOLE_TRACE("IOleInPlaceFrame::TranslateAccelerator");
2022 // TODO: send an event with this id
2023 if (m_window
->m_oleInPlaceActiveObject
.Ok())
2024 m_window
->m_oleInPlaceActiveObject
->TranslateAccelerator(lpmsg
);
2031 HRESULT
FrameSite::CanInPlaceActivate()
2033 WXOLE_TRACE("IOleInPlaceSite::CanInPlaceActivate");
2037 HRESULT
FrameSite::OnInPlaceActivate()
2039 WXOLE_TRACE("IOleInPlaceSite::OnInPlaceActivate");
2040 m_bInPlaceActive
= true;
2044 HRESULT
FrameSite::OnUIActivate()
2046 WXOLE_TRACE("IOleInPlaceSite::OnUIActivate");
2051 HRESULT
FrameSite::GetWindowContext(IOleInPlaceFrame
**ppFrame
,
2052 IOleInPlaceUIWindow
**ppDoc
,
2054 LPRECT lprcClipRect
,
2055 LPOLEINPLACEFRAMEINFO lpFrameInfo
)
2057 WXOLE_TRACE("IOleInPlaceSite::GetWindowContext");
2058 if (ppFrame
== NULL
|| ppDoc
== NULL
|| lprcPosRect
== NULL
||
2059 lprcClipRect
== NULL
|| lpFrameInfo
== NULL
)
2061 if (ppFrame
!= NULL
)
2065 return E_INVALIDARG
;
2068 HRESULT hr
= QueryInterface(IID_IOleInPlaceFrame
, (void **) ppFrame
);
2069 if (! SUCCEEDED(hr
))
2071 WXOLE_TRACE("IOleInPlaceSite::IOleInPlaceFrame Error !");
2072 return E_UNEXPECTED
;
2075 hr
= QueryInterface(IID_IOleInPlaceUIWindow
, (void **) ppDoc
);
2076 if (! SUCCEEDED(hr
))
2078 WXOLE_TRACE("IOleInPlaceSite::IOleInPlaceUIWindow Error !");
2079 (*ppFrame
)->Release();
2081 return E_UNEXPECTED
;
2085 m_window
->GetClientSize(&w
, &h
);
2088 lprcPosRect
->left
= lprcPosRect
->top
= 0;
2089 lprcPosRect
->right
= w
;
2090 lprcPosRect
->bottom
= h
;
2094 lprcClipRect
->left
= lprcClipRect
->top
= 0;
2095 lprcClipRect
->right
= w
;
2096 lprcClipRect
->bottom
= h
;
2099 memset(lpFrameInfo
, 0, sizeof(OLEINPLACEFRAMEINFO
));
2100 lpFrameInfo
->cb
= sizeof(OLEINPLACEFRAMEINFO
);
2101 lpFrameInfo
->hwndFrame
= m_hWndParent
;
2106 HRESULT
FrameSite::Scroll(SIZE scrollExtent
)
2108 WXOLE_TRACE("IOleInPlaceSite::Scroll");
2112 HRESULT
FrameSite::OnUIDeactivate(BOOL fUndoable
)
2114 WXOLE_TRACE("IOleInPlaceSite::OnUIDeactivate");
2115 m_bUIActive
= false;
2119 HRESULT
FrameSite::OnInPlaceDeactivate()
2121 WXOLE_TRACE("IOleInPlaceSite::OnInPlaceDeactivate");
2122 m_bInPlaceActive
= false;
2126 HRESULT
FrameSite::DiscardUndoState()
2128 WXOLE_TRACE("IOleInPlaceSite::DiscardUndoState");
2132 HRESULT
FrameSite::DeactivateAndUndo()
2134 WXOLE_TRACE("IOleInPlaceSite::DeactivateAndUndo");
2138 HRESULT
FrameSite::OnPosRectChange(LPCRECT lprcPosRect
)
2140 WXOLE_TRACE("IOleInPlaceSite::OnPosRectChange");
2141 if (m_window
->m_oleInPlaceObject
.Ok() && lprcPosRect
)
2142 m_window
->m_oleInPlaceObject
->SetObjectRects(lprcPosRect
, lprcPosRect
);
2149 HRESULT
FrameSite::OnInPlaceActivateEx(BOOL
* pfNoRedraw
, DWORD dwFlags
)
2151 WXOLE_TRACE("IOleInPlaceSiteEx::OnInPlaceActivateEx");
2152 OleLockRunning(m_window
->m_ActiveX
, TRUE
, FALSE
);
2154 (*pfNoRedraw
) = FALSE
;
2158 HRESULT
FrameSite::OnInPlaceDeactivateEx(BOOL fNoRedraw
)
2160 WXOLE_TRACE("IOleInPlaceSiteEx::OnInPlaceDeactivateEx");
2161 OleLockRunning(m_window
->m_ActiveX
, FALSE
, FALSE
);
2165 HRESULT
FrameSite::RequestUIActivate()
2167 WXOLE_TRACE("IOleInPlaceSiteEx::RequestUIActivate");
2174 HRESULT
FrameSite::SaveObject()
2176 WXOLE_TRACE("IOleClientSite::SaveObject");
2180 const char *OleGetMonikerToStr(DWORD dwAssign
)
2184 case OLEGETMONIKER_ONLYIFTHERE
: return "OLEGETMONIKER_ONLYIFTHERE";
2185 case OLEGETMONIKER_FORCEASSIGN
: return "OLEGETMONIKER_FORCEASSIGN";
2186 case OLEGETMONIKER_UNASSIGN
: return "OLEGETMONIKER_UNASSIGN";
2187 case OLEGETMONIKER_TEMPFORUSER
: return "OLEGETMONIKER_TEMPFORUSER";
2188 default : return "Bad Enum";
2192 const char *OleGetWhicMonikerStr(DWORD dwWhichMoniker
)
2194 switch(dwWhichMoniker
)
2196 case OLEWHICHMK_CONTAINER
: return "OLEWHICHMK_CONTAINER";
2197 case OLEWHICHMK_OBJREL
: return "OLEWHICHMK_OBJREL";
2198 case OLEWHICHMK_OBJFULL
: return "OLEWHICHMK_OBJFULL";
2199 default : return "Bad Enum";
2203 HRESULT
FrameSite::GetMoniker(DWORD dwAssign
, DWORD dwWhichMoniker
,
2206 WXOLE_TRACEOUT("IOleClientSite::GetMoniker(" << OleGetMonikerToStr(dwAssign
) << ", " << OleGetWhicMonikerStr(dwWhichMoniker
) << ")");
2213 HRESULT hr = CreateFileMoniker(L"e:\\dev\\wxie\\bug-zap.swf", ppmk);
2222 HRESULT
FrameSite::GetContainer(LPOLECONTAINER
* ppContainer
)
2224 WXOLE_TRACE("IOleClientSite::GetContainer");
2225 if (ppContainer
== NULL
)
2226 return E_INVALIDARG
;
2228 HRESULT hr
= QueryInterface(IID_IOleContainer
, (void**)(ppContainer
));
2229 wxASSERT(SUCCEEDED(hr
));
2234 HRESULT
FrameSite::ShowObject()
2236 WXOLE_TRACE("IOleClientSite::ShowObject");
2237 if (m_window
->m_oleObjectHWND
)
2238 ::ShowWindow(m_window
->m_oleObjectHWND
, SW_SHOW
);
2242 HRESULT
FrameSite::OnShowWindow(BOOL fShow
)
2244 WXOLE_TRACE("IOleClientSite::OnShowWindow");
2248 HRESULT
FrameSite::RequestNewObjectLayout()
2250 WXOLE_TRACE("IOleClientSite::RequestNewObjectLayout");
2254 // IParseDisplayName
2256 HRESULT
FrameSite::ParseDisplayName(IBindCtx
*pbc
, LPOLESTR pszDisplayName
,
2257 ULONG
*pchEaten
, IMoniker
**ppmkOut
)
2259 WXOLE_TRACE("IParseDisplayName::ParseDisplayName");
2265 HRESULT
FrameSite::EnumObjects(DWORD grfFlags
, IEnumUnknown
**ppenum
)
2267 WXOLE_TRACE("IOleContainer::EnumObjects");
2271 HRESULT
FrameSite::LockContainer(BOOL fLock
)
2273 WXOLE_TRACE("IOleContainer::LockContainer");
2280 HRESULT
FrameSite::GetObject(LPOLESTR pszItem
, DWORD dwSpeedNeeded
,
2281 IBindCtx
* pbc
, REFIID riid
, void ** ppvObject
)
2283 WXOLE_TRACE("IOleItemContainer::GetObject");
2284 if (pszItem
== NULL
)
2285 return E_INVALIDARG
;
2286 if (ppvObject
== NULL
)
2287 return E_INVALIDARG
;
2290 return MK_E_NOOBJECT
;
2293 HRESULT
FrameSite::GetObjectStorage(LPOLESTR pszItem
, IBindCtx
* pbc
,
2294 REFIID riid
, void ** ppvStorage
)
2296 WXOLE_TRACE("IOleItemContainer::GetObjectStorage");
2297 if (pszItem
== NULL
)
2298 return E_INVALIDARG
;
2299 if (ppvStorage
== NULL
)
2300 return E_INVALIDARG
;
2303 return MK_E_NOOBJECT
;
2306 HRESULT
FrameSite::IsRunning(LPOLESTR pszItem
)
2308 WXOLE_TRACE("IOleItemContainer::IsRunning");
2309 if (pszItem
== NULL
)
2310 return E_INVALIDARG
;
2312 return MK_E_NOOBJECT
;
2319 HRESULT
FrameSite::OnControlInfoChanged()
2321 WXOLE_TRACE("IOleControlSite::OnControlInfoChanged");
2325 HRESULT
FrameSite::LockInPlaceActive(BOOL fLock
)
2327 WXOLE_TRACE("IOleControlSite::LockInPlaceActive");
2328 m_bInPlaceLocked
= (fLock
) ? true : false;
2332 HRESULT
FrameSite::GetExtendedControl(IDispatch
** ppDisp
)
2334 WXOLE_TRACE("IOleControlSite::GetExtendedControl");
2338 HRESULT
FrameSite::TransformCoords(POINTL
* pPtlHimetric
, POINTF
* pPtfContainer
, DWORD dwFlags
)
2340 WXOLE_TRACE("IOleControlSite::TransformCoords");
2343 if (pPtlHimetric
== NULL
)
2344 return E_INVALIDARG
;
2346 if (pPtfContainer
== NULL
)
2347 return E_INVALIDARG
;
2353 HRESULT
FrameSite::TranslateAccelerator(LPMSG pMsg
, DWORD grfModifiers
)
2355 WXOLE_TRACE("IOleControlSite::TranslateAccelerator");
2356 // TODO: send an event with this id
2360 HRESULT
FrameSite::OnFocus(BOOL fGotFocus
)
2362 WXOLE_TRACE("IOleControlSite::OnFocus");
2366 HRESULT
FrameSite::ShowPropertyFrame()
2368 WXOLE_TRACE("IOleControlSite::ShowPropertyFrame");
2374 HRESULT
FrameSite::QueryStatus(const GUID
* pguidCmdGroup
, ULONG cCmds
,
2375 OLECMD
* prgCmds
, OLECMDTEXT
* pCmdTet
)
2377 WXOLE_TRACE("IOleCommandTarget::QueryStatus");
2378 if (prgCmds
== NULL
) return E_INVALIDARG
;
2379 bool bCmdGroupFound
= false;
2381 for (ULONG nCmd
= 0; nCmd
< cCmds
; nCmd
++)
2383 // unsupported by default
2384 prgCmds
[nCmd
].cmdf
= 0;
2389 if (!bCmdGroupFound
) { OLECMDERR_E_UNKNOWNGROUP
; }
2393 HRESULT
FrameSite::Exec(const GUID
* pguidCmdGroup
, DWORD nCmdID
,
2394 DWORD nCmdExecOpt
, VARIANTARG
* pVaIn
,
2395 VARIANTARG
* pVaOut
)
2397 WXOLE_TRACE("IOleCommandTarget::Exec");
2398 bool bCmdGroupFound
= false;
2400 if (!bCmdGroupFound
) { OLECMDERR_E_UNKNOWNGROUP
; }
2401 return OLECMDERR_E_NOTSUPPORTED
;
2406 void STDMETHODCALLTYPE
FrameSite::OnDataChange(FORMATETC
* pFormatEtc
, STGMEDIUM
* pgStgMed
)
2408 WXOLE_TRACE("IAdviseSink::OnDataChange");
2411 void STDMETHODCALLTYPE
FrameSite::OnViewChange(DWORD dwAspect
, LONG lIndex
)
2413 WXOLE_TRACE("IAdviseSink::OnViewChange");
2414 // redraw the control
2417 void STDMETHODCALLTYPE
FrameSite::OnRename(IMoniker
* pmk
)
2419 WXOLE_TRACE("IAdviseSink::OnRename");
2422 void STDMETHODCALLTYPE
FrameSite::OnSave()
2424 WXOLE_TRACE("IAdviseSink::OnSave");
2427 void STDMETHODCALLTYPE
FrameSite::OnClose()
2429 WXOLE_TRACE("IAdviseSink::OnClose");
2432 /////////////////////////////////////////////
2434 HRESULT STDMETHODCALLTYPE
FrameSite::ActivateMe(
2435 /* [in] */ IOleDocumentView __RPC_FAR
*pViewToActivate
)
2437 wxAutoOleInterface
<IOleInPlaceSite
> inPlaceSite(IID_IOleInPlaceSite
, (IDispatch
*) this);
2438 if (!inPlaceSite
.Ok())
2441 if (pViewToActivate
)
2443 m_window
->m_docView
= pViewToActivate
;
2444 m_window
->m_docView
->SetInPlaceSite(inPlaceSite
);
2448 wxAutoOleInterface
<IOleDocument
> oleDoc(IID_IOleDocument
, m_window
->m_oleObject
);
2452 HRESULT hr
= oleDoc
->CreateView(inPlaceSite
, NULL
, 0, m_window
->m_docView
.GetRef());
2456 m_window
->m_docView
->SetInPlaceSite(inPlaceSite
);
2459 m_window
->m_docView
->UIActivate(TRUE
);
2465 static IMalloc
*iMalloc
= NULL
;
2467 IMalloc
*wxOleInit::GetIMalloc()
2473 wxOleInit::wxOleInit()
2475 if (OleInitialize(NULL
) == S_OK
&& iMalloc
== NULL
)
2476 CoGetMalloc(1, &iMalloc
);
2481 wxOleInit::~wxOleInit()
2485 if (iMalloc
->Release() == 0)
2492 bool GetSysErrMessage(int err
, wxString
& s
)
2496 FORMAT_MESSAGE_FROM_SYSTEM
, NULL
,
2497 err
,0, buf
, sizeof(buf
), NULL
) == 0)
2500 buf
[sizeof(buf
) - 1] = 0;
2505 wxString
OLEHResultToString(HRESULT hr
)
2507 // try formatmessage
2509 if (GetSysErrMessage(hr
, err
))
2515 return wxEmptyString
;
2517 case CONNECT_E_CANNOTCONNECT
:
2518 return _T("Cannot connect to event interface (maybe not there ?) - see MSDN");
2520 case DISP_E_MEMBERNOTFOUND
:
2521 return _T("The requested member does not exist, or the call to Invoke tried to set the value of a read-only property.");
2523 case DISP_E_BADVARTYPE
:
2524 return _T("One of the parameters in rgvarg is not a valid variant type.");
2526 case DISP_E_BADPARAMCOUNT
:
2527 return _T("The number of elements provided to DISPPARAMS is different from the number of parameters accepted by the method or property");
2529 case DISP_E_EXCEPTION
:
2530 return _T("The application needs to raise an exception. In this case, the structure passed in pExcepInfo should be filled in.");
2532 case DISP_E_TYPEMISMATCH
:
2533 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.");
2535 case DISP_E_PARAMNOTOPTIONAL
:
2536 return _T("A required parameter was omitted.");
2538 case DISP_E_PARAMNOTFOUND
:
2539 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.");
2541 case OLECMDERR_E_UNKNOWNGROUP
:
2542 return _T("The pguidCmdGroup parameter is not NULL but does not specify a recognized command group.");
2544 case OLECMDERR_E_NOTSUPPORTED
:
2545 return _T("The nCmdID parameter is not a valid command in the group identified by pguidCmdGroup.");
2547 case OLECMDERR_E_DISABLED
:
2548 return _T("The command identified by nCmdID is currently disabled and cannot be executed.");
2550 case OLECMDERR_E_NOHELP
:
2551 return _T("The caller has asked for help on the command identified by nCmdID, but no help is available.");
2553 case OLECMDERR_E_CANCELED
:
2554 return _T("The user canceled the execution of the command.");
2557 return _T("E_INVALIDARG");
2560 return _T("E_OUTOFMEMORY");
2563 return _T("E_NOINTERFACE");
2566 return _T("E_UNEXPECTED");
2568 case STG_E_INVALIDFLAG
:
2569 return _T("STG_E_INVALIDFLAG");
2572 return _T("E_FAIL");
2575 return _T("E_NOTIMPL");
2580 buf
.Printf(_T("Unknown - 0x%X"), hr
);
2586 // borrowed from src/msw/ole/oleutils.cpp
2587 wxString
GetIIDName(REFIID riid
)
2589 // an association between symbolic name and numeric value of an IID
2593 const wxChar
*szName
;
2596 // construct the table containing all known interfaces
2597 #define ADD_KNOWN_IID(name) { &IID_I##name, _T(#name) }
2598 #define ADD_KNOWN_GUID(name) { &name, _T(#name) }
2600 static const KNOWN_IID aKnownIids
[] =
2602 ADD_KNOWN_IID(ServiceProvider
),
2603 ADD_KNOWN_IID(AdviseSink
),
2604 ADD_KNOWN_IID(AdviseSink2
),
2605 ADD_KNOWN_IID(BindCtx
),
2606 ADD_KNOWN_IID(ClassFactory
),
2607 #if ( !defined( __VISUALC__) || (__VISUALC__!=1010) ) && !defined(__MWERKS__)
2608 ADD_KNOWN_IID(ContinueCallback
),
2609 ADD_KNOWN_IID(EnumOleDocumentViews
),
2610 ADD_KNOWN_IID(OleCommandTarget
),
2611 ADD_KNOWN_IID(OleDocument
),
2612 ADD_KNOWN_IID(OleDocumentSite
),
2613 ADD_KNOWN_IID(OleDocumentView
),
2614 ADD_KNOWN_IID(Print
),
2616 ADD_KNOWN_IID(DataAdviseHolder
),
2617 ADD_KNOWN_IID(DataObject
),
2618 ADD_KNOWN_IID(Debug
),
2619 ADD_KNOWN_IID(DebugStream
),
2620 ADD_KNOWN_IID(DfReserved1
),
2621 ADD_KNOWN_IID(DfReserved2
),
2622 ADD_KNOWN_IID(DfReserved3
),
2623 ADD_KNOWN_IID(Dispatch
),
2624 ADD_KNOWN_IID(DropSource
),
2625 ADD_KNOWN_IID(DropTarget
),
2626 ADD_KNOWN_IID(EnumCallback
),
2627 ADD_KNOWN_IID(EnumFORMATETC
),
2628 ADD_KNOWN_IID(EnumGeneric
),
2629 ADD_KNOWN_IID(EnumHolder
),
2630 ADD_KNOWN_IID(EnumMoniker
),
2631 ADD_KNOWN_IID(EnumOLEVERB
),
2632 ADD_KNOWN_IID(EnumSTATDATA
),
2633 ADD_KNOWN_IID(EnumSTATSTG
),
2634 ADD_KNOWN_IID(EnumString
),
2635 ADD_KNOWN_IID(EnumUnknown
),
2636 ADD_KNOWN_IID(EnumVARIANT
),
2637 ADD_KNOWN_IID(ExternalConnection
),
2638 ADD_KNOWN_IID(InternalMoniker
),
2639 ADD_KNOWN_IID(LockBytes
),
2640 ADD_KNOWN_IID(Malloc
),
2641 ADD_KNOWN_IID(Marshal
),
2642 ADD_KNOWN_IID(MessageFilter
),
2643 ADD_KNOWN_IID(Moniker
),
2644 ADD_KNOWN_IID(OleAdviseHolder
),
2645 ADD_KNOWN_IID(OleCache
),
2646 ADD_KNOWN_IID(OleCache2
),
2647 ADD_KNOWN_IID(OleCacheControl
),
2648 ADD_KNOWN_IID(OleClientSite
),
2649 ADD_KNOWN_IID(OleContainer
),
2650 ADD_KNOWN_IID(OleInPlaceActiveObject
),
2651 ADD_KNOWN_IID(OleInPlaceFrame
),
2652 ADD_KNOWN_IID(OleInPlaceObject
),
2653 ADD_KNOWN_IID(OleInPlaceSite
),
2654 ADD_KNOWN_IID(OleInPlaceUIWindow
),
2655 ADD_KNOWN_IID(OleItemContainer
),
2656 ADD_KNOWN_IID(OleLink
),
2657 ADD_KNOWN_IID(OleManager
),
2658 ADD_KNOWN_IID(OleObject
),
2659 ADD_KNOWN_IID(OlePresObj
),
2660 ADD_KNOWN_IID(OleWindow
),
2661 ADD_KNOWN_IID(PSFactory
),
2662 ADD_KNOWN_IID(ParseDisplayName
),
2663 ADD_KNOWN_IID(Persist
),
2664 ADD_KNOWN_IID(PersistFile
),
2665 ADD_KNOWN_IID(PersistStorage
),
2666 ADD_KNOWN_IID(PersistStream
),
2667 ADD_KNOWN_IID(ProxyManager
),
2668 ADD_KNOWN_IID(RootStorage
),
2669 ADD_KNOWN_IID(RpcChannel
),
2670 ADD_KNOWN_IID(RpcProxy
),
2671 ADD_KNOWN_IID(RpcStub
),
2672 ADD_KNOWN_IID(RunnableObject
),
2673 ADD_KNOWN_IID(RunningObjectTable
),
2674 ADD_KNOWN_IID(StdMarshalInfo
),
2675 ADD_KNOWN_IID(Storage
),
2676 ADD_KNOWN_IID(Stream
),
2677 ADD_KNOWN_IID(StubManager
),
2678 ADD_KNOWN_IID(Unknown
),
2679 ADD_KNOWN_IID(ViewObject
),
2680 ADD_KNOWN_IID(ViewObject2
),
2681 ADD_KNOWN_GUID(IID_IDispatch
),
2682 ADD_KNOWN_GUID(IID_IWebBrowser
),
2683 ADD_KNOWN_GUID(IID_IWebBrowserApp
),
2684 ADD_KNOWN_GUID(IID_IWebBrowser2
),
2685 ADD_KNOWN_GUID(IID_IWebBrowser
),
2686 ADD_KNOWN_GUID(DIID_DWebBrowserEvents2
),
2687 ADD_KNOWN_GUID(DIID_DWebBrowserEvents
),
2690 // don't clobber preprocessor name space
2691 #undef ADD_KNOWN_IID
2692 #undef ADD_KNOWN_GUID
2694 // try to find the interface in the table
2695 for ( size_t ui
= 0; ui
< WXSIZEOF(aKnownIids
); ui
++ )
2697 if ( riid
== *aKnownIids
[ui
].pIid
)
2699 return aKnownIids
[ui
].szName
;
2703 // unknown IID, just transform to string
2704 LPOLESTR str
= NULL
;
2705 StringFromIID(riid
, &str
);
2713 return _T("StringFromIID() error");