Back to index

lightning-sunbird  0.9+nobinonly
BrowserFrm.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: Mozilla-sample-code 1.0
00004  *
00005  * Copyright (c) 2002 Netscape Communications Corporation and
00006  * other contributors
00007  *
00008  * Permission is hereby granted, free of charge, to any person obtaining a
00009  * copy of this Mozilla sample software and associated documentation files
00010  * (the "Software"), to deal in the Software without restriction, including
00011  * without limitation the rights to use, copy, modify, merge, publish,
00012  * distribute, sublicense, and/or sell copies of the Software, and to permit
00013  * persons to whom the Software is furnished to do so, subject to the
00014  * following conditions:
00015  *
00016  * The above copyright notice and this permission notice shall be included
00017  * in all copies or substantial portions of the Software.
00018  *
00019  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00020  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00021  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
00022  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00023  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
00024  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
00025  * DEALINGS IN THE SOFTWARE.
00026  *
00027  * Contributor(s):
00028  *   Chak Nanga <chak@netscape.com>
00029  *
00030  * ***** END LICENSE BLOCK ***** */
00031 
00032 // BrowserFrm.h : interface of the CBrowserFrame class
00033 //
00035 
00036 #ifndef _IBROWSERFRM_H
00037 #define _IBROWSERFRM_H
00038 
00039 #if _MSC_VER > 1000
00040 #pragma once
00041 #endif // _MSC_VER > 1000
00042 
00043 #include "BrowserView.h"
00044 #include "BrowserToolTip.h"
00045 #include "IBrowserFrameGlue.h"
00046 #include "MostRecentUrls.h"
00047 
00048 // A simple UrlBar class...
00049 class CUrlBar : public CComboBoxEx
00050 {
00051 public:
00052     inline void GetEnteredURL(CString& url) {
00053         GetEditCtrl()->GetWindowText(url);
00054     }
00055     inline void GetSelectedURL(CString& url) {
00056         GetLBText(GetCurSel(), url);
00057     }
00058     inline void SetCurrentURL(LPCTSTR pUrl) {
00059         SetWindowText(pUrl);
00060     }
00061     inline void AddURLToList(CString& url, bool bAddToMRUList = true) {
00062         USES_CONVERSION;
00063         COMBOBOXEXITEM ci;
00064         ci.mask = CBEIF_TEXT; ci.iItem = -1;
00065         ci.pszText = const_cast<TCHAR *>((LPCTSTR)url);
00066         InsertItem(&ci);
00067 
00068         if(bAddToMRUList)
00069             m_MRUList.AddURL(T2CA(url));
00070     }
00071     inline void LoadMRUList() {
00072         for (int i=0;i<m_MRUList.GetNumURLs();i++) 
00073         {
00074             USES_CONVERSION;
00075             CString urlStr(A2CT(m_MRUList.GetURL(i)));
00076             AddURLToList(urlStr, false); 
00077         }
00078     }
00079     inline BOOL EditCtrlHasFocus() {
00080         return (GetEditCtrl()->m_hWnd == CWnd::GetFocus()->m_hWnd);
00081     }
00082     inline BOOL EditCtrlHasSelection() {
00083         int nStartChar = 0, nEndChar = 0;
00084         if(EditCtrlHasFocus())
00085             GetEditCtrl()->GetSel(nStartChar, nEndChar);
00086         return (nEndChar > nStartChar) ? TRUE : FALSE;
00087     }
00088     inline BOOL CanCutToClipboard() {
00089         return EditCtrlHasSelection();
00090     }
00091     inline void CutToClipboard() {
00092         GetEditCtrl()->Cut();
00093     }
00094     inline BOOL CanCopyToClipboard() {
00095         return EditCtrlHasSelection();
00096     }
00097     inline void CopyToClipboard() {
00098         GetEditCtrl()->Copy();
00099     }
00100     inline BOOL CanPasteFromClipboard() {
00101         return EditCtrlHasFocus();
00102     }
00103     inline void PasteFromClipboard() {
00104         GetEditCtrl()->Paste();
00105     }
00106     inline BOOL CanUndoEditOp() {
00107         return EditCtrlHasFocus() ? GetEditCtrl()->CanUndo() : FALSE;
00108     }
00109     inline void UndoEditOp() {        
00110         if(EditCtrlHasFocus())
00111             GetEditCtrl()->Undo();
00112     }
00113 
00114 protected:
00115       CMostRecentUrls m_MRUList;
00116 };
00117 
00118 // CMyStatusBar class
00119 class CMyStatusBar : public CStatusBar
00120 {
00121 public:
00122     CMyStatusBar();
00123     virtual ~CMyStatusBar();
00124 
00125 protected:
00126     afx_msg void OnLButtonDown(UINT nFlags, CPoint point);
00127 
00128     DECLARE_MESSAGE_MAP()
00129 };
00130 
00131 class CBrowserFrame : public CFrameWnd
00132 {    
00133 public:
00134     CBrowserFrame();
00135     CBrowserFrame(PRUint32 chromeMask);
00136 
00137 protected: 
00138     DECLARE_DYNAMIC(CBrowserFrame)
00139 
00140 public:
00141     inline CBrowserImpl *GetBrowserImpl() { return m_wndBrowserView.mpBrowserImpl; }
00142 
00143     CToolBar    m_wndToolBar;
00144     CMyStatusBar  m_wndStatusBar;
00145     CProgressCtrl m_wndProgressBar;
00146     CUrlBar m_wndUrlBar;
00147     CReBar m_wndReBar;
00148     CBrowserToolTip m_wndTooltip;
00149 
00150     // The view inside which the embedded browser will
00151     // be displayed in
00152     CBrowserView    m_wndBrowserView;
00153 
00154     void UpdateSecurityStatus(PRInt32 aState);
00155     void ShowSecurityInfo();
00156 
00157     // Wrapper functions for UrlBar clipboard operations
00158     inline BOOL CanCutUrlBarSelection() { return m_wndUrlBar.CanCutToClipboard(); }
00159     inline void CutUrlBarSelToClipboard() { m_wndUrlBar.CutToClipboard(); }
00160     inline BOOL CanCopyUrlBarSelection() { return m_wndUrlBar.CanCopyToClipboard(); }
00161     inline void CopyUrlBarSelToClipboard() { m_wndUrlBar.CopyToClipboard(); }
00162     inline BOOL CanPasteToUrlBar() { return m_wndUrlBar.CanPasteFromClipboard(); }
00163     inline void PasteFromClipboardToUrlBar() { m_wndUrlBar.PasteFromClipboard(); }
00164     inline BOOL CanUndoUrlBarEditOp() { return m_wndUrlBar.CanUndoEditOp(); }
00165     inline void UndoUrlBarEditOp() { m_wndUrlBar.UndoEditOp(); }
00166 
00167     // This specifies what UI elements this frame will sport
00168     // w.r.t. toolbar, statusbar, urlbar etc.
00169     PRUint32 m_chromeMask;
00170 
00171 protected:
00172     //
00173     // This nested class implements the IBrowserFramGlue interface
00174     // The Gecko embedding interfaces call on this interface
00175     // to update the status bars etc.
00176     //
00177     class BrowserFrameGlueObj : public IBrowserFrameGlue 
00178     {
00179         //
00180         // NS_DECL_BROWSERFRAMEGLUE below is a macro which expands
00181         // to the function prototypes of methods in IBrowserFrameGlue
00182         // Take a look at IBrowserFrameGlue.h for this macro define
00183         //
00184 
00185         NS_DECL_BROWSERFRAMEGLUE
00186 
00187     } m_xBrowserFrameGlueObj;
00188     friend class BrowserFrameGlueObj;
00189 
00190 public:
00191     void SetupFrameChrome();
00192     void SetEditable(BOOL isEditor) { mIsEditor = isEditor; }
00193     BOOL GetEditable() { return mIsEditor; }
00194 
00195 // Overrides
00196     // ClassWizard generated virtual function overrides
00197     //{{AFX_VIRTUAL(CBrowserFrame)
00198     virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
00199     virtual BOOL OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo);
00200     //}}AFX_VIRTUAL
00201 
00202 // Implementation
00203 public:
00204     virtual ~CBrowserFrame();
00205 #ifdef _DEBUG
00206     virtual void AssertValid() const;
00207     virtual void Dump(CDumpContext& dc) const;
00208 #endif
00209 
00210 // Generated message map functions
00211 protected:
00212     //{{AFX_MSG(CBrowserFrame)
00213     afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
00214     afx_msg void OnSetFocus(CWnd *pOldWnd);
00215     afx_msg void OnSize(UINT nType, int cx, int cy);
00216     afx_msg void OnClose();
00217     afx_msg void OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized);
00218     //}}AFX_MSG
00219     DECLARE_MESSAGE_MAP()
00220 
00221 private:
00222     BOOL mIsEditor;
00223 };
00224 
00226 
00227 //{{AFX_INSERT_LOCATION}}
00228 // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
00229 
00230 #endif //_IBROWSERFRM_H