diff --git a/embedding/tests/mfcembed/BrowserFrm.cpp b/embedding/tests/mfcembed/BrowserFrm.cpp index 48bcb6844501..6168b3746f2a 100644 --- a/embedding/tests/mfcembed/BrowserFrm.cpp +++ b/embedding/tests/mfcembed/BrowserFrm.cpp @@ -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 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 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 - -} diff --git a/embedding/tests/mfcembed/BrowserFrm.h b/embedding/tests/mfcembed/BrowserFrm.h index 22cc2410f424..45f24dfbf90b 100644 --- a/embedding/tests/mfcembed/BrowserFrm.h +++ b/embedding/tests/mfcembed/BrowserFrm.h @@ -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; }; ///////////////////////////////////////////////////////////////////////////// diff --git a/embedding/tests/mfcembed/BrowserImpl.cpp b/embedding/tests/mfcembed/BrowserImpl.cpp index 7650a07fdf0d..9f3531dd4f69 100644 --- a/embedding/tests/mfcembed/BrowserImpl.cpp +++ b/embedding/tests/mfcembed/BrowserImpl.cpp @@ -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 domWindow; - mWebBrowser->GetContentDOMWindow(getter_AddRefs(domWindow)); - if (!domWindow) - return NS_ERROR_FAILURE; - nsCOMPtr scriptGlobalObject = do_QueryInterface(domWindow); - if (!scriptGlobalObject) - return NS_ERROR_FAILURE; - nsCOMPtr docShell; - rv = scriptGlobalObject->GetDocShell(getter_AddRefs(docShell)); - if (NS_FAILED(rv)) - return rv; - if (!docShell) - return NS_ERROR_FAILURE; - - - - nsCOMPtr 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 docShellEnumerator; - docShell->GetDocShellEnumerator( nsIDocShellTreeItem::typeContent, - nsIDocShell::ENUMERATE_FORWARDS, - getter_AddRefs(docShellEnumerator)); - if (docShellEnumerator) - { - PRBool hasMore; - while (NS_SUCCEEDED(docShellEnumerator->HasMoreElements(&hasMore)) && hasMore) - { - nsCOMPtr curSupports; - rv = docShellEnumerator->GetNext(getter_AddRefs(curSupports)); - if (NS_FAILED(rv)) break; - - nsCOMPtr curShell = do_QueryInterface(curSupports, &rv); - if (NS_FAILED(rv)) break; - - nsCOMPtr childWindow = do_GetInterface(curShell,&rv); - if (childWindow) - editingSession->MakeWindowEditable(childWindow, PR_FALSE); - } - } - return NS_OK; -} - - -//nsIObserver - -NS_IMETHODIMP -CEditorImpl::AddEditorObservers(nsIObserver *aObserver) -{ - nsCOMPtr 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 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 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 commandManager; - nsresult rv = NS_ERROR_FAILURE; - commandManager = do_GetInterface(mWebBrowser,&rv); - if (commandManager) - { - rv = commandManager->GetCommandState(aCommandParams); - } - return rv; -} \ No newline at end of file diff --git a/embedding/tests/mfcembed/BrowserImpl.h b/embedding/tests/mfcembed/BrowserImpl.h index 63a72d784981..34c5c2518899 100644 --- a/embedding/tests/mfcembed/BrowserImpl.h +++ b/embedding/tests/mfcembed/BrowserImpl.h @@ -73,16 +73,4 @@ protected: nsCOMPtr 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 diff --git a/embedding/tests/mfcembed/CCommandObserver.cpp b/embedding/tests/mfcembed/CCommandObserver.cpp index dd207f187d68..6054cf4a70ec 100644 --- a/embedding/tests/mfcembed/CCommandObserver.cpp +++ b/embedding/tests/mfcembed/CCommandObserver.cpp @@ -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 + * + * + * 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; } diff --git a/embedding/tests/mfcembed/CCommandObserver.h b/embedding/tests/mfcembed/CCommandObserver.h index 25c740664900..e384f8a04778 100644 --- a/embedding/tests/mfcembed/CCommandObserver.h +++ b/embedding/tests/mfcembed/CCommandObserver.h @@ -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 + * + * + * 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; }; - diff --git a/embedding/tests/mfcembed/EditorFrm.cpp b/embedding/tests/mfcembed/EditorFrm.cpp new file mode 100644 index 000000000000..5163e24e5f04 --- /dev/null +++ b/embedding/tests/mfcembed/EditorFrm.cpp @@ -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 + * Chak Nanga + * + * + * 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 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 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 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 domWindow; + m_wndBrowserView.mWebBrowser->GetContentDOMWindow(getter_AddRefs(domWindow)); + if (!domWindow) + return NS_ERROR_FAILURE; + + nsCOMPtr scriptGlobalObject = do_QueryInterface(domWindow); + if (!scriptGlobalObject) + return NS_ERROR_FAILURE; + + nsCOMPtr docShell; + rv = scriptGlobalObject->GetDocShell(getter_AddRefs(docShell)); + if (NS_FAILED(rv)) + return rv; + if (!docShell) + return NS_ERROR_FAILURE; + + nsCOMPtr 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 docShellEnumerator; + docShell->GetDocShellEnumerator( nsIDocShellTreeItem::typeContent, + nsIDocShell::ENUMERATE_FORWARDS, + getter_AddRefs(docShellEnumerator)); + if (docShellEnumerator) + { + PRBool hasMore; + while (NS_SUCCEEDED(docShellEnumerator->HasMoreElements(&hasMore)) && hasMore) + { + nsCOMPtr curSupports; + rv = docShellEnumerator->GetNext(getter_AddRefs(curSupports)); + if (NS_FAILED(rv)) break; + + nsCOMPtr curShell = do_QueryInterface(curSupports, &rv); + if (NS_FAILED(rv)) break; + + nsCOMPtr childWindow = do_GetInterface(curShell,&rv); + if (childWindow) + editingSession->MakeWindowEditable(childWindow, PR_FALSE); + } + } + + return NS_OK; +} + +NS_METHOD +CEditorFrame::DoCommand(nsICommandParams *aCommandParams) +{ + nsCOMPtr 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 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 commandManager; + nsresult rv = NS_ERROR_FAILURE; + commandManager = do_GetInterface(m_wndBrowserView.mWebBrowser,&rv); + if (commandManager) + { + rv = commandManager->GetCommandState(aCommandParams); + } + + return rv; +} diff --git a/embedding/tests/mfcembed/EditorFrm.h b/embedding/tests/mfcembed/EditorFrm.h new file mode 100644 index 000000000000..ecd8ba492cab --- /dev/null +++ b/embedding/tests/mfcembed/EditorFrm.h @@ -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 + * Chak Nanga + * + * + * 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_ diff --git a/embedding/tests/mfcembed/MfcEmbed.cpp b/embedding/tests/mfcembed/MfcEmbed.cpp index 89f5a9fd3fab..7bf1367952b4 100644 --- a/embedding/tests/mfcembed/MfcEmbed.cpp +++ b/embedding/tests/mfcembed/MfcEmbed.cpp @@ -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 diff --git a/embedding/tests/mfcembed/MfcEmbed.h b/embedding/tests/mfcembed/MfcEmbed.h index c8bbbc5f7ffa..9b0bd828d029 100644 --- a/embedding/tests/mfcembed/MfcEmbed.h +++ b/embedding/tests/mfcembed/MfcEmbed.h @@ -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. diff --git a/embedding/tests/mfcembed/MfcEmbed.rc b/embedding/tests/mfcembed/MfcEmbed.rc index d5c167564824..b33ed5073449 100644 --- a/embedding/tests/mfcembed/MfcEmbed.rc +++ b/embedding/tests/mfcembed/MfcEmbed.rc @@ -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 diff --git a/embedding/tests/mfcembed/makefile.win b/embedding/tests/mfcembed/makefile.win index 39410b07b596..31978aec67dc 100644 --- a/embedding/tests/mfcembed/makefile.win +++ b/embedding/tests/mfcembed/makefile.win @@ -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 \ diff --git a/embedding/tests/mfcembed/mfcembed.dsp b/embedding/tests/mfcembed/mfcembed.dsp index 7734f0fd5d1c..8d75d4a6c0df 100644 --- a/embedding/tests/mfcembed/mfcembed.dsp +++ b/embedding/tests/mfcembed/mfcembed.dsp @@ -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 diff --git a/embedding/tests/mfcembed/resource.h b/embedding/tests/mfcembed/resource.h index 4d06ceca5e75..a698777d3b27 100644 --- a/embedding/tests/mfcembed/resource.h +++ b/embedding/tests/mfcembed/resource.h @@ -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 //