Back to index

lightning-sunbird  0.9+nobinonly
nsEditorController.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  *
00026  * Alternatively, the contents of this file may be used under the terms of
00027  * either of the GNU General Public License Version 2 or later (the "GPL"),
00028  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00029  * in which case the provisions of the GPL or the LGPL are applicable instead
00030  * of those above. If you wish to allow use of your version of this file only
00031  * under the terms of either the GPL or the LGPL, and not to allow others to
00032  * use your version of this file under the terms of the MPL, indicate your
00033  * decision by deleting the provisions above and replace them with the notice
00034  * and other provisions required by the GPL or the LGPL. If you do not delete
00035  * the provisions above, a recipient may use your version of this file under
00036  * the terms of any one of the MPL, the GPL or the LGPL.
00037  *
00038  * ***** END LICENSE BLOCK ***** */
00039 
00040 #include "nsString.h"
00041 #include "nsIComponentManager.h"
00042 #include "nsEditorController.h"
00043 #include "nsEditorCommands.h"
00044 #include "nsIControllerCommandTable.h"
00045 
00046 
00047 
00048 #define NS_REGISTER_ONE_COMMAND(_cmdClass, _cmdName)                                      \
00049   {                                                                                       \
00050     _cmdClass* theCmd;                                                                    \
00051     NS_NEWXPCOM(theCmd, _cmdClass);                                                       \
00052     if (!theCmd) return NS_ERROR_OUT_OF_MEMORY;                                           \
00053     rv = inCommandTable->RegisterCommand(_cmdName,                                        \
00054                                    NS_STATIC_CAST(nsIControllerCommand *, theCmd));       \
00055   }
00056 
00057 #define NS_REGISTER_FIRST_COMMAND(_cmdClass, _cmdName)                                    \
00058   {                                                                                       \
00059     _cmdClass* theCmd;                                                                    \
00060     NS_NEWXPCOM(theCmd, _cmdClass);                                                       \
00061     if (!theCmd) return NS_ERROR_OUT_OF_MEMORY;                                           \
00062     rv = inCommandTable->RegisterCommand(_cmdName,                                        \
00063                                    NS_STATIC_CAST(nsIControllerCommand *, theCmd));
00064 
00065 #define NS_REGISTER_NEXT_COMMAND(_cmdClass, _cmdName)                                     \
00066     rv = inCommandTable->RegisterCommand(_cmdName,                                        \
00067                                    NS_STATIC_CAST(nsIControllerCommand *, theCmd));
00068 
00069 #define NS_REGISTER_LAST_COMMAND(_cmdClass, _cmdName)                                     \
00070     rv = inCommandTable->RegisterCommand(_cmdName,                                        \
00071                                    NS_STATIC_CAST(nsIControllerCommand *, theCmd));       \
00072   }
00073 
00074 
00075 // static
00076 nsresult nsEditorController::RegisterEditorCommands(nsIControllerCommandTable *inCommandTable)
00077 {
00078   nsresult rv;
00079  
00080   // now register all our commands
00081   // These are commands that will be used in text widgets, and in composer
00082   
00083   NS_REGISTER_ONE_COMMAND(nsUndoCommand, "cmd_undo");
00084   NS_REGISTER_ONE_COMMAND(nsRedoCommand, "cmd_redo");
00085   NS_REGISTER_ONE_COMMAND(nsClearUndoCommand, "cmd_clearUndo");
00086 
00087   NS_REGISTER_ONE_COMMAND(nsCutCommand, "cmd_cut");
00088   NS_REGISTER_ONE_COMMAND(nsCutOrDeleteCommand, "cmd_cutOrDelete");
00089   NS_REGISTER_ONE_COMMAND(nsCopyCommand, "cmd_copy");
00090   NS_REGISTER_ONE_COMMAND(nsCopyOrDeleteCommand, "cmd_copyOrDelete");
00091   NS_REGISTER_ONE_COMMAND(nsSelectAllCommand, "cmd_selectAll");
00092   
00093   NS_REGISTER_ONE_COMMAND(nsPasteCommand, "cmd_paste");
00094   NS_REGISTER_ONE_COMMAND(nsSwitchTextDirectionCommand, "cmd_switchTextDirection");
00095   
00096   NS_REGISTER_FIRST_COMMAND(nsDeleteCommand, "cmd_delete");
00097   NS_REGISTER_NEXT_COMMAND(nsDeleteCommand, "cmd_deleteCharBackward");
00098   NS_REGISTER_NEXT_COMMAND(nsDeleteCommand, "cmd_deleteCharForward");
00099   NS_REGISTER_NEXT_COMMAND(nsDeleteCommand, "cmd_deleteWordBackward");
00100   NS_REGISTER_NEXT_COMMAND(nsDeleteCommand, "cmd_deleteWordForward");
00101   NS_REGISTER_NEXT_COMMAND(nsDeleteCommand, "cmd_deleteToBeginningOfLine");
00102   NS_REGISTER_LAST_COMMAND(nsDeleteCommand, "cmd_deleteToEndOfLine");
00103 
00104   NS_REGISTER_FIRST_COMMAND(nsSelectionMoveCommands, "cmd_scrollTop");
00105   NS_REGISTER_NEXT_COMMAND(nsSelectionMoveCommands, "cmd_scrollBottom");
00106   NS_REGISTER_NEXT_COMMAND(nsSelectionMoveCommands, "cmd_moveTop");
00107   NS_REGISTER_NEXT_COMMAND(nsSelectionMoveCommands, "cmd_moveBottom");
00108   NS_REGISTER_NEXT_COMMAND(nsSelectionMoveCommands, "cmd_selectTop");
00109   NS_REGISTER_NEXT_COMMAND(nsSelectionMoveCommands, "cmd_selectBottom");
00110   NS_REGISTER_NEXT_COMMAND(nsSelectionMoveCommands, "cmd_lineNext");
00111   NS_REGISTER_NEXT_COMMAND(nsSelectionMoveCommands, "cmd_linePrevious");
00112   NS_REGISTER_NEXT_COMMAND(nsSelectionMoveCommands, "cmd_selectLineNext");
00113   NS_REGISTER_NEXT_COMMAND(nsSelectionMoveCommands, "cmd_selectLinePrevious");
00114   NS_REGISTER_NEXT_COMMAND(nsSelectionMoveCommands, "cmd_charPrevious");
00115   NS_REGISTER_NEXT_COMMAND(nsSelectionMoveCommands, "cmd_charNext");
00116   NS_REGISTER_NEXT_COMMAND(nsSelectionMoveCommands, "cmd_selectCharPrevious");
00117   NS_REGISTER_NEXT_COMMAND(nsSelectionMoveCommands, "cmd_selectCharNext");
00118   NS_REGISTER_NEXT_COMMAND(nsSelectionMoveCommands, "cmd_beginLine");
00119   NS_REGISTER_NEXT_COMMAND(nsSelectionMoveCommands, "cmd_endLine");
00120   NS_REGISTER_NEXT_COMMAND(nsSelectionMoveCommands, "cmd_selectBeginLine");
00121   NS_REGISTER_NEXT_COMMAND(nsSelectionMoveCommands, "cmd_selectEndLine");
00122   NS_REGISTER_NEXT_COMMAND(nsSelectionMoveCommands, "cmd_wordPrevious");
00123   NS_REGISTER_NEXT_COMMAND(nsSelectionMoveCommands, "cmd_wordNext");
00124   NS_REGISTER_NEXT_COMMAND(nsSelectionMoveCommands, "cmd_selectWordPrevious");
00125   NS_REGISTER_NEXT_COMMAND(nsSelectionMoveCommands, "cmd_selectWordNext");
00126   NS_REGISTER_NEXT_COMMAND(nsSelectionMoveCommands, "cmd_scrollPageUp");
00127   NS_REGISTER_NEXT_COMMAND(nsSelectionMoveCommands, "cmd_scrollPageDown");
00128   NS_REGISTER_NEXT_COMMAND(nsSelectionMoveCommands, "cmd_scrollLineUp");
00129   NS_REGISTER_NEXT_COMMAND(nsSelectionMoveCommands, "cmd_scrollLineDown");
00130   NS_REGISTER_NEXT_COMMAND(nsSelectionMoveCommands, "cmd_movePageUp");
00131   NS_REGISTER_NEXT_COMMAND(nsSelectionMoveCommands, "cmd_movePageDown");
00132   NS_REGISTER_NEXT_COMMAND(nsSelectionMoveCommands, "cmd_selectPageUp");
00133   NS_REGISTER_LAST_COMMAND(nsSelectionMoveCommands, "cmd_selectPageDown");
00134     
00135   // Insert content
00136   NS_REGISTER_ONE_COMMAND(nsInsertPlaintextCommand, "cmd_insertText");
00137   NS_REGISTER_ONE_COMMAND(nsPasteQuotationCommand,  "cmd_pasteQuote");
00138 
00139 
00140   return NS_OK;
00141 }
00142