/* 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: Dk4WxApplicationHelper.cpt */ /* Copyright (C) 2015-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. */ #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 #include "dk4conf.h" #endif #ifndef DK4TYPES_H_INCLUDED #include "dk4types.h" #endif #ifndef DK4CONST_H_INCLUDED #include "dk4const.h" #endif #ifndef DK4ERROR_H_INCLUDED #include "dk4error.h" #endif #ifndef DK4STO_H_INCLUDED #include "dk4sto.h" #endif #ifndef DK4WXCS_H_INCLUDED #include "dk4wxcs.h" #endif #ifndef DK4FSH_H_INCLUDED #include "dk4fs.h" #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 #define WX_CONFIG_H_INCLUDED 1 #endif #ifndef WX_FILENAME_H_INCLUDED #include #define WX_FILENAME_H_INCLUDED 1 #endif #ifndef WX_THREAD_H_INCLUDED #include #define WX_THREAD_H_INCLUDED 1 #endif #ifndef DK4WXSTT_H_INCLUDED #include "dk4wxstt.h" #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; /** 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 /** 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
if dptr or sptr is NULL or dsz is 0, - DK4_E_BUFFER_TOO_SMALL
if dptr is too small, - DK4_E_SYNTAX
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
if dptr or sptr is NULL or dsz is 0, - DK4_E_BUFFER_TOO_SMALL
if dptr is too small, - DK4_E_SYNTAX
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 ); public: /** 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
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
if the function failed to find the current working directory, - DK4_E_SYNTAX
if there are string conversion problems, - DK4_E_BUFFER_TOO_SMALL
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
if a Windows registry entry differs from the expected type. - DK4_E_MATH_OVERFLOW
if a numeric overflow occured in a memory allocation size calculation, - DK4_E_MEMORY_ALLOCATION_FAILED
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 /** 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
if dptr or sptr is NULL or dsz is 0, - DK4_E_BUFFER_TOO_SMALL
if dptr is too small, - DK4_E_SYNTAX
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
if dptr or sptr is NULL or dsz is 0, - DK4_E_BUFFER_TOO_SMALL
if dptr is too small, - DK4_E_SYNTAX
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
if dptr or sptr is NULL or dsz is 0, - DK4_E_BUFFER_TOO_SMALL
if dptr is too small, - DK4_E_SYNTAX
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 ); /** Correct top level frame position. @param x Window x position. @param y Window y position. @param w Window width. @param h Window height. */ static void CorrectPosition(int & x, int & y, int & w, int & h); /** Correct position of a top level window (frame or dialog). @param w Window to correct. */ static void CorrectPosition(wxWindow & w); /** 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); }; #endif