]> git.saurik.com Git - wxWidgets.git/blame_incremental - include/wx/msw/registry.h
Removed unnecessary code from utilsunx.cpp
[wxWidgets.git] / include / wx / msw / registry.h
... / ...
CommitLineData
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
39typedef unsigned long ulong;
40
41// ----------------------------------------------------------------------------
42// class wxRegKey encapsulates window HKEY handle
43// ----------------------------------------------------------------------------
44class WXDLLEXPORT wxRegKey
45{
46public:
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 // rename the key
148 bool Rename(const wxChar *szNewName);
149 // copy value to another key possibly changing its name (by default it will
150 // remain the same)
151 bool CopyValue(const wxChar *szValue, wxRegKey& keyDst,
152 const wxChar *szNewName = NULL);
153 // copy the entire contents of the key recursively to another location
154 bool Copy(const wxChar *szNewName);
155 // same as Copy() but using a key and not the name
156 bool Copy(wxRegKey& keyDst);
157 // close the key (will be automatically done in dtor)
158 bool Close();
159
160 // deleting keys/values
161 // deletes this key and all of it's subkeys/values
162 bool DeleteSelf();
163 // deletes the subkey with all of it's subkeys/values recursively
164 bool DeleteKey(const wxChar *szKey);
165 // deletes the named value (may be NULL to remove the default value)
166 bool DeleteValue(const wxChar *szValue);
167
168 // access to values and subkeys
169 // get value type
170 ValueType GetValueType(const wxChar *szValue) const;
171 // returns TRUE if the value contains a number (else it's some string)
172 bool IsNumericValue(const wxChar *szValue) const;
173
174 // assignment operators set the default value of the key
175 wxRegKey& operator=(const wxString& strValue)
176 { SetValue(NULL, strValue); return *this; }
177 wxRegKey& operator=(long lValue)
178 { SetValue(NULL, lValue); return *this; }
179
180 // conversion operators query the default value of the key
181 operator wxString() const;
182
183 // set the string value
184 bool SetValue(const wxChar *szValue, const wxString& strValue);
185 // return the string value
186 bool QueryValue(const wxChar *szValue, wxString& strValue) const;
187
188#ifdef __WIN32__
189 // set the numeric value
190 bool SetValue(const wxChar *szValue, long lValue);
191 // return the numeric value
192 bool QueryValue(const wxChar *szValue, long *plValue) const;
193#endif //Win32
194
195 // query existence of a key/value
196 // return true if value exists
197 bool HasValue(const wxChar *szKey) const;
198 // return true if given subkey exists
199 bool HasSubKey(const wxChar *szKey) const;
200 // return true if any subkeys exist
201 bool HasSubkeys() const;
202 // return true if any values exist
203 bool HasValues() const;
204 // return true if the key is empty (nothing under this key)
205 bool IsEmpty() const { return !HasSubkeys() && !HasValues(); }
206
207 // enumerate values and subkeys
208 bool GetFirstValue(wxString& strValueName, long& lIndex);
209 bool GetNextValue (wxString& strValueName, long& lIndex) const;
210
211 bool GetFirstKey (wxString& strKeyName , long& lIndex);
212 bool GetNextKey (wxString& strKeyName , long& lIndex) const;
213
214private:
215 // no copy ctor/assignment operator
216 wxRegKey(const wxRegKey& key); // not implemented
217 wxRegKey& operator=(const wxRegKey& key); // not implemented
218
219 WXHKEY m_hKey, // our handle
220 m_hRootKey; // handle of the top key (i.e. StdKey)
221 wxString m_strKey; // key name (relative to m_hRootKey)
222
223 MUTABLE long m_dwLastError; // last error (0 if none)
224};
225
226#endif //_REGISTRY_H
227