2008-03-08 13:52:38 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: cmdproc.h
|
2008-04-08 05:34:11 +00:00
|
|
|
// Purpose: interface of wxCommandProcessor and wxCommand
|
2008-03-08 13:52:38 +00:00
|
|
|
// Author: wxWidgets team
|
|
|
|
// RCS-ID: $Id$
|
2010-07-13 13:29:13 +00:00
|
|
|
// Licence: wxWindows licence
|
2008-03-08 13:52:38 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/**
|
|
|
|
@class wxCommand
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-04-08 05:34:11 +00:00
|
|
|
wxCommand is a base class for modelling an application command, which is an
|
|
|
|
action usually performed by selecting a menu item, pressing a toolbar
|
|
|
|
button or any other means provided by the application to change the data or
|
|
|
|
view.
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
@library{wxcore}
|
2008-04-08 05:34:11 +00:00
|
|
|
@category{docview}
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-04-08 05:34:11 +00:00
|
|
|
@see @ref overview_docview_wxcommand
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
|
|
|
class wxCommand : public wxObject
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
Constructor. wxCommand is an abstract class, so you will need to derive
|
|
|
|
a new class and call this constructor from your own constructor.
|
2008-04-08 05:34:11 +00:00
|
|
|
|
|
|
|
@param canUndo
|
|
|
|
Tells the command processor whether this command is undo-able. You
|
|
|
|
can achieve the same functionality by overriding the CanUndo()
|
|
|
|
member function (if for example the criteria for undoability is
|
|
|
|
context-dependent).
|
|
|
|
@param name
|
|
|
|
Must be supplied for the command processor to display the command
|
|
|
|
name in the application's edit menu.
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-09-24 23:29:43 +00:00
|
|
|
wxCommand(bool canUndo = false, const wxString& name = wxEmptyString);
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Destructor.
|
|
|
|
*/
|
2008-09-22 19:01:17 +00:00
|
|
|
virtual ~wxCommand();
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns @true if the command can be undone, @false otherwise.
|
|
|
|
*/
|
2008-09-22 19:01:17 +00:00
|
|
|
virtual bool CanUndo() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
2008-04-08 05:34:11 +00:00
|
|
|
Override this member function to execute the appropriate action when
|
|
|
|
called.
|
|
|
|
|
2008-05-11 01:38:53 +00:00
|
|
|
@return @true to indicate that the action has taken place, @false
|
|
|
|
otherwise. Returning @false will indicate to the command
|
|
|
|
processor that the action is not undoable and should not be
|
|
|
|
added to the command history.
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-09-29 10:52:37 +00:00
|
|
|
virtual bool Do() = 0;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the command name.
|
|
|
|
*/
|
2008-09-22 19:01:17 +00:00
|
|
|
virtual wxString GetName() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Override this member function to un-execute a previous Do.
|
2008-04-08 05:34:11 +00:00
|
|
|
|
|
|
|
How you implement this command is totally application dependent, but
|
|
|
|
typical strategies include:
|
2008-09-24 23:29:43 +00:00
|
|
|
|
2008-04-08 05:34:11 +00:00
|
|
|
- Perform an inverse operation on the last modified piece of data in
|
|
|
|
the document. When redone, a copy of data stored in command is pasted
|
|
|
|
back or some operation reapplied. This relies on the fact that you
|
|
|
|
know the ordering of Undos; the user can never Undo at an arbitrary
|
|
|
|
position in the command history.
|
|
|
|
- Restore the entire document state (perhaps using document
|
|
|
|
transactioning). Potentially very inefficient, but possibly easier to
|
|
|
|
code if the user interface and data are complex, and an "inverse
|
|
|
|
execute" operation is hard to write. The docview sample uses the
|
|
|
|
first method, to remove or restore segments in the drawing.
|
|
|
|
|
2008-05-11 01:38:53 +00:00
|
|
|
@return @true to indicate that the action has taken place, @false
|
|
|
|
otherwise. Returning @false will indicate to the command
|
|
|
|
processor that the action is not redoable and no change should
|
|
|
|
be made to the command history.
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-09-29 10:52:37 +00:00
|
|
|
virtual bool Undo() = 0;
|
2008-03-08 13:52:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-03-10 15:24:38 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
/**
|
|
|
|
@class wxCommandProcessor
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-04-08 05:34:11 +00:00
|
|
|
wxCommandProcessor is a class that maintains a history of wxCommands, with
|
|
|
|
undo/redo functionality built-in. Derive a new class from this if you want
|
|
|
|
different behaviour.
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
@library{wxcore}
|
2008-04-08 05:34:11 +00:00
|
|
|
@category{docview}
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-04-08 05:34:11 +00:00
|
|
|
@see @ref overview_docview_wxcommandproc, wxCommand
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
|
|
|
class wxCommandProcessor : public wxObject
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
Constructor.
|
2008-04-08 05:34:11 +00:00
|
|
|
|
|
|
|
@param maxCommands
|
|
|
|
May be set to a positive integer to limit the number of commands
|
|
|
|
stored to it, otherwise (and by default) the list of commands can
|
|
|
|
grow arbitrarily.
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
|
|
|
wxCommandProcessor(int maxCommands = -1);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Destructor.
|
|
|
|
*/
|
2008-09-22 19:01:17 +00:00
|
|
|
virtual ~wxCommandProcessor();
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
2008-04-08 05:34:11 +00:00
|
|
|
Returns @true if the currently-active command can be undone, @false
|
|
|
|
otherwise.
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-09-22 19:01:17 +00:00
|
|
|
virtual bool CanUndo() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
2008-04-08 05:34:11 +00:00
|
|
|
Deletes all commands in the list and sets the current command pointer
|
|
|
|
to @NULL.
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
|
|
|
virtual void ClearCommands();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the list of commands.
|
|
|
|
*/
|
2008-09-22 19:01:17 +00:00
|
|
|
wxList& GetCommands();
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the edit menu associated with the command processor.
|
|
|
|
*/
|
2008-03-09 16:24:26 +00:00
|
|
|
wxMenu* GetEditMenu() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
2008-04-08 05:34:11 +00:00
|
|
|
Returns the maximum number of commands that the command processor
|
|
|
|
stores.
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-03-09 16:24:26 +00:00
|
|
|
int GetMaxCommands() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the string that will be appended to the Redo menu item.
|
|
|
|
*/
|
2008-04-08 05:34:11 +00:00
|
|
|
const wxString& GetRedoAccelerator() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the string that will be shown for the redo menu item.
|
|
|
|
*/
|
2008-03-09 16:24:26 +00:00
|
|
|
wxString GetRedoMenuLabel() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the string that will be appended to the Undo menu item.
|
|
|
|
*/
|
2008-04-08 05:34:11 +00:00
|
|
|
const wxString& GetUndoAccelerator() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the string that will be shown for the undo menu item.
|
|
|
|
*/
|
2008-03-09 16:24:26 +00:00
|
|
|
wxString GetUndoMenuLabel() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Initializes the command processor, setting the current command to the
|
|
|
|
last in the list (if any), and updating the edit menu (if one has been
|
|
|
|
specified).
|
|
|
|
*/
|
|
|
|
virtual void Initialize();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns a boolean value that indicates if changes have been made since
|
2008-04-08 05:34:11 +00:00
|
|
|
the last save operation. This only works if MarkAsSaved() is called
|
|
|
|
whenever the project is saved.
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-09-22 19:01:17 +00:00
|
|
|
virtual bool IsDirty() const;
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
2008-04-08 05:34:11 +00:00
|
|
|
You must call this method whenever the project is saved if you plan to
|
|
|
|
use IsDirty().
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-09-22 19:01:17 +00:00
|
|
|
void MarkAsSaved();
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
2008-04-08 05:34:11 +00:00
|
|
|
Executes (redoes) the current command (the command that has just been
|
|
|
|
undone if any).
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
|
|
|
virtual bool Redo();
|
|
|
|
|
|
|
|
/**
|
|
|
|
Tells the command processor to update the Undo and Redo items on this
|
|
|
|
menu as appropriate. Set this to @NULL if the menu is about to be
|
|
|
|
destroyed and command operations may still be performed, or the command
|
|
|
|
processor may try to access an invalid pointer.
|
|
|
|
*/
|
|
|
|
void SetEditMenu(wxMenu* menu);
|
|
|
|
|
|
|
|
/**
|
2008-04-08 05:34:11 +00:00
|
|
|
Sets the menu labels according to the currently set menu and the
|
|
|
|
current command state.
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-09-22 19:01:17 +00:00
|
|
|
virtual void SetMenuStrings();
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Sets the string that will be appended to the Redo menu item.
|
|
|
|
*/
|
|
|
|
void SetRedoAccelerator(const wxString& accel);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Sets the string that will be appended to the Undo menu item.
|
|
|
|
*/
|
|
|
|
void SetUndoAccelerator(const wxString& accel);
|
|
|
|
|
|
|
|
/**
|
2008-10-04 20:49:51 +00:00
|
|
|
Submits a new command to the command processor.
|
2008-04-08 05:34:11 +00:00
|
|
|
|
2008-10-04 20:49:51 +00:00
|
|
|
The command processor calls wxCommand::Do() to execute the command;
|
|
|
|
if it succeeds, the command is stored in the history list, and the
|
|
|
|
associated edit menu (if any) updated appropriately.
|
|
|
|
If it fails, the command is deleted immediately. Once Submit() has been
|
|
|
|
called, the passed command should not be deleted directly by the application.
|
|
|
|
|
|
|
|
@param command
|
|
|
|
The command to submit
|
2008-04-08 05:34:11 +00:00
|
|
|
@param storeIt
|
|
|
|
Indicates whether the successful command should be stored in the
|
|
|
|
history list.
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-03-09 12:33:59 +00:00
|
|
|
virtual bool Submit(wxCommand* command, bool storeIt = true);
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
2008-04-08 05:34:11 +00:00
|
|
|
Undoes the last command executed.
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
|
|
|
virtual bool Undo();
|
|
|
|
};
|
2008-03-10 15:24:38 +00:00
|
|
|
|