summaryrefslogtreecommitdiff
path: root/support/dktools/WxdkdrawDlgTextInput.wxc
blob: 1b5e703727dfffb5bf32e3e5ad993f4b4937c4e9 (plain)
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
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
%%	options
copyright owner	= Dirk Krause
copyright year	= 2019-xxxx
SPDX-License-Identifier:	BSD-3-Clause


%%	wx-gui

type		= dialog
contents	= sizerHorizontal

[wxBoxSizer		sizerHorizontal]
proportion	=	1
grow		=	yes
direction	=	horizontal
contents	=	$space(10)
contents	=	sizerVertical
contents	=	$space(10)

[wxBoxSizer		sizerVertical]
direction	=	vertical
grow		=	yes
proportion	=	1
contents	=	$space(10)
contents	=	sizerContents		centered-x
contents	=	$space(10)
contents	=	sizerButtons		centered-x
contents	=	$space(10)

[wxBoxSizer		sizerContents]
direction	=	vertical
grow		=	yes
proportion	=	1
contents	=	labelExport			left
contents	=	textExport			left
contents	=	$space(10)
contents	=	labelScreen			left
contents	=	textScreen			left

[wxStaticText	labelExport]
text		=	pLocTexts[396]

[wxTextCtrl		textExport]
proportion	=	1
grow		=	yes
id			=	WXD_ID_EXPORT_TEXT
tip			=	pLocTexts[398]
text		=	pNlTexts[20]
text style	=	enter

[wxStaticText	labelScreen]
text		=	pLocTexts[397]

[wxTextCtrl		textScreen]
proportion	=	1
grow		=	yes
id			=	WXD_ID_SCREEN_TEXT
tip			=	pLocTexts[399]
text		=	pNlTexts[20]
text style	=	enter

[wxStdDialogButtonSizer	sizerButtons]
contents	=	buttonOK
contents	=	buttonCancel

[wxButton		buttonOK]
id			=	wxID_OK
text		=	pLocTexts[259]
tip			=	pLocTexts[401]

[wxButton		buttonCancel]
id			=	wxID_CANCEL
text		=	pLocTexts[260]
tip			=	pLocTexts[402]


%%	header start

#ifndef	WXDKDRAW_H_INCLUDED
#include "wxdkdraw.h"
#endif

#ifndef	WXDKDRAWFRAME_H_INCLUDED
#include "WxdkdrawFrame.h"
#endif


%%	class start


/**	Text input dialog to create or modify a text label.
*/
class WxdkdrawDlgTextInput : public wxDialog
{
	private:

		/**	Events to handle.
		*/
#if	wxCHECK_VERSION(3,0,0)
		wxDECLARE_EVENT_TABLE();
#else
		DECLARE_EVENT_TABLE()
#endif

	protected:

		/**	Red colour for label.
		*/
		wxColour		 		  m_cRed;

		/**	Localized texts.
		*/
		wxChar const * const	 *m_pLocTexts;

		/**	Parent frame (main window).
		*/
		WxdkdrawFrame			 *m_pParent;

		/**	Address of export text pointer.
		*/
		wxChar					**m_ppExport;

		/**	Address of screen text pointer.
		*/
		wxChar					**m_ppScreen;

		/**	Error report for out of memory.
		*/
		dk4_er_t				 *m_pErrorReport;

		/**	Text object is LaTeX special text.
		*/
		bool					  m_bLaTeX;

	public:

		/**	Window IDs.
		*/
		enum {
			WXD_ID_EXPORT_TEXT = (wxID_HIGHEST + 1),	/**< Export text. */
			WXD_ID_SCREEN_TEXT							/**< Screen text. */
		};

%%	class end

	public:

		/**	Constructor.
			@param	pParent		Parent frame (main window).
			@param	pLocTexts	Localized text fragments.
			@param	pNlTexts	Not localized text fragments.
			@param	ppExport	Address of export text pointer.
			@param	ppScreen	Address of screen text pointer.
			@param	bLaTeX		Flag: LaTeX special text object.
		*/
		WxdkdrawDlgTextInput(
			WxdkdrawFrame			 *pParent,
			wxChar const * const	 *pLocTexts,
			wxChar const * const	 *pNlTexts,
			wxChar					**ppExport,
			wxChar					**ppScreen,
			bool					  bLaTeX,
			dk4_er_t				 *pErrorReport
		);

		/**	OK button handler.
			@param	event	Event to process.
		*/
		void
		OnOK(wxCommandEvent & event);
		
