]>
Commit | Line | Data |
---|---|---|
0cbff120 JS |
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 | |
65571936 | 9 | // Licence: wxWindows licence |
0cbff120 JS |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | // ============================================================================ | |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // --------------------------------------------------------------------------- | |
17 | // headers | |
18 | // --------------------------------------------------------------------------- | |
19 | ||
14f355c2 | 20 | #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) |
0cbff120 JS |
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" | |
df5168c4 | 40 | #include "wx/arrstr.h" |
0cbff120 JS |
41 | |
42 | // ---------------------------------------------------------------------------- | |
43 | // private classes | |
44 | // ---------------------------------------------------------------------------- | |
45 | ||
46 | // the module which is used to clean up wxSystemOptions data (this is a | |
47 | // singleton class so it can't be done in the dtor) | |
48 | class wxSystemOptionsModule : public wxModule | |
49 | { | |
bb24c68f | 50 | friend class WXDLLIMPEXP_BASE wxSystemOptions; |
0cbff120 JS |
51 | public: |
52 | virtual bool OnInit(); | |
53 | virtual void OnExit(); | |
54 | ||
55 | private: | |
56 | DECLARE_DYNAMIC_CLASS(wxSystemOptionsModule) | |
57 | ||
58 | static wxArrayString sm_optionNames; | |
59 | static wxArrayString sm_optionValues; | |
60 | }; | |
61 | ||
62 | // =========================================================================== | |
63 | // implementation | |
64 | // =========================================================================== | |
65 | ||
66 | // ---------------------------------------------------------------------------- | |
67 | // wxSystemOptionsModule | |
68 | // ---------------------------------------------------------------------------- | |
69 | ||
70 | IMPLEMENT_DYNAMIC_CLASS(wxSystemOptionsModule, wxModule) | |
71 | ||
72 | wxArrayString wxSystemOptionsModule::sm_optionNames; | |
73 | wxArrayString wxSystemOptionsModule::sm_optionValues; | |
74 | ||
75 | bool wxSystemOptionsModule::OnInit() | |
76 | { | |
77 | return TRUE; | |
78 | } | |
79 | ||
80 | void wxSystemOptionsModule::OnExit() | |
81 | { | |
82 | sm_optionNames.Clear(); | |
83 | sm_optionValues.Clear(); | |
84 | } | |
85 | ||
86 | // ---------------------------------------------------------------------------- | |
87 | // wxSystemOptions | |
88 | // ---------------------------------------------------------------------------- | |
89 | ||
90 | // Option functions (arbitrary name/value mapping) | |
91 | void wxSystemOptions::SetOption(const wxString& name, const wxString& value) | |
92 | { | |
93 | int idx = wxSystemOptionsModule::sm_optionNames.Index(name, FALSE); | |
94 | if (idx == wxNOT_FOUND) | |
95 | { | |
96 | wxSystemOptionsModule::sm_optionNames.Add(name); | |
97 | wxSystemOptionsModule::sm_optionValues.Add(value); | |
98 | } | |
99 | else | |
100 | { | |
101 | wxSystemOptionsModule::sm_optionNames[idx] = name; | |
102 | wxSystemOptionsModule::sm_optionValues[idx] = value; | |
103 | } | |
104 | } | |
105 | ||
106 | void wxSystemOptions::SetOption(const wxString& name, int value) | |
107 | { | |
108 | wxString valStr; | |
109 | valStr.Printf(wxT("%d"), value); | |
110 | SetOption(name, valStr); | |
111 | } | |
112 | ||
113 | wxString wxSystemOptions::GetOption(const wxString& name) | |
114 | { | |
115 | int idx = wxSystemOptionsModule::sm_optionNames.Index(name, FALSE); | |
116 | if (idx == wxNOT_FOUND) | |
117 | return wxEmptyString; | |
118 | else | |
119 | return wxSystemOptionsModule::sm_optionValues[idx]; | |
120 | } | |
121 | ||
122 | int wxSystemOptions::GetOptionInt(const wxString& name) | |
123 | { | |
124 | return wxAtoi(GetOption(name)); | |
125 | } | |
126 | ||
127 | bool wxSystemOptions::HasOption(const wxString& name) | |
128 | { | |
129 | return (wxSystemOptionsModule::sm_optionNames.Index(name, FALSE) != wxNOT_FOUND); | |
130 | } | |
131 | ||
132 | #endif | |
133 | // wxUSE_SYSTEM_OPTIONS | |
134 |