Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members   Related Pages  

HtmlFrm.cpp

00001 /* QuestDesigner - Open Zelda's Project
00002    Copyright (C) 2003 Kronuz
00003    Copyright (C) 2001/2003 Open Zelda's Project
00004  
00005    This program is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU General Public License
00007    as published by the Free Software Foundation; either version 2
00008    of the License, or (at your option) any later version.
00009 
00010    This program is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013    GNU General Public License for more details.
00014 
00015    You should have received a copy of the GNU General Public License
00016    along with this program; if not, write to the Free Software
00017    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00018 */
00019 
00021 // HtmlFrm.cpp : implementation of the CHtmlFrame class
00022 //
00023 
00024 #include "stdafx.h"
00025 #include "HtmlFrm.h"
00026 
00027 CHtmlFrame::CHtmlFrame(CMainFrame *pMainFrame) :
00028     m_pHtmlView(NULL)
00029 {
00030     m_pMainFrame = pMainFrame;
00031     m_pCmdBar = NULL;
00032 }
00033 
00034 void CHtmlFrame::OnFinalMessage(HWND /*hWnd*/)
00035 {
00036     delete this;
00037 }
00038 void CHtmlFrame::SetCommandBarCtrlForContextMenu(CTabbedMDICommandBarCtrl* pCmdBar)
00039 {
00040     m_pCmdBar = pCmdBar;
00041 }
00042 
00043 LRESULT CHtmlFrame::OnCreate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled)
00044 {
00045     LRESULT lRet = DefWindowProc();
00046     bHandled = TRUE;
00047 
00048     m_pHtmlView = new CHtmlView(this);
00049 
00050     // create our view
00051     m_hWndClient = m_pHtmlView->Create( m_hWnd, 
00052                                         rcDefault, 
00053                                         _T(""), 
00054                                         WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_HSCROLL | WS_VSCROLL, 
00055                                         WS_EX_CLIENTEDGE);
00056     if ( NULL == m_hWndClient ) {
00057         ATLTRACE ( _T ( "Error: failed to create child window\n" ) );
00058         return FALSE;
00059     }
00060 
00061     m_pHtmlView->get_Control(&m_punkBrowser);
00062     if(m_punkBrowser)
00063         DispEventAdvise(m_punkBrowser, &DIID_DWebBrowserEvents2);
00064 
00065     return TRUE;
00066 }
00067 LRESULT CHtmlFrame::OnDestroy(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled)
00068 {
00069     if(m_punkBrowser)
00070         DispEventUnadvise(m_punkBrowser, &DIID_DWebBrowserEvents2);
00071     bHandled = FALSE;
00072     return 0;
00073 }
00074 LRESULT CHtmlFrame::OnForwardMsg(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM lParam, BOOL& /*bHandled*/)
00075 {
00076     LPMSG pMsg = (LPMSG)lParam;
00077 
00078     if(baseClass::PreTranslateMessage(pMsg))
00079         return TRUE;
00080 
00081     return m_pHtmlView->PreTranslateMessage(pMsg);
00082 }
00083 LRESULT CHtmlFrame::OnSettingChange(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& /*bHandled*/)
00084 {
00085     // System settings or metrics have changed.  Propogate this message
00086     // to all the child windows so they can update themselves as appropriate.
00087     SendMessageToDescendants(uMsg, wParam, lParam, TRUE);
00088     
00089     return 0;
00090 }
00091 LRESULT CHtmlFrame::OnShowTabContextMenu(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM lParam, BOOL& bHandled)
00092 {
00093     bHandled = TRUE;
00094 
00095     POINT ptPopup = {GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)};
00096 
00097     // Build up the menu to show
00098     CMenu mnuContext;
00099 
00100     // Load from resource
00101     //mnuContext.LoadMenu(IDR_CONTEXT);
00102 
00103     // or build dynamically
00104     // (being sure to enable/disable menu items as appropriate,
00105     // and giving the appropriate IDs)
00106     if(mnuContext.CreatePopupMenu()) {
00107         int cchWindowText = GetWindowTextLength();
00108         CString sWindowText;
00109         GetWindowText(sWindowText.GetBuffer(cchWindowText+1), cchWindowText+1);
00110         sWindowText.ReleaseBuffer();
00111 
00112         CString sSave(_T("&Save '"));
00113         sSave += sWindowText;
00114         sSave += _T("'");
00115 
00116         mnuContext.AppendMenu((MF_ENABLED | MF_STRING), ID_FILE_SAVE, sSave);
00117         mnuContext.AppendMenu((MF_ENABLED | MF_STRING), ID_FILE_CLOSE, _T("&Close\tCtrl+F4"));
00118         mnuContext.AppendMenu(MF_SEPARATOR);
00119 
00120         if(m_pCmdBar != NULL) {
00121             // NOTE: The CommandBarCtrl in our case is the mainframe's, so the commands
00122             //  would actually go to the main frame if we don't specify TPM_RETURNCMD.
00123             //  In the main frame's message map, if we don't specify
00124             //  CHAIN_MDI_CHILD_COMMANDS, we are not going to see those command
00125             //  messages. We have 2 choices here - either specify TPM_RETURNCMD,
00126             //  then send/post the message to our window, or don't specify
00127             //  TPM_RETURNCMD, and be sure to have CHAIN_MDI_CHILD_COMMANDS
00128             //  in the main frame's message map.
00129 
00130             //m_pCmdBar->TrackPopupMenu(mnuContext, TPM_LEFTALIGN | TPM_RIGHTBUTTON | TPM_TOPALIGN | TPM_VERTICAL,
00131             //  ptPopup.x, ptPopup.y);
00132 
00133             DWORD nSelection = m_pCmdBar->TrackPopupMenu(mnuContext, TPM_LEFTALIGN | TPM_RIGHTBUTTON | TPM_TOPALIGN | TPM_VERTICAL | TPM_RETURNCMD,
00134                 ptPopup.x, ptPopup.y);
00135             if(nSelection != 0)
00136                 PostMessage(WM_COMMAND, MAKEWPARAM(nSelection, 0));
00137         } else {
00138             mnuContext.TrackPopupMenuEx(TPM_LEFTALIGN | TPM_RIGHTBUTTON | TPM_TOPALIGN | TPM_VERTICAL,
00139                 ptPopup.x, ptPopup.y, m_hWnd, NULL);
00140         }
00141     }
00142 
00143     return 0;
00144 }
00145 LRESULT CHtmlFrame::OnFileSave(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
00146 {
00147     MessageBox(_T("OnFileSave"));
00148     return 0;
00149 }
00150 LRESULT CHtmlFrame::OnFileClose(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
00151 {
00152     PostMessage(WM_SYSCOMMAND, SC_CLOSE, 0L);
00153     return 0;
00154 }
00155 
00157 
00158 void CALLBACK CHtmlFrame::OnTitleChange(BSTR sTitle)
00159 {
00160     USES_CONVERSION;
00161     baseClass::SetTitle(OLE2CT(sTitle));
00162 }
00163 
00164 void CALLBACK CHtmlFrame::OnNavigateComplete2(IDispatch* pDisp, VARIANT* vtURL)
00165 {
00166     HRESULT hr = S_OK;
00167     CComQIPtr<IWebBrowser2> pBrowser(pDisp);
00168     if(pBrowser) {
00169         //CComPtr<IHTMLDocument> pDocument;
00170         CComPtr<IDispatch> pDocument;
00171         hr = pBrowser->get_Document(&pDocument);
00172 
00173         CComQIPtr<IHTMLDocument2> pHtmlDocument(pDocument);
00174         if(pHtmlDocument) {
00175             CComPtr<IHTMLLocation> pHtmlLocation;
00176             pHtmlDocument->get_location(&pHtmlLocation);
00177             if(pHtmlLocation) {
00178                 CComBSTR sHref;
00179                 pHtmlLocation->get_href(&sHref);
00180                 if(sHref.Length() > 0) {
00181                     USES_CONVERSION;
00182                     baseClass::SetTabToolTip(OLE2CT(sHref));
00183                 }
00184             }
00185         }
00186     }
00187 }
00188 
00189 void CALLBACK CHtmlFrame::OnDocumentComplete(IDispatch* pDisp, VARIANT* vtURL)
00190 {
00191     HRESULT hr = S_OK;
00192     CComQIPtr<IWebBrowser2> pBrowser(pDisp);
00193     if(pBrowser) {
00194         //CComPtr<IHTMLDocument> pDocument;
00195         CComPtr<IDispatch> pDocument;
00196         hr = pBrowser->get_Document(&pDocument);
00197 
00198         CComQIPtr<IPersistStreamInit> pPersistStreamInit(pDocument);
00199         if(pPersistStreamInit) {
00200             ULARGE_INTEGER cbSize = {0};
00201             pPersistStreamInit->GetSizeMax(&cbSize);
00202 
00203             HGLOBAL hGlobal = ::GlobalAlloc(GHND, (DWORD)cbSize.QuadPart);
00204 
00205             if(hGlobal != NULL) {
00206                 CComPtr<IStream> pStream;
00207                 hr = ::CreateStreamOnHGlobal(hGlobal, FALSE, &pStream);
00208                 if(pStream) {
00209                     hr = pPersistStreamInit->Save(pStream, TRUE);
00210 
00211                     // TODO: Figure out the character encoding,
00212                     //  and translate to LPTSTR
00213                     LPVOID sText = ::GlobalLock(hGlobal);
00214                     DWORD cbText = ::GlobalSize(hGlobal);
00215 
00216 //                  m_pHtmlSourceView->SetWindowText((LPTSTR)sText);
00217 
00218                     ::GlobalUnlock(hGlobal);
00219                 }
00220 
00221                 ::GlobalFree(hGlobal);
00222             }
00223         }
00224     }
00225 }

Generated on Wed Apr 16 19:12:22 2003 for QuestDesigner by doxygen1.2.18