]> git.saurik.com Git - wxWidgets.git/blame - src/gtk1/utilsres.cpp
non-pch build fix
[wxWidgets.git] / src / gtk1 / utilsres.cpp
CommitLineData
c801d85f 1/////////////////////////////////////////////////////////////////////////////
8ecff181 2// Name: src/gtk1/utilsres.cpp
c801d85f
KB
3// Purpose:
4// Author: Robert Roebling
a81258be 5// Id: $Id$
bd046d42 6// Copyright: (c) 1998 Robert Roebling
65571936 7// Licence: wxWindows licence
c801d85f
KB
8/////////////////////////////////////////////////////////////////////////////
9
14f355c2
VS
10// For compilers that support precompilation, includes "wx.h".
11#include "wx/wxprec.h"
12
df91131c
WS
13#include "wx/utils.h"
14
8ecff181
WS
15#ifndef WX_PRECOMP
16 #include "wx/list.h"
df91131c 17 #include "wx/string.h"
e4db172a 18 #include "wx/log.h"
670f9935 19 #include "wx/app.h"
8ecff181
WS
20#endif
21
bd046d42 22#include "wx/config.h"
c801d85f
KB
23
24//-----------------------------------------------------------------------------
25// resource functions
26//-----------------------------------------------------------------------------
27
28bool wxWriteResource(const wxString& section, const wxString& entry, const wxString& value, const wxString& file )
29{
bd046d42 30 wxString filename( file );
8ecff181 31 if (filename.empty()) filename = wxT(".wxWindows");
3d257b8d 32
bd046d42 33 wxFileConfig conf( wxTheApp->GetAppName(), wxTheApp->GetVendorName(), filename );
3d257b8d 34
bd046d42 35 conf.SetPath( section );
3d257b8d 36
bd046d42
RR
37 return conf.Write( entry, value );
38}
c801d85f
KB
39
40bool wxWriteResource(const wxString& section, const wxString& entry, float value, const wxString& file )
41{
bd046d42
RR
42 wxString buf;
43 buf.Printf(wxT("%.4f"), value);
44
c801d85f 45 return wxWriteResource(section, entry, buf, file);
bd046d42 46}
c801d85f
KB
47
48bool wxWriteResource(const wxString& section, const wxString& entry, long value, const wxString& file )
49{
bd046d42
RR
50 wxString buf;
51 buf.Printf(wxT("%ld"), value);
52
c801d85f 53 return wxWriteResource(section, entry, buf, file);
bd046d42 54}
c801d85f
KB
55
56bool wxWriteResource(const wxString& section, const wxString& entry, int value, const wxString& file )
57{
bd046d42
RR
58 wxString buf;
59 buf.Printf(wxT("%d"), value);
60
c801d85f 61 return wxWriteResource(section, entry, buf, file);
bd046d42 62}
c801d85f 63
cbf97a6c 64bool wxGetResource(const wxString& section, const wxString& entry, wxChar **value, const wxString& file )
c801d85f 65{
bd046d42 66 wxString filename( file );
8ecff181 67 if (filename.empty()) filename = wxT(".wxWindows");
9c2882d9 68
bd046d42 69 wxFileConfig conf( wxTheApp->GetAppName(), wxTheApp->GetVendorName(), filename );
9c2882d9 70
bd046d42 71 conf.SetPath( section );
9c2882d9 72
bd046d42 73 wxString result;
9c2882d9 74 if (conf.Read( entry, &result ))
3e61c765 75 {
8ecff181 76 if (!result.empty())
9c2882d9 77 {
cbf97a6c 78 wxChar *s = new wxChar[result.Len()+1];
9c2882d9
VZ
79 wxStrcpy( s, result.c_str() );
80 *value = s;
8ecff181 81 return true;
9c2882d9 82 }
c801d85f 83 }
9c2882d9 84
8ecff181 85 return false;
bd046d42 86}
c801d85f
KB
87
88bool wxGetResource(const wxString& section, const wxString& entry, float *value, const wxString& file )
89{
bd046d42
RR
90 wxChar *s = NULL;
91 bool succ = wxGetResource(section, entry, (wxChar **)&s, file);
92 if (succ)
3e61c765 93 {
934960d1 94 *value = (float)wxStrtod(s, (wchar_t **) NULL);
bd046d42 95 delete[] s;
8ecff181 96 return true;
bd046d42 97 }
8ecff181 98 else return false;
bd046d42 99}
c801d85f
KB
100
101bool wxGetResource(const wxString& section, const wxString& entry, long *value, const wxString& file )
102{
bd046d42
RR
103 wxChar *s = NULL;
104 bool succ = wxGetResource(section, entry, (wxChar **)&s, file);
105 if (succ)
3e61c765 106 {
934960d1 107 *value = wxStrtol(s, (wchar_t **) NULL, 10);
bd046d42 108 delete[] s;
8ecff181 109 return true;
bd046d42 110 }
8ecff181 111 else return false;
bd046d42 112}
c801d85f
KB
113
114bool wxGetResource(const wxString& section, const wxString& entry, int *value, const wxString& file )
115{
bd046d42
RR
116 wxChar *s = NULL;
117 bool succ = wxGetResource(section, entry, (wxChar **)&s, file);
118 if (succ)
3e61c765 119 {
934960d1 120 *value = (int)wxStrtol(s, (wchar_t **) NULL, 10);
bd046d42 121 delete[] s;
8ecff181 122 return true;
bd046d42 123 }
8ecff181 124 else return false;
bd046d42 125}