1\section{\class{wxCommand}}\label{wxcommand}
2
3wxCommand is a base class for modelling an application command,
4which is an action usually performed by selecting a menu item, pressing
5a toolbar button or any other means provided by the application to
6change the data or view.
7
8\wxheading{Derived from}
9
10\helpref{wxObject}{wxobject}
11
12\wxheading{Include files}
13
14<wx/cmdproc.h>
15
16\wxheading{See also}
17
18\overview{Overview}{wxcommandoverview}
19
20\latexignore{\rtfignore{\wxheading{Members}}}
21
22\membersection{wxCommand::wxCommand}\label{wxcommandctor}
23
24\func{}{wxCommand}{\param{bool}{ canUndo = false}, \param{const wxString\& }{name = NULL}}
25
26Constructor. wxCommand is an abstract class, so you will need to derive
27a new class and call this constructor from your own constructor.
28
29{\it canUndo} tells the command processor whether this command is undo-able. You
30can achieve the same functionality by overriding the CanUndo member function (if for example
31the criteria for undoability is context-dependent).
32
33{\it name} must be supplied for the command processor to display the command name
34in the application's edit menu.
35
36\membersection{wxCommand::\destruct{wxCommand}}\label{wxcommanddtor}
37
38\func{}{\destruct{wxCommand}}{\void}
39
40Destructor.
41
42\membersection{wxCommand::CanUndo}\label{wxcommandcanundo}
43
44\func{bool}{CanUndo}{\void}
45
46Returns true if the command can be undone, false otherwise.
47
48\membersection{wxCommand::Do}\label{wxcommanddo}
49
50\func{bool}{Do}{\void}
51
52Override this member function to execute the appropriate action when called.
53Return true to indicate that the action has taken place, false otherwise.
54Returning false will indicate to the command processor that the action is
55not undoable and should not be added to the command history.
56
57\membersection{wxCommand::GetName}\label{wxcommandgetname}
58
59\func{wxString}{GetName}{\void}
60
61Returns the command name.
62
63\membersection{wxCommand::Undo}\label{wxcommandundo}
64
65\func{bool}{Undo}{\void}
66
67Override this member function to un-execute a previous Do.
68Return true to indicate that the action has taken place, false otherwise.
69Returning false will indicate to the command processor that the action is
70not redoable and no change should be made to the command history.
71
72How you implement this command is totally application dependent, but typical
73strategies include:
74
75\begin{itemize}\itemsep=0pt
76\item Perform an inverse operation on the last modified piece of
77data in the document. When redone, a copy of data stored in command
78is pasted back or some operation reapplied. This relies on the fact that
79you know the ordering of Undos; the user can never Undo at an arbitrary position
80in the command history.
81\item Restore the entire document state (perhaps using document transactioning).
82Potentially very inefficient, but possibly easier to code if the user interface
83and data are complex, and an `inverse execute' operation is hard to write.
84\end{itemize}
85
86The docview sample uses the first method, to remove or restore segments
87in the drawing.
88
89
90