]>
Commit | Line | Data |
---|---|---|
1e6feb95 VZ |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Name: wx/cmdproc.h | |
3 | // Purpose: undo/redo capable command processing framework | |
4 | // Author: Julian Smart (extracted from docview.h by VZ) | |
5 | // Modified by: | |
6 | // Created: 05.11.00 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) wxWindows team | |
9 | // Licence: wxWindows licence | |
10 | /////////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifndef _WX_CMDPROC_H_ | |
13 | #define _WX_CMDPROC_H_ | |
14 | ||
af49c4b8 | 15 | #if defined(__GNUG__) && !defined(__APPLE__) |
1e6feb95 VZ |
16 | #pragma interface "cmdproc.h" |
17 | #endif | |
18 | ||
19 | #include "wx/object.h" | |
20 | #include "wx/list.h" | |
21 | ||
bad93b35 VZ |
22 | class WXDLLEXPORT wxMenu; |
23 | ||
1e6feb95 VZ |
24 | // ---------------------------------------------------------------------------- |
25 | // wxCommand: a single command capable of performing itself | |
26 | // ---------------------------------------------------------------------------- | |
27 | ||
28 | class WXDLLEXPORT wxCommand : public wxObject | |
29 | { | |
30 | public: | |
fda7962d | 31 | wxCommand(bool canUndoIt = FALSE, const wxString& name = wxEmptyString); |
1e6feb95 VZ |
32 | ~wxCommand(); |
33 | ||
34 | // Override this to perform a command | |
35 | virtual bool Do() = 0; | |
36 | ||
37 | // Override this to undo a command | |
38 | virtual bool Undo() = 0; | |
39 | ||
40 | virtual bool CanUndo() const { return m_canUndo; } | |
41 | virtual wxString GetName() const { return m_commandName; } | |
42 | ||
43 | protected: | |
44 | bool m_canUndo; | |
45 | wxString m_commandName; | |
46 | ||
47 | private: | |
48 | DECLARE_CLASS(wxCommand) | |
49 | }; | |
50 | ||
51 | // ---------------------------------------------------------------------------- | |
52 | // wxCommandProcessor: wxCommand manager | |
53 | // ---------------------------------------------------------------------------- | |
54 | ||
55 | class WXDLLEXPORT wxCommandProcessor : public wxObject | |
56 | { | |
57 | public: | |
58 | // if max number of commands is -1, it is unlimited | |
59 | wxCommandProcessor(int maxCommands = -1); | |
60 | virtual ~wxCommandProcessor(); | |
61 | ||
62 | // Pass a command to the processor. The processor calls Do(); if | |
63 | // successful, is appended to the command history unless storeIt is FALSE. | |
64 | virtual bool Submit(wxCommand *command, bool storeIt = TRUE); | |
65 | ||
66 | // just store the command without executing it | |
67 | virtual void Store(wxCommand *command); | |
68 | ||
69 | virtual bool Undo(); | |
70 | virtual bool Redo(); | |
71 | virtual bool CanUndo() const; | |
72 | virtual bool CanRedo() const; | |
73 | ||
d863ed83 | 74 | // Initialises the current command and menu strings. |
1e6feb95 | 75 | virtual void Initialize(); |
d863ed83 JS |
76 | |
77 | // Sets the Undo/Redo menu strings for the current menu. | |
1e6feb95 VZ |
78 | virtual void SetMenuStrings(); |
79 | ||
d863ed83 JS |
80 | // Gets the current Undo menu label. |
81 | wxString GetUndoMenuLabel() const; | |
82 | ||
83 | // Gets the current Undo menu label. | |
84 | wxString GetRedoMenuLabel() const; | |
85 | ||
1e6feb95 VZ |
86 | #if wxUSE_MENUS |
87 | // Call this to manage an edit menu. | |
88 | void SetEditMenu(wxMenu *menu) { m_commandEditMenu = menu; } | |
89 | wxMenu *GetEditMenu() const { return m_commandEditMenu; } | |
90 | #endif // wxUSE_MENUS | |
91 | ||
92 | // command list access | |
93 | wxList& GetCommands() const { return (wxList&) m_commands; } | |
94 | wxCommand *GetCurrentCommand() const | |
95 | { | |
b1d4dd7a | 96 | return (wxCommand *)(m_currentCommand ? m_currentCommand->GetData() : NULL); |
1e6feb95 VZ |
97 | } |
98 | int GetMaxCommands() const { return m_maxNoCommands; } | |
99 | virtual void ClearCommands(); | |
100 | ||
6aa3ea88 JS |
101 | // By default, the accelerators are "\tCtrl+Z" and "\tCtrl+Y" |
102 | const wxString& GetUndoAccelerator() const { return m_undoAccelerator; } | |
103 | const wxString& GetRedoAccelerator() const { return m_redoAccelerator; } | |
104 | ||
105 | void SetUndoAccelerator(const wxString& accel) { m_undoAccelerator = accel; } | |
106 | void SetRedoAccelerator(const wxString& accel) { m_redoAccelerator = accel; } | |
107 | ||
1e6feb95 VZ |
108 | protected: |
109 | // for further flexibility, command processor doesn't call wxCommand::Do() | |
110 | // and Undo() directly but uses these functions which can be overridden in | |
111 | // the derived class | |
112 | virtual bool DoCommand(wxCommand& cmd); | |
113 | virtual bool UndoCommand(wxCommand& cmd); | |
114 | ||
115 | int m_maxNoCommands; | |
116 | wxList m_commands; | |
222ed1d6 | 117 | wxList::compatibility_iterator m_currentCommand; |
1e6feb95 VZ |
118 | |
119 | #if wxUSE_MENUS | |
120 | wxMenu* m_commandEditMenu; | |
121 | #endif // wxUSE_MENUS | |
122 | ||
6aa3ea88 JS |
123 | wxString m_undoAccelerator; |
124 | wxString m_redoAccelerator; | |
125 | ||
1e6feb95 VZ |
126 | private: |
127 | DECLARE_DYNAMIC_CLASS(wxCommandProcessor) | |
22f3361e | 128 | DECLARE_NO_COPY_CLASS(wxCommandProcessor) |
1e6feb95 VZ |
129 | }; |
130 | ||
131 | #endif // _WX_CMDPROC_H_ |