1///////////////////////////////////////////////////////////////////////////// 2// Name: src/gtk/utilsres.cpp 3// Purpose: 4// Author: Robert Roebling 5// Id: $Id: utilsres.cpp 45836 2007-05-05 17:13:30Z PC $ 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#if wxUSE_CONFIG 14 15#include "wx/utils.h" 16 17#ifndef WX_PRECOMP 18 #include "wx/list.h" 19 #include "wx/string.h" 20 #include "wx/log.h" 21 #include "wx/app.h" 22#endif 23 24#include "wx/config.h" 25 26//----------------------------------------------------------------------------- 27// resource functions 28//----------------------------------------------------------------------------- 29 30bool wxWriteResource(const wxString& section, const wxString& entry, const wxString& value, const wxString& file ) 31{ 32 wxString filename( file ); 33 if (filename.empty()) filename = wxT(".wxWindows"); 34 35 wxFileConfig conf( wxTheApp->GetAppName(), wxTheApp->GetVendorName(), filename ); 36 37 conf.SetPath( section ); 38 39 return conf.Write( entry, value ); 40} 41 42bool wxWriteResource(const wxString& section, const wxString& entry, float value, const wxString& file ) 43{ 44 wxString buf; 45 buf.Printf(wxT("%.4f"), value); 46 47 return wxWriteResource(section, entry, buf, file); 48} 49 50bool wxWriteResource(const wxString& section, const wxString& entry, long value, const wxString& file ) 51{ 52 wxString buf; 53 buf.Printf(wxT("%ld"), value); 54 55 return wxWriteResource(section, entry, buf, file); 56} 57 58bool wxWriteResource(const wxString& section, const wxString& entry, int value, const wxString& file ) 59{ 60 wxString buf; 61 buf.Printf(wxT("%d"), value); 62 63 return wxWriteResource(section, entry, buf, file); 64} 65 66bool wxGetResource(const wxString& section, const wxString& entry, wxChar **value, const wxString& file ) 67{ 68 wxString filename( file ); 69 if (filename.empty()) filename = wxT(".wxWindows"); 70 71 wxFileConfig conf( wxTheApp->GetAppName(), wxTheApp->GetVendorName(), filename ); 72 73 conf.SetPath( section ); 74 75 wxString result; 76 if (conf.Read( entry, &result )) 77 { 78 if (!result.empty()) 79 { 80 wxChar *s = new wxChar[result.Len()+1]; 81 wxStrcpy( s, result.c_str() ); 82 *value = s; 83 return true; 84 } 85 } 86 87 return false; 88} 89 90bool wxGetResource(const wxString& section, const wxString& entry, float *value, const wxString& file ) 91{ 92 wxChar *s = NULL; 93 bool succ = wxGetResource(section, entry, (wxChar **)&s, file); 94 if (succ) 95 { 96 *value = (float)wxStrtod(s, NULL); 97 delete[] s; 98 return true; 99 } 100 else return false; 101} 102 103bool wxGetResource(const wxString& section, const wxString& entry, long *value, const wxString& file ) 104{ 105 wxChar *s = NULL; 106 bool succ = wxGetResource(section, entry, (wxChar **)&s, file); 107 if (succ) 108 { 109 *value = wxStrtol(s, NULL, 10); 110 delete[] s; 111 return true; 112 } 113 else return false; 114} 115 116bool wxGetResource(const wxString& section, const wxString& entry, int *value, const wxString& file ) 117{ 118 wxChar *s = NULL; 119 bool succ = wxGetResource(section, entry, (wxChar **)&s, file); 120 if (succ) 121 { 122 *value = (int)wxStrtol(s, NULL, 10); 123 delete[] s; 124 return true; 125 } 126 else return false; 127} 128 129#endif // wxUSE_CONFIG 130