]> git.saurik.com Git - wxWidgets.git/blob - include/wx/cmdproc.h
added a few more composite functions
[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 // 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 // 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; }
105
106 void SetUndoAccelerator(const wxString& accel) { m_undoAccelerator = accel; }
107 void SetRedoAccelerator(const wxString& accel) { m_redoAccelerator = accel; }
108
109 protected:
110 // for further flexibility, command processor doesn't call wxCommand::Do()
111 // and Undo() directly but uses these functions which can be overridden in
112 // the derived class
113 virtual bool DoCommand(wxCommand& cmd);
114 virtual bool UndoCommand(wxCommand& cmd);
115
116 int m_maxNoCommands;
117 wxList m_commands;
118 wxList::compatibility_iterator m_currentCommand;
119
120 #if wxUSE_MENUS
121 wxMenu* m_commandEditMenu;
122 #endif // wxUSE_MENUS
123
124 wxString m_undoAccelerator;
125 wxString m_redoAccelerator;
126
127 private:
128 DECLARE_DYNAMIC_CLASS(wxCommandProcessor)
129 DECLARE_NO_COPY_CLASS(wxCommandProcessor)
130 };
131
132 #endif // _WX_CMDPROC_H_