]>
Commit | Line | Data |
---|---|---|
2bda0e17 | 1 | ///////////////////////////////////////////////////////////////////////////// |
8bf30fe9 | 2 | // Name: msw/settings.cpp |
7516ed26 | 3 | // Purpose: wxSystemSettingsNative implementation for MSW |
2bda0e17 KB |
4 | // Author: Julian Smart |
5 | // Modified by: | |
6 | // Created: 04/01/98 | |
7 | // RCS-ID: $Id$ | |
6c9a19aa | 8 | // Copyright: (c) Julian Smart |
65571936 | 9 | // Licence: wxWindows licence |
2bda0e17 KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
8bf30fe9 VZ |
12 | // ============================================================================ |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
2bda0e17 KB |
20 | // For compilers that support precompilation, includes "wx.h". |
21 | #include "wx/wxprec.h" | |
22 | ||
23 | #ifdef __BORLANDC__ | |
7516ed26 | 24 | #pragma hdrstop |
2bda0e17 KB |
25 | #endif |
26 | ||
27 | #ifndef WX_PRECOMP | |
e02e8816 | 28 | #include "wx/utils.h" |
8bf30fe9 | 29 | #include "wx/gdicmn.h" |
2bda0e17 KB |
30 | #endif |
31 | ||
32 | #include "wx/settings.h" | |
7516ed26 | 33 | |
2bda0e17 | 34 | #include "wx/msw/private.h" |
7516ed26 | 35 | |
d1eebf40 SC |
36 | #ifndef SPI_GETFLATMENU |
37 | #define SPI_GETFLATMENU 0x1022 | |
38 | #endif | |
39 | ||
2e6d38ad | 40 | #include "wx/module.h" |
04ef50df | 41 | #include "wx/fontutil.h" |
2bda0e17 | 42 | |
eae4425d JS |
43 | #ifdef __WXWINCE__ // for SM_CXCURSOR and SM_CYCURSOR |
44 | #include "wx/msw/wince/missing.h" | |
45 | #endif // __WXWINCE__ | |
46 | ||
8bf30fe9 VZ |
47 | // ---------------------------------------------------------------------------- |
48 | // private classes | |
49 | // ---------------------------------------------------------------------------- | |
50 | ||
7516ed26 | 51 | // the module which is used to clean up wxSystemSettingsNative data (this is a |
8bf30fe9 VZ |
52 | // singleton class so it can't be done in the dtor) |
53 | class wxSystemSettingsModule : public wxModule | |
54 | { | |
55 | public: | |
56 | virtual bool OnInit(); | |
57 | virtual void OnExit(); | |
58 | ||
59 | private: | |
60 | DECLARE_DYNAMIC_CLASS(wxSystemSettingsModule) | |
61 | }; | |
62 | ||
63 | // ---------------------------------------------------------------------------- | |
64 | // global data | |
65 | // ---------------------------------------------------------------------------- | |
66 | ||
7516ed26 VZ |
67 | // the font returned by GetFont(wxSYS_DEFAULT_GUI_FONT): it is created when |
68 | // GetFont() is called for the first time and deleted by wxSystemSettingsModule | |
8bf30fe9 VZ |
69 | static wxFont *gs_fontDefault = NULL; |
70 | ||
71 | // ============================================================================ | |
72 | // implementation | |
73 | // ============================================================================ | |
74 | ||
7516ed26 VZ |
75 | // TODO: see ::SystemParametersInfo for all sorts of Windows settings. |
76 | // Different args are required depending on the id. How does this differ | |
77 | // from GetSystemMetric, and should it? Perhaps call it GetSystemParameter | |
78 | // and pass an optional void* arg to get further info. | |
79 | // Should also have SetSystemParameter. | |
80 | // Also implement WM_WININICHANGE (NT) / WM_SETTINGCHANGE (Win95) | |
81 | ||
8bf30fe9 VZ |
82 | // ---------------------------------------------------------------------------- |
83 | // wxSystemSettingsModule | |
84 | // ---------------------------------------------------------------------------- | |
85 | ||
86 | IMPLEMENT_DYNAMIC_CLASS(wxSystemSettingsModule, wxModule) | |
87 | ||
88 | bool wxSystemSettingsModule::OnInit() | |
89 | { | |
57f4f925 | 90 | return true; |
8bf30fe9 VZ |
91 | } |
92 | ||
93 | void wxSystemSettingsModule::OnExit() | |
94 | { | |
95 | delete gs_fontDefault; | |
0cbff120 | 96 | gs_fontDefault = NULL; |
8bf30fe9 VZ |
97 | } |
98 | ||
99 | // ---------------------------------------------------------------------------- | |
7516ed26 | 100 | // wxSystemSettingsNative |
8bf30fe9 VZ |
101 | // ---------------------------------------------------------------------------- |
102 | ||
7516ed26 VZ |
103 | // ---------------------------------------------------------------------------- |
104 | // colours | |
105 | // ---------------------------------------------------------------------------- | |
2bda0e17 | 106 | |
7516ed26 | 107 | wxColour wxSystemSettingsNative::GetColour(wxSystemColour index) |
2bda0e17 | 108 | { |
7d6d3bf3 VZ |
109 | // we use 0 as the default value just to avoid compiler warnings, as there |
110 | // is no invalid colour value we use hasCol as the real indicator of | |
111 | // whether colSys was initialized or not | |
112 | COLORREF colSys = 0; | |
57f4f925 | 113 | bool hasCol = false; |
7d6d3bf3 VZ |
114 | |
115 | // the default colours for the entries after BTNHIGHLIGHT | |
116 | static const COLORREF s_defaultSysColors[] = | |
117 | { | |
118 | 0x000000, // 3DDKSHADOW | |
119 | 0xdfdfdf, // 3DLIGHT | |
120 | 0x000000, // INFOTEXT | |
121 | 0xe1ffff, // INFOBK | |
122 | ||
123 | 0, // filler - no std colour with this index | |
124 | ||
125 | // TODO: please fill in the standard values of those, I don't have them | |
126 | 0, // HOTLIGHT | |
127 | 0, // GRADIENTACTIVECAPTION | |
128 | 0, // GRADIENTINACTIVECAPTION | |
129 | 0, // MENU | |
130 | 0, // MENUBAR (unused) | |
131 | }; | |
132 | ||
133 | if ( index == wxSYS_COLOUR_LISTBOX ) | |
134 | { | |
135 | // there is no standard colour with this index, map to another one | |
136 | index = wxSYS_COLOUR_WINDOW; | |
137 | } | |
138 | else if ( index > wxSYS_COLOUR_BTNHIGHLIGHT ) | |
139 | { | |
140 | // the indices before BTNHIGHLIGHT are understood by GetSysColor() in | |
141 | // all Windows version, for the other ones we have to check | |
142 | bool useDefault; | |
143 | ||
7d6d3bf3 VZ |
144 | int verMaj, verMin; |
145 | wxGetOsVersion(&verMaj, &verMin); | |
146 | if ( verMaj < 4 ) | |
147 | { | |
148 | // NT 3.5 | |
57f4f925 | 149 | useDefault = true; |
7d6d3bf3 VZ |
150 | } |
151 | else if ( verMaj == 4 ) | |
152 | { | |
153 | // Win95/NT 4.0 | |
154 | useDefault = index > wxSYS_COLOUR_INFOBK; | |
155 | } | |
156 | else if ( verMaj == 5 && verMin == 0 ) | |
157 | { | |
158 | // Win98/Win2K | |
159 | useDefault = index > wxSYS_COLOUR_GRADIENTINACTIVECAPTION; | |
160 | } | |
161 | else // >= 5.1 | |
162 | { | |
163 | // 5.1 is Windows XP | |
57f4f925 WS |
164 | useDefault = false; |
165 | // Determine if we are using flat menus, only then allow wxSYS_COLOUR_MENUBAR | |
166 | if ( index == wxSYS_COLOUR_MENUBAR ) | |
167 | { | |
168 | BOOL isFlat ; | |
169 | if ( SystemParametersInfo( SPI_GETFLATMENU , 0 ,&isFlat, 0 ) ) | |
170 | { | |
171 | if ( !isFlat ) | |
172 | index = wxSYS_COLOUR_MENU ; | |
173 | } | |
174 | } | |
d1eebf40 | 175 | } |
7d6d3bf3 VZ |
176 | |
177 | if ( useDefault ) | |
178 | { | |
179 | // special handling for MENUBAR colour: we use this in wxToolBar | |
180 | // and wxStatusBar to have correct bg colour under Windows XP | |
181 | // (which uses COLOR_MENUBAR for them) but they should still look | |
182 | // correctly under previous Windows versions as well | |
183 | if ( index == wxSYS_COLOUR_MENUBAR ) | |
184 | { | |
185 | index = wxSYS_COLOUR_3DFACE; | |
186 | } | |
187 | else // replace with default colour | |
188 | { | |
d285d708 | 189 | unsigned int n = index - wxSYS_COLOUR_BTNHIGHLIGHT; |
7d6d3bf3 VZ |
190 | |
191 | wxASSERT_MSG( n < WXSIZEOF(s_defaultSysColors), | |
192 | _T("forgot tp update the default colours array") ); | |
193 | ||
194 | colSys = s_defaultSysColors[n]; | |
57f4f925 | 195 | hasCol = true; |
7d6d3bf3 VZ |
196 | } |
197 | } | |
198 | } | |
199 | ||
200 | if ( !hasCol ) | |
201 | { | |
39d2f9a7 JS |
202 | #ifdef __WXWINCE__ |
203 | colSys = ::GetSysColor(index|SYS_COLOR_INDEX_FLAG); | |
204 | #else | |
7d6d3bf3 | 205 | colSys = ::GetSysColor(index); |
39d2f9a7 | 206 | #endif |
7d6d3bf3 VZ |
207 | } |
208 | ||
209 | return wxRGBToColour(colSys); | |
2bda0e17 KB |
210 | } |
211 | ||
7516ed26 VZ |
212 | // ---------------------------------------------------------------------------- |
213 | // fonts | |
214 | // ---------------------------------------------------------------------------- | |
215 | ||
04ef50df | 216 | wxFont wxCreateFontFromStockObject(int index) |
2bda0e17 | 217 | { |
8bf30fe9 VZ |
218 | wxFont font; |
219 | ||
019a60d6 | 220 | HFONT hFont = (HFONT) ::GetStockObject(index); |
8bf30fe9 | 221 | if ( hFont ) |
019a60d6 VS |
222 | { |
223 | LOGFONT lf; | |
224 | if ( ::GetObject(hFont, sizeof(LOGFONT), &lf) != 0 ) | |
225 | { | |
04ef50df JS |
226 | wxNativeFontInfo info; |
227 | info.lf = lf; | |
b4772c24 JS |
228 | // We want Windows 2000 or later to have new fonts even MS Shell Dlg |
229 | // is returned as default GUI font for compatibility | |
230 | int verMaj; | |
231 | if(index == DEFAULT_GUI_FONT && wxGetOsVersion(&verMaj) == wxWINDOWS_NT && verMaj >= 5) | |
232 | wxStrcpy(info.lf.lfFaceName, wxT("MS Shell Dlg 2")); | |
233 | ||
04ef50df JS |
234 | // Under MicroWindows we pass the HFONT as well |
235 | // because it's hard to convert HFONT -> LOGFONT -> HFONT | |
236 | // It's OK to delete stock objects, the delete will be ignored. | |
237 | #ifdef __WXMICROWIN__ | |
238 | font.Create(info, (WXHFONT) hFont); | |
239 | #else | |
240 | font.Create(info); | |
241 | #endif | |
019a60d6 VS |
242 | } |
243 | else | |
244 | { | |
8bf30fe9 | 245 | wxFAIL_MSG( _T("failed to get LOGFONT") ); |
019a60d6 VS |
246 | } |
247 | } | |
8bf30fe9 VZ |
248 | else // GetStockObject() failed |
249 | { | |
250 | wxFAIL_MSG( _T("stock font not found") ); | |
251 | } | |
7516ed26 | 252 | |
04ef50df JS |
253 | return font; |
254 | } | |
255 | ||
7516ed26 | 256 | wxFont wxSystemSettingsNative::GetFont(wxSystemFont index) |
04ef50df | 257 | { |
27adb8ba VZ |
258 | #ifdef __WXWINCE__ |
259 | // under CE only a single SYSTEM_FONT exists | |
260 | index; | |
261 | ||
262 | if ( !gs_fontDefault ) | |
263 | { | |
264 | gs_fontDefault = new wxFont(wxCreateFontFromStockObject(SYSTEM_FONT)); | |
265 | } | |
266 | ||
267 | return *gs_fontDefault; | |
268 | #else // !__WXWINCE__ | |
46697f31 | 269 | // wxWindow ctor calls GetFont(wxSYS_DEFAULT_GUI_FONT) so we're |
553c5bcc VZ |
270 | // called fairly often -- this is why we cache this particular font |
271 | const bool isDefaultRequested = index == wxSYS_DEFAULT_GUI_FONT; | |
272 | if ( isDefaultRequested ) | |
04ef50df | 273 | { |
553c5bcc VZ |
274 | if ( gs_fontDefault ) |
275 | return *gs_fontDefault; | |
04ef50df JS |
276 | } |
277 | ||
278 | wxFont font = wxCreateFontFromStockObject(index); | |
8bf30fe9 VZ |
279 | |
280 | if ( isDefaultRequested ) | |
019a60d6 | 281 | { |
8bf30fe9 VZ |
282 | // if we got here it means we hadn't cached it yet - do now |
283 | gs_fontDefault = new wxFont(font); | |
019a60d6 | 284 | } |
8bf30fe9 VZ |
285 | |
286 | return font; | |
27adb8ba | 287 | #endif // __WXWINCE__/!__WXWINCE__ |
2bda0e17 KB |
288 | } |
289 | ||
7516ed26 VZ |
290 | // ---------------------------------------------------------------------------- |
291 | // system metrics/features | |
292 | // ---------------------------------------------------------------------------- | |
293 | ||
294 | // TODO: some of the "metrics" clearly should be features now that we have | |
295 | // HasFeature()! | |
296 | ||
297 | // the conversion table from wxSystemMetric enum to GetSystemMetrics() param | |
298 | // | |
299 | // if the constant is not defined, put -1 in the table to indicate that it is | |
300 | // unknown | |
301 | static const int gs_metricsMap[] = | |
2bda0e17 | 302 | { |
fc29e86e | 303 | -1, // wxSystemMetric enums start at 1, so give a dummy value for pos 0. |
4676948b | 304 | #if defined(__WIN32__) && !defined(__WXWINCE__) |
7516ed26 VZ |
305 | SM_CMOUSEBUTTONS, |
306 | #else | |
307 | -1, | |
2bda0e17 KB |
308 | #endif |
309 | ||
7516ed26 VZ |
310 | SM_CXBORDER, |
311 | SM_CYBORDER, | |
312 | SM_CXCURSOR, | |
313 | SM_CYCURSOR, | |
314 | SM_CXDOUBLECLK, | |
315 | SM_CYDOUBLECLK, | |
2432b92d | 316 | #if defined(__WIN32__) && defined(SM_CXDRAG) |
7516ed26 VZ |
317 | SM_CXDRAG, |
318 | SM_CYDRAG, | |
319 | SM_CXEDGE, | |
320 | SM_CYEDGE, | |
321 | #else | |
4676948b | 322 | -1, -1, -1, -1, |
2bda0e17 | 323 | #endif |
7516ed26 VZ |
324 | SM_CXHSCROLL, |
325 | SM_CYHSCROLL, | |
4676948b | 326 | #ifdef SM_CXHTHUMB |
7516ed26 | 327 | SM_CXHTHUMB, |
4676948b JS |
328 | #else |
329 | -1, | |
330 | #endif | |
7516ed26 VZ |
331 | SM_CXICON, |
332 | SM_CYICON, | |
333 | SM_CXICONSPACING, | |
334 | SM_CYICONSPACING, | |
4676948b | 335 | #ifdef SM_CXHTHUMB |
7516ed26 VZ |
336 | SM_CXMIN, |
337 | SM_CYMIN, | |
4676948b JS |
338 | #else |
339 | -1, -1, | |
340 | #endif | |
7516ed26 VZ |
341 | SM_CXSCREEN, |
342 | SM_CYSCREEN, | |
2432b92d JS |
343 | |
344 | #if defined(__WIN32__) && defined(SM_CXSIZEFRAME) | |
7516ed26 VZ |
345 | SM_CXSIZEFRAME, |
346 | SM_CYSIZEFRAME, | |
347 | SM_CXSMICON, | |
348 | SM_CYSMICON, | |
349 | #else | |
4676948b | 350 | -1, -1, -1, -1, |
2bda0e17 | 351 | #endif |
7516ed26 VZ |
352 | SM_CYHSCROLL, |
353 | SM_CXVSCROLL, | |
354 | SM_CXVSCROLL, | |
355 | SM_CYVSCROLL, | |
4676948b | 356 | #ifdef SM_CYVTHUMB |
7516ed26 | 357 | SM_CYVTHUMB, |
4676948b JS |
358 | #else |
359 | -1, | |
360 | #endif | |
7516ed26 VZ |
361 | SM_CYCAPTION, |
362 | SM_CYMENU, | |
2432b92d | 363 | #if defined(__WIN32__) && defined(SM_NETWORK) |
7516ed26 VZ |
364 | SM_NETWORK, |
365 | #else | |
366 | -1, | |
2bda0e17 | 367 | #endif |
4676948b | 368 | #ifdef SM_PENWINDOWS |
7516ed26 | 369 | SM_PENWINDOWS, |
4676948b JS |
370 | #else |
371 | -1, | |
372 | #endif | |
2432b92d | 373 | #if defined(__WIN32__) && defined(SM_SHOWSOUNDS) |
7516ed26 VZ |
374 | SM_SHOWSOUNDS, |
375 | #else | |
376 | -1, | |
2bda0e17 | 377 | #endif |
4676948b | 378 | #ifdef SM_SWAPBUTTON |
7516ed26 | 379 | SM_SWAPBUTTON, |
4676948b JS |
380 | #else |
381 | -1 | |
382 | #endif | |
7516ed26 VZ |
383 | }; |
384 | ||
385 | // Get a system metric, e.g. scrollbar size | |
9b0b5ba7 | 386 | int wxSystemSettingsNative::GetMetric(wxSystemMetric index, wxWindow* WXUNUSED(win)) |
7516ed26 VZ |
387 | { |
388 | #ifdef __WXMICROWIN__ | |
389 | // TODO: probably use wxUniv themes functionality | |
390 | return 0; | |
391 | #else // !__WXMICROWIN__ | |
68d95db4 VZ |
392 | wxCHECK_MSG( index > 0 && (size_t)index < WXSIZEOF(gs_metricsMap), 0, |
393 | _T("invalid metric") ); | |
7516ed26 VZ |
394 | |
395 | int indexMSW = gs_metricsMap[index]; | |
396 | if ( indexMSW == -1 ) | |
397 | { | |
398 | // not supported under current system | |
1d451c5b | 399 | return -1; |
019a60d6 | 400 | } |
7516ed26 VZ |
401 | |
402 | int rc = ::GetSystemMetrics(indexMSW); | |
403 | if ( index == wxSYS_NETWORK_PRESENT ) | |
404 | { | |
405 | // only the last bit is significant according to the MSDN | |
406 | rc &= 1; | |
407 | } | |
408 | ||
409 | return rc; | |
410 | #endif // __WXMICROWIN__/!__WXMICROWIN__ | |
2bda0e17 KB |
411 | } |
412 | ||
7516ed26 | 413 | bool wxSystemSettingsNative::HasFeature(wxSystemFeature index) |
253293c1 | 414 | { |
7516ed26 | 415 | switch ( index ) |
253293c1 | 416 | { |
7516ed26 | 417 | case wxSYS_CAN_ICONIZE_FRAME: |
253293c1 | 418 | case wxSYS_CAN_DRAW_FRAME_DECORATIONS: |
57f4f925 | 419 | return true; |
7516ed26 | 420 | |
253293c1 | 421 | default: |
7516ed26 VZ |
422 | wxFAIL_MSG( _T("unknown system feature") ); |
423 | ||
57f4f925 | 424 | return false; |
253293c1 VS |
425 | } |
426 | } | |
553c5bcc VZ |
427 | |
428 | // ---------------------------------------------------------------------------- | |
429 | // function from wx/msw/wrapcctl.h: there is really no other place for it... | |
430 | // ---------------------------------------------------------------------------- | |
431 | ||
432 | #if wxUSE_LISTCTRL || wxUSE_TREECTRL | |
433 | ||
434 | extern wxFont wxGetCCDefaultFont() | |
435 | { | |
436 | #ifndef __WXWINCE__ | |
437 | // under the systems enumerated below (anything released after Win98), the | |
438 | // default font used for the common controls seems to be the desktop font | |
439 | // which is also used for the icon titles and not the stock default GUI | |
440 | // font | |
441 | bool useIconFont; | |
442 | int verMaj, verMin; | |
443 | switch ( wxGetOsVersion(&verMaj, &verMin) ) | |
444 | { | |
445 | case wxWIN95: | |
446 | // 4.10 is Win98 | |
b594d7f7 | 447 | useIconFont = verMaj == 4 && verMin >= 10; |
553c5bcc VZ |
448 | break; |
449 | ||
450 | case wxWINDOWS_NT: | |
451 | // 5.0 is Win2k | |
452 | useIconFont = verMaj >= 5; | |
453 | break; | |
454 | ||
455 | default: | |
456 | useIconFont = false; | |
457 | } | |
458 | ||
459 | if ( useIconFont ) | |
460 | { | |
461 | LOGFONT lf; | |
462 | if ( ::SystemParametersInfo | |
463 | ( | |
464 | SPI_GETICONTITLELOGFONT, | |
465 | sizeof(lf), | |
466 | &lf, | |
467 | 0 | |
468 | ) ) | |
469 | { | |
470 | return wxFont(wxCreateFontFromLogFont(&lf)); | |
471 | } | |
472 | else | |
473 | { | |
474 | wxLogLastError(_T("SystemParametersInfo(SPI_GETICONTITLELOGFONT")); | |
475 | } | |
476 | } | |
477 | #endif // __WXWINCE__ | |
478 | ||
479 | // fall back to the default font for the normal controls | |
480 | return wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); | |
481 | } | |
482 | ||
483 | #endif // wxUSE_LISTCTRL || wxUSE_TREECTRL |