]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/webview_ie.cpp
Add expand/collapse button to wxRibbonBar.
[wxWidgets.git] / src / msw / webview_ie.cpp
index ddfbd362d0da550459654ddfd331126972904ff9..5797f01c78e0246cc5a6830e3e05d5826ba2b11e 100644 (file)
@@ -83,7 +83,6 @@ bool wxWebViewIE::Create(wxWindow* parent,
     m_webBrowser->put_RegisterAsDropTarget(VARIANT_TRUE);
 
     m_uiHandler = new DocHostUIHandler;
-    m_uiHandler->AddRef();
 
     m_container = new wxIEContainer(this, IID_IWebBrowser2, m_webBrowser, m_uiHandler);
 
@@ -99,8 +98,6 @@ wxWebViewIE::~wxWebViewIE()
     {
         m_factories[i]->Release();
     }
-
-    m_uiHandler->Release();
 }
 
 void wxWebViewIE::LoadURL(const wxString& url)
@@ -108,7 +105,7 @@ void wxWebViewIE::LoadURL(const wxString& url)
     m_ie.CallMethod("Navigate", wxConvertStringToOle(url));
 }
 
-void wxWebViewIE::SetPage(const wxString& html, const wxString& baseUrl)
+void wxWebViewIE::DoSetPage(const wxString& html, const wxString& baseUrl)
 {
     BSTR bstr = SysAllocString(OLESTR(""));
     SAFEARRAY *psaStrings = SafeArrayCreateVector(VT_VARIANT, 0, 1);
@@ -121,14 +118,13 @@ void wxWebViewIE::SetPage(const wxString& html, const wxString& baseUrl)
 
         hr = SafeArrayUnaccessData(psaStrings);
 
-        IHTMLDocument2* document = GetDocument();
+        wxCOMPtr<IHTMLDocument2> document(GetDocument());
 
         if(!document)
             return;
 
         document->write(psaStrings);
         document->close();
-        document->Release();
 
         SafeArrayDestroy(psaStrings);
 
@@ -149,7 +145,6 @@ void wxWebViewIE::SetPage(const wxString& html, const wxString& baseUrl)
                 return;
 
             document->write(psaStrings);
-            document->Release();
 
             // SafeArrayDestroy calls SysFreeString for each BSTR
             SafeArrayDestroy(psaStrings);
@@ -179,12 +174,12 @@ void wxWebViewIE::SetPage(const wxString& html, const wxString& baseUrl)
 
 wxString wxWebViewIE::GetPageSource() const
 {
-    IHTMLDocument2* document = GetDocument();
+    wxCOMPtr<IHTMLDocument2> document(GetDocument());
 
     if(document)
     {
-        IHTMLElement *bodyTag = NULL;
-        IHTMLElement *htmlTag = NULL;
+        wxCOMPtr<IHTMLElement> bodyTag;
+        wxCOMPtr<IHTMLElement> htmlTag;
         wxString source;
         HRESULT hr = document->get_body(&bodyTag);
         if(SUCCEEDED(hr))
@@ -195,12 +190,8 @@ wxString wxWebViewIE::GetPageSource() const
                 BSTR bstr;
                 htmlTag->get_outerHTML(&bstr);
                 source = wxString(bstr);
-                htmlTag->Release();
             }
-            bodyTag->Release();
         }
-
-        document->Release();
         return source;
     }
     else
