]> git.saurik.com Git - wxWidgets.git/blame - include/wx/cmdproc.h
OS X savvy implementation
[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
6aa3ea88
JS
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
1e6feb95
VZ
109protected:
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;
222ed1d6 118 wxList::compatibility_iterator m_currentCommand;
1e6feb95
VZ
119
120#if wxUSE_MENUS
121 wxMenu* m_commandEditMenu;
122#endif // wxUSE_MENUS
123
6aa3ea88
JS
124 wxString m_undoAccelerator;
125 wxString m_redoAccelerator;
126
1e6feb95
VZ
127private:
128 DECLARE_DYNAMIC_CLASS(wxCommandProcessor)
22f3361e 129 DECLARE_NO_COPY_CLASS(wxCommandProcessor)
1e6feb95
VZ
130};
131
132#endif // _WX_CMDPROC_H_