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"
29 #include "wx/gdicmn.h"
32 #include "wx/settings.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 #ifdef __WXWINCE__ // for SM_CXCURSOR and SM_CYCURSOR
44 #include "wx/msw/wince/missing.h"
47 // ----------------------------------------------------------------------------
49 // ----------------------------------------------------------------------------
51 // the module which is used to clean up wxSystemSettingsNative data (this is a
52 // singleton class so it can't be done in the dtor)
53 class wxSystemSettingsModule
: public wxModule
56 virtual bool OnInit();
57 virtual void OnExit();
60 DECLARE_DYNAMIC_CLASS(wxSystemSettingsModule
)
63 // ----------------------------------------------------------------------------
65 // ----------------------------------------------------------------------------
67 // the font returned by GetFont(wxSYS_DEFAULT_GUI_FONT): it is created when
68 // GetFont() is called for the first time and deleted by wxSystemSettingsModule
69 static wxFont
*gs_fontDefault
= NULL
;
71 // ============================================================================
73 // ============================================================================
75 // TODO: see ::SystemParametersInfo for all sorts of Windows settings.
76 // Different args are required depending on the id. How does this differ
77 // from GetSystemMetric, and should it? Perhaps call it GetSystemParameter
78 // and pass an optional void* arg to get further info.
79 // Should also have SetSystemParameter.
80 // Also implement WM_WININICHANGE (NT) / WM_SETTINGCHANGE (Win95)
82 // ----------------------------------------------------------------------------
83 // wxSystemSettingsModule
84 // ----------------------------------------------------------------------------
86 IMPLEMENT_DYNAMIC_CLASS(wxSystemSettingsModule
, wxModule
)
88 bool wxSystemSettingsModule::OnInit()
93 void wxSystemSettingsModule::OnExit()
95 delete gs_fontDefault
;
96 gs_fontDefault
= NULL
;
99 // ----------------------------------------------------------------------------
100 // wxSystemSettingsNative
101 // ----------------------------------------------------------------------------
103 // ----------------------------------------------------------------------------
105 // ----------------------------------------------------------------------------
107 wxColour
wxSystemSettingsNative::GetColour(wxSystemColour index
)
109 // we use 0 as the default value just to avoid compiler warnings, as there
110 // is no invalid colour value we use hasCol as the real indicator of
111 // whether colSys was initialized or not
115 // the default colours for the entries after BTNHIGHLIGHT
116 static const COLORREF s_defaultSysColors
[] =
118 0x000000, // 3DDKSHADOW
120 0x000000, // INFOTEXT
123 0, // filler - no std colour with this index
125 // TODO: please fill in the standard values of those, I don't have them
127 0, // GRADIENTACTIVECAPTION
128 0, // GRADIENTINACTIVECAPTION
130 0, // MENUBAR (unused)
133 if ( index
== wxSYS_COLOUR_LISTBOX
)
135 // there is no standard colour with this index, map to another one
136 index
= wxSYS_COLOUR_WINDOW
;
138 else if ( index
> wxSYS_COLOUR_BTNHIGHLIGHT
)
140 // the indices before BTNHIGHLIGHT are understood by GetSysColor() in
141 // all Windows version, for the other ones we have to check
145 wxGetOsVersion(&verMaj
, &verMin
);
151 else if ( verMaj
== 4 )
154 useDefault
= index
> wxSYS_COLOUR_INFOBK
;
156 else if ( verMaj
== 5 && verMin
== 0 )
159 useDefault
= index
> wxSYS_COLOUR_GRADIENTINACTIVECAPTION
;
165 // Determine if we are using flat menus, only then allow wxSYS_COLOUR_MENUBAR
166 if ( index
== wxSYS_COLOUR_MENUBAR
)
169 if ( SystemParametersInfo( SPI_GETFLATMENU
, 0 ,&isFlat
, 0 ) )
172 index
= wxSYS_COLOUR_MENU
;
179 // special handling for MENUBAR colour: we use this in wxToolBar
180 // and wxStatusBar to have correct bg colour under Windows XP
181 // (which uses COLOR_MENUBAR for them) but they should still look
182 // correctly under previous Windows versions as well
183 if ( index
== wxSYS_COLOUR_MENUBAR
)
185 index
= wxSYS_COLOUR_3DFACE
;
187 else // replace with default colour
189 unsigned int n
= index
- wxSYS_COLOUR_BTNHIGHLIGHT
;
191 wxASSERT_MSG( n
< WXSIZEOF(s_defaultSysColors
),
192 _T("forgot tp update the default colours array") );
194 colSys
= s_defaultSysColors
[n
];
203 colSys
= ::GetSysColor(index
|SYS_COLOR_INDEX_FLAG
);
205 colSys
= ::GetSysColor(index
);
209 return wxRGBToColour(colSys
);
212 // ----------------------------------------------------------------------------
214 // ----------------------------------------------------------------------------
216 wxFont
wxCreateFontFromStockObject(int index
)
220 HFONT hFont
= (HFONT
) ::GetStockObject(index
);
224 if ( ::GetObject(hFont
, sizeof(LOGFONT
), &lf
) != 0 )
226 wxNativeFontInfo info
;
229 // We want Windows 2000 or later to have new fonts even MS Shell Dlg
230 // is returned as default GUI font for compatibility
232 if(index
== DEFAULT_GUI_FONT
&& wxGetOsVersion(&verMaj
) == wxWINDOWS_NT
&& verMaj
>= 5)
233 wxStrcpy(info
.lf
.lfFaceName
, wxT("MS Shell Dlg 2"));
235 // Under MicroWindows we pass the HFONT as well
236 // because it's hard to convert HFONT -> LOGFONT -> HFONT
237 // It's OK to delete stock objects, the delete will be ignored.
238 #ifdef __WXMICROWIN__
239 font
.Create(info
, (WXHFONT
) hFont
);
246 wxFAIL_MSG( _T("failed to get LOGFONT") );
249 else // GetStockObject() failed
251 wxFAIL_MSG( _T("stock font not found") );
257 wxFont
wxSystemSettingsNative::GetFont(wxSystemFont index
)
260 // under CE only a single SYSTEM_FONT exists
263 if ( !gs_fontDefault
)
265 gs_fontDefault
= new wxFont(wxCreateFontFromStockObject(SYSTEM_FONT
));
268 return *gs_fontDefault
;
269 #else // !__WXWINCE__
270 // wxWindow ctor calls GetFont(wxSYS_DEFAULT_GUI_FONT) so we're
271 // called fairly often -- this is why we cache this particular font
272 const bool isDefaultRequested
= index
== wxSYS_DEFAULT_GUI_FONT
;
273 if ( isDefaultRequested
)
275 if ( gs_fontDefault
)
276 return *gs_fontDefault
;
279 wxFont font
= wxCreateFontFromStockObject(index
);
281 if ( isDefaultRequested
)
283 // if we got here it means we hadn't cached it yet - do now
284 gs_fontDefault
= new wxFont(font
);
288 #endif // __WXWINCE__/!__WXWINCE__
291 // ----------------------------------------------------------------------------
292 // system metrics/features
293 // ----------------------------------------------------------------------------
295 // TODO: some of the "metrics" clearly should be features now that we have
298 // the conversion table from wxSystemMetric enum to GetSystemMetrics() param
300 // if the constant is not defined, put -1 in the table to indicate that it is
302 static const int gs_metricsMap
[] =
304 -1, // wxSystemMetric enums start at 1, so give a dummy value for pos 0.
305 #if defined(__WIN32__) && !defined(__WXWINCE__)
317 #if defined(__WIN32__) && defined(SM_CXDRAG)
345 #if defined(__WIN32__) && defined(SM_CXSIZEFRAME)
364 #if defined(__WIN32__) && defined(SM_NETWORK)
374 #if defined(__WIN32__) && defined(SM_SHOWSOUNDS)
386 // Get a system metric, e.g. scrollbar size
387 int wxSystemSettingsNative::GetMetric(wxSystemMetric index
, wxWindow
* WXUNUSED(win
))
389 #ifdef __WXMICROWIN__
390 // TODO: probably use wxUniv themes functionality
392 #else // !__WXMICROWIN__
393 wxCHECK_MSG( index
> 0 && (size_t)index
< WXSIZEOF(gs_metricsMap
), 0,
394 _T("invalid metric") );
396 int indexMSW
= gs_metricsMap
[index
];
397 if ( indexMSW
== -1 )
399 // not supported under current system
403 int rc
= ::GetSystemMetrics(indexMSW
);
404 if ( index
== wxSYS_NETWORK_PRESENT
)
406 // only the last bit is significant according to the MSDN
411 #endif // __WXMICROWIN__/!__WXMICROWIN__
414 bool wxSystemSettingsNative::HasFeature(wxSystemFeature index
)
418 case wxSYS_CAN_ICONIZE_FRAME
:
419 case wxSYS_CAN_DRAW_FRAME_DECORATIONS
:
423 wxFAIL_MSG( _T("unknown system feature") );
429 // ----------------------------------------------------------------------------
430 // function from wx/msw/wrapcctl.h: there is really no other place for it...
431 // ----------------------------------------------------------------------------
433 #if wxUSE_LISTCTRL || wxUSE_TREECTRL
435 extern wxFont
wxGetCCDefaultFont()
438 // under the systems enumerated below (anything released after Win98), the
439 // default font used for the common controls seems to be the desktop font
440 // which is also used for the icon titles and not the stock default GUI
444 switch ( wxGetOsVersion(&verMaj
, &verMin
) )
448 useIconFont
= verMaj
== 4 && verMin
>= 10;
453 useIconFont
= verMaj
>= 5;
463 if ( ::SystemParametersInfo
465 SPI_GETICONTITLELOGFONT
,
471 return wxFont(wxCreateFontFromLogFont(&lf
));
475 wxLogLastError(_T("SystemParametersInfo(SPI_GETICONTITLELOGFONT"));
478 #endif // __WXWINCE__
480 // fall back to the default font for the normal controls
481 return wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
484 #endif // wxUSE_LISTCTRL || wxUSE_TREECTRL