Fix for #123570 - Rearrange the editor embedding code in MfcEmbed

r=adamlock, sr=alecf
This commit is contained in:
chak%netscape.com 2002-02-06 05:13:44 +00:00
parent 5e1b453e92
commit 0a3f63aaec
14 changed files with 512 additions and 302 deletions

View File

@ -76,6 +76,7 @@
#include "stdafx.h"
#include "MfcEmbed.h"
#include "BrowserFrm.h"
#include "EditorFrm.h"
#include "BrowserImpl.h"
#ifdef _DEBUG
@ -84,13 +85,6 @@
static char THIS_FILE[] = __FILE__;
#endif
//prototypes
nsresult GetStateCommandParams(nsICommandParams **aParams);
#define ABOUT_BLANK "about:blank"
/////////////////////////////////////////////////////////////////////////////
// CBrowserFrame
@ -103,13 +97,6 @@ BEGIN_MESSAGE_MAP(CBrowserFrame, CFrameWnd)
ON_WM_SIZE()
ON_WM_CLOSE()
ON_WM_ACTIVATE()
ON_COMMAND(ID_NEW_EDITWINDOW, OnNewEditor)
ON_COMMAND(ID_BOLD, OnBold)
ON_UPDATE_COMMAND_UI(ID_BOLD, OnUpdateBold)
ON_COMMAND(ID_ITALICS, OnItalics)
ON_UPDATE_COMMAND_UI(ID_ITALICS, OnUpdateItalics)
ON_COMMAND(ID_UNDERLINE, OnUnderline)
ON_UPDATE_COMMAND_UI(ID_UNDERLINE, OnUpdateUnderline)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
@ -123,6 +110,11 @@ static UINT indicators[] =
/////////////////////////////////////////////////////////////////////////////
// CBrowserFrame construction/destruction
CBrowserFrame::CBrowserFrame()
{
mIsEditor = FALSE;
}
CBrowserFrame::CBrowserFrame(PRUint32 chromeMask)
{
// Save the chromeMask off. It'll be used
@ -130,8 +122,7 @@ CBrowserFrame::CBrowserFrame(PRUint32 chromeMask)
// will have menubar, toolbar, statusbar etc.
m_chromeMask = chromeMask;
mIsEditor = FALSE;
NS_ADDREF(&mToolBarObserver);//make sure no one releases this
mIsEditor = FALSE;
}
CBrowserFrame::~CBrowserFrame()
@ -187,11 +178,11 @@ int CBrowserFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
// Load the Most Recently Used(MRU) Urls into the UrlBar
m_wndUrlBar.LoadMRUList();
UINT resID = IDR_MAINFRAME;
if (mIsEditor)
resID = IDR_EDITOR;
UINT resID = mIsEditor ? IDR_EDITOR : IDR_MAINFRAME;
// Create the toolbar with Back, Fwd, Stop, etc. buttons..
// Create the toolbar with Back, Fwd, Stop, etc. buttons..
// or
// Create a toolbar with the Editor toolbar buttons - Bold, Italic etc.
if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
| CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
!m_wndToolBar.LoadToolBar(resID))
@ -200,9 +191,7 @@ int CBrowserFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
return -1; // fail to create
}
mToolBarObserver.SetFrame(this,ID_TOOLBAR_UPDATE,100); //update if 100 ticks goes by and no more changes
// Create a ReBar window to which the toolbar and UrlBar
// Create a ReBar window to which the toolbar and UrlBar
// will be added
if (!m_wndReBar.Create(this))
{
@ -212,8 +201,9 @@ int CBrowserFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
//Add the ToolBar and UrlBar windows to the rebar
m_wndReBar.AddBar(&m_wndToolBar);
if (!mIsEditor)
m_wndReBar.AddBar(&m_wndUrlBar, "Enter URL:");
m_wndReBar.AddBar(&m_wndUrlBar, "Enter URL:");
// Create the status bar with two panes - one pane for actual status
// text msgs. and the other for the progress control
@ -415,98 +405,3 @@ void CMyStatusBar::OnLButtonDown(UINT nFlags, CPoint point)
CStatusBar::OnLButtonDown(nFlags, point);
}
void CBrowserFrame::OnNewEditor()
{
// TODO: Add your command handler code here
// TODO: Add your command handler code here
// TODO: Add your command handler code here
// TODO: Add your command handler code here
CMfcEmbedApp *pApp = (CMfcEmbedApp *)AfxGetApp();
CBrowserFrame *pEditorFrame = pApp->CreateNewBrowserFrame(nsIWebBrowserChrome::CHROME_ALL,
-1, -1, -1, -1,
PR_TRUE,PR_TRUE);
if (pEditorFrame)
{
CString tUrl;
m_wndUrlBar.GetEnteredURL(tUrl);
pEditorFrame->m_wndBrowserView.OpenURL(ABOUT_BLANK);
CBrowserImpl *impl = pEditorFrame->GetBrowserImpl();
if (impl)
{
((CEditorImpl *)impl)->AddEditorObservers(&mToolBarObserver);
((CEditorImpl *)impl)->MakeEditable();
}
}
}
/*
"bold"
state_all //setter and getter
state_begin //getter
state_end //getter
state_mixed //getter
*/
#define COMMAND_NAME NS_ConvertASCIItoUCS2("cmd_name")
#define STATE_ALL NS_ConvertASCIItoUCS2("state_all")
#define BOLD_COMMAND NS_ConvertASCIItoUCS2("cmd_bold")
void CBrowserFrame::OnBold()
{
// TODO: Add your command handler code here
nsresult rv;
nsCOMPtr<nsICommandParams> params = do_CreateInstance(NS_COMMAND_PARAMS_CONTRACTID,&rv);
if (NS_FAILED(rv) || !params)
return;
params->SetBooleanValue(STATE_ALL,true);
params->SetStringValue(COMMAND_NAME,BOLD_COMMAND);
CEditorImpl *impl = (CEditorImpl *)GetBrowserImpl();
if (impl)
impl->DoCommand(params);
}
void CBrowserFrame::OnUpdateBold(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
nsresult rv;
nsCOMPtr<nsICommandParams> params = do_CreateInstance(NS_COMMAND_PARAMS_CONTRACTID,&rv);
params->SetStringValue(COMMAND_NAME,BOLD_COMMAND);
CEditorImpl *impl = (CEditorImpl *)GetBrowserImpl();
if (impl)
{
rv = impl->GetCommandState(params);
if (NS_SUCCEEDED(rv))
{
//set tri state of button here if we need to
}
}
//just return true for now
pCmdUI->Enable();
}
void CBrowserFrame::OnItalics()
{
// TODO: Add your command handler code here
}
void CBrowserFrame::OnUpdateItalics(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
}
void CBrowserFrame::OnUnderline()
{
// TODO: Add your command handler code here
}
void CBrowserFrame::OnUpdateUnderline(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
}

