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