]> git.saurik.com Git - wxWidgets.git/blame - src/msw/settings.cpp
don't use wxTheXXXList in wxXXX ctor/dtor, only objects explicitly created
[wxWidgets.git] / src / msw / settings.cpp
CommitLineData
2bda0e17 1/////////////////////////////////////////////////////////////////////////////
8bf30fe9
VZ
2// Name: msw/settings.cpp
3// Purpose: wxSystemSettings
2bda0e17
KB
4// Author: Julian Smart
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart and Markus Holzem
019a60d6 9// Licence: wxWindows license
2bda0e17
KB
10/////////////////////////////////////////////////////////////////////////////
11
8bf30fe9
VZ
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
2bda0e17 20#ifdef __GNUG__
8bf30fe9 21 #pragma implementation "settings.h"
2bda0e17
KB
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
8bf30fe9
VZ
32 #include <stdio.h>
33 #include "wx/defs.h"
34 #include "wx/pen.h"
35 #include "wx/brush.h"
36 #include "wx/gdicmn.h"
2bda0e17
KB
37#endif
38
39#include "wx/settings.h"
40#include "wx/window.h"
41#include "wx/msw/private.h"
2e6d38ad 42#include "wx/module.h"
04ef50df 43#include "wx/fontutil.h"
2bda0e17 44
8bf30fe9
VZ
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)
51class wxSystemSettingsModule : public wxModule
52{
d3211838 53 friend class wxSystemSettings;
8bf30fe9
VZ
54public:
55 virtual bool OnInit();
56 virtual void OnExit();
57
58private:
59 DECLARE_DYNAMIC_CLASS(wxSystemSettingsModule)
60};
61
62// ----------------------------------------------------------------------------
63// global data
64// ----------------------------------------------------------------------------
65
66static wxFont *gs_fontDefault = NULL;
67
68// ============================================================================
69// implementation
70// ============================================================================
71
72// ----------------------------------------------------------------------------
73// wxSystemSettingsModule
74// ----------------------------------------------------------------------------
75
76IMPLEMENT_DYNAMIC_CLASS(wxSystemSettingsModule, wxModule)
77
78bool wxSystemSettingsModule::OnInit()
79{
80 return TRUE;
81}
82
83void wxSystemSettingsModule::OnExit()
84{
85 delete gs_fontDefault;
0cbff120 86 gs_fontDefault = NULL;
8bf30fe9
VZ
87}
88
89// ----------------------------------------------------------------------------
90// wxSystemSettings
91// ----------------------------------------------------------------------------
92
2bda0e17
KB
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
100wxColour wxSystemSettings::GetSystemColour(int index)
101{
019a60d6
VS
102 switch (index)
103 {
104 case wxSYS_COLOUR_LISTBOX:
105 return *wxWHITE;
8bf30fe9 106
019a60d6
VS
107 default:
108 COLORREF ref = ::GetSysColor(index);
109 wxColour col(GetRValue(ref), GetGValue(ref), GetBValue(ref));
110 return col;
019a60d6 111 }
2bda0e17
KB
112}
113
04ef50df 114wxFont wxCreateFontFromStockObject(int index)
2bda0e17 115{
8bf30fe9
VZ
116 wxFont font;
117
019a60d6 118 HFONT hFont = (HFONT) ::GetStockObject(index);
8bf30fe9 119 if ( hFont )
019a60d6
VS
120 {
121 LOGFONT lf;
122 if ( ::GetObject(hFont, sizeof(LOGFONT), &lf) != 0 )
123 {
04ef50df
JS
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
019a60d6
VS
134 }
135 else
136 {
8bf30fe9 137 wxFAIL_MSG( _T("failed to get LOGFONT") );
019a60d6
VS
138 }
139 }
8bf30fe9
VZ
140 else // GetStockObject() failed
141 {
142 wxFAIL_MSG( _T("stock font not found") );
143 }
04ef50df
JS
144 return font;
145}
146
147wxFont 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);
8bf30fe9
VZ
158
159 if ( isDefaultRequested )
019a60d6 160 {
8bf30fe9
VZ
161 // if we got here it means we hadn't cached it yet - do now
162 gs_fontDefault = new wxFont(font);
019a60d6 163 }
8bf30fe9
VZ
164
165 return font;
2bda0e17
KB
166}
167
168// Get a system metric, e.g. scrollbar size
169int wxSystemSettings::GetSystemMetric(int index)
170{
04ef50df
JS
171#ifdef __WXMICROWIN__
172 // TODO: probably use wxUniv themes functionality
173 return 0;
174#else
019a60d6
VS
175 switch ( index)
176 {
2bda0e17
KB
177#ifdef __WIN32__
178 case wxSYS_MOUSE_BUTTONS:
019a60d6 179 return ::GetSystemMetrics(SM_CMOUSEBUTTONS);
2bda0e17
KB
180#endif
181
182 case wxSYS_BORDER_X:
019a60d6 183 return ::GetSystemMetrics(SM_CXBORDER);
2bda0e17 184 case wxSYS_BORDER_Y:
019a60d6 185 return ::GetSystemMetrics(SM_CYBORDER);
2bda0e17 186 case wxSYS_CURSOR_X:
019a60d6 187 return ::GetSystemMetrics(SM_CXCURSOR);
2bda0e17 188 case wxSYS_CURSOR_Y:
019a60d6 189 return ::GetSystemMetrics(SM_CYCURSOR);
2bda0e17 190 case wxSYS_DCLICK_X:
019a60d6 191 return ::GetSystemMetrics(SM_CXDOUBLECLK);
2bda0e17 192 case wxSYS_DCLICK_Y:
019a60d6 193 return ::GetSystemMetrics(SM_CYDOUBLECLK);
2432b92d 194#if defined(__WIN32__) && defined(SM_CXDRAG)
2bda0e17 195 case wxSYS_DRAG_X:
019a60d6 196 return ::GetSystemMetrics(SM_CXDRAG);
2bda0e17 197 case wxSYS_DRAG_Y:
019a60d6 198 return ::GetSystemMetrics(SM_CYDRAG);
2bda0e17 199 case wxSYS_EDGE_X:
019a60d6 200 return ::GetSystemMetrics(SM_CXEDGE);
2bda0e17 201 case wxSYS_EDGE_Y:
019a60d6 202 return ::GetSystemMetrics(SM_CYEDGE);
2bda0e17
KB
203#endif
204 case wxSYS_HSCROLL_ARROW_X:
019a60d6 205 return ::GetSystemMetrics(SM_CXHSCROLL);
2bda0e17 206 case wxSYS_HSCROLL_ARROW_Y:
019a60d6 207 return ::GetSystemMetrics(SM_CYHSCROLL);
2bda0e17 208 case wxSYS_HTHUMB_X:
019a60d6 209 return ::GetSystemMetrics(SM_CXHTHUMB);
2bda0e17 210 case wxSYS_ICON_X:
019a60d6 211 return ::GetSystemMetrics(SM_CXICON);
2bda0e17 212 case wxSYS_ICON_Y:
019a60d6 213 return ::GetSystemMetrics(SM_CYICON);
2bda0e17 214 case wxSYS_ICONSPACING_X:
019a60d6 215 return ::GetSystemMetrics(SM_CXICONSPACING);
2bda0e17 216 case wxSYS_ICONSPACING_Y:
019a60d6 217 return ::GetSystemMetrics(SM_CYICONSPACING);
2bda0e17 218 case wxSYS_WINDOWMIN_X:
019a60d6 219 return ::GetSystemMetrics(SM_CXMIN);
2bda0e17 220 case wxSYS_WINDOWMIN_Y:
019a60d6 221 return ::GetSystemMetrics(SM_CYMIN);
2bda0e17 222 case wxSYS_SCREEN_X:
019a60d6 223 return ::GetSystemMetrics(SM_CXSCREEN);
2bda0e17 224 case wxSYS_SCREEN_Y:
019a60d6 225 return ::GetSystemMetrics(SM_CYSCREEN);
2432b92d
JS
226
227#if defined(__WIN32__) && defined(SM_CXSIZEFRAME)
2bda0e17 228 case wxSYS_FRAMESIZE_X:
019a60d6 229 return ::GetSystemMetrics(SM_CXSIZEFRAME);
2bda0e17 230 case wxSYS_FRAMESIZE_Y:
019a60d6 231 return ::GetSystemMetrics(SM_CYSIZEFRAME);
2bda0e17 232 case wxSYS_SMALLICON_X:
019a60d6 233 return ::GetSystemMetrics(SM_CXSMICON);
2bda0e17 234 case wxSYS_SMALLICON_Y:
019a60d6 235 return ::GetSystemMetrics(SM_CYSMICON);
2bda0e17
KB
236#endif
237 case wxSYS_HSCROLL_Y:
019a60d6 238 return ::GetSystemMetrics(SM_CYHSCROLL);
2bda0e17 239 case wxSYS_VSCROLL_X:
019a60d6 240 return ::GetSystemMetrics(SM_CXVSCROLL);
2bda0e17 241 case wxSYS_VSCROLL_ARROW_X:
019a60d6 242 return ::GetSystemMetrics(SM_CXVSCROLL);
2bda0e17 243 case wxSYS_VSCROLL_ARROW_Y:
019a60d6 244 return ::GetSystemMetrics(SM_CYVSCROLL);
2bda0e17 245 case wxSYS_VTHUMB_Y:
019a60d6 246 return ::GetSystemMetrics(SM_CYVTHUMB);
2bda0e17 247 case wxSYS_CAPTION_Y:
019a60d6 248 return ::GetSystemMetrics(SM_CYCAPTION);
2bda0e17 249 case wxSYS_MENU_Y:
019a60d6 250 return ::GetSystemMetrics(SM_CYMENU);
2432b92d 251#if defined(__WIN32__) && defined(SM_NETWORK)
2bda0e17 252 case wxSYS_NETWORK_PRESENT:
019a60d6 253 return ::GetSystemMetrics(SM_NETWORK) & 0x0001;
2bda0e17
KB
254#endif
255 case wxSYS_PENWINDOWS_PRESENT:
019a60d6 256 return ::GetSystemMetrics(SM_PENWINDOWS);
2432b92d 257#if defined(__WIN32__) && defined(SM_SHOWSOUNDS)
2bda0e17 258 case wxSYS_SHOW_SOUNDS:
019a60d6 259 return ::GetSystemMetrics(SM_SHOWSOUNDS);
2bda0e17
KB
260#endif
261 case wxSYS_SWAP_BUTTONS:
019a60d6
VS
262 return ::GetSystemMetrics(SM_SWAPBUTTON);
263 default:
264 return 0;
265 }
04ef50df
JS
266#endif
267 // __WXMICROWIN__
2bda0e17
KB
268}
269
253293c1
VS
270bool wxSystemSettings::GetCapability(int index)
271{
272 switch (index)
273 {
274 case wxSYS_CAN_ICONIZE_FRAME:
275 case wxSYS_CAN_DRAW_FRAME_DECORATIONS:
276 return TRUE; break;
277 default:
278 return FALSE;
279 }
280}