View File

@ -51,7 +51,6 @@
#include "BrowserView.h"
#include "IBrowserFrameGlue.h"
#include "MostRecentUrls.h"
#include "CCommandObserver.h"
// A simple UrlBar class...
class CUrlBar : public CComboBoxEx
@ -137,6 +136,7 @@ protected:
class CBrowserFrame : public CFrameWnd
{
public:
CBrowserFrame();
CBrowserFrame(PRUint32 chromeMask);
protected:
@ -192,8 +192,8 @@ protected:
public:
void SetupFrameChrome();
void SetEditable(BOOL isEditor){mIsEditor = isEditor;}
BOOL GetEditable(){return mIsEditor;}
void SetEditable(BOOL isEditor) { mIsEditor = isEditor; }
BOOL GetEditable() { return mIsEditor; }
// Overrides
// ClassWizard generated virtual function overrides
@ -218,18 +218,11 @@ protected:
afx_msg void OnSize(UINT nType, int cx, int cy);
afx_msg void OnClose();
afx_msg void OnActivate(UINT nState, CWnd* pWndOther, BOOL bMinimized);
afx_msg void OnNewEditor();
afx_msg void OnBold();
afx_msg void OnUpdateBold(CCmdUI* pCmdUI);
afx_msg void OnItalics();
afx_msg void OnUpdateItalics(CCmdUI* pCmdUI);
afx_msg void OnUnderline();
afx_msg void OnUpdateUnderline(CCmdUI* pCmdUI);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
private:
BOOL mIsEditor;
CCommandObserver mToolBarObserver;
BOOL mIsEditor;
};
/////////////////////////////////////////////////////////////////////////////

