]> git.saurik.com Git - wxWidgets.git/blame - include/wx/cmdproc.h
Add missing wxUSE_OLE checks to safearray.cpp.
[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
e5898961 15#include "wx/defs.h"
1e6feb95
VZ
16#include "wx/object.h"
17#include "wx/list.h"
18
b5dbe15d 19class WXDLLIMPEXP_FWD_CORE wxMenu;
bad93b35 20
1e6feb95
VZ
21// ----------------------------------------------------------------------------
22// wxCommand: a single command capable of performing itself
23// ----------------------------------------------------------------------------
24
53a2db12 25class WXDLLIMPEXP_CORE wxCommand : public wxObject
1e6feb95
VZ
26{
27public:
68379eaf 28 wxCommand(bool canUndoIt = false, const wxString& name = wxEmptyString);
d3c7fc99 29 virtual ~wxCommand(){}
1e6feb95
VZ
30
31 // Override this to perform a command
32 virtual bool Do() = 0;
33
34 // Override this to undo a command
35 virtual bool Undo() = 0;
36
37 virtual bool CanUndo() const { return m_canUndo; }
38 virtual wxString GetName() const { return m_commandName; }
39
40protected:
41 bool m_canUndo;
42 wxString m_commandName;
43
44private:
45 DECLARE_CLASS(wxCommand)
46};
47
48// ----------------------------------------------------------------------------
49// wxCommandProcessor: wxCommand manager
50// ----------------------------------------------------------------------------
51
53a2db12 52class WXDLLIMPEXP_CORE wxCommandProcessor : public wxObject
1e6feb95
VZ
53{
54public:
55 // if max number of commands is -1, it is unlimited
56 wxCommandProcessor(int maxCommands = -1);
57 virtual ~wxCommandProcessor();
58
59 // Pass a command to the processor. The processor calls Do(); if
68379eaf
WS
60 // successful, is appended to the command history unless storeIt is false.
61 virtual bool Submit(wxCommand *command, bool storeIt = true);
1e6feb95
VZ
62
63 // just store the command without executing it
64 virtual void Store(wxCommand *command);
65
66 virtual bool Undo();
67 virtual bool Redo();
68 virtual bool CanUndo() const;
69 virtual bool CanRedo() const;
70
d863ed83 71 // Initialises the current command and menu strings.
1e6feb95 72 virtual void Initialize();
d863ed83
JS
73
74 // Sets the Undo/Redo menu strings for the current menu.
1e6feb95
VZ
75 virtual void SetMenuStrings();
76
d863ed83
JS
77 // Gets the current Undo menu label.
78 wxString GetUndoMenuLabel() const;
79
80 // Gets the current Undo menu label.
81 wxString GetRedoMenuLabel() const;
82
1e6feb95
VZ
83#if wxUSE_MENUS
84 // Call this to manage an edit menu.
85 void SetEditMenu(wxMenu *menu) { m_commandEditMenu = menu; }
86 wxMenu *GetEditMenu() const { return m_commandEditMenu; }
87#endif // wxUSE_MENUS
88
89 // command list access
b80388aa
VZ
90 wxList& GetCommands() { return m_commands; }
91 const wxList& GetCommands() const { return m_commands; }
1e6feb95
VZ
92 wxCommand *GetCurrentCommand() const
93 {
b1d4dd7a 94 return (wxCommand *)(m_currentCommand ? m_currentCommand->GetData() : NULL);
1e6feb95
VZ
95 }
96 int GetMaxCommands() const { return m_maxNoCommands; }
97 virtual void ClearCommands();
98
f260c476 99 // Has the current project been changed?
ef20428e 100 virtual bool IsDirty() const;
f260c476
VZ
101
102 // Mark the current command as the one where the last save took place
103 void MarkAsSaved()
104 {
105 m_lastSavedCommand = m_currentCommand;
106 }
107
108
6aa3ea88
JS
109 // By default, the accelerators are "\tCtrl+Z" and "\tCtrl+Y"
110 const wxString& GetUndoAccelerator() const { return m_undoAccelerator; }
111 const wxString& GetRedoAccelerator() const { return m_redoAccelerator; }
112
113 void SetUndoAccelerator(const wxString& accel) { m_undoAccelerator = accel; }
114 void SetRedoAccelerator(const wxString& accel) { m_redoAccelerator = accel; }
115
1e6feb95
VZ
116protected:
117 // for further flexibility, command processor doesn't call wxCommand::Do()
118 // and Undo() directly but uses these functions which can be overridden in
119 // the derived class
120 virtual bool DoCommand(wxCommand& cmd);
121 virtual bool UndoCommand(wxCommand& cmd);
122
123 int m_maxNoCommands;
124 wxList m_commands;
f260c476
VZ
125 wxList::compatibility_iterator m_currentCommand,
126 m_lastSavedCommand;
1e6feb95
VZ
127
128#if wxUSE_MENUS
129 wxMenu* m_commandEditMenu;
130#endif // wxUSE_MENUS
131
6aa3ea88
JS
132 wxString m_undoAccelerator;
133 wxString m_redoAccelerator;
134
1e6feb95
VZ
135private:
136 DECLARE_DYNAMIC_CLASS(wxCommandProcessor)
c0c133e1 137 wxDECLARE_NO_COPY_CLASS(wxCommandProcessor);
1e6feb95
VZ
138};
139
140#endif // _WX_CMDPROC_H_
f260c476 141