]>
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 | { |
7516ed26 VZ |
100 | wxColour col; |
101 | wxRGBToColour(col, ::GetSysColor(index)); | |
102 | return col; | |
2bda0e17 KB |
103 | } |
104 | ||
7516ed26 VZ |
105 | // ---------------------------------------------------------------------------- |
106 | // fonts | |
107 | // ---------------------------------------------------------------------------- | |
108 | ||
04ef50df | 109 | wxFont wxCreateFontFromStockObject(int index) |
2bda0e17 | 110 | { |
8bf30fe9 VZ |
111 | wxFont font; |
112 | ||
019a60d6 | 113 | HFONT hFont = (HFONT) ::GetStockObject(index); |
8bf30fe9 | 114 | if ( hFont ) |
019a60d6 VS |
115 | { |
116 | LOGFONT lf; | |
117 | if ( ::GetObject(hFont, sizeof(LOGFONT), &lf) != 0 ) | |
118 | { | |
04ef50df JS |
119 | wxNativeFontInfo info; |
120 | info.lf = lf; | |
121 | // Under MicroWindows we pass the HFONT as well | |
122 | // because it's hard to convert HFONT -> LOGFONT -> HFONT | |
123 | // It's OK to delete stock objects, the delete will be ignored. | |
124 | #ifdef __WXMICROWIN__ | |
125 | font.Create(info, (WXHFONT) hFont); | |
126 | #else | |
127 | font.Create(info); | |
128 | #endif | |
019a60d6 VS |
129 | } |
130 | else | |
131 | { | |
8bf30fe9 | 132 | wxFAIL_MSG( _T("failed to get LOGFONT") ); |
019a60d6 VS |
133 | } |
134 | } | |
8bf30fe9 VZ |
135 | else // GetStockObject() failed |
136 | { | |
137 | wxFAIL_MSG( _T("stock font not found") ); | |
138 | } | |
7516ed26 | 139 | |
04ef50df JS |
140 | return font; |
141 | } | |
142 | ||
7516ed26 | 143 | wxFont wxSystemSettingsNative::GetFont(wxSystemFont index) |
04ef50df JS |
144 | { |
145 | // wxWindow ctor calls GetSystemFont(wxSYS_DEFAULT_GUI_FONT) so we're | |
146 | // called fairly often - this is why we cache this particular font | |
147 | bool isDefaultRequested = index == wxSYS_DEFAULT_GUI_FONT; | |
148 | if ( isDefaultRequested && gs_fontDefault ) | |
149 | { | |
150 | return *gs_fontDefault; | |
151 | } | |
152 | ||
153 | wxFont font = wxCreateFontFromStockObject(index); | |
8bf30fe9 VZ |
154 | |
155 | if ( isDefaultRequested ) | |
019a60d6 | 156 | { |
8bf30fe9 VZ |
157 | // if we got here it means we hadn't cached it yet - do now |
158 | gs_fontDefault = new wxFont(font); | |
019a60d6 | 159 | } |
8bf30fe9 VZ |
160 | |
161 | return font; | |
2bda0e17 KB |
162 | } |
163 | ||
7516ed26 VZ |
164 | // ---------------------------------------------------------------------------- |
165 | // system metrics/features | |
166 | // ---------------------------------------------------------------------------- | |
167 | ||
168 | // TODO: some of the "metrics" clearly should be features now that we have | |
169 | // HasFeature()! | |
170 | ||
171 | // the conversion table from wxSystemMetric enum to GetSystemMetrics() param | |
172 | // | |
173 | // if the constant is not defined, put -1 in the table to indicate that it is | |
174 | // unknown | |
175 | static const int gs_metricsMap[] = | |
2bda0e17 | 176 | { |
2bda0e17 | 177 | #ifdef __WIN32__ |
7516ed26 VZ |
178 | SM_CMOUSEBUTTONS, |
179 | #else | |
180 | -1, | |
2bda0e17 KB |
181 | #endif |
182 | ||
7516ed26 VZ |
183 | SM_CXBORDER, |
184 | SM_CYBORDER, | |
185 | SM_CXCURSOR, | |
186 | SM_CYCURSOR, | |
187 | SM_CXDOUBLECLK, | |
188 | SM_CYDOUBLECLK, | |
2432b92d | 189 | #if defined(__WIN32__) && defined(SM_CXDRAG) |
7516ed26 VZ |
190 | SM_CXDRAG, |
191 | SM_CYDRAG, | |
192 | SM_CXEDGE, | |
193 | SM_CYEDGE, | |
194 | #else | |
195 | -1, -1, -1, -1 | |
2bda0e17 | 196 | #endif |
7516ed26 VZ |
197 | SM_CXHSCROLL, |
198 | SM_CYHSCROLL, | |
199 | SM_CXHTHUMB, | |
200 | SM_CXICON, | |
201 | SM_CYICON, | |
202 | SM_CXICONSPACING, | |
203 | SM_CYICONSPACING, | |
204 | SM_CXMIN, | |
205 | SM_CYMIN, | |
206 | SM_CXSCREEN, | |
207 | SM_CYSCREEN, | |
2432b92d JS |
208 | |
209 | #if defined(__WIN32__) && defined(SM_CXSIZEFRAME) | |
7516ed26 VZ |
210 | SM_CXSIZEFRAME, |
211 | SM_CYSIZEFRAME, | |
212 | SM_CXSMICON, | |
213 | SM_CYSMICON, | |
214 | #else | |
215 | -1, -1, -1, -1 | |
2bda0e17 | 216 | #endif |
7516ed26 VZ |
217 | SM_CYHSCROLL, |
218 | SM_CXVSCROLL, | |
219 | SM_CXVSCROLL, | |
220 | SM_CYVSCROLL, | |
221 | SM_CYVTHUMB, | |
222 | SM_CYCAPTION, | |
223 | SM_CYMENU, | |
2432b92d | 224 | #if defined(__WIN32__) && defined(SM_NETWORK) |
7516ed26 VZ |
225 | SM_NETWORK, |
226 | #else | |
227 | -1, | |
2bda0e17 | 228 | #endif |
7516ed26 | 229 | SM_PENWINDOWS, |
2432b92d | 230 | #if defined(__WIN32__) && defined(SM_SHOWSOUNDS) |
7516ed26 VZ |
231 | SM_SHOWSOUNDS, |
232 | #else | |
233 | -1, | |
2bda0e17 | 234 | #endif |
7516ed26 VZ |
235 | SM_SWAPBUTTON, |
236 | }; | |
237 | ||
238 | // Get a system metric, e.g. scrollbar size | |
239 | int wxSystemSettingsNative::GetMetric(wxSystemMetric index) | |
240 | { | |
241 | #ifdef __WXMICROWIN__ | |
242 | // TODO: probably use wxUniv themes functionality | |
243 | return 0; | |
244 | #else // !__WXMICROWIN__ | |
245 | wxCHECK_MSG( index < WXSIZEOF(gs_metricsMap), 0, _T("invalid metric") ); | |
246 | ||
247 | int indexMSW = gs_metricsMap[index]; | |
248 | if ( indexMSW == -1 ) | |
249 | { | |
250 | // not supported under current system | |
251 | return 0; | |
019a60d6 | 252 | } |
7516ed26 VZ |
253 | |
254 | int rc = ::GetSystemMetrics(indexMSW); | |
255 | if ( index == wxSYS_NETWORK_PRESENT ) | |
256 | { | |
257 | // only the last bit is significant according to the MSDN | |
258 | rc &= 1; | |
259 | } | |
260 | ||
261 | return rc; | |
262 | #endif // __WXMICROWIN__/!__WXMICROWIN__ | |
2bda0e17 KB |
263 | } |
264 | ||
7516ed26 | 265 | bool wxSystemSettingsNative::HasFeature(wxSystemFeature index) |
253293c1 | 266 | { |
7516ed26 | 267 | switch ( index ) |
253293c1 | 268 | { |
7516ed26 | 269 | case wxSYS_CAN_ICONIZE_FRAME: |
253293c1 | 270 | case wxSYS_CAN_DRAW_FRAME_DECORATIONS: |
bb6de5ff | 271 | return TRUE; |
7516ed26 | 272 | |
253293c1 | 273 | default: |
7516ed26 VZ |
274 | wxFAIL_MSG( _T("unknown system feature") ); |
275 | ||
253293c1 VS |
276 | return FALSE; |
277 | } | |
278 | } |