]>
git.saurik.com Git - wxWidgets.git/blob - interface/wx/cmdproc.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxCommandProcessor and wxCommand
4 // Author: wxWidgets team
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
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
20 @see @ref overview_docview_wxcommand
22 class wxCommand
: public wxObject
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.
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
35 Must be supplied for the command processor to display the command
36 name in the application's edit menu.
38 wxCommand(bool canUndo
= false, const wxString
& name
= wxEmptyString
);
46 Returns @true if the command can be undone, @false otherwise.
48 virtual bool CanUndo() const;
51 Override this member function to execute the appropriate action when
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.
59 virtual bool Do() = 0;
62 Returns the command name.
64 virtual wxString
GetName() const;
67 Override this member function to un-execute a previous Do.
69 How you implement this command is totally application dependent, but
70 typical strategies include:
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
78 transacting). Potentially very inefficient, but possibly easier to
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.
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.
88 virtual bool Undo() = 0;
94 @class wxCommandProcessor
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
103 @see @ref overview_docview_wxcommandproc, wxCommand
105 class wxCommandProcessor
: public wxObject
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
116 wxCommandProcessor(int maxCommands
= -1);
121 virtual ~wxCommandProcessor();
124 Returns @true if the currently-active command can be undone, @false
127 virtual bool CanUndo() const;
130 Returns @true if the currently-active command can be redone, @false
133 virtual bool CanRedo() const;
136 Deletes all commands in the list and sets the current command pointer
139 virtual void ClearCommands();
142 Returns the list of commands.
144 wxList
& GetCommands();
147 Returns the current command.
149 wxCommand
*GetCurrentCommand() const;
152 Returns the edit menu associated with the command processor.
154 wxMenu
* GetEditMenu() const;
157 Returns the maximum number of commands that the command processor
160 int GetMaxCommands() const;
163 Returns the string that will be appended to the Redo menu item.
165 const wxString
& GetRedoAccelerator() const;
168 Returns the string that will be shown for the redo menu item.
170 wxString
GetRedoMenuLabel() const;
173 Returns the string that will be appended to the Undo menu item.
175 const wxString
& GetUndoAccelerator() const;
178 Returns the string that will be shown for the undo menu item.
180 wxString
GetUndoMenuLabel() const;
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
187 virtual void Initialize();
190 Returns a boolean value that indicates if changes have been made since
191 the last save operation. This only works if MarkAsSaved() is called
192 whenever the project is saved.
194 virtual bool IsDirty() const;
197 You must call this method whenever the project is saved if you plan to
203 Executes (redoes) the current command (the command that has just been
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.
214 void SetEditMenu(wxMenu
* menu
);
217 Sets the menu labels according to the currently set menu and the
218 current command state.
220 virtual void SetMenuStrings();
223 Sets the string that will be appended to the Redo menu item.
225 void SetRedoAccelerator(const wxString
& accel
);
228 Sets the string that will be appended to the Undo menu item.
230 void SetUndoAccelerator(const wxString
& accel
);
233 Submits a new command to the command processor.
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.
242 The command to submit
244 Indicates whether the successful command should be stored in the
247 virtual bool Submit(wxCommand
* command
, bool storeIt
= true);
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.
253 virtual void Store(wxCommand
*command
);
256 Undoes the last command executed.