1 ///////////////////////////////////////////////////////////////////////////////
3 // Purpose: undo/redo capable command processing framework
4 // Author: Julian Smart (extracted from docview.h by VZ)
8 // Copyright: (c) wxWindows team
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_CMDPROC_H_
13 #define _WX_CMDPROC_H_
15 #if defined(__GNUG__) && !defined(__APPLE__)
16 #pragma interface "cmdproc.h"
19 #include "wx/object.h"
22 class WXDLLEXPORT wxMenu
;
24 // ----------------------------------------------------------------------------
25 // wxCommand: a single command capable of performing itself
26 // ----------------------------------------------------------------------------
28 class WXDLLEXPORT wxCommand
: public wxObject
31 wxCommand(bool canUndoIt
= FALSE
, const wxString
& name
= wxEmptyString
);
34 // Override this to perform a command
35 virtual bool Do() = 0;
37 // Override this to undo a command
38 virtual bool Undo() = 0;
40 virtual bool CanUndo() const { return m_canUndo
; }
41 virtual wxString
GetName() const { return m_commandName
; }
45 wxString m_commandName
;
48 DECLARE_CLASS(wxCommand
)
51 // ----------------------------------------------------------------------------
52 // wxCommandProcessor: wxCommand manager
53 // ----------------------------------------------------------------------------
55 class WXDLLEXPORT wxCommandProcessor
: public wxObject
58 // if max number of commands is -1, it is unlimited
59 wxCommandProcessor(int maxCommands
= -1);
60 virtual ~wxCommandProcessor();
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
);
66 // just store the command without executing it
67 virtual void Store(wxCommand
*command
);
71 virtual bool CanUndo() const;
72 virtual bool CanRedo() const;
74 // Initialises the current command and menu strings.
75 virtual void Initialize();
77 // Sets the Undo/Redo menu strings for the current menu.
78 virtual void SetMenuStrings();
80 // Gets the current Undo menu label.
81 wxString
GetUndoMenuLabel() const;
83 // Gets the current Undo menu label.
84 wxString
GetRedoMenuLabel() const;
87 // Call this to manage an edit menu.
88 void SetEditMenu(wxMenu
*menu
) { m_commandEditMenu
= menu
; }
89 wxMenu
*GetEditMenu() const { return m_commandEditMenu
; }
92 // command list access
93 wxList
& GetCommands() const { return (wxList
&) m_commands
; }
94 wxCommand
*GetCurrentCommand() const
96 return (wxCommand
*)(m_currentCommand
? m_currentCommand
->GetData() : NULL
);
98 int GetMaxCommands() const { return m_maxNoCommands
; }
99 virtual void ClearCommands();
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
; }
105 void SetUndoAccelerator(const wxString
& accel
) { m_undoAccelerator
= accel
; }
106 void SetRedoAccelerator(const wxString
& accel
) { m_redoAccelerator
= accel
; }
109 // for further flexibility, command processor doesn't call wxCommand::Do()
110 // and Undo() directly but uses these functions which can be overridden in
112 virtual bool DoCommand(wxCommand
& cmd
);
113 virtual bool UndoCommand(wxCommand
& cmd
);
117 wxNode
* m_currentCommand
;
120 wxMenu
* m_commandEditMenu
;
121 #endif // wxUSE_MENUS
123 wxString m_undoAccelerator
;
124 wxString m_redoAccelerator
;
127 DECLARE_DYNAMIC_CLASS(wxCommandProcessor
)
128 DECLARE_NO_COPY_CLASS(wxCommandProcessor
)
131 #endif // _WX_CMDPROC_H_