Back to index

lightning-sunbird  0.9+nobinonly
nsComposerCommands.h
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-2000
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Ryan Cassin      <rcassin@supernova.org>
00024  *   Daniel Glazman   <glazman@netscape.com>
00025  *   Charles Manske   <cmanske@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 #ifndef nsComposerCommands_h_
00042 #define nsComposerCommands_h_
00043 
00044 #include "nsIControllerCommand.h"
00045 #include "nsString.h"
00046 
00047 class nsIEditor;
00048 
00049 // This is a virtual base class for commands registered with the composer controller.
00050 // Note that such commands are instantiated once per composer, so can store state.
00051 // Also note that IsCommandEnabled can be called with an editor that may not
00052 // have an editor yet (because the document is loading). Most commands will want
00053 // to return false in this case.
00054 // Don't hold on to any references to the editor or document from
00055 // your command. This will cause leaks. Also, be aware that the document the
00056 // editor is editing can change under you (if the user Reverts the file, for
00057 // instance).
00058 class nsBaseComposerCommand : public nsIControllerCommand
00059 {
00060 public:
00061 
00062               nsBaseComposerCommand();
00063   virtual     ~nsBaseComposerCommand() {}
00064     
00065   // nsISupports
00066   NS_DECL_ISUPPORTS
00067     
00068   // nsIControllerCommand. Declared longhand so we can make them pure virtual
00069   NS_IMETHOD IsCommandEnabled(const char * aCommandName, nsISupports *aCommandRefCon, PRBool *_retval) = 0;
00070   NS_IMETHOD DoCommand(const char * aCommandName, nsISupports *aCommandRefCon) = 0;
00071 
00072 };
00073 
00074 
00075 #define NS_DECL_COMPOSER_COMMAND(_cmd)                  \
00076 class _cmd : public nsBaseComposerCommand               \
00077 {                                                       \
00078 public:                                                 \
00079   NS_DECL_NSICONTROLLERCOMMAND                          \
00080 };
00081 
00082 // virtual base class for commands that need to save and update Boolean state (like styles etc)
00083 class nsBaseStateUpdatingCommand : public nsBaseComposerCommand
00084 {
00085 public:
00086 
00087               nsBaseStateUpdatingCommand(const char* aTagName);
00088   virtual     ~nsBaseStateUpdatingCommand();
00089     
00090   NS_DECL_ISUPPORTS_INHERITED
00091 
00092   NS_DECL_NSICONTROLLERCOMMAND
00093 
00094 protected:
00095 
00096   // get the current state (on or off) for this style or block format
00097   virtual nsresult  GetCurrentState(nsIEditor *aEditor, const char* aTagName, nsICommandParams *aParams) = 0;
00098   
00099   // add/remove the style
00100   virtual nsresult  ToggleState(nsIEditor *aEditor, const char* aTagName) = 0;
00101 
00102 protected:
00103 
00104   const char* mTagName;
00105 };
00106 
00107 
00108 // Shared class for the various style updating commands like bold, italics etc.
00109 // Suitable for commands whose state is either 'on' or 'off'.
00110 class nsStyleUpdatingCommand : public nsBaseStateUpdatingCommand
00111 {
00112 public:
00113 
00114             nsStyleUpdatingCommand(const char* aTagName);
00115            
00116 protected:
00117 
00118   // get the current state (on or off) for this style or block format
00119   virtual nsresult  GetCurrentState(nsIEditor *aEditor, const char* aTagName, nsICommandParams *aParams);
00120   
00121   // add/remove the style
00122   virtual nsresult  ToggleState(nsIEditor *aEditor, const char* aTagName);
00123   
00124 };
00125 
00126 
00127 class nsInsertTagCommand : public nsBaseComposerCommand
00128 {
00129 public:
00130 
00131               nsInsertTagCommand(const char* aTagName);
00132   virtual     ~nsInsertTagCommand();
00133     
00134   NS_DECL_ISUPPORTS_INHERITED
00135 
00136   NS_DECL_NSICONTROLLERCOMMAND
00137 
00138 protected:
00139 
00140   const char* mTagName;
00141 };
00142 
00143 
00144 class nsListCommand : public nsBaseStateUpdatingCommand
00145 {
00146 public:
00147 
00148             nsListCommand(const char* aTagName);
00149 
00150 protected:
00151 
00152   // get the current state (on or off) for this style or block format
00153   virtual nsresult  GetCurrentState(nsIEditor *aEditor, const char* aTagName, nsICommandParams *aParams);
00154   
00155   // add/remove the style
00156   virtual nsresult  ToggleState(nsIEditor *aEditor, const char* aTagName);
00157 };
00158 
00159 class nsListItemCommand : public nsBaseStateUpdatingCommand
00160 {
00161 public:
00162 
00163             nsListItemCommand(const char* aTagName);
00164 
00165 protected:
00166 
00167   // get the current state (on or off) for this style or block format
00168   virtual nsresult  GetCurrentState(nsIEditor *aEditor, const char* aTagName, nsICommandParams *aParams);
00169   
00170   // add/remove the style
00171   virtual nsresult  ToggleState(nsIEditor *aEditor, const char* aTagName);
00172 };
00173 
00174 // Base class for commands whose state consists of a string (e.g. para format)
00175 class nsMultiStateCommand : public nsBaseComposerCommand
00176 {
00177 public:
00178   
00179                    nsMultiStateCommand();
00180   virtual          ~nsMultiStateCommand();
00181   
00182   NS_DECL_ISUPPORTS_INHERITED
00183   NS_DECL_NSICONTROLLERCOMMAND
00184 
00185 protected:
00186 
00187   virtual nsresult GetCurrentState(nsIEditor *aEditor, nsICommandParams* aParams) =0;
00188   virtual nsresult SetState(nsIEditor *aEditor, nsString& newState) = 0;
00189   
00190 };
00191 
00192 
00193 class nsParagraphStateCommand : public nsMultiStateCommand
00194 {
00195 public:
00196                    nsParagraphStateCommand();
00197 
00198 protected:
00199 
00200   virtual nsresult GetCurrentState(nsIEditor *aEditor, nsICommandParams* aParams);
00201   virtual nsresult SetState(nsIEditor *aEditor, nsString& newState);
00202 };
00203 
00204 class nsFontFaceStateCommand : public nsMultiStateCommand
00205 {
00206 public:
00207                    nsFontFaceStateCommand();
00208 
00209 protected:
00210 
00211   virtual nsresult GetCurrentState(nsIEditor *aEditor, nsICommandParams* aParams);
00212   virtual nsresult SetState(nsIEditor *aEditor, nsString& newState);
00213 };
00214 
00215 class nsFontSizeStateCommand : public nsMultiStateCommand
00216 {
00217 public:
00218                    nsFontSizeStateCommand();
00219 
00220 protected:
00221 
00222   virtual nsresult GetCurrentState(nsIEditor *aEditor,
00223                                    nsICommandParams* aParams);
00224   virtual nsresult SetState(nsIEditor *aEditor, nsString& newState);
00225 };
00226 
00227 class nsHighlightColorStateCommand : public nsMultiStateCommand
00228 {
00229 public:
00230                    nsHighlightColorStateCommand();
00231 
00232 protected:
00233 
00234   NS_IMETHOD IsCommandEnabled(const char *aCommandName, nsISupports *aCommandRefCon, PRBool *_retval);
00235   virtual nsresult GetCurrentState(nsIEditor *aEditor, nsICommandParams* aParams);
00236   virtual nsresult SetState(nsIEditor *aEditor, nsString& newState);
00237 
00238 };
00239 
00240 class nsFontColorStateCommand : public nsMultiStateCommand
00241 {
00242 public:
00243                    nsFontColorStateCommand();
00244 
00245 protected:
00246 
00247   virtual nsresult GetCurrentState(nsIEditor *aEditor, nsICommandParams* aParams);
00248   virtual nsresult SetState(nsIEditor *aEditor, nsString& newState);
00249 };
00250 
00251 class nsAlignCommand : public nsMultiStateCommand
00252 {
00253 public:
00254                    nsAlignCommand();
00255 
00256 protected:
00257 
00258   virtual nsresult GetCurrentState(nsIEditor *aEditor, nsICommandParams* aParams);
00259   virtual nsresult SetState(nsIEditor *aEditor, nsString& newState);
00260 };
00261 
00262 class nsBackgroundColorStateCommand : public nsMultiStateCommand
00263 {
00264 public:
00265                    nsBackgroundColorStateCommand();
00266 
00267 protected:
00268 
00269   virtual nsresult GetCurrentState(nsIEditor *aEditor, nsICommandParams* aParams);
00270   virtual nsresult SetState(nsIEditor *aEditor, nsString& newState);
00271 };
00272 
00273 class nsAbsolutePositioningCommand : public nsBaseStateUpdatingCommand
00274 {
00275 public:
00276                    nsAbsolutePositioningCommand();
00277 
00278 protected:
00279 
00280   NS_IMETHOD IsCommandEnabled(const char *aCommandName, nsISupports *aCommandRefCon, PRBool *_retval);
00281   virtual nsresult  GetCurrentState(nsIEditor *aEditor, const char* aTagName, nsICommandParams *aParams);
00282   virtual nsresult  ToggleState(nsIEditor *aEditor, const char* aTagName);
00283 };
00284 
00285 // composer commands
00286 
00287 NS_DECL_COMPOSER_COMMAND(nsCloseCommand)
00288 NS_DECL_COMPOSER_COMMAND(nsDocumentStateCommand)
00289 NS_DECL_COMPOSER_COMMAND(nsSetDocumentStateCommand)
00290 NS_DECL_COMPOSER_COMMAND(nsSetDocumentOptionsCommand)
00291 //NS_DECL_COMPOSER_COMMAND(nsPrintingCommands)
00292 
00293 NS_DECL_COMPOSER_COMMAND(nsDecreaseZIndexCommand)
00294 NS_DECL_COMPOSER_COMMAND(nsIncreaseZIndexCommand)
00295 
00296 // Generic commands
00297 
00298 // File menu
00299 NS_DECL_COMPOSER_COMMAND(nsNewCommands)   // handles 'new' anything
00300 
00301 // Edit menu
00302 NS_DECL_COMPOSER_COMMAND(nsPasteNoFormattingCommand)
00303 
00304 // Block transformations
00305 NS_DECL_COMPOSER_COMMAND(nsIndentCommand)
00306 NS_DECL_COMPOSER_COMMAND(nsOutdentCommand)
00307 
00308 NS_DECL_COMPOSER_COMMAND(nsRemoveListCommand)
00309 NS_DECL_COMPOSER_COMMAND(nsRemoveStylesCommand)
00310 NS_DECL_COMPOSER_COMMAND(nsIncreaseFontSizeCommand)
00311 NS_DECL_COMPOSER_COMMAND(nsDecreaseFontSizeCommand)
00312 
00313 // Insert content commands
00314 NS_DECL_COMPOSER_COMMAND(nsInsertHTMLCommand)
00315 
00316 #endif // nsComposerCommands_h_