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_LISTBOXHIGHLIGHTTEXT
)
138 // there is no standard colour with this index, map to another one
139 index
= wxSYS_COLOUR_HIGHLIGHTTEXT
;
141 else if ( index
== wxSYS_COLOUR_LISTBOX
)
143 // there is no standard colour with this index, map to another one
144 index
= wxSYS_COLOUR_WINDOW
;
146 else if ( index
> wxSYS_COLOUR_BTNHIGHLIGHT
)
148 // the indices before BTNHIGHLIGHT are understood by GetSysColor() in
149 // all Windows version, for the other ones we have to check
153 wxGetOsVersion(&verMaj
, &verMin
);
159 else if ( verMaj
== 4 )
162 useDefault
= index
> wxSYS_COLOUR_INFOBK
;
164 else if ( verMaj
== 5 && verMin
== 0 )
167 useDefault
= index
> wxSYS_COLOUR_GRADIENTINACTIVECAPTION
;
173 // Determine if we are using flat menus, only then allow wxSYS_COLOUR_MENUBAR
174 if ( index
== wxSYS_COLOUR_MENUBAR
)
177 if ( SystemParametersInfo( SPI_GETFLATMENU
, 0 ,&isFlat
, 0 ) )
180 index
= wxSYS_COLOUR_MENU
;
187 // special handling for MENUBAR colour: we use this in wxToolBar
188 // and wxStatusBar to have correct bg colour under Windows XP
189 // (which uses COLOR_MENUBAR for them) but they should still look
190 // correctly under previous Windows versions as well
191 if ( index
== wxSYS_COLOUR_MENUBAR
)
193 index
= wxSYS_COLOUR_3DFACE
;
195 else // replace with default colour
197 unsigned int n
= index
- wxSYS_COLOUR_BTNHIGHLIGHT
;
199 wxASSERT_MSG( n
< WXSIZEOF(s_defaultSysColors
),
200 wxT("forgot tp update the default colours array") );
202 colSys
= s_defaultSysColors
[n
];
211 colSys
= ::GetSysColor(index
|SYS_COLOR_INDEX_FLAG
);
213 colSys
= ::GetSysColor(index
);
217 wxColour ret
= wxRGBToColour(colSys
);
218 wxASSERT(ret
.IsOk());
222 // ----------------------------------------------------------------------------
224 // ----------------------------------------------------------------------------
226 wxFont
wxCreateFontFromStockObject(int index
)
230 HFONT hFont
= (HFONT
) ::GetStockObject(index
);
234 if ( ::GetObject(hFont
, sizeof(LOGFONT
), &lf
) != 0 )
236 wxNativeFontInfo info
;
238 // Under MicroWindows we pass the HFONT as well
239 // because it's hard to convert HFONT -> LOGFONT -> HFONT
240 // It's OK to delete stock objects, the delete will be ignored.
241 #ifdef __WXMICROWIN__
242 font
.Create(info
, (WXHFONT
) hFont
);
249 wxFAIL_MSG( wxT("failed to get LOGFONT") );
252 else // GetStockObject() failed
254 wxFAIL_MSG( wxT("stock font not found") );
260 wxFont
wxSystemSettingsNative::GetFont(wxSystemFont index
)
263 // under CE only a single SYSTEM_FONT exists
266 if ( !gs_fontDefault
)
268 gs_fontDefault
= new wxFont(wxCreateFontFromStockObject(SYSTEM_FONT
));
271 wxASSERT(gs_fontDefault
->IsOk() &&
272 wxFontEnumerator::IsValidFacename(gs_fontDefault
->GetFaceName()));
273 return *gs_fontDefault
;
274 #else // !__WXWINCE__
275 // wxWindow ctor calls GetFont(wxSYS_DEFAULT_GUI_FONT) so we're
276 // called fairly often -- this is why we cache this particular font
277 if ( index
== wxSYS_DEFAULT_GUI_FONT
)
279 if ( !gs_fontDefault
)
281 // http://blogs.msdn.com/oldnewthing/archive/2005/07/07/436435.aspx
282 // explains why neither SYSTEM_FONT nor DEFAULT_GUI_FONT should be
285 // the message box font seems to be the one which should be used
286 // for most (simple) controls, e.g. buttons and such but other
287 // controls may prefer to use lfStatusFont or lfCaptionFont if it
288 // is more appropriate for them
289 wxNativeFontInfo info
;
290 info
.lf
= wxMSWImpl::GetNonClientMetrics().lfMessageFont
;
291 gs_fontDefault
= new wxFont(info
);
294 return *gs_fontDefault
;
297 wxFont font
= wxCreateFontFromStockObject(index
);
299 wxASSERT(font
.IsOk());
302 wxASSERT(wxFontEnumerator::IsValidFacename(font
.GetFaceName()));
303 #endif // wxUSE_FONTENUM
306 #endif // __WXWINCE__/!__WXWINCE__
309 // ----------------------------------------------------------------------------
310 // system metrics/features
311 // ----------------------------------------------------------------------------
313 // TODO: some of the "metrics" clearly should be features now that we have
316 // the conversion table from wxSystemMetric enum to GetSystemMetrics() param
318 // if the constant is not defined, put -1 in the table to indicate that it is
320 static const int gs_metricsMap
[] =
322 -1, // wxSystemMetric enums start at 1, so give a dummy value for pos 0.
323 #if defined(__WIN32__) && !defined(__WXWINCE__)
339 #if defined(__WIN32__) && defined(SM_CXDRAG)
367 #if defined(__WIN32__) && defined(SM_CXSIZEFRAME)
386 #if defined(__WIN32__) && defined(SM_NETWORK)
396 #if defined(__WIN32__) && defined(SM_SHOWSOUNDS)
401 // SM_SWAPBUTTON is not available under CE and it doesn't make sense to ask
408 -1 // wxSYS_DCLICK_MSEC - not available as system metric
411 // Get a system metric, e.g. scrollbar size
412 int wxSystemSettingsNative::GetMetric(wxSystemMetric index
, wxWindow
* WXUNUSED(win
))
414 #ifdef __WXMICROWIN__
415 // TODO: probably use wxUniv themes functionality
417 #else // !__WXMICROWIN__
418 wxCHECK_MSG( index
> 0 && (size_t)index
< WXSIZEOF(gs_metricsMap
), 0,
419 wxT("invalid metric") );
421 if ( index
== wxSYS_DCLICK_MSEC
)
423 // This one is not a Win32 system metric
424 return ::GetDoubleClickTime();
427 int indexMSW
= gs_metricsMap
[index
];
428 if ( indexMSW
== -1 )
430 // not supported under current system
434 int rc
= ::GetSystemMetrics(indexMSW
);
435 if ( index
== wxSYS_NETWORK_PRESENT
)
437 // only the last bit is significant according to the MSDN
442 #endif // __WXMICROWIN__/!__WXMICROWIN__
445 bool wxSystemSettingsNative::HasFeature(wxSystemFeature index
)
449 case wxSYS_CAN_ICONIZE_FRAME
:
450 case wxSYS_CAN_DRAW_FRAME_DECORATIONS
:
453 case wxSYS_TABLET_PRESENT
:
454 return ::GetSystemMetrics(SM_TABLETPC
) != 0;
457 wxFAIL_MSG( wxT("unknown system feature") );
463 // ----------------------------------------------------------------------------
464 // function from wx/msw/wrapcctl.h: there is really no other place for it...
465 // ----------------------------------------------------------------------------
467 #if wxUSE_LISTCTRL || wxUSE_TREECTRL
469 extern wxFont
wxGetCCDefaultFont()
472 // under the systems enumerated below (anything released after Win98), the
473 // default font used for the common controls seems to be the desktop font
474 // which is also used for the icon titles and not the stock default GUI
478 switch ( wxGetOsVersion(&verMaj
, &verMin
) )
480 case wxOS_WINDOWS_9X
:
482 useIconFont
= verMaj
== 4 && verMin
>= 10;
485 case wxOS_WINDOWS_NT
:
487 useIconFont
= verMaj
>= 5;
497 if ( ::SystemParametersInfo
499 SPI_GETICONTITLELOGFONT
,
505 return wxFont(wxCreateFontFromLogFont(&lf
));
509 wxLogLastError(wxT("SystemParametersInfo(SPI_GETICONTITLELOGFONT"));
512 #endif // __WXWINCE__
514 // fall back to the default font for the normal controls
515 return wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT
);
518 #endif // wxUSE_LISTCTRL || wxUSE_TREECTRL