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