1 /////////////////////////////////////////////////////////////////////////////
2 // Name: msw/settings.cpp
3 // Purpose: wxSystemSettings
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
21 #pragma implementation "settings.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
36 #include "wx/gdicmn.h"
39 #include "wx/settings.h"
40 #include "wx/window.h"
41 #include "wx/msw/private.h"
42 #include "wx/module.h"
44 // ----------------------------------------------------------------------------
46 // ----------------------------------------------------------------------------
48 // the module which is used to clean up wxSystemSettings data (this is a
49 // singleton class so it can't be done in the dtor)
50 class wxSystemSettingsModule
: public wxModule
52 friend class wxSystemSettings
;
54 virtual bool OnInit();
55 virtual void OnExit();
58 DECLARE_DYNAMIC_CLASS(wxSystemSettingsModule
)
60 static wxArrayString sm_optionNames
;
61 static wxArrayString sm_optionValues
;
64 // ----------------------------------------------------------------------------
66 // ----------------------------------------------------------------------------
68 static wxFont
*gs_fontDefault
= NULL
;
70 // ============================================================================
72 // ============================================================================
74 // ----------------------------------------------------------------------------
75 // wxSystemSettingsModule
76 // ----------------------------------------------------------------------------
78 IMPLEMENT_DYNAMIC_CLASS(wxSystemSettingsModule
, wxModule
)
80 wxArrayString
wxSystemSettingsModule::sm_optionNames
;
81 wxArrayString
wxSystemSettingsModule::sm_optionValues
;
83 bool wxSystemSettingsModule::OnInit()
88 void wxSystemSettingsModule::OnExit()
90 sm_optionNames
.Clear();
91 sm_optionValues
.Clear();
92 delete gs_fontDefault
;
95 // ----------------------------------------------------------------------------
97 // ----------------------------------------------------------------------------
99 // TODO: see ::SystemParametersInfo for all sorts of Windows settings.
100 // Different args are required depending on the id. How does this differ
101 // from GetSystemMetric, and should it? Perhaps call it GetSystemParameter
102 // and pass an optional void* arg to get further info.
103 // Should also have SetSystemParameter.
104 // Also implement WM_WININICHANGE (NT) / WM_SETTINGCHANGE (Win95)
106 wxColour
wxSystemSettings::GetSystemColour(int index
)
110 case wxSYS_COLOUR_LISTBOX
:
114 COLORREF ref
= ::GetSysColor(index
);
115 wxColour
col(GetRValue(ref
), GetGValue(ref
), GetBValue(ref
));
120 wxFont
wxSystemSettings::GetSystemFont(int index
)
122 // wxWindow ctor calls GetSystemFont(wxSYS_DEFAULT_GUI_FONT) so we're
123 // called fairly often - this is why we cache this particular font
124 bool isDefaultRequested
= index
== wxSYS_DEFAULT_GUI_FONT
;
125 if ( isDefaultRequested
&& gs_fontDefault
)
127 return *gs_fontDefault
;
132 HFONT hFont
= (HFONT
) ::GetStockObject(index
);
136 if ( ::GetObject(hFont
, sizeof(LOGFONT
), &lf
) != 0 )
138 font
= wxCreateFontFromLogFont(&lf
);
142 wxFAIL_MSG( _T("failed to get LOGFONT") );
145 else // GetStockObject() failed
147 wxFAIL_MSG( _T("stock font not found") );
150 if ( isDefaultRequested
)
152 // if we got here it means we hadn't cached it yet - do now
153 gs_fontDefault
= new wxFont(font
);
159 // Get a system metric, e.g. scrollbar size
160 int wxSystemSettings::GetSystemMetric(int index
)
165 case wxSYS_MOUSE_BUTTONS
:
166 return ::GetSystemMetrics(SM_CMOUSEBUTTONS
);
170 return ::GetSystemMetrics(SM_CXBORDER
);
172 return ::GetSystemMetrics(SM_CYBORDER
);
174 return ::GetSystemMetrics(SM_CXCURSOR
);
176 return ::GetSystemMetrics(SM_CYCURSOR
);
178 return ::GetSystemMetrics(SM_CXDOUBLECLK
);
180 return ::GetSystemMetrics(SM_CYDOUBLECLK
);
181 #if defined(__WIN32__) && defined(SM_CXDRAG)
183 return ::GetSystemMetrics(SM_CXDRAG
);
185 return ::GetSystemMetrics(SM_CYDRAG
);
187 return ::GetSystemMetrics(SM_CXEDGE
);
189 return ::GetSystemMetrics(SM_CYEDGE
);
191 case wxSYS_HSCROLL_ARROW_X
:
192 return ::GetSystemMetrics(SM_CXHSCROLL
);
193 case wxSYS_HSCROLL_ARROW_Y
:
194 return ::GetSystemMetrics(SM_CYHSCROLL
);
196 return ::GetSystemMetrics(SM_CXHTHUMB
);
198 return ::GetSystemMetrics(SM_CXICON
);
200 return ::GetSystemMetrics(SM_CYICON
);
201 case wxSYS_ICONSPACING_X
:
202 return ::GetSystemMetrics(SM_CXICONSPACING
);
203 case wxSYS_ICONSPACING_Y
:
204 return ::GetSystemMetrics(SM_CYICONSPACING
);
205 case wxSYS_WINDOWMIN_X
:
206 return ::GetSystemMetrics(SM_CXMIN
);
207 case wxSYS_WINDOWMIN_Y
:
208 return ::GetSystemMetrics(SM_CYMIN
);
210 return ::GetSystemMetrics(SM_CXSCREEN
);
212 return ::GetSystemMetrics(SM_CYSCREEN
);
214 #if defined(__WIN32__) && defined(SM_CXSIZEFRAME)
215 case wxSYS_FRAMESIZE_X
:
216 return ::GetSystemMetrics(SM_CXSIZEFRAME
);
217 case wxSYS_FRAMESIZE_Y
:
218 return ::GetSystemMetrics(SM_CYSIZEFRAME
);
219 case wxSYS_SMALLICON_X
:
220 return ::GetSystemMetrics(SM_CXSMICON
);
221 case wxSYS_SMALLICON_Y
:
222 return ::GetSystemMetrics(SM_CYSMICON
);
224 case wxSYS_HSCROLL_Y
:
225 return ::GetSystemMetrics(SM_CYHSCROLL
);
226 case wxSYS_VSCROLL_X
:
227 return ::GetSystemMetrics(SM_CXVSCROLL
);
228 case wxSYS_VSCROLL_ARROW_X
:
229 return ::GetSystemMetrics(SM_CXVSCROLL
);
230 case wxSYS_VSCROLL_ARROW_Y
:
231 return ::GetSystemMetrics(SM_CYVSCROLL
);
233 return ::GetSystemMetrics(SM_CYVTHUMB
);
234 case wxSYS_CAPTION_Y
:
235 return ::GetSystemMetrics(SM_CYCAPTION
);
237 return ::GetSystemMetrics(SM_CYMENU
);
238 #if defined(__WIN32__) && defined(SM_NETWORK)
239 case wxSYS_NETWORK_PRESENT
:
240 return ::GetSystemMetrics(SM_NETWORK
) & 0x0001;
242 case wxSYS_PENWINDOWS_PRESENT
:
243 return ::GetSystemMetrics(SM_PENWINDOWS
);
244 #if defined(__WIN32__) && defined(SM_SHOWSOUNDS)
245 case wxSYS_SHOW_SOUNDS
:
246 return ::GetSystemMetrics(SM_SHOWSOUNDS
);
248 case wxSYS_SWAP_BUTTONS
:
249 return ::GetSystemMetrics(SM_SWAPBUTTON
);
255 // Option functions (arbitrary name/value mapping)
256 void wxSystemSettings::SetOption(const wxString
& name
, const wxString
& value
)
258 int idx
= wxSystemSettingsModule::sm_optionNames
.Index(name
, FALSE
);
259 if (idx
== wxNOT_FOUND
)
261 wxSystemSettingsModule::sm_optionNames
.Add(name
);
262 wxSystemSettingsModule::sm_optionValues
.Add(value
);
266 wxSystemSettingsModule::sm_optionNames
[idx
] = name
;
267 wxSystemSettingsModule::sm_optionValues
[idx
] = value
;
271 void wxSystemSettings::SetOption(const wxString
& name
, int value
)
274 valStr
.Printf(wxT("%d"), value
);
275 SetOption(name
, valStr
);
278 wxString
wxSystemSettings::GetOption(const wxString
& name
)
280 int idx
= wxSystemSettingsModule::sm_optionNames
.Index(name
, FALSE
);
281 if (idx
== wxNOT_FOUND
)
282 return wxEmptyString
;
284 return wxSystemSettingsModule::sm_optionValues
[idx
];
287 int wxSystemSettings::GetOptionInt(const wxString
& name
)
289 return wxAtoi(GetOption(name
));
292 bool wxSystemSettings::HasOption(const wxString
& name
)
294 return (wxSystemSettingsModule::sm_optionNames
.Index(name
, FALSE
) != wxNOT_FOUND
);