/[pcsx2_0.9.7]/branch/r3113_0.9.7_beta/3rdparty/wxWidgets/src/msw/settings.cpp
ViewVC logotype

Contents of /branch/r3113_0.9.7_beta/3rdparty/wxWidgets/src/msw/settings.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 32 - (show annotations) (download)
Tue Sep 7 03:29:01 2010 UTC (9 years, 11 months ago) by william
File size: 13835 byte(s)
branching from upstream revision (http://pcsx2.googlecode.com/svn/trunk
): r3113 to
https://svn.netsolutions.dnsalias.com/websvn/ps2/pcsx2/pcsx2_0.9.7/branch/r3113_0.9.7_beta
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/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: settings.cpp 57542 2008-12-25 13:03:24Z VZ $
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
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 #include "wx/settings.h"
28
29 #ifndef WX_PRECOMP
30 #include "wx/utils.h"
31 #include "wx/gdicmn.h"
32 #include "wx/module.h"
33 #endif
34
35 #include "wx/msw/private.h"
36 #include "wx/msw/missing.h" // for SM_CXCURSOR, SM_CYCURSOR, SM_TABLETPC
37
38 #ifndef SPI_GETFLATMENU
39 #define SPI_GETFLATMENU 0x1022
40 #endif
41
42 #include "wx/fontutil.h"
43
44 // ----------------------------------------------------------------------------
45 // private classes
46 // ----------------------------------------------------------------------------
47
48 // the module which is used to clean up wxSystemSettingsNative data (this is a
49 // singleton class so it can't be done in the dtor)
50 class wxSystemSettingsModule : public wxModule
51 {
52 public:
53 virtual bool OnInit();
54 virtual void OnExit();
55
56 private:
57 DECLARE_DYNAMIC_CLASS(wxSystemSettingsModule)
58 };
59
60 // ----------------------------------------------------------------------------
61 // global data
62 // ----------------------------------------------------------------------------
63
64 // the font returned by GetFont(wxSYS_DEFAULT_GUI_FONT): it is created when
65 // GetFont() is called for the first time and deleted by wxSystemSettingsModule
66 static wxFont *gs_fontDefault = NULL;
67
68 // ============================================================================
69 // implementation
70 // ============================================================================
71
72 // TODO: see ::SystemParametersInfo for all sorts of Windows settings.
73 // Different args are required depending on the id. How does this differ
74 // from GetSystemMetric, and should it? Perhaps call it GetSystemParameter
75 // and pass an optional void* arg to get further info.
76 // Should also have SetSystemParameter.
77 // Also implement WM_WININICHANGE (NT) / WM_SETTINGCHANGE (Win95)
78
79 // ----------------------------------------------------------------------------
80 // wxSystemSettingsModule
81 // ----------------------------------------------------------------------------
82
83 IMPLEMENT_DYNAMIC_CLASS(wxSystemSettingsModule, wxModule)
84
85 bool wxSystemSettingsModule::OnInit()
86 {
87 return true;
88 }
89
90 void wxSystemSettingsModule::OnExit()
91 {
92 delete gs_fontDefault;
93 gs_fontDefault = NULL;
94 }
95
96 // ----------------------------------------------------------------------------
97 // wxSystemSettingsNative
98 // ----------------------------------------------------------------------------
99
100 // ----------------------------------------------------------------------------
101 // colours
102 // ----------------------------------------------------------------------------
103
104 wxColour wxSystemSettingsNative::GetColour(wxSystemColour index)
105 {
106 // we use 0 as the default value just to avoid compiler warnings, as there
107 // is no invalid colour value we use hasCol as the real indicator of
108 // whether colSys was initialized or not
109 COLORREF colSys = 0;
110 bool hasCol = false;
111
112 // the default colours for the entries after BTNHIGHLIGHT
113 static const COLORREF s_defaultSysColors[] =
114 {
115 0x000000, // 3DDKSHADOW
116 0xdfdfdf, // 3DLIGHT
117 0x000000, // INFOTEXT
118 0xe1ffff, // INFOBK
119
120 0, // filler - no std colour with this index
121
122 // TODO: please fill in the standard values of those, I don't have them
123 0, // HOTLIGHT
124 0, // GRADIENTACTIVECAPTION
125 0, // GRADIENTINACTIVECAPTION
126 0, // MENU
127 0, // MENUBAR (unused)
128 };
129
130 if ( index == wxSYS_COLOUR_LISTBOXTEXT)
131 {
132 // there is no standard colour with this index, map to another one
133 index = wxSYS_COLOUR_WINDOWTEXT;
134 }
135 else if ( index == wxSYS_COLOUR_LISTBOX )
136 {
137 // there is no standard colour with this index, map to another one
138 index = wxSYS_COLOUR_WINDOW;
139 }
140 else if ( index > wxSYS_COLOUR_BTNHIGHLIGHT )
141 {
142 // the indices before BTNHIGHLIGHT are understood by GetSysColor() in
143 // all Windows version, for the other ones we have to check
144 bool useDefault;
145
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;
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 }
178
179 if ( useDefault )
180 {
181 // special handling for MENUBAR colour: we use this in wxToolBar
182 // and wxStatusBar to have correct bg colour under Windows XP
183 // (which uses COLOR_MENUBAR for them) but they should still look
184 // correctly under previous Windows versions as well
185 if ( index == wxSYS_COLOUR_MENUBAR )
186 {
187 index = wxSYS_COLOUR_3DFACE;
188 }
189 else // replace with default colour
190 {
191 unsigned int n = index - wxSYS_COLOUR_BTNHIGHLIGHT;
192
193 wxASSERT_MSG( n < WXSIZEOF(s_defaultSysColors),
194 _T("forgot tp update the default colours array") );
195
196 colSys = s_defaultSysColors[n];
197 hasCol = true;
198 }
199 }
200 }
201
202 if ( !hasCol )
203 {
204 #ifdef __WXWINCE__
205 colSys = ::GetSysColor(index|SYS_COLOR_INDEX_FLAG);
206 #else
207 colSys = ::GetSysColor(index);
208 #endif
209 }
210
211 return wxRGBToColour(colSys);
212 }
213
214 // ----------------------------------------------------------------------------
215 // fonts
216 // ----------------------------------------------------------------------------
217
218 wxFont wxCreateFontFromStockObject(int index)
219 {
220 wxFont font;
221
222 HFONT hFont = (HFONT) ::GetStockObject(index);
223 if ( hFont )
224 {
225 LOGFONT lf;
226 if ( ::GetObject(hFont, sizeof(LOGFONT), &lf) != 0 )
227 {
228 wxNativeFontInfo info;
229 info.lf = lf;
230 #ifndef __WXWINCE__
231 // We want Windows 2000 or later to have new fonts even MS Shell Dlg
232 // is returned as default GUI font for compatibility
233 int verMaj;
234 if(index == DEFAULT_GUI_FONT && wxGetOsVersion(&verMaj) == wxOS_WINDOWS_NT && verMaj >= 5)
235 wxStrcpy(info.lf.lfFaceName, wxT("MS Shell Dlg 2"));
236 #endif
237 // Under MicroWindows we pass the HFONT as well
238 // because it's hard to convert HFONT -> LOGFONT -> HFONT
239 // It's OK to delete stock objects, the delete will be ignored.
240 #ifdef __WXMICROWIN__
241 font.Create(info, (WXHFONT) hFont);
242 #else
243 font.Create(info);
244 #endif
245 }
246 else
247 {
248 wxFAIL_MSG( _T("failed to get LOGFONT") );
249 }
250 }
251 else // GetStockObject() failed
252 {
253 wxFAIL_MSG( _T("stock font not found") );
254 }
255
256 return font;
257 }
258
259 wxFont wxSystemSettingsNative::GetFont(wxSystemFont index)
260 {
261 #ifdef __WXWINCE__
262 // under CE only a single SYSTEM_FONT exists
263 index;
264
265 if ( !gs_fontDefault )
266 {
267 gs_fontDefault = new wxFont(wxCreateFontFromStockObject(SYSTEM_FONT));
268 }
269
270 return *gs_fontDefault;
271 #else // !__WXWINCE__
272 // wxWindow ctor calls GetFont(wxSYS_DEFAULT_GUI_FONT) so we're
273 // called fairly often -- this is why we cache this particular font
274 const bool isDefaultRequested = index == wxSYS_DEFAULT_GUI_FONT;
275 if ( isDefaultRequested )
276 {
277 if ( gs_fontDefault )
278 return *gs_fontDefault;
279 }
280
281 wxFont font = wxCreateFontFromStockObject(index);
282
283 if ( isDefaultRequested )
284 {
285 // if we got here it means we hadn't cached it yet - do now
286 gs_fontDefault = new wxFont(font);
287 }
288
289 return font;
290 #endif // __WXWINCE__/!__WXWINCE__
291 }
292
293 // ----------------------------------------------------------------------------
294 // system metrics/features
295 // ----------------------------------------------------------------------------
296
297 // TODO: some of the "metrics" clearly should be features now that we have
298 // HasFeature()!
299
300 // the conversion table from wxSystemMetric enum to GetSystemMetrics() param
301 //
302 // if the constant is not defined, put -1 in the table to indicate that it is
303 // unknown
304 static const int gs_metricsMap[] =
305 {
306 -1, // wxSystemMetric enums start at 1, so give a dummy value for pos 0.
307 #if defined(__WIN32__) && !defined(__WXWINCE__)
308 SM_CMOUSEBUTTONS,
309 #else
310 -1,
311 #endif
312
313 SM_CXBORDER,
314 SM_CYBORDER,
315 #ifdef SM_CXCURSOR
316 SM_CXCURSOR,
317 SM_CYCURSOR,
318 #else
319 -1, -1,
320 #endif
321 SM_CXDOUBLECLK,
322 SM_CYDOUBLECLK,
323 #if defined(__WIN32__) && defined(SM_CXDRAG)
324 SM_CXDRAG,
325 SM_CYDRAG,
326 SM_CXEDGE,
327 SM_CYEDGE,
328 #else
329 -1, -1, -1, -1,
330 #endif
331 SM_CXHSCROLL,
332 SM_CYHSCROLL,
333 #ifdef SM_CXHTHUMB
334 SM_CXHTHUMB,
335 #else
336 -1,
337 #endif
338 SM_CXICON,
339 SM_CYICON,
340 SM_CXICONSPACING,
341 SM_CYICONSPACING,
342 #ifdef SM_CXHTHUMB
343 SM_CXMIN,
344 SM_CYMIN,
345 #else
346 -1, -1,
347 #endif
348 SM_CXSCREEN,
349 SM_CYSCREEN,
350
351 #if defined(__WIN32__) && defined(SM_CXSIZEFRAME)
352 SM_CXSIZEFRAME,
353 SM_CYSIZEFRAME,
354 SM_CXSMICON,
355 SM_CYSMICON,
356 #else
357 -1, -1, -1, -1,
358 #endif
359 SM_CYHSCROLL,
360 SM_CXHSCROLL,
361 SM_CXVSCROLL,
362 SM_CYVSCROLL,
363 #ifdef SM_CYVTHUMB
364 SM_CYVTHUMB,
365 #else
366 -1,
367 #endif
368 SM_CYCAPTION,
369 SM_CYMENU,
370 #if defined(__WIN32__) && defined(SM_NETWORK)
371 SM_NETWORK,
372 #else
373 -1,
374 #endif
375 #ifdef SM_PENWINDOWS
376 SM_PENWINDOWS,
377 #else
378 -1,
379 #endif
380 #if defined(__WIN32__) && defined(SM_SHOWSOUNDS)
381 SM_SHOWSOUNDS,
382 #else
383 -1,
384 #endif
385 #ifdef SM_SWAPBUTTON
386 SM_SWAPBUTTON,
387 #else
388 -1
389 #endif
390 };
391
392 // Get a system metric, e.g. scrollbar size
393 int wxSystemSettingsNative::GetMetric(wxSystemMetric index, wxWindow* WXUNUSED(win))
394 {
395 #ifdef __WXMICROWIN__
396 // TODO: probably use wxUniv themes functionality
397 return 0;
398 #else // !__WXMICROWIN__
399 wxCHECK_MSG( index > 0 && (size_t)index < WXSIZEOF(gs_metricsMap), 0,
400 _T("invalid metric") );
401
402 int indexMSW = gs_metricsMap[index];
403 if ( indexMSW == -1 )
404 {
405 // not supported under current system
406 return -1;
407 }
408
409 int rc = ::GetSystemMetrics(indexMSW);
410 if ( index == wxSYS_NETWORK_PRESENT )
411 {
412 // only the last bit is significant according to the MSDN
413 rc &= 1;
414 }
415
416 return rc;
417 #endif // __WXMICROWIN__/!__WXMICROWIN__
418 }
419
420 bool wxSystemSettingsNative::HasFeature(wxSystemFeature index)
421 {
422 switch ( index )
423 {
424 case wxSYS_CAN_ICONIZE_FRAME:
425 case wxSYS_CAN_DRAW_FRAME_DECORATIONS:
426 return true;
427
428 case wxSYS_TABLET_PRESENT:
429 return ::GetSystemMetrics(SM_TABLETPC) != 0;
430
431 default:
432 wxFAIL_MSG( _T("unknown system feature") );
433
434 return false;
435 }
436 }
437
438 // ----------------------------------------------------------------------------
439 // function from wx/msw/wrapcctl.h: there is really no other place for it...
440 // ----------------------------------------------------------------------------
441
442 #if wxUSE_LISTCTRL || wxUSE_TREECTRL
443
444 extern wxFont wxGetCCDefaultFont()
445 {
446 #ifndef __WXWINCE__
447 // under the systems enumerated below (anything released after Win98), the
448 // default font used for the common controls seems to be the desktop font
449 // which is also used for the icon titles and not the stock default GUI
450 // font
451 bool useIconFont;
452 int verMaj, verMin;
453 switch ( wxGetOsVersion(&verMaj, &verMin) )
454 {
455 case wxOS_WINDOWS_9X:
456 // 4.10 is Win98
457 useIconFont = verMaj == 4 && verMin >= 10;
458 break;
459
460 case wxOS_WINDOWS_NT:
461 // 5.0 is Win2k
462 useIconFont = verMaj >= 5;
463 break;
464
465 default:
466 useIconFont = false;
467 }
468
469 if ( useIconFont )
470 {
471 LOGFONT lf;
472 if ( ::SystemParametersInfo
473 (
474 SPI_GETICONTITLELOGFONT,
475 sizeof(lf),
476 &lf,
477 0
478 ) )
479 {
480 return wxFont(wxCreateFontFromLogFont(&lf));
481 }
482 else
483 {
484 wxLogLastError(_T("SystemParametersInfo(SPI_GETICONTITLELOGFONT"));
485 }
486 }
487 #endif // __WXWINCE__
488
489 // fall back to the default font for the normal controls
490 return wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
491 }
492
493 #endif // wxUSE_LISTCTRL || wxUSE_TREECTRL

  ViewVC Help
Powered by ViewVC 1.1.22