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
47 // predefined registry keys
53 // access mode for the key
57 Write
// read and write
60 // information about standard (predefined) registry keys
61 // number of standard keys
62 static const size_t nStdKeys
;
63 // get the name of a standard key
64 static const wxChar
*GetStdKeyName(size_t key
);
65 // get the short name of a standard key
66 static const wxChar
*GetStdKeyShortName(size_t key
);
67 // get StdKey from root HKEY
68 static StdKey
GetStdKeyFromHkey(WXHKEY hkey
);
70 // extacts the std key prefix from the string (return value) and
71 // leaves only the part after it (i.e. modifies the string passed!)
72 static StdKey
ExtractKeyName(wxString
& str
);
75 // root key is set to HKCR (the only root key under Win16)
77 // strKey is the full name of the key (i.e. starting with HKEY_xxx...)
78 wxRegKey(const wxString
& strKey
);
79 // strKey is the name of key under (standard key) keyParent
80 wxRegKey(StdKey keyParent
, const wxString
& strKey
);
81 // strKey is the name of key under (previously created) keyParent
82 wxRegKey(const wxRegKey
& keyParent
, const wxString
& strKey
);
83 // dtor closes the key
86 // change key (closes the previously opened key if any)
87 // the name is absolute, i.e. should start with HKEY_xxx
88 void SetName(const wxString
& strKey
);
89 // the name is relative to the parent key
90 void SetName(StdKey keyParent
, const wxString
& strKey
);
91 // the name is relative to the parent key
92 void SetName(const wxRegKey
& keyParent
, const wxString
& strKey
);
93 // hKey should be opened and will be closed in wxRegKey dtor
94 void SetHkey(WXHKEY hKey
);
96 // get infomation about the key
97 // get the (full) key name. Abbreviate std root keys if bShortPrefix.
98 wxString
GetName(bool bShortPrefix
= true) const;
99 // return true if the key exists
101 // get the info about key (any number of these pointers may be NULL)
102 bool GetKeyInfo(size_t *pnSubKeys
, // number of subkeys
103 size_t *pnMaxKeyLen
, // max len of subkey name
104 size_t *pnValues
, // number of values
105 size_t *pnMaxValueLen
) const;
106 // return true if the key is opened
107 bool IsOpened() const { return m_hKey
!= 0; }
108 // for "if ( !key ) wxLogError(...)" kind of expressions
109 operator bool() const { return m_dwLastError
== 0; }
111 // operations on the key itself
112 // explicitly open the key (will be automatically done by all functions
113 // which need the key to be opened if the key is not opened yet)
114 bool Open(AccessMode mode
= Write
);
115 // create the key: will fail if the key already exists and !bOkIfExists
116 bool Create(bool bOkIfExists
= true);
117 // rename a value from old name to new one
118 bool RenameValue(const wxChar
*szValueOld
, const wxChar
*szValueNew
);
120 bool Rename(const wxChar
*szNewName
);
121 // copy value to another key possibly changing its name (by default it will
123 bool CopyValue(const wxChar
*szValue
, wxRegKey
& keyDst
,
124 const wxChar
*szNewName
= NULL
);
125 // copy the entire contents of the key recursively to another location
126 bool Copy(const wxChar
*szNewName
);
127 // same as Copy() but using a key and not the name
128 bool Copy(wxRegKey
& keyDst
);
129 // close the key (will be automatically done in dtor)
132 // deleting keys/values
133 // deletes this key and all of it's subkeys/values
135 // deletes the subkey with all of it's subkeys/values recursively
136 bool DeleteKey(const wxChar
*szKey
);
137 // deletes the named value (may be NULL to remove the default value)
138 bool DeleteValue(const wxChar
*szValue
);
140 // access to values and subkeys
142 ValueType
GetValueType(const wxChar
*szValue
) const;
143 // returns true if the value contains a number (else it's some string)
144 bool IsNumericValue(const wxChar
*szValue
) const;
146 // assignment operators set the default value of the key
147 wxRegKey
& operator=(const wxString
& strValue
)
148 { SetValue(NULL
, strValue
); return *this; }
150 // query the default value of the key: implicitly or explicitly
151 wxString
QueryDefaultValue() const;
152 operator wxString() const { return QueryDefaultValue(); }
156 // set the string value
157 bool SetValue(const wxChar
*szValue
, const wxString
& strValue
);
158 // retrieve the string value
159 bool QueryValue(const wxChar
*szValue
, wxString
& strValue
) const
160 { return QueryValue(szValue
, strValue
, false); }
161 // retrieve raw string value
162 bool QueryRawValue(const wxChar
*szValue
, wxString
& strValue
) const
163 { return QueryValue(szValue
, strValue
, true); }
164 // retrieve either raw or expanded string value
165 bool QueryValue(const wxChar
*szValue
, wxString
& strValue
, bool raw
) const;
167 // query existence of a key/value
168 // return true if value exists
169 bool HasValue(const wxChar
*szKey
) const;
170 // return true if given subkey exists
171 bool HasSubKey(const wxChar
*szKey
) const;
172 // return true if any subkeys exist
173 bool HasSubkeys() const;
174 // return true if any values exist
175 bool HasValues() const;
176 // return true if the key is empty (nothing under this key)
177 bool IsEmpty() const { return !HasSubkeys() && !HasValues(); }
179 // enumerate values and subkeys
180 bool GetFirstValue(wxString
& strValueName
, long& lIndex
);
181 bool GetNextValue (wxString
& strValueName
, long& lIndex
) const;
183 bool GetFirstKey (wxString
& strKeyName
, long& lIndex
);
184 bool GetNextKey (wxString
& strKeyName
, long& lIndex
) const;
186 // for wxRegConfig usage only: preallocate some memory for the name
187 void ReserveMemoryForName(size_t bytes
) { m_strKey
.reserve(bytes
); }
190 // common part of all ctors
193 m_hKey
= (WXHKEY
) NULL
;
197 // no copy ctor/assignment operator
198 wxRegKey(const wxRegKey
& key
); // not implemented
199 wxRegKey
& operator=(const wxRegKey
& key
); // not implemented
201 WXHKEY m_hKey
, // our handle
202 m_hRootKey
; // handle of the top key (i.e. StdKey)
203 wxString m_strKey
; // key name (relative to m_hRootKey)
205 long m_dwLastError
; // last error (0 if none)