Line data Source code
1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* This Source Code Form is subject to the terms of the Mozilla Public
3 : * License, v. 2.0. If a copy of the MPL was not distributed with this
4 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 :
6 : #ifndef nsComposerCommands_h_
7 : #define nsComposerCommands_h_
8 :
9 : #include "nsIControllerCommand.h"
10 : #include "nsISupportsImpl.h" // for NS_DECL_ISUPPORTS_INHERITED, etc
11 : #include "nscore.h" // for nsresult, NS_IMETHOD
12 :
13 : class nsIAtom;
14 : class nsICommandParams;
15 : class nsIEditor;
16 : class nsISupports;
17 : class nsString;
18 :
19 : // This is a virtual base class for commands registered with the composer controller.
20 : // Note that such commands are instantiated once per composer, so can store state.
21 : // Also note that IsCommandEnabled can be called with an editor that may not
22 : // have an editor yet (because the document is loading). Most commands will want
23 : // to return false in this case.
24 : // Don't hold on to any references to the editor or document from
25 : // your command. This will cause leaks. Also, be aware that the document the
26 : // editor is editing can change under you (if the user Reverts the file, for
27 : // instance).
28 : class nsBaseComposerCommand : public nsIControllerCommand
29 : {
30 : protected:
31 0 : virtual ~nsBaseComposerCommand() {}
32 :
33 : public:
34 :
35 : nsBaseComposerCommand();
36 :
37 : // nsISupports
38 : NS_DECL_ISUPPORTS
39 :
40 : // nsIControllerCommand. Declared longhand so we can make them pure virtual
41 : NS_IMETHOD IsCommandEnabled(const char * aCommandName, nsISupports *aCommandRefCon, bool *_retval) override = 0;
42 : NS_IMETHOD DoCommand(const char * aCommandName, nsISupports *aCommandRefCon) override = 0;
43 :
44 : };
45 :
46 :
47 : #define NS_DECL_COMPOSER_COMMAND(_cmd) \
48 : class _cmd : public nsBaseComposerCommand \
49 : { \
50 : public: \
51 : NS_DECL_NSICONTROLLERCOMMAND \
52 : };
53 :
54 : // virtual base class for commands that need to save and update Boolean state (like styles etc)
55 : class nsBaseStateUpdatingCommand : public nsBaseComposerCommand
56 : {
57 : public:
58 : explicit nsBaseStateUpdatingCommand(nsIAtom* aTagName);
59 :
60 : NS_DECL_ISUPPORTS_INHERITED
61 :
62 : NS_DECL_NSICONTROLLERCOMMAND
63 :
64 : protected:
65 : virtual ~nsBaseStateUpdatingCommand();
66 :
67 : // get the current state (on or off) for this style or block format
68 : virtual nsresult GetCurrentState(nsIEditor* aEditor, nsICommandParams* aParams) = 0;
69 :
70 : // add/remove the style
71 : virtual nsresult ToggleState(nsIEditor* aEditor) = 0;
72 :
73 : protected:
74 : nsIAtom* mTagName;
75 : };
76 :
77 :
78 : // Shared class for the various style updating commands like bold, italics etc.
79 : // Suitable for commands whose state is either 'on' or 'off'.
80 0 : class nsStyleUpdatingCommand : public nsBaseStateUpdatingCommand
81 : {
82 : public:
83 : explicit nsStyleUpdatingCommand(nsIAtom* aTagName);
84 :
85 : protected:
86 :
87 : // get the current state (on or off) for this style or block format
88 : virtual nsresult GetCurrentState(nsIEditor* aEditor, nsICommandParams* aParams);
89 :
90 : // add/remove the style
91 : virtual nsresult ToggleState(nsIEditor* aEditor);
92 : };
93 :
94 :
95 : class nsInsertTagCommand : public nsBaseComposerCommand
96 : {
97 : public:
98 : explicit nsInsertTagCommand(nsIAtom* aTagName);
99 :
100 : NS_DECL_ISUPPORTS_INHERITED
101 :
102 : NS_DECL_NSICONTROLLERCOMMAND
103 :
104 : protected:
105 : virtual ~nsInsertTagCommand();
106 :
107 : nsIAtom* mTagName;
108 : };
109 :
110 :
111 0 : class nsListCommand : public nsBaseStateUpdatingCommand
112 : {
113 : public:
114 : explicit nsListCommand(nsIAtom* aTagName);
115 :
116 : protected:
117 :
118 : // get the current state (on or off) for this style or block format
119 : virtual nsresult GetCurrentState(nsIEditor* aEditor, nsICommandParams* aParams);
120 :
121 : // add/remove the style
122 : virtual nsresult ToggleState(nsIEditor* aEditor);
123 : };
124 :
125 0 : class nsListItemCommand : public nsBaseStateUpdatingCommand
126 : {
127 : public:
128 : explicit nsListItemCommand(nsIAtom* aTagName);
129 :
130 : protected:
131 :
132 : // get the current state (on or off) for this style or block format
133 : virtual nsresult GetCurrentState(nsIEditor* aEditor, nsICommandParams* aParams);
134 :
135 : // add/remove the style
136 : virtual nsresult ToggleState(nsIEditor* aEditor);
137 : };
138 :
139 : // Base class for commands whose state consists of a string (e.g. para format)
140 : class nsMultiStateCommand : public nsBaseComposerCommand
141 : {
142 : public:
143 :
144 : nsMultiStateCommand();
145 :
146 : NS_DECL_ISUPPORTS_INHERITED
147 : NS_DECL_NSICONTROLLERCOMMAND
148 :
149 : protected:
150 : virtual ~nsMultiStateCommand();
151 :
152 : virtual nsresult GetCurrentState(nsIEditor *aEditor, nsICommandParams* aParams) =0;
153 : virtual nsresult SetState(nsIEditor *aEditor, nsString& newState) = 0;
154 :
155 : };
156 :
157 :
158 0 : class nsParagraphStateCommand : public nsMultiStateCommand
159 : {
160 : public:
161 : nsParagraphStateCommand();
162 :
163 : protected:
164 :
165 : virtual nsresult GetCurrentState(nsIEditor *aEditor, nsICommandParams* aParams);
166 : virtual nsresult SetState(nsIEditor *aEditor, nsString& newState);
167 : };
168 :
169 0 : class nsFontFaceStateCommand : public nsMultiStateCommand
170 : {
171 : public:
172 : nsFontFaceStateCommand();
173 :
174 : protected:
175 :
176 : virtual nsresult GetCurrentState(nsIEditor *aEditor, nsICommandParams* aParams);
177 : virtual nsresult SetState(nsIEditor *aEditor, nsString& newState);
178 : };
179 :
180 0 : class nsFontSizeStateCommand : public nsMultiStateCommand
181 : {
182 : public:
183 : nsFontSizeStateCommand();
184 :
185 : protected:
186 :
187 : virtual nsresult GetCurrentState(nsIEditor *aEditor,
188 : nsICommandParams* aParams);
189 : virtual nsresult SetState(nsIEditor *aEditor, nsString& newState);
190 : };
191 :
192 0 : class nsHighlightColorStateCommand : public nsMultiStateCommand
193 : {
194 : public:
195 : nsHighlightColorStateCommand();
196 :
197 : protected:
198 :
199 : NS_IMETHOD IsCommandEnabled(const char *aCommandName, nsISupports *aCommandRefCon, bool *_retval);
200 : virtual nsresult GetCurrentState(nsIEditor *aEditor, nsICommandParams* aParams);
201 : virtual nsresult SetState(nsIEditor *aEditor, nsString& newState);
202 :
203 : };
204 :
205 0 : class nsFontColorStateCommand : public nsMultiStateCommand
206 : {
207 : public:
208 : nsFontColorStateCommand();
209 :
210 : protected:
211 :
212 : virtual nsresult GetCurrentState(nsIEditor *aEditor, nsICommandParams* aParams);
213 : virtual nsresult SetState(nsIEditor *aEditor, nsString& newState);
214 : };
215 :
216 0 : class nsAlignCommand : public nsMultiStateCommand
217 : {
218 : public:
219 : nsAlignCommand();
220 :
221 : protected:
222 :
223 : virtual nsresult GetCurrentState(nsIEditor *aEditor, nsICommandParams* aParams);
224 : virtual nsresult SetState(nsIEditor *aEditor, nsString& newState);
225 : };
226 :
227 0 : class nsBackgroundColorStateCommand : public nsMultiStateCommand
228 : {
229 : public:
230 : nsBackgroundColorStateCommand();
231 :
232 : protected:
233 :
234 : virtual nsresult GetCurrentState(nsIEditor *aEditor, nsICommandParams* aParams);
235 : virtual nsresult SetState(nsIEditor *aEditor, nsString& newState);
236 : };
237 :
238 0 : class nsAbsolutePositioningCommand : public nsBaseStateUpdatingCommand
239 : {
240 : public:
241 : nsAbsolutePositioningCommand();
242 :
243 : protected:
244 :
245 : NS_IMETHOD IsCommandEnabled(const char *aCommandName, nsISupports *aCommandRefCon, bool *_retval);
246 : virtual nsresult GetCurrentState(nsIEditor* aEditor, nsICommandParams* aParams);
247 : virtual nsresult ToggleState(nsIEditor* aEditor);
248 : };
249 :
250 : // composer commands
251 :
252 : NS_DECL_COMPOSER_COMMAND(nsCloseCommand)
253 0 : NS_DECL_COMPOSER_COMMAND(nsDocumentStateCommand)
254 0 : NS_DECL_COMPOSER_COMMAND(nsSetDocumentStateCommand)
255 0 : NS_DECL_COMPOSER_COMMAND(nsSetDocumentOptionsCommand)
256 : //NS_DECL_COMPOSER_COMMAND(nsPrintingCommands)
257 :
258 0 : NS_DECL_COMPOSER_COMMAND(nsDecreaseZIndexCommand)
259 0 : NS_DECL_COMPOSER_COMMAND(nsIncreaseZIndexCommand)
260 :
261 : // Generic commands
262 :
263 : // File menu
264 : NS_DECL_COMPOSER_COMMAND(nsNewCommands) // handles 'new' anything
265 :
266 : // Edit menu
267 0 : NS_DECL_COMPOSER_COMMAND(nsPasteNoFormattingCommand)
268 :
269 : // Block transformations
270 0 : NS_DECL_COMPOSER_COMMAND(nsIndentCommand)
271 0 : NS_DECL_COMPOSER_COMMAND(nsOutdentCommand)
272 :
273 0 : NS_DECL_COMPOSER_COMMAND(nsRemoveListCommand)
274 0 : NS_DECL_COMPOSER_COMMAND(nsRemoveStylesCommand)
275 0 : NS_DECL_COMPOSER_COMMAND(nsIncreaseFontSizeCommand)
276 0 : NS_DECL_COMPOSER_COMMAND(nsDecreaseFontSizeCommand)
277 :
278 : // Insert content commands
279 0 : NS_DECL_COMPOSER_COMMAND(nsInsertHTMLCommand)
280 :
281 : #endif // nsComposerCommands_h_
|