]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/webview_ie.cpp
missing commit
[wxWidgets.git] / src / msw / webview_ie.cpp
index 76c1c0a5feb35fa8aac6f8ad537147669a3ee6ba..b3f5e289ef2b613928e6ea4eb7d95e0799a5970e 100644 (file)
@@ -188,13 +188,13 @@ void wxWebViewIE::DoSetPage(const wxString& html, const wxString& baseUrl)
 
             //We send the events when we are done to mimic webkit
             //Navigated event
 
             //We send the events when we are done to mimic webkit
             //Navigated event
-            wxWebViewEvent event(wxEVT_COMMAND_WEBVIEW_NAVIGATED,
+            wxWebViewEvent event(wxEVT_WEBVIEW_NAVIGATED,
                                  GetId(), baseUrl, "");
             event.SetEventObject(this);
             HandleWindowEvent(event);
 
             //Document complete event
                                  GetId(), baseUrl, "");
             event.SetEventObject(this);
             HandleWindowEvent(event);
 
             //Document complete event
-            event.SetEventType(wxEVT_COMMAND_WEBVIEW_LOADED);
+            event.SetEventType(wxEVT_WEBVIEW_LOADED);
             event.SetEventObject(this);
             HandleWindowEvent(event);
         }
             event.SetEventObject(this);
             HandleWindowEvent(event);
         }
@@ -940,19 +940,19 @@ wxCOMPtr<IHTMLDocument2> wxWebViewIE::GetDocument() const
     return document;
 }
 
     return document;
 }
 
