]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/ole/activex.cpp
Ensure there is valid context for DrawRectangle
[wxWidgets.git] / src / msw / ole / activex.cpp
index 71bbed04508a21acff9a1c54d5cf5fa5801423d0..8baad0bf012bcab308717ca737bbd20810d29271 100644 (file)
@@ -354,7 +354,7 @@ public:
     HRESULT STDMETHODCALLTYPE TranslateAccelerator(LPMSG lpmsg, WORD)
     {
         // TODO: send an event with this id
     HRESULT STDMETHODCALLTYPE TranslateAccelerator(LPMSG lpmsg, WORD)
     {
         // TODO: send an event with this id
-        if (m_window->m_oleInPlaceActiveObject.Ok())
+        if (m_window->m_oleInPlaceActiveObject.IsOk())
             m_window->m_oleInPlaceActiveObject->TranslateAccelerator(lpmsg);
         return S_FALSE;
     }
             m_window->m_oleInPlaceActiveObject->TranslateAccelerator(lpmsg);
         return S_FALSE;
     }
@@ -425,7 +425,7 @@ public:
     HRESULT STDMETHODCALLTYPE DeactivateAndUndo(){return S_OK; }
     HRESULT STDMETHODCALLTYPE OnPosRectChange(LPCRECT lprcPosRect)
     {
     HRESULT STDMETHODCALLTYPE DeactivateAndUndo(){return S_OK; }
     HRESULT STDMETHODCALLTYPE OnPosRectChange(LPCRECT lprcPosRect)
     {
-        if (m_window->m_oleInPlaceObject.Ok() && lprcPosRect)
+        if (m_window->m_oleInPlaceObject.IsOk() && lprcPosRect)
         {
            //
            // Result of several hours and days of bug hunting -
         {
            //
            // Result of several hours and days of bug hunting -
@@ -606,7 +606,7 @@ public:
     {
         wxAutoIOleInPlaceSite inPlaceSite(
             IID_IOleInPlaceSite, (IDispatch *) this);
     {
         wxAutoIOleInPlaceSite inPlaceSite(
             IID_IOleInPlaceSite, (IDispatch *) this);
-        if (!inPlaceSite.Ok())
+        if (!inPlaceSite.IsOk())
             return E_FAIL;
 
         if (pViewToActivate)
             return E_FAIL;
 
         if (pViewToActivate)
@@ -618,7 +618,7 @@ public:
         {
             wxAutoIOleDocument oleDoc(
                 IID_IOleDocument, m_window->m_oleObject);
         {
             wxAutoIOleDocument oleDoc(
                 IID_IOleDocument, m_window->m_oleObject);
-            if (! oleDoc.Ok())
+            if (! oleDoc.IsOk())
                 return E_FAIL;
 
             HRESULT hr = oleDoc->CreateView(inPlaceSite, NULL,
                 return E_FAIL;
 
             HRESULT hr = oleDoc->CreateView(inPlaceSite, NULL,
@@ -633,6 +633,10 @@ public:
         return S_OK;
     }
 
         return S_OK;
     }
 
+    friend bool QueryClientSiteInterface(FrameSite *self, REFIID iid, void **_interface, const char *&desc)
+    {
+        return self->m_window->QueryClientSiteInterface(iid,_interface,desc);
+    }
 
 protected:
     wxActiveXContainer * m_window;
 
 protected:
     wxActiveXContainer * m_window;
@@ -670,6 +674,7 @@ DEFINE_OLE_TABLE(FrameSite)
     OLE_IINTERFACE(IOleDocumentSite)
     OLE_IINTERFACE(IAdviseSink)
     OLE_IINTERFACE(IOleControlSite)
     OLE_IINTERFACE(IOleDocumentSite)
     OLE_IINTERFACE(IAdviseSink)
     OLE_IINTERFACE(IOleControlSite)
+    OLE_INTERFACE_CUSTOM(QueryClientSiteInterface)
 END_OLE_TABLE
 
 
 END_OLE_TABLE
 
 
@@ -878,13 +883,13 @@ wxActiveXContainer::wxActiveXContainer(wxWindow * parent,
 wxActiveXContainer::~wxActiveXContainer()
 {
     // disconnect connection points
 wxActiveXContainer::~wxActiveXContainer()
 {
     // disconnect connection points
-    if (m_oleInPlaceObject.Ok())
+    if (m_oleInPlaceObject.IsOk())
     {
         m_oleInPlaceObject->InPlaceDeactivate();
         m_oleInPlaceObject->UIDeactivate();
     }
 
     {
         m_oleInPlaceObject->InPlaceDeactivate();
         m_oleInPlaceObject->UIDeactivate();
     }
 
-    if (m_oleObject.Ok())
+    if (m_oleObject.IsOk())
     {
         if (m_docAdviseCookie != 0)
             m_oleObject->Unadvise(m_docAdviseCookie);
     {
         if (m_docAdviseCookie != 0)
             m_oleObject->Unadvise(m_docAdviseCookie);
@@ -934,7 +939,7 @@ void wxActiveXContainer::CreateActiveX(REFIID iid, IUnknown* pUnk)
     CHECK_HR(hret);
     // adviseSink
     wxAutoIAdviseSink adviseSink(IID_IAdviseSink, (IDispatch *) m_frameSite);
     CHECK_HR(hret);
     // adviseSink
     wxAutoIAdviseSink adviseSink(IID_IAdviseSink, (IDispatch *) m_frameSite);
-    wxASSERT(adviseSink.Ok());
+    wxASSERT(adviseSink.IsOk());
 
     // Get Dispatch interface
     hret = m_Dispatch.QueryInterface(IID_IDispatch, m_ActiveX);
 
     // Get Dispatch interface
     hret = m_Dispatch.QueryInterface(IID_IDispatch, m_ActiveX);
@@ -946,13 +951,13 @@ void wxActiveXContainer::CreateActiveX(REFIID iid, IUnknown* pUnk)
 
     // get type info via class info
     wxAutoIProvideClassInfo classInfo(IID_IProvideClassInfo, m_ActiveX);
 
     // get type info via class info
     wxAutoIProvideClassInfo classInfo(IID_IProvideClassInfo, m_ActiveX);
-    wxASSERT(classInfo.Ok());
+    wxASSERT(classInfo.IsOk());
 
     // type info
     wxAutoITypeInfo typeInfo;
     hret = classInfo->GetClassInfo(typeInfo.GetRef());
     CHECK_HR(hret);
 
     // type info
     wxAutoITypeInfo typeInfo;
     hret = classInfo->GetClassInfo(typeInfo.GetRef());
     CHECK_HR(hret);
-    wxASSERT(typeInfo.Ok());
+    wxASSERT(typeInfo.IsOk());
 
     // TYPEATTR
     TYPEATTR *ta = NULL;
 
     // TYPEATTR
     TYPEATTR *ta = NULL;
@@ -975,7 +980,7 @@ void wxActiveXContainer::CreateActiveX(REFIID iid, IUnknown* pUnk)
         // get dispatch type info interface
         wxAutoITypeInfo  ti;
         hret = typeInfo->GetRefTypeInfo(rt, ti.GetRef());
         // get dispatch type info interface
         wxAutoITypeInfo  ti;
         hret = typeInfo->GetRefTypeInfo(rt, ti.GetRef());
-        if (! ti.Ok())
+        if (! ti.IsOk())
             continue;
 
         CHECK_HR(hret);
             continue;
 
         CHECK_HR(hret);
@@ -1016,7 +1021,7 @@ void wxActiveXContainer::CreateActiveX(REFIID iid, IUnknown* pUnk)
                 DWORD                    adviseCookie = 0;
 
                 wxAutoIConnectionPointContainer cpContainer(IID_IConnectionPointContainer, m_ActiveX);
                 DWORD                    adviseCookie = 0;
 
                 wxAutoIConnectionPointContainer cpContainer(IID_IConnectionPointContainer, m_ActiveX);
-                wxASSERT( cpContainer.Ok());
+                wxASSERT( cpContainer.IsOk());
 
                 HRESULT hret =
                     cpContainer->FindConnectionPoint(ta->guid, cp.GetRef());
 
                 HRESULT hret =
                     cpContainer->FindConnectionPoint(ta->guid, cp.GetRef());
@@ -1093,7 +1098,7 @@ void wxActiveXContainer::CreateActiveX(REFIID iid, IUnknown* pUnk)
     wxAutoIPersistStreamInit
         pPersistStreamInit(IID_IPersistStreamInit, m_oleObject);
 
     wxAutoIPersistStreamInit
         pPersistStreamInit(IID_IPersistStreamInit, m_oleObject);
 
-    if (pPersistStreamInit.Ok())
+    if (pPersistStreamInit.IsOk())
     {
         hret = pPersistStreamInit->InitNew();
         CHECK_HR(hret);
     {
         hret = pPersistStreamInit->InitNew();
         CHECK_HR(hret);
@@ -1105,35 +1110,35 @@ void wxActiveXContainer::CreateActiveX(REFIID iid, IUnknown* pUnk)
 
     m_oleObjectHWND = 0;
 
 
     m_oleObjectHWND = 0;
 
-    if (m_oleInPlaceObject.Ok())
-    {
-        hret = m_oleInPlaceObject->GetWindow(&m_oleObjectHWND);
-        if (SUCCEEDED(hret))
-            ::SetActiveWindow(m_oleObjectHWND);
-    }
-
 
     if (! (dwMiscStatus & OLEMISC_INVISIBLEATRUNTIME))
     {
         RECT posRect;
         wxCopyRectToRECT(m_realparent->GetClientSize(), posRect);
 
 
     if (! (dwMiscStatus & OLEMISC_INVISIBLEATRUNTIME))
     {
         RECT posRect;
         wxCopyRectToRECT(m_realparent->GetClientSize(), posRect);
 
+        hret = m_oleObject->DoVerb(OLEIVERB_INPLACEACTIVATE, NULL,
+            m_clientSite, 0, (HWND)m_realparent->GetHWND(), &posRect);
+        CHECK_HR(hret);
+
+        if (m_oleInPlaceObject.IsOk())
+        {
+            hret = m_oleInPlaceObject->GetWindow(&m_oleObjectHWND);
+            CHECK_HR(hret);
+            ::SetActiveWindow(m_oleObjectHWND);
+        }
+
         if (posRect.right > 0 && posRect.bottom > 0 &&
         if (posRect.right > 0 && posRect.bottom > 0 &&
-            m_oleInPlaceObject.Ok())
+            m_oleInPlaceObject.IsOk())
         {
             m_oleInPlaceObject->SetObjectRects(&posRect, &posRect);
         }
 
         {
             m_oleInPlaceObject->SetObjectRects(&posRect, &posRect);
         }
 
-        hret = m_oleObject->DoVerb(OLEIVERB_INPLACEACTIVATE, NULL,
-            m_clientSite, 0, (HWND)m_realparent->GetHWND(), &posRect);
-        CHECK_HR(hret);
-
         hret = m_oleObject->DoVerb(OLEIVERB_SHOW, 0, m_clientSite, 0,
             (HWND)m_realparent->GetHWND(), &posRect);
         CHECK_HR(hret);
     }
 
         hret = m_oleObject->DoVerb(OLEIVERB_SHOW, 0, m_clientSite, 0,
             (HWND)m_realparent->GetHWND(), &posRect);
         CHECK_HR(hret);
     }
 
-    if (! m_oleObjectHWND && m_oleInPlaceObject.Ok())
+    if (! m_oleObjectHWND && m_oleInPlaceObject.IsOk())
     {
         hret = m_oleInPlaceObject->GetWindow(&m_oleObjectHWND);
         CHECK_HR(hret);
     {
         hret = m_oleInPlaceObject->GetWindow(&m_oleObjectHWND);
         CHECK_HR(hret);
@@ -1178,14 +1183,12 @@ void wxActiveXContainer::OnSize(wxSizeEvent& event)
     posRect.right = w;
     posRect.bottom = h;
 
     posRect.right = w;
     posRect.bottom = h;
 
-    if (w <= 0 && h <= 0)
+    if (w <= 0 || h <= 0)
         return;
 
     // extents are in HIMETRIC units
         return;
 
     // extents are in HIMETRIC units
-    if (m_oleObject.Ok())
+    if (m_oleObject.IsOk())
     {
     {
-        m_oleObject->DoVerb(OLEIVERB_HIDE, 0, m_clientSite, 0,
-            (HWND)m_realparent->GetHWND(), &posRect);
 
         SIZEL sz = {w, h};
         PixelsToHimetric(sz);
 
         SIZEL sz = {w, h};
         PixelsToHimetric(sz);
@@ -1196,11 +1199,9 @@ void wxActiveXContainer::OnSize(wxSizeEvent& event)
         if (sz2.cx !=  sz.cx || sz.cy != sz2.cy)
             m_oleObject->SetExtent(DVASPECT_CONTENT, &sz);
 
         if (sz2.cx !=  sz.cx || sz.cy != sz2.cy)
             m_oleObject->SetExtent(DVASPECT_CONTENT, &sz);
 
-        m_oleObject->DoVerb(OLEIVERB_SHOW, 0, m_clientSite, 0,
-            (HWND)m_realparent->GetHWND(), &posRect);
     }
 
     }
 
-    if (m_oleInPlaceObject.Ok())
+    if (m_oleInPlaceObject.IsOk())
         m_oleInPlaceObject->SetObjectRects(&posRect, &posRect);
 
     event.Skip();
         m_oleInPlaceObject->SetObjectRects(&posRect, &posRect);
 
     event.Skip();
@@ -1244,7 +1245,7 @@ void wxActiveXContainer::OnPaint(wxPaintEvent& WXUNUSED(event))
 //---------------------------------------------------------------------------
 void wxActiveXContainer::OnSetFocus(wxFocusEvent& event)
 {
 //---------------------------------------------------------------------------
 void wxActiveXContainer::OnSetFocus(wxFocusEvent& event)
 {
-    if (m_oleInPlaceActiveObject.Ok())
+    if (m_oleInPlaceActiveObject.IsOk())
         m_oleInPlaceActiveObject->OnFrameWindowActivate(TRUE);
 
     event.Skip();
         m_oleInPlaceActiveObject->OnFrameWindowActivate(TRUE);
 
     event.Skip();
@@ -1258,10 +1259,39 @@ void wxActiveXContainer::OnSetFocus(wxFocusEvent& event)
 //---------------------------------------------------------------------------
 void wxActiveXContainer::OnKillFocus(wxFocusEvent& event)
 {
 //---------------------------------------------------------------------------
 void wxActiveXContainer::OnKillFocus(wxFocusEvent& event)
 {
-    if (m_oleInPlaceActiveObject.Ok())
+    if (m_oleInPlaceActiveObject.IsOk())
         m_oleInPlaceActiveObject->OnFrameWindowActivate(FALSE);
 
     event.Skip();
 }
 
         m_oleInPlaceActiveObject->OnFrameWindowActivate(FALSE);
 
     event.Skip();
 }
 
+//---------------------------------------------------------------------------
+// wxActiveXContainer::MSWTranslateMessage
+//
+// Called for every message that needs to be translated.
+// Some controls might need more keyboard keys to process (CTRL-C, CTRL-A etc),
+// In that case TranslateAccelerator should always be called first.
+//---------------------------------------------------------------------------
+bool wxActiveXContainer::MSWTranslateMessage(WXMSG* pMsg)
+{
+    if(m_oleInPlaceActiveObject.IsOk() && m_oleInPlaceActiveObject->TranslateAccelerator(pMsg) == S_OK)
+    {
+        return true;
+    }
+    return wxWindow::MSWTranslateMessage(pMsg);
+}
+
+//---------------------------------------------------------------------------
+// wxActiveXContainer::QueryClientSiteInterface
+//
+// Called in the host's site's query method for other interfaces.
+//---------------------------------------------------------------------------
+bool wxActiveXContainer::QueryClientSiteInterface(REFIID iid, void **_interface, const char *&desc)
+{
+    wxUnusedVar(iid);
+    wxUnusedVar(_interface);
+    wxUnusedVar(desc);
+    return false;
+}
+
 #endif // wxUSE_ACTIVEX
 #endif // wxUSE_ACTIVEX