]> git.saurik.com Git - wxWidgets.git/blame - src/msw/settings.cpp
Applied patch #421073 (making setup options work)
[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"
2bda0e17 43
8bf30fe9
VZ
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)
50class wxSystemSettingsModule : public wxModule
51{
52public:
53 virtual bool OnInit();
54 virtual void OnExit();
55
56private:
57 DECLARE_DYNAMIC_CLASS(wxSystemSettingsModule)
58};
59
60// ----------------------------------------------------------------------------
61// global data
62// ----------------------------------------------------------------------------
63
64static wxFont *gs_fontDefault = NULL;
65
66// ============================================================================
67// implementation
68// ============================================================================
69
70// ----------------------------------------------------------------------------
71// wxSystemSettingsModule
72// ----------------------------------------------------------------------------
73
74IMPLEMENT_DYNAMIC_CLASS(wxSystemSettingsModule, wxModule)
75
76bool wxSystemSettingsModule::OnInit()
77{
78 return TRUE;
79}
80
81void wxSystemSettingsModule::OnExit()
82{
83 delete gs_fontDefault;
84}
85
86// ----------------------------------------------------------------------------
87// wxSystemSettings
88// ----------------------------------------------------------------------------
89
2bda0e17
KB
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
97wxColour wxSystemSettings::GetSystemColour(int index)
98{
019a60d6
VS
99 switch (index)
100 {
101 case wxSYS_COLOUR_LISTBOX:
102 return *wxWHITE;
8bf30fe9 103
019a60d6
VS
104 default:
105 COLORREF ref = ::GetSysColor(index);
106 wxColour col(GetRValue(ref), GetGValue(ref), GetBValue(ref));
107 return col;
019a60d6 108 }
2bda0e17
KB
109}
110
111wxFont wxSystemSettings::GetSystemFont(int index)
112{
8bf30fe9
VZ
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
019a60d6 123 HFONT hFont = (HFONT) ::GetStockObject(index);
8bf30fe9 124 if ( hFont )
019a60d6
VS
125 {
126 LOGFONT lf;
127 if ( ::GetObject(hFont, sizeof(LOGFONT), &lf) != 0 )
128 {
8bf30fe9 129 font = wxCreateFontFromLogFont(&lf);
019a60d6
VS
130 }
131 else
132 {
8bf30fe9 133 wxFAIL_MSG( _T("failed to get LOGFONT") );
019a60d6
VS
134 }
135 }
8bf30fe9
VZ
136 else // GetStockObject() failed
137 {
138 wxFAIL_MSG( _T("stock font not found") );
139 }
140
141 if ( isDefaultRequested )
019a60d6 142 {
8bf30fe9
VZ
143 // if we got here it means we hadn't cached it yet - do now
144 gs_fontDefault = new wxFont(font);
019a60d6 145 }
8bf30fe9
VZ
146
147 return font;
2bda0e17
KB
148}
149
150// Get a system metric, e.g. scrollbar size
151int wxSystemSettings::GetSystemMetric(int index)
152{
019a60d6
VS
153 switch ( index)
154 {
2bda0e17
KB
155#ifdef __WIN32__
156 case wxSYS_MOUSE_BUTTONS:
019a60d6 157 return ::GetSystemMetrics(SM_CMOUSEBUTTONS);
2bda0e17
KB
158#endif
159
160 case wxSYS_BORDER_X:
019a60d6 161 return ::GetSystemMetrics(SM_CXBORDER);
2bda0e17 162 case wxSYS_BORDER_Y:
019a60d6 163 return ::GetSystemMetrics(SM_CYBORDER);
2bda0e17 164 case wxSYS_CURSOR_X:
019a60d6 165 return ::GetSystemMetrics(SM_CXCURSOR);
2bda0e17 166 case wxSYS_CURSOR_Y:
019a60d6 167 return ::GetSystemMetrics(SM_CYCURSOR);
2bda0e17 168 case wxSYS_DCLICK_X:
019a60d6 169 return ::GetSystemMetrics(SM_CXDOUBLECLK);
2bda0e17 170 case wxSYS_DCLICK_Y:
019a60d6 171 return ::GetSystemMetrics(SM_CYDOUBLECLK);
2432b92d 172#if defined(__WIN32__) && defined(SM_CXDRAG)
2bda0e17 173 case wxSYS_DRAG_X:
019a60d6 174 return ::GetSystemMetrics(SM_CXDRAG);
2bda0e17 175 case wxSYS_DRAG_Y:
019a60d6 176 return ::GetSystemMetrics(SM_CYDRAG);
2bda0e17 177 case wxSYS_EDGE_X:
019a60d6 178 return ::GetSystemMetrics(SM_CXEDGE);
2bda0e17 179 case wxSYS_EDGE_Y:
019a60d6 180 return ::GetSystemMetrics(SM_CYEDGE);
2bda0e17
KB
181#endif
182 case wxSYS_HSCROLL_ARROW_X:
019a60d6 183 return ::GetSystemMetrics(SM_CXHSCROLL);
2bda0e17 184 case wxSYS_HSCROLL_ARROW_Y:
019a60d6 185 return ::GetSystemMetrics(SM_CYHSCROLL);
2bda0e17 186 case wxSYS_HTHUMB_X:
019a60d6 187 return ::GetSystemMetrics(SM_CXHTHUMB);
2bda0e17 188 case wxSYS_ICON_X:
019a60d6 189 return ::GetSystemMetrics(SM_CXICON);
2bda0e17 190 case wxSYS_ICON_Y:
019a60d6 191 return ::GetSystemMetrics(SM_CYICON);
2bda0e17 192 case wxSYS_ICONSPACING_X:
019a60d6 193 return ::GetSystemMetrics(SM_CXICONSPACING);
2bda0e17 194 case wxSYS_ICONSPACING_Y:
019a60d6 195 return ::GetSystemMetrics(SM_CYICONSPACING);
2bda0e17 196 case wxSYS_WINDOWMIN_X:
019a60d6 197 return ::GetSystemMetrics(SM_CXMIN);
2bda0e17 198 case wxSYS_WINDOWMIN_Y:
019a60d6 199 return ::GetSystemMetrics(SM_CYMIN);
2bda0e17 200 case wxSYS_SCREEN_X:
019a60d6 201 return ::GetSystemMetrics(SM_CXSCREEN);
2bda0e17 202 case wxSYS_SCREEN_Y:
019a60d6 203 return ::GetSystemMetrics(SM_CYSCREEN);
2432b92d
JS
204
205#if defined(__WIN32__) && defined(SM_CXSIZEFRAME)
2bda0e17 206 case wxSYS_FRAMESIZE_X:
019a60d6 207 return ::GetSystemMetrics(SM_CXSIZEFRAME);
2bda0e17 208 case wxSYS_FRAMESIZE_Y:
019a60d6 209 return ::GetSystemMetrics(SM_CYSIZEFRAME);
2bda0e17 210 case wxSYS_SMALLICON_X:
019a60d6 211 return ::GetSystemMetrics(SM_CXSMICON);
2bda0e17 212 case wxSYS_SMALLICON_Y:
019a60d6 213 return ::GetSystemMetrics(SM_CYSMICON);
2bda0e17
KB
214#endif
215 case wxSYS_HSCROLL_Y:
019a60d6 216 return ::GetSystemMetrics(SM_CYHSCROLL);
2bda0e17 217 case wxSYS_VSCROLL_X:
019a60d6 218 return ::GetSystemMetrics(SM_CXVSCROLL);
2bda0e17 219 case wxSYS_VSCROLL_ARROW_X:
019a60d6 220 return ::GetSystemMetrics(SM_CXVSCROLL);
2bda0e17 221 case wxSYS_VSCROLL_ARROW_Y:
019a60d6 222 return ::GetSystemMetrics(SM_CYVSCROLL);
2bda0e17 223 case wxSYS_VTHUMB_Y:
019a60d6 224 return ::GetSystemMetrics(SM_CYVTHUMB);
2bda0e17 225 case wxSYS_CAPTION_Y:
019a60d6 226 return ::GetSystemMetrics(SM_CYCAPTION);
2bda0e17 227 case wxSYS_MENU_Y:
019a60d6 228 return ::GetSystemMetrics(SM_CYMENU);
2432b92d 229#if defined(__WIN32__) && defined(SM_NETWORK)
2bda0e17 230 case wxSYS_NETWORK_PRESENT:
019a60d6 231 return ::GetSystemMetrics(SM_NETWORK) & 0x0001;
2bda0e17
KB
232#endif
233 case wxSYS_PENWINDOWS_PRESENT:
019a60d6 234 return ::GetSystemMetrics(SM_PENWINDOWS);
2432b92d 235#if defined(__WIN32__) && defined(SM_SHOWSOUNDS)
2bda0e17 236 case wxSYS_SHOW_SOUNDS:
019a60d6 237 return ::GetSystemMetrics(SM_SHOWSOUNDS);
2bda0e17
KB
238#endif
239 case wxSYS_SWAP_BUTTONS:
019a60d6
VS
240 return ::GetSystemMetrics(SM_SWAPBUTTON);
241 default:
242 return 0;
243 }
2bda0e17
KB
244}
245