]> git.saurik.com Git - wxWidgets.git/blame - include/wx/msw/registry.h
implemented wxMenuBar ctor taking array of menus/titles for all ports; added optional...
[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
12028905 15#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
0d3820b3
JS
16#pragma interface "registry.h"
17#endif
18
20d8c319 19class WXDLLIMPEXP_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
20d8c319
VZ
55 HKUSR // users
56#ifndef __WXWINCE__
57 ,
23f681ec 58 HKPD // performance data (WinNT/2K only)
20d8c319 59#endif
23f681ec
VZ
60#if WINVER >= 0x0400
61 ,
62 HKCC, // current config (starting from Win95/NT 4.0)
63 HKDD // dynamic data (Win95/98 only)
2bda0e17 64#endif // Winver
2bda0e17
KB
65 };
66
bee96abf
VZ
67 // access mode for the key
68 enum AccessMode
69 {
70 Read, // read-only
71 Write // read and write
72 };
73
2bda0e17
KB
74 // information about standard (predefined) registry keys
75 // number of standard keys
76 static const size_t nStdKeys;
77 // get the name of a standard key
4de6207a 78 static const wxChar *GetStdKeyName(size_t key);
2bda0e17 79 // get the short name of a standard key
4de6207a 80 static const wxChar *GetStdKeyShortName(size_t key);
2bda0e17 81 // get StdKey from root HKEY
0d8d91a9 82 static StdKey GetStdKeyFromHkey(WXHKEY hkey);
2bda0e17
KB
83
84 // extacts the std key prefix from the string (return value) and
85 // leaves only the part after it (i.e. modifies the string passed!)
86 static StdKey ExtractKeyName(wxString& str);
87
88 // ctors
89 // root key is set to HKCR (the only root key under Win16)
90 wxRegKey();
91 // strKey is the full name of the key (i.e. starting with HKEY_xxx...)
92 wxRegKey(const wxString& strKey);
93 // strKey is the name of key under (standard key) keyParent
2dc77646 94 wxRegKey(StdKey keyParent, const wxString& strKey);
2bda0e17
KB
95 // strKey is the name of key under (previously created) keyParent
96 wxRegKey(const wxRegKey& keyParent, const wxString& strKey);
bee96abf 97 // dtor closes the key
2bda0e17
KB
98 ~wxRegKey();
99
100 // change key (closes the previously opened key if any)
2dc77646 101 // the name is absolute, i.e. should start with HKEY_xxx
2bda0e17 102 void SetName(const wxString& strKey);
2dc77646
VZ
103 // the name is relative to the parent key
104 void SetName(StdKey keyParent, const wxString& strKey);
105 // the name is relative to the parent key
106 void SetName(const wxRegKey& keyParent, const wxString& strKey);
107 // hKey should be opened and will be closed in wxRegKey dtor
0d8d91a9 108 void SetHkey(WXHKEY hKey);
2bda0e17
KB
109
110 // get infomation about the key
111 // get the (full) key name. Abbreviate std root keys if bShortPrefix.
4d08943e 112 wxString GetName(bool bShortPrefix = true) const;
2dc77646 113 // return true if the key exists
8f494e5d
VZ
114 bool Exists() const;
115 // get the info about key (any number of these pointers may be NULL)
3cda6353
VZ
116 bool GetKeyInfo(size_t *pnSubKeys, // number of subkeys
117 size_t *pnMaxKeyLen, // max len of subkey name
118 size_t *pnValues, // number of values
119 size_t *pnMaxValueLen) const;
2dc77646 120 // return true if the key is opened
8f494e5d 121 bool IsOpened() const { return m_hKey != 0; }
2bda0e17
KB
122 // for "if ( !key ) wxLogError(...)" kind of expressions
123 operator bool() const { return m_dwLastError == 0; }
124
125 // operations on the key itself
126 // explicitly open the key (will be automatically done by all functions
127 // which need the key to be opened if the key is not opened yet)
bee96abf 128 bool Open(AccessMode mode = Write);
23f681ec 129 // create the key: will fail if the key already exists and !bOkIfExists
4d08943e 130 bool Create(bool bOkIfExists = true);
23f681ec
VZ
131 // rename a value from old name to new one
132 bool RenameValue(const wxChar *szValueOld, const wxChar *szValueNew);
225fe9d6
VZ
133 // rename the key
134 bool Rename(const wxChar *szNewName);
23f681ec
VZ
135 // copy value to another key possibly changing its name (by default it will
136 // remain the same)
137 bool CopyValue(const wxChar *szValue, wxRegKey& keyDst,
138 const wxChar *szNewName = NULL);
139 // copy the entire contents of the key recursively to another location
225fe9d6 140 bool Copy(const wxChar *szNewName);
23f681ec
VZ
141 // same as Copy() but using a key and not the name
142 bool Copy(wxRegKey& keyDst);
2bda0e17
KB
143 // close the key (will be automatically done in dtor)
144 bool Close();
145
146 // deleting keys/values
147 // deletes this key and all of it's subkeys/values
148 bool DeleteSelf();
149 // deletes the subkey with all of it's subkeys/values recursively
4de6207a 150 bool DeleteKey(const wxChar *szKey);
2bda0e17 151 // deletes the named value (may be NULL to remove the default value)
4de6207a 152 bool DeleteValue(const wxChar *szValue);
2bda0e17
KB
153
154 // access to values and subkeys
155 // get value type
4de6207a 156 ValueType GetValueType(const wxChar *szValue) const;
4d08943e 157 // returns true if the value contains a number (else it's some string)
4de6207a 158 bool IsNumericValue(const wxChar *szValue) const;
2bda0e17
KB
159
160 // assignment operators set the default value of the key
161 wxRegKey& operator=(const wxString& strValue)
162 { SetValue(NULL, strValue); return *this; }
163 wxRegKey& operator=(long lValue)
164 { SetValue(NULL, lValue); return *this; }
165
50e42404
VZ
166 // query the default value of the key: implicitly or explicitly
167 wxString QueryDefaultValue() const;
168 operator wxString() const { return QueryDefaultValue(); }
169
170 // named values
2bda0e17
KB
171
172 // set the string value
4de6207a 173 bool SetValue(const wxChar *szValue, const wxString& strValue);
6dfec4b8
VZ
174 // retrieve the string value
175 bool QueryValue(const wxChar *szValue, wxString& strValue) const
4d08943e 176 { return QueryValue(szValue, strValue, false); }
6dfec4b8
VZ
177 // retrieve raw string value
178 bool QueryRawValue(const wxChar *szValue, wxString& strValue) const
4d08943e 179 { return QueryValue(szValue, strValue, true); }
6dfec4b8
VZ
180 // retrieve either raw or expanded string value
181 bool QueryValue(const wxChar *szValue, wxString& strValue, bool raw) const;
2bda0e17 182
2bda0e17 183 // set the numeric value
4de6207a 184 bool SetValue(const wxChar *szValue, long lValue);
2bda0e17 185 // return the numeric value
4de6207a 186 bool QueryValue(const wxChar *szValue, long *plValue) const;
9b386eca
RG
187 // set the binary value
188 bool SetValue(const wxChar *szValue, const wxMemoryBuffer& buf);
189 // return the binary value
190 bool QueryValue(const wxChar *szValue, wxMemoryBuffer& buf) const;
2bda0e17 191
2dc77646
VZ
192 // query existence of a key/value
193 // return true if value exists
92049cd4 194 bool HasValue(const wxChar *szKey) const;
2dc77646 195 // return true if given subkey exists
92049cd4 196 bool HasSubKey(const wxChar *szKey) const;
2dc77646 197 // return true if any subkeys exist
92049cd4
VZ
198 bool HasSubkeys() const;
199 // return true if any values exist
200 bool HasValues() const;
201 // return true if the key is empty (nothing under this key)
202 bool IsEmpty() const { return !HasSubkeys() && !HasValues(); }
2bda0e17
KB
203
204 // enumerate values and subkeys
2bda0e17
KB
205 bool GetFirstValue(wxString& strValueName, long& lIndex);
206 bool GetNextValue (wxString& strValueName, long& lIndex) const;
2bda0e17
KB
207
208 bool GetFirstKey (wxString& strKeyName , long& lIndex);
209 bool GetNextKey (wxString& strKeyName , long& lIndex) const;
210
20d8c319
VZ
211 // export the contents of this key and all its subkeys to the given file
212 // (which won't be overwritten, it's an error if it already exists)
213 //
214 // note that we export the key in REGEDIT4 format, not RegSaveKey() binary
215 // format nor newer REGEDIT5 one
216 bool Export(const wxString& filename) const;
217
218 // same as above but write to the given (opened) stream
219 bool Export(wxOutputStream& ostr) const;
220
221
807a903e
VZ
222 // for wxRegConfig usage only: preallocate some memory for the name
223 void ReserveMemoryForName(size_t bytes) { m_strKey.reserve(bytes); }
224
2bda0e17 225private:
807a903e
VZ
226 // common part of all ctors
227 void Init()
228 {
229 m_hKey = (WXHKEY) NULL;
230 m_dwLastError = 0;
231 }
232
20d8c319
VZ
233 // recursive helper for Export()
234 bool DoExport(wxOutputStream& ostr) const;
235
236 // export a single value
237 bool DoExportValue(wxOutputStream& ostr, const wxString& name) const;
238
239 // return the text representation (in REGEDIT4 format) of the value with the
240 // given name
241 wxString FormatValue(const wxString& name) const;
242
2bda0e17 243
c085e333 244 WXHKEY m_hKey, // our handle
2bda0e17
KB
245 m_hRootKey; // handle of the top key (i.e. StdKey)
246 wxString m_strKey; // key name (relative to m_hRootKey)
247
807a903e 248 long m_dwLastError; // last error (0 if none)
20d8c319
VZ
249
250
251 DECLARE_NO_COPY_CLASS(wxRegKey)
2bda0e17
KB
252};
253
20d8c319 254#endif // _WX_MSW_REGISTRY_H_
2dc77646 255