|
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 public: |
|
31 |
|
32 nsBaseComposerCommand(); |
|
33 virtual ~nsBaseComposerCommand() {} |
|
34 |
|
35 // nsISupports |
|
36 NS_DECL_ISUPPORTS |
|
37 |
|
38 // nsIControllerCommand. Declared longhand so we can make them pure virtual |
|
39 NS_IMETHOD IsCommandEnabled(const char * aCommandName, nsISupports *aCommandRefCon, bool *_retval) = 0; |
|
40 NS_IMETHOD DoCommand(const char * aCommandName, nsISupports *aCommandRefCon) = 0; |
|
41 |
|
42 }; |
|
43 |
|
44 |
|
45 #define NS_DECL_COMPOSER_COMMAND(_cmd) \ |
|
46 class _cmd : public nsBaseComposerCommand \ |
|
47 { \ |
|
48 public: \ |
|
49 NS_DECL_NSICONTROLLERCOMMAND \ |
|
50 }; |
|
51 |
|
52 // virtual base class for commands that need to save and update Boolean state (like styles etc) |
|
53 class nsBaseStateUpdatingCommand : public nsBaseComposerCommand |
|
54 { |
|
55 public: |
|
56 nsBaseStateUpdatingCommand(nsIAtom* aTagName); |
|
57 virtual ~nsBaseStateUpdatingCommand(); |
|
58 |
|
59 NS_DECL_ISUPPORTS_INHERITED |
|
60 |
|
61 NS_DECL_NSICONTROLLERCOMMAND |
|
62 |
|
63 protected: |
|
64 |
|
65 // get the current state (on or off) for this style or block format |
|
66 virtual nsresult GetCurrentState(nsIEditor* aEditor, nsICommandParams* aParams) = 0; |
|
67 |
|
68 // add/remove the style |
|
69 virtual nsresult ToggleState(nsIEditor* aEditor) = 0; |
|
70 |
|
71 protected: |
|
72 nsIAtom* mTagName; |
|
73 }; |
|
74 |
|
75 |
|
76 // Shared class for the various style updating commands like bold, italics etc. |
|
77 // Suitable for commands whose state is either 'on' or 'off'. |
|
78 class nsStyleUpdatingCommand : public nsBaseStateUpdatingCommand |
|
79 { |
|
80 public: |
|
81 nsStyleUpdatingCommand(nsIAtom* aTagName); |
|
82 |
|
83 protected: |
|
84 |
|
85 // get the current state (on or off) for this style or block format |
|
86 virtual nsresult GetCurrentState(nsIEditor* aEditor, nsICommandParams* aParams); |
|
87 |
|
88 // add/remove the style |
|
89 virtual nsresult ToggleState(nsIEditor* aEditor); |
|
90 }; |
|
91 |
|
92 |
|
93 class nsInsertTagCommand : public nsBaseComposerCommand |
|
94 { |
|
95 public: |
|
96 explicit nsInsertTagCommand(nsIAtom* aTagName); |
|
97 virtual ~nsInsertTagCommand(); |
|
98 |
|
99 NS_DECL_ISUPPORTS_INHERITED |
|
100 |
|
101 NS_DECL_NSICONTROLLERCOMMAND |
|
102 |
|
103 protected: |
|
104 |
|
105 nsIAtom* mTagName; |
|
106 }; |
|
107 |
|
108 |
|
109 class nsListCommand : public nsBaseStateUpdatingCommand |
|
110 { |
|
111 public: |
|
112 nsListCommand(nsIAtom* aTagName); |
|
113 |
|
114 protected: |
|
115 |
|
116 // get the current state (on or off) for this style or block format |
|
117 virtual nsresult GetCurrentState(nsIEditor* aEditor, nsICommandParams* aParams); |
|
118 |
|
119 // add/remove the style |
|
120 virtual nsresult ToggleState(nsIEditor* aEditor); |
|
121 }; |
|
122 |
|
123 class nsListItemCommand : public nsBaseStateUpdatingCommand |
|
124 { |
|
125 public: |
|
126 nsListItemCommand(nsIAtom* aTagName); |
|
127 |
|
128 protected: |
|
129 |
|
130 // get the current state (on or off) for this style or block format |
|
131 virtual nsresult GetCurrentState(nsIEditor* aEditor, nsICommandParams* aParams); |
|
132 |
|
133 // add/remove the style |
|
134 virtual nsresult ToggleState(nsIEditor* aEditor); |
|
135 }; |
|
136 |
|
137 // Base class for commands whose state consists of a string (e.g. para format) |
|
138 class nsMultiStateCommand : public nsBaseComposerCommand |
|
139 { |
|
140 public: |
|
141 |
|
142 nsMultiStateCommand(); |
|
143 virtual ~nsMultiStateCommand(); |
|
144 |
|
145 NS_DECL_ISUPPORTS_INHERITED |
|
146 NS_DECL_NSICONTROLLERCOMMAND |
|
147 |
|
148 protected: |
|
149 |
|
150 virtual nsresult GetCurrentState(nsIEditor *aEditor, nsICommandParams* aParams) =0; |
|
151 virtual nsresult SetState(nsIEditor *aEditor, nsString& newState) = 0; |
|
152 |
|
153 }; |
|
154 |
|
155 |
|
156 class nsParagraphStateCommand : public nsMultiStateCommand |
|
157 { |
|
158 public: |
|
159 nsParagraphStateCommand(); |
|
160 |
|
161 protected: |
|
162 |
|
163 virtual nsresult GetCurrentState(nsIEditor *aEditor, nsICommandParams* aParams); |
|
164 virtual nsresult SetState(nsIEditor *aEditor, nsString& newState); |
|
165 }; |
|
166 |
|
167 class nsFontFaceStateCommand : public nsMultiStateCommand |
|
168 { |
|
169 public: |
|
170 nsFontFaceStateCommand(); |
|
171 |
|
172 protected: |
|
173 |
|
174 virtual nsresult GetCurrentState(nsIEditor *aEditor, nsICommandParams* aParams); |
|
175 virtual nsresult SetState(nsIEditor *aEditor, nsString& newState); |
|
176 }; |
|
177 |
|
178 class nsFontSizeStateCommand : public nsMultiStateCommand |
|
179 { |
|
180 public: |
|
181 nsFontSizeStateCommand(); |
|
182 |
|
183 protected: |
|
184 |
|
185 virtual nsresult GetCurrentState(nsIEditor *aEditor, |
|
186 nsICommandParams* aParams); |
|
187 virtual nsresult SetState(nsIEditor *aEditor, nsString& newState); |
|
188 }; |
|
189 |
|
190 class nsHighlightColorStateCommand : public nsMultiStateCommand |
|
191 { |
|
192 public: |
|
193 nsHighlightColorStateCommand(); |
|
194 |
|
195 protected: |
|
196 |
|
197 NS_IMETHOD IsCommandEnabled(const char *aCommandName, nsISupports *aCommandRefCon, bool *_retval); |
|
198 virtual nsresult GetCurrentState(nsIEditor *aEditor, nsICommandParams* aParams); |
|
199 virtual nsresult SetState(nsIEditor *aEditor, nsString& newState); |
|
200 |
|
201 }; |
|
202 |
|
203 class nsFontColorStateCommand : public nsMultiStateCommand |
|
204 { |
|
205 public: |
|
206 nsFontColorStateCommand(); |
|
207 |
|
208 protected: |
|
209 |
|
210 virtual nsresult GetCurrentState(nsIEditor *aEditor, nsICommandParams* aParams); |
|
211 virtual nsresult SetState(nsIEditor *aEditor, nsString& newState); |
|
212 }; |
|
213 |
|
214 class nsAlignCommand : public nsMultiStateCommand |
|
215 { |
|
216 public: |
|
217 nsAlignCommand(); |
|
218 |
|
219 protected: |
|
220 |
|
221 virtual nsresult GetCurrentState(nsIEditor *aEditor, nsICommandParams* aParams); |
|
222 virtual nsresult SetState(nsIEditor *aEditor, nsString& newState); |
|
223 }; |
|
224 |
|
225 class nsBackgroundColorStateCommand : public nsMultiStateCommand |
|
226 { |
|
227 public: |
|
228 nsBackgroundColorStateCommand(); |
|
229 |
|
230 protected: |
|
231 |
|
232 virtual nsresult GetCurrentState(nsIEditor *aEditor, nsICommandParams* aParams); |
|
233 virtual nsresult SetState(nsIEditor *aEditor, nsString& newState); |
|
234 }; |
|
235 |
|
236 class nsAbsolutePositioningCommand : public nsBaseStateUpdatingCommand |
|
237 { |
|
238 public: |
|
239 nsAbsolutePositioningCommand(); |
|
240 |
|
241 protected: |
|
242 |
|
243 NS_IMETHOD IsCommandEnabled(const char *aCommandName, nsISupports *aCommandRefCon, bool *_retval); |
|
244 virtual nsresult GetCurrentState(nsIEditor* aEditor, nsICommandParams* aParams); |
|
245 virtual nsresult ToggleState(nsIEditor* aEditor); |
|
246 }; |
|
247 |
|
248 // composer commands |
|
249 |
|
250 NS_DECL_COMPOSER_COMMAND(nsCloseCommand) |
|
251 NS_DECL_COMPOSER_COMMAND(nsDocumentStateCommand) |
|
252 NS_DECL_COMPOSER_COMMAND(nsSetDocumentStateCommand) |
|
253 NS_DECL_COMPOSER_COMMAND(nsSetDocumentOptionsCommand) |
|
254 //NS_DECL_COMPOSER_COMMAND(nsPrintingCommands) |
|
255 |
|
256 NS_DECL_COMPOSER_COMMAND(nsDecreaseZIndexCommand) |
|
257 NS_DECL_COMPOSER_COMMAND(nsIncreaseZIndexCommand) |
|
258 |
|
259 // Generic commands |
|
260 |
|
261 // File menu |
|
262 NS_DECL_COMPOSER_COMMAND(nsNewCommands) // handles 'new' anything |
|
263 |
|
264 // Edit menu |
|
265 NS_DECL_COMPOSER_COMMAND(nsPasteNoFormattingCommand) |
|
266 |
|
267 // Block transformations |
|
268 NS_DECL_COMPOSER_COMMAND(nsIndentCommand) |
|
269 NS_DECL_COMPOSER_COMMAND(nsOutdentCommand) |
|
270 |
|
271 NS_DECL_COMPOSER_COMMAND(nsRemoveListCommand) |
|
272 NS_DECL_COMPOSER_COMMAND(nsRemoveStylesCommand) |
|
273 NS_DECL_COMPOSER_COMMAND(nsIncreaseFontSizeCommand) |
|
274 NS_DECL_COMPOSER_COMMAND(nsDecreaseFontSizeCommand) |
|
275 |
|
276 // Insert content commands |
|
277 NS_DECL_COMPOSER_COMMAND(nsInsertHTMLCommand) |
|
278 |
|
279 #endif // nsComposerCommands_h_ |