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