]> git.saurik.com Git - wxWidgets.git/blob - src/msw/settings.cpp
compilation fixes - wxGTK compiles but not links
[wxWidgets.git] / src / msw / settings.cpp
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
44 // ----------------------------------------------------------------------------
45 // private classes
46 // ----------------------------------------------------------------------------
47
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
51 {
52 friend class wxSystemSettings;
53 public:
54 virtual bool OnInit();
55 virtual void OnExit();
56
57 private:
58 DECLARE_DYNAMIC_CLASS(wxSystemSettingsModule)
59
60 static wxArrayString sm_optionNames;
61 static wxArrayString sm_optionValues;
62 };
63
64 // ----------------------------------------------------------------------------
65 // global data
66 // ----------------------------------------------------------------------------
67
68 static wxFont *gs_fontDefault = NULL;
69
70 // ============================================================================
71 // implementation
72 // ============================================================================
73
74 // ----------------------------------------------------------------------------
75 // wxSystemSettingsModule
76 // ----------------------------------------------------------------------------
77
78 IMPLEMENT_DYNAMIC_CLASS(wxSystemSettingsModule, wxModule)
79
80 wxArrayString wxSystemSettingsModule::sm_optionNames;
81 wxArrayString wxSystemSettingsModule::sm_optionValues;
82
83 bool wxSystemSettingsModule::OnInit()
84 {
85 return TRUE;
86 }
87
88 void wxSystemSettingsModule::OnExit()
89 {
90 sm_optionNames.Clear();
91 sm_optionValues.Clear();
92 delete gs_fontDefault;
93 }
94
95 // ----------------------------------------------------------------------------
96 // wxSystemSettings
97 // ----------------------------------------------------------------------------
98
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)
105
106 wxColour wxSystemSettings::GetSystemColour(int index)
107 {
108 switch (index)
109 {
110 case wxSYS_COLOUR_LISTBOX:
111 return *wxWHITE;
112
113 default:
114 COLORREF ref = ::GetSysColor(index);
115 wxColour col(GetRValue(ref), GetGValue(ref), GetBValue(ref));
116 return col;
117 }
118 }
119
120 wxFont wxSystemSettings::GetSystemFont(int index)
121 {
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 )
126 {
127 return *gs_fontDefault;
128 }
129
130 wxFont font;
131
132 HFONT hFont = (HFONT) ::GetStockObject(index);
133 if ( hFont )
134 {
135 LOGFONT lf;
136 if ( ::GetObject(hFont, sizeof(LOGFONT), &lf) != 0 )
137 {
138 font = wxCreateFontFromLogFont(&lf);
139 }
140 else
141 {
142 wxFAIL_MSG( _T("failed to get LOGFONT") );
143 }
144 }
145 else // GetStockObject() failed
146 {
147 wxFAIL_MSG( _T("stock font not found") );
148 }
149
150 if ( isDefaultRequested )
151 {
152 // if we got here it means we hadn't cached it yet - do now
153 gs_fontDefault = new wxFont(font);
154 }
155
156 return font;
157 }
158
159 // Get a system metric, e.g. scrollbar size
160 int wxSystemSettings::GetSystemMetric(int index)
161 {
162 switch ( index)
163 {
164 #ifdef __WIN32__
165 case wxSYS_MOUSE_BUTTONS:
166 return ::GetSystemMetrics(SM_CMOUSEBUTTONS);
167 #endif
168
169 case wxSYS_BORDER_X:
170 return ::GetSystemMetrics(SM_CXBORDER);
171 case wxSYS_BORDER_Y:
172 return ::GetSystemMetrics(SM_CYBORDER);
173 case wxSYS_CURSOR_X:
174 return ::GetSystemMetrics(SM_CXCURSOR);
175 case wxSYS_CURSOR_Y:
176 return ::GetSystemMetrics(SM_CYCURSOR);
177 case wxSYS_DCLICK_X:
178 return ::GetSystemMetrics(SM_CXDOUBLECLK);
179 case wxSYS_DCLICK_Y:
180 return ::GetSystemMetrics(SM_CYDOUBLECLK);
181 #if defined(__WIN32__) && defined(SM_CXDRAG)
182 case wxSYS_DRAG_X:
183 return ::GetSystemMetrics(SM_CXDRAG);
184 case wxSYS_DRAG_Y:
185 return ::GetSystemMetrics(SM_CYDRAG);
186 case wxSYS_EDGE_X:
187 return ::GetSystemMetrics(SM_CXEDGE);
188 case wxSYS_EDGE_Y:
189 return ::GetSystemMetrics(SM_CYEDGE);
190 #endif
191 case wxSYS_HSCROLL_ARROW_X:
192 return ::GetSystemMetrics(SM_CXHSCROLL);
193 case wxSYS_HSCROLL_ARROW_Y:
194 return ::GetSystemMetrics(SM_CYHSCROLL);
195 case wxSYS_HTHUMB_X:
196 return ::GetSystemMetrics(SM_CXHTHUMB);
197 case wxSYS_ICON_X:
198 return ::GetSystemMetrics(SM_CXICON);
199 case wxSYS_ICON_Y:
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);
209 case wxSYS_SCREEN_X:
210 return ::GetSystemMetrics(SM_CXSCREEN);
211 case wxSYS_SCREEN_Y:
212 return ::GetSystemMetrics(SM_CYSCREEN);
213
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);
223 #endif
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);
232 case wxSYS_VTHUMB_Y:
233 return ::GetSystemMetrics(SM_CYVTHUMB);
234 case wxSYS_CAPTION_Y:
235 return ::GetSystemMetrics(SM_CYCAPTION);
236 case wxSYS_MENU_Y:
237 return ::GetSystemMetrics(SM_CYMENU);
238 #if defined(__WIN32__) && defined(SM_NETWORK)
239 case wxSYS_NETWORK_PRESENT:
240 return ::GetSystemMetrics(SM_NETWORK) & 0x0001;
241 #endif
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);
247 #endif
248 case wxSYS_SWAP_BUTTONS:
249 return ::GetSystemMetrics(SM_SWAPBUTTON);
250 default:
251 return 0;
252 }
253 }
254
255 // Option functions (arbitrary name/value mapping)
256 void wxSystemSettings::SetOption(const wxString& name, const wxString& value)
257 {
258 int idx = wxSystemSettingsModule::sm_optionNames.Index(name, FALSE);
259 if (idx == wxNOT_FOUND)
260 {
261 wxSystemSettingsModule::sm_optionNames.Add(name);
262 wxSystemSettingsModule::sm_optionValues.Add(value);
263 }
264 else
265 {
266 wxSystemSettingsModule::sm_optionNames[idx] = name;
267 wxSystemSettingsModule::sm_optionValues[idx] = value;
268 }
269 }
270
271 void wxSystemSettings::SetOption(const wxString& name, int value)
272 {
273 wxString valStr;
274 valStr.Printf(wxT("%d"), value);
275 SetOption(name, valStr);
276 }
277
278 wxString wxSystemSettings::GetOption(const wxString& name)
279 {
280 int idx = wxSystemSettingsModule::sm_optionNames.Index(name, FALSE);
281 if (idx == wxNOT_FOUND)
282 return wxEmptyString;
283 else
284 return wxSystemSettingsModule::sm_optionValues[idx];
285 }
286
287 int wxSystemSettings::GetOptionInt(const wxString& name)
288 {
289 return wxAtoi(GetOption(name));
290 }
291
292 bool wxSystemSettings::HasOption(const wxString& name)
293 {
294 return (wxSystemSettingsModule::sm_optionNames.Index(name, FALSE) != wxNOT_FOUND);
295 }
296