]> git.saurik.com Git - wxWidgets.git/blame - src/msw/settings.cpp
patch to fix various filename-related functions for cygwin
[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
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)
44class wxSystemSettingsModule : public wxModule
45{
46public:
47 virtual bool OnInit();
48 virtual void OnExit();
49
50private:
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
60static 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
77IMPLEMENT_DYNAMIC_CLASS(wxSystemSettingsModule, wxModule)
78
79bool wxSystemSettingsModule::OnInit()
80{
81 return TRUE;
82}
83
84void 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 98wxColour 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 109wxFont 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 143wxFont 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
175static const int gs_metricsMap[] =
2bda0e17 176{
fc29e86e 177 -1, // wxSystemMetric enums start at 1, so give a dummy value for pos 0.
2bda0e17 178#ifdef __WIN32__
7516ed26
VZ
179 SM_CMOUSEBUTTONS,
180#else
181 -1,
2bda0e17
KB
182#endif
183
7516ed26
VZ
184 SM_CXBORDER,
185 SM_CYBORDER,
186 SM_CXCURSOR,
187 SM_CYCURSOR,
188 SM_CXDOUBLECLK,
189 SM_CYDOUBLECLK,
2432b92d 190#if defined(__WIN32__) && defined(SM_CXDRAG)
7516ed26
VZ
191 SM_CXDRAG,
192 SM_CYDRAG,
193 SM_CXEDGE,
194 SM_CYEDGE,
195#else
196 -1, -1, -1, -1
2bda0e17 197#endif
7516ed26
VZ
198 SM_CXHSCROLL,
199 SM_CYHSCROLL,
200 SM_CXHTHUMB,
201 SM_CXICON,
202 SM_CYICON,
203 SM_CXICONSPACING,
204 SM_CYICONSPACING,
205 SM_CXMIN,
206 SM_CYMIN,
207 SM_CXSCREEN,
208 SM_CYSCREEN,
2432b92d
JS
209
210#if defined(__WIN32__) && defined(SM_CXSIZEFRAME)
7516ed26
VZ
211 SM_CXSIZEFRAME,
212 SM_CYSIZEFRAME,
213 SM_CXSMICON,
214 SM_CYSMICON,
215#else
216 -1, -1, -1, -1
2bda0e17 217#endif
7516ed26
VZ
218 SM_CYHSCROLL,
219 SM_CXVSCROLL,
220 SM_CXVSCROLL,
221 SM_CYVSCROLL,
222 SM_CYVTHUMB,
223 SM_CYCAPTION,
224 SM_CYMENU,
2432b92d 225#if defined(__WIN32__) && defined(SM_NETWORK)
7516ed26
VZ
226 SM_NETWORK,
227#else
228 -1,
2bda0e17 229#endif
7516ed26 230 SM_PENWINDOWS,
2432b92d 231#if defined(__WIN32__) && defined(SM_SHOWSOUNDS)
7516ed26
VZ
232 SM_SHOWSOUNDS,
233#else
234 -1,
2bda0e17 235#endif
7516ed26
VZ
236 SM_SWAPBUTTON,
237};
238
239// Get a system metric, e.g. scrollbar size
240int wxSystemSettingsNative::GetMetric(wxSystemMetric index)
241{
242#ifdef __WXMICROWIN__
243 // TODO: probably use wxUniv themes functionality
244 return 0;
245#else // !__WXMICROWIN__
246 wxCHECK_MSG( index < WXSIZEOF(gs_metricsMap), 0, _T("invalid metric") );
247
248 int indexMSW = gs_metricsMap[index];
249 if ( indexMSW == -1 )
250 {
251 // not supported under current system
252 return 0;
019a60d6 253 }
7516ed26
VZ
254
255 int rc = ::GetSystemMetrics(indexMSW);
256 if ( index == wxSYS_NETWORK_PRESENT )
257 {
258 // only the last bit is significant according to the MSDN
259 rc &= 1;
260 }
261
262 return rc;
263#endif // __WXMICROWIN__/!__WXMICROWIN__
2bda0e17
KB
264}
265
7516ed26 266bool wxSystemSettingsNative::HasFeature(wxSystemFeature index)
253293c1 267{
7516ed26 268 switch ( index )
253293c1 269 {
7516ed26 270 case wxSYS_CAN_ICONIZE_FRAME:
253293c1 271 case wxSYS_CAN_DRAW_FRAME_DECORATIONS:
bb6de5ff 272 return TRUE;
7516ed26 273
253293c1 274 default:
7516ed26
VZ
275 wxFAIL_MSG( _T("unknown system feature") );
276
253293c1
VS
277 return FALSE;
278 }
279}