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