]> git.saurik.com Git - wxWidgets.git/blob - src/common/sysopt.cpp
wxDialogBase only has one ctor, so just do initialization in ctor instead of Init()
[wxWidgets.git] / src / common / sysopt.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/sysopt.cpp
3 // Purpose: wxSystemOptions
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 2001-07-10
7 // Copyright: (c) Julian Smart
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 // ============================================================================
12 // declarations
13 // ============================================================================
14
15 // ---------------------------------------------------------------------------
16 // headers
17 // ---------------------------------------------------------------------------
18
19 // For compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
21
22 #if defined(__BORLANDC__)
23 #pragma hdrstop
24 #endif
25
26 #if wxUSE_SYSTEM_OPTIONS
27
28 #include "wx/sysopt.h"
29
30 #ifndef WX_PRECOMP
31 #include "wx/app.h"
32 #include "wx/list.h"
33 #include "wx/string.h"
34 #include "wx/arrstr.h"
35 #endif
36
37 // ----------------------------------------------------------------------------
38 // private globals
39 // ----------------------------------------------------------------------------
40
41 static wxArrayString gs_optionNames,
42 gs_optionValues;
43
44 // ============================================================================
45 // wxSystemOptions implementation
46 // ============================================================================
47
48 // Option functions (arbitrary name/value mapping)
49 void wxSystemOptions::SetOption(const wxString& name, const wxString& value)
50 {
51 int idx = gs_optionNames.Index(name, false);
52 if (idx == wxNOT_FOUND)
53 {
54 gs_optionNames.Add(name);
55 gs_optionValues.Add(value);
56 }
57 else
58 {
59 gs_optionNames[idx] = name;
60 gs_optionValues[idx] = value;
61 }
62 }
63
64 void wxSystemOptions::SetOption(const wxString& name, int value)
65 {
66 SetOption(name, wxString::Format(wxT("%d"), value));
67 }
68
69 wxString wxSystemOptions::GetOption(const wxString& name)
70 {
71 wxString val;
72
73 int idx = gs_optionNames.Index(name, false);
74 if ( idx != wxNOT_FOUND )
75 {
76 val = gs_optionValues[idx];
77 }
78 else // not set explicitly
79 {
80 // look in the environment: first for a variable named "wx_appname_name"
81 // which can be set to affect the behaviour or just this application
82 // and then for "wx_name" which can be set to change the option globally
83 wxString var(name);
84 var.Replace(wxT("."), wxT("_")); // '.'s not allowed in env var names
85 var.Replace(wxT("-"), wxT("_")); // and neither are '-'s
86
87 wxString appname;
88 if ( wxTheApp )
89 appname = wxTheApp->GetAppName();
90
91 if ( !appname.empty() )
92 val = wxGetenv(wxT("wx_") + appname + wxT('_') + var);
93
94 if ( val.empty() )
95 val = wxGetenv(wxT("wx_") + var);
96 }
97
98 return val;
99 }
100
101 int wxSystemOptions::GetOptionInt(const wxString& name)
102 {
103 return wxAtoi (GetOption(name));
104 }
105
106 bool wxSystemOptions::HasOption(const wxString& name)
107 {
108 return !GetOption(name).empty();
109 }
110
111 #endif // wxUSE_SYSTEM_OPTIONS