1 /////////////////////////////////////////////////////////////////////////////
2 // Name: msw/settings.cpp
3 // Purpose: wxSystemSettings
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
21 #pragma implementation "settings.h"
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
36 #include "wx/gdicmn.h"
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"
45 // ----------------------------------------------------------------------------
47 // ----------------------------------------------------------------------------
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
53 friend class wxSystemSettings
;
55 virtual bool OnInit();
56 virtual void OnExit();
59 DECLARE_DYNAMIC_CLASS(wxSystemSettingsModule
)
62 // ----------------------------------------------------------------------------
64 // ----------------------------------------------------------------------------
66 static wxFont
*gs_fontDefault
= NULL
;
68 // ============================================================================
70 // ============================================================================
72 // ----------------------------------------------------------------------------
73 // wxSystemSettingsModule
74 // ----------------------------------------------------------------------------
76 IMPLEMENT_DYNAMIC_CLASS(wxSystemSettingsModule
, wxModule
)
78 bool wxSystemSettingsModule::OnInit()
83 void wxSystemSettingsModule::OnExit()
85 delete gs_fontDefault
;
86 gs_fontDefault
= NULL
;
89 // ----------------------------------------------------------------------------
91 // ----------------------------------------------------------------------------
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)
100 wxColour
wxSystemSettings::GetSystemColour(int index
)
104 case wxSYS_COLOUR_LISTBOX
:
108 COLORREF ref
= ::GetSysColor(index
);
109 wxColour
col(GetRValue(ref
), GetGValue(ref
), GetBValue(ref
));
114 wxFont
wxCreateFontFromStockObject(int index
)
118 HFONT hFont
= (HFONT
) ::GetStockObject(index
);
122 if ( ::GetObject(hFont
, sizeof(LOGFONT
), &lf
) != 0 )
124 wxNativeFontInfo info
;
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
);
137 wxFAIL_MSG( _T("failed to get LOGFONT") );
140 else // GetStockObject() failed
142 wxFAIL_MSG( _T("stock font not found") );
147 wxFont
wxSystemSettings::GetSystemFont(int index
)
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
)
154 return *gs_fontDefault
;
157 wxFont font
= wxCreateFontFromStockObject(index
);
159 if ( isDefaultRequested
)
161 // if we got here it means we hadn't cached it yet - do now
162 gs_fontDefault
= new wxFont(font
);
168 // Get a system metric, e.g. scrollbar size
169 int wxSystemSettings::GetSystemMetric(int index
)
171 #ifdef __WXMICROWIN__
172 // TODO: probably use wxUniv themes functionality
178 case wxSYS_MOUSE_BUTTONS
:
179 return ::GetSystemMetrics(SM_CMOUSEBUTTONS
);
183 return ::GetSystemMetrics(SM_CXBORDER
);
185 return ::GetSystemMetrics(SM_CYBORDER
);
187 return ::GetSystemMetrics(SM_CXCURSOR
);
189 return ::GetSystemMetrics(SM_CYCURSOR
);
191 return ::GetSystemMetrics(SM_CXDOUBLECLK
);
193 return ::GetSystemMetrics(SM_CYDOUBLECLK
);
194 #if defined(__WIN32__) && defined(SM_CXDRAG)
196 return ::GetSystemMetrics(SM_CXDRAG
);
198 return ::GetSystemMetrics(SM_CYDRAG
);
200 return ::GetSystemMetrics(SM_CXEDGE
);
202 return ::GetSystemMetrics(SM_CYEDGE
);
204 case wxSYS_HSCROLL_ARROW_X
:
205 return ::GetSystemMetrics(SM_CXHSCROLL
);
206 case wxSYS_HSCROLL_ARROW_Y
:
207 return ::GetSystemMetrics(SM_CYHSCROLL
);
209 return ::GetSystemMetrics(SM_CXHTHUMB
);
211 return ::GetSystemMetrics(SM_CXICON
);
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
);
223 return ::GetSystemMetrics(SM_CXSCREEN
);
225 return ::GetSystemMetrics(SM_CYSCREEN
);
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
);
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
);
246 return ::GetSystemMetrics(SM_CYVTHUMB
);
247 case wxSYS_CAPTION_Y
:
248 return ::GetSystemMetrics(SM_CYCAPTION
);
250 return ::GetSystemMetrics(SM_CYMENU
);
251 #if defined(__WIN32__) && defined(SM_NETWORK)
252 case wxSYS_NETWORK_PRESENT
:
253 return ::GetSystemMetrics(SM_NETWORK
) & 0x0001;
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
);
261 case wxSYS_SWAP_BUTTONS
:
262 return ::GetSystemMetrics(SM_SWAPBUTTON
);
270 bool wxSystemSettings::GetCapability(int index
)
274 case wxSYS_CAN_ICONIZE_FRAME
:
275 case wxSYS_CAN_DRAW_FRAME_DECORATIONS
: