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