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