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