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