1999-06-11 03:50:26 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
1999-11-06 06:43:54 +03:00
|
|
|
* 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/
|
1999-06-11 03:50:26 +04:00
|
|
|
*
|
1999-11-06 06:43:54 +03:00
|
|
|
* 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.
|
1999-06-11 03:50:26 +04:00
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Communicator client code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape Communications
|
1999-11-06 06:43:54 +03:00
|
|
|
* Corporation. Portions created by Netscape are
|
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
1999-06-11 03:50:26 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "nsEditorShell.h"
|
|
|
|
#include "nsIWebShell.h"
|
1999-12-18 02:44:43 +03:00
|
|
|
#include "nsIBaseWindow.h"
|
1999-11-19 10:35:27 +03:00
|
|
|
#include "nsIContentViewerFile.h"
|
1999-06-11 03:50:26 +04:00
|
|
|
#include "pratom.h"
|
|
|
|
#include "prprf.h"
|
|
|
|
#include "nsIComponentManager.h"
|
|
|
|
|
|
|
|
#include "nsIScriptContext.h"
|
|
|
|
#include "nsIScriptGlobalObject.h"
|
2000-03-28 04:15:56 +04:00
|
|
|
#include "nsIScriptGlobalObjectOwner.h"
|
1999-06-11 03:50:26 +04:00
|
|
|
#include "nsIDOMDocument.h"
|
1999-10-29 06:33:51 +04:00
|
|
|
#include "nsIDOMXULDocument.h"
|
1999-10-14 04:13:27 +04:00
|
|
|
#include "nsIDOMHTMLDocument.h"
|
1999-06-11 03:50:26 +04:00
|
|
|
#include "nsIDiskDocument.h"
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsIDOMWindow.h"
|
1999-10-14 04:13:27 +04:00
|
|
|
#include "nsIDOMNode.h"
|
|
|
|
#include "nsIDOMNodeList.h"
|
1999-09-30 01:45:50 +04:00
|
|
|
#include "nsICSSLoader.h"
|
|
|
|
#include "nsICSSStyleSheet.h"
|
2000-05-10 03:03:41 +04:00
|
|
|
#include "nsIContent.h"
|
1999-09-30 01:45:50 +04:00
|
|
|
#include "nsIHTMLContentContainer.h"
|
|
|
|
#include "nsIStyleSet.h"
|
|
|
|
#include "nsIURI.h"
|
1999-11-30 07:50:42 +03:00
|
|
|
#include "nsNetUtil.h"
|
1999-06-11 03:50:26 +04:00
|
|
|
|
|
|
|
#include "nsIScriptGlobalObject.h"
|
2000-03-11 04:00:48 +03:00
|
|
|
#include "nsIWebNavigation.h"
|
1999-06-11 03:50:26 +04:00
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
|
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsIURL.h"
|
|
|
|
#include "nsIWidget.h"
|
1999-11-11 03:12:23 +03:00
|
|
|
#include "nsIWindowMediator.h"
|
1999-06-11 03:50:26 +04:00
|
|
|
#include "plevent.h"
|
2000-03-11 04:00:48 +03:00
|
|
|
#include "nsXPIDLString.h"
|
1999-06-11 03:50:26 +04:00
|
|
|
|
|
|
|
#include "nsIAppShell.h"
|
|
|
|
#include "nsIAppShellService.h"
|
|
|
|
#include "nsAppShellCIDs.h"
|
|
|
|
|
|
|
|
#include "nsIDocumentViewer.h"
|
|
|
|
#include "nsIDOMHTMLImageElement.h"
|
|
|
|
#include "nsIPresShell.h"
|
|
|
|
#include "nsIPresContext.h"
|
|
|
|
#include "nsIDOMSelection.h"
|
|
|
|
|
|
|
|
#include "nsIFileWidget.h"
|
1999-06-13 00:40:29 +04:00
|
|
|
#include "nsFileSpec.h"
|
1999-06-11 03:50:26 +04:00
|
|
|
#include "nsIFindComponent.h"
|
1999-08-31 04:51:23 +04:00
|
|
|
#include "nsIPrompt.h"
|
1999-09-01 05:22:37 +04:00
|
|
|
#include "nsICommonDialogs.h"
|
1999-06-11 03:50:26 +04:00
|
|
|
|
1999-12-15 06:46:27 +03:00
|
|
|
#include "nsIEditorController.h"
|
|
|
|
#include "nsEditorController.h"
|
|
|
|
#include "nsIControllers.h"
|
2000-02-08 16:40:10 +03:00
|
|
|
#include "nsIDocShell.h"
|
2000-03-11 04:00:48 +03:00
|
|
|
#include "nsIDocShellTreeItem.h"
|
2000-04-12 03:48:14 +04:00
|
|
|
#include "nsIDocShellTreeOwner.h"
|
2000-03-31 06:13:00 +04:00
|
|
|
#include "nsIDocShellTreeNode.h"
|
2000-02-16 04:38:02 +03:00
|
|
|
#include "nsITransactionManager.h"
|
2000-04-19 02:39:10 +04:00
|
|
|
#include "nsIDocumentEncoder.h"
|
1999-12-15 06:46:27 +03:00
|
|
|
|
2000-04-15 01:19:44 +04:00
|
|
|
#include "nsIRefreshURI.h"
|
2000-04-19 02:39:10 +04:00
|
|
|
#include "nsIPref.h"
|
2000-04-15 01:19:44 +04:00
|
|
|
|
1999-06-11 03:50:26 +04:00
|
|
|
///////////////////////////////////////
|
|
|
|
// Editor Includes
|
|
|
|
///////////////////////////////////////
|
|
|
|
#include "nsIDOMEventCapturer.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsIDOMText.h"
|
|
|
|
#include "nsIDOMElement.h"
|
|
|
|
#include "nsIDOMDocument.h"
|
2000-03-31 06:13:00 +04:00
|
|
|
#include "nsIDocumentLoader.h"
|
1999-06-11 03:50:26 +04:00
|
|
|
|
|
|
|
#include "nsIEditor.h"
|
|
|
|
#include "nsIHTMLEditor.h"
|
1999-08-09 05:37:50 +04:00
|
|
|
#include "nsIEditorStyleSheets.h"
|
|
|
|
#include "nsIEditorMailSupport.h"
|
|
|
|
#include "nsITableEditor.h"
|
|
|
|
#include "nsIEditorLogging.h"
|
|
|
|
|
1999-06-11 03:50:26 +04:00
|
|
|
#include "nsEditorCID.h"
|
|
|
|
|
|
|
|
#include "nsIComponentManager.h"
|
|
|
|
#include "nsTextServicesCID.h"
|
|
|
|
#include "nsITextServicesDocument.h"
|
|
|
|
#include "nsISpellChecker.h"
|
1999-07-28 06:54:35 +04:00
|
|
|
#include "nsInterfaceState.h"
|
1999-07-15 02:30:39 +04:00
|
|
|
|
2000-04-19 02:39:10 +04:00
|
|
|
#include "nsAOLCiter.h"
|
|
|
|
#include "nsInternetCiter.h"
|
2000-05-10 03:03:41 +04:00
|
|
|
#include "nsEditorShellMouseListener.h"
|
2000-04-19 02:39:10 +04:00
|
|
|
|
1999-06-11 03:50:26 +04:00
|
|
|
///////////////////////////////////////
|
|
|
|
|
|
|
|
// Drag & Drop, Clipboard
|
|
|
|
#include "nsWidgetsCID.h"
|
|
|
|
#include "nsIClipboard.h"
|
|
|
|
#include "nsITransferable.h"
|
|
|
|
#include "nsISupportsArray.h"
|
|
|
|
|
|
|
|
/* Define Class IDs */
|
|
|
|
static NS_DEFINE_IID(kAppShellServiceCID, NS_APPSHELL_SERVICE_CID);
|
|
|
|
static NS_DEFINE_CID(kHTMLEditorCID, NS_HTMLEDITOR_CID);
|
|
|
|
static NS_DEFINE_CID(kCTextServicesDocumentCID, NS_TEXTSERVICESDOCUMENT_CID);
|
1999-08-28 06:40:18 +04:00
|
|
|
static NS_DEFINE_IID(kCFileWidgetCID, NS_FILEWIDGET_CID);
|
|
|
|
static NS_DEFINE_CID(kCStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID);
|
1999-09-01 05:22:37 +04:00
|
|
|
static NS_DEFINE_CID(kCommonDialogsCID, NS_CommonDialog_CID );
|
|
|
|
static NS_DEFINE_CID(kDialogParamBlockCID, NS_DialogParamBlock_CID);
|
2000-04-19 02:39:10 +04:00
|
|
|
static NS_DEFINE_CID(kPrefServiceCID, NS_PREF_CID);
|
1999-12-15 06:46:27 +03:00
|
|
|
|
1999-06-11 03:50:26 +04:00
|
|
|
/* Define Interface IDs */
|
|
|
|
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
|
|
|
|
|
|
|
#define APP_DEBUG 0
|
|
|
|
|
1999-09-21 10:30:03 +04:00
|
|
|
#define EDITOR_BUNDLE_URL "chrome://editor/locale/editor.properties"
|
1999-06-11 03:50:26 +04:00
|
|
|
|
2000-05-10 03:03:41 +04:00
|
|
|
enum {
|
|
|
|
eEditorController,
|
|
|
|
eComposerController
|
|
|
|
};
|
|
|
|
|
1999-10-29 06:33:51 +04:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
// Utility to extract document from a webshell object.
|
|
|
|
static nsresult
|
2000-04-12 03:48:14 +04:00
|
|
|
GetDocument(nsIDocShell *aDocShell, nsIDocument **aDoc )
|
1999-10-29 06:33:51 +04:00
|
|
|
{
|
|
|
|
// Get content viewer from the web shell.
|
|
|
|
nsCOMPtr<nsIContentViewer> contentViewer;
|
2000-04-12 03:48:14 +04:00
|
|
|
nsresult res = (aDocShell && aDoc) ?
|
|
|
|
aDocShell->GetContentViewer(getter_AddRefs(contentViewer))
|
1999-10-29 06:33:51 +04:00
|
|
|
: NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
if ( NS_SUCCEEDED(res) && contentViewer )
|
|
|
|
{
|
|
|
|
// Up-cast to a document viewer.
|
|
|
|
nsCOMPtr<nsIDocumentViewer> docViewer(do_QueryInterface(contentViewer));
|
|
|
|
if ( docViewer )
|
|
|
|
{
|
|
|
|
// Get the document from the doc viewer.
|
|
|
|
res = docViewer->GetDocument(*aDoc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2000-05-04 18:02:03 +04:00
|
|
|
// Utility get a UI element
|
1999-10-29 06:33:51 +04:00
|
|
|
static nsresult
|
2000-05-04 18:02:03 +04:00
|
|
|
GetChromeElement(nsIDocShell *aShell, const char *aID, nsIDOMElement **aElement)
|
1999-10-29 06:33:51 +04:00
|
|
|
{
|
2000-05-04 18:02:03 +04:00
|
|
|
if (!aElement) return NS_ERROR_NULL_POINTER;
|
|
|
|
*aElement = nsnull;
|
|
|
|
|
1999-10-29 06:33:51 +04:00
|
|
|
nsCOMPtr<nsIDocument> doc;
|
2000-05-04 18:02:03 +04:00
|
|
|
nsresult rv = GetDocument( aShell, getter_AddRefs(doc) );
|
1999-10-29 06:33:51 +04:00
|
|
|
if(NS_SUCCEEDED(rv) && doc)
|
|
|
|
{
|
|
|
|
// Up-cast.
|
|
|
|
nsCOMPtr<nsIDOMXULDocument> xulDoc( do_QueryInterface(doc) );
|
|
|
|
if ( xulDoc )
|
|
|
|
{
|
|
|
|
// Find specified element.
|
|
|
|
nsCOMPtr<nsIDOMElement> elem;
|
2000-05-04 18:02:03 +04:00
|
|
|
rv = xulDoc->GetElementById( NS_ConvertASCIItoUCS2(aID), getter_AddRefs(elem) );
|
|
|
|
if (elem)
|
|
|
|
{
|
|
|
|
*aElement = elem.get();
|
|
|
|
NS_ADDREF(*aElement);
|
|
|
|
}
|
1999-10-29 06:33:51 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2000-05-04 18:02:03 +04:00
|
|
|
// Utility to set and attribute of a UI element
|
|
|
|
static nsresult
|
|
|
|
SetChromeAttribute(nsIDocShell *aShell, const char *aID,
|
|
|
|
const char *aName, const nsString &aValue)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMElement> elem;
|
|
|
|
nsresult rv = GetChromeElement(aShell, aID, getter_AddRefs(elem));
|
|
|
|
if (NS_SUCCEEDED(rv) && elem)
|
|
|
|
// Set the text attribute.
|
|
|
|
rv = elem->SetAttribute( NS_ConvertASCIItoUCS2(aName), aValue);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
static nsresult
|
|
|
|
RemoveChromeAttribute(nsIDocShell *aShell, const char *aID, const char *aName)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMElement> elem;
|
|
|
|
nsresult rv = GetChromeElement(aShell, aID, getter_AddRefs(elem));
|
|
|
|
if (NS_SUCCEEDED(rv) && elem)
|
|
|
|
// Set the text attribute.
|
|
|
|
rv = elem->RemoveAttribute(NS_ConvertASCIItoUCS2(aName));
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2000-04-12 03:48:14 +04:00
|
|
|
// Utility to get the treeOwner for a docShell
|
|
|
|
static nsresult
|
|
|
|
GetTreeOwner(nsIDocShell* aDocShell, nsIBaseWindow** aBaseWindow)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> docShellAsItem(do_QueryInterface(aDocShell));
|
|
|
|
NS_ENSURE_TRUE(docShellAsItem, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocShellTreeOwner> treeOwner;
|
|
|
|
docShellAsItem->GetTreeOwner(getter_AddRefs(treeOwner));
|
|
|
|
NS_ENSURE_TRUE(treeOwner, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
NS_ENSURE_SUCCESS(CallQueryInterface(treeOwner, aBaseWindow),
|
|
|
|
NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-06-11 03:50:26 +04:00
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsEditorShell
|
|
|
|
/////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
nsEditorShell::nsEditorShell()
|
2000-05-04 18:37:56 +04:00
|
|
|
: mMailCompose(0)
|
|
|
|
, mDisplayMode(eDisplayModeNormal)
|
2000-05-02 01:49:52 +04:00
|
|
|
, mWebShellWindow(nsnull)
|
|
|
|
, mContentWindow(nsnull)
|
2000-05-04 18:37:56 +04:00
|
|
|
, mParserObserver(nsnull)
|
|
|
|
, mStateMaintainer(nsnull)
|
2000-05-02 01:49:52 +04:00
|
|
|
, mEditorController(nsnull)
|
2000-04-12 03:48:14 +04:00
|
|
|
, mDocShell(nsnull)
|
|
|
|
, mContentAreaDocShell(nsnull)
|
2000-04-19 02:39:10 +04:00
|
|
|
, mCloseWindowWhenLoaded(PR_FALSE)
|
1999-07-15 02:30:39 +04:00
|
|
|
, mEditorType(eUninitializedEditorType)
|
1999-07-31 03:37:57 +04:00
|
|
|
, mWrapColumn(0)
|
1999-07-15 18:43:48 +04:00
|
|
|
, mSuggestedWordIndex(0)
|
|
|
|
, mDictionaryIndex(0)
|
1999-06-11 03:50:26 +04:00
|
|
|
{
|
2000-05-02 07:24:11 +04:00
|
|
|
//TODO:Save last-used display mode in prefs so new window inherits?
|
1999-06-11 03:50:26 +04:00
|
|
|
NS_INIT_REFCNT();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsEditorShell::~nsEditorShell()
|
|
|
|
{
|
1999-07-28 06:54:35 +04:00
|
|
|
NS_IF_RELEASE(mStateMaintainer);
|
2000-03-31 06:13:00 +04:00
|
|
|
NS_IF_RELEASE(mParserObserver);
|
|
|
|
|
1999-07-28 06:54:35 +04:00
|
|
|
// the only other references we hold are in nsCOMPtrs, so they'll take
|
1999-07-15 02:30:39 +04:00
|
|
|
// care of themselves.
|
1999-06-11 03:50:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF(nsEditorShell)
|
|
|
|
NS_IMPL_RELEASE(nsEditorShell)
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::QueryInterface(REFNSIID aIID,void** aInstancePtr)
|
|
|
|
{
|
|
|
|
if (aInstancePtr == NULL) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Always NULL result, in case of failure
|
|
|
|
*aInstancePtr = NULL;
|
|
|
|
|
|
|
|
if ( aIID.Equals(kISupportsIID)) {
|
|
|
|
*aInstancePtr = (void*) ((nsISupports*)((nsIEditorShell *)this));
|
|
|
|
AddRef();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-01-11 23:49:15 +03:00
|
|
|
else if ( aIID.Equals(NS_GET_IID(nsIEditorShell)) ) {
|
1999-06-11 03:50:26 +04:00
|
|
|
*aInstancePtr = (void*) ((nsIEditorShell*)this);
|
|
|
|
AddRef();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-01-11 23:49:15 +03:00
|
|
|
else if ( aIID.Equals(NS_GET_IID(nsIEditorSpellCheck)) ) {
|
1999-06-12 02:43:19 +04:00
|
|
|
*aInstancePtr = (void*) ((nsIEditorSpellCheck*)this);
|
1999-06-11 03:50:26 +04:00
|
|
|
AddRef();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-01-11 23:49:15 +03:00
|
|
|
else if (aIID.Equals(NS_GET_IID(nsIDocumentLoaderObserver))) {
|
1999-06-20 02:13:46 +04:00
|
|
|
*aInstancePtr = (void*) ((nsIDocumentLoaderObserver*)this);
|
1999-06-11 03:50:26 +04:00
|
|
|
AddRef();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_ERROR_NO_INTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::Init()
|
|
|
|
{
|
2000-04-18 11:44:58 +04:00
|
|
|
nsAutoString editorType; editorType.AssignWithConversion("html"); // default to creating HTML editor
|
1999-06-11 03:50:26 +04:00
|
|
|
mEditorTypeString = editorType;
|
|
|
|
mEditorTypeString.ToLowerCase();
|
|
|
|
|
1999-08-28 06:40:18 +04:00
|
|
|
// Get pointer to our string bundle
|
1999-10-08 18:39:20 +04:00
|
|
|
nsresult res;
|
2000-03-31 06:13:00 +04:00
|
|
|
nsCOMPtr<nsIStringBundleService> stringBundleService = do_GetService(kCStringBundleServiceCID, &res);
|
|
|
|
if (!stringBundleService) {
|
|
|
|
NS_WARNING("ERROR: Failed to get StringBundle Service instance.\n");
|
1999-10-08 18:39:20 +04:00
|
|
|
return res;
|
1999-08-28 06:40:18 +04:00
|
|
|
}
|
2000-03-31 06:13:00 +04:00
|
|
|
nsILocale* aLocale = nsnull;
|
|
|
|
res = stringBundleService->CreateBundle(EDITOR_BUNDLE_URL, aLocale, getter_AddRefs(mStringBundle));
|
1999-09-15 05:10:10 +04:00
|
|
|
|
1999-10-08 18:39:20 +04:00
|
|
|
// XXX: why are we returning NS_OK here rather than res?
|
|
|
|
// is it ok to fail to get a string bundle? if so, it should be documented.
|
2000-05-02 01:49:52 +04:00
|
|
|
|
1999-06-11 03:50:26 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-05-15 07:06:29 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::Shutdown()
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
// Remove our document mouse event listener
|
|
|
|
if (mMouseListenerP)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMEventReceiver> erP;
|
|
|
|
rv = GetDocumentEventReceiver(getter_AddRefs(erP));
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
{
|
|
|
|
if (erP)
|
|
|
|
{
|
|
|
|
erP->RemoveEventListenerByIID(mMouseListenerP, NS_GET_IID(nsIDOMMouseListener));
|
|
|
|
mMouseListenerP = nsnull;
|
|
|
|
}
|
|
|
|
else rv = NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
2000-05-06 03:19:08 +04:00
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsEditorShell::ResetEditingState()
|
1999-11-13 19:37:58 +03:00
|
|
|
{
|
2000-05-06 03:19:08 +04:00
|
|
|
if (!mEditor) return NS_OK; // nothing to do
|
1999-11-13 19:37:58 +03:00
|
|
|
|
2000-05-06 03:19:08 +04:00
|
|
|
// Mmm, we have an editor already. That means that someone loaded more than
|
|
|
|
// one URL into the content area. Let's tear down what we have, and rip 'em a
|
|
|
|
// new one.
|
1999-11-13 19:37:58 +03:00
|
|
|
|
2000-05-06 03:19:08 +04:00
|
|
|
// Unload existing stylesheets
|
|
|
|
nsCOMPtr<nsIEditorStyleSheets> styleSheets = do_QueryInterface(mEditor);
|
|
|
|
if (styleSheets)
|
|
|
|
{
|
|
|
|
if (mBaseStyleSheet)
|
1999-11-13 19:37:58 +03:00
|
|
|
{
|
2000-05-06 03:19:08 +04:00
|
|
|
styleSheets->RemoveOverrideStyleSheet(mBaseStyleSheet);
|
|
|
|
mBaseStyleSheet = 0;
|
1999-11-13 19:37:58 +03:00
|
|
|
}
|
2000-05-06 03:19:08 +04:00
|
|
|
if (mEditModeStyleSheet)
|
2000-05-02 01:49:52 +04:00
|
|
|
{
|
2000-05-06 03:19:08 +04:00
|
|
|
styleSheets->RemoveOverrideStyleSheet(mEditModeStyleSheet);
|
|
|
|
mEditModeStyleSheet = 0;
|
|
|
|
}
|
|
|
|
if (mAllTagsModeStyleSheet)
|
|
|
|
{
|
|
|
|
styleSheets->RemoveOverrideStyleSheet(mAllTagsModeStyleSheet);
|
|
|
|
mAllTagsModeStyleSheet = 0;
|
|
|
|
}
|
|
|
|
if (mParagraphMarksStyleSheet)
|
|
|
|
{
|
|
|
|
styleSheets->RemoveOverrideStyleSheet(mParagraphMarksStyleSheet);
|
|
|
|
mParagraphMarksStyleSheet = 0;
|
2000-05-02 01:49:52 +04:00
|
|
|
}
|
1999-11-13 19:37:58 +03:00
|
|
|
}
|
2000-05-06 03:19:08 +04:00
|
|
|
|
2000-05-10 03:03:41 +04:00
|
|
|
nsresult rv;
|
2000-05-06 03:19:08 +04:00
|
|
|
// now, unregister the selection listener, if there was one
|
|
|
|
if (mStateMaintainer)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMSelection> domSelection;
|
|
|
|
// using a scoped result, because we don't really care if this fails
|
2000-05-10 03:03:41 +04:00
|
|
|
rv = GetEditorSelection(getter_AddRefs(domSelection));
|
|
|
|
if (NS_SUCCEEDED(rv) && domSelection)
|
2000-05-06 03:19:08 +04:00
|
|
|
{
|
|
|
|
domSelection->RemoveSelectionListener(mStateMaintainer);
|
|
|
|
NS_IF_RELEASE(mStateMaintainer);
|
|
|
|
}
|
|
|
|
}
|
2000-05-10 03:03:41 +04:00
|
|
|
|
|
|
|
// Remove our document mouse event listener
|
|
|
|
if (mMouseListenerP)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMEventReceiver> erP;
|
|
|
|
rv = GetDocumentEventReceiver(getter_AddRefs(erP));
|
|
|
|
if (NS_SUCCEEDED(rv) && erP)
|
|
|
|
{
|
|
|
|
erP->RemoveEventListenerByIID(mMouseListenerP, NS_GET_IID(nsIDOMMouseListener));
|
|
|
|
mMouseListenerP = nsnull;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-05-06 03:19:08 +04:00
|
|
|
// clear this editor out of the controller
|
|
|
|
if (mEditorController)
|
|
|
|
{
|
|
|
|
mEditorController->SetCommandRefCon(nsnull);
|
|
|
|
}
|
|
|
|
|
|
|
|
mEditorType = eUninitializedEditorType;
|
|
|
|
mEditor = 0; // clear out the nsCOMPtr
|
|
|
|
|
|
|
|
// and tell them that they are doing bad things
|
|
|
|
NS_WARNING("Multiple loads of the editor's document detected.");
|
|
|
|
// Note that if you registered doc state listeners before the second
|
|
|
|
// URL load, they don't get transferred to the new editor.
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsEditorShell::PrepareDocumentForEditing(nsIDocumentLoader* aLoader, nsIURI *aUrl)
|
|
|
|
{
|
|
|
|
if (!mContentAreaDocShell || !mContentWindow)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
|
|
|
NS_ASSERTION(!mEditor, "Should never have an editor here");
|
|
|
|
|
2000-04-12 03:48:14 +04:00
|
|
|
// get the webshell for this loader. Need this, not mContentAreaDocShell, in
|
2000-03-31 06:13:00 +04:00
|
|
|
// case we are editing a frameset
|
|
|
|
nsCOMPtr<nsISupports> loaderContainer;
|
|
|
|
aLoader->GetContainer(getter_AddRefs(loaderContainer));
|
2000-04-12 03:48:14 +04:00
|
|
|
nsCOMPtr<nsIDocShell> containerAsDocShell = do_QueryInterface(loaderContainer);
|
|
|
|
if (!containerAsDocShell)
|
2000-03-31 06:13:00 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(0, "Failed to get loader container as web shell");
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
1999-11-13 19:37:58 +03:00
|
|
|
|
2000-04-12 03:48:14 +04:00
|
|
|
nsresult rv = DoEditorMode(containerAsDocShell);
|
1999-11-13 19:37:58 +03:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
// transfer the doc state listeners to the editor
|
|
|
|
rv = TransferDocumentStateListeners();
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
// make the UI state maintainer
|
2000-01-19 00:50:15 +03:00
|
|
|
NS_NEWXPCOM(mStateMaintainer, nsInterfaceState);
|
1999-11-13 19:37:58 +03:00
|
|
|
if (!mStateMaintainer) return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
mStateMaintainer->AddRef(); // the owning reference
|
2000-01-19 00:50:15 +03:00
|
|
|
|
|
|
|
// get the XULDoc from the webshell
|
|
|
|
nsCOMPtr<nsIContentViewer> cv;
|
2000-04-12 03:48:14 +04:00
|
|
|
rv = mDocShell->GetContentViewer(getter_AddRefs(cv));
|
2000-01-19 00:50:15 +03:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocumentViewer> docViewer = do_QueryInterface(cv, &rv);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocument> chromeDoc;
|
|
|
|
rv = docViewer->GetDocument(*getter_AddRefs(chromeDoc));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMXULDocument> xulDoc = do_QueryInterface(chromeDoc, &rv);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
// now init the state maintainer
|
|
|
|
rv = mStateMaintainer->Init(mEditor, xulDoc);
|
1999-11-13 19:37:58 +03:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
// set it up as a selection listener
|
|
|
|
nsCOMPtr<nsIDOMSelection> domSelection;
|
|
|
|
rv = GetEditorSelection(getter_AddRefs(domSelection));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = domSelection->AddSelectionListener(mStateMaintainer);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
// and set it up as a doc state listener
|
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(mEditor, &rv);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
2000-02-16 04:38:02 +03:00
|
|
|
rv = editor->AddDocumentStateListener(NS_STATIC_CAST(nsIDocumentStateListener*, mStateMaintainer));
|
1999-11-13 19:37:58 +03:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2000-02-16 04:38:02 +03:00
|
|
|
// and as a transaction listener
|
|
|
|
nsCOMPtr<nsITransactionManager> txnMgr;
|
|
|
|
editor->GetTransactionManager(getter_AddRefs(txnMgr));
|
|
|
|
if (txnMgr)
|
|
|
|
{
|
|
|
|
txnMgr->AddListener(NS_STATIC_CAST(nsITransactionListener*, mStateMaintainer));
|
|
|
|
}
|
2000-05-02 01:49:52 +04:00
|
|
|
|
|
|
|
// set the editor in the editor controller
|
|
|
|
if (mEditorController)
|
1999-12-15 06:46:27 +03:00
|
|
|
{
|
2000-05-02 01:49:52 +04:00
|
|
|
nsCOMPtr<nsISupports> editorAsISupports = do_QueryInterface(editor);
|
|
|
|
mEditorController->SetCommandRefCon(editorAsISupports);
|
1999-12-15 06:46:27 +03:00
|
|
|
}
|
|
|
|
|
2000-05-10 03:03:41 +04:00
|
|
|
|
|
|
|
// get a mouse listener for double click on tags
|
|
|
|
// We can't use nsEditor listener because core editor shouldn't call UI commands
|
|
|
|
rv = NS_NewEditorShellMouseListener(getter_AddRefs(mMouseListenerP), this);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
{
|
|
|
|
mMouseListenerP = nsnull;
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add mouse listener to document
|
|
|
|
nsCOMPtr<nsIDOMEventReceiver> erP;
|
|
|
|
rv = GetDocumentEventReceiver(getter_AddRefs(erP));
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
{
|
|
|
|
mMouseListenerP = nsnull;
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = erP->AddEventListenerByIID(mMouseListenerP, NS_GET_IID(nsIDOMMouseListener));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
1999-11-13 19:37:58 +03:00
|
|
|
// now all the listeners are set up, we can call PostCreate
|
|
|
|
rv = editor->PostCreate();
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
// get the URL of the page we are editing
|
|
|
|
if (aUrl)
|
|
|
|
{
|
1999-11-22 17:52:21 +03:00
|
|
|
char* pageURLString = nsnull;
|
|
|
|
char* pageScheme = nsnull;
|
|
|
|
aUrl->GetScheme(&pageScheme);
|
1999-11-13 19:37:58 +03:00
|
|
|
aUrl->GetSpec(&pageURLString);
|
1999-11-22 17:52:21 +03:00
|
|
|
|
2000-03-31 06:13:00 +04:00
|
|
|
#if DEBUG
|
2000-05-02 07:24:11 +04:00
|
|
|
printf("PrepareDocumentForEditing: Editor is editing %s\n", pageURLString ? pageURLString : "");
|
2000-03-31 06:13:00 +04:00
|
|
|
#endif
|
|
|
|
|
2000-02-15 18:54:05 +03:00
|
|
|
// only save the file spec if this is a local file, and is not
|
|
|
|
// about:blank
|
|
|
|
if (nsCRT::strncmp(pageScheme, "file", 4) == 0 &&
|
|
|
|
nsCRT::strncmp(pageURLString,"about:blank", 11) != 0)
|
1999-11-13 19:37:58 +03:00
|
|
|
{
|
2000-05-02 07:24:11 +04:00
|
|
|
// Clutzy method of converting URL to local file format
|
2000-05-10 03:03:41 +04:00
|
|
|
// nsIFileSpec is going away -- WE NEED TO REWRITE nsIDiskDocument!
|
1999-11-13 19:37:58 +03:00
|
|
|
nsFileURL pageURL(pageURLString);
|
|
|
|
nsFileSpec pageSpec(pageURL);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMDocument> domDoc;
|
|
|
|
editor->GetDocument(getter_AddRefs(domDoc));
|
|
|
|
|
|
|
|
if (domDoc)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDiskDocument> diskDoc = do_QueryInterface(domDoc);
|
|
|
|
if (diskDoc)
|
|
|
|
diskDoc->InitDiskDocument(&pageSpec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (pageURLString)
|
|
|
|
nsCRT::free(pageURLString);
|
1999-11-22 17:52:21 +03:00
|
|
|
if (pageScheme)
|
|
|
|
nsCRT::free(pageScheme);
|
1999-11-13 19:37:58 +03:00
|
|
|
}
|
|
|
|
// Set the editor-specific Window caption
|
|
|
|
UpdateWindowTitle();
|
|
|
|
|
|
|
|
nsCOMPtr<nsIEditorStyleSheets> styleSheets = do_QueryInterface(mEditor);
|
|
|
|
if (!styleSheets)
|
|
|
|
return NS_NOINTERFACE;
|
|
|
|
|
|
|
|
// Load style sheet with settings that should never
|
|
|
|
// change, even in "Browser" mode
|
2000-03-31 08:18:29 +04:00
|
|
|
// We won't unload this, so we don't need to be returned the style sheet pointer
|
2000-05-02 07:24:11 +04:00
|
|
|
|
|
|
|
|
|
|
|
styleSheets->ApplyOverrideStyleSheet(NS_ConvertASCIItoUCS2("chrome://editor/content/EditorOverride.css"),
|
|
|
|
getter_AddRefs(mBaseStyleSheet));
|
1999-11-13 19:37:58 +03:00
|
|
|
|
2000-05-02 07:24:11 +04:00
|
|
|
SetDisplayMode(mDisplayMode);
|
1999-11-13 19:37:58 +03:00
|
|
|
|
2000-02-15 18:54:05 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
// Activate the debug menu only in debug builds
|
|
|
|
// by removing the "hidden" attribute set "true" in XUL
|
|
|
|
nsCOMPtr<nsIDOMElement> elem;
|
2000-04-18 11:44:58 +04:00
|
|
|
rv = xulDoc->GetElementById(NS_ConvertASCIItoUCS2("debugMenu"), getter_AddRefs(elem));
|
2000-02-15 18:54:05 +03:00
|
|
|
if (elem)
|
2000-04-18 11:44:58 +04:00
|
|
|
elem->RemoveAttribute(NS_ConvertASCIItoUCS2("hidden"));
|
2000-02-15 18:54:05 +03:00
|
|
|
#endif
|
|
|
|
|
2000-05-02 07:24:11 +04:00
|
|
|
// Force initial focus to the content window except if in mail compose
|
|
|
|
if (!mMailCompose)
|
|
|
|
{
|
2000-05-14 09:27:17 +04:00
|
|
|
if(!mContentWindow)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
nsCOMPtr<nsIDOMWindow> cwP = do_QueryReferent(mContentWindow);
|
|
|
|
if (!cwP) return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
cwP->Focus();
|
|
|
|
|
|
|
|
//mContentWindow->Focus();
|
2000-05-04 18:02:03 +04:00
|
|
|
// Collapse the selection to the begining of the document
|
|
|
|
// (this also turns on the caret)
|
|
|
|
mEditor->SetCaretToDocumentStart();
|
2000-05-02 07:24:11 +04:00
|
|
|
}
|
1999-11-13 19:37:58 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-05-10 03:03:41 +04:00
|
|
|
nsresult nsEditorShell::GetDocumentEventReceiver(nsIDOMEventReceiver **aEventReceiver)
|
|
|
|
{
|
|
|
|
if (!aEventReceiver) return NS_ERROR_NULL_POINTER;
|
|
|
|
if (!mContentWindow || !mEditor) return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
2000-05-14 09:27:17 +04:00
|
|
|
nsCOMPtr<nsIDOMDocument> domDoc;
|
|
|
|
|
|
|
|
if(!mContentWindow)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
nsCOMPtr<nsIDOMWindow> cwP = do_QueryReferent(mContentWindow);
|
|
|
|
if (!cwP) return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
cwP->GetDocument(getter_AddRefs(domDoc));
|
|
|
|
//mContentWindow->GetDocument(getter_AddRefs(domDoc));
|
|
|
|
|
2000-05-10 03:03:41 +04:00
|
|
|
if (!domDoc) return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMElement> rootElement;
|
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(mEditor);
|
|
|
|
nsresult rv = editor->GetRootElement(getter_AddRefs(rootElement));
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMEventReceiver> erP;
|
2000-05-10 17:56:30 +04:00
|
|
|
rv = rootElement->QueryInterface(NS_GET_IID(nsIDOMEventReceiver), getter_AddRefs(erP));
|
2000-05-10 03:03:41 +04:00
|
|
|
|
|
|
|
if (erP)
|
|
|
|
{
|
|
|
|
*aEventReceiver = erP;
|
|
|
|
NS_ADDREF(*aEventReceiver);
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-13 19:37:58 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::SetContentWindow(nsIDOMWindow* aWin)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aWin != nsnull, "null ptr");
|
|
|
|
if (!aWin)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
2000-05-14 09:27:17 +04:00
|
|
|
mContentWindow = getter_AddRefs( NS_GetWeakReference(aWin) ); // weak reference to aWin
|
|
|
|
//mContentWindow = aWin;
|
1999-11-13 19:37:58 +03:00
|
|
|
|
|
|
|
nsresult rv;
|
2000-05-14 09:27:17 +04:00
|
|
|
nsCOMPtr<nsIScriptGlobalObject> globalObj = do_QueryReferent(mContentWindow, &rv);
|
1999-11-13 19:37:58 +03:00
|
|
|
if (NS_FAILED(rv) || !globalObj)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2000-02-08 16:40:10 +03:00
|
|
|
nsCOMPtr<nsIDocShell> docShell;
|
|
|
|
globalObj->GetDocShell(getter_AddRefs(docShell));
|
2000-04-12 03:48:14 +04:00
|
|
|
if (!docShell)
|
1999-11-13 19:37:58 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2000-04-12 03:48:14 +04:00
|
|
|
mContentAreaDocShell = docShell; // dont AddRef
|
2000-05-02 01:49:52 +04:00
|
|
|
rv = docShell->SetDocLoaderObserver((nsIDocumentLoaderObserver *)this);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
// we make two controllers
|
|
|
|
nsCOMPtr<nsIControllers> controllers;
|
2000-05-14 09:27:17 +04:00
|
|
|
if(!mContentWindow)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
nsCOMPtr<nsIDOMWindow> cwP = do_QueryReferent(mContentWindow);
|
|
|
|
if (!cwP) return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
cwP->GetControllers(getter_AddRefs(controllers));
|
|
|
|
//rv = mContentWindow->GetControllers(getter_AddRefs(controllers));
|
2000-05-02 01:49:52 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
{
|
|
|
|
// the first is an editor controller, and takes an nsIEditor as the refCon
|
|
|
|
nsCOMPtr<nsIController> controller = do_CreateInstance("component://netscape/editor/editorcontroller", &rv);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
nsCOMPtr<nsIEditorController> editorController = do_QueryInterface(controller);
|
|
|
|
rv = editorController->Init(nsnull); // we set the editor later when we have one
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
mEditorController = editorController; // temp weak link, so we can get it and set the editor later
|
|
|
|
|
2000-05-10 03:03:41 +04:00
|
|
|
rv = controllers->InsertControllerAt(eEditorController, controller);
|
2000-05-02 01:49:52 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2000-05-10 03:03:41 +04:00
|
|
|
// the second is a composer controller, and takes an nsIEditorShell as the refCon
|
2000-05-02 01:49:52 +04:00
|
|
|
nsCOMPtr<nsIController> controller = do_CreateInstance("component://netscape/editor/composercontroller", &rv);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
nsCOMPtr<nsIEditorController> editorController = do_QueryInterface(controller);
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> shellAsISupports = do_QueryInterface((nsIEditorShell*)this);
|
|
|
|
rv = editorController->Init(shellAsISupports);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2000-05-10 03:03:41 +04:00
|
|
|
rv = controllers->InsertControllerAt(eComposerController, controller);
|
2000-05-02 01:49:52 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::GetContentWindow(nsIDOMWindow * *aContentWindow)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aContentWindow);
|
2000-05-14 09:27:17 +04:00
|
|
|
|
|
|
|
if(!mContentWindow)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
nsCOMPtr<nsIDOMWindow> cwP = do_QueryReferent(mContentWindow);
|
|
|
|
if (!cwP)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
|
|
|
NS_IF_ADDREF(*aContentWindow = cwP);
|
2000-05-02 01:49:52 +04:00
|
|
|
return NS_OK;
|
1999-11-13 19:37:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::SetWebShellWindow(nsIDOMWindow* aWin)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aWin != nsnull, "null ptr");
|
|
|
|
if (!aWin)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
2000-05-02 01:49:52 +04:00
|
|
|
mWebShellWindow = aWin; // no addref
|
|
|
|
|
1999-11-13 19:37:58 +03:00
|
|
|
nsCOMPtr<nsIScriptGlobalObject> globalObj( do_QueryInterface(aWin) );
|
|
|
|
if (!globalObj) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
2000-02-08 16:40:10 +03:00
|
|
|
nsCOMPtr<nsIDocShell> docShell;
|
|
|
|
globalObj->GetDocShell(getter_AddRefs(docShell));
|
2000-04-12 03:48:14 +04:00
|
|
|
if (!docShell)
|
1999-11-13 19:37:58 +03:00
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
2000-04-12 03:48:14 +04:00
|
|
|
mDocShell = docShell;
|
2000-03-31 06:13:00 +04:00
|
|
|
|
|
|
|
/*
|
1999-11-13 19:37:58 +03:00
|
|
|
#ifdef APP_DEBUG
|
2000-03-11 04:00:48 +03:00
|
|
|
nsXPIDLString name;
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> docShellAsItem(do_QueryInterface(docShell));
|
|
|
|
docShellAsItem->GetName(getter_Copies(name));
|
1999-11-13 19:37:58 +03:00
|
|
|
nsAutoString str(name);
|
|
|
|
|
|
|
|
char* cstr = str.ToNewCString();
|
|
|
|
printf("Attaching to WebShellWindow[%s]\n", cstr);
|
|
|
|
nsCRT::free(cstr);
|
|
|
|
#endif
|
2000-03-31 06:13:00 +04:00
|
|
|
*/
|
1999-11-13 19:37:58 +03:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2000-05-02 01:49:52 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::GetWebShellWindow(nsIDOMWindow * *aWebShellWindow)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aWebShellWindow);
|
|
|
|
NS_IF_ADDREF(*aWebShellWindow = mWebShellWindow);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-06-11 03:50:26 +04:00
|
|
|
// tell the appcore what type of editor to instantiate
|
|
|
|
// this must be called before the editor has been instantiated,
|
|
|
|
// otherwise, an error is returned.
|
|
|
|
NS_METHOD
|
|
|
|
nsEditorShell::SetEditorType(const PRUnichar *editorType)
|
|
|
|
{
|
|
|
|
if (mEditor)
|
|
|
|
return NS_ERROR_ALREADY_INITIALIZED;
|
|
|
|
|
|
|
|
nsAutoString theType = editorType;
|
|
|
|
theType.ToLowerCase();
|
2000-05-02 07:24:11 +04:00
|
|
|
|
|
|
|
PRBool textMail = theType.EqualsWithConversion("textmail");
|
|
|
|
mMailCompose = theType.EqualsWithConversion("htmlmail") || textMail;
|
|
|
|
|
|
|
|
if (mMailCompose ||theType.EqualsWithConversion("text") || theType.EqualsWithConversion("html") || theType.IsEmpty())
|
1999-06-11 03:50:26 +04:00
|
|
|
{
|
2000-05-02 07:24:11 +04:00
|
|
|
// We don't store a separate type for textmail
|
|
|
|
if (textMail)
|
|
|
|
mEditorTypeString = NS_ConvertASCIItoUCS2("text");
|
|
|
|
else
|
|
|
|
mEditorTypeString = theType;
|
1999-06-11 03:50:26 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NS_WARNING("Editor type not recognized");
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-04-04 05:06:25 +04:00
|
|
|
nsresult
|
1999-06-11 03:50:26 +04:00
|
|
|
nsEditorShell::InstantiateEditor(nsIDOMDocument *aDoc, nsIPresShell *aPresShell)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aDoc && aPresShell, "null ptr");
|
|
|
|
if (!aDoc || !aPresShell)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
if (mEditor)
|
|
|
|
return NS_ERROR_ALREADY_INITIALIZED;
|
1999-11-11 02:40:38 +03:00
|
|
|
|
1999-06-11 03:50:26 +04:00
|
|
|
nsresult err = NS_OK;
|
|
|
|
|
1999-08-09 05:37:50 +04:00
|
|
|
nsCOMPtr<nsIEditor> editor;
|
2000-01-11 23:49:15 +03:00
|
|
|
err = nsComponentManager::CreateInstance(kHTMLEditorCID, nsnull, NS_GET_IID(nsIEditor), getter_AddRefs(editor));
|
1999-08-09 05:37:50 +04:00
|
|
|
if(!editor)
|
|
|
|
err = NS_ERROR_OUT_OF_MEMORY;
|
2000-04-28 10:20:36 +04:00
|
|
|
nsCOMPtr<nsISelectionController> selCon = do_QueryInterface(aPresShell);
|
|
|
|
|
1999-08-09 05:37:50 +04:00
|
|
|
if (NS_SUCCEEDED(err))
|
1999-06-11 03:50:26 +04:00
|
|
|
{
|
2000-04-18 11:44:58 +04:00
|
|
|
if (mEditorTypeString.EqualsWithConversion("text"))
|
1999-06-11 03:50:26 +04:00
|
|
|
{
|
2000-05-04 12:33:48 +04:00
|
|
|
err = editor->Init(aDoc, aPresShell, nsnull, selCon, nsIHTMLEditor::eEditorPlaintextMask);
|
1999-11-11 02:40:38 +03:00
|
|
|
mEditorType = ePlainTextEditorType;
|
1999-09-08 10:26:53 +04:00
|
|
|
}
|
2000-04-18 11:44:58 +04:00
|
|
|
else if (mEditorTypeString.EqualsWithConversion("html") || mEditorTypeString.IsEmpty()) // empty string default to HTML editor
|
1999-06-11 03:50:26 +04:00
|
|
|
{
|
2000-05-04 12:33:48 +04:00
|
|
|
err = editor->Init(aDoc, aPresShell, nsnull, selCon, 0);
|
1999-11-11 02:40:38 +03:00
|
|
|
mEditorType = eHTMLTextEditorType;
|
1999-09-08 10:26:53 +04:00
|
|
|
}
|
2000-04-18 11:44:58 +04:00
|
|
|
else if (mEditorTypeString.EqualsWithConversion("htmlmail")) // HTML editor with special mail rules
|
1999-09-08 10:26:53 +04:00
|
|
|
{
|
2000-05-04 12:33:48 +04:00
|
|
|
err = editor->Init(aDoc, aPresShell, nsnull, selCon, nsIHTMLEditor::eEditorMailMask);
|
1999-11-11 02:40:38 +03:00
|
|
|
mEditorType = eHTMLTextEditorType;
|
1999-09-08 10:26:53 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
err = NS_ERROR_INVALID_ARG; // this is not an editor we know about
|
1999-06-11 03:50:26 +04:00
|
|
|
#if DEBUG
|
2000-04-18 11:44:58 +04:00
|
|
|
nsAutoString errorMsg; errorMsg.AssignWithConversion("Failed to init editor. Unknown editor type \"");
|
1999-09-08 10:26:53 +04:00
|
|
|
errorMsg += mEditorTypeString;
|
2000-04-18 11:44:58 +04:00
|
|
|
errorMsg.AppendWithConversion("\"\n");
|
1999-09-08 10:26:53 +04:00
|
|
|
char *errorMsgCString = errorMsg.ToNewCString();
|
|
|
|
NS_WARNING(errorMsgCString);
|
|
|
|
nsCRT::free(errorMsgCString);
|
1999-06-11 03:50:26 +04:00
|
|
|
#endif
|
1999-09-08 10:26:53 +04:00
|
|
|
}
|
1999-08-09 05:37:50 +04:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(err) && editor)
|
|
|
|
{
|
1999-09-08 10:26:53 +04:00
|
|
|
mEditor = do_QueryInterface(editor); // this does the addref that is the owning reference
|
1999-08-09 05:37:50 +04:00
|
|
|
}
|
1999-06-11 03:50:26 +04:00
|
|
|
}
|
1999-07-15 02:30:39 +04:00
|
|
|
|
1999-06-11 03:50:26 +04:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-04-04 05:06:25 +04:00
|
|
|
nsresult
|
2000-04-12 03:48:14 +04:00
|
|
|
nsEditorShell::DoEditorMode(nsIDocShell *aDocShell)
|
1999-06-11 03:50:26 +04:00
|
|
|
{
|
|
|
|
nsresult err = NS_OK;
|
|
|
|
|
2000-04-12 03:48:14 +04:00
|
|
|
NS_PRECONDITION(aDocShell, "Need a webshell here");
|
|
|
|
if (!aDocShell)
|
1999-06-11 03:50:26 +04:00
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
2000-03-31 06:13:00 +04:00
|
|
|
nsCOMPtr<nsIDocument> doc;
|
2000-04-12 03:48:14 +04:00
|
|
|
err = GetDocument(aDocShell, getter_AddRefs(doc));
|
2000-04-04 05:06:25 +04:00
|
|
|
if (NS_FAILED(err)) return err;
|
|
|
|
if (!doc) return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMDocument> domDoc = do_QueryInterface(doc, &err);
|
|
|
|
if (NS_FAILED(err)) return err;
|
|
|
|
if (!domDoc) return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPresShell> presShell;
|
2000-04-12 03:48:14 +04:00
|
|
|
err = aDocShell->GetPresShell(getter_AddRefs(presShell));
|
2000-04-04 05:06:25 +04:00
|
|
|
if (NS_FAILED(err)) return err;
|
|
|
|
if (!presShell) return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
return InstantiateEditor(domDoc, presShell);
|
1999-06-11 03:50:26 +04:00
|
|
|
}
|
|
|
|
|
1999-09-22 05:20:24 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-05-02 01:49:52 +04:00
|
|
|
nsEditorShell::UpdateInterfaceState(const PRUnichar *tagToUpdate)
|
1999-09-22 05:20:24 +04:00
|
|
|
{
|
|
|
|
if (!mStateMaintainer)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
1999-11-11 02:40:38 +03:00
|
|
|
|
2000-05-02 01:49:52 +04:00
|
|
|
return mStateMaintainer->ForceUpdate(tagToUpdate);
|
1999-09-22 05:20:24 +04:00
|
|
|
}
|
|
|
|
|
1999-11-25 07:11:51 +03:00
|
|
|
// Deletion routines
|
|
|
|
nsresult
|
|
|
|
nsEditorShell::ScrollSelectionIntoView()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(mEditor);
|
|
|
|
if (!editor) return NS_ERROR_NOT_INITIALIZED;
|
2000-04-27 11:37:12 +04:00
|
|
|
nsCOMPtr<nsISelectionController> selCon;
|
|
|
|
editor->GetSelectionController(getter_AddRefs(selCon));
|
|
|
|
if (!selCon)
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
return selCon->ScrollSelectionIntoView(nsISelectionController::SELECTION_NORMAL,
|
|
|
|
nsISelectionController::SELECTION_FOCUS_REGION);
|
1999-11-25 07:11:51 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::DeleteCharForward()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(mEditor);
|
|
|
|
if (!editor) return NS_ERROR_NOT_INITIALIZED;
|
1999-12-07 11:30:19 +03:00
|
|
|
nsresult rv = editor->DeleteSelection(nsIEditor::eNext);
|
1999-11-25 07:11:51 +03:00
|
|
|
ScrollSelectionIntoView();
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::DeleteCharBackward()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(mEditor);
|
|
|
|
if (!editor) return NS_ERROR_NOT_INITIALIZED;
|
1999-12-07 11:30:19 +03:00
|
|
|
nsresult rv = editor->DeleteSelection(nsIEditor::ePrevious);
|
1999-11-25 07:11:51 +03:00
|
|
|
ScrollSelectionIntoView();
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::DeleteWordForward()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(mEditor);
|
|
|
|
if (!editor) return NS_ERROR_NOT_INITIALIZED;
|
1999-12-07 11:30:19 +03:00
|
|
|
nsresult rv = editor->DeleteSelection(nsIEditor::eNextWord);
|
1999-11-25 07:11:51 +03:00
|
|
|
ScrollSelectionIntoView();
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::DeleteWordBackward()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(mEditor);
|
|
|
|
if (!editor) return NS_ERROR_NOT_INITIALIZED;
|
1999-12-07 11:30:19 +03:00
|
|
|
nsresult rv = editor->DeleteSelection(nsIEditor::ePreviousWord);
|
1999-11-25 07:11:51 +03:00
|
|
|
ScrollSelectionIntoView();
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::DeleteToEndOfLine()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(mEditor);
|
|
|
|
if (!editor) return NS_ERROR_NOT_INITIALIZED;
|
1999-12-07 11:30:19 +03:00
|
|
|
nsresult rv = editor->DeleteSelection(nsIEditor::eToEndOfLine);
|
1999-11-25 07:11:51 +03:00
|
|
|
ScrollSelectionIntoView();
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2000-01-04 23:38:12 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::DeleteToBeginningOfLine()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(mEditor);
|
|
|
|
if (!editor) return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
nsresult rv = editor->DeleteSelection(nsIEditor::eToBeginningOfLine);
|
|
|
|
ScrollSelectionIntoView();
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-10-14 04:13:27 +04:00
|
|
|
// Generic attribute setting and removal
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::SetAttribute(nsIDOMElement *element, const PRUnichar *attr, const PRUnichar *value)
|
|
|
|
{
|
|
|
|
if (!element || !attr || !value)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
nsresult result = NS_NOINTERFACE;
|
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(mEditor);
|
|
|
|
if (editor) {
|
|
|
|
nsAutoString attributeStr(attr);
|
|
|
|
nsAutoString valueStr(value);
|
|
|
|
result = editor->SetAttribute(element, attributeStr, valueStr);
|
|
|
|
}
|
2000-05-02 01:49:52 +04:00
|
|
|
UpdateInterfaceState(nsnull);
|
1999-10-14 04:13:27 +04:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::RemoveAttribute(nsIDOMElement *element, const PRUnichar *attr)
|
|
|
|
{
|
|
|
|
if (!element || !attr)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
nsresult result = NS_NOINTERFACE;
|
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(mEditor);
|
|
|
|
if (editor) {
|
|
|
|
nsAutoString attributeStr(attr);
|
|
|
|
result = editor->RemoveAttribute(element, attributeStr);
|
|
|
|
}
|
2000-05-02 01:49:52 +04:00
|
|
|
UpdateInterfaceState(nsnull);
|
1999-10-14 04:13:27 +04:00
|
|
|
return result;
|
|
|
|
}
|
1999-09-22 05:20:24 +04:00
|
|
|
|
1999-06-11 03:50:26 +04:00
|
|
|
// the name of the attribute here should be the contents of the appropriate
|
|
|
|
// tag, e.g. 'b' for bold, 'i' for italics.
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::SetTextProperty(const PRUnichar *prop, const PRUnichar *attr, const PRUnichar *value)
|
|
|
|
{
|
|
|
|
nsresult err = NS_NOINTERFACE;
|
|
|
|
|
2000-05-02 01:49:52 +04:00
|
|
|
nsCOMPtr<nsIAtom> styleAtom = getter_AddRefs(NS_NewAtom(prop)); /// XXX Hack alert! Look in nsIEditProperty.h for this
|
|
|
|
if (! styleAtom) return NS_ERROR_OUT_OF_MEMORY;
|
1999-06-11 03:50:26 +04:00
|
|
|
|
1999-09-08 10:26:53 +04:00
|
|
|
nsAutoString attributeStr(attr);
|
|
|
|
nsAutoString valueStr(value);
|
1999-06-11 03:50:26 +04:00
|
|
|
|
|
|
|
switch (mEditorType)
|
|
|
|
{
|
|
|
|
case ePlainTextEditorType:
|
|
|
|
// should we allow this?
|
|
|
|
case eHTMLTextEditorType:
|
1999-08-09 05:37:50 +04:00
|
|
|
err = mEditor->SetInlineProperty(styleAtom, &attributeStr, &valueStr);
|
1999-06-11 03:50:26 +04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
err = NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
2000-05-02 01:49:52 +04:00
|
|
|
|
|
|
|
UpdateInterfaceState(prop);
|
1999-06-11 03:50:26 +04:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2000-04-04 05:06:25 +04:00
|
|
|
nsresult
|
1999-06-11 03:50:26 +04:00
|
|
|
nsEditorShell::RemoveOneProperty(const nsString& aProp, const nsString &aAttr)
|
|
|
|
{
|
|
|
|
nsresult err = NS_NOINTERFACE;
|
|
|
|
|
2000-05-02 01:49:52 +04:00
|
|
|
nsCOMPtr<nsIAtom> styleAtom = getter_AddRefs(NS_NewAtom(aProp)); /// XXX Hack alert! Look in nsIEditProperty.h for this
|
|
|
|
if (! styleAtom) return NS_ERROR_OUT_OF_MEMORY;
|
1999-06-11 03:50:26 +04:00
|
|
|
|
|
|
|
switch (mEditorType)
|
|
|
|
{
|
|
|
|
case ePlainTextEditorType:
|
|
|
|
// should we allow this?
|
|
|
|
case eHTMLTextEditorType:
|
1999-08-09 05:37:50 +04:00
|
|
|
err = mEditor->RemoveInlineProperty(styleAtom, &aAttr);
|
1999-06-11 03:50:26 +04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
err = NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2000-05-02 01:49:52 +04:00
|
|
|
UpdateInterfaceState(aProp.GetUnicode());
|
1999-06-11 03:50:26 +04:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// the name of the attribute here should be the contents of the appropriate
|
|
|
|
// tag, e.g. 'b' for bold, 'i' for italics.
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::RemoveTextProperty(const PRUnichar *prop, const PRUnichar *attr)
|
|
|
|
{
|
2000-04-14 01:50:19 +04:00
|
|
|
// OK, I'm really hacking now. This is just so that we can accept 'all' as input.
|
1999-06-11 03:50:26 +04:00
|
|
|
nsAutoString allStr(prop);
|
1999-09-08 10:26:53 +04:00
|
|
|
nsAutoString aAttr(attr);
|
1999-06-11 03:50:26 +04:00
|
|
|
|
|
|
|
allStr.ToLowerCase();
|
2000-04-18 11:44:58 +04:00
|
|
|
PRBool doingAll = (allStr.EqualsWithConversion("all"));
|
1999-06-11 03:50:26 +04:00
|
|
|
nsresult err = NS_OK;
|
|
|
|
|
|
|
|
if (doingAll)
|
|
|
|
{
|
2000-04-14 01:50:19 +04:00
|
|
|
err = mEditor->RemoveAllInlineProperties();
|
1999-06-11 03:50:26 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
1999-09-08 10:26:53 +04:00
|
|
|
nsAutoString aProp(prop);
|
1999-06-11 03:50:26 +04:00
|
|
|
err = RemoveOneProperty(aProp, aAttr);
|
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-08-02 02:37:58 +04:00
|
|
|
nsEditorShell::GetTextProperty(const PRUnichar *prop, const PRUnichar *attr, const PRUnichar *value, PRBool *firstHas, PRBool *anyHas, PRBool *allHas)
|
1999-06-11 03:50:26 +04:00
|
|
|
{
|
|
|
|
nsIAtom *styleAtom = nsnull;
|
|
|
|
nsresult err = NS_NOINTERFACE;
|
|
|
|
|
|
|
|
styleAtom = NS_NewAtom(prop); /// XXX Hack alert! Look in nsIEditProperty.h for this
|
|
|
|
|
|
|
|
nsAutoString aAttr(attr);
|
|
|
|
nsAutoString aValue(value);
|
|
|
|
|
|
|
|
switch (mEditorType)
|
|
|
|
{
|
|
|
|
case ePlainTextEditorType:
|
|
|
|
// should we allow this?
|
|
|
|
case eHTMLTextEditorType:
|
1999-08-09 05:37:50 +04:00
|
|
|
err = mEditor->GetInlineProperty(styleAtom, &aAttr, &aValue, *firstHas, *anyHas, *allHas);
|
1999-06-11 03:50:26 +04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
err = NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
NS_RELEASE(styleAtom);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
1999-11-13 19:37:58 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::IncreaseFontSize()
|
|
|
|
{
|
|
|
|
nsresult err = NS_NOINTERFACE;
|
|
|
|
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
|
|
|
|
|
|
|
|
if (htmlEditor)
|
|
|
|
err = htmlEditor->IncreaseFontSize();
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::DecreaseFontSize()
|
|
|
|
{
|
|
|
|
nsresult err = NS_NOINTERFACE;
|
|
|
|
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
|
|
|
|
|
|
|
|
if (htmlEditor)
|
|
|
|
err = htmlEditor->DecreaseFontSize();
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::SetBackgroundColor(const PRUnichar *color)
|
1999-06-11 03:50:26 +04:00
|
|
|
{
|
|
|
|
nsresult result = NS_NOINTERFACE;
|
|
|
|
|
|
|
|
nsAutoString aColor(color);
|
|
|
|
|
1999-08-09 05:37:50 +04:00
|
|
|
result = mEditor->SetBackgroundColor(aColor);
|
1999-06-11 03:50:26 +04:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1999-11-13 19:37:58 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::ApplyStyleSheet(const PRUnichar *url)
|
1999-07-01 23:32:35 +04:00
|
|
|
{
|
|
|
|
nsresult result = NS_NOINTERFACE;
|
|
|
|
|
|
|
|
nsAutoString aURL(url);
|
|
|
|
|
1999-09-30 01:45:50 +04:00
|
|
|
nsCOMPtr<nsIEditorStyleSheets> styleSheets = do_QueryInterface(mEditor);
|
|
|
|
if (styleSheets)
|
2000-03-31 08:18:29 +04:00
|
|
|
result = styleSheets->ApplyStyleSheet(aURL, nsnull);
|
1999-07-01 23:32:35 +04:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1999-09-30 01:45:50 +04:00
|
|
|
// Note: This is not undoable action (on purpose!)
|
1999-11-13 19:37:58 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::SetDisplayMode(PRInt32 aDisplayMode)
|
1999-09-30 01:45:50 +04:00
|
|
|
{
|
2000-05-04 18:02:03 +04:00
|
|
|
// Reqesting SourceMode and we are already doing that
|
2000-05-02 07:24:11 +04:00
|
|
|
if (aDisplayMode == eDisplayModeSource && mDisplayMode == eDisplayModeSource)
|
|
|
|
return NS_OK;
|
|
|
|
|
2000-05-04 18:02:03 +04:00
|
|
|
// The rest of the HTML Source display work is in EditorCommand.js
|
2000-05-02 07:24:11 +04:00
|
|
|
|
2000-03-31 08:18:29 +04:00
|
|
|
nsCOMPtr<nsIEditorStyleSheets> styleSheets = do_QueryInterface(mEditor);
|
|
|
|
if (!styleSheets) return NS_NOINTERFACE;
|
1999-09-30 01:45:50 +04:00
|
|
|
|
2000-05-02 07:24:11 +04:00
|
|
|
mDisplayMode = aDisplayMode;
|
|
|
|
|
|
|
|
if (aDisplayMode == eDisplayModePreview)
|
1999-09-30 01:45:50 +04:00
|
|
|
{
|
2000-04-14 07:19:31 +04:00
|
|
|
// Remove all extra "edit mode" style sheets
|
|
|
|
if (mEditModeStyleSheet)
|
|
|
|
{
|
|
|
|
styleSheets->RemoveOverrideStyleSheet(mEditModeStyleSheet);
|
|
|
|
mEditModeStyleSheet = nsnull;
|
|
|
|
}
|
|
|
|
if (mAllTagsModeStyleSheet)
|
|
|
|
{
|
|
|
|
styleSheets->RemoveOverrideStyleSheet(mAllTagsModeStyleSheet);
|
|
|
|
mAllTagsModeStyleSheet = nsnull;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (aDisplayMode == eDisplayModeNormal)
|
|
|
|
{
|
|
|
|
// Remove the AllTags sheet
|
|
|
|
if (mAllTagsModeStyleSheet)
|
|
|
|
{
|
|
|
|
styleSheets->RemoveOverrideStyleSheet(mAllTagsModeStyleSheet);
|
|
|
|
mAllTagsModeStyleSheet = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We are already in the requested mode
|
2000-03-31 08:18:29 +04:00
|
|
|
if (mEditModeStyleSheet) return NS_OK;
|
|
|
|
|
|
|
|
//Load the editmode style sheet
|
2000-05-02 07:24:11 +04:00
|
|
|
return styleSheets->ApplyOverrideStyleSheet(NS_ConvertASCIItoUCS2("chrome://editor/content/EditorContent.css"),
|
|
|
|
getter_AddRefs(mEditModeStyleSheet));
|
2000-03-31 08:18:29 +04:00
|
|
|
}
|
2000-04-14 07:19:31 +04:00
|
|
|
else if (aDisplayMode == eDisplayModeAllTags)
|
2000-03-31 08:18:29 +04:00
|
|
|
{
|
2000-04-14 07:19:31 +04:00
|
|
|
// We are already in the requested mode
|
|
|
|
if (mAllTagsModeStyleSheet) return NS_OK;
|
|
|
|
|
|
|
|
//Load the normal mode style sheet
|
|
|
|
if (!mEditModeStyleSheet)
|
1999-09-30 01:45:50 +04:00
|
|
|
{
|
2000-04-14 07:19:31 +04:00
|
|
|
// Note: using "@import url(chrome://editor/content/EditorContent.css);"
|
|
|
|
// in EditorAllTags.css doesn't seem to work!?
|
2000-05-02 07:24:11 +04:00
|
|
|
styleSheets->ApplyOverrideStyleSheet(NS_ConvertASCIItoUCS2("chrome://editor/content/EditorContent.css"),
|
|
|
|
getter_AddRefs(mEditModeStyleSheet));
|
2000-03-31 08:18:29 +04:00
|
|
|
}
|
2000-04-14 07:19:31 +04:00
|
|
|
|
2000-05-02 07:24:11 +04:00
|
|
|
return styleSheets->ApplyOverrideStyleSheet(NS_ConvertASCIItoUCS2("chrome://editor/content/EditorAllTags.css"),
|
|
|
|
getter_AddRefs(mAllTagsModeStyleSheet));
|
2000-03-31 08:18:29 +04:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-09-30 01:45:50 +04:00
|
|
|
|
2000-03-31 08:18:29 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::DisplayParagraphMarks(PRBool aShowMarks)
|
|
|
|
{
|
|
|
|
nsresult res = NS_OK;
|
2000-03-31 06:13:00 +04:00
|
|
|
|
2000-03-31 08:18:29 +04:00
|
|
|
nsCOMPtr<nsIEditorStyleSheets> styleSheets = do_QueryInterface(mEditor);
|
|
|
|
if (!styleSheets) return NS_NOINTERFACE;
|
|
|
|
|
|
|
|
if (aShowMarks)
|
|
|
|
{
|
|
|
|
// Check if style sheet is already loaded
|
|
|
|
if (mParagraphMarksStyleSheet) return NS_OK;
|
1999-09-30 01:45:50 +04:00
|
|
|
|
2000-03-31 08:18:29 +04:00
|
|
|
//Load the style sheet
|
|
|
|
nsCOMPtr<nsICSSStyleSheet> styleSheet;
|
2000-04-18 11:44:58 +04:00
|
|
|
res = styleSheets->ApplyOverrideStyleSheet(NS_ConvertASCIItoUCS2("chrome://editor/content/EditorParagraphMarks.css"),
|
2000-05-02 07:24:11 +04:00
|
|
|
getter_AddRefs(mParagraphMarksStyleSheet));
|
1999-09-30 01:45:50 +04:00
|
|
|
}
|
2000-03-31 08:18:29 +04:00
|
|
|
else if (mParagraphMarksStyleSheet)
|
|
|
|
{
|
|
|
|
res = styleSheets->RemoveOverrideStyleSheet(mParagraphMarksStyleSheet);
|
|
|
|
mParagraphMarksStyleSheet = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
1999-09-30 01:45:50 +04:00
|
|
|
}
|
|
|
|
|
1999-11-13 19:37:58 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::SetBodyAttribute(const PRUnichar *attr, const PRUnichar *value)
|
1999-06-11 03:50:26 +04:00
|
|
|
{
|
|
|
|
nsresult result = NS_NOINTERFACE;
|
|
|
|
|
|
|
|
nsAutoString aAttr(attr);
|
|
|
|
nsAutoString aValue(value);
|
|
|
|
|
|
|
|
switch (mEditorType)
|
|
|
|
{
|
|
|
|
case eHTMLTextEditorType:
|
|
|
|
{
|
1999-08-09 05:37:50 +04:00
|
|
|
result = mEditor->SetBodyAttribute(aAttr, aValue);
|
1999-06-11 03:50:26 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
result = NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::LoadUrl(const PRUnichar *url)
|
|
|
|
{
|
2000-05-03 01:46:23 +04:00
|
|
|
if(!mContentAreaDocShell)
|
2000-05-02 07:24:11 +04:00
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
2000-03-11 04:00:48 +03:00
|
|
|
|
2000-05-06 03:19:08 +04:00
|
|
|
nsresult rv = ResetEditingState();
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
2000-05-03 01:46:23 +04:00
|
|
|
|
2000-05-02 07:24:11 +04:00
|
|
|
nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(mContentAreaDocShell));
|
|
|
|
NS_ENSURE_SUCCESS(webNav->LoadURI(url), NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
return NS_OK;
|
1999-06-11 03:50:26 +04:00
|
|
|
}
|
|
|
|
|
1999-08-03 04:57:57 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::RegisterDocumentStateListener(nsIDocumentStateListener *docListener)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
if (!docListener)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
// if we have an editor already, just pass this baby through.
|
|
|
|
if (mEditor)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(mEditor, &rv);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
return editor->AddDocumentStateListener(docListener);
|
|
|
|
}
|
|
|
|
|
|
|
|
// otherwise, keep it until we create an editor.
|
|
|
|
if (!mDocStateListeners)
|
|
|
|
{
|
|
|
|
rv = NS_NewISupportsArray(getter_AddRefs(mDocStateListeners));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsISupports> iSupports = do_QueryInterface(docListener, &rv);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
// note that this return value is really a PRBool, so be sure to use
|
|
|
|
// NS_SUCCEEDED or NS_FAILED to check it.
|
|
|
|
return mDocStateListeners->AppendElement(iSupports);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::UnregisterDocumentStateListener(nsIDocumentStateListener *docListener)
|
|
|
|
{
|
|
|
|
if (!docListener)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
// if we have an editor already, just pass this baby through.
|
|
|
|
if (mEditor)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(mEditor, &rv);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
return editor->RemoveDocumentStateListener(docListener);
|
|
|
|
}
|
|
|
|
|
|
|
|
// otherwise, see if it exists in our list
|
|
|
|
if (!mDocStateListeners)
|
|
|
|
return (nsresult)PR_FALSE; // yeah, this sucks, but I'm emulating the behaviour of
|
|
|
|
// nsISupportsArray::RemoveElement()
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> iSupports = do_QueryInterface(docListener, &rv);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
// note that this return value is really a PRBool, so be sure to use
|
|
|
|
// NS_SUCCEEDED or NS_FAILED to check it.
|
|
|
|
return mDocStateListeners->RemoveElement(iSupports);
|
|
|
|
}
|
|
|
|
|
|
|
|
// called after making an editor. Transfer the nsIDOcumentStateListeners
|
|
|
|
// that we have been stashing in mDocStateListeners to the editor.
|
2000-04-04 05:06:25 +04:00
|
|
|
nsresult
|
1999-08-03 04:57:57 +04:00
|
|
|
nsEditorShell::TransferDocumentStateListeners()
|
|
|
|
{
|
|
|
|
if (!mDocStateListeners)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
if (!mEditor)
|
1999-09-08 10:26:53 +04:00
|
|
|
return NS_ERROR_NOT_INITIALIZED; // called too early.
|
1999-08-03 04:57:57 +04:00
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(mEditor, &rv);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
PRUint32 numListeners;
|
|
|
|
while (NS_SUCCEEDED(mDocStateListeners->Count(&numListeners)) && numListeners > 0)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsISupports> iSupports = getter_AddRefs(mDocStateListeners->ElementAt(0));
|
|
|
|
nsCOMPtr<nsIDocumentStateListener> docStateListener = do_QueryInterface(iSupports);
|
|
|
|
if (docStateListener)
|
|
|
|
{
|
|
|
|
// this checks for duplicates
|
|
|
|
rv = editor->AddDocumentStateListener(docStateListener);
|
|
|
|
}
|
|
|
|
|
|
|
|
mDocStateListeners->RemoveElementAt(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
// free the array
|
|
|
|
mDocStateListeners = 0;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-11-11 03:12:23 +03:00
|
|
|
NS_IMETHODIMP
|
1999-12-03 18:18:38 +03:00
|
|
|
nsEditorShell::CheckOpenWindowForURLMatch(const PRUnichar* inFileURL, nsIDOMWindow* inCheckWindow, PRBool *aDidFind)
|
1999-11-11 03:12:23 +03:00
|
|
|
{
|
1999-12-03 18:18:38 +03:00
|
|
|
if (!inCheckWindow) return NS_ERROR_NULL_POINTER;
|
|
|
|
*aDidFind = PR_FALSE;
|
1999-11-11 03:12:23 +03:00
|
|
|
|
2000-04-04 18:51:26 +04:00
|
|
|
|
1999-11-11 03:12:23 +03:00
|
|
|
// get an nsFileSpec from the URL
|
2000-04-04 18:51:26 +04:00
|
|
|
// This assumes inFileURL is "file://" format
|
2000-04-14 07:19:31 +04:00
|
|
|
nsFileURL fileURL(inFileURL);
|
|
|
|
nsFileSpec fileSpec(fileURL);
|
2000-04-04 18:51:26 +04:00
|
|
|
|
1999-12-03 18:18:38 +03:00
|
|
|
nsCOMPtr<nsIDOMWindow> contentWindow;
|
|
|
|
inCheckWindow->GetContent(getter_AddRefs(contentWindow));
|
|
|
|
if (contentWindow)
|
1999-11-11 03:12:23 +03:00
|
|
|
{
|
1999-12-03 18:18:38 +03:00
|
|
|
// get the content doc
|
|
|
|
nsCOMPtr<nsIDOMDocument> contentDoc;
|
|
|
|
contentWindow->GetDocument(getter_AddRefs(contentDoc));
|
|
|
|
if (contentDoc)
|
1999-11-11 03:12:23 +03:00
|
|
|
{
|
1999-12-03 18:18:38 +03:00
|
|
|
nsCOMPtr<nsIDiskDocument> diskDoc(do_QueryInterface(contentDoc));
|
|
|
|
if (diskDoc)
|
|
|
|
{
|
|
|
|
nsFileSpec docFileSpec;
|
|
|
|
if (NS_SUCCEEDED(diskDoc->GetFileSpec(docFileSpec)))
|
1999-11-11 03:12:23 +03:00
|
|
|
{
|
1999-12-03 18:18:38 +03:00
|
|
|
// is this the filespec we are looking for?
|
|
|
|
if (docFileSpec == fileSpec)
|
1999-11-11 03:12:23 +03:00
|
|
|
{
|
1999-12-03 18:18:38 +03:00
|
|
|
*aDidFind = PR_TRUE;
|
1999-11-11 03:12:23 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-06-11 03:50:26 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-12-03 18:18:38 +03:00
|
|
|
return NS_OK;
|
1999-06-11 03:50:26 +04:00
|
|
|
}
|
|
|
|
|
1999-08-31 04:51:23 +04:00
|
|
|
NS_IMETHODIMP
|
1999-10-27 03:13:00 +04:00
|
|
|
nsEditorShell::CheckAndSaveDocument(const PRUnichar *reasonToSave, PRBool *_retval)
|
1999-08-31 04:51:23 +04:00
|
|
|
{
|
|
|
|
*_retval = PR_FALSE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMDocument> theDoc;
|
|
|
|
nsresult rv = GetEditorDocument(getter_AddRefs(theDoc));
|
|
|
|
if (NS_SUCCEEDED(rv) && theDoc)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDiskDocument> diskDoc = do_QueryInterface(theDoc);
|
|
|
|
if (diskDoc)
|
|
|
|
{
|
|
|
|
PRInt32 modCount = 0;
|
|
|
|
diskDoc->GetModCount(&modCount);
|
|
|
|
|
|
|
|
// Return true unless user cancels an action
|
|
|
|
*_retval = PR_TRUE;
|
|
|
|
|
|
|
|
if (modCount > 0)
|
|
|
|
{
|
|
|
|
// Ask user if they want to save current changes
|
2000-03-20 18:44:32 +03:00
|
|
|
nsAutoString reasonToSaveStr(reasonToSave);
|
|
|
|
nsAutoString tmp1, tmp2, title;
|
2000-04-18 11:44:58 +04:00
|
|
|
GetBundleString(NS_ConvertASCIItoUCS2("Save"), tmp1);
|
|
|
|
GetBundleString(NS_ConvertASCIItoUCS2("DontSave"), tmp2);
|
2000-01-14 02:33:00 +03:00
|
|
|
GetDocumentTitleString(title);
|
2000-02-15 18:54:05 +03:00
|
|
|
// If title is empty, use "untitled"
|
|
|
|
if (title.Length() == 0)
|
2000-04-18 11:44:58 +04:00
|
|
|
GetBundleString(NS_ConvertASCIItoUCS2("untitled"), title);
|
2000-02-15 18:54:05 +03:00
|
|
|
|
2000-03-20 18:44:32 +03:00
|
|
|
nsAutoString saveMsg;
|
2000-04-18 11:44:58 +04:00
|
|
|
GetBundleString(NS_ConvertASCIItoUCS2("SaveFilePrompt"), saveMsg);
|
2000-04-21 10:56:47 +04:00
|
|
|
saveMsg.ReplaceSubstring(NS_ConvertASCIItoUCS2("%title%"), title);
|
|
|
|
saveMsg.ReplaceSubstring(NS_ConvertASCIItoUCS2("%reason%"), reasonToSaveStr);
|
1999-10-27 03:13:00 +04:00
|
|
|
|
2000-03-20 18:44:32 +03:00
|
|
|
nsAutoString saveDocString;
|
2000-04-18 11:44:58 +04:00
|
|
|
GetBundleString(NS_ConvertASCIItoUCS2("SaveDocument"), saveDocString);
|
2000-03-20 18:44:32 +03:00
|
|
|
EConfirmResult result = ConfirmWithCancel(saveDocString, saveMsg, &tmp1, &tmp2);
|
1999-09-03 05:23:19 +04:00
|
|
|
if (result == eCancel)
|
|
|
|
{
|
|
|
|
*_retval = PR_FALSE;
|
|
|
|
} else if (result == eYes)
|
1999-08-31 04:51:23 +04:00
|
|
|
{
|
|
|
|
// Either save to existing file or prompt for name (as for SaveAs)
|
1999-09-03 05:23:19 +04:00
|
|
|
// We don't continue if we failed to save file (_retval is set to FALSE)
|
1999-08-31 04:51:23 +04:00
|
|
|
rv = SaveDocument(PR_FALSE, PR_FALSE, _retval);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-08-28 06:40:18 +04:00
|
|
|
NS_IMETHODIMP
|
1999-08-31 04:51:23 +04:00
|
|
|
nsEditorShell::SaveDocument(PRBool saveAs, PRBool saveCopy, PRBool *_retval)
|
1999-06-11 03:50:26 +04:00
|
|
|
{
|
1999-08-28 06:40:18 +04:00
|
|
|
nsresult res = NS_NOINTERFACE;
|
1999-08-31 04:51:23 +04:00
|
|
|
*_retval = PR_FALSE;
|
|
|
|
|
1999-06-11 03:50:26 +04:00
|
|
|
switch (mEditorType)
|
|
|
|
{
|
|
|
|
case ePlainTextEditorType:
|
|
|
|
case eHTMLTextEditorType:
|
1999-08-28 06:40:18 +04:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(mEditor);
|
|
|
|
if (editor)
|
1999-06-11 03:50:26 +04:00
|
|
|
{
|
1999-08-28 06:40:18 +04:00
|
|
|
// get the document
|
|
|
|
nsCOMPtr<nsIDOMDocument> doc;
|
|
|
|
res = editor->GetDocument(getter_AddRefs(doc));
|
|
|
|
if (NS_FAILED(res)) return res;
|
|
|
|
if (!doc) return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDiskDocument> diskDoc = do_QueryInterface(doc);
|
|
|
|
if (!diskDoc)
|
|
|
|
return NS_ERROR_NO_INTERFACE;
|
|
|
|
|
|
|
|
// find out if the doc already has a fileSpec associated with it.
|
|
|
|
nsFileSpec docFileSpec;
|
1999-10-20 18:15:25 +04:00
|
|
|
PRBool noFileSpec = (diskDoc->GetFileSpec(docFileSpec) == NS_ERROR_NOT_INITIALIZED);
|
|
|
|
PRBool mustShowFileDialog = saveAs || noFileSpec;
|
1999-08-28 06:40:18 +04:00
|
|
|
PRBool replacing = !saveAs;
|
2000-03-25 05:41:19 +03:00
|
|
|
|
|
|
|
|
|
|
|
// Get existing document title
|
|
|
|
nsAutoString title;
|
|
|
|
nsCOMPtr<nsIDOMHTMLDocument> HTMLDoc = do_QueryInterface(doc);
|
|
|
|
if (!HTMLDoc) return NS_ERROR_FAILURE;
|
|
|
|
res = HTMLDoc->GetTitle(title);
|
|
|
|
if (NS_FAILED(res)) return res;
|
|
|
|
|
1999-08-28 06:40:18 +04:00
|
|
|
if (mustShowFileDialog)
|
|
|
|
{
|
2000-03-25 05:41:19 +03:00
|
|
|
// Prompt for title ONLY if existing title is empty
|
|
|
|
if ( title.Length() == 0)
|
1999-08-31 04:51:23 +04:00
|
|
|
{
|
2000-03-25 05:41:19 +03:00
|
|
|
// Use a "prompt" common dialog to get title string from user
|
|
|
|
NS_WITH_SERVICE(nsICommonDialogs, dialog, kCommonDialogsCID, &res);
|
|
|
|
if (NS_SUCCEEDED(res))
|
|
|
|
{
|
|
|
|
PRUnichar *titleUnicode;
|
2000-05-12 06:37:33 +04:00
|
|
|
nsAutoString captionStr, msgStr1, msgStr2;
|
2000-03-25 05:41:19 +03:00
|
|
|
|
2000-04-18 11:44:58 +04:00
|
|
|
GetBundleString(NS_ConvertASCIItoUCS2("DocumentTitle"), captionStr);
|
2000-05-12 06:37:33 +04:00
|
|
|
GetBundleString(NS_ConvertASCIItoUCS2("NeedDocTitle"), msgStr1);
|
|
|
|
GetBundleString(NS_ConvertASCIItoUCS2("DocTitleHelp"), msgStr2);
|
|
|
|
msgStr1 += NS_ConvertASCIItoUCS2("\n") + msgStr2;
|
2000-03-25 05:41:19 +03:00
|
|
|
|
|
|
|
PRBool retVal = PR_FALSE;
|
2000-05-14 09:27:17 +04:00
|
|
|
if(!mContentWindow)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
nsCOMPtr<nsIDOMWindow> cwP = do_QueryReferent(mContentWindow);
|
|
|
|
if (!cwP) return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
|
|
|
res = dialog->Prompt(cwP, captionStr.GetUnicode(), msgStr1.GetUnicode(),
|
2000-03-25 05:41:19 +03:00
|
|
|
title.GetUnicode(), &titleUnicode, &retVal);
|
|
|
|
|
|
|
|
if( retVal == PR_FALSE)
|
|
|
|
{
|
|
|
|
// This indicates Cancel was used -- don't continue saving
|
|
|
|
*_retval = PR_FALSE;
|
|
|
|
return NS_OK;
|
1999-08-31 04:51:23 +04:00
|
|
|
}
|
2000-03-25 05:41:19 +03:00
|
|
|
title = titleUnicode;
|
|
|
|
nsCRT::free(titleUnicode);
|
1999-08-31 04:51:23 +04:00
|
|
|
}
|
2000-04-21 18:55:54 +04:00
|
|
|
// This sets title in HTML node
|
|
|
|
SetDocumentTitle(title.GetUnicode());
|
2000-03-25 05:41:19 +03:00
|
|
|
}
|
1999-08-28 06:40:18 +04:00
|
|
|
|
2000-04-04 18:51:26 +04:00
|
|
|
// #if 0 Replace this with nsIFilePicker code
|
|
|
|
|
2000-03-25 05:41:19 +03:00
|
|
|
nsCOMPtr<nsIFileWidget> fileWidget;
|
|
|
|
res = nsComponentManager::CreateInstance(kCFileWidgetCID, nsnull,
|
|
|
|
NS_GET_IID(nsIFileWidget),
|
|
|
|
getter_AddRefs(fileWidget));
|
|
|
|
if (NS_SUCCEEDED(res) && fileWidget)
|
|
|
|
{
|
|
|
|
nsAutoString promptString;
|
2000-04-18 11:44:58 +04:00
|
|
|
GetBundleString(NS_ConvertASCIItoUCS2("SaveDocumentAs"), promptString);
|
2000-03-25 05:41:19 +03:00
|
|
|
|
|
|
|
nsString* titles = nsnull;
|
|
|
|
nsString* filters = nsnull;
|
|
|
|
nsString* nextTitle;
|
|
|
|
nsString* nextFilter;
|
|
|
|
nsAutoString HTMLFiles;
|
|
|
|
nsAutoString TextFiles;
|
|
|
|
nsAutoString fileName;
|
|
|
|
nsFileSpec parentPath;
|
|
|
|
|
|
|
|
titles = new nsString[3];
|
|
|
|
if (!titles)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
filters = new nsString[3];
|
|
|
|
if (!filters)
|
1999-09-08 10:26:53 +04:00
|
|
|
{
|
2000-03-25 05:41:19 +03:00
|
|
|
delete [] titles;
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
nextTitle = titles;
|
|
|
|
nextFilter = filters;
|
|
|
|
// The names of the file types are localizable
|
2000-04-18 11:44:58 +04:00
|
|
|
GetBundleString(NS_ConvertASCIItoUCS2("HTMLFiles"), HTMLFiles);
|
|
|
|
GetBundleString(NS_ConvertASCIItoUCS2("TextFiles"), TextFiles);
|
2000-03-25 05:41:19 +03:00
|
|
|
if (! (HTMLFiles.Length() == 0 || TextFiles.Length() == 0))
|
|
|
|
{
|
|
|
|
nsAutoString allFilesStr;
|
2000-04-18 11:44:58 +04:00
|
|
|
GetBundleString(NS_ConvertASCIItoUCS2("AllFiles"), allFilesStr);
|
1999-10-20 18:15:25 +04:00
|
|
|
|
2000-03-25 05:41:19 +03:00
|
|
|
*nextTitle++ = HTMLFiles;
|
2000-04-18 11:44:58 +04:00
|
|
|
(*nextFilter++).AssignWithConversion("*.htm; *.html; *.shtml");
|
2000-03-25 05:41:19 +03:00
|
|
|
*nextTitle++ = TextFiles;
|
2000-04-18 11:44:58 +04:00
|
|
|
(*nextFilter++).AssignWithConversion("*.txt");
|
2000-03-25 05:41:19 +03:00
|
|
|
*nextTitle++ = allFilesStr;
|
2000-04-18 11:44:58 +04:00
|
|
|
(*nextFilter++).AssignWithConversion("*.*");
|
2000-03-25 05:41:19 +03:00
|
|
|
fileWidget->SetFilterList(3, titles, filters);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (noFileSpec)
|
|
|
|
{
|
|
|
|
// check the current url, use that file name if possible
|
|
|
|
nsString urlstring;
|
|
|
|
res = HTMLDoc->GetURL(urlstring);
|
2000-03-17 18:27:05 +03:00
|
|
|
|
2000-03-25 05:41:19 +03:00
|
|
|
// ?????
|
|
|
|
// res = HTMLDoc->GetSourceDocumentURL(jscx, uri);
|
|
|
|
// do a QI to get an nsIURL and then call GetFileName()
|
2000-03-17 18:27:05 +03:00
|
|
|
|
2000-03-25 05:41:19 +03:00
|
|
|
// if it's not a local file already, grab the current file name
|
2000-04-18 11:44:58 +04:00
|
|
|
if ( (urlstring.CompareWithConversion("file", PR_TRUE, 4) != 0 )
|
|
|
|
&& (urlstring.CompareWithConversion("about:blank", PR_TRUE, -1) != 0) )
|
2000-03-20 18:44:32 +03:00
|
|
|
{
|
2000-03-25 05:41:19 +03:00
|
|
|
PRInt32 index = urlstring.RFindChar((PRUnichar)'/', PR_FALSE, -1, -1 );
|
|
|
|
if ( index != -1 )
|
1999-10-20 18:15:25 +04:00
|
|
|
{
|
2000-03-25 05:41:19 +03:00
|
|
|
// remove cruft before file name including '/'
|
|
|
|
// if the url ends with a '/' then the whole string will be cut
|
2000-03-26 15:39:08 +04:00
|
|
|
urlstring.Cut(0, index + 1);
|
2000-03-25 05:41:19 +03:00
|
|
|
if (urlstring.Length() > 0)
|
2000-04-18 11:44:58 +04:00
|
|
|
fileName.Assign( urlstring );
|
1999-10-20 18:15:25 +04:00
|
|
|
}
|
|
|
|
}
|
2000-03-20 18:44:32 +03:00
|
|
|
|
2000-03-25 05:41:19 +03:00
|
|
|
// Use page title as suggested name for new document
|
|
|
|
if (fileName.Length() == 0 && title.Length() > 0)
|
1999-10-16 02:06:41 +04:00
|
|
|
{
|
2000-03-25 05:41:19 +03:00
|
|
|
//Replace "bad" filename characteres with "_"
|
|
|
|
PRUnichar space = (PRUnichar)' ';
|
|
|
|
PRUnichar dot = (PRUnichar)'.';
|
|
|
|
PRUnichar bslash = (PRUnichar)'\\';
|
|
|
|
PRUnichar fslash = (PRUnichar)'/';
|
|
|
|
PRUnichar at = (PRUnichar)'@';
|
|
|
|
PRUnichar colon = (PRUnichar)':';
|
|
|
|
PRUnichar underscore = (PRUnichar)'_';
|
2000-04-18 11:44:58 +04:00
|
|
|
title.ReplaceChar(space, underscore);
|
|
|
|
title.ReplaceChar(dot, underscore);
|
|
|
|
title.ReplaceChar(bslash, underscore);
|
|
|
|
title.ReplaceChar(fslash, underscore);
|
|
|
|
title.ReplaceChar(at, underscore);
|
|
|
|
title.ReplaceChar(colon, underscore);
|
2000-03-26 15:39:08 +04:00
|
|
|
fileName = title;
|
2000-04-18 11:44:58 +04:00
|
|
|
fileName.AppendWithConversion(".html");
|
1999-10-16 02:06:41 +04:00
|
|
|
}
|
2000-03-25 05:41:19 +03:00
|
|
|
}
|
1999-10-16 02:06:41 +04:00
|
|
|
else
|
1999-08-31 04:51:23 +04:00
|
|
|
{
|
2000-03-25 05:41:19 +03:00
|
|
|
char *leafName = docFileSpec.GetLeafName();
|
|
|
|
if (leafName)
|
|
|
|
{
|
2000-04-18 11:44:58 +04:00
|
|
|
fileName.AssignWithConversion(leafName);
|
2000-03-25 05:41:19 +03:00
|
|
|
nsCRT::free(leafName);
|
|
|
|
}
|
|
|
|
docFileSpec.GetParent(parentPath);
|
|
|
|
|
|
|
|
// TODO: CHANGE TO THE DIRECTORY OF THE PARENT PATH?
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fileName.Length() > 0)
|
|
|
|
fileWidget->SetDefaultString(fileName);
|
|
|
|
|
|
|
|
nsFileDlgResults dialogResult;
|
|
|
|
// 1ST PARAM SHOULD BE nsIDOMWindow*, not nsIWidget*
|
|
|
|
dialogResult = fileWidget->PutFile(nsnull, promptString, docFileSpec);
|
|
|
|
delete [] titles;
|
|
|
|
delete [] filters;
|
|
|
|
|
|
|
|
if (dialogResult == nsFileDlgResults_Cancel)
|
|
|
|
{
|
|
|
|
// Note that *_retval = PR_FALSE at this point
|
|
|
|
return NS_OK;
|
1999-08-31 04:51:23 +04:00
|
|
|
}
|
2000-03-25 05:41:19 +03:00
|
|
|
replacing = (dialogResult == nsFileDlgResults_Replace);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NS_ASSERTION(0, "Failed to get file widget");
|
|
|
|
return res;
|
1999-08-28 06:40:18 +04:00
|
|
|
}
|
2000-04-04 18:51:26 +04:00
|
|
|
//#endif end replace with nsIFilePicker block
|
2000-03-25 05:41:19 +03:00
|
|
|
|
2000-01-14 02:33:00 +03:00
|
|
|
// Set the new URL for the webshell
|
2000-04-12 03:48:14 +04:00
|
|
|
nsCOMPtr<nsIWebShell> webShell(do_QueryInterface(mContentAreaDocShell));
|
|
|
|
if (webShell)
|
2000-01-14 02:33:00 +03:00
|
|
|
{
|
|
|
|
nsFileURL fileURL(docFileSpec);
|
2000-04-18 11:44:58 +04:00
|
|
|
nsAutoString fileURLString; fileURLString.AssignWithConversion(fileURL.GetURLString());
|
2000-01-14 02:33:00 +03:00
|
|
|
PRUnichar *fileURLUnicode = fileURLString.ToNewUnicode();
|
|
|
|
if (fileURLUnicode)
|
|
|
|
{
|
2000-04-12 03:48:14 +04:00
|
|
|
webShell->SetURL(fileURLUnicode);
|
2000-01-14 02:33:00 +03:00
|
|
|
Recycle(fileURLUnicode);
|
|
|
|
}
|
2000-03-25 05:41:19 +03:00
|
|
|
}
|
1999-10-16 02:06:41 +04:00
|
|
|
} // mustShowFileDialog
|
1999-08-28 06:40:18 +04:00
|
|
|
|
|
|
|
// TODO: Get the file type (from the extension?) the user set for the file
|
|
|
|
// How do we do this in an XP way???
|
|
|
|
// For now, just save as HTML type
|
2000-04-26 05:00:50 +04:00
|
|
|
nsString format;
|
|
|
|
format.AssignWithConversion("text/html");
|
|
|
|
res = editor->SaveFile(&docFileSpec, replacing, saveCopy, format);
|
1999-08-28 06:40:18 +04:00
|
|
|
if (NS_FAILED(res))
|
|
|
|
{
|
2000-03-20 18:44:32 +03:00
|
|
|
nsAutoString saveDocStr, failedStr;
|
2000-04-18 11:44:58 +04:00
|
|
|
GetBundleString(NS_ConvertASCIItoUCS2("SaveDocument"), saveDocStr);
|
|
|
|
GetBundleString(NS_ConvertASCIItoUCS2("SaveFileFailed"), failedStr);
|
2000-03-20 18:44:32 +03:00
|
|
|
Alert(saveDocStr, failedStr);
|
1999-08-31 04:51:23 +04:00
|
|
|
} else {
|
|
|
|
// File was saved successfully
|
|
|
|
*_retval = PR_TRUE;
|
2000-05-02 01:49:52 +04:00
|
|
|
|
2000-04-21 18:55:54 +04:00
|
|
|
// Update window title to show possibly different filename
|
2000-03-25 05:41:19 +03:00
|
|
|
if (mustShowFileDialog)
|
2000-04-21 18:55:54 +04:00
|
|
|
UpdateWindowTitle();
|
1999-08-28 06:40:18 +04:00
|
|
|
}
|
1999-06-11 03:50:26 +04:00
|
|
|
}
|
|
|
|
break;
|
1999-08-28 06:40:18 +04:00
|
|
|
}
|
1999-06-11 03:50:26 +04:00
|
|
|
default:
|
1999-08-28 06:40:18 +04:00
|
|
|
res = NS_ERROR_NOT_IMPLEMENTED;
|
1999-06-11 03:50:26 +04:00
|
|
|
}
|
1999-08-28 06:40:18 +04:00
|
|
|
return res;
|
|
|
|
}
|
1999-06-11 03:50:26 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-11-03 08:28:02 +03:00
|
|
|
nsEditorShell::CloseWindow( PRBool *_retval )
|
1999-06-11 03:50:26 +04:00
|
|
|
{
|
2000-03-20 18:44:32 +03:00
|
|
|
nsAutoString beforeClosingStr;
|
2000-04-18 11:44:58 +04:00
|
|
|
GetBundleString(NS_ConvertASCIItoUCS2("BeforeClosing"), beforeClosingStr);
|
1999-06-11 03:50:26 +04:00
|
|
|
|
2000-03-20 18:44:32 +03:00
|
|
|
nsresult rv = CheckAndSaveDocument(beforeClosingStr.GetUnicode(), _retval);
|
1999-11-03 08:28:02 +03:00
|
|
|
|
1999-08-31 04:51:23 +04:00
|
|
|
// Don't close the window if there was an error saving file or
|
|
|
|
// user canceled an action along the way
|
1999-11-03 08:28:02 +03:00
|
|
|
if (NS_SUCCEEDED(rv) && *_retval)
|
2000-05-02 01:49:52 +04:00
|
|
|
{
|
2000-04-12 03:48:14 +04:00
|
|
|
nsCOMPtr<nsIBaseWindow> baseWindow;
|
|
|
|
GetTreeOwner(mDocShell, getter_AddRefs(baseWindow));
|
|
|
|
NS_ENSURE_TRUE(baseWindow, NS_ERROR_FAILURE);
|
|
|
|
baseWindow->Destroy();
|
2000-05-02 01:49:52 +04:00
|
|
|
}
|
1999-08-31 04:51:23 +04:00
|
|
|
|
1999-06-11 03:50:26 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::Print()
|
|
|
|
{
|
2000-04-12 03:48:14 +04:00
|
|
|
if (!mContentAreaDocShell)
|
1999-09-15 05:10:10 +04:00
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
2000-03-11 04:00:48 +03:00
|
|
|
nsCOMPtr<nsIContentViewer> viewer;
|
2000-04-12 03:48:14 +04:00
|
|
|
mContentAreaDocShell->GetContentViewer(getter_AddRefs(viewer));
|
1999-11-19 10:35:27 +03:00
|
|
|
if (nsnull != viewer)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIContentViewerFile> viewerFile = do_QueryInterface(viewer);
|
|
|
|
if (viewerFile) {
|
2000-01-26 19:01:40 +03:00
|
|
|
NS_ENSURE_SUCCESS(viewerFile->Print(PR_FALSE,nsnull), NS_ERROR_FAILURE);
|
1999-11-19 10:35:27 +03:00
|
|
|
}
|
1999-09-15 05:10:10 +04:00
|
|
|
}
|
|
|
|
return NS_OK;
|
1999-06-11 03:50:26 +04:00
|
|
|
}
|
1999-11-19 10:35:27 +03:00
|
|
|
|
1999-06-11 03:50:26 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::GetLocalFileURL(nsIDOMWindow *parent, const PRUnichar *filterType, PRUnichar **_retval)
|
|
|
|
{
|
1999-10-27 03:13:00 +04:00
|
|
|
nsAutoString FilterType(filterType);
|
|
|
|
PRBool htmlFilter = FilterType.EqualsIgnoreCase("html");
|
|
|
|
PRBool imgFilter = FilterType.EqualsIgnoreCase("img");
|
1999-06-11 03:50:26 +04:00
|
|
|
|
|
|
|
*_retval = nsnull;
|
|
|
|
|
|
|
|
// TODO: DON'T ACCEPT NULL PARENT AFTER WIDGET IS FIXED
|
1999-09-07 23:08:24 +04:00
|
|
|
if (/*parent||*/ !(htmlFilter || imgFilter))
|
1999-06-11 03:50:26 +04:00
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
|
|
|
|
|
|
|
nsCOMPtr<nsIFileWidget> fileWidget;
|
2000-03-20 18:44:32 +03:00
|
|
|
nsAutoString HTMLTitle;
|
2000-04-18 11:44:58 +04:00
|
|
|
GetBundleString(NS_ConvertASCIItoUCS2("OpenHTMLFile"), HTMLTitle);
|
1999-08-28 06:40:18 +04:00
|
|
|
|
|
|
|
// An empty string should just result in "Open" for the dialog
|
|
|
|
nsAutoString title;
|
1999-08-31 04:51:23 +04:00
|
|
|
if (htmlFilter)
|
1999-08-28 06:40:18 +04:00
|
|
|
{
|
|
|
|
title = HTMLTitle;
|
|
|
|
} else {
|
2000-03-20 18:44:32 +03:00
|
|
|
nsAutoString ImageTitle;
|
2000-04-18 11:44:58 +04:00
|
|
|
GetBundleString(NS_ConvertASCIItoUCS2("SelectImageFile"), ImageTitle);
|
1999-08-28 06:40:18 +04:00
|
|
|
|
1999-08-31 04:51:23 +04:00
|
|
|
if (ImageTitle.Length() > 0 && imgFilter)
|
1999-08-28 06:40:18 +04:00
|
|
|
title = ImageTitle;
|
|
|
|
}
|
|
|
|
|
1999-06-11 03:50:26 +04:00
|
|
|
nsFileSpec fileSpec;
|
|
|
|
// TODO: GET THE DEFAULT DIRECTORY FOR DIFFERENT TYPES FROM PREFERENCES
|
|
|
|
nsFileSpec aDisplayDirectory;
|
|
|
|
|
1999-08-31 04:51:23 +04:00
|
|
|
nsresult res = nsComponentManager::CreateInstance(kCFileWidgetCID,
|
|
|
|
nsnull,
|
2000-01-11 23:49:15 +03:00
|
|
|
NS_GET_IID(nsIFileWidget),
|
1999-08-31 04:51:23 +04:00
|
|
|
(void**)&fileWidget);
|
1999-06-11 03:50:26 +04:00
|
|
|
if (NS_SUCCEEDED(res))
|
|
|
|
{
|
|
|
|
nsFileDlgResults dialogResult;
|
1999-10-20 18:15:25 +04:00
|
|
|
nsString* titles = nsnull;
|
|
|
|
nsString* filters = nsnull;
|
|
|
|
nsString* nextTitle;
|
|
|
|
nsString* nextFilter;
|
|
|
|
|
2000-03-20 18:44:32 +03:00
|
|
|
nsAutoString tempStr;
|
|
|
|
|
1999-06-11 03:50:26 +04:00
|
|
|
if (htmlFilter)
|
|
|
|
{
|
1999-10-20 18:15:25 +04:00
|
|
|
titles = new nsString[3];
|
|
|
|
filters = new nsString[3];
|
|
|
|
if (!titles || ! filters)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2000-03-20 18:44:32 +03:00
|
|
|
|
1999-10-20 18:15:25 +04:00
|
|
|
nextTitle = titles;
|
|
|
|
nextFilter = filters;
|
2000-04-18 11:44:58 +04:00
|
|
|
GetBundleString(NS_ConvertASCIItoUCS2("HTMLFiles"), tempStr);
|
2000-03-20 18:44:32 +03:00
|
|
|
*nextTitle++ = tempStr;
|
2000-04-18 11:44:58 +04:00
|
|
|
GetBundleString(NS_ConvertASCIItoUCS2("TextFiles"), tempStr);
|
2000-03-20 18:44:32 +03:00
|
|
|
*nextTitle++ = tempStr;
|
2000-04-18 11:44:58 +04:00
|
|
|
(*nextFilter++).AssignWithConversion("*.htm; *.html; *.shtml");
|
|
|
|
(*nextFilter++).AssignWithConversion("*.txt");
|
1999-10-20 18:15:25 +04:00
|
|
|
fileWidget->SetFilterList(3, titles, filters);
|
1999-06-11 03:50:26 +04:00
|
|
|
} else {
|
1999-10-20 18:15:25 +04:00
|
|
|
titles = new nsString[2];
|
|
|
|
filters = new nsString[2];
|
|
|
|
if (!titles || ! filters)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
nextTitle = titles;
|
|
|
|
nextFilter = filters;
|
2000-04-18 11:44:58 +04:00
|
|
|
GetBundleString(NS_ConvertASCIItoUCS2("IMGFiles"), tempStr);
|
2000-03-20 18:44:32 +03:00
|
|
|
*nextTitle++ = tempStr;
|
2000-04-18 11:44:58 +04:00
|
|
|
(*nextFilter++).AssignWithConversion("*.gif; *.jpg; *.jpeg; *.png; *.*");
|
1999-10-20 18:15:25 +04:00
|
|
|
fileWidget->SetFilterList(2, titles, filters);
|
1999-06-11 03:50:26 +04:00
|
|
|
}
|
2000-04-18 11:44:58 +04:00
|
|
|
GetBundleString(NS_ConvertASCIItoUCS2("AllFiles"), tempStr);
|
2000-03-20 18:44:32 +03:00
|
|
|
*nextTitle++ = tempStr;
|
2000-04-18 11:44:58 +04:00
|
|
|
(*nextFilter++).AssignWithConversion("*.*");
|
1999-10-20 18:15:25 +04:00
|
|
|
// First param should be Parent window, but type is nsIWidget*
|
|
|
|
// Bug is filed to change this to a more suitable window type
|
|
|
|
dialogResult = fileWidget->GetFile(/*parent*/ nsnull, title, fileSpec);
|
|
|
|
delete [] titles;
|
|
|
|
delete [] filters;
|
|
|
|
|
1999-06-11 03:50:26 +04:00
|
|
|
// Do this after we get this from preferences
|
|
|
|
//fileWidget->SetDisplayDirectory(aDisplayDirectory);
|
|
|
|
|
|
|
|
if (dialogResult != nsFileDlgResults_Cancel)
|
|
|
|
{
|
|
|
|
// Get the platform-specific format
|
|
|
|
// Convert it to the string version of the URL format
|
|
|
|
// NOTE: THIS CRASHES IF fileSpec is empty
|
|
|
|
nsFileURL url(fileSpec);
|
2000-04-18 11:44:58 +04:00
|
|
|
nsAutoString returnVal; returnVal.AssignWithConversion(url.GetURLString());
|
1999-06-11 03:50:26 +04:00
|
|
|
*_retval = returnVal.ToNewUnicode();
|
|
|
|
}
|
|
|
|
// TODO: SAVE THIS TO THE PREFS?
|
|
|
|
fileWidget->GetDisplayDirectory(aDisplayDirectory);
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2000-04-04 05:06:25 +04:00
|
|
|
nsresult
|
1999-10-16 02:06:41 +04:00
|
|
|
nsEditorShell::UpdateWindowTitle()
|
1999-10-20 18:15:25 +04:00
|
|
|
{
|
1999-11-13 19:37:58 +03:00
|
|
|
nsresult res = NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
2000-04-12 03:48:14 +04:00
|
|
|
if (!mContentAreaDocShell || !mEditor)
|
1999-11-13 19:37:58 +03:00
|
|
|
return res;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(mEditor);
|
|
|
|
if (!editor)
|
|
|
|
return res;
|
1999-10-20 18:15:25 +04:00
|
|
|
|
|
|
|
nsAutoString windowCaption;
|
2000-01-14 02:33:00 +03:00
|
|
|
res = GetDocumentTitleString(windowCaption);
|
2000-02-15 18:54:05 +03:00
|
|
|
// If title is empty, use "untitled"
|
|
|
|
if (windowCaption.Length() == 0)
|
2000-04-18 11:44:58 +04:00
|
|
|
GetBundleString(NS_ConvertASCIItoUCS2("untitled"), windowCaption);
|
1999-11-13 19:37:58 +03:00
|
|
|
|
|
|
|
// Append just the 'leaf' filename to the Doc. Title for the window caption
|
1999-10-20 18:15:25 +04:00
|
|
|
if (NS_SUCCEEDED(res))
|
1999-11-13 19:37:58 +03:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMDocument> domDoc;
|
|
|
|
editor->GetDocument(getter_AddRefs(domDoc));
|
|
|
|
if (domDoc)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDiskDocument> diskDoc = do_QueryInterface(domDoc);
|
|
|
|
if (diskDoc)
|
|
|
|
{
|
|
|
|
// find out if the doc already has a fileSpec associated with it.
|
1999-11-13 22:27:59 +03:00
|
|
|
nsFileSpec docFileSpec;
|
|
|
|
if (NS_SUCCEEDED(diskDoc->GetFileSpec(docFileSpec)))
|
1999-11-13 19:37:58 +03:00
|
|
|
{
|
2000-04-04 18:51:26 +04:00
|
|
|
nsAutoString name;
|
|
|
|
docFileSpec.GetLeafName(name);
|
2000-04-18 11:44:58 +04:00
|
|
|
windowCaption.AppendWithConversion(" [");
|
2000-04-04 18:51:26 +04:00
|
|
|
windowCaption += name;
|
2000-04-18 11:44:58 +04:00
|
|
|
windowCaption.AppendWithConversion("]");
|
1999-11-13 19:37:58 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-04-12 03:48:14 +04:00
|
|
|
nsCOMPtr<nsIBaseWindow> contentAreaAsWin(do_QueryInterface(mContentAreaDocShell));
|
1999-12-18 02:44:43 +03:00
|
|
|
NS_ASSERTION(contentAreaAsWin, "This object should implement nsIBaseWindow");
|
|
|
|
res = contentAreaAsWin->SetTitle(windowCaption.GetUnicode());
|
1999-11-13 19:37:58 +03:00
|
|
|
}
|
1999-10-20 18:15:25 +04:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2000-04-04 05:06:25 +04:00
|
|
|
nsresult
|
2000-01-14 02:33:00 +03:00
|
|
|
nsEditorShell::GetDocumentTitleString(nsString& title)
|
1999-10-16 02:06:41 +04:00
|
|
|
{
|
|
|
|
nsresult res = NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
1999-10-20 18:15:25 +04:00
|
|
|
if (!mEditor)
|
1999-10-16 02:06:41 +04:00
|
|
|
return res;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(mEditor);
|
|
|
|
if (!editor)
|
|
|
|
return res;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMDocument> domDoc;
|
1999-10-20 18:15:25 +04:00
|
|
|
res = editor->GetDocument(getter_AddRefs(domDoc));
|
|
|
|
if (NS_SUCCEEDED(res) && domDoc)
|
1999-10-16 02:06:41 +04:00
|
|
|
{
|
|
|
|
// Get the document title
|
|
|
|
nsCOMPtr<nsIDOMHTMLDocument> HTMLDoc = do_QueryInterface(domDoc);
|
|
|
|
if (HTMLDoc)
|
1999-10-20 18:15:25 +04:00
|
|
|
res = HTMLDoc->GetTitle(title);
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
// JavaScript version
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::GetDocumentTitle(PRUnichar **title)
|
|
|
|
{
|
|
|
|
if (!title)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
nsAutoString titleStr;
|
2000-01-14 02:33:00 +03:00
|
|
|
nsresult res = GetDocumentTitleString(titleStr);
|
1999-10-20 18:15:25 +04:00
|
|
|
if (NS_SUCCEEDED(res))
|
|
|
|
{
|
|
|
|
*title = titleStr.ToNewUnicode();
|
|
|
|
} else {
|
|
|
|
// Don't fail, just return an empty string
|
2000-04-18 11:44:58 +04:00
|
|
|
nsAutoString empty;
|
1999-10-20 18:15:25 +04:00
|
|
|
*title = empty.ToNewUnicode();
|
|
|
|
res = NS_OK;
|
1999-10-16 02:06:41 +04:00
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-10-20 18:15:25 +04:00
|
|
|
nsEditorShell::SetDocumentTitle(const PRUnichar *title)
|
1999-10-16 02:06:41 +04:00
|
|
|
{
|
|
|
|
nsresult res = NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
2000-04-12 03:48:14 +04:00
|
|
|
if (!mEditor && !mContentAreaDocShell)
|
1999-10-16 02:06:41 +04:00
|
|
|
return res;
|
|
|
|
|
1999-10-20 18:15:25 +04:00
|
|
|
// This should only be allowed for HTML documents
|
|
|
|
if (mEditorType != eHTMLTextEditorType)
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
|
1999-10-16 02:06:41 +04:00
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(mEditor);
|
|
|
|
if (!editor)
|
1999-10-20 18:15:25 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
1999-10-16 02:06:41 +04:00
|
|
|
|
1999-10-20 18:15:25 +04:00
|
|
|
nsAutoString titleStr(title);
|
1999-10-16 02:06:41 +04:00
|
|
|
nsCOMPtr<nsIDOMDocument> domDoc;
|
|
|
|
res = editor->GetDocument(getter_AddRefs(domDoc));
|
|
|
|
|
|
|
|
if (domDoc)
|
|
|
|
{
|
|
|
|
// Get existing document title node
|
|
|
|
nsCOMPtr<nsIDOMHTMLDocument> HTMLDoc = do_QueryInterface(domDoc);
|
|
|
|
if (HTMLDoc)
|
|
|
|
{
|
|
|
|
// This sets the window title, and saves the title as a member varialble,
|
|
|
|
// but does NOT insert the <title> node.
|
1999-10-20 18:15:25 +04:00
|
|
|
HTMLDoc->SetTitle(titleStr);
|
1999-10-16 02:06:41 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMNodeList> titleList;
|
|
|
|
nsCOMPtr<nsIDOMNode>titleNode;
|
|
|
|
nsCOMPtr<nsIDOMNode>headNode;
|
|
|
|
nsCOMPtr<nsIDOMNode> resultNode;
|
2000-04-18 11:44:58 +04:00
|
|
|
res = domDoc->GetElementsByTagName(NS_ConvertASCIItoUCS2("title"), getter_AddRefs(titleList));
|
1999-10-16 02:06:41 +04:00
|
|
|
if (NS_SUCCEEDED(res))
|
|
|
|
{
|
|
|
|
if(titleList)
|
|
|
|
{
|
|
|
|
/* I'm tempted to just get the 1st title element in the list
|
|
|
|
(there should always be just 1). But in case there's > 1,
|
|
|
|
I assume the last one will be used, so this finds that one.
|
|
|
|
*/
|
|
|
|
PRUint32 len = 0;
|
|
|
|
titleList->GetLength(&len);
|
|
|
|
if (len >= 1)
|
|
|
|
titleList->Item(len-1, getter_AddRefs(titleNode));
|
|
|
|
|
|
|
|
if (titleNode)
|
|
|
|
{
|
2000-02-15 18:54:05 +03:00
|
|
|
//Delete existing children (text) of title node
|
1999-10-16 02:06:41 +04:00
|
|
|
nsCOMPtr<nsIDOMNodeList> children;
|
|
|
|
res = titleNode->GetChildNodes(getter_AddRefs(children));
|
|
|
|
if(NS_SUCCEEDED(res) && children)
|
|
|
|
{
|
|
|
|
PRUint32 count = 0;
|
|
|
|
children->GetLength(&count);
|
|
|
|
for( PRUint32 i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMNode> child;
|
|
|
|
res = children->Item(i,getter_AddRefs(child));
|
|
|
|
if(NS_SUCCEEDED(res) && child)
|
|
|
|
titleNode->RemoveChild(child,getter_AddRefs(resultNode));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Get the <HEAD> node, create a <TITLE> and insert it under the HEAD
|
|
|
|
nsCOMPtr<nsIDOMNodeList> headList;
|
2000-04-18 11:44:58 +04:00
|
|
|
res = domDoc->GetElementsByTagName(NS_ConvertASCIItoUCS2("head"),getter_AddRefs(headList));
|
2000-02-15 18:54:05 +03:00
|
|
|
if (NS_FAILED(res)) return res;
|
|
|
|
if (headList)
|
1999-10-16 02:06:41 +04:00
|
|
|
{
|
|
|
|
headList->Item(0, getter_AddRefs(headNode));
|
|
|
|
if (headNode)
|
|
|
|
{
|
|
|
|
PRBool newTitleNode = PR_FALSE;
|
1999-10-20 18:15:25 +04:00
|
|
|
if (!titleNode)
|
|
|
|
{
|
1999-10-16 02:06:41 +04:00
|
|
|
// Didn't find one above: Create a new one
|
|
|
|
nsCOMPtr<nsIDOMElement>titleElement;
|
2000-04-18 11:44:58 +04:00
|
|
|
res = domDoc->CreateElement(NS_ConvertASCIItoUCS2("title"),getter_AddRefs(titleElement));
|
1999-10-16 02:06:41 +04:00
|
|
|
if (NS_SUCCEEDED(res) && titleElement)
|
|
|
|
{
|
|
|
|
titleNode = do_QueryInterface(titleElement);
|
|
|
|
newTitleNode = PR_TRUE;
|
|
|
|
}
|
1999-10-20 18:15:25 +04:00
|
|
|
// Note: There should ALWAYS be a <title> in any HTML document,
|
|
|
|
// so we will insert the node and not make it undoable
|
|
|
|
res = headNode->AppendChild(titleNode, getter_AddRefs(resultNode));
|
2000-02-15 18:54:05 +03:00
|
|
|
if (NS_FAILED(res)) return res;
|
1999-10-16 02:06:41 +04:00
|
|
|
}
|
1999-10-20 18:15:25 +04:00
|
|
|
// Append a text node under the TITLE
|
|
|
|
// only if the title text isn't empty
|
|
|
|
if (titleNode && titleStr.Length() > 0)
|
1999-10-16 02:06:41 +04:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIDOMText> textNode;
|
1999-10-20 18:15:25 +04:00
|
|
|
res = domDoc->CreateTextNode(titleStr, getter_AddRefs(textNode));
|
2000-02-15 18:54:05 +03:00
|
|
|
if (NS_FAILED(res)) return res;
|
|
|
|
if (!textNode) return NS_ERROR_FAILURE;
|
2000-05-12 06:37:33 +04:00
|
|
|
// Do NOT use editor transaction -- we don't want this to be undoable
|
|
|
|
res = titleNode->AppendChild(textNode, getter_AddRefs(resultNode));
|
|
|
|
if (NS_FAILED(res)) return res;
|
1999-10-16 02:06:41 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
1999-09-02 05:47:18 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::CloneAttributes(nsIDOMNode *destNode, nsIDOMNode *sourceNode)
|
|
|
|
{
|
|
|
|
if (!destNode || !sourceNode) { return NS_ERROR_NULL_POINTER; }
|
|
|
|
nsresult rv = NS_NOINTERFACE;
|
|
|
|
|
|
|
|
switch (mEditorType)
|
|
|
|
{
|
|
|
|
case ePlainTextEditorType:
|
|
|
|
case eHTMLTextEditorType:
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(mEditor);
|
|
|
|
if (editor)
|
|
|
|
rv = editor->CloneAttributes(destNode, sourceNode);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
rv = NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-09-01 05:22:37 +04:00
|
|
|
NS_IMETHODIMP
|
1999-09-01 23:58:25 +04:00
|
|
|
nsEditorShell::NodeIsBlock(nsIDOMNode *node, PRBool *_retval)
|
1999-09-01 05:22:37 +04:00
|
|
|
{
|
|
|
|
if (!node || !_retval) { return NS_ERROR_NULL_POINTER; }
|
|
|
|
nsresult rv = NS_NOINTERFACE;
|
|
|
|
|
|
|
|
switch (mEditorType)
|
|
|
|
{
|
|
|
|
case ePlainTextEditorType:
|
|
|
|
case eHTMLTextEditorType:
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(mEditor);
|
|
|
|
if (editor)
|
1999-09-01 23:58:25 +04:00
|
|
|
rv = editor->NodeIsBlock(node, *_retval);
|
1999-09-01 05:22:37 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
rv = NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-06-11 03:50:26 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::Undo()
|
|
|
|
{
|
|
|
|
nsresult err = NS_NOINTERFACE;
|
|
|
|
|
|
|
|
switch (mEditorType)
|
|
|
|
{
|
|
|
|
case ePlainTextEditorType:
|
|
|
|
case eHTMLTextEditorType:
|
|
|
|
{
|
1999-08-09 05:37:50 +04:00
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(mEditor);
|
|
|
|
if (editor)
|
|
|
|
err = editor->Undo(1);
|
1999-06-11 03:50:26 +04:00
|
|
|
}
|
|
|
|
break;
|
1999-08-09 05:37:50 +04:00
|
|
|
|
1999-06-11 03:50:26 +04:00
|
|
|
default:
|
|
|
|
err = NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::Redo()
|
|
|
|
{
|
|
|
|
nsresult err = NS_NOINTERFACE;
|
|
|
|
|
|
|
|
switch (mEditorType)
|
|
|
|
{
|
|
|
|
case ePlainTextEditorType:
|
|
|
|
case eHTMLTextEditorType:
|
|
|
|
{
|
1999-08-09 05:37:50 +04:00
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(mEditor);
|
|
|
|
if (editor)
|
|
|
|
err = editor->Redo(1);
|
1999-06-11 03:50:26 +04:00
|
|
|
}
|
|
|
|
break;
|
1999-08-09 05:37:50 +04:00
|
|
|
|
1999-06-11 03:50:26 +04:00
|
|
|
default:
|
|
|
|
err = NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::Cut()
|
|
|
|
{
|
|
|
|
nsresult err = NS_NOINTERFACE;
|
|
|
|
|
|
|
|
switch (mEditorType)
|
|
|
|
{
|
|
|
|
case ePlainTextEditorType:
|
|
|
|
case eHTMLTextEditorType:
|
|
|
|
{
|
1999-08-09 05:37:50 +04:00
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(mEditor);
|
|
|
|
if (editor)
|
|
|
|
err = editor->Cut();
|
1999-06-11 03:50:26 +04:00
|
|
|
}
|
|
|
|
break;
|
1999-08-09 05:37:50 +04:00
|
|
|
|
1999-06-11 03:50:26 +04:00
|
|
|
default:
|
|
|
|
err = NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::Copy()
|
|
|
|
{
|
|
|
|
nsresult err = NS_NOINTERFACE;
|
|
|
|
|
|
|
|
switch (mEditorType)
|
|
|
|
{
|
|
|
|
case ePlainTextEditorType:
|
|
|
|
case eHTMLTextEditorType:
|
|
|
|
{
|
1999-08-09 05:37:50 +04:00
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(mEditor);
|
|
|
|
if (editor)
|
|
|
|
err = editor->Copy();
|
1999-06-11 03:50:26 +04:00
|
|
|
}
|
|
|
|
break;
|
1999-08-09 05:37:50 +04:00
|
|
|
|
1999-06-11 03:50:26 +04:00
|
|
|
default:
|
|
|
|
err = NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-04-15 03:38:21 +04:00
|
|
|
nsEditorShell::Paste(PRInt32 aSelectionType)
|
1999-06-11 03:50:26 +04:00
|
|
|
{
|
|
|
|
nsresult err = NS_NOINTERFACE;
|
|
|
|
|
|
|
|
switch (mEditorType)
|
|
|
|
{
|
|
|
|
case ePlainTextEditorType:
|
|
|
|
case eHTMLTextEditorType:
|
|
|
|
{
|
1999-08-09 05:37:50 +04:00
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(mEditor);
|
|
|
|
if (editor)
|
2000-04-15 03:38:21 +04:00
|
|
|
err = editor->Paste(aSelectionType);
|
1999-06-11 03:50:26 +04:00
|
|
|
}
|
|
|
|
break;
|
1999-08-09 05:37:50 +04:00
|
|
|
|
1999-06-11 03:50:26 +04:00
|
|
|
default:
|
|
|
|
err = NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-04-15 03:38:21 +04:00
|
|
|
nsEditorShell::PasteAsQuotation(PRInt32 aSelectionType)
|
1999-06-11 03:50:26 +04:00
|
|
|
{
|
|
|
|
nsresult err = NS_NOINTERFACE;
|
|
|
|
|
|
|
|
switch (mEditorType)
|
|
|
|
{
|
|
|
|
case ePlainTextEditorType:
|
|
|
|
case eHTMLTextEditorType:
|
|
|
|
{
|
1999-08-09 05:37:50 +04:00
|
|
|
nsCOMPtr<nsIEditorMailSupport> mailEditor = do_QueryInterface(mEditor);
|
|
|
|
if (mailEditor)
|
2000-04-15 03:38:21 +04:00
|
|
|
err = mailEditor->PasteAsQuotation(aSelectionType);
|
1999-06-11 03:50:26 +04:00
|
|
|
}
|
|
|
|
break;
|
1999-08-09 05:37:50 +04:00
|
|
|
|
1999-06-11 03:50:26 +04:00
|
|
|
default:
|
|
|
|
err = NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-04-15 03:38:21 +04:00
|
|
|
nsEditorShell::PasteAsCitedQuotation(const PRUnichar *cite, PRInt32 aSelectionType)
|
1999-06-11 03:50:26 +04:00
|
|
|
{
|
|
|
|
nsresult err = NS_NOINTERFACE;
|
|
|
|
|
|
|
|
nsAutoString aCiteString(cite);
|
|
|
|
|
|
|
|
switch (mEditorType)
|
|
|
|
{
|
|
|
|
case ePlainTextEditorType:
|
|
|
|
case eHTMLTextEditorType:
|
|
|
|
{
|
1999-08-09 05:37:50 +04:00
|
|
|
nsCOMPtr<nsIEditorMailSupport> mailEditor = do_QueryInterface(mEditor);
|
|
|
|
if (mailEditor)
|
2000-04-15 03:38:21 +04:00
|
|
|
err = mailEditor->PasteAsCitedQuotation(aCiteString, aSelectionType);
|
1999-06-11 03:50:26 +04:00
|
|
|
}
|
|
|
|
break;
|
1999-08-09 05:37:50 +04:00
|
|
|
|
1999-06-11 03:50:26 +04:00
|
|
|
default:
|
|
|
|
err = NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-11-24 23:48:59 +03:00
|
|
|
nsEditorShell::InsertAsQuotation(const PRUnichar *quotedText,
|
|
|
|
nsIDOMNode** aNodeInserted)
|
1999-06-11 03:50:26 +04:00
|
|
|
{
|
|
|
|
nsresult err = NS_NOINTERFACE;
|
|
|
|
|
|
|
|
nsAutoString aQuotedText(quotedText);
|
|
|
|
|
|
|
|
switch (mEditorType)
|
|
|
|
{
|
|
|
|
case ePlainTextEditorType:
|
|
|
|
case eHTMLTextEditorType:
|
|
|
|
{
|
1999-08-09 05:37:50 +04:00
|
|
|
nsCOMPtr<nsIEditorMailSupport> mailEditor = do_QueryInterface(mEditor);
|
|
|
|
if (mailEditor)
|
1999-11-24 23:48:59 +03:00
|
|
|
err = mailEditor->InsertAsQuotation(aQuotedText, aNodeInserted);
|
1999-06-11 03:50:26 +04:00
|
|
|
}
|
|
|
|
break;
|
1999-08-09 05:37:50 +04:00
|
|
|
|
1999-06-11 03:50:26 +04:00
|
|
|
default:
|
|
|
|
err = NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-11-24 23:48:59 +03:00
|
|
|
nsEditorShell::InsertAsCitedQuotation(const PRUnichar *quotedText,
|
|
|
|
const PRUnichar *cite,
|
2000-03-21 02:13:25 +03:00
|
|
|
PRBool aInsertHTML,
|
2000-01-04 23:38:12 +03:00
|
|
|
const PRUnichar *charset,
|
1999-11-24 23:48:59 +03:00
|
|
|
nsIDOMNode** aNodeInserted)
|
1999-06-11 03:50:26 +04:00
|
|
|
{
|
|
|
|
nsresult err = NS_NOINTERFACE;
|
|
|
|
|
2000-01-04 23:38:12 +03:00
|
|
|
nsCOMPtr<nsIEditorMailSupport> mailEditor = do_QueryInterface(mEditor);
|
|
|
|
if (!mailEditor)
|
|
|
|
return NS_NOINTERFACE;
|
|
|
|
|
1999-06-11 03:50:26 +04:00
|
|
|
nsAutoString aQuotedText(quotedText);
|
|
|
|
nsAutoString aCiteString(cite);
|
2000-01-04 23:38:12 +03:00
|
|
|
nsAutoString aCharset(charset);
|
1999-06-11 03:50:26 +04:00
|
|
|
|
|
|
|
switch (mEditorType)
|
|
|
|
{
|
|
|
|
case ePlainTextEditorType:
|
2000-01-04 23:38:12 +03:00
|
|
|
err = mailEditor->InsertAsQuotation(aQuotedText, aNodeInserted);
|
|
|
|
break;
|
|
|
|
|
1999-06-11 03:50:26 +04:00
|
|
|
case eHTMLTextEditorType:
|
2000-01-04 23:38:12 +03:00
|
|
|
err = mailEditor->InsertAsCitedQuotation(aQuotedText, aCiteString,
|
2000-03-21 02:13:25 +03:00
|
|
|
aInsertHTML,
|
2000-01-04 23:38:12 +03:00
|
|
|
aCharset, aNodeInserted);
|
1999-06-11 03:50:26 +04:00
|
|
|
break;
|
1999-08-09 05:37:50 +04:00
|
|
|
|
1999-06-11 03:50:26 +04:00
|
|
|
default:
|
|
|
|
err = NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2000-04-19 02:39:10 +04:00
|
|
|
// Utility routine to make a new citer. This addrefs, of course.
|
|
|
|
static nsICiter* MakeACiter()
|
|
|
|
{
|
|
|
|
// Make a citer of an appropriate type
|
|
|
|
nsICiter* citer = 0;
|
|
|
|
nsresult rv;
|
|
|
|
NS_WITH_SERVICE(nsIPref, prefs, kPrefServiceCID, &rv);
|
|
|
|
if (NS_FAILED(rv)) return 0;
|
|
|
|
|
|
|
|
char *citationType = 0;
|
|
|
|
rv = prefs->CopyCharPref("mail.compose.citationType", &citationType);
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv) && citationType[0])
|
|
|
|
{
|
|
|
|
if (!strncmp(citationType, "aol", 3))
|
|
|
|
citer = new nsAOLCiter;
|
|
|
|
else
|
|
|
|
citer = new nsInternetCiter;
|
|
|
|
PL_strfree(citationType);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
citer = new nsInternetCiter;
|
|
|
|
|
|
|
|
if (citer)
|
|
|
|
NS_ADDREF(citer);
|
|
|
|
return citer;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-04-21 02:45:54 +04:00
|
|
|
nsEditorShell::Rewrap(PRBool aRespectNewlines)
|
2000-04-19 02:39:10 +04:00
|
|
|
{
|
|
|
|
PRInt32 wrapCol;
|
|
|
|
nsresult rv = GetWrapColumn(&wrapCol);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return NS_OK;
|
|
|
|
#ifdef DEBUG_akkana
|
|
|
|
printf("nsEditorShell::Rewrap to %ld columns\n", (long)wrapCol);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMSelection> selection;
|
|
|
|
rv = GetEditorSelection(getter_AddRefs(selection));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
if (!selection)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
PRBool isCollapsed;
|
|
|
|
rv = selection->GetIsCollapsed(&isCollapsed);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
// Variables we'll need either way
|
2000-04-21 10:56:47 +04:00
|
|
|
nsAutoString format; format.AssignWithConversion("text/plain");
|
2000-04-19 02:39:10 +04:00
|
|
|
nsAutoString current;
|
|
|
|
nsString wrapped;
|
|
|
|
nsCOMPtr<nsIEditor> nsied (do_QueryInterface(mEditor));
|
|
|
|
if (!nsied)
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
|
|
|
|
if (isCollapsed) // rewrap the whole document
|
|
|
|
{
|
|
|
|
rv = nsied->OutputToString(current, format,
|
|
|
|
nsIDocumentEncoder::OutputFormatted);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsICiter> citer = dont_AddRef(MakeACiter());
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
if (!citer) return NS_ERROR_UNEXPECTED;
|
|
|
|
|
2000-04-21 02:45:54 +04:00
|
|
|
rv = citer->Rewrap(current, wrapCol, 0, aRespectNewlines, wrapped);
|
2000-04-19 02:39:10 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = SelectAll();
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
return mEditor->InsertText(wrapped);
|
|
|
|
}
|
|
|
|
else // rewrap only the selection
|
|
|
|
{
|
|
|
|
rv = nsied->OutputToString(current, format,
|
|
|
|
nsIDocumentEncoder::OutputFormatted
|
|
|
|
| nsIDocumentEncoder::OutputSelectionOnly);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsICiter> citer = dont_AddRef(MakeACiter());
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
if (!citer) return NS_ERROR_UNEXPECTED;
|
|
|
|
|
|
|
|
PRUint32 firstLineOffset = 0; // XXX need to get this
|
2000-04-21 02:45:54 +04:00
|
|
|
rv = citer->Rewrap(current, wrapCol, firstLineOffset, aRespectNewlines,
|
|
|
|
wrapped);
|
2000-04-19 02:39:10 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
return mEditor->InsertText(wrapped);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::StripCites()
|
|
|
|
{
|
|
|
|
#ifdef DEBUG_akkana
|
|
|
|
printf("nsEditorShell::StripCites()\n");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMSelection> selection;
|
|
|
|
nsresult rv = GetEditorSelection(getter_AddRefs(selection));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
if (!selection)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
PRBool isCollapsed;
|
|
|
|
rv = selection->GetIsCollapsed(&isCollapsed);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
// Variables we'll need either way
|
2000-04-21 10:56:47 +04:00
|
|
|
nsAutoString format; format.AssignWithConversion("text/plain");
|
2000-04-19 02:39:10 +04:00
|
|
|
nsAutoString current;
|
|
|
|
nsString stripped;
|
|
|
|
nsCOMPtr<nsIEditor> nsied (do_QueryInterface(mEditor));
|
|
|
|
if (!nsied)
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
|
|
|
|
if (isCollapsed) // rewrap the whole document
|
|
|
|
{
|
|
|
|
rv = nsied->OutputToString(current, format,
|
|
|
|
nsIDocumentEncoder::OutputFormatted);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsICiter> citer = dont_AddRef(MakeACiter());
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
if (!citer) return NS_ERROR_UNEXPECTED;
|
|
|
|
|
|
|
|
rv = citer->StripCites(current, stripped);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = SelectAll();
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
return mEditor->InsertText(stripped);
|
|
|
|
}
|
|
|
|
else // rewrap only the selection
|
|
|
|
{
|
|
|
|
rv = nsied->OutputToString(current, format,
|
|
|
|
nsIDocumentEncoder::OutputFormatted
|
|
|
|
| nsIDocumentEncoder::OutputSelectionOnly);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsICiter> citer = dont_AddRef(MakeACiter());
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
if (!citer) return NS_ERROR_UNEXPECTED;
|
|
|
|
|
|
|
|
rv = citer->StripCites(current, stripped);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
return mEditor->InsertText(stripped);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-06-11 03:50:26 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::SelectAll()
|
|
|
|
{
|
|
|
|
nsresult err = NS_NOINTERFACE;
|
|
|
|
|
|
|
|
switch (mEditorType)
|
|
|
|
{
|
|
|
|
case ePlainTextEditorType:
|
|
|
|
case eHTMLTextEditorType:
|
|
|
|
{
|
1999-08-09 05:37:50 +04:00
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(mEditor);
|
|
|
|
if (editor)
|
|
|
|
err = editor->SelectAll();
|
1999-06-11 03:50:26 +04:00
|
|
|
}
|
|
|
|
break;
|
1999-08-09 05:37:50 +04:00
|
|
|
|
1999-06-11 03:50:26 +04:00
|
|
|
default:
|
|
|
|
err = NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-06-15 00:02:46 +04:00
|
|
|
nsEditorShell::DeleteSelection(PRInt32 action)
|
1999-06-11 03:50:26 +04:00
|
|
|
{
|
|
|
|
nsresult err = NS_NOINTERFACE;
|
1999-12-07 11:30:19 +03:00
|
|
|
nsIEditor::EDirection selectionAction;
|
1999-06-15 00:02:46 +04:00
|
|
|
|
|
|
|
switch(action)
|
|
|
|
{
|
1999-08-09 05:37:50 +04:00
|
|
|
case 1:
|
1999-12-07 11:30:19 +03:00
|
|
|
selectionAction = nsIEditor::eNext;
|
1999-06-15 00:02:46 +04:00
|
|
|
break;
|
1999-08-09 05:37:50 +04:00
|
|
|
case 2:
|
1999-12-07 11:30:19 +03:00
|
|
|
selectionAction = nsIEditor::ePrevious;
|
1999-06-15 00:02:46 +04:00
|
|
|
break;
|
|
|
|
default:
|
1999-12-07 11:30:19 +03:00
|
|
|
selectionAction = nsIEditor::eNone;
|
1999-06-15 00:02:46 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1999-06-11 03:50:26 +04:00
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(mEditor);
|
|
|
|
if (editor)
|
1999-06-15 00:02:46 +04:00
|
|
|
err = editor->DeleteSelection(selectionAction);
|
1999-06-11 03:50:26 +04:00
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
1999-10-06 23:34:09 +04:00
|
|
|
/* This routine should only be called when playing back a log */
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::TypedText(const PRUnichar *aTextToInsert, PRInt32 aAction)
|
|
|
|
{
|
|
|
|
nsresult err = NS_NOINTERFACE;
|
|
|
|
|
|
|
|
nsAutoString textToInsert(aTextToInsert);
|
|
|
|
|
|
|
|
switch (mEditorType)
|
|
|
|
{
|
|
|
|
case ePlainTextEditorType:
|
|
|
|
case eHTMLTextEditorType:
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
|
|
|
|
if (htmlEditor)
|
|
|
|
err = htmlEditor->TypedText(textToInsert, aAction);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
err = NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
1999-06-11 03:50:26 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::InsertText(const PRUnichar *textToInsert)
|
|
|
|
{
|
|
|
|
nsresult err = NS_NOINTERFACE;
|
|
|
|
|
|
|
|
nsAutoString aTextToInsert(textToInsert);
|
|
|
|
|
|
|
|
switch (mEditorType)
|
|
|
|
{
|
|
|
|
case ePlainTextEditorType:
|
|
|
|
case eHTMLTextEditorType:
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
|
|
|
|
if (htmlEditor)
|
|
|
|
err = htmlEditor->InsertText(aTextToInsert);
|
|
|
|
}
|
|
|
|
break;
|
1999-08-09 05:37:50 +04:00
|
|
|
|
1999-06-11 03:50:26 +04:00
|
|
|
default:
|
|
|
|
err = NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
1999-06-30 23:26:08 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::InsertSource(const PRUnichar *aSourceToInsert)
|
|
|
|
{
|
|
|
|
nsresult err = NS_NOINTERFACE;
|
|
|
|
|
|
|
|
nsAutoString sourceToInsert(aSourceToInsert);
|
|
|
|
|
|
|
|
switch (mEditorType)
|
|
|
|
{
|
|
|
|
case ePlainTextEditorType:
|
|
|
|
case eHTMLTextEditorType:
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
|
|
|
|
if (htmlEditor)
|
|
|
|
err = htmlEditor->InsertHTML(sourceToInsert);
|
|
|
|
}
|
|
|
|
break;
|
1999-08-09 05:37:50 +04:00
|
|
|
|
1999-06-30 23:26:08 +04:00
|
|
|
default:
|
|
|
|
err = NS_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2000-01-04 23:38:12 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::InsertSourceWithCharset(const PRUnichar *aSourceToInsert,
|
|
|
|
const PRUnichar *aCharset)
|
|
|
|
{
|
|
|
|
nsresult err = NS_NOINTERFACE;
|
|
|
|
|
|
|
|
nsAutoString sourceToInsert(aSourceToInsert);
|
|
|
|
nsAutoString charset(aCharset);
|
|
|
|
|
|
|
|
switch (mEditorType)
|
|
|
|
{
|
|
|
|
case ePlainTextEditorType:
|
|
|
|
case eHTMLTextEditorType:
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
|
|
|
|
if (htmlEditor)
|
|
|
|
err = htmlEditor->InsertHTMLWithCharset(sourceToInsert, charset);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
err = NS_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
1999-06-11 03:50:26 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::InsertBreak()
|
|
|
|
{
|
|
|
|
nsresult err = NS_NOINTERFACE;
|
|
|
|
|
1999-08-09 05:37:50 +04:00
|
|
|
if (mEditor)
|
|
|
|
err = mEditor->InsertBreak();
|
1999-06-11 03:50:26 +04:00
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Both Find and FindNext call through here.
|
2000-04-04 05:06:25 +04:00
|
|
|
nsresult
|
1999-06-11 03:50:26 +04:00
|
|
|
nsEditorShell::DoFind(PRBool aFindNext)
|
|
|
|
{
|
2000-04-12 03:48:14 +04:00
|
|
|
if (!mContentAreaDocShell)
|
1999-06-11 03:50:26 +04:00
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
|
|
|
PRBool foundIt = PR_FALSE;
|
|
|
|
|
|
|
|
// Get find component.
|
1999-10-08 18:39:20 +04:00
|
|
|
nsresult rv;
|
|
|
|
NS_WITH_SERVICE(nsIFindComponent, findComponent, NS_IFINDCOMPONENT_PROGID, &rv);
|
|
|
|
NS_ASSERTION(((NS_SUCCEEDED(rv)) && findComponent), "GetService failed for find component.");
|
|
|
|
if (NS_FAILED(rv)) { return rv; }
|
|
|
|
|
|
|
|
// make the search context if we need to
|
|
|
|
if (!mSearchContext)
|
1999-06-11 03:50:26 +04:00
|
|
|
{
|
2000-05-14 09:27:17 +04:00
|
|
|
if(!mContentWindow)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
nsCOMPtr<nsIDOMWindow> cwP = do_QueryReferent(mContentWindow);
|
|
|
|
if (!cwP) return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
rv = findComponent->CreateContext(cwP, nsnull, getter_AddRefs(mSearchContext));
|
1999-06-11 03:50:26 +04:00
|
|
|
}
|
1999-10-08 18:39:20 +04:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(rv))
|
1999-06-11 03:50:26 +04:00
|
|
|
{
|
1999-10-08 18:39:20 +04:00
|
|
|
if (aFindNext)
|
|
|
|
rv = findComponent->FindNext(mSearchContext, &foundIt);
|
|
|
|
else
|
|
|
|
rv = findComponent->Find(mSearchContext, &foundIt);
|
1999-06-11 03:50:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::Find()
|
|
|
|
{
|
|
|
|
return DoFind(PR_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::FindNext()
|
|
|
|
{
|
|
|
|
return DoFind(PR_TRUE);
|
|
|
|
}
|
|
|
|
|
1999-08-28 06:40:18 +04:00
|
|
|
/* Get localized strings for UI from the Editor's string bundle */
|
|
|
|
// Use this version from JavaScript:
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::GetString(const PRUnichar *name, PRUnichar **_retval)
|
|
|
|
{
|
|
|
|
if (!name || !_retval)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
1999-09-03 05:23:19 +04:00
|
|
|
// Don't fail, just return an empty string
|
2000-04-18 11:44:58 +04:00
|
|
|
nsAutoString empty;
|
1999-08-28 06:40:18 +04:00
|
|
|
|
|
|
|
if (mStringBundle)
|
|
|
|
{
|
|
|
|
if (NS_FAILED(mStringBundle->GetStringFromName(name, _retval)))
|
|
|
|
*_retval = empty.ToNewUnicode();
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
} else {
|
|
|
|
*_retval = empty.ToNewUnicode();
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-08-31 04:51:23 +04:00
|
|
|
|
1999-08-28 06:40:18 +04:00
|
|
|
// Use this version within the shell:
|
2000-03-20 18:44:32 +03:00
|
|
|
void nsEditorShell::GetBundleString(const nsString& name, nsString &outString)
|
1999-08-28 06:40:18 +04:00
|
|
|
{
|
2000-03-20 18:44:32 +03:00
|
|
|
if (mStringBundle && name.Length() > 0)
|
1999-08-28 06:40:18 +04:00
|
|
|
{
|
|
|
|
PRUnichar *ptrv = nsnull;
|
2000-03-20 18:44:32 +03:00
|
|
|
if (NS_SUCCEEDED(mStringBundle->GetStringFromName(name.GetUnicode(), &ptrv)))
|
|
|
|
outString = ptrv;
|
|
|
|
else
|
2000-04-18 11:44:58 +04:00
|
|
|
outString.SetLength(0);
|
2000-03-20 18:44:32 +03:00
|
|
|
|
|
|
|
nsAllocator::Free(ptrv);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2000-04-18 11:44:58 +04:00
|
|
|
outString.SetLength(0);
|
1999-08-31 04:51:23 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-09-01 05:22:37 +04:00
|
|
|
// Utility to bring up a Yes/No/Cancel dialog.
|
1999-09-03 05:23:19 +04:00
|
|
|
nsEditorShell::EConfirmResult
|
|
|
|
nsEditorShell::ConfirmWithCancel(const nsString& aTitle, const nsString& aQuestion,
|
|
|
|
const nsString *aYesString, const nsString *aNoString)
|
1999-09-01 05:22:37 +04:00
|
|
|
{
|
1999-09-03 05:23:19 +04:00
|
|
|
nsEditorShell::EConfirmResult result = nsEditorShell::eCancel;
|
|
|
|
|
1999-09-01 05:22:37 +04:00
|
|
|
nsIDialogParamBlock* block = NULL;
|
1999-09-03 05:23:19 +04:00
|
|
|
nsresult rv = nsComponentManager::CreateInstance(kDialogParamBlockCID, 0,
|
2000-01-11 23:49:15 +03:00
|
|
|
NS_GET_IID(nsIDialogParamBlock),
|
1999-09-01 05:22:37 +04:00
|
|
|
(void**)&block );
|
1999-09-03 05:23:19 +04:00
|
|
|
if ( NS_SUCCEEDED(rv) )
|
1999-09-01 05:22:37 +04:00
|
|
|
{
|
1999-09-03 05:23:19 +04:00
|
|
|
// Stuff in Parameters
|
|
|
|
block->SetString( nsICommonDialogs::eMsg, aQuestion.GetUnicode());
|
2000-04-18 11:44:58 +04:00
|
|
|
nsAutoString url; url.AssignWithConversion( "chrome://global/skin/question-icon.gif" );
|
1999-09-03 05:23:19 +04:00
|
|
|
block->SetString( nsICommonDialogs::eIconURL, url.GetUnicode());
|
|
|
|
|
2000-03-20 18:44:32 +03:00
|
|
|
nsAutoString yesStr, noStr;
|
2000-05-10 03:03:41 +04:00
|
|
|
// Default is Yes, No, Cancel
|
|
|
|
PRInt32 numberOfButtons = 3;
|
2000-03-20 18:44:32 +03:00
|
|
|
if (aYesString)
|
2000-04-18 11:44:58 +04:00
|
|
|
yesStr.Assign(*aYesString);
|
2000-03-20 18:44:32 +03:00
|
|
|
else
|
2000-05-10 03:03:41 +04:00
|
|
|
// We always want a "Yes" string, so supply the default
|
2000-04-18 11:44:58 +04:00
|
|
|
GetBundleString(NS_ConvertASCIItoUCS2("Yes"), yesStr);
|
2000-03-20 18:44:32 +03:00
|
|
|
|
2000-05-10 03:03:41 +04:00
|
|
|
if (aNoString && aNoString->Length() > 0)
|
|
|
|
{
|
2000-04-18 11:44:58 +04:00
|
|
|
noStr.Assign(*aNoString);
|
2000-05-10 03:03:41 +04:00
|
|
|
block->SetString( nsICommonDialogs::eButton2Text, noStr.GetUnicode() );
|
|
|
|
}
|
2000-03-20 18:44:32 +03:00
|
|
|
else
|
2000-05-10 03:03:41 +04:00
|
|
|
{
|
|
|
|
// No string for "No" means we only want Yes, Cancel
|
|
|
|
numberOfButtons = 2;
|
|
|
|
}
|
|
|
|
block->SetInt( nsICommonDialogs::eNumberButtons, numberOfButtons );
|
2000-03-20 18:44:32 +03:00
|
|
|
|
|
|
|
nsAutoString cancelStr;
|
2000-04-18 11:44:58 +04:00
|
|
|
GetBundleString(NS_ConvertASCIItoUCS2("Cancel"), cancelStr);
|
2000-03-20 18:44:32 +03:00
|
|
|
|
2000-02-19 04:53:59 +03:00
|
|
|
block->SetString( nsICommonDialogs::eDialogTitle, aTitle.GetUnicode() );
|
1999-10-14 04:13:27 +04:00
|
|
|
//Note: "button0" is always Ok or Yes action, "button1" is Cancel
|
2000-03-20 18:44:32 +03:00
|
|
|
block->SetString( nsICommonDialogs::eButton0Text, yesStr.GetUnicode() );
|
|
|
|
block->SetString( nsICommonDialogs::eButton1Text, cancelStr.GetUnicode() );
|
1999-09-03 05:23:19 +04:00
|
|
|
|
|
|
|
NS_WITH_SERVICE(nsICommonDialogs, dialog, kCommonDialogsCID, &rv);
|
|
|
|
if ( NS_SUCCEEDED( rv ) )
|
|
|
|
{
|
|
|
|
PRInt32 buttonPressed = 0;
|
2000-05-14 09:27:17 +04:00
|
|
|
if(!mContentWindow)
|
|
|
|
return result;
|
|
|
|
nsCOMPtr<nsIDOMWindow> cwP = do_QueryReferent(mContentWindow);
|
|
|
|
if (!cwP) return result;
|
|
|
|
rv = dialog->DoDialog( cwP, block, "chrome://global/content/commonDialog.xul" );
|
1999-09-03 05:23:19 +04:00
|
|
|
block->GetInt( nsICommonDialogs::eButtonPressed, &buttonPressed );
|
|
|
|
// NOTE: If order of buttons changes in nsICommonDialogs,
|
|
|
|
// then we must change the EConfirmResult enums in nsEditorShell.h
|
|
|
|
result = nsEditorShell::EConfirmResult(buttonPressed);
|
|
|
|
}
|
|
|
|
NS_IF_RELEASE( block );
|
|
|
|
}
|
|
|
|
return result;
|
1999-09-01 05:22:37 +04:00
|
|
|
}
|
|
|
|
|
1999-09-03 05:23:19 +04:00
|
|
|
// Utility to bring up a OK/Cancel dialog.
|
1999-08-31 04:51:23 +04:00
|
|
|
PRBool
|
1999-09-03 05:23:19 +04:00
|
|
|
nsEditorShell::Confirm(const nsString& aTitle, const nsString& aQuestion)
|
1999-08-31 04:51:23 +04:00
|
|
|
{
|
1999-09-03 05:23:19 +04:00
|
|
|
nsresult rv;
|
1999-08-31 04:51:23 +04:00
|
|
|
PRBool result = PR_FALSE;
|
|
|
|
|
1999-09-03 05:23:19 +04:00
|
|
|
NS_WITH_SERVICE(nsICommonDialogs, dialog, kCommonDialogsCID, &rv);
|
|
|
|
if (NS_SUCCEEDED(rv) && dialog)
|
|
|
|
{
|
2000-05-14 09:27:17 +04:00
|
|
|
if(!mContentWindow)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
nsCOMPtr<nsIDOMWindow> cwP = do_QueryReferent(mContentWindow);
|
|
|
|
if (!cwP) return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
rv = dialog->Confirm(cwP, aTitle.GetUnicode(), aQuestion.GetUnicode(), &result);
|
1999-09-03 05:23:19 +04:00
|
|
|
}
|
1999-08-31 04:51:23 +04:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2000-04-06 05:17:54 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::AlertWithTitle(const PRUnichar *aTitle, const PRUnichar *aMsg)
|
|
|
|
{
|
|
|
|
if (!aTitle || !aMsg)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
NS_WITH_SERVICE(nsICommonDialogs, dialog, kCommonDialogsCID, &rv);
|
|
|
|
if (NS_SUCCEEDED(rv) && dialog)
|
2000-05-14 09:27:17 +04:00
|
|
|
{
|
|
|
|
if(!mContentWindow)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
nsCOMPtr<nsIDOMWindow> cwP = do_QueryReferent(mContentWindow);
|
|
|
|
if (!cwP) return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
rv = dialog->Alert(cwP, aTitle, aMsg);
|
|
|
|
}
|
2000-04-06 05:17:54 +04:00
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-09-03 05:23:19 +04:00
|
|
|
nsEditorShell::Alert(const nsString& aTitle, const nsString& aMsg)
|
1999-08-31 04:51:23 +04:00
|
|
|
{
|
1999-09-03 05:23:19 +04:00
|
|
|
nsresult rv;
|
|
|
|
NS_WITH_SERVICE(nsICommonDialogs, dialog, kCommonDialogsCID, &rv);
|
|
|
|
if (NS_SUCCEEDED(rv) && dialog)
|
1999-08-31 04:51:23 +04:00
|
|
|
{
|
2000-05-14 09:27:17 +04:00
|
|
|
if(!mContentWindow)
|
|
|
|
return;
|
|
|
|
nsCOMPtr<nsIDOMWindow> cwP = do_QueryReferent(mContentWindow);
|
|
|
|
if (!cwP) return;
|
|
|
|
rv = dialog->Alert(cwP, aTitle.GetUnicode(), aMsg.GetUnicode());
|
1999-08-28 06:40:18 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-08-14 02:26:50 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::GetDocumentCharacterSet(PRUnichar** characterSet)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(mEditor);
|
|
|
|
|
|
|
|
if (editor)
|
1999-09-08 10:26:53 +04:00
|
|
|
return editor->GetDocumentCharacterSet(characterSet);
|
1999-08-14 02:26:50 +04:00
|
|
|
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::SetDocumentCharacterSet(const PRUnichar* characterSet)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(mEditor);
|
|
|
|
|
|
|
|
if (editor)
|
1999-09-08 10:26:53 +04:00
|
|
|
return editor->SetDocumentCharacterSet(characterSet);
|
1999-08-14 02:26:50 +04:00
|
|
|
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
1999-06-11 03:50:26 +04:00
|
|
|
NS_IMETHODIMP
|
1999-07-14 22:54:29 +04:00
|
|
|
nsEditorShell::GetContentsAs(const PRUnichar *format, PRUint32 flags,
|
2000-04-28 09:59:16 +04:00
|
|
|
PRUnichar **aContentsAs)
|
1999-06-11 03:50:26 +04:00
|
|
|
{
|
|
|
|
nsresult err = NS_NOINTERFACE;
|
|
|
|
|
1999-09-15 03:40:16 +04:00
|
|
|
nsAutoString aFormat (format);
|
2000-04-28 09:59:16 +04:00
|
|
|
nsAutoString contentsAs;
|
1999-06-11 03:50:26 +04:00
|
|
|
|
1999-08-09 05:37:50 +04:00
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(mEditor);
|
|
|
|
if (editor)
|
2000-04-28 09:59:16 +04:00
|
|
|
err = editor->OutputToString(contentsAs, aFormat, flags);
|
1999-08-09 05:37:50 +04:00
|
|
|
|
2000-04-28 09:59:16 +04:00
|
|
|
*aContentsAs = contentsAs.ToNewUnicode();
|
1999-06-30 00:14:58 +04:00
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2000-04-28 09:59:16 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::GetHeadContentsAsHTML(PRUnichar **aHeadContents)
|
|
|
|
{
|
|
|
|
nsresult err = NS_NOINTERFACE;
|
|
|
|
|
|
|
|
nsAutoString headContents;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIHTMLEditor> editor = do_QueryInterface(mEditor);
|
|
|
|
if (editor)
|
|
|
|
err = editor->GetHeadContentsAsHTML(headContents);
|
|
|
|
|
|
|
|
*aHeadContents = headContents.ToNewUnicode();
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::ReplaceHeadContentsWithHTML(const PRUnichar *aSourceToInsert)
|
|
|
|
{
|
|
|
|
nsresult err = NS_NOINTERFACE;
|
|
|
|
|
|
|
|
nsAutoString sourceToInsert(aSourceToInsert);
|
|
|
|
|
|
|
|
switch (mEditorType)
|
|
|
|
{
|
|
|
|
case ePlainTextEditorType:
|
|
|
|
case eHTMLTextEditorType:
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
|
|
|
|
if (htmlEditor)
|
|
|
|
err = htmlEditor->ReplaceHeadContentsWithHTML(sourceToInsert);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
err = NS_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
1999-06-30 00:14:58 +04:00
|
|
|
NS_IMETHODIMP
|
1999-07-14 22:54:29 +04:00
|
|
|
nsEditorShell::DumpContentTree()
|
1999-06-30 00:14:58 +04:00
|
|
|
{
|
1999-07-14 22:54:29 +04:00
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(mEditor);
|
|
|
|
if (!editor)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
return editor->DumpContentTree();
|
1999-06-11 03:50:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::GetWrapColumn(PRInt32* aWrapColumn)
|
|
|
|
{
|
|
|
|
nsresult err = NS_NOINTERFACE;
|
|
|
|
|
|
|
|
if (!aWrapColumn)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
// fill result in case of failure
|
1999-07-14 22:54:29 +04:00
|
|
|
*aWrapColumn = mWrapColumn;
|
|
|
|
|
|
|
|
// If we don't have an editor yet, say we're not initialized
|
|
|
|
// even though mWrapColumn may have a value.
|
|
|
|
if (!mEditor)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
1999-06-11 03:50:26 +04:00
|
|
|
switch (mEditorType)
|
|
|
|
{
|
|
|
|
case ePlainTextEditorType:
|
|
|
|
{
|
1999-08-09 05:37:50 +04:00
|
|
|
nsCOMPtr<nsIEditorMailSupport> mailEditor = do_QueryInterface(mEditor);
|
|
|
|
if (mailEditor)
|
1999-06-30 23:26:08 +04:00
|
|
|
{
|
1999-07-01 23:01:04 +04:00
|
|
|
PRInt32 wc;
|
1999-08-09 05:37:50 +04:00
|
|
|
err = mailEditor->GetBodyWrapWidth(&wc);
|
1999-06-30 23:26:08 +04:00
|
|
|
if (NS_SUCCEEDED(err))
|
|
|
|
*aWrapColumn = (PRInt32)wc;
|
|
|
|
}
|
1999-06-11 03:50:26 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
err = NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::SetWrapColumn(PRInt32 aWrapColumn)
|
|
|
|
{
|
1999-07-14 22:54:29 +04:00
|
|
|
nsresult err = NS_OK;
|
|
|
|
|
|
|
|
mWrapColumn = aWrapColumn;
|
|
|
|
|
|
|
|
if (mEditor)
|
1999-06-11 03:50:26 +04:00
|
|
|
{
|
1999-07-14 22:54:29 +04:00
|
|
|
switch (mEditorType)
|
|
|
|
{
|
|
|
|
case ePlainTextEditorType:
|
|
|
|
{
|
1999-08-09 05:37:50 +04:00
|
|
|
nsCOMPtr<nsIEditorMailSupport> mailEditor = do_QueryInterface(mEditor);
|
|
|
|
if (mailEditor)
|
|
|
|
err = mailEditor->SetBodyWrapWidth(mWrapColumn);
|
1999-07-14 22:54:29 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
err = NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
1999-06-11 03:50:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-09-20 03:46:35 +04:00
|
|
|
nsEditorShell::SetParagraphFormat(const PRUnichar * paragraphFormat)
|
1999-06-11 03:50:26 +04:00
|
|
|
{
|
|
|
|
nsresult err = NS_NOINTERFACE;
|
|
|
|
|
|
|
|
nsAutoString aParagraphFormat(paragraphFormat);
|
|
|
|
|
|
|
|
switch (mEditorType)
|
|
|
|
{
|
|
|
|
case eHTMLTextEditorType:
|
1999-08-09 05:37:50 +04:00
|
|
|
err = mEditor->SetParagraphFormat(aParagraphFormat);
|
1999-06-11 03:50:26 +04:00
|
|
|
break;
|
1999-08-09 05:37:50 +04:00
|
|
|
|
1999-06-11 03:50:26 +04:00
|
|
|
default:
|
|
|
|
err = NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
1999-11-11 03:58:40 +03:00
|
|
|
NS_IMETHODIMP
|
1999-06-11 03:50:26 +04:00
|
|
|
nsEditorShell::GetEditorDocument(nsIDOMDocument** aEditorDocument)
|
|
|
|
{
|
|
|
|
if (mEditor)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(mEditor);
|
|
|
|
if (editor)
|
|
|
|
{
|
|
|
|
return editor->GetDocument(aEditorDocument);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
1999-11-11 03:58:40 +03:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::GetEditor(nsIEditor** aEditor)
|
|
|
|
{
|
|
|
|
if (mEditor)
|
|
|
|
return mEditor->QueryInterface(NS_GET_IID(nsIEditor), (void **)aEditor); // the QI does the addref
|
|
|
|
|
|
|
|
*aEditor = nsnull;
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-06-11 03:50:26 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::GetEditorSelection(nsIDOMSelection** aEditorSelection)
|
|
|
|
{
|
1999-09-09 03:32:04 +04:00
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(mEditor);
|
|
|
|
if (editor)
|
1999-06-11 03:50:26 +04:00
|
|
|
return editor->GetSelection(aEditorSelection);
|
|
|
|
|
|
|
|
return NS_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
1999-12-03 00:47:30 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::GetSelectionController(nsISelectionController** aSelectionController)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(mEditor);
|
|
|
|
if (!editor)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
2000-04-27 11:37:12 +04:00
|
|
|
nsCOMPtr<nsISelectionController> selCont;
|
|
|
|
nsresult rv = editor->GetSelectionController(getter_AddRefs(selCont));
|
1999-12-03 00:47:30 +03:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
if (!selCont)
|
|
|
|
return NS_ERROR_NO_INTERFACE;
|
|
|
|
*aSelectionController = selCont;
|
|
|
|
NS_IF_ADDREF(*aSelectionController);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-07-15 02:30:39 +04:00
|
|
|
NS_IMETHODIMP
|
1999-07-28 06:54:35 +04:00
|
|
|
nsEditorShell::GetDocumentModified(PRBool *aDocumentModified)
|
1999-07-15 02:30:39 +04:00
|
|
|
{
|
1999-07-28 06:54:35 +04:00
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(mEditor);
|
|
|
|
if (editor)
|
|
|
|
return editor->GetDocumentModified(aDocumentModified);
|
1999-07-15 02:30:39 +04:00
|
|
|
|
1999-07-28 06:54:35 +04:00
|
|
|
return NS_NOINTERFACE;
|
1999-07-15 02:30:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-09-09 03:32:04 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::GetDocumentIsEmpty(PRBool *aDocumentIsEmpty)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(mEditor);
|
|
|
|
if (editor)
|
|
|
|
return editor->GetDocumentIsEmpty(aDocumentIsEmpty);
|
|
|
|
|
|
|
|
return NS_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
2000-05-02 01:49:52 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::GetDocumentEditable(PRBool *aDocumentEditable)
|
|
|
|
{
|
|
|
|
*aDocumentEditable = PR_FALSE; // default return value
|
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(mEditor);
|
|
|
|
if (!editor) return NS_OK;
|
|
|
|
|
|
|
|
PRUint32 editorFlags;
|
|
|
|
editor->GetFlags(&editorFlags);
|
|
|
|
|
|
|
|
if (editorFlags & nsIHTMLEditor::eEditorReadonlyMask)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMDocument> doc;
|
|
|
|
editor->GetDocument(getter_AddRefs(doc));
|
|
|
|
if (!doc) return NS_OK;
|
|
|
|
|
|
|
|
*aDocumentEditable = PR_TRUE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-09-09 03:32:04 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::GetDocumentLength(PRInt32 *aDocumentLength)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIHTMLEditor> editor = do_QueryInterface(mEditor);
|
|
|
|
if (editor)
|
|
|
|
return editor->GetDocumentLength(aDocumentLength);
|
|
|
|
|
|
|
|
return NS_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-06-11 03:50:26 +04:00
|
|
|
NS_IMETHODIMP
|
1999-10-27 03:13:00 +04:00
|
|
|
nsEditorShell::MakeOrChangeList(const PRUnichar *listType)
|
1999-06-11 03:50:26 +04:00
|
|
|
{
|
|
|
|
nsresult err = NS_NOINTERFACE;
|
|
|
|
|
|
|
|
nsAutoString aListType(listType);
|
|
|
|
|
|
|
|
switch (mEditorType)
|
|
|
|
{
|
|
|
|
case eHTMLTextEditorType:
|
2000-03-26 15:39:08 +04:00
|
|
|
if (aListType.IsEmpty())
|
1999-10-27 03:13:00 +04:00
|
|
|
{
|
2000-04-18 11:44:58 +04:00
|
|
|
err = mEditor->RemoveList(NS_ConvertASCIItoUCS2("ol"));
|
1999-10-27 03:13:00 +04:00
|
|
|
if(NS_SUCCEEDED(err))
|
|
|
|
{
|
2000-04-18 11:44:58 +04:00
|
|
|
err = mEditor->RemoveList(NS_ConvertASCIItoUCS2("ul"));
|
1999-10-27 03:13:00 +04:00
|
|
|
if(NS_SUCCEEDED(err))
|
2000-04-18 11:44:58 +04:00
|
|
|
err = mEditor->RemoveList(NS_ConvertASCIItoUCS2("dl"));
|
1999-10-27 03:13:00 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
err = mEditor->MakeOrChangeList(aListType);
|
1999-06-11 03:50:26 +04:00
|
|
|
break;
|
1999-08-09 05:37:50 +04:00
|
|
|
|
1999-06-11 03:50:26 +04:00
|
|
|
case ePlainTextEditorType:
|
|
|
|
default:
|
|
|
|
err = NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
1999-09-06 23:47:25 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::RemoveList(const PRUnichar *listType)
|
|
|
|
{
|
|
|
|
nsresult err = NS_NOINTERFACE;
|
|
|
|
|
|
|
|
nsAutoString aListType(listType);
|
|
|
|
|
|
|
|
switch (mEditorType)
|
|
|
|
{
|
|
|
|
case eHTMLTextEditorType:
|
2000-03-26 15:39:08 +04:00
|
|
|
if (aListType.IsEmpty())
|
1999-10-27 03:13:00 +04:00
|
|
|
{
|
2000-04-18 11:44:58 +04:00
|
|
|
err = mEditor->RemoveList(NS_ConvertASCIItoUCS2("ol"));
|
1999-10-27 03:13:00 +04:00
|
|
|
if(NS_SUCCEEDED(err))
|
|
|
|
{
|
2000-04-18 11:44:58 +04:00
|
|
|
err = mEditor->RemoveList(NS_ConvertASCIItoUCS2("ul"));
|
1999-10-27 03:13:00 +04:00
|
|
|
if(NS_SUCCEEDED(err))
|
2000-04-18 11:44:58 +04:00
|
|
|
err = mEditor->RemoveList(NS_ConvertASCIItoUCS2("dl"));
|
1999-10-27 03:13:00 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
err = mEditor->RemoveList(aListType);
|
1999-09-06 23:47:25 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ePlainTextEditorType:
|
|
|
|
default:
|
|
|
|
err = NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
1999-06-11 03:50:26 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::Indent(const PRUnichar *indent)
|
|
|
|
{
|
|
|
|
nsresult err = NS_NOINTERFACE;
|
|
|
|
|
|
|
|
nsAutoString aIndent(indent);
|
|
|
|
|
|
|
|
switch (mEditorType)
|
|
|
|
{
|
|
|
|
case eHTMLTextEditorType:
|
1999-08-09 05:37:50 +04:00
|
|
|
err = mEditor->Indent(aIndent);
|
1999-06-11 03:50:26 +04:00
|
|
|
break;
|
1999-08-09 05:37:50 +04:00
|
|
|
|
1999-06-11 03:50:26 +04:00
|
|
|
case ePlainTextEditorType:
|
|
|
|
default:
|
|
|
|
err = NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::Align(const PRUnichar *align)
|
|
|
|
{
|
|
|
|
nsresult err = NS_NOINTERFACE;
|
|
|
|
|
|
|
|
nsAutoString aAlignType(align);
|
|
|
|
|
|
|
|
switch (mEditorType)
|
|
|
|
{
|
|
|
|
case eHTMLTextEditorType:
|
1999-08-09 05:37:50 +04:00
|
|
|
err = mEditor->Align(aAlignType);
|
1999-06-11 03:50:26 +04:00
|
|
|
break;
|
1999-08-09 05:37:50 +04:00
|
|
|
|
1999-06-11 03:50:26 +04:00
|
|
|
case ePlainTextEditorType:
|
|
|
|
default:
|
|
|
|
err = NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-08-09 05:37:50 +04:00
|
|
|
nsEditorShell::GetSelectedElement(const PRUnichar *aInTagName, nsIDOMElement **aOutElement)
|
1999-06-11 03:50:26 +04:00
|
|
|
{
|
1999-08-09 05:37:50 +04:00
|
|
|
if (!aInTagName || !aOutElement)
|
1999-06-11 03:50:26 +04:00
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
nsresult result = NS_NOINTERFACE;
|
1999-08-09 05:37:50 +04:00
|
|
|
nsAutoString tagName(aInTagName);
|
1999-06-11 03:50:26 +04:00
|
|
|
|
|
|
|
switch (mEditorType)
|
|
|
|
{
|
|
|
|
case eHTMLTextEditorType:
|
1999-08-09 05:37:50 +04:00
|
|
|
result = mEditor->GetSelectedElement(tagName, aOutElement);
|
2000-05-02 07:24:11 +04:00
|
|
|
// Don't return NS_EDITOR_ELEMENT_NOT_FOUND (passes NS_SUCCEEDED macro)
|
|
|
|
// to JavaScript
|
|
|
|
if(NS_SUCCEEDED(result)) return NS_OK;
|
1999-06-11 03:50:26 +04:00
|
|
|
break;
|
1999-08-09 05:37:50 +04:00
|
|
|
|
1999-06-11 03:50:26 +04:00
|
|
|
case ePlainTextEditorType:
|
|
|
|
default:
|
|
|
|
result = NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2000-03-21 09:05:24 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::GetFirstSelectedCell(nsIDOMElement **aOutElement)
|
|
|
|
{
|
|
|
|
if (!aOutElement)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
nsresult result = NS_NOINTERFACE;
|
|
|
|
|
|
|
|
switch (mEditorType)
|
|
|
|
{
|
|
|
|
case eHTMLTextEditorType:
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsITableEditor> tableEditor = do_QueryInterface(mEditor);
|
|
|
|
if (tableEditor)
|
2000-05-02 07:24:11 +04:00
|
|
|
{
|
2000-03-31 08:18:29 +04:00
|
|
|
result = tableEditor->GetFirstSelectedCell(aOutElement, nsnull);
|
2000-05-02 07:24:11 +04:00
|
|
|
// Don't return NS_EDITOR_ELEMENT_NOT_FOUND (passes NS_SUCCEEDED macro)
|
|
|
|
// to JavaScript
|
|
|
|
if(NS_SUCCEEDED(result)) return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-03-21 09:05:24 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case ePlainTextEditorType:
|
|
|
|
default:
|
|
|
|
result = NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2000-05-15 07:06:29 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::GetFirstSelectedCellInTable(PRInt32 *aRowIndex, PRInt32 *aColIndex, nsIDOMElement **aOutElement)
|
|
|
|
{
|
|
|
|
if (!aOutElement || !aRowIndex || !aColIndex)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
nsresult result = NS_NOINTERFACE;
|
|
|
|
|
|
|
|
switch (mEditorType)
|
|
|
|
{
|
|
|
|
case eHTMLTextEditorType:
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsITableEditor> tableEditor = do_QueryInterface(mEditor);
|
|
|
|
if (tableEditor)
|
|
|
|
{
|
|
|
|
result = tableEditor->GetFirstSelectedCellInTable(aOutElement, aRowIndex, aColIndex);
|
|
|
|
// Don't return NS_EDITOR_ELEMENT_NOT_FOUND (passes NS_SUCCEEDED macro)
|
|
|
|
// to JavaScript
|
|
|
|
if(NS_SUCCEEDED(result)) return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case ePlainTextEditorType:
|
|
|
|
default:
|
|
|
|
result = NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2000-03-21 09:05:24 +03:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::GetNextSelectedCell(nsIDOMElement **aOutElement)
|
|
|
|
{
|
|
|
|
if (!aOutElement)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
nsresult result = NS_NOINTERFACE;
|
|
|
|
|
|
|
|
switch (mEditorType)
|
|
|
|
{
|
|
|
|
case eHTMLTextEditorType:
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsITableEditor> tableEditor = do_QueryInterface(mEditor);
|
|
|
|
if (tableEditor)
|
2000-03-31 08:18:29 +04:00
|
|
|
result = tableEditor->GetNextSelectedCell(aOutElement, nsnull);
|
2000-03-21 09:05:24 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case ePlainTextEditorType:
|
|
|
|
default:
|
|
|
|
result = NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-07-28 03:59:22 +04:00
|
|
|
NS_IMETHODIMP
|
1999-08-09 05:37:50 +04:00
|
|
|
nsEditorShell::GetElementOrParentByTagName(const PRUnichar *aInTagName, nsIDOMNode *node, nsIDOMElement **aOutElement)
|
1999-07-28 03:59:22 +04:00
|
|
|
{
|
1999-08-02 02:37:58 +04:00
|
|
|
//node can be null -- this signals using the selection anchorNode
|
1999-08-09 05:37:50 +04:00
|
|
|
if (!aInTagName || !aOutElement)
|
1999-07-28 03:59:22 +04:00
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
nsresult result = NS_NOINTERFACE;
|
1999-08-09 05:37:50 +04:00
|
|
|
nsAutoString tagName(aInTagName);
|
1999-07-28 03:59:22 +04:00
|
|
|
|
|
|
|
switch (mEditorType)
|
|
|
|
{
|
|
|
|
case eHTMLTextEditorType:
|
1999-08-09 05:37:50 +04:00
|
|
|
result = mEditor->GetElementOrParentByTagName(tagName, node, aOutElement);
|
2000-05-02 07:24:11 +04:00
|
|
|
// Don't return NS_EDITOR_ELEMENT_NOT_FOUND (passes NS_SUCCEEDED macro)
|
|
|
|
// to JavaScript
|
|
|
|
if(NS_SUCCEEDED(result)) return NS_OK;
|
1999-07-28 03:59:22 +04:00
|
|
|
break;
|
1999-08-09 05:37:50 +04:00
|
|
|
|
|
|
|
case ePlainTextEditorType:
|
1999-07-28 03:59:22 +04:00
|
|
|
default:
|
|
|
|
result = NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1999-06-11 03:50:26 +04:00
|
|
|
NS_IMETHODIMP
|
1999-08-09 05:37:50 +04:00
|
|
|
nsEditorShell::CreateElementWithDefaults(const PRUnichar *aInTagName, nsIDOMElement **aOutElement)
|
1999-06-11 03:50:26 +04:00
|
|
|
{
|
1999-08-09 05:37:50 +04:00
|
|
|
if (!aOutElement)
|
1999-06-11 03:50:26 +04:00
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
nsresult result = NS_NOINTERFACE;
|
1999-08-09 05:37:50 +04:00
|
|
|
nsAutoString tagName(aInTagName);
|
1999-06-11 03:50:26 +04:00
|
|
|
|
|
|
|
switch (mEditorType)
|
|
|
|
{
|
|
|
|
case eHTMLTextEditorType:
|
1999-08-09 05:37:50 +04:00
|
|
|
result = mEditor->CreateElementWithDefaults(tagName, aOutElement);
|
1999-06-11 03:50:26 +04:00
|
|
|
break;
|
1999-08-09 05:37:50 +04:00
|
|
|
|
1999-06-11 03:50:26 +04:00
|
|
|
case ePlainTextEditorType:
|
|
|
|
default:
|
|
|
|
result = NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-10-14 04:13:27 +04:00
|
|
|
nsEditorShell::DeleteElement(nsIDOMElement *element)
|
|
|
|
{
|
|
|
|
if (!element)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
nsresult result = NS_NOINTERFACE;
|
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(mEditor);
|
|
|
|
if (editor) {
|
|
|
|
// The nsIEditor::DeleteNode() wants a node
|
|
|
|
// but it actually requires that it is an element!
|
|
|
|
nsCOMPtr<nsIDOMNode> node = do_QueryInterface(element);
|
|
|
|
result = editor->DeleteNode(node);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::InsertElement(nsIDOMElement *element, nsIDOMElement *parent, PRInt32 position)
|
|
|
|
{
|
|
|
|
if (!element || !parent)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
nsresult result = NS_NOINTERFACE;
|
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(mEditor);
|
|
|
|
if (editor) {
|
|
|
|
// The nsIEditor::InsertNode() wants nodes as params,
|
|
|
|
// but it actually requires that they are elements!
|
|
|
|
nsCOMPtr<nsIDOMNode> node = do_QueryInterface(element);
|
|
|
|
nsCOMPtr<nsIDOMNode> parentNode = do_QueryInterface(parent);
|
|
|
|
result = editor->InsertNode(node, parentNode, position);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::InsertElementAtSelection(nsIDOMElement *element, PRBool deleteSelection)
|
1999-06-11 03:50:26 +04:00
|
|
|
{
|
1999-06-11 22:57:33 +04:00
|
|
|
if (!element)
|
1999-06-11 03:50:26 +04:00
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
nsresult result = NS_NOINTERFACE;
|
1999-06-11 22:57:33 +04:00
|
|
|
switch (mEditorType)
|
1999-06-11 03:50:26 +04:00
|
|
|
{
|
|
|
|
case eHTMLTextEditorType:
|
1999-10-14 04:13:27 +04:00
|
|
|
result = mEditor->InsertElementAtSelection(element, deleteSelection);
|
1999-06-11 03:50:26 +04:00
|
|
|
break;
|
1999-08-09 05:37:50 +04:00
|
|
|
|
|
|
|
case ePlainTextEditorType:
|
1999-06-11 03:50:26 +04:00
|
|
|
default:
|
|
|
|
result = NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::InsertLinkAroundSelection(nsIDOMElement* aAnchorElement)
|
|
|
|
{
|
|
|
|
nsresult result = NS_NOINTERFACE;
|
|
|
|
switch (mEditorType)
|
|
|
|
{
|
|
|
|
case eHTMLTextEditorType:
|
1999-08-09 05:37:50 +04:00
|
|
|
result = mEditor->InsertLinkAroundSelection(aAnchorElement);
|
1999-06-11 03:50:26 +04:00
|
|
|
break;
|
1999-08-09 05:37:50 +04:00
|
|
|
|
|
|
|
case ePlainTextEditorType:
|
1999-06-11 03:50:26 +04:00
|
|
|
default:
|
|
|
|
result = NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::SelectElement(nsIDOMElement* aElement)
|
|
|
|
{
|
|
|
|
if (!aElement)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
nsresult result = NS_NOINTERFACE;
|
|
|
|
switch (mEditorType)
|
|
|
|
{
|
|
|
|
case eHTMLTextEditorType:
|
1999-08-09 05:37:50 +04:00
|
|
|
result = mEditor->SelectElement(aElement);
|
1999-06-11 03:50:26 +04:00
|
|
|
break;
|
1999-08-09 05:37:50 +04:00
|
|
|
|
|
|
|
case ePlainTextEditorType:
|
1999-06-11 03:50:26 +04:00
|
|
|
default:
|
|
|
|
result = NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::SetSelectionAfterElement(nsIDOMElement* aElement)
|
|
|
|
{
|
|
|
|
if (!aElement)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
nsresult result = NS_NOINTERFACE;
|
|
|
|
switch (mEditorType)
|
|
|
|
{
|
|
|
|
case eHTMLTextEditorType:
|
1999-08-09 05:37:50 +04:00
|
|
|
result = mEditor->SetCaretAfterElement(aElement);
|
1999-06-11 03:50:26 +04:00
|
|
|
break;
|
1999-08-09 05:37:50 +04:00
|
|
|
|
|
|
|
case ePlainTextEditorType:
|
1999-06-11 03:50:26 +04:00
|
|
|
default:
|
|
|
|
result = NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1999-07-28 03:59:22 +04:00
|
|
|
/* Table Editing */
|
1999-08-04 06:06:03 +04:00
|
|
|
NS_IMETHODIMP
|
1999-12-04 04:46:23 +03:00
|
|
|
nsEditorShell::InsertTableRow(PRInt32 aNumber, PRBool bAfter)
|
1999-08-04 06:06:03 +04:00
|
|
|
{
|
|
|
|
nsresult result = NS_NOINTERFACE;
|
|
|
|
switch (mEditorType)
|
|
|
|
{
|
|
|
|
case eHTMLTextEditorType:
|
|
|
|
{
|
1999-08-09 05:37:50 +04:00
|
|
|
nsCOMPtr<nsITableEditor> tableEditor = do_QueryInterface(mEditor);
|
|
|
|
if (tableEditor)
|
1999-12-04 04:46:23 +03:00
|
|
|
result = tableEditor->InsertTableRow(aNumber,bAfter);
|
1999-08-04 06:06:03 +04:00
|
|
|
}
|
|
|
|
break;
|
1999-08-09 05:37:50 +04:00
|
|
|
|
|
|
|
case ePlainTextEditorType:
|
1999-08-04 06:06:03 +04:00
|
|
|
default:
|
|
|
|
result = NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-12-04 04:46:23 +03:00
|
|
|
nsEditorShell::InsertTableColumn(PRInt32 aNumber, PRBool bAfter)
|
1999-08-04 06:06:03 +04:00
|
|
|
{
|
|
|
|
nsresult result = NS_NOINTERFACE;
|
|
|
|
switch (mEditorType)
|
|
|
|
{
|
|
|
|
case eHTMLTextEditorType:
|
|
|
|
{
|
1999-08-09 05:37:50 +04:00
|
|
|
nsCOMPtr<nsITableEditor> tableEditor = do_QueryInterface(mEditor);
|
|
|
|
if (tableEditor)
|
1999-12-04 04:46:23 +03:00
|
|
|
result = tableEditor->InsertTableColumn(aNumber,bAfter);
|
1999-08-04 06:06:03 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
result = NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-12-04 04:46:23 +03:00
|
|
|
nsEditorShell::InsertTableCell(PRInt32 aNumber, PRBool bAfter)
|
1999-08-04 06:06:03 +04:00
|
|
|
{
|
|
|
|
nsresult result = NS_NOINTERFACE;
|
|
|
|
switch (mEditorType)
|
|
|
|
{
|
|
|
|
case eHTMLTextEditorType:
|
|
|
|
{
|
1999-08-09 05:37:50 +04:00
|
|
|
nsCOMPtr<nsITableEditor> tableEditor = do_QueryInterface(mEditor);
|
|
|
|
if (tableEditor)
|
1999-12-04 04:46:23 +03:00
|
|
|
result = tableEditor->InsertTableCell(aNumber, bAfter);
|
1999-08-04 06:06:03 +04:00
|
|
|
}
|
|
|
|
break;
|
1999-12-04 04:46:23 +03:00
|
|
|
|
|
|
|
case ePlainTextEditorType:
|
1999-08-04 06:06:03 +04:00
|
|
|
default:
|
|
|
|
result = NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::DeleteTable()
|
|
|
|
{
|
|
|
|
nsresult result = NS_NOINTERFACE;
|
|
|
|
switch (mEditorType)
|
|
|
|
{
|
|
|
|
case eHTMLTextEditorType:
|
|
|
|
{
|
1999-08-09 05:37:50 +04:00
|
|
|
nsCOMPtr<nsITableEditor> tableEditor = do_QueryInterface(mEditor);
|
|
|
|
if (tableEditor)
|
|
|
|
result = tableEditor->DeleteTable();
|
1999-08-04 06:06:03 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
result = NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::DeleteTableCell(PRInt32 aNumber)
|
|
|
|
{
|
|
|
|
nsresult result = NS_NOINTERFACE;
|
|
|
|
switch (mEditorType)
|
|
|
|
{
|
|
|
|
case eHTMLTextEditorType:
|
|
|
|
{
|
1999-08-09 05:37:50 +04:00
|
|
|
nsCOMPtr<nsITableEditor> tableEditor = do_QueryInterface(mEditor);
|
|
|
|
if (tableEditor)
|
|
|
|
result = tableEditor->DeleteTableCell(aNumber);
|
1999-08-04 06:06:03 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
result = NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2000-01-14 02:33:00 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::DeleteTableCellContents()
|
|
|
|
{
|
|
|
|
nsresult result = NS_NOINTERFACE;
|
|
|
|
switch (mEditorType)
|
|
|
|
{
|
|
|
|
case eHTMLTextEditorType:
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsITableEditor> tableEditor = do_QueryInterface(mEditor);
|
|
|
|
if (tableEditor)
|
|
|
|
result = tableEditor->DeleteTableCellContents();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
result = NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
1999-08-04 06:06:03 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::DeleteTableRow(PRInt32 aNumber)
|
|
|
|
{
|
|
|
|
nsresult result = NS_NOINTERFACE;
|
|
|
|
switch (mEditorType)
|
|
|
|
{
|
|
|
|
case eHTMLTextEditorType:
|
|
|
|
{
|
1999-08-09 05:37:50 +04:00
|
|
|
nsCOMPtr<nsITableEditor> tableEditor = do_QueryInterface(mEditor);
|
|
|
|
if (tableEditor)
|
|
|
|
result = tableEditor->DeleteTableRow(aNumber);
|
1999-08-04 06:06:03 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
result = NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::DeleteTableColumn(PRInt32 aNumber)
|
|
|
|
{
|
|
|
|
nsresult result = NS_NOINTERFACE;
|
|
|
|
switch (mEditorType)
|
|
|
|
{
|
|
|
|
case eHTMLTextEditorType:
|
|
|
|
{
|
1999-08-09 05:37:50 +04:00
|
|
|
nsCOMPtr<nsITableEditor> tableEditor = do_QueryInterface(mEditor);
|
|
|
|
if (tableEditor)
|
|
|
|
result = tableEditor->DeleteTableColumn(aNumber);
|
1999-08-04 06:06:03 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
result = NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::JoinTableCells()
|
|
|
|
{
|
|
|
|
nsresult result = NS_NOINTERFACE;
|
|
|
|
switch (mEditorType)
|
|
|
|
{
|
|
|
|
case eHTMLTextEditorType:
|
|
|
|
{
|
1999-08-09 05:37:50 +04:00
|
|
|
nsCOMPtr<nsITableEditor> tableEditor = do_QueryInterface(mEditor);
|
|
|
|
if (tableEditor)
|
|
|
|
result = tableEditor->JoinTableCells();
|
1999-08-04 06:06:03 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
result = NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2000-05-05 02:32:24 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::SplitTableCell()
|
|
|
|
{
|
|
|
|
nsresult result = NS_NOINTERFACE;
|
|
|
|
switch (mEditorType)
|
|
|
|
{
|
|
|
|
case eHTMLTextEditorType:
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsITableEditor> tableEditor = do_QueryInterface(mEditor);
|
|
|
|
if (tableEditor)
|
|
|
|
result = tableEditor->SplitTableCell();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
result = NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2000-02-10 08:14:52 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::SelectTableCell()
|
|
|
|
{
|
|
|
|
nsresult result = NS_NOINTERFACE;
|
|
|
|
switch (mEditorType)
|
|
|
|
{
|
|
|
|
case eHTMLTextEditorType:
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsITableEditor> tableEditor = do_QueryInterface(mEditor);
|
|
|
|
if (tableEditor)
|
|
|
|
result = tableEditor->SelectTableCell();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
result = NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2000-03-17 02:45:41 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::SelectBlockOfCells(nsIDOMElement *aStartCell, nsIDOMElement *aEndCell)
|
|
|
|
{
|
|
|
|
nsresult result = NS_NOINTERFACE;
|
|
|
|
switch (mEditorType)
|
|
|
|
{
|
|
|
|
case eHTMLTextEditorType:
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsITableEditor> tableEditor = do_QueryInterface(mEditor);
|
|
|
|
if (tableEditor)
|
|
|
|
result = tableEditor->SelectBlockOfCells(aStartCell, aEndCell);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
result = NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-02-10 08:14:52 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::SelectTableRow()
|
|
|
|
{
|
|
|
|
nsresult result = NS_NOINTERFACE;
|
|
|
|
switch (mEditorType)
|
|
|
|
{
|
|
|
|
case eHTMLTextEditorType:
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsITableEditor> tableEditor = do_QueryInterface(mEditor);
|
|
|
|
if (tableEditor)
|
|
|
|
result = tableEditor->SelectTableRow();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
result = NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::SelectTableColumn()
|
|
|
|
{
|
|
|
|
nsresult result = NS_NOINTERFACE;
|
|
|
|
switch (mEditorType)
|
|
|
|
{
|
|
|
|
case eHTMLTextEditorType:
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsITableEditor> tableEditor = do_QueryInterface(mEditor);
|
|
|
|
if (tableEditor)
|
|
|
|
result = tableEditor->SelectTableColumn();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
result = NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::SelectTable()
|
|
|
|
{
|
|
|
|
nsresult result = NS_NOINTERFACE;
|
|
|
|
switch (mEditorType)
|
|
|
|
{
|
|
|
|
case eHTMLTextEditorType:
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsITableEditor> tableEditor = do_QueryInterface(mEditor);
|
|
|
|
if (tableEditor)
|
|
|
|
result = tableEditor->SelectTable();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
result = NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::SelectAllTableCells()
|
|
|
|
{
|
|
|
|
nsresult result = NS_NOINTERFACE;
|
|
|
|
switch (mEditorType)
|
|
|
|
{
|
|
|
|
case eHTMLTextEditorType:
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsITableEditor> tableEditor = do_QueryInterface(mEditor);
|
|
|
|
if (tableEditor)
|
|
|
|
result = tableEditor->SelectAllTableCells();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
result = NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1999-08-04 06:06:03 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::NormalizeTable(nsIDOMElement *aTable)
|
|
|
|
{
|
|
|
|
nsresult result = NS_NOINTERFACE;
|
|
|
|
switch (mEditorType)
|
|
|
|
{
|
|
|
|
case eHTMLTextEditorType:
|
|
|
|
{
|
1999-08-09 05:37:50 +04:00
|
|
|
nsCOMPtr<nsITableEditor> tableEditor = do_QueryInterface(mEditor);
|
|
|
|
if (tableEditor)
|
|
|
|
result = tableEditor->NormalizeTable(aTable);
|
1999-08-04 06:06:03 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
result = NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1999-08-02 02:37:58 +04:00
|
|
|
// The next four methods are factored to return single items
|
|
|
|
// separately for row and column.
|
|
|
|
// Underlying implementation gets both at the same time for efficiency.
|
|
|
|
|
1999-07-28 03:59:22 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::GetRowIndex(nsIDOMElement *cellElement, PRInt32 *_retval)
|
|
|
|
{
|
1999-08-02 02:37:58 +04:00
|
|
|
if (!_retval)
|
1999-07-28 03:59:22 +04:00
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
nsresult result = NS_NOINTERFACE;
|
|
|
|
switch (mEditorType)
|
|
|
|
{
|
|
|
|
case eHTMLTextEditorType:
|
|
|
|
{
|
1999-08-09 05:37:50 +04:00
|
|
|
nsCOMPtr<nsITableEditor> tableEditor = do_QueryInterface(mEditor);
|
|
|
|
if (tableEditor)
|
1999-08-02 02:37:58 +04:00
|
|
|
{
|
|
|
|
// Get both row and column indexes - return just row
|
|
|
|
PRInt32 colIndex;
|
1999-08-09 05:37:50 +04:00
|
|
|
result = tableEditor->GetCellIndexes(cellElement, *_retval, colIndex);
|
1999-08-02 02:37:58 +04:00
|
|
|
}
|
1999-07-28 03:59:22 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
result = NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::GetColumnIndex(nsIDOMElement *cellElement, PRInt32 *_retval)
|
|
|
|
{
|
1999-08-02 02:37:58 +04:00
|
|
|
if (!_retval)
|
1999-07-28 03:59:22 +04:00
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
nsresult result = NS_NOINTERFACE;
|
|
|
|
switch (mEditorType)
|
|
|
|
{
|
|
|
|
case eHTMLTextEditorType:
|
|
|
|
{
|
1999-08-09 05:37:50 +04:00
|
|
|
nsCOMPtr<nsITableEditor> tableEditor = do_QueryInterface(mEditor);
|
|
|
|
if (tableEditor)
|
1999-08-02 02:37:58 +04:00
|
|
|
{
|
|
|
|
// Get both row and column indexes - return just column
|
|
|
|
PRInt32 rowIndex;
|
1999-08-09 05:37:50 +04:00
|
|
|
result = tableEditor->GetCellIndexes(cellElement, rowIndex, *_retval);
|
1999-08-02 02:37:58 +04:00
|
|
|
}
|
1999-07-28 03:59:22 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
result = NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-08-02 02:37:58 +04:00
|
|
|
nsEditorShell::GetTableRowCount(nsIDOMElement *tableElement, PRInt32 *_retval)
|
1999-07-28 03:59:22 +04:00
|
|
|
{
|
1999-08-02 02:37:58 +04:00
|
|
|
if (!_retval)
|
1999-07-28 03:59:22 +04:00
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
nsresult result = NS_NOINTERFACE;
|
|
|
|
switch (mEditorType)
|
|
|
|
{
|
|
|
|
case eHTMLTextEditorType:
|
|
|
|
{
|
1999-08-09 05:37:50 +04:00
|
|
|
nsCOMPtr<nsITableEditor> tableEditor = do_QueryInterface(mEditor);
|
|
|
|
if (tableEditor)
|
1999-08-02 02:37:58 +04:00
|
|
|
{
|
|
|
|
// This returns both the number of rows and columns: return just rows
|
|
|
|
PRInt32 cols;
|
1999-08-09 05:37:50 +04:00
|
|
|
result = tableEditor->GetTableSize(tableElement, *_retval, cols);
|
1999-08-02 02:37:58 +04:00
|
|
|
}
|
1999-07-28 03:59:22 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
result = NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-08-02 02:37:58 +04:00
|
|
|
nsEditorShell::GetTableColumnCount(nsIDOMElement *tableElement, PRInt32 *_retval)
|
1999-07-28 03:59:22 +04:00
|
|
|
{
|
1999-08-02 02:37:58 +04:00
|
|
|
if (!_retval)
|
1999-07-28 03:59:22 +04:00
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
nsresult result = NS_NOINTERFACE;
|
|
|
|
switch (mEditorType)
|
|
|
|
{
|
|
|
|
case eHTMLTextEditorType:
|
|
|
|
{
|
1999-08-09 05:37:50 +04:00
|
|
|
nsCOMPtr<nsITableEditor> tableEditor = do_QueryInterface(mEditor);
|
|
|
|
if (tableEditor)
|
1999-08-02 02:37:58 +04:00
|
|
|
{
|
|
|
|
// This returns both the number of rows and columns: return just columns
|
|
|
|
PRInt32 rows;
|
1999-08-09 05:37:50 +04:00
|
|
|
result = tableEditor->GetTableSize(tableElement, rows, *_retval);
|
1999-08-02 02:37:58 +04:00
|
|
|
}
|
1999-07-28 03:59:22 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
result = NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-08-02 02:37:58 +04:00
|
|
|
nsEditorShell::GetCellAt(nsIDOMElement *tableElement, PRInt32 rowIndex, PRInt32 colIndex, nsIDOMElement **_retval)
|
1999-07-28 03:59:22 +04:00
|
|
|
{
|
1999-08-02 02:37:58 +04:00
|
|
|
if (!_retval)
|
1999-07-28 03:59:22 +04:00
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
nsresult result = NS_NOINTERFACE;
|
|
|
|
switch (mEditorType)
|
|
|
|
{
|
|
|
|
case eHTMLTextEditorType:
|
|
|
|
{
|
1999-08-09 05:37:50 +04:00
|
|
|
nsCOMPtr<nsITableEditor> tableEditor = do_QueryInterface(mEditor);
|
|
|
|
if (tableEditor)
|
2000-05-02 07:24:11 +04:00
|
|
|
{
|
1999-08-09 05:37:50 +04:00
|
|
|
result = tableEditor->GetCellAt(tableElement, rowIndex, colIndex, *_retval);
|
2000-05-02 07:24:11 +04:00
|
|
|
// Don't return NS_EDITOR_ELEMENT_NOT_FOUND (passes NS_SUCCEEDED macro)
|
|
|
|
// to JavaScript
|
|
|
|
if(NS_SUCCEEDED(result)) return NS_OK;
|
|
|
|
}
|
1999-07-28 03:59:22 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
result = NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1999-08-02 02:37:58 +04:00
|
|
|
// Note that the return param in the IDL must be the LAST out param here,
|
|
|
|
// so order of params is different from nsIHTMLEditor
|
1999-07-28 03:59:22 +04:00
|
|
|
NS_IMETHODIMP
|
1999-08-02 02:37:58 +04:00
|
|
|
nsEditorShell::GetCellDataAt(nsIDOMElement *tableElement, PRInt32 rowIndex, PRInt32 colIndex,
|
|
|
|
PRInt32 *aStartRowIndex, PRInt32 *aStartColIndex,
|
2000-01-26 17:57:43 +03:00
|
|
|
PRInt32 *aRowSpan, PRInt32 *aColSpan,
|
|
|
|
PRInt32 *aActualRowSpan, PRInt32 *aActualColSpan,
|
|
|
|
PRBool *aIsSelected, nsIDOMElement **_retval)
|
1999-07-28 03:59:22 +04:00
|
|
|
{
|
1999-08-02 02:37:58 +04:00
|
|
|
if (!_retval ||
|
|
|
|
!aStartRowIndex || !aStartColIndex ||
|
2000-01-26 17:57:43 +03:00
|
|
|
!aRowSpan || !aColSpan ||
|
|
|
|
!aActualRowSpan || !aActualColSpan ||
|
|
|
|
!aIsSelected )
|
1999-07-28 03:59:22 +04:00
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
nsresult result = NS_NOINTERFACE;
|
|
|
|
switch (mEditorType)
|
|
|
|
{
|
|
|
|
case eHTMLTextEditorType:
|
|
|
|
{
|
1999-08-09 05:37:50 +04:00
|
|
|
nsCOMPtr<nsITableEditor> tableEditor = do_QueryInterface(mEditor);
|
|
|
|
if (tableEditor)
|
|
|
|
result = tableEditor->GetCellDataAt(tableElement, rowIndex, colIndex, *_retval,
|
2000-01-26 17:57:43 +03:00
|
|
|
*aStartRowIndex, *aStartColIndex,
|
|
|
|
*aRowSpan, *aColSpan,
|
|
|
|
*aActualRowSpan, *aActualColSpan,
|
|
|
|
*aIsSelected);
|
1999-07-28 03:59:22 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
result = NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2000-02-03 05:06:10 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::GetFirstRow(nsIDOMElement *aTableElement, nsIDOMElement **_retval)
|
|
|
|
{
|
|
|
|
if (!_retval || !aTableElement)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
nsresult result = NS_NOINTERFACE;
|
|
|
|
switch (mEditorType)
|
|
|
|
{
|
|
|
|
case eHTMLTextEditorType:
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsITableEditor> tableEditor = do_QueryInterface(mEditor);
|
|
|
|
if (tableEditor)
|
|
|
|
result = tableEditor->GetFirstRow(aTableElement, *_retval);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
result = NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::GetNextRow(nsIDOMElement *aCurrentRow, nsIDOMElement **_retval)
|
|
|
|
{
|
|
|
|
if (!_retval || !*_retval || !aCurrentRow)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
nsresult result = NS_NOINTERFACE;
|
|
|
|
|
|
|
|
switch (mEditorType)
|
|
|
|
{
|
|
|
|
case eHTMLTextEditorType:
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsITableEditor> tableEditor = do_QueryInterface(mEditor);
|
|
|
|
if (tableEditor)
|
|
|
|
result = tableEditor->GetNextRow(aCurrentRow, *_retval);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
result = NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-03-21 09:05:24 +03:00
|
|
|
nsEditorShell::GetSelectedOrParentTableElement(PRUnichar **aTagName, PRInt32 *aSelectedCount, nsIDOMElement **_retval)
|
2000-02-03 05:06:10 +03:00
|
|
|
{
|
2000-03-21 09:05:24 +03:00
|
|
|
if (!_retval || !aTagName || !aSelectedCount)
|
2000-02-03 05:06:10 +03:00
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
nsresult result = NS_NOINTERFACE;
|
|
|
|
switch (mEditorType)
|
|
|
|
{
|
|
|
|
case eHTMLTextEditorType:
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsITableEditor> tableEditor = do_QueryInterface(mEditor);
|
|
|
|
nsAutoString TagName(*aTagName);
|
|
|
|
if (tableEditor)
|
2000-03-21 09:05:24 +03:00
|
|
|
result = tableEditor->GetSelectedOrParentTableElement(*_retval, TagName, *aSelectedCount);
|
2000-02-15 18:54:05 +03:00
|
|
|
*aTagName = TagName.ToNewUnicode();
|
2000-02-03 05:06:10 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
result = NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2000-03-21 09:05:24 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::GetSelectedCellsType(nsIDOMElement *aElement, PRUint32 *_retval)
|
|
|
|
{
|
|
|
|
if (!_retval)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
nsresult result = NS_NOINTERFACE;
|
|
|
|
switch (mEditorType)
|
|
|
|
{
|
|
|
|
case eHTMLTextEditorType:
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsITableEditor> tableEditor = do_QueryInterface(mEditor);
|
|
|
|
if (tableEditor)
|
|
|
|
result = tableEditor->GetSelectedCellsType(aElement, *_retval);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
result = NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1999-07-28 03:59:22 +04:00
|
|
|
/* end of table editing */
|
|
|
|
|
1999-07-20 02:36:12 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::GetEmbeddedObjects(nsISupportsArray **aObjectArray)
|
|
|
|
{
|
|
|
|
if (!aObjectArray)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
nsresult result;
|
|
|
|
|
|
|
|
switch (mEditorType)
|
|
|
|
{
|
|
|
|
case eHTMLTextEditorType:
|
|
|
|
{
|
1999-08-09 05:37:50 +04:00
|
|
|
nsCOMPtr<nsIEditorMailSupport> mailEditor = do_QueryInterface(mEditor);
|
|
|
|
if (mailEditor)
|
|
|
|
result = mailEditor->GetEmbeddedObjects(aObjectArray);
|
1999-07-20 02:36:12 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
result = NS_NOINTERFACE;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1999-06-11 03:50:26 +04:00
|
|
|
NS_IMETHODIMP
|
2000-05-05 18:58:43 +04:00
|
|
|
nsEditorShell::InitSpellChecker()
|
1999-06-11 03:50:26 +04:00
|
|
|
{
|
|
|
|
nsresult result = NS_NOINTERFACE;
|
2000-05-05 18:58:43 +04:00
|
|
|
|
1999-06-11 03:50:26 +04:00
|
|
|
// We can spell check with any editor type
|
|
|
|
if (mEditor)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsITextServicesDocument>tsDoc;
|
|
|
|
|
|
|
|
result = nsComponentManager::CreateInstance(
|
|
|
|
kCTextServicesDocumentCID,
|
|
|
|
nsnull,
|
2000-01-11 23:49:15 +03:00
|
|
|
NS_GET_IID(nsITextServicesDocument),
|
1999-06-11 03:50:26 +04:00
|
|
|
(void **)getter_AddRefs(tsDoc));
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
if (!tsDoc)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
// Pass the editor to the text services document
|
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(mEditor);
|
|
|
|
if (!editor)
|
|
|
|
return NS_NOINTERFACE;
|
|
|
|
|
|
|
|
result = tsDoc->InitWithEditor(editor);
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
2000-05-05 18:58:43 +04:00
|
|
|
result = nsComponentManager::CreateInstance(NS_SPELLCHECKER_PROGID,
|
1999-06-11 03:50:26 +04:00
|
|
|
nsnull,
|
2000-01-11 23:49:15 +03:00
|
|
|
NS_GET_IID(nsISpellChecker),
|
1999-06-11 03:50:26 +04:00
|
|
|
(void **)getter_AddRefs(mSpellChecker));
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
if (!mSpellChecker)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
result = mSpellChecker->SetDocument(tsDoc, PR_FALSE);
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
DeleteSuggestedWordList();
|
|
|
|
}
|
2000-05-05 18:58:43 +04:00
|
|
|
|
1999-06-11 03:50:26 +04:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-07-15 18:43:48 +04:00
|
|
|
nsEditorShell::GetNextMisspelledWord(PRUnichar **aNextMisspelledWord)
|
1999-06-11 03:50:26 +04:00
|
|
|
{
|
|
|
|
nsresult result = NS_NOINTERFACE;
|
1999-07-15 18:43:48 +04:00
|
|
|
nsAutoString nextMisspelledWord;
|
1999-06-11 03:50:26 +04:00
|
|
|
|
|
|
|
// We can spell check with any editor type
|
|
|
|
if (mEditor && mSpellChecker)
|
|
|
|
{
|
|
|
|
DeleteSuggestedWordList();
|
1999-07-15 18:43:48 +04:00
|
|
|
result = mSpellChecker->NextMisspelledWord(&nextMisspelledWord, &mSuggestedWordList);
|
1999-06-11 03:50:26 +04:00
|
|
|
}
|
1999-07-15 18:43:48 +04:00
|
|
|
*aNextMisspelledWord = nextMisspelledWord.ToNewUnicode();
|
1999-06-11 03:50:26 +04:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-07-15 18:43:48 +04:00
|
|
|
nsEditorShell::GetSuggestedWord(PRUnichar **aSuggestedWord)
|
1999-06-11 03:50:26 +04:00
|
|
|
{
|
|
|
|
nsresult result = NS_NOINTERFACE;
|
1999-07-15 18:43:48 +04:00
|
|
|
nsAutoString word;
|
1999-06-11 03:50:26 +04:00
|
|
|
// We can spell check with any editor type
|
|
|
|
if (mEditor)
|
|
|
|
{
|
|
|
|
if ( mSuggestedWordIndex < mSuggestedWordList.Count())
|
|
|
|
{
|
1999-07-15 18:43:48 +04:00
|
|
|
mSuggestedWordList.StringAt(mSuggestedWordIndex, word);
|
1999-06-11 03:50:26 +04:00
|
|
|
mSuggestedWordIndex++;
|
|
|
|
} else {
|
|
|
|
// A blank string signals that there are no more strings
|
2000-04-18 11:44:58 +04:00
|
|
|
word.SetLength(0);
|
1999-06-11 03:50:26 +04:00
|
|
|
}
|
|
|
|
result = NS_OK;
|
|
|
|
}
|
1999-07-15 18:43:48 +04:00
|
|
|
*aSuggestedWord = word.ToNewUnicode();
|
1999-06-11 03:50:26 +04:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-07-15 18:43:48 +04:00
|
|
|
nsEditorShell::CheckCurrentWord(const PRUnichar *aSuggestedWord, PRBool *aIsMisspelled)
|
1999-06-11 03:50:26 +04:00
|
|
|
{
|
|
|
|
nsresult result = NS_NOINTERFACE;
|
1999-07-15 18:43:48 +04:00
|
|
|
nsAutoString suggestedWord(aSuggestedWord);
|
1999-06-11 03:50:26 +04:00
|
|
|
// We can spell check with any editor type
|
|
|
|
if (mEditor && mSpellChecker)
|
|
|
|
{
|
|
|
|
DeleteSuggestedWordList();
|
1999-07-15 18:43:48 +04:00
|
|
|
result = mSpellChecker->CheckWord(&suggestedWord, aIsMisspelled, &mSuggestedWordList);
|
1999-06-11 03:50:26 +04:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-07-15 18:43:48 +04:00
|
|
|
nsEditorShell::ReplaceWord(const PRUnichar *aMisspelledWord, const PRUnichar *aReplaceWord, PRBool allOccurrences)
|
1999-06-11 03:50:26 +04:00
|
|
|
{
|
|
|
|
nsresult result = NS_NOINTERFACE;
|
1999-07-15 18:43:48 +04:00
|
|
|
nsAutoString misspelledWord(aMisspelledWord);
|
|
|
|
nsAutoString replaceWord(aReplaceWord);
|
1999-06-11 03:50:26 +04:00
|
|
|
if (mEditor && mSpellChecker)
|
|
|
|
{
|
1999-07-15 18:43:48 +04:00
|
|
|
result = mSpellChecker->Replace(&misspelledWord, &replaceWord, allOccurrences);
|
1999-06-11 03:50:26 +04:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-07-15 18:43:48 +04:00
|
|
|
nsEditorShell::IgnoreWordAllOccurrences(const PRUnichar *aWord)
|
1999-06-11 03:50:26 +04:00
|
|
|
{
|
|
|
|
nsresult result = NS_NOINTERFACE;
|
1999-07-15 18:43:48 +04:00
|
|
|
nsAutoString word(aWord);
|
1999-06-11 03:50:26 +04:00
|
|
|
if (mEditor && mSpellChecker)
|
|
|
|
{
|
1999-07-15 18:43:48 +04:00
|
|
|
result = mSpellChecker->IgnoreAll(&word);
|
1999-06-11 03:50:26 +04:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-07-15 18:43:48 +04:00
|
|
|
nsEditorShell::GetPersonalDictionary()
|
1999-06-11 03:50:26 +04:00
|
|
|
{
|
|
|
|
nsresult result = NS_NOINTERFACE;
|
1999-07-15 18:43:48 +04:00
|
|
|
// We can spell check with any editor type
|
1999-06-11 03:50:26 +04:00
|
|
|
if (mEditor && mSpellChecker)
|
|
|
|
{
|
1999-07-15 18:43:48 +04:00
|
|
|
mDictionaryList.Clear();
|
|
|
|
mDictionaryIndex = 0;
|
|
|
|
result = mSpellChecker->GetPersonalDictionary(&mDictionaryList);
|
1999-06-11 03:50:26 +04:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-07-15 18:43:48 +04:00
|
|
|
nsEditorShell::GetPersonalDictionaryWord(PRUnichar **aDictionaryWord)
|
1999-06-11 03:50:26 +04:00
|
|
|
{
|
|
|
|
nsresult result = NS_NOINTERFACE;
|
1999-07-15 18:43:48 +04:00
|
|
|
nsAutoString word;
|
|
|
|
if (mEditor)
|
1999-06-11 03:50:26 +04:00
|
|
|
{
|
1999-07-15 18:43:48 +04:00
|
|
|
if ( mDictionaryIndex < mDictionaryList.Count())
|
|
|
|
{
|
|
|
|
mDictionaryList.StringAt(mDictionaryIndex, word);
|
|
|
|
mDictionaryIndex++;
|
|
|
|
} else {
|
|
|
|
// A blank string signals that there are no more strings
|
2000-04-18 11:44:58 +04:00
|
|
|
word.SetLength(0);
|
1999-07-15 18:43:48 +04:00
|
|
|
}
|
|
|
|
result = NS_OK;
|
1999-06-11 03:50:26 +04:00
|
|
|
}
|
1999-07-15 18:43:48 +04:00
|
|
|
*aDictionaryWord = word.ToNewUnicode();
|
1999-06-11 03:50:26 +04:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-07-15 18:43:48 +04:00
|
|
|
nsEditorShell::AddWordToDictionary(const PRUnichar *aWord)
|
1999-06-11 03:50:26 +04:00
|
|
|
{
|
|
|
|
nsresult result = NS_NOINTERFACE;
|
1999-09-15 03:40:16 +04:00
|
|
|
nsAutoString word(aWord);
|
1999-06-11 03:50:26 +04:00
|
|
|
if (mEditor && mSpellChecker)
|
|
|
|
{
|
1999-07-15 18:43:48 +04:00
|
|
|
result = mSpellChecker->AddWordToPersonalDictionary(&word);
|
1999-06-11 03:50:26 +04:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1999-07-15 18:43:48 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::RemoveWordFromDictionary(const PRUnichar *aWord)
|
|
|
|
{
|
|
|
|
nsresult result = NS_NOINTERFACE;
|
1999-09-15 03:40:16 +04:00
|
|
|
nsAutoString word(aWord);
|
1999-07-15 18:43:48 +04:00
|
|
|
if (mEditor && mSpellChecker)
|
|
|
|
{
|
|
|
|
result = mSpellChecker->RemoveWordFromPersonalDictionary(&word);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
1999-06-11 03:50:26 +04:00
|
|
|
|
2000-05-04 18:37:56 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::GetDictionaryList(PRUnichar ***aDictionaryList, PRUint32 *aCount)
|
|
|
|
{
|
|
|
|
nsresult result = NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
|
|
|
|
if (!aDictionaryList || !aCount)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
*aDictionaryList = 0;
|
|
|
|
*aCount = 0;
|
|
|
|
|
|
|
|
if (mEditor && mSpellChecker)
|
|
|
|
{
|
|
|
|
nsStringArray dictList;
|
|
|
|
|
|
|
|
result = mSpellChecker->GetDictionaryList(&dictList);
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
PRUnichar **tmpPtr = 0;
|
|
|
|
|
|
|
|
if (dictList.Count() < 1)
|
|
|
|
{
|
|
|
|
// If there are no dictionaries, return an array containing
|
|
|
|
// one element and a count of one.
|
|
|
|
|
|
|
|
tmpPtr = (PRUnichar **)nsAllocator::Alloc(sizeof(PRUnichar *));
|
|
|
|
|
|
|
|
if (!tmpPtr)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
*tmpPtr = 0;
|
|
|
|
*aDictionaryList = tmpPtr;
|
|
|
|
*aCount = 0;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
tmpPtr = (PRUnichar **)nsAllocator::Alloc(sizeof(PRUnichar *) * dictList.Count());
|
|
|
|
|
|
|
|
if (!tmpPtr)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
*aDictionaryList = tmpPtr;
|
|
|
|
*aCount = dictList.Count();
|
|
|
|
|
|
|
|
nsAutoString dictStr;
|
|
|
|
|
|
|
|
PRUint32 i;
|
|
|
|
|
|
|
|
for (i = 0; i < *aCount; i++)
|
|
|
|
{
|
|
|
|
dictList.StringAt(i, dictStr);
|
|
|
|
tmpPtr[i] = dictStr.ToNewUnicode();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::GetCurrentDictionary(PRUnichar **aDictionary)
|
|
|
|
{
|
|
|
|
nsresult result = NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
|
|
|
if (!aDictionary)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
*aDictionary = 0;
|
|
|
|
|
|
|
|
if (mEditor && mSpellChecker)
|
|
|
|
{
|
|
|
|
nsAutoString dictStr;
|
|
|
|
result = mSpellChecker->GetCurrentDictionary(&dictStr);
|
|
|
|
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
*aDictionary = dictStr.ToNewUnicode();
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::SetCurrentDictionary(const PRUnichar *aDictionary)
|
|
|
|
{
|
|
|
|
nsresult result = NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
|
|
|
if (!aDictionary)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
if (mEditor && mSpellChecker)
|
|
|
|
{
|
|
|
|
nsAutoString dictStr(aDictionary);
|
|
|
|
result = mSpellChecker->SetCurrentDictionary(&dictStr);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1999-06-11 03:50:26 +04:00
|
|
|
NS_IMETHODIMP
|
2000-05-05 18:58:43 +04:00
|
|
|
nsEditorShell::UninitSpellChecker()
|
1999-06-11 03:50:26 +04:00
|
|
|
{
|
|
|
|
nsresult result = NS_NOINTERFACE;
|
|
|
|
// We can spell check with any editor type
|
|
|
|
if (mEditor)
|
|
|
|
{
|
|
|
|
// Cleanup - kill the spell checker
|
|
|
|
DeleteSuggestedWordList();
|
1999-07-15 18:43:48 +04:00
|
|
|
mDictionaryList.Clear();
|
|
|
|
mDictionaryIndex = 0;
|
1999-06-11 03:50:26 +04:00
|
|
|
mSpellChecker = 0;
|
|
|
|
result = NS_OK;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2000-04-04 05:06:25 +04:00
|
|
|
nsresult
|
1999-06-11 03:50:26 +04:00
|
|
|
nsEditorShell::DeleteSuggestedWordList()
|
|
|
|
{
|
|
|
|
mSuggestedWordList.Clear();
|
|
|
|
mSuggestedWordIndex = 0;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef XP_MAC
|
|
|
|
#pragma mark -
|
|
|
|
#endif
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::BeginBatchChanges()
|
|
|
|
{
|
|
|
|
nsresult err = NS_NOINTERFACE;
|
|
|
|
|
|
|
|
switch (mEditorType)
|
|
|
|
{
|
|
|
|
case ePlainTextEditorType:
|
|
|
|
case eHTMLTextEditorType:
|
|
|
|
{
|
1999-08-09 05:37:50 +04:00
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(mEditor);
|
|
|
|
if (editor)
|
|
|
|
err = editor->BeginTransaction();
|
1999-06-11 03:50:26 +04:00
|
|
|
}
|
|
|
|
break;
|
1999-08-09 05:37:50 +04:00
|
|
|
|
1999-06-11 03:50:26 +04:00
|
|
|
default:
|
|
|
|
err = NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::EndBatchChanges()
|
|
|
|
{
|
|
|
|
nsresult err = NS_NOINTERFACE;
|
|
|
|
|
|
|
|
switch (mEditorType)
|
|
|
|
{
|
|
|
|
case ePlainTextEditorType:
|
|
|
|
case eHTMLTextEditorType:
|
|
|
|
{
|
1999-08-09 05:37:50 +04:00
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(mEditor);
|
|
|
|
if (editor)
|
|
|
|
err = editor->EndTransaction();
|
1999-06-11 03:50:26 +04:00
|
|
|
}
|
|
|
|
break;
|
1999-08-09 05:37:50 +04:00
|
|
|
|
1999-06-11 03:50:26 +04:00
|
|
|
default:
|
|
|
|
err = NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::RunUnitTests()
|
|
|
|
{
|
|
|
|
PRInt32 numTests = 0;
|
|
|
|
PRInt32 numTestsFailed = 0;
|
|
|
|
|
|
|
|
nsresult err = NS_OK;
|
|
|
|
nsCOMPtr<nsIEditor> editor = do_QueryInterface(mEditor);
|
|
|
|
if (editor)
|
|
|
|
err = editor->DebugUnitTests(&numTests, &numTestsFailed);
|
|
|
|
|
|
|
|
#ifdef APP_DEBUG
|
|
|
|
printf("\nRan %ld tests, of which %ld failed\n", (long)numTests, (long)numTestsFailed);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-06-15 00:02:46 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::StartLogging(nsIFileSpec *logFile)
|
|
|
|
{
|
|
|
|
nsresult err = NS_OK;
|
|
|
|
|
|
|
|
switch (mEditorType)
|
|
|
|
{
|
|
|
|
case ePlainTextEditorType:
|
|
|
|
case eHTMLTextEditorType:
|
|
|
|
{
|
1999-08-09 05:37:50 +04:00
|
|
|
nsCOMPtr<nsIEditorLogging> logger = do_QueryInterface(mEditor);
|
|
|
|
if (logger)
|
|
|
|
err = logger->StartLogging(logFile);
|
1999-06-15 00:02:46 +04:00
|
|
|
}
|
|
|
|
break;
|
1999-08-09 05:37:50 +04:00
|
|
|
|
1999-06-15 00:02:46 +04:00
|
|
|
default:
|
|
|
|
err = NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::StopLogging()
|
|
|
|
{
|
|
|
|
nsresult err = NS_OK;
|
|
|
|
|
|
|
|
switch (mEditorType)
|
|
|
|
{
|
|
|
|
case ePlainTextEditorType:
|
|
|
|
case eHTMLTextEditorType:
|
|
|
|
{
|
1999-08-09 05:37:50 +04:00
|
|
|
nsCOMPtr<nsIEditorLogging> logger = do_QueryInterface(mEditor);
|
|
|
|
if (logger)
|
|
|
|
err = logger->StopLogging();
|
1999-06-15 00:02:46 +04:00
|
|
|
}
|
|
|
|
break;
|
1999-08-09 05:37:50 +04:00
|
|
|
|
1999-06-15 00:02:46 +04:00
|
|
|
default:
|
|
|
|
err = NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
1999-06-11 03:50:26 +04:00
|
|
|
#ifdef XP_MAC
|
|
|
|
#pragma mark -
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// nsIDocumentLoaderObserver methods
|
|
|
|
NS_IMETHODIMP
|
1999-06-23 07:29:44 +04:00
|
|
|
nsEditorShell::OnStartDocumentLoad(nsIDocumentLoader* loader, nsIURI* aURL, const char* aCommand)
|
1999-06-11 03:50:26 +04:00
|
|
|
{
|
1999-10-29 06:33:51 +04:00
|
|
|
// Start the throbber
|
|
|
|
// TODO: We should also start/stop it for saving and publishing?
|
2000-04-18 11:44:58 +04:00
|
|
|
SetChromeAttribute( mDocShell, "Editor:Throbber", "busy", NS_ConvertASCIItoUCS2("true") );
|
2000-03-28 04:15:56 +04:00
|
|
|
|
|
|
|
// Disable JavaScript in this document:
|
2000-04-12 03:48:14 +04:00
|
|
|
nsCOMPtr<nsIScriptGlobalObjectOwner> sgoo (do_QueryInterface(mContentAreaDocShell));
|
2000-03-28 04:15:56 +04:00
|
|
|
if (sgoo)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIScriptGlobalObject> sgo;
|
|
|
|
sgoo->GetScriptGlobalObject(getter_AddRefs(sgo));
|
|
|
|
if (sgo)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIScriptContext> scriptContext;
|
|
|
|
sgo->GetContext(getter_AddRefs(scriptContext));
|
|
|
|
if (scriptContext)
|
|
|
|
scriptContext->SetScriptsEnabled(PR_FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-03-31 06:13:00 +04:00
|
|
|
// set up a parser observer
|
|
|
|
if (!mParserObserver)
|
|
|
|
{
|
|
|
|
mParserObserver = new nsEditorParserObserver();
|
|
|
|
if (!mParserObserver) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
NS_ADDREF(mParserObserver);
|
|
|
|
mParserObserver->RegisterTagToWatch("FRAMESET");
|
|
|
|
mParserObserver->Start();
|
|
|
|
}
|
|
|
|
|
1999-10-30 02:33:34 +04:00
|
|
|
return NS_OK;
|
1999-06-11 03:50:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-03-31 06:13:00 +04:00
|
|
|
nsEditorShell::OnEndDocumentLoad(nsIDocumentLoader* aLoader, nsIChannel* aChannel, nsresult aStatus)
|
1999-06-11 03:50:26 +04:00
|
|
|
{
|
1999-09-17 03:54:08 +04:00
|
|
|
// for pages with charsets, this gets called the first time with a
|
|
|
|
// non-zero status value. Don't prepare the editor that time.
|
|
|
|
// aStatus will be NS_BINDING_ABORTED then.
|
1999-10-29 06:33:51 +04:00
|
|
|
nsresult res = NS_OK;
|
2000-04-04 05:06:25 +04:00
|
|
|
if (NS_FAILED(aStatus))
|
|
|
|
return NS_OK;
|
|
|
|
|
2000-04-19 02:39:10 +04:00
|
|
|
// Disable meta-refresh
|
|
|
|
nsCOMPtr<nsIRefreshURI> refreshURI = do_QueryInterface(mContentAreaDocShell);
|
|
|
|
if (refreshURI)
|
|
|
|
refreshURI->CancelRefreshURITimers();
|
|
|
|
|
2000-04-04 05:06:25 +04:00
|
|
|
// can we handle this document?
|
|
|
|
if (mParserObserver)
|
|
|
|
{
|
|
|
|
mParserObserver->End(); // how do we know if this is the last call?
|
|
|
|
PRBool cancelEdit;
|
|
|
|
mParserObserver->GetBadTagFound(&cancelEdit);
|
|
|
|
if (cancelEdit)
|
2000-03-31 06:13:00 +04:00
|
|
|
{
|
2000-04-04 05:06:25 +04:00
|
|
|
NS_RELEASE(mParserObserver);
|
2000-04-12 03:48:14 +04:00
|
|
|
if (mDocShell)
|
2000-03-31 06:13:00 +04:00
|
|
|
{
|
2000-04-04 05:06:25 +04:00
|
|
|
// where do we pop up a dialog telling the user they can't edit this doc?
|
|
|
|
// this next call will close the window, but do we want to do that? or tell the .js UI to do it?
|
|
|
|
mCloseWindowWhenLoaded = PR_TRUE;
|
2000-03-31 06:13:00 +04:00
|
|
|
}
|
|
|
|
}
|
2000-04-04 05:06:25 +04:00
|
|
|
}
|
2000-03-31 06:13:00 +04:00
|
|
|
|
2000-04-04 05:06:25 +04:00
|
|
|
PRBool isRootDoc;
|
|
|
|
res = DocumentIsRootDoc(aLoader, isRootDoc);
|
|
|
|
if (NS_FAILED(res)) return res;
|
|
|
|
|
|
|
|
if (mCloseWindowWhenLoaded && isRootDoc)
|
|
|
|
{
|
|
|
|
nsAutoString alertLabel, alertMessage;
|
2000-04-18 11:44:58 +04:00
|
|
|
GetBundleString(NS_ConvertASCIItoUCS2("Alert"), alertLabel);
|
|
|
|
GetBundleString(NS_ConvertASCIItoUCS2("CantEditFramesetMsg"), alertMessage);
|
2000-04-04 05:06:25 +04:00
|
|
|
Alert(alertLabel, alertMessage);
|
|
|
|
|
2000-04-12 03:48:14 +04:00
|
|
|
nsCOMPtr<nsIBaseWindow> baseWindow;
|
|
|
|
GetTreeOwner(mDocShell, getter_AddRefs(baseWindow));
|
|
|
|
NS_ENSURE_TRUE(baseWindow, NS_ERROR_ABORT);
|
|
|
|
baseWindow->Destroy();
|
|
|
|
|
2000-04-04 05:06:25 +04:00
|
|
|
return NS_ERROR_ABORT;
|
1999-09-17 03:54:08 +04:00
|
|
|
}
|
2000-03-31 06:13:00 +04:00
|
|
|
|
2000-04-04 05:06:25 +04:00
|
|
|
// if we're loading a frameset document (which we can't edit yet), don't make an editor.
|
|
|
|
// Only make an editor for child documents.
|
|
|
|
PRBool docHasFrames;
|
|
|
|
if (NS_SUCCEEDED(DocumentContainsFrames(aLoader, docHasFrames)) && !docHasFrames)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIURI> aUrl;
|
|
|
|
aChannel->GetURI(getter_AddRefs(aUrl));
|
|
|
|
res = PrepareDocumentForEditing(aLoader, aUrl);
|
2000-04-18 11:44:58 +04:00
|
|
|
SetChromeAttribute( mDocShell, "Editor:Throbber", "busy", NS_ConvertASCIItoUCS2("false") );
|
2000-04-04 05:06:25 +04:00
|
|
|
}
|
2000-03-31 06:13:00 +04:00
|
|
|
|
|
|
|
nsAutoString doneText;
|
2000-04-18 11:44:58 +04:00
|
|
|
GetBundleString(NS_ConvertASCIItoUCS2("LoadingDone"), doneText);
|
2000-04-12 03:48:14 +04:00
|
|
|
SetChromeAttribute(mDocShell, "statusText", "value", doneText);
|
2000-03-31 06:13:00 +04:00
|
|
|
|
1999-10-29 06:33:51 +04:00
|
|
|
return res;
|
1999-06-11 03:50:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-06-28 17:01:55 +04:00
|
|
|
nsEditorShell::OnStartURLLoad(nsIDocumentLoader* loader,
|
1999-12-29 10:32:59 +03:00
|
|
|
nsIChannel* channel)
|
1999-06-11 03:50:26 +04:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-03-31 06:13:00 +04:00
|
|
|
nsEditorShell::OnProgressURLLoad(nsIDocumentLoader* aLoader,
|
1999-06-28 17:01:55 +04:00
|
|
|
nsIChannel* channel, PRUint32 aProgress,
|
|
|
|
PRUint32 aProgressMax)
|
1999-06-11 03:50:26 +04:00
|
|
|
{
|
2000-03-31 06:13:00 +04:00
|
|
|
if (mParserObserver)
|
|
|
|
{
|
|
|
|
PRBool cancelEdit;
|
|
|
|
mParserObserver->GetBadTagFound(&cancelEdit);
|
|
|
|
if (cancelEdit)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
nsCOMPtr<nsIDocShell> docShell = do_QueryInterface(mWebShell);
|
|
|
|
if (docShell)
|
|
|
|
docShell->StopLoad();
|
2000-04-04 05:06:25 +04:00
|
|
|
*/
|
2000-03-31 06:13:00 +04:00
|
|
|
|
|
|
|
mParserObserver->End();
|
|
|
|
NS_RELEASE(mParserObserver);
|
|
|
|
|
2000-04-12 03:48:14 +04:00
|
|
|
if (mDocShell)
|
2000-03-31 06:13:00 +04:00
|
|
|
{
|
|
|
|
// where do we pop up a dialog telling the user they can't edit this doc?
|
|
|
|
// this next call will close the window, but do we want to do that? or tell the .js UI to do it?
|
|
|
|
mCloseWindowWhenLoaded = PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-06-11 03:50:26 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-06-28 17:01:55 +04:00
|
|
|
nsEditorShell::OnStatusURLLoad(nsIDocumentLoader* loader,
|
|
|
|
nsIChannel* channel, nsString& aMsg)
|
1999-06-11 03:50:26 +04:00
|
|
|
{
|
2000-03-31 06:13:00 +04:00
|
|
|
|
2000-04-12 03:48:14 +04:00
|
|
|
SetChromeAttribute(mDocShell, "statusText", "value", aMsg);
|
2000-03-31 06:13:00 +04:00
|
|
|
|
1999-06-11 03:50:26 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-06-28 17:01:55 +04:00
|
|
|
nsEditorShell::OnEndURLLoad(nsIDocumentLoader* loader,
|
1999-08-05 05:28:30 +04:00
|
|
|
nsIChannel* channel, nsresult aStatus)
|
1999-06-11 03:50:26 +04:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-04-04 05:06:25 +04:00
|
|
|
|
|
|
|
#ifdef XP_MAC
|
|
|
|
#pragma mark -
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// does the document being loaded contain subframes?
|
|
|
|
nsresult
|
|
|
|
nsEditorShell::DocumentContainsFrames(nsIDocumentLoader* aLoader, PRBool& outHasFrames)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
outHasFrames = PR_FALSE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> container;
|
|
|
|
aLoader->GetContainer(getter_AddRefs(container));
|
|
|
|
nsCOMPtr<nsIDocShellTreeNode> docShellAsNode = do_QueryInterface(container, &rv);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
if (!docShellAsNode)
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
|
|
|
|
PRInt32 numChildren;
|
|
|
|
rv = docShellAsNode->GetChildCount(&numChildren);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
outHasFrames = (numChildren != 0);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// is the document being loaded the root of a frameset, or a non-frameset doc?
|
|
|
|
nsresult
|
|
|
|
nsEditorShell::DocumentIsRootDoc(nsIDocumentLoader* aLoader, PRBool& outIsRoot)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
outIsRoot = PR_TRUE;
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> container;
|
|
|
|
aLoader->GetContainer(getter_AddRefs(container));
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> docShellAsTreeItem = do_QueryInterface(container, &rv);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
if (!docShellAsTreeItem)
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocShellTreeItem> rootItem;
|
|
|
|
rv = docShellAsTreeItem->GetSameTypeRootTreeItem(getter_AddRefs(rootItem));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
if (!rootItem)
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
|
|
|
|
outIsRoot = (rootItem.get() == docShellAsTreeItem.get());
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-05-10 03:03:41 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsEditorShell::EditElementProperties(nsIDOMElement *aElement, int x, int y)
|
|
|
|
{
|
|
|
|
if (!aElement) return NS_OK;
|
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
#if DEBUG_cmanske
|
|
|
|
nsAutoString TagName;
|
|
|
|
aElement->GetTagName(TagName);
|
|
|
|
TagName.ToLowerCase();
|
|
|
|
char szTagName[64];
|
|
|
|
TagName.ToCString(szTagName, 64);
|
|
|
|
printf("***** DBLClick: TagName of element clicked on: %s\n", szTagName);
|
|
|
|
#endif
|
|
|
|
// Get the ComposerController:
|
|
|
|
nsCOMPtr<nsIControllers> controllers;
|
2000-05-14 09:27:17 +04:00
|
|
|
if(!mContentWindow)
|
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
nsCOMPtr<nsIDOMWindow> cwP = do_QueryReferent(mContentWindow);
|
|
|
|
if (!cwP) return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
rv = cwP->GetControllers(getter_AddRefs(controllers));
|
2000-05-10 03:03:41 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
if (!controllers) return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIController> controller;
|
|
|
|
rv = controllers->GetControllerAt(eComposerController, getter_AddRefs(controller));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
if (!controller) return NS_ERROR_NULL_POINTER;
|
|
|
|
nsCOMPtr<nsIEditorController> composerController = do_QueryInterface(controller);
|
|
|
|
|
|
|
|
// Execute the command
|
|
|
|
nsAutoString commandName(NS_ConvertASCIItoUCS2("cmd_advancedProperties"));
|
|
|
|
return composerController->DoCommand(commandName.GetUnicode());
|
|
|
|
}
|