]> git.saurik.com Git - wxWidgets.git/blame - interface/wx/cmdproc.h
Fixed bug: wxPropertyGridInterface::SetPropertyReadOnly() with wxPG_DONT_RECURSE...
[wxWidgets.git] / interface / wx / cmdproc.h
CommitLineData
23324ae1
FM
1/////////////////////////////////////////////////////////////////////////////
2// Name: cmdproc.h
d18d9f60 3// Purpose: interface of wxCommandProcessor and wxCommand
23324ae1
FM
4// Author: wxWidgets team
5// RCS-ID: $Id$
6// Licence: wxWindows license
7/////////////////////////////////////////////////////////////////////////////
8
9/**
10 @class wxCommand
7c913512 11
d18d9f60
BP
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
15 view.
7c913512 16
23324ae1 17 @library{wxcore}
d18d9f60 18 @category{docview}
7c913512 19
d18d9f60 20 @see @ref overview_docview_wxcommand
23324ae1
FM
21*/
22class wxCommand : public wxObject
23{
24public:
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.
d18d9f60
BP
28
29 @param canUndo
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
33 context-dependent).
34 @param name
35 Must be supplied for the command processor to display the command
36 name in the application's edit menu.
23324ae1 37 */
4707b84c 38 wxCommand(bool canUndo = false, const wxString& name = wxEmptyString);
23324ae1
FM
39
40 /**
41 Destructor.
42 */
b7e94bd7 43 virtual ~wxCommand();
23324ae1
FM
44
45 /**
46 Returns @true if the command can be undone, @false otherwise.
47 */
b7e94bd7 48 virtual bool CanUndo() const;
23324ae1
FM
49
50 /**
d18d9f60
BP
51 Override this member function to execute the appropriate action when
52 called.
53
d29a9a8a
BP
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.
23324ae1 58 */
b91c4601 59 virtual bool Do() = 0;
23324ae1
FM
60
61 /**
62 Returns the command name.
63 */
b7e94bd7 64 virtual wxString GetName() const;
23324ae1
FM
65
66 /**
67 Override this member function to un-execute a previous Do.
d18d9f60
BP
68
69 How you implement this command is totally application dependent, but
70 typical strategies include:
4707b84c 71
d18d9f60
BP
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 transactioning). 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.
82
d29a9a8a
BP
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.
23324ae1 87 */
b91c4601 88 virtual bool Undo() = 0;
23324ae1
FM
89};
90
91
e54c96f1 92
23324ae1
FM
93/**
94 @class wxCommandProcessor
7c913512 95
d18d9f60
BP
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
98 different behaviour.
7c913512 99
23324ae1 100 @library{wxcore}
d18d9f60 101 @category{docview}
7c913512 102
d18d9f60 103 @see @ref overview_docview_wxcommandproc, wxCommand
23324ae1
FM
104*/
105class wxCommandProcessor : public wxObject
106{
107public:
108 /**
109 Constructor.
d18d9f60
BP
110
111 @param maxCommands
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
114 grow arbitrarily.
23324ae1
FM
115 */
116 wxCommandProcessor(int maxCommands = -1);
117
118 /**
119 Destructor.
120 */
b7e94bd7 121 virtual ~wxCommandProcessor();
23324ae1
FM
122
123 /**
d18d9f60
BP
124 Returns @true if the currently-active command can be undone, @false
125 otherwise.
23324ae1 126 */
b7e94bd7 127 virtual bool CanUndo() const;
23324ae1
FM
128
129 /**
d18d9f60
BP
130 Deletes all commands in the list and sets the current command pointer
131 to @NULL.
23324ae1
FM
132 */
133 virtual void ClearCommands();
134
135 /**
136 Returns the list of commands.
137 */
b7e94bd7 138 wxList& GetCommands();
23324ae1
FM
139
140 /**
141 Returns the edit menu associated with the command processor.
142 */
328f5751 143 wxMenu* GetEditMenu() const;
23324ae1
FM
144
145 /**
d18d9f60
BP
146 Returns the maximum number of commands that the command processor
147 stores.
23324ae1 148 */
328f5751 149 int GetMaxCommands() const;
23324ae1
FM
150
151 /**
152 Returns the string that will be appended to the Redo menu item.
153 */
d18d9f60 154 const wxString& GetRedoAccelerator() const;
23324ae1
FM
155
156 /**
157 Returns the string that will be shown for the redo menu item.
158 */
328f5751 159 wxString GetRedoMenuLabel() const;
23324ae1
FM
160
161 /**
162 Returns the string that will be appended to the Undo menu item.
163 */
d18d9f60 164 const wxString& GetUndoAccelerator() const;
23324ae1
FM
165
166 /**
167 Returns the string that will be shown for the undo menu item.
168 */
328f5751 169 wxString GetUndoMenuLabel() const;
23324ae1
FM
170
171 /**
172 Initializes the command processor, setting the current command to the
173 last in the list (if any), and updating the edit menu (if one has been
174 specified).
175 */
176 virtual void Initialize();
177
178 /**
179 Returns a boolean value that indicates if changes have been made since
d18d9f60
BP
180 the last save operation. This only works if MarkAsSaved() is called
181 whenever the project is saved.
23324ae1 182 */
b7e94bd7 183 virtual bool IsDirty() const;
23324ae1
FM
184
185 /**
d18d9f60
BP
186 You must call this method whenever the project is saved if you plan to
187 use IsDirty().
23324ae1 188 */
b7e94bd7 189 void MarkAsSaved();
23324ae1
FM
190
191 /**
d18d9f60
BP
192 Executes (redoes) the current command (the command that has just been
193 undone if any).
23324ae1
FM
194 */
195 virtual bool Redo();
196
197 /**
198 Tells the command processor to update the Undo and Redo items on this
199 menu as appropriate. Set this to @NULL if the menu is about to be
200 destroyed and command operations may still be performed, or the command
201 processor may try to access an invalid pointer.
202 */
203 void SetEditMenu(wxMenu* menu);
204
205 /**
d18d9f60
BP
206 Sets the menu labels according to the currently set menu and the
207 current command state.
23324ae1 208 */
b7e94bd7 209 virtual void SetMenuStrings();
23324ae1
FM
210
211 /**
212 Sets the string that will be appended to the Redo menu item.
213 */
214 void SetRedoAccelerator(const wxString& accel);
215
216 /**
217 Sets the string that will be appended to the Undo menu item.
218 */
219 void SetUndoAccelerator(const wxString& accel);
220
221 /**
76e9224e 222 Submits a new command to the command processor.
d18d9f60 223
76e9224e
FM
224 The command processor calls wxCommand::Do() to execute the command;
225 if it succeeds, the command is stored in the history list, and the
226 associated edit menu (if any) updated appropriately.
227 If it fails, the command is deleted immediately. Once Submit() has been
228 called, the passed command should not be deleted directly by the application.
229
230 @param command
231 The command to submit
d18d9f60
BP
232 @param storeIt
233 Indicates whether the successful command should be stored in the
234 history list.
23324ae1 235 */
4cc4bfaf 236 virtual bool Submit(wxCommand* command, bool storeIt = true);
23324ae1
FM
237
238 /**
d18d9f60 239 Undoes the last command executed.
23324ae1
FM
240 */
241 virtual bool Undo();
242};
e54c96f1 243