]> git.saurik.com Git - wxWidgets.git/blame - src/msw/settings.cpp
Added wxDataViewListCtrl, use it in the sample
[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
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 }
135 else if ( index == wxSYS_COLOUR_LISTBOX )
7d6d3bf3
VZ
136 {
137 // there is no standard colour with this index, map to another one
138 index = wxSYS_COLOUR_WINDOW;
139 }
140 else if ( index > wxSYS_COLOUR_BTNHIGHLIGHT )
141 {
142 // the indices before BTNHIGHLIGHT are understood by GetSysColor() in
143 // all Windows version, for the other ones we have to check
144 bool useDefault;
145
7d6d3bf3
VZ
146 int verMaj, verMin;
147 wxGetOsVersion(&verMaj, &verMin);
148 if ( verMaj < 4 )
149 {
150 // NT 3.5
57f4f925 151 useDefault = true;
7d6d3bf3
VZ
152 }
153 else if ( verMaj == 4 )
154 {
155 // Win95/NT 4.0
156 useDefault = index > wxSYS_COLOUR_INFOBK;
157 }
158 else if ( verMaj == 5 && verMin == 0 )
159 {
160 // Win98/Win2K
161 useDefault = index > wxSYS_COLOUR_GRADIENTINACTIVECAPTION;
162 }
163 else // >= 5.1
164 {
165 // 5.1 is Windows XP
57f4f925
WS
166 useDefault = false;
167 // Determine if we are using flat menus, only then allow wxSYS_COLOUR_MENUBAR
168 if ( index == wxSYS_COLOUR_MENUBAR )
169 {
170 BOOL isFlat ;
171 if ( SystemParametersInfo( SPI_GETFLATMENU , 0 ,&isFlat, 0 ) )
172 {
173 if ( !isFlat )
174 index = wxSYS_COLOUR_MENU ;
175 }
176 }
92218ce6 177 }
7d6d3bf3
VZ
178
179 if ( useDefault )
180 {
181 // special handling for MENUBAR colour: we use this in wxToolBar
182 // and wxStatusBar to have correct bg colour under Windows XP
183 // (which uses COLOR_MENUBAR for them) but they should still look
184 // correctly under previous Windows versions as well
185 if ( index == wxSYS_COLOUR_MENUBAR )
186 {
187 index = wxSYS_COLOUR_3DFACE;
188 }
189 else // replace with default colour
190 {
d285d708 191 unsigned int n = index - wxSYS_COLOUR_BTNHIGHLIGHT;
7d6d3bf3
VZ
192
193 wxASSERT_MSG( n < WXSIZEOF(s_defaultSysColors),
194 _T("forgot tp update the default colours array") );
195
196 colSys = s_defaultSysColors[n];
57f4f925 197 hasCol = true;
7d6d3bf3
VZ
198 }
199 }
200 }
201
202 if ( !hasCol )
203 {
39d2f9a7
JS
204#ifdef __WXWINCE__
205 colSys = ::GetSysColor(index|SYS_COLOR_INDEX_FLAG);
206#else
7d6d3bf3 207 colSys = ::GetSysColor(index);
39d2f9a7 208#endif
7d6d3bf3
VZ
209 }
210
211 return wxRGBToColour(colSys);
2bda0e17
KB
212}
213
7516ed26
VZ
214// ----------------------------------------------------------------------------
215// fonts
216// ----------------------------------------------------------------------------
217
04ef50df 218wxFont wxCreateFontFromStockObject(int index)
2bda0e17 219{
8bf30fe9
VZ
220 wxFont font;
221
019a60d6 222 HFONT hFont = (HFONT) ::GetStockObject(index);
8bf30fe9 223 if ( hFont )
019a60d6
VS
224 {
225 LOGFONT lf;
226 if ( ::GetObject(hFont, sizeof(LOGFONT), &lf) != 0 )
227 {
04ef50df
JS
228 wxNativeFontInfo info;
229 info.lf = lf;
f8c10795 230#ifndef __WXWINCE__
b4772c24
JS
231 // We want Windows 2000 or later to have new fonts even MS Shell Dlg
232 // is returned as default GUI font for compatibility
233 int verMaj;
406d283a 234 if(index == DEFAULT_GUI_FONT && wxGetOsVersion(&verMaj) == wxOS_WINDOWS_NT && verMaj >= 5)
b4772c24 235 wxStrcpy(info.lf.lfFaceName, wxT("MS Shell Dlg 2"));
f8c10795 236#endif
04ef50df
JS
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 {
8bf30fe9 248 wxFAIL_MSG( _T("failed to get LOGFONT") );
019a60d6
VS
249 }
250 }
8bf30fe9
VZ
251 else // GetStockObject() failed
252 {
253 wxFAIL_MSG( _T("stock font not found") );
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
270 return *gs_fontDefault;
271#else // !__WXWINCE__
46697f31 272 // wxWindow ctor calls GetFont(wxSYS_DEFAULT_GUI_FONT) so we're
553c5bcc
VZ
273 // called fairly often -- this is why we cache this particular font
274 const bool isDefaultRequested = index == wxSYS_DEFAULT_GUI_FONT;
275 if ( isDefaultRequested )
04ef50df 276 {
553c5bcc
VZ
277 if ( gs_fontDefault )
278 return *gs_fontDefault;
04ef50df
JS
279 }
280
281 wxFont font = wxCreateFontFromStockObject(index);
8bf30fe9
VZ
282
283 if ( isDefaultRequested )
019a60d6 284 {
8bf30fe9
VZ
285 // if we got here it means we hadn't cached it yet - do now
286 gs_fontDefault = new wxFont(font);
019a60d6 287 }
8bf30fe9
VZ
288
289 return font;
27adb8ba 290#endif // __WXWINCE__/!__WXWINCE__
2bda0e17
KB
291}
292
7516ed26
VZ
293// ----------------------------------------------------------------------------
294// system metrics/features
295// ----------------------------------------------------------------------------
296
297// TODO: some of the "metrics" clearly should be features now that we have
298// HasFeature()!
299
300// the conversion table from wxSystemMetric enum to GetSystemMetrics() param
301//
302// if the constant is not defined, put -1 in the table to indicate that it is
303// unknown
304static const int gs_metricsMap[] =
2bda0e17 305{
fc29e86e 306 -1, // wxSystemMetric enums start at 1, so give a dummy value for pos 0.
4676948b 307#if defined(__WIN32__) && !defined(__WXWINCE__)
7516ed26
VZ
308 SM_CMOUSEBUTTONS,
309#else
310 -1,
2bda0e17
KB
311#endif
312
7516ed26
VZ
313 SM_CXBORDER,
314 SM_CYBORDER,
c1dfa9eb 315#ifdef SM_CXCURSOR
9eddec69 316 SM_CXCURSOR,
7516ed26 317 SM_CYCURSOR,
c1dfa9eb 318#else
9eddec69 319 -1, -1,
c1dfa9eb 320#endif
7516ed26
VZ
321 SM_CXDOUBLECLK,
322 SM_CYDOUBLECLK,
2432b92d 323#if defined(__WIN32__) && defined(SM_CXDRAG)
7516ed26
VZ
324 SM_CXDRAG,
325 SM_CYDRAG,
326 SM_CXEDGE,
327 SM_CYEDGE,
328#else
4676948b 329 -1, -1, -1, -1,
2bda0e17 330#endif
7516ed26
VZ
331 SM_CXHSCROLL,
332 SM_CYHSCROLL,
4676948b 333#ifdef SM_CXHTHUMB
7516ed26 334 SM_CXHTHUMB,
4676948b
JS
335#else
336 -1,
337#endif
7516ed26
VZ
338 SM_CXICON,
339 SM_CYICON,
340 SM_CXICONSPACING,
341 SM_CYICONSPACING,
4676948b 342#ifdef SM_CXHTHUMB
7516ed26
VZ
343 SM_CXMIN,
344 SM_CYMIN,
4676948b
JS
345#else
346 -1, -1,
347#endif
7516ed26
VZ
348 SM_CXSCREEN,
349 SM_CYSCREEN,
2432b92d
JS
350
351#if defined(__WIN32__) && defined(SM_CXSIZEFRAME)
7516ed26
VZ
352 SM_CXSIZEFRAME,
353 SM_CYSIZEFRAME,
354 SM_CXSMICON,
355 SM_CYSMICON,
356#else
4676948b 357 -1, -1, -1, -1,
2bda0e17 358#endif
7516ed26 359 SM_CYHSCROLL,
5573f5b8 360 SM_CXHSCROLL,
7516ed26
VZ
361 SM_CXVSCROLL,
362 SM_CYVSCROLL,
4676948b 363#ifdef SM_CYVTHUMB
7516ed26 364 SM_CYVTHUMB,
4676948b
JS
365#else
366 -1,
367#endif
7516ed26
VZ
368 SM_CYCAPTION,
369 SM_CYMENU,
2432b92d 370#if defined(__WIN32__) && defined(SM_NETWORK)
7516ed26
VZ
371 SM_NETWORK,
372#else
373 -1,
2bda0e17 374#endif
4676948b 375#ifdef SM_PENWINDOWS
7516ed26 376 SM_PENWINDOWS,
4676948b
JS
377#else
378 -1,
379#endif
2432b92d 380#if defined(__WIN32__) && defined(SM_SHOWSOUNDS)
7516ed26
VZ
381 SM_SHOWSOUNDS,
382#else
383 -1,
2bda0e17 384#endif
d9fda37b
VZ
385 // SM_SWAPBUTTON is not available under CE and it doesn't make sense to ask
386 // for it there
387#ifdef SM_SWAPBUTTON
7516ed26 388 SM_SWAPBUTTON,
d9fda37b
VZ
389#else
390 -1,
391#endif
5595181f 392 -1 // wxSYS_DCLICK_MSEC - not available as system metric
7516ed26
VZ
393};
394
395// Get a system metric, e.g. scrollbar size
9b0b5ba7 396int wxSystemSettingsNative::GetMetric(wxSystemMetric index, wxWindow* WXUNUSED(win))
7516ed26
VZ
397{
398#ifdef __WXMICROWIN__
399 // TODO: probably use wxUniv themes functionality
400 return 0;
401#else // !__WXMICROWIN__
68d95db4
VZ
402 wxCHECK_MSG( index > 0 && (size_t)index < WXSIZEOF(gs_metricsMap), 0,
403 _T("invalid metric") );
7516ed26 404
5595181f
VZ
405 if ( index == wxSYS_DCLICK_MSEC )
406 {
407 // This one is not a Win32 system metric
408 return ::GetDoubleClickTime();
409 }
410
7516ed26
VZ
411 int indexMSW = gs_metricsMap[index];
412 if ( indexMSW == -1 )
413 {
414 // not supported under current system
1d451c5b 415 return -1;
019a60d6 416 }
7516ed26
VZ
417
418 int rc = ::GetSystemMetrics(indexMSW);
419 if ( index == wxSYS_NETWORK_PRESENT )
420 {
421 // only the last bit is significant according to the MSDN
422 rc &= 1;
423 }
424
425 return rc;
426#endif // __WXMICROWIN__/!__WXMICROWIN__
2bda0e17
KB
427}
428
7516ed26 429bool wxSystemSettingsNative::HasFeature(wxSystemFeature index)
253293c1 430{
7516ed26 431 switch ( index )
253293c1 432 {
7516ed26 433 case wxSYS_CAN_ICONIZE_FRAME:
253293c1 434 case wxSYS_CAN_DRAW_FRAME_DECORATIONS:
57f4f925 435 return true;
7516ed26 436
ddec9f1e
JS
437 case wxSYS_TABLET_PRESENT:
438 return ::GetSystemMetrics(SM_TABLETPC) != 0;
439
253293c1 440 default:
7516ed26
VZ
441 wxFAIL_MSG( _T("unknown system feature") );
442
57f4f925 443 return false;
253293c1
VS
444 }
445}
553c5bcc
VZ
446
447// ----------------------------------------------------------------------------
448// function from wx/msw/wrapcctl.h: there is really no other place for it...
449// ----------------------------------------------------------------------------
450
451#if wxUSE_LISTCTRL || wxUSE_TREECTRL
452
453extern wxFont wxGetCCDefaultFont()
454{
455#ifndef __WXWINCE__
456 // under the systems enumerated below (anything released after Win98), the
457 // default font used for the common controls seems to be the desktop font
458 // which is also used for the icon titles and not the stock default GUI
459 // font
460 bool useIconFont;
461 int verMaj, verMin;
462 switch ( wxGetOsVersion(&verMaj, &verMin) )
463 {
406d283a 464 case wxOS_WINDOWS_9X:
553c5bcc 465 // 4.10 is Win98
b594d7f7 466 useIconFont = verMaj == 4 && verMin >= 10;
553c5bcc
VZ
467 break;
468
406d283a 469 case wxOS_WINDOWS_NT:
553c5bcc
VZ
470 // 5.0 is Win2k
471 useIconFont = verMaj >= 5;
472 break;
473
474 default:
475 useIconFont = false;
476 }
477
478 if ( useIconFont )
479 {
480 LOGFONT lf;
481 if ( ::SystemParametersInfo
482 (
483 SPI_GETICONTITLELOGFONT,
484 sizeof(lf),
485 &lf,
486 0
487 ) )
488 {
489 return wxFont(wxCreateFontFromLogFont(&lf));
490 }
491 else
492 {
493 wxLogLastError(_T("SystemParametersInfo(SPI_GETICONTITLELOGFONT"));
494 }
495 }
496#endif // __WXWINCE__
497
498 // fall back to the default font for the normal controls
499 return wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
500}
501
502#endif // wxUSE_LISTCTRL || wxUSE_TREECTRL