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