]>
Commit | Line | Data |
---|---|---|
0cbff120 | 1 | ///////////////////////////////////////////////////////////////////////////// |
df91131c | 2 | // Name: src/common/sysopt.cpp |
0cbff120 JS |
3 | // Purpose: wxSystemOptions |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 2001-07-10 | |
0cbff120 | 7 | // Copyright: (c) Julian Smart |
d775fa82 | 8 | // Licence: wxWindows licence |
0cbff120 JS |
9 | ///////////////////////////////////////////////////////////////////////////// |
10 | ||
11 | // ============================================================================ | |
12 | // declarations | |
13 | // ============================================================================ | |
14 | ||
15 | // --------------------------------------------------------------------------- | |
16 | // headers | |
17 | // --------------------------------------------------------------------------- | |
18 | ||
0cbff120 JS |
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 | ||
410c3efc VZ |
26 | #if wxUSE_SYSTEM_OPTIONS |
27 | ||
df91131c WS |
28 | #include "wx/sysopt.h" |
29 | ||
0cbff120 | 30 | #ifndef WX_PRECOMP |
bf85ddfc | 31 | #include "wx/app.h" |
0cbff120 | 32 | #include "wx/list.h" |
df91131c | 33 | #include "wx/string.h" |
aaa6d89a | 34 | #include "wx/arrstr.h" |
0cbff120 JS |
35 | #endif |
36 | ||
0cbff120 | 37 | // ---------------------------------------------------------------------------- |
410c3efc | 38 | // private globals |
0cbff120 JS |
39 | // ---------------------------------------------------------------------------- |
40 | ||
410c3efc VZ |
41 | static wxArrayString gs_optionNames, |
42 | gs_optionValues; | |
0cbff120 | 43 | |
410c3efc VZ |
44 | // ============================================================================ |
45 | // wxSystemOptions implementation | |
46 | // ============================================================================ | |
0cbff120 JS |
47 | |
48 | // Option functions (arbitrary name/value mapping) | |
49 | void wxSystemOptions::SetOption(const wxString& name, const wxString& value) | |
50 | { | |
410c3efc | 51 | int idx = gs_optionNames.Index(name, false); |
0cbff120 JS |
52 | if (idx == wxNOT_FOUND) |
53 | { | |
410c3efc VZ |
54 | gs_optionNames.Add(name); |
55 | gs_optionValues.Add(value); | |
0cbff120 JS |
56 | } |
57 | else | |
58 | { | |
410c3efc VZ |
59 | gs_optionNames[idx] = name; |
60 | gs_optionValues[idx] = value; | |
0cbff120 JS |
61 | } |
62 | } | |
63 | ||
64 | void wxSystemOptions::SetOption(const wxString& name, int value) | |
65 | { | |
410c3efc | 66 | SetOption(name, wxString::Format(wxT("%d"), value)); |
0cbff120 JS |
67 | } |
68 | ||
69 | wxString wxSystemOptions::GetOption(const wxString& name) | |
70 | { | |
bf85ddfc VZ |
71 | wxString val; |
72 | ||
410c3efc | 73 | int idx = gs_optionNames.Index(name, false); |
bf85ddfc VZ |
74 | if ( idx != wxNOT_FOUND ) |
75 | { | |
76 | val = gs_optionValues[idx]; | |
77 | } | |
4c51a665 | 78 | else // not set explicitly |
bf85ddfc VZ |
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); | |
9a83f860 | 84 | var.Replace(wxT("."), wxT("_")); // '.'s not allowed in env var names |
aa0af8ce | 85 | var.Replace(wxT("-"), wxT("_")); // and neither are '-'s |
bf85ddfc VZ |
86 | |
87 | wxString appname; | |
88 | if ( wxTheApp ) | |
89 | appname = wxTheApp->GetAppName(); | |
90 | ||
91 | if ( !appname.empty() ) | |
9a83f860 | 92 | val = wxGetenv(wxT("wx_") + appname + wxT('_') + var); |
bf85ddfc VZ |
93 | |
94 | if ( val.empty() ) | |
9a83f860 | 95 | val = wxGetenv(wxT("wx_") + var); |
bf85ddfc VZ |
96 | } |
97 | ||
98 | return val; | |
0cbff120 JS |
99 | } |
100 | ||
101 | int wxSystemOptions::GetOptionInt(const wxString& name) | |
102 | { | |
fcb9fb91 | 103 | return wxAtoi (GetOption(name)); |
0cbff120 JS |
104 | } |
105 | ||
106 | bool wxSystemOptions::HasOption(const wxString& name) | |
107 | { | |
bf85ddfc | 108 | return !GetOption(name).empty(); |
0cbff120 JS |
109 | } |
110 | ||
410c3efc | 111 | #endif // wxUSE_SYSTEM_OPTIONS |