-bool wxWebViewIE::IsElementVisible(IHTMLElement* elm)
+bool wxWebViewIE::IsElementVisible(wxCOMPtr<IHTMLElement> elm)
 {
 {
-    wxIHTMLCurrentStyle* style;
-    IHTMLElement *elm1 = elm;
-    wxIHTMLElement2 *elm2;
+    wxCOMPtr<IHTMLElement> elm1 = elm;
     BSTR tmp_bstr;
     bool is_visible = true;
     //This method is not perfect but it does discover most of the hidden elements.
     //so if a better solution is found, then please do improve.
     while(elm1)
     {
     BSTR tmp_bstr;
     bool is_visible = true;
     //This method is not perfect but it does discover most of the hidden elements.
     //so if a better solution is found, then please do improve.
     while(elm1)
     {
+        wxCOMPtr<wxIHTMLElement2> elm2;
         if(SUCCEEDED(elm1->QueryInterface(wxIID_IHTMLElement2, (void**) &elm2)))
         {
         if(SUCCEEDED(elm1->QueryInterface(wxIID_IHTMLElement2, (void**) &elm2)))
         {
+            wxCOMPtr<wxIHTMLCurrentStyle> style;
             if(SUCCEEDED(elm2->get_currentStyle(&style)))
             {
                 //Check if the object has the style display:none.
             if(SUCCEEDED(elm2->get_currentStyle(&style)))
             {
                 //Check if the object has the style display:none.
@@ -962,7 +962,7 @@ bool wxWebViewIE::IsElementVisible(IHTMLElement* elm)
                     is_visible = false;
                 }
                 //Check if the object has the style visibility:hidden.
                     is_visible = false;
                 }
                 //Check if the object has the style visibility:hidden.
-                if(is_visible && (style->get_visibility(&tmp_bstr) != S_OK) || 
+                if((is_visible && (style->get_visibility(&tmp_bstr) != S_OK)) ||
                   (tmp_bstr != NULL && _wcsicmp(tmp_bstr, L"hidden") == 0))
                 {
                     is_visible = false;
                   (tmp_bstr != NULL && _wcsicmp(tmp_bstr, L"hidden") == 0))
                 {
                     is_visible = false;
@@ -976,7 +976,6 @@ bool wxWebViewIE::IsElementVisible(IHTMLElement* elm)
         IHTMLElement* parent;
         if(is_visible && SUCCEEDED(elm1->get_parentElement(&parent)))
         {
         IHTMLElement* parent;
         if(is_visible && SUCCEEDED(elm1->get_parentElement(&parent)))
         {
-            elm1->Release();
             elm1 = parent;
         }
         else
             elm1 = parent;
         }
         else
@@ -990,17 +989,17 @@ bool wxWebViewIE::IsElementVisible(IHTMLElement* elm)
 
 void wxWebViewIE::FindInternal(const wxString& text, int flags, int internal_flag)
 {
 
 void wxWebViewIE::FindInternal(const wxString& text, int flags, int internal_flag)
 {
-    wxIMarkupServices *pIMS;
-    wxIMarkupContainer *pIMC;
-    wxIMarkupPointer *ptrBegin, *ptrEnd;
-    IHTMLElement* elm;
     long find_flag = 0;
     long find_flag = 0;
-    IHTMLDocument2 *document = GetDocument();
+    wxCOMPtr<wxIMarkupServices> pIMS;
+    wxCOMPtr<IHTMLDocument2> document = GetDocument();
+
     //This function does the acutal work.
     //This function does the acutal work.
-    if(SUCCEEDED(document->QueryInterface(wxIID_IMarkupServices, (void **)&pIMS)))
+    if(document && SUCCEEDED(document->QueryInterface(wxIID_IMarkupServices, (void **)&pIMS)))
     {
     {
+        wxCOMPtr<wxIMarkupContainer> pIMC;
         if(SUCCEEDED(document->QueryInterface(wxIID_IMarkupContainer, (void **)&pIMC)))
         {
         if(SUCCEEDED(document->QueryInterface(wxIID_IMarkupContainer, (void **)&pIMC)))
         {
+            wxCOMPtr<wxIMarkupPointer> ptrBegin, ptrEnd;
             BSTR attr_bstr = SysAllocString(L"style=\"background-color:#ffff00\"");
             BSTR text_bstr = SysAllocString(text.wc_str());
             pIMS->CreateMarkupPointer(&ptrBegin);
             BSTR attr_bstr = SysAllocString(L"style=\"background-color:#ffff00\"");
             BSTR text_bstr = SysAllocString(text.wc_str());
             pIMS->CreateMarkupPointer(&ptrBegin);
@@ -1026,6 +1025,7 @@ void wxWebViewIE::FindInternal(const wxString& text, int flags, int internal_fla
 
             while(ptrBegin->FindText(text_bstr, find_flag, ptrEnd, NULL) == S_OK)
             {
 
             while(ptrBegin->FindText(text_bstr, find_flag, ptrEnd, NULL) == S_OK)
             {
+                wxCOMPtr<IHTMLElement> elm;
                 if(ptrBegin->CurrentScope(&elm) == S_OK)
                 {
                     if(IsElementVisible(elm))
                 if(ptrBegin->CurrentScope(&elm) == S_OK)
                 {
                     if(IsElementVisible(elm))
@@ -1054,20 +1054,14 @@ void wxWebViewIE::FindInternal(const wxString& text, int flags, int internal_fla
                             m_findPointers.push_back(wxFindPointers(cptrBegin,cptrEnd));
                         }
                     }
                             m_findPointers.push_back(wxFindPointers(cptrBegin,cptrEnd));
                         }
                     }
-                    elm->Release();
                 }
                 ptrBegin->MoveToPointer(ptrEnd);
             }
             //Clean up.
             SysFreeString(text_bstr);
             SysFreeString(attr_bstr);
                 }
                 ptrBegin->MoveToPointer(ptrEnd);
             }
             //Clean up.
             SysFreeString(text_bstr);
             SysFreeString(attr_bstr);
-            pIMC->Release();
-            ptrBegin->Release();
-            ptrEnd->Release();
         }
         }
-        pIMS->Release();
     }
     }
-    document->Release();
 }
 
 long wxWebViewIE::FindNext(int direction)
 }
 
 long wxWebViewIE::FindNext(int direction)
@@ -1111,20 +1105,21 @@ long wxWebViewIE::FindNext(int direction)
             return wxNOT_FOUND;
         }
     }
             return wxNOT_FOUND;
         }
     }
-    //some variables to use later on.
-    IHTMLElement *body_element;
-    IHTMLBodyElement *body;
-    wxIHTMLTxtRange *range = NULL;
-    wxIMarkupServices *pIMS;
-    IHTMLDocument2 *document = GetDocument();
+
+    wxCOMPtr<IHTMLDocument2> document = GetDocument();
+    wxCOMPtr<IHTMLElement> body_element;
+
     long ret = -1;
     //Now try to create a range from the body.
     long ret = -1;
     //Now try to create a range from the body.
-    if(SUCCEEDED(document->get_body(&body_element)))
+    if(document && SUCCEEDED(document->get_body(&body_element)))
     {
     {
+        wxCOMPtr<IHTMLBodyElement> body;
         if(SUCCEEDED(body_element->QueryInterface(IID_IHTMLBodyElement,(void**)&body)))
         {
         if(SUCCEEDED(body_element->QueryInterface(IID_IHTMLBodyElement,(void**)&body)))
         {
+            wxCOMPtr<wxIHTMLTxtRange> range;
             if(SUCCEEDED(body->createTextRange((IHTMLTxtRange**)(&range))))
             {
             if(SUCCEEDED(body->createTextRange((IHTMLTxtRange**)(&range))))
             {
+                wxCOMPtr<wxIMarkupServices> pIMS;
                 //So far so good, now we try to position our find pointers.
                 if(SUCCEEDED(document->QueryInterface(wxIID_IMarkupServices,(void **)&pIMS)))
                 {
                 //So far so good, now we try to position our find pointers.
                 if(SUCCEEDED(document->QueryInterface(wxIID_IMarkupServices,(void **)&pIMS)))
                 {
@@ -1133,15 +1128,10 @@ long wxWebViewIE::FindNext(int direction)
                     {
                         ret = m_findPosition;
                     }
                     {
                         ret = m_findPosition;
                     }
-                    pIMS->Release();
                 }
                 }
-                range->Release();
             }
             }
-            body->Release();
         }
         }
-        body_element->Release();
     }
     }
-    document->Release();
     return ret;
 }
 
     return ret;
 }
 
