-
Notifications
You must be signed in to change notification settings - Fork 2
/
GenericConfigGUI.cpp
181 lines (151 loc) · 3.96 KB
/
GenericConfigGUI.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
// Statsgen Includes
#include "GenericConfigGUI.h"
#include "GenericConfigPanel.h"
#include "GlobalStatistics.h"
BEGIN_EVENT_TABLE(GenericConfigGUI, wxDialog)
EVT_SIZE(GenericConfigGUI::OnResize)
EVT_BUTTON(WINDOW_ID_BUTTON_SAVE,GenericConfigGUI::OnSave)
EVT_BUTTON(WINDOW_ID_BUTTON_QUIT,GenericConfigGUI::OnQuit)
END_EVENT_TABLE()
GenericConfigGUI::GenericConfigGUI(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;
firstTimeResize=false;
}
void GenericConfigGUI::OnQuit(wxCommandEvent& event)
{
EndModal(event.GetId());
}
void GenericConfigGUI::OnSave(wxCommandEvent& event)
{
EndModal(event.GetId());
}
GenericConfigGUI::~GenericConfigGUI()
{
}
void GenericConfigGUI::SetConfigPanel(GenericConfigPanel *configPanelIn)
{
configPanel=configPanelIn;
}
void GenericConfigGUI::CreateDialog()
{
wxString label="Generic Configuration";
wxString defaultValue="";
wxString configKey;
wxSizeEvent event;
GroupedConfigItemsPanel *configPanel;
wxPoint configItemsPosition=wxDefaultPosition;
wxSize configItemsSize=wxDefaultSize;
saveButton.Create(this,
WINDOW_ID_BUTTON_SAVE,
_T(WINDOW_ID_BUTTON_SAVE_TEXT),
wxDefaultPosition);
quitButton.Create(this,
WINDOW_ID_BUTTON_QUIT,
_T(WINDOW_ID_BUTTON_QUIT_TEXT),
wxDefaultPosition);
OnResize(event);
}
void GenericConfigGUI::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 GenericConfigGUI::OnResize(wxSizeEvent &event)
{
wxString msg;
int dialogWidth;
int dialogHeight;
int quitWidth;
int quitHeight;
int saveWidth;
int saveHeight;
int configPanelWidth;
int configPanelHeight;
wxSize itemSize;
wxPoint itemPosition;
int yPosition;
itemSize=GetSize();
dialogWidth=itemSize.GetWidth();
dialogHeight=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();
configPanelHeight=dialogHeight-saveHeight-DIALOG_BOTTOM_BORDER_SIZE;
configPanelWidth=dialogWidth;
// Config Panel
yPosition=0;
// Config Panels resize themselves to fit
if (configPanel!=NULL)
{
itemSize=configPanel->GetSize();
if (firstTimeResize)
{
configPanelHeight=itemSize.GetHeight();
dialogHeight=configPanelHeight+
saveHeight+
DIALOG_BOTTOM_BORDER_SIZE;
}
configPanel->SetSize(0,yPosition,configPanelWidth,
configPanelHeight);
itemSize=configPanel->GetSize();
if (firstTimeResize)
{
configPanelHeight=itemSize.GetHeight();
dialogHeight=configPanelHeight+
saveHeight+
DIALOG_BOTTOM_BORDER_SIZE;
}
}
// 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+BUTTON_WIDTH_GAP;
itemPosition.y=dialogHeight-quitHeight-DIALOG_BOTTOM_BORDER_SIZE;
quitButton.SetPosition(itemPosition);
if (firstTimeResize)
{
SetSize(dialogWidth,dialogHeight);
}
firstTimeResize=false;
}