]> git.saurik.com Git - wxWidgets.git/blob - docs/latex/wx/command.tex
rebaked after animation control and helpbest.h changes
[wxWidgets.git] / docs / latex / wx / command.tex
1 \section{\class{wxCommand}}\label{wxcommand}
2
3 wxCommand is a base class for modelling an application command,
4 which is an action usually performed by selecting a menu item, pressing
5 a toolbar button or any other means provided by the application to
6 change 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
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.
28
29 {\it canUndo} tells the command processor whether this command is undo-able. You
30 can achieve the same functionality by overriding the CanUndo member function (if for example
31 the criteria for undoability is context-dependent).
32
33 {\it name} must be supplied for the command processor to display the command name
34 in the application's edit menu.
35
36 \membersection{wxCommand::\destruct{wxCommand}}\label{wxcommanddtor}
37
38 \func{}{\destruct{wxCommand}}{\void}
39
40 Destructor.
41
42 \membersection{wxCommand::CanUndo}\label{wxcommandcanundo}
43
44 \func{bool}{CanUndo}{\void}
45
46 Returns true if the command can be undone, false otherwise.
47
48 \membersection{wxCommand::Do}\label{wxcommanddo}
49
50 \func{bool}{Do}{\void}
51
52 Override this member function to execute the appropriate action when called.
53 Return true to indicate that the action has taken place, false otherwise.
54 Returning false will indicate to the command processor that the action is
55 not undoable and should not be added to the command history.
56
57 \membersection{wxCommand::GetName}\label{wxcommandgetname}
58
59 \func{wxString}{GetName}{\void}
60
61 Returns the command name.
62
63 \membersection{wxCommand::Undo}\label{wxcommandundo}
64
65 \func{bool}{Undo}{\void}
66
67 Override this member function to un-execute a previous Do.
68 Return true to indicate that the action has taken place, false otherwise.
69 Returning false will indicate to the command processor that the action is
70 not redoable and no change should be made to the command history.
71
72 How you implement this command is totally application dependent, but typical
73 strategies include:
74
75 \begin{itemize}\itemsep=0pt
76 \item Perform an inverse operation on the last modified piece of
77 data in the document. When redone, a copy of data stored in command
78 is pasted back or some operation reapplied. This relies on the fact that
79 you know the ordering of Undos; the user can never Undo at an arbitrary position
80 in the command history.
81 \item Restore the entire document state (perhaps using document transactioning).
82 Potentially very inefficient, but possibly easier to code if the user interface
83 and data are complex, and an `inverse execute' operation is hard to write.
84 \end{itemize}
85
86 The docview sample uses the first method, to remove or restore segments
87 in the drawing.
88
89