View File

@ -81,12 +81,6 @@
#endif
#include "nsIDOMWindow.h"
#include "nsIScriptGlobalObject.h"
#include "nsIDocShell.h"
#include "nsISimpleEnumerator.h"
#include "nsIEditingSession.h"
#include "nsICommandManager.h"
#include "BrowserImpl.h"
CBrowserImpl::CBrowserImpl()
@ -388,120 +382,3 @@ NS_IMETHODIMP CBrowserImpl::SetVisibility(PRBool aVisibility)
return NS_OK;
}
//EDITORIMPL
NS_METHOD
CEditorImpl::MakeEditable()
{
nsresult rv;
nsCOMPtr<nsIDOMWindow> domWindow;
mWebBrowser->GetContentDOMWindow(getter_AddRefs(domWindow));
if (!domWindow)
return NS_ERROR_FAILURE;
nsCOMPtr<nsIScriptGlobalObject> scriptGlobalObject = do_QueryInterface(domWindow);
if (!scriptGlobalObject)
return NS_ERROR_FAILURE;
nsCOMPtr<nsIDocShell> docShell;
rv = scriptGlobalObject->GetDocShell(getter_AddRefs(docShell));
if (NS_FAILED(rv))
return rv;
if (!docShell)
return NS_ERROR_FAILURE;
nsCOMPtr<nsIEditingSession> editingSession = do_GetInterface(docShell);
if (!editingSession)
return NS_ERROR_FAILURE;
rv= editingSession->MakeWindowEditable(domWindow, PR_TRUE);
// this can fail for the root (if it's a frameset), but we still want
// to make children editable
nsCOMPtr<nsISimpleEnumerator> docShellEnumerator;
docShell->GetDocShellEnumerator( nsIDocShellTreeItem::typeContent,
nsIDocShell::ENUMERATE_FORWARDS,
getter_AddRefs(docShellEnumerator));
if (docShellEnumerator)
{
PRBool hasMore;
while (NS_SUCCEEDED(docShellEnumerator->HasMoreElements(&hasMore)) && hasMore)
{
nsCOMPtr<nsISupports> curSupports;
rv = docShellEnumerator->GetNext(getter_AddRefs(curSupports));
if (NS_FAILED(rv)) break;
nsCOMPtr<nsIDocShell> curShell = do_QueryInterface(curSupports, &rv);
if (NS_FAILED(rv)) break;
nsCOMPtr<nsIDOMWindow> childWindow = do_GetInterface(curShell,&rv);
if (childWindow)
editingSession->MakeWindowEditable(childWindow, PR_FALSE);
}
}
return NS_OK;
}
//nsIObserver
NS_IMETHODIMP
CEditorImpl::AddEditorObservers(nsIObserver *aObserver)
{
nsCOMPtr<nsICommandManager> commandManager;
nsresult rv;
commandManager = do_GetInterface(mWebBrowser,&rv);
if (commandManager)
{
nsAutoString tString(NS_LITERAL_STRING("cmd_bold"));
rv = commandManager->AddCommandObserver(aObserver,tString);
tString = NS_LITERAL_STRING("cmd_italic");
rv = commandManager->AddCommandObserver(aObserver,tString);
tString = NS_LITERAL_STRING("cmd_underline");
rv = commandManager->AddCommandObserver(aObserver,tString);
}
return rv;
}
NS_IMETHODIMP
CEditorImpl::DoCommand(nsICommandParams *aCommandParams)
{
nsCOMPtr<nsICommandManager> commandManager;
nsresult rv = NS_ERROR_FAILURE;
commandManager = do_GetInterface(mWebBrowser,&rv);
if (commandManager)
{
rv = commandManager->DoCommand(aCommandParams);
}
return rv;
}
NS_IMETHODIMP
CEditorImpl::IsCommandEnabled(const nsAString &aCommand, PRBool *retval)
{
nsCOMPtr<nsICommandManager> commandManager;
nsresult rv = NS_ERROR_FAILURE;
commandManager = do_GetInterface(mWebBrowser,&rv);
if (commandManager)
{
rv = commandManager->IsCommandEnabled(aCommand,retval);
}
return rv;
}
NS_IMETHODIMP
CEditorImpl::GetCommandState(nsICommandParams *aCommandParams)
{
nsCOMPtr<nsICommandManager> commandManager;
nsresult rv = NS_ERROR_FAILURE;
commandManager = do_GetInterface(mWebBrowser,&rv);
if (commandManager)
{
rv = commandManager->GetCommandState(aCommandParams);
}
return rv;
}

