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