ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

webchild.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright 2004, 2005 Martin Fuchs
00003  *
00004  * This library is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU Lesser General Public
00006  * License as published by the Free Software Foundation; either
00007  * version 2.1 of the License, or (at your option) any later version.
00008  *
00009  * This library is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * Lesser General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU Lesser General Public
00015  * License along with this library; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00017  */
00018 
00019 
00020  //
00021  // Explorer clone
00022  //
00023  // webchild.cpp
00024  //
00025  // Martin Fuchs, 08.02.2004
00026  //
00027 
00028 
00029 #include <precomp.h>
00030 
00031 #include "../resource.h"
00032 
00033 #include "webchild.h"
00034 
00035 
00036 #ifdef _MSC_VER
00037 
00038 #if _MSC_VER>=1300  // vtMissing for VS.Net
00039 #include <comutil.h>
00040 #pragma comment(lib, "comsupp")
00041 #endif
00042 
00043 #else
00044 
00045 #ifdef __MINGW32__  // MinGW is lacking vtMissing (as of 07.02.2004)
00046 static Variant vtMissing;
00047 #endif
00048 
00049 #endif
00050 
00051 //#include <mshtml.h>
00052 
00053 
00054 Variant::Variant(const VARIANT& var)
00055 {
00056     VariantInit(this);
00057     CheckError(VariantCopy(this, const_cast<VARIANT*>(&var)));
00058 }
00059 
00060 Variant::Variant(const VARIANT* var)
00061 {
00062     VariantInit(this);
00063     CheckError(VariantCopy(this, const_cast<VARIANT*>(var)));
00064 }
00065 
00066 Variant::~Variant()
00067 {
00068     VariantClear(this);
00069 }
00070 
00071 
00072 Variant::operator long() const
00073 {
00074     Variant v;
00075     CheckError(VariantChangeType(&v, (VARIANT*)this, 0, VT_I4));
00076     return V_I4(&v);
00077 }
00078 
00079 Variant::operator bool() const
00080 {
00081     Variant v;
00082     CheckError(VariantChangeType(&v, (VARIANT*)this, 0, VT_BOOL));
00083     return V_BOOL(&v)? true: false;
00084 }
00085 
00086 Variant::operator IDispatch*() const
00087 {
00088     Variant v;
00089     CheckError(VariantChangeType(&v, (VARIANT*)this, 0, VT_DISPATCH));
00090     return V_DISPATCH(&v);
00091 }
00092 
00093 Variant::operator VARIANT_BOOL() const
00094 {
00095     Variant v;
00096     CheckError(VariantChangeType(&v, (VARIANT*)this, 0, VT_BOOL));
00097     return V_BOOL(&v);
00098 }
00099 
00100 
00101 void BStr::assign(BSTR s)
00102 {
00103     if (!SysReAllocString(&_p, s))
00104         THROW_EXCEPTION(E_OUTOFMEMORY);
00105 }
00106 
00107 void BStr::assign(const VARIANT& var)
00108 {
00109     if (V_VT(&var) == VT_BSTR)
00110         assign(V_BSTR(&var));
00111     else {
00112         Variant v;
00113         CheckError(VariantChangeType(&v, const_cast<VARIANT*>(&var), 0, VT_BSTR));
00114         assign(V_BSTR(&v));
00115     }
00116 }
00117 
00118 
00119 BrowserNavigator::BrowserNavigator()
00120  :  _browser_initialized(false)
00121 {
00122 }
00123 
00124 void BrowserNavigator::attach(IWebBrowser* browser)
00125 {
00126     _browser = browser;
00127 }
00128 
00129 void BrowserNavigator::goto_url(LPCTSTR url)
00130 {
00131     if (_browser_initialized)
00132         _browser->Navigate(BStr(url), NULL, NULL, NULL, NULL);
00133     else {
00134         _new_url = url;
00135 
00136         _browser->Navigate(BStr(L"about:blank"), NULL, NULL, NULL, NULL);
00137     }
00138 }
00139 
00140 void BrowserNavigator::set_html_page(const String& html_txt)
00141 {
00142     _new_html_txt = html_txt;
00143 
00144     goto_url(TEXT("about:blank"));
00145 }
00146 
00147 void T2nA_binary(LPCTSTR s, LPSTR d, int len)
00148 {
00149     while(len-- > 0)
00150         *d++ = (unsigned char)*s++;
00151 }
00152 
00153 void BrowserNavigator::navigated(LPCTSTR url)
00154 {
00155     _browser_initialized = true;
00156 
00157     bool nav = false;
00158 
00159     if (!_new_url.empty()) {
00160         if (!_tcscmp(url,TEXT("about:blank")) && _new_url!=TEXT("about:blank")) {
00161             _browser->Navigate(BStr(_new_url), NULL, NULL, NULL, NULL);
00162             ++nav;
00163         }
00164 
00165         _new_url.erase();
00166     }
00167 
00168     if (!nav && !_new_html_txt.empty()) {   
00169         int len = _new_html_txt.length();
00170         HGLOBAL hHtmlText = GlobalAlloc(GPTR, len);
00171 
00172         if (!hHtmlText) {
00173             T2nA_binary(_new_html_txt, (char*)hHtmlText, len);
00174             _new_html_txt.erase();
00175 
00176             SIfacePtr<IStream> pStream;
00177             HRESULT hr = CreateStreamOnHGlobal(hHtmlText, TRUE, &pStream);
00178 
00179             if (SUCCEEDED(hr)) {
00180                 SIfacePtr<IDispatch> pHtmlDoc;
00181                 CheckError(_browser->get_Document(&pHtmlDoc));
00182 
00183                 SIfacePtr<IPersistStreamInit> pPersistStreamInit;
00184                 pHtmlDoc.QueryInterface(IID_IPersistStreamInit, &pPersistStreamInit);
00185 
00186                 CheckError(pPersistStreamInit->InitNew());
00187                 CheckError(pPersistStreamInit->Load(pStream));
00188             } else
00189                 GlobalFree(hHtmlText);
00190         }
00191     }
00192 }
00193 
00194 
00195 HWND create_webchildwindow(const WebChildWndInfo& info)
00196 {
00197     WebChildWindow* pWnd = WebChildWindow::create(info);
00198 
00199     if (!pWnd)
00200         return 0;
00201 
00202     return *pWnd;
00203 }
00204 
00205 static const CLSID CLSID_MozillaBrowser =
00206     {0x1339B54C, 0x3453, 0x11D2, {0x93, 0xB9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}};
00207 
00208 
00209 WebChildWindow::WebChildWindow(HWND hwnd, const WebChildWndInfo& info)
00210  :  super(hwnd, info),
00211     web_super(_navigator)
00212 {
00213      // first try to create a web control with MS IE's CLASSID
00214     HRESULT hr = create_control(hwnd, CLSID_WebBrowser, IID_IWebBrowser2);
00215 
00216      // If this failed, try to use Mozilla's web control
00217     if (FAILED(hr))
00218         hr = create_control(hwnd, CLSID_MozillaBrowser, IID_IWebBrowser2);
00219 
00220     if (SUCCEEDED(hr)) {
00221         _navigator.attach(_control);
00222 
00223         _connector = auto_ptr<EventConnector>(new EventConnector(_control, DIID_DWebBrowserEvents2, this));
00224 
00225         _control->Navigate(BStr(info._path), &vtMissing, &vtMissing, &vtMissing, &vtMissing);
00226         //browser->Navigate2(&Variant(info._path), &vtMissing, &vtMissing, &vtMissing, &vtMissing);
00227     }
00228 }
00229 
00230 LRESULT WebChildWindow::WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam)
00231 {
00232     try {
00233         switch(nmsg) {
00234           case WM_ERASEBKGND:
00235             if (!_control) {
00236                 HDC hdc = (HDC)wparam;
00237                 ClientRect rect(_hwnd);
00238 
00239                 HBRUSH hbrush = CreateSolidBrush(RGB(200,200,235));
00240                 BkMode mode(hdc, TRANSPARENT);
00241                 TextColor color(hdc, RGB(200,40,40));
00242                 FillRect(hdc, &rect, hbrush);
00243                 DrawText(hdc, TEXT("Sorry - no web browser control could be loaded."), -1, &rect, DT_CENTER|DT_VCENTER|DT_SINGLELINE);
00244                 DeleteObject(hbrush);
00245             }
00246 
00247             return TRUE;
00248 
00249           case PM_DISPATCH_COMMAND: {
00250             if (!_control)
00251                 return FALSE;
00252 
00253             HRESULT hr = E_FAIL;
00254 
00255             switch(LOWORD(wparam)) {
00256               case ID_GO_BACK:
00257                 hr = _control->GoBack();
00258                 break;
00259 
00260               case ID_GO_FORWARD:
00261                 hr = _control->GoForward();
00262                 break;
00263 
00264               case ID_GO_UP:
00266                 break;
00267 
00268               case ID_GO_HOME:
00269                 hr = _control->GoHome();
00270                 break;
00271 
00272               case ID_GO_SEARCH:
00273                 hr = _control->GoSearch();
00274                 break;
00275 
00276               case ID_REFRESH:
00277                 hr = _control->Refresh();
00278                 break;
00279 
00280               case ID_STOP:
00281                 hr = _control->Stop();
00282                 break;
00283 
00284               default:
00285                 return super::WndProc(nmsg, wparam, lparam);
00286             }
00287 
00288             if (FAILED(hr) && hr!=E_FAIL)
00289                 THROW_EXCEPTION(hr);
00290 
00291             return TRUE;}
00292 
00293           default:
00294             return super::WndProc(nmsg, wparam, lparam);
00295         }
00296     } catch(COMException& e) {
00297         HandleException(e, _hwnd);
00298     }
00299 
00300     return 0;
00301 }
00302 
00303 
00304 String WebChildWindow::jump_to_int(LPCTSTR url)
00305 {
00306     _navigator.goto_url(url);
00307 
00308     return url;
00309 }

Generated on Fri May 25 2012 04:16:45 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.