1 /////////////////////////////////////////////////////////////////////////////
2 // Name: common/sysopt.cpp
3 // Purpose: wxSystemOptions
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ---------------------------------------------------------------------------
18 // ---------------------------------------------------------------------------
20 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
21 #pragma implementation "sysopt.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
27 #if defined(__BORLANDC__)
35 #if wxUSE_SYSTEM_OPTIONS
37 #include "wx/string.h"
38 #include "wx/sysopt.h"
39 #include "wx/module.h"
40 #include "wx/arrstr.h"
42 // ----------------------------------------------------------------------------
44 // ----------------------------------------------------------------------------
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
50 friend class WXDLLIMPEXP_BASE wxSystemOptions
;
52 virtual bool OnInit();
53 virtual void OnExit();
56 DECLARE_DYNAMIC_CLASS(wxSystemOptionsModule
)
58 static wxArrayString sm_optionNames
;
59 static wxArrayString sm_optionValues
;
62 // ===========================================================================
64 // ===========================================================================
66 // ----------------------------------------------------------------------------
67 // wxSystemOptionsModule
68 // ----------------------------------------------------------------------------
70 IMPLEMENT_DYNAMIC_CLASS(wxSystemOptionsModule
, wxModule
)
72 wxArrayString
wxSystemOptionsModule::sm_optionNames
;
73 wxArrayString
wxSystemOptionsModule::sm_optionValues
;
75 bool wxSystemOptionsModule::OnInit()
80 void wxSystemOptionsModule::OnExit()
82 sm_optionNames
.Clear();
83 sm_optionValues
.Clear();
86 // ----------------------------------------------------------------------------
88 // ----------------------------------------------------------------------------
90 // Option functions (arbitrary name/value mapping)
91 void wxSystemOptions::SetOption(const wxString
& name
, const wxString
& value
)
93 int idx
= wxSystemOptionsModule::sm_optionNames
.Index(name
, FALSE
);
94 if (idx
== wxNOT_FOUND
)
96 wxSystemOptionsModule::sm_optionNames
.Add(name
);
97 wxSystemOptionsModule::sm_optionValues
.Add(value
);
101 wxSystemOptionsModule::sm_optionNames
[idx
] = name
;
102 wxSystemOptionsModule::sm_optionValues
[idx
] = value
;
106 void wxSystemOptions::SetOption(const wxString
& name
, int value
)
109 valStr
.Printf(wxT("%d"), value
);
110 SetOption(name
, valStr
);
113 wxString
wxSystemOptions::GetOption(const wxString
& name
)
115 int idx
= wxSystemOptionsModule::sm_optionNames
.Index(name
, FALSE
);
116 if (idx
== wxNOT_FOUND
)
117 return wxEmptyString
;
119 return wxSystemOptionsModule::sm_optionValues
[idx
];
122 int wxSystemOptions::GetOptionInt(const wxString
& name
)
124 return wxAtoi(GetOption(name
));
127 bool wxSystemOptions::HasOption(const wxString
& name
)
129 return (wxSystemOptionsModule::sm_optionNames
.Index(name
, FALSE
) != wxNOT_FOUND
);
133 // wxUSE_SYSTEM_OPTIONS