1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: undo/redo capable command processing framework
4 // Author: Julian Smart (extracted from docview.h by VZ)
8 // Copyright: (c) wxWidgets team
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_CMDPROC_H_
13 #define _WX_CMDPROC_H_
15 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
16 #pragma interface "cmdproc.h"
20 #include "wx/object.h"
23 class WXDLLEXPORT wxMenu
;
25 // ----------------------------------------------------------------------------
26 // wxCommand: a single command capable of performing itself
27 // ----------------------------------------------------------------------------
29 class WXDLLEXPORT wxCommand
: public wxObject
32 wxCommand(bool canUndoIt
= FALSE
, const wxString
& name
= wxEmptyString
);
35 // Override this to perform a command
36 virtual bool Do() = 0;
38 // Override this to undo a command
39 virtual bool Undo() = 0;
41 virtual bool CanUndo() const { return m_canUndo
; }
42 virtual wxString
GetName() const { return m_commandName
; }
46 wxString m_commandName
;
49 DECLARE_CLASS(wxCommand
)
52 // ----------------------------------------------------------------------------
53 // wxCommandProcessor: wxCommand manager
54 // ----------------------------------------------------------------------------
56 class WXDLLEXPORT wxCommandProcessor
: public wxObject
59 // if max number of commands is -1, it is unlimited
60 wxCommandProcessor(int maxCommands
= -1);
61 virtual ~wxCommandProcessor();
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
);
67 // just store the command without executing it
68 virtual void Store(wxCommand
*command
);
72 virtual bool CanUndo() const;
73 virtual bool CanRedo() const;
75 // Initialises the current command and menu strings.
76 virtual void Initialize();
78 // Sets the Undo/Redo menu strings for the current menu.
79 virtual void SetMenuStrings();
81 // Gets the current Undo menu label.
82 wxString
GetUndoMenuLabel() const;
84 // Gets the current Undo menu label.
85 wxString
GetRedoMenuLabel() const;
88 // Call this to manage an edit menu.
89 void SetEditMenu(wxMenu
*menu
) { m_commandEditMenu
= menu
; }
90 wxMenu
*GetEditMenu() const { return m_commandEditMenu
; }
93 // command list access
94 wxList
& GetCommands() const { return (wxList
&) m_commands
; }
95 wxCommand
*GetCurrentCommand() const
97 return (wxCommand
*)(m_currentCommand
? m_currentCommand
->GetData() : NULL
);
99 int GetMaxCommands() const { return m_maxNoCommands
; }
100 virtual void ClearCommands();
102 // By default, the accelerators are "\tCtrl+Z" and "\tCtrl+Y"
103 const wxString
& GetUndoAccelerator() const { return m_undoAccelerator
; }
104 const wxString
& GetRedoAccelerator() const { return m_redoAccelerator
; }
106 void SetUndoAccelerator(const wxString
& accel
) { m_undoAccelerator
= accel
; }
107 void SetRedoAccelerator(const wxString
& accel
) { m_redoAccelerator
= accel
; }
110 // for further flexibility, command processor doesn't call wxCommand::Do()
111 // and Undo() directly but uses these functions which can be overridden in
113 virtual bool DoCommand(wxCommand
& cmd
);
114 virtual bool UndoCommand(wxCommand
& cmd
);
118 wxList::compatibility_iterator m_currentCommand
;
121 wxMenu
* m_commandEditMenu
;
122 #endif // wxUSE_MENUS
124 wxString m_undoAccelerator
;
125 wxString m_redoAccelerator
;
128 DECLARE_DYNAMIC_CLASS(wxCommandProcessor
)
129 DECLARE_NO_COPY_CLASS(wxCommandProcessor
)
132 #endif // _WX_CMDPROC_H_