summaryrefslogtreecommitdiff
path: root/support/dktools/DkWxAppHelper.h
blob: c4ec96724ef3914825ad927d51e55d66b927e11f (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
/*
	WARNING: This file was generated by dkct.
	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: DkWxAppHelper.cpt
*/

/*
Copyright (C) 2011-2017, Dirk Krause

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice,
  this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above opyright notice,
  this list of conditions and the following disclaimer in the documentation
  and/or other materials provided with the distribution.
* Neither the name of the author nor the names of contributors may be used
  to endorse or promote products derived from this software without specific
  prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

/**	@file DkWxAppHelper.h Header file for the DkWxAppHelper module.
*/

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


#line 10 "DkWxAppHelper.cpt"

#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;

};




#endif