]>
Commit | Line | Data |
---|---|---|
2bda0e17 KB |
1 | /////////////////////////////////////////////////////////////////////////////// |
2 | // Name: msw/registry.h | |
3 | // Purpose: Registry classes and functions | |
4 | // Author: Vadim Zeitlin | |
23f681ec | 5 | // Modified by: |
2bda0e17 KB |
6 | // Created: 03.04.198 |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) 1998 Vadim Zeitlin <zeitlin@dptmaths.ens-cachan.fr> | |
bbcdf8bc | 9 | // Licence: wxWindows licence |
2bda0e17 KB |
10 | /////////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #ifndef _REGISTRY_H | |
13 | #define _REGISTRY_H | |
14 | ||
0d3820b3 JS |
15 | #ifdef __GNUG__ |
16 | #pragma interface "registry.h" | |
17 | #endif | |
18 | ||
2bda0e17 | 19 | // ---------------------------------------------------------------------------- |
8f494e5d | 20 | // types used in this module |
2bda0e17 | 21 | // ---------------------------------------------------------------------------- |
0d8d91a9 JS |
22 | |
23 | /* | |
2bda0e17 KB |
24 | #ifndef HKEY_DEFINED |
25 | #define HKEY_DEFINED | |
26 | #define HKEY unsigned long | |
27 | #endif | |
0d8d91a9 | 28 | */ |
2bda0e17 | 29 | |
8f494e5d VZ |
30 | typedef unsigned long ulong; |
31 | ||
2bda0e17 KB |
32 | // ---------------------------------------------------------------------------- |
33 | // class wxRegKey encapsulates window HKEY handle | |
34 | // ---------------------------------------------------------------------------- | |
1fa9e5bc | 35 | class WXDLLIMPEXP_BASE wxRegKey |
2bda0e17 KB |
36 | { |
37 | public: | |
38 | // NB: do _not_ change the values of elements in these enumerations! | |
39 | ||
40 | // registry value types (with comments from winnt.h) | |
41 | enum ValueType | |
42 | { | |
43 | Type_None, // No value type | |
44 | Type_String, // Unicode nul terminated string | |
45 | #ifdef __WIN32__ | |
46 | Type_Expand_String, // Unicode nul terminated string | |
47 | // (with environment variable references) | |
48 | Type_Binary, // Free form binary | |
49 | Type_Dword, // 32-bit number | |
23f681ec VZ |
50 | Type_Dword_little_endian // 32-bit number |
51 | = Type_Dword, // (same as Type_DWORD) | |
2bda0e17 KB |
52 | Type_Dword_big_endian, // 32-bit number |
53 | Type_Link, // Symbolic Link (unicode) | |
54 | Type_Multi_String, // Multiple Unicode strings | |
55 | Type_Resource_list, // Resource list in the resource map | |
56 | Type_Full_resource_descriptor, // Resource list in the hardware description | |
a3ef5bf5 | 57 | Type_Resource_requirements_list // ??? |
2bda0e17 KB |
58 | #endif //WIN32 |
59 | }; | |
60 | ||
61 | // predefined registry keys | |
62 | enum StdKey | |
63 | { | |
23f681ec | 64 | HKCR // classes root |
2bda0e17 | 65 | #ifdef __WIN32__ |
23f681ec VZ |
66 | , |
67 | HKCU, // current user | |
68 | HKLM, // local machine | |
69 | HKUSR, // users | |
70 | HKPD // performance data (WinNT/2K only) | |
71 | #if WINVER >= 0x0400 | |
72 | , | |
73 | HKCC, // current config (starting from Win95/NT 4.0) | |
74 | HKDD // dynamic data (Win95/98 only) | |
2bda0e17 KB |
75 | #endif // Winver |
76 | #endif // Win32/16 | |
77 | }; | |
78 | ||
79 | // information about standard (predefined) registry keys | |
80 | // number of standard keys | |
81 | static const size_t nStdKeys; | |
82 | // get the name of a standard key | |
4de6207a | 83 | static const wxChar *GetStdKeyName(size_t key); |
2bda0e17 | 84 | // get the short name of a standard key |
4de6207a | 85 | static const wxChar *GetStdKeyShortName(size_t key); |
2bda0e17 | 86 | // get StdKey from root HKEY |
0d8d91a9 | 87 | static StdKey GetStdKeyFromHkey(WXHKEY hkey); |
2bda0e17 KB |
88 | |
89 | // extacts the std key prefix from the string (return value) and | |
90 | // leaves only the part after it (i.e. modifies the string passed!) | |
91 | static StdKey ExtractKeyName(wxString& str); | |
92 | ||
93 | // ctors | |
94 | // root key is set to HKCR (the only root key under Win16) | |
95 | wxRegKey(); | |
96 | // strKey is the full name of the key (i.e. starting with HKEY_xxx...) | |
97 | wxRegKey(const wxString& strKey); | |
98 | // strKey is the name of key under (standard key) keyParent | |
2dc77646 | 99 | wxRegKey(StdKey keyParent, const wxString& strKey); |
2bda0e17 KB |
100 | // strKey is the name of key under (previously created) keyParent |
101 | wxRegKey(const wxRegKey& keyParent, const wxString& strKey); | |
102 | // | |
103 | ~wxRegKey(); | |
104 | ||
105 | // change key (closes the previously opened key if any) | |
2dc77646 | 106 | // the name is absolute, i.e. should start with HKEY_xxx |
2bda0e17 | 107 | void SetName(const wxString& strKey); |
2dc77646 VZ |
108 | // the name is relative to the parent key |
109 | void SetName(StdKey keyParent, const wxString& strKey); | |
110 | // the name is relative to the parent key | |
111 | void SetName(const wxRegKey& keyParent, const wxString& strKey); | |
112 | // hKey should be opened and will be closed in wxRegKey dtor | |
0d8d91a9 | 113 | void SetHkey(WXHKEY hKey); |
2bda0e17 KB |
114 | |
115 | // get infomation about the key | |
116 | // get the (full) key name. Abbreviate std root keys if bShortPrefix. | |
cf447356 | 117 | wxString GetName(bool bShortPrefix = TRUE) const; |
2dc77646 | 118 | // return true if the key exists |
8f494e5d VZ |
119 | bool Exists() const; |
120 | // get the info about key (any number of these pointers may be NULL) | |
3cda6353 VZ |
121 | bool GetKeyInfo(size_t *pnSubKeys, // number of subkeys |
122 | size_t *pnMaxKeyLen, // max len of subkey name | |
123 | size_t *pnValues, // number of values | |
124 | size_t *pnMaxValueLen) const; | |
2dc77646 | 125 | // return true if the key is opened |
8f494e5d | 126 | bool IsOpened() const { return m_hKey != 0; } |
2bda0e17 KB |
127 | // for "if ( !key ) wxLogError(...)" kind of expressions |
128 | operator bool() const { return m_dwLastError == 0; } | |
129 | ||
130 | // operations on the key itself | |
131 | // explicitly open the key (will be automatically done by all functions | |
132 | // which need the key to be opened if the key is not opened yet) | |
133 | bool Open(); | |
23f681ec | 134 | // create the key: will fail if the key already exists and !bOkIfExists |
cf447356 | 135 | bool Create(bool bOkIfExists = TRUE); |
23f681ec VZ |
136 | // rename a value from old name to new one |
137 | bool RenameValue(const wxChar *szValueOld, const wxChar *szValueNew); | |
225fe9d6 VZ |
138 | // rename the key |
139 | bool Rename(const wxChar *szNewName); | |
23f681ec VZ |
140 | // copy value to another key possibly changing its name (by default it will |
141 | // remain the same) | |
142 | bool CopyValue(const wxChar *szValue, wxRegKey& keyDst, | |
143 | const wxChar *szNewName = NULL); | |
144 | // copy the entire contents of the key recursively to another location | |
225fe9d6 | 145 | bool Copy(const wxChar *szNewName); |
23f681ec VZ |
146 | // same as Copy() but using a key and not the name |
147 | bool Copy(wxRegKey& keyDst); | |
2bda0e17 KB |
148 | // close the key (will be automatically done in dtor) |
149 | bool Close(); | |
150 | ||
151 | // deleting keys/values | |
152 | // deletes this key and all of it's subkeys/values | |
153 | bool DeleteSelf(); | |
154 | // deletes the subkey with all of it's subkeys/values recursively | |
4de6207a | 155 | bool DeleteKey(const wxChar *szKey); |
2bda0e17 | 156 | // deletes the named value (may be NULL to remove the default value) |
4de6207a | 157 | bool DeleteValue(const wxChar *szValue); |
2bda0e17 KB |
158 | |
159 | // access to values and subkeys | |
160 | // get value type | |
4de6207a | 161 | ValueType GetValueType(const wxChar *szValue) const; |
90186e52 | 162 | // returns TRUE if the value contains a number (else it's some string) |
4de6207a | 163 | bool IsNumericValue(const wxChar *szValue) const; |
2bda0e17 KB |
164 | |
165 | // assignment operators set the default value of the key | |
166 | wxRegKey& operator=(const wxString& strValue) | |
167 | { SetValue(NULL, strValue); return *this; } | |
168 | wxRegKey& operator=(long lValue) | |
169 | { SetValue(NULL, lValue); return *this; } | |
170 | ||
50e42404 VZ |
171 | // query the default value of the key: implicitly or explicitly |
172 | wxString QueryDefaultValue() const; | |
173 | operator wxString() const { return QueryDefaultValue(); } | |
174 | ||
175 | // named values | |
2bda0e17 KB |
176 | |
177 | // set the string value | |
4de6207a | 178 | bool SetValue(const wxChar *szValue, const wxString& strValue); |
6dfec4b8 VZ |
179 | // retrieve the string value |
180 | bool QueryValue(const wxChar *szValue, wxString& strValue) const | |
181 | { return QueryValue(szValue, strValue, FALSE); } | |
182 | // retrieve raw string value | |
183 | bool QueryRawValue(const wxChar *szValue, wxString& strValue) const | |
184 | { return QueryValue(szValue, strValue, TRUE); } | |
185 | // retrieve either raw or expanded string value | |
186 | bool QueryValue(const wxChar *szValue, wxString& strValue, bool raw) const; | |
2bda0e17 KB |
187 | |
188 | #ifdef __WIN32__ | |
189 | // set the numeric value | |
4de6207a | 190 | bool SetValue(const wxChar *szValue, long lValue); |
2bda0e17 | 191 | // return the numeric value |
4de6207a | 192 | bool QueryValue(const wxChar *szValue, long *plValue) const; |
2bda0e17 KB |
193 | #endif //Win32 |
194 | ||
2dc77646 VZ |
195 | // query existence of a key/value |
196 | // return true if value exists | |
92049cd4 | 197 | bool HasValue(const wxChar *szKey) const; |
2dc77646 | 198 | // return true if given subkey exists |
92049cd4 | 199 | bool HasSubKey(const wxChar *szKey) const; |
2dc77646 | 200 | // return true if any subkeys exist |
92049cd4 VZ |
201 | bool HasSubkeys() const; |
202 | // return true if any values exist | |
203 | bool HasValues() const; | |
204 | // return true if the key is empty (nothing under this key) | |
205 | bool IsEmpty() const { return !HasSubkeys() && !HasValues(); } | |
2bda0e17 KB |
206 | |
207 | // enumerate values and subkeys | |
2bda0e17 KB |
208 | bool GetFirstValue(wxString& strValueName, long& lIndex); |
209 | bool GetNextValue (wxString& strValueName, long& lIndex) const; | |
2bda0e17 KB |
210 | |
211 | bool GetFirstKey (wxString& strKeyName , long& lIndex); | |
212 | bool GetNextKey (wxString& strKeyName , long& lIndex) const; | |
213 | ||
807a903e VZ |
214 | // for wxRegConfig usage only: preallocate some memory for the name |
215 | void ReserveMemoryForName(size_t bytes) { m_strKey.reserve(bytes); } | |
216 | ||
2bda0e17 | 217 | private: |
807a903e VZ |
218 | // common part of all ctors |
219 | void Init() | |
220 | { | |
221 | m_hKey = (WXHKEY) NULL; | |
222 | m_dwLastError = 0; | |
223 | } | |
224 | ||
2bda0e17 KB |
225 | // no copy ctor/assignment operator |
226 | wxRegKey(const wxRegKey& key); // not implemented | |
227 | wxRegKey& operator=(const wxRegKey& key); // not implemented | |
228 | ||
c085e333 | 229 | WXHKEY m_hKey, // our handle |
2bda0e17 KB |
230 | m_hRootKey; // handle of the top key (i.e. StdKey) |
231 | wxString m_strKey; // key name (relative to m_hRootKey) | |
232 | ||
807a903e | 233 | long m_dwLastError; // last error (0 if none) |
2bda0e17 KB |
234 | }; |
235 | ||
236 | #endif //_REGISTRY_H | |
2dc77646 | 237 |