summary refs log tree commit diff stats
path: root/tools/mapedit/src/undo.h
blob: 621f42c8ebbe7743bbd36cd81e084d8575c3e56a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#ifndef UNDO_H
#define UNDO_H

#include <wx/wxprec.h>

#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif

#include <functional>
#include <string>
#include <list>

class MapeditFrame;

class Undoable {
  public:
    Undoable(std::string title, std::function<void ()> forward, std::function<void ()> backward);
    virtual std::string getTitle() const;
    virtual void apply();
    virtual void undo();
    virtual void endChanges() {}
    
  protected:
    Undoable() {}
    
    std::string title;
    std::function<void ()> forward;
    std::function<void ()> backward;
};

class UndoableTextBox : public wxTextCtrl {
  public:
    UndoableTextBox();
    UndoableTextBox(wxWindow* parent, wxWindowID id, wxString startText, std::string undoType, MapeditFrame* realParent, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = 0);
    
  private:
    class Undo : public Undoable {
      public:
        Undo(std::string title, wxString origText, UndoableTextBox& parent);
        void apply();
        void undo();
        void endChanges();
      
        wxString origText;
        wxString newText;
        UndoableTextBox& parent;
    };
    
    void Init();
    void OnFocus(wxFocusEvent& event);
    void OnKillFocus(wxFocusEvent& event);
    void OnTextChange(wxCommandEvent& event);
    
    MapeditFrame* realParent;
    std::string undoText;
    wxString curText;
    std::shared_ptr<Undo> undo;
    
    wxDECLARE_EVENT_TABLE();
};

class UndoableChoice : public wxChoice {
  public:
    UndoableChoice();
    UndoableChoice(wxWindow* parent, wxWindowID id, MapeditFrame* realParent, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, int n = 0, const wxString choices[] = NULL, long style = 0, const wxValidator& validator = wxDefaultValidator, const wxString& name = wxChoiceNameStr);
    
  protected:
    void Init();
    void OnChoose(wxCommandEvent& event);
    
  private:
    MapeditFrame* realParent;
};

class UndoableSlider : public wxSlider {
  public:
    UndoableSlider();
    UndoableSlider(wxWindow* parent, wxWindowID id, MapeditFrame* realParent, int value, int minvalue, int maxvalue, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxSL_HORIZONTAL, const wxValidator& validator = wxDefaultValidator, const wxString& name = wxSliderNameStr);
    
  protected:
    void Init();
    void OnSlide(wxScrollEvent& event);
    
  private:
    MapeditFrame* realParent;
    
    wxDECLARE_EVENT_TABLE();
};

#endif