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"
44 // ----------------------------------------------------------------------------
46 // ----------------------------------------------------------------------------
48 // the module which is used to clean up wxSystemSettingsNative data (this is a
49 // singleton class so it can't be done in the dtor)
50 class wxSystemSettingsModule
: public wxModule
53 virtual bool OnInit();
54 virtual void OnExit();
57 DECLARE_DYNAMIC_CLASS(wxSystemSettingsModule
)
60 // ----------------------------------------------------------------------------
62 // ----------------------------------------------------------------------------
64 // the font returned by GetFont(wxSYS_DEFAULT_GUI_FONT): it is created when
65 // GetFont() is called for the first time and deleted by wxSystemSettingsModule
66 static wxFont
*gs_fontDefault
= NULL
;
68 // ============================================================================
70 // ============================================================================
72 // TODO: see ::SystemParametersInfo for all sorts of Windows settings.
73 // Different args are required depending on the id. How does this differ
74 // from GetSystemMetric, and should it? Perhaps call it GetSystemParameter
75 // and pass an optional void* arg to get further info.
76 // Should also have SetSystemParameter.
77 // Also implement WM_WININICHANGE (NT) / WM_SETTINGCHANGE (Win95)
79 // ----------------------------------------------------------------------------
80 // wxSystemSettingsModule
81 // ----------------------------------------------------------------------------
83 IMPLEMENT_DYNAMIC_CLASS(wxSystemSettingsModule
, wxModule
)
85 bool wxSystemSettingsModule::OnInit()
90 void wxSystemSettingsModule::OnExit()
92 delete gs_fontDefault
;
93 gs_fontDefault
= NULL
;
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_LISTBOX
)
137 // there is no standard colour with this index, map to another one
138 index
= wxSYS_COLOUR_WINDOW
;
140 else if ( index
> wxSYS_COLOUR_BTNHIGHLIGHT
)
142 // the indices before BTNHIGHLIGHT are understood by GetSysColor() in
143 // all Windows version, for the other ones we have to check
147 wxGetOsVersion(&verMaj
, &verMin
);
153 else if ( verMaj
== 4 )
156 useDefault
= index
> wxSYS_COLOUR_INFOBK
;
158 else if ( verMaj
== 5 && verMin
== 0 )
161 useDefault
= index
> wxSYS_COLOUR_GRADIENTINACTIVECAPTION
;
167 // Determine if we are using flat menus, only then allow wxSYS_COLOUR_MENUBAR
168 if ( index
== wxSYS_COLOUR_MENUBAR
)
171 if ( SystemParametersInfo( SPI_GETFLATMENU
, 0 ,&isFlat
, 0 ) )
174 index
= wxSYS_COLOUR_MENU
;
181 // special handling for MENUBAR colour: we use this in wxToolBar
182 // and wxStatusBar to have correct bg colour under Windows XP
183 // (which uses COLOR_MENUBAR for them) but they should still look
184 // correctly under previous Windows versions as well
185 if ( index
== wxSYS_COLOUR_MENUBAR
)
187 index
= wxSYS_COLOUR_3DFACE
;
189 else // replace with default colour
191 unsigned int n
= index
- wxSYS_COLOUR_BTNHIGHLIGHT
;
193 wxASSERT_MSG( n
< WXSIZEOF(s_defaultSysColors
),
194 _T("forgot tp update the default colours array") );
196 colSys
= s_defaultSysColors
[n
];
205 colSys
= ::GetSysColor(index
|SYS_COLOR_INDEX_FLAG
);
207 colSys
= ::GetSysColor(index
);
211 return wxRGBToColour(colSys
);
214 // ----------------------------------------------------------------------------
216 // ----------------------------------------------------------------------------
218 wxFont
wxCreateFontFromStockObject(int index
)
222 HFONT hFont
= (HFONT
) ::GetStockObject(index
);
226 if ( ::GetObject(hFont
, sizeof(LOGFONT
), &lf
) != 0 )
228 wxNativeFontInfo info
;
231 // We want Windows 2000 or later to have new fonts even MS Shell Dlg
232 // is returned as default GUI font for compatibility
234 if(index
== DEFAULT_GUI_FONT
&& wxGetOsVersion(&verMaj
) == wxOS_WINDOWS_NT
&& verMaj
>= 5)
235 wxStrcpy(info
.lf
.lfFaceName
, wxT("MS Shell Dlg 2"));
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( _T("failed to get LOGFONT") );
251 else // GetStockObject() failed
253 wxFAIL_MSG( _T("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 return *gs_fontDefault
;
271 #else // !__WXWINCE__
272 // wxWindow ctor calls GetFont(wxSYS_DEFAULT_GUI_FONT) so we're
273 // called fairly often -- this is why we cache this particular font
274 const bool isDefaultRequested
= index
== wxSYS_DEFAULT_GUI_FONT
;
275 if ( isDefaultRequested
)
277 if ( gs_fontDefault
)
278 return *gs_fontDefault
;
281 wxFont font
= wxCreateFontFromStockObject(index
);
283 if ( isDefaultRequested
)
285 // if we got here it means we hadn't cached it yet - do now
286 gs_fontDefault
= new wxFont(font
);
290 #endif // __WXWINCE__/!__WXWINCE__
293 // ----------------------------------------------------------------------------
294 // system metrics/features
295 // ----------------------------------------------------------------------------
297 // TODO: some of the "metrics" clearly should be features now that we have
300 // the conversion table from wxSystemMetric enum to GetSystemMetrics() param
302 // if the constant is not defined, put -1 in the table to indicate that it is
304 static const int gs_metricsMap
[] =
306 -1, // wxSystemMetric enums start at 1, so give a dummy value for pos 0.
307 #if defined(__WIN32__) && !defined(__WXWINCE__)
323 #if defined(__WIN32__) && defined(SM_CXDRAG)
351 #if defined(__WIN32__) && defined(SM_CXSIZEFRAME)
370 #if defined(__WIN32__) && defined(SM_NETWORK)
380 #if defined(__WIN32__) && defined(SM_SHOWSOUNDS)
385 // SM_SWAPBUTTON is not available under CE and it doesn't make sense to ask
392 -1 // wxSYS_DCLICK_MSEC - not available as system metric
395 // Get a system metric, e.g. scrollbar size
396 int wxSystemSettingsNative::GetMetric(wxSystemMetric index
, wxWindow
* WXUNUSED(win
))
398 #ifdef __WXMICROWIN__
399 // TODO: probably use wxUniv themes functionality
401 #else // !__WXMICROWIN__
402 wxCHECK_MSG( index
> 0 && (size_t)index
< WXSIZEOF(gs_metricsMap
), 0,
403 _T("invalid metric") );
405 if ( index
== wxSYS_DCLICK_MSEC
)
407 // This one is not a Win32 system metric
408 return ::GetDoubleClickTime();
411 int indexMSW
= gs_metricsMap
[index
];
412 if ( indexMSW
== -1 )
414 // not supported under current system
418 int rc
= ::GetSystemMetrics(indexMSW
);
419 if ( index
== wxSYS_NETWORK_PRESENT
)
421 // only the last bit is significant according to the MSDN
426 #endif // __WXMICROWIN__/!__WXMICROWIN__
429 bool wxSystemSettingsNative::HasFeature(wxSystemFeature index
)
433 case wxSYS_CAN_ICONIZE_FRAME
:
434 case wxSYS_CAN_DRAW_FRAME_DECORATIONS
:
437 case wxSYS_TABLET_PRESENT
:
438 return ::GetSystemMetrics(SM_TABLETPC
) != 0;
441 wxFAIL_MSG( _T("unknown system feature") );
447 // ----------------------------------------------------------------------------
448 // function from wx/msw/wrapcctl.h: there is really no other place for it...
449 // ----------------------------------------------------------------------------
451 #if wxUSE_LISTCTRL || wxUSE_TREECTRL
453 extern wxFont
wxGetCCDefaultFont()
456 // under the systems enumerated below (anything released after Win98), the
457 // default font used for the common controls seems to be the desktop font
458 // which is also used for the icon titles and not the stock default GUI
462 switch ( wxGetOsVersion(&verMaj
, &verMin
) )
464 case wxOS_WINDOWS_9X
:
466 useIconFont
= verMaj
== 4 && verMin
>= 10;
469 case wxOS_WINDOWS_NT
:
471 useIconFont
= verMaj
>= 5;
481 if ( ::SystemParametersInfo
483 SPI_GETICONTITLELOGFONT
,
489 return wxFont(wxCreateFontFromLogFont(&lf
));
493 wxLogLastError(_T("SystemParametersInfo(SPI_GETICONTITLELOGFONT"));
496 #endif // __WXWINCE__
498 // fall back to the default font for the normal controls
499 return wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
502 #endif // wxUSE_LISTCTRL || wxUSE_TREECTRL