summaryrefslogtreecommitdiff
path: root/support/dktools/WxdkdrawDlgFontName.wxc
blob: 963dd82b5c9ef52a1897a4f1998b4d80b06f19af (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
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
%%	options
copyright owner	= Dirk Krause
copyright year	= 2019-xxxx
SPDX-License-Identifier:	BSD-3-Clause

%%	wx-gui

type		= dialog
contents	= sizerHorizontal

[wxBoxSizer		sizerHorizontal]
direction	=	horizontal
contents	=	$space(10)
contents	=	sizerVertical
contents	=	$space(10)

[wxBoxSizer		sizerVertical]
direction	=	vertical
contents	=	$space(10)
contents	=	sizerInputs			centered-x
contents	=	$space(10)
contents	=	sizerResult			centered-x
contents	=	$space(10)
contents	=	sizerButtons		centered-x
contents	=	$space(10)

[wxGridBagSizer	sizerInputs]
grid		=	5 5
contents	=	b00					 0	 0	 1	 1	left	centered-y
contents	=	b01					 .	+1	 1	 1	left	centered-y
contents	=	b02					 .	+1	 1	 1	left	centered-y
contents	=	b03					 .	+1	 1	 1	left	centered-y
contents	=	b04					+1	 0	 1	 1	left	centered-y
contents	=	b05					 .	+1	 1	 1	left	centered-y
contents	=	b06					 .	+1	 1	 1	left	centered-y
contents	=	b07					 .	+1	 1	 1	left	centered-y
contents	=	b08					+1	 0	 1	 1	left	centered-y
contents	=	b09					 .	+1	 1	 1	left	centered-y
contents	=	b10					 .	+1	 1	 1	left	centered-y
contents	=	$space(10)			+1	 0	 1	 1	left	centered-y
contents	=	checkboxBold		+1	 0	 1	 4	left	centered-y
contents	=	checkboxItalic		+1	 0	 1	 1	left	centered-y
contents	=	$space(10)			+1	 0	 1	 1	left	centered-y

[wxRadioButton	b00]
id			=	WXD_ID_FONT_00
text		=	pTexts[352]
tip			=	pTexts[352]
start group	=	yes

[wxRadioButton	b01]
id			=	WXD_ID_FONT_01
text		=	pTexts[353]
tip			=	pTexts[353]

[wxRadioButton	b02]
id			=	WXD_ID_FONT_02
text		=	pTexts[354]
tip			=	pTexts[354]

[wxRadioButton	b03]
id			=	WXD_ID_FONT_03
text		=	pTexts[355]
tip			=	pTexts[355]

[wxRadioButton	b04]
id			=	WXD_ID_FONT_04
text		=	pTexts[356]
tip			=	pTexts[356]

[wxRadioButton	b05]
id			=	WXD_ID_FONT_05
text		=	pTexts[357]
tip			=	pTexts[357]

[wxRadioButton	b06]
id			=	WXD_ID_FONT_06
text		=	pTexts[358]
tip			=	pTexts[358]

[wxRadioButton	b07]
id			=	WXD_ID_FONT_07
text		=	pTexts[359]
tip			=	pTexts[359]

[wxRadioButton	b08]
id			=	WXD_ID_FONT_08
text		=	pTexts[360]
tip			=	pTexts[360]

[wxRadioButton	b09]
id			=	WXD_ID_FONT_09
text		=	pTexts[361]
tip			=	pTexts[361]

[wxRadioButton	b10]
id			=	WXD_ID_FONT_10
text		=	pTexts[362]
tip			=	pTexts[362]

[wxCheckBox		checkboxBold]
id			=	WXD_ID_FONT_BOLD
text		=	pTexts[363]

[wxCheckBox		checkboxItalic]
id			=	WXD_ID_FONT_ITALIC
text		=	pTexts[364]

[wxBoxSizer		sizerResult]
direction	=	vertical
contents	=	labelFontname		left
contents	=	$space(5)
contents	=	bitmapFontname		centered-x

[wxStaticText	labelFontname]
text		=	pTexts[352]

[wxStaticBitmap	bitmapFontname]
bitmap		=	wxBitmap(pImages[0])

[wxStdDialogButtonSizer	sizerButtons]
contents	=	buttonOK
contents	=	buttonCancel

[wxButton		buttonOK]
id			=	wxID_OK
text		=	pTexts[365]
tip			=	pTexts[366]

[wxButton		buttonCancel]
id			=	wxID_CANCEL
text		=	pTexts[297]
tip			=	pTexts[298]


%%	header start


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

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


%%	class start

/**	Dialog to modify font.
*/
class WxdkdrawDlgFontName : public wxDialog
{

	private:

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

%%	class end

	protected:

		/**	Applications main frame.
		*/
		WxdkdrawFrame			*m_pParent;

		/**	Object to modify.
		*/
		Wxd_object_t			*m_pObject;

		/**	Localized text fragments.
		*/
		wxChar const * const	*m_pTexts;

		/**	Images to show fonts.
		*/
		const char ** const		*m_pImages;

		/**	Original font number when opening dialog.
		*/
		uint8_t					 m_uOldFontnumber;

		/**	Complete font number (family+bold+italic).
		*/
		uint8_t					 m_uFontnumber;

		/**	Base font number, ignoring bold/italic.
		*/
		uint8_t					 m_uFontbase;

		/**	Flag: Modify drawing object (style default object otherwise).
		*/
		bool					 m_bRealObj;

	public:

		/**	Window IDs used in GUI.
		*/
		enum {
			WXD_ID_FONT_00	= (wxID_HIGHEST + 1),	/**< Times. */
			WXD_ID_FONT_01 ,						/**< AvantGarde. */
			WXD_ID_FONT_02 ,						/**< Bookman. */
			WXD_ID_FONT_03 ,						/**< Courier. */
			WXD_ID_FONT_04 ,						/**< Helvetica. */
			WXD_ID_FONT_05 ,						/**< HelveticaNarrow. */
			WXD_ID_FONT_06 ,						/**< NewCenturySchoolbk. */
			WXD_ID_FONT_07 ,						/**< Palatino. */
			WXD_ID_FONT_08 ,						/**< Symbol. */
			WXD_ID_FONT_09 ,						/**< ZapfChancery. */
			WXD_ID_FONT_10 ,						/**< ZapfDingbats. */
			WXD_ID_FONT_BOLD ,						/**< Bold font. */
			WXD_ID_FONT_ITALIC						/**< Italic font. */
		};

	public:

		/**	Constructor.
			@param	pParent		Applications main frame.
			@param	pObject		Object to modify.
			@param	bRealObj	Flag: Real object (style object otherwise).
			@param	pTexts		Localized text fragments.
			@param	pImages		Images for line style buttons.
		*/

		WxdkdrawDlgFontName(
			WxdkdrawFrame			*pParent,
			Wxd_object_t			*pObject,
			bool					 bRealObj,
			wxChar const * const	*pTexts,
			const char ** const		*pImages
		);

		/**	Handler for radio button click.
			@param	event	Event to process.
		*/
		void
		OnFontFamily(wxCommandEvent & event);

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

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

		/**	Bold checkbox handler.
			@param	event	Event to process.
		*/
		void
		OnBold(wxCommandEvent & event);

		/**	Italic checkbox handler.
			@param	event	Event to process.
		*/
		void
		OnItalic(wxCommandEvent & event);

	protected:

		/**	Update UI after click on font family radio button
			or bold or italic checkbox.
		*/
		void
		UpdateFontInformation(void);

};


%%	header end

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

%%	module start


#ifndef	WXDKDRAWDLGFONTNAME_H_INCLUDED
#include "WxdkdrawDlgFontName.h"
#endif



$!trace-include


/**	Assign event handlers to window IDs.
*/
#if	wxCHECK_VERSION(3,0,0)
wxBEGIN_EVENT_TABLE(WxdkdrawDlgFontName,wxDialog)
#else
BEGIN_EVENT_TABLE(WxdkdrawDlgFontName,wxDialog)
#endif
	EVT_RADIOBUTTON(\
		WxdkdrawDlgFontName::WXD_ID_FONT_00,\
		WxdkdrawDlgFontName::OnFontFamily\
	)
	EVT_RADIOBUTTON(\
		WxdkdrawDlgFontName::WXD_ID_FONT_01,\
		WxdkdrawDlgFontName::OnFontFamily\
	)
	EVT_RADIOBUTTON(\
		WxdkdrawDlgFontName::WXD_ID_FONT_02,\
		WxdkdrawDlgFontName::OnFontFamily\
	)
	EVT_RADIOBUTTON(\
		WxdkdrawDlgFontName::WXD_ID_FONT_03,\
		WxdkdrawDlgFontName::OnFontFamily\
	)
	EVT_RADIOBUTTON(\
		WxdkdrawDlgFontName::WXD_ID_FONT_04,\
		WxdkdrawDlgFontName::OnFontFamily\
	)
	EVT_RADIOBUTTON(\
		WxdkdrawDlgFontName::WXD_ID_FONT_05,\
		WxdkdrawDlgFontName::OnFontFamily\
	)
	EVT_RADIOBUTTON(\
		WxdkdrawDlgFontName::WXD_ID_FONT_06,\
		WxdkdrawDlgFontName::OnFontFamily\
	)
	EVT_RADIOBUTTON(\
		WxdkdrawDlgFontName::WXD_ID_FONT_07,\
		WxdkdrawDlgFontName::OnFontFamily\
	)
	EVT_RADIOBUTTON(\
		WxdkdrawDlgFontName::WXD_ID_FONT_08,\
		WxdkdrawDlgFontName::OnFontFamily\
	)
	EVT_RADIOBUTTON(\
		WxdkdrawDlgFontName::WXD_ID_FONT_09,\
		WxdkdrawDlgFontName::OnFontFamily\
	)
	EVT_RADIOBUTTON(\
		WxdkdrawDlgFontName::WXD_ID_FONT_10,\
		WxdkdrawDlgFontName::OnFontFamily\
	)
	EVT_CHECKBOX(\
		WxdkdrawDlgFontName::WXD_ID_FONT_BOLD,\
		WxdkdrawDlgFontName::OnBold\
	)
	EVT_CHECKBOX(\
		WxdkdrawDlgFontName::WXD_ID_FONT_ITALIC,\
		WxdkdrawDlgFontName::OnItalic\
	)
	EVT_BUTTON(\
		wxID_OK,\
		WxdkdrawDlgFontName::OnOK\
	)
	EVT_BUTTON(\
		wxID_CANCEL,\
		WxdkdrawDlgFontName::OnCancel\
	)
#if	wxCHECK_VERSION(3,0,0)
wxEND_EVENT_TABLE()
#else
END_EVENT_TABLE()
#endif


%%	constructor start

WxdkdrawDlgFontName::WxdkdrawDlgFontName(
	WxdkdrawFrame			*pParent,
	Wxd_object_t			*pObject,
	bool					 bRealObj,
	wxChar const * const	*pTexts,
	const char ** const		*pImages
) : wxDialog(
	pParent, wxID_ANY, pTexts[296],
	wxDefaultPosition, wxDefaultSize,
	(
		(wxDEFAULT_DIALOG_STYLE)
		& (~(wxRESIZE_BORDER))
		& (~(wxCLOSE_BOX))
		& (~(wxSYSTEM_MENU))
	)
)
{
	m_pParent	= pParent;
	m_pObject	= pObject;
	m_bRealObj	= bRealObj;
	m_pTexts	= pTexts;
	m_pImages	= pImages;
	m_uOldFontnumber = m_uFontnumber = (pObject->det).t.find;
	m_uFontbase = m_uFontnumber;
	if (32U > m_uFontnumber) {
		m_uFontbase = 4U * (m_uFontbase / 4U);
	}
%%	constructor end
	if (dkctGUILayoutOK) {
		/*
			Fix dialog size
		*/
		wxSize	minsize = GetMinSize();
		SetMaxSize(minsize);
		/*
			Transfer font from drawing object to UI elements
		*/
		labelFontname->SetLabel(pTexts[299 + m_uFontnumber]);
		bitmapFontname->SetBitmap(wxBitmap(pImages[m_uFontnumber]));
		switch (m_uFontbase) {
			case 0 : 	{ b00->SetValue(true); } break;
			case 4 : 	{ b01->SetValue(true); } break;
			case 8 : 	{ b02->SetValue(true); } break;
			case 12 : 	{ b03->SetValue(true); } break;
			case 16 : 	{ b04->SetValue(true); } break;
			case 20 : 	{ b05->SetValue(true); } break;
			case 24 : 	{ b06->SetValue(true); } break;
			case 28 : 	{ b07->SetValue(true); } break;
			case 32 : 	{ b08->SetValue(true); } break;
			case 33 : 	{ b09->SetValue(true); } break;
			case 34 : 	{ b10->SetValue(true); } break;
		}
		if (32U > m_uFontnumber) {
			switch (m_uFontnumber % 4U) {
			 	case 0 : {
			 		checkboxBold->SetValue(false);
					checkboxItalic->SetValue(false);
			 	} break;
			 	case 1 : {
			 		checkboxBold->SetValue(false);
					checkboxItalic->SetValue(true);
			 	} break;
			 	case 2 : {
			 		checkboxBold->SetValue(true);
					checkboxItalic->SetValue(false);
			 	} break;
			 	case 3 : {
			 		checkboxBold->SetValue(true);
					checkboxItalic->SetValue(true);
			 	} break;
			}
		}
		else {
			checkboxBold->SetValue(false);
			checkboxItalic->SetValue(false);
			checkboxBold->Enable(false);
			checkboxItalic->Enable(false);
		}
	}
}

%%	module end


void
WxdkdrawDlgFontName::UpdateFontInformation(void)
{
	$? "+ UpdateFontInformation"
	m_uFontnumber = m_uFontbase;
	if (32U > m_uFontnumber) {
		/*
			Fonts allowing bold/italic variants
		*/
		if (checkboxBold->GetValue()) {
			m_uFontnumber += 2U;
		}
		if (checkboxItalic->GetValue()) {
			m_uFontnumber += 1U;
		}
		checkboxBold->Enable();
		checkboxItalic->Enable();
	}
	else {
		/*
			Fonts without bold/italic variants
		*/
		checkboxBold->Enable(false);
		checkboxItalic->Enable(false);
	}
	/*
		Update dialog
	*/
	labelFontname->SetLabel(m_pTexts[299 + m_uFontnumber]);
	bitmapFontname->SetBitmap(m_pImages[m_uFontnumber]);
	Refresh();
	Update();
	(m_pObject->det).t.find = m_uFontnumber;
	/*
		When modifying a drawing element, update draw control
	*/
	if (m_bRealObj) {
		m_pParent->UpdateTextForFont(m_pObject);
	}
	$? "- UpdateFontInformation"
}



void
WxdkdrawDlgFontName::OnFontFamily(wxCommandEvent & event)
{
	$? "+ OnFontFamily %d", (int)(event.GetId())
	m_uFontbase = 0U;
	switch (event.GetId()) {
		case WXD_ID_FONT_00 : {		$? ". 00"
			m_uFontbase = 0U;
		} break;
		case WXD_ID_FONT_01 : {		$? ". 01"
			m_uFontbase = 4U;
		} break;
		case WXD_ID_FONT_02 : {		$? ". 02"
			m_uFontbase = 8U;
		} break;
		case WXD_ID_FONT_03 : {		$? ". 03"
			m_uFontbase = 12U;
		} break;
		case WXD_ID_FONT_04 : {		$? ". 04"
			m_uFontbase = 16U;
		} break;
		case WXD_ID_FONT_05 : {		$? ". 05"
			m_uFontbase = 20U;
		} break;
		case WXD_ID_FONT_06 : {		$? ". 06"
			m_uFontbase = 24U;
		} break;
		case WXD_ID_FONT_07 : {		$? ". 07"
			m_uFontbase = 28U;
		} break;
		case WXD_ID_FONT_08 : {		$? ". 08"
			m_uFontbase = 32U;
		} break;
		case WXD_ID_FONT_09 : {		$? ". 09"
			m_uFontbase = 33U;
		} break;
		case WXD_ID_FONT_10 : {		$? ". 10"
			m_uFontbase = 34U;
		} break;
	}
	$? ". m_uFontbase = %u", (unsigned)m_uFontbase
	UpdateFontInformation();
	$? "- OnFontFamily"
}



void
WxdkdrawDlgFontName::OnOK(wxCommandEvent & WXUNUSED(event))
{
	if (m_bRealObj) {
		m_pParent->RequireRedraw(WXD_REFRESH_DRAWING);
	}
	if(IsModal()) {
		EndModal(wxID_OK);
	}
	else {
		SetReturnCode(wxID_OK);
		Show(false);
	}
}



void
WxdkdrawDlgFontName::OnCancel(wxCommandEvent & WXUNUSED(event))
{
	bool	bDoRefresh	=	false;
	if ((m_bRealObj) && (m_uOldFontnumber != (m_pObject->det).t.find)) {
		bDoRefresh =  true;
	}
	(m_pObject->det).t.find = m_uFontnumber = m_uOldFontnumber;
	if (bDoRefresh) {
		m_pParent->RequireRedraw(WXD_REFRESH_DRAWING);
	}
	if(IsModal()) {
		EndModal(wxID_CANCEL);
	}
	else {
		SetReturnCode(wxID_CANCEL);
		Show(false);
	}
}



void
WxdkdrawDlgFontName::OnBold(wxCommandEvent & WXUNUSED(event))
{
	UpdateFontInformation();
}



void
WxdkdrawDlgFontName::OnItalic(wxCommandEvent & WXUNUSED(event))
{
	UpdateFontInformation();
}





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