michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef nsComposerCommands_h_ michael@0: #define nsComposerCommands_h_ michael@0: michael@0: #include "nsIControllerCommand.h" michael@0: #include "nsISupportsImpl.h" // for NS_DECL_ISUPPORTS_INHERITED, etc michael@0: #include "nscore.h" // for nsresult, NS_IMETHOD michael@0: michael@0: class nsIAtom; michael@0: class nsICommandParams; michael@0: class nsIEditor; michael@0: class nsISupports; michael@0: class nsString; michael@0: michael@0: // This is a virtual base class for commands registered with the composer controller. michael@0: // Note that such commands are instantiated once per composer, so can store state. michael@0: // Also note that IsCommandEnabled can be called with an editor that may not michael@0: // have an editor yet (because the document is loading). Most commands will want michael@0: // to return false in this case. michael@0: // Don't hold on to any references to the editor or document from michael@0: // your command. This will cause leaks. Also, be aware that the document the michael@0: // editor is editing can change under you (if the user Reverts the file, for michael@0: // instance). michael@0: class nsBaseComposerCommand : public nsIControllerCommand michael@0: { michael@0: public: michael@0: michael@0: nsBaseComposerCommand(); michael@0: virtual ~nsBaseComposerCommand() {} michael@0: michael@0: // nsISupports michael@0: NS_DECL_ISUPPORTS michael@0: michael@0: // nsIControllerCommand. Declared longhand so we can make them pure virtual michael@0: NS_IMETHOD IsCommandEnabled(const char * aCommandName, nsISupports *aCommandRefCon, bool *_retval) = 0; michael@0: NS_IMETHOD DoCommand(const char * aCommandName, nsISupports *aCommandRefCon) = 0; michael@0: michael@0: }; michael@0: michael@0: michael@0: #define NS_DECL_COMPOSER_COMMAND(_cmd) \ michael@0: class _cmd : public nsBaseComposerCommand \ michael@0: { \ michael@0: public: \ michael@0: NS_DECL_NSICONTROLLERCOMMAND \ michael@0: }; michael@0: michael@0: // virtual base class for commands that need to save and update Boolean state (like styles etc) michael@0: class nsBaseStateUpdatingCommand : public nsBaseComposerCommand michael@0: { michael@0: public: michael@0: nsBaseStateUpdatingCommand(nsIAtom* aTagName); michael@0: virtual ~nsBaseStateUpdatingCommand(); michael@0: michael@0: NS_DECL_ISUPPORTS_INHERITED michael@0: michael@0: NS_DECL_NSICONTROLLERCOMMAND michael@0: michael@0: protected: michael@0: michael@0: // get the current state (on or off) for this style or block format michael@0: virtual nsresult GetCurrentState(nsIEditor* aEditor, nsICommandParams* aParams) = 0; michael@0: michael@0: // add/remove the style michael@0: virtual nsresult ToggleState(nsIEditor* aEditor) = 0; michael@0: michael@0: protected: michael@0: nsIAtom* mTagName; michael@0: }; michael@0: michael@0: michael@0: // Shared class for the various style updating commands like bold, italics etc. michael@0: // Suitable for commands whose state is either 'on' or 'off'. michael@0: class nsStyleUpdatingCommand : public nsBaseStateUpdatingCommand michael@0: { michael@0: public: michael@0: nsStyleUpdatingCommand(nsIAtom* aTagName); michael@0: michael@0: protected: michael@0: michael@0: // get the current state (on or off) for this style or block format michael@0: virtual nsresult GetCurrentState(nsIEditor* aEditor, nsICommandParams* aParams); michael@0: michael@0: // add/remove the style michael@0: virtual nsresult ToggleState(nsIEditor* aEditor); michael@0: }; michael@0: michael@0: michael@0: class nsInsertTagCommand : public nsBaseComposerCommand michael@0: { michael@0: public: michael@0: explicit nsInsertTagCommand(nsIAtom* aTagName); michael@0: virtual ~nsInsertTagCommand(); michael@0: michael@0: NS_DECL_ISUPPORTS_INHERITED michael@0: michael@0: NS_DECL_NSICONTROLLERCOMMAND michael@0: michael@0: protected: michael@0: michael@0: nsIAtom* mTagName; michael@0: }; michael@0: michael@0: michael@0: class nsListCommand : public nsBaseStateUpdatingCommand michael@0: { michael@0: public: michael@0: nsListCommand(nsIAtom* aTagName); michael@0: michael@0: protected: michael@0: michael@0: // get the current state (on or off) for this style or block format michael@0: virtual nsresult GetCurrentState(nsIEditor* aEditor, nsICommandParams* aParams); michael@0: michael@0: // add/remove the style michael@0: virtual nsresult ToggleState(nsIEditor* aEditor); michael@0: }; michael@0: michael@0: class nsListItemCommand : public nsBaseStateUpdatingCommand michael@0: { michael@0: public: michael@0: nsListItemCommand(nsIAtom* aTagName); michael@0: michael@0: protected: michael@0: michael@0: // get the current state (on or off) for this style or block format michael@0: virtual nsresult GetCurrentState(nsIEditor* aEditor, nsICommandParams* aParams); michael@0: michael@0: // add/remove the style michael@0: virtual nsresult ToggleState(nsIEditor* aEditor); michael@0: }; michael@0: michael@0: // Base class for commands whose state consists of a string (e.g. para format) michael@0: class nsMultiStateCommand : public nsBaseComposerCommand michael@0: { michael@0: public: michael@0: michael@0: nsMultiStateCommand(); michael@0: virtual ~nsMultiStateCommand(); michael@0: michael@0: NS_DECL_ISUPPORTS_INHERITED michael@0: NS_DECL_NSICONTROLLERCOMMAND michael@0: michael@0: protected: michael@0: michael@0: virtual nsresult GetCurrentState(nsIEditor *aEditor, nsICommandParams* aParams) =0; michael@0: virtual nsresult SetState(nsIEditor *aEditor, nsString& newState) = 0; michael@0: michael@0: }; michael@0: michael@0: michael@0: class nsParagraphStateCommand : public nsMultiStateCommand michael@0: { michael@0: public: michael@0: nsParagraphStateCommand(); michael@0: michael@0: protected: michael@0: michael@0: virtual nsresult GetCurrentState(nsIEditor *aEditor, nsICommandParams* aParams); michael@0: virtual nsresult SetState(nsIEditor *aEditor, nsString& newState); michael@0: }; michael@0: michael@0: class nsFontFaceStateCommand : public nsMultiStateCommand michael@0: { michael@0: public: michael@0: nsFontFaceStateCommand(); michael@0: michael@0: protected: michael@0: michael@0: virtual nsresult GetCurrentState(nsIEditor *aEditor, nsICommandParams* aParams); michael@0: virtual nsresult SetState(nsIEditor *aEditor, nsString& newState); michael@0: }; michael@0: michael@0: class nsFontSizeStateCommand : public nsMultiStateCommand michael@0: { michael@0: public: michael@0: nsFontSizeStateCommand(); michael@0: michael@0: protected: michael@0: michael@0: virtual nsresult GetCurrentState(nsIEditor *aEditor, michael@0: nsICommandParams* aParams); michael@0: virtual nsresult SetState(nsIEditor *aEditor, nsString& newState); michael@0: }; michael@0: michael@0: class nsHighlightColorStateCommand : public nsMultiStateCommand michael@0: { michael@0: public: michael@0: nsHighlightColorStateCommand(); michael@0: michael@0: protected: michael@0: michael@0: NS_IMETHOD IsCommandEnabled(const char *aCommandName, nsISupports *aCommandRefCon, bool *_retval); michael@0: virtual nsresult GetCurrentState(nsIEditor *aEditor, nsICommandParams* aParams); michael@0: virtual nsresult SetState(nsIEditor *aEditor, nsString& newState); michael@0: michael@0: }; michael@0: michael@0: class nsFontColorStateCommand : public nsMultiStateCommand michael@0: { michael@0: public: michael@0: nsFontColorStateCommand(); michael@0: michael@0: protected: michael@0: michael@0: virtual nsresult GetCurrentState(nsIEditor *aEditor, nsICommandParams* aParams); michael@0: virtual nsresult SetState(nsIEditor *aEditor, nsString& newState); michael@0: }; michael@0: michael@0: class nsAlignCommand : public nsMultiStateCommand michael@0: { michael@0: public: michael@0: nsAlignCommand(); michael@0: michael@0: protected: michael@0: michael@0: virtual nsresult GetCurrentState(nsIEditor *aEditor, nsICommandParams* aParams); michael@0: virtual nsresult SetState(nsIEditor *aEditor, nsString& newState); michael@0: }; michael@0: michael@0: class nsBackgroundColorStateCommand : public nsMultiStateCommand michael@0: { michael@0: public: michael@0: nsBackgroundColorStateCommand(); michael@0: michael@0: protected: michael@0: michael@0: virtual nsresult GetCurrentState(nsIEditor *aEditor, nsICommandParams* aParams); michael@0: virtual nsresult SetState(nsIEditor *aEditor, nsString& newState); michael@0: }; michael@0: michael@0: class nsAbsolutePositioningCommand : public nsBaseStateUpdatingCommand michael@0: { michael@0: public: michael@0: nsAbsolutePositioningCommand(); michael@0: michael@0: protected: michael@0: michael@0: NS_IMETHOD IsCommandEnabled(const char *aCommandName, nsISupports *aCommandRefCon, bool *_retval); michael@0: virtual nsresult GetCurrentState(nsIEditor* aEditor, nsICommandParams* aParams); michael@0: virtual nsresult ToggleState(nsIEditor* aEditor); michael@0: }; michael@0: michael@0: // composer commands michael@0: michael@0: NS_DECL_COMPOSER_COMMAND(nsCloseCommand) michael@0: NS_DECL_COMPOSER_COMMAND(nsDocumentStateCommand) michael@0: NS_DECL_COMPOSER_COMMAND(nsSetDocumentStateCommand) michael@0: NS_DECL_COMPOSER_COMMAND(nsSetDocumentOptionsCommand) michael@0: //NS_DECL_COMPOSER_COMMAND(nsPrintingCommands) michael@0: michael@0: NS_DECL_COMPOSER_COMMAND(nsDecreaseZIndexCommand) michael@0: NS_DECL_COMPOSER_COMMAND(nsIncreaseZIndexCommand) michael@0: michael@0: // Generic commands michael@0: michael@0: // File menu michael@0: NS_DECL_COMPOSER_COMMAND(nsNewCommands) // handles 'new' anything michael@0: michael@0: // Edit menu michael@0: NS_DECL_COMPOSER_COMMAND(nsPasteNoFormattingCommand) michael@0: michael@0: // Block transformations michael@0: NS_DECL_COMPOSER_COMMAND(nsIndentCommand) michael@0: NS_DECL_COMPOSER_COMMAND(nsOutdentCommand) michael@0: michael@0: NS_DECL_COMPOSER_COMMAND(nsRemoveListCommand) michael@0: NS_DECL_COMPOSER_COMMAND(nsRemoveStylesCommand) michael@0: NS_DECL_COMPOSER_COMMAND(nsIncreaseFontSizeCommand) michael@0: NS_DECL_COMPOSER_COMMAND(nsDecreaseFontSizeCommand) michael@0: michael@0: // Insert content commands michael@0: NS_DECL_COMPOSER_COMMAND(nsInsertHTMLCommand) michael@0: michael@0: #endif // nsComposerCommands_h_