summaryrefslogtreecommitdiff
path: root/support/dktools/Dk4WxApplicationHelper.h
blob: e583c86e53ca6f29f7a2cb5402e6bb756657e1b9 (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
/*
Copyright (C) 2015-2020, Dirk Krause
SPDX-License-Identifier: BSD-3-Clause
*/

/*
	WARNING: This file was generated by the dkct program (see
	http://dktools.sourceforge.net/ for details).
	Changes you make here will be lost if dkct is run again!
	You should modify the original source and run dkct on it.
	Original source: Dk4WxApplicationHelper.cpt
*/

#ifndef DK4WXAPPLICATIONHELPER_H_INCLUDED
/** Avoid multiple inclusions. */
#define DK4WXAPPLICATIONHELPER_H_INCLUDED 1


#line 9 "Dk4WxApplicationHelper.cpt"

/**	@file	Dk4WxApplicationHelper.h	The Dk4WxApplicationHelper
	class.
*/

#ifndef DK4CONF_H_INCLUDED
#if DK4_BUILDING_DKTOOLS4
#include "dk4conf.h"
#else
#include <dktools-4/dk4conf.h>
#endif
#endif

#ifndef	DK4_SIZEOF_WXCHAR
#ifndef	DK4WXCS_H_INCLUDED
#if DK4_BUILDING_DKTOOLS4
#include "dk4wxcs.h"
#else
#include <dktools-4/dk4wxcs.h>
#endif
#endif
#endif

#ifndef DK4TYPES_H_INCLUDED
#if DK4_BUILDING_DKTOOLS4
#include "dk4types.h"
#else
#include <dktools-4/dk4types.h>
#endif
#endif

#ifndef DK4CONST_H_INCLUDED
#if DK4_BUILDING_DKTOOLS4
#include "dk4const.h"
#else
#include <dktools-4/dk4const.h>
#endif
#endif

#ifndef DK4ERROR_H_INCLUDED
#if DK4_BUILDING_DKTOOLS4
#include "dk4error.h"
#else
#include <dktools-4/dk4error.h>
#endif
#endif

#ifndef DK4STO_H_INCLUDED
#if DK4_BUILDING_DKTOOLS4
#include "dk4sto.h"
#else
#include <dktools-4/dk4sto.h>
#endif
#endif

#ifndef DK4WXCS_H_INCLUDED
#if DK4_BUILDING_DKTOOLS4
#include "dk4wxcs.h"
#else
#include <dktools-4/dk4wxcs.h>
#endif
#endif

#ifndef DK4FSH_H_INCLUDED
#if DK4_BUILDING_DKTOOLS4
#include "dk4fs.h"
#else
#include <dktools-4/dk4fs.h>
#endif
#endif

#ifndef WX_WXPREC_H_INCLUDED
#include "wx/wxprec.h"
#define WX_WXPREC_H_INCLUDED 1
#endif

#ifdef __BORLANDC__
#pragma hdrstop
#endif

#ifndef WX_PRECOMP
#ifndef WX_WX_H_INCLUDED
#include "wx/wx.h"
#define	WX_WX_H_INCLUDED 1
#endif
#endif

#ifndef WX_CONFIG_H_INCLUDED
#include <wx/config.h>
#define	WX_CONFIG_H_INCLUDED 1
#endif

#ifndef WX_FILENAME_H_INCLUDED
#include <wx/filename.h>
#define	WX_FILENAME_H_INCLUDED 1
#endif

#ifndef WX_THREAD_H_INCLUDED
#include <wx/thread.h>
#define	WX_THREAD_H_INCLUDED 1
#endif

#ifndef DK4WXSTT_H_INCLUDED
#if DK4_BUILDING_DKTOOLS4
#include "dk4wxstt.h"
#else
#include <dktools-4/dk4wxstt.h>
#endif
#endif


/**	Application helper.
	Each application should have one application helper object
	as the member of the wxApp-derived application class.
	In the applications OnInit() method call the Initialize() method.
*/
class Dk4WxApplicationHelper
{
  protected:

    /**	Synchronization for access from multiple threads.
    */
    wxCriticalSection		csProtect;

    /**	The basic strings for GUIs.
    */
    const wxChar * const	*ppBasicStrings;

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

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

    /**	Application group name.
    */
    const dkChar		*pcdksGroup;

    /**	Application name.
    */
    wxChar			*pwxsApp;

    /**	The /usr/share equivalent directory.
    */
    wxChar			*pwxsShare;

    /**	First command line argument (allocated).
    */
    dkChar			*pcdksArgv0;

    /**	Host name.
    */
    dkChar			*pdksHost;

    /**	Users login name.
    */
    dkChar			*pdksLogname;

    /**	Home directory.
    */
    dkChar			*pdksHome;

    /**	Application name.
    */
    dkChar			*pdksApp;

    /**	System configuration directory.
    */
    dkChar			*pdksSysconf;

    /**	Data directory.
    */
    dkChar			*pdksShare;

    /**	Users language.
    */
    dkChar			*pdksLanguage;

    /**	Users region.
    */
    dkChar			*pdksRegion;

    /**	String tables storage.
    */
    dk4_sto_t			*sStt;

    /**	String tables storage iterator.
    */
    dk4_sto_it_t		*iStt;

    /**	System preferences storage.
    */
    dk4_sto_t			*sPrSys;

    /**	System preferences storage iterator.
    */
    dk4_sto_it_t		*iPrSys;

    /**	User preferences storage.
    */
    dk4_sto_t			*sPrUser;

    /**	User preferences storage iterator.
    */
    dk4_sto_it_t		*iPrUser;

    /**	Number of strings in the ppBasicStrings array. 
    */
    size_t			 nBasicStrings;

    /**	Encoding for dkChar strings.
    */
    int				 iDkEncoding;

    /**	Encoding for wxChar strings.
    */
    int				 iWxEncoding;

    /**	Expected encoding for file input.
    */
    int				 iFiEncoding;
	
    /**	Flag: Controller is set up and can be used.
    */
    bool			bActive;

  protected:

    /**	Clean up internal data structures.
    */
    void
    InternalCleanup(void);


    /**	Search for data file.
	@param	fnb	File name buffer.
	@param	szfnb	Buffer size (number of dkChar).
	@param	sfn	Short file name.
	@param	maxpass	Maximum pass number for search.
	@param	aco	Flag: Allow compressed versions.
	@return	True if the file was found (name in fnb), false otherwise.
    */
    bool
    InternalFindDataFile(
      dkChar 		*fnb,
      size_t		 szfnb,
      dkChar const	*sfn,
      int		 maxpass,
      bool		 aco
    );

#if DK4_SIZEOF_WXCHAR != DK4_CHAR_SIZE

    /**	Search for data file.
	@param	fnb	File name buffer.
	@param	szfnb	Buffer size (number of wxChar).
	@param	sfn	Short file name.
	@param	maxpass	Maximum pass number for search.
	@param	aco	Flag: Allow compressed versions.
	@return	True if the file was found (name in fnb), false otherwise.
    */
    bool
    InternalFindDataFile(
      wxChar 		*fnb,
      size_t		 szfnb,
      dkChar const	*sfn,
      int		 maxpass,
      bool		 aco
    );

#endif

    /**	Search for documentation or help file.
	@param	fnb	File name buffer.
	@param	szfnb	Buffer size (number of dkChar).
	@param	sfn	Short file name.

	The method searches for the file <i>sfn</i> in the
	following directories, first file found is returned:
	- /usr/share/<i>group</i>/help/<i>program</i>/<i>language</i>/<i>region</i>
	- /usr/share/doc/<i>group</i>/help/<i>program</i>/<i>language</i>/<i>region</i>
	- /usr/share/<i>group</i>/help/<i>program</i>/<i>language</i>
	- /usr/share/doc/<i>group</i>/help/<i>program</i>/<i>language</i>
	- /usr/share/<i>group</i>/help/<i>program</i>/en
	- /usr/share/doc/<i>group</i>/help/<i>program</i>/en
	- /usr/share/<i>group</i>/help/<i>program</i>
	- /usr/share/doc/<i>group</i>/help/<i>program</i>
	
	For a relocated installation replace /usr/share by ${datadir}.

	@return	True if the file was found (name in fnb), false otherwise.
    */
    bool
    InternalFindHelpFile(
      dkChar 		*fnb,
      size_t		 szfnb,
      dkChar const	*sfn
    );

#if DK4_SIZEOF_WXCHAR != DK4_CHAR_SIZE

    /**	Search for documentation or help file.
	@param	fnb	File name buffer.
	@param	szfnb	Buffer size (number of dkChar).
	@param	sfn	Short file name.
	@return	True if the file was found (name in fnb), false otherwise.
    */
    bool
    InternalFindHelpFile(
      wxChar 		*fnb,
      size_t		 szfnb,
      dkChar const	*sfn
    );

#endif

    /**	Convert dkChar string to wxChar string.
	@param	dptr	Result buffer.
	@param	dsz	Buffer size (number of wxChar).
	@param	sptr	Source string.
	@param	erp	Error report, may be NULL.

	Error codes:
	- DK4_E_INVALID_ARGUMENTS<br>
	  if dptr or sptr is NULL or dsz is 0,
	- DK4_E_BUFFER_TOO_SMALL<br>
	  if dptr is too small,
	- DK4_E_SYNTAX<br>
	  if a non-recodable character was found.
    */
    bool
    InternalStringToWx(
      wxChar *dptr, size_t dsz, const dkChar *sptr, dk4_er_t *erp
    );

    /**	Convert wxChar string to dkChar string.
	@param	dptr	Result buffer.
	@param	dsz	Result buffer size (number of dkChar).
	@param	sptr	Source string.
	@param	erp	Error report, may be NULL.

	Error codes:
	- DK4_E_INVALID_ARGUMENTS<br>
	  if dptr or sptr is NULL or dsz is 0,
	- DK4_E_BUFFER_TOO_SMALL<br>
	  if dptr is too small,
	- DK4_E_SYNTAX<br>
	  if a non-recodable character was found.
    */
    bool
    InternalStringToDk(
      dkChar *dptr, size_t dsz, const wxChar *sptr, dk4_er_t *erp
    );

    /**	Retrieve a string table.
    	@param	tableName	Short string table file name.
	@param	tableSize	Minimum number of elements required in table.
	@return	Pointer to string table found or NULL.
    */
    const wxChar * const *
    InternalGetStringTable(
      const dkChar		*tableName,
      size_t			 tableSize
    );

    /**	Save multiple long values.
	@param	names	Entry names array, sz elements.
	@param	array	Values, sz elements.
	@param	sz	Array size for names and array.
	@return	True on success, false on error.
    */
    bool
    InternalSetMultiple(const wxChar * const *names, long *array, size_t sz);

    /**	Save multiple int values.
	@param	names	Entry names array, sz elements.
	@param	array	Values, sz elements.
	@param	sz	Array size for names and array.
	@return	True on success, false on error.
    */
    bool
    InternalSetMultiple(const wxChar * const *names, int *array, size_t sz);

    /**	Save multiple bool values.
	@param	names	Entry names array, sz elements.
	@param	array	Values, sz elements.
	@param	sz	Array size for names and array.
	@return	True on success, false on error.
    */
    bool
    InternalSetMultiple(const wxChar * const *names, bool *array, size_t sz);

    /**	Save multiple double values.
	@param	names	Entry names array, sz elements.
	@param	array	Values, sz elements.
	@param	sz	Array size for names and array.
	@return	True on success, false on error.
    */
    bool
    InternalSetMultiple(const wxChar * const *names, double *array, size_t sz);

    /**	Save multiple string values.
	@param	names	Entry names array, sz elements.
	@param	array	Values, sz elements.
	@param	sz	Array size for names and array.
	@return	True on success, false on error.
    */
    bool
    InternalSetMultiple(
      const wxChar * const *names, const wxChar * const *array, size_t sz
    );

    /**	Retrieve multiple long values.
	@param	names	Entry names array, sz elements.
	@param	array	Values, sz elements.
	@param	sz	Array size for names and array.
	@return	True on success, false on error.
    */
    bool
    InternalGetMultiple(const wxChar * const *names, long *array, size_t sz);

    /**	Retrieve multiple int values.
	@param	names	Entry names array, sz elements.
	@param	array	Values, sz elements.
	@param	sz	Array size for names and array.
	@return	True on success, false on error.
    */
    bool
    InternalGetMultiple(const wxChar * const *names, int *array, size_t sz);

    /**	Retrieve multiple bool values.
	@param	names	Entry names array, sz elements.
	@param	array	Values, sz elements.
	@param	sz	Array size for names and array.
	@return	True on success, false on error.
    */
    bool
    InternalGetMultiple(const wxChar * const *names, bool *array, size_t sz);

    /**	Retrieve multiple double values.
	@param	names	Entry names array, sz elements.
	@param	array	Values, sz elements.
	@param	sz	Array size for names and array.
	@return	True on success, false on error.
    */
    bool
    InternalGetMultiple(const wxChar * const *names, double *array, size_t sz);

    /**	Retrieve multiple string values.
	@param	names	Entry names array, sz elements.
	@param	array	Values, sz elements.
	@param	sz	Array size for names and array.
	@param	ov	Flag: Overwrite existing strings.
	Memory for already existing strings is freed, memory for the new
	found string is allocated if the flag is set. Existing strings
	are left untouched if the flag is not set.
	@return	True on success, false on error.
    */
    bool
    InternalGetMultiple(
      const wxChar * const *names, wxChar **array, size_t sz, bool ov = true
    );

    /**	Create copy of pdksShare to pwxsShare.
    */
    void
    UpdateWxsShare(void);

  public:

    /**	Error codes in Initialize().
    */
    enum {
    			/**	No error occured.
    			*/
      ERROR_NONE	=	0,
    
    			/**	Not enough memory.
    			*/
      ERROR_MEMORY ,
    
    			/**	Failed to find host name.
    			*/
      ERROR_HOSTNAME ,
    
    			/**	Failed to find localization settings.
    			*/
      ERROR_LANG_REG_ENC ,
    
    			/**	Failed to find login name.
    			*/
      ERROR_LOGNAME ,
    
    			/**	Failed to find home directory.
    			*/
      ERROR_HOMEDIR ,
    
    			/**	Failed to find path name of executable.
    			*/
      ERROR_EXECUTABLE ,
    
    			/**	Executable file name too long.
    			*/
      ERROR_EXEC_TOO_LONG ,
    
    			/**	Invalid arguments were passed to Initialize().
    			*/
      ERROR_ARGUMENTS ,
    };

    /**	Default constructor.
    */
    Dk4WxApplicationHelper();

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

    /**	Initialize before used, called from the applications OnInit() method.
	If this method returns false, the OnInit() method should return
	false too.
	@param	argv0		First command line argument.
	@param	vendorName	Software vendor name.
	@param	groupName	Application group name.
	@param	erp		Error report, may be NULL.
	@return	True if initialized successfully, false otherwise.

	Error codes:
	- DK4_E_NOT_FOUND<br>
	  if the system function(s) failed to find the name of the
	  file currently executed or the users home directory
	  or the users home directory or login name,
	- DK4_E_SYSTEM<br>
	  if the function failed to find the current working directory,
	- DK4_E_SYNTAX<br>
	  if there are string conversion problems,
	- DK4_E_BUFFER_TOO_SMALL<br>
	  if the internal buffer is too small to hold the file name
	  of the executed file, the users home directory, login name
	  or a conversion buffer is too small,
	- DK4_E_SYNTAX<br>
	  if a Windows registry entry differs from the expected type.
	- DK4_E_MATH_OVERFLOW<br>
	  if a numeric overflow occured in a memory allocation size
	  calculation,
	- DK4_E_MEMORY_ALLOCATION_FAILED<br>
	  if a memory allocation attempt failed due to insufficient memory.

    */
    bool
    Initialize(
      const wxChar	*argv0,
      const wxChar	*vendorName,
      const dkChar	*groupName,
      dk4_er_t		*erp		= NULL
    );

    /**	Clean up internal data structures.
	You should call this from the applications OnExit() method.
    */
    void
    Cleanup(void);

    /**	Search for data file.
	@param	fnb	File name buffer.
	@param	szfnb	Buffer size (number of dkChar).
	@param	sfn	Short file name.
	@param	maxpass	Maximum pass number for search.
	@param	aco	Flag: Allow compressed versions.
	@return	True if the file was found (name in fnb), false otherwise.
    */
    bool
    FindDataFile(
      dkChar 		*fnb,
      size_t		 szfnb,
      dkChar const	*sfn,
      int		 maxpass	= DK4_FS_DATA_MAX_SYS,
      bool		 aco		= false
    );

#if DK4_SIZEOF_WXCHAR != DK4_CHAR_SIZE

    /**	Search for data file.
	@param	fnb	File name buffer.
	@param	szfnb	Buffer size (number of wxChar).
	@param	sfn	Short file name.
	@param	maxpass	Maximum pass number for search.
	@param	aco	Flag: Allow compressed versions.
	@return	True if the file was found (name in fnb), false otherwise.
    */
    bool
    FindDataFile(
      wxChar 		*fnb,
      size_t		 szfnb,
      dkChar const	*sfn,
      int		 maxpass	= DK4_FS_DATA_MAX_SYS,
      bool		 aco		= false
    );

#endif

    /**	Search for documentation or help file.
	@param	fnb	File name buffer.
	@param	szfnb	Buffer size (number of dkChar).
	@param	sfn	Short file name.
	@return	True if the file was found (name in fnb), false otherwise.
    */
    bool
    FindHelpFile(
      dkChar 		*fnb,
      size_t		 szfnb,
      dkChar const	*sfn
    );

#if DK4_SIZEOF_WXCHAR != DK4_CHAR_SIZE

    /**	Search for documentation or help file.
	@param	fnb	File name buffer.
	@param	szfnb	Buffer size (number of dkChar).
	@param	sfn	Short file name.
	@return	True if the file was found (name in fnb), false otherwise.
    */
    bool
    FindHelpFile(
      wxChar 		*fnb,
      size_t		 szfnb,
      dkChar const	*sfn
    );

#endif

    /**	Retrieve dkChar encoding.
	@return	Encoding.
    */
    int
    GetDkEncoding(void);

    /**	Retrieve wxChar encoding.
	@return	Encoding.
    */
    int
    GetWxEncoding(void);

    /**	Retrieve expected input encoding when reading files.
	@return	Encoding.
    */
    int
    GetFiEncoding(void);

    /**	Retrieve a string table.
    	@param	tableName	Short string table file name.
	@param	defaultTable	Default strings to use if not found.
	@return	Pointer to string table found or defaultTable.
    */
    const wxChar * const *
    GetStringTable(
      const dkChar		*tableName,
      const wxChar * const	*defaultTable
    );

    /**	Retrieve one of the basic strings.
	@param	numstr	Index of string in basic strings array.
	@return	String pointer on success, NULL on error (index out of range).
    */
    const wxChar *
    GetBasicString(size_t numstr);

    /**	Retrieve entire basic strings array.
	@param	pNumBasicStrings	Address of variable to store the
	array length, may be NULL.
	@return	Pointer to array of basic strings.
    */
    const wxChar * const	*
    GetBasicStrings(size_t *pNumBasicStrings = NULL);

    /**	Convert dkChar string to wxChar string.
	@param	dptr	Result buffer.
	@param	dsz	Buffer size (number of wxChar).
	@param	sptr	Source string.
	@param	erp	Error report, may be NULL.

	Error codes:
	- DK4_E_INVALID_ARGUMENTS<br>
	  if dptr or sptr is NULL or dsz is 0,
	- DK4_E_BUFFER_TOO_SMALL<br>
	  if dptr is too small,
	- DK4_E_SYNTAX<br>
	  if a non-recodable character was found.
    */
    bool
    StringToWx(
      wxChar *dptr, size_t dsz, const dkChar *sptr, dk4_er_t *erp = NULL
    );

    /**	Convert wxChar string to dkChar string.
	@param	dptr	Result buffer.
	@param	dsz	Result buffer size (number of dkChar).
	@param	sptr	Source string.
	@param	erp	Error report, may be NULL.

	Error codes:
	- DK4_E_INVALID_ARGUMENTS<br>
	  if dptr or sptr is NULL or dsz is 0,
	- DK4_E_BUFFER_TOO_SMALL<br>
	  if dptr is too small,
	- DK4_E_SYNTAX<br>
	  if a non-recodable character was found.
    */
    bool
    StringToDk(
      dkChar *dptr, size_t dsz, const wxChar *sptr, dk4_er_t *erp = NULL
    );

    /**	Convert wxChar string to char string.
	@param	dptr	Result buffer.
	@param	dsz	Result buffer size (number of char).
	@param	sptr	Source string.
	@param	erp	Error report, may be NULL.

	Error codes:
	- DK4_E_INVALID_ARGUMENTS<br>
	  if dptr or sptr is NULL or dsz is 0,
	- DK4_E_BUFFER_TOO_SMALL<br>
	  if dptr is too small,
	- DK4_E_SYNTAX<br>
	  if a non-recodable character was found.
    */
    bool
    StringToChar(
      char *dptr, size_t dsz, const wxChar *sptr, dk4_er_t *erp = NULL
    );

    /**	Save multiple long values.
	@param	names	Entry names array, sz elements.
	@param	array	Values, sz elements.
	@param	sz	Array size for names and array.
	@return	True on success, false on error.
    */
    bool
    SetMultiple(const wxChar * const *names, long *array, size_t sz);

    /**	Save multiple int values.
	@param	names	Entry names array, sz elements.
	@param	array	Values, sz elements.
	@param	sz	Array size for names and array.
	@return	True on success, false on error.
    */
    bool
    SetMultiple(const wxChar * const *names, int *array, size_t sz);

    /**	Save multiple bool values.
	@param	names	Entry names array, sz elements.
	@param	array	Values, sz elements.
	@param	sz	Array size for names and array.
	@return	True on success, false on error.
    */
    bool
    SetMultiple(const wxChar * const *names, bool *array, size_t sz);

    /**	Save multiple double values.
	@param	names	Entry names array, sz elements.
	@param	array	Values, sz elements.
	@param	sz	Array size for names and array.
	@return	True on success, false on error.
    */
    bool
    SetMultiple(const wxChar * const *names, double *array, size_t sz);

    /**	Save multiple string values.
	@param	names	Entry names array, sz elements.
	@param	array	Values, sz elements.
	@param	sz	Array size for names and array.
	@return	True on success, false on error.
    */
    bool
    SetMultiple(
      const wxChar * const *names, const wxChar * const *array, size_t sz
    );

    /**	Retrieve multiple long values.
	@param	names	Entry names array, sz elements.
	@param	array	Values, sz elements.
	@param	sz	Array size for names and array.
	@return	True on success, false on error.
    */
    bool
    GetMultiple(const wxChar * const *names, long *array, size_t sz);

    /**	Retrieve multiple int values.
	@param	names	Entry names array, sz elements.
	@param	array	Values, sz elements.
	@param	sz	Array size for names and array.
	@return	True on success, false on error.
    */
    bool
    GetMultiple(const wxChar * const *names, int *array, size_t sz);

    /**	Retrieve multiple bool values.
	@param	names	Entry names array, sz elements.
	@param	array	Values, sz elements.
	@param	sz	Array size for names and array.
	@return	True on success, false on error.
    */
    bool
    GetMultiple(const wxChar * const *names, bool *array, size_t sz);

    /**	Retrieve multiple double values.
	@param	names	Entry names array, sz elements.
	@param	array	Values, sz elements.
	@param	sz	Array size for names and array.
	@return	True on success, false on error.
    */
    bool
    GetMultiple(const wxChar * const *names, double *array, size_t sz);

    /**	Retrieve multiple string values.
	@param	names	Entry names array, sz elements.
	@param	array	Values, sz elements.
	@param	sz	Array size for names and array.
	@param	ov	Flag: Overwrite existing strings.
	Memory for already existing strings is freed, memory for the new
	found string is allocated if the flag is set. Existing strings
	are left untouched if the flag is not set.
	@return	True on success, false on error.
    */
    bool
    GetMultiple(
      const wxChar * const *names, wxChar **array, size_t sz, bool ov = true
    );

    /**	Save one key value pair of strings.
    	@param	key	Key string.
	@param	value	Value string.
	@return	True on success, false on error.
    */
    bool
    SetString(const wxString & key, const wxString & value);

    /**	Retrieve one string value.
    	@param	key	Key string.
	@param	pvalue	Address of value string.
	@return	True on success, false on error.
    */
    bool
    GetString(const wxString & key, wxString *pvalue);

    /**	Get argv[0] command line argument as dkChar string.
    	@return	Valid pointer on success, NULL on error.
    */
    const
    dkChar *
    GetDkArgv0(void);

    /**	Get group name.
    	@return	Valid pointer on success, NULL on error.
    */
    const
    dkChar *
    GetDkGroupName(void);

	/**	Get /usr/share equivalent directory.
		@return	Valid pointer on success, NULL on error.
	*/
	const
	wxChar *
	GetWxsShare(void) const ;

    /**	Correct top level frame position.
    	Negative x or y values can occur for two purposes:
	* When restoring saved positions negative values indicate
	  that no position was saved yet. The window should be centered.
	  Set cn=true for this interpretation.
	* If the position was calculated relatively to another window
	  or frame the window should not exceed the screen. The negative
	  value should be corrected to 0.
	  Set cn=false for this interpretation.
	@param	x	Window x position.
	@param	y	Window y position.
	@param	w	Window width.
	@param	h	Window height.
	@param	cn	Flag: Center window on screen for negative x or y.
    */
    static
    void
    CorrectPosition(int & x, int & y, int & w, int & h, bool cn = true);

    /**	Correct position of a top level window (frame or dialog).
    	Negative x or y values can occur for two purposes:
	* When restoring saved positions negative values indicate
	  that no position was saved yet. The window should be centered.
	  Set cn=true for this interpretation.
	* If the position was calculated relatively to another window
	  or frame the window should not exceed the screen. The negative
	  value should be corrected to 0.
	  Set cn=false for this interpretation.
	@param	w	Window to correct.
	@param	cn	Flag: Center window on screen for negative x or y.
    */
    static
    void
    CorrectPosition(wxWindow & w, bool cn = true);

    /**	Choose position for a child top level window (frame or dialog).
	@param	p	Parent window, unchanged.
	@param	c	Child window, position is set.
	@param	beside	Flag: Position child beside parent, not on top.
    */
    static
    void
    ChooseChildPosition(
      const wxWindow & p, wxWindow & c, bool beside = false
    );

    /**	Find string table size (number of strings in table).
	@param	sttptr	String table to find size for.
	@return	Size of string table.
    */
    static
    size_t
    StringTableSize(const wxChar * const *sttptr);

    /**	Release array of wxChar strings.
	@param	array	Array, array contents is to release.
	@param	sz	Array size.
	@param	ea	Flag: After releasing contents, release array itself.
    */
    static
    void
    ReleaseWxcharStringArray(wxChar **array, size_t sz, bool ea = false);

};



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


#endif