2 wxActiveX Library Licence, Version 3
3 ====================================
5 Copyright (C) 2003 Lindsay Mathieson [, ...]
7 Everyone is permitted to copy and distribute verbatim copies
8 of this licence document, but changing it is not allowed.
10 wxActiveX LIBRARY LICENCE
11 TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
13 This library is free software; you can redistribute it and/or modify it
14 under the terms of the GNU Library General Public Licence as published by
15 the Free Software Foundation; either version 2 of the Licence, or (at
16 your option) any later version.
18 This library is distributed in the hope that it will be useful, but
19 WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library
21 General Public Licence for more details.
23 You should have received a copy of the GNU Library General Public Licence
24 along with this software, usually in a file named COPYING.LIB. If not,
25 write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
26 Boston, MA 02111-1307 USA.
30 1. As a special exception, the copyright holders of this library give
31 permission for additional uses of the text contained in this release of
32 the library as licenced under the wxActiveX Library Licence, applying
33 either version 3 of the Licence, or (at your option) any later version of
34 the Licence as published by the copyright holders of version 3 of the
37 2. The exception is that you may use, copy, link, modify and distribute
38 under the user's own terms, binary object code versions of works based
41 3. If you copy code from files distributed under the terms of the GNU
42 General Public Licence or the GNU Library General Public Licence into a
43 copy of this library, as this licence permits, the exception does not
44 apply to the code that you add in this way. To avoid misleading anyone as
45 to the status of such modified files, you must delete this exception
46 notice from such code and/or adjust the licensing conditions notice
49 4. If you write modifications of your own for this library, it is your
50 choice whether to permit this exception to apply to your modifications.
51 If you do not wish that, you must delete the exception notice from such
52 code and/or adjust the licensing conditions notice accordingly.
55 #include "wxActiveX.h"
56 #include <wx/strconv.h>
58 #include <wx/string.h>
59 #include <wx/datetime.h>
67 // Depending on compilation mode, the wx headers may have undef'd
68 // this, but in this case we need it so the virtual method in
69 // FrameSite will match what is in oleidl.h.
72 #define GetObject GetObjectW
74 #define GetObject GetObjectA
79 //////////////////////////////////////////////////////////////////////
80 BEGIN_EVENT_TABLE(wxActiveX
, wxWindow
)
81 EVT_SIZE(wxActiveX::OnSize
)
82 EVT_PAINT(wxActiveX::OnPaint
)
83 EVT_MOUSE_EVENTS(wxActiveX::OnMouse
)
84 EVT_SET_FOCUS(wxActiveX::OnSetFocus
)
85 EVT_KILL_FOCUS(wxActiveX::OnKillFocus
)
88 IMPLEMENT_CLASS(wxActiveX
, wxWindow
)
93 public IOleClientSite
,
94 public IOleInPlaceSiteEx
,
95 public IOleInPlaceFrame
,
96 public IOleItemContainer
,
98 public IOleCommandTarget
,
99 public IOleDocumentSite
,
101 public IOleControlSite
104 DECLARE_OLE_UNKNOWN(FrameSite
);
107 FrameSite(wxActiveX
* win
);
108 virtual ~FrameSite();
111 STDMETHODIMP
GetWindow(HWND
*);
112 STDMETHODIMP
ContextSensitiveHelp(BOOL
);
114 //IOleInPlaceUIWindow
115 STDMETHODIMP
GetBorder(LPRECT
);
116 STDMETHODIMP
RequestBorderSpace(LPCBORDERWIDTHS
);
117 STDMETHODIMP
SetBorderSpace(LPCBORDERWIDTHS
);
118 STDMETHODIMP
SetActiveObject(IOleInPlaceActiveObject
*, LPCOLESTR
);
121 STDMETHODIMP
InsertMenus(HMENU
, LPOLEMENUGROUPWIDTHS
);
122 STDMETHODIMP
SetMenu(HMENU
, HOLEMENU
, HWND
);
123 STDMETHODIMP
RemoveMenus(HMENU
);
124 STDMETHODIMP
SetStatusText(LPCOLESTR
);
125 STDMETHODIMP
EnableModeless(BOOL
);
126 STDMETHODIMP
TranslateAccelerator(LPMSG
, WORD
);
129 STDMETHODIMP
CanInPlaceActivate();
130 STDMETHODIMP
OnInPlaceActivate();
131 STDMETHODIMP
OnUIActivate();
132 STDMETHODIMP
GetWindowContext(IOleInPlaceFrame
**, IOleInPlaceUIWindow
**,
133 LPRECT
, LPRECT
, LPOLEINPLACEFRAMEINFO
);
134 STDMETHODIMP
Scroll(SIZE
);
135 STDMETHODIMP
OnUIDeactivate(BOOL
);
136 STDMETHODIMP
OnInPlaceDeactivate();
137 STDMETHODIMP
DiscardUndoState();
138 STDMETHODIMP
DeactivateAndUndo();
139 STDMETHODIMP
OnPosRectChange(LPCRECT
);
142 STDMETHODIMP
OnInPlaceActivateEx(BOOL
*, DWORD
);
143 STDMETHODIMP
OnInPlaceDeactivateEx(BOOL
);
144 STDMETHODIMP
RequestUIActivate();
147 STDMETHODIMP
SaveObject();
148 STDMETHODIMP
GetMoniker(DWORD
, DWORD
, IMoniker
**);
149 STDMETHODIMP
GetContainer(LPOLECONTAINER FAR
*);
150 STDMETHODIMP
ShowObject();
151 STDMETHODIMP
OnShowWindow(BOOL
);
152 STDMETHODIMP
RequestNewObjectLayout();
155 STDMETHODIMP
OnControlInfoChanged();
156 STDMETHODIMP
LockInPlaceActive(BOOL
);
157 STDMETHODIMP
GetExtendedControl(IDispatch
**);
158 STDMETHODIMP
TransformCoords(POINTL
*, POINTF
*, DWORD
);
159 STDMETHODIMP
TranslateAccelerator(LPMSG
, DWORD
);
160 STDMETHODIMP
OnFocus(BOOL
);
161 STDMETHODIMP
ShowPropertyFrame();
164 STDMETHODIMP
QueryStatus(const GUID
*, ULONG
, OLECMD
[], OLECMDTEXT
*);
165 STDMETHODIMP
Exec(const GUID
*, DWORD
, DWORD
, VARIANTARG
*, VARIANTARG
*);
168 STDMETHODIMP
ParseDisplayName(IBindCtx
*, LPOLESTR
, ULONG
*, IMoniker
**);
171 STDMETHODIMP
EnumObjects(DWORD
, IEnumUnknown
**);
172 STDMETHODIMP
LockContainer(BOOL
);
175 STDMETHODIMP
GetObject(LPOLESTR
, DWORD
, IBindCtx
*, REFIID
, void**);
176 STDMETHODIMP
GetObjectStorage(LPOLESTR
, IBindCtx
*, REFIID
, void**);
177 STDMETHODIMP
IsRunning(LPOLESTR
);
180 STDMETHODIMP
GetIDsOfNames(REFIID
, OLECHAR
**, unsigned int, LCID
, DISPID
*);
181 STDMETHODIMP
GetTypeInfo(unsigned int, LCID
, ITypeInfo
**);
182 STDMETHODIMP
GetTypeInfoCount(unsigned int*);
183 STDMETHODIMP
Invoke(DISPID
, REFIID
, LCID
, WORD
, DISPPARAMS
*, VARIANT
*, EXCEPINFO
*, UINT
*);
186 void STDMETHODCALLTYPE
OnDataChange(FORMATETC
*, STGMEDIUM
*);
187 void STDMETHODCALLTYPE
OnViewChange(DWORD
, LONG
);
188 void STDMETHODCALLTYPE
OnRename(IMoniker
*);
189 void STDMETHODCALLTYPE
OnSave();
190 void STDMETHODCALLTYPE
OnClose();
193 HRESULT STDMETHODCALLTYPE
ActivateMe(IOleDocumentView __RPC_FAR
*pViewToActivate
);
197 wxActiveX
* m_window
;
202 bool m_bSupportsWindowlessActivation
;
203 bool m_bInPlaceLocked
;
204 bool m_bInPlaceActive
;
210 LCID m_nAmbientLocale
;
211 COLORREF m_clrAmbientForeColor
;
212 COLORREF m_clrAmbientBackColor
;
213 bool m_bAmbientShowHatching
;
214 bool m_bAmbientShowGrabHandles
;
215 bool m_bAmbientAppearance
;
218 DEFINE_OLE_TABLE(FrameSite
)
219 OLE_INTERFACE(IID_IUnknown
, IOleClientSite
)
221 OLE_IINTERFACE(IOleClientSite
)
223 OLE_INTERFACE(IID_IOleWindow
, IOleInPlaceSite
)
224 OLE_IINTERFACE(IOleInPlaceSite
)
225 OLE_IINTERFACE(IOleInPlaceSiteEx
)
227 //OLE_IINTERFACE(IOleWindow)
228 OLE_IINTERFACE(IOleInPlaceUIWindow
)
229 OLE_IINTERFACE(IOleInPlaceFrame
)
231 OLE_IINTERFACE(IParseDisplayName
)
232 OLE_IINTERFACE(IOleContainer
)
233 OLE_IINTERFACE(IOleItemContainer
)
235 OLE_IINTERFACE(IDispatch
)
237 OLE_IINTERFACE(IOleCommandTarget
)
239 OLE_IINTERFACE(IOleDocumentSite
)
241 OLE_IINTERFACE(IAdviseSink
)
243 OLE_IINTERFACE(IOleControlSite
)
248 wxActiveX::wxActiveX(wxWindow
* parent
, REFCLSID clsid
, wxWindowID id
,
252 const wxString
& name
) :
253 wxWindow(parent
, id
, pos
, size
, style
, name
)
255 m_bAmbientUserMode
= true;
256 m_docAdviseCookie
= 0;
257 CreateActiveX(clsid
);
260 wxActiveX::wxActiveX(wxWindow
* parent
, const wxString
& progId
, wxWindowID id
,
264 const wxString
& name
) :
265 wxWindow(parent
, id
, pos
, size
, style
, name
)
267 m_bAmbientUserMode
= true;
268 m_docAdviseCookie
= 0;
269 CreateActiveX((LPOLESTR
) (const wchar_t *) progId
.wc_str(wxConvUTF8
));
272 wxActiveX::~wxActiveX()
274 // disconnect connection points
275 wxOleConnectionArray::iterator it
= m_connections
.begin();
276 while (it
!= m_connections
.end())
278 wxOleConnectionPoint
& cp
= it
->first
;
279 cp
->Unadvise(it
->second
);
283 m_connections
.clear();
285 if (m_oleInPlaceObject
.Ok())
287 m_oleInPlaceObject
->InPlaceDeactivate();
288 m_oleInPlaceObject
->UIDeactivate();
292 if (m_oleObject
.Ok())
294 if (m_docAdviseCookie
!= 0)
295 m_oleObject
->Unadvise(m_docAdviseCookie
);
297 m_oleObject
->DoVerb(OLEIVERB_HIDE
, NULL
, m_clientSite
, 0, (HWND
) GetHWND(), NULL
);
298 m_oleObject
->Close(OLECLOSE_NOSAVE
);
299 m_oleObject
->SetClientSite(NULL
);
303 void wxActiveX::CreateActiveX(REFCLSID clsid
)
309 ////////////////////////////////////////////////////////
311 FrameSite
*frame
= new FrameSite(this);
313 hret
= m_clientSite
.QueryInterface(IID_IOleClientSite
, (IDispatch
*) frame
);
314 wxCHECK_RET(SUCCEEDED(hret
), _T("m_clientSite.QueryInterface failed"));
316 wxAutoOleInterface
<IAdviseSink
> adviseSink(IID_IAdviseSink
, (IDispatch
*) frame
);
317 wxCHECK_RET(adviseSink
.Ok(), _T("adviseSink not Ok"));
320 // Create Object, get IUnknown interface
321 m_ActiveX
.CreateInstance(clsid
, IID_IUnknown
);
322 wxCHECK_RET(m_ActiveX
.Ok(), _T("m_ActiveX.CreateInstance failed"));
324 // Register object as active
325 unsigned long pdwRegister
;
326 hret
= RegisterActiveObject(m_ActiveX
, clsid
, ACTIVEOBJECT_WEAK
, &pdwRegister
);
327 WXOLE_WARN(hret
, "Unable to register object as active");
329 // Get Dispatch interface
330 hret
= m_Dispatch
.QueryInterface(IID_IDispatch
, m_ActiveX
);
331 WXOLE_WARN(hret
, "Unable to get dispatch interface");
336 // Get IOleObject interface
337 hret
= m_oleObject
.QueryInterface(IID_IOleObject
, m_ActiveX
);
338 wxCHECK_RET(SUCCEEDED(hret
), _("Unable to get IOleObject interface"));
340 // get IViewObject Interface
341 hret
= m_viewObject
.QueryInterface(IID_IViewObject
, m_ActiveX
);
342 wxCHECK_RET(SUCCEEDED(hret
), _T("Unable to get IViewObject Interface"));
345 m_docAdviseCookie
= 0;
346 hret
= m_oleObject
->Advise(adviseSink
, &m_docAdviseCookie
);
347 WXOLE_WARN(hret
, "m_oleObject->Advise(adviseSink, &m_docAdviseCookie),\"Advise\")");
348 m_oleObject
->SetHostNames(L
"wxActiveXContainer", NULL
);
349 OleSetContainedObject(m_oleObject
, TRUE
);
353 // Get IOleInPlaceObject interface
354 hret
= m_oleInPlaceObject
.QueryInterface(IID_IOleInPlaceObject
, m_ActiveX
);
355 wxCHECK_RET(SUCCEEDED(hret
), _T("Unable to get IOleInPlaceObject interface"));
359 m_oleObject
->GetMiscStatus(DVASPECT_CONTENT
, &dwMiscStatus
);
360 wxCHECK_RET(SUCCEEDED(hret
), _T("Unable to get oleObject status"));
362 // set client site first ?
363 if (dwMiscStatus
& OLEMISC_SETCLIENTSITEFIRST
)
364 m_oleObject
->SetClientSite(m_clientSite
);
368 wxAutoOleInterface
<IPersistStreamInit
>
369 pPersistStreamInit(IID_IPersistStreamInit
, m_oleObject
);
371 if (pPersistStreamInit
.Ok())
373 hret
= pPersistStreamInit
->InitNew();
374 WXOLE_WARN(hret
, "CreateActiveX::pPersistStreamInit->InitNew()");
377 if (! (dwMiscStatus
& OLEMISC_SETCLIENTSITEFIRST
))
378 m_oleObject
->SetClientSite(m_clientSite
);
382 GetClientSize(&w
, &h
);
391 if (m_oleInPlaceObject
.Ok())
393 hret
= m_oleInPlaceObject
->GetWindow(&m_oleObjectHWND
);
394 WXOLE_WARN(hret
, "m_oleInPlaceObject->GetWindow(&m_oleObjectHWND)");
396 ::SetActiveWindow(m_oleObjectHWND
);
400 if (! (dwMiscStatus
& OLEMISC_INVISIBLEATRUNTIME
))
402 if (w
> 0 && h
> 0 && m_oleInPlaceObject
.Ok())
403 m_oleInPlaceObject
->SetObjectRects(&posRect
, &posRect
);
405 hret
= m_oleObject
->DoVerb(OLEIVERB_INPLACEACTIVATE
, NULL
, m_clientSite
, 0, (HWND
)GetHWND(), &posRect
);
406 hret
= m_oleObject
->DoVerb(OLEIVERB_SHOW
, 0, m_clientSite
, 0, (HWND
)GetHWND(), &posRect
);
409 if (! m_oleObjectHWND
&& m_oleInPlaceObject
.Ok())
411 hret
= m_oleInPlaceObject
->GetWindow(&m_oleObjectHWND
);
412 WXOLE_WARN(hret
, "m_oleInPlaceObject->GetWindow(&m_oleObjectHWND)");
417 ::SetActiveWindow(m_oleObjectHWND
);
418 ::ShowWindow(m_oleObjectHWND
, SW_SHOW
);
420 // Update by GBR to resize older controls
422 szEvent
.m_size
= wxSize(w
, h
) ;
423 GetEventHandler()->AddPendingEvent(szEvent
);
427 void wxActiveX::CreateActiveX(LPOLESTR progId
)
430 if (CLSIDFromProgID(progId
, &clsid
) != S_OK
)
433 CreateActiveX(clsid
);
436 ////////////////////////////////////////////////////////////////////////////////////////////////////////////
437 // Case Insensitive Map of Event names to eventTypes
438 // created dynamically at run time in:
439 // EVT_ACTIVEX(eventName, id, fn)
440 // we map the pointer to them so that:
441 // const wxEventType& RegisterActiveXEvent(wxString eventName);
442 // can return a const reference, which is neccessary for event tables
443 // probably should use a wxWindows hash table here, but I'm lazy ...
444 typedef map
<wxString
, wxEventType
*, NS_wxActiveX::less_wxStringI
> ActiveXNamedEventMap
;
445 static ActiveXNamedEventMap sg_NamedEventMap
;
447 const wxEventType
& RegisterActiveXEvent(const wxChar
*eventName
)
449 wxString ev
= eventName
;
450 ActiveXNamedEventMap::iterator it
= sg_NamedEventMap
.find(ev
);
451 if (it
== sg_NamedEventMap
.end())
453 wxEventType
*et
= new wxEventType(wxNewEventType());
454 sg_NamedEventMap
[ev
] = et
;
459 return *(it
->second
);
463 ////////////////////////////////////////////////////////////////////////////////////////////////////////////
464 // Map of Event DISPID's to eventTypes
465 // created dynamically at run time in:
466 // EVT_ACTIVEX(eventName, id, fn)
467 // we map the pointer to them so that:
468 // const wxEventType& RegisterActiveXEvent(wxString eventName);
469 // can return a const reference, which is neccessary for event tables
471 typedef map
<DISPID
, wxEventType
*> ActiveXDISPIDEventMap
;
472 static ActiveXDISPIDEventMap sg_dispIdEventMap
;
474 const wxEventType
& RegisterActiveXEvent(DISPID event
)
476 ActiveXDISPIDEventMap::iterator it
= sg_dispIdEventMap
.find(event
);
477 if (it
== sg_dispIdEventMap
.end())
479 wxEventType
*et
= new wxEventType(wxNewEventType());
480 sg_dispIdEventMap
[event
] = et
;
485 return *(it
->second
);
488 // one off class for automatic freeing of activeX eventtypes
489 class ActiveXEventMapFlusher
492 ~ActiveXEventMapFlusher()
495 ActiveXNamedEventMap::iterator it
= sg_NamedEventMap
.end();
496 while (it
!= sg_NamedEventMap
.end())
501 sg_NamedEventMap
.clear();
504 ActiveXDISPIDEventMap::iterator dit
= sg_dispIdEventMap
.end();
505 while (dit
!= sg_dispIdEventMap
.end())
510 sg_dispIdEventMap
.clear();
514 static ActiveXEventMapFlusher s_dummyActiveXEventMapFlusher
;
517 //////////////////////////////////////////////////////
518 VARTYPE
wxTypeToVType(const wxVariant
& v
)
520 wxString type
= v
.GetType();
521 if (type
== wxT("bool"))
523 else if (type
== wxT("char"))
525 else if (type
== wxT("datetime"))
527 else if (type
== wxT("double"))
529 else if (type
== wxT("list"))
531 else if (type
== wxT("long"))
533 else if (type
== wxT("string"))
535 else if (type
== wxT("stringlist"))
537 else if (type
== wxT("date"))
539 else if (type
== wxT("time"))
541 else if (type
== wxT("void*"))
542 return VT_VOID
| VT_BYREF
;
547 bool wxDateTimeToDATE(wxDateTime dt
, DATE
& d
)
550 memset(&st
, 0, sizeof(st
));
552 st
.wYear
= dt
.GetYear();
553 st
.wMonth
= dt
.GetMonth() + 1;
554 st
.wDay
= dt
.GetDay();
555 st
.wHour
= dt
.GetHour();
556 st
.wMinute
= dt
.GetMinute();
557 st
.wSecond
= dt
.GetSecond();
558 st
.wMilliseconds
= dt
.GetMillisecond();
559 return SystemTimeToVariantTime(&st
, &d
) != FALSE
;
562 bool wxDateTimeToVariant(wxDateTime dt
, VARIANTARG
& va
)
564 return wxDateTimeToDATE(dt
, va
.date
);
567 bool DATEToWxDateTime(DATE date
, wxDateTime
& dt
)
570 if (! VariantTimeToSystemTime(date
, &st
))
575 wxDateTime::Month(int(wxDateTime::Jan
) + st
.wMonth
- 1),
577 st
.wHour
, st
.wMinute
, st
.wSecond
, st
.wMilliseconds
);
582 bool VariantToWxDateTime(VARIANTARG va
, wxDateTime
& dt
)
584 HRESULT hr
= VariantChangeType(&va
, &va
, 0, VT_DATE
);
588 return DATEToWxDateTime(va
.date
, dt
);
591 bool MSWVariantToVariant(VARIANTARG
& va
, wxVariant
& vx
)
597 return false; // don't support arrays yet
610 return MSWVariantToVariant(*va
.pvarVal
, vx
);
614 VariantChangeType(&tmp
, &tmp
, 0, wxTypeToVType(vx
));
615 bool rc
= MSWVariantToVariant(tmp
, vx
);
624 vx
= (char) *va
.pbVal
;
633 vx
= (long) *va
.puiVal
;
635 vx
= (long) va
.uiVal
;
645 vx
= (long) *va
.pulVal
;
647 vx
= (long) va
.ulVal
;
669 vx
= (*va
.pboolVal
? true : false);
671 vx
= (va
.boolVal
? true : false);
676 return false; // what the hell is a CY ?
683 hr
= VarR8FromDec(va
.pdecVal
, &d
);
685 hr
= VarR8FromDec(&va
.decVal
, &d
);
688 return SUCCEEDED(hr
);
696 rc
= DATEToWxDateTime(*va
.pdate
, dt
);
698 rc
= VariantToWxDateTime(va
, dt
);
705 vx
= wxString(*va
.pbstrVal
);
707 vx
= wxString(va
.bstrVal
);
710 case VT_UNKNOWN
: // should do a custom wxVariantData for this
712 vx
= (void *) *va
.ppunkVal
;
714 vx
= (void *) va
.punkVal
;
717 case VT_DISPATCH
: // should do a custom wxVariantData for this
719 vx
= (void *) *va
.ppdispVal
;
721 vx
= (void *) va
.pdispVal
;
730 bool VariantToMSWVariant(const wxVariant
& vx
, VARIANTARG
& va
)
736 return false; // don't support arrays yet
748 return VariantToMSWVariant(vx
, *va
.pvarVal
);
751 va
.vt
= wxTypeToVType(vx
);
752 return VariantToMSWVariant(vx
, va
);
759 *va
.pbVal
= (char) vx
;
768 *va
.puiVal
= (long) vx
;
770 va
.uiVal
= (long) vx
;
780 *va
.pulVal
= (long) vx
;
782 va
.ulVal
= (long) vx
;
789 *va
.pfltVal
= (double) vx
;
791 va
.fltVal
= (double) vx
;
797 *va
.pdblVal
= (double) vx
;
799 va
.dblVal
= (double) vx
;
804 *va
.pboolVal
= ((bool) vx
) ? TRUE
: FALSE
;
806 va
.boolVal
= ((bool) vx
) ? TRUE
: FALSE
;
810 return false; // what the hell is a CY ?
814 return SUCCEEDED(VarDecFromR8(vx
, va
.pdecVal
));
816 return SUCCEEDED(VarDecFromR8(vx
, &va
.decVal
));
820 return wxDateTimeToDATE(vx
, *va
.pdate
);
822 return wxDateTimeToVariant(vx
,va
);
826 *va
.pbstrVal
= SysAllocString(vx
.GetString().wc_str(wxConvUTF8
));
828 va
.bstrVal
= SysAllocString(vx
.GetString().wc_str(wxConvUTF8
));
831 case VT_UNKNOWN
: // should do a custom wxVariantData for this
833 *va
.ppunkVal
= (IUnknown
*) (void *) vx
;
835 va
.punkVal
= (IUnknown
*) (void *) vx
;
838 case VT_DISPATCH
: // should do a custom wxVariantData for this
840 *va
.ppdispVal
= (IDispatch
*) (void *) vx
;
842 va
.pdispVal
= (IDispatch
*) (void *) vx
;
850 IMPLEMENT_CLASS(wxActiveXEvent
, wxCommandEvent
)
852 class wxActiveXEvents
: public IDispatch
855 DECLARE_OLE_UNKNOWN(wxActiveXEvents
);
858 wxActiveX
*m_activeX
;
862 friend bool wxActiveXEventsInterface(wxActiveXEvents
*self
, REFIID iid
, void **_interface
, const char *&desc
);
865 wxActiveXEvents(wxActiveX
*ax
) : m_activeX(ax
), m_haveCustomId(false) {}
866 wxActiveXEvents(wxActiveX
*ax
, REFIID iid
) : m_activeX(ax
), m_haveCustomId(true), m_customId(iid
) {}
867 virtual ~wxActiveXEvents()
872 STDMETHODIMP
GetIDsOfNames(REFIID r
, OLECHAR
** o
, unsigned int i
, LCID l
, DISPID
* d
)
877 STDMETHODIMP
GetTypeInfo(unsigned int i
, LCID l
, ITypeInfo
** t
)
882 STDMETHODIMP
GetTypeInfoCount(unsigned int* i
)
888 void DispatchEvent(wxActiveX::FuncX
&func
, const wxEventType
& eventType
, DISPPARAMS
* pDispParams
)
890 wxActiveXEvent event
;
891 event
.SetId(m_activeX
->GetId());
892 event
.SetEventType(eventType
);
893 event
.m_params
.NullList();
894 event
.m_params
.SetName(func
.name
);
900 // sometimes the pDispParams does not match the param info for a activex control
901 int nArg
= wxMin(func
.params
.size(), pDispParams
->cArgs
);
902 for (int i
= nArg
- 1; i
>= 0; i
--)
904 VARIANTARG
& va
= pDispParams
->rgvarg
[i
];
905 wxActiveX::ParamX
&px
= func
.params
[nArg
- i
- 1];
909 MSWVariantToVariant(va
, vx
);
910 event
.m_params
.Append(vx
);
916 int nArg
= wxMin(func
.params
.size(), pDispParams
->cArgs
);
917 m_activeX
->GetEventHandler()->ProcessEvent(event
);
918 for (int i
= 0; i
< nArg
; i
++)
920 VARIANTARG
& va
= pDispParams
->rgvarg
[i
];
921 wxActiveX::ParamX
&px
= func
.params
[nArg
- i
- 1];
925 wxVariant
& vx
= event
.m_params
[nArg
- i
- 1];
927 VariantToMSWVariant(vx
, va
);
932 m_activeX
->GetEventHandler()->AddPendingEvent(event
);
936 STDMETHODIMP
Invoke(DISPID dispIdMember
, REFIID riid
, LCID lcid
,
937 WORD wFlags
, DISPPARAMS
* pDispParams
,
938 VARIANT
* pVarResult
, EXCEPINFO
* pExcepInfo
,
939 unsigned int * puArgErr
)
941 if (wFlags
& (DISPATCH_PROPERTYGET
| DISPATCH_PROPERTYPUT
| DISPATCH_PROPERTYPUTREF
))
946 // find event for dispid
947 wxActiveX::MemberIdMap::iterator mit
= m_activeX
->m_eventMemberIds
.find((MEMBERID
) dispIdMember
);
948 if (mit
== m_activeX
->m_eventMemberIds
.end())
952 int midx
= mit
->second
;
953 if (midx
< 0 || midx
>= m_activeX
->GetEventCount())
956 wxActiveX::FuncX
&func
= m_activeX
->m_events
[midx
];
959 // try to find dispid event
960 ActiveXDISPIDEventMap::iterator dit
= sg_dispIdEventMap
.find(dispIdMember
);
961 if (dit
!= sg_dispIdEventMap
.end())
964 DispatchEvent(func
, *(dit
->second
), pDispParams
);
969 ActiveXNamedEventMap::iterator nit
= sg_NamedEventMap
.find(func
.name
);
970 if (nit
== sg_NamedEventMap
.end())
974 DispatchEvent(func
, *(nit
->second
), pDispParams
);
979 bool wxActiveXEventsInterface(wxActiveXEvents
*self
, REFIID iid
, void **_interface
, const char *&desc
)
981 if (self
->m_haveCustomId
&& IsEqualIID(iid
, self
->m_customId
))
983 WXOLE_TRACE("Found Custom Dispatch Interface");
984 *_interface
= (IUnknown
*) (IDispatch
*) self
;
985 desc
= "Custom Dispatch Interface";
992 DEFINE_OLE_TABLE(wxActiveXEvents
)
993 OLE_IINTERFACE(IUnknown
)
994 OLE_INTERFACE(IID_IDispatch
, IDispatch
)
995 OLE_INTERFACE_CUSTOM(wxActiveXEventsInterface
)
998 wxString
wxActiveXEvent::EventName()
1000 return m_params
.GetName();
1003 int wxActiveXEvent::ParamCount() const
1005 return m_params
.GetCount();
1008 wxString
wxActiveXEvent::ParamType(int idx
)
1010 wxASSERT(idx
>= 0 && idx
< m_params
.GetCount());
1012 return m_params
[idx
].GetType();
1015 wxString
wxActiveXEvent::ParamName(int idx
)
1017 wxASSERT(idx
>= 0 && idx
< m_params
.GetCount());
1019 return m_params
[idx
].GetName();
1022 static wxVariant nullVar
;
1024 wxVariant
& wxActiveXEvent::operator[] (int idx
)
1026 wxASSERT(idx
>= 0 && idx
< ParamCount());
1028 return m_params
[idx
];
1031 wxVariant
& wxActiveXEvent::operator[] (wxString name
)
1033 for (int i
= 0; i
< m_params
.GetCount(); i
++)
1035 if (name
.CmpNoCase(m_params
[i
].GetName()) == 0)
1039 wxString err
= _T("wxActiveXEvent::operator[] invalid name <") + name
+ _T(">");
1040 err
+= _T("\r\nValid Names = :\r\n");
1041 for (i
= 0; i
< m_params
.GetCount(); i
++)
1043 err
+= m_params
[i
].GetName();
1047 wxASSERT_MSG(false, err
);
1052 void wxActiveX::GetTypeInfo()
1055 We are currently only interested in the IDispatch interface
1056 to the control. For dual interfaces (TypeKind = TKIND_INTERFACE)
1057 we should drill down through the inheritance
1058 (using TYPEATTR->cImplTypes) and GetRefTypeOfImplType(n)
1059 and retrieve all the func names etc that way, then generate a C++
1062 But we don't do this and probably never will, so if we have a DUAL
1063 interface then we query for the IDispatch
1064 via GetRefTypeOfImplType(-1).
1069 // get type info via class info
1070 wxAutoOleInterface
<IProvideClassInfo
> classInfo(IID_IProvideClassInfo
, m_ActiveX
);
1071 if (! classInfo
.Ok())
1075 wxAutoOleInterface
<ITypeInfo
> typeInfo
;
1076 hret
= classInfo
->GetClassInfo(typeInfo
.GetRef());
1077 if (! typeInfo
.Ok())
1081 TYPEATTR
*ta
= NULL
;
1082 hret
= typeInfo
->GetTypeAttr(&ta
);
1086 // this should be a TKIND_COCLASS
1087 wxASSERT(ta
->typekind
== TKIND_COCLASS
);
1089 // iterate contained interfaces
1090 for (int i
= 0; i
< ta
->cImplTypes
; i
++)
1094 // get dispatch type info handle
1095 hret
= typeInfo
->GetRefTypeOfImplType(i
, &rt
);
1096 if (! SUCCEEDED(hret
))
1099 // get dispatch type info interface
1100 wxAutoOleInterface
<ITypeInfo
> ti
;
1101 hret
= typeInfo
->GetRefTypeInfo(rt
, ti
.GetRef());
1105 // check if default event sink
1106 bool defInterface
= false;
1107 bool defEventSink
= false;
1108 int impTypeFlags
= 0;
1109 typeInfo
->GetImplTypeFlags(i
, &impTypeFlags
);
1111 if (impTypeFlags
& IMPLTYPEFLAG_FDEFAULT
)
1113 if (impTypeFlags
& IMPLTYPEFLAG_FSOURCE
)
1115 WXOLE_TRACEOUT("Default Event Sink");
1116 defEventSink
= true;
1117 if (impTypeFlags
& IMPLTYPEFLAG_FDEFAULTVTABLE
)
1119 WXOLE_TRACEOUT("*ERROR* - Default Event Sink is via vTable");
1120 defEventSink
= false;
1125 WXOLE_TRACEOUT("Default Interface");
1126 defInterface
= true;
1132 GetTypeInfo(ti
, defInterface
, defEventSink
);
1137 typeInfo
->ReleaseTypeAttr(ta
);
1140 void ElemDescToParam(const ELEMDESC
& ed
, wxActiveX::ParamX
& param
)
1142 param
.flags
= ed
.idldesc
.wIDLFlags
;
1143 param
.vt
= ed
.tdesc
.vt
;
1144 param
.isPtr
= (param
.vt
== VT_PTR
);
1145 param
.isSafeArray
= (param
.vt
== VT_SAFEARRAY
);
1146 if (param
.isPtr
|| param
.isSafeArray
)
1147 param
.vt
= ed
.tdesc
.lptdesc
->vt
;
1150 void wxActiveX::GetTypeInfo(ITypeInfo
*ti
, bool defInterface
, bool defEventSink
)
1152 // wxAutoOleInterface<> assumes a ref has already been added
1154 wxAutoOleInterface
<ITypeInfo
> typeInfo(ti
);
1157 TYPEATTR
*ta
= NULL
;
1158 HRESULT hret
= typeInfo
->GetTypeAttr(&ta
);
1162 if (ta
->typekind
== TKIND_DISPATCH
)
1164 WXOLE_TRACEOUT("GUID = " << GetIIDName(ta
->guid
).c_str());
1168 wxActiveXEvents
*disp
= new wxActiveXEvents(this, ta
->guid
);
1169 ConnectAdvise(ta
->guid
, disp
);
1173 // Get Function Names
1174 for (int i
= 0; i
< ta
->cFuncs
; i
++)
1176 FUNCDESC FAR
*fd
= NULL
;
1178 hret
= typeInfo
->GetFuncDesc(i
, &fd
);
1182 BSTR anames
[1] = {NULL
};
1185 hret
= typeInfo
->GetNames(fd
->memid
, anames
, 1, &n
);
1189 wxString name
= anames
[0];
1191 WXOLE_TRACEOUT("Name " << i
<< " = " << name
.c_str());
1192 SysFreeString(anames
[0]);
1194 if (defInterface
|| defEventSink
)
1198 func
.memid
= fd
->memid
;
1199 func
.hasOut
= false;
1202 unsigned int maxPNames
= fd
->cParams
+ 1;
1203 unsigned int nPNames
= 0;
1204 BSTR
*pnames
= new BSTR
[maxPNames
];
1206 hret
= typeInfo
->GetNames(fd
->memid
, pnames
, maxPNames
, &nPNames
);
1209 if (fd
->cParams
< int(nPNames
))
1212 SysFreeString(pnames
[0]);
1216 ElemDescToParam(fd
->elemdescFunc
, func
.retType
);
1217 for (int p
= 0; p
< fd
->cParams
; p
++)
1221 ElemDescToParam(fd
->lprgelemdescParam
[p
], param
);
1223 param
.name
= pnames
[pbase
+ p
];
1224 SysFreeString(pnames
[pbase
+ p
]);
1226 param
.isOptional
= (p
> fd
->cParams
- fd
->cParamsOpt
);
1228 func
.hasOut
|= (param
.IsOut() || param
.isPtr
);
1229 func
.params
.push_back(param
);
1235 m_events
.push_back(func
);
1236 m_eventMemberIds
[fd
->memid
] = m_events
.size() - 1;
1240 if (fd
->invkind
== INVOKE_FUNC
)
1242 m_methods
.push_back(func
);
1243 m_methodNames
[func
.name
] = m_methods
.size() - 1;
1247 NameMap::iterator it
= m_propNames
.find(func
.name
);
1249 if (it
== m_propNames
.end())
1251 m_props
.push_back(PropX());
1252 idx
= m_props
.size() - 1;
1253 m_propNames
[func
.name
] = idx
;
1254 m_props
[idx
].name
= func
.name
;
1255 m_props
[idx
].memid
= func
.memid
;
1261 if (fd
->invkind
== INVOKE_PROPERTYGET
)
1262 m_props
[idx
].type
= func
.retType
;
1263 else if (func
.params
.size() > 0)
1265 m_props
[idx
].arg
= func
.params
[0];
1266 m_props
[idx
].putByRef
= (fd
->invkind
== INVOKE_PROPERTYPUTREF
);
1273 typeInfo
->ReleaseFuncDesc(fd
);
1277 typeInfo
->ReleaseTypeAttr(ta
);
1280 ///////////////////////////////////////////////
1281 // Type Info exposure
1282 const wxActiveX::FuncX
& wxActiveX::GetEventDesc(int idx
) const
1284 wxASSERT(idx
>= 0 && idx
< GetEventCount());
1286 return m_events
[idx
];
1289 const wxActiveX::PropX
& wxActiveX::GetPropDesc(int idx
) const
1291 if (idx
< 0 || idx
>= GetPropCount())
1292 throw exception("Property index out of bounds");
1294 return m_props
[idx
];
1297 const wxActiveX::PropX
& wxActiveX::GetPropDesc(const wxString
& name
) const
1299 NameMap::const_iterator it
= m_propNames
.find(name
);
1300 if (it
== m_propNames
.end())
1303 s
<< _T("property <") << name
<< _T("> not found");
1304 throw exception(s
.mb_str());
1307 return GetPropDesc(it
->second
);
1310 const wxActiveX::FuncX
& wxActiveX::GetMethodDesc(int idx
) const
1312 if (idx
< 0 || idx
>= GetMethodCount())
1313 throw exception("Method index out of bounds");
1316 return m_methods
[idx
];
1320 const wxActiveX::FuncX
& wxActiveX::GetMethodDesc(const wxString
& name
) const
1322 NameMap::const_iterator it
= m_methodNames
.find(name
);
1323 if (it
== m_methodNames
.end())
1326 s
<< _T("method <") << name
<< _T("> not found");
1327 throw exception(s
.mb_str());
1330 return GetMethodDesc(it
->second
);
1334 void wxActiveX::SetProp(MEMBERID name
, VARIANTARG
& value
)
1336 DISPID pids
[1] = {DISPID_PROPERTYPUT
};
1337 DISPPARAMS params
= {&value
, pids
, 1, 1};
1340 memset(&x
, 0, sizeof(x
));
1341 unsigned int argErr
= 0;
1343 HRESULT hr
= m_Dispatch
->Invoke(
1345 IID_NULL
, LOCALE_USER_DEFAULT
, DISPATCH_PROPERTYPUT
,
1346 ¶ms
, NULL
, &x
, &argErr
);
1348 WXOLE_WARN(hr
, "Invoke Prop(...)");
1351 void wxActiveX::SetProp(const wxString
&name
, const wxVariant
&value
)
1353 const PropX
& prop
= GetPropDesc(name
);
1354 if (! prop
.CanSet())
1357 s
<< _T("property <") << name
<< _T("> is readonly");
1358 throw exception(s
.mb_str());
1361 VARIANT v
= {prop
.arg
.vt
};
1362 VariantToMSWVariant(value
, v
);
1363 SetProp(prop
.memid
, v
);
1364 VariantClear(&v
); // this releases any BSTR's etc
1367 VARIANT
wxActiveX::GetPropAsVariant(MEMBERID name
)
1372 DISPPARAMS params
= {NULL
, NULL
, 0, 0};
1375 memset(&x
, 0, sizeof(x
));
1376 unsigned int argErr
= 0;
1378 HRESULT hr
= m_Dispatch
->Invoke(
1380 IID_NULL
, LOCALE_USER_DEFAULT
, DISPATCH_PROPERTYGET
,
1381 ¶ms
, &v
, &x
, &argErr
);
1383 WXOLE_WARN(hr
, "Invoke Prop(...)");
1388 VARIANT
wxActiveX::GetPropAsVariant(const wxString
& name
)
1390 const PropX
& prop
= GetPropDesc(name
);
1391 if (! prop
.CanGet())
1394 s
<< _T("property <") << name
<< _T("> is writeonly");
1395 throw exception(s
.mb_str());
1398 return GetPropAsVariant(prop
.memid
);
1401 wxVariant
wxActiveX::GetPropAsWxVariant(const wxString
& name
)
1403 VARIANT v
= GetPropAsVariant(name
);
1404 HRESULT hr
= VariantChangeType(&v
, &v
, 0, VT_BSTR
);
1405 if (! SUCCEEDED(hr
))
1406 throw exception("Unable to convert variant");
1409 MSWVariantToVariant(v
, wv
);
1416 wxString
wxActiveX::GetPropAsString(const wxString
& name
)
1418 VARIANT v
= GetPropAsVariant(name
);
1419 HRESULT hr
= VariantChangeType(&v
, &v
, 0, VT_BSTR
);
1420 if (! SUCCEEDED(hr
))
1421 throw exception("Unable to convert variant");
1423 wxString s
= v
.bstrVal
;
1429 char wxActiveX::GetPropAsChar(const wxString
& name
)
1431 VARIANT v
= GetPropAsVariant(name
);
1432 HRESULT hr
= VariantChangeType(&v
, &v
, 0, VT_I1
);
1433 if (! SUCCEEDED(hr
))
1434 throw exception("Unable to convert variant");
1439 long wxActiveX::GetPropAsLong(const wxString
& name
)
1441 VARIANT v
= GetPropAsVariant(name
);
1442 HRESULT hr
= VariantChangeType(&v
, &v
, 0, VT_I4
);
1443 if (! SUCCEEDED(hr
))
1444 throw exception("Unable to convert variant");
1449 bool wxActiveX::GetPropAsBool(const wxString
& name
)
1451 VARIANT v
= GetPropAsVariant(name
);
1452 HRESULT hr
= VariantChangeType(&v
, &v
, 0, VT_BOOL
);
1453 if (! SUCCEEDED(hr
))
1454 throw exception("Unable to convert variant");
1456 return v
.boolVal
!= 0;
1459 double wxActiveX::GetPropAsDouble(const wxString
& name
)
1461 VARIANT v
= GetPropAsVariant(name
);
1462 HRESULT hr
= VariantChangeType(&v
, &v
, 0, VT_R8
);
1463 if (! SUCCEEDED(hr
))
1464 throw exception("Unable to convert variant");
1469 wxDateTime
wxActiveX::GetPropAsDateTime(const wxString
& name
)
1472 VARIANT v
= GetPropAsVariant(name
);
1474 if (! VariantToWxDateTime(v
, dt
))
1475 throw exception("Unable to convert variant to wxDateTime");
1480 void *wxActiveX::GetPropAsPointer(const wxString
& name
)
1482 VARIANT v
= GetPropAsVariant(name
);
1483 HRESULT hr
= VariantChangeType(&v
, &v
, 0, VT_BYREF
);
1484 if (! SUCCEEDED(hr
))
1485 throw exception("Unable to convert variant");
1493 VARIANT
wxActiveX::CallMethod(MEMBERID name
, VARIANTARG args
[], int argc
)
1495 DISPPARAMS pargs
= {args
, NULL
, argc
, 0};
1497 VariantInit(&retVal
);
1500 memset(&x
, 0, sizeof(x
));
1501 unsigned int argErr
= 0;
1503 HRESULT hr
= m_Dispatch
->Invoke(
1505 IID_NULL
, LOCALE_USER_DEFAULT
, DISPATCH_METHOD
,
1506 &pargs
, &retVal
, &x
, &argErr
);
1508 WXOLE_WARN(hr
, "Invoke Method(...)");
1512 VARIANT
wxActiveX::CallMethod(const wxString
& name
, VARIANTARG args
[], int argc
)
1514 const FuncX
& func
= GetMethodDesc(name
);
1516 argc
= func
.params
.size();
1518 return CallMethod(func
.memid
, args
, argc
);
1522 wxVariant
wxActiveX::CallMethod(const wxString
& name
, wxVariant args
[], int nargs
)
1524 const FuncX
& func
= GetMethodDesc(name
);
1529 VARIANTARG
*vargs
= NULL
;
1531 nargs
= func
.params
.size();
1534 vargs
= new VARIANTARG
[nargs
];
1538 // init type of vargs
1539 for (int i
= 0; i
< nargs
; i
++)
1540 vargs
[nargs
- i
- 1].vt
= func
.params
[i
].vt
;
1543 for (i
= 0; i
< nargs
; i
++)
1544 VariantToMSWVariant(args
[i
], vargs
[nargs
- i
- 1]);
1547 VARIANT rv
= CallMethod(func
.memid
, vargs
, nargs
);
1549 // process any by ref params
1552 for (int i
= 0; i
< nargs
; i
++)
1554 VARIANTARG
& va
= vargs
[nargs
- i
- 1];
1555 const wxActiveX::ParamX
&px
= func
.params
[i
];
1559 wxVariant
& vx
= args
[i
];
1561 MSWVariantToVariant(va
, vx
);
1568 for (int i
= 0; i
< nargs
; i
++)
1569 VariantClear(&vargs
[i
]);
1575 MSWVariantToVariant(rv
, ret
);
1582 ///////////////////////////////////////////////
1584 HRESULT
wxActiveX::ConnectAdvise(REFIID riid
, IUnknown
*events
)
1586 wxOleConnectionPoint cp
;
1587 DWORD adviseCookie
= 0;
1589 wxAutoOleInterface
<IConnectionPointContainer
> cpContainer(IID_IConnectionPointContainer
, m_ActiveX
);
1590 if (! cpContainer
.Ok())
1593 HRESULT hret
= cpContainer
->FindConnectionPoint(riid
, cp
.GetRef());
1594 if (! SUCCEEDED(hret
))
1597 hret
= cp
->Advise(events
, &adviseCookie
);
1599 if (SUCCEEDED(hret
))
1600 m_connections
.push_back(wxOleConnection(cp
, adviseCookie
));
1603 WXOLE_WARN(hret
, "ConnectAdvise");
1609 HRESULT
wxActiveX::AmbientPropertyChanged(DISPID dispid
)
1611 wxAutoOleInterface
<IOleControl
> oleControl(IID_IOleControl
, m_oleObject
);
1613 if (oleControl
.Ok())
1614 return oleControl
->OnAmbientPropertyChange(dispid
);
1619 #define HIMETRIC_PER_INCH 2540
1620 #define MAP_PIX_TO_LOGHIM(x,ppli) MulDiv(HIMETRIC_PER_INCH, (x), (ppli))
1622 static void PixelsToHimetric(SIZEL
&sz
)
1624 static int logX
= 0;
1625 static int logY
= 0;
1630 HDC dc
= GetDC(NULL
);
1631 logX
= GetDeviceCaps(dc
, LOGPIXELSX
);
1632 logY
= GetDeviceCaps(dc
, LOGPIXELSY
);
1633 ReleaseDC(NULL
, dc
);
1636 #define HIMETRIC_INCH 2540
1637 #define CONVERT(x, logpixels) MulDiv(HIMETRIC_INCH, (x), (logpixels))
1639 sz
.cx
= CONVERT(sz
.cx
, logX
);
1640 sz
.cy
= CONVERT(sz
.cy
, logY
);
1643 #undef HIMETRIC_INCH
1647 void wxActiveX::OnSize(wxSizeEvent
& event
)
1650 GetClientSize(&w
, &h
);
1658 if (w
<= 0 && h
<= 0)
1661 // extents are in HIMETRIC units
1662 if (m_oleObject
.Ok())
1665 PixelsToHimetric(sz
);
1669 m_oleObject
->GetExtent(DVASPECT_CONTENT
, &sz2
);
1670 if (sz2
.cx
!= sz
.cx
|| sz
.cy
!= sz2
.cy
)
1671 m_oleObject
->SetExtent(DVASPECT_CONTENT
, &sz
);
1674 if (m_oleInPlaceObject
.Ok())
1675 m_oleInPlaceObject
->SetObjectRects(&posRect
, &posRect
);
1678 void wxActiveX::OnPaint(wxPaintEvent
& event
)
1680 wxLogTrace(wxT(""),wxT("repainting activex win"));
1691 // Draw only when control is windowless or deactivated
1694 ::RedrawWindow(m_oleObjectHWND
, NULL
, NULL
, RDW_INTERNALPAINT
);
1696 RECTL
*prcBounds
= (RECTL
*) &posRect
;
1697 m_viewObject
->Draw(DVASPECT_CONTENT
, -1, NULL
, NULL
, NULL
,
1698 (HDC
)dc
.GetHDC(), prcBounds
, NULL
, NULL
, 0);
1703 dc
.SetBrush(*wxRED_BRUSH
);
1704 dc
.DrawRectangle(0, 0, w
, h
);
1705 dc
.SetBrush(wxNullBrush
);
1711 void wxActiveX::OnMouse(wxMouseEvent
& event
)
1713 if (m_oleObjectHWND
== NULL
)
1715 wxLogTrace(wxT(""),wxT("no oleInPlaceObject"));
1720 wxLogTrace(wxT(""),wxT("mouse event"));
1724 LRESULT lResult
= 0;
1726 if (event
.m_metaDown
)
1727 wParam
|= MK_CONTROL
;
1728 if (event
.m_shiftDown
)
1730 if (event
.m_leftDown
)
1731 wParam
|= MK_LBUTTON
;
1732 if (event
.m_middleDown
)
1733 wParam
|= MK_MBUTTON
;
1734 if (event
.m_rightDown
)
1735 wParam
|= MK_RBUTTON
;
1736 lParam
= event
.m_x
<< 16;
1737 lParam
|= event
.m_y
;
1739 if (event
.LeftDown())
1740 msg
= WM_LBUTTONDOWN
;
1741 else if (event
.LeftDClick())
1742 msg
= WM_LBUTTONDBLCLK
;
1743 else if (event
.LeftUp())
1745 else if (event
.MiddleDown())
1746 msg
= WM_MBUTTONDOWN
;
1747 else if (event
.MiddleDClick())
1748 msg
= WM_MBUTTONDBLCLK
;
1749 else if (event
.MiddleUp())
1751 else if (event
.RightDown())
1752 msg
= WM_RBUTTONDOWN
;
1753 else if (event
.RightDClick())
1754 msg
= WM_RBUTTONDBLCLK
;
1755 else if (event
.RightUp())
1757 else if (event
.Moving() || event
.Dragging())
1763 wxLogTrace(wxT(""),wxT("no message"));
1764 event
.Skip(); return;
1767 if (!::SendMessage(m_oleObjectHWND
, msg
, wParam
, lParam
))
1769 wxLogTrace(wxT(""),wxT("msg not delivered"));
1774 wxLogTrace(wxT(""),wxT("msg sent"));
1777 long wxActiveX::MSWWindowProc(WXUINT nMsg
, WXWPARAM wParam
, WXLPARAM lParam
)
1779 if (m_oleObjectHWND
== NULL
)
1780 return wxWindow::MSWWindowProc(nMsg
, wParam
, lParam
);
1789 case WM_SYSDEADCHAR
:
1792 PostMessage(m_oleObjectHWND
, nMsg
, wParam
, lParam
);
1795 return wxWindow::MSWWindowProc(nMsg
, wParam
, lParam
);
1799 void wxActiveX::OnSetFocus(wxFocusEvent
& event
)
1801 if (m_oleInPlaceActiveObject
.Ok())
1802 m_oleInPlaceActiveObject
->OnFrameWindowActivate(TRUE
);
1805 void wxActiveX::OnKillFocus(wxFocusEvent
& event
)
1807 if (m_oleInPlaceActiveObject
.Ok())
1808 m_oleInPlaceActiveObject
->OnFrameWindowActivate(FALSE
);
1812 FrameSite::FrameSite(wxActiveX
* win
)
1815 m_bSupportsWindowlessActivation
= true;
1816 m_bInPlaceLocked
= false;
1817 m_bUIActive
= false;
1818 m_bInPlaceActive
= false;
1819 m_bWindowless
= false;
1821 m_nAmbientLocale
= 0;
1822 m_clrAmbientForeColor
= ::GetSysColor(COLOR_WINDOWTEXT
);
1823 m_clrAmbientBackColor
= ::GetSysColor(COLOR_WINDOW
);
1824 m_bAmbientShowHatching
= true;
1825 m_bAmbientShowGrabHandles
= true;
1826 m_bAmbientAppearance
= true;
1829 m_hWndParent
= (HWND
)m_window
->GetHWND();
1832 FrameSite::~FrameSite()
1839 HRESULT
FrameSite::GetIDsOfNames(REFIID riid
, OLECHAR
** rgszNames
, unsigned int cNames
,
1840 LCID lcid
, DISPID
* rgDispId
)
1842 WXOLE_TRACE("IDispatch::GetIDsOfNames");
1846 HRESULT
FrameSite::GetTypeInfo(unsigned int iTInfo
, LCID lcid
, ITypeInfo
** ppTInfo
)
1848 WXOLE_TRACE("IDispatch::GetTypeInfo");
1852 HRESULT
FrameSite::GetTypeInfoCount(unsigned int * pcTInfo
)
1854 WXOLE_TRACE("IDispatch::GetTypeInfoCount");
1858 HRESULT
FrameSite::Invoke(DISPID dispIdMember
, REFIID riid
, LCID lcid
,
1859 WORD wFlags
, DISPPARAMS
* pDispParams
,
1860 VARIANT
* pVarResult
, EXCEPINFO
* pExcepInfo
,
1861 unsigned int * puArgErr
)
1863 WXOLE_TRACE("IDispatch::Invoke");
1865 if (!(wFlags
& DISPATCH_PROPERTYGET
))
1870 if (pVarResult
== NULL
)
1871 return E_INVALIDARG
;
1873 //The most common case is boolean, use as an initial type
1874 V_VT(pVarResult
) = VT_BOOL
;
1876 switch (dispIdMember
)
1878 case DISPID_AMBIENT_MESSAGEREFLECT
:
1879 WXOLE_TRACE("Invoke::DISPID_AMBIENT_MESSAGEREFLECT");
1880 V_BOOL(pVarResult
)= FALSE
;
1883 case DISPID_AMBIENT_DISPLAYASDEFAULT
:
1884 WXOLE_TRACE("Invoke::DISPID_AMBIENT_DISPLAYASDEFAULT");
1885 V_BOOL(pVarResult
)= TRUE
;
1888 case DISPID_AMBIENT_OFFLINEIFNOTCONNECTED
:
1889 WXOLE_TRACE("Invoke::DISPID_AMBIENT_OFFLINEIFNOTCONNECTED");
1890 V_BOOL(pVarResult
) = TRUE
;
1894 case DISPID_AMBIENT_SILENT
:
1895 WXOLE_TRACE("Invoke::DISPID_AMBIENT_SILENT");
1896 V_BOOL(pVarResult
)= TRUE
;
1899 case DISPID_AMBIENT_APPEARANCE
:
1900 pVarResult
->vt
= VT_BOOL
;
1901 pVarResult
->boolVal
= m_bAmbientAppearance
;
1904 case DISPID_AMBIENT_FORECOLOR
:
1905 pVarResult
->vt
= VT_I4
;
1906 pVarResult
->lVal
= (long) m_clrAmbientForeColor
;
1909 case DISPID_AMBIENT_BACKCOLOR
:
1910 pVarResult
->vt
= VT_I4
;
1911 pVarResult
->lVal
= (long) m_clrAmbientBackColor
;
1914 case DISPID_AMBIENT_LOCALEID
:
1915 pVarResult
->vt
= VT_I4
;
1916 pVarResult
->lVal
= (long) m_nAmbientLocale
;
1919 case DISPID_AMBIENT_USERMODE
:
1920 pVarResult
->vt
= VT_BOOL
;
1921 pVarResult
->boolVal
= m_window
->m_bAmbientUserMode
;
1924 case DISPID_AMBIENT_SHOWGRABHANDLES
:
1925 pVarResult
->vt
= VT_BOOL
;
1926 pVarResult
->boolVal
= m_bAmbientShowGrabHandles
;
1929 case DISPID_AMBIENT_SHOWHATCHING
:
1930 pVarResult
->vt
= VT_BOOL
;
1931 pVarResult
->boolVal
= m_bAmbientShowHatching
;
1935 return DISP_E_MEMBERNOTFOUND
;
1943 HRESULT
FrameSite::GetWindow(HWND
* phwnd
)
1945 WXOLE_TRACE("IOleWindow::GetWindow");
1947 return E_INVALIDARG
;
1948 (*phwnd
) = m_hWndParent
;
1952 HRESULT
FrameSite::ContextSensitiveHelp(BOOL fEnterMode
)
1954 WXOLE_TRACE("IOleWindow::ContextSensitiveHelp");
1958 //IOleInPlaceUIWindow
1960 HRESULT
FrameSite::GetBorder(LPRECT lprectBorder
)
1962 WXOLE_TRACE("IOleInPlaceUIWindow::GetBorder");
1963 if (lprectBorder
== NULL
)
1964 return E_INVALIDARG
;
1965 return INPLACE_E_NOTOOLSPACE
;
1968 HRESULT
FrameSite::RequestBorderSpace(LPCBORDERWIDTHS pborderwidths
)
1970 WXOLE_TRACE("IOleInPlaceUIWindow::RequestBorderSpace");
1971 if (pborderwidths
== NULL
)
1972 return E_INVALIDARG
;
1973 return INPLACE_E_NOTOOLSPACE
;
1976 HRESULT
FrameSite::SetBorderSpace(LPCBORDERWIDTHS pborderwidths
)
1978 WXOLE_TRACE("IOleInPlaceUIWindow::SetBorderSpace");
1982 HRESULT
FrameSite::SetActiveObject(IOleInPlaceActiveObject
*pActiveObject
, LPCOLESTR pszObjName
)
1984 WXOLE_TRACE("IOleInPlaceUIWindow::SetActiveObject");
1987 pActiveObject
->AddRef();
1989 m_window
->m_oleInPlaceActiveObject
= pActiveObject
;
1995 HRESULT
FrameSite::InsertMenus(HMENU hmenuShared
, LPOLEMENUGROUPWIDTHS lpMenuWidths
)
1997 WXOLE_TRACE("IOleInPlaceFrame::InsertMenus");
2001 HRESULT
FrameSite::SetMenu(HMENU hmenuShared
, HOLEMENU holemenu
, HWND hwndActiveObject
)
2003 WXOLE_TRACE("IOleInPlaceFrame::SetMenu");
2007 HRESULT
FrameSite::RemoveMenus(HMENU hmenuShared
)
2009 WXOLE_TRACE("IOleInPlaceFrame::RemoveMenus");
2013 HRESULT
FrameSite::SetStatusText(LPCOLESTR pszStatusText
)
2015 WXOLE_TRACE("IOleInPlaceFrame::SetStatusText");
2016 //((wxFrame*)wxGetApp().GetTopWindow())->GetStatusBar()->SetStatusText(pszStatusText);
2020 HRESULT
FrameSite::EnableModeless(BOOL fEnable
)
2022 WXOLE_TRACE("IOleInPlaceFrame::EnableModeless");
2026 HRESULT
FrameSite::TranslateAccelerator(LPMSG lpmsg
, WORD wID
)
2028 WXOLE_TRACE("IOleInPlaceFrame::TranslateAccelerator");
2029 // TODO: send an event with this id
2030 if (m_window
->m_oleInPlaceActiveObject
.Ok())
2031 m_window
->m_oleInPlaceActiveObject
->TranslateAccelerator(lpmsg
);
2038 HRESULT
FrameSite::CanInPlaceActivate()
2040 WXOLE_TRACE("IOleInPlaceSite::CanInPlaceActivate");
2044 HRESULT
FrameSite::OnInPlaceActivate()
2046 WXOLE_TRACE("IOleInPlaceSite::OnInPlaceActivate");
2047 m_bInPlaceActive
= true;
2051 HRESULT
FrameSite::OnUIActivate()
2053 WXOLE_TRACE("IOleInPlaceSite::OnUIActivate");
2058 HRESULT
FrameSite::GetWindowContext(IOleInPlaceFrame
**ppFrame
,
2059 IOleInPlaceUIWindow
**ppDoc
,
2061 LPRECT lprcClipRect
,
2062 LPOLEINPLACEFRAMEINFO lpFrameInfo
)
2064 WXOLE_TRACE("IOleInPlaceSite::GetWindowContext");
2065 if (ppFrame
== NULL
|| ppDoc
== NULL
|| lprcPosRect
== NULL
||
2066 lprcClipRect
== NULL
|| lpFrameInfo
== NULL
)
2068 if (ppFrame
!= NULL
)
2072 return E_INVALIDARG
;
2075 HRESULT hr
= QueryInterface(IID_IOleInPlaceFrame
, (void **) ppFrame
);
2076 if (! SUCCEEDED(hr
))
2078 WXOLE_TRACE("IOleInPlaceSite::IOleInPlaceFrame Error !");
2079 return E_UNEXPECTED
;
2082 hr
= QueryInterface(IID_IOleInPlaceUIWindow
, (void **) ppDoc
);
2083 if (! SUCCEEDED(hr
))
2085 WXOLE_TRACE("IOleInPlaceSite::IOleInPlaceUIWindow Error !");
2086 (*ppFrame
)->Release();
2088 return E_UNEXPECTED
;
2092 m_window
->GetClientSize(&w
, &h
);
2095 lprcPosRect
->left
= lprcPosRect
->top
= 0;
2096 lprcPosRect
->right
= w
;
2097 lprcPosRect
->bottom
= h
;
2101 lprcClipRect
->left
= lprcClipRect
->top
= 0;
2102 lprcClipRect
->right
= w
;
2103 lprcClipRect
->bottom
= h
;
2106 memset(lpFrameInfo
, 0, sizeof(OLEINPLACEFRAMEINFO
));
2107 lpFrameInfo
->cb
= sizeof(OLEINPLACEFRAMEINFO
);
2108 lpFrameInfo
->hwndFrame
= m_hWndParent
;
2113 HRESULT
FrameSite::Scroll(SIZE scrollExtent
)
2115 WXOLE_TRACE("IOleInPlaceSite::Scroll");
2119 HRESULT
FrameSite::OnUIDeactivate(BOOL fUndoable
)
2121 WXOLE_TRACE("IOleInPlaceSite::OnUIDeactivate");
2122 m_bUIActive
= false;
2126 HRESULT
FrameSite::OnInPlaceDeactivate()
2128 WXOLE_TRACE("IOleInPlaceSite::OnInPlaceDeactivate");
2129 m_bInPlaceActive
= false;
2133 HRESULT
FrameSite::DiscardUndoState()
2135 WXOLE_TRACE("IOleInPlaceSite::DiscardUndoState");
2139 HRESULT
FrameSite::DeactivateAndUndo()
2141 WXOLE_TRACE("IOleInPlaceSite::DeactivateAndUndo");
2145 HRESULT
FrameSite::OnPosRectChange(LPCRECT lprcPosRect
)
2147 WXOLE_TRACE("IOleInPlaceSite::OnPosRectChange");
2148 if (m_window
->m_oleInPlaceObject
.Ok() && lprcPosRect
)
2149 m_window
->m_oleInPlaceObject
->SetObjectRects(lprcPosRect
, lprcPosRect
);
2156 HRESULT
FrameSite::OnInPlaceActivateEx(BOOL
* pfNoRedraw
, DWORD dwFlags
)
2158 WXOLE_TRACE("IOleInPlaceSiteEx::OnInPlaceActivateEx");
2159 OleLockRunning(m_window
->m_ActiveX
, TRUE
, FALSE
);
2161 (*pfNoRedraw
) = FALSE
;
2165 HRESULT
FrameSite::OnInPlaceDeactivateEx(BOOL fNoRedraw
)
2167 WXOLE_TRACE("IOleInPlaceSiteEx::OnInPlaceDeactivateEx");
2168 OleLockRunning(m_window
->m_ActiveX
, FALSE
, FALSE
);
2172 HRESULT
FrameSite::RequestUIActivate()
2174 WXOLE_TRACE("IOleInPlaceSiteEx::RequestUIActivate");
2181 HRESULT
FrameSite::SaveObject()
2183 WXOLE_TRACE("IOleClientSite::SaveObject");
2187 const char *OleGetMonikerToStr(DWORD dwAssign
)
2191 case OLEGETMONIKER_ONLYIFTHERE
: return "OLEGETMONIKER_ONLYIFTHERE";
2192 case OLEGETMONIKER_FORCEASSIGN
: return "OLEGETMONIKER_FORCEASSIGN";
2193 case OLEGETMONIKER_UNASSIGN
: return "OLEGETMONIKER_UNASSIGN";
2194 case OLEGETMONIKER_TEMPFORUSER
: return "OLEGETMONIKER_TEMPFORUSER";
2195 default : return "Bad Enum";
2199 const char *OleGetWhicMonikerStr(DWORD dwWhichMoniker
)
2201 switch(dwWhichMoniker
)
2203 case OLEWHICHMK_CONTAINER
: return "OLEWHICHMK_CONTAINER";
2204 case OLEWHICHMK_OBJREL
: return "OLEWHICHMK_OBJREL";
2205 case OLEWHICHMK_OBJFULL
: return "OLEWHICHMK_OBJFULL";
2206 default : return "Bad Enum";
2210 HRESULT
FrameSite::GetMoniker(DWORD dwAssign
, DWORD dwWhichMoniker
,
2213 WXOLE_TRACEOUT("IOleClientSite::GetMoniker(" << OleGetMonikerToStr(dwAssign
) << ", " << OleGetWhicMonikerStr(dwWhichMoniker
) << ")");
2220 HRESULT hr = CreateFileMoniker(L"e:\\dev\\wxie\\bug-zap.swf", ppmk);
2229 HRESULT
FrameSite::GetContainer(LPOLECONTAINER
* ppContainer
)
2231 WXOLE_TRACE("IOleClientSite::GetContainer");
2232 if (ppContainer
== NULL
)
2233 return E_INVALIDARG
;
2235 HRESULT hr
= QueryInterface(IID_IOleContainer
, (void**)(ppContainer
));
2236 wxASSERT(SUCCEEDED(hr
));
2241 HRESULT
FrameSite::ShowObject()
2243 WXOLE_TRACE("IOleClientSite::ShowObject");
2244 if (m_window
->m_oleObjectHWND
)
2245 ::ShowWindow(m_window
->m_oleObjectHWND
, SW_SHOW
);
2249 HRESULT
FrameSite::OnShowWindow(BOOL fShow
)
2251 WXOLE_TRACE("IOleClientSite::OnShowWindow");
2255 HRESULT
FrameSite::RequestNewObjectLayout()
2257 WXOLE_TRACE("IOleClientSite::RequestNewObjectLayout");
2261 // IParseDisplayName
2263 HRESULT
FrameSite::ParseDisplayName(IBindCtx
*pbc
, LPOLESTR pszDisplayName
,
2264 ULONG
*pchEaten
, IMoniker
**ppmkOut
)
2266 WXOLE_TRACE("IParseDisplayName::ParseDisplayName");
2272 HRESULT
FrameSite::EnumObjects(DWORD grfFlags
, IEnumUnknown
**ppenum
)
2274 WXOLE_TRACE("IOleContainer::EnumObjects");
2278 HRESULT
FrameSite::LockContainer(BOOL fLock
)
2280 WXOLE_TRACE("IOleContainer::LockContainer");
2287 HRESULT
FrameSite::GetObject(LPOLESTR pszItem
, DWORD dwSpeedNeeded
,
2288 IBindCtx
* pbc
, REFIID riid
, void ** ppvObject
)
2290 WXOLE_TRACE("IOleItemContainer::GetObject");
2291 if (pszItem
== NULL
)
2292 return E_INVALIDARG
;
2293 if (ppvObject
== NULL
)
2294 return E_INVALIDARG
;
2297 return MK_E_NOOBJECT
;
2300 HRESULT
FrameSite::GetObjectStorage(LPOLESTR pszItem
, IBindCtx
* pbc
,
2301 REFIID riid
, void ** ppvStorage
)
2303 WXOLE_TRACE("IOleItemContainer::GetObjectStorage");
2304 if (pszItem
== NULL
)
2305 return E_INVALIDARG
;
2306 if (ppvStorage
== NULL
)
2307 return E_INVALIDARG
;
2310 return MK_E_NOOBJECT
;
2313 HRESULT
FrameSite::IsRunning(LPOLESTR pszItem
)
2315 WXOLE_TRACE("IOleItemContainer::IsRunning");
2316 if (pszItem
== NULL
)
2317 return E_INVALIDARG
;
2319 return MK_E_NOOBJECT
;
2326 HRESULT
FrameSite::OnControlInfoChanged()
2328 WXOLE_TRACE("IOleControlSite::OnControlInfoChanged");
2332 HRESULT
FrameSite::LockInPlaceActive(BOOL fLock
)
2334 WXOLE_TRACE("IOleControlSite::LockInPlaceActive");
2335 m_bInPlaceLocked
= (fLock
) ? true : false;
2339 HRESULT
FrameSite::GetExtendedControl(IDispatch
** ppDisp
)
2341 WXOLE_TRACE("IOleControlSite::GetExtendedControl");
2345 HRESULT
FrameSite::TransformCoords(POINTL
* pPtlHimetric
, POINTF
* pPtfContainer
, DWORD dwFlags
)
2347 WXOLE_TRACE("IOleControlSite::TransformCoords");
2350 if (pPtlHimetric
== NULL
)
2351 return E_INVALIDARG
;
2353 if (pPtfContainer
== NULL
)
2354 return E_INVALIDARG
;
2360 HRESULT
FrameSite::TranslateAccelerator(LPMSG pMsg
, DWORD grfModifiers
)
2362 WXOLE_TRACE("IOleControlSite::TranslateAccelerator");
2363 // TODO: send an event with this id
2367 HRESULT
FrameSite::OnFocus(BOOL fGotFocus
)
2369 WXOLE_TRACE("IOleControlSite::OnFocus");
2373 HRESULT
FrameSite::ShowPropertyFrame()
2375 WXOLE_TRACE("IOleControlSite::ShowPropertyFrame");
2381 HRESULT
FrameSite::QueryStatus(const GUID
* pguidCmdGroup
, ULONG cCmds
,
2382 OLECMD
* prgCmds
, OLECMDTEXT
* pCmdTet
)
2384 WXOLE_TRACE("IOleCommandTarget::QueryStatus");
2385 if (prgCmds
== NULL
) return E_INVALIDARG
;
2386 bool bCmdGroupFound
= false;
2388 for (ULONG nCmd
= 0; nCmd
< cCmds
; nCmd
++)
2390 // unsupported by default
2391 prgCmds
[nCmd
].cmdf
= 0;
2396 if (!bCmdGroupFound
) { OLECMDERR_E_UNKNOWNGROUP
; }
2400 HRESULT
FrameSite::Exec(const GUID
* pguidCmdGroup
, DWORD nCmdID
,
2401 DWORD nCmdExecOpt
, VARIANTARG
* pVaIn
,
2402 VARIANTARG
* pVaOut
)
2404 WXOLE_TRACE("IOleCommandTarget::Exec");
2405 bool bCmdGroupFound
= false;
2407 if (!bCmdGroupFound
) { OLECMDERR_E_UNKNOWNGROUP
; }
2408 return OLECMDERR_E_NOTSUPPORTED
;
2413 void STDMETHODCALLTYPE
FrameSite::OnDataChange(FORMATETC
* pFormatEtc
, STGMEDIUM
* pgStgMed
)
2415 WXOLE_TRACE("IAdviseSink::OnDataChange");
2418 void STDMETHODCALLTYPE
FrameSite::OnViewChange(DWORD dwAspect
, LONG lIndex
)
2420 WXOLE_TRACE("IAdviseSink::OnViewChange");
2421 // redraw the control
2424 void STDMETHODCALLTYPE
FrameSite::OnRename(IMoniker
* pmk
)
2426 WXOLE_TRACE("IAdviseSink::OnRename");
2429 void STDMETHODCALLTYPE
FrameSite::OnSave()
2431 WXOLE_TRACE("IAdviseSink::OnSave");
2434 void STDMETHODCALLTYPE
FrameSite::OnClose()
2436 WXOLE_TRACE("IAdviseSink::OnClose");
2439 /////////////////////////////////////////////
2441 HRESULT STDMETHODCALLTYPE
FrameSite::ActivateMe(
2442 /* [in] */ IOleDocumentView __RPC_FAR
*pViewToActivate
)
2444 wxAutoOleInterface
<IOleInPlaceSite
> inPlaceSite(IID_IOleInPlaceSite
, (IDispatch
*) this);
2445 if (!inPlaceSite
.Ok())
2448 if (pViewToActivate
)
2450 m_window
->m_docView
= pViewToActivate
;
2451 m_window
->m_docView
->SetInPlaceSite(inPlaceSite
);
2455 wxAutoOleInterface
<IOleDocument
> oleDoc(IID_IOleDocument
, m_window
->m_oleObject
);
2459 HRESULT hr
= oleDoc
->CreateView(inPlaceSite
, NULL
, 0, m_window
->m_docView
.GetRef());
2463 m_window
->m_docView
->SetInPlaceSite(inPlaceSite
);
2466 m_window
->m_docView
->UIActivate(TRUE
);
2472 static IMalloc
*iMalloc
= NULL
;
2474 IMalloc
*wxOleInit::GetIMalloc()
2480 wxOleInit::wxOleInit()
2482 if (OleInitialize(NULL
) == S_OK
&& iMalloc
== NULL
)
2483 CoGetMalloc(1, &iMalloc
);
2488 wxOleInit::~wxOleInit()
2492 if (iMalloc
->Release() == 0)
2499 bool GetSysErrMessage(int err
, wxString
& s
)
2503 FORMAT_MESSAGE_FROM_SYSTEM
, NULL
,
2504 err
,0, buf
, sizeof(buf
), NULL
) == 0)
2507 buf
[sizeof(buf
) - 1] = 0;
2512 wxString
OLEHResultToString(HRESULT hr
)
2514 // try formatmessage
2516 if (GetSysErrMessage(hr
, err
))
2522 return wxEmptyString
;
2524 case CONNECT_E_CANNOTCONNECT
:
2525 return _T("Cannot connect to event interface (maybe not there ?) - see MSDN");
2527 case DISP_E_MEMBERNOTFOUND
:
2528 return _T("The requested member does not exist, or the call to Invoke tried to set the value of a read-only property.");
2530 case DISP_E_BADVARTYPE
:
2531 return _T("One of the parameters in rgvarg is not a valid variant type.");
2533 case DISP_E_BADPARAMCOUNT
:
2534 return _T("The number of elements provided to DISPPARAMS is different from the number of parameters accepted by the method or property");
2536 case DISP_E_EXCEPTION
:
2537 return _T("The application needs to raise an exception. In this case, the structure passed in pExcepInfo should be filled in.");
2539 case DISP_E_TYPEMISMATCH
:
2540 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.");
2542 case DISP_E_PARAMNOTOPTIONAL
:
2543 return _T("A required parameter was omitted.");
2545 case DISP_E_PARAMNOTFOUND
:
2546 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.");
2548 case OLECMDERR_E_UNKNOWNGROUP
:
2549 return _T("The pguidCmdGroup parameter is not NULL but does not specify a recognized command group.");
2551 case OLECMDERR_E_NOTSUPPORTED
:
2552 return _T("The nCmdID parameter is not a valid command in the group identified by pguidCmdGroup.");
2554 case OLECMDERR_E_DISABLED
:
2555 return _T("The command identified by nCmdID is currently disabled and cannot be executed.");
2557 case OLECMDERR_E_NOHELP
:
2558 return _T("The caller has asked for help on the command identified by nCmdID, but no help is available.");
2560 case OLECMDERR_E_CANCELED
:
2561 return _T("The user canceled the execution of the command.");
2564 return _T("E_INVALIDARG");
2567 return _T("E_OUTOFMEMORY");
2570 return _T("E_NOINTERFACE");
2573 return _T("E_UNEXPECTED");
2575 case STG_E_INVALIDFLAG
:
2576 return _T("STG_E_INVALIDFLAG");
2579 return _T("E_FAIL");
2582 return _T("E_NOTIMPL");
2587 buf
.Printf(_T("Unknown - 0x%X"), hr
);
2593 // borrowed from src/msw/ole/oleutils.cpp
2594 wxString
GetIIDName(REFIID riid
)
2596 // an association between symbolic name and numeric value of an IID
2600 const wxChar
*szName
;
2603 // construct the table containing all known interfaces
2604 #define ADD_KNOWN_IID(name) { &IID_I##name, _T(#name) }
2605 #define ADD_KNOWN_GUID(name) { &name, _T(#name) }
2607 static const KNOWN_IID aKnownIids
[] =
2609 ADD_KNOWN_IID(ServiceProvider
),
2610 ADD_KNOWN_IID(AdviseSink
),
2611 ADD_KNOWN_IID(AdviseSink2
),
2612 ADD_KNOWN_IID(BindCtx
),
2613 ADD_KNOWN_IID(ClassFactory
),
2614 #if ( !defined( __VISUALC__) || (__VISUALC__!=1010) ) && !defined(__MWERKS__)
2615 ADD_KNOWN_IID(ContinueCallback
),
2616 ADD_KNOWN_IID(EnumOleDocumentViews
),
2617 ADD_KNOWN_IID(OleCommandTarget
),
2618 ADD_KNOWN_IID(OleDocument
),
2619 ADD_KNOWN_IID(OleDocumentSite
),
2620 ADD_KNOWN_IID(OleDocumentView
),
2621 ADD_KNOWN_IID(Print
),
2623 ADD_KNOWN_IID(DataAdviseHolder
),
2624 ADD_KNOWN_IID(DataObject
),
2625 ADD_KNOWN_IID(Debug
),
2626 ADD_KNOWN_IID(DebugStream
),
2627 ADD_KNOWN_IID(DfReserved1
),
2628 ADD_KNOWN_IID(DfReserved2
),
2629 ADD_KNOWN_IID(DfReserved3
),
2630 ADD_KNOWN_IID(Dispatch
),
2631 ADD_KNOWN_IID(DropSource
),
2632 ADD_KNOWN_IID(DropTarget
),
2633 ADD_KNOWN_IID(EnumCallback
),
2634 ADD_KNOWN_IID(EnumFORMATETC
),
2635 ADD_KNOWN_IID(EnumGeneric
),
2636 ADD_KNOWN_IID(EnumHolder
),
2637 ADD_KNOWN_IID(EnumMoniker
),
2638 ADD_KNOWN_IID(EnumOLEVERB
),
2639 ADD_KNOWN_IID(EnumSTATDATA
),
2640 ADD_KNOWN_IID(EnumSTATSTG
),
2641 ADD_KNOWN_IID(EnumString
),
2642 ADD_KNOWN_IID(EnumUnknown
),
2643 ADD_KNOWN_IID(EnumVARIANT
),
2644 ADD_KNOWN_IID(ExternalConnection
),
2645 ADD_KNOWN_IID(InternalMoniker
),
2646 ADD_KNOWN_IID(LockBytes
),
2647 ADD_KNOWN_IID(Malloc
),
2648 ADD_KNOWN_IID(Marshal
),
2649 ADD_KNOWN_IID(MessageFilter
),
2650 ADD_KNOWN_IID(Moniker
),
2651 ADD_KNOWN_IID(OleAdviseHolder
),
2652 ADD_KNOWN_IID(OleCache
),
2653 ADD_KNOWN_IID(OleCache2
),
2654 ADD_KNOWN_IID(OleCacheControl
),
2655 ADD_KNOWN_IID(OleClientSite
),
2656 ADD_KNOWN_IID(OleContainer
),
2657 ADD_KNOWN_IID(OleInPlaceActiveObject
),
2658 ADD_KNOWN_IID(OleInPlaceFrame
),
2659 ADD_KNOWN_IID(OleInPlaceObject
),
2660 ADD_KNOWN_IID(OleInPlaceSite
),
2661 ADD_KNOWN_IID(OleInPlaceUIWindow
),
2662 ADD_KNOWN_IID(OleItemContainer
),
2663 ADD_KNOWN_IID(OleLink
),
2664 ADD_KNOWN_IID(OleManager
),
2665 ADD_KNOWN_IID(OleObject
),
2666 ADD_KNOWN_IID(OlePresObj
),
2667 ADD_KNOWN_IID(OleWindow
),
2668 ADD_KNOWN_IID(PSFactory
),
2669 ADD_KNOWN_IID(ParseDisplayName
),
2670 ADD_KNOWN_IID(Persist
),
2671 ADD_KNOWN_IID(PersistFile
),
2672 ADD_KNOWN_IID(PersistStorage
),
2673 ADD_KNOWN_IID(PersistStream
),
2674 ADD_KNOWN_IID(ProxyManager
),
2675 ADD_KNOWN_IID(RootStorage
),
2676 ADD_KNOWN_IID(RpcChannel
),
2677 ADD_KNOWN_IID(RpcProxy
),
2678 ADD_KNOWN_IID(RpcStub
),
2679 ADD_KNOWN_IID(RunnableObject
),
2680 ADD_KNOWN_IID(RunningObjectTable
),
2681 ADD_KNOWN_IID(StdMarshalInfo
),
2682 ADD_KNOWN_IID(Storage
),
2683 ADD_KNOWN_IID(Stream
),
2684 ADD_KNOWN_IID(StubManager
),
2685 ADD_KNOWN_IID(Unknown
),
2686 ADD_KNOWN_IID(ViewObject
),
2687 ADD_KNOWN_IID(ViewObject2
),
2688 ADD_KNOWN_GUID(IID_IDispatch
),
2689 ADD_KNOWN_GUID(IID_IWebBrowser
),
2690 ADD_KNOWN_GUID(IID_IWebBrowserApp
),
2691 ADD_KNOWN_GUID(IID_IWebBrowser2
),
2692 ADD_KNOWN_GUID(IID_IWebBrowser
),
2693 ADD_KNOWN_GUID(DIID_DWebBrowserEvents2
),
2694 ADD_KNOWN_GUID(DIID_DWebBrowserEvents
),
2697 // don't clobber preprocessor name space
2698 #undef ADD_KNOWN_IID
2699 #undef ADD_KNOWN_GUID
2701 // try to find the interface in the table
2702 for ( size_t ui
= 0; ui
< WXSIZEOF(aKnownIids
); ui
++ )
2704 if ( riid
== *aKnownIids
[ui
].pIid
)
2706 return aKnownIids
[ui
].szName
;
2710 // unknown IID, just transform to string
2711 LPOLESTR str
= NULL
;
2712 StringFromIID(riid
, &str
);
2720 return _T("StringFromIID() error");