/* 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 #endif #endif #ifndef DK4_SIZEOF_WXCHAR #ifndef DK4WXCS_H_INCLUDED #if DK4_BUILDING_DKTOOLS4 #include "dk4wxcs.h" #else #include #endif #endif #endif #ifndef DK4TYPES_H_INCLUDED #if DK4_BUILDING_DKTOOLS4 #include "dk4types.h" #else #include #endif #endif #ifndef DK4CONST_H_INCLUDED #if DK4_BUILDING_DKTOOLS4 #include "dk4const.h" #else #include #endif #endif #ifndef DK4ERROR_H_INCLUDED #if DK4_BUILDING_DKTOOLS4 #include "dk4error.h" #else #include #endif #endif #ifndef DK4STO_H_INCLUDED #if DK4_BUILDING_DKTOOLS4 #include "dk4sto.h" #else #include #endif #endif #ifndef DK4WXCS_H_INCLUDED #if DK4_BUILDING_DKTOOLS4 #include "dk4wxcs.h" #else #include #endif #endif #ifndef DK4FSH_H_INCLUDED #if DK4_BUILDING_DKTOOLS4 #include "dk4fs.h" #else #include #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 #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 #if DK4_BUILDING_DKTOOLS4 #include "dk4wxstt.h" #else #include #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 sfn in the following directories, first file found is returned: - /usr/share/group/help/program/language/region - /usr/share/doc/group/help/program/language/region - /usr/share/group/help/program/language - /usr/share/doc/group/help/program/language - /usr/share/group/help/program/en - /usr/share/doc/group/help/program/en - /usr/share/group/help/program - /usr/share/doc/group/help/program 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
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 ); /** 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
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 /** 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
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 ); /** 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