]>
Commit | Line | Data |
---|---|---|
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) wxWidgets team | |
9 | // Licence: wxWindows licence | |
10 | /////////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifndef _WX_CMDPROC_H_ | |
13 | #define _WX_CMDPROC_H_ | |
14 | ||
15 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) | |
16 | #pragma interface "cmdproc.h" | |
17 | #endif | |
18 | ||
19 | #include "wx/defs.h" | |
20 | #include "wx/object.h" | |
21 | #include "wx/list.h" | |
22 | ||
23 | class WXDLLEXPORT wxMenu; | |
24 | ||
25 | // ---------------------------------------------------------------------------- | |
26 | // wxCommand: a single command capable of performing itself | |
27 | // ---------------------------------------------------------------------------- | |
28 | ||
29 | class WXDLLEXPORT wxCommand : public wxObject | |
30 | { | |
31 | public: | |
32 | wxCommand(bool canUndoIt = false, const wxString& name = wxEmptyString); | |
33 | ~wxCommand(){} | |
34 | ||
35 | // Override this to perform a command | |
36 | virtual bool Do() = 0; | |
37 | ||
38 | // Override this to undo a command | |
39 | virtual bool Undo() = 0; | |
40 | ||
41 | virtual bool CanUndo() const { return m_canUndo; } | |
42 | virtual wxString GetName() const { return m_commandName; } | |
43 | ||
44 | protected: | |
45 | bool m_canUndo; | |
46 | wxString m_commandName; | |
47 | ||
48 | private: | |
49 | DECLARE_CLASS(wxCommand) | |
50 | }; | |
51 | ||
52 | // ---------------------------------------------------------------------------- | |
53 | // wxCommandProcessor: wxCommand manager | |
54 | // ---------------------------------------------------------------------------- | |
55 | ||
56 | class WXDLLEXPORT wxCommandProcessor : public wxObject | |
57 | { | |
58 | public: | |
59 | // if max number of commands is -1, it is unlimited | |
60 | wxCommandProcessor(int maxCommands = -1); | |
61 | virtual ~wxCommandProcessor(); | |
62 | ||
63 | // Pass a command to the processor. The processor calls Do(); if | |
64 | // successful, is appended to the command history unless storeIt is false. | |
65 | virtual bool Submit(wxCommand *command, bool storeIt = true); | |
66 | ||
67 | // just store the command without executing it | |
68 | virtual void Store(wxCommand *command); | |
69 | ||
70 | virtual bool Undo(); | |
71 | virtual bool Redo(); | |
72 | virtual bool CanUndo() const; | |
73 | virtual bool CanRedo() const; | |
74 | ||
75 | // Initialises the current command and menu strings. | |
76 | virtual void Initialize(); | |
77 | ||
78 | // Sets the Undo/Redo menu strings for the current menu. | |
79 | virtual void SetMenuStrings(); | |
80 | ||
81 | // Gets the current Undo menu label. | |
82 | wxString GetUndoMenuLabel() const; | |
83 | ||
84 | // Gets the current Undo menu label. | |
85 | wxString GetRedoMenuLabel() const; | |
86 | ||
87 | #if wxUSE_MENUS | |
88 | // Call this to manage an edit menu. | |
89 | void SetEditMenu(wxMenu *menu) { m_commandEditMenu = menu; } | |
90 | wxMenu *GetEditMenu() const { return m_commandEditMenu; } | |
91 | #endif // wxUSE_MENUS | |
92 | ||
93 | // command list access | |
94 | wxList& GetCommands() const { return (wxList&) m_commands; } | |
95 | wxCommand *GetCurrentCommand() const | |
96 | { | |
97 | return (wxCommand *)(m_currentCommand ? m_currentCommand->GetData() : NULL); | |
98 | } | |
99 | int GetMaxCommands() const { return m_maxNoCommands; } | |
100 | virtual void ClearCommands(); | |
101 | ||
102 | // Has the current project been changed? | |
103 | virtual bool IsDirty() const | |
104 | { | |
105 | return m_currentCommand && (m_lastSavedCommand != m_currentCommand); | |
106 | } | |
107 | ||
108 | // Mark the current command as the one where the last save took place | |
109 | void MarkAsSaved() | |
110 | { | |
111 | m_lastSavedCommand = m_currentCommand; | |
112 | } | |
113 | ||
114 | ||
115 | // By default, the accelerators are "\tCtrl+Z" and "\tCtrl+Y" | |
116 | const wxString& GetUndoAccelerator() const { return m_undoAccelerator; } | |
117 | const wxString& GetRedoAccelerator() const { return m_redoAccelerator; } | |
118 | ||
119 | void SetUndoAccelerator(const wxString& accel) { m_undoAccelerator = accel; } | |
120 | void SetRedoAccelerator(const wxString& accel) { m_redoAccelerator = accel; } | |
121 | ||
122 | protected: | |
123 | // for further flexibility, command processor doesn't call wxCommand::Do() | |
124 | // and Undo() directly but uses these functions which can be overridden in | |
125 | // the derived class | |
126 | virtual bool DoCommand(wxCommand& cmd); | |
127 | virtual bool UndoCommand(wxCommand& cmd); | |
128 | ||
129 | int m_maxNoCommands; | |
130 | wxList m_commands; | |
131 | wxList::compatibility_iterator m_currentCommand, | |
132 | m_lastSavedCommand; | |
133 | ||
134 | #if wxUSE_MENUS | |
135 | wxMenu* m_commandEditMenu; | |
136 | #endif // wxUSE_MENUS | |
137 | ||
138 | wxString m_undoAccelerator; | |
139 | wxString m_redoAccelerator; | |
140 | ||
141 | private: | |
142 | DECLARE_DYNAMIC_CLASS(wxCommandProcessor) | |
143 | DECLARE_NO_COPY_CLASS(wxCommandProcessor) | |
144 | }; | |
145 | ||
146 | #endif // _WX_CMDPROC_H_ | |
147 |