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
37 #include "wx/msw/private/metrics.h"
39 #ifndef SPI_GETFLATMENU
40 #define SPI_GETFLATMENU 0x1022
43 #include "wx/fontutil.h"
44 #include "wx/fontenum.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 wxDELETE(gs_fontDefault
);
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
;
233 // Under MicroWindows we pass the HFONT as well
234 // because it's hard to convert HFONT -> LOGFONT -> HFONT
235 // It's OK to delete stock objects, the delete will be ignored.
236 #ifdef __WXMICROWIN__
237 font
.Create(info
, (WXHFONT
) hFont
);
244 wxFAIL_MSG( wxT("failed to get LOGFONT") );
247 else // GetStockObject() failed
249 wxFAIL_MSG( wxT("stock font not found") );
255 wxFont
wxSystemSettingsNative::GetFont(wxSystemFont index
)
258 // under CE only a single SYSTEM_FONT exists
261 if ( !gs_fontDefault
)
263 gs_fontDefault
= new wxFont(wxCreateFontFromStockObject(SYSTEM_FONT
));
266 wxASSERT(gs_fontDefault
->IsOk() &&
267 wxFontEnumerator::IsValidFacename(gs_fontDefault
->GetFaceName()));
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 if ( index
== wxSYS_DEFAULT_GUI_FONT
)
274 if ( !gs_fontDefault
)
276 // http://blogs.msdn.com/oldnewthing/archive/2005/07/07/436435.aspx
277 // explains why neither SYSTEM_FONT nor DEFAULT_GUI_FONT should be
280 // the message box font seems to be the one which should be used
281 // for most (simple) controls, e.g. buttons and such but other
282 // controls may prefer to use lfStatusFont or lfCaptionFont if it
283 // is more appropriate for them
284 wxNativeFontInfo info
;
285 info
.lf
= wxMSWImpl::GetNonClientMetrics().lfMessageFont
;
286 gs_fontDefault
= new wxFont(info
);
289 return *gs_fontDefault
;
292 wxFont font
= wxCreateFontFromStockObject(index
);
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