]> git.saurik.com Git - wxWidgets.git/blame - src/msw/settings.cpp
compilation fixes
[wxWidgets.git] / src / msw / settings.cpp
CommitLineData
2bda0e17 1/////////////////////////////////////////////////////////////////////////////
8bf30fe9
VZ
2// Name: msw/settings.cpp
3// Purpose: wxSystemSettings
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 20#ifdef __GNUG__
8bf30fe9 21 #pragma implementation "settings.h"
2bda0e17
KB
22#endif
23
24// For compilers that support precompilation, includes "wx.h".
25#include "wx/wxprec.h"
26
27#ifdef __BORLANDC__
28#pragma hdrstop
29#endif
30
31#ifndef WX_PRECOMP
8bf30fe9
VZ
32 #include <stdio.h>
33 #include "wx/defs.h"
34 #include "wx/pen.h"
35 #include "wx/brush.h"
36 #include "wx/gdicmn.h"
2bda0e17
KB
37#endif
38
39#include "wx/settings.h"
40#include "wx/window.h"
41#include "wx/msw/private.h"
2e6d38ad 42#include "wx/module.h"
2bda0e17 43
8bf30fe9
VZ
44// ----------------------------------------------------------------------------
45// private classes
46// ----------------------------------------------------------------------------
47
48// the module which is used to clean up wxSystemSettings data (this is a
49// singleton class so it can't be done in the dtor)
50class wxSystemSettingsModule : public wxModule
51{
d3211838 52 friend class wxSystemSettings;
8bf30fe9
VZ
53public:
54 virtual bool OnInit();
55 virtual void OnExit();
56
57private:
58 DECLARE_DYNAMIC_CLASS(wxSystemSettingsModule)
d3211838
JS
59
60 static wxArrayString sm_optionNames;
61 static wxArrayString sm_optionValues;
8bf30fe9
VZ
62};
63
64// ----------------------------------------------------------------------------
65// global data
66// ----------------------------------------------------------------------------
67
68static wxFont *gs_fontDefault = NULL;
69
70// ============================================================================
71// implementation
72// ============================================================================
73
74// ----------------------------------------------------------------------------
75// wxSystemSettingsModule
76// ----------------------------------------------------------------------------
77
78IMPLEMENT_DYNAMIC_CLASS(wxSystemSettingsModule, wxModule)
79
d3211838
JS
80wxArrayString wxSystemSettingsModule::sm_optionNames;
81wxArrayString wxSystemSettingsModule::sm_optionValues;
82
8bf30fe9
VZ
83bool wxSystemSettingsModule::OnInit()
84{
85 return TRUE;
86}
87
88void wxSystemSettingsModule::OnExit()
89{
d3211838
JS
90 sm_optionNames.Clear();
91 sm_optionValues.Clear();
8bf30fe9
VZ
92 delete gs_fontDefault;
93}
94
95// ----------------------------------------------------------------------------
96// wxSystemSettings
97// ----------------------------------------------------------------------------
98
2bda0e17
KB
99// TODO: see ::SystemParametersInfo for all sorts of Windows settings.
100// Different args are required depending on the id. How does this differ
101// from GetSystemMetric, and should it? Perhaps call it GetSystemParameter
102// and pass an optional void* arg to get further info.
103// Should also have SetSystemParameter.
104// Also implement WM_WININICHANGE (NT) / WM_SETTINGCHANGE (Win95)
105
106wxColour wxSystemSettings::GetSystemColour(int index)
107{
019a60d6
VS
108 switch (index)
109 {
110 case wxSYS_COLOUR_LISTBOX:
111 return *wxWHITE;
8bf30fe9 112
019a60d6
VS
113 default:
114 COLORREF ref = ::GetSysColor(index);
115 wxColour col(GetRValue(ref), GetGValue(ref), GetBValue(ref));
116 return col;
019a60d6 117 }
2bda0e17
KB
118}
119
120wxFont wxSystemSettings::GetSystemFont(int index)
121{
8bf30fe9
VZ
122 // wxWindow ctor calls GetSystemFont(wxSYS_DEFAULT_GUI_FONT) so we're
123 // called fairly often - this is why we cache this particular font
124 bool isDefaultRequested = index == wxSYS_DEFAULT_GUI_FONT;
125 if ( isDefaultRequested && gs_fontDefault )
126 {
127 return *gs_fontDefault;
128 }
129
130 wxFont font;
131
019a60d6 132 HFONT hFont = (HFONT) ::GetStockObject(index);
8bf30fe9 133 if ( hFont )
019a60d6
VS
134 {
135 LOGFONT lf;
136 if ( ::GetObject(hFont, sizeof(LOGFONT), &lf) != 0 )
137 {
8bf30fe9 138 font = wxCreateFontFromLogFont(&lf);
019a60d6
VS
139 }
140 else
141 {
8bf30fe9 142 wxFAIL_MSG( _T("failed to get LOGFONT") );
019a60d6
VS
143 }
144 }
8bf30fe9
VZ
145 else // GetStockObject() failed
146 {
147 wxFAIL_MSG( _T("stock font not found") );
148 }
149
150 if ( isDefaultRequested )
019a60d6 151 {
8bf30fe9
VZ
152 // if we got here it means we hadn't cached it yet - do now
153 gs_fontDefault = new wxFont(font);
019a60d6 154 }
8bf30fe9
VZ
155
156 return font;
2bda0e17
KB
157}
158
159// Get a system metric, e.g. scrollbar size
160int wxSystemSettings::GetSystemMetric(int index)
161{
019a60d6
VS
162 switch ( index)
163 {
2bda0e17
KB
164#ifdef __WIN32__
165 case wxSYS_MOUSE_BUTTONS:
019a60d6 166 return ::GetSystemMetrics(SM_CMOUSEBUTTONS);
2bda0e17
KB
167#endif
168
169 case wxSYS_BORDER_X:
019a60d6 170 return ::GetSystemMetrics(SM_CXBORDER);
2bda0e17 171 case wxSYS_BORDER_Y:
019a60d6 172 return ::GetSystemMetrics(SM_CYBORDER);
2bda0e17 173 case wxSYS_CURSOR_X:
019a60d6 174 return ::GetSystemMetrics(SM_CXCURSOR);
2bda0e17 175 case wxSYS_CURSOR_Y:
019a60d6 176 return ::GetSystemMetrics(SM_CYCURSOR);
2bda0e17 177 case wxSYS_DCLICK_X:
019a60d6 178 return ::GetSystemMetrics(SM_CXDOUBLECLK);
2bda0e17 179 case wxSYS_DCLICK_Y:
019a60d6 180 return ::GetSystemMetrics(SM_CYDOUBLECLK);
2432b92d 181#if defined(__WIN32__) && defined(SM_CXDRAG)
2bda0e17 182 case wxSYS_DRAG_X:
019a60d6 183 return ::GetSystemMetrics(SM_CXDRAG);
2bda0e17 184 case wxSYS_DRAG_Y:
019a60d6 185 return ::GetSystemMetrics(SM_CYDRAG);
2bda0e17 186 case wxSYS_EDGE_X:
019a60d6 187 return ::GetSystemMetrics(SM_CXEDGE);
2bda0e17 188 case wxSYS_EDGE_Y:
019a60d6 189 return ::GetSystemMetrics(SM_CYEDGE);
2bda0e17
KB
190#endif
191 case wxSYS_HSCROLL_ARROW_X:
019a60d6 192 return ::GetSystemMetrics(SM_CXHSCROLL);
2bda0e17 193 case wxSYS_HSCROLL_ARROW_Y:
019a60d6 194 return ::GetSystemMetrics(SM_CYHSCROLL);
2bda0e17 195 case wxSYS_HTHUMB_X:
019a60d6 196 return ::GetSystemMetrics(SM_CXHTHUMB);
2bda0e17 197 case wxSYS_ICON_X:
019a60d6 198 return ::GetSystemMetrics(SM_CXICON);
2bda0e17 199 case wxSYS_ICON_Y:
019a60d6 200 return ::GetSystemMetrics(SM_CYICON);
2bda0e17 201 case wxSYS_ICONSPACING_X:
019a60d6 202 return ::GetSystemMetrics(SM_CXICONSPACING);
2bda0e17 203 case wxSYS_ICONSPACING_Y:
019a60d6 204 return ::GetSystemMetrics(SM_CYICONSPACING);
2bda0e17 205 case wxSYS_WINDOWMIN_X:
019a60d6 206 return ::GetSystemMetrics(SM_CXMIN);
2bda0e17 207 case wxSYS_WINDOWMIN_Y:
019a60d6 208 return ::GetSystemMetrics(SM_CYMIN);
2bda0e17 209 case wxSYS_SCREEN_X:
019a60d6 210 return ::GetSystemMetrics(SM_CXSCREEN);
2bda0e17 211 case wxSYS_SCREEN_Y:
019a60d6 212 return ::GetSystemMetrics(SM_CYSCREEN);
2432b92d
JS
213
214#if defined(__WIN32__) && defined(SM_CXSIZEFRAME)
2bda0e17 215 case wxSYS_FRAMESIZE_X:
019a60d6 216 return ::GetSystemMetrics(SM_CXSIZEFRAME);
2bda0e17 217 case wxSYS_FRAMESIZE_Y:
019a60d6 218 return ::GetSystemMetrics(SM_CYSIZEFRAME);
2bda0e17 219 case wxSYS_SMALLICON_X:
019a60d6 220 return ::GetSystemMetrics(SM_CXSMICON);
2bda0e17 221 case wxSYS_SMALLICON_Y:
019a60d6 222 return ::GetSystemMetrics(SM_CYSMICON);
2bda0e17
KB
223#endif
224 case wxSYS_HSCROLL_Y:
019a60d6 225 return ::GetSystemMetrics(SM_CYHSCROLL);
2bda0e17 226 case wxSYS_VSCROLL_X:
019a60d6 227 return ::GetSystemMetrics(SM_CXVSCROLL);
2bda0e17 228 case wxSYS_VSCROLL_ARROW_X:
019a60d6 229 return ::GetSystemMetrics(SM_CXVSCROLL);
2bda0e17 230 case wxSYS_VSCROLL_ARROW_Y:
019a60d6 231 return ::GetSystemMetrics(SM_CYVSCROLL);
2bda0e17 232 case wxSYS_VTHUMB_Y:
019a60d6 233 return ::GetSystemMetrics(SM_CYVTHUMB);
2bda0e17 234 case wxSYS_CAPTION_Y:
019a60d6 235 return ::GetSystemMetrics(SM_CYCAPTION);
2bda0e17 236 case wxSYS_MENU_Y:
019a60d6 237 return ::GetSystemMetrics(SM_CYMENU);
2432b92d 238#if defined(__WIN32__) && defined(SM_NETWORK)
2bda0e17 239 case wxSYS_NETWORK_PRESENT:
019a60d6 240 return ::GetSystemMetrics(SM_NETWORK) & 0x0001;
2bda0e17
KB
241#endif
242 case wxSYS_PENWINDOWS_PRESENT:
019a60d6 243 return ::GetSystemMetrics(SM_PENWINDOWS);
2432b92d 244#if defined(__WIN32__) && defined(SM_SHOWSOUNDS)
2bda0e17 245 case wxSYS_SHOW_SOUNDS:
019a60d6 246 return ::GetSystemMetrics(SM_SHOWSOUNDS);
2bda0e17
KB
247#endif
248 case wxSYS_SWAP_BUTTONS:
019a60d6
VS
249 return ::GetSystemMetrics(SM_SWAPBUTTON);
250 default:
251 return 0;
252 }
2bda0e17
KB
253}
254
d3211838
JS
255// Option functions (arbitrary name/value mapping)
256void wxSystemSettings::SetOption(const wxString& name, const wxString& value)
257{
258 int idx = wxSystemSettingsModule::sm_optionNames.Index(name, FALSE);
259 if (idx == wxNOT_FOUND)
260 {
261 wxSystemSettingsModule::sm_optionNames.Add(name);
262 wxSystemSettingsModule::sm_optionValues.Add(value);
263 }
264 else
265 {
266 wxSystemSettingsModule::sm_optionNames[idx] = name;
267 wxSystemSettingsModule::sm_optionValues[idx] = value;
268 }
269}
270
271void wxSystemSettings::SetOption(const wxString& name, int value)
272{
273 wxString valStr;
274 valStr.Printf(wxT("%d"), value);
275 SetOption(name, valStr);
276}
277
278wxString wxSystemSettings::GetOption(const wxString& name)
279{
280 int idx = wxSystemSettingsModule::sm_optionNames.Index(name, FALSE);
281 if (idx == wxNOT_FOUND)
282 return wxEmptyString;
283 else
284 return wxSystemSettingsModule::sm_optionValues[idx];
285}
286
287int wxSystemSettings::GetOptionInt(const wxString& name)
288{
289 return wxAtoi(GetOption(name));
290}
291
292bool wxSystemSettings::HasOption(const wxString& name)
293{
294 return (wxSystemSettingsModule::sm_optionNames.Index(name, FALSE) != wxNOT_FOUND);
295}
296