]>
Commit | Line | Data |
---|---|---|
2bda0e17 | 1 | ///////////////////////////////////////////////////////////////////////////// |
8bf30fe9 VZ |
2 | // Name: msw/settings.cpp |
3 | // Purpose: wxSystemSettings | |
2bda0e17 KB |
4 | // Author: Julian Smart |
5 | // Modified by: | |
6 | // Created: 04/01/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart and Markus Holzem | |
019a60d6 | 9 | // Licence: wxWindows license |
2bda0e17 KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
8bf30fe9 VZ |
12 | // ============================================================================ |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
2bda0e17 | 20 | #ifdef __GNUG__ |
8bf30fe9 | 21 | #pragma implementation "settings.h" |
2bda0e17 KB |
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 | |
8bf30fe9 VZ |
32 | #include <stdio.h> |
33 | #include "wx/defs.h" | |
34 | #include "wx/pen.h" | |
35 | #include "wx/brush.h" | |
36 | #include "wx/gdicmn.h" | |
2bda0e17 KB |
37 | #endif |
38 | ||
39 | #include "wx/settings.h" | |
40 | #include "wx/window.h" | |
41 | #include "wx/msw/private.h" | |
2e6d38ad | 42 | #include "wx/module.h" |
04ef50df | 43 | #include "wx/fontutil.h" |
2bda0e17 | 44 | |
8bf30fe9 VZ |
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) | |
51 | class wxSystemSettingsModule : public wxModule | |
52 | { | |
d3211838 | 53 | friend class wxSystemSettings; |
8bf30fe9 VZ |
54 | public: |
55 | virtual bool OnInit(); | |
56 | virtual void OnExit(); | |
57 | ||
58 | private: | |
59 | DECLARE_DYNAMIC_CLASS(wxSystemSettingsModule) | |
d3211838 JS |
60 | |
61 | static wxArrayString sm_optionNames; | |
62 | static wxArrayString sm_optionValues; | |
8bf30fe9 VZ |
63 | }; |
64 | ||
65 | // ---------------------------------------------------------------------------- | |
66 | // global data | |
67 | // ---------------------------------------------------------------------------- | |
68 | ||
69 | static wxFont *gs_fontDefault = NULL; | |
70 | ||
71 | // ============================================================================ | |
72 | // implementation | |
73 | // ============================================================================ | |
74 | ||
75 | // ---------------------------------------------------------------------------- | |
76 | // wxSystemSettingsModule | |
77 | // ---------------------------------------------------------------------------- | |
78 | ||
79 | IMPLEMENT_DYNAMIC_CLASS(wxSystemSettingsModule, wxModule) | |
80 | ||
d3211838 JS |
81 | wxArrayString wxSystemSettingsModule::sm_optionNames; |
82 | wxArrayString wxSystemSettingsModule::sm_optionValues; | |
83 | ||
8bf30fe9 VZ |
84 | bool wxSystemSettingsModule::OnInit() |
85 | { | |
86 | return TRUE; | |
87 | } | |
88 | ||
89 | void wxSystemSettingsModule::OnExit() | |
90 | { | |
d3211838 JS |
91 | sm_optionNames.Clear(); |
92 | sm_optionValues.Clear(); | |
8bf30fe9 VZ |
93 | delete gs_fontDefault; |
94 | } | |
95 | ||
96 | // ---------------------------------------------------------------------------- | |
97 | // wxSystemSettings | |
98 | // ---------------------------------------------------------------------------- | |
99 | ||
2bda0e17 KB |
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 | ||
107 | wxColour wxSystemSettings::GetSystemColour(int index) | |
108 | { | |
019a60d6 VS |
109 | switch (index) |
110 | { | |
111 | case wxSYS_COLOUR_LISTBOX: | |
112 | return *wxWHITE; | |
8bf30fe9 | 113 | |
019a60d6 VS |
114 | default: |
115 | COLORREF ref = ::GetSysColor(index); | |
116 | wxColour col(GetRValue(ref), GetGValue(ref), GetBValue(ref)); | |
117 | return col; | |
019a60d6 | 118 | } |
2bda0e17 KB |
119 | } |
120 | ||
04ef50df | 121 | wxFont wxCreateFontFromStockObject(int index) |
2bda0e17 | 122 | { |
8bf30fe9 VZ |
123 | wxFont font; |
124 | ||
019a60d6 | 125 | HFONT hFont = (HFONT) ::GetStockObject(index); |
8bf30fe9 | 126 | if ( hFont ) |
019a60d6 VS |
127 | { |
128 | LOGFONT lf; | |
129 | if ( ::GetObject(hFont, sizeof(LOGFONT), &lf) != 0 ) | |
130 | { | |
04ef50df JS |
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 | |
019a60d6 VS |
141 | } |
142 | else | |
143 | { | |
8bf30fe9 | 144 | wxFAIL_MSG( _T("failed to get LOGFONT") ); |
019a60d6 VS |
145 | } |
146 | } | |
8bf30fe9 VZ |
147 | else // GetStockObject() failed |
148 | { | |
149 | wxFAIL_MSG( _T("stock font not found") ); | |
150 | } | |
04ef50df JS |
151 | return font; |
152 | } | |
153 | ||
154 | wxFont 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); | |
8bf30fe9 VZ |
165 | |
166 | if ( isDefaultRequested ) | |
019a60d6 | 167 | { |
8bf30fe9 VZ |
168 | // if we got here it means we hadn't cached it yet - do now |
169 | gs_fontDefault = new wxFont(font); | |
019a60d6 | 170 | } |
8bf30fe9 VZ |
171 | |
172 | return font; | |
2bda0e17 KB |
173 | } |
174 | ||
175 | // Get a system metric, e.g. scrollbar size | |
176 | int wxSystemSettings::GetSystemMetric(int index) | |
177 | { | |
04ef50df JS |
178 | #ifdef __WXMICROWIN__ |
179 | // TODO: probably use wxUniv themes functionality | |
180 | return 0; | |
181 | #else | |
019a60d6 VS |
182 | switch ( index) |
183 | { | |
2bda0e17 KB |
184 | #ifdef __WIN32__ |
185 | case wxSYS_MOUSE_BUTTONS: | |
019a60d6 | 186 | return ::GetSystemMetrics(SM_CMOUSEBUTTONS); |
2bda0e17 KB |
187 | #endif |
188 | ||
189 | case wxSYS_BORDER_X: | |
019a60d6 | 190 | return ::GetSystemMetrics(SM_CXBORDER); |
2bda0e17 | 191 | case wxSYS_BORDER_Y: |
019a60d6 | 192 | return ::GetSystemMetrics(SM_CYBORDER); |
2bda0e17 | 193 | case wxSYS_CURSOR_X: |
019a60d6 | 194 | return ::GetSystemMetrics(SM_CXCURSOR); |
2bda0e17 | 195 | case wxSYS_CURSOR_Y: |
019a60d6 | 196 | return ::GetSystemMetrics(SM_CYCURSOR); |
2bda0e17 | 197 | case wxSYS_DCLICK_X: |
019a60d6 | 198 | return ::GetSystemMetrics(SM_CXDOUBLECLK); |
2bda0e17 | 199 | case wxSYS_DCLICK_Y: |
019a60d6 | 200 | return ::GetSystemMetrics(SM_CYDOUBLECLK); |
2432b92d | 201 | #if defined(__WIN32__) && defined(SM_CXDRAG) |
2bda0e17 | 202 | case wxSYS_DRAG_X: |
019a60d6 | 203 | return ::GetSystemMetrics(SM_CXDRAG); |
2bda0e17 | 204 | case wxSYS_DRAG_Y: |
019a60d6 | 205 | return ::GetSystemMetrics(SM_CYDRAG); |
2bda0e17 | 206 | case wxSYS_EDGE_X: |
019a60d6 | 207 | return ::GetSystemMetrics(SM_CXEDGE); |
2bda0e17 | 208 | case wxSYS_EDGE_Y: |
019a60d6 | 209 | return ::GetSystemMetrics(SM_CYEDGE); |
2bda0e17 KB |
210 | #endif |
211 | case wxSYS_HSCROLL_ARROW_X: | |
019a60d6 | 212 | return ::GetSystemMetrics(SM_CXHSCROLL); |
2bda0e17 | 213 | case wxSYS_HSCROLL_ARROW_Y: |
019a60d6 | 214 | return ::GetSystemMetrics(SM_CYHSCROLL); |
2bda0e17 | 215 | case wxSYS_HTHUMB_X: |
019a60d6 | 216 | return ::GetSystemMetrics(SM_CXHTHUMB); |
2bda0e17 | 217 | case wxSYS_ICON_X: |
019a60d6 | 218 | return ::GetSystemMetrics(SM_CXICON); |
2bda0e17 | 219 | case wxSYS_ICON_Y: |
019a60d6 | 220 | return ::GetSystemMetrics(SM_CYICON); |
2bda0e17 | 221 | case wxSYS_ICONSPACING_X: |
019a60d6 | 222 | return ::GetSystemMetrics(SM_CXICONSPACING); |
2bda0e17 | 223 | case wxSYS_ICONSPACING_Y: |
019a60d6 | 224 | return ::GetSystemMetrics(SM_CYICONSPACING); |
2bda0e17 | 225 | case wxSYS_WINDOWMIN_X: |
019a60d6 | 226 | return ::GetSystemMetrics(SM_CXMIN); |
2bda0e17 | 227 | case wxSYS_WINDOWMIN_Y: |
019a60d6 | 228 | return ::GetSystemMetrics(SM_CYMIN); |
2bda0e17 | 229 | case wxSYS_SCREEN_X: |
019a60d6 | 230 | return ::GetSystemMetrics(SM_CXSCREEN); |
2bda0e17 | 231 | case wxSYS_SCREEN_Y: |
019a60d6 | 232 | return ::GetSystemMetrics(SM_CYSCREEN); |
2432b92d JS |
233 | |
234 | #if defined(__WIN32__) && defined(SM_CXSIZEFRAME) | |
2bda0e17 | 235 | case wxSYS_FRAMESIZE_X: |
019a60d6 | 236 | return ::GetSystemMetrics(SM_CXSIZEFRAME); |
2bda0e17 | 237 | case wxSYS_FRAMESIZE_Y: |
019a60d6 | 238 | return ::GetSystemMetrics(SM_CYSIZEFRAME); |
2bda0e17 | 239 | case wxSYS_SMALLICON_X: |
019a60d6 | 240 | return ::GetSystemMetrics(SM_CXSMICON); |
2bda0e17 | 241 | case wxSYS_SMALLICON_Y: |
019a60d6 | 242 | return ::GetSystemMetrics(SM_CYSMICON); |
2bda0e17 KB |
243 | #endif |
244 | case wxSYS_HSCROLL_Y: | |
019a60d6 | 245 | return ::GetSystemMetrics(SM_CYHSCROLL); |
2bda0e17 | 246 | case wxSYS_VSCROLL_X: |
019a60d6 | 247 | return ::GetSystemMetrics(SM_CXVSCROLL); |
2bda0e17 | 248 | case wxSYS_VSCROLL_ARROW_X: |
019a60d6 | 249 | return ::GetSystemMetrics(SM_CXVSCROLL); |
2bda0e17 | 250 | case wxSYS_VSCROLL_ARROW_Y: |
019a60d6 | 251 | return ::GetSystemMetrics(SM_CYVSCROLL); |
2bda0e17 | 252 | case wxSYS_VTHUMB_Y: |
019a60d6 | 253 | return ::GetSystemMetrics(SM_CYVTHUMB); |
2bda0e17 | 254 | case wxSYS_CAPTION_Y: |
019a60d6 | 255 | return ::GetSystemMetrics(SM_CYCAPTION); |
2bda0e17 | 256 | case wxSYS_MENU_Y: |
019a60d6 | 257 | return ::GetSystemMetrics(SM_CYMENU); |
2432b92d | 258 | #if defined(__WIN32__) && defined(SM_NETWORK) |
2bda0e17 | 259 | case wxSYS_NETWORK_PRESENT: |
019a60d6 | 260 | return ::GetSystemMetrics(SM_NETWORK) & 0x0001; |
2bda0e17 KB |
261 | #endif |
262 | case wxSYS_PENWINDOWS_PRESENT: | |
019a60d6 | 263 | return ::GetSystemMetrics(SM_PENWINDOWS); |
2432b92d | 264 | #if defined(__WIN32__) && defined(SM_SHOWSOUNDS) |
2bda0e17 | 265 | case wxSYS_SHOW_SOUNDS: |
019a60d6 | 266 | return ::GetSystemMetrics(SM_SHOWSOUNDS); |
2bda0e17 KB |
267 | #endif |
268 | case wxSYS_SWAP_BUTTONS: | |
019a60d6 VS |
269 | return ::GetSystemMetrics(SM_SWAPBUTTON); |
270 | default: | |
271 | return 0; | |
272 | } | |
04ef50df JS |
273 | #endif |
274 | // __WXMICROWIN__ | |
2bda0e17 KB |
275 | } |
276 | ||
d3211838 JS |
277 | // Option functions (arbitrary name/value mapping) |
278 | void 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 | ||
293 | void wxSystemSettings::SetOption(const wxString& name, int value) | |
294 | { | |
295 | wxString valStr; | |
296 | valStr.Printf(wxT("%d"), value); | |
297 | SetOption(name, valStr); | |
298 | } | |
299 | ||
300 | wxString 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 | ||
309 | int wxSystemSettings::GetOptionInt(const wxString& name) | |
310 | { | |
311 | return wxAtoi(GetOption(name)); | |
312 | } | |
313 | ||
314 | bool wxSystemSettings::HasOption(const wxString& name) | |
315 | { | |
316 | return (wxSystemSettingsModule::sm_optionNames.Index(name, FALSE) != wxNOT_FOUND); | |
317 | } | |
318 |