1 /////////////////////////////////////////////////////////////////////////////
2 // Name: 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"
29 #include "wx/gdicmn.h"
32 #include "wx/settings.h"
34 #include "wx/msw/private.h"
36 #ifndef SPI_GETFLATMENU
37 #define SPI_GETFLATMENU 0x1022
40 #include "wx/module.h"
41 #include "wx/fontutil.h"
43 // ----------------------------------------------------------------------------
45 // ----------------------------------------------------------------------------
47 // the module which is used to clean up wxSystemSettingsNative data (this is a
48 // singleton class so it can't be done in the dtor)
49 class wxSystemSettingsModule
: public wxModule
52 virtual bool OnInit();
53 virtual void OnExit();
56 DECLARE_DYNAMIC_CLASS(wxSystemSettingsModule
)
59 // ----------------------------------------------------------------------------
61 // ----------------------------------------------------------------------------
63 // the font returned by GetFont(wxSYS_DEFAULT_GUI_FONT): it is created when
64 // GetFont() is called for the first time and deleted by wxSystemSettingsModule
65 static wxFont
*gs_fontDefault
= NULL
;
67 // ============================================================================
69 // ============================================================================
71 // TODO: see ::SystemParametersInfo for all sorts of Windows settings.
72 // Different args are required depending on the id. How does this differ
73 // from GetSystemMetric, and should it? Perhaps call it GetSystemParameter
74 // and pass an optional void* arg to get further info.
75 // Should also have SetSystemParameter.
76 // Also implement WM_WININICHANGE (NT) / WM_SETTINGCHANGE (Win95)
78 // ----------------------------------------------------------------------------
79 // wxSystemSettingsModule
80 // ----------------------------------------------------------------------------
82 IMPLEMENT_DYNAMIC_CLASS(wxSystemSettingsModule
, wxModule
)
84 bool wxSystemSettingsModule::OnInit()
89 void wxSystemSettingsModule::OnExit()
91 delete gs_fontDefault
;
92 gs_fontDefault
= NULL
;
95 // ----------------------------------------------------------------------------
96 // wxSystemSettingsNative
97 // ----------------------------------------------------------------------------
99 // ----------------------------------------------------------------------------
101 // ----------------------------------------------------------------------------
103 wxColour
wxSystemSettingsNative::GetColour(wxSystemColour index
)
105 // we use 0 as the default value just to avoid compiler warnings, as there
106 // is no invalid colour value we use hasCol as the real indicator of
107 // whether colSys was initialized or not
111 // the default colours for the entries after BTNHIGHLIGHT
112 static const COLORREF s_defaultSysColors
[] =
114 0x000000, // 3DDKSHADOW
116 0x000000, // INFOTEXT
119 0, // filler - no std colour with this index
121 // TODO: please fill in the standard values of those, I don't have them
123 0, // GRADIENTACTIVECAPTION
124 0, // GRADIENTINACTIVECAPTION
126 0, // MENUBAR (unused)
129 if ( index
== wxSYS_COLOUR_LISTBOX
)
131 // there is no standard colour with this index, map to another one
132 index
= wxSYS_COLOUR_WINDOW
;
134 else if ( index
> wxSYS_COLOUR_BTNHIGHLIGHT
)
136 // the indices before BTNHIGHLIGHT are understood by GetSysColor() in
137 // all Windows version, for the other ones we have to check
140 // none of the is supported under Win16 anyhow
143 wxGetOsVersion(&verMaj
, &verMin
);
149 else if ( verMaj
== 4 )
152 useDefault
= index
> wxSYS_COLOUR_INFOBK
;
154 else if ( verMaj
== 5 && verMin
== 0 )
157 useDefault
= index
> wxSYS_COLOUR_GRADIENTINACTIVECAPTION
;
163 // Determine if we are using flat menus, only then allow wxSYS_COLOUR_MENUBAR
164 if ( index
== wxSYS_COLOUR_MENUBAR
)
167 if ( SystemParametersInfo( SPI_GETFLATMENU
, 0 ,&isFlat
, 0 ) )
170 index
= wxSYS_COLOUR_MENU
;
180 // special handling for MENUBAR colour: we use this in wxToolBar
181 // and wxStatusBar to have correct bg colour under Windows XP
182 // (which uses COLOR_MENUBAR for them) but they should still look
183 // correctly under previous Windows versions as well
184 if ( index
== wxSYS_COLOUR_MENUBAR
)
186 index
= wxSYS_COLOUR_3DFACE
;
188 else // replace with default colour
190 unsigned int n
= index
- wxSYS_COLOUR_BTNHIGHLIGHT
;
192 wxASSERT_MSG( n
< WXSIZEOF(s_defaultSysColors
),
193 _T("forgot tp update the default colours array") );
195 colSys
= s_defaultSysColors
[n
];
204 colSys
= ::GetSysColor(index
|SYS_COLOR_INDEX_FLAG
);
206 colSys
= ::GetSysColor(index
);
210 return wxRGBToColour(colSys
);
213 // ----------------------------------------------------------------------------
215 // ----------------------------------------------------------------------------
217 wxFont
wxCreateFontFromStockObject(int index
)
221 HFONT hFont
= (HFONT
) ::GetStockObject(index
);
225 if ( ::GetObject(hFont
, sizeof(LOGFONT
), &lf
) != 0 )
227 wxNativeFontInfo info
;
229 // Under MicroWindows we pass the HFONT as well
230 // because it's hard to convert HFONT -> LOGFONT -> HFONT
231 // It's OK to delete stock objects, the delete will be ignored.
232 #ifdef __WXMICROWIN__
233 font
.Create(info
, (WXHFONT
) hFont
);
240 wxFAIL_MSG( _T("failed to get LOGFONT") );
243 else // GetStockObject() failed
245 wxFAIL_MSG( _T("stock font not found") );
251 wxFont
wxSystemSettingsNative::GetFont(wxSystemFont index
)
253 // wxWindow ctor calls GetSystemFont(wxSYS_DEFAULT_GUI_FONT) so we're
254 // called fairly often - this is why we cache this particular font
255 bool isDefaultRequested
= index
== wxSYS_DEFAULT_GUI_FONT
;
256 if ( isDefaultRequested
&& gs_fontDefault
)
258 return *gs_fontDefault
;
261 wxFont font
= wxCreateFontFromStockObject(index
);
263 if ( isDefaultRequested
)
265 // if we got here it means we hadn't cached it yet - do now
266 gs_fontDefault
= new wxFont(font
);
272 // ----------------------------------------------------------------------------
273 // system metrics/features
274 // ----------------------------------------------------------------------------
276 // TODO: some of the "metrics" clearly should be features now that we have
279 // the conversion table from wxSystemMetric enum to GetSystemMetrics() param
281 // if the constant is not defined, put -1 in the table to indicate that it is
283 static const int gs_metricsMap
[] =
285 -1, // wxSystemMetric enums start at 1, so give a dummy value for pos 0.
286 #if defined(__WIN32__) && !defined(__WXWINCE__)
298 #if defined(__WIN32__) && defined(SM_CXDRAG)
326 #if defined(__WIN32__) && defined(SM_CXSIZEFRAME)
345 #if defined(__WIN32__) && defined(SM_NETWORK)
355 #if defined(__WIN32__) && defined(SM_SHOWSOUNDS)
367 // Get a system metric, e.g. scrollbar size
368 int wxSystemSettingsNative::GetMetric(wxSystemMetric index
)
370 #ifdef __WXMICROWIN__
371 // TODO: probably use wxUniv themes functionality
373 #else // !__WXMICROWIN__
374 wxCHECK_MSG( index
> 0 && (size_t)index
< WXSIZEOF(gs_metricsMap
), 0,
375 _T("invalid metric") );
377 int indexMSW
= gs_metricsMap
[index
];
378 if ( indexMSW
== -1 )
380 // not supported under current system
384 int rc
= ::GetSystemMetrics(indexMSW
);
385 if ( index
== wxSYS_NETWORK_PRESENT
)
387 // only the last bit is significant according to the MSDN
392 #endif // __WXMICROWIN__/!__WXMICROWIN__
395 bool wxSystemSettingsNative::HasFeature(wxSystemFeature index
)
399 case wxSYS_CAN_ICONIZE_FRAME
:
400 case wxSYS_CAN_DRAW_FRAME_DECORATIONS
:
404 wxFAIL_MSG( _T("unknown system feature") );