]> git.saurik.com Git - wxWidgets.git/blame - interface/wx/config.h
Add wxTextEntry::AutoCompleteDirectories().
[wxWidgets.git] / interface / wx / config.h
CommitLineData
23324ae1
FM
1/////////////////////////////////////////////////////////////////////////////
2// Name: config.h
e54c96f1 3// Purpose: interface of wxConfigBase
23324ae1
FM
4// Author: wxWidgets team
5// RCS-ID: $Id$
526954c5 6// Licence: wxWindows licence
23324ae1
FM
7/////////////////////////////////////////////////////////////////////////////
8
9/**
10 @class wxConfigBase
7c913512 11
4c51a665 12 wxConfigBase defines the basic interface of all config classes. It cannot
bd0812fe
BP
13 be used by itself (it is an abstract base class) and you will always use
14 one of its derivations: wxFileConfig, wxRegConfig or any other.
15
16 However, usually you don't even need to know the precise nature of the
17 class you're working with but you would just use the wxConfigBase methods.
18 This allows you to write the same code regardless of whether you're working
df693ed6
FM
19 with the registry under Windows or text-based config files under Unix.
20 To make writing the portable code even easier, wxWidgets provides a typedef
21 wxConfig which is mapped onto the native wxConfigBase implementation on the
22 given platform: i.e. wxRegConfig under Windows and wxFileConfig otherwise.
bd0812fe
BP
23
24 See @ref overview_config for a description of all features of this class.
25
26 It is highly recommended to use static functions Get() and/or Set(), so
27 please have a look at them.
28
29 Related Include Files:
30
31 @li @c <wx/config.h> - Let wxWidgets choose a wxConfig class for your
32 platform.
33 @li @c <wx/confbase.h> - Base config class.
34 @li @c <wx/fileconf.h> - wxFileConfig class.
bbc5b7f8 35 @li @c <wx/msw/regconf.h> - wxRegConfig class, see also wxRegKey.
bd0812fe
BP
36
37
38 @section configbase_example Example
39
40 Here is how you would typically use this class:
41
42 @code
43 // using wxConfig instead of writing wxFileConfig or wxRegConfig enhances
44 // portability of the code
45 wxConfig *config = new wxConfig("MyAppName");
46
47 wxString str;
48 if ( config->Read("LastPrompt", &str) ) {
49 // last prompt was found in the config file/registry and its value is
50 // now in str
51 // ...
52 }
53 else {
54 // no last prompt...
55 }
56
57 // another example: using default values and the full path instead of just
58 // key name: if the key is not found , the value 17 is returned
59 long value = config->ReadLong("/LastRun/CalculatedValues/MaxValue", 17);
60
61 // at the end of the program we would save everything back
62 config->Write("LastPrompt", str);
63 config->Write("/LastRun/CalculatedValues/MaxValue", value);
64
65 // the changes will be written back automatically
66 delete config;
67 @endcode
68
69 This basic example, of course, doesn't show all wxConfig features, such as
70 enumerating, testing for existence and deleting the entries and groups of
71 entries in the config file, its abilities to automatically store the
72 default values or expand the environment variables on the fly. However, the
73 main idea is that using this class is easy and that it should normally do
74 what you expect it to.
75
76 @note In the documentation of this class, the words "config file" also mean
77 "registry hive" for wxRegConfig and, generally speaking, might mean
78 any physical storage where a wxConfigBase-derived class stores its
79 data.
80
81
82 @section configbase_static Static Functions
83
84 The static functions provided deal with the "default" config object.
85 Although its usage is not at all mandatory it may be convenient to use a
86 global config object instead of creating and deleting the local config
87 objects each time you need one (especially because creating a wxFileConfig
88 object might be a time consuming operation). In this case, you may create
89 this global config object in the very start of the program and Set() it as
90 the default. Then, from anywhere in your program, you may access it using
91 the Get() function. This global wxConfig object will be deleted by
92 wxWidgets automatically if it exists. Note that this implies that if you do
93 delete this object yourself (usually in wxApp::OnExit()) you must use
94 Set(@NULL) to prevent wxWidgets from deleting it the second time.
95
96 As it happens, you may even further simplify the procedure described above:
97 you may forget about calling Set(). When Get() is called and there is no
98 current object, it will create one using Create() function. To disable this
99 behaviour DontCreateOnDemand() is provided.
100
101 @note You should use either Set() or Get() because wxWidgets library itself
102 would take advantage of it and could save various information in it.
103 For example wxFontMapper or Unix version of wxFileDialog have the
104 ability to use wxConfig class.
105
106
107 @section configbase_paths Path Management
108
109 As explained in the @ref overview_config "config overview", the config
110 classes support a file system-like hierarchy of keys (files) and groups
111 (directories). As in the file system case, to specify a key in the config
112 class you must use a path to it. Config classes also support the notion of
113 the current group, which makes it possible to use the relative paths. To
114 clarify all this, here is an example (it is only for the sake of
115 demonstration, it doesn't do anything sensible!):
116
117 @code
118 wxConfig *config = new wxConfig("FooBarApp");
119
120 // right now the current path is '/'
121 conf->Write("RootEntry", 1);
122
123 // go to some other place: if the group(s) don't exist, they will be created
124 conf->SetPath("/Group/Subgroup");
125
126 // create an entry in subgroup
127 conf->Write("SubgroupEntry", 3);
128
129 // '..' is understood
130 conf->Write("../GroupEntry", 2);
131 conf->SetPath("..");
132
133 wxASSERT( conf->ReadLong("Subgroup/SubgroupEntry", 0) == 3 );
134
135 // use absolute path: it is allowed, too
136 wxASSERT( conf->ReadLong("/RootEntry", 0) == 1 );
137 @endcode
138
139 It is highly recommended that you restore the path to its old value on
140 function exit:
141
142 @code
143 void foo(wxConfigBase *config)
144 {
145 wxString strOldPath = config->GetPath();
146
147 config->SetPath("/Foo/Data");
148 // ...
149
150 config->SetPath(strOldPath);
151 }
152 @endcode
153
154 Otherwise the assert in the following example will surely fail (we suppose
155 here that the foo() function is the same as above except that it doesn’t
156 save and restore the path):
157
158 @code
159 void bar(wxConfigBase *config)
160 {
161 config->Write("Test", 17);
162
163 foo(config);
164
165 // we're reading "/Foo/Data/Test" here! -1 will probably be returned...
166 wxASSERT( config->ReadLong("Test", -1) == 17 );
167 }
168 @endcode
169
170 Finally, the path separator in wxConfigBase and derived classes is always
171 "/", regardless of the platform (i.e. it is not "\\" under Windows).
172
173
174 @section configbase_enumeration Enumeration
175
176 The enumeration functions allow you to enumerate all entries and groups in
177 the config file. All functions here return @false when there are no more
178 items.
179
180 You must pass the same index to GetNext() and GetFirst() (don't modify it).
181 Please note that it is not the index of the current item (you will have
182 some great surprises with wxRegConfig if you assume this) and you shouldn't
183 even look at it: it is just a "cookie" which stores the state of the
184 enumeration. It can't be stored inside the class because it would prevent
185 you from running several enumerations simultaneously, that's why you must
186 pass it explicitly.
187
188 Having said all this, enumerating the config entries/groups is very simple:
189
190 @code
191 wxConfigBase *config = ...;
192 wxArrayString aNames;
193
194 // enumeration variables
195 wxString str;
196 long dummy;
197
198 // first enum all entries
199 bool bCont = config->GetFirstEntry(str, dummy);
200 while ( bCont ) {
201 aNames.Add(str);
202
203 bCont = GetConfig()->GetNextEntry(str, dummy);
204 }
205
206 // ... we have all entry names in aNames...
207
208 // now all groups...
209 bCont = GetConfig()->GetFirstGroup(str, dummy);
210 while ( bCont ) {
211 aNames.Add(str);
212
213 bCont = GetConfig()->GetNextGroup(str, dummy);
214 }
215
216 // ... we have all group (and entry) names in aNames...
217 @endcode
218
219 There are also functions to get the number of entries/subgroups without
220 actually enumerating them, but you will probably never need them.
221
222
223 @section configbase_keyaccess Key Access
224
225 The key access functions are the core of wxConfigBase class: they allow you
226 to read and write config file data. All Read() functions take a default
227 value which will be returned if the specified key is not found in the
228 config file.
229
230 Currently, supported types of data are: wxString, @c long, @c double,
231 @c bool, wxColour and any other types for which the functions
232 wxToString() and wxFromString() are defined.
233
234 Try not to read long values into string variables and vice versa:
235 although it just might work with wxFileConfig, you will get a system
236 error with wxRegConfig because in the Windows registry the different
237 types of entries are indeed used.
238
239 Final remark: the @a szKey parameter for all these functions can
240 contain an arbitrary path (either relative or absolute), not just the
241 key name.
242
243 @beginWxPythonOnly
244 In place of a single overloaded method name, wxPython implements the
245 following methods:
246 - Read(key, default="") - Returns a string.
247 - ReadInt(key, default=0) - Returns an integer.
248 - ReadFloat(key, default=0.0) - Returns a floating point number.
249 - ReadBool(key, default=0) - Returns a boolean.
250 - Write(key, value) - Writes a string.
251 - WriteInt(key, value) - Writes an int.
252 - WriteFloat(key, value) - Writes a floating point number.
253 @endWxPythonOnly
254
7c913512 255
23324ae1 256 @library{wxbase}
3c99e2fd 257 @category{cfg}
23324ae1
FM
258*/
259class wxConfigBase : public wxObject
260{
261public:
262 /**
23324ae1
FM
263 This is the default and only constructor of the wxConfigBase class, and
264 derived classes.
3c4f71cc 265
7c913512 266 @param appName
bd0812fe
BP
267 The application name. If this is empty, the class will normally use
268 wxApp::GetAppName() to set it. The application name is used in the
269 registry key on Windows, and can be used to deduce the local
270 filename parameter if that is missing.
7c913512 271 @param vendorName
bd0812fe
BP
272 The vendor name. If this is empty, it is assumed that no vendor
273 name is wanted, if this is optional for the current config class.
274 The vendor name is appended to the application name for
275 wxRegConfig.
7c913512 276 @param localFilename
bd0812fe
BP
277 Some config classes require a local filename. If this is not
278 present, but required, the application name will be used instead.
7c913512 279 @param globalFilename
bd0812fe
BP
280 Some config classes require a global filename. If this is not
281 present, but required, the application name will be used instead.
7c913512 282 @param style
df693ed6
FM
283 Can be one of @c wxCONFIG_USE_LOCAL_FILE and @c wxCONFIG_USE_GLOBAL_FILE.
284 @n The style interpretation depends on the config class and is ignored
bd0812fe
BP
285 by some implementations. For wxFileConfig, these styles determine
286 whether a local or global config file is created or used: if
df693ed6
FM
287 @c wxCONFIG_USE_GLOBAL_FILE is used, then settings are read from the
288 global config file and if @c wxCONFIG_USE_LOCAL_FILE is used, settings
bd0812fe
BP
289 are read from and written to local config file (if they are both
290 set, global file is read first, then local file, overwriting global
291 settings). If the flag is present but the parameter is empty, the
292 parameter will be set to a default. If the parameter is present but
293 the style flag not, the relevant flag will be added to the style.
df693ed6
FM
294 For wxRegConfig, the GLOBAL flag refers to the @c HKLM key while LOCAL
295 one is for the usual @c HKCU one.
296 @n For wxFileConfig you can also add @c wxCONFIG_USE_RELATIVE_PATH by
bd0812fe
BP
297 logically or'ing it to either of the _FILE options to tell
298 wxFileConfig to use relative instead of absolute paths.
299 @n On non-VMS Unix systems, the default local configuration file is
300 "~/.appname". However, this path may be also used as user data
301 directory (see wxStandardPaths::GetUserDataDir()) if the
302 application has several data files. In this case
df693ed6 303 @c wxCONFIG_USE_SUBDIR flag, which changes the default local
bd0812fe 304 configuration file to "~/.appname/appname" should be used. Notice
df693ed6
FM
305 that this flag is ignored if @a localFilename is provided.
306 @c wxCONFIG_USE_SUBDIR is new since wxWidgets version 2.8.2.
bd0812fe 307 @n For wxFileConfig, you can also add
df693ed6 308 @c wxCONFIG_USE_NO_ESCAPE_CHARACTERS which will turn off character
bd0812fe
BP
309 escaping for the values of entries stored in the config file: for
310 example a foo key with some backslash characters will be stored as
311 "foo=C:\mydir" instead of the usual storage of "foo=C:\\mydir".
df693ed6 312 @n The @c wxCONFIG_USE_NO_ESCAPE_CHARACTERS style can be helpful if your
bd0812fe
BP
313 config file must be read or written to by a non-wxWidgets program
314 (which might not understand the escape characters). Note, however,
d13b34d3 315 that if @c wxCONFIG_USE_NO_ESCAPE_CHARACTERS style is used, it is
bd0812fe
BP
316 now your application's responsibility to ensure that there is no
317 newline or other illegal characters in a value, before writing that
318 value to the file.
7c913512 319 @param conv
bd0812fe
BP
320 This parameter is only used by wxFileConfig when compiled in
321 Unicode mode. It specifies the encoding in which the configuration
322 file is written.
3c4f71cc 323
23324ae1 324 @remarks By default, environment variable expansion is on and recording
4cc4bfaf 325 defaults is off.
23324ae1
FM
326 */
327 wxConfigBase(const wxString& appName = wxEmptyString,
328 const wxString& vendorName = wxEmptyString,
329 const wxString& localFilename = wxEmptyString,
330 const wxString& globalFilename = wxEmptyString,
76e9224e
FM
331 long style = 0,
332 const wxMBConv& conv = wxConvAuto());
23324ae1
FM
333
334 /**
335 Empty but ensures that dtor of all derived classes is virtual.
336 */
b7e94bd7 337 virtual ~wxConfigBase();
23324ae1 338
23324ae1
FM
339
340 /**
bd0812fe 341 @name Path Management
23324ae1 342
bd0812fe 343 See @ref configbase_paths
23324ae1 344 */
bd0812fe 345 //@{
23324ae1
FM
346
347 /**
bd0812fe 348 Retrieve the current path (always as absolute path).
23324ae1 349 */
382f12e4 350 virtual const wxString& GetPath() const = 0;
23324ae1
FM
351
352 /**
bd0812fe
BP
353 Set current path: if the first character is '/', it is the absolute
354 path, otherwise it is a relative path. '..' is supported. If @a strPath
355 doesn't exist it is created.
23324ae1 356 */
382f12e4 357 virtual void SetPath(const wxString& strPath) = 0;
23324ae1 358
bd0812fe 359 //@}
23324ae1 360
23324ae1
FM
361
362 /**
bd0812fe 363 @name Enumeration
23324ae1 364
bd0812fe 365 See @ref configbase_enumeration
23324ae1 366 */
bd0812fe 367 //@{
23324ae1
FM
368
369 /**
370 Gets the first entry.
bd0812fe
BP
371
372 @beginWxPythonOnly
373 The wxPython version of this method returns a 3-tuple consisting of the
374 continue flag, the value string, and the index for the next call.
375 @endWxPythonOnly
1058f652
MB
376
377 @beginWxPerlOnly
378 In wxPerl this method takes no parameters and returns a 3-element
379 list (continue_flag, string, index_for_getnextentry).
380 @endWxPerlOnly
23324ae1 381 */
382f12e4 382 virtual bool GetFirstEntry(wxString& str, long& index) const = 0;
23324ae1
FM
383
384 /**
385 Gets the first group.
bd0812fe
BP
386
387 @beginWxPythonOnly
388 The wxPython version of this method returns a 3-tuple consisting of the
389 continue flag, the value string, and the index for the next call.
390 @endWxPythonOnly
1058f652
MB
391
392 @beginWxPerlOnly
393 In wxPerl this method takes no parameters and returns a 3-element
394 list (continue_flag, string, index_for_getnextentry).
395 @endWxPerlOnly
23324ae1 396 */
382f12e4 397 virtual bool GetFirstGroup(wxString& str, long& index) const = 0;
23324ae1
FM
398
399 /**
400 Gets the next entry.
bd0812fe
BP
401
402 @beginWxPythonOnly
403 The wxPython version of this method returns a 3-tuple consisting of the
404 continue flag, the value string, and the index for the next call.
405 @endWxPythonOnly
1058f652
MB
406
407 @beginWxPerlOnly
408 In wxPerl this method only takes the @a index parameter and
409 returns a 3-element list (continue_flag, string,
410 index_for_getnextentry).
411 @endWxPerlOnly
23324ae1 412 */
382f12e4 413 virtual bool GetNextEntry(wxString& str, long& index) const = 0;
23324ae1
FM
414
415 /**
416 Gets the next group.
bd0812fe
BP
417
418 @beginWxPythonOnly
419 The wxPython version of this method returns a 3-tuple consisting of the
420 continue flag, the value string, and the index for the next call.
421 @endWxPythonOnly
1058f652
MB
422
423 @beginWxPerlOnly
424 In wxPerl this method only takes the @a index parameter and
425 returns a 3-element list (continue_flag, string,
426 index_for_getnextentry).
427 @endWxPerlOnly
23324ae1 428 */
382f12e4 429 virtual bool GetNextGroup(wxString& str, long& index) const = 0;
23324ae1
FM
430
431 /**
bd0812fe 432 Get number of entries in the current group.
23324ae1 433 */
382f12e4 434 virtual size_t GetNumberOfEntries(bool bRecursive = false) const = 0;
23324ae1
FM
435
436 /**
bd0812fe
BP
437 Get number of entries/subgroups in the current group, with or without
438 its subgroups.
23324ae1 439 */
382f12e4 440 virtual size_t GetNumberOfGroups(bool bRecursive = false) const = 0;
23324ae1 441
bd0812fe
BP
442 //@}
443
444
445 enum EntryType
446 {
447 Type_Unknown,
448 Type_String,
449 Type_Boolean,
450 Type_Integer,
451 Type_Float
452 };
23324ae1
FM
453
454 /**
bd0812fe 455 @name Tests of Existence
23324ae1 456 */
bd0812fe 457 //@{
23324ae1
FM
458
459 /**
d29a9a8a 460 @return @true if either a group or an entry with a given name exists.
23324ae1 461 */
382f12e4 462 bool Exists(const wxString& strName) const;
23324ae1
FM
463
464 /**
bd0812fe
BP
465 Returns the type of the given entry or @e Unknown if the entry doesn't
466 exist. This function should be used to decide which version of Read()
467 should be used because some of wxConfig implementations will complain
468 about type mismatch otherwise: e.g., an attempt to read a string value
469 from an integer key with wxRegConfig will fail.
23324ae1 470 */
382f12e4 471 virtual wxConfigBase::EntryType GetEntryType(const wxString& name) const;
23324ae1
FM
472
473 /**
d29a9a8a 474 @return @true if the entry by this name exists.
23324ae1 475 */
382f12e4 476 virtual bool HasEntry(const wxString& strName) const = 0;
23324ae1
FM
477
478 /**
d29a9a8a 479 @return @true if the group by this name exists.
23324ae1 480 */
382f12e4 481 virtual bool HasGroup(const wxString& strName) const = 0;
23324ae1 482
bd0812fe 483 //@}
3c4f71cc 484
3c4f71cc 485
bd0812fe
BP
486 /**
487 @name Miscellaneous Functions
23324ae1 488 */
bd0812fe 489 //@{
23324ae1
FM
490
491 /**
bd0812fe 492 Returns the application name.
23324ae1 493 */
bd0812fe 494 wxString GetAppName() const;
23324ae1
FM
495
496 /**
bd0812fe
BP
497 Returns the vendor name.
498 */
499 wxString GetVendorName() const;
3c4f71cc 500
bd0812fe 501 //@}
3c4f71cc 502
3c4f71cc 503
bd0812fe
BP
504 /**
505 @name Key Access
3c4f71cc 506
bd0812fe 507 See @ref configbase_keyaccess
23324ae1 508 */
bd0812fe 509 //@{
23324ae1
FM
510
511 /**
bd0812fe
BP
512 Permanently writes all changes (otherwise, they're only written from
513 object's destructor).
23324ae1 514 */
382f12e4 515 virtual bool Flush(bool bCurrentOnly = false) = 0;
23324ae1 516
23324ae1 517 /**
bd0812fe
BP
518 Read a string from the key, returning @true if the value was read. If
519 the key was not found, @a str is not changed.
1058f652
MB
520
521 @beginWxPerlOnly
522 Not supported by wxPerl.
523 @endWxPerlOnly
23324ae1 524 */
328f5751 525 bool Read(const wxString& key, wxString* str) const;
bd0812fe
BP
526 /**
527 Read a string from the key. The default value is returned if the key
528 was not found.
529
d29a9a8a 530 @return @true if value was really read, @false if the default was used.
1058f652
MB
531
532 @beginWxPerlOnly
533 Not supported by wxPerl.
534 @endWxPerlOnly
bd0812fe 535 */
11e3af6e
FM
536 bool Read(const wxString& key, wxString* str,
537 const wxString& defaultVal) const;
bd0812fe
BP
538 /**
539 Another version of Read(), returning the string value directly.
1058f652
MB
540
541 @beginWxPerlOnly
542 In wxPerl, this can be called as:
543 - Read(key): returns the empty string if no key is found
544 - Read(key, default): returns the default value if no key is found
545 @endWxPerlOnly
bd0812fe
BP
546 */
547 const wxString Read(const wxString& key,
11e3af6e 548 const wxString& defaultVal) const;
bd0812fe
BP
549 /**
550 Reads a long value, returning @true if the value was found. If the
551 value was not found, @a l is not changed.
1058f652
MB
552
553 @beginWxPerlOnly
554 Not supported by wxPerl.
555 @endWxPerlOnly
bd0812fe 556 */
11e3af6e 557 bool Read(const wxString& key, long* l) const;
bd0812fe
BP
558 /**
559 Reads a long value, returning @true if the value was found. If the
560 value was not found, @a defaultVal is used instead.
1058f652
MB
561
562 @beginWxPerlOnly
563 In wxPerl, this can be called as:
564 - ReadInt(key): returns the 0 if no key is found
565 - ReadInt(key, default): returns the default value if no key is found
566 @endWxPerlOnly
bd0812fe 567 */
11e3af6e
FM
568 bool Read(const wxString& key, long* l,
569 long defaultVal) const;
bd0812fe
BP
570 /**
571 Reads a double value, returning @true if the value was found. If the
572 value was not found, @a d is not changed.
1058f652
MB
573
574 @beginWxPerlOnly
575 Not supported by wxPerl.
576 @endWxPerlOnly
bd0812fe 577 */
11e3af6e 578 bool Read(const wxString& key, double* d) const;
bd0812fe
BP
579 /**
580 Reads a double value, returning @true if the value was found. If the
581 value was not found, @a defaultVal is used instead.
1058f652
MB
582
583 @beginWxPerlOnly
584 In wxPerl, this can be called as:
585 - ReadFloat(key): returns the 0.0 if no key is found
586 - ReadFloat(key, default): returns the default value if no key is found
587 @endWxPerlOnly
bd0812fe 588 */
11e3af6e 589 bool Read(const wxString& key, double* d,
bd0812fe 590 double defaultVal) const;
384859f8 591
bd0812fe 592 /**
384859f8
VZ
593 Reads a float value, returning @true if the value was found.
594
595 With the second overload, if the value was not found, @a defaultVal is
596 used instead.
597
598 Notice that the value is read as a double but must be in a valid range
599 for floats for the function to return @true.
600
601 @since 2.9.1
602
603 @beginWxPerlOnly
604 Not supported by wxPerl.
605 @endWxPerlOnly
606 */
607 //@{
608 bool Read(const wxString& key, float* f) const;
609 bool Read(const wxString& key, float* f, float defaultVal) const;
610 //@}
611
612 /**
613 Reads a float value, returning @true if the value was found. If the
bd0812fe 614 value was not found, @a b is not changed.
1058f652 615
384859f8
VZ
616 @since 2.9.1
617
1058f652
MB
618 @beginWxPerlOnly
619 Not supported by wxPerl.
620 @endWxPerlOnly
bd0812fe 621 */
11e3af6e 622 bool Read(const wxString& key, bool* b) const;
bd0812fe
BP
623 /**
624 Reads a bool value, returning @true if the value was found. If the
625 value was not found, @a defaultVal is used instead.
1058f652
MB
626
627 @beginWxPerlOnly
628 In wxPerl, this can be called as:
629 - ReadBool(key): returns false if no key is found
630 - ReadBool(key, default): returns the default value if no key is found
631 @endWxPerlOnly
bd0812fe 632 */
11e3af6e
FM
633 bool Read(const wxString& key, bool* d,
634 bool defaultVal) const;
bd0812fe
BP
635 /**
636 Reads a binary block, returning @true if the value was found. If the
637 value was not found, @a buf is not changed.
638 */
11e3af6e 639 bool Read(const wxString& key, wxMemoryBuffer* buf) const;
bd0812fe
BP
640 /**
641 Reads a value of type T, for which function wxFromString() is defined,
642 returning @true if the value was found. If the value was not found,
643 @a value is not changed.
644 */
11e3af6e 645 bool Read(const wxString& key, T* value) const;
bd0812fe
BP
646 /**
647 Reads a value of type T, for which function wxFromString() is defined,
648 returning @true if the value was found. If the value was not found,
649 @a defaultVal is used instead.
650 */
11e3af6e
FM
651 bool Read(const wxString& key, T* value,
652 const T& defaultVal) const;
23324ae1
FM
653
654 /**
bd0812fe
BP
655 Reads a bool value from the key and returns it. @a defaultVal is
656 returned if the key is not found.
23324ae1 657 */
382f12e4 658 bool ReadBool(const wxString& key, bool defaultVal) const;
23324ae1
FM
659
660 /**
bd0812fe
BP
661 Reads a double value from the key and returns it. @a defaultVal is
662 returned if the key is not found.
23324ae1 663 */
382f12e4 664 double ReadDouble(const wxString& key, double defaultVal) const;
23324ae1
FM
665
666 /**
bd0812fe
BP
667 Reads a long value from the key and returns it. @a defaultVal is
668 returned if the key is not found.
23324ae1 669 */
328f5751 670 long ReadLong(const wxString& key, long defaultVal) const;
23324ae1
FM
671
672 /**
bd0812fe
BP
673 Reads a value of type T (for which the function wxFromString() must be
674 defined) from the key and returns it. @a defaultVal is returned if the
675 key is not found.
23324ae1 676 */
328f5751 677 T ReadObject(const wxString& key, T const& defaultVal) const;
23324ae1
FM
678
679 /**
bd0812fe
BP
680 Writes the wxString value to the config file and returns @true on
681 success.
682 */
683 bool Write(const wxString& key, const wxString& value);
684 /**
685 Writes the long value to the config file and returns @true on success.
686 */
687 bool Write(const wxString& key, long value);
688 /**
689 Writes the double value to the config file and returns @true on
690 success.
7e22c2bd
VZ
691
692 Notice that if floating point numbers are saved as strings (as is the
693 case with the configuration files used by wxFileConfig), this function
694 uses the C locale for writing out the number, i.e. it will always use a
695 period as the decimal separator, irrespectively of the current locale.
696 This behaviour is new since wxWidgets 2.9.1 as the current locale was
697 used before, but the change should be transparent because both C and
698 current locales are tried when reading the numbers back.
bd0812fe
BP
699 */
700 bool Write(const wxString& key, double value);
701 /**
702 Writes the bool value to the config file and returns @true on success.
23324ae1 703 */
bd0812fe
BP
704 bool Write(const wxString& key, bool value);
705 /**
706 Writes the wxMemoryBuffer value to the config file and returns @true on
707 success.
708 */
709 bool Write(const wxString& key, const wxMemoryBuffer& buf);
710 /**
711 Writes the specified value to the config file and returns @true on
712 success. The function wxToString() must be defined for type @e T.
713 */
714 bool Write(const wxString& key, T const& buf);
715
716 //@}
23324ae1
FM
717
718
719 /**
bd0812fe
BP
720 @name Rename Entries/Groups
721
722 These functions allow renaming entries or subgroups of the current
723 group. They will return @false on error, typically because either the
724 entry/group with the original name doesn't exist, because the
725 entry/group with the new name already exists or because the function is
726 not supported in this wxConfig implementation.
23324ae1 727 */
bd0812fe 728 //@{
23324ae1
FM
729
730 /**
bd0812fe
BP
731 Renames an entry in the current group. The entries names (both the old
732 and the new one) shouldn't contain backslashes, i.e. only simple names
733 and not arbitrary paths are accepted by this function.
734
d29a9a8a
BP
735 @return @false if @a oldName doesn't exist or if @a newName already
736 exists.
23324ae1 737 */
382f12e4
FM
738 virtual bool RenameEntry(const wxString& oldName,
739 const wxString& newName) = 0;
23324ae1
FM
740
741 /**
bd0812fe
BP
742 Renames a subgroup of the current group. The subgroup names (both the
743 old and the new one) shouldn't contain backslashes, i.e. only simple
744 names and not arbitrary paths are accepted by this function.
745
d29a9a8a
BP
746 @return @false if @a oldName doesn't exist or if @a newName already
747 exists.
23324ae1 748 */
382f12e4
FM
749 virtual bool RenameGroup(const wxString& oldName,
750 const wxString& newName) = 0;
bd0812fe
BP
751
752 //@}
753
23324ae1
FM
754
755 /**
bd0812fe
BP
756 @name Delete Entries/Groups
757
758 These functions delete entries and/or groups of entries from the config
759 file. DeleteAll() is especially useful if you want to erase all traces
760 of your program presence: for example, when you uninstall it.
23324ae1 761 */
bd0812fe 762 //@{
23324ae1
FM
763
764 /**
bd0812fe 765 Delete the whole underlying object (disk file, registry key, ...).
d13b34d3 766 Primarily for use by uninstallation routine.
23324ae1 767 */
382f12e4 768 virtual bool DeleteAll() = 0;
23324ae1
FM
769
770 /**
bd0812fe
BP
771 Deletes the specified entry and the group it belongs to if it was the
772 last key in it and the second parameter is @true.
23324ae1 773 */
382f12e4
FM
774 virtual bool DeleteEntry(const wxString& key,
775 bool bDeleteGroupIfEmpty = true) = 0;
23324ae1
FM
776
777 /**
bd0812fe
BP
778 Delete the group (with all subgroups). If the current path is under the
779 group being deleted it is changed to its deepest still existing
780 component. E.g. if the current path is @c "/A/B/C/D" and the group @c C
781 is deleted, the path becomes @c "/A/B".
782 */
382f12e4 783 virtual bool DeleteGroup(const wxString& key) = 0;
3c4f71cc 784
bd0812fe 785 //@}
3c4f71cc 786
3c4f71cc 787
bd0812fe
BP
788 /**
789 @name Options
23324ae1 790
bd0812fe
BP
791 Some aspects of wxConfigBase behaviour can be changed during run-time.
792 The first of them is the expansion of environment variables in the
793 string values read from the config file: for example, if you have the
794 following in your config file:
23324ae1 795
bd0812fe
BP
796 @code
797 # config file for my program
798 UserData = $HOME/data
3c4f71cc 799
bd0812fe
BP
800 # the following syntax is valud only under Windows
801 UserData = %windir%\\data.dat
802 @endcode
3c4f71cc 803
bd0812fe
BP
804 The call to Read("UserData") will return something like
805 @c "/home/zeitlin/data" on linux for example.
3c4f71cc 806
bd0812fe
BP
807 Although this feature is very useful, it may be annoying if you read a
808 value which containts '$' or '%' symbols (% is used for environment
809 variables expansion under Windows) which are not used for environment
810 variable expansion. In this situation you may call
811 SetExpandEnvVars(@false) just before reading this value and
812 SetExpandEnvVars(@true) just after. Another solution would be to prefix
813 the offending symbols with a backslash.
23324ae1 814 */
bd0812fe 815 //@{
23324ae1 816
bd0812fe
BP
817 /**
818 Returns @true if we are expanding environment variables in key values.
819 */
820 bool IsExpandingEnvVars() const;
23324ae1 821
23324ae1 822 /**
bd0812fe
BP
823 Returns @true if we are writing defaults back to the config file.
824 */
825 bool IsRecordingDefaults() const;
3c4f71cc 826
bd0812fe
BP
827 /**
828 Determine whether we wish to expand environment variables in key
829 values.
830 */
831 void SetExpandEnvVars(bool bDoIt = true);
3c4f71cc 832
bd0812fe
BP
833 /**
834 Sets whether defaults are recorded to the config file whenever an
835 attempt to read the value which is not present in it is done.
3c4f71cc 836
bd0812fe
BP
837 If on (default is off) all default values for the settings used by the
838 program are written back to the config file. This allows the user to
839 see what config options may be changed and is probably useful only for
840 wxFileConfig.
841 */
842 void SetRecordDefaults(bool bDoIt = true);
3c4f71cc 843
bd0812fe 844 //@}
3c4f71cc 845
3c4f71cc 846
bd0812fe 847 /**
ba67d647
VZ
848 Create a new config object and sets it as the current one.
849
850 This function will create the most appropriate implementation of
851 wxConfig available for the current platform. By default this means that
852 the system registry will be used for storing the configuration
853 information under MSW and a file under the user home directory (see
854 wxStandardPaths::GetUserConfigDir()) elsewhere.
855
856 If you prefer to use the configuration files everywhere, you can define
857 @c wxUSE_CONFIG_NATIVE to 0 when compiling wxWidgets. Or you can simply
858 always create wxFileConfig explicitly.
859
860 Finally, if you want to create a custom wxConfig subclass you may
861 change this function behaviour by overriding wxAppTraits::CreateConfig()
862 to create it. An example when this could be useful could be an
863 application which could be installed either normally (in which case the
864 default behaviour of using wxRegConfig is appropriate) or in a
865 "portable" way in which case a wxFileConfig with a file in the program
866 directory would be used and the choice would be done in CreateConfig()
867 at run-time.
bd0812fe
BP
868 */
869 static wxConfigBase* Create();
3c4f71cc 870
bd0812fe
BP
871 /**
872 Calling this function will prevent @e Get() from automatically creating
873 a new config object if the current one is @NULL. It might be useful to
874 call it near the program end to prevent "accidental" creation of a new
875 config object.
876 */
877 static void DontCreateOnDemand();
3c4f71cc 878
bd0812fe
BP
879 /**
880 Get the current config object. If there is no current object and
881 @a CreateOnDemand is @true, this creates one (using Create()) unless
882 DontCreateOnDemand() was called previously.
883 */
884 static wxConfigBase* Get(bool CreateOnDemand = true);
3c4f71cc 885
bd0812fe
BP
886 /**
887 Sets the config object as the current one, returns the pointer to the
888 previous current object (both the parameter and returned value may be
889 @NULL).
23324ae1 890 */
bd0812fe 891 static wxConfigBase* Set(wxConfigBase* pConfig);
23324ae1 892};
e54c96f1 893