-
Notifications
You must be signed in to change notification settings - Fork 2
/
GenericConfigPanel.cpp
158 lines (141 loc) · 3.48 KB
/
GenericConfigPanel.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
// Statsgen Includes
#include "GenericConfigPanel.h"
#include "GenericNumberedConfigPanel.h"
#include "GlobalStatistics.h"
BEGIN_EVENT_TABLE(GenericConfigPanel, wxPanel)
EVT_SIZE(GenericConfigPanel::OnResize)
EVT_TEXT(WINDOW_ID_TEXTCTRL_CONFIGVALUE,GenericConfigPanel::OnTextChange)
END_EVENT_TABLE()
GenericConfigPanel::GenericConfigPanel(wxWindow *parent,
wxWindowID id,
const wxPoint &pos,
const wxSize &size,
long style,
const wxString &name):
wxPanel(parent,
id,
pos,
size,
style,
name)
{
}
GenericConfigPanel::~GenericConfigPanel()
{
}
void GenericConfigPanel::AddConfigGroup(GroupedConfigItemsPanel *configPanel)
{
wxSizeEvent dummy;
panelTypes.Add(1);
configItems.Add((void *)configPanel);
OnResize(dummy);
}
void GenericConfigPanel::AddConfigGroup(wxPanel *configPanel)
{
wxSizeEvent dummy;
panelTypes.Add(0);
configItems.Add((void *)configPanel);
OnResize(dummy);
}
void GenericConfigPanel::AddConfigGroup(GenericNumberedConfigPanel *configPanel)
{
wxSizeEvent dummy;
panelTypes.Add(2);
configItems.Add((void *)configPanel);
OnResize(dummy);
}
bool GenericConfigPanel::UpdateFromTrigger()
{
bool panelTriggered;
int panelCount;
int panelIndex;
int panelType;
panelTriggered=false;
panelCount=configItems.GetCount();
for (panelIndex=0;panelIndex<panelCount;panelIndex++)
{
panelType=panelTypes.Item(panelIndex);
if (panelType==1)
{
GroupedConfigItemsPanel *configPanel;
configPanel=(GroupedConfigItemsPanel *)configItems.Item(panelIndex);
if (configPanel->UpdateFromTrigger())
{
panelTriggered=true;
}
}
if (panelType==2)
{
GenericNumberedConfigPanel *configPanel;
configPanel=(GenericNumberedConfigPanel *)configItems.Item(panelIndex);
if (configPanel->UpdateFromTrigger())
{
panelTriggered=true;
}
}
}
wxSizeEvent dummyEvent;
OnResize(dummyEvent);
return (panelTriggered);
}
void GenericConfigPanel::OnTextChange(wxCommandEvent &event)
{
UpdateFromTrigger();
}
void GenericConfigPanel::OnResize(wxSizeEvent &event)
{
wxString msg;
int dialogWidth;
int dialogHeight;
wxSize itemSize;
wxPoint itemPosition;
int configPanelHeight;
int configPanelWidth;
GroupedConfigItemsPanel *configPanel;
int configPanelCount;
int configPanelIndex;
int yPosition;
int panelType;
itemSize=GetSize();
dialogWidth=itemSize.GetWidth();
dialogHeight=itemSize.GetHeight();
configPanelHeight=dialogHeight;
configPanelWidth=dialogWidth;
// Config Panel
configPanelCount=configItems.GetCount();
yPosition=0;
// Config Panels resize themselves to fit
for (configPanelIndex=0;configPanelIndex<configPanelCount;configPanelIndex++)
{
configPanel=(GroupedConfigItemsPanel *)configItems.Item(configPanelIndex);
panelType=panelTypes.Item(configPanelIndex);
configPanelHeight=0;
switch (panelType)
{
case 1:
{
GroupedConfigItemsPanel *thisPanel;
thisPanel=(GroupedConfigItemsPanel *)configItems.Item(configPanelIndex);
configPanelHeight=thisPanel->PreferredHeight();
}
break;
case 2:
{
GenericNumberedConfigPanel *thisPanel;
thisPanel=(GenericNumberedConfigPanel *)configItems.Item(configPanelIndex);
configPanelHeight=dialogHeight-yPosition;
}
break;
default:
configPanelHeight=dialogHeight-yPosition;
break;
}
if (configPanelHeight<10)
{
configPanelHeight=10;
}
configPanel->SetSize(0,yPosition,configPanelWidth,configPanelHeight);
// Move to the next panel
yPosition+=configPanelHeight;
}
}