View File

@ -73,16 +73,4 @@ protected:
nsCOMPtr<nsIWebBrowser> mWebBrowser;
};
class CEditorImpl : public CBrowserImpl
{
public:
CEditorImpl(){};
virtual ~CEditorImpl(){};
NS_METHOD MakeEditable();
NS_METHOD AddEditorObservers(nsIObserver *aObserver);
NS_METHOD DoCommand(nsICommandParams *aCommandParams);
NS_METHOD IsCommandEnabled(const nsAString &aCommand, PRBool *retval);
NS_METHOD GetCommandState(nsICommandParams *aCommandParams);
};
#endif //_BROWSERIMPL_H

View File

@ -1,35 +1,76 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Mike Judge <mjudge@netscape.com>
*
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
// ----------------------------------------------------------
// This file is related to the Editor embedding functionality
// ----------------------------------------------------------
#include "stdafx.h"
#include "CCommandObserver.h"
NS_IMPL_ADDREF(CCommandObserver)
NS_IMPL_RELEASE(CCommandObserver)
NS_IMPL_QUERY_INTERFACE1(CCommandObserver, nsIObserver)
CCommandObserver::CCommandObserver()
{
NS_INIT_REFCNT();
mFrame = 0;
NS_INIT_REFCNT();
mFrame = 0;
}
/* void observe (in nsISupports aSubject, in string aTopic, in wstring aData); */
NS_IMETHODIMP
CCommandObserver::Observe(nsISupports *aSubject, const char *aTopic, const PRUnichar *aData)
{
if (!mFrame)
return NS_ERROR_NOT_INITIALIZED;
mFrame->KillTimer(mTimerId);
mFrame->SetTimer(mTimerId,mDelay,0);//reset delay on update.
return NS_OK;
if (!mFrame)
return NS_ERROR_NOT_INITIALIZED;
mFrame->KillTimer(mTimerId);
mFrame->SetTimer(mTimerId,mDelay,0);//reset delay on update.
return NS_OK;
}
void
CCommandObserver::SetFrame(CFrameWnd *frame,UINT timerId,UINT delay) //update if 100 ticks goes by and no more changes
{
mFrame = frame;
mDelay = delay;
mTimerId = timerId;
mFrame = frame;
mDelay = delay;
mTimerId = timerId;
}

View File

@ -1,24 +1,62 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Mike Judge <mjudge@netscape.com>
*
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#pragma once
#include "nsIObserver.h"
class CFrameWnd;
class CCommandObserver : public nsIObserver
{
public:
NS_DECL_ISUPPORTS
CCommandObserver();
~CCommandObserver(){}
NS_DECL_ISUPPORTS
NS_DECL_NSIOBSERVER
//update if 100 ticks goes by and no more changes
void SetFrame(CFrameWnd *frame,UINT timerId,UINT delay);
CCommandObserver();
~CCommandObserver(){}
//NSIOBSERVER
NS_DECL_NSIOBSERVER
//CCommandObserver
void SetFrame(CFrameWnd *frame,UINT timerId,UINT delay); //update if 100 ticks goes by and no more changes
private:
CFrameWnd *mFrame;
UINT mDelay;
UINT mTimerId;
CFrameWnd *mFrame;
UINT mDelay;
UINT mTimerId;
};

