]> git.saurik.com Git - wxWidgets.git/blob - wxPython/contrib/iewin/wxactivex.cpp
Fix some GCC 3.1 compilation warnings
[wxWidgets.git] / wxPython / contrib / iewin / wxactivex.cpp
1 #include "wxActiveX.h"
2 #include <wx/strconv.h>
3 #include <wx/msw/ole/uuid.h>
4 #include <oleidl.h>
5 #include <winerror.h>
6 #include <idispids.h>
7 #include <exdispid.h>
8 #include <olectl.h>
9 #include <Mshtml.h>
10 #include <sstream>
11 using namespace std;
12
13 // Depending on compilation mode, the wx headers may have undef'd
14 // this, but in this case we need it so the virtual method in
15 // FrameSite will match what is in oleidl.h.
16 #ifndef GetObject
17 #ifdef _UNICODE
18 #define GetObject GetObjectW
19 #else
20 #define GetObject GetObjectA
21 #endif
22 #endif
23
24 //////////////////////////////////////////////////////////////////////
25 BEGIN_EVENT_TABLE(wxActiveX, wxWindow)
26 EVT_SIZE(OnSize)
27 EVT_SET_FOCUS(OnSetFocus)
28 EVT_KILL_FOCUS(OnKillFocus)
29 END_EVENT_TABLE()
30
31 class wxActiveX;
32
33 class FrameSite :
34 public IOleClientSite,
35 public IOleInPlaceSiteEx,
36 public IOleInPlaceFrame,
37 public IOleItemContainer,
38 public IDispatch,
39 public IOleCommandTarget,
40 public IOleDocumentSite,
41 public IAdviseSink,
42 public IOleControlSite
43 {
44 private:
45 DECLARE_OLE_UNKNOWN(FrameSite);
46
47 public:
48 FrameSite(wxActiveX * win);
49 ~FrameSite();
50
51 //IOleWindow
52 STDMETHODIMP GetWindow(HWND*);
53 STDMETHODIMP ContextSensitiveHelp(BOOL);
54
55 //IOleInPlaceUIWindow
56 STDMETHODIMP GetBorder(LPRECT);
57 STDMETHODIMP RequestBorderSpace(LPCBORDERWIDTHS);
58 STDMETHODIMP SetBorderSpace(LPCBORDERWIDTHS);
59 STDMETHODIMP SetActiveObject(IOleInPlaceActiveObject*, LPCOLESTR);
60
61 //IOleInPlaceFrame
62 STDMETHODIMP InsertMenus(HMENU, LPOLEMENUGROUPWIDTHS);
63 STDMETHODIMP SetMenu(HMENU, HOLEMENU, HWND);
64 STDMETHODIMP RemoveMenus(HMENU);
65 STDMETHODIMP SetStatusText(LPCOLESTR);
66 STDMETHODIMP EnableModeless(BOOL);
67 STDMETHODIMP TranslateAccelerator(LPMSG, WORD);
68
69 //IOleInPlaceSite
70 STDMETHODIMP CanInPlaceActivate();
71 STDMETHODIMP OnInPlaceActivate();
72 STDMETHODIMP OnUIActivate();
73 STDMETHODIMP GetWindowContext(IOleInPlaceFrame**, IOleInPlaceUIWindow**,
74 LPRECT, LPRECT, LPOLEINPLACEFRAMEINFO);
75 STDMETHODIMP Scroll(SIZE);
76 STDMETHODIMP OnUIDeactivate(BOOL);
77 STDMETHODIMP OnInPlaceDeactivate();
78 STDMETHODIMP DiscardUndoState();
79 STDMETHODIMP DeactivateAndUndo();
80 STDMETHODIMP OnPosRectChange(LPCRECT);
81
82 //IOleInPlaceSiteEx
83 STDMETHODIMP OnInPlaceActivateEx(BOOL*, DWORD);
84 STDMETHODIMP OnInPlaceDeactivateEx(BOOL);
85 STDMETHODIMP RequestUIActivate();
86
87 //IOleClientSite
88 STDMETHODIMP SaveObject();
89 STDMETHODIMP GetMoniker(DWORD, DWORD, IMoniker**);
90 STDMETHODIMP GetContainer(LPOLECONTAINER FAR*);
91 STDMETHODIMP ShowObject();
92 STDMETHODIMP OnShowWindow(BOOL);
93 STDMETHODIMP RequestNewObjectLayout();
94
95 //IOleControlSite
96 STDMETHODIMP OnControlInfoChanged();
97 STDMETHODIMP LockInPlaceActive(BOOL);
98 STDMETHODIMP GetExtendedControl(IDispatch**);
99 STDMETHODIMP TransformCoords(POINTL*, POINTF*, DWORD);
100 STDMETHODIMP TranslateAccelerator(LPMSG, DWORD);
101 STDMETHODIMP OnFocus(BOOL);
102 STDMETHODIMP ShowPropertyFrame();
103
104 //IOleCommandTarget
105 STDMETHODIMP QueryStatus(const GUID*, ULONG, OLECMD[], OLECMDTEXT*);
106 STDMETHODIMP Exec(const GUID*, DWORD, DWORD, VARIANTARG*, VARIANTARG*);
107
108 //IParseDisplayName
109 STDMETHODIMP ParseDisplayName(IBindCtx*, LPOLESTR, ULONG*, IMoniker**);
110
111 //IOleContainer
112 STDMETHODIMP EnumObjects(DWORD, IEnumUnknown**);
113 STDMETHODIMP LockContainer(BOOL);
114
115 //IOleItemContainer
116 STDMETHODIMP GetObject(LPOLESTR, DWORD, IBindCtx*, REFIID, void**);
117 STDMETHODIMP GetObjectStorage(LPOLESTR, IBindCtx*, REFIID, void**);
118 STDMETHODIMP IsRunning(LPOLESTR);
119
120 //IDispatch
121 STDMETHODIMP GetIDsOfNames(REFIID, OLECHAR**, unsigned int, LCID, DISPID*);
122 STDMETHODIMP GetTypeInfo(unsigned int, LCID, ITypeInfo**);
123 STDMETHODIMP GetTypeInfoCount(unsigned int*);
124 STDMETHODIMP Invoke(DISPID, REFIID, LCID, WORD, DISPPARAMS*, VARIANT*, EXCEPINFO*, UINT*);
125
126 //IAdviseSink
127 void STDMETHODCALLTYPE OnDataChange(FORMATETC*, STGMEDIUM*);
128 void STDMETHODCALLTYPE OnViewChange(DWORD, LONG);
129 void STDMETHODCALLTYPE OnRename(IMoniker*);
130 void STDMETHODCALLTYPE OnSave();
131 void STDMETHODCALLTYPE OnClose();
132
133 // IOleDocumentSite
134 HRESULT STDMETHODCALLTYPE ActivateMe(IOleDocumentView __RPC_FAR *pViewToActivate);
135
136 protected:
137
138 wxActiveX * m_window;
139
140 HDC m_hDCBuffer;
141 HWND m_hWndParent;
142
143 bool m_bSupportsWindowlessActivation;
144 bool m_bInPlaceLocked;
145 bool m_bInPlaceActive;
146 bool m_bUIActive;
147 bool m_bWindowless;
148
149
150
151 LCID m_nAmbientLocale;
152 COLORREF m_clrAmbientForeColor;
153 COLORREF m_clrAmbientBackColor;
154 bool m_bAmbientShowHatching;
155 bool m_bAmbientShowGrabHandles;
156 bool m_bAmbientAppearance;
157 };
158
159 DEFINE_OLE_TABLE(FrameSite)
160 OLE_INTERFACE(IID_IUnknown, IOleClientSite)
161
162 OLE_IINTERFACE(IOleClientSite)
163
164 OLE_INTERFACE(IID_IOleWindow, IOleInPlaceSite)
165 OLE_IINTERFACE(IOleInPlaceSite)
166 OLE_IINTERFACE(IOleInPlaceSiteEx)
167
168 //OLE_IINTERFACE(IOleWindow)
169 OLE_IINTERFACE(IOleInPlaceUIWindow)
170 OLE_IINTERFACE(IOleInPlaceFrame)
171
172 OLE_IINTERFACE(IParseDisplayName)
173 OLE_IINTERFACE(IOleContainer)
174 OLE_IINTERFACE(IOleItemContainer)
175
176 OLE_IINTERFACE(IDispatch)
177
178 OLE_IINTERFACE(IOleCommandTarget)
179
180 OLE_IINTERFACE(IOleDocumentSite)
181
182 OLE_IINTERFACE(IAdviseSink)
183
184 OLE_IINTERFACE(IOleControlSite)
185 END_OLE_TABLE;
186
187
188 wxActiveX::wxActiveX(wxWindow * parent, REFCLSID clsid, wxWindowID id) :
189 wxWindow(parent, id)
190 {
191 m_bAmbientUserMode = true;
192 m_docAdviseCookie = 0;
193 CreateActiveX(clsid);
194 }
195
196 wxActiveX::wxActiveX(wxWindow * parent, wxString progId, wxWindowID id) :
197 wxWindow(parent, id)
198 {
199 m_bAmbientUserMode = true;
200 m_docAdviseCookie = 0;
201 CreateActiveX((LPOLESTR) wxConvUTF8.cMB2WC(progId).data());
202 }
203
204 wxActiveX::~wxActiveX()
205 {
206 // disconnect connection points
207 wxOleConnectionArray::iterator it = m_connections.begin();
208 while (it != m_connections.end())
209 {
210 wxOleConnectionPoint& cp = it->first;
211 cp->Unadvise(it->second);
212
213 it++;
214 };
215 m_connections.clear();
216
217 if (m_oleInPlaceObject.Ok())
218 {
219 m_oleInPlaceObject->InPlaceDeactivate();
220 m_oleInPlaceObject->UIDeactivate();
221 }
222
223
224 if (m_oleObject.Ok())
225 {
226 if (m_docAdviseCookie != 0)
227 m_oleObject->Unadvise(m_docAdviseCookie);
228
229 m_oleObject->DoVerb(OLEIVERB_HIDE, NULL, m_clientSite, 0, (HWND) GetHWND(), NULL);
230 m_oleObject->Close(OLECLOSE_NOSAVE);
231 m_oleObject->SetClientSite(NULL);
232 }
233 }
234
235 void wxActiveX::CreateActiveX(REFCLSID clsid)
236 {
237 SetTransparent();
238
239 HRESULT hret;
240
241 ////////////////////////////////////////////////////////
242 // FrameSite
243 FrameSite *frame = new FrameSite(this);
244 // oleClientSite
245 hret = m_clientSite.QueryInterface(IID_IOleClientSite, (IDispatch *) frame);
246 wxASSERT(SUCCEEDED(hret));
247 // adviseSink
248 wxAutoOleInterface<IAdviseSink> adviseSink(IID_IAdviseSink, (IDispatch *) frame);
249 wxASSERT(adviseSink.Ok());
250
251
252
253
254 // // Create Object, get IUnknown interface
255 m_ActiveX.CreateInstance(clsid, IID_IUnknown);
256 wxASSERT(m_ActiveX.Ok());
257
258 // Get IOleObject interface
259 hret = m_oleObject.QueryInterface(IID_IOleObject, m_ActiveX);
260 wxASSERT(SUCCEEDED(hret));
261 // Get IOleInPlaceObject interface
262 hret = m_oleInPlaceObject.QueryInterface(IID_IOleInPlaceObject, m_ActiveX);
263 wxASSERT(SUCCEEDED(hret));
264
265 // status
266 DWORD dwMiscStatus;
267 m_oleObject->GetMiscStatus(DVASPECT_CONTENT, &dwMiscStatus);
268 wxASSERT(SUCCEEDED(hret));
269
270 // set client site first ?
271 if (dwMiscStatus & OLEMISC_SETCLIENTSITEFIRST)
272 m_oleObject->SetClientSite(m_clientSite);
273
274
275 // stream init
276 wxAutoOleInterface<IPersistStreamInit>
277 pPersistStreamInit(IID_IPersistStreamInit, m_oleObject);
278
279 if (pPersistStreamInit.Ok())
280 {
281 hret = pPersistStreamInit->InitNew();
282 WXOLE_WARN(hret, "CreateActiveX::pPersistStreamInit->InitNew()");
283 };
284
285 // document advise
286 m_docAdviseCookie = 0;
287 hret = m_oleObject->Advise(adviseSink, &m_docAdviseCookie);
288 WXOLE_WARN(hret, "m_oleObject->Advise(adviseSink, &m_docAdviseCookie),\"Advise\")");
289 m_oleObject->SetHostNames(L"wxActiveXContainer", NULL);
290 OleSetContainedObject(m_oleObject, TRUE);
291
292 if (! (dwMiscStatus & OLEMISC_SETCLIENTSITEFIRST))
293 m_oleObject->SetClientSite(m_clientSite);
294
295
296 int w, h;
297 GetClientSize(&w, &h);
298 RECT posRect;
299 posRect.left = 0;
300 posRect.top = 0;
301 posRect.right = w;
302 posRect.bottom = h;
303
304 m_oleObjectHWND = 0;
305 hret = m_oleInPlaceObject->GetWindow(&m_oleObjectHWND);
306 WXOLE_WARN(hret, "m_oleInPlaceObject->GetWindow(&m_oleObjectHWND)");
307 if (SUCCEEDED(hret))
308 ::SetActiveWindow(m_oleObjectHWND);
309
310
311 if (! (dwMiscStatus & OLEMISC_INVISIBLEATRUNTIME))
312 {
313 m_oleInPlaceObject->SetObjectRects(&posRect, &posRect);
314
315 hret = m_oleObject->DoVerb(OLEIVERB_INPLACEACTIVATE, NULL, m_clientSite, 0, (HWND)GetHWND(), &posRect);
316 hret = m_oleObject->DoVerb(OLEIVERB_SHOW, 0, m_clientSite, 0, (HWND)GetHWND(), &posRect);
317 };
318
319 }
320
321 void wxActiveX::CreateActiveX(LPOLESTR progId)
322 {
323 CLSID clsid;
324 if (CLSIDFromProgID(progId, &clsid) != S_OK)
325 return;
326
327 CreateActiveX(clsid);
328 };
329
330 HRESULT wxActiveX::ConnectAdvise(REFIID riid, IUnknown *events)
331 {
332 wxOleConnectionPoint cp;
333 DWORD adviseCookie = 0;
334
335 wxAutoOleInterface<IConnectionPointContainer> cpContainer(IID_IConnectionPointContainer, m_ActiveX);
336 if (! cpContainer.Ok())
337 return E_FAIL;
338
339 HRESULT hret = cpContainer->FindConnectionPoint(riid, cp.GetRef());
340 if (! SUCCEEDED(hret))
341 return hret;
342
343 hret = cp->Advise(events, &adviseCookie);
344
345 if (SUCCEEDED(hret))
346 m_connections.push_back(wxOleConnection(cp, adviseCookie));
347
348 return hret;
349 };
350
351 HRESULT wxActiveX::AmbientPropertyChanged(DISPID dispid)
352 {
353 wxAutoOleInterface<IOleControl> oleControl(IID_IOleControl, m_oleObject);
354
355 if (oleControl.Ok())
356 return oleControl->OnAmbientPropertyChange(dispid);
357 else
358 return S_FALSE;
359 };
360
361 #define HIMETRIC_PER_INCH 2540
362 #define MAP_PIX_TO_LOGHIM(x,ppli) MulDiv(HIMETRIC_PER_INCH, (x), (ppli))
363
364 static void PixelsToHimetric(SIZEL &sz)
365 {
366 static int logX = 0;
367 static int logY = 0;
368
369 if (logY == 0)
370 {
371 // initaliase
372 HDC dc = GetDC(NULL);
373 logX = GetDeviceCaps(dc, LOGPIXELSX);
374 logY = GetDeviceCaps(dc, LOGPIXELSY);
375 ReleaseDC(NULL, dc);
376 };
377
378 #define HIMETRIC_INCH 2540
379 #define CONVERT(x, logpixels) MulDiv(HIMETRIC_INCH, (x), (logpixels))
380
381 sz.cx = CONVERT(sz.cx, logX);
382 sz.cy = CONVERT(sz.cy, logY);
383
384 #undef CONVERT
385 #undef HIMETRIC_INCH
386 }
387
388
389 void wxActiveX::OnSize(wxSizeEvent& event)
390 {
391 int w, h;
392 GetClientSize(&w, &h);
393
394 RECT posRect;
395 posRect.left = 0;
396 posRect.top = 0;
397 posRect.right = w;
398 posRect.bottom = h;
399
400 if (m_oleInPlaceObject)
401 m_oleInPlaceObject->SetObjectRects(&posRect, &posRect);
402
403 // extents are in HIMETRIC units
404 SIZEL sz = {w, h};
405 PixelsToHimetric(sz);
406
407 SIZEL sz2;
408 m_oleObject->GetExtent(DVASPECT_CONTENT, &sz2);
409 if (sz2.cx != sz.cx || sz.cy != sz2.cy)
410 m_oleObject->SetExtent(DVASPECT_CONTENT, &sz);
411 }
412
413 void wxActiveX::OnSetFocus(wxFocusEvent& event)
414 {
415 if (m_oleInPlaceActiveObject.Ok())
416 m_oleInPlaceActiveObject->OnFrameWindowActivate(TRUE);
417 }
418
419 void wxActiveX::OnKillFocus(wxFocusEvent& event)
420 {
421 if (m_oleInPlaceActiveObject.Ok())
422 m_oleInPlaceActiveObject->OnFrameWindowActivate(FALSE);
423 }
424
425
426 FrameSite::FrameSite(wxActiveX * win)
427 {
428 m_window = win;
429 m_bSupportsWindowlessActivation = true;
430 m_bInPlaceLocked = false;
431 m_bUIActive = false;
432 m_bInPlaceActive = false;
433 m_bWindowless = false;
434
435 m_nAmbientLocale = 0;
436 m_clrAmbientForeColor = ::GetSysColor(COLOR_WINDOWTEXT);
437 m_clrAmbientBackColor = ::GetSysColor(COLOR_WINDOW);
438 m_bAmbientShowHatching = true;
439 m_bAmbientShowGrabHandles = true;
440 m_bAmbientAppearance = true;
441
442 m_hDCBuffer = NULL;
443 m_hWndParent = (HWND)m_window->GetHWND();
444 }
445
446 FrameSite::~FrameSite()
447 {
448 }
449
450
451 //IDispatch
452
453 HRESULT FrameSite::GetIDsOfNames(REFIID riid, OLECHAR ** rgszNames, unsigned int cNames,
454 LCID lcid, DISPID * rgDispId)
455 {
456 WXOLE_TRACE("IDispatch::GetIDsOfNames");
457 return E_NOTIMPL;
458 }
459
460 HRESULT FrameSite::GetTypeInfo(unsigned int iTInfo, LCID lcid, ITypeInfo ** ppTInfo)
461 {
462 WXOLE_TRACE("IDispatch::GetTypeInfo");
463 return E_NOTIMPL;
464 }
465
466 HRESULT FrameSite::GetTypeInfoCount(unsigned int * pcTInfo)
467 {
468 WXOLE_TRACE("IDispatch::GetTypeInfoCount");
469 return E_NOTIMPL;
470 }
471
472 HRESULT FrameSite::Invoke(DISPID dispIdMember, REFIID riid, LCID lcid,
473 WORD wFlags, DISPPARAMS * pDispParams,
474 VARIANT * pVarResult, EXCEPINFO * pExcepInfo,
475 unsigned int * puArgErr)
476 {
477 WXOLE_TRACE("IDispatch::Invoke");
478
479 if (!(wFlags & DISPATCH_PROPERTYGET))
480 return S_OK;
481
482 HRESULT hr;
483
484 if (pVarResult == NULL)
485 return E_INVALIDARG;
486
487 //The most common case is boolean, use as an initial type
488 V_VT(pVarResult) = VT_BOOL;
489
490 switch (dispIdMember)
491 {
492 case DISPID_AMBIENT_MESSAGEREFLECT:
493 WXOLE_TRACE("Invoke::DISPID_AMBIENT_MESSAGEREFLECT");
494 V_BOOL(pVarResult)= FALSE;
495 return S_OK;
496
497 case DISPID_AMBIENT_DISPLAYASDEFAULT:
498 WXOLE_TRACE("Invoke::DISPID_AMBIENT_DISPLAYASDEFAULT");
499 V_BOOL(pVarResult)= TRUE;
500 return S_OK;
501
502 case DISPID_AMBIENT_OFFLINEIFNOTCONNECTED:
503 WXOLE_TRACE("Invoke::DISPID_AMBIENT_OFFLINEIFNOTCONNECTED");
504 V_BOOL(pVarResult) = TRUE;
505 return S_OK;
506
507
508 case DISPID_AMBIENT_SILENT:
509 WXOLE_TRACE("Invoke::DISPID_AMBIENT_SILENT");
510 V_BOOL(pVarResult)= TRUE;
511 return S_OK;
512
513 case DISPID_AMBIENT_APPEARANCE:
514 pVarResult->vt = VT_BOOL;
515 pVarResult->boolVal = m_bAmbientAppearance;
516 break;
517
518 case DISPID_AMBIENT_FORECOLOR:
519 pVarResult->vt = VT_I4;
520 pVarResult->lVal = (long) m_clrAmbientForeColor;
521 break;
522
523 case DISPID_AMBIENT_BACKCOLOR:
524 pVarResult->vt = VT_I4;
525 pVarResult->lVal = (long) m_clrAmbientBackColor;
526 break;
527
528 case DISPID_AMBIENT_LOCALEID:
529 pVarResult->vt = VT_I4;
530 pVarResult->lVal = (long) m_nAmbientLocale;
531 break;
532
533 case DISPID_AMBIENT_USERMODE:
534 pVarResult->vt = VT_BOOL;
535 pVarResult->boolVal = m_window->m_bAmbientUserMode;
536 break;
537
538 case DISPID_AMBIENT_SHOWGRABHANDLES:
539 pVarResult->vt = VT_BOOL;
540 pVarResult->boolVal = m_bAmbientShowGrabHandles;
541 break;
542
543 case DISPID_AMBIENT_SHOWHATCHING:
544 pVarResult->vt = VT_BOOL;
545 pVarResult->boolVal = m_bAmbientShowHatching;
546 break;
547
548 default:
549 return DISP_E_MEMBERNOTFOUND;
550 }
551
552 return S_OK;
553 }
554
555 //IOleWindow
556
557 HRESULT FrameSite::GetWindow(HWND * phwnd)
558 {
559 WXOLE_TRACE("IOleWindow::GetWindow");
560 if (phwnd == NULL)
561 return E_INVALIDARG;
562 (*phwnd) = m_hWndParent;
563 return S_OK;
564 }
565
566 HRESULT FrameSite::ContextSensitiveHelp(BOOL fEnterMode)
567 {
568 WXOLE_TRACE("IOleWindow::ContextSensitiveHelp");
569 return S_OK;
570 }
571
572 //IOleInPlaceUIWindow
573
574 HRESULT FrameSite::GetBorder(LPRECT lprectBorder)
575 {
576 WXOLE_TRACE("IOleInPlaceUIWindow::GetBorder");
577 if (lprectBorder == NULL)
578 return E_INVALIDARG;
579 return INPLACE_E_NOTOOLSPACE;
580 }
581
582 HRESULT FrameSite::RequestBorderSpace(LPCBORDERWIDTHS pborderwidths)
583 {
584 WXOLE_TRACE("IOleInPlaceUIWindow::RequestBorderSpace");
585 if (pborderwidths == NULL)
586 return E_INVALIDARG;
587 return INPLACE_E_NOTOOLSPACE;
588 }
589
590 HRESULT FrameSite::SetBorderSpace(LPCBORDERWIDTHS pborderwidths)
591 {
592 WXOLE_TRACE("IOleInPlaceUIWindow::SetBorderSpace");
593 return S_OK;
594 }
595
596 HRESULT FrameSite::SetActiveObject(IOleInPlaceActiveObject *pActiveObject, LPCOLESTR pszObjName)
597 {
598 WXOLE_TRACE("IOleInPlaceUIWindow::SetActiveObject");
599
600 if (pActiveObject)
601 pActiveObject->AddRef();
602
603 m_window->m_oleInPlaceActiveObject = pActiveObject;
604 return S_OK;
605 }
606
607 //IOleInPlaceFrame
608
609 HRESULT FrameSite::InsertMenus(HMENU hmenuShared, LPOLEMENUGROUPWIDTHS lpMenuWidths)
610 {
611 WXOLE_TRACE("IOleInPlaceFrame::InsertMenus");
612 return S_OK;
613 }
614
615 HRESULT FrameSite::SetMenu(HMENU hmenuShared, HOLEMENU holemenu, HWND hwndActiveObject)
616 {
617 WXOLE_TRACE("IOleInPlaceFrame::SetMenu");
618 return S_OK;
619 }
620
621 HRESULT FrameSite::RemoveMenus(HMENU hmenuShared)
622 {
623 WXOLE_TRACE("IOleInPlaceFrame::RemoveMenus");
624 return S_OK;
625 }
626
627 HRESULT FrameSite::SetStatusText(LPCOLESTR pszStatusText)
628 {
629 WXOLE_TRACE("IOleInPlaceFrame::SetStatusText");
630 //((wxFrame*)wxGetApp().GetTopWindow())->GetStatusBar()->SetStatusText(pszStatusText);
631 return S_OK;
632 }
633
634 HRESULT FrameSite::EnableModeless(BOOL fEnable)
635 {
636 WXOLE_TRACE("IOleInPlaceFrame::EnableModeless");
637 return S_OK;
638 }
639
640 HRESULT FrameSite::TranslateAccelerator(LPMSG lpmsg, WORD wID)
641 {
642 WXOLE_TRACE("IOleInPlaceFrame::TranslateAccelerator");
643 // TODO: send an event with this id
644 if (m_window->m_oleInPlaceActiveObject.Ok())
645 m_window->m_oleInPlaceActiveObject->TranslateAccelerator(lpmsg);
646
647 return S_FALSE;
648 }
649
650 //IOleInPlaceSite
651
652 HRESULT FrameSite::CanInPlaceActivate()
653 {
654 WXOLE_TRACE("IOleInPlaceSite::CanInPlaceActivate");
655 return S_OK;
656 }
657
658 HRESULT FrameSite::OnInPlaceActivate()
659 {
660 WXOLE_TRACE("IOleInPlaceSite::OnInPlaceActivate");
661 m_bInPlaceActive = true;
662 return S_OK;
663 }
664
665 HRESULT FrameSite::OnUIActivate()
666 {
667 WXOLE_TRACE("IOleInPlaceSite::OnUIActivate");
668 m_bUIActive = true;
669 return S_OK;
670 }
671
672 HRESULT FrameSite::GetWindowContext(IOleInPlaceFrame **ppFrame,
673 IOleInPlaceUIWindow **ppDoc,
674 LPRECT lprcPosRect,
675 LPRECT lprcClipRect,
676 LPOLEINPLACEFRAMEINFO lpFrameInfo)
677 {
678 WXOLE_TRACE("IOleInPlaceSite::GetWindowContext");
679 if (ppFrame == NULL || ppDoc == NULL || lprcPosRect == NULL ||
680 lprcClipRect == NULL || lpFrameInfo == NULL)
681 {
682 if (ppFrame != NULL)
683 (*ppFrame) = NULL;
684 if (ppDoc != NULL)
685 (*ppDoc) = NULL;
686 return E_INVALIDARG;
687 }
688
689 HRESULT hr = QueryInterface(IID_IOleInPlaceFrame, (void **) ppFrame);
690 if (! SUCCEEDED(hr))
691 {
692 WXOLE_TRACE("IOleInPlaceSite::IOleInPlaceFrame Error !");
693 return E_UNEXPECTED;
694 };
695
696 hr = QueryInterface(IID_IOleInPlaceUIWindow, (void **) ppDoc);
697 if (! SUCCEEDED(hr))
698 {
699 WXOLE_TRACE("IOleInPlaceSite::IOleInPlaceUIWindow Error !");
700 (*ppFrame)->Release();
701 *ppFrame = NULL;
702 return E_UNEXPECTED;
703 };
704
705 int w, h;
706 m_window->GetClientSize(&w, &h);
707 if (lprcPosRect)
708 {
709 lprcPosRect->left = lprcPosRect->top = 0;
710 lprcPosRect->right = w;
711 lprcPosRect->bottom = h;
712 };
713 if (lprcClipRect)
714 {
715 lprcClipRect->left = lprcClipRect->top = 0;
716 lprcClipRect->right = w;
717 lprcClipRect->bottom = h;
718 };
719
720 memset(lpFrameInfo, 0, sizeof(OLEINPLACEFRAMEINFO));
721 lpFrameInfo->cb = sizeof(OLEINPLACEFRAMEINFO);
722 lpFrameInfo->hwndFrame = m_hWndParent;
723
724 return S_OK;
725 }
726
727 HRESULT FrameSite::Scroll(SIZE scrollExtent)
728 {
729 WXOLE_TRACE("IOleInPlaceSite::Scroll");
730 return S_OK;
731 }
732
733 HRESULT FrameSite::OnUIDeactivate(BOOL fUndoable)
734 {
735 WXOLE_TRACE("IOleInPlaceSite::OnUIDeactivate");
736 m_bUIActive = false;
737 return S_OK;
738 }
739
740 HRESULT FrameSite::OnInPlaceDeactivate()
741 {
742 WXOLE_TRACE("IOleInPlaceSite::OnInPlaceDeactivate");
743 m_bInPlaceActive = false;
744 return S_OK;
745 }
746
747 HRESULT FrameSite::DiscardUndoState()
748 {
749 WXOLE_TRACE("IOleInPlaceSite::DiscardUndoState");
750 return S_OK;
751 }
752
753 HRESULT FrameSite::DeactivateAndUndo()
754 {
755 WXOLE_TRACE("IOleInPlaceSite::DeactivateAndUndo");
756 return S_OK;
757 }
758
759 HRESULT FrameSite::OnPosRectChange(LPCRECT lprcPosRect)
760 {
761 WXOLE_TRACE("IOleInPlaceSite::OnPosRectChange");
762 if (m_window->m_oleInPlaceObject.Ok() && lprcPosRect)
763 m_window->m_oleInPlaceObject->SetObjectRects(lprcPosRect, lprcPosRect);
764
765 return S_OK;
766 }
767
768 //IOleInPlaceSiteEx
769
770 HRESULT FrameSite::OnInPlaceActivateEx(BOOL * pfNoRedraw, DWORD dwFlags)
771 {
772 WXOLE_TRACE("IOleInPlaceSiteEx::OnInPlaceActivateEx");
773 OleLockRunning(m_window->m_ActiveX, TRUE, FALSE);
774 if (pfNoRedraw)
775 (*pfNoRedraw) = FALSE;
776 return S_OK;
777 }
778
779 HRESULT FrameSite::OnInPlaceDeactivateEx(BOOL fNoRedraw)
780 {
781 WXOLE_TRACE("IOleInPlaceSiteEx::OnInPlaceDeactivateEx");
782 OleLockRunning(m_window->m_ActiveX, FALSE, FALSE);
783 return S_OK;
784 }
785
786 HRESULT FrameSite::RequestUIActivate()
787 {
788 WXOLE_TRACE("IOleInPlaceSiteEx::RequestUIActivate");
789 return S_OK;
790 }
791
792
793 //IOleClientSite
794
795 HRESULT FrameSite::SaveObject()
796 {
797 WXOLE_TRACE("IOleClientSite::SaveObject");
798 return S_OK;
799 }
800
801 HRESULT FrameSite::GetMoniker(DWORD dwAssign, DWORD dwWhichMoniker,
802 IMoniker ** ppmk)
803 {
804 WXOLE_TRACE("IOleClientSite::GetMoniker");
805 return E_NOTIMPL;
806 }
807
808 HRESULT FrameSite::GetContainer(LPOLECONTAINER * ppContainer)
809 {
810 WXOLE_TRACE("IOleClientSite::GetContainer");
811 if (ppContainer == NULL)
812 return E_INVALIDARG;
813
814 HRESULT hr = QueryInterface(IID_IOleContainer, (void**)(ppContainer));
815 wxASSERT(SUCCEEDED(hr));
816
817 return hr;
818 }
819
820 HRESULT FrameSite::ShowObject()
821 {
822 WXOLE_TRACE("IOleClientSite::ShowObject");
823 return S_OK;
824 }
825
826 HRESULT FrameSite::OnShowWindow(BOOL fShow)
827 {
828 WXOLE_TRACE("IOleClientSite::OnShowWindow");
829 return S_OK;
830 }
831
832 HRESULT FrameSite::RequestNewObjectLayout()
833 {
834 WXOLE_TRACE("IOleClientSite::RequestNewObjectLayout");
835 return E_NOTIMPL;
836 }
837
838 // IParseDisplayName
839
840 HRESULT FrameSite::ParseDisplayName(IBindCtx *pbc, LPOLESTR pszDisplayName,
841 ULONG *pchEaten, IMoniker **ppmkOut)
842 {
843 WXOLE_TRACE("IParseDisplayName::ParseDisplayName");
844 return E_NOTIMPL;
845 }
846
847 //IOleContainer
848
849 HRESULT FrameSite::EnumObjects(DWORD grfFlags, IEnumUnknown **ppenum)
850 {
851 WXOLE_TRACE("IOleContainer::EnumObjects");
852 return E_NOTIMPL;
853 }
854
855 HRESULT FrameSite::LockContainer(BOOL fLock)
856 {
857 WXOLE_TRACE("IOleContainer::LockContainer");
858 // TODO
859 return S_OK;
860 }
861
862 //IOleItemContainer
863
864 HRESULT FrameSite::GetObject(LPOLESTR pszItem, DWORD dwSpeedNeeded,
865 IBindCtx * pbc, REFIID riid, void ** ppvObject)
866 {
867 WXOLE_TRACE("IOleItemContainer::GetObject");
868 if (pszItem == NULL)
869 return E_INVALIDARG;
870 if (ppvObject == NULL)
871 return E_INVALIDARG;
872
873 *ppvObject = NULL;
874 return MK_E_NOOBJECT;
875 }
876
877 HRESULT FrameSite::GetObjectStorage(LPOLESTR pszItem, IBindCtx * pbc,
878 REFIID riid, void ** ppvStorage)
879 {
880 WXOLE_TRACE("IOleItemContainer::GetObjectStorage");
881 if (pszItem == NULL)
882 return E_INVALIDARG;
883 if (ppvStorage == NULL)
884 return E_INVALIDARG;
885
886 *ppvStorage = NULL;
887 return MK_E_NOOBJECT;
888 }
889
890 HRESULT FrameSite::IsRunning(LPOLESTR pszItem)
891 {
892 WXOLE_TRACE("IOleItemContainer::IsRunning");
893 if (pszItem == NULL)
894 return E_INVALIDARG;
895
896 return MK_E_NOOBJECT;
897 }
898
899
900
901 //IOleControlSite
902
903 HRESULT FrameSite::OnControlInfoChanged()
904 {
905 WXOLE_TRACE("IOleControlSite::OnControlInfoChanged");
906 return S_OK;
907 }
908
909 HRESULT FrameSite::LockInPlaceActive(BOOL fLock)
910 {
911 WXOLE_TRACE("IOleControlSite::LockInPlaceActive");
912 m_bInPlaceLocked = (fLock) ? true : false;
913 return S_OK;
914 }
915
916 HRESULT FrameSite::GetExtendedControl(IDispatch ** ppDisp)
917 {
918 WXOLE_TRACE("IOleControlSite::GetExtendedControl");
919 return E_NOTIMPL;
920 }
921
922 HRESULT FrameSite::TransformCoords(POINTL * pPtlHimetric, POINTF * pPtfContainer, DWORD dwFlags)
923 {
924 WXOLE_TRACE("IOleControlSite::TransformCoords");
925 HRESULT hr = S_OK;
926
927 if (pPtlHimetric == NULL)
928 return E_INVALIDARG;
929
930 if (pPtfContainer == NULL)
931 return E_INVALIDARG;
932
933 return E_NOTIMPL;
934
935 }
936
937 HRESULT FrameSite::TranslateAccelerator(LPMSG pMsg, DWORD grfModifiers)
938 {
939 WXOLE_TRACE("IOleControlSite::TranslateAccelerator");
940 // TODO: send an event with this id
941 return E_NOTIMPL;
942 }
943
944 HRESULT FrameSite::OnFocus(BOOL fGotFocus)
945 {
946 WXOLE_TRACE("IOleControlSite::OnFocus");
947 return S_OK;
948 }
949
950 HRESULT FrameSite::ShowPropertyFrame()
951 {
952 WXOLE_TRACE("IOleControlSite::ShowPropertyFrame");
953 return E_NOTIMPL;
954 }
955
956 //IOleCommandTarget
957
958 HRESULT FrameSite::QueryStatus(const GUID * pguidCmdGroup, ULONG cCmds,
959 OLECMD * prgCmds, OLECMDTEXT * pCmdTet)
960 {
961 WXOLE_TRACE("IOleCommandTarget::QueryStatus");
962 if (prgCmds == NULL) return E_INVALIDARG;
963 bool bCmdGroupFound = false;
964
965 for (ULONG nCmd = 0; nCmd < cCmds; nCmd++)
966 {
967 // unsupported by default
968 prgCmds[nCmd].cmdf = 0;
969
970 // TODO
971 }
972
973 if (!bCmdGroupFound) { OLECMDERR_E_UNKNOWNGROUP; }
974 return S_OK;
975 }
976
977 HRESULT FrameSite::Exec(const GUID * pguidCmdGroup, DWORD nCmdID,
978 DWORD nCmdExecOpt, VARIANTARG * pVaIn,
979 VARIANTARG * pVaOut)
980 {
981 WXOLE_TRACE("IOleCommandTarget::Exec");
982 bool bCmdGroupFound = false;
983
984 if (!bCmdGroupFound) { OLECMDERR_E_UNKNOWNGROUP; }
985 return OLECMDERR_E_NOTSUPPORTED;
986 }
987
988 //IAdviseSink
989
990 void STDMETHODCALLTYPE FrameSite::OnDataChange(FORMATETC * pFormatEtc, STGMEDIUM * pgStgMed)
991 {
992 WXOLE_TRACE("IAdviseSink::OnDataChange");
993 }
994
995 void STDMETHODCALLTYPE FrameSite::OnViewChange(DWORD dwAspect, LONG lIndex)
996 {
997 WXOLE_TRACE("IAdviseSink::OnViewChange");
998 // redraw the control
999 }
1000
1001 void STDMETHODCALLTYPE FrameSite::OnRename(IMoniker * pmk)
1002 {
1003 WXOLE_TRACE("IAdviseSink::OnRename");
1004 }
1005
1006 void STDMETHODCALLTYPE FrameSite::OnSave()
1007 {
1008 WXOLE_TRACE("IAdviseSink::OnSave");
1009 }
1010
1011 void STDMETHODCALLTYPE FrameSite::OnClose()
1012 {
1013 WXOLE_TRACE("IAdviseSink::OnClose");
1014 }
1015
1016 /////////////////////////////////////////////
1017 // IOleDocumentSite
1018 HRESULT STDMETHODCALLTYPE FrameSite::ActivateMe(
1019 /* [in] */ IOleDocumentView __RPC_FAR *pViewToActivate)
1020 {
1021 wxAutoOleInterface<IOleInPlaceSite> inPlaceSite(IID_IOleInPlaceSite, (IDispatch *) this);
1022 if (!inPlaceSite.Ok())
1023 return E_FAIL;
1024
1025 if (pViewToActivate)
1026 {
1027 m_window->m_docView = pViewToActivate;
1028 m_window->m_docView->SetInPlaceSite(inPlaceSite);
1029 }
1030 else
1031 {
1032 wxAutoOleInterface<IOleDocument> oleDoc(IID_IOleDocument, m_window->m_oleObject);
1033 if (! oleDoc.Ok())
1034 return E_FAIL;
1035
1036 HRESULT hr = oleDoc->CreateView(inPlaceSite, NULL, 0, m_window->m_docView.GetRef());
1037 if (hr != S_OK)
1038 return E_FAIL;
1039
1040 m_window->m_docView->SetInPlaceSite(inPlaceSite);
1041 };
1042
1043 m_window->m_docView->UIActivate(TRUE);
1044
1045 return S_OK;
1046 };
1047
1048
1049
1050 static IMalloc *iMalloc = NULL;
1051
1052 IMalloc *wxOleInit::GetIMalloc()
1053 {
1054 assert(iMalloc);
1055 return iMalloc;
1056 };
1057
1058 wxOleInit::wxOleInit()
1059 {
1060 if (OleInitialize(NULL) == S_OK && iMalloc == NULL)
1061 CoGetMalloc(1, &iMalloc);
1062 else if (iMalloc)
1063 iMalloc->AddRef();
1064 };
1065
1066 wxOleInit::~wxOleInit()
1067 {
1068 if (iMalloc)
1069 {
1070 if (iMalloc->Release() == 0)
1071 iMalloc = NULL;
1072 };
1073
1074 OleUninitialize();
1075 }
1076
1077 wxString OLEHResultToString(HRESULT hr)
1078 {
1079 switch (hr)
1080 {
1081 case S_OK:
1082 return "";
1083
1084 case OLECMDERR_E_UNKNOWNGROUP:
1085 return "The pguidCmdGroup parameter is not NULL but does not specify a recognized command group.";
1086
1087 case OLECMDERR_E_NOTSUPPORTED:
1088 return "The nCmdID parameter is not a valid command in the group identified by pguidCmdGroup.";
1089
1090 case OLECMDERR_E_DISABLED:
1091 return "The command identified by nCmdID is currently disabled and cannot be executed.";
1092
1093 case OLECMDERR_E_NOHELP:
1094 return "The caller has asked for help on the command identified by nCmdID, but no help is available.";
1095
1096 case OLECMDERR_E_CANCELED:
1097 return "The user canceled the execution of the command.";
1098
1099 case E_INVALIDARG:
1100 return "E_INVALIDARG";
1101
1102 case E_OUTOFMEMORY:
1103 return "E_OUTOFMEMORY";
1104
1105 case E_NOINTERFACE:
1106 return "E_NOINTERFACE";
1107
1108 case E_UNEXPECTED:
1109 return "E_UNEXPECTED";
1110
1111 case STG_E_INVALIDFLAG:
1112 return "STG_E_INVALIDFLAG";
1113
1114 case E_FAIL:
1115 return "E_FAIL";
1116
1117 case E_NOTIMPL:
1118 return "E_NOTIMPL";
1119
1120 default:
1121 {
1122 char buf[64];
1123 sprintf(buf, "Unknown - 0x%X", hr);
1124 return wxString(buf);
1125 }
1126 };
1127 };
1128
1129 // borrowed from src/msw/ole/oleutils.cpp
1130 wxString GetIIDName(REFIID riid)
1131 {
1132 // an association between symbolic name and numeric value of an IID
1133 struct KNOWN_IID
1134 {
1135 const IID *pIid;
1136 const wxChar *szName;
1137 };
1138
1139 // construct the table containing all known interfaces
1140 #define ADD_KNOWN_IID(name) { &IID_I##name, _T(#name) }
1141
1142 static const KNOWN_IID aKnownIids[] =
1143 {
1144 ADD_KNOWN_IID(AdviseSink),
1145 ADD_KNOWN_IID(AdviseSink2),
1146 ADD_KNOWN_IID(BindCtx),
1147 ADD_KNOWN_IID(ClassFactory),
1148 #if ( !defined( __VISUALC__) || (__VISUALC__!=1010) ) && !defined(__MWERKS__)
1149 ADD_KNOWN_IID(ContinueCallback),
1150 ADD_KNOWN_IID(EnumOleDocumentViews),
1151 ADD_KNOWN_IID(OleCommandTarget),
1152 ADD_KNOWN_IID(OleDocument),
1153 ADD_KNOWN_IID(OleDocumentSite),
1154 ADD_KNOWN_IID(OleDocumentView),
1155 ADD_KNOWN_IID(Print),
1156 #endif
1157 ADD_KNOWN_IID(DataAdviseHolder),
1158 ADD_KNOWN_IID(DataObject),
1159 ADD_KNOWN_IID(Debug),
1160 ADD_KNOWN_IID(DebugStream),
1161 ADD_KNOWN_IID(DfReserved1),
1162 ADD_KNOWN_IID(DfReserved2),
1163 ADD_KNOWN_IID(DfReserved3),
1164 ADD_KNOWN_IID(Dispatch),
1165 ADD_KNOWN_IID(DropSource),
1166 ADD_KNOWN_IID(DropTarget),
1167 ADD_KNOWN_IID(EnumCallback),
1168 ADD_KNOWN_IID(EnumFORMATETC),
1169 ADD_KNOWN_IID(EnumGeneric),
1170 ADD_KNOWN_IID(EnumHolder),
1171 ADD_KNOWN_IID(EnumMoniker),
1172 ADD_KNOWN_IID(EnumOLEVERB),
1173 ADD_KNOWN_IID(EnumSTATDATA),
1174 ADD_KNOWN_IID(EnumSTATSTG),
1175 ADD_KNOWN_IID(EnumString),
1176 ADD_KNOWN_IID(EnumUnknown),
1177 ADD_KNOWN_IID(EnumVARIANT),
1178 ADD_KNOWN_IID(ExternalConnection),
1179 ADD_KNOWN_IID(InternalMoniker),
1180 ADD_KNOWN_IID(LockBytes),
1181 ADD_KNOWN_IID(Malloc),
1182 ADD_KNOWN_IID(Marshal),
1183 ADD_KNOWN_IID(MessageFilter),
1184 ADD_KNOWN_IID(Moniker),
1185 ADD_KNOWN_IID(OleAdviseHolder),
1186 ADD_KNOWN_IID(OleCache),
1187 ADD_KNOWN_IID(OleCache2),
1188 ADD_KNOWN_IID(OleCacheControl),
1189 ADD_KNOWN_IID(OleClientSite),
1190 ADD_KNOWN_IID(OleContainer),
1191 ADD_KNOWN_IID(OleInPlaceActiveObject),
1192 ADD_KNOWN_IID(OleInPlaceFrame),
1193 ADD_KNOWN_IID(OleInPlaceObject),
1194 ADD_KNOWN_IID(OleInPlaceSite),
1195 ADD_KNOWN_IID(OleInPlaceUIWindow),
1196 ADD_KNOWN_IID(OleItemContainer),
1197 ADD_KNOWN_IID(OleLink),
1198 ADD_KNOWN_IID(OleManager),
1199 ADD_KNOWN_IID(OleObject),
1200 ADD_KNOWN_IID(OlePresObj),
1201 ADD_KNOWN_IID(OleWindow),
1202 ADD_KNOWN_IID(PSFactory),
1203 ADD_KNOWN_IID(ParseDisplayName),
1204 ADD_KNOWN_IID(Persist),
1205 ADD_KNOWN_IID(PersistFile),
1206 ADD_KNOWN_IID(PersistStorage),
1207 ADD_KNOWN_IID(PersistStream),
1208 ADD_KNOWN_IID(ProxyManager),
1209 ADD_KNOWN_IID(RootStorage),
1210 ADD_KNOWN_IID(RpcChannel),
1211 ADD_KNOWN_IID(RpcProxy),
1212 ADD_KNOWN_IID(RpcStub),
1213 ADD_KNOWN_IID(RunnableObject),
1214 ADD_KNOWN_IID(RunningObjectTable),
1215 ADD_KNOWN_IID(StdMarshalInfo),
1216 ADD_KNOWN_IID(Storage),
1217 ADD_KNOWN_IID(Stream),
1218 ADD_KNOWN_IID(StubManager),
1219 ADD_KNOWN_IID(Unknown),
1220 ADD_KNOWN_IID(ViewObject),
1221 ADD_KNOWN_IID(ViewObject2),
1222 };
1223
1224 // don't clobber preprocessor name space
1225 #undef ADD_KNOWN_IID
1226
1227 // try to find the interface in the table
1228 for ( size_t ui = 0; ui < WXSIZEOF(aKnownIids); ui++ )
1229 {
1230 if ( riid == *aKnownIids[ui].pIid )
1231 {
1232 return aKnownIids[ui].szName;
1233 }
1234 }
1235
1236 // unknown IID, just transform to string
1237 LPOLESTR str = NULL;
1238 StringFromIID(riid, &str);
1239 if (str)
1240 {
1241 wxString s = str;
1242 CoTaskMemFree(str);
1243 return s;
1244 }
1245 else
1246 return "StringFromIID() error";
1247 }