summaryrefslogtreecommitdiff
path: root/support/dktools/DkWxAppHelper.cpt
blob: c2d4f55ae89a7d21b4d1a0d1eb4006e55727d5b0 (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
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
%%	options

copyright owner	=	Dirk Krause
copyright year	=	2011-xxxx
license		=	bsd



%%	header

#if 0
#include <dk3all.h>
#else
#include <dk3conf.h>
#include <dk3types.h>
#include <dk3const.h>
#endif



#include <wx/wxprec.h>
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
#include <wx/config.h>
#include <wx/filename.h>

/**	Application helper class, provides file search, internationalization
	and some functions for GUI development using the wxWidgets libraries.
*/
class DkWxAppHelper
{
  protected:

    /**	Application structure.
    */
    dk3_app_t		*app;

    /**	Storage for string tables.
    */
    dk3_sto_t		*sStringTables;

    /**	Iterator through string tables storage.
    */
    dk3_sto_it_t	*iStringTables;

    /**	Basic strings used by wxWidgets applications.
    */
    wxChar const * const	*basicStrings;

    /**	First command line argument.
    */
    wxChar const	*cmdName;

    /**	Application name.
    */
    wxChar const	*appName;

    /**	Software vendor name.
    */
    wxChar const	*vendorName;

    /**	Number of entries in the basicStrings array.
    */
    size_t		nBasicStrings;

    /**	Encoding for dkChar.
    */
    int			dkEncoding;

    /**	Encoding for wxChar.
    */
    int			wxEncoding;

    /**	Code for errors from constructor.
    */
    int			errorCode;
 
  protected:

    /**	Report problems within the constructor, if any.
    */
    void
    reportProblemsIfAny(void);

    /**	Show an error message.
    	@param	i_title	Index of dialog title in basic strings.
	@param	i_text	Index of message text in basic strings.
    */
    void
    showErrorMessage(size_t i_title, size_t i_text);

  public:

    /**	Constructor.
    	@param	arg0		First command line argument.
	@param	vName		Software vendor name.
	@param	groupName	Application group name.
    */
    DkWxAppHelper(
      wxChar const	*arg0,
      wxChar const	*vName,
      dkChar const	*groupName
    );

    /**	Destructor.
    */
    ~DkWxAppHelper();

    /**	Check whether application helper object is set up correctly
    	and is ready to use.
    	@return	1 on success, 0 on error.
    */
    int
    checkSetup() const;

    /**	Retrieve array of localized texts.
    	@param	dt	Default texts, used if problems occur.
	@param	tn	Table name.
	@return	Pointer to localized messages array or dt.
    */
    wxChar const * const *
    getStringTable(
      wxChar const * const	*dt,
      dkChar const		*tn
    );

    /**	Find data file name. Provide a short file name like "x.y",
    	on success the program writes a full path like
	"/usr/share/myapp/en/x.y" to the result buffer.
    	@param	fn	Short file name.
	@param	fnb	Buffer for full path name.
	@param	szfnb	Size of @arg fnb (number of wxChar).
	@return	1 on success, 0 on error.
    */
    int
    findDataFile(wxChar const *fn, wxChar *fnb, size_t szfnb);

    /**	Retrieve multiple int settings at once.
    	@param	names	Pointer to names array, must be terminated
			by a NULL pointer.
	@param	values	Pointer to destination value array.
	@return	Number of items read successfully.
    */
    size_t
    retrieveMultipleInts(
      wxChar const * const	*names,
      int			*values
    ) const;

    /**	Retrieve multiple long settings at once.
    	@param	names	Pointer to names array, must be terminated
			by a NULL pointer.
	@param	values	Pointer to destination value array.
	@return	Number of items read successfully.
    */
    size_t
    retrieveMultipleLongs(
      wxChar const * const	*names,
      long			*values
    ) const;

    /**	Save multiple int settings at once.
    	@param	names	Pointer to names array, must be terminated by
			a NULL pointer.
	@param	values	Pointer to values array.
	@return	Number of items successfully written.
    */
    size_t
    saveMultipleInts(
      wxChar const * const	*names,
      int			*values
    ) const;

    /**	Save multiple long settings at once.
    	@param	names	Pointer to names array, must be terminated by
			a NULL pointer.
	@param	values	Pointer to values array.
	@return	Number of items successfully written.
    */
    size_t
    saveMultipleLongs(
      wxChar const * const	*names,
      long			*values
    ) const;

    /**	Retrieve multiple double settings at once.
    	@param	names	Pointer to names array, must be terminated by
			a NULL pointer.
	@param	values	Pointer to values array.
	@return	Number of items successfully read.
    */
    size_t
    retrieveMultipleDoubles(
      wxChar const * const	*names,
      double			*values
    ) const;

    /**	Save multiple doubles at once.
    	@param	names	Pointer to names array, must be terminated by
			a NULL pointer.
	@param	values	Pointer to values array.
	@return	Number of items successfully written.
    */
    size_t
    saveMultipleDoubles(
      wxChar const * const	*names,
      double			*values
    ) const;

    /**	Retrieve a string preference.
    	@param	name	Preference name.
	@return	Pointer to new string on success, NULL on error.
    */
    wxChar const *
    retrieveString(
      wxChar const		*name
    ) const;

    /**	Save a string entry.
    	@param	name	Entry name.
	@param	value	Entry value.
	@return	1 on success, 0 on error.
    */
    int
    saveString(
      wxChar const		*name,
      wxChar const		*value
    ) const;

    /**	Retrieve encoding for wxChar.
    	@return	Encoding used for wxChar.
    */
    int
    getWxEncoding() const;

    /**	Retrieve encoding for dkChar.
    	@return	Encoding used for dkChar.
    */
    int
    getDkEncoding() const;

    /**	Retrieve encoding to use for 8 bit characters.
    	@return	Encoding to use for 8 bit character strings.
    */
    int
    getC8Encoding() const;

    /**	Retrieve application structure.
    	@return	Application structure on success, NULL on error.
    */
    dk3_app_t *
    getApp() const;

    /**	Get one of the basic application strings.
    	@param	i	Index of string in array.
	@return	String pointer on success or NULL on error.
    */
    wxChar const *
    getBasicString(size_t i) const;

    /**	Get basic strings array.
    	@return	Array pointer to basic strings.
    */
    wxChar const * const *
    getBasicStrings() const;

    /**	Find number of basic strings stored in the \a basicStrings array.
    	@return	Number of strings in the array.
    */
    size_t
    getBasicStringNumbers() const;

    /**	Convert wxChar string to dkChar string.
    	@param	bu	Destination buffer.
	@param	sz	Destination buffer size (number of dkChar).
	@param	src	Source buffer.
	@return	true on success, false on error.
    */
    bool
    wxToDk(dkChar *bu, size_t sz, wxChar const *src) const;

    /**	Convert wxChar string to 8-bit char string.
    	@param	bu	Destination buffer.
	@param	sz	Destination buffer size.
	@param	src	Source buffer.
	@return	true on success, false on error.
    */
    bool
    wxToC8(char *bu, size_t sz, wxChar const *src) const;

    /**	Convert wxChar string to 8-bit char string.
    	@param	bu	Destination buffer.
	@param	sz	Destination buffer size.
	@param	str	Source string.
	@return	true on success, false on error.
    */
    bool
    wxToC8(char *bu, size_t sz, wxString & str) const;

    /**	Convert dkChar string to wxChar string.
    	@param	bu	Destination buffer.
	@param	sz	Destination buffer size (number of wxChar).
	@param	src	Source buffer.
	@return	true on success, false on error.
    */
    bool
    dkToWx(wxChar *bu, size_t sz, dkChar const *src) const;

    /**	Set related position (child over parent), the child
    	is either placed on a known previous position or placed
	centered on top of the parent.
    	@param	parent	Parent top level window (frame).
	@param	child	Child top level window (dialog).
	@param	pcx	Pointer to previous child x position.
	@param	pcy	Pointer to previous child y position.
    */
    void
    setRelatedPosition(
      wxWindow	*parent,
      wxWindow	*child,
      int	*pcx = NULL,
      int	*pcy = NULL
    ) const;

};



%%	module


#include <dk3all.h>
#include "DkWxAppHelper.h"


#include "dk3wxs.h"



$!trace-include



/**	Storage entry for wxChar string table.
*/
typedef struct {
  wxChar const	**array;	/**< String table contents. */
  dkChar const	 *name;		/**< String table name. */
  size_t	  nelem;	/**< Number of elements. */
} DkAppHelperWxStringTable;



/**	Pointer to constant wxChar string.
*/
typedef wxChar const	*wxConstPtr;



/**	Error codes.
*/
enum {
			/** No error occured.
			*/
  ERROR_NONE		= 0,

			/** Failed to encode arg0 to dkChar.
			*/
  ERROR_ENCODE_ARG0 ,
};



/**	Basic texts issued by wxWidgets applications.
*/
static wxChar const * const dkwxapphelper_defwxappstr[] = {
$!string-table	macro=wxT
#
#   0:	Log level: Worse than panic
#
Error worse than Panic
#
#   1:	Log level: Panic
#
Panic
#
#   2:	Log level: Fatal error
#
Fatal error
#
#   3:	Log level: Error
#
Error
#
#   4:	Log level: Warning
#
Warning
#
#   5:	Log level: Information
#
Information
#
#   6:	Log level: Progress message
#
Progress
#
#   7:	Log level: Debug message
#
Debug
#
#   8:	Log level: Ignore message
#
Ignore
#
#   9:	Error: Not enough memory!
#
Not enough memory!
#
#  10:	Error: Help file not found!
#
Help file not found!
#
#  11:	Error: Failed to initialize application structure!
#
Failed to initialize application structure!
#
#  12:	Error: Failed to recode command line!
#
Failed to recode command line!
$!end
};



/**	String table file containing localized versions of the
	texts in \a dkwxapphelper_defwxappstr.
*/
static dkChar const dkwxapphelper_sttname[] = { dkT("dkwx.str") };



/**	Compare two string table entries.
	@param	l	Left entry.
	@param	r	Right entry.
	@param	cr	Comparison criteria (0=entry/entry, 1=entr/name).
	@return	Comparison result.
*/
static
int
dkwxah_string_table_compare(void const *l, void const *r, int cr)
{
  int back = 0;
  DkAppHelperWxStringTable const	*pl;
  DkAppHelperWxStringTable const	*pr;
  if(l) {
    if(r) {
      pl = (DkAppHelperWxStringTable const *)l;
      pr = (DkAppHelperWxStringTable const *)r;
      switch(cr) {
        case 1: {
	  if(pl->name) {
	    back = dk3str_cmp(pl->name, (dkChar const *)r);
	  } else { back = -1; }
	} break;
	default: {
	  if(pl->name) {
	    if(pr->name) {
	      back = dk3str_cmp(pl->name, pr->name);
	    } else { back = 1;}
	  } else {
	    if(pr->name) { back = -1; }
	  }
	} break;
      }
    } else { back = 1; }
  } else {
    if(r) { back = -1; }
  }
  if(back < -1) { back = -1; }
  if(back >  1) { back =  1; }
  return back;
}



/**	Close string table.
	@param	p	String table to close.
*/
static
void
dkwxah_string_table_close(DkAppHelperWxStringTable *p)
{
  wxChar const	**ptr;
  size_t	 i;
  $? "+ dkwxah_string_table_close PTR=%d", TR_IPTR(p)
  if(p) {
    if(p->array) {
      if(p->nelem) {	$? ". %lu elements", (unsigned long)(p->nelem)
        ptr = p->array;
	for(i = 0; i < p->nelem; i++) {
	  if(*ptr) {	$? ". delete element %lu", (unsigned long)i
	  }
	  dk3_release(*ptr);
	  ptr++;
	}
      }
      dk3_delete(p->array);
    }
    dk3_release(p->name);
    dk3_delete(p);
  } $? "- dkwxah_string_table_close"
}




#if DK3_ON_WINDOWS || DK3_HAVE_BACKSLASH
/**	Separator character for file names.
*/
#define	SEP	wxT('\\')
#else
/**	Separator character for file names.
*/
#define	SEP	wxT('/')
#endif



/**	Non-localized keywords, 8-bit characters.
*/
static char const * const dkwxapphelper_c8_kw[] = {
/*  0 */	"UTF-8",
/*  1 */	"utf8",
NULL
};



DkWxAppHelper::DkWxAppHelper(
  wxChar const	*arg0,
  wxChar const	*vName,
  dkChar const	*groupName
)
{
  dkChar	dkcb[DK3_MAX_PATH];
  dkChar	*newargv[2];
  wxChar	*ptr;
  wxChar const	*cptr;
  wxChar const * const *ptrGetNumBasicStrings;
  $? "+ DkWxAppHelper::DkWxAppHelper"
  newargv[0]	= NULL;
  app = NULL;
  sStringTables = NULL;
  iStringTables = NULL;
  basicStrings	= NULL;
  nBasicStrings	= 0;
  cmdName	= NULL;
  appName	= NULL;
  vendorName	= NULL;
  errorCode	= ERROR_NONE;
  dkEncoding = DK3_ENCODING_PLAIN;
  wxEncoding = DK3_ENCODING_PLAIN;
  if(DK3_CHAR_SIZE > 1) {
    if(DK3_CHAR_SIZE > 2) {
      dkEncoding = DK3_ENCODING_UNICODE;
    } else {
      dkEncoding = DK3_ENCODING_UTF16;
    }
  } else {
    /* dkChar is 1 byte. */
#if DK3_ON_WINDOWS
#else
    char *ptr;
    ptr = getenv("LANG");
    if(ptr) {
      ptr = dk3str_c8_chr(ptr, '.');
      if(ptr) {
        ptr++;
	if(dk3str_c8_casecmp(dkwxapphelper_c8_kw[0], ptr) == 0) {
	  dkEncoding = DK3_ENCODING_UTF8;
	} else {
	  if(dk3str_c8_casecmp(dkwxapphelper_c8_kw[1], ptr) == 0) {
	    dkEncoding = DK3_ENCODING_UTF8;
	  }
	}
      }
    }
#endif
  }
  if(sizeof(wxChar) > 1) {
    if(sizeof(wxChar) > 2) {
      wxEncoding = DK3_ENCODING_UNICODE;
    } else {
      wxEncoding = DK3_ENCODING_UTF16;
    }
  } else {
#if DK3_ON_WINDOWS
#else
    char *ptr;
    ptr = getenv("LANG");
    if(ptr) {
      ptr = dk3str_c8_chr(ptr, '.');
      if(ptr) {
        ptr++;
	if(dk3str_c8_casecmp(dkwxapphelper_c8_kw[0], ptr) == 0) {
	  wxEncoding = DK3_ENCODING_UTF8;
	} else {
	  if(dk3str_c8_casecmp(dkwxapphelper_c8_kw[1], ptr) == 0) {
	    wxEncoding = DK3_ENCODING_UTF8;
	  }
	}
      }
    }
#endif
  }
  if(dk3wxs_to_dkstr(dkcb,DK3_SIZEOF(dkcb,dkChar),dkEncoding,arg0,wxEncoding))
  {
    newargv[0] = dkcb,
    newargv[1] = 0;
    app = dk3app_open_gui(1, newargv, groupName);
    if(app) {
      sStringTables = dk3sto_open_app(app);
      if(sStringTables) {
        dk3sto_set_comp(sStringTables, dkwxah_string_table_compare, 0);
        iStringTables = dk3sto_it_open(sStringTables);
	if(iStringTables) {
	}
      }
    }
  }
  else
  {
    errorCode = ERROR_ENCODE_ARG0;
  }
  cmdName = dk3wxs_dup_app(arg0, app);
  if(cmdName) {
    cptr = dk3wxs_rchr(cmdName, SEP);
    if(cptr) {
      cptr++;
    } else {
      cptr = cmdName;
    }
    appName = dk3wxs_dup_app(cptr, app);
    if(appName) {
      ptr = dk3wxs_rchr(appName, '.');
      if(ptr) { *ptr = wxT('\0'); }
    }
  }
  vendorName = dk3wxs_dup_app(vName, app);
  /*
  	Finally retrieve the basic application strings.
  */
  ptrGetNumBasicStrings = dkwxapphelper_defwxappstr;
  while(*(ptrGetNumBasicStrings++)) { nBasicStrings++; }
  basicStrings = getStringTable(
    dkwxapphelper_defwxappstr,
    dkwxapphelper_sttname
  );
  reportProblemsIfAny();
  $? "- DkWxAppHelper::DkWxAppHelper"
}



DkWxAppHelper::~DkWxAppHelper()
{
  $? "+ DkWxAppHelper::~DkWxAppHelper"
  DkAppHelperWxStringTable	*e;
  basicStrings = NULL;
  if(sStringTables) {
    if(iStringTables) {
      dk3sto_it_reset(iStringTables);
      do {
        e = (DkAppHelperWxStringTable *)dk3sto_it_next(iStringTables);
	if(e) {
	  dkwxah_string_table_close(e);
	}
      } while(e != NULL);
      dk3sto_it_close(iStringTables);
    }
    dk3sto_close(sStringTables);
  } sStringTables = NULL; iStringTables = NULL;
  if(app) {
    dk3app_close(app); app = NULL;
  }
  dk3_release(cmdName);
  dk3_release(appName);
  dk3_release(vendorName);
  $? "- DkWxAppHelper::~DkWxAppHelper"
}



int
DkWxAppHelper::checkSetup() const
{
  int back = 0;
  $? "+ DkWxAppHelper::checkSetup"
  if(app) {			$? ". app ok"
    if(sStringTables) {		$? ". string table storage ok"
      if(iStringTables) {	$? ". string table iterator ok"
        if(cmdName) {		$? ". cmdName ok"
	  if(appName) {		$? ". appName ok"
	    if(vendorName) {	$? ". vendorName ok"
              back = 1;
	    } else {		$? "! vendorName"
	    }
	  } else {		$? "! appName"
	  }
	} else {		$? "! cmdName"
	}
      } else {			$? "! string table iterator"
      }
    } else {			$? "! string table storage"
    }
  } else {			$? "! app"
  } $? "- DkWxAppHelper::checkSetup %d", back
  return back;
}



wxChar const * const *
DkWxAppHelper::getStringTable(
      wxChar const * const	*dt,
      dkChar const		*tn
)
{
#if 0
  wxChar const * const		*back	= NULL;
  wxChar const * 		*wxptr;
  DkAppHelperWxStringTable	*tp	= NULL;
  FILE				*fipo	= NULL;
  dkChar const			*oldsource	= NULL;
#if 0
  dkChar			dkb[4096];
#endif
  dkChar			fnb[DK3_MAX_PATH];
  wxChar			wxb[4096];
  char				il[4096];
  unsigned long			lineno	= 0UL;
  unsigned long			oldline	= 0UL;
  size_t			nelem	= 0;
  size_t			i	= 0;
  int				cc	= 1;
  int				ok	= 0;

  $? "+ DkWxAppHelper::getStringTable \"%!ds\"", TR_STR(tn)
  if((dt) && (tn)) {				$? ". args ok"
    if(checkSetup()) {				$? ". setup ok"
      tp = (DkAppHelperWxStringTable *)dk3sto_it_find_like(
        iStringTables, (void *)tn, 1
      );
      if(!(tp)) {				$? ". must read from file"
        if(dk3app_find_data_file(app, tn, fnb, DK3_SIZEOF(fnb,dkChar))) { $? ". find"
	  fipo = dk3sf_fopen_app(fnb, dk3app_not_localized(22), app);
	  if(fipo) {				$? ". fopen ok"
	    wxptr = (wxChar const **)dt; nelem = 0;
	    while(*(wxptr++)) { nelem++; }
	    if(nelem) {		$? ". have %lu elements", (unsigned long)nelem
	      tp = dk3_new_app(DkAppHelperWxStringTable,1,app);
	      if(tp) {		$? ". allocation ok"
	        ok = 0;
		tp->array = NULL;
		tp->nelem = nelem;
		tp->name = dk3str_dup_app(tn, app);
		if(tp->name) {	$? ". dup ok for name"
		  tp->array = dk3_new_app(wxConstPtr,nelem,app);
		  if(tp->array) {	$? ". array allocation ok"
		    wxptr = tp->array;
		    tp->nelem = nelem;
		    for(i = 0; i < nelem; i++) { *(wxptr++) = NULL; }
		    if(dk3sto_add(sStringTables, (void *)tp)) {	$? ". add ok"
		      ok = 1;
		      oldsource = dk3app_get_source_file(app);
		      oldline   = dk3app_get_source_line(app);
		      dk3app_set_source_file(app, fnb);
		      dk3app_set_source_line(app, 0UL);
		      lineno = 0UL;
		      wxptr = tp->array; nelem = 0;
		      do {			$? ". loop start"
		        cc = 0;
			if(fgets(il, sizeof(il), fipo)) {	$? ". line ok"
			  dk3app_set_source_line(app, ++lineno);
			  cc = 1;
			  if(il[0] != '#') {		$? ". no comment"
			    dk3app_squeeze_line(il);
			    if(dk3wxs_from_utf8(wxb,DK3_SIZEOF(wxb,wxChar),il))
			    {
			      *wxptr = dk3wxs_dup_app(wxb, app);
			      if(!(*wxptr)) {	$? "! dup failed"
			        ok = 0;
			      }
			      wxptr++;
			    }
			    else
			    {
			      ok = 0;		$? "! conversion failed"
			    }
			  } else {		$? ". comment line"
			  }
			  if(nelem >= tp->nelem) { cc = 0; }
			} else {		$? "! no more lines"
			}
		      } while((cc) && (ok));
		      if(nelem < tp->nelem) {
		        ok = 0;
		      }
		      dk3app_set_source_file(app, oldsource);
		      dk3app_set_source_line(app, oldline);
		    } else {		$? "! add failed"
		    }
		  } else {		$? "! array allocation failed"
		  }
		} else {		$? "! dup failed for name"
		}
		if(ok) {
		  back = (wxChar const * const *)(tp->array);
		} else {
		  dkwxah_string_table_close(tp);
		}
	      } else {			$? "! allocation failed"
	      }
	    } else {			$? "! defaults array empty"
	    }
	    fclose(fipo);
	  } else {			$? "! fopen"
	  }
	} else {			$? "! not found"
	}
      } else {				$? ". found in storage"
      }
      if(tp) {				$? ". have entry"
        back = (wxChar const * const *)(tp->array);
      }
    } else {				$? "! setup"
    }
  } else {				$? "! args"
  }
  if(!(back)) {
    back = dt;
  } $? "- DkWxAppHelper::getStringTable PTR=%d", TR_IPTR(back)
#else
  dkChar			 fnb[DK3_MAX_PATH];	/* Full file name. */ 
  char				 il[4096];	/* Input line */
  wxChar			 wxb[sizeof(il)];
  wxChar const * const		*back = NULL;
  DkAppHelperWxStringTable	*tp;	/* String table if exists. */
  wxChar const * 		*wxptr;	/* Traverse dt array. */
  FILE				*fipo;	/* Read input file. */
#if VERSION_BEFORE_20150821
  unsigned long			 lineno;	/* Current line. */
#endif
  size_t			 nelem;	/* Number of elements in dt. */
  size_t			 i;	/* Current string to process. */
  int				 res;	/* Search result. */
  int				 cc;	/* Flag: Can continue. */
  int				 ok;	/* Flag: All strings read succes. */
  $? "+ getStringTable"
  if((dt) && (tn)) {			$? ". args ok"
    if(checkSetup()) {			$? ". controller setup ok"
      tp = (DkAppHelperWxStringTable *)dk3sto_it_find_like(
        iStringTables, (void *)tn, 1
      );
      if(!(tp)) {			$? ". table not yet found, must read"
        res = dk3app_find_data_file(app,tn,fnb,DK3_SIZEOF(fnb,dkChar));
	$? ". res = %d", res
	if(res) {			$? ". file found"
	  fipo = dk3sf_fopen_app(fnb, dk3app_not_localized(22), app);
	  if(fipo) {			$? ". file opened"
	    wxptr = (wxChar const **)dt; nelem = 0;
	    while(*(wxptr++)) { nelem++; }
	    if(nelem) {
	      tp = dk3_new_app(DkAppHelperWxStringTable,1,app);
	      if(tp) {
	        tp->array = NULL;
		tp->nelem = nelem;
		tp->name = NULL;
		tp->name = dk3str_dup_app(tn, app);
		if(tp->name) {
		  tp->array = dk3_new_app(wxConstPtr,nelem,app);
		  if(tp->array) {
		    wxptr = tp->array;
		    tp->nelem = nelem;
		    for(i = 0; i < nelem; i++) { *(wxptr++) = NULL; }
		    wxptr = tp->array; nelem = 0;
#if VERSION_BEFORE_20150821
		    lineno = 0UL;
#endif
#if VERSION_BEFORE_20150821
		    cc = 1;
#endif
		    ok = 1;
		    do {
		      cc = 0;
		      if(fgets(il, sizeof(il), fipo)) {
		        cc = 1;			$? ". line \"%!8s\"", il
			if(il[0] != '#') {	$? ". no comment"
			  dk3app_squeeze_line(il);
			  if(dk3wxs_from_utf8(wxb,DK3_SIZEOF(wxb,wxChar),il)) {
			    *wxptr = dk3wxs_dup_app(wxb, app);
			    if(*wxptr) {
			      nelem++;
			      if(nelem >= tp->nelem) {
			        cc = 0;
			      }
			    } else {
			      ok = 0; cc = 0;
			    }
			    wxptr++;
			  } else {		$? "! conversion failed"
			    ok = 0; cc = 0;
			  }
			} else {		$? ". comment"
			}
		      }
		    } while(cc);
		    if(nelem < tp->nelem) {
		      ok = 0;			$? "! too few elements"
		    }
		    if(ok) {				$? ". success so far"
		      if(!dk3sto_add(sStringTables, (void *)tp)) {
		        dkwxah_string_table_close(tp);	$? "! memory"
			tp = NULL;
		      }
		    } else {				$? "! anything wrong"
		      dkwxah_string_table_close(tp);
		      tp = NULL;
		    }
		  } else {
		    dkwxah_string_table_close(tp);
		    tp = NULL;
		  }
		} else {
		  dkwxah_string_table_close(tp);
		  tp = NULL;
		}
	      } else {			$? "! memory"
	      }
	    }
	    fclose(fipo);
	  } else {			$? "! failed to open file"
	  }
	} else {			$? "! file not found"
	}
      }
      if(tp) {				$? ". table found"
        back = (wxChar const * const *)(tp->array);
      }
    } else {				$? "! controller setup not ok"
    }
  } else {				$? "! invalid args"
  }
  if(!(back)) {				$? "! no result, using default texts"
    back = dt;
  } $? "- getStringTable PTR=%d", TR_IPTR(back)
#endif
  return back;
}


size_t
DkWxAppHelper::retrieveMultipleInts(
      wxChar const * const	*names,
      int			*values
) const
{
  size_t		back = 0;
  wxChar const * const	*nptr;
  int			*vptr;
  long			 l;
  $? "+ DkWxAppHelper::retrieveMultipleInts"
  if((appName) && (vendorName) && (names) && (values)) {
    wxConfig *conf = new wxConfig(appName, vendorName);
    if(conf) {
      nptr = names; vptr = values;
      while(*nptr) {
        l = 0L;
	if(conf->Read(*nptr, &l)) {
	  *vptr = (int)l;
	  back++;
	}
	nptr++; vptr++;
      }
      delete(conf);
    }
  } $? "- DkWxAppHelper::retrieveMultipleInts %lu", (unsigned long)back
  return back;
}



size_t
DkWxAppHelper::retrieveMultipleLongs(
	wxChar const * const	*names,
	long			*values
) const
{
  size_t		 back = 0;
  wxChar const * const	*nptr;
  long			*vptr;
  long			 l;
  $? "+ DkWxAppHelper::retrieveMultipleLongs"
  if((appName) && (vendorName) && (names) && (values)) {
    wxConfig *conf = new wxConfig(appName, vendorName);
    if(conf) {
      nptr = names; vptr = values;
      while(*nptr) {
        l = 0L;
	if(conf->Read(*nptr, &l)) {
	  *vptr = l;
	  back++;
	}
        nptr++; vptr++;
      }
      delete(conf);
    }
  }
  $? "- DkWxAppHelper::retrieveMultipleLongs %u", (unsigned)back
  return back;
}


size_t
DkWxAppHelper::retrieveMultipleDoubles(
      wxChar const * const	*names,
      double			*values
) const
{
  size_t		 back	= 0;
  double		 d;
  wxChar const * const	*nptr;
  double		*vptr;
  $? "+ DkWxAppHelper::retrieveMultipleDoubles"
  if((appName) && (vendorName) && (names) && (values)) {
    wxConfig *conf = new wxConfig(appName,  vendorName);
    if(conf) {
      nptr = names; vptr = values;
      while(*nptr) {
        d = 0.0;
	if(conf->Read(*nptr, &d)) {
	  *vptr = d;
	  back++;
	}
	nptr++; vptr++;
      }
      delete(conf);
    }
  } $? "- DkWxAppHelper::retrieveMultipleDoubles %u", (unsigned)back
  return back;
}


size_t
DkWxAppHelper::saveMultipleInts(
      wxChar const * const	*names,
      int			*values
) const
{
  size_t		back = 0;
  wxChar const * const	*nptr;
  int			*vptr;
  long			l;
  $? "+ DkWxAppHelper::saveMultipleInts"
  if((appName) && (vendorName) && (names) && (values)) {
    wxConfig *conf = new wxConfig(appName, vendorName);
    if(conf) {				$? ". conf ok"
      nptr = names; vptr = values;
      while(*nptr) {			$? ". write entry"
        l = (long)(*vptr);
	if(conf->Write(*nptr, l)) {
	  back++;
	}
	nptr++; vptr++;
      }
      delete(conf);
    }
  } $? "- DkWxAppHelper::saveMultipleInts %lu", (unsigned long)back
  return back;
}



size_t
DkWxAppHelper::saveMultipleLongs(
	wxChar const * const	*names,
	long			*values
) const
{
  size_t		 back = 0;
  wxChar const * const	*nptr;
  long			*vptr;
  long			 l;
  $? "+ DkWxAppHelper::saveMultipleLongs"
  if((appName) && (vendorName) && (names) && (values)) {
    wxConfig *conf = new wxConfig(appName, vendorName);
    if(conf) {
      nptr = names; vptr = values;
      while(*nptr) {
        l = *vptr;
	if(conf->Write(*nptr, l)) {
	  back++;
	}
	nptr++; vptr++;
      }
      delete(conf);
    }
  }
  $? "- DkWxAppHelper::saveMultipleLongs %u", (unsigned)back
  return back;
}



size_t
DkWxAppHelper::saveMultipleDoubles(
	wxChar const * const	*names,
	double			*values
) const
{
  size_t		 back	= 0;
  double		 d;
  wxChar const * const	*nptr;
  double		*vptr;
  $? "+ DkWxAppHelper::saveMultipleDoubles"
  if((appName) && (vendorName) && (names) && (values)) {
    wxConfig *conf = new wxConfig(appName, vendorName);
    if(conf) {
      nptr = names; vptr = values;
      while(*nptr) {
        d = *vptr;
	if(conf->Write(*nptr, d)) {
	  back++;
	}
        nptr++; vptr++;
      }
      delete(conf);
    }
  } $? "- DkWxAppHelper::saveMultipleDoubles %u", (unsigned)back
  return back;
}



wxChar const *
DkWxAppHelper::retrieveString(
  wxChar const		*name
) const
{
  wxChar const		*back = NULL;
  wxChar const		*ptr;
  $? "+ DkWxAppHelper::retrieveString"
  if((name) && (appName) && (vendorName)) {
    wxConfig *conf = new wxConfig(appName, vendorName);
    if(conf) {
      wxString str;
      if(conf->Read(name, &str)) {
        ptr = str.c_str();
	if(ptr) {
	  back = dk3wxs_dup_app(ptr, app);
	}
      }
      delete(conf);
    }
  } $? "- DkWxAppHelper::retrieveString PTR=%d", TR_IPTR(back)
  return back;
}



int
DkWxAppHelper::saveString(
  wxChar const		*name,
  wxChar const		*value
) const
{
  int			back = 0;
  $? "+ DkWxAppHelper::saveString"
  if((name) && (value) && (appName) && (vendorName)) {
    wxConfig *conf = new wxConfig(appName, vendorName);
    if(conf) {
      conf->Write(name, value);
      delete(conf);
    }
  } $? "- DkWxAppHelper::saveString %d", back
  return back;
}



int
DkWxAppHelper::getWxEncoding() const
{
  $? "= getWxEncoding %d", wxEncoding
  return wxEncoding;
}



int
DkWxAppHelper::getDkEncoding() const
{
  $? "= getDkEncoding %d", dkEncoding
  return dkEncoding;
}



int
DkWxAppHelper::getC8Encoding() const
{
  int		back;
  $? "+ DkWxAppHelper::getC8Encoding"
  back = dkEncoding;
  if(DK3_ENCODING_UTF8 != back) {
    back = DK3_ENCODING_PLAIN;
  } $? "- DkWxAppHelper::getC8Encoding %d", back
  return back;
}



dk3_app_t *
DkWxAppHelper::getApp() const
{
  $? "= DkWxAppHelper::getApp PTR=%d", TR_IPTR(app)
  return app;
}



int
DkWxAppHelper::findDataFile(wxChar const *fn, wxChar *fnb, size_t szfnb)
{
  dkChar	shnDk[DK3_MAX_PATH];
  dkChar	ffnDk[DK3_MAX_PATH];
  int		back = 0;
  $? "+ findDataFile"
  if((fn) && (fnb) && (szfnb)) {	$? ". args ok"
    if(checkSetup()) {			$? ". setup ok"
      if(dk3wxs_to_dkstr(
           shnDk, DK3_SIZEOF(shnDk,dkChar), dkEncoding, fn, wxEncoding
         )
        )
      {
        if(app) {			$? ". app available"
	  if(dk3app_find_data_file(app,shnDk,ffnDk,DK3_SIZEOF(ffnDk,dkChar))) {
	    if(dk3wxs_from_dkstr(fnb, szfnb, wxEncoding, ffnDk, dkEncoding)) {
	      back = 1;			$? ". found"
	    } else {			$? "! conversion failed"
	    }
	  } else {			$? "! not found"
	  }
	} else {			$? "! no app"
	}
      } else {				$? "! conversion failed"
      }
    }
  } $? "- findDataFile %d", back
  return back;
}



wxChar const *
DkWxAppHelper::getBasicString(size_t i) const
{
  wxChar const		*back	= NULL;
  $? "+ DkWxAppHelper::getBasicString"
  if(basicStrings) {
    if(i < nBasicStrings) {
      back = basicStrings[i];
    }
  } $? "- DkWxAppHelper::getBasicString PTR=%d", TR_IPTR(back)
  return back;
}



wxChar const * const *
DkWxAppHelper::getBasicStrings() const
{
  $? "= DkWxAppHelper::getBasicStrings PTR=%d", TR_IPTR(basicStrings)
  return basicStrings;
}

    
    
size_t
DkWxAppHelper::getBasicStringNumbers() const
{
  $? "= DkWxAppHelper::getBasicStringNumbers %u", (unsigned)nBasicStrings
  return nBasicStrings;
}



bool
DkWxAppHelper::wxToDk(dkChar *bu, size_t sz, wxChar const *src) const
{
  bool		back	= false;
  $? "+ DkWxAppHelper::wxToDk"
  if((bu) && (sz) && (src)) {
    if(dk3wxs_to_dkstr(bu, sz, dkEncoding, src, wxEncoding)) {
      back = true;
    }
  } $? "- DkWxAppHelper::wxToDk %d", ((back) ? 1 : 0)
  return back;
}



bool
DkWxAppHelper::wxToC8(char *bu, size_t sz, wxChar const *src) const
{
  bool		back	= false;
  $? "+ DkWxAppHelper::wxToC8"
  if((bu) && (sz) && (src)) {
    if(dk3wxs_to_c8(bu, sz, getC8Encoding(), src, wxEncoding)) {
      back = true;
    }
  } $? "- DkWxAppHelper::wxToC8 %d", (back ? 1 : 0)
  return back;
}



bool
DkWxAppHelper::wxToC8(char *bu, size_t sz, wxString & str) const
{
  bool		 back = false;
  wxChar const	*ptr;
  $? "+ DkWxAppHelper::wxToC8"
  if((bu) && (sz)) {
    ptr = str.c_str();
    if(ptr) {
      back = wxToC8(bu, sz, ptr);
    }
  } $? "- DkWxAppHelper::wxToC8 %d", ((back) ? 1 : 0)
  return back;
}



bool
DkWxAppHelper::dkToWx(wxChar *bu, size_t sz, dkChar const *src) const
{
  bool		back	= false;
  $? "+ DkWxAppHelper::dkToWx"
  if((bu) && (sz) && (src)) {
    if(dk3wxs_from_dkstr(bu, sz, wxEncoding, src, dkEncoding)) {
      back = true;
    }
  } $? "- DkWxAppHelper::dkToWx %d", ((back) ? 1 : 0)
  return back;
}


void
DkWxAppHelper::setRelatedPosition(
  wxWindow	*parent,
  wxWindow	*child,
  int		*pcx,
  int		*pcy
) const
{
  int		px	=	0;	/* Parent x position. */
  int		py	=	0;	/* Parent y position. */
  int		pw	=	0;	/* Parent width. */
  int		ph	=	0;	/* Parent height. */
  int		cx	=	0;	/* Child x position. */
  int		cy	=	0;	/* Child y position. */
  int		cw	=	0;	/* Child width. */
  int		ch	=	0;	/* Child height. */
  wxSize	scsz;			/* Screen size. */

  scsz = wxGetDisplaySize();
  parent->GetPosition(&px, &py);
  parent->GetSize(&pw, &ph);
  child->GetSize(&cw, &ch);
  cx = px + (pw - cw) / 2;
  cy = py + (ph - ch) / 2;
  if((cx + cw) > scsz.x) {
    cx = scsz.x - cw;
  }
  if((cy + ch) > scsz.y) {
    cy = scsz.y - ch;
  }
  if(cx < 0) {
    cx = 0;
  }
  if(cy < 0) {
    cy = 0;
  }
  if((pcx) && (pcy)) {
    if(((*pcx) >= 0) && ((*pcy) >= 0)) {
      cx = *pcx;
      cy = *pcy;
    }
  }
  child->SetSize(cx, cy, cw, ch);
}


void
DkWxAppHelper::reportProblemsIfAny(void)
{
  bool		didReport	= false;

  if (!didReport) {
    if (NULL == app) {
      didReport = true;
      switch (errorCode) {
        case ERROR_ENCODE_ARG0 : {
	  /* ERROR: Failed to encode arg0 to dkChar */
	  showErrorMessage(3, 12);
	} break;
	default : {
	  /* ERROR: Failed to initialize application structure */
	  showErrorMessage(3, 11);
	} break;
      }
    }
  }
  if (!didReport) {
    if (NULL != app) {
      if ((NULL == sStringTables) || (NULL == iStringTables)) {
        didReport = true;
	/* ERROR: Memory */
	showErrorMessage(3, 9);
      }
    }
  }
  if (!didReport) {
    if ((NULL == cmdName) || (NULL == appName) || (NULL == vendorName)) {
      didReport = true;
      /* ERROR: Memory */
      showErrorMessage(3, 9);
    }
  }
}



void
DkWxAppHelper::showErrorMessage(size_t i_title, size_t i_text)
{
  const wxChar	*str_title	= NULL;
  const wxChar	*str_text	= NULL;
  if (NULL != basicStrings) {
    str_title = basicStrings[i_title];
    str_text  = basicStrings[i_text];
  } else {
    str_title = dkwxapphelper_defwxappstr[i_title];
    str_text  = dkwxapphelper_defwxappstr[i_text];
  }
  wxMessageBox(str_text, str_title, (wxOK | wxCENTRE | wxICON_ERROR));
}