]> git.saurik.com Git - wxWidgets.git/blame - interface/wx/cmdproc.h
Convert wxFSW_EVENT_{WARNING,ERROR} to string correctly.
[wxWidgets.git] / interface / wx / cmdproc.h
CommitLineData
23324ae1
FM
1/////////////////////////////////////////////////////////////////////////////
2// Name: cmdproc.h
d18d9f60 3// Purpose: interface of wxCommandProcessor and wxCommand
23324ae1
FM
4// Author: wxWidgets team
5// RCS-ID: $Id$
526954c5 6// Licence: wxWindows licence
23324ae1
FM
7/////////////////////////////////////////////////////////////////////////////
8
9/**
10 @class wxCommand
7c913512 11
d18d9f60
BP
12 wxCommand is a base class for modelling an application command, which is an
13 action usually performed by selecting a menu item, pressing a toolbar
14 button or any other means provided by the application to change the data or
15 view.
7c913512 16
23324ae1 17 @library{wxcore}
d18d9f60 18 @category{docview}
7c913512 19
d18d9f60 20 @see @ref overview_docview_wxcommand
23324ae1
FM
21*/
22class wxCommand : public wxObject
23{
24public:
25 /**
26 Constructor. wxCommand is an abstract class, so you will need to derive
27 a new class and call this constructor from your own constructor.
d18d9f60
BP
28
29 @param canUndo
30 Tells the command processor whether this command is undo-able. You
31 can achieve the same functionality by overriding the CanUndo()
32 member function (if for example the criteria for undoability is
33 context-dependent).
34 @param name
35 Must be supplied for the command processor to display the command
36 name in the application's edit menu.
23324ae1 37 */
4707b84c 38 wxCommand(bool canUndo = false, const wxString& name = wxEmptyString);
23324ae1
FM
39
40 /**
41 Destructor.
42 */
b7e94bd7 43 virtual ~wxCommand();
23324ae1
FM
44
45 /**
46 Returns @true if the command can be undone, @false otherwise.
47 */
b7e94bd7 48 virtual bool CanUndo() const;
23324ae1
FM
49
50 /**
d18d9f60
BP
51 Override this member function to execute the appropriate action when
52 called.
53
d29a9a8a
BP
54 @return @true to indicate that the action has taken place, @false
55 otherwise. Returning @false will indicate to the command
56 processor that the action is not undoable and should not be
57 added to the command history.
23324ae1 58 */
b91c4601 59 virtual bool Do() = 0;
23324ae1
FM
60
61 /**
62 Returns the command name.
63 */
b7e94bd7 64 virtual wxString GetName() const;
23324ae1
FM
65
66 /**
67 Override this member function to un-execute a previous Do.
d18d9f60
BP
68
69 How you implement this command is totally application dependent, but
70 typical strategies include:
4707b84c 71
d18d9f60
BP
72 - Perform an inverse operation on the last modified piece of data in
73 the document. When redone, a copy of data stored in command is pasted
74 back or some operation reapplied. This relies on the fact that you
75 know the ordering of Undos; the user can never Undo at an arbitrary
76 position in the command history.
77 - Restore the entire document state (perhaps using document
d13b34d3 78 transacting). Potentially very inefficient, but possibly easier to
d18d9f60
BP
79 code if the user interface and data are complex, and an "inverse
80 execute" operation is hard to write. The docview sample uses the
81 first method, to remove or restore segments in the drawing.
82
d29a9a8a
BP
83 @return @true to indicate that the action has taken place, @false
84 otherwise. Returning @false will indicate to the command
85 processor that the action is not redoable and no change should
86 be made to the command history.
23324ae1 87 */
b91c4601 88 virtual bool Undo() = 0;
23324ae1
FM
89};
90
91
e54c96f1 92
23324ae1
FM
93/**
94 @class wxCommandProcessor
7c913512 95
d18d9f60
BP
96 wxCommandProcessor is a class that maintains a history of wxCommands, with
97 undo/redo functionality built-in. Derive a new class from this if you want
98 different behaviour.
7c913512 99
23324ae1 100 @library{wxcore}
d18d9f60 101 @category{docview}
7c913512 102
d18d9f60 103 @see @ref overview_docview_wxcommandproc, wxCommand
23324ae1
FM
104*/
105class wxCommandProcessor : public wxObject
106{
107public:
108 /**
109 Constructor.
d18d9f60
BP
110
111 @param maxCommands
112 May be set to a positive integer to limit the number of commands
113 stored to it, otherwise (and by default) the list of commands can
114 grow arbitrarily.
23324ae1
FM
115 */
116 wxCommandProcessor(int maxCommands = -1);
117
118 /**
119 Destructor.
120 */
b7e94bd7 121 virtual ~wxCommandProcessor();
23324ae1
FM
122
123 /**
d18d9f60
BP
124 Returns @true if the currently-active command can be undone, @false
125 otherwise.
23324ae1 126 */
b7e94bd7 127 virtual bool CanUndo() const;
23324ae1 128
a3d73e4c
VZ
129 /**
130 Returns @true if the currently-active command can be redone, @false
131 otherwise.
132 */
133 virtual bool CanRedo() const;
134
23324ae1 135 /**
d18d9f60
BP
136 Deletes all commands in the list and sets the current command pointer
137 to @NULL.
23324ae1
FM
138 */
139 virtual void ClearCommands();
140
141 /**
142 Returns the list of commands.
143 */
b7e94bd7 144 wxList& GetCommands();
23324ae1 145
a3d73e4c
VZ
146 /**
147 Returns the current command.
148 */
149 wxCommand *GetCurrentCommand() const;
150
23324ae1
FM
151 /**
152 Returns the edit menu associated with the command processor.
153 */
328f5751 154 wxMenu* GetEditMenu() const;
23324ae1
FM
155
156 /**
d18d9f60
BP
157 Returns the maximum number of commands that the command processor
158 stores.
23324ae1 159 */
328f5751 160 int GetMaxCommands() const;
23324ae1
FM
161
162 /**
163 Returns the string that will be appended to the Redo menu item.
164 */
d18d9f60 165 const wxString& GetRedoAccelerator() const;
23324ae1
FM
166
167 /**
168 Returns the string that will be shown for the redo menu item.
169 */
328f5751 170 wxString GetRedoMenuLabel() const;
23324ae1
FM
171
172 /**
173 Returns the string that will be appended to the Undo menu item.
174 */
d18d9f60 175 const wxString& GetUndoAccelerator() const;
23324ae1
FM
176
177 /**
178 Returns the string that will be shown for the undo menu item.
179 */
328f5751 180 wxString GetUndoMenuLabel() const;
23324ae1
FM
181
182 /**
183 Initializes the command processor, setting the current command to the
184 last in the list (if any), and updating the edit menu (if one has been
185 specified).
186 */
187 virtual void Initialize();
188
189 /**
190 Returns a boolean value that indicates if changes have been made since
d18d9f60
BP
191 the last save operation. This only works if MarkAsSaved() is called
192 whenever the project is saved.
23324ae1 193 */
b7e94bd7 194 virtual bool IsDirty() const;
23324ae1
FM
195
196 /**
d18d9f60
BP
197 You must call this method whenever the project is saved if you plan to
198 use IsDirty().
23324ae1 199 */
b7e94bd7 200 void MarkAsSaved();
23324ae1
FM
201
202 /**
d18d9f60
BP
203 Executes (redoes) the current command (the command that has just been
204 undone if any).
23324ae1
FM
205 */
206 virtual bool Redo();
207
208 /**
209 Tells the command processor to update the Undo and Redo items on this
210 menu as appropriate. Set this to @NULL if the menu is about to be
211 destroyed and command operations may still be performed, or the command
212 processor may try to access an invalid pointer.
213 */
214 void SetEditMenu(wxMenu* menu);
215
216 /**
d18d9f60
BP
217 Sets the menu labels according to the currently set menu and the
218 current command state.
23324ae1 219 */
b7e94bd7 220 virtual void SetMenuStrings();
23324ae1
FM
221
222 /**
223 Sets the string that will be appended to the Redo menu item.
224 */
225 void SetRedoAccelerator(const wxString& accel);
226
227 /**
228 Sets the string that will be appended to the Undo menu item.
229 */
230 void SetUndoAccelerator(const wxString& accel);
231
232 /**
76e9224e 233 Submits a new command to the command processor.
d18d9f60 234
76e9224e
FM
235 The command processor calls wxCommand::Do() to execute the command;
236 if it succeeds, the command is stored in the history list, and the
237 associated edit menu (if any) updated appropriately.
238 If it fails, the command is deleted immediately. Once Submit() has been
239 called, the passed command should not be deleted directly by the application.
240
241 @param command
242 The command to submit
d18d9f60
BP
243 @param storeIt
244 Indicates whether the successful command should be stored in the
245 history list.
23324ae1 246 */
4cc4bfaf 247 virtual bool Submit(wxCommand* command, bool storeIt = true);
23324ae1 248
a3d73e4c
VZ
249 /**
250 Just store the command without executing it. The command is stored in the
251 history list, and the associated edit menu (if any) updated appropriately.
252 */
253 virtual void Store(wxCommand *command);
254
23324ae1 255 /**
d18d9f60 256 Undoes the last command executed.
23324ae1
FM
257 */
258 virtual bool Undo();
259};
e54c96f1 260