1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: undo/redo capable command processing framework
4 // Author: Julian Smart (extracted from docview.h by VZ)
7 // Copyright: (c) wxWidgets team
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_CMDPROC_H_
12 #define _WX_CMDPROC_H_
15 #include "wx/object.h"
18 class WXDLLIMPEXP_FWD_CORE wxMenu
;
20 // ----------------------------------------------------------------------------
21 // wxCommand: a single command capable of performing itself
22 // ----------------------------------------------------------------------------
24 class WXDLLIMPEXP_CORE wxCommand
: public wxObject
27 wxCommand(bool canUndoIt
= false, const wxString
& name
= wxEmptyString
);
28 virtual ~wxCommand(){}
30 // Override this to perform a command
31 virtual bool Do() = 0;
33 // Override this to undo a command
34 virtual bool Undo() = 0;
36 virtual bool CanUndo() const { return m_canUndo
; }
37 virtual wxString
GetName() const { return m_commandName
; }
41 wxString m_commandName
;
44 DECLARE_CLASS(wxCommand
)
47 // ----------------------------------------------------------------------------
48 // wxCommandProcessor: wxCommand manager
49 // ----------------------------------------------------------------------------
51 class WXDLLIMPEXP_CORE wxCommandProcessor
: public wxObject
54 // if max number of commands is -1, it is unlimited
55 wxCommandProcessor(int maxCommands
= -1);
56 virtual ~wxCommandProcessor();
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);
62 // just store the command without executing it
63 virtual void Store(wxCommand
*command
);
67 virtual bool CanUndo() const;
68 virtual bool CanRedo() const;
70 // Initialises the current command and menu strings.
71 virtual void Initialize();
73 // Sets the Undo/Redo menu strings for the current menu.
74 virtual void SetMenuStrings();
76 // Gets the current Undo menu label.
77 wxString
GetUndoMenuLabel() const;
79 // Gets the current Undo menu label.
80 wxString
GetRedoMenuLabel() const;
83 // Call this to manage an edit menu.
84 void SetEditMenu(wxMenu
*menu
) { m_commandEditMenu
= menu
; }
85 wxMenu
*GetEditMenu() const { return m_commandEditMenu
; }
88 // command list access
89 wxList
& GetCommands() { return m_commands
; }
90 const wxList
& GetCommands() const { return m_commands
; }
91 wxCommand
*GetCurrentCommand() const
93 return (wxCommand
*)(m_currentCommand
? m_currentCommand
->GetData() : NULL
);
95 int GetMaxCommands() const { return m_maxNoCommands
; }
96 virtual void ClearCommands();
98 // Has the current project been changed?
99 virtual bool IsDirty() const;
101 // Mark the current command as the one where the last save took place
104 m_lastSavedCommand
= m_currentCommand
;
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
; }
112 void SetUndoAccelerator(const wxString
& accel
) { m_undoAccelerator
= accel
; }
113 void SetRedoAccelerator(const wxString
& accel
) { m_redoAccelerator
= accel
; }
116 // for further flexibility, command processor doesn't call wxCommand::Do()
117 // and Undo() directly but uses these functions which can be overridden in
119 virtual bool DoCommand(wxCommand
& cmd
);
120 virtual bool UndoCommand(wxCommand
& cmd
);
124 wxList::compatibility_iterator m_currentCommand
,
128 wxMenu
* m_commandEditMenu
;
129 #endif // wxUSE_MENUS
131 wxString m_undoAccelerator
;
132 wxString m_redoAccelerator
;
135 DECLARE_DYNAMIC_CLASS(wxCommandProcessor
)
136 wxDECLARE_NO_COPY_CLASS(wxCommandProcessor
);
139 #endif // _WX_CMDPROC_H_