1 // =========================================================================== 2 // Purpose: wxConfig and wxConfigBase classes 3 // Author: J Winwood, John Labenski 4 // Created: 14/11/2001 5 // Copyright: (c) 2001-2002 Lomtick Software. All rights reserved. 6 // Licence: wxWidgets licence 7 // wxWidgets: Updated to 2.8.4 8 // =========================================================================== 9 10 // TODO - add wxConfigFile and Reg 11 12 // --------------------------------------------------------------------------- 13 // wxConfigBase 14 15 #if wxLUA_USE_wxConfig && wxUSE_CONFIG 16 17 #include "wx/confbase.h" 18 #include "wx/config.h" 19 #include "wx/fileconf.h" 20 21 enum 22 { 23 wxCONFIG_USE_LOCAL_FILE, 24 wxCONFIG_USE_GLOBAL_FILE, 25 wxCONFIG_USE_RELATIVE_PATH, 26 wxCONFIG_USE_NO_ESCAPE_CHARACTERS, 27 %wxchkver_2_8_1 wxCONFIG_USE_SUBDIR 28 }; 29 30 enum wxConfigBase::EntryType 31 { 32 Type_Unknown, 33 Type_String, 34 Type_Boolean, 35 Type_Integer, 36 Type_Float 37 }; 38 39 class %delete wxConfigBase : public wxObject 40 { 41 // No constructor since this is a base class 42 43 // %override wxConfigBase::delete() - this is a wxLua provided function to 44 // delete the config (or derived class). Created wxConfigs are NOT tracked 45 // in memory since you MUST call wxConfigBase::Set(NULL) before 46 // deleting them. This is because the wxConfig you install using 47 // wxConfigBase::Set may need to exist outside of the scope it was created 48 // in and we don't want Lua to garbage collect it. 49 //void delete(); 50 51 // Note: the return wxConfig cannot be deleted. 52 // You must call "config = Set(wx.NULL); config:delete()" 53 static wxConfigBase* Create(); 54 static void DontCreateOnDemand(); 55 56 bool DeleteAll(); 57 bool DeleteEntry(const wxString& key, bool bDeleteGroupIfEmpty = true); 58 bool DeleteGroup(const wxString& key); 59 bool Exists(wxString& strName) const; 60 bool Flush(bool bCurrentOnly = false); 61 static wxConfigBase* Get(bool CreateOnDemand = true); 62 wxString GetAppName() const; 63 wxConfigBase::EntryType GetEntryType(const wxString& name) const; 64 65 // %override [bool, string, index] wxConfigBase::GetFirstGroup(); 66 // C++ Func: bool GetFirstGroup(wxString& str, long& index) const; 67 bool GetFirstGroup() const; 68 69 // %override [bool, string, index] wxConfigBase::GetFirstEntry(); 70 // C++ Func: bool GetFirstEntry(wxString& str, long& index) const; 71 bool GetFirstEntry() const; 72 73 // %override [bool, string, index] wxConfigBase::GetNextGroup(index); 74 // C++ Func: bool GetNextGroup(wxString& str, long& index) const; 75 bool GetNextGroup() const; 76 77 // %override [bool, string, index] wxConfigBase::GetNextEntry(index); 78 // C++ Func: bool GetNextEntry(wxString& str, long& index) const; 79 bool GetNextEntry(long index) const; 80 81 unsigned int GetNumberOfEntries(bool bRecursive = false) const; 82 unsigned int GetNumberOfGroups(bool bRecursive = false) const; 83 const wxString& GetPath() const; 84 wxString GetVendorName() const; 85 bool HasEntry(wxString& strName) const; 86 bool HasGroup(const wxString& strName) const; 87 bool IsExpandingEnvVars() const; 88 bool IsRecordingDefaults() const; 89 90 // %override [bool, string] wxConfigBase::Read(const wxString& key, const wxString& defaultVal = ""); 91 // C++ Func: bool Read(const wxString& key, wxString* str, const wxString& defaultVal) const; 92 bool Read(const wxString& key, const wxString& defaultVal = "") const; 93 94 // Since Lua uses double as it's number type, we only read/write doubles 95 96 // %override [bool, double] wxConfigBase::Read(const wxString& key, double defaultVal = 0); 97 // C++ Func: bool Read(const wxString& key, double* d, double defaultVal = 0) const; 98 %override_name wxLua_wxConfigBase_ReadFloat bool Read(const wxString& key, double defaultVal) const; 99 100 // // %override [bool, int] wxConfigBase::ReadInt(const wxString& key, long defaultVal = 0); 101 // // C++ Func: bool Read(const wxString& key, long* l, long defaultVal = 0) const; 102 // %rename ReadInt bool Read(const wxString& key, long defaultVal = 0) const; 103 // // %override [bool, double] wxConfigBase::ReadFloat(const wxString& key, double defaultVal = 0); 104 // // C++ Func: bool Read(const wxString& key, double* d, double defaultVal = 0) const; 105 // %rename ReadFloat bool Read(const wxString& key, double defaultVal = 0) const; 106 107 bool RenameEntry(const wxString& oldName, const wxString& newName); 108 bool RenameGroup(const wxString& oldName, const wxString& newName); 109 static %gc wxConfigBase* Set(%ungc wxConfigBase *pConfig = NULL); 110 void SetExpandEnvVars(bool bDoIt = true); 111 void SetPath(const wxString& strPath); 112 void SetRecordDefaults(bool bDoIt = true); 113 114 115 bool Write(const wxString& key, wxString &value); 116 // Since Lua uses double as it's number type, we only read/write doubles 117 bool Write(const wxString &key, double value); 118 119 // %rename WriteInt bool Write(const wxString &key, long value); 120 // %rename WriteFloat bool Write(const wxString &key, double value); 121 }; 122 123 // --------------------------------------------------------------------------- 124 // wxConfig 125 126 class %delete wxConfig : public wxConfigBase 127 { 128 wxConfig(const wxString& appName = "", const wxString& vendorName = "", const wxString& localFilename = "", const wxString& globalFilename = "", long style = 0); 129 }; 130 131 // --------------------------------------------------------------------------- 132 // wxFileConfig 133 134 class %delete wxFileConfig : public wxConfigBase 135 { 136 wxFileConfig(const wxString& appName = "", const wxString& vendorName = "", const wxString& localFilename = "", const wxString& globalFilename = "", long style = wxCONFIG_USE_LOCAL_FILE | wxCONFIG_USE_GLOBAL_FILE); //, wxMBConv& conv = wxConvUTF8); 137 wxFileConfig(wxInputStream& is); //, const wxMBConv& conv = wxConvAuto()); 138 139 static wxFileName GetGlobalFile(const wxString& basename); 140 static wxFileName GetLocalFile(const wxString& basename, int style = 0); 141 142 static wxString GetGlobalFileName(const wxString& szFile); 143 static wxString GetLocalFileName(const wxString& szFile, int style = 0); 144 145 virtual bool Save(wxOutputStream& os); //, const wxMBConv& conv = wxConvAuto()); 146 147 %wxchkver_3_1_3 void EnableAutoSave(); 148 %wxchkver_3_1_3 void DisableAutoSave(); 149 150 void SetUmask(int mode); 151 }; 152 153 // --------------------------------------------------------------------------- 154 // wxMemoryConfig 155 156 #include "wx/memconf.h" 157 158 class %delete wxMemoryConfig : public wxFileConfig 159 { 160 wxMemoryConfig(); 161 }; 162 163 // --------------------------------------------------------------------------- 164 // wxConfigPathChanger 165 166 // a handy little class which changes current path to the path of given entry 167 // and restores it in dtor: so if you declare a local variable of this type, 168 // you work in the entry directory and the path is automatically restored 169 // when the function returns 170 171 class %delete wxConfigPathChanger 172 { 173 // NOTE: ALWAYS delete() this when done since Lua's gc may not delete it soon enough 174 wxConfigPathChanger(const wxConfigBase *pContainer, const wxString& strEntry); 175 176 wxString Name() const; 177 %wxchkver_2_8 void UpdateIfDeleted(); 178 }; 179 180 #endif //wxLUA_USE_wxConfig && wxUSE_CONFIG 181