]> git.saurik.com Git - wxWidgets.git/blame - src/msw/settings.cpp
remove files for win 3.1
[wxWidgets.git] / src / msw / settings.cpp
CommitLineData
2bda0e17 1/////////////////////////////////////////////////////////////////////////////
8bf30fe9 2// Name: msw/settings.cpp
7516ed26 3// Purpose: wxSystemSettingsNative implementation for MSW
2bda0e17
KB
4// Author: Julian Smart
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id$
6c9a19aa
JS
8// Copyright: (c) Julian Smart
9// Licence: wxWindows licence
2bda0e17
KB
10/////////////////////////////////////////////////////////////////////////////
11
8bf30fe9
VZ
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
2bda0e17
KB
20// For compilers that support precompilation, includes "wx.h".
21#include "wx/wxprec.h"
22
23#ifdef __BORLANDC__
7516ed26 24 #pragma hdrstop
2bda0e17
KB
25#endif
26
27#ifndef WX_PRECOMP
e02e8816 28 #include "wx/utils.h"
8bf30fe9 29 #include "wx/gdicmn.h"
2bda0e17
KB
30#endif
31
32#include "wx/settings.h"
7516ed26 33
2bda0e17 34#include "wx/msw/private.h"
7516ed26 35
d1eebf40
SC
36#ifndef SPI_GETFLATMENU
37#define SPI_GETFLATMENU 0x1022
38#endif
39
2e6d38ad 40#include "wx/module.h"
04ef50df 41#include "wx/fontutil.h"
2bda0e17 42
eae4425d
JS
43#ifdef __WXWINCE__ // for SM_CXCURSOR and SM_CYCURSOR
44#include "wx/msw/wince/missing.h"
45#endif // __WXWINCE__
46
8bf30fe9
VZ
47// ----------------------------------------------------------------------------
48// private classes
49// ----------------------------------------------------------------------------
50
7516ed26 51// the module which is used to clean up wxSystemSettingsNative data (this is a
8bf30fe9
VZ
52// singleton class so it can't be done in the dtor)
53class wxSystemSettingsModule : public wxModule
54{
55public:
56 virtual bool OnInit();
57 virtual void OnExit();
58
59private:
60 DECLARE_DYNAMIC_CLASS(wxSystemSettingsModule)
61};
62
63// ----------------------------------------------------------------------------
64// global data
65// ----------------------------------------------------------------------------
66
7516ed26
VZ
67// the font returned by GetFont(wxSYS_DEFAULT_GUI_FONT): it is created when
68// GetFont() is called for the first time and deleted by wxSystemSettingsModule
8bf30fe9
VZ
69static wxFont *gs_fontDefault = NULL;
70
71// ============================================================================
72// implementation
73// ============================================================================
74
7516ed26
VZ
75// TODO: see ::SystemParametersInfo for all sorts of Windows settings.
76// Different args are required depending on the id. How does this differ
77// from GetSystemMetric, and should it? Perhaps call it GetSystemParameter
78// and pass an optional void* arg to get further info.
79// Should also have SetSystemParameter.
80// Also implement WM_WININICHANGE (NT) / WM_SETTINGCHANGE (Win95)
81
8bf30fe9
VZ
82// ----------------------------------------------------------------------------
83// wxSystemSettingsModule
84// ----------------------------------------------------------------------------
85
86IMPLEMENT_DYNAMIC_CLASS(wxSystemSettingsModule, wxModule)
87
88bool wxSystemSettingsModule::OnInit()
89{
90 return TRUE;
91}
92
93void wxSystemSettingsModule::OnExit()
94{
95 delete gs_fontDefault;
0cbff120 96 gs_fontDefault = NULL;
8bf30fe9
VZ
97}
98
99// ----------------------------------------------------------------------------
7516ed26 100// wxSystemSettingsNative
8bf30fe9
VZ
101// ----------------------------------------------------------------------------
102
7516ed26
VZ
103// ----------------------------------------------------------------------------
104// colours
105// ----------------------------------------------------------------------------
2bda0e17 106
7516ed26 107wxColour wxSystemSettingsNative::GetColour(wxSystemColour index)
2bda0e17 108{
7d6d3bf3
VZ
109 // we use 0 as the default value just to avoid compiler warnings, as there
110 // is no invalid colour value we use hasCol as the real indicator of
111 // whether colSys was initialized or not
112 COLORREF colSys = 0;
113 bool hasCol = FALSE;
114
115 // the default colours for the entries after BTNHIGHLIGHT
116 static const COLORREF s_defaultSysColors[] =
117 {
118 0x000000, // 3DDKSHADOW
119 0xdfdfdf, // 3DLIGHT
120 0x000000, // INFOTEXT
121 0xe1ffff, // INFOBK
122
123 0, // filler - no std colour with this index
124
125 // TODO: please fill in the standard values of those, I don't have them
126 0, // HOTLIGHT
127 0, // GRADIENTACTIVECAPTION
128 0, // GRADIENTINACTIVECAPTION
129 0, // MENU
130 0, // MENUBAR (unused)
131 };
132
133 if ( index == wxSYS_COLOUR_LISTBOX )
134 {
135 // there is no standard colour with this index, map to another one
136 index = wxSYS_COLOUR_WINDOW;
137 }
138 else if ( index > wxSYS_COLOUR_BTNHIGHLIGHT )
139 {
140 // the indices before BTNHIGHLIGHT are understood by GetSysColor() in
141 // all Windows version, for the other ones we have to check
142 bool useDefault;
143
144 // none of the is supported under Win16 anyhow
145#ifdef __WIN32__
146 int verMaj, verMin;
147 wxGetOsVersion(&verMaj, &verMin);
148 if ( verMaj < 4 )
149 {
150 // NT 3.5
151 useDefault = TRUE;
152 }
153 else if ( verMaj == 4 )
154 {
155 // Win95/NT 4.0
156 useDefault = index > wxSYS_COLOUR_INFOBK;
157 }
158 else if ( verMaj == 5 && verMin == 0 )
159 {
160 // Win98/Win2K
161 useDefault = index > wxSYS_COLOUR_GRADIENTINACTIVECAPTION;
162 }
163 else // >= 5.1
164 {
165 // 5.1 is Windows XP
166 useDefault = FALSE;
d1eebf40
SC
167 // Determine if we are using flat menus, only then allow wxSYS_COLOUR_MENUBAR
168 if ( index == wxSYS_COLOUR_MENUBAR )
169 {
170 BOOL isFlat ;
171 if ( SystemParametersInfo( SPI_GETFLATMENU , 0 ,&isFlat, 0 ) )
172 {
173 if ( !isFlat )
174 index = wxSYS_COLOUR_MENU ;
175 }
176 }
177 }
7d6d3bf3
VZ
178#else
179 useDefault = TRUE;
180#endif // __WIN32__
181
182 if ( useDefault )
183 {
184 // special handling for MENUBAR colour: we use this in wxToolBar
185 // and wxStatusBar to have correct bg colour under Windows XP
186 // (which uses COLOR_MENUBAR for them) but they should still look
187 // correctly under previous Windows versions as well
188 if ( index == wxSYS_COLOUR_MENUBAR )
189 {
190 index = wxSYS_COLOUR_3DFACE;
191 }
192 else // replace with default colour
193 {
d285d708 194 unsigned int n = index - wxSYS_COLOUR_BTNHIGHLIGHT;
7d6d3bf3
VZ
195
196 wxASSERT_MSG( n < WXSIZEOF(s_defaultSysColors),
197 _T("forgot tp update the default colours array") );
198
199 colSys = s_defaultSysColors[n];
200 hasCol = TRUE;
201 }
202 }
203 }
204
205 if ( !hasCol )
206 {
39d2f9a7
JS
207#ifdef __WXWINCE__
208 colSys = ::GetSysColor(index|SYS_COLOR_INDEX_FLAG);
209#else
7d6d3bf3 210 colSys = ::GetSysColor(index);
39d2f9a7 211#endif
7d6d3bf3
VZ
212 }
213
214 return wxRGBToColour(colSys);
2bda0e17
KB
215}
216
7516ed26
VZ
217// ----------------------------------------------------------------------------
218// fonts
219// ----------------------------------------------------------------------------
220
04ef50df 221wxFont wxCreateFontFromStockObject(int index)
2bda0e17 222{
8bf30fe9
VZ
223 wxFont font;
224
019a60d6 225 HFONT hFont = (HFONT) ::GetStockObject(index);
8bf30fe9 226 if ( hFont )
019a60d6
VS
227 {
228 LOGFONT lf;
229 if ( ::GetObject(hFont, sizeof(LOGFONT), &lf) != 0 )
230 {
04ef50df
JS
231 wxNativeFontInfo info;
232 info.lf = lf;
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);
238#else
239 font.Create(info);
240#endif
019a60d6
VS
241 }
242 else
243 {
8bf30fe9 244 wxFAIL_MSG( _T("failed to get LOGFONT") );
019a60d6
VS
245 }
246 }
8bf30fe9
VZ
247 else // GetStockObject() failed
248 {
249 wxFAIL_MSG( _T("stock font not found") );
250 }
7516ed26 251
04ef50df
JS
252 return font;
253}
254
7516ed26 255wxFont wxSystemSettingsNative::GetFont(wxSystemFont index)
04ef50df 256{
e688defd 257#ifndef __WXWINCE__
3cb99894
VZ
258 // this one is special: we don't get it from GetStockObject()
259 if ( index == wxSYS_ICONTITLE_FONT )
260 {
261 LOGFONT lf;
262 SystemParametersInfo(SPI_GETICONTITLELOGFONT, sizeof(lf), &lf, 0);
263 return wxCreateFontFromLogFont(&lf);
264 }
eae4425d 265#endif // __WXWINCE__
3cb99894 266
04ef50df
JS
267 // wxWindow ctor calls GetSystemFont(wxSYS_DEFAULT_GUI_FONT) so we're
268 // called fairly often - this is why we cache this particular font
269 bool isDefaultRequested = index == wxSYS_DEFAULT_GUI_FONT;
270 if ( isDefaultRequested && gs_fontDefault )
271 {
272 return *gs_fontDefault;
273 }
274
275 wxFont font = wxCreateFontFromStockObject(index);
8bf30fe9
VZ
276
277 if ( isDefaultRequested )
019a60d6 278 {
8bf30fe9
VZ
279 // if we got here it means we hadn't cached it yet - do now
280 gs_fontDefault = new wxFont(font);
019a60d6 281 }
8bf30fe9
VZ
282
283 return font;
2bda0e17
KB
284}
285
7516ed26
VZ
286// ----------------------------------------------------------------------------
287// system metrics/features
288// ----------------------------------------------------------------------------
289
290// TODO: some of the "metrics" clearly should be features now that we have
291// HasFeature()!
292
293// the conversion table from wxSystemMetric enum to GetSystemMetrics() param
294//
295// if the constant is not defined, put -1 in the table to indicate that it is
296// unknown
297static const int gs_metricsMap[] =
2bda0e17 298{
fc29e86e 299 -1, // wxSystemMetric enums start at 1, so give a dummy value for pos 0.
4676948b 300#if defined(__WIN32__) && !defined(__WXWINCE__)
7516ed26
VZ
301 SM_CMOUSEBUTTONS,
302#else
303 -1,
2bda0e17
KB
304#endif
305
7516ed26
VZ
306 SM_CXBORDER,
307 SM_CYBORDER,
308 SM_CXCURSOR,
309 SM_CYCURSOR,
310 SM_CXDOUBLECLK,
311 SM_CYDOUBLECLK,
2432b92d 312#if defined(__WIN32__) && defined(SM_CXDRAG)
7516ed26
VZ
313 SM_CXDRAG,
314 SM_CYDRAG,
315 SM_CXEDGE,
316 SM_CYEDGE,
317#else
4676948b 318 -1, -1, -1, -1,
2bda0e17 319#endif
7516ed26
VZ
320 SM_CXHSCROLL,
321 SM_CYHSCROLL,
4676948b 322#ifdef SM_CXHTHUMB
7516ed26 323 SM_CXHTHUMB,
4676948b
JS
324#else
325 -1,
326#endif
7516ed26
VZ
327 SM_CXICON,
328 SM_CYICON,
329 SM_CXICONSPACING,
330 SM_CYICONSPACING,
4676948b 331#ifdef SM_CXHTHUMB
7516ed26
VZ
332 SM_CXMIN,
333 SM_CYMIN,
4676948b
JS
334#else
335 -1, -1,
336#endif
7516ed26
VZ
337 SM_CXSCREEN,
338 SM_CYSCREEN,
2432b92d
JS
339
340#if defined(__WIN32__) && defined(SM_CXSIZEFRAME)
7516ed26
VZ
341 SM_CXSIZEFRAME,
342 SM_CYSIZEFRAME,
343 SM_CXSMICON,
344 SM_CYSMICON,
345#else
4676948b 346 -1, -1, -1, -1,
2bda0e17 347#endif
7516ed26
VZ
348 SM_CYHSCROLL,
349 SM_CXVSCROLL,
350 SM_CXVSCROLL,
351 SM_CYVSCROLL,
4676948b 352#ifdef SM_CYVTHUMB
7516ed26 353 SM_CYVTHUMB,
4676948b
JS
354#else
355 -1,
356#endif
7516ed26
VZ
357 SM_CYCAPTION,
358 SM_CYMENU,
2432b92d 359#if defined(__WIN32__) && defined(SM_NETWORK)
7516ed26
VZ
360 SM_NETWORK,
361#else
362 -1,
2bda0e17 363#endif
4676948b 364#ifdef SM_PENWINDOWS
7516ed26 365 SM_PENWINDOWS,
4676948b
JS
366#else
367 -1,
368#endif
2432b92d 369#if defined(__WIN32__) && defined(SM_SHOWSOUNDS)
7516ed26
VZ
370 SM_SHOWSOUNDS,
371#else
372 -1,
2bda0e17 373#endif
4676948b 374#ifdef SM_SWAPBUTTON
7516ed26 375 SM_SWAPBUTTON,
4676948b
JS
376#else
377 -1
378#endif
7516ed26
VZ
379};
380
381// Get a system metric, e.g. scrollbar size
382int wxSystemSettingsNative::GetMetric(wxSystemMetric index)
383{
384#ifdef __WXMICROWIN__
385 // TODO: probably use wxUniv themes functionality
386 return 0;
387#else // !__WXMICROWIN__
68d95db4
VZ
388 wxCHECK_MSG( index > 0 && (size_t)index < WXSIZEOF(gs_metricsMap), 0,
389 _T("invalid metric") );
7516ed26
VZ
390
391 int indexMSW = gs_metricsMap[index];
392 if ( indexMSW == -1 )
393 {
394 // not supported under current system
395 return 0;
019a60d6 396 }
7516ed26
VZ
397
398 int rc = ::GetSystemMetrics(indexMSW);
399 if ( index == wxSYS_NETWORK_PRESENT )
400 {
401 // only the last bit is significant according to the MSDN
402 rc &= 1;
403 }
404
405 return rc;
406#endif // __WXMICROWIN__/!__WXMICROWIN__
2bda0e17
KB
407}
408
7516ed26 409bool wxSystemSettingsNative::HasFeature(wxSystemFeature index)
253293c1 410{
7516ed26 411 switch ( index )
253293c1 412 {
7516ed26 413 case wxSYS_CAN_ICONIZE_FRAME:
253293c1 414 case wxSYS_CAN_DRAW_FRAME_DECORATIONS:
bb6de5ff 415 return TRUE;
7516ed26 416
253293c1 417 default:
7516ed26
VZ
418 wxFAIL_MSG( _T("unknown system feature") );
419
253293c1
VS
420 return FALSE;
421 }
422}