-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAGE_TextControls.h
295 lines (267 loc) · 8.78 KB
/
AGE_TextControls.h
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
#pragma once
#include "Common.h"
class ProperList: public wxVListBox
{
public:
ProperList(wxWindow *parent, const wxSize &size):
wxVListBox(parent, wxID_ANY, wxDefaultPosition, size, wxLB_INT_HEIGHT | wxLB_MULTIPLE)//wxLB_EXTENDED)
{
SetItemCount(0);
row_height = GetCharHeight();
}
void EnsureVisible(size_t n);
inline void Sweep() {names.clear(); indexes.clear();}
//inline void Add(const wxString &name, size_t i);
wxArrayString names;
vector<size_t> indexes;
private:
wxCoord OnMeasureItem(size_t) const override {return row_height;}
void OnDrawItem(wxDC &dc, const wxRect &rect, size_t n) const override;
void OnDrawBackground(wxDC &dc, const wxRect &rect, size_t n) const override;
int row_height = 0;
};
// The purpose of these custom text controls is that you get specified error messages
// when your mouse cursor focus gets off from a data edit box.
class AGETextCtrl;
class AGELinkedBox
{
public:
virtual void OnChoose(wxCommandEvent&)=0;
virtual void SetChoice(int)=0;
virtual void EnableCtrl(bool)=0;
AGETextCtrl *TextBox;
};
// This could be used if linked box system gets abolished.
class AGEBaseCtrl
{
public:
inline void clear(){container.clear();}
inline void prepend(void* data){container.push_back(data);}
virtual int SaveEdits(bool forced = false)=0;
static const wxString BATCHWARNING, BWTITLE, IETITLE;
protected:
void OnKillFocus(wxFocusEvent &event)
{
event.Skip();
SaveEdits();
}
void OnEnter(wxCommandEvent&){SaveEdits(true);}
vector<void*> container;
ContainerType type;
int editedFileId, edits;
DelayedPopUp *editor;
wxFrame* frame;
};
class AGETextCtrl: public wxTextCtrl, public AGEBaseCtrl
{
public:
AGETextCtrl(wxWindow *parent, int width):
wxTextCtrl(parent, wxID_ANY, "", wxDefaultPosition, wxSize(width, -1), wxTE_PROCESS_ENTER){edits = 0;}
static unsigned SMALL, MEDIUM, NORMAL, LARGE, GIANT;
static AGETextCtrl* init(const ContainerType type, vector<AGETextCtrl*> *group,
wxFrame *frame, DelayedPopUp *editor, wxWindow *parent, unsigned length = NORMAL);
virtual void update()
{
if(container.empty())
{
Clear();
Enable(false);
if(!LinkedBoxes.empty())
for(auto it = LinkedBoxes.begin(); it != LinkedBoxes.end(); ++it)
{
(*it)->SetChoice(-1);
(*it)->EnableCtrl(false);
}
return;
}
editedFileId = editor->loadedFileId;
replenish();
Enable(true);
}
virtual void refill()
{
if(container.empty())
{
Clear();
return;
}
editedFileId = editor->loadedFileId;
replenish();
}
virtual void replenish()=0;
void changeContainerType(const ContainerType type)
{
switch(type)
{
case CByte:
case CUByte: SetBackgroundColour(wxColour(255, 235, 215)); break;
case CFloat: SetBackgroundColour(wxColour(255, 225, 255)); break;
case CLong:
case CULong: SetBackgroundColour(wxColour(215, 255, 255)); break;
case CShort:
case CUShort: SetBackgroundColour(wxColour(210, 230, 255)); break;
case CString: SetBackgroundColour(wxColour(220, 255, 220)); break;
}
}
virtual inline void setMaxChars(unsigned short){}
vector<AGELinkedBox*> LinkedBoxes; // These are for check boxes.
protected:
bool BatchCheck(string &value, short &batchMode)
{
if(value.size() < 3) return false;
switch((char)value[1])
{
case '+': batchMode = 1; value = value.substr(2); return true;
case '-': batchMode = 2; value = value.substr(2); return true;
case '*': batchMode = 3; value = value.substr(2); return true;
case '/': batchMode = 4; value = value.substr(2); return true;
case '%': batchMode = 5; value = value.substr(2); return true;
default: return false;
}
}
void HandleResults(int casted)
{
for(auto it = LinkedBoxes.begin(); it != LinkedBoxes.end(); ++it)
{
(*it)->SetChoice(casted);
}
frame->SetStatusText("Edits: "+std::to_string(editor->unSaved)+" + "+std::to_string(edits), 3);
editor->unSaved += edits;
edits = 0;
}
};
class TextCtrl_DLL: public wxTextCtrl
{
public:
TextCtrl_DLL(wxWindow *parent, wxSize dimensions):
wxTextCtrl(parent, wxID_ANY, "", wxDefaultPosition, dimensions, wxTE_MULTILINE)
{
Bind(wxEVT_MOUSEWHEEL, [this](wxMouseEvent &event){GetParent()->GetEventHandler()->ProcessEvent(event);});
}
int index;
};
class TextCtrl_Byte: public AGETextCtrl
{
public:
TextCtrl_Byte(wxFrame *frame, DelayedPopUp *editor, wxWindow *parent, unsigned size):
AGETextCtrl(parent, size)
{
this->frame = frame;
this->editor = editor;
SetBackgroundColour(wxColour(255, 235, 215));
Bind(wxEVT_KILL_FOCUS, &TextCtrl_Byte::OnKillFocus, this); // Must-have
Bind(wxEVT_TEXT_ENTER, &TextCtrl_Byte::OnEnter, this);
}
int SaveEdits(bool forced = false);
void replenish();
};
class TextCtrl_UByte: public AGETextCtrl
{
public:
TextCtrl_UByte(wxFrame *frame, DelayedPopUp *editor, wxWindow *parent, unsigned size):
AGETextCtrl(parent, size)
{
this->frame = frame;
this->editor = editor;
SetBackgroundColour(wxColour(255, 235, 215));
Bind(wxEVT_KILL_FOCUS, &TextCtrl_UByte::OnKillFocus, this);
Bind(wxEVT_TEXT_ENTER, &TextCtrl_UByte::OnEnter, this);
}
int SaveEdits(bool forced = false);
void replenish();
};
class TextCtrl_Float: public AGETextCtrl
{
public:
TextCtrl_Float(wxFrame *frame, DelayedPopUp *editor, wxWindow *parent, unsigned petit):
AGETextCtrl(parent, petit)
{
this->frame = frame;
this->editor = editor;
SetBackgroundColour(wxColour(255, 225, 255));
Bind(wxEVT_KILL_FOCUS, &TextCtrl_Float::OnKillFocus, this);
Bind(wxEVT_TEXT_ENTER, &TextCtrl_Float::OnEnter, this);
}
int SaveEdits(bool forced = false);
void replenish();
};
class TextCtrl_Long: public AGETextCtrl
{
public:
TextCtrl_Long(wxFrame *frame, DelayedPopUp *editor, wxWindow *parent, unsigned petit):
AGETextCtrl(parent, petit)
{
this->frame = frame;
this->editor = editor;
SetBackgroundColour(wxColour(215, 255, 255));
Bind(wxEVT_KILL_FOCUS, &TextCtrl_Long::OnKillFocus, this);
Bind(wxEVT_TEXT_ENTER, &TextCtrl_Long::OnEnter, this);
}
int SaveEdits(bool forced = false);
void replenish();
};
class TextCtrl_ULong: public AGETextCtrl
{
public:
TextCtrl_ULong(wxFrame *frame, DelayedPopUp *editor, wxWindow *parent, unsigned petit):
AGETextCtrl(parent, petit)
{
this->frame = frame;
this->editor = editor;
SetBackgroundColour(wxColour(215, 255, 255));
Bind(wxEVT_KILL_FOCUS, &TextCtrl_ULong::OnKillFocus, this);
Bind(wxEVT_TEXT_ENTER, &TextCtrl_ULong::OnEnter, this);
}
int SaveEdits(bool forced = false);
void replenish();
};
class TextCtrl_Short: public AGETextCtrl
{
public:
TextCtrl_Short(wxFrame *frame, DelayedPopUp *editor, wxWindow *parent, unsigned petit):
AGETextCtrl(parent, petit)
{
this->frame = frame;
this->editor = editor;
SetBackgroundColour(wxColour(210, 230, 255));
Bind(wxEVT_KILL_FOCUS, &TextCtrl_Short::OnKillFocus, this);
Bind(wxEVT_TEXT_ENTER, &TextCtrl_Short::OnEnter, this);
}
int SaveEdits(bool forced = false);
void replenish();
};
class TextCtrl_UShort: public AGETextCtrl
{
public:
TextCtrl_UShort(wxFrame *frame, DelayedPopUp *editor, wxWindow *parent, unsigned petit):
AGETextCtrl(parent, petit)
{
this->frame = frame;
this->editor = editor;
SetBackgroundColour(wxColour(210, 230, 255));
Bind(wxEVT_KILL_FOCUS, &TextCtrl_UShort::OnKillFocus, this);
Bind(wxEVT_TEXT_ENTER, &TextCtrl_UShort::OnEnter, this);
}
int SaveEdits(bool forced = false);
void replenish();
};
extern const unsigned short lengthiest;
class TextCtrl_String: public AGETextCtrl
{
public:
TextCtrl_String(wxFrame *frame, DelayedPopUp *editor, wxWindow *parent, unsigned short CLength = 0):
AGETextCtrl(parent, AGETextCtrl::GIANT)
{
this->frame = frame;
this->editor = editor;
maxSize = CLength;
SetBackgroundColour(wxColour(220, 255, 220));
Bind(wxEVT_KILL_FOCUS, &TextCtrl_String::OnKillFocus, this);
Bind(wxEVT_TEXT_ENTER, &TextCtrl_String::OnEnter, this);
}
int SaveEdits(bool forced = false);
void replenish();
inline void setMaxChars(unsigned short size) {maxSize = size;}
private:
unsigned short maxSize;
};