Statistics
| Revision:

root / trunk / install / launcher / izpack-launcher-1.3_linux / src / wx / include / wx / cmdproc.h @ 6834

History | View | Annotate | Download (3.89 KB)

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: cmdproc.h 6834 2006-08-24 08:23:24Z jmvivo $
8
// Copyright:   (c) wxWindows team
9
// Licence:     wxWindows licence
10
///////////////////////////////////////////////////////////////////////////////
11

    
12
#ifndef _WX_CMDPROC_H_
13
#define _WX_CMDPROC_H_
14

    
15
#include "wx/object.h"
16
#include "wx/list.h"
17

    
18
// ----------------------------------------------------------------------------
19
// wxCommand: a single command capable of performing itself
20
// ----------------------------------------------------------------------------
21

    
22
class WXDLLEXPORT wxCommand : public wxObject
23
{
24
public:
25
    wxCommand(bool canUndoIt = FALSE, const wxString& name = wxT(""));
26
    ~wxCommand();
27

    
28
    // Override this to perform a command
29
    virtual bool Do() = 0;
30

    
31
    // Override this to undo a command
32
    virtual bool Undo() = 0;
33

    
34
    virtual bool CanUndo() const { return m_canUndo; }
35
    virtual wxString GetName() const { return m_commandName; }
36

    
37
protected:
38
    bool     m_canUndo;
39
    wxString m_commandName;
40

    
41
private:
42
    DECLARE_CLASS(wxCommand)
43
};
44

    
45
// ----------------------------------------------------------------------------
46
// wxCommandProcessor: wxCommand manager
47
// ----------------------------------------------------------------------------
48

    
49
class WXDLLEXPORT wxCommandProcessor : public wxObject
50
{
51
public:
52
    // if max number of commands is -1, it is unlimited
53
    wxCommandProcessor(int maxCommands = -1);
54
    virtual ~wxCommandProcessor();
55

    
56
    // Pass a command to the processor. The processor calls Do(); if
57
    // successful, is appended to the command history unless storeIt is FALSE.
58
    virtual bool Submit(wxCommand *command, bool storeIt = TRUE);
59

    
60
    // just store the command without executing it
61
    virtual void Store(wxCommand *command);
62

    
63
    virtual bool Undo();
64
    virtual bool Redo();
65
    virtual bool CanUndo() const;
66
    virtual bool CanRedo() const;
67

    
68
    // Initialises the current command and menu strings.
69
    virtual void Initialize();
70

    
71
    // Sets the Undo/Redo menu strings for the current menu.
72
    virtual void SetMenuStrings();
73

    
74
    // Gets the current Undo menu label.
75
    wxString GetUndoMenuLabel() const;
76

    
77
    // Gets the current Undo menu label.
78
    wxString GetRedoMenuLabel() const;
79

    
80
#if wxUSE_MENUS
81
    // Call this to manage an edit menu.
82
    void SetEditMenu(wxMenu *menu) { m_commandEditMenu = menu; }
83
    wxMenu *GetEditMenu() const { return m_commandEditMenu; }
84
#endif // wxUSE_MENUS
85

    
86
    // command list access
87
    wxList& GetCommands() const { return (wxList&) m_commands; }
88
    wxCommand *GetCurrentCommand() const
89
    {
90
        return (wxCommand *)(m_currentCommand ? m_currentCommand->Data() : NULL);
91
    }
92
    int GetMaxCommands() const { return m_maxNoCommands; }
93
    virtual void ClearCommands();
94

    
95
    // By default, the accelerators are "\tCtrl+Z" and "\tCtrl+Y"
96
    const wxString& GetUndoAccelerator() const { return m_undoAccelerator; }
97
    const wxString& GetRedoAccelerator() const { return m_redoAccelerator; }
98

    
99
    void SetUndoAccelerator(const wxString& accel) { m_undoAccelerator = accel; }
100
    void SetRedoAccelerator(const wxString& accel) { m_redoAccelerator = accel; }
101

    
102
protected:
103
    // for further flexibility, command processor doesn't call wxCommand::Do()
104
    // and Undo() directly but uses these functions which can be overridden in
105
    // the derived class
106
    virtual bool DoCommand(wxCommand& cmd);
107
    virtual bool UndoCommand(wxCommand& cmd);
108

    
109
    int           m_maxNoCommands;
110
    wxList        m_commands;
111
    wxNode*       m_currentCommand;
112

    
113
#if wxUSE_MENUS
114
    wxMenu*       m_commandEditMenu;
115
#endif // wxUSE_MENUS
116

    
117
    wxString      m_undoAccelerator;
118
    wxString      m_redoAccelerator;
119

    
120
private:
121
    DECLARE_DYNAMIC_CLASS(wxCommandProcessor)
122
};
123

    
124
#endif // _WX_CMDPROC_H_