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