1 /////////////////////////////////////////////////////////////////////////////
2 // Name: msw/settings.cpp
3 // Purpose: wxSystemSettingsNative implementation for MSW
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
27 #include "wx/settings.h"
31 #include "wx/gdicmn.h"
34 #include "wx/msw/private.h"
36 #ifndef SPI_GETFLATMENU
37 #define SPI_GETFLATMENU 0x1022
40 #include "wx/module.h"
41 #include "wx/fontutil.h"
43 // for SM_CXCURSOR, SM_CYCURSOR, SM_TABLETPC
44 #include "wx/msw/missing.h"
46 // ----------------------------------------------------------------------------
48 // ----------------------------------------------------------------------------
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)
52 class wxSystemSettingsModule
: public wxModule
55 virtual bool OnInit();
56 virtual void OnExit();
59 DECLARE_DYNAMIC_CLASS(wxSystemSettingsModule
)
62 // ----------------------------------------------------------------------------
64 // ----------------------------------------------------------------------------
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
68 static wxFont
*gs_fontDefault
= NULL
;
70 // ============================================================================
72 // ============================================================================
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)
81 // ----------------------------------------------------------------------------
82 // wxSystemSettingsModule
83 // ----------------------------------------------------------------------------
85 IMPLEMENT_DYNAMIC_CLASS(wxSystemSettingsModule
, wxModule
)
87 bool wxSystemSettingsModule::OnInit()
92 void wxSystemSettingsModule::OnExit()
94 delete gs_fontDefault
;
95 gs_fontDefault
= NULL
;
98 // ----------------------------------------------------------------------------
99 // wxSystemSettingsNative
100 // ----------------------------------------------------------------------------
102 // ----------------------------------------------------------------------------
104 // ----------------------------------------------------------------------------
106 wxColour
wxSystemSettingsNative::GetColour(wxSystemColour index
)
108 // we use 0 as the default value just to avoid compiler warnings, as there
109 // is no invalid colour value we use hasCol as the real indicator of
110 // whether colSys was initialized or not
114 // the default colours for the entries after BTNHIGHLIGHT
115 static const COLORREF s_defaultSysColors
[] =
117 0x000000, // 3DDKSHADOW
119 0x000000, // INFOTEXT
122 0, // filler - no std colour with this index
124 // TODO: please fill in the standard values of those, I don't have them
126 0, // GRADIENTACTIVECAPTION
127 0, // GRADIENTINACTIVECAPTION
129 0, // MENUBAR (unused)
132 if ( index
== wxSYS_COLOUR_LISTBOX
)
134 // there is no standard colour with this index, map to another one
135 index
= wxSYS_COLOUR_WINDOW
;
137 else if ( index
> wxSYS_COLOUR_BTNHIGHLIGHT
)
139 // the indices before BTNHIGHLIGHT are understood by GetSysColor() in
140 // all Windows version, for the other ones we have to check
144 wxGetOsVersion(&verMaj
, &verMin
);
150 else if ( verMaj
== 4 )
153 useDefault
= index
> wxSYS_COLOUR_INFOBK
;
155 else if ( verMaj
== 5 && verMin
== 0 )
158 useDefault
= index
> wxSYS_COLOUR_GRADIENTINACTIVECAPTION
;
164 // Determine if we are using flat menus, only then allow wxSYS_COLOUR_MENUBAR
165 if ( index
== wxSYS_COLOUR_MENUBAR
)
168 if ( SystemParametersInfo( SPI_GETFLATMENU
, 0 ,&isFlat
, 0 ) )
171 index
= wxSYS_COLOUR_MENU
;
178 // special handling for MENUBAR colour: we use this in wxToolBar
179 // and wxStatusBar to have correct bg colour under Windows XP
180 // (which uses COLOR_MENUBAR for them) but they should still look
181 // correctly under previous Windows versions as well
182 if ( index
== wxSYS_COLOUR_MENUBAR
)
184 index
= wxSYS_COLOUR_3DFACE
;
186 else // replace with default colour
188 unsigned int n
= index
- wxSYS_COLOUR_BTNHIGHLIGHT
;
190 wxASSERT_MSG( n
< WXSIZEOF(s_defaultSysColors
),
191 _T("forgot tp update the default colours array") );
193 colSys
= s_defaultSysColors
[n
];
202 colSys
= ::GetSysColor(index
|SYS_COLOR_INDEX_FLAG
);
204 colSys
= ::GetSysColor(index
);
208 return wxRGBToColour(colSys
);
211 // ----------------------------------------------------------------------------
213 // ----------------------------------------------------------------------------
215 wxFont
wxCreateFontFromStockObject(int index
)
219 HFONT hFont
= (HFONT
) ::GetStockObject(index
);
223 if ( ::GetObject(hFont
, sizeof(LOGFONT
), &lf
) != 0 )
225 wxNativeFontInfo info
;
228 // We want Windows 2000 or later to have new fonts even MS Shell Dlg
229 // is returned as default GUI font for compatibility
231 if(index
== DEFAULT_GUI_FONT
&& wxGetOsVersion(&verMaj
) == wxWINDOWS_NT
&& verMaj
>= 5)
232 wxStrcpy(info
.lf
.lfFaceName
, wxT("MS Shell Dlg 2"));
234 // Under MicroWindows we pass the HFONT as well
235 // because it's hard to convert HFONT -> LOGFONT -> HFONT
236 // It's OK to delete stock objects, the delete will be ignored.
237 #ifdef __WXMICROWIN__
238 font
.Create(info
, (WXHFONT
) hFont
);
245 wxFAIL_MSG( _T("failed to get LOGFONT") );
248 else // GetStockObject() failed
250 wxFAIL_MSG( _T("stock font not found") );
256 wxFont
wxSystemSettingsNative::GetFont(wxSystemFont index
)
259 // under CE only a single SYSTEM_FONT exists
262 if ( !gs_fontDefault
)
264 gs_fontDefault
= new wxFont(wxCreateFontFromStockObject(SYSTEM_FONT
));
267 return *gs_fontDefault
;
268 #else // !__WXWINCE__
269 // wxWindow ctor calls GetFont(wxSYS_DEFAULT_GUI_FONT) so we're
270 // called fairly often -- this is why we cache this particular font
271 const bool isDefaultRequested
= index
== wxSYS_DEFAULT_GUI_FONT
;
272 if ( isDefaultRequested
)
274 if ( gs_fontDefault
)
275 return *gs_fontDefault
;
278 wxFont font
= wxCreateFontFromStockObject(index
);
280 if ( isDefaultRequested
)
282 // if we got here it means we hadn't cached it yet - do now
283 gs_fontDefault
= new wxFont(font
);
287 #endif // __WXWINCE__/!__WXWINCE__
290 // ----------------------------------------------------------------------------
291 // system metrics/features
292 // ----------------------------------------------------------------------------
294 // TODO: some of the "metrics" clearly should be features now that we have
297 // the conversion table from wxSystemMetric enum to GetSystemMetrics() param
299 // if the constant is not defined, put -1 in the table to indicate that it is
301 static const int gs_metricsMap
[] =
303 -1, // wxSystemMetric enums start at 1, so give a dummy value for pos 0.
304 #if defined(__WIN32__) && !defined(__WXWINCE__)
320 #if defined(__WIN32__) && defined(SM_CXDRAG)
348 #if defined(__WIN32__) && defined(SM_CXSIZEFRAME)
367 #if defined(__WIN32__) && defined(SM_NETWORK)
377 #if defined(__WIN32__) && defined(SM_SHOWSOUNDS)
389 // Get a system metric, e.g. scrollbar size
390 int wxSystemSettingsNative::GetMetric(wxSystemMetric index
, wxWindow
* WXUNUSED(win
))
392 #ifdef __WXMICROWIN__
393 // TODO: probably use wxUniv themes functionality
395 #else // !__WXMICROWIN__
396 wxCHECK_MSG( index
> 0 && (size_t)index
< WXSIZEOF(gs_metricsMap
), 0,
397 _T("invalid metric") );
399 int indexMSW
= gs_metricsMap
[index
];
400 if ( indexMSW
== -1 )
402 // not supported under current system
406 int rc
= ::GetSystemMetrics(indexMSW
);
407 if ( index
== wxSYS_NETWORK_PRESENT
)
409 // only the last bit is significant according to the MSDN
414 #endif // __WXMICROWIN__/!__WXMICROWIN__
417 bool wxSystemSettingsNative::HasFeature(wxSystemFeature index
)
421 case wxSYS_CAN_ICONIZE_FRAME
:
422 case wxSYS_CAN_DRAW_FRAME_DECORATIONS
:
425 case wxSYS_TABLET_PRESENT
:
426 return ::GetSystemMetrics(SM_TABLETPC
) != 0;
429 wxFAIL_MSG( _T("unknown system feature") );
435 // ----------------------------------------------------------------------------
436 // function from wx/msw/wrapcctl.h: there is really no other place for it...
437 // ----------------------------------------------------------------------------
439 #if wxUSE_LISTCTRL || wxUSE_TREECTRL
441 extern wxFont
wxGetCCDefaultFont()
444 // under the systems enumerated below (anything released after Win98), the
445 // default font used for the common controls seems to be the desktop font
446 // which is also used for the icon titles and not the stock default GUI
450 switch ( wxGetOsVersion(&verMaj
, &verMin
) )
454 useIconFont
= verMaj
== 4 && verMin
>= 10;
459 useIconFont
= verMaj
>= 5;
469 if ( ::SystemParametersInfo
471 SPI_GETICONTITLELOGFONT
,
477 return wxFont(wxCreateFontFromLogFont(&lf
));
481 wxLogLastError(_T("SystemParametersInfo(SPI_GETICONTITLELOGFONT"));
484 #endif // __WXWINCE__
486 // fall back to the default font for the normal controls
487 return wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
490 #endif // wxUSE_LISTCTRL || wxUSE_TREECTRL