@@ -536,13 +527,12 @@ wxString wxWebViewIE::GetCurrentURL() const
 
 wxString wxWebViewIE::GetCurrentTitle() const
 {
-    IHTMLDocument2* document = GetDocument();
+    wxCOMPtr<IHTMLDocument2> document(GetDocument());
 
     if(document)
     {
         BSTR title;
         document->get_nameProp(&title);
-        document->Release();
         return wxString(title);
     }
     else
@@ -603,7 +593,7 @@ void wxWebViewIE::Redo()
 
 void wxWebViewIE::SetEditable(bool enable)
 {
-    IHTMLDocument2* document = GetDocument();
+    wxCOMPtr<IHTMLDocument2> document(GetDocument());
 
     if(document)
     {
@@ -612,19 +602,17 @@ void wxWebViewIE::SetEditable(bool enable)
         else
             document->put_designMode(SysAllocString(L"Off"));
 
-        document->Release();
     }
 }
 
 bool wxWebViewIE::IsEditable() const
 {
-    IHTMLDocument2* document = GetDocument();
+    wxCOMPtr<IHTMLDocument2> document(GetDocument());
 
     if(document)
     {
         BSTR mode;
         document->get_designMode(&mode);
-        document->Release();
         if(wxString(mode) == "On")
             return true;
         else
@@ -643,11 +631,11 @@ void wxWebViewIE::SelectAll()
 
 bool wxWebViewIE::HasSelection() const
 {
-    IHTMLDocument2* document = GetDocument();
+    wxCOMPtr<IHTMLDocument2> document(GetDocument());
 
     if(document)
     {
-        IHTMLSelectionObject* selection;
+        wxCOMPtr<IHTMLSelectionObject> selection;
         wxString sel;
         HRESULT hr = document->get_selection(&selection);
         if(SUCCEEDED(hr))
@@ -655,9 +643,7 @@ bool wxWebViewIE::HasSelection() const
             BSTR type;
             selection->get_type(&type);
             sel = wxString(type);
-            selection->Release();
         }
-        document->Release();
         return sel != "None";
     }
     else
@@ -673,33 +659,29 @@ void wxWebViewIE::DeleteSelection()
 
 wxString wxWebViewIE::GetSelectedText() const
 {
-    IHTMLDocument2* document = GetDocument();
+    wxCOMPtr<IHTMLDocument2> document(GetDocument());
 
     if(document)
     {
-        IHTMLSelectionObject* selection;
+        wxCOMPtr<IHTMLSelectionObject> selection;
         wxString selected;
         HRESULT hr = document->get_selection(&selection);
         if(SUCCEEDED(hr))
         {
-            IDispatch* disrange;
+            wxCOMPtr<IDispatch> disrange;
             hr = selection->createRange(&disrange);
             if(SUCCEEDED(hr))
             {
-                IHTMLTxtRange* range;
+                wxCOMPtr<IHTMLTxtRange> range;
                 hr = disrange->QueryInterface(IID_IHTMLTxtRange, (void**)&range);
                 if(SUCCEEDED(hr))
                 {
                     BSTR text;
                     range->get_text(&text);
                     selected = wxString(text);
-                    range->Release();
                 }
-                disrange->Release();
             }
-            selection->Release();
         }
-        document->Release();
         return selected;
     }
     else
@@ -710,33 +692,29 @@ wxString wxWebViewIE::GetSelectedText() const
 
 wxString wxWebViewIE::GetSelectedSource() const
 {
-    IHTMLDocument2* document = GetDocument();
+    wxCOMPtr<IHTMLDocument2> document(GetDocument());
 
     if(document)
     {
-        IHTMLSelectionObject* selection;
+        wxCOMPtr<IHTMLSelectionObject> selection;
         wxString selected;
         HRESULT hr = document->get_selection(&selection);
         if(SUCCEEDED(hr))
         {
-            IDispatch* disrange;
+            wxCOMPtr<IDispatch> disrange;
             hr = selection->createRange(&disrange);
             if(SUCCEEDED(hr))
             {
-                IHTMLTxtRange* range;
+                wxCOMPtr<IHTMLTxtRange> range;
                 hr = disrange->QueryInterface(IID_IHTMLTxtRange, (void**)&range);
                 if(SUCCEEDED(hr))
                 {
                     BSTR text;
                     range->get_htmlText(&text);
                     selected = wxString(text);
-                    range->Release();
                 }
-                disrange->Release();
             }
-            selection->Release();
         }
-        document->Release();
         return selected;
     }
     else
@@ -747,39 +725,35 @@ wxString wxWebViewIE::GetSelectedSource() const
 
 void wxWebViewIE::ClearSelection()
 {
-    IHTMLDocument2* document = GetDocument();
+    wxCOMPtr<IHTMLDocument2> document(GetDocument());
 
     if(document)
     {
-        IHTMLSelectionObject* selection;
+        wxCOMPtr<IHTMLSelectionObject> selection;
         wxString selected;
         HRESULT hr = document->get_selection(&selection);
         if(SUCCEEDED(hr))
         {
             selection->empty();
-            selection->Release();
         }
-        document->Release();
     }
 }
 
 wxString wxWebViewIE::GetPageText() const
 {
-    IHTMLDocument2* document = GetDocument();
+    wxCOMPtr<IHTMLDocument2> document(GetDocument());
 
     if(document)
     {
         wxString text;
-        IHTMLElement* body;
+        wxCOMPtr<IHTMLElement> body;
         HRESULT hr = document->get_body(&body);
         if(SUCCEEDED(hr))
         {
             BSTR out;
             body->get_innerText(&out);
             text = wxString(out);
-            body->Release();
         }
-        document->Release();
         return text;
     }
     else
@@ -790,11 +764,11 @@ wxString wxWebViewIE::GetPageText() const
 
 void wxWebViewIE::RunScript(const wxString& javascript)
 {
-    IHTMLDocument2* document = GetDocument();
+    wxCOMPtr<IHTMLDocument2> document(GetDocument());
 
     if(document)
     {
-        IHTMLWindow2* window;
+        wxCOMPtr<IHTMLWindow2> window;
         wxString language = "javascript";
         HRESULT hr = document->get_parentWindow(&window);
         if(SUCCEEDED(hr))
@@ -806,7 +780,6 @@ void wxWebViewIE::RunScript(const wxString& javascript)
                                SysAllocString(language.wc_str()),
                                &level);
         }
-        document->Release();
     }
 }
 
@@ -843,14 +816,13 @@ void wxWebViewIE::RegisterHandler(wxSharedPtr<wxWebViewHandler> handler)
 
 bool wxWebViewIE::CanExecCommand(wxString command) const
 {
-    IHTMLDocument2* document = GetDocument();
+    wxCOMPtr<IHTMLDocument2> document(GetDocument());
 
     if(document)
     {
         VARIANT_BOOL enabled;
 
         document->queryCommandEnabled(SysAllocString(command.wc_str()), &enabled);
-        document->Release();
 
         return (enabled == VARIANT_TRUE);
     }
@@ -863,30 +835,25 @@ bool wxWebViewIE::CanExecCommand(wxString command) const
 
 void wxWebViewIE::ExecCommand(wxString command)
 {
-    IHTMLDocument2* document = GetDocument();
+    wxCOMPtr<IHTMLDocument2> document(GetDocument());
 
     if(document)
     {
         document->execCommand(SysAllocString(command.wc_str()), VARIANT_FALSE, VARIANT(), NULL);
-        document->Release();
     }
 }
 
-IHTMLDocument2* wxWebViewIE::GetDocument() const
+wxCOMPtr<IHTMLDocument2> wxWebViewIE::GetDocument() const
 {
-    IDispatch* dispatch;
+    wxCOMPtr<IDispatch> dispatch;
+    wxCOMPtr<IHTMLDocument2> document;
     HRESULT result = m_webBrowser->get_Document(&dispatch);
-    if(SUCCEEDED(result))
+    if(dispatch && SUCCEEDED(result))
     {
-        IHTMLDocument2* document;
-        dispatch->QueryInterface(IID_IHTMLDocument2, (void**)&document);
         //document is set to null automatically if the interface isn't supported
-        return document;
-    }
-    else
-    {
-        return NULL;
+        dispatch->QueryInterface(IID_IHTMLDocument2, (void**)&document);
     }
+    return document;
 }
 
 bool wxWebViewIE::EnableControlFeature(long flag, bool enable)
@@ -1206,7 +1173,7 @@ END_IID_TABLE;
 
 IMPLEMENT_IUNKNOWN_METHODS(VirtualProtocol)
 
-HRESULT VirtualProtocol::Start(LPCWSTR szUrl, wxIInternetProtocolSink *pOIProtSink,
+HRESULT STDMETHODCALLTYPE VirtualProtocol::Start(LPCWSTR szUrl, wxIInternetProtocolSink *pOIProtSink,
                                wxIInternetBindInfo *pOIBindInfo, DWORD grfPI,
                                HANDLE_PTR dwReserved)
 {
@@ -1233,7 +1200,7 @@ HRESULT VirtualProtocol::Start(LPCWSTR szUrl, wxIInternetProtocolSink *pOIProtSi
     return S_OK;
 }
 
-HRESULT VirtualProtocol::Read(void *pv, ULONG cb, ULONG *pcbRead)
+HRESULT STDMETHODCALLTYPE VirtualProtocol::Read(void *pv, ULONG cb, ULONG *pcbRead)
 {
     //If the file is null we return false to indicte it is finished
     if(!m_file)
@@ -1279,7 +1246,7 @@ END_IID_TABLE;
 
 IMPLEMENT_IUNKNOWN_METHODS(ClassFactory)
 
-HRESULT ClassFactory::CreateInstance(IUnknown* pUnkOuter, REFIID riid,
+HRESULT STDMETHODCALLTYPE ClassFactory::CreateInstance(IUnknown* pUnkOuter, REFIID riid,
                                      void ** ppvObject)
 {
     if (pUnkOuter)
@@ -1321,7 +1288,7 @@ bool wxIEContainer::QueryClientSiteInterface(REFIID iid, void **_interface,
     return false;
 }
 
-HRESULT DocHostUIHandler::ShowContextMenu(DWORD dwID, POINT *ppt,
+HRESULT wxSTDCALL DocHostUIHandler::ShowContextMenu(DWORD dwID, POINT *ppt,
                                           IUnknown *pcmdtReserved,
                                           IDispatch *pdispReserved)
 {
@@ -1332,14 +1299,14 @@ HRESULT DocHostUIHandler::ShowContextMenu(DWORD dwID, POINT *ppt,
     return E_NOTIMPL;
 }
 
-HRESULT DocHostUIHandler::GetHostInfo(DOCHOSTUIINFO *pInfo)
+HRESULT wxSTDCALL DocHostUIHandler::GetHostInfo(DOCHOSTUIINFO *pInfo)
 {
     //don't show 3d border and enable themes.
     pInfo->dwFlags = pInfo->dwFlags | DOCHOSTUIFLAG_NO3DBORDER | DOCHOSTUIFLAG_THEME;
     return S_OK;
 }
 
-HRESULT DocHostUIHandler::ShowUI(DWORD dwID,
+HRESULT wxSTDCALL DocHostUIHandler::ShowUI(DWORD dwID,
                                  IOleInPlaceActiveObject *pActiveObject,
                                  IOleCommandTarget *pCommandTarget,
                                  IOleInPlaceFrame *pFrame,
@@ -1353,35 +1320,35 @@ HRESULT DocHostUIHandler::ShowUI(DWORD dwID,
     return S_FALSE;
 }
 
-HRESULT DocHostUIHandler::HideUI(void)
+HRESULT wxSTDCALL DocHostUIHandler::HideUI(void)
 {
     return E_NOTIMPL;
 }
 
-HRESULT DocHostUIHandler::UpdateUI(void)
+HRESULT wxSTDCALL DocHostUIHandler::UpdateUI(void)
 {
     return E_NOTIMPL;
 }
 
-HRESULT DocHostUIHandler::EnableModeless(BOOL fEnable)
+HRESULT wxSTDCALL DocHostUIHandler::EnableModeless(BOOL fEnable)
 {
     wxUnusedVar(fEnable);
     return E_NOTIMPL;
 }
 
-HRESULT DocHostUIHandler::OnDocWindowActivate(BOOL fActivate)
+HRESULT wxSTDCALL DocHostUIHandler::OnDocWindowActivate(BOOL fActivate)
 {
     wxUnusedVar(fActivate);
     return E_NOTIMPL;
 }
 
-HRESULT DocHostUIHandler::OnFrameWindowActivate(BOOL fActivate)
+HRESULT wxSTDCALL DocHostUIHandler::OnFrameWindowActivate(BOOL fActivate)
 {
     wxUnusedVar(fActivate);
     return E_NOTIMPL;
 }
 
-HRESULT DocHostUIHandler::ResizeBorder(LPCRECT prcBorder,
+HRESULT wxSTDCALL DocHostUIHandler::ResizeBorder(LPCRECT prcBorder,
                                        IOleInPlaceUIWindow *pUIWindow,
                                        BOOL fFrameWindow)
 {
@@ -1391,7 +1358,7 @@ HRESULT DocHostUIHandler::ResizeBorder(LPCRECT prcBorder,
     return E_NOTIMPL;
 }
 
-HRESULT DocHostUIHandler::TranslateAccelerator(LPMSG lpMsg,
+HRESULT wxSTDCALL DocHostUIHandler::TranslateAccelerator(LPMSG lpMsg,
                                                const GUID *pguidCmdGroup,
                                                DWORD nCmdID)
 {
@@ -1400,10 +1367,15 @@ HRESULT DocHostUIHandler::TranslateAccelerator(LPMSG lpMsg,
         //control is down?
         if((GetKeyState(VK_CONTROL) & 0x8000 ))
         {
-            //skip CTRL-N, CTRL-F and CTRL-P
-            if(lpMsg->wParam == 'N' || lpMsg->wParam == 'P' || lpMsg->wParam == 'F')
+            //skip the accelerators used by the control
+            switch(lpMsg->wParam)
             {
-                return S_OK;
+                case 'F':
+                case 'L':
+                case 'N':
+                case 'O':
+                case 'P':
+                    return S_OK;
             }
         }
         //skip F5
@@ -1418,14 +1390,14 @@ HRESULT DocHostUIHandler::TranslateAccelerator(LPMSG lpMsg,
     return E_NOTIMPL;
 }
 
-HRESULT DocHostUIHandler::GetOptionKeyPath(LPOLESTR *pchKey,DWORD dw)
+HRESULT wxSTDCALL DocHostUIHandler::GetOptionKeyPath(LPOLESTR *pchKey,DWORD dw)
 {
     wxUnusedVar(pchKey);
     wxUnusedVar(dw);
     return E_NOTIMPL;
 }
 
-HRESULT DocHostUIHandler::GetDropTarget(IDropTarget *pDropTarget,
+HRESULT wxSTDCALL DocHostUIHandler::GetDropTarget(IDropTarget *pDropTarget,
                                         IDropTarget **ppDropTarget)
 {
     wxUnusedVar(pDropTarget);
@@ -1433,13 +1405,13 @@ HRESULT DocHostUIHandler::GetDropTarget(IDropTarget *pDropTarget,
     return E_NOTIMPL;
 }
 
-HRESULT DocHostUIHandler::GetExternal(IDispatch **ppDispatch)
+HRESULT wxSTDCALL DocHostUIHandler::GetExternal(IDispatch **ppDispatch)
 {
     wxUnusedVar(ppDispatch);
     return E_NOTIMPL;
 }
 
-HRESULT DocHostUIHandler::TranslateUrl(DWORD dwTranslate,
+HRESULT wxSTDCALL DocHostUIHandler::TranslateUrl(DWORD dwTranslate,
                                        OLECHAR *pchURLIn,
                                        OLECHAR **ppchURLOut)
 {
@@ -1449,7 +1421,7 @@ HRESULT DocHostUIHandler::TranslateUrl(DWORD dwTranslate,
     return E_NOTIMPL;
 }
 
-HRESULT DocHostUIHandler::FilterDataObject(IDataObject *pDO, IDataObject **ppDORet)
+HRESULT wxSTDCALL DocHostUIHandler::FilterDataObject(IDataObject *pDO, IDataObject **ppDORet)
 {
     wxUnusedVar(pDO);
     wxUnusedVar(ppDORet);