]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/msw/settings.cpp
fixing osx_cocoa
[wxWidgets.git] / src / msw / settings.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/msw/settings.cpp
3// Purpose: wxSystemSettingsNative implementation for MSW
4// Author: Julian Smart
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
20// For compilers that support precompilation, includes "wx.h".
21#include "wx/wxprec.h"
22
23#ifdef __BORLANDC__
24 #pragma hdrstop
25#endif
26
27#include "wx/settings.h"
28
29#ifndef WX_PRECOMP
30 #include "wx/utils.h"
31 #include "wx/gdicmn.h"
32 #include "wx/module.h"
33#endif
34
35#include "wx/msw/private.h"
36#include "wx/msw/missing.h" // for SM_CXCURSOR, SM_CYCURSOR, SM_TABLETPC
37#include "wx/msw/private/metrics.h"
38
39#ifndef SPI_GETFLATMENU
40#define SPI_GETFLATMENU 0x1022
41#endif
42
43#include "wx/fontutil.h"
44#include "wx/fontenum.h"
45
46// ----------------------------------------------------------------------------
47// private classes
48// ----------------------------------------------------------------------------
49
50// the module which is used to clean up wxSystemSettingsNative data (this is a
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
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
68static wxFont *gs_fontDefault = NULL;
69
70// ============================================================================
71// implementation
72// ============================================================================
73
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
81// ----------------------------------------------------------------------------
82// wxSystemSettingsModule
83// ----------------------------------------------------------------------------
84
85IMPLEMENT_DYNAMIC_CLASS(wxSystemSettingsModule, wxModule)
86
87bool wxSystemSettingsModule::OnInit()
88{
89 return true;
90}
91
92void wxSystemSettingsModule::OnExit()
93{
94 wxDELETE(gs_fontDefault);
95}
96
97// ----------------------------------------------------------------------------
98// wxSystemSettingsNative
99// ----------------------------------------------------------------------------
100
101// ----------------------------------------------------------------------------
102// colours
103// ----------------------------------------------------------------------------
104
105wxColour wxSystemSettingsNative::GetColour(wxSystemColour index)
106{
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;
111 bool hasCol = false;
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
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 }
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 }
141 else if ( index == wxSYS_COLOUR_LISTBOX )
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
152 int verMaj, verMin;
153 wxGetOsVersion(&verMaj, &verMin);
154 if ( verMaj < 4 )
155 {
156 // NT 3.5
157 useDefault = true;
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
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 }
183 }
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 {
197 unsigned int n = index - wxSYS_COLOUR_BTNHIGHLIGHT;
198
199 wxASSERT_MSG( n < WXSIZEOF(s_defaultSysColors),
200 wxT("forgot tp update the default colours array") );
201
202 colSys = s_defaultSysColors[n];
203 hasCol = true;
204 }
205 }
206 }
207
208 if ( !hasCol )
209 {
210#ifdef __WXWINCE__
211 colSys = ::GetSysColor(index|SYS_COLOR_INDEX_FLAG);
212#else
213 colSys = ::GetSysColor(index);
214#endif
215 }
216
217 wxColour ret = wxRGBToColour(colSys);
218 wxASSERT(ret.IsOk());
219 return ret;
220}
221
222// ----------------------------------------------------------------------------
223// fonts
224// ----------------------------------------------------------------------------
225
226wxFont wxCreateFontFromStockObject(int index)
227{
228 wxFont font;
229
230 HFONT hFont = (HFONT) ::GetStockObject(index);
231 if ( hFont )
232 {
233 LOGFONT lf;
234 if ( ::GetObject(hFont, sizeof(LOGFONT), &lf) != 0 )
235 {
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
246 }
247 else
248 {
249 wxFAIL_MSG( wxT("failed to get LOGFONT") );
250 }
251 }
252 else // GetStockObject() failed
253 {
254 wxFAIL_MSG( wxT("stock font not found") );
255 }
256
257 return font;
258}
259
260wxFont wxSystemSettingsNative::GetFont(wxSystemFont index)
261{
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
271 wxASSERT(gs_fontDefault->IsOk() &&
272 wxFontEnumerator::IsValidFacename(gs_fontDefault->GetFaceName()));
273 return *gs_fontDefault;
274#else // !__WXWINCE__
275 // wxWindow ctor calls GetFont(wxSYS_DEFAULT_GUI_FONT) so we're
276 // called fairly often -- this is why we cache this particular font
277 if ( index == wxSYS_DEFAULT_GUI_FONT )
278 {
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;
295 }
296
297 wxFont font = wxCreateFontFromStockObject(index);
298
299 wxASSERT(font.IsOk());
300
301#if wxUSE_FONTENUM
302 wxASSERT(wxFontEnumerator::IsValidFacename(font.GetFaceName()));
303#endif // wxUSE_FONTENUM
304
305 return font;
306#endif // __WXWINCE__/!__WXWINCE__
307}
308
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[] =
321{
322 -1, // wxSystemMetric enums start at 1, so give a dummy value for pos 0.
323#if defined(__WIN32__) && !defined(__WXWINCE__)
324 SM_CMOUSEBUTTONS,
325#else
326 -1,
327#endif
328
329 SM_CXBORDER,
330 SM_CYBORDER,
331#ifdef SM_CXCURSOR
332 SM_CXCURSOR,
333 SM_CYCURSOR,
334#else
335 -1, -1,
336#endif
337 SM_CXDOUBLECLK,
338 SM_CYDOUBLECLK,
339#if defined(__WIN32__) && defined(SM_CXDRAG)
340 SM_CXDRAG,
341 SM_CYDRAG,
342 SM_CXEDGE,
343 SM_CYEDGE,
344#else
345 -1, -1, -1, -1,
346#endif
347 SM_CXHSCROLL,
348 SM_CYHSCROLL,
349#ifdef SM_CXHTHUMB
350 SM_CXHTHUMB,
351#else
352 -1,
353#endif
354 SM_CXICON,
355 SM_CYICON,
356 SM_CXICONSPACING,
357 SM_CYICONSPACING,
358#ifdef SM_CXHTHUMB
359 SM_CXMIN,
360 SM_CYMIN,
361#else
362 -1, -1,
363#endif
364 SM_CXSCREEN,
365 SM_CYSCREEN,
366
367#if defined(__WIN32__) && defined(SM_CXSIZEFRAME)
368 SM_CXSIZEFRAME,
369 SM_CYSIZEFRAME,
370 SM_CXSMICON,
371 SM_CYSMICON,
372#else
373 -1, -1, -1, -1,
374#endif
375 SM_CYHSCROLL,
376 SM_CXHSCROLL,
377 SM_CXVSCROLL,
378 SM_CYVSCROLL,
379#ifdef SM_CYVTHUMB
380 SM_CYVTHUMB,
381#else
382 -1,
383#endif
384 SM_CYCAPTION,
385 SM_CYMENU,
386#if defined(__WIN32__) && defined(SM_NETWORK)
387 SM_NETWORK,
388#else
389 -1,
390#endif
391#ifdef SM_PENWINDOWS
392 SM_PENWINDOWS,
393#else
394 -1,
395#endif
396#if defined(__WIN32__) && defined(SM_SHOWSOUNDS)
397 SM_SHOWSOUNDS,
398#else
399 -1,
400#endif
401 // SM_SWAPBUTTON is not available under CE and it doesn't make sense to ask
402 // for it there
403#ifdef SM_SWAPBUTTON
404 SM_SWAPBUTTON,
405#else
406 -1,
407#endif
408 -1 // wxSYS_DCLICK_MSEC - not available as system metric
409};
410
411// Get a system metric, e.g. scrollbar size
412int wxSystemSettingsNative::GetMetric(wxSystemMetric index, wxWindow* WXUNUSED(win))
413{
414#ifdef __WXMICROWIN__
415 // TODO: probably use wxUniv themes functionality
416 return 0;
417#else // !__WXMICROWIN__
418 wxCHECK_MSG( index > 0 && (size_t)index < WXSIZEOF(gs_metricsMap), 0,
419 wxT("invalid metric") );
420
421 if ( index == wxSYS_DCLICK_MSEC )
422 {
423 // This one is not a Win32 system metric
424 return ::GetDoubleClickTime();
425 }
426
427 int indexMSW = gs_metricsMap[index];
428 if ( indexMSW == -1 )
429 {
430 // not supported under current system
431 return -1;
432 }
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__
443}
444
445bool wxSystemSettingsNative::HasFeature(wxSystemFeature index)
446{
447 switch ( index )
448 {
449 case wxSYS_CAN_ICONIZE_FRAME:
450 case wxSYS_CAN_DRAW_FRAME_DECORATIONS:
451 return true;
452
453 case wxSYS_TABLET_PRESENT:
454 return ::GetSystemMetrics(SM_TABLETPC) != 0;
455
456 default:
457 wxFAIL_MSG( wxT("unknown system feature") );
458
459 return false;
460 }
461}
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 {
480 case wxOS_WINDOWS_9X:
481 // 4.10 is Win98
482 useIconFont = verMaj == 4 && verMin >= 10;
483 break;
484
485 case wxOS_WINDOWS_NT:
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 {
509 wxLogLastError(wxT("SystemParametersInfo(SPI_GETICONTITLELOGFONT"));
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