]> git.saurik.com Git - wxWidgets.git/blob - src/common/sysopt.cpp
Further fixes to references
[wxWidgets.git] / src / common / sysopt.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: 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 #ifdef __GNUG__
21 #pragma implementation "sysopt.h"
22 #endif
23
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
26
27 #if defined(__BORLANDC__)
28 #pragma hdrstop
29 #endif
30
31 #ifndef WX_PRECOMP
32 #include "wx/list.h"
33 #endif
34
35 #if wxUSE_SYSTEM_OPTIONS
36
37 #include "wx/string.h"
38 #include "wx/sysopt.h"
39 #include "wx/module.h"
40
41 // ----------------------------------------------------------------------------
42 // private classes
43 // ----------------------------------------------------------------------------
44
45 // the module which is used to clean up wxSystemOptions data (this is a
46 // singleton class so it can't be done in the dtor)
47 class wxSystemOptionsModule : public wxModule
48 {
49 friend class wxSystemOptions;
50 public:
51 virtual bool OnInit();
52 virtual void OnExit();
53
54 private:
55 DECLARE_DYNAMIC_CLASS(wxSystemOptionsModule)
56
57 static wxArrayString sm_optionNames;
58 static wxArrayString sm_optionValues;
59 };
60
61 // ===========================================================================
62 // implementation
63 // ===========================================================================
64
65 // ----------------------------------------------------------------------------
66 // wxSystemOptionsModule
67 // ----------------------------------------------------------------------------
68
69 IMPLEMENT_DYNAMIC_CLASS(wxSystemOptionsModule, wxModule)
70
71 wxArrayString wxSystemOptionsModule::sm_optionNames;
72 wxArrayString wxSystemOptionsModule::sm_optionValues;
73
74 bool wxSystemOptionsModule::OnInit()
75 {
76 return TRUE;
77 }
78
79 void wxSystemOptionsModule::OnExit()
80 {
81 sm_optionNames.Clear();
82 sm_optionValues.Clear();
83 }
84
85 // ----------------------------------------------------------------------------
86 // wxSystemOptions
87 // ----------------------------------------------------------------------------
88
89 // Option functions (arbitrary name/value mapping)
90 void wxSystemOptions::SetOption(const wxString& name, const wxString& value)
91 {
92 int idx = wxSystemOptionsModule::sm_optionNames.Index(name, FALSE);
93 if (idx == wxNOT_FOUND)
94 {
95 wxSystemOptionsModule::sm_optionNames.Add(name);
96 wxSystemOptionsModule::sm_optionValues.Add(value);
97 }
98 else
99 {
100 wxSystemOptionsModule::sm_optionNames[idx] = name;
101 wxSystemOptionsModule::sm_optionValues[idx] = value;
102 }
103 }
104
105 void wxSystemOptions::SetOption(const wxString& name, int value)
106 {
107 wxString valStr;
108 valStr.Printf(wxT("%d"), value);
109 SetOption(name, valStr);
110 }
111
112 wxString wxSystemOptions::GetOption(const wxString& name)
113 {
114 int idx = wxSystemOptionsModule::sm_optionNames.Index(name, FALSE);
115 if (idx == wxNOT_FOUND)
116 return wxEmptyString;
117 else
118 return wxSystemOptionsModule::sm_optionValues[idx];
119 }
120
121 int wxSystemOptions::GetOptionInt(const wxString& name)
122 {
123 return wxAtoi(GetOption(name));
124 }
125
126 bool wxSystemOptions::HasOption(const wxString& name)
127 {
128 return (wxSystemOptionsModule::sm_optionNames.Index(name, FALSE) != wxNOT_FOUND);
129 }
130
131 #endif
132 // wxUSE_SYSTEM_OPTIONS
133