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"
43 #include "wx/fontutil.h"
45 // ----------------------------------------------------------------------------
47 // ----------------------------------------------------------------------------
49 // the module which is used to clean up wxSystemSettings data (this is a
50 // singleton class so it can't be done in the dtor)
51 class wxSystemSettingsModule
: public wxModule
53 friend class wxSystemSettings
;
55 virtual bool OnInit();
56 virtual void OnExit();
59 DECLARE_DYNAMIC_CLASS(wxSystemSettingsModule
)
61 static wxArrayString sm_optionNames
;
62 static wxArrayString sm_optionValues
;
65 // ----------------------------------------------------------------------------
67 // ----------------------------------------------------------------------------
69 static wxFont
*gs_fontDefault
= NULL
;
71 // ============================================================================
73 // ============================================================================
75 // ----------------------------------------------------------------------------
76 // wxSystemSettingsModule
77 // ----------------------------------------------------------------------------
79 IMPLEMENT_DYNAMIC_CLASS(wxSystemSettingsModule
, wxModule
)
81 wxArrayString
wxSystemSettingsModule::sm_optionNames
;
82 wxArrayString
wxSystemSettingsModule::sm_optionValues
;
84 bool wxSystemSettingsModule::OnInit()
89 void wxSystemSettingsModule::OnExit()
91 sm_optionNames
.Clear();
92 sm_optionValues
.Clear();
93 delete gs_fontDefault
;
96 // ----------------------------------------------------------------------------
98 // ----------------------------------------------------------------------------
100 // TODO: see ::SystemParametersInfo for all sorts of Windows settings.
101 // Different args are required depending on the id. How does this differ
102 // from GetSystemMetric, and should it? Perhaps call it GetSystemParameter
103 // and pass an optional void* arg to get further info.
104 // Should also have SetSystemParameter.
105 // Also implement WM_WININICHANGE (NT) / WM_SETTINGCHANGE (Win95)
107 wxColour
wxSystemSettings::GetSystemColour(int index
)
111 case wxSYS_COLOUR_LISTBOX
:
115 COLORREF ref
= ::GetSysColor(index
);
116 wxColour
col(GetRValue(ref
), GetGValue(ref
), GetBValue(ref
));
121 wxFont
wxCreateFontFromStockObject(int index
)
125 HFONT hFont
= (HFONT
) ::GetStockObject(index
);
129 if ( ::GetObject(hFont
, sizeof(LOGFONT
), &lf
) != 0 )
131 wxNativeFontInfo info
;
133 // Under MicroWindows we pass the HFONT as well
134 // because it's hard to convert HFONT -> LOGFONT -> HFONT
135 // It's OK to delete stock objects, the delete will be ignored.
136 #ifdef __WXMICROWIN__
137 font
.Create(info
, (WXHFONT
) hFont
);
144 wxFAIL_MSG( _T("failed to get LOGFONT") );
147 else // GetStockObject() failed
149 wxFAIL_MSG( _T("stock font not found") );
154 wxFont
wxSystemSettings::GetSystemFont(int index
)
156 // wxWindow ctor calls GetSystemFont(wxSYS_DEFAULT_GUI_FONT) so we're
157 // called fairly often - this is why we cache this particular font
158 bool isDefaultRequested
= index
== wxSYS_DEFAULT_GUI_FONT
;
159 if ( isDefaultRequested
&& gs_fontDefault
)
161 return *gs_fontDefault
;
164 wxFont font
= wxCreateFontFromStockObject(index
);
166 if ( isDefaultRequested
)
168 // if we got here it means we hadn't cached it yet - do now
169 gs_fontDefault
= new wxFont(font
);
175 // Get a system metric, e.g. scrollbar size
176 int wxSystemSettings::GetSystemMetric(int index
)
178 #ifdef __WXMICROWIN__
179 // TODO: probably use wxUniv themes functionality
185 case wxSYS_MOUSE_BUTTONS
:
186 return ::GetSystemMetrics(SM_CMOUSEBUTTONS
);
190 return ::GetSystemMetrics(SM_CXBORDER
);
192 return ::GetSystemMetrics(SM_CYBORDER
);
194 return ::GetSystemMetrics(SM_CXCURSOR
);
196 return ::GetSystemMetrics(SM_CYCURSOR
);
198 return ::GetSystemMetrics(SM_CXDOUBLECLK
);
200 return ::GetSystemMetrics(SM_CYDOUBLECLK
);
201 #if defined(__WIN32__) && defined(SM_CXDRAG)
203 return ::GetSystemMetrics(SM_CXDRAG
);
205 return ::GetSystemMetrics(SM_CYDRAG
);
207 return ::GetSystemMetrics(SM_CXEDGE
);
209 return ::GetSystemMetrics(SM_CYEDGE
);
211 case wxSYS_HSCROLL_ARROW_X
:
212 return ::GetSystemMetrics(SM_CXHSCROLL
);
213 case wxSYS_HSCROLL_ARROW_Y
:
214 return ::GetSystemMetrics(SM_CYHSCROLL
);
216 return ::GetSystemMetrics(SM_CXHTHUMB
);
218 return ::GetSystemMetrics(SM_CXICON
);
220 return ::GetSystemMetrics(SM_CYICON
);
221 case wxSYS_ICONSPACING_X
:
222 return ::GetSystemMetrics(SM_CXICONSPACING
);
223 case wxSYS_ICONSPACING_Y
:
224 return ::GetSystemMetrics(SM_CYICONSPACING
);
225 case wxSYS_WINDOWMIN_X
:
226 return ::GetSystemMetrics(SM_CXMIN
);
227 case wxSYS_WINDOWMIN_Y
:
228 return ::GetSystemMetrics(SM_CYMIN
);
230 return ::GetSystemMetrics(SM_CXSCREEN
);
232 return ::GetSystemMetrics(SM_CYSCREEN
);
234 #if defined(__WIN32__) && defined(SM_CXSIZEFRAME)
235 case wxSYS_FRAMESIZE_X
:
236 return ::GetSystemMetrics(SM_CXSIZEFRAME
);
237 case wxSYS_FRAMESIZE_Y
:
238 return ::GetSystemMetrics(SM_CYSIZEFRAME
);
239 case wxSYS_SMALLICON_X
:
240 return ::GetSystemMetrics(SM_CXSMICON
);
241 case wxSYS_SMALLICON_Y
:
242 return ::GetSystemMetrics(SM_CYSMICON
);
244 case wxSYS_HSCROLL_Y
:
245 return ::GetSystemMetrics(SM_CYHSCROLL
);
246 case wxSYS_VSCROLL_X
:
247 return ::GetSystemMetrics(SM_CXVSCROLL
);
248 case wxSYS_VSCROLL_ARROW_X
:
249 return ::GetSystemMetrics(SM_CXVSCROLL
);
250 case wxSYS_VSCROLL_ARROW_Y
:
251 return ::GetSystemMetrics(SM_CYVSCROLL
);
253 return ::GetSystemMetrics(SM_CYVTHUMB
);
254 case wxSYS_CAPTION_Y
:
255 return ::GetSystemMetrics(SM_CYCAPTION
);
257 return ::GetSystemMetrics(SM_CYMENU
);
258 #if defined(__WIN32__) && defined(SM_NETWORK)
259 case wxSYS_NETWORK_PRESENT
:
260 return ::GetSystemMetrics(SM_NETWORK
) & 0x0001;
262 case wxSYS_PENWINDOWS_PRESENT
:
263 return ::GetSystemMetrics(SM_PENWINDOWS
);
264 #if defined(__WIN32__) && defined(SM_SHOWSOUNDS)
265 case wxSYS_SHOW_SOUNDS
:
266 return ::GetSystemMetrics(SM_SHOWSOUNDS
);
268 case wxSYS_SWAP_BUTTONS
:
269 return ::GetSystemMetrics(SM_SWAPBUTTON
);
277 // Option functions (arbitrary name/value mapping)
278 void wxSystemSettings::SetOption(const wxString
& name
, const wxString
& value
)
280 int idx
= wxSystemSettingsModule::sm_optionNames
.Index(name
, FALSE
);
281 if (idx
== wxNOT_FOUND
)
283 wxSystemSettingsModule::sm_optionNames
.Add(name
);
284 wxSystemSettingsModule::sm_optionValues
.Add(value
);
288 wxSystemSettingsModule::sm_optionNames
[idx
] = name
;
289 wxSystemSettingsModule::sm_optionValues
[idx
] = value
;
293 void wxSystemSettings::SetOption(const wxString
& name
, int value
)
296 valStr
.Printf(wxT("%d"), value
);
297 SetOption(name
, valStr
);
300 wxString
wxSystemSettings::GetOption(const wxString
& name
)
302 int idx
= wxSystemSettingsModule::sm_optionNames
.Index(name
, FALSE
);
303 if (idx
== wxNOT_FOUND
)
304 return wxEmptyString
;
306 return wxSystemSettingsModule::sm_optionValues
[idx
];
309 int wxSystemSettings::GetOptionInt(const wxString
& name
)
311 return wxAtoi(GetOption(name
));
314 bool wxSystemSettings::HasOption(const wxString
& name
)
316 return (wxSystemSettingsModule::sm_optionNames
.Index(name
, FALSE
) != wxNOT_FOUND
);