View File

@ -0,0 +1,261 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Mike Judge <mjudge@netscape.com>
* Chak Nanga <chak@netscape.com>
*
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "stdafx.h"
#include "MfcEmbed.h"
#include "BrowserFrm.h"
#include "EditorFrm.h"
IMPLEMENT_DYNAMIC(CEditorFrame, CBrowserFrame)
BEGIN_MESSAGE_MAP(CEditorFrame, CBrowserFrame)
//{{AFX_MSG_MAP(CEditorFrame)
ON_COMMAND(ID_BOLD, OnBold)
ON_UPDATE_COMMAND_UI(ID_BOLD, OnUpdateBold)
ON_COMMAND(ID_ITALICS, OnItalics)
ON_UPDATE_COMMAND_UI(ID_ITALICS, OnUpdateItalics)
ON_COMMAND(ID_UNDERLINE, OnUnderline)
ON_UPDATE_COMMAND_UI(ID_UNDERLINE, OnUpdateUnderline)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
CEditorFrame::CEditorFrame(PRUint32 chromeMask)
{
m_chromeMask = chromeMask;
NS_ADDREF(&mToolBarObserver);//make sure no one releases this
}
CEditorFrame::~CEditorFrame()
{
}
BOOL CEditorFrame::InitEditor()
{
mToolBarObserver.SetFrame(this,ID_TOOLBAR_UPDATE,100); //update if 100 ticks goes by and no more changes
AddEditorObservers();
MakeEditable();
return TRUE;
}
/*
"bold"
state_all //setter and getter
state_begin //getter
state_end //getter
state_mixed //getter
*/
#define COMMAND_NAME NS_ConvertASCIItoUCS2("cmd_name")
#define STATE_ALL NS_ConvertASCIItoUCS2("state_all")
#define BOLD_COMMAND NS_ConvertASCIItoUCS2("cmd_bold")
void CEditorFrame::OnBold()
{
nsresult rv;
nsCOMPtr<nsICommandParams> params = do_CreateInstance(NS_COMMAND_PARAMS_CONTRACTID, &rv);
if (NS_FAILED(rv) || !params)
return;
params->SetBooleanValue(STATE_ALL, true);
params->SetStringValue(COMMAND_NAME, BOLD_COMMAND);
DoCommand(params);
}
void CEditorFrame::OnUpdateBold(CCmdUI* pCmdUI)
{
nsresult rv;
nsCOMPtr<nsICommandParams> params = do_CreateInstance(NS_COMMAND_PARAMS_CONTRACTID,&rv);
params->SetStringValue(COMMAND_NAME,BOLD_COMMAND);
rv = GetCommandState(params);
if (NS_SUCCEEDED(rv))
{
//set tri state of button here if we need to
}
//just return true for now
pCmdUI->Enable();
}
void CEditorFrame::OnItalics()
{
// TODO: Add your command handler code here
}
void CEditorFrame::OnUpdateItalics(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
}
void CEditorFrame::OnUnderline()
{
// TODO: Add your command handler code here
}
void CEditorFrame::OnUpdateUnderline(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
}
NS_METHOD
CEditorFrame::AddEditorObservers()
{
nsCOMPtr<nsICommandManager> commandManager;
nsresult rv;
commandManager = do_GetInterface(m_wndBrowserView.mWebBrowser,&rv);
if (commandManager)
{
nsAutoString tString(NS_LITERAL_STRING("cmd_bold"));
rv = commandManager->AddCommandObserver(&mToolBarObserver,tString);
tString = NS_LITERAL_STRING("cmd_italic");
rv = commandManager->AddCommandObserver(&mToolBarObserver,tString);
tString = NS_LITERAL_STRING("cmd_underline");
rv = commandManager->AddCommandObserver(&mToolBarObserver,tString);
}
return rv;
}
NS_METHOD
CEditorFrame::MakeEditable()
{
nsresult rv;
nsCOMPtr<nsIDOMWindow> domWindow;
m_wndBrowserView.mWebBrowser->GetContentDOMWindow(getter_AddRefs(domWindow));
if (!domWindow)
return NS_ERROR_FAILURE;
nsCOMPtr<nsIScriptGlobalObject> scriptGlobalObject = do_QueryInterface(domWindow);
if (!scriptGlobalObject)
return NS_ERROR_FAILURE;
nsCOMPtr<nsIDocShell> docShell;
rv = scriptGlobalObject->GetDocShell(getter_AddRefs(docShell));
if (NS_FAILED(rv))
return rv;
if (!docShell)
return NS_ERROR_FAILURE;
nsCOMPtr<nsIEditingSession> editingSession = do_GetInterface(docShell);
if (!editingSession)
return NS_ERROR_FAILURE;
rv= editingSession->MakeWindowEditable(domWindow, PR_TRUE);
// this can fail for the root (if it's a frameset), but we still want
// to make children editable
nsCOMPtr<nsISimpleEnumerator> docShellEnumerator;
docShell->GetDocShellEnumerator( nsIDocShellTreeItem::typeContent,
nsIDocShell::ENUMERATE_FORWARDS,
getter_AddRefs(docShellEnumerator));
if (docShellEnumerator)
{
PRBool hasMore;
while (NS_SUCCEEDED(docShellEnumerator->HasMoreElements(&hasMore)) && hasMore)
{
nsCOMPtr<nsISupports> curSupports;
rv = docShellEnumerator->GetNext(getter_AddRefs(curSupports));
if (NS_FAILED(rv)) break;
nsCOMPtr<nsIDocShell> curShell = do_QueryInterface(curSupports, &rv);
if (NS_FAILED(rv)) break;
nsCOMPtr<nsIDOMWindow> childWindow = do_GetInterface(curShell,&rv);
if (childWindow)
editingSession->MakeWindowEditable(childWindow, PR_FALSE);
}
}
return NS_OK;
}
NS_METHOD
CEditorFrame::DoCommand(nsICommandParams *aCommandParams)
{
nsCOMPtr<nsICommandManager> commandManager;
nsresult rv = NS_ERROR_FAILURE;
commandManager = do_GetInterface(m_wndBrowserView.mWebBrowser,&rv);
if (commandManager)
{
rv = commandManager->DoCommand(aCommandParams);
}
return rv;
}
NS_METHOD
CEditorFrame::IsCommandEnabled(const nsAString &aCommand, PRBool *retval)
{
nsCOMPtr<nsICommandManager> commandManager;
nsresult rv = NS_ERROR_FAILURE;
commandManager = do_GetInterface(m_wndBrowserView.mWebBrowser,&rv);
if (commandManager)
{
rv = commandManager->IsCommandEnabled(aCommand,retval);
}
return rv;
}
NS_METHOD
CEditorFrame::GetCommandState(nsICommandParams *aCommandParams)
{
nsCOMPtr<nsICommandManager> commandManager;
nsresult rv = NS_ERROR_FAILURE;
commandManager = do_GetInterface(m_wndBrowserView.mWebBrowser,&rv);
if (commandManager)
{
rv = commandManager->GetCommandState(aCommandParams);
}
return rv;
}

