]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/settings.cpp
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"
44 // ----------------------------------------------------------------------------
46 // ----------------------------------------------------------------------------
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
53 virtual bool OnInit();
54 virtual void OnExit();
57 DECLARE_DYNAMIC_CLASS(wxSystemSettingsModule
)
60 // ----------------------------------------------------------------------------
62 // ----------------------------------------------------------------------------
64 static wxFont
*gs_fontDefault
= NULL
;
66 // ============================================================================
68 // ============================================================================
70 // ----------------------------------------------------------------------------
71 // wxSystemSettingsModule
72 // ----------------------------------------------------------------------------
74 IMPLEMENT_DYNAMIC_CLASS(wxSystemSettingsModule
, wxModule
)
76 bool wxSystemSettingsModule::OnInit()
81 void wxSystemSettingsModule::OnExit()
83 delete gs_fontDefault
;
86 // ----------------------------------------------------------------------------
88 // ----------------------------------------------------------------------------
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)
97 wxColour
wxSystemSettings::GetSystemColour(int index
)
101 case wxSYS_COLOUR_LISTBOX
:
105 COLORREF ref
= ::GetSysColor(index
);
106 wxColour
col(GetRValue(ref
), GetGValue(ref
), GetBValue(ref
));
111 wxFont
wxSystemSettings::GetSystemFont(int index
)
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
)
118 return *gs_fontDefault
;
123 HFONT hFont
= (HFONT
) ::GetStockObject(index
);
127 if ( ::GetObject(hFont
, sizeof(LOGFONT
), &lf
) != 0 )
129 font
= wxCreateFontFromLogFont(&lf
);
133 wxFAIL_MSG( _T("failed to get LOGFONT") );
136 else // GetStockObject() failed
138 wxFAIL_MSG( _T("stock font not found") );
141 if ( isDefaultRequested
)
143 // if we got here it means we hadn't cached it yet - do now
144 gs_fontDefault
= new wxFont(font
);
150 // Get a system metric, e.g. scrollbar size
151 int wxSystemSettings::GetSystemMetric(int index
)
156 case wxSYS_MOUSE_BUTTONS
:
157 return ::GetSystemMetrics(SM_CMOUSEBUTTONS
);
161 return ::GetSystemMetrics(SM_CXBORDER
);
163 return ::GetSystemMetrics(SM_CYBORDER
);
165 return ::GetSystemMetrics(SM_CXCURSOR
);
167 return ::GetSystemMetrics(SM_CYCURSOR
);
169 return ::GetSystemMetrics(SM_CXDOUBLECLK
);
171 return ::GetSystemMetrics(SM_CYDOUBLECLK
);
172 #if defined(__WIN32__) && defined(SM_CXDRAG)
174 return ::GetSystemMetrics(SM_CXDRAG
);
176 return ::GetSystemMetrics(SM_CYDRAG
);
178 return ::GetSystemMetrics(SM_CXEDGE
);
180 return ::GetSystemMetrics(SM_CYEDGE
);
182 case wxSYS_HSCROLL_ARROW_X
:
183 return ::GetSystemMetrics(SM_CXHSCROLL
);
184 case wxSYS_HSCROLL_ARROW_Y
:
185 return ::GetSystemMetrics(SM_CYHSCROLL
);
187 return ::GetSystemMetrics(SM_CXHTHUMB
);
189 return ::GetSystemMetrics(SM_CXICON
);
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
);
201 return ::GetSystemMetrics(SM_CXSCREEN
);
203 return ::GetSystemMetrics(SM_CYSCREEN
);
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
);
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
);
224 return ::GetSystemMetrics(SM_CYVTHUMB
);
225 case wxSYS_CAPTION_Y
:
226 return ::GetSystemMetrics(SM_CYCAPTION
);
228 return ::GetSystemMetrics(SM_CYMENU
);
229 #if defined(__WIN32__) && defined(SM_NETWORK)
230 case wxSYS_NETWORK_PRESENT
:
231 return ::GetSystemMetrics(SM_NETWORK
) & 0x0001;
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
);
239 case wxSYS_SWAP_BUTTONS
:
240 return ::GetSystemMetrics(SM_SWAPBUTTON
);