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
];
203 colSys
= ::GetSysColor(index
);
206 return wxRGBToColour(colSys
);
209 // ----------------------------------------------------------------------------
211 // ----------------------------------------------------------------------------
213 wxFont
wxCreateFontFromStockObject(int index
)
217 HFONT hFont
= (HFONT
) ::GetStockObject(index
);
221 if ( ::GetObject(hFont
, sizeof(LOGFONT
), &lf
) != 0 )
223 wxNativeFontInfo info
;
225 // Under MicroWindows we pass the HFONT as well
226 // because it's hard to convert HFONT -> LOGFONT -> HFONT
227 // It's OK to delete stock objects, the delete will be ignored.
228 #ifdef __WXMICROWIN__
229 font
.Create(info
, (WXHFONT
) hFont
);
236 wxFAIL_MSG( _T("failed to get LOGFONT") );
239 else // GetStockObject() failed
241 wxFAIL_MSG( _T("stock font not found") );
247 wxFont
wxSystemSettingsNative::GetFont(wxSystemFont index
)
249 // wxWindow ctor calls GetSystemFont(wxSYS_DEFAULT_GUI_FONT) so we're
250 // called fairly often - this is why we cache this particular font
251 bool isDefaultRequested
= index
== wxSYS_DEFAULT_GUI_FONT
;
252 if ( isDefaultRequested
&& gs_fontDefault
)
254 return *gs_fontDefault
;
257 wxFont font
= wxCreateFontFromStockObject(index
);
259 if ( isDefaultRequested
)
261 // if we got here it means we hadn't cached it yet - do now
262 gs_fontDefault
= new wxFont(font
);
268 // ----------------------------------------------------------------------------
269 // system metrics/features
270 // ----------------------------------------------------------------------------
272 // TODO: some of the "metrics" clearly should be features now that we have
275 // the conversion table from wxSystemMetric enum to GetSystemMetrics() param
277 // if the constant is not defined, put -1 in the table to indicate that it is
279 static const int gs_metricsMap
[] =
281 -1, // wxSystemMetric enums start at 1, so give a dummy value for pos 0.
294 #if defined(__WIN32__) && defined(SM_CXDRAG)
314 #if defined(__WIN32__) && defined(SM_CXSIZEFRAME)
329 #if defined(__WIN32__) && defined(SM_NETWORK)
335 #if defined(__WIN32__) && defined(SM_SHOWSOUNDS)
343 // Get a system metric, e.g. scrollbar size
344 int wxSystemSettingsNative::GetMetric(wxSystemMetric index
)
346 #ifdef __WXMICROWIN__
347 // TODO: probably use wxUniv themes functionality
349 #else // !__WXMICROWIN__
350 wxCHECK_MSG( index
> 0 && (size_t)index
< WXSIZEOF(gs_metricsMap
), 0,
351 _T("invalid metric") );
353 int indexMSW
= gs_metricsMap
[index
];
354 if ( indexMSW
== -1 )
356 // not supported under current system
360 int rc
= ::GetSystemMetrics(indexMSW
);
361 if ( index
== wxSYS_NETWORK_PRESENT
)
363 // only the last bit is significant according to the MSDN
368 #endif // __WXMICROWIN__/!__WXMICROWIN__
371 bool wxSystemSettingsNative::HasFeature(wxSystemFeature index
)
375 case wxSYS_CAN_ICONIZE_FRAME
:
376 case wxSYS_CAN_DRAW_FRAME_DECORATIONS
:
380 wxFAIL_MSG( _T("unknown system feature") );