]>
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 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart | |
d775fa82 | 9 | // Licence: wxWindows licence |
0cbff120 JS |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | // ============================================================================ | |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // --------------------------------------------------------------------------- | |
17 | // headers | |
18 | // --------------------------------------------------------------------------- | |
19 | ||
0cbff120 JS |
20 | // For compilers that support precompilation, includes "wx.h". |
21 | #include "wx/wxprec.h" | |
22 | ||
23 | #if defined(__BORLANDC__) | |
24 | #pragma hdrstop | |
25 | #endif | |
26 | ||
410c3efc VZ |
27 | #if wxUSE_SYSTEM_OPTIONS |
28 | ||
df91131c WS |
29 | #include "wx/sysopt.h" |
30 | ||
0cbff120 | 31 | #ifndef WX_PRECOMP |
bf85ddfc | 32 | #include "wx/app.h" |
0cbff120 | 33 | #include "wx/list.h" |
df91131c | 34 | #include "wx/string.h" |
aaa6d89a | 35 | #include "wx/arrstr.h" |
0cbff120 JS |
36 | #endif |
37 | ||
0cbff120 | 38 | // ---------------------------------------------------------------------------- |
410c3efc | 39 | // private globals |
0cbff120 JS |
40 | // ---------------------------------------------------------------------------- |
41 | ||
410c3efc VZ |
42 | static wxArrayString gs_optionNames, |
43 | gs_optionValues; | |
0cbff120 | 44 | |
410c3efc VZ |
45 | // ============================================================================ |
46 | // wxSystemOptions implementation | |
47 | // ============================================================================ | |
0cbff120 JS |
48 | |
49 | // Option functions (arbitrary name/value mapping) | |
50 | void wxSystemOptions::SetOption(const wxString& name, const wxString& value) | |
51 | { | |
410c3efc | 52 | int idx = gs_optionNames.Index(name, false); |
0cbff120 JS |
53 | if (idx == wxNOT_FOUND) |
54 | { | |
410c3efc VZ |
55 | gs_optionNames.Add(name); |
56 | gs_optionValues.Add(value); | |
0cbff120 JS |
57 | } |
58 | else | |
59 | { | |
410c3efc VZ |
60 | gs_optionNames[idx] = name; |
61 | gs_optionValues[idx] = value; | |
0cbff120 JS |
62 | } |
63 | } | |
64 | ||
65 | void wxSystemOptions::SetOption(const wxString& name, int value) | |
66 | { | |
410c3efc | 67 | SetOption(name, wxString::Format(wxT("%d"), value)); |
0cbff120 JS |
68 | } |
69 | ||
70 | wxString wxSystemOptions::GetOption(const wxString& name) | |
71 | { | |
bf85ddfc VZ |
72 | wxString val; |
73 | ||
410c3efc | 74 | int idx = gs_optionNames.Index(name, false); |
bf85ddfc VZ |
75 | if ( idx != wxNOT_FOUND ) |
76 | { | |
77 | val = gs_optionValues[idx]; | |
78 | } | |
4c51a665 | 79 | else // not set explicitly |
bf85ddfc VZ |
80 | { |
81 | // look in the environment: first for a variable named "wx_appname_name" | |
82 | // which can be set to affect the behaviour or just this application | |
83 | // and then for "wx_name" which can be set to change the option globally | |
84 | wxString var(name); | |
9a83f860 | 85 | var.Replace(wxT("."), wxT("_")); // '.'s not allowed in env var names |
aa0af8ce | 86 | var.Replace(wxT("-"), wxT("_")); // and neither are '-'s |
bf85ddfc VZ |
87 | |
88 | wxString appname; | |
89 | if ( wxTheApp ) | |
90 | appname = wxTheApp->GetAppName(); | |
91 | ||
92 | if ( !appname.empty() ) | |
9a83f860 | 93 | val = wxGetenv(wxT("wx_") + appname + wxT('_') + var); |
bf85ddfc VZ |
94 | |
95 | if ( val.empty() ) | |
9a83f860 | 96 | val = wxGetenv(wxT("wx_") + var); |
bf85ddfc VZ |
97 | } |
98 | ||
99 | return val; | |
0cbff120 JS |
100 | } |
101 | ||
102 | int wxSystemOptions::GetOptionInt(const wxString& name) | |
103 | { | |
fcb9fb91 VZ |
104 | #ifdef _PACC_VER |
105 | // work around the PalmOS pacc compiler bug | |
106 | return wxAtoi (GetOption(name).data()); | |
107 | #else | |
108 | return wxAtoi (GetOption(name)); | |
109 | #endif | |
0cbff120 JS |
110 | } |
111 | ||
112 | bool wxSystemOptions::HasOption(const wxString& name) | |
113 | { | |
bf85ddfc | 114 | return !GetOption(name).empty(); |
0cbff120 JS |
115 | } |
116 | ||
410c3efc | 117 | #endif // wxUSE_SYSTEM_OPTIONS |