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