Back to index

lightning-sunbird  0.9+nobinonly
nsComposerController.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is Mozilla Communicator client code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Pierre Phaneuf <pp@ludusdesign.com>
00024  *   Ryan Cassin <rcassin@supernova.org>
00025  *   Daniel Glazman <glazman@netscape.com>
00026  *
00027  * Alternatively, the contents of this file may be used under the terms of
00028  * either of the GNU General Public License Version 2 or later (the "GPL"),
00029  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00030  * in which case the provisions of the GPL or the LGPL are applicable instead
00031  * of those above. If you wish to allow use of your version of this file only
00032  * under the terms of either the GPL or the LGPL, and not to allow others to
00033  * use your version of this file under the terms of the MPL, indicate your
00034  * decision by deleting the provisions above and replace them with the notice
00035  * and other provisions required by the GPL or the LGPL. If you do not delete
00036  * the provisions above, a recipient may use your version of this file under
00037  * the terms of any one of the MPL, the GPL or the LGPL.
00038  *
00039  * ***** END LICENSE BLOCK ***** */
00040 
00041 #include "nsIControllerCommandTable.h"
00042 #include "nsComposerController.h"
00043 #include "nsComposerCommands.h"
00044 
00045 #define NS_REGISTER_ONE_COMMAND(_cmdClass, _cmdName)                    \
00046   {                                                                     \
00047     _cmdClass* theCmd;                                                  \
00048     NS_NEWXPCOM(theCmd, _cmdClass);                                     \
00049     if (!theCmd) return NS_ERROR_OUT_OF_MEMORY;                         \
00050     rv = inCommandTable->RegisterCommand(_cmdName,                      \
00051                        NS_STATIC_CAST(nsIControllerCommand *, theCmd)); \
00052   }
00053 
00054 #define NS_REGISTER_FIRST_COMMAND(_cmdClass, _cmdName)                  \
00055   {                                                                     \
00056     _cmdClass* theCmd;                                                  \
00057     NS_NEWXPCOM(theCmd, _cmdClass);                                     \
00058     if (!theCmd) return NS_ERROR_OUT_OF_MEMORY;                         \
00059     rv = inCommandTable->RegisterCommand(_cmdName,                      \
00060                        NS_STATIC_CAST(nsIControllerCommand *, theCmd));
00061 
00062 #define NS_REGISTER_NEXT_COMMAND(_cmdClass, _cmdName)                   \
00063     rv = inCommandTable->RegisterCommand(_cmdName,                      \
00064                         NS_STATIC_CAST(nsIControllerCommand *, theCmd));
00065 
00066 #define NS_REGISTER_LAST_COMMAND(_cmdClass, _cmdName)                   \
00067     rv = inCommandTable->RegisterCommand(_cmdName,                      \
00068                        NS_STATIC_CAST(nsIControllerCommand *, theCmd)); \
00069   }
00070 
00071 #define NS_REGISTER_STYLE_COMMAND(_cmdClass, _cmdName, _styleTag)       \
00072   {                                                                     \
00073     _cmdClass* theCmd = new _cmdClass(_styleTag);                       \
00074     if (!theCmd) return NS_ERROR_OUT_OF_MEMORY;                         \
00075     rv = inCommandTable->RegisterCommand(_cmdName,                      \
00076                        NS_STATIC_CAST(nsIControllerCommand *, theCmd)); \
00077   }
00078   
00079 #define NS_REGISTER_TAG_COMMAND(_cmdClass, _cmdName, _tagName)          \
00080   {                                                                     \
00081     _cmdClass* theCmd = new _cmdClass(_tagName);                        \
00082     if (!theCmd) return NS_ERROR_OUT_OF_MEMORY;                         \
00083     rv = inCommandTable->RegisterCommand(_cmdName,                      \
00084                        NS_STATIC_CAST(nsIControllerCommand *, theCmd)); \
00085   }
00086   
00087 
00088 // static
00089 nsresult
00090 nsComposerController::RegisterEditorDocStateCommands(
00091                         nsIControllerCommandTable *inCommandTable)
00092 {
00093   nsresult rv;
00094 
00095   // observer commands for document state
00096   NS_REGISTER_FIRST_COMMAND(nsDocumentStateCommand, "obs_documentCreated")
00097   NS_REGISTER_NEXT_COMMAND(nsDocumentStateCommand, "obs_documentWillBeDestroyed")
00098   NS_REGISTER_LAST_COMMAND(nsDocumentStateCommand, "obs_documentLocationChanged")
00099 
00100   // commands that may get or change state
00101   NS_REGISTER_FIRST_COMMAND(nsSetDocumentStateCommand, "cmd_setDocumentModified")
00102   NS_REGISTER_NEXT_COMMAND(nsSetDocumentStateCommand, "cmd_setDocumentUseCSS")
00103   NS_REGISTER_NEXT_COMMAND(nsSetDocumentStateCommand, "cmd_setDocumentReadOnly")
00104   NS_REGISTER_NEXT_COMMAND(nsSetDocumentStateCommand, "cmd_insertBrOnReturn")
00105   NS_REGISTER_NEXT_COMMAND(nsSetDocumentStateCommand, "cmd_enableObjectResizing")
00106   NS_REGISTER_LAST_COMMAND(nsSetDocumentStateCommand, "cmd_enableInlineTableEditing")
00107 
00108   NS_REGISTER_ONE_COMMAND(nsSetDocumentOptionsCommand, "cmd_setDocumentOptions")
00109 
00110   return NS_OK;
00111 }
00112 
00113 // static
00114 nsresult
00115 nsComposerController::RegisterHTMLEditorCommands(
00116                         nsIControllerCommandTable *inCommandTable)
00117 {
00118   nsresult rv;
00119   
00120   // Edit menu
00121   NS_REGISTER_ONE_COMMAND(nsPasteNoFormattingCommand, "cmd_pasteNoFormatting");
00122 
00123   // indent/outdent
00124   NS_REGISTER_ONE_COMMAND(nsIndentCommand, "cmd_indent");
00125   NS_REGISTER_ONE_COMMAND(nsOutdentCommand, "cmd_outdent");
00126 
00127   // Styles
00128   NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_bold", "b");
00129   NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_italic", "i");
00130   NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_underline", "u");
00131   NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_tt", "tt");
00132 
00133   NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_strikethrough", "strike");
00134   NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_superscript", "sup");
00135   NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_subscript", "sub");
00136   NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_nobreak", "nobr");
00137 
00138   NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_em", "em");
00139   NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_strong", "strong");
00140   NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_cite", "cite");
00141   NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_abbr", "abbr");
00142   NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_acronym", "acronym");
00143   NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_code", "code");
00144   NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_samp", "samp");
00145   NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_var", "var");
00146   NS_REGISTER_STYLE_COMMAND(nsStyleUpdatingCommand, "cmd_removeLinks", "href");
00147 
00148   // lists
00149   NS_REGISTER_STYLE_COMMAND(nsListCommand,     "cmd_ol", "ol");
00150   NS_REGISTER_STYLE_COMMAND(nsListCommand,     "cmd_ul", "ul");
00151   NS_REGISTER_STYLE_COMMAND(nsListItemCommand, "cmd_dt", "dt");
00152   NS_REGISTER_STYLE_COMMAND(nsListItemCommand, "cmd_dd", "dd");
00153   NS_REGISTER_ONE_COMMAND(nsRemoveListCommand, "cmd_removeList");
00154 
00155   // format stuff
00156   NS_REGISTER_ONE_COMMAND(nsParagraphStateCommand,       "cmd_paragraphState");
00157   NS_REGISTER_ONE_COMMAND(nsFontFaceStateCommand,        "cmd_fontFace");
00158   NS_REGISTER_ONE_COMMAND(nsFontSizeStateCommand,        "cmd_fontSize");
00159   NS_REGISTER_ONE_COMMAND(nsFontColorStateCommand,       "cmd_fontColor");
00160   NS_REGISTER_ONE_COMMAND(nsBackgroundColorStateCommand, "cmd_backgroundColor");
00161   NS_REGISTER_ONE_COMMAND(nsHighlightColorStateCommand,  "cmd_highlight");
00162 
00163   NS_REGISTER_ONE_COMMAND(nsAlignCommand, "cmd_align");
00164   NS_REGISTER_ONE_COMMAND(nsRemoveStylesCommand, "cmd_removeStyles");
00165 
00166   NS_REGISTER_ONE_COMMAND(nsIncreaseFontSizeCommand, "cmd_increaseFont");
00167   NS_REGISTER_ONE_COMMAND(nsDecreaseFontSizeCommand, "cmd_decreaseFont");
00168 
00169   // Insert content
00170   NS_REGISTER_ONE_COMMAND(nsInsertHTMLCommand, "cmd_insertHTML");
00171   NS_REGISTER_TAG_COMMAND(nsInsertTagCommand, "cmd_insertLinkNoUI", "a");
00172   NS_REGISTER_TAG_COMMAND(nsInsertTagCommand, "cmd_insertImageNoUI", "img");
00173   NS_REGISTER_TAG_COMMAND(nsInsertTagCommand, "cmd_insertHR", "hr");
00174 
00175   NS_REGISTER_ONE_COMMAND(nsAbsolutePositioningCommand, "cmd_absPos");
00176   NS_REGISTER_ONE_COMMAND(nsDecreaseZIndexCommand, "cmd_decreaseZIndex");
00177   NS_REGISTER_ONE_COMMAND(nsIncreaseZIndexCommand, "cmd_increaseZIndex");
00178 
00179   return NS_OK;
00180 }