]> git.saurik.com Git - wxWidgets.git/blob - include/wx/palmos/registry.h
68b15921d9dd319003d4c38cd4f1d34b03f126b7
[wxWidgets.git] / include / wx / palmos / registry.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: palmos/registry.h
3 // Purpose: Registry classes and functions
4 // Author: William Osborne
5 // Modified by:
6 // Created: 10/13/04
7 // RCS-ID: $Id:
8 // Copyright: (c) William Osborne
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _REGISTRY_H
13 #define _REGISTRY_H
14
15 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
16 #pragma interface "registry.h"
17 #endif
18
19 // ----------------------------------------------------------------------------
20 // types used in this module
21 // ----------------------------------------------------------------------------
22
23 /*
24 #ifndef HKEY_DEFINED
25 #define HKEY_DEFINED
26 #define HKEY unsigned long
27 #endif
28 */
29
30 typedef unsigned long ulong;
31
32 // ----------------------------------------------------------------------------
33 // class wxRegKey encapsulates window HKEY handle
34 // ----------------------------------------------------------------------------
35 class WXDLLIMPEXP_BASE wxRegKey
36 {
37 public:
38 // NB: do _not_ change the values of elements in these enumerations!
39
40 // registry value types (with comments from winnt.h)
41 enum ValueType
42 {
43 Type_None, // No value type
44 Type_String, // Unicode nul terminated string
45 };
46
47 // predefined registry keys
48 enum StdKey
49 {
50 HKCR // classes root
51 };
52
53 // access mode for the key
54 enum AccessMode
55 {
56 Read, // read-only
57 Write // read and write
58 };
59
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);
69
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);
73
74 // ctors
75 // root key is set to HKCR (the only root key under Win16)
76 wxRegKey();
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
84 ~wxRegKey();
85
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);
95
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
100 bool Exists() const;
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; }
110
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);
119 // rename the key
120 bool Rename(const wxChar *szNewName);
121 // copy value to another key possibly changing its name (by default it will
122 // remain the same)
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)
130 bool Close();
131
132 // deleting keys/values
133 // deletes this key and all of it's subkeys/values
134 bool DeleteSelf();
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);
139
140 // access to values and subkeys
141 // get value type
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;
145
146 // assignment operators set the default value of the key
147 wxRegKey& operator=(const wxString& strValue)
148 { SetValue(NULL, strValue); return *this; }
149
150 // query the default value of the key: implicitly or explicitly
151 wxString QueryDefaultValue() const;
152 operator wxString() const { return QueryDefaultValue(); }
153
154 // named values
155
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;
166
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(); }
178
179 // enumerate values and subkeys
180 bool GetFirstValue(wxString& strValueName, long& lIndex);
181 bool GetNextValue (wxString& strValueName, long& lIndex) const;
182
183 bool GetFirstKey (wxString& strKeyName , long& lIndex);
184 bool GetNextKey (wxString& strKeyName , long& lIndex) const;
185
186 // for wxRegConfig usage only: preallocate some memory for the name
187 void ReserveMemoryForName(size_t bytes) { m_strKey.reserve(bytes); }
188
189 private:
190 // common part of all ctors
191 void Init()
192 {
193 m_hKey = (WXHKEY) NULL;
194 m_dwLastError = 0;
195 }
196
197 // no copy ctor/assignment operator
198 wxRegKey(const wxRegKey& key); // not implemented
199 wxRegKey& operator=(const wxRegKey& key); // not implemented
200
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)
204
205 long m_dwLastError; // last error (0 if none)
206 };
207
208 #endif //_REGISTRY_H
209