]>
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 | ||
9eddec69 WS |
27 | #include "wx/settings.h" |
28 | ||
2bda0e17 | 29 | #ifndef WX_PRECOMP |
e02e8816 | 30 | #include "wx/utils.h" |
8bf30fe9 | 31 | #include "wx/gdicmn.h" |
2bda0e17 KB |
32 | #endif |
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 | |
ddec9f1e JS |
43 | // for SM_CXCURSOR, SM_CYCURSOR, SM_TABLETPC |
44 | #include "wx/msw/missing.h" | |
eae4425d | 45 | |
8bf30fe9 VZ |
46 | // ---------------------------------------------------------------------------- |
47 | // private classes | |
48 | // ---------------------------------------------------------------------------- | |
49 | ||
7516ed26 | 50 | // the module which is used to clean up wxSystemSettingsNative data (this is a |
8bf30fe9 VZ |
51 | // singleton class so it can't be done in the dtor) |
52 | class wxSystemSettingsModule : public wxModule | |
53 | { | |
54 | public: | |
55 | virtual bool OnInit(); | |
56 | virtual void OnExit(); | |
57 | ||
58 | private: | |
59 | DECLARE_DYNAMIC_CLASS(wxSystemSettingsModule) | |
60 | }; | |
61 | ||
62 | // ---------------------------------------------------------------------------- | |
63 | // global data | |
64 | // ---------------------------------------------------------------------------- | |
65 | ||
7516ed26 VZ |
66 | // the font returned by GetFont(wxSYS_DEFAULT_GUI_FONT): it is created when |
67 | // GetFont() is called for the first time and deleted by wxSystemSettingsModule | |
8bf30fe9 VZ |
68 | static wxFont *gs_fontDefault = NULL; |
69 | ||
70 | // ============================================================================ | |
71 | // implementation | |
72 | // ============================================================================ | |
73 | ||
7516ed26 VZ |
74 | // TODO: see ::SystemParametersInfo for all sorts of Windows settings. |
75 | // Different args are required depending on the id. How does this differ | |
76 | // from GetSystemMetric, and should it? Perhaps call it GetSystemParameter | |
77 | // and pass an optional void* arg to get further info. | |
78 | // Should also have SetSystemParameter. | |
79 | // Also implement WM_WININICHANGE (NT) / WM_SETTINGCHANGE (Win95) | |
80 | ||
8bf30fe9 VZ |
81 | // ---------------------------------------------------------------------------- |
82 | // wxSystemSettingsModule | |
83 | // ---------------------------------------------------------------------------- | |
84 | ||
85 | IMPLEMENT_DYNAMIC_CLASS(wxSystemSettingsModule, wxModule) | |
86 | ||
87 | bool wxSystemSettingsModule::OnInit() | |
88 | { | |
57f4f925 | 89 | return true; |
8bf30fe9 VZ |
90 | } |
91 | ||
92 | void wxSystemSettingsModule::OnExit() | |
93 | { | |
94 | delete gs_fontDefault; | |
0cbff120 | 95 | gs_fontDefault = NULL; |
8bf30fe9 VZ |
96 | } |
97 | ||
98 | // ---------------------------------------------------------------------------- | |
7516ed26 | 99 | // wxSystemSettingsNative |
8bf30fe9 VZ |
100 | // ---------------------------------------------------------------------------- |
101 | ||
7516ed26 VZ |
102 | // ---------------------------------------------------------------------------- |
103 | // colours | |
104 | // ---------------------------------------------------------------------------- | |
2bda0e17 | 105 | |
7516ed26 | 106 | wxColour wxSystemSettingsNative::GetColour(wxSystemColour index) |
2bda0e17 | 107 | { |
7d6d3bf3 VZ |
108 | // we use 0 as the default value just to avoid compiler warnings, as there |
109 | // is no invalid colour value we use hasCol as the real indicator of | |
110 | // whether colSys was initialized or not | |
111 | COLORREF colSys = 0; | |
57f4f925 | 112 | bool hasCol = false; |
7d6d3bf3 VZ |
113 | |
114 | // the default colours for the entries after BTNHIGHLIGHT | |
115 | static const COLORREF s_defaultSysColors[] = | |
116 | { | |
117 | 0x000000, // 3DDKSHADOW | |
118 | 0xdfdfdf, // 3DLIGHT | |
119 | 0x000000, // INFOTEXT | |
120 | 0xe1ffff, // INFOBK | |
121 | ||
122 | 0, // filler - no std colour with this index | |
123 | ||
124 | // TODO: please fill in the standard values of those, I don't have them | |
125 | 0, // HOTLIGHT | |
126 | 0, // GRADIENTACTIVECAPTION | |
127 | 0, // GRADIENTINACTIVECAPTION | |
128 | 0, // MENU | |
129 | 0, // MENUBAR (unused) | |
130 | }; | |
131 | ||
132 | if ( index == wxSYS_COLOUR_LISTBOX ) | |
133 | { | |
134 | // there is no standard colour with this index, map to another one | |
135 | index = wxSYS_COLOUR_WINDOW; | |
136 | } | |
137 | else if ( index > wxSYS_COLOUR_BTNHIGHLIGHT ) | |
138 | { | |
139 | // the indices before BTNHIGHLIGHT are understood by GetSysColor() in | |
140 | // all Windows version, for the other ones we have to check | |
141 | bool useDefault; | |
142 | ||
7d6d3bf3 VZ |
143 | int verMaj, verMin; |
144 | wxGetOsVersion(&verMaj, &verMin); | |
145 | if ( verMaj < 4 ) | |
146 | { | |
147 | // NT 3.5 | |
57f4f925 | 148 | useDefault = true; |
7d6d3bf3 VZ |
149 | } |
150 | else if ( verMaj == 4 ) | |
151 | { | |
152 | // Win95/NT 4.0 | |
153 | useDefault = index > wxSYS_COLOUR_INFOBK; | |
154 | } | |
155 | else if ( verMaj == 5 && verMin == 0 ) | |
156 | { | |
157 | // Win98/Win2K | |
158 | useDefault = index > wxSYS_COLOUR_GRADIENTINACTIVECAPTION; | |
159 | } | |
160 | else // >= 5.1 | |
161 | { | |
162 | // 5.1 is Windows XP | |
57f4f925 WS |
163 | useDefault = false; |
164 | // Determine if we are using flat menus, only then allow wxSYS_COLOUR_MENUBAR | |
165 | if ( index == wxSYS_COLOUR_MENUBAR ) | |
166 | { | |
167 | BOOL isFlat ; | |
168 | if ( SystemParametersInfo( SPI_GETFLATMENU , 0 ,&isFlat, 0 ) ) | |
169 | { | |
170 | if ( !isFlat ) | |
171 | index = wxSYS_COLOUR_MENU ; | |
172 | } | |
173 | } | |
92218ce6 | 174 | } |
7d6d3bf3 VZ |
175 | |
176 | if ( useDefault ) | |
177 | { | |
178 | // special handling for MENUBAR colour: we use this in wxToolBar | |
179 | // and wxStatusBar to have correct bg colour under Windows XP | |
180 | // (which uses COLOR_MENUBAR for them) but they should still look | |
181 | // correctly under previous Windows versions as well | |
182 | if ( index == wxSYS_COLOUR_MENUBAR ) | |
183 | { | |
184 | index = wxSYS_COLOUR_3DFACE; | |
185 | } | |
186 | else // replace with default colour | |
187 | { | |
d285d708 | 188 | unsigned int n = index - wxSYS_COLOUR_BTNHIGHLIGHT; |
7d6d3bf3 VZ |
189 | |
190 | wxASSERT_MSG( n < WXSIZEOF(s_defaultSysColors), | |
191 | _T("forgot tp update the default colours array") ); | |
192 | ||
193 | colSys = s_defaultSysColors[n]; | |
57f4f925 | 194 | hasCol = true; |
7d6d3bf3 VZ |
195 | } |
196 | } | |
197 | } | |
198 | ||
199 | if ( !hasCol ) | |
200 | { | |
39d2f9a7 JS |
201 | #ifdef __WXWINCE__ |
202 | colSys = ::GetSysColor(index|SYS_COLOR_INDEX_FLAG); | |
203 | #else | |
7d6d3bf3 | 204 | colSys = ::GetSysColor(index); |
39d2f9a7 | 205 | #endif |
7d6d3bf3 VZ |
206 | } |
207 | ||
208 | return wxRGBToColour(colSys); | |
2bda0e17 KB |
209 | } |
210 | ||
7516ed26 VZ |
211 | // ---------------------------------------------------------------------------- |
212 | // fonts | |
213 | // ---------------------------------------------------------------------------- | |
214 | ||
04ef50df | 215 | wxFont wxCreateFontFromStockObject(int index) |
2bda0e17 | 216 | { |
8bf30fe9 VZ |
217 | wxFont font; |
218 | ||
019a60d6 | 219 | HFONT hFont = (HFONT) ::GetStockObject(index); |
8bf30fe9 | 220 | if ( hFont ) |
019a60d6 VS |
221 | { |
222 | LOGFONT lf; | |
223 | if ( ::GetObject(hFont, sizeof(LOGFONT), &lf) != 0 ) | |
224 | { | |
04ef50df JS |
225 | wxNativeFontInfo info; |
226 | info.lf = lf; | |
f8c10795 | 227 | #ifndef __WXWINCE__ |
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")); | |
f8c10795 | 233 | #endif |
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, | |
c1dfa9eb | 312 | #ifdef SM_CXCURSOR |
9eddec69 | 313 | SM_CXCURSOR, |
7516ed26 | 314 | SM_CYCURSOR, |
c1dfa9eb | 315 | #else |
9eddec69 | 316 | -1, -1, |
c1dfa9eb | 317 | #endif |
7516ed26 VZ |
318 | SM_CXDOUBLECLK, |
319 | SM_CYDOUBLECLK, | |
2432b92d | 320 | #if defined(__WIN32__) && defined(SM_CXDRAG) |
7516ed26 VZ |
321 | SM_CXDRAG, |
322 | SM_CYDRAG, | |
323 | SM_CXEDGE, | |
324 | SM_CYEDGE, | |
325 | #else | |
4676948b | 326 | -1, -1, -1, -1, |
2bda0e17 | 327 | #endif |
7516ed26 VZ |
328 | SM_CXHSCROLL, |
329 | SM_CYHSCROLL, | |
4676948b | 330 | #ifdef SM_CXHTHUMB |
7516ed26 | 331 | SM_CXHTHUMB, |
4676948b JS |
332 | #else |
333 | -1, | |
334 | #endif | |
7516ed26 VZ |
335 | SM_CXICON, |
336 | SM_CYICON, | |
337 | SM_CXICONSPACING, | |
338 | SM_CYICONSPACING, | |
4676948b | 339 | #ifdef SM_CXHTHUMB |
7516ed26 VZ |
340 | SM_CXMIN, |
341 | SM_CYMIN, | |
4676948b JS |
342 | #else |
343 | -1, -1, | |
344 | #endif | |
7516ed26 VZ |
345 | SM_CXSCREEN, |
346 | SM_CYSCREEN, | |
2432b92d JS |
347 | |
348 | #if defined(__WIN32__) && defined(SM_CXSIZEFRAME) | |
7516ed26 VZ |
349 | SM_CXSIZEFRAME, |
350 | SM_CYSIZEFRAME, | |
351 | SM_CXSMICON, | |
352 | SM_CYSMICON, | |
353 | #else | |
4676948b | 354 | -1, -1, -1, -1, |
2bda0e17 | 355 | #endif |
7516ed26 VZ |
356 | SM_CYHSCROLL, |
357 | SM_CXVSCROLL, | |
358 | SM_CXVSCROLL, | |
359 | SM_CYVSCROLL, | |
4676948b | 360 | #ifdef SM_CYVTHUMB |
7516ed26 | 361 | SM_CYVTHUMB, |
4676948b JS |
362 | #else |
363 | -1, | |
364 | #endif | |
7516ed26 VZ |
365 | SM_CYCAPTION, |
366 | SM_CYMENU, | |
2432b92d | 367 | #if defined(__WIN32__) && defined(SM_NETWORK) |
7516ed26 VZ |
368 | SM_NETWORK, |
369 | #else | |
370 | -1, | |
2bda0e17 | 371 | #endif |
4676948b | 372 | #ifdef SM_PENWINDOWS |
7516ed26 | 373 | SM_PENWINDOWS, |
4676948b JS |
374 | #else |
375 | -1, | |
376 | #endif | |
2432b92d | 377 | #if defined(__WIN32__) && defined(SM_SHOWSOUNDS) |
7516ed26 VZ |
378 | SM_SHOWSOUNDS, |
379 | #else | |
380 | -1, | |
2bda0e17 | 381 | #endif |
4676948b | 382 | #ifdef SM_SWAPBUTTON |
7516ed26 | 383 | SM_SWAPBUTTON, |
4676948b JS |
384 | #else |
385 | -1 | |
386 | #endif | |
7516ed26 VZ |
387 | }; |
388 | ||
389 | // Get a system metric, e.g. scrollbar size | |
9b0b5ba7 | 390 | int wxSystemSettingsNative::GetMetric(wxSystemMetric index, wxWindow* WXUNUSED(win)) |
7516ed26 VZ |
391 | { |
392 | #ifdef __WXMICROWIN__ | |
393 | // TODO: probably use wxUniv themes functionality | |
394 | return 0; | |
395 | #else // !__WXMICROWIN__ | |
68d95db4 VZ |
396 | wxCHECK_MSG( index > 0 && (size_t)index < WXSIZEOF(gs_metricsMap), 0, |
397 | _T("invalid metric") ); | |
7516ed26 VZ |
398 | |
399 | int indexMSW = gs_metricsMap[index]; | |
400 | if ( indexMSW == -1 ) | |
401 | { | |
402 | // not supported under current system | |
1d451c5b | 403 | return -1; |
019a60d6 | 404 | } |
7516ed26 VZ |
405 | |
406 | int rc = ::GetSystemMetrics(indexMSW); | |
407 | if ( index == wxSYS_NETWORK_PRESENT ) | |
408 | { | |
409 | // only the last bit is significant according to the MSDN | |
410 | rc &= 1; | |
411 | } | |
412 | ||
413 | return rc; | |
414 | #endif // __WXMICROWIN__/!__WXMICROWIN__ | |
2bda0e17 KB |
415 | } |
416 | ||
7516ed26 | 417 | bool wxSystemSettingsNative::HasFeature(wxSystemFeature index) |
253293c1 | 418 | { |
7516ed26 | 419 | switch ( index ) |
253293c1 | 420 | { |
7516ed26 | 421 | case wxSYS_CAN_ICONIZE_FRAME: |
253293c1 | 422 | case wxSYS_CAN_DRAW_FRAME_DECORATIONS: |
57f4f925 | 423 | return true; |
7516ed26 | 424 | |
ddec9f1e JS |
425 | case wxSYS_TABLET_PRESENT: |
426 | return ::GetSystemMetrics(SM_TABLETPC) != 0; | |
427 | ||
253293c1 | 428 | default: |
7516ed26 VZ |
429 | wxFAIL_MSG( _T("unknown system feature") ); |
430 | ||
57f4f925 | 431 | return false; |
253293c1 VS |
432 | } |
433 | } | |
553c5bcc VZ |
434 | |
435 | // ---------------------------------------------------------------------------- | |
436 | // function from wx/msw/wrapcctl.h: there is really no other place for it... | |
437 | // ---------------------------------------------------------------------------- | |
438 | ||
439 | #if wxUSE_LISTCTRL || wxUSE_TREECTRL | |
440 | ||
441 | extern wxFont wxGetCCDefaultFont() | |
442 | { | |
443 | #ifndef __WXWINCE__ | |
444 | // under the systems enumerated below (anything released after Win98), the | |
445 | // default font used for the common controls seems to be the desktop font | |
446 | // which is also used for the icon titles and not the stock default GUI | |
447 | // font | |
448 | bool useIconFont; | |
449 | int verMaj, verMin; | |
450 | switch ( wxGetOsVersion(&verMaj, &verMin) ) | |
451 | { | |
452 | case wxWIN95: | |
453 | // 4.10 is Win98 | |
b594d7f7 | 454 | useIconFont = verMaj == 4 && verMin >= 10; |
553c5bcc VZ |
455 | break; |
456 | ||
457 | case wxWINDOWS_NT: | |
458 | // 5.0 is Win2k | |
459 | useIconFont = verMaj >= 5; | |
460 | break; | |
461 | ||
462 | default: | |
463 | useIconFont = false; | |
464 | } | |
465 | ||
466 | if ( useIconFont ) | |
467 | { | |
468 | LOGFONT lf; | |
469 | if ( ::SystemParametersInfo | |
470 | ( | |
471 | SPI_GETICONTITLELOGFONT, | |
472 | sizeof(lf), | |
473 | &lf, | |
474 | 0 | |
475 | ) ) | |
476 | { | |
477 | return wxFont(wxCreateFontFromLogFont(&lf)); | |
478 | } | |
479 | else | |
480 | { | |
481 | wxLogLastError(_T("SystemParametersInfo(SPI_GETICONTITLELOGFONT")); | |
482 | } | |
483 | } | |
484 | #endif // __WXWINCE__ | |
485 | ||
486 | // fall back to the default font for the normal controls | |
487 | return wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); | |
488 | } | |
489 | ||
490 | #endif // wxUSE_LISTCTRL || wxUSE_TREECTRL |