		/**	Cancel button handler.
			@param	event	Event to process.
		*/
		void
		OnCancel(wxCommandEvent & event);

		/**	Enter in export text handler.
			@param	event	Event to process.
		*/
		void
		OnExportText(wxCommandEvent & event);

		/**	Enter in screen text handler.
			@param	event	Event to process.
		*/
		void
		OnScreenText(wxCommandEvent & event);

	protected:

		/**	Check whether sufficient input available.
			@return	True on success, false on error.
		*/
		bool
		CheckSufficientInput(void);

		/**	Transfer data from text fields to the destination pointers.
		*/
		void
		TransferInputData(void);
};

%%	header end


%%	module start

#ifndef	WXDKDRAWDLGTEXTINPUT_H_INCLUDED
#include "WxdkdrawDlgTextInput.h"
#endif


$!trace-include

/**	Assign methods to event IDs.
*/
#if	wxCHECK_VERSION(3,0,0)
wxBEGIN_EVENT_TABLE(WxdkdrawDlgTextInput,wxDialog)
#else
BEGIN_EVENT_TABLE(WxdkdrawDlgTextInput,wxDialog)
#endif
	EVT_BUTTON(\
		wxID_OK,\
		WxdkdrawDlgTextInput::OnOK\
	)
	EVT_BUTTON(\
		wxID_CANCEL,\
		WxdkdrawDlgTextInput::OnCancel\
	)
	EVT_TEXT_ENTER(\
		WXD_ID_EXPORT_TEXT,\
		WxdkdrawDlgTextInput::OnExportText\
	)
	EVT_TEXT_ENTER(\
		WXD_ID_SCREEN_TEXT,\
		WxdkdrawDlgTextInput::OnScreenText\
	)
#if	wxCHECK_VERSION(3,0,0)
wxEND_EVENT_TABLE()
#else
END_EVENT_TABLE()
#endif


%%	constructor start
WxdkdrawDlgTextInput::WxdkdrawDlgTextInput(
	WxdkdrawFrame			 *pParent,
	wxChar const * const	 *pLocTexts,
	wxChar const * const	 *pNlTexts,
	wxChar					**ppExport,
	wxChar					**ppScreen,
	bool					  bLaTeX,
	dk4_er_t				 *pErrorReport
) : wxDialog(
	pParent, wxID_ANY, pLocTexts[400],
	wxDefaultPosition, wxDefaultSize,
	(
		((wxDEFAULT_DIALOG_STYLE) | (wxRESIZE_BORDER))
#if	0
		& (~(wxRESIZE_BORDER))
#endif
		& (~(wxCLOSE_BOX))
		& (~(wxSYSTEM_MENU))
	)
),
m_cRed(0x7F, 0, 0)
{
	m_pParent = pParent;
	m_bLaTeX  = bLaTeX;
	m_ppExport = ppExport;
	m_ppScreen = ppScreen;
	m_pLocTexts = pLocTexts;
	m_pErrorReport = pErrorReport;
%%	constructor end
	if (dkctGUILayoutOK) {
		if (NULL != *ppExport) {
			wxString str(*ppExport);
			{
				textExport->SetValue(str);
			}
		}
		else {
			textExport->SetValue(pNlTexts[19]);
		}
		if ((bLaTeX) && (NULL != *ppScreen)) {
			wxString str(*ppScreen);
			{
				textScreen->SetValue(str);
			}
		}
		else {
			textScreen->SetValue(pNlTexts[19]);
		}
		if (!(bLaTeX)) {
			textScreen->Enable(false);
		}
#if	0
		panelContents->Layout();
#endif
		Layout();
#if	0
		wxSize	minsize = GetMinSize();
		SetMaxSize(minsize);
#endif
	}
}


%%	module end



bool
WxdkdrawDlgTextInput::CheckSufficientInput(void)
{
	bool		back	= false;
	wxString	exportString = textExport->GetValue();
	{
		wxCStrData	exportCstr = exportString.c_str();
		{
			wxChar const *exportPtr = (wxChar const *)exportCstr;
			if (NULL != exportPtr) {
				if ((size_t)0U < dk4strx_len(exportPtr)) {
					back = true;
				}
			}
		}
	}
	return back;
}



