-
Notifications
You must be signed in to change notification settings - Fork 2
/
GenericNumberedConfigPanel.cpp
162 lines (137 loc) · 3.48 KB
/
GenericNumberedConfigPanel.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
// Statsgen Includes
#include "GenericNumberedConfigPanel.h"
#include "GenericConfigPanel.h"
#include "GlobalStatistics.h"
BEGIN_EVENT_TABLE(GenericNumberedConfigPanel, wxPanel)
EVT_SIZE(GenericNumberedConfigPanel::OnResize)
EVT_COMBOBOX(WINDOW_ID_LISTBOX_CONFIGITEMS,GenericNumberedConfigPanel::OnListItemSelected)
EVT_TEXT(WINDOW_ID_TEXTCTRL_CONFIGVALUE,GenericNumberedConfigPanel::OnTextChange)
END_EVENT_TABLE()
GenericNumberedConfigPanel::GenericNumberedConfigPanel(
GenericConfigPanel * (*newPanelFunctionIn)(wxWindow *parentID,wxString &listID),
wxString &listGroupIn,
wxString &listGroupPrefixIn,
wxWindow *parent,
wxWindowID id,
const wxPoint &pos,
const wxSize &size,
long style,
const wxString &name):
wxPanel(parent,
id,
pos,
size,
style,
name)
{
configPanel=NULL;
listGroup=listGroupIn;
listGroupPrefix=listGroupPrefixIn;
newPanelFunction=newPanelFunctionIn;
}
bool GenericNumberedConfigPanel::UpdateFromTrigger()
{
if (configPanel!=NULL)
{
configPanel->UpdateFromTrigger();
}
return (true);
}
void GenericNumberedConfigPanel::OnTextChange(wxCommandEvent &event)
{
UpdateFromTrigger();
if (GetParent()!=NULL)
{
GetParent()->AddPendingEvent(event);
}
}
void GenericNumberedConfigPanel::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();
configPanel=NULL;
}
currentSelection=idList.GetValue();
if (currentSelection.Length()>0)
{
configPanel=newPanelFunction(this,currentSelection);
configPanel->OnResize(dummyEvent);
SetConfigPanel(configPanel);
}
OnResize(dummyEvent);
}
GenericNumberedConfigPanel::~GenericNumberedConfigPanel()
{
}
void GenericNumberedConfigPanel::SetConfigPanel(GenericConfigPanel *configPanelIn)
{
configPanel=configPanelIn;
}
void GenericNumberedConfigPanel::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
);
OnListItemSelected(event);
}
void GenericNumberedConfigPanel::OnResize(wxSizeEvent &event)
{
wxString msg;
int dialogWidth;
int dialogHeight;
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();
configPanelHeight=dialogHeight-listHeight;
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);
}
}