Follow-on fix for bug 457825. Use sheet principal for agent and user sheets. r=dbaron...
[wine-gecko.git] / embedding / qa / testembed / BrowserFrm.cpp
blobb72b9d959e72056e7a98b6f051121935e7780794
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
23 * Chak Nanga <chak@netscape.com>
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
39 // File Overview....
41 // The typical MFC View, toolbar, statusbar creation done
42 // in CBrowserFrame::OnCreate()
44 // Code to update the Status/Tool bars in response to the
45 // Web page loading progress(called from methods in CBrowserImpl)
47 // SetupFrameChrome() determines what, if any, UI elements this Frame
48 // will sport based on the current "chromeMask"
50 // Also take a look at OnClose() which gets used when you close a browser
51 // window. This needs to be overrided mainly to handle supporting multiple
52 // browser frame windows via the "New Browser Window" menu item
53 // Without this being overridden the MFC framework handles the OnClose and
54 // shutsdown the complete application when a frame window is closed.
55 // In our case, we want the app to shutdown when the File/Exit menu is chosen
57 // Another key functionality this object implements is the IBrowserFrameGlue
58 // interface - that's the interface the Gecko embedding interfaces call
59 // upong to update the status bar etc.
60 // (Take a look at IBrowserFrameGlue.h for the interface definition and
61 // the BrowserFrm.h to see how we implement this interface - as a nested
62 // class)
63 // We pass this Glue object pointer to the CBrowserView object via the
64 // SetBrowserFrameGlue() method. The CBrowserView passes this on to the
65 // embedding interface implementaion
67 // Please note the use of the macro METHOD_PROLOGUE in the implementation
68 // of the nested BrowserFrameGlue object. Essentially what this macro does
69 // is to get you access to the outer (or the object which is containing the
70 // nested object) object via the pThis pointer.
71 // Refer to the AFXDISP.H file in VC++ include dirs
73 // Next suggested file to look at : BrowserView.cpp
75 #include "stdafx.h"
76 #include "TestEmbed.h"
77 #include "BrowserFrm.h"
79 #ifdef _DEBUG
80 #define new DEBUG_NEW
81 #undef THIS_FILE
82 static char THIS_FILE[] = __FILE__;
83 #endif
85 /////////////////////////////////////////////////////////////////////////////
86 // CBrowserFrame
88 IMPLEMENT_DYNAMIC(CBrowserFrame, CFrameWnd)
90 BEGIN_MESSAGE_MAP(CBrowserFrame, CFrameWnd)
91 //{{AFX_MSG_MAP(CBrowserFrame)
92 ON_WM_CREATE()
93 ON_WM_SETFOCUS()
94 ON_WM_SIZE()
95 ON_WM_CLOSE()
96 ON_WM_ACTIVATE()
97 //}}AFX_MSG_MAP
98 END_MESSAGE_MAP()
100 static UINT indicators[] =
102 ID_SEPARATOR, // For the Status line
103 ID_SEPARATOR, // For the Progress Bar
106 /////////////////////////////////////////////////////////////////////////////
107 // CBrowserFrame construction/destruction
109 CBrowserFrame::CBrowserFrame(PRUint32 chromeMask)
111 // Save the chromeMask off. It'll be used
112 // later to determine whether this browser frame
113 // will have menubar, toolbar, statusbar etc.
115 m_chromeMask = chromeMask;
118 CBrowserFrame::~CBrowserFrame()
122 void CBrowserFrame::OnClose()
124 CTestEmbedApp *pApp = (CTestEmbedApp *)AfxGetApp();
125 pApp->RemoveFrameFromList(this);
127 DestroyWindow();
130 // This is where the UrlBar, ToolBar, StatusBar, ProgressBar
131 // get created
133 int CBrowserFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
135 if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
136 return -1;
138 // Pass "this" to the View for later callbacks
139 // and/or access to any public data members, if needed
141 m_wndBrowserView.SetBrowserFrame(this);
143 // Pass on the BrowserFrameGlue also to the View which
144 // it will use during the Init() process after creation
145 // of the BrowserImpl obj. Essentially, the View object
146 // hooks up the Embedded browser's callbacks to the BrowserFrame
147 // via this BrowserFrameGlue object
148 m_wndBrowserView.SetBrowserFrameGlue((PBROWSERFRAMEGLUE)&m_xBrowserFrameGlueObj);
150 // create a view to occupy the client area of the frame
151 // This will be the view in which the embedded browser will
152 // be displayed in
154 if (!m_wndBrowserView.Create(NULL, NULL, AFX_WS_DEFAULT_VIEW,
155 CRect(0, 0, 0, 0), this, AFX_IDW_PANE_FIRST, NULL))
157 TRACE0("Failed to create view window\n");
158 return -1;
161 // create the URL bar (essentially a ComboBoxEx object)
162 if (!m_wndUrlBar.Create(CBS_DROPDOWN | WS_CHILD, CRect(0, 0, 200, 150), this, ID_URL_BAR))
164 TRACE0("Failed to create URL Bar\n");
165 return -1; // fail to create
168 // Load the Most Recently Used(MRU) Urls into the UrlBar
169 m_wndUrlBar.LoadMRUList();
171 // Create the toolbar with Back, Fwd, Stop, etc. buttons..
172 if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
173 | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
174 !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
176 TRACE0("Failed to create toolbar\n");
177 return -1; // fail to create
180 // Create a ReBar window to which the toolbar and UrlBar
181 // will be added
182 if (!m_wndReBar.Create(this))
184 TRACE0("Failed to create ReBar\n");
185 return -1; // fail to create
188 //Add the ToolBar and UrlBar windows to the rebar
189 m_wndReBar.AddBar(&m_wndToolBar);
190 m_wndReBar.AddBar(&m_wndUrlBar, "Enter URL:");
192 // Create the status bar with two panes - one pane for actual status
193 // text msgs. and the other for the progress control
194 if (!m_wndStatusBar.Create(this) ||
195 !m_wndStatusBar.SetIndicators(indicators,
196 sizeof(indicators)/sizeof(UINT)))
198 TRACE0("Failed to create status bar\n");
199 return -1; // fail to create
202 // Create the progress bar as a child of the status bar.
203 // Note that the ItemRect which we'll get at this stage
204 // is bogus since the status bar panes are not fully
205 // positioned yet i.e. we'll be passing in an invalid rect
206 // to the Create function below
207 // The actual positioning of the progress bar will be done
208 // in response to OnSize()
209 RECT rc;
210 m_wndStatusBar.GetItemRect (1, &rc);
211 if (!m_wndProgressBar.Create(WS_CHILD|WS_VISIBLE|PBS_SMOOTH, rc, &m_wndStatusBar, ID_PROG_BAR))
213 TRACE0("Failed to create progress bar\n");
214 return -1; // fail to create
217 // The third pane(i.e. at index 2) of the status bar will have
218 // the security lock icon displayed in it. Set up it's size(16)
219 // and style(no border)so that the padlock icons can be properly drawn
220 // m_wndStatusBar.SetPaneInfo(2, -1, SBPS_NORMAL|SBPS_NOBORDERS, 16);
222 // Based on the "chromeMask" we were supplied during construction
223 // hide any requested UI elements - statusbar, menubar etc...
224 // Note that the window styles (WM_RESIZE etc) are set inside
225 // of PreCreateWindow()
227 SetupFrameChrome();
229 return 0;
232 void CBrowserFrame::SetupFrameChrome()
234 if(m_chromeMask == nsIWebBrowserChrome::CHROME_ALL)
235 return;
237 if(! (m_chromeMask & nsIWebBrowserChrome::CHROME_MENUBAR) )
238 SetMenu(NULL); // Hide the MenuBar
240 if(! (m_chromeMask & nsIWebBrowserChrome::CHROME_TOOLBAR) )
241 m_wndReBar.ShowWindow(SW_HIDE); // Hide the ToolBar
243 if(! (m_chromeMask & nsIWebBrowserChrome::CHROME_STATUSBAR) )
244 m_wndStatusBar.ShowWindow(SW_HIDE); // Hide the StatusBar
247 BOOL CBrowserFrame::PreCreateWindow(CREATESTRUCT& cs)
249 if( !CFrameWnd::PreCreateWindow(cs) )
250 return FALSE;
252 cs.dwExStyle &= ~WS_EX_CLIENTEDGE;
254 // Change window style based on the chromeMask
256 if(! (m_chromeMask & nsIWebBrowserChrome::CHROME_TITLEBAR) )
257 cs.style &= ~WS_CAPTION; // No caption
259 if(! (m_chromeMask & nsIWebBrowserChrome::CHROME_WINDOW_RESIZE) )
261 // Can't resize this window
262 cs.style &= ~WS_SIZEBOX;
263 cs.style &= ~WS_THICKFRAME;
264 cs.style &= ~WS_MINIMIZEBOX;
265 cs.style &= ~WS_MAXIMIZEBOX;
268 cs.lpszClass = AfxRegisterWndClass(0);
270 return TRUE;
273 /////////////////////////////////////////////////////////////////////////////
274 // CBrowserFrame message handlers
275 void CBrowserFrame::OnSetFocus(CWnd* pOldWnd)
277 // forward focus to the view window
278 m_wndBrowserView.SetFocus();
281 BOOL CBrowserFrame::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo)
283 // let the view have first crack at the command
284 if (m_wndBrowserView.OnCmdMsg(nID, nCode, pExtra, pHandlerInfo))
285 return TRUE;
287 // otherwise, do default handling
288 return CFrameWnd::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
291 // Needed to properly position/resize the progress bar
293 void CBrowserFrame::OnSize(UINT nType, int cx, int cy)
295 CFrameWnd::OnSize(nType, cx, cy);
297 // Get the ItemRect of the status bar's Pane 1
298 // That's where the progress bar will be located
299 RECT rc;
300 m_wndStatusBar.GetItemRect(1, &rc);
302 // Move the progress bar into it's correct location
304 m_wndProgressBar.MoveWindow(&rc);
307 #ifdef _DEBUG
308 void CBrowserFrame::AssertValid() const
310 CFrameWnd::AssertValid();
313 void CBrowserFrame::Dump(CDumpContext& dc) const
315 CFrameWnd::Dump(dc);
318 #endif //_DEBUG
321 void CBrowserFrame::OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized)
323 CFrameWnd::OnActivate(nState, pWndOther, bMinimized);
325 m_wndBrowserView.Activate(nState, pWndOther, bMinimized);