]> git.saurik.com Git - wxWidgets.git/blame - include/wx/cmdproc.h
wxMSWUniv build fix.
[wxWidgets.git] / include / wx / cmdproc.h
CommitLineData
1e6feb95
VZ
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$
77ffb593 8// Copyright: (c) wxWidgets team
65571936 9// Licence: wxWindows licence
1e6feb95
VZ
10///////////////////////////////////////////////////////////////////////////////
11
12#ifndef _WX_CMDPROC_H_
13#define _WX_CMDPROC_H_
14
12028905 15#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
1e6feb95
VZ
16 #pragma interface "cmdproc.h"
17#endif
18
e5898961 19#include "wx/defs.h"
1e6feb95
VZ
20#include "wx/object.h"
21#include "wx/list.h"
22
bad93b35
VZ
23class WXDLLEXPORT wxMenu;
24
1e6feb95
VZ
25// ----------------------------------------------------------------------------
26// wxCommand: a single command capable of performing itself
27// ----------------------------------------------------------------------------
28
29class WXDLLEXPORT wxCommand : public wxObject
30{
31public:
68379eaf 32 wxCommand(bool canUndoIt = false, const wxString& name = wxEmptyString);
e4a4a50b 33 ~wxCommand(){}
1e6feb95
VZ
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
44protected:
45 bool m_canUndo;
46 wxString m_commandName;
47
48private:
49 DECLARE_CLASS(wxCommand)
50};
51
52// ----------------------------------------------------------------------------
53// wxCommandProcessor: wxCommand manager
54// ----------------------------------------------------------------------------
55
56class WXDLLEXPORT wxCommandProcessor : public wxObject
57{
58public:
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
68379eaf
WS
64 // successful, is appended to the command history unless storeIt is false.
65 virtual bool Submit(wxCommand *command, bool storeIt = true);
1e6feb95
VZ
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
d863ed83 75 // Initialises the current command and menu strings.
1e6feb95 76 virtual void Initialize();
d863ed83
JS
77
78 // Sets the Undo/Redo menu strings for the current menu.
1e6feb95
VZ
79 virtual void SetMenuStrings();
80
d863ed83
JS
81 // Gets the current Undo menu label.
82 wxString GetUndoMenuLabel() const;
83
84 // Gets the current Undo menu label.
85 wxString GetRedoMenuLabel() const;
86
1e6feb95
VZ
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 {
b1d4dd7a 97 return (wxCommand *)(m_currentCommand ? m_currentCommand->GetData() : NULL);
1e6feb95
VZ
98 }
99 int GetMaxCommands() const { return m_maxNoCommands; }
100 virtual void ClearCommands();
101
f260c476
VZ
102 // Has the current project been changed?
103 virtual bool IsDirty() const
104 {
105 return m_currentCommand && (m_lastSavedCommand != m_currentCommand);
106 }
107
108 // Mark the current command as the one where the last save took place
109 void MarkAsSaved()
110 {
111 m_lastSavedCommand = m_currentCommand;
112 }
113
114
6aa3ea88
JS
115 // By default, the accelerators are "\tCtrl+Z" and "\tCtrl+Y"
116 const wxString& GetUndoAccelerator() const { return m_undoAccelerator; }
117 const wxString& GetRedoAccelerator() const { return m_redoAccelerator; }
118
119 void SetUndoAccelerator(const wxString& accel) { m_undoAccelerator = accel; }
120 void SetRedoAccelerator(const wxString& accel) { m_redoAccelerator = accel; }
121
1e6feb95
VZ
122protected:
123 // for further flexibility, command processor doesn't call wxCommand::Do()
124 // and Undo() directly but uses these functions which can be overridden in
125 // the derived class
126 virtual bool DoCommand(wxCommand& cmd);
127 virtual bool UndoCommand(wxCommand& cmd);
128
129 int m_maxNoCommands;
130 wxList m_commands;
f260c476
VZ
131 wxList::compatibility_iterator m_currentCommand,
132 m_lastSavedCommand;
1e6feb95
VZ
133
134#if wxUSE_MENUS
135 wxMenu* m_commandEditMenu;
136#endif // wxUSE_MENUS
137
6aa3ea88
JS
138 wxString m_undoAccelerator;
139 wxString m_redoAccelerator;
140
1e6feb95
VZ
141private:
142 DECLARE_DYNAMIC_CLASS(wxCommandProcessor)
22f3361e 143 DECLARE_NO_COPY_CLASS(wxCommandProcessor)
1e6feb95
VZ
144};
145
146#endif // _WX_CMDPROC_H_
f260c476 147