-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchildhood.cpp
More file actions
349 lines (282 loc) · 10.1 KB
/
childhood.cpp
File metadata and controls
349 lines (282 loc) · 10.1 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
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
338
339
340
341
342
343
344
345
346
347
348
349
/////////////////////////////////////////////////////////////////////////////
// Name: childhood.cpp
// Purpose:
// Author: Thackev D.V., Talipov S.N.
// Modified by:
// Created: Sun Apr 13 19:29:16 2025
// RCS-ID:
// Copyright: Thackev D.V., Talipov S.N.
// Licence:
/////////////////////////////////////////////////////////////////////////////
// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif
////@begin includes
#include "greeting.h"
#include "school.h"
////@end includes
#include "childhood.h"
#include "DialogBlocks_5Win.h"
////@begin XPM images
#include "teacher.xpm"
#include "smile.xpm"
////@end XPM images
/*
* Childhood type definition
*/
IMPLEMENT_CLASS(Childhood, wxFrame)
/*
* Childhood event table definition
*/
BEGIN_EVENT_TABLE(Childhood, wxFrame)
////@begin Childhood event table entries
EVT_CLOSE( Childhood::OnCloseWindow )
EVT_RADIOBOX( ID_RADIOBOX, Childhood::OnRadioboxSelected )
EVT_BUTTON( ID_CHILDHOOD_BTN_BACK, Childhood::OnChildhoodBtnBackClick )
EVT_BUTTON( ID_CHILDHOOD_BTN_NEXT, Childhood::OnChildhoodBtnNextClick )
////@end Childhood event table entries
END_EVENT_TABLE()
/*
* Childhood constructors
*/
Childhood::Childhood()
{
Init();
}
Childhood::Childhood(wxWindow *parent, wxWindowID id, const wxString &caption, const wxPoint &pos, const wxSize &size, long style)
{
Init();
Create(parent, id, caption, pos, size, style);
}
/*
* Childhood creator
*/
bool Childhood::Create(wxWindow *parent, wxWindowID id, const wxString &caption, const wxPoint &pos, const wxSize &size, long style)
{
////@begin Childhood creation
wxFrame::Create( parent, id, caption, pos, size, style );
CreateControls();
SetIcon(GetIconResource(wxT("teacher.xpm")));
if (GetSizer())
{
GetSizer()->SetSizeHints(this);
}
Centre();
////@end Childhood creation
PostInit();
return true;
}
/*
* Childhood destructor
*/
Childhood::~Childhood()
{
////@begin Childhood destruction
////@end Childhood destruction
}
/*
* Member initialisation
*/
void Childhood::Init()
{
////@begin Childhood member initialisation
onBackClicked = false;
m_question_st = NULL;
m_radio_items = NULL;
m_selected_st = NULL;
m_btn_back = NULL;
m_btn_next = NULL;
////@end Childhood member initialisation
}
/*
* Control creation for Childhood
*/
void Childhood::CreateControls()
{
////@begin Childhood content construction
Childhood* itemFrame1 = this;
wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
itemFrame1->SetSizer(itemBoxSizer2);
m_question_st = new wxStaticText( itemFrame1, wxID_STATIC, wxT("Выберите любимую кашу"), wxDefaultPosition, wxDefaultSize, 0 );
m_question_st->SetFont(wxFont(15, wxFONTFAMILY_TELETYPE, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, false, wxT("Monospace")));
itemBoxSizer2->Add(m_question_st, 0, wxALIGN_LEFT|wxALL, 30);
wxBoxSizer* itemBoxSizer1 = new wxBoxSizer(wxHORIZONTAL);
itemBoxSizer2->Add(itemBoxSizer1, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
wxArrayString m_radio_itemsStrings;
m_radio_itemsStrings.Add(wxT("&Манная"));
m_radio_itemsStrings.Add(wxT("&Рисовая"));
m_radio_itemsStrings.Add(wxT("&Гороховая"));
m_radio_itemsStrings.Add(wxT("&Гречневая"));
m_radio_items = new wxRadioBox( itemFrame1, ID_RADIOBOX, wxEmptyString, wxDefaultPosition, wxDefaultSize, m_radio_itemsStrings, 1, wxRA_SPECIFY_ROWS );
m_radio_items->SetSelection(0);
m_radio_items->SetFont(wxFont(15, wxFONTFAMILY_TELETYPE, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, false, wxT("Monospace")));
itemBoxSizer1->Add(m_radio_items, 0, wxALIGN_CENTER_VERTICAL|wxLEFT, 25);
wxStaticBitmap* itemStaticBitmap1 = new wxStaticBitmap( itemFrame1, wxID_STATIC, itemFrame1->GetBitmapResource(wxT("smile.xpm")), wxDefaultPosition, wxSize(236, 236), 0 );
itemBoxSizer1->Add(itemStaticBitmap1, 0, wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT, 75);
m_selected_st = new wxStaticText( itemFrame1, wxID_STATIC, wxT("Выбрано:"), wxDefaultPosition, wxDefaultSize, 0 );
m_selected_st->SetForegroundColour(wxColour(0, 0, 0));
m_selected_st->SetBackgroundColour(wxColour(229, 229, 229));
m_selected_st->SetFont(wxFont(13, wxFONTFAMILY_TELETYPE, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, false, wxT("Monospace")));
itemBoxSizer2->Add(m_selected_st, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP, 25);
wxStaticLine* itemStaticLine6 = new wxStaticLine( itemFrame1, wxID_STATIC, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL );
itemBoxSizer2->Add(itemStaticLine6, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 10);
wxBoxSizer* itemBoxSizer3 = new wxBoxSizer(wxHORIZONTAL);
itemBoxSizer2->Add(itemBoxSizer3, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
m_btn_back = new wxButton( itemFrame1, ID_CHILDHOOD_BTN_BACK, wxT(" Назад "), wxDefaultPosition, wxDefaultSize, 0 );
m_btn_back->SetForegroundColour(wxColour(0, 0, 0));
m_btn_back->SetBackgroundColour(wxColour(173, 216, 230));
m_btn_back->SetFont(wxFont(15, wxFONTFAMILY_TELETYPE, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD, false, wxT("Monospace")));
itemBoxSizer3->Add(m_btn_back, 0, wxGROW|wxALL, 5);
wxStaticLine* itemStaticLine5 = new wxStaticLine( itemFrame1, wxID_STATIC, wxDefaultPosition, wxDefaultSize, wxLI_VERTICAL );
itemStaticLine5->SetName(wxT("Spacer"));
itemBoxSizer3->Add(itemStaticLine5, 0, wxALIGN_CENTER_VERTICAL|wxRIGHT, 200);
m_btn_next = new wxButton( itemFrame1, ID_CHILDHOOD_BTN_NEXT, wxT(" Вперед "), wxDefaultPosition, wxDefaultSize, 0 );
m_btn_next->SetForegroundColour(wxColour(26, 26, 26));
m_btn_next->SetBackgroundColour(wxColour(173, 216, 230));
m_btn_next->SetFont(wxFont(15, wxFONTFAMILY_TELETYPE, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD, false, wxT("Monospace")));
itemBoxSizer3->Add(m_btn_next, 0, wxGROW|wxALL, 5);
////@end Childhood content construction
}
// begin custom
void Childhood::PostInit()
{
idx_selected = 0;
selectedItem = wxEmptyString;
// Init variables to handle
selectedPrefix = m_selected_st->GetLabel();
wxCommandEvent dummy;
OnRadioboxSelected(dummy);
}
void Childhood::BeforeNextWindow()
{
//if (selectedItem.IsEmpty()) {
////wxLogMessage("[%s] [BeforeNextWindow] selected item is empty, skip...", __FUNCTION__);
// return;
//}
MWSApp& mwsapp = wxGetApp();
wxString question = m_question_st->GetLabel();
std::vector<wxString> questions = mwsapp.SplitString(mwsapp.GetQuestions());
std::vector<wxString> answers = mwsapp.SplitString(mwsapp.GetAnswers());
size_t idx = mwsapp.GetChildhoodIndex();
bool questionRepeat = false;
bool answerRepeat = false;
for (const auto& q : questions) {
if (q == question) {
questionRepeat = true;
////wxLogMessage("[%s] Question repeat detected: [%s]", __FUNCTION__, q);
break;
}
}
for (const auto& a : answers) {
if (a == selectedItem) {
answerRepeat = true;
////wxLogMessage("[%s] Answer repeat detected: [%s]", __FUNCTION__, a);
break;
}
}
if (questionRepeat && !answerRepeat) {
if (idx < answers.size()) {
answers[idx] = selectedItem;
}
}
else if (!questionRepeat && !answerRepeat) {
// Обновить или добавить answer
if (idx <= answers.size()) {
if (idx < answers.size())
answers[idx] = selectedItem;
else
answers.push_back(selectedItem);
}
// Обновить или добавить question
if (idx <= questions.size()) {
if (idx < questions.size())
questions[idx] = question;
else
questions.push_back(question);
}
}
mwsapp.SetQuestions(mwsapp.JoinString(questions));
mwsapp.SetAnswers(mwsapp.JoinString(answers));
////wxLogMessage("[%s] State synced -> Q: [%s] | A: [%s]", __FUNCTION__, mwsapp.GetQuestions(), mwsapp.GetAnswers());
}
// end custom
/*
* Should we show tooltips?
*/
bool Childhood::ShowToolTips()
{
return true;
}
/*
* Get bitmap resources
*/
wxBitmap Childhood::GetBitmapResource(const wxString &name)
{
// Bitmap retrieval
////@begin Childhood bitmap retrieval
wxUnusedVar(name);
if (name == wxT("smile.xpm"))
{
wxBitmap bitmap(f1e7b23cce114568b1ed2bf6de04ff6dic4QXBwfTfJPnqIn);
return bitmap;
}
return wxNullBitmap;
////@end Childhood bitmap retrieval
}
/*
* Get icon resources
*/
wxIcon Childhood::GetIconResource(const wxString &name)
{
// Icon retrieval
////@begin Childhood icon retrieval
wxUnusedVar(name);
if (name == wxT("teacher.xpm"))
{
wxIcon icon(teacher);
return icon;
}
return wxNullIcon;
////@end Childhood icon retrieval
}
void Childhood::OnChildhoodBtnBackClick(wxCommandEvent &event)
{
Destroy();
this->GetParent()->Show(true);
}
/*
* wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_BUTTON_NEXT
*/
void Childhood::OnChildhoodBtnNextClick(wxCommandEvent &event)
{
BeforeNextWindow();
////@begin wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_BUTTON_NEXT in Childhood.
// Before editing this code, remove the block markers.
School *window = new School(this);
window->Show(true);
////@end wxEVT_COMMAND_BUTTON_CLICKED event handler for ID_BUTTON_NEXT in Childhood.
Show(false);
}
/*
* wxEVT_COMMAND_RADIOBOX_SELECTED event handler for ID_RADIOBOX
*/
void Childhood::OnRadioboxSelected(wxCommandEvent &event)
{
idx_selected = m_radio_items->GetSelection();
selectedItem = m_radio_items->GetString(idx_selected);
selectedMessage = wxString::Format("%s %s", selectedPrefix, selectedItem);
m_selected_st->SetLabel(selectedMessage);
}
/*
* wxEVT_CLOSE_WINDOW event handler for ID_CHILDHOOD
*/
void Childhood::OnCloseWindow( wxCloseEvent& event )
{
Destroy();
this->GetParent()->Close(true);
}