1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/settings.cpp
3 // Purpose: wxSystemSettingsNative implementation for MSW
4 // Author: Julian Smart
7 // Copyright: (c) Julian Smart
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // ============================================================================
13 // ============================================================================
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
19 // For compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
26 #include "wx/settings.h"
30 #include "wx/gdicmn.h"
31 #include "wx/module.h"
34 #include "wx/msw/private.h"
35 #include "wx/msw/missing.h" // for SM_CXCURSOR, SM_CYCURSOR, SM_TABLETPC
36 #include "wx/msw/private/metrics.h"
38 #ifndef SPI_GETFLATMENU
39 #define SPI_GETFLATMENU 0x1022
42 #include "wx/fontutil.h"
43 #include "wx/fontenum.h"
45 // ----------------------------------------------------------------------------
47 // ----------------------------------------------------------------------------
49 // the module which is used to clean up wxSystemSettingsNative data (this is a
50 // singleton class so it can't be done in the dtor)
51 class wxSystemSettingsModule
: public wxModule
54 virtual bool OnInit();
55 virtual void OnExit();
58 DECLARE_DYNAMIC_CLASS(wxSystemSettingsModule
)
61 // ----------------------------------------------------------------------------
63 // ----------------------------------------------------------------------------
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
67 static wxFont
*gs_fontDefault
= NULL
;
69 // ============================================================================
71 // ============================================================================
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)
80 // ----------------------------------------------------------------------------
81 // wxSystemSettingsModule
82 // ----------------------------------------------------------------------------
84 IMPLEMENT_DYNAMIC_CLASS(wxSystemSettingsModule
, wxModule
)
86 bool wxSystemSettingsModule::OnInit()
91 void wxSystemSettingsModule::OnExit()
93 wxDELETE(gs_fontDefault
);
96 // ----------------------------------------------------------------------------
97 // wxSystemSettingsNative
98 // ----------------------------------------------------------------------------
100 // ----------------------------------------------------------------------------
102 // ----------------------------------------------------------------------------
104 wxColour
wxSystemSettingsNative::GetColour(wxSystemColour index
)
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
112 // the default colours for the entries after BTNHIGHLIGHT
113 static const COLORREF s_defaultSysColors
[] =
115 0x000000, // 3DDKSHADOW
117 0x000000, // INFOTEXT
120 0, // filler - no std colour with this index
122 // TODO: please fill in the standard values of those, I don't have them
124 0, // GRADIENTACTIVECAPTION
125 0, // GRADIENTINACTIVECAPTION
127 0, // MENUBAR (unused)
130 if ( index
== wxSYS_COLOUR_LISTBOXTEXT
)
132 // there is no standard colour with this index, map to another one
133 index
= wxSYS_COLOUR_WINDOWTEXT
;
135 else if ( index
== wxSYS_COLOUR_LISTBOXHIGHLIGHTTEXT
)
137 // there is no standard colour with this index, map to another one
138 index
= wxSYS_COLOUR_HIGHLIGHTTEXT
;
140 else if ( index
== wxSYS_COLOUR_LISTBOX
)
142 // there is no standard colour with this index, map to another one
143 index
= wxSYS_COLOUR_WINDOW
;
145 else if ( index
> wxSYS_COLOUR_BTNHIGHLIGHT
)
147 // the indices before BTNHIGHLIGHT are understood by GetSysColor() in
148 // all Windows version, for the other ones we have to check
152 wxGetOsVersion(&verMaj
, &verMin
);
158 else if ( verMaj
== 4 )
161 useDefault
= index
> wxSYS_COLOUR_INFOBK
;
163 else if ( verMaj
== 5 && verMin
== 0 )
166 useDefault
= index
> wxSYS_COLOUR_GRADIENTINACTIVECAPTION
;
172 // Determine if we are using flat menus, only then allow wxSYS_COLOUR_MENUBAR
173 if ( index
== wxSYS_COLOUR_MENUBAR
)
176 if ( SystemParametersInfo( SPI_GETFLATMENU
, 0 ,&isFlat
, 0 ) )
179 index
= wxSYS_COLOUR_MENU
;
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
)
192 index
= wxSYS_COLOUR_3DFACE
;
194 else // replace with default colour
196 unsigned int n
= index
- wxSYS_COLOUR_BTNHIGHLIGHT
;
198 wxASSERT_MSG( n
< WXSIZEOF(s_defaultSysColors
),
199 wxT("forgot tp update the default colours array") );
201 colSys
= s_defaultSysColors
[n
];
210 colSys
= ::GetSysColor(index
|SYS_COLOR_INDEX_FLAG
);
212 colSys
= ::GetSysColor(index
);
216 wxColour ret
= wxRGBToColour(colSys
);
217 wxASSERT(ret
.IsOk());
221 // ----------------------------------------------------------------------------
223 // ----------------------------------------------------------------------------
225 wxFont
wxCreateFontFromStockObject(int index
)
229 HFONT hFont
= (HFONT
) ::GetStockObject(index
);
233 if ( ::GetObject(hFont
, sizeof(LOGFONT
), &lf
) != 0 )
235 wxNativeFontInfo info
;
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
);
248 wxFAIL_MSG( wxT("failed to get LOGFONT") );
251 else // GetStockObject() failed
253 wxFAIL_MSG( wxT("stock font not found") );
259 wxFont
wxSystemSettingsNative::GetFont(wxSystemFont index
)
262 // under CE only a single SYSTEM_FONT exists
265 if ( !gs_fontDefault
)
267 gs_fontDefault
= new wxFont(wxCreateFontFromStockObject(SYSTEM_FONT
));
270 wxASSERT(gs_fontDefault
->IsOk() &&
271 wxFontEnumerator::IsValidFacename(gs_fontDefault
->GetFaceName()));
272 return *gs_fontDefault
;
273 #else // !__WXWINCE__
274 // wxWindow ctor calls GetFont(wxSYS_DEFAULT_GUI_FONT) so we're
275 // called fairly often -- this is why we cache this particular font
276 if ( index
== wxSYS_DEFAULT_GUI_FONT
)
278 if ( !gs_fontDefault
)
280 // http://blogs.msdn.com/oldnewthing/archive/2005/07/07/436435.aspx
281 // explains why neither SYSTEM_FONT nor DEFAULT_GUI_FONT should be
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
);
293 return *gs_fontDefault
;
296 wxFont font
= wxCreateFontFromStockObject(index
);
298 wxASSERT(font
.IsOk());
301 wxASSERT(wxFontEnumerator::IsValidFacename(font
.GetFaceName()));
302 #endif // wxUSE_FONTENUM
305 #endif // __WXWINCE__/!__WXWINCE__
308 // ----------------------------------------------------------------------------
309 // system metrics/features
310 // ----------------------------------------------------------------------------
312 // TODO: some of the "metrics" clearly should be features now that we have
315 // the conversion table from wxSystemMetric enum to GetSystemMetrics() param
317 // if the constant is not defined, put -1 in the table to indicate that it is
319 static const int gs_metricsMap
[] =
321 -1, // wxSystemMetric enums start at 1, so give a dummy value for pos 0.
322 #if defined(__WIN32__) && !defined(__WXWINCE__)
338 #if defined(__WIN32__) && defined(SM_CXDRAG)
366 #if defined(__WIN32__) && defined(SM_CXSIZEFRAME)
385 #if defined(__WIN32__) && defined(SM_NETWORK)
395 #if defined(__WIN32__) && defined(SM_SHOWSOUNDS)
400 // SM_SWAPBUTTON is not available under CE and it doesn't make sense to ask
407 -1 // wxSYS_DCLICK_MSEC - not available as system metric
410 // Get a system metric, e.g. scrollbar size
411 int wxSystemSettingsNative::GetMetric(wxSystemMetric index
, wxWindow
* WXUNUSED(win
))
413 #ifdef __WXMICROWIN__
414 // TODO: probably use wxUniv themes functionality
416 #else // !__WXMICROWIN__
417 wxCHECK_MSG( index
> 0 && (size_t)index
< WXSIZEOF(gs_metricsMap
), 0,
418 wxT("invalid metric") );
420 if ( index
== wxSYS_DCLICK_MSEC
)
422 // This one is not a Win32 system metric
423 return ::GetDoubleClickTime();
426 int indexMSW
= gs_metricsMap
[index
];
427 if ( indexMSW
== -1 )
429 // not supported under current system
433 int rc
= ::GetSystemMetrics(indexMSW
);
434 if ( index
== wxSYS_NETWORK_PRESENT
)
436 // only the last bit is significant according to the MSDN
441 #endif // __WXMICROWIN__/!__WXMICROWIN__
444 bool wxSystemSettingsNative::HasFeature(wxSystemFeature index
)
448 case wxSYS_CAN_ICONIZE_FRAME
:
449 case wxSYS_CAN_DRAW_FRAME_DECORATIONS
:
452 case wxSYS_TABLET_PRESENT
:
453 return ::GetSystemMetrics(SM_TABLETPC
) != 0;
456 wxFAIL_MSG( wxT("unknown system feature") );
462 // ----------------------------------------------------------------------------
463 // function from wx/msw/wrapcctl.h: there is really no other place for it...
464 // ----------------------------------------------------------------------------
466 #if wxUSE_LISTCTRL || wxUSE_TREECTRL
468 extern wxFont
wxGetCCDefaultFont()
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
477 switch ( wxGetOsVersion(&verMaj
, &verMin
) )
479 case wxOS_WINDOWS_9X
:
481 useIconFont
= verMaj
== 4 && verMin
>= 10;
484 case wxOS_WINDOWS_NT
:
486 useIconFont
= verMaj
>= 5;
496 if ( ::SystemParametersInfo
498 SPI_GETICONTITLELOGFONT
,
504 return wxFont(wxCreateFontFromLogFont(&lf
));
508 wxLogLastError(wxT("SystemParametersInfo(SPI_GETICONTITLELOGFONT"));
511 #endif // __WXWINCE__
513 // fall back to the default font for the normal controls
514 return wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
517 #endif // wxUSE_LISTCTRL || wxUSE_TREECTRL