1 /* 2 Copyright (C) 2011-2021, Dirk Krause 3 SPDX-License-Identifier: BSD-3-Clause 4 */ 5 6 /* 7 WARNING: This file was generated by the dkct program (see 8 http://dktools.sourceforge.net/ for details). 9 Changes you make here will be lost if dkct is run again! 10 You should modify the original source and run dkct on it. 11 Original source: DkWxAppHelper.cpt 12 */ 13 14 /** @file DkWxAppHelper.h Header file for the DkWxAppHelper module. 15 */ 16 17 #ifndef DKWXAPPHELPER_H_INCLUDED 18 /** Avoid multiple inclusions. */ 19 #define DKWXAPPHELPER_H_INCLUDED 1 20 21 22 #if 0 23 #include <libdk3c/dk3all.h> 24 #else 25 #include "dk3conf.h" 26 #include <libdk3c/dk3types.h> 27 #include <libdk3c/dk3const.h> 28 #endif 29 30 31 32 #include <wx/wxprec.h> 33 #ifdef __BORLANDC__ 34 #pragma hdrstop 35 #endif 36 #ifndef WX_PRECOMP 37 #include <wx/wx.h> 38 #endif 39 #include <wx/config.h> 40 #include <wx/filename.h> 41 42 /** Application helper class, provides file search, internationalization 43 and some functions for GUI development using the wxWidgets libraries. 44 */ 45 class DkWxAppHelper 46 { 47 protected: 48 49 /** Error codes. 50 */ 51 enum { 52 /** No error occured. 53 */ 54 ERROR_NONE = 0, 55 /** Failed to encode arg0 to dkChar. 56 */ 57 ERROR_ENCODE_ARG0 , 58 }; 59 60 /** Application structure. 61 */ 62 dk3_app_t *app; 63 64 /** Storage for string tables. 65 */ 66 dk3_sto_t *sStringTables; 67 68 /** Iterator through string tables storage. 69 */ 70 dk3_sto_it_t *iStringTables; 71 72 /** Basic strings used by wxWidgets applications. 73 */ 74 wxChar const * const *basicStrings; 75 76 /** First command line argument. 77 */ 78 wxChar const *cmdName; 79 80 /** Application name. 81 */ 82 wxChar const *appName; 83 84 /** Software vendor name. 85 */ 86 wxChar const *vendorName; 87 88 /** Number of entries in the basicStrings array. 89 */ 90 size_t nBasicStrings; 91 92 /** Encoding for dkChar. 93 */ 94 int dkEncoding; 95 96 /** Encoding for wxChar. 97 */ 98 int wxEncoding; 99 100 /** Code for errors from constructor. 101 */ 102 int errorCode; 103 104 protected: 105 106 /** Report problems within the constructor, if any. 107 */ 108 void 109 reportProblemsIfAny(void); 110 111 /** Show an error message. 112 @param i_title Index of dialog title in basic strings. 113 @param i_text Index of message text in basic strings. 114 */ 115 void 116 showErrorMessage(size_t i_title, size_t i_text); 117 118 public: 119 120 /** Constructor. 121 @param arg0 First command line argument. 122 @param vName Software vendor name. 123 @param groupName Application group name. 124 */ 125 DkWxAppHelper( 126 wxChar const *arg0, 127 wxChar const *vName, 128 dkChar const *groupName 129 ); 130 131 /** Destructor. 132 */ 133 ~DkWxAppHelper(); 134 135 /** Check whether application helper object is set up correctly 136 and is ready to use. 137 @return 1 on success, 0 on error. 138 */ 139 int 140 checkSetup() const; 141 142 /** Retrieve array of localized texts. 143 @param dt Default texts, used if problems occur. 144 @param tn Table name. 145 @return Pointer to localized messages array or dt. 146 */ 147 wxChar const * const * 148 getStringTable( 149 wxChar const * const *dt, 150 dkChar const *tn 151 ); 152 153 /** Find data file name. Provide a short file name like "x.y", 154 on success the program writes a full path like 155 "/usr/share/myapp/en/x.y" to the result buffer. 156 @param fn Short file name. 157 @param fnb Buffer for full path name. 158 @param szfnb Size of @arg fnb (number of wxChar). 159 @return 1 on success, 0 on error. 160 */ 161 int 162 findDataFile(wxChar const *fn, wxChar *fnb, size_t szfnb); 163 164 /** Retrieve multiple int settings at once. 165 @param names Pointer to names array, must be terminated 166 by a NULL pointer. 167 @param values Pointer to destination value array. 168 @return Number of items read successfully. 169 */ 170 size_t 171 retrieveMultipleInts( 172 wxChar const * const *names, 173 int *values 174 ) const; 175 176 /** Retrieve multiple long settings at once. 177 @param names Pointer to names array, must be terminated 178 by a NULL pointer. 179 @param values Pointer to destination value array. 180 @return Number of items read successfully. 181 */ 182 size_t 183 retrieveMultipleLongs( 184 wxChar const * const *names, 185 long *values 186 ) const; 187 188 /** Save multiple int settings at once. 189 @param names Pointer to names array, must be terminated by 190 a NULL pointer. 191 @param values Pointer to values array. 192 @return Number of items successfully written. 193 */ 194 size_t 195 saveMultipleInts( 196 wxChar const * const *names, 197 int *values 198 ) const; 199 200 /** Save multiple long settings at once. 201 @param names Pointer to names array, must be terminated by 202 a NULL pointer. 203 @param values Pointer to values array. 204 @return Number of items successfully written. 205 */ 206 size_t 207 saveMultipleLongs( 208 wxChar const * const *names, 209 long *values 210 ) const; 211 212 /** Retrieve multiple double settings at once. 213 @param names Pointer to names array, must be terminated by 214 a NULL pointer. 215 @param values Pointer to values array. 216 @return Number of items successfully read. 217 */ 218 size_t 219 retrieveMultipleDoubles( 220 wxChar const * const *names, 221 double *values 222 ) const; 223 224 /** Save multiple doubles at once. 225 @param names Pointer to names array, must be terminated by 226 a NULL pointer. 227 @param values Pointer to values array. 228 @return Number of items successfully written. 229 */ 230 size_t 231 saveMultipleDoubles( 232 wxChar const * const *names, 233 double *values 234 ) const; 235 236 /** Retrieve a string preference. 237 @param name Preference name. 238 @return Pointer to new string on success, NULL on error. 239 */ 240 wxChar const * 241 retrieveString( 242 wxChar const *name 243 ) const; 244 245 /** Save a string entry. 246 @param name Entry name. 247 @param value Entry value. 248 @return 1 on success, 0 on error. 249 */ 250 int 251 saveString( 252 wxChar const *name, 253 wxChar const *value 254 ) const; 255 256 /** Retrieve encoding for wxChar. 257 @return Encoding used for wxChar. 258 */ 259 int 260 getWxEncoding() const; 261 262 /** Retrieve encoding for dkChar. 263 @return Encoding used for dkChar. 264 */ 265 int 266 getDkEncoding() const; 267 268 /** Retrieve encoding to use for 8 bit characters. 269 @return Encoding to use for 8 bit character strings. 270 */ 271 int 272 getC8Encoding() const; 273 274 /** Retrieve application structure. 275 @return Application structure on success, NULL on error. 276 */ 277 dk3_app_t * 278 getApp() const; 279 280 /** Get one of the basic application strings. 281 @param i Index of string in array. 282 @return String pointer on success or NULL on error. 283 */ 284 wxChar const * 285 getBasicString(size_t i) const; 286 287 /** Get basic strings array. 288 @return Array pointer to basic strings. 289 */ 290 wxChar const * const * 291 getBasicStrings() const; 292 293 /** Find number of basic strings stored in the \a basicStrings array. 294 @return Number of strings in the array. 295 */ 296 size_t 297 getBasicStringNumbers() const; 298 299 /** Convert wxChar string to dkChar string. 300 @param bu Destination buffer. 301 @param sz Destination buffer size (number of dkChar). 302 @param src Source buffer. 303 @return true on success, false on error. 304 */ 305 bool 306 wxToDk(dkChar *bu, size_t sz, wxChar const *src) const; 307 308 /** Convert wxChar string to 8-bit char string. 309 @param bu Destination buffer. 310 @param sz Destination buffer size. 311 @param src Source buffer. 312 @return true on success, false on error. 313 */ 314 bool 315 wxToC8(char *bu, size_t sz, wxChar const *src) const; 316 317 /** Convert wxChar string to 8-bit char string. 318 @param bu Destination buffer. 319 @param sz Destination buffer size. 320 @param str Source string. 321 @return true on success, false on error. 322 */ 323 bool 324 wxToC8(char *bu, size_t sz, wxString & str) const; 325 326 /** Convert dkChar string to wxChar string. 327 @param bu Destination buffer. 328 @param sz Destination buffer size (number of wxChar). 329 @param src Source buffer. 330 @return true on success, false on error. 331 */ 332 bool 333 dkToWx(wxChar *bu, size_t sz, dkChar const *src) const; 334 335 /** Set related position (child over parent), the child 336 is either placed on a known previous position or placed 337 centered on top of the parent. 338 @param parent Parent top level window (frame). 339 @param child Child top level window (dialog). 340 @param pcx Pointer to previous child x position. 341 @param pcy Pointer to previous child y position. 342 */ 343 void 344 setRelatedPosition( 345 wxWindow *parent, 346 wxWindow *child, 347 int *pcx = NULL, 348 int *pcy = NULL 349 ) const; 350 351 }; 352 353 354 355 356 #endif 357