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