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