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