@@ -1217,7 +1207,7 @@ void wxWebViewIE::onActiveXEvent(wxActiveXEvent& evt)
             wxString url = evt[1].GetString();
             wxString target = evt[3].GetString();
 
             wxString url = evt[1].GetString();
             wxString target = evt[3].GetString();
 
-            wxWebViewEvent event(wxEVT_COMMAND_WEBVIEW_NAVIGATING,
+            wxWebViewEvent event(wxEVT_WEBVIEW_NAVIGATING,
                                  GetId(), url, target);
 
             //skip empty javascript events.
                                  GetId(), url, target);
 
             //skip empty javascript events.
@@ -1252,7 +1242,7 @@ void wxWebViewIE::onActiveXEvent(wxActiveXEvent& evt)
             wxString url = evt[1].GetString();
             // TODO: set target parameter if possible
             wxString target = wxEmptyString;
             wxString url = evt[1].GetString();
             // TODO: set target parameter if possible
             wxString target = wxEmptyString;
-            wxWebViewEvent event(wxEVT_COMMAND_WEBVIEW_NAVIGATED,
+            wxWebViewEvent event(wxEVT_WEBVIEW_NAVIGATED,
                                  GetId(), url, target);
             event.SetEventObject(this);
             HandleWindowEvent(event);
                                  GetId(), url, target);
             event.SetEventObject(this);
             HandleWindowEvent(event);
@@ -1303,7 +1293,7 @@ void wxWebViewIE::onActiveXEvent(wxActiveXEvent& evt)
             FindClear();
             // TODO: set target parameter if possible
             wxString target = wxEmptyString;
             FindClear();
             // TODO: set target parameter if possible
             wxString target = wxEmptyString;
-            wxWebViewEvent event(wxEVT_COMMAND_WEBVIEW_LOADED, GetId(),
+            wxWebViewEvent event(wxEVT_WEBVIEW_LOADED, GetId(),
                                  url, target);
             event.SetEventObject(this);
             HandleWindowEvent(event);
                                  url, target);
             event.SetEventObject(this);
             HandleWindowEvent(event);
@@ -1319,7 +1309,7 @@ void wxWebViewIE::onActiveXEvent(wxActiveXEvent& evt)
         {
             wxString title = evt[0].GetString();
 
         {
             wxString title = evt[0].GetString();
 
-            wxWebViewEvent event(wxEVT_COMMAND_WEBVIEW_TITLE_CHANGED,
+            wxWebViewEvent event(wxEVT_WEBVIEW_TITLE_CHANGED,
                                  GetId(), GetCurrentURL(), "");
             event.SetString(title);
             event.SetEventObject(this);
                                  GetId(), GetCurrentURL(), "");
             event.SetString(title);
             event.SetEventObject(this);
@@ -1329,7 +1319,7 @@ void wxWebViewIE::onActiveXEvent(wxActiveXEvent& evt)
 
         case DISPID_NAVIGATEERROR:
         {
 
         case DISPID_NAVIGATEERROR:
         {
-            wxWebViewEvent event(wxEVT_COMMAND_WEBVIEW_ERROR, GetId(),
+            wxWebViewEvent event(wxEVT_WEBVIEW_ERROR, GetId(),
                                  evt[1].GetString(), evt[2].GetString());
             event.SetEventObject(this);
 
                                  evt[1].GetString(), evt[2].GetString());
             event.SetEventObject(this);
 
@@ -1396,7 +1386,7 @@ void wxWebViewIE::onActiveXEvent(wxActiveXEvent& evt)
         {
             wxString url = evt[4].GetString();
 
         {
             wxString url = evt[4].GetString();
 
-            wxWebViewEvent event(wxEVT_COMMAND_WEBVIEW_NEWWINDOW,
+            wxWebViewEvent event(wxEVT_WEBVIEW_NEWWINDOW,
                                  GetId(), url, wxEmptyString);
             event.SetEventObject(this);
             HandleWindowEvent(event);
                                  GetId(), url, wxEmptyString);
             event.SetEventObject(this);
             HandleWindowEvent(event);