View File

@ -0,0 +1,85 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Netscape Public License
* Version 1.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* Mike Judge <mjudge@netscape.com>
* Chak Nanga <chak@netscape.com>
*
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the NPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the NPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef _EDITORFRM_H_
#define _EDITORFRM_H_
#include "nsICommandParams.h"
#include "nsIEditingSession.h"
#include "nsICommandManager.h"
#include "CCommandObserver.h"
#include "nsIScriptGlobalObject.h"
#include "nsISimpleEnumerator.h"
class CEditorFrame : public CBrowserFrame
{
public:
CEditorFrame(PRUint32 chromeMask);
virtual ~CEditorFrame();
protected:
DECLARE_DYNAMIC(CEditorFrame)
public:
BOOL InitEditor();
NS_METHOD MakeEditable();
NS_METHOD AddEditorObservers();
NS_METHOD DoCommand(nsICommandParams *aCommandParams);
NS_METHOD IsCommandEnabled(const nsAString &aCommand, PRBool *retval);
NS_METHOD GetCommandState(nsICommandParams *aCommandParams);
// Generated message map functions
protected:
//{{AFX_MSG(CEditorFrame)
afx_msg void OnBold();
afx_msg void OnUpdateBold(CCmdUI* pCmdUI);
afx_msg void OnItalics();
afx_msg void OnUpdateItalics(CCmdUI* pCmdUI);
afx_msg void OnUnderline();
afx_msg void OnUpdateUnderline(CCmdUI* pCmdUI);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
private:
CCommandObserver mToolBarObserver;
};
#endif //_EDITORFRM_H_

View File

@ -56,6 +56,7 @@
#include "stdafx.h"
#include "MfcEmbed.h"
#include "BrowserFrm.h"
#include "EditorFrm.h"
#include "winEmbedFileLocProvider.h"
#include "ProfileMgr.h"
#include "BrowserImpl.h"
@ -87,6 +88,7 @@ static NS_DEFINE_CID(kHelperAppLauncherDialogCID, NS_HELPERAPPLAUNCHERDIALOG_CID
BEGIN_MESSAGE_MAP(CMfcEmbedApp, CWinApp)
//{{AFX_MSG_MAP(CMfcEmbedApp)
ON_COMMAND(ID_NEW_BROWSER, OnNewBrowser)
ON_COMMAND(ID_NEW_EDITORWINDOW, OnNewEditor)
ON_COMMAND(ID_MANAGE_PROFILES, OnManageProfiles)
ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
ON_COMMAND(ID_EDIT_PREFERENCES, OnEditPreferences)
@ -333,9 +335,8 @@ CBrowserFrame* CMfcEmbedApp::CreateNewBrowserFrame(PRUint32 chromeMask,
PRBool bIsEditor,
PRBool bShowWindow)
{
UINT resId = IDR_MAINFRAME;
if (bIsEditor)
resId = IDR_EDITOR;
UINT resId = bIsEditor ? IDR_EDITOR : IDR_MAINFRAME;
// Setup a CRect with the requested window dimensions
CRect winSize(x, y, cx, cy);
@ -348,8 +349,10 @@ CBrowserFrame* CMfcEmbedApp::CreateNewBrowserFrame(PRUint32 chromeMask,
strTitle.LoadString(IDR_MAINFRAME);
// Now, create the browser frame
CBrowserFrame* pFrame = new CBrowserFrame(chromeMask);
pFrame->SetEditable(bIsEditor);
CBrowserFrame* pFrame = bIsEditor ? ( new CEditorFrame(chromeMask) ) :
( new CBrowserFrame(chromeMask) );
pFrame->SetEditable(bIsEditor);
if (!pFrame->Create(NULL, strTitle, WS_OVERLAPPEDWINDOW,
winSize, NULL, MAKEINTRESOURCE(resId), 0L, NULL))
{
@ -381,6 +384,18 @@ void CMfcEmbedApp::OnNewBrowser()
pBrowserFrame->m_wndBrowserView.LoadHomePage();
}
void CMfcEmbedApp::OnNewEditor()
{
CEditorFrame *pEditorFrame = (CEditorFrame *)CreateNewBrowserFrame(nsIWebBrowserChrome::CHROME_ALL,
-1, -1, -1, -1,
PR_TRUE,PR_TRUE);
if (pEditorFrame)
{
pEditorFrame->m_wndBrowserView.OpenURL("about:blank");
pEditorFrame->InitEditor();
}
}
// This gets called anytime a BrowserFrameWindow is
// closed i.e. by choosing the "close" menu item from
// a window's system menu or by dbl clicking on the

View File

@ -113,6 +113,7 @@ public:
//{{AFX_MSG(CMfcEmbedApp)
afx_msg void OnAppAbout();
afx_msg void OnNewBrowser();
afx_msg void OnNewEditor();
afx_msg void OnManageProfiles();
afx_msg void OnEditPreferences();
// NOTE - the ClassWizard will add and remove member functions here.

View File

@ -115,7 +115,7 @@ BEGIN
POPUP "&File"
BEGIN
MENUITEM "&New Browser Window\tCtrl+N", ID_NEW_BROWSER
MENUITEM "&New Editor Window", ID_NEW_EDITWINDOW
MENUITEM "New &Editor Window", ID_NEW_EDITORWINDOW
MENUITEM SEPARATOR
MENUITEM "&Open File...\tCtrl+O", ID_FILE_OPEN
MENUITEM "&Save Page As...\tCtrl+S", ID_FILE_SAVE_AS
@ -232,7 +232,8 @@ IDR_EDITOR MENU PRELOAD DISCARDABLE
BEGIN
POPUP "&File"
BEGIN
MENUITEM "New &Browser Window\tCtrl+N", ID_NEW_BROWSER
MENUITEM "&New Browser Window\tCtrl+N", ID_NEW_BROWSER
MENUITEM "New &Editor Window", ID_NEW_EDITORWINDOW
MENUITEM SEPARATOR
MENUITEM "&Open File...\tCtrl+O", ID_FILE_OPEN
MENUITEM "&Save Page As...\tCtrl+S", ID_FILE_SAVE_AS
@ -240,7 +241,6 @@ BEGIN
MENUITEM "&Print...\tCtrl-P", ID_FILE_PRINT
MENUITEM SEPARATOR
MENUITEM "E&xit\tCtrl+Q", ID_APP_EXIT
MENUITEM "New &Editor Window", ID_NEW_EDITORWINDOW
END
POPUP "&Edit"
BEGIN

View File

@ -58,6 +58,7 @@ LINCS = -Icomponents \
OBJS = \
.\$(OBJDIR)\MfcEmbed.obj \
.\$(OBJDIR)\BrowserFrm.obj \
.\$(OBJDIR)\EditorFrm.obj \
.\$(OBJDIR)\BrowserFrameGlue.obj \
.\$(OBJDIR)\BrowserView.obj \
.\$(OBJDIR)\BrowserImpl.obj \

View File

@ -114,10 +114,18 @@ SOURCE=.\BrowserView.cpp
# End Source File
# Begin Source File
SOURCE=.\CCommandObserver.cpp
# End Source File
# Begin Source File
SOURCE=.\Dialogs.cpp
# End Source File
# Begin Source File
SOURCE=.\EditorFrm.cpp
# End Source File
# Begin Source File
SOURCE=.\MfcEmbed.cpp
# End Source File
# Begin Source File
@ -174,10 +182,18 @@ SOURCE=.\BrowserView.h
# End Source File
# Begin Source File
SOURCE=.\CCommandObserver.h
# End Source File
# Begin Source File
SOURCE=.\Dialogs.h
# End Source File
# Begin Source File
SOURCE=.\EditorFrm.h
# End Source File
# Begin Source File
SOURCE=.\IBrowserFrameGlue.h
# End Source File
# Begin Source File

View File

@ -98,13 +98,12 @@
#define ID_EDIT_PREFERENCES 32788
#define ID_FILE_PRINTPREVIEW 32789
#define ID_FILE_PRINTSETUP 32790
#define ID_NEW_EDITORWINDOW 32790
#define ID_VIEW_FRAME_SOURCE 32791
#define ID_OPEN_FRAME_IN_NEW_WINDOW 32792
#define ID_BOLD 32793
#define ID_UNDERLINE 32794
#define ID_ITALICS 32795
#define ID_NEW_EDITWINDOW 32796
#define ID_NEW_EDITORWINDOW 32796
// Next default values for new objects
//