-
Notifications
You must be signed in to change notification settings - Fork 2
/
GenericNumberedConfigGUI.cpp
338 lines (286 loc) · 8.11 KB
/
GenericNumberedConfigGUI.cpp
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
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
// Statsgen Includes
#include "GenericNumberedConfigGUI.h"
#include "GenericConfigPanel.h"
#include "GlobalStatistics.h"
#include "StaticFunctions.h"
BEGIN_EVENT_TABLE(GenericNumberedConfigGUI, wxDialog)
EVT_SIZE(GenericNumberedConfigGUI::OnResize)
EVT_BUTTON(WINDOW_ID_BUTTON_SAVE,GenericNumberedConfigGUI::OnSave)
EVT_BUTTON(WINDOW_ID_BUTTON_QUIT,GenericNumberedConfigGUI::OnQuit)
EVT_BUTTON(WINDOW_ID_BUTTON_NEW,GenericNumberedConfigGUI::OnNew)
EVT_BUTTON(WINDOW_ID_BUTTON_DELETE,GenericNumberedConfigGUI::OnDelete)
EVT_COMBOBOX(WINDOW_ID_LISTBOX_CONFIGITEMS,GenericNumberedConfigGUI::OnListItemSelected)
END_EVENT_TABLE()
GenericNumberedConfigGUI::GenericNumberedConfigGUI(
// GenericConfigPanel * (*newPanelFunctionIn)(wxWindow *parentID,wxString &listID),
wxPanel * (*newPanelFunctionIn)(wxWindow *parentID,wxString &listID),
wxString &listGroupIn,
wxString &listGroupPrefixIn,
wxWindow *parent,
wxWindowID id,
const wxString &title,
const wxPoint &pos,
const wxSize &size,
long style,
const wxString &name):
wxDialog(parent,
id,
title,
pos,
size,
style,
name)
{
configPanel=NULL;
listGroup=listGroupIn;
listGroupPrefix=listGroupPrefixIn;
newPanelFunction=newPanelFunctionIn;
}
void GenericNumberedConfigGUI::OnListItemSelected(wxCommandEvent& event)
{
wxSizeEvent dummyEvent;
// we have a new selection
// remove the current panel (if present) and retrieve
// a new one using the retrieve function
wxString currentSelection;
if (configPanel!=NULL)
{
// first remove the old panel
configPanel->Destroy();
//delete(configPanel);
configPanel=NULL;
}
currentSelection=idList.GetValue();
if (currentSelection.Length()>0)
{
configPanel=newPanelFunction(this,currentSelection);
//configPanel->OnResize(dummyEvent);
SetConfigPanel(configPanel);
}
OnResize(dummyEvent);
}
void GenericNumberedConfigGUI::OnQuit(wxCommandEvent& event)
{
EndModal(event.GetId());
}
void GenericNumberedConfigGUI::OnSave(wxCommandEvent& event)
{
EndModal(event.GetId());
}
void GenericNumberedConfigGUI::WriteIDList()
{
int idCount;
int idIndex;
wxArrayString ids;
wxString id;
idCount=idList.GetCount();
for (idIndex=0;idIndex<idCount;idIndex++)
{
id=idList.GetString(idIndex);
ids.Add(id);
}
globalStatistics.configData.WriteList(listGroup,ids);
}
void GenericNumberedConfigGUI::OnNew(wxCommandEvent& event)
{
wxString caption="Enter New ID";
wxString message="Enter New ID";
wxString chosen;
wxCommandEvent dummyEvent;
chosen=wxGetTextFromUser(message,caption);
if (chosen.Length()>0)
{
SafeString(chosen);
idList.Append(chosen);
idList.SetValue(chosen);
OnListItemSelected(dummyEvent);
WriteIDList();
}
}
void GenericNumberedConfigGUI::OnDelete(wxCommandEvent& event)
{
wxString currentSelection;
wxString group;
int currentSelectionIndex;
wxCommandEvent dummyEvent;
int idCount;
wxString msg;
STATSGEN_DEBUG_FUNCTION_START("GenericNumberedConfigGUI","OnDelete")
currentSelection=idList.GetValue();
if (currentSelection.Length()>0)
{
STATSGEN_DEBUG(DEBUG_ALWAYS,currentSelection)
currentSelectionIndex=idList.GetSelection();
msg.Printf("currentSelectionIndex=%d",currentSelectionIndex);
STATSGEN_DEBUG(DEBUG_ALWAYS,msg)
if (currentSelectionIndex!=wxNOT_FOUND)
{
STATSGEN_DEBUG(DEBUG_ALWAYS,"Found it")
// delete the group from the config file
group=listGroupPrefix+currentSelection;
globalStatistics.configData.DeleteGroup(group);
// delete the current selection from the id list
idList.Delete(currentSelectionIndex);
// select another panel
idCount=idList.GetCount();
if (idCount>0)
{
idList.SetSelection(0);
}
// Need to force the selection event
OnListItemSelected(dummyEvent);
// Write the ID List back to the config
WriteIDList();
}
// Write the ID List to the config
}
STATSGEN_DEBUG_FUNCTION_END
}
GenericNumberedConfigGUI::~GenericNumberedConfigGUI()
{
}
//void GenericNumberedConfigGUI::SetConfigPanel(GenericConfigPanel *configPanelIn)
void GenericNumberedConfigGUI::SetConfigPanel(wxPanel *configPanelIn)
{
configPanel=configPanelIn;
}
void GenericNumberedConfigGUI::CreateDialog()
{
wxString label="Generic Configuration";
wxString defaultValue="";
wxString configKey;
wxCommandEvent event;
GroupedConfigItemsPanel *configPanel;
wxPoint configItemsPosition=wxDefaultPosition;
wxSize configItemsSize=wxDefaultSize;
wxArrayString ids;
wxString initialSelection="";
globalStatistics.configData.ReadList(listGroup,ids);
if (ids.GetCount()>0)
{
initialSelection=ids.Item(0);
}
idList.Create(this,
WINDOW_ID_LISTBOX_CONFIGITEMS,
initialSelection,
wxDefaultPosition,
wxDefaultSize,
ids,
wxCB_DROPDOWN | wxCB_READONLY | wxLB_SINGLE
);
saveButton.Create(this,
WINDOW_ID_BUTTON_SAVE,
_T(WINDOW_ID_BUTTON_SAVE_TEXT),
wxDefaultPosition);
deleteButton.Create(this,
WINDOW_ID_BUTTON_DELETE,
_T(WINDOW_ID_BUTTON_DELETE_TEXT),
wxDefaultPosition);
newButton.Create(this,
WINDOW_ID_BUTTON_NEW,
_T(WINDOW_ID_BUTTON_NEW_TEXT),
wxDefaultPosition);
quitButton.Create(this,
WINDOW_ID_BUTTON_QUIT,
_T(WINDOW_ID_BUTTON_QUIT_TEXT),
wxDefaultPosition);
OnListItemSelected(event);
}
void GenericNumberedConfigGUI::DisplayDialog()
{
int dialogRetVal;
// Called when we want to pop the dialog box
// into existance for the first time
// First we want to create all the items in the dialog box
CreateDialog();
// Now we can resize every item in the dialog to fit nicely
// Then we pop it into existance
dialogRetVal=ShowModal();
// Now we do what is necessary dependent on the return code
switch (dialogRetVal)
{
case WINDOW_ID_BUTTON_SAVE:
// We have been asked to save the changes
// just commit the config changes
globalStatistics.configData.CommitChanges();
break;
case WINDOW_ID_BUTTON_QUIT:
default:
// We have been asked to quit without saving
// rollback the config changes
globalStatistics.configData.RollbackChanges();
break;
}
}
void GenericNumberedConfigGUI::OnResize(wxSizeEvent &event)
{
wxString msg;
int dialogWidth;
int dialogHeight;
int quitWidth;
int quitHeight;
int saveWidth;
int saveHeight;
int newWidth;
int newHeight;
int deleteWidth;
int deleteHeight;
int configPanelWidth;
int configPanelHeight;
wxSize itemSize;
wxPoint itemPosition;
int yPosition;
int listWidth;
int listHeight;
itemSize=GetSize();
dialogWidth=itemSize.GetWidth();
dialogHeight=itemSize.GetHeight();
itemSize=idList.GetSize();
listWidth=itemSize.GetWidth();
if (listWidth<150)
{
listWidth=150;
}
idList.SetSize(listWidth,listHeight);
listHeight=itemSize.GetHeight();
// Quit and Save buttons are at the bottom of the screen
itemSize=quitButton.GetSize();
quitWidth=itemSize.GetWidth();
quitHeight=itemSize.GetHeight();
itemSize=saveButton.GetSize();
saveWidth=itemSize.GetWidth();
saveHeight=itemSize.GetHeight();
itemSize=newButton.GetSize();
newWidth=itemSize.GetWidth();
newHeight=itemSize.GetHeight();
itemSize=deleteButton.GetSize();
deleteWidth=itemSize.GetWidth();
deleteHeight=itemSize.GetHeight();
configPanelHeight=dialogHeight-saveHeight-DIALOG_BOTTOM_BORDER_SIZE;
configPanelWidth=dialogWidth;
// ID List
idList.SetSize(0,0,listWidth,listHeight);
// Config Panel
yPosition=listHeight;
// Config Panels resize themselves to fit
if (configPanel!=NULL)
{
configPanel->SetSize(0,yPosition,configPanelWidth,configPanelHeight-listHeight);
}
// Save button
itemPosition.x=BUTTON_WIDTH_GAP;
itemPosition.y=dialogHeight-saveHeight-DIALOG_BOTTOM_BORDER_SIZE;
saveButton.SetPosition(itemPosition);
// Quit button
itemPosition.x+=(saveWidth+BUTTON_WIDTH_GAP);
itemPosition.y=dialogHeight-quitHeight-DIALOG_BOTTOM_BORDER_SIZE;
quitButton.SetPosition(itemPosition);
// new button
itemPosition.x+=(quitWidth+BUTTON_WIDTH_GAP);
itemPosition.y=dialogHeight-newHeight-DIALOG_BOTTOM_BORDER_SIZE;
newButton.SetPosition(itemPosition);
// delete button
itemPosition.x+=(newWidth+BUTTON_WIDTH_GAP);
itemPosition.y=dialogHeight-deleteHeight-DIALOG_BOTTOM_BORDER_SIZE;
deleteButton.SetPosition(itemPosition);
}