]> git.saurik.com Git - wxWidgets.git/blob - src/gtk1/utilsres.cpp
fixed typos in wxBase template and project file
[wxWidgets.git] / src / gtk1 / utilsres.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: utilres.cpp
3 // Purpose:
4 // Author: Robert Roebling
5 // Id: $Id$
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
9
10 //#ifdef __GNUG__
11 //#pragma implementation "utils.h"
12 //#endif
13
14 #include "wx/utils.h"
15 #include "wx/string.h"
16 #include "wx/list.h"
17 #include "wx/log.h"
18 #include "wx/config.h"
19 #include "wx/app.h"
20
21 //-----------------------------------------------------------------------------
22 // resource functions
23 //-----------------------------------------------------------------------------
24
25 bool wxWriteResource(const wxString& section, const wxString& entry, const wxString& value, const wxString& file )
26 {
27 wxString filename( file );
28 if (filename.IsEmpty()) filename = wxT(".wxWindows");
29
30 wxFileConfig conf( wxTheApp->GetAppName(), wxTheApp->GetVendorName(), filename );
31
32 conf.SetPath( section );
33
34 return conf.Write( entry, value );
35 }
36
37 bool wxWriteResource(const wxString& section, const wxString& entry, float value, const wxString& file )
38 {
39 wxString buf;
40 buf.Printf(wxT("%.4f"), value);
41
42 return wxWriteResource(section, entry, buf, file);
43 }
44
45 bool wxWriteResource(const wxString& section, const wxString& entry, long value, const wxString& file )
46 {
47 wxString buf;
48 buf.Printf(wxT("%ld"), value);
49
50 return wxWriteResource(section, entry, buf, file);
51 }
52
53 bool wxWriteResource(const wxString& section, const wxString& entry, int value, const wxString& file )
54 {
55 wxString buf;
56 buf.Printf(wxT("%d"), value);
57
58 return wxWriteResource(section, entry, buf, file);
59 }
60
61 bool wxGetResource(const wxString& section, const wxString& entry, wxChar **value, const wxString& file )
62 {
63 wxString filename( file );
64 if (filename.IsEmpty()) filename = wxT(".wxWindows");
65
66 wxFileConfig conf( wxTheApp->GetAppName(), wxTheApp->GetVendorName(), filename );
67
68 conf.SetPath( section );
69
70 wxString result;
71 if (conf.Read( entry, &result ))
72 {
73 if (!result.IsEmpty())
74 {
75 wxChar *s = new wxChar[result.Len()+1];
76 wxStrcpy( s, result.c_str() );
77 *value = s;
78 return TRUE;
79 }
80 }
81
82 return FALSE;
83 }
84
85 bool wxGetResource(const wxString& section, const wxString& entry, float *value, const wxString& file )
86 {
87 wxChar *s = NULL;
88 bool succ = wxGetResource(section, entry, (wxChar **)&s, file);
89 if (succ)
90 {
91 *value = (float)wxStrtod(s, NULL);
92 delete[] s;
93 return TRUE;
94 }
95 else return FALSE;
96 }
97
98 bool wxGetResource(const wxString& section, const wxString& entry, long *value, const wxString& file )
99 {
100 wxChar *s = NULL;
101 bool succ = wxGetResource(section, entry, (wxChar **)&s, file);
102 if (succ)
103 {
104 *value = wxStrtol(s, NULL, 10);
105 delete[] s;
106 return TRUE;
107 }
108 else return FALSE;
109 }
110
111 bool wxGetResource(const wxString& section, const wxString& entry, int *value, const wxString& file )
112 {
113 wxChar *s = NULL;
114 bool succ = wxGetResource(section, entry, (wxChar **)&s, file);
115 if (succ)
116 {
117 *value = (int)wxStrtol(s, NULL, 10);
118 delete[] s;
119 return TRUE;
120 }
121 else return FALSE;
122 }
123