]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/msw/settings.cpp
Corrections to config checking; tweaking wxUniv's setup.h; added fix to makeb32.env
[wxWidgets.git] / src / msw / settings.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: msw/settings.cpp
3// Purpose: wxSystemSettings
4// Author: Julian Smart
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart and Markus Holzem
9// Licence: wxWindows license
10/////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
20#ifdef __GNUG__
21 #pragma implementation "settings.h"
22#endif
23
24// For compilers that support precompilation, includes "wx.h".
25#include "wx/wxprec.h"
26
27#ifdef __BORLANDC__
28#pragma hdrstop
29#endif
30
31#ifndef WX_PRECOMP
32 #include <stdio.h>
33 #include "wx/defs.h"
34 #include "wx/pen.h"
35 #include "wx/brush.h"
36 #include "wx/gdicmn.h"
37#endif
38
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"
44
45// ----------------------------------------------------------------------------
46// private classes
47// ----------------------------------------------------------------------------
48
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)
51class wxSystemSettingsModule : public wxModule
52{
53 friend class wxSystemSettings;
54public:
55 virtual bool OnInit();
56 virtual void OnExit();
57
58private:
59 DECLARE_DYNAMIC_CLASS(wxSystemSettingsModule)
60
61 static wxArrayString sm_optionNames;
62 static wxArrayString sm_optionValues;
63};
64
65// ----------------------------------------------------------------------------
66// global data
67// ----------------------------------------------------------------------------
68
69static wxFont *gs_fontDefault = NULL;
70
71// ============================================================================
72// implementation
73// ============================================================================
74
75// ----------------------------------------------------------------------------
76// wxSystemSettingsModule
77// ----------------------------------------------------------------------------
78
79IMPLEMENT_DYNAMIC_CLASS(wxSystemSettingsModule, wxModule)
80
81wxArrayString wxSystemSettingsModule::sm_optionNames;
82wxArrayString wxSystemSettingsModule::sm_optionValues;
83
84bool wxSystemSettingsModule::OnInit()
85{
86 return TRUE;
87}
88
89void wxSystemSettingsModule::OnExit()
90{
91 sm_optionNames.Clear();
92 sm_optionValues.Clear();
93 delete gs_fontDefault;
94}
95
96// ----------------------------------------------------------------------------
97// wxSystemSettings
98// ----------------------------------------------------------------------------
99
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)
106
107wxColour wxSystemSettings::GetSystemColour(int index)
108{
109 switch (index)
110 {
111 case wxSYS_COLOUR_LISTBOX:
112 return *wxWHITE;
113
114 default:
115 COLORREF ref = ::GetSysColor(index);
116 wxColour col(GetRValue(ref), GetGValue(ref), GetBValue(ref));
117 return col;
118 }
119}
120
121wxFont wxCreateFontFromStockObject(int index)
122{
123 wxFont font;
124
125 HFONT hFont = (HFONT) ::GetStockObject(index);
126 if ( hFont )
127 {
128 LOGFONT lf;
129 if ( ::GetObject(hFont, sizeof(LOGFONT), &lf) != 0 )
130 {
131 wxNativeFontInfo info;
132 info.lf = lf;
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);
138#else
139 font.Create(info);
140#endif
141 }
142 else
143 {
144 wxFAIL_MSG( _T("failed to get LOGFONT") );
145 }
146 }
147 else // GetStockObject() failed
148 {
149 wxFAIL_MSG( _T("stock font not found") );
150 }
151 return font;
152}
153
154wxFont wxSystemSettings::GetSystemFont(int index)
155{
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 )
160 {
161 return *gs_fontDefault;
162 }
163
164 wxFont font = wxCreateFontFromStockObject(index);
165
166 if ( isDefaultRequested )
167 {
168 // if we got here it means we hadn't cached it yet - do now
169 gs_fontDefault = new wxFont(font);
170 }
171
172 return font;
173}
174
175// Get a system metric, e.g. scrollbar size
176int wxSystemSettings::GetSystemMetric(int index)
177{
178#ifdef __WXMICROWIN__
179 // TODO: probably use wxUniv themes functionality
180 return 0;
181#else
182 switch ( index)
183 {
184#ifdef __WIN32__
185 case wxSYS_MOUSE_BUTTONS:
186 return ::GetSystemMetrics(SM_CMOUSEBUTTONS);
187#endif
188
189 case wxSYS_BORDER_X:
190 return ::GetSystemMetrics(SM_CXBORDER);
191 case wxSYS_BORDER_Y:
192 return ::GetSystemMetrics(SM_CYBORDER);
193 case wxSYS_CURSOR_X:
194 return ::GetSystemMetrics(SM_CXCURSOR);
195 case wxSYS_CURSOR_Y:
196 return ::GetSystemMetrics(SM_CYCURSOR);
197 case wxSYS_DCLICK_X:
198 return ::GetSystemMetrics(SM_CXDOUBLECLK);
199 case wxSYS_DCLICK_Y:
200 return ::GetSystemMetrics(SM_CYDOUBLECLK);
201#if defined(__WIN32__) && defined(SM_CXDRAG)
202 case wxSYS_DRAG_X:
203 return ::GetSystemMetrics(SM_CXDRAG);
204 case wxSYS_DRAG_Y:
205 return ::GetSystemMetrics(SM_CYDRAG);
206 case wxSYS_EDGE_X:
207 return ::GetSystemMetrics(SM_CXEDGE);
208 case wxSYS_EDGE_Y:
209 return ::GetSystemMetrics(SM_CYEDGE);
210#endif
211 case wxSYS_HSCROLL_ARROW_X:
212 return ::GetSystemMetrics(SM_CXHSCROLL);
213 case wxSYS_HSCROLL_ARROW_Y:
214 return ::GetSystemMetrics(SM_CYHSCROLL);
215 case wxSYS_HTHUMB_X:
216 return ::GetSystemMetrics(SM_CXHTHUMB);
217 case wxSYS_ICON_X:
218 return ::GetSystemMetrics(SM_CXICON);
219 case wxSYS_ICON_Y:
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);
229 case wxSYS_SCREEN_X:
230 return ::GetSystemMetrics(SM_CXSCREEN);
231 case wxSYS_SCREEN_Y:
232 return ::GetSystemMetrics(SM_CYSCREEN);
233
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);
243#endif
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);
252 case wxSYS_VTHUMB_Y:
253 return ::GetSystemMetrics(SM_CYVTHUMB);
254 case wxSYS_CAPTION_Y:
255 return ::GetSystemMetrics(SM_CYCAPTION);
256 case wxSYS_MENU_Y:
257 return ::GetSystemMetrics(SM_CYMENU);
258#if defined(__WIN32__) && defined(SM_NETWORK)
259 case wxSYS_NETWORK_PRESENT:
260 return ::GetSystemMetrics(SM_NETWORK) & 0x0001;
261#endif
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);
267#endif
268 case wxSYS_SWAP_BUTTONS:
269 return ::GetSystemMetrics(SM_SWAPBUTTON);
270 default:
271 return 0;
272 }
273#endif
274 // __WXMICROWIN__
275}
276
277// Option functions (arbitrary name/value mapping)
278void wxSystemSettings::SetOption(const wxString& name, const wxString& value)
279{
280 int idx = wxSystemSettingsModule::sm_optionNames.Index(name, FALSE);
281 if (idx == wxNOT_FOUND)
282 {
283 wxSystemSettingsModule::sm_optionNames.Add(name);
284 wxSystemSettingsModule::sm_optionValues.Add(value);
285 }
286 else
287 {
288 wxSystemSettingsModule::sm_optionNames[idx] = name;
289 wxSystemSettingsModule::sm_optionValues[idx] = value;
290 }
291}
292
293void wxSystemSettings::SetOption(const wxString& name, int value)
294{
295 wxString valStr;
296 valStr.Printf(wxT("%d"), value);
297 SetOption(name, valStr);
298}
299
300wxString wxSystemSettings::GetOption(const wxString& name)
301{
302 int idx = wxSystemSettingsModule::sm_optionNames.Index(name, FALSE);
303 if (idx == wxNOT_FOUND)
304 return wxEmptyString;
305 else
306 return wxSystemSettingsModule::sm_optionValues[idx];
307}
308
309int wxSystemSettings::GetOptionInt(const wxString& name)
310{
311 return wxAtoi(GetOption(name));
312}
313
314bool wxSystemSettings::HasOption(const wxString& name)
315{
316 return (wxSystemSettingsModule::sm_optionNames.Index(name, FALSE) != wxNOT_FOUND);
317}
318