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