]> git.saurik.com Git - wxWidgets.git/blob - src/msw/settings.cpp
applied correction from Marc Newsam in calculations of linesize
[wxWidgets.git] / src / msw / settings.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: msw/settings.cpp
3 // Purpose: wxSystemSettings
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 04/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 #ifdef __GNUG__
21 #pragma implementation "settings.h"
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
32 #include <stdio.h>
33 #include "wx/defs.h"
34 #include "wx/pen.h"
35 #include "wx/brush.h"
36 #include "wx/gdicmn.h"
37 #endif
38
39 #include "wx/settings.h"
40 #include "wx/window.h"
41 #include "wx/msw/private.h"
42
43 // ----------------------------------------------------------------------------
44 // private classes
45 // ----------------------------------------------------------------------------
46
47 // the module which is used to clean up wxSystemSettings data (this is a
48 // singleton class so it can't be done in the dtor)
49 class wxSystemSettingsModule : public wxModule
50 {
51 public:
52 virtual bool OnInit();
53 virtual void OnExit();
54
55 private:
56 DECLARE_DYNAMIC_CLASS(wxSystemSettingsModule)
57 };
58
59 // ----------------------------------------------------------------------------
60 // global data
61 // ----------------------------------------------------------------------------
62
63 static wxFont *gs_fontDefault = NULL;
64
65 // ============================================================================
66 // implementation
67 // ============================================================================
68
69 // ----------------------------------------------------------------------------
70 // wxSystemSettingsModule
71 // ----------------------------------------------------------------------------
72
73 IMPLEMENT_DYNAMIC_CLASS(wxSystemSettingsModule, wxModule)
74
75 bool wxSystemSettingsModule::OnInit()
76 {
77 return TRUE;
78 }
79
80 void wxSystemSettingsModule::OnExit()
81 {
82 delete gs_fontDefault;
83 }
84
85 // ----------------------------------------------------------------------------
86 // wxSystemSettings
87 // ----------------------------------------------------------------------------
88
89 // TODO: see ::SystemParametersInfo for all sorts of Windows settings.
90 // Different args are required depending on the id. How does this differ
91 // from GetSystemMetric, and should it? Perhaps call it GetSystemParameter
92 // and pass an optional void* arg to get further info.
93 // Should also have SetSystemParameter.
94 // Also implement WM_WININICHANGE (NT) / WM_SETTINGCHANGE (Win95)
95
96 wxColour wxSystemSettings::GetSystemColour(int index)
97 {
98 switch (index)
99 {
100 case wxSYS_COLOUR_LISTBOX:
101 return *wxWHITE;
102
103 default:
104 COLORREF ref = ::GetSysColor(index);
105 wxColour col(GetRValue(ref), GetGValue(ref), GetBValue(ref));
106 return col;
107 }
108 }
109
110 wxFont wxSystemSettings::GetSystemFont(int index)
111 {
112 // wxWindow ctor calls GetSystemFont(wxSYS_DEFAULT_GUI_FONT) so we're
113 // called fairly often - this is why we cache this particular font
114 bool isDefaultRequested = index == wxSYS_DEFAULT_GUI_FONT;
115 if ( isDefaultRequested && gs_fontDefault )
116 {
117 return *gs_fontDefault;
118 }
119
120 wxFont font;
121
122 HFONT hFont = (HFONT) ::GetStockObject(index);
123 if ( hFont )
124 {
125 LOGFONT lf;
126 if ( ::GetObject(hFont, sizeof(LOGFONT), &lf) != 0 )
127 {
128 font = wxCreateFontFromLogFont(&lf);
129 }
130 else
131 {
132 wxFAIL_MSG( _T("failed to get LOGFONT") );
133 }
134 }
135 else // GetStockObject() failed
136 {
137 wxFAIL_MSG( _T("stock font not found") );
138 }
139
140 if ( isDefaultRequested )
141 {
142 // if we got here it means we hadn't cached it yet - do now
143 gs_fontDefault = new wxFont(font);
144 }
145
146 return font;
147 }
148
149 // Get a system metric, e.g. scrollbar size
150 int wxSystemSettings::GetSystemMetric(int index)
151 {
152 switch ( index)
153 {
154 #ifdef __WIN32__
155 case wxSYS_MOUSE_BUTTONS:
156 return ::GetSystemMetrics(SM_CMOUSEBUTTONS);
157 #endif
158
159 case wxSYS_BORDER_X:
160 return ::GetSystemMetrics(SM_CXBORDER);
161 case wxSYS_BORDER_Y:
162 return ::GetSystemMetrics(SM_CYBORDER);
163 case wxSYS_CURSOR_X:
164 return ::GetSystemMetrics(SM_CXCURSOR);
165 case wxSYS_CURSOR_Y:
166 return ::GetSystemMetrics(SM_CYCURSOR);
167 case wxSYS_DCLICK_X:
168 return ::GetSystemMetrics(SM_CXDOUBLECLK);
169 case wxSYS_DCLICK_Y:
170 return ::GetSystemMetrics(SM_CYDOUBLECLK);
171 #if defined(__WIN32__) && defined(SM_CXDRAG)
172 case wxSYS_DRAG_X:
173 return ::GetSystemMetrics(SM_CXDRAG);
174 case wxSYS_DRAG_Y:
175 return ::GetSystemMetrics(SM_CYDRAG);
176 case wxSYS_EDGE_X:
177 return ::GetSystemMetrics(SM_CXEDGE);
178 case wxSYS_EDGE_Y:
179 return ::GetSystemMetrics(SM_CYEDGE);
180 #endif
181 case wxSYS_HSCROLL_ARROW_X:
182 return ::GetSystemMetrics(SM_CXHSCROLL);
183 case wxSYS_HSCROLL_ARROW_Y:
184 return ::GetSystemMetrics(SM_CYHSCROLL);
185 case wxSYS_HTHUMB_X:
186 return ::GetSystemMetrics(SM_CXHTHUMB);
187 case wxSYS_ICON_X:
188 return ::GetSystemMetrics(SM_CXICON);
189 case wxSYS_ICON_Y:
190 return ::GetSystemMetrics(SM_CYICON);
191 case wxSYS_ICONSPACING_X:
192 return ::GetSystemMetrics(SM_CXICONSPACING);
193 case wxSYS_ICONSPACING_Y:
194 return ::GetSystemMetrics(SM_CYICONSPACING);
195 case wxSYS_WINDOWMIN_X:
196 return ::GetSystemMetrics(SM_CXMIN);
197 case wxSYS_WINDOWMIN_Y:
198 return ::GetSystemMetrics(SM_CYMIN);
199 case wxSYS_SCREEN_X:
200 return ::GetSystemMetrics(SM_CXSCREEN);
201 case wxSYS_SCREEN_Y:
202 return ::GetSystemMetrics(SM_CYSCREEN);
203
204 #if defined(__WIN32__) && defined(SM_CXSIZEFRAME)
205 case wxSYS_FRAMESIZE_X:
206 return ::GetSystemMetrics(SM_CXSIZEFRAME);
207 case wxSYS_FRAMESIZE_Y:
208 return ::GetSystemMetrics(SM_CYSIZEFRAME);
209 case wxSYS_SMALLICON_X:
210 return ::GetSystemMetrics(SM_CXSMICON);
211 case wxSYS_SMALLICON_Y:
212 return ::GetSystemMetrics(SM_CYSMICON);
213 #endif
214 case wxSYS_HSCROLL_Y:
215 return ::GetSystemMetrics(SM_CYHSCROLL);
216 case wxSYS_VSCROLL_X:
217 return ::GetSystemMetrics(SM_CXVSCROLL);
218 case wxSYS_VSCROLL_ARROW_X:
219 return ::GetSystemMetrics(SM_CXVSCROLL);
220 case wxSYS_VSCROLL_ARROW_Y:
221 return ::GetSystemMetrics(SM_CYVSCROLL);
222 case wxSYS_VTHUMB_Y:
223 return ::GetSystemMetrics(SM_CYVTHUMB);
224 case wxSYS_CAPTION_Y:
225 return ::GetSystemMetrics(SM_CYCAPTION);
226 case wxSYS_MENU_Y:
227 return ::GetSystemMetrics(SM_CYMENU);
228 #if defined(__WIN32__) && defined(SM_NETWORK)
229 case wxSYS_NETWORK_PRESENT:
230 return ::GetSystemMetrics(SM_NETWORK) & 0x0001;
231 #endif
232 case wxSYS_PENWINDOWS_PRESENT:
233 return ::GetSystemMetrics(SM_PENWINDOWS);
234 #if defined(__WIN32__) && defined(SM_SHOWSOUNDS)
235 case wxSYS_SHOW_SOUNDS:
236 return ::GetSystemMetrics(SM_SHOWSOUNDS);
237 #endif
238 case wxSYS_SWAP_BUTTONS:
239 return ::GetSystemMetrics(SM_SWAPBUTTON);
240 default:
241 return 0;
242 }
243 }
244