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