]>
git.saurik.com Git - wxWidgets.git/blob - src/gtk/utilsres.cpp
1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Robert Roebling
6 // Copyright: (c) 1998 Robert Roebling
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
11 //#pragma implementation "utils.h"
15 #include "wx/string.h"
18 #include "wx/config.h"
21 //-----------------------------------------------------------------------------
23 //-----------------------------------------------------------------------------
25 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, const wxString
& value
, const wxString
& file
)
27 wxString
filename( file
);
28 if (filename
.IsEmpty()) filename
= wxT(".wxWindows");
30 wxFileConfig
conf( wxTheApp
->GetAppName(), wxTheApp
->GetVendorName(), filename
);
32 conf
.SetPath( section
);
34 return conf
.Write( entry
, value
);
37 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, float value
, const wxString
& file
)
40 buf
.Printf(wxT("%.4f"), value
);
42 return wxWriteResource(section
, entry
, buf
, file
);
45 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, long value
, const wxString
& file
)
48 buf
.Printf(wxT("%ld"), value
);
50 return wxWriteResource(section
, entry
, buf
, file
);
53 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, int value
, const wxString
& file
)
56 buf
.Printf(wxT("%d"), value
);
58 return wxWriteResource(section
, entry
, buf
, file
);
61 bool wxGetResource(const wxString
& section
, const wxString
& entry
, char **value
, const wxString
& file
)
63 wxString
filename( file
);
64 if (filename
.IsEmpty()) filename
= wxT(".wxWindows");
66 wxFileConfig
conf( wxTheApp
->GetAppName(), wxTheApp
->GetVendorName(), filename
);
68 conf
.SetPath( section
);
71 if (conf
.Read( entry
, &result
))
73 if (!result
.IsEmpty())
75 char *s
= new char[result
.Len()+1];
76 wxStrcpy( s
, result
.c_str() );
85 bool wxGetResource(const wxString
& section
, const wxString
& entry
, float *value
, const wxString
& file
)
88 bool succ
= wxGetResource(section
, entry
, (wxChar
**)&s
, file
);
91 *value
= (float)wxStrtod(s
, NULL
);
98 bool wxGetResource(const wxString
& section
, const wxString
& entry
, long *value
, const wxString
& file
)
101 bool succ
= wxGetResource(section
, entry
, (wxChar
**)&s
, file
);
104 *value
= wxStrtol(s
, NULL
, 10);
111 bool wxGetResource(const wxString
& section
, const wxString
& entry
, int *value
, const wxString
& file
)
114 bool succ
= wxGetResource(section
, entry
, (wxChar
**)&s
, file
);
117 *value
= (int)wxStrtol(s
, NULL
, 10);