GME  13
HtmlCtrl.cpp
Go to the documentation of this file.
00001 // HtmlCtrl.cpp : implementation file
00002 //
00003 
00004 #include "stdafx.h"
00005 #include "console.h"
00006 #include "HtmlCtrl.h"
00007 #include "ConsoleCtl.h"
00008 
00009 
00010 #ifdef _DEBUG
00011 #define new DEBUG_NEW
00012 #undef THIS_FILE
00013 static char THIS_FILE[] = __FILE__;
00014 #endif
00015 
00017 // CHtmlCtrl
00018 
00019 IMPLEMENT_DYNAMIC(CHtmlCtrl, CHtmlView)
00020 
00021 
00022 CHtmlCtrl::CHtmlCtrl()
00023 {
00024         //{{AFX_DATA_INIT(CHtmlCtrl)
00025                 // NOTE: the ClassWizard will add member initialization here
00026         //}}AFX_DATA_INIT
00027 }
00028 
00029 
00030 void CHtmlCtrl::DoDataExchange(CDataExchange* pDX)
00031 {
00032         CHtmlView::DoDataExchange(pDX);
00033         //{{AFX_DATA_MAP(CHtmlCtrl)
00034                 // NOTE: the ClassWizard will add DDX and DDV calls here
00035         //}}AFX_DATA_MAP
00036 }
00037 
00038 
00039 BEGIN_MESSAGE_MAP(CHtmlCtrl, CHtmlView)
00040         //{{AFX_MSG_MAP(CHtmlCtrl)
00041         ON_WM_DESTROY()
00042         ON_WM_MOUSEACTIVATE()
00043         //}}AFX_MSG_MAP
00044 END_MESSAGE_MAP()
00045 
00047 // CHtmlCtrl diagnostics
00048 
00049 #ifdef _DEBUG
00050 //
00051 // MFC manages/stores states in statically linked (small) stubs
00052 // Also, it updates the current module state for window message dispatch
00053 // In this case, message is sent to the hosted IE window (so the module state won't be changed to our DLL), 
00054 // which calls CHtmlView through COM. For some reason CHtmlView does not update module state when called trhough COM, 
00055 // and eventually it calls MFC functions (only this one in our case) which will not find the (correct) module state
00056 //
00057 void CHtmlCtrl::AssertValid() const
00058 {
00059         AFX_MANAGE_STATE(AfxGetStaticModuleState( ));
00060         CHtmlView::AssertValid();
00061 }
00062 
00063 void CHtmlCtrl::Dump(CDumpContext& dc) const
00064 {
00065         CHtmlView::Dump(dc);
00066 }
00067 #endif //_DEBUG
00068 
00070 // CHtmlCtrl message handlers
00071 
00073 // Create control in same position as an existing static control with
00074 // the same ID (could be any kind of control, really)
00075 //
00076 BOOL CHtmlCtrl::CreateFromStatic(UINT nID, CWnd* pParent)
00077 {
00078         CStatic wndStatic;
00079         if (!wndStatic.SubclassDlgItem(nID, pParent))
00080                 return FALSE;
00081 
00082         // Get static control rect, convert to parent's client coords.
00083         CRect rc;
00084         wndStatic.GetWindowRect(&rc);
00085         pParent->ScreenToClient(&rc);
00086         wndStatic.DestroyWindow();
00087 
00088         // create HTML control (CHtmlView)
00089         return Create(NULL,                  // class name
00090                 NULL,                             // title
00091                 (WS_CHILD | WS_VISIBLE ),         // style
00092                 rc,                               // rectangle
00093                 pParent,                          // parent
00094                 nID,                              // control ID
00095                 NULL);                            // frame/doc context not used
00096 }
00097 
00099 // Override to avoid CView stuff that assumes a frame.
00100 //
00101 void CHtmlCtrl::OnDestroy()
00102 {
00103         // This is probably unecessary since ~CHtmlView does it, but
00104         // safer to mimic CHtmlView::OnDestroy.
00105         /*if (m_pBrowserApp) {
00106                 m_pBrowserApp->Release();
00107                 m_pBrowserApp = NULL;
00108         }*/ //commented for vc7, Release its not a public member of IWebBrowser2
00109         CWnd::OnDestroy(); // bypass CView doc/frame stuff
00110 }
00111 
00113 // Override to avoid CView stuff that assumes a frame.
00114 //
00115 int CHtmlCtrl::OnMouseActivate(CWnd* pDesktopWnd, UINT nHitTest, UINT msg)
00116 {
00117         // bypass CView doc/frame stuff
00118         return CWnd::OnMouseActivate(pDesktopWnd, nHitTest, msg);
00119 }
00120 
00122 // Override navigation handler to pass to "app:" links to virtual handler.
00123 // Cancels the navigation in the browser, since app: is a pseudo-protocol.
00124 //
00125 void CHtmlCtrl::OnBeforeNavigate2( LPCTSTR lpszURL,
00126         DWORD nFlags,
00127         LPCTSTR lpszTargetFrameName,
00128         CByteArray& baPostedData,
00129         LPCTSTR lpszHeaders,
00130         BOOL* pbCancel )
00131 {
00132         const TCHAR MGA_PROTOCOL[] = _T("mga:");
00133         int len = _tcslen(MGA_PROTOCOL);
00134         if (_tcsnicmp(lpszURL, MGA_PROTOCOL, len)==0) {
00135                 OnMgaURL(lpszURL + len);
00136                 *pbCancel = TRUE;
00137         }
00138 }
00139 
00140 void CHtmlCtrl::OnMgaURL(LPCTSTR lpszWhere)
00141 {
00142         CWnd *wnd = GetParent();
00143         if (wnd->IsKindOf(RUNTIME_CLASS(CConsoleCtrl))) {
00144                 CConsoleCtrl *ctrl = STATIC_DOWNCAST(CConsoleCtrl, wnd);
00145                 ctrl->FireClickMGAID(lpszWhere);
00146         }
00147 }
00148 
00149 void CHtmlCtrl::OnDocumentComplete(LPCTSTR lpszURL)
00150 {
00151         CWnd *wnd = GetParent();
00152         if (wnd->IsKindOf(RUNTIME_CLASS(CConsoleCtrl))) {
00153                 CConsoleCtrl *ctrl = STATIC_DOWNCAST(CConsoleCtrl, wnd);
00154                 ctrl->AddGMEToScript();
00155         }
00156 }