1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/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"
32 #include "wx/module.h"
35 #include "wx/msw/private.h"
36 #include "wx/msw/missing.h" // for SM_CXCURSOR, SM_CYCURSOR, SM_TABLETPC
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 delete gs_fontDefault
;
94 gs_fontDefault
= NULL
;
97 // ----------------------------------------------------------------------------
98 // wxSystemSettingsNative
99 // ----------------------------------------------------------------------------
101 // ----------------------------------------------------------------------------
103 // ----------------------------------------------------------------------------
105 wxColour
wxSystemSettingsNative::GetColour(wxSystemColour index
)
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
113 // the default colours for the entries after BTNHIGHLIGHT
114 static const COLORREF s_defaultSysColors
[] =
116 0x000000, // 3DDKSHADOW
118 0x000000, // INFOTEXT
121 0, // filler - no std colour with this index
123 // TODO: please fill in the standard values of those, I don't have them
125 0, // GRADIENTACTIVECAPTION
126 0, // GRADIENTINACTIVECAPTION
128 0, // MENUBAR (unused)
131 if ( index
== wxSYS_COLOUR_LISTBOXTEXT
)
133 // there is no standard colour with this index, map to another one
134 index
= wxSYS_COLOUR_WINDOWTEXT
;
136 else if ( index
== wxSYS_COLOUR_LISTBOX
)
138 // there is no standard colour with this index, map to another one
139 index
= wxSYS_COLOUR_WINDOW
;
141 else if ( index
> wxSYS_COLOUR_BTNHIGHLIGHT
)
143 // the indices before BTNHIGHLIGHT are understood by GetSysColor() in
144 // all Windows version, for the other ones we have to check
148 wxGetOsVersion(&verMaj
, &verMin
);
154 else if ( verMaj
== 4 )
157 useDefault
= index
> wxSYS_COLOUR_INFOBK
;
159 else if ( verMaj
== 5 && verMin
== 0 )
162 useDefault
= index
> wxSYS_COLOUR_GRADIENTINACTIVECAPTION
;
168 // Determine if we are using flat menus, only then allow wxSYS_COLOUR_MENUBAR
169 if ( index
== wxSYS_COLOUR_MENUBAR
)
172 if ( SystemParametersInfo( SPI_GETFLATMENU
, 0 ,&isFlat
, 0 ) )
175 index
= wxSYS_COLOUR_MENU
;
182 // special handling for MENUBAR colour: we use this in wxToolBar
183 // and wxStatusBar to have correct bg colour under Windows XP
184 // (which uses COLOR_MENUBAR for them) but they should still look
185 // correctly under previous Windows versions as well
186 if ( index
== wxSYS_COLOUR_MENUBAR
)
188 index
= wxSYS_COLOUR_3DFACE
;
190 else // replace with default colour
192 unsigned int n
= index
- wxSYS_COLOUR_BTNHIGHLIGHT
;
194 wxASSERT_MSG( n
< WXSIZEOF(s_defaultSysColors
),
195 _T("forgot tp update the default colours array") );
197 colSys
= s_defaultSysColors
[n
];
206 colSys
= ::GetSysColor(index
|SYS_COLOR_INDEX_FLAG
);
208 colSys
= ::GetSysColor(index
);
212 wxColour ret
= wxRGBToColour(colSys
);
213 wxASSERT(ret
.IsOk());
217 // ----------------------------------------------------------------------------
219 // ----------------------------------------------------------------------------
221 wxFont
wxCreateFontFromStockObject(int index
)
225 HFONT hFont
= (HFONT
) ::GetStockObject(index
);
229 if ( ::GetObject(hFont
, sizeof(LOGFONT
), &lf
) != 0 )
231 wxNativeFontInfo info
;
234 // We want Windows 2000 or later to have new fonts even MS Shell Dlg
235 // is returned as default GUI font for compatibility
237 if(index
== DEFAULT_GUI_FONT
&& wxGetOsVersion(&verMaj
) == wxOS_WINDOWS_NT
&& verMaj
>= 5)
238 wxStrcpy(info
.lf
.lfFaceName
, wxT("MS Shell Dlg 2"));
240 // Under MicroWindows we pass the HFONT as well
241 // because it's hard to convert HFONT -> LOGFONT -> HFONT
242 // It's OK to delete stock objects, the delete will be ignored.
243 #ifdef __WXMICROWIN__
244 font
.Create(info
, (WXHFONT
) hFont
);
251 wxFAIL_MSG( _T("failed to get LOGFONT") );
254 else // GetStockObject() failed
256 wxFAIL_MSG( _T("stock font not found") );
262 wxFont
wxSystemSettingsNative::GetFont(wxSystemFont index
)
265 // under CE only a single SYSTEM_FONT exists
268 if ( !gs_fontDefault
)
270 gs_fontDefault
= new wxFont(wxCreateFontFromStockObject(SYSTEM_FONT
));
273 wxASSERT(gs_fontDefault
->IsOk() &&
274 wxFontEnumerator::IsValidFacename(gs_fontDefault
->GetFaceName()));
275 return *gs_fontDefault
;
276 #else // !__WXWINCE__
277 // wxWindow ctor calls GetFont(wxSYS_DEFAULT_GUI_FONT) so we're
278 // called fairly often -- this is why we cache this particular font
279 const bool isDefaultRequested
= index
== wxSYS_DEFAULT_GUI_FONT
;
280 if ( isDefaultRequested
)
282 if ( gs_fontDefault
)
283 return *gs_fontDefault
;
286 wxFont font
= wxCreateFontFromStockObject(index
);
288 if ( isDefaultRequested
)
290 // if we got here it means we hadn't cached it yet - do now
291 gs_fontDefault
= new wxFont(font
);
294 wxASSERT(font
.IsOk() && wxFontEnumerator::IsValidFacename(font
.GetFaceName()));
296 #endif // __WXWINCE__/!__WXWINCE__
299 // ----------------------------------------------------------------------------
300 // system metrics/features
301 // ----------------------------------------------------------------------------
303 // TODO: some of the "metrics" clearly should be features now that we have
306 // the conversion table from wxSystemMetric enum to GetSystemMetrics() param
308 // if the constant is not defined, put -1 in the table to indicate that it is
310 static const int gs_metricsMap
[] =
312 -1, // wxSystemMetric enums start at 1, so give a dummy value for pos 0.
313 #if defined(__WIN32__) && !defined(__WXWINCE__)
329 #if defined(__WIN32__) && defined(SM_CXDRAG)
357 #if defined(__WIN32__) && defined(SM_CXSIZEFRAME)
376 #if defined(__WIN32__) && defined(SM_NETWORK)
386 #if defined(__WIN32__) && defined(SM_SHOWSOUNDS)
391 // SM_SWAPBUTTON is not available under CE and it doesn't make sense to ask
398 -1 // wxSYS_DCLICK_MSEC - not available as system metric
401 // Get a system metric, e.g. scrollbar size
402 int wxSystemSettingsNative::GetMetric(wxSystemMetric index
, wxWindow
* WXUNUSED(win
))
404 #ifdef __WXMICROWIN__
405 // TODO: probably use wxUniv themes functionality
407 #else // !__WXMICROWIN__
408 wxCHECK_MSG( index
> 0 && (size_t)index
< WXSIZEOF(gs_metricsMap
), 0,
409 _T("invalid metric") );
411 if ( index
== wxSYS_DCLICK_MSEC
)
413 // This one is not a Win32 system metric
414 return ::GetDoubleClickTime();
417 int indexMSW
= gs_metricsMap
[index
];
418 if ( indexMSW
== -1 )
420 // not supported under current system
424 int rc
= ::GetSystemMetrics(indexMSW
);
425 if ( index
== wxSYS_NETWORK_PRESENT
)
427 // only the last bit is significant according to the MSDN
432 #endif // __WXMICROWIN__/!__WXMICROWIN__
435 bool wxSystemSettingsNative::HasFeature(wxSystemFeature index
)
439 case wxSYS_CAN_ICONIZE_FRAME
:
440 case wxSYS_CAN_DRAW_FRAME_DECORATIONS
:
443 case wxSYS_TABLET_PRESENT
:
444 return ::GetSystemMetrics(SM_TABLETPC
) != 0;
447 wxFAIL_MSG( _T("unknown system feature") );
453 // ----------------------------------------------------------------------------
454 // function from wx/msw/wrapcctl.h: there is really no other place for it...
455 // ----------------------------------------------------------------------------
457 #if wxUSE_LISTCTRL || wxUSE_TREECTRL
459 extern wxFont
wxGetCCDefaultFont()
462 // under the systems enumerated below (anything released after Win98), the
463 // default font used for the common controls seems to be the desktop font
464 // which is also used for the icon titles and not the stock default GUI
468 switch ( wxGetOsVersion(&verMaj
, &verMin
) )
470 case wxOS_WINDOWS_9X
:
472 useIconFont
= verMaj
== 4 && verMin
>= 10;
475 case wxOS_WINDOWS_NT
:
477 useIconFont
= verMaj
>= 5;
487 if ( ::SystemParametersInfo
489 SPI_GETICONTITLELOGFONT
,
495 return wxFont(wxCreateFontFromLogFont(&lf
));
499 wxLogLastError(_T("SystemParametersInfo(SPI_GETICONTITLELOGFONT"));
502 #endif // __WXWINCE__
504 // fall back to the default font for the normal controls
505 return wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
508 #endif // wxUSE_LISTCTRL || wxUSE_TREECTRL