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