1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: palmos/registry.h
3 // Purpose: Registry classes and functions
4 // Author: William Osborne
8 // Copyright: (c) William Osborne
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
15 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
16 #pragma interface "registry.h"
19 // ----------------------------------------------------------------------------
20 // types used in this module
21 // ----------------------------------------------------------------------------
26 #define HKEY unsigned long
30 typedef unsigned long ulong
;
32 // ----------------------------------------------------------------------------
33 // class wxRegKey encapsulates window HKEY handle
34 // ----------------------------------------------------------------------------
35 class WXDLLIMPEXP_BASE wxRegKey
38 // NB: do _not_ change the values of elements in these enumerations!
40 // registry value types (with comments from winnt.h)
43 Type_None
, // No value type
44 Type_String
, // Unicode nul terminated string
46 Type_Expand_String
, // Unicode nul terminated string
47 // (with environment variable references)
48 Type_Binary
, // Free form binary
49 Type_Dword
, // 32-bit number
50 Type_Dword_little_endian
// 32-bit number
51 = Type_Dword
, // (same as Type_DWORD)
52 Type_Dword_big_endian
, // 32-bit number
53 Type_Link
, // Symbolic Link (unicode)
54 Type_Multi_String
, // Multiple Unicode strings
55 Type_Resource_list
, // Resource list in the resource map
56 Type_Full_resource_descriptor
, // Resource list in the hardware description
57 Type_Resource_requirements_list
// ???
61 // predefined registry keys
68 HKLM
, // local machine
70 HKPD
// performance data (WinNT/2K only)
73 HKCC
, // current config (starting from Win95/NT 4.0)
74 HKDD
// dynamic data (Win95/98 only)
79 // access mode for the key
83 Write
// read and write
86 // information about standard (predefined) registry keys
87 // number of standard keys
88 static const size_t nStdKeys
;
89 // get the name of a standard key
90 static const wxChar
*GetStdKeyName(size_t key
);
91 // get the short name of a standard key
92 static const wxChar
*GetStdKeyShortName(size_t key
);
93 // get StdKey from root HKEY
94 static StdKey
GetStdKeyFromHkey(WXHKEY hkey
);
96 // extacts the std key prefix from the string (return value) and
97 // leaves only the part after it (i.e. modifies the string passed!)
98 static StdKey
ExtractKeyName(wxString
& str
);
101 // root key is set to HKCR (the only root key under Win16)
103 // strKey is the full name of the key (i.e. starting with HKEY_xxx...)
104 wxRegKey(const wxString
& strKey
);
105 // strKey is the name of key under (standard key) keyParent
106 wxRegKey(StdKey keyParent
, const wxString
& strKey
);
107 // strKey is the name of key under (previously created) keyParent
108 wxRegKey(const wxRegKey
& keyParent
, const wxString
& strKey
);
109 // dtor closes the key
112 // change key (closes the previously opened key if any)
113 // the name is absolute, i.e. should start with HKEY_xxx
114 void SetName(const wxString
& strKey
);
115 // the name is relative to the parent key
116 void SetName(StdKey keyParent
, const wxString
& strKey
);
117 // the name is relative to the parent key
118 void SetName(const wxRegKey
& keyParent
, const wxString
& strKey
);
119 // hKey should be opened and will be closed in wxRegKey dtor
120 void SetHkey(WXHKEY hKey
);
122 // get infomation about the key
123 // get the (full) key name. Abbreviate std root keys if bShortPrefix.
124 wxString
GetName(bool bShortPrefix
= TRUE
) const;
125 // return true if the key exists
127 // get the info about key (any number of these pointers may be NULL)
128 bool GetKeyInfo(size_t *pnSubKeys
, // number of subkeys
129 size_t *pnMaxKeyLen
, // max len of subkey name
130 size_t *pnValues
, // number of values
131 size_t *pnMaxValueLen
) const;
132 // return true if the key is opened
133 bool IsOpened() const { return m_hKey
!= 0; }
134 // for "if ( !key ) wxLogError(...)" kind of expressions
135 operator bool() const { return m_dwLastError
== 0; }
137 // operations on the key itself
138 // explicitly open the key (will be automatically done by all functions
139 // which need the key to be opened if the key is not opened yet)
140 bool Open(AccessMode mode
= Write
);
141 // create the key: will fail if the key already exists and !bOkIfExists
142 bool Create(bool bOkIfExists
= TRUE
);
143 // rename a value from old name to new one
144 bool RenameValue(const wxChar
*szValueOld
, const wxChar
*szValueNew
);
146 bool Rename(const wxChar
*szNewName
);
147 // copy value to another key possibly changing its name (by default it will
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 wxChar
*szNewName
);
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)
158 // deleting keys/values
159 // deletes this key and all of it's subkeys/values
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
);
166 // access to values and subkeys
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;
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; }
178 // query the default value of the key: implicitly or explicitly
179 wxString
QueryDefaultValue() const;
180 operator wxString() const { return QueryDefaultValue(); }
184 // set the string value
185 bool SetValue(const wxChar
*szValue
, const wxString
& strValue
);
186 // retrieve the string value
187 bool QueryValue(const wxChar
*szValue
, wxString
& strValue
) const
188 { return QueryValue(szValue
, strValue
, FALSE
); }
189 // retrieve raw string value
190 bool QueryRawValue(const wxChar
*szValue
, wxString
& strValue
) const
191 { return QueryValue(szValue
, strValue
, TRUE
); }
192 // retrieve either raw or expanded string value
193 bool QueryValue(const wxChar
*szValue
, wxString
& strValue
, bool raw
) const;
196 // set the numeric value
197 bool SetValue(const wxChar
*szValue
, long lValue
);
198 // return the numeric value
199 bool QueryValue(const wxChar
*szValue
, long *plValue
) const;
202 // query existence of a key/value
203 // return true if value exists
204 bool HasValue(const wxChar
*szKey
) const;
205 // return true if given subkey exists
206 bool HasSubKey(const wxChar
*szKey
) const;
207 // return true if any subkeys exist
208 bool HasSubkeys() const;
209 // return true if any values exist
210 bool HasValues() const;
211 // return true if the key is empty (nothing under this key)
212 bool IsEmpty() const { return !HasSubkeys() && !HasValues(); }
214 // enumerate values and subkeys
215 bool GetFirstValue(wxString
& strValueName
, long& lIndex
);
216 bool GetNextValue (wxString
& strValueName
, long& lIndex
) const;
218 bool GetFirstKey (wxString
& strKeyName
, long& lIndex
);
219 bool GetNextKey (wxString
& strKeyName
, long& lIndex
) const;
221 // for wxRegConfig usage only: preallocate some memory for the name
222 void ReserveMemoryForName(size_t bytes
) { m_strKey
.reserve(bytes
); }
225 // common part of all ctors
228 m_hKey
= (WXHKEY
) NULL
;
232 // no copy ctor/assignment operator
233 wxRegKey(const wxRegKey
& key
); // not implemented
234 wxRegKey
& operator=(const wxRegKey
& key
); // not implemented
236 WXHKEY m_hKey
, // our handle
237 m_hRootKey
; // handle of the top key (i.e. StdKey)
238 wxString m_strKey
; // key name (relative to m_hRootKey)
240 long m_dwLastError
; // last error (0 if none)