This repository was archived by the owner on May 27, 2026. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathdynaCRUD.cpp
More file actions
242 lines (191 loc) · 9.58 KB
/
Copy pathdynaCRUD.cpp
File metadata and controls
242 lines (191 loc) · 9.58 KB
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
//---------------------------------------------------------------------------
#pragma hdrstop
#include "dynaCRUD.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
dynaCRUD::dynaCRUD(TWRForm *ParentWindow)
{
parentWindow = ParentWindow;
btns_n_chbxs = new std::vector<workingControl>;
};
bool dynaCRUD::LoadPanels(TWRForm *ParentForm)
{
TIniFile *winrusIni = new TIniFile(GetCurrentDir() + "\\winr0x2.conf");
TStringList *panelsList = new TStringList();
winrusIni->ReadSectionValues("Panels", panelsList);
TStringList *sectionsList = new TStringList();
winrusIni->ReadSections(sectionsList);
// int elemCount = sectionsList->Count;
// îñòàëîñü ñ âåðñèè 0.01:
int controlLeft = winrusIni->ReadInteger("Panels.First", "Left", 112);
int controlTop = winrusIni->ReadInteger("Panels.First", "Top", 48);
int controlHeight = winrusIni->ReadInteger("Panels.First", "Height", 289);
int controlWidth = winrusIni->ReadInteger("Panels.First", "Width", 345);
std::pair<String, TPanel*> rbPair;
// Dyn. creating Left Slider widget and Panels
for (int i = 0; i < panelsList->Count; ++i)
{
TPanel *panelFromIni = new TPanel(*ParentForm);
panelFromIni->Parent = ParentForm;
panelFromIni->Left = controlLeft;
panelFromIni->Top = controlTop;
panelFromIni->Height = controlHeight;
panelFromIni->Width = controlWidth;
panelFromIni->SendToBack();
panelFromIni->Font->Color = clWhite;
panelFromIni->Color = clNavy;
panelFromIni->BorderStyle = bsSingle;
panelFromIni->Name = panelsList->Strings[i].SubString(0, panelsList->Strings[i].Pos("=")-1);
panelFromIni->Caption = "";
panelFromIni->SendToBack();
TRadioButton *rbFromIni = new TRadioButton(*ParentForm);
rbFromIni->Parent = ParentForm;
byte lineLength = panelsList->Strings[i].Length(); // "PanelWindows = Windows" | 23
byte rbCaption_eqSignPos = panelsList->Strings[i].Pos("=") + 1; // "PanelWindows =| 13
byte rbCaptionLength = lineLength - rbCaption_eqSignPos + 1; // we've get "| Windows"
rbFromIni->Caption = " " + panelsList->Strings[i].SubString(rbCaption_eqSignPos, rbCaptionLength) + " ";
rbFromIni->Top = 48 + i*24;
rbFromIni->Left = 8;
rbFromIni->Color = clNavy;
rbFromIni->Font->Color = clWhite;
AnsiString rbName = "rb" + (String)i;
rbFromIni->Name = rbName;
rbPair.first = rbName;
rbPair.second = panelFromIni;
rbFromIni->OnClick = parentWindow->func->RadioButtonClick;
rbPanels.insert(std::make_pair(rbName, panelFromIni));
// Îðãàíèçàöèÿ Tooltip
TBevel *bevelHoriz = new TBevel(panelFromIni);
bevelHoriz->Parent = panelFromIni;
bevelHoriz->Top = 248;
bevelHoriz->Height = 9;
bevelHoriz->Left = 112;
bevelHoriz->Width = 225;
bevelHoriz->Shape = bsBottomLine;
TLabel *textDynTooltip = new TLabel(panelFromIni);
textDynTooltip->Left = 120;
textDynTooltip->Top = 264;
textDynTooltip->Font->Color = clWhite;
textDynTooltip->Parent = panelFromIni;
textTooltip = textDynTooltip;
pair_rb_n_TooltipLabels.insert(std::make_pair(rbName, textDynTooltip));
radioButtons.push_back(rbFromIni);
};
delete winrusIni;
return false;
}
bool dynaCRUD::CreateButtons_nCheckboxes(TForm *ParentForm)
{
TIniFile *winrusIni = new TIniFile(GetCurrentDir() + "\\winr0x2.conf");
TStringList *panelsList = new TStringList();
winrusIni->ReadSectionValues("Panels", panelsList);
TStringList *sectionsList = new TStringList();
winrusIni->ReadSections(sectionsList);
int elemCount = sectionsList->Count;
// Reading the whole INI elements-file
for (int i = 1; i < elemCount; ++i) // '1' cause skip "Panels" section
{
workingControl *wElement = new workingControl();
wElement->Index = i-1;
AnsiString Section = sectionsList->Strings[i].c_str();
wElement->ControlName = "contrl" + parentWindow->func->toString<int>(i);
wElement->ComponentType = winrusIni->ReadString(Section, "ControlType", ctCheckbox).c_str();
wElement->Top = winrusIni->ReadInteger(Section, "Top", 0);
wElement->DataType = parentWindow->func->toDataType( winrusIni->ReadString(Section, "DataType", "String").c_str() );
std::string sParentPanel = winrusIni->ReadString(Section, "Parent", "ParentForm").c_str();
wElement->parentPanel = StringToTPanel(ParentForm, sParentPanel);
wElement->Left = winrusIni->ReadInteger(Section, "Left", 18);
wElement->Title = winrusIni->ReadString(Section, "Title", Section + "Title error").c_str();
wElement->ToolTip = winrusIni->ReadString(Section, "ToolTip", "No Tooltip").c_str();
wElement->RootKey = winrusIni->ReadString(Section, "RootKey", Section + "RootKey error").c_str();
wElement->Key = winrusIni->ReadString(Section, "Key", Section + "Key error").c_str();
wElement->Param = winrusIni->ReadString(Section, "Param", Section + "Param error").c_str();
wElement->Set = winrusIni->ReadString(Section, "Set", Section + "Set error").c_str();
wElement->Unset = winrusIni->ReadString(Section, "Unset", Section + "Unset error").c_str();
wElement->BrowseOn = winrusIni->ReadBool(Section, "BrowseOn", false);
btns_n_chbxs->push_back(*wElement);
}
// Dynamically creating checkboxes and buttons
for (unsigned short i = 0; i < elemCount-1; ++i) // '-1' cause skip "Panels" section
{
workingControl wcElement = btns_n_chbxs[0][i];
if (wcElement.ComponentType == ctCheckbox)
{
TCheckBox *cbHandle = createControl<TCheckBox>(&wcElement);
cbHandle->OnMouseMove = &(parentWindow->func->cbMouseMove);
std::string readSet;
// Åñëè Set-äàííûå ñîâïàäàþò ñ òåì, ÷òî â ðååñòðå - ñòàâèì ãàëî÷êó:
switch (wcElement.DataType)
{
case dtString:
readSet = reg::ReadString(wcElement.RootKey, wcElement.Key, wcElement.Param, wcElement.Unset);;
break;
case dtDWORD:
readSet = reg::ReadInt(wcElement.RootKey, wcElement.Key, wcElement.Param, wcElement.Unset);
break;
case dtBinary:
readSet = reg::ReadBinary(wcElement.RootKey, wcElement.Key, wcElement.Param, wcElement.Unset);
break;
}
if(readSet == wcElement.Set)
cbHandle->State = cbChecked;
//cbHandle->WindowProc = &WndProc;
cbHandle->OnClick = parentWindow->func->CheckBoxClick;
}
if (wcElement.ComponentType == ctButton)
{
TButton *btnHandle = createControl<TButton>(&wcElement);
// createControl<TButton>(&wcElement)->OnClick = ButtonClick;
btnHandle->OnMouseMove = &(parentWindow->func->BtnMouseMove);
btnHandle->OnClick = parentWindow->func->ButtonClick;
}
};
delete winrusIni;
return false;
}
void dynaCRUD::HandlerSetter(workingControl elm, int Value)
{
// WriteDecimalInt?
}
void dynaCRUD::HandlerSetter(workingControl elm, std::string Value)
{
reg::WriteString(elm.RootKey, elm.Key, elm.Param, parentWindow->edtRegistryValue->Text.c_str());
}
void dynaCRUD::HandlerSetter(workingControl elm, bool Value) // for Checkboxes
{
//String sValueToSet = IsChecked ? elm.Set : elm.Unset;
switch (elm.DataType)
{
case dtString:
reg::WriteString(elm.RootKey, elm.Key, elm.Param, Value ? elm.Set : elm.Unset);
break;
case dtBinary:
// bitset<8> RValue = Value ? reg::stringToBitset(elm.Set) : reg::stringToBitset(elm.Unset);
reg::Write_REG_BINARY(elm.RootKey, elm.Key, elm.Param, Value ? elm.Set : elm.Unset);
break;
case dtDWORD:
reg::WriteInt(elm.RootKey, elm.Key, elm.Param, Value ? atoi(elm.Set.c_str()) : atoi(elm.Unset.c_str()));
break;
}
}
TPanel* dynaCRUD::StringToTPanel(TForm *ParentForm, std::string str_PanelFromIniFile)
{
for (int i = 0; i < ParentForm->ControlCount; ++i)
{
// Let us extract the control at index i
TControl *control = ParentForm->Controls[i];
// Now we want to test whether this is any specific type, for instance a
// TEdit or any TEdit descendant.
TPanel *panel = dynamic_cast<TPanel *>(control);
// If this control is a TPanel or any control deriving from it, we will have
// a pointer to it, if this is any other type, we will be left with a zero
// pointer.
if (panel)
{
// This is a TPanel control... we can now access TPanel's only properties
if(str_PanelFromIniFile == panel->Name.c_str())
return panel;
}
}
return NULL;
};