2001-09-25 22:53:13 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-18 14:21:17 +00:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
2001-04-05 23:51:30 +00:00
|
|
|
*
|
2004-04-18 14:21:17 +00:00
|
|
|
* The contents of this file are subject to the Mozilla 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/MPL/
|
2001-04-05 23:51:30 +00:00
|
|
|
*
|
2001-09-25 22:53:13 +00: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.
|
2001-04-05 23:51:30 +00:00
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2004-04-18 14:21:17 +00:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-25 22:53:13 +00:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
2001-04-05 23:51:30 +00:00
|
|
|
*
|
2001-09-25 22:53:13 +00:00
|
|
|
* Contributor(s):
|
2002-11-12 23:03:27 +00:00
|
|
|
* Michael Judge <mjudge@netscape.com>
|
|
|
|
* Charles Manske <cmanske@netscape.com>
|
2001-09-25 22:53:13 +00:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-18 14:21:17 +00:00
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
2001-09-25 22:53:13 +00:00
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
2004-04-18 14:21:17 +00:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-25 22:53:13 +00:00
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
2004-04-18 14:21:17 +00:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-25 22:53:13 +00:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
2001-04-05 23:51:30 +00:00
|
|
|
|
2010-06-10 18:11:40 +00:00
|
|
|
#include "mozilla/ModuleUtils.h"
|
2001-04-05 23:51:30 +00:00
|
|
|
|
2002-02-02 05:13:56 +00:00
|
|
|
#include "nsEditingSession.h" // for the CID
|
2002-10-11 23:46:57 +00:00
|
|
|
#include "nsComposerController.h" // for the CID
|
|
|
|
#include "nsEditorSpellCheck.h" // for the CID
|
2002-12-10 15:03:04 +00:00
|
|
|
#include "nsComposeTxtSrvFilter.h"
|
2003-07-14 14:37:23 +00:00
|
|
|
#include "nsIController.h"
|
2002-11-12 23:03:27 +00:00
|
|
|
#include "nsIControllerContext.h"
|
2003-04-10 18:44:03 +00:00
|
|
|
#include "nsIControllerCommandTable.h"
|
|
|
|
|
2004-11-24 22:48:45 +00:00
|
|
|
#include "nsServiceManagerUtils.h"
|
2004-10-29 19:28:38 +00:00
|
|
|
|
2003-04-10 18:44:03 +00:00
|
|
|
#define NS_HTMLEDITOR_COMMANDTABLE_CID \
|
2005-06-17 18:17:08 +00:00
|
|
|
{ 0x13e50d8d, 0x9cee, 0x4ad1, { 0xa3, 0xa2, 0x4a, 0x44, 0x2f, 0xdf, 0x7d, 0xfa } }
|
2003-04-10 18:44:03 +00:00
|
|
|
|
|
|
|
#define NS_HTMLEDITOR_DOCSTATE_COMMANDTABLE_CID \
|
2005-06-17 18:17:08 +00:00
|
|
|
{ 0xa33982d3, 0x1adf, 0x4162, { 0x99, 0x41, 0xf7, 0x34, 0xbc, 0x45, 0xe4, 0xed } }
|
2003-04-10 18:44:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
static NS_DEFINE_CID(kHTMLEditorCommandTableCID, NS_HTMLEDITOR_COMMANDTABLE_CID);
|
|
|
|
static NS_DEFINE_CID(kHTMLEditorDocStateCommandTableCID, NS_HTMLEDITOR_DOCSTATE_COMMANDTABLE_CID);
|
|
|
|
|
2001-04-05 23:51:30 +00:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// Define the contructor function for the objects
|
|
|
|
//
|
|
|
|
// NOTE: This creates an instance of objects by using the default constructor
|
|
|
|
//
|
|
|
|
|
2002-02-02 05:13:56 +00:00
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR(nsEditingSession)
|
2002-10-11 23:46:57 +00:00
|
|
|
NS_GENERIC_FACTORY_CONSTRUCTOR(nsEditorSpellCheck)
|
2001-04-05 23:51:30 +00:00
|
|
|
|
2002-12-10 15:03:04 +00:00
|
|
|
// There are no macros that enable us to have 2 constructors
|
|
|
|
// for the same object
|
|
|
|
//
|
|
|
|
// Here we are creating the same object with two different contract IDs
|
|
|
|
// and then initializing it different.
|
|
|
|
// Basically, we need to tell the filter whether it is doing mail or not
|
2010-06-10 18:11:40 +00:00
|
|
|
static nsresult
|
2002-12-10 15:03:04 +00:00
|
|
|
nsComposeTxtSrvFilterConstructor(nsISupports *aOuter, REFNSIID aIID,
|
2011-09-29 06:19:26 +00:00
|
|
|
void **aResult, bool aIsForMail)
|
2002-12-10 15:03:04 +00:00
|
|
|
{
|
|
|
|
*aResult = NULL;
|
|
|
|
if (NULL != aOuter)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NO_AGGREGATION;
|
|
|
|
}
|
2010-07-05 09:42:18 +00:00
|
|
|
nsComposeTxtSrvFilter * inst = new nsComposeTxtSrvFilter();
|
2002-12-10 15:03:04 +00:00
|
|
|
if (NULL == inst)
|
|
|
|
{
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
NS_ADDREF(inst);
|
|
|
|
inst->Init(aIsForMail);
|
|
|
|
nsresult rv = inst->QueryInterface(aIID, aResult);
|
|
|
|
NS_RELEASE(inst);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2010-06-10 18:11:40 +00:00
|
|
|
static nsresult
|
2002-12-10 15:03:04 +00:00
|
|
|
nsComposeTxtSrvFilterConstructorForComposer(nsISupports *aOuter,
|
|
|
|
REFNSIID aIID,
|
|
|
|
void **aResult)
|
|
|
|
{
|
2002-12-18 02:23:10 +00:00
|
|
|
return nsComposeTxtSrvFilterConstructor(aOuter, aIID, aResult, PR_FALSE);
|
2002-12-10 15:03:04 +00:00
|
|
|
}
|
|
|
|
|
2010-06-10 18:11:40 +00:00
|
|
|
static nsresult
|
2002-12-10 15:03:04 +00:00
|
|
|
nsComposeTxtSrvFilterConstructorForMail(nsISupports *aOuter,
|
|
|
|
REFNSIID aIID,
|
|
|
|
void **aResult)
|
|
|
|
{
|
2002-12-18 02:23:10 +00:00
|
|
|
return nsComposeTxtSrvFilterConstructor(aOuter, aIID, aResult, PR_TRUE);
|
2002-12-10 15:03:04 +00:00
|
|
|
}
|
2002-11-12 23:03:27 +00:00
|
|
|
|
2003-04-10 18:44:03 +00:00
|
|
|
|
|
|
|
// Constructor for a controller set up with a command table specified
|
|
|
|
// by the CID passed in. This function uses do_GetService to get the
|
|
|
|
// command table, so that every controller shares a single command
|
|
|
|
// table, for space-efficiency.
|
|
|
|
//
|
|
|
|
// The only reason to go via the service manager for the command table
|
|
|
|
// is that it holds onto the singleton for us, avoiding static variables here.
|
|
|
|
static nsresult
|
|
|
|
CreateControllerWithSingletonCommandTable(const nsCID& inCommandTableCID, nsIController **aResult)
|
2002-11-12 23:03:27 +00:00
|
|
|
{
|
2003-04-10 18:44:03 +00:00
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIController> controller = do_CreateInstance("@mozilla.org/embedcomp/base-command-controller;1", &rv);
|
2010-06-17 19:27:24 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2003-04-10 18:44:03 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIControllerCommandTable> composerCommandTable = do_GetService(inCommandTableCID, &rv);
|
2010-06-17 19:27:24 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2002-11-12 23:03:27 +00:00
|
|
|
|
2003-04-10 18:44:03 +00:00
|
|
|
// this guy is a singleton, so make it immutable
|
|
|
|
composerCommandTable->MakeImmutable();
|
|
|
|
|
|
|
|
nsCOMPtr<nsIControllerContext> controllerContext = do_QueryInterface(controller, &rv);
|
2010-06-17 19:27:24 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2003-04-10 18:44:03 +00:00
|
|
|
|
|
|
|
rv = controllerContext->Init(composerCommandTable);
|
2010-06-17 19:27:24 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2003-04-10 18:44:03 +00:00
|
|
|
|
|
|
|
*aResult = controller;
|
|
|
|
NS_ADDREF(*aResult);
|
|
|
|
return NS_OK;
|
2002-11-12 23:03:27 +00:00
|
|
|
}
|
|
|
|
|
2003-04-10 18:44:03 +00:00
|
|
|
|
|
|
|
// Here we make an instance of the controller that holds doc state commands.
|
|
|
|
// We set it up with a singleton command table.
|
2010-06-10 18:11:40 +00:00
|
|
|
static nsresult
|
2003-04-10 18:44:03 +00:00
|
|
|
nsHTMLEditorDocStateControllerConstructor(nsISupports *aOuter, REFNSIID aIID,
|
2002-11-12 23:03:27 +00:00
|
|
|
void **aResult)
|
|
|
|
{
|
2003-04-10 18:44:03 +00:00
|
|
|
nsCOMPtr<nsIController> controller;
|
|
|
|
nsresult rv = CreateControllerWithSingletonCommandTable(kHTMLEditorDocStateCommandTableCID, getter_AddRefs(controller));
|
2010-06-17 19:27:24 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2003-04-10 18:44:03 +00:00
|
|
|
|
|
|
|
return controller->QueryInterface(aIID, aResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Tere we make an instance of the controller that holds composer commands.
|
|
|
|
// We set it up with a singleton command table.
|
2010-06-10 18:11:40 +00:00
|
|
|
static nsresult
|
2003-04-10 18:44:03 +00:00
|
|
|
nsHTMLEditorControllerConstructor(nsISupports *aOuter, REFNSIID aIID, void **aResult)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIController> controller;
|
|
|
|
nsresult rv = CreateControllerWithSingletonCommandTable(kHTMLEditorCommandTableCID, getter_AddRefs(controller));
|
2010-06-17 19:27:24 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2002-11-12 23:03:27 +00:00
|
|
|
|
2003-04-10 18:44:03 +00:00
|
|
|
return controller->QueryInterface(aIID, aResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Constructor for a command table that is pref-filled with HTML editor commands
|
2010-06-10 18:11:40 +00:00
|
|
|
static nsresult
|
2003-04-10 18:44:03 +00:00
|
|
|
nsHTMLEditorCommandTableConstructor(nsISupports *aOuter, REFNSIID aIID,
|
|
|
|
void **aResult)
|
|
|
|
{
|
2002-11-12 23:03:27 +00:00
|
|
|
nsresult rv;
|
2003-04-10 18:44:03 +00:00
|
|
|
nsCOMPtr<nsIControllerCommandTable> commandTable =
|
|
|
|
do_CreateInstance(NS_CONTROLLERCOMMANDTABLE_CONTRACTID, &rv);
|
2010-06-17 19:27:24 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2003-04-10 18:44:03 +00:00
|
|
|
|
|
|
|
rv = nsComposerController::RegisterHTMLEditorCommands(commandTable);
|
2010-06-17 19:27:24 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2003-04-10 18:44:03 +00:00
|
|
|
|
|
|
|
// we don't know here whether we're being created as an instance,
|
|
|
|
// or a service, so we can't become immutable
|
|
|
|
|
|
|
|
return commandTable->QueryInterface(aIID, aResult);
|
|
|
|
}
|
2002-11-12 23:03:27 +00:00
|
|
|
|
2003-04-10 18:44:03 +00:00
|
|
|
|
|
|
|
// Constructor for a command table that is pref-filled with HTML editor doc state commands
|
2010-06-10 18:11:40 +00:00
|
|
|
static nsresult
|
2003-04-10 18:44:03 +00:00
|
|
|
nsHTMLEditorDocStateCommandTableConstructor(nsISupports *aOuter, REFNSIID aIID,
|
|
|
|
void **aResult)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIControllerCommandTable> commandTable =
|
|
|
|
do_CreateInstance(NS_CONTROLLERCOMMANDTABLE_CONTRACTID, &rv);
|
2010-06-17 19:27:24 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2003-04-10 18:44:03 +00:00
|
|
|
|
|
|
|
rv = nsComposerController::RegisterEditorDocStateCommands(commandTable);
|
2010-06-17 19:27:24 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2002-11-12 23:03:27 +00:00
|
|
|
|
2003-04-10 18:44:03 +00:00
|
|
|
// we don't know here whether we're being created as an instance,
|
|
|
|
// or a service, so we can't become immutable
|
|
|
|
|
|
|
|
return commandTable->QueryInterface(aIID, aResult);
|
2002-11-12 23:03:27 +00:00
|
|
|
}
|
|
|
|
|
2010-06-10 18:11:40 +00:00
|
|
|
NS_DEFINE_NAMED_CID(NS_HTMLEDITORCONTROLLER_CID);
|
|
|
|
NS_DEFINE_NAMED_CID(NS_EDITORDOCSTATECONTROLLER_CID);
|
|
|
|
NS_DEFINE_NAMED_CID(NS_HTMLEDITOR_COMMANDTABLE_CID);
|
|
|
|
NS_DEFINE_NAMED_CID(NS_HTMLEDITOR_DOCSTATE_COMMANDTABLE_CID);
|
|
|
|
NS_DEFINE_NAMED_CID(NS_EDITINGSESSION_CID);
|
|
|
|
NS_DEFINE_NAMED_CID(NS_EDITORSPELLCHECK_CID);
|
|
|
|
NS_DEFINE_NAMED_CID(NS_COMPOSERTXTSRVFILTER_CID);
|
|
|
|
NS_DEFINE_NAMED_CID(NS_COMPOSERTXTSRVFILTERMAIL_CID);
|
|
|
|
|
|
|
|
|
|
|
|
static const mozilla::Module::CIDEntry kComposerCIDs[] = {
|
|
|
|
{ &kNS_HTMLEDITORCONTROLLER_CID, false, NULL, nsHTMLEditorControllerConstructor },
|
|
|
|
{ &kNS_EDITORDOCSTATECONTROLLER_CID, false, NULL, nsHTMLEditorDocStateControllerConstructor },
|
|
|
|
{ &kNS_HTMLEDITOR_COMMANDTABLE_CID, false, NULL, nsHTMLEditorCommandTableConstructor },
|
|
|
|
{ &kNS_HTMLEDITOR_DOCSTATE_COMMANDTABLE_CID, false, NULL, nsHTMLEditorDocStateCommandTableConstructor },
|
|
|
|
{ &kNS_EDITINGSESSION_CID, false, NULL, nsEditingSessionConstructor },
|
|
|
|
{ &kNS_EDITORSPELLCHECK_CID, false, NULL, nsEditorSpellCheckConstructor },
|
|
|
|
{ &kNS_COMPOSERTXTSRVFILTER_CID, false, NULL, nsComposeTxtSrvFilterConstructorForComposer },
|
|
|
|
{ &kNS_COMPOSERTXTSRVFILTERMAIL_CID, false, NULL, nsComposeTxtSrvFilterConstructorForMail },
|
|
|
|
{ NULL }
|
|
|
|
};
|
2003-04-10 18:44:03 +00:00
|
|
|
|
2010-06-10 18:11:40 +00:00
|
|
|
static const mozilla::Module::ContractIDEntry kComposerContracts[] = {
|
|
|
|
{ "@mozilla.org/editor/htmleditorcontroller;1", &kNS_HTMLEDITORCONTROLLER_CID },
|
|
|
|
{ "@mozilla.org/editor/editordocstatecontroller;1", &kNS_EDITORDOCSTATECONTROLLER_CID },
|
|
|
|
{ "@mozilla.org/editor/editingsession;1", &kNS_EDITINGSESSION_CID },
|
|
|
|
{ "@mozilla.org/editor/editorspellchecker;1", &kNS_EDITORSPELLCHECK_CID },
|
|
|
|
{ COMPOSER_TXTSRVFILTER_CONTRACTID, &kNS_COMPOSERTXTSRVFILTER_CID },
|
|
|
|
{ COMPOSER_TXTSRVFILTERMAIL_CONTRACTID, &kNS_COMPOSERTXTSRVFILTERMAIL_CID },
|
|
|
|
{ NULL }
|
|
|
|
};
|
2003-04-10 18:44:03 +00:00
|
|
|
|
2010-06-10 18:11:40 +00:00
|
|
|
static const mozilla::Module kComposerModule = {
|
|
|
|
mozilla::Module::kVersion,
|
|
|
|
kComposerCIDs,
|
|
|
|
kComposerContracts
|
2001-04-05 23:51:30 +00:00
|
|
|
};
|
|
|
|
|
2010-06-10 18:11:40 +00:00
|
|
|
NSMODULE_DEFN(nsComposerModule) = &kComposerModule;
|