void
WxdkdrawDlgTextInput::TransferInputData(void)
{
	bool		successExport	=	false;
	wxString	exportString	=	textExport->GetValue();
	{
		wxCStrData	exportCstr	=	exportString.c_str();
		{
			wxChar const	*exportPtr	=	(wxChar const *)exportCstr;
			if (NULL != exportPtr) {
				if ((size_t)0U < dk4strx_len(exportPtr)) {
					wxChar	*exportNew	=	dk4strx_dup(exportPtr, NULL);
					if (NULL != exportNew) {
						if (NULL != *m_ppExport) {
							dk4mem_free(*m_ppExport);
						}
						*m_ppExport = exportNew;
						successExport = true;
					}
					else {
						/* ERROR: Memory */
						dk4error_set_simple_error_code(
							m_pErrorReport, DK4_E_MEMORY_ALLOCATION_FAILED
						);
					}
				}
				else {
					/* ERROR: No text entered */
					labelExport->SetForegroundColour(m_cRed);
					labelExport->SetLabel(m_pLocTexts[642]);
					textExport->SetFocus();
					Refresh();
					Update();
				}
			}
			else {
				/* ERROR: No text entered */
				labelExport->SetForegroundColour(m_cRed);
				labelExport->SetLabel(m_pLocTexts[642]);
				textExport->SetFocus();
				Refresh();
				Update();
			}
		}
	}
	if (successExport && m_bLaTeX) {
		wxString	screenString	=	textScreen->GetValue();
		{
			wxCStrData	screenCstr	=	screenString.c_str();
			{
				wxChar const	*screenPtr	=	(wxChar const *)screenCstr;
				if (NULL != screenPtr) {
					if ((size_t)0U < dk4strx_len(screenPtr)) {
						wxChar *screenNew	=	dk4strx_dup(screenPtr, NULL);
						if (NULL != screenNew) {
							if (NULL != *m_ppScreen) {
								dk4mem_free(*m_ppScreen);
							}
							*m_ppScreen = screenNew;
						}
						else {
							/* ERROR: Memory */
							dk4error_set_simple_error_code(
								m_pErrorReport, DK4_E_MEMORY_ALLOCATION_FAILED
							);

						}
					}
					else {
						/* No text entered */
					}
				}
				else {
					/* No text entered */
				}
			}
		}
	}
	else {
		if (NULL != *m_ppScreen) {
			dk4mem_free(*m_ppScreen);
			*m_ppScreen = NULL;
		}
	}
}



void
WxdkdrawDlgTextInput::OnOK(wxCommandEvent & WXUNUSED(event))
{
	if (CheckSufficientInput()) {
		TransferInputData();
		if(IsModal()) {
			EndModal(wxID_OK);
		}
		else {
			SetReturnCode(wxID_OK);
			Show(false);
		}
	}
	else {
		/* TODO: Return to export text */
		labelExport->SetForegroundColour(m_cRed);
		labelExport->SetLabel(m_pLocTexts[642]);
		textExport->SetFocus();
		Refresh();
		Update();
	}
}



void
WxdkdrawDlgTextInput::OnCancel(wxCommandEvent & WXUNUSED(event))
{
	if(IsModal()) {
		EndModal(wxID_CANCEL);
	}
	else {
		SetReturnCode(wxID_CANCEL);
		Show(false);
	}
}



void
WxdkdrawDlgTextInput::OnExportText(wxCommandEvent & WXUNUSED(event))
{
	$? "+ OnExportText"
	if (m_bLaTeX) {
		textScreen->SetFocus();
	}
	else {
		if (CheckSufficientInput()) {
			TransferInputData();
			if(IsModal()) {
				EndModal(wxID_OK);
			}
			else {
				SetReturnCode(wxID_OK);
				Show(false);
			}
		}
		else {
			/* TODO: Return to export text */
			labelExport->SetForegroundColour(m_cRed);
			labelExport->SetLabel(m_pLocTexts[642]);
			textExport->SetFocus();
			Refresh();
			Update();
		}
	}
	$? "- OnExportText"
}



void
WxdkdrawDlgTextInput::OnScreenText(wxCommandEvent & WXUNUSED(event))
{
	$? "+ OnScreenText"
	if (CheckSufficientInput()) {
		TransferInputData();
		if(IsModal()) {
			EndModal(wxID_OK);
		}
		else {
			SetReturnCode(wxID_OK);
			Show(false);
		}
	}
	else {
		/* TODO: Return to export text */
		labelExport->SetForegroundColour(m_cRed);
		labelExport->SetLabel(m_pLocTexts[642]);
		textExport->SetFocus();
		Refresh();
		Update();
	}
	$? "- OnScreenText"
}




/* vim: set ai sw=4 ts=4 : */