]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/common/sysopt.cpp
#9675: wxDataViewModel::Reset() and scrollbar problem (wxMac)
[wxWidgets.git] / src / common / sysopt.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/common/sysopt.cpp
3// Purpose: wxSystemOptions
4// Author: Julian Smart
5// Modified by:
6// Created: 2001-07-10
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ---------------------------------------------------------------------------
17// headers
18// ---------------------------------------------------------------------------
19
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
27#if wxUSE_SYSTEM_OPTIONS
28
29#include "wx/sysopt.h"
30
31#ifndef WX_PRECOMP
32 #include "wx/app.h"
33 #include "wx/list.h"
34 #include "wx/string.h"
35 #include "wx/arrstr.h"
36#endif
37
38// ----------------------------------------------------------------------------
39// private globals
40// ----------------------------------------------------------------------------
41
42static wxArrayString gs_optionNames,
43 gs_optionValues;
44
45// ============================================================================
46// wxSystemOptions implementation
47// ============================================================================
48
49// Option functions (arbitrary name/value mapping)
50void wxSystemOptions::SetOption(const wxString& name, const wxString& value)
51{
52 int idx = gs_optionNames.Index(name, false);
53 if (idx == wxNOT_FOUND)
54 {
55 gs_optionNames.Add(name);
56 gs_optionValues.Add(value);
57 }
58 else
59 {
60 gs_optionNames[idx] = name;
61 gs_optionValues[idx] = value;
62 }
63}
64
65void wxSystemOptions::SetOption(const wxString& name, int value)
66{
67 SetOption(name, wxString::Format(wxT("%d"), value));
68}
69
70wxString wxSystemOptions::GetOption(const wxString& name)
71{
72 wxString val;
73
74 int idx = gs_optionNames.Index(name, false);
75 if ( idx != wxNOT_FOUND )
76 {
77 val = gs_optionValues[idx];
78 }
79 else // not set explicitely
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);
85 var.Replace(_T("."), _T("_")); // '.'s not allowed in env var names
86
87 wxString appname;
88 if ( wxTheApp )
89 appname = wxTheApp->GetAppName();
90
91 if ( !appname.empty() )
92 val = wxGetenv(_T("wx_") + appname + _T('_') + var);
93
94 if ( val.empty() )
95 val = wxGetenv(_T("wx_") + var);
96 }
97
98 return val;
99}
100
101int wxSystemOptions::GetOptionInt(const wxString& name)
102{
103#ifdef _PACC_VER
104 // work around the PalmOS pacc compiler bug
105 return wxAtoi (GetOption(name).data());
106#else
107 return wxAtoi (GetOption(name));
108#endif
109}
110
111bool wxSystemOptions::HasOption(const wxString& name)
112{
113 return !GetOption(name).empty();
114}
115
116#endif // wxUSE_SYSTEM_OPTIONS