]> git.saurik.com Git - wxWidgets.git/blame - src/os2/settings.cpp
cleanup
[wxWidgets.git] / src / os2 / settings.cpp
CommitLineData
0e320a79 1/////////////////////////////////////////////////////////////////////////////
63a3cd7a 2// Name: src/os2/settings.cpp
0e320a79 3// Purpose: wxSettings
409c9842 4// Author: David Webster
0e320a79 5// Modified by:
409c9842 6// Created: 10/15/99
0e320a79 7// RCS-ID: $Id$
409c9842 8// Copyright: (c) David Webster
65571936 9// Licence: wxWindows licence
0e320a79
DW
10/////////////////////////////////////////////////////////////////////////////
11
409c9842
DW
12// For compilers that support precompilation, includes "wx.h".
13#include "wx/wxprec.h"
14
15#ifndef WX_PRECOMP
7520f3da
WS
16 #include <stdio.h>
17 #include "wx/pen.h"
18 #include "wx/brush.h"
19 #include "wx/gdicmn.h"
cdccdfab 20 #include "wx/window.h"
9eddec69 21 #include "wx/settings.h"
02761f6c 22 #include "wx/module.h"
0e320a79
DW
23#endif
24
03eefe82
WS
25#include "wx/fontutil.h"
26
409c9842 27#include "wx/os2/private.h"
0e320a79 28
fd6d5c94
DW
29// the module which is used to clean up wxSystemSettings data (this is a
30// singleton class so it can't be done in the dtor)
31class wxSystemSettingsModule : public wxModule
32{
33 friend class wxSystemSettings;
34public:
35 virtual bool OnInit();
36 virtual void OnExit();
37
38private:
39 DECLARE_DYNAMIC_CLASS(wxSystemSettingsModule)
40
41 static wxArrayString sm_optionNames;
42 static wxArrayString sm_optionValues;
43};
44
45// ----------------------------------------------------------------------------
46// global data
47// ----------------------------------------------------------------------------
48
49static wxFont *gs_fontDefault = NULL;
50
51// ============================================================================
52// implementation
53// ============================================================================
54
55// ----------------------------------------------------------------------------
56// wxSystemSettingsModule
57// ----------------------------------------------------------------------------
58
59IMPLEMENT_DYNAMIC_CLASS(wxSystemSettingsModule, wxModule)
60
61wxArrayString wxSystemSettingsModule::sm_optionNames;
62wxArrayString wxSystemSettingsModule::sm_optionValues;
63
64bool wxSystemSettingsModule::OnInit()
65{
63a3cd7a 66 return true;
fd6d5c94
DW
67}
68
69void wxSystemSettingsModule::OnExit()
70{
71 sm_optionNames.Clear();
72 sm_optionValues.Clear();
73 delete gs_fontDefault;
109c9204 74 gs_fontDefault = NULL;
fd6d5c94
DW
75}
76
793c7f9b
DW
77wxColour wxSystemSettingsNative::GetColour(
78 wxSystemColour nIndex
a0606634 79)
0e320a79 80{
a0606634
DW
81 COLORREF vRef;
82 wxColour vCol;
a12f4647 83 LONG vSysClr;
a0606634
DW
84 switch (nIndex)
85 {
86 //
87 // PM actually has values for these
88 //
89 case wxSYS_COLOUR_WINDOW:
a12f4647 90 vSysClr = SYSCLR_WINDOW;
a0606634
DW
91 break;
92
93 case wxSYS_COLOUR_WINDOWFRAME:
a12f4647 94 vSysClr = SYSCLR_WINDOWFRAME;
a0606634
DW
95 break;
96
97 case wxSYS_COLOUR_MENUTEXT:
a12f4647
SN
98 vSysClr = SYSCLR_MENUTEXT;
99 break;
100
101 case wxSYS_COLOUR_MENUHILIGHT:
102 vSysClr = SYSCLR_MENUHILITE;
a0606634
DW
103 break;
104
105 case wxSYS_COLOUR_BTNFACE:
a12f4647 106 vSysClr = SYSCLR_BUTTONMIDDLE;
a0606634
DW
107 break;
108
109 case wxSYS_COLOUR_BTNSHADOW:
a12f4647 110 vSysClr = SYSCLR_BUTTONDARK;
a0606634
DW
111 break;
112
113 case wxSYS_COLOUR_BTNHIGHLIGHT:
a12f4647
SN
114 vSysClr = SYSCLR_BUTTONLIGHT;
115 break;
116
117 case wxSYS_COLOUR_BACKGROUND:
118 vSysClr = SYSCLR_BACKGROUND;
119 break;
120
121 case wxSYS_COLOUR_APPWORKSPACE:
122 vSysClr = SYSCLR_APPWORKSPACE;
a0606634
DW
123 break;
124
d697657f 125 case wxSYS_COLOUR_MENUBAR:
a12f4647
SN
126 case wxSYS_COLOUR_MENU:
127 vSysClr = SYSCLR_MENU;
128 break;
129
130 case wxSYS_COLOUR_INACTIVECAPTION:
131 vSysClr = SYSCLR_INACTIVETITLE;
132 break;
133
134 case wxSYS_COLOUR_INACTIVEBORDER:
135 vSysClr = SYSCLR_INACTIVEBORDER;
d697657f
DW
136 break;
137
a0606634 138 case wxSYS_COLOUR_LISTBOX:
a12f4647
SN
139 vSysClr = SYSCLR_ENTRYFIELD;
140 break;
141
a0606634 142 case wxSYS_COLOUR_CAPTIONTEXT:
a12f4647
SN
143 vSysClr = SYSCLR_TITLETEXT;
144 break;
a0606634 145
a0606634 146 case wxSYS_COLOUR_INACTIVECAPTIONTEXT:
a12f4647
SN
147 vSysClr = SYSCLR_INACTIVETITLETEXT;
148 break;
149
150 case wxSYS_COLOUR_WINDOWTEXT:
a0606634 151 case wxSYS_COLOUR_BTNTEXT:
a12f4647 152 vSysClr = SYSCLR_WINDOWTEXT;
a0606634
DW
153 break;
154
a12f4647
SN
155 case wxSYS_COLOUR_INFOTEXT:
156 vSysClr = SYSCLR_HELPTEXT;
157 break;
a0606634
DW
158
159 case wxSYS_COLOUR_ACTIVECAPTION:
a12f4647
SN
160 vSysClr = SYSCLR_ACTIVETITLE;
161 break;
162
a0606634 163 case wxSYS_COLOUR_ACTIVEBORDER:
a12f4647
SN
164 vSysClr = SYSCLR_ACTIVEBORDER;
165 break;
166
a0606634 167 case wxSYS_COLOUR_HIGHLIGHT:
a12f4647 168 vSysClr = SYSCLR_HILITEBACKGROUND;
a0606634
DW
169 break;
170
171 case wxSYS_COLOUR_SCROLLBAR:
a12f4647
SN
172 vSysClr = SYSCLR_SCROLLBAR;
173 break;
174
a0606634 175 case wxSYS_COLOUR_HIGHLIGHTTEXT:
a12f4647
SN
176 vSysClr = SYSCLR_HILITEFOREGROUND;
177 break;
178
179 case wxSYS_COLOUR_INFOBK:
180 vSysClr = SYSCLR_HELPBACKGROUND;
181 break;
182
183 // Don't know what these should be, so leave them grey (normally)
a0606634
DW
184 case wxSYS_COLOUR_GRAYTEXT:
185 case wxSYS_COLOUR_3DDKSHADOW:
186 case wxSYS_COLOUR_3DLIGHT:
a12f4647
SN
187 case wxSYS_COLOUR_HOTLIGHT:
188 case wxSYS_COLOUR_GRADIENTACTIVECAPTION:
189 case wxSYS_COLOUR_GRADIENTINACTIVECAPTION:
190 vSysClr = SYSCLR_BUTTONMIDDLE;
a0606634
DW
191 break;
192
193 default:
a12f4647 194 vSysClr = SYSCLR_WINDOW;
a0606634
DW
195 break;
196 }
a12f4647
SN
197 vRef = (ULONG)::WinQuerySysColor( HWND_DESKTOP,
198 vSysClr,
199 0L );
200 vCol.Set( GetRValue(vRef),
201 GetGValue(vRef),
202 GetBValue(vRef) );
a0606634 203 return(vCol);
793c7f9b 204} // end of wxSystemSettingsNative::GetColour
0e320a79 205
109c9204
SN
206// ----------------------------------------------------------------------------
207// fonts
208// ----------------------------------------------------------------------------
209
793c7f9b
DW
210wxFont wxSystemSettingsNative::GetFont(
211 wxSystemFont index
212)
0e320a79 213{
109c9204
SN
214 const bool isDefaultRequested = index == wxSYS_DEFAULT_GUI_FONT;
215 if ( isDefaultRequested )
0e320a79 216 {
109c9204
SN
217 if ( gs_fontDefault )
218 return *gs_fontDefault;
219 }
220
3b0e208f
SN
221 wxFont font;
222 // FIXME: The mapping could be improved and also OS/2 system fonts
223 // should be taken into account e.g. by using PrfQueryProfileString
224 // to look for PM_System_Fonts in HINI_USERPROFILE.
225 // FIXME2: Creating a font from the native font info does not
226 // seem to work properly.
227 switch (index)
228 {
229 case wxSYS_SYSTEM_FIXED_FONT:
230 case wxSYS_OEM_FIXED_FONT:
231 case wxSYS_ANSI_FIXED_FONT:
232 font.Create( 10,
233 wxFONTFAMILY_TELETYPE,
234 wxFONTSTYLE_NORMAL,
235 wxFONTWEIGHT_NORMAL );
236 break;
237 case wxSYS_ANSI_VAR_FONT:
238 font.Create( 10,
239 wxFONTFAMILY_MODERN,
240 wxFONTSTYLE_NORMAL,
241 wxFONTWEIGHT_NORMAL );
242 break;
243 case wxSYS_SYSTEM_FONT:
244 case wxSYS_DEFAULT_GUI_FONT:
245 font.Create( 10,
246 wxFONTFAMILY_SWISS,
247 wxFONTSTYLE_NORMAL,
248 wxFONTWEIGHT_NORMAL );
249 break;
250 default:
251 wxFAIL_MSG( _T("stock font not found") );
252 return GetFont(wxSYS_ANSI_VAR_FONT);
253 }
254
109c9204
SN
255
256 if ( isDefaultRequested )
257 {
258 // if we got here it means we hadn't cached it yet - do now
259 gs_fontDefault = new wxFont(font);
0e320a79
DW
260 }
261
109c9204 262 return font;
0e320a79
DW
263}
264
265// Get a system metric, e.g. scrollbar size
6670f564
WS
266int wxSystemSettingsNative::GetMetric( wxSystemMetric index,
267 wxWindow* WXUNUSED(win) )
0e320a79 268{
409c9842
DW
269 switch ( index)
270 {
1d451c5b
RD
271 // TODO case wxSYS_MOUSE_BUTTONS:
272 // TODO case wxSYS_BORDER_X:
273 // TODO case wxSYS_BORDER_Y:
274 // TODO case wxSYS_CURSOR_X:
275 // TODO case wxSYS_CURSOR_Y:
276 // TODO case wxSYS_DCLICK_X:
277 // TODO case wxSYS_DCLICK_Y:
278 // TODO case wxSYS_DRAG_X:
279 // TODO case wxSYS_DRAG_Y:
280 // TODO case wxSYS_EDGE_X:
281 // TODO case wxSYS_EDGE_Y:
282 // TODO case wxSYS_HSCROLL_ARROW_X:
283 // TODO case wxSYS_HSCROLL_ARROW_Y:
284 // TODO case wxSYS_HTHUMB_X:
285 // TODO case wxSYS_ICON_X:
286 // TODO case wxSYS_ICON_Y:
287 // TODO case wxSYS_ICONSPACING_X:
288 // TODO case wxSYS_ICONSPACING_Y:
289 // TODO case wxSYS_WINDOWMIN_X:
290 // TODO case wxSYS_WINDOWMIN_Y:
6670f564 291
0e320a79 292 case wxSYS_SCREEN_X:
68a2e005 293 return ::WinQuerySysValue(HWND_DESKTOP,SV_CXSCREEN);
0e320a79 294 case wxSYS_SCREEN_Y:
68a2e005 295 return ::WinQuerySysValue(HWND_DESKTOP,SV_CYSCREEN);
6670f564 296
1d451c5b
RD
297 // TODO case wxSYS_FRAMESIZE_X:
298 // TODO case wxSYS_FRAMESIZE_Y:
299 // TODO case wxSYS_SMALLICON_X:
300 // TODO case wxSYS_SMALLICON_Y:
a12f4647
SN
301
302 case wxSYS_HSCROLL_Y:
303 return ::WinQuerySysValue(HWND_DESKTOP,SV_CYHSCROLL);
304 case wxSYS_VSCROLL_X:
305 return ::WinQuerySysValue(HWND_DESKTOP,SV_CXVSCROLL);
306
1d451c5b
RD
307 // TODO case wxSYS_VSCROLL_ARROW_X:
308 // TODO case wxSYS_VSCROLL_ARROW_Y:
309 // TODO case wxSYS_VTHUMB_Y:
310 // TODO case wxSYS_CAPTION_Y:
311 // TODO case wxSYS_MENU_Y:
312 // TODO case wxSYS_NETWORK_PRESENT:
313 // TODO case wxSYS_PENWINDOWS_PRESENT:
314 // TODO case wxSYS_SHOW_SOUNDS:
315 // TODO case wxSYS_SWAP_BUTTONS:
63a3cd7a
WS
316
317 default:
63ae3663 318 break;
409c9842 319 }
6670f564 320 return -1; // unsupported metric
0e320a79
DW
321}
322
6670f564 323bool wxSystemSettingsNative::HasFeature( wxSystemFeature index )
253293c1
VS
324{
325 switch (index)
326 {
1a2076a2 327 case wxSYS_CAN_ICONIZE_FRAME:
6670f564 328 return true;
793c7f9b 329
45abfa71
WS
330 // TODO case wxSYS_CAN_DRAW_FRAME_DECORATIONS:
331 // TODO case wxSYS_TABLET_PRESENT:
332
333 default:
334 break;
253293c1 335 }
6670f564
WS
336
337 return false;
253293c1 338}