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 wxT("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( wxT("failed to get LOGFONT") );
254 else // GetStockObject() failed
256 wxFAIL_MSG( wxT("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());
297 wxASSERT(wxFontEnumerator::IsValidFacename(font
.GetFaceName()));
298 #endif // wxUSE_FONTENUM
301 #endif // __WXWINCE__/!__WXWINCE__
304 // ----------------------------------------------------------------------------
305 // system metrics/features
306 // ----------------------------------------------------------------------------
308 // TODO: some of the "metrics" clearly should be features now that we have
311 // the conversion table from wxSystemMetric enum to GetSystemMetrics() param
313 // if the constant is not defined, put -1 in the table to indicate that it is
315 static const int gs_metricsMap
[] =
317 -1, // wxSystemMetric enums start at 1, so give a dummy value for pos 0.
318 #if defined(__WIN32__) && !defined(__WXWINCE__)
334 #if defined(__WIN32__) && defined(SM_CXDRAG)
362 #if defined(__WIN32__) && defined(SM_CXSIZEFRAME)
381 #if defined(__WIN32__) && defined(SM_NETWORK)
391 #if defined(__WIN32__) && defined(SM_SHOWSOUNDS)
396 // SM_SWAPBUTTON is not available under CE and it doesn't make sense to ask
403 -1 // wxSYS_DCLICK_MSEC - not available as system metric
406 // Get a system metric, e.g. scrollbar size
407 int wxSystemSettingsNative::GetMetric(wxSystemMetric index
, wxWindow
* WXUNUSED(win
))
409 #ifdef __WXMICROWIN__
410 // TODO: probably use wxUniv themes functionality
412 #else // !__WXMICROWIN__
413 wxCHECK_MSG( index
> 0 && (size_t)index
< WXSIZEOF(gs_metricsMap
), 0,
414 wxT("invalid metric") );
416 if ( index
== wxSYS_DCLICK_MSEC
)
418 // This one is not a Win32 system metric
419 return ::GetDoubleClickTime();
422 int indexMSW
= gs_metricsMap
[index
];
423 if ( indexMSW
== -1 )
425 // not supported under current system
429 int rc
= ::GetSystemMetrics(indexMSW
);
430 if ( index
== wxSYS_NETWORK_PRESENT
)
432 // only the last bit is significant according to the MSDN
437 #endif // __WXMICROWIN__/!__WXMICROWIN__
440 bool wxSystemSettingsNative::HasFeature(wxSystemFeature index
)
444 case wxSYS_CAN_ICONIZE_FRAME
:
445 case wxSYS_CAN_DRAW_FRAME_DECORATIONS
:
448 case wxSYS_TABLET_PRESENT
:
449 return ::GetSystemMetrics(SM_TABLETPC
) != 0;
452 wxFAIL_MSG( wxT("unknown system feature") );
458 // ----------------------------------------------------------------------------
459 // function from wx/msw/wrapcctl.h: there is really no other place for it...
460 // ----------------------------------------------------------------------------
462 #if wxUSE_LISTCTRL || wxUSE_TREECTRL
464 extern wxFont
wxGetCCDefaultFont()
467 // under the systems enumerated below (anything released after Win98), the
468 // default font used for the common controls seems to be the desktop font
469 // which is also used for the icon titles and not the stock default GUI
473 switch ( wxGetOsVersion(&verMaj
, &verMin
) )
475 case wxOS_WINDOWS_9X
:
477 useIconFont
= verMaj
== 4 && verMin
>= 10;
480 case wxOS_WINDOWS_NT
:
482 useIconFont
= verMaj
>= 5;
492 if ( ::SystemParametersInfo
494 SPI_GETICONTITLELOGFONT
,
500 return wxFont(wxCreateFontFromLogFont(&lf
));
504 wxLogLastError(wxT("SystemParametersInfo(SPI_GETICONTITLELOGFONT"));
507 #endif // __WXWINCE__
509 // fall back to the default font for the normal controls
510 return wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
513 #endif // wxUSE_LISTCTRL || wxUSE_TREECTRL