]>
Commit | Line | Data |
---|---|---|
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$ | |
8 | // Copyright: (c) Julian Smart and Markus Holzem | |
019a60d6 | 9 | // Licence: wxWindows license |
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 | |
8bf30fe9 | 28 | #include "wx/gdicmn.h" |
2bda0e17 KB |
29 | #endif |
30 | ||
31 | #include "wx/settings.h" | |
7516ed26 | 32 | |
2bda0e17 | 33 | #include "wx/msw/private.h" |
7516ed26 | 34 | |
2e6d38ad | 35 | #include "wx/module.h" |
04ef50df | 36 | #include "wx/fontutil.h" |
2bda0e17 | 37 | |
8bf30fe9 VZ |
38 | // ---------------------------------------------------------------------------- |
39 | // private classes | |
40 | // ---------------------------------------------------------------------------- | |
41 | ||
7516ed26 | 42 | // the module which is used to clean up wxSystemSettingsNative data (this is a |
8bf30fe9 VZ |
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 | ||
7516ed26 VZ |
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 | |
8bf30fe9 VZ |
60 | static wxFont *gs_fontDefault = NULL; |
61 | ||
62 | // ============================================================================ | |
63 | // implementation | |
64 | // ============================================================================ | |
65 | ||
7516ed26 VZ |
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 | ||
8bf30fe9 VZ |
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; | |
0cbff120 | 87 | gs_fontDefault = NULL; |
8bf30fe9 VZ |
88 | } |
89 | ||
90 | // ---------------------------------------------------------------------------- | |
7516ed26 | 91 | // wxSystemSettingsNative |
8bf30fe9 VZ |
92 | // ---------------------------------------------------------------------------- |
93 | ||
7516ed26 VZ |
94 | // ---------------------------------------------------------------------------- |
95 | // colours | |
96 | // ---------------------------------------------------------------------------- | |
2bda0e17 | 97 | |
7516ed26 | 98 | wxColour wxSystemSettingsNative::GetColour(wxSystemColour index) |
2bda0e17 | 99 | { |
7d6d3bf3 VZ |
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); | |
2bda0e17 KB |
192 | } |
193 | ||
7516ed26 VZ |
194 | // ---------------------------------------------------------------------------- |
195 | // fonts | |
196 | // ---------------------------------------------------------------------------- | |
197 | ||
04ef50df | 198 | wxFont wxCreateFontFromStockObject(int index) |
2bda0e17 | 199 | { |
8bf30fe9 VZ |
200 | wxFont font; |
201 | ||
019a60d6 | 202 | HFONT hFont = (HFONT) ::GetStockObject(index); |
8bf30fe9 | 203 | if ( hFont ) |
019a60d6 VS |
204 | { |
205 | LOGFONT lf; | |
206 | if ( ::GetObject(hFont, sizeof(LOGFONT), &lf) != 0 ) | |
207 | { | |
04ef50df JS |
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 | |
019a60d6 VS |
218 | } |
219 | else | |
220 | { | |
8bf30fe9 | 221 | wxFAIL_MSG( _T("failed to get LOGFONT") ); |
019a60d6 VS |
222 | } |
223 | } | |
8bf30fe9 VZ |
224 | else // GetStockObject() failed |
225 | { | |
226 | wxFAIL_MSG( _T("stock font not found") ); | |
227 | } | |
7516ed26 | 228 | |
04ef50df JS |
229 | return font; |
230 | } | |
231 | ||
7516ed26 | 232 | wxFont wxSystemSettingsNative::GetFont(wxSystemFont index) |
04ef50df JS |
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); | |
8bf30fe9 VZ |
243 | |
244 | if ( isDefaultRequested ) | |
019a60d6 | 245 | { |
8bf30fe9 VZ |
246 | // if we got here it means we hadn't cached it yet - do now |
247 | gs_fontDefault = new wxFont(font); | |
019a60d6 | 248 | } |
8bf30fe9 VZ |
249 | |
250 | return font; | |
2bda0e17 KB |
251 | } |
252 | ||
7516ed26 VZ |
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[] = | |
2bda0e17 | 265 | { |
fc29e86e | 266 | -1, // wxSystemMetric enums start at 1, so give a dummy value for pos 0. |
2bda0e17 | 267 | #ifdef __WIN32__ |
7516ed26 VZ |
268 | SM_CMOUSEBUTTONS, |
269 | #else | |
270 | -1, | |
2bda0e17 KB |
271 | #endif |
272 | ||
7516ed26 VZ |
273 | SM_CXBORDER, |
274 | SM_CYBORDER, | |
275 | SM_CXCURSOR, | |
276 | SM_CYCURSOR, | |
277 | SM_CXDOUBLECLK, | |
278 | SM_CYDOUBLECLK, | |
2432b92d | 279 | #if defined(__WIN32__) && defined(SM_CXDRAG) |
7516ed26 VZ |
280 | SM_CXDRAG, |
281 | SM_CYDRAG, | |
282 | SM_CXEDGE, | |
283 | SM_CYEDGE, | |
284 | #else | |
285 | -1, -1, -1, -1 | |
2bda0e17 | 286 | #endif |
7516ed26 VZ |
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, | |
2432b92d JS |
298 | |
299 | #if defined(__WIN32__) && defined(SM_CXSIZEFRAME) | |
7516ed26 VZ |
300 | SM_CXSIZEFRAME, |
301 | SM_CYSIZEFRAME, | |
302 | SM_CXSMICON, | |
303 | SM_CYSMICON, | |
304 | #else | |
305 | -1, -1, -1, -1 | |
2bda0e17 | 306 | #endif |
7516ed26 VZ |
307 | SM_CYHSCROLL, |
308 | SM_CXVSCROLL, | |
309 | SM_CXVSCROLL, | |
310 | SM_CYVSCROLL, | |
311 | SM_CYVTHUMB, | |
312 | SM_CYCAPTION, | |
313 | SM_CYMENU, | |
2432b92d | 314 | #if defined(__WIN32__) && defined(SM_NETWORK) |
7516ed26 VZ |
315 | SM_NETWORK, |
316 | #else | |
317 | -1, | |
2bda0e17 | 318 | #endif |
7516ed26 | 319 | SM_PENWINDOWS, |
2432b92d | 320 | #if defined(__WIN32__) && defined(SM_SHOWSOUNDS) |
7516ed26 VZ |
321 | SM_SHOWSOUNDS, |
322 | #else | |
323 | -1, | |
2bda0e17 | 324 | #endif |
7516ed26 VZ |
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; | |
019a60d6 | 342 | } |
7516ed26 VZ |
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__ | |
2bda0e17 KB |
353 | } |
354 | ||
7516ed26 | 355 | bool wxSystemSettingsNative::HasFeature(wxSystemFeature index) |
253293c1 | 356 | { |
7516ed26 | 357 | switch ( index ) |
253293c1 | 358 | { |
7516ed26 | 359 | case wxSYS_CAN_ICONIZE_FRAME: |
253293c1 | 360 | case wxSYS_CAN_DRAW_FRAME_DECORATIONS: |
bb6de5ff | 361 | return TRUE; |
7516ed26 | 362 | |
253293c1 | 363 | default: |
7516ed26 VZ |
364 | wxFAIL_MSG( _T("unknown system feature") ); |
365 | ||
253293c1 VS |
366 | return FALSE; |
367 | } | |
368 | } |