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