]> git.saurik.com Git - wxWidgets.git/blame - src/os2/settings.cpp
Rewind the input stream after failing to load image from it.
[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();
5276b0a5 73 wxDELETE(gs_fontDefault);
fd6d5c94
DW
74}
75
793c7f9b
DW
76wxColour wxSystemSettingsNative::GetColour(
77 wxSystemColour nIndex
a0606634 78)
0e320a79 79{
a0606634
DW
80 COLORREF vRef;
81 wxColour vCol;
a12f4647 82 LONG vSysClr;
a0606634
DW
83 switch (nIndex)
84 {
85 //
86 // PM actually has values for these
87 //
88 case wxSYS_COLOUR_WINDOW:
a12f4647 89 vSysClr = SYSCLR_WINDOW;
a0606634
DW
90 break;
91
92 case wxSYS_COLOUR_WINDOWFRAME:
a12f4647 93 vSysClr = SYSCLR_WINDOWFRAME;
a0606634
DW
94 break;
95
96 case wxSYS_COLOUR_MENUTEXT:
a12f4647
SN
97 vSysClr = SYSCLR_MENUTEXT;
98 break;
99
100 case wxSYS_COLOUR_MENUHILIGHT:
101 vSysClr = SYSCLR_MENUHILITE;
a0606634
DW
102 break;
103
104 case wxSYS_COLOUR_BTNFACE:
a12f4647 105 vSysClr = SYSCLR_BUTTONMIDDLE;
a0606634
DW
106 break;
107
108 case wxSYS_COLOUR_BTNSHADOW:
a12f4647 109 vSysClr = SYSCLR_BUTTONDARK;
a0606634
DW
110 break;
111
112 case wxSYS_COLOUR_BTNHIGHLIGHT:
a12f4647
SN
113 vSysClr = SYSCLR_BUTTONLIGHT;
114 break;
115
116 case wxSYS_COLOUR_BACKGROUND:
117 vSysClr = SYSCLR_BACKGROUND;
118 break;
119
120 case wxSYS_COLOUR_APPWORKSPACE:
121 vSysClr = SYSCLR_APPWORKSPACE;
a0606634
DW
122 break;
123
d697657f 124 case wxSYS_COLOUR_MENUBAR:
a12f4647
SN
125 case wxSYS_COLOUR_MENU:
126 vSysClr = SYSCLR_MENU;
127 break;
128
129 case wxSYS_COLOUR_INACTIVECAPTION:
130 vSysClr = SYSCLR_INACTIVETITLE;
131 break;
132
133 case wxSYS_COLOUR_INACTIVEBORDER:
134 vSysClr = SYSCLR_INACTIVEBORDER;
d697657f
DW
135 break;
136
a0606634 137 case wxSYS_COLOUR_LISTBOX:
a12f4647
SN
138 vSysClr = SYSCLR_ENTRYFIELD;
139 break;
140
a0606634 141 case wxSYS_COLOUR_CAPTIONTEXT:
a12f4647
SN
142 vSysClr = SYSCLR_TITLETEXT;
143 break;
a0606634 144
a0606634 145 case wxSYS_COLOUR_INACTIVECAPTIONTEXT:
a12f4647
SN
146 vSysClr = SYSCLR_INACTIVETITLETEXT;
147 break;
148
149 case wxSYS_COLOUR_WINDOWTEXT:
a0606634 150 case wxSYS_COLOUR_BTNTEXT:
a12f4647 151 vSysClr = SYSCLR_WINDOWTEXT;
a0606634
DW
152 break;
153
a12f4647
SN
154 case wxSYS_COLOUR_INFOTEXT:
155 vSysClr = SYSCLR_HELPTEXT;
156 break;
a0606634
DW
157
158 case wxSYS_COLOUR_ACTIVECAPTION:
a12f4647
SN
159 vSysClr = SYSCLR_ACTIVETITLE;
160 break;
161
a0606634 162 case wxSYS_COLOUR_ACTIVEBORDER:
a12f4647
SN
163 vSysClr = SYSCLR_ACTIVEBORDER;
164 break;
165
a0606634 166 case wxSYS_COLOUR_HIGHLIGHT:
a12f4647 167 vSysClr = SYSCLR_HILITEBACKGROUND;
a0606634
DW
168 break;
169
170 case wxSYS_COLOUR_SCROLLBAR:
a12f4647
SN
171 vSysClr = SYSCLR_SCROLLBAR;
172 break;
173
a0606634 174 case wxSYS_COLOUR_HIGHLIGHTTEXT:
a12f4647
SN
175 vSysClr = SYSCLR_HILITEFOREGROUND;
176 break;
177
178 case wxSYS_COLOUR_INFOBK:
179 vSysClr = SYSCLR_HELPBACKGROUND;
180 break;
181
182 // Don't know what these should be, so leave them grey (normally)
a0606634
DW
183 case wxSYS_COLOUR_GRAYTEXT:
184 case wxSYS_COLOUR_3DDKSHADOW:
185 case wxSYS_COLOUR_3DLIGHT:
a12f4647
SN
186 case wxSYS_COLOUR_HOTLIGHT:
187 case wxSYS_COLOUR_GRADIENTACTIVECAPTION:
188 case wxSYS_COLOUR_GRADIENTINACTIVECAPTION:
189 vSysClr = SYSCLR_BUTTONMIDDLE;
a0606634
DW
190 break;
191
192 default:
a12f4647 193 vSysClr = SYSCLR_WINDOW;
a0606634
DW
194 break;
195 }
a12f4647
SN
196 vRef = (ULONG)::WinQuerySysColor( HWND_DESKTOP,
197 vSysClr,
198 0L );
199 vCol.Set( GetRValue(vRef),
200 GetGValue(vRef),
201 GetBValue(vRef) );
a0606634 202 return(vCol);
793c7f9b 203} // end of wxSystemSettingsNative::GetColour
0e320a79 204
109c9204
SN
205// ----------------------------------------------------------------------------
206// fonts
207// ----------------------------------------------------------------------------
208
793c7f9b
DW
209wxFont wxSystemSettingsNative::GetFont(
210 wxSystemFont index
211)
0e320a79 212{
109c9204
SN
213 const bool isDefaultRequested = index == wxSYS_DEFAULT_GUI_FONT;
214 if ( isDefaultRequested )
0e320a79 215 {
109c9204
SN
216 if ( gs_fontDefault )
217 return *gs_fontDefault;
218 }
219
3b0e208f
SN
220 wxFont font;
221 // FIXME: The mapping could be improved and also OS/2 system fonts
222 // should be taken into account e.g. by using PrfQueryProfileString
223 // to look for PM_System_Fonts in HINI_USERPROFILE.
224 // FIXME2: Creating a font from the native font info does not
225 // seem to work properly.
226 switch (index)
227 {
228 case wxSYS_SYSTEM_FIXED_FONT:
229 case wxSYS_OEM_FIXED_FONT:
230 case wxSYS_ANSI_FIXED_FONT:
231 font.Create( 10,
232 wxFONTFAMILY_TELETYPE,
233 wxFONTSTYLE_NORMAL,
234 wxFONTWEIGHT_NORMAL );
235 break;
236 case wxSYS_ANSI_VAR_FONT:
237 font.Create( 10,
238 wxFONTFAMILY_MODERN,
239 wxFONTSTYLE_NORMAL,
240 wxFONTWEIGHT_NORMAL );
241 break;
242 case wxSYS_SYSTEM_FONT:
243 case wxSYS_DEFAULT_GUI_FONT:
244 font.Create( 10,
245 wxFONTFAMILY_SWISS,
246 wxFONTSTYLE_NORMAL,
247 wxFONTWEIGHT_NORMAL );
248 break;
249 default:
9a83f860 250 wxFAIL_MSG( wxT("stock font not found") );
3b0e208f
SN
251 return GetFont(wxSYS_ANSI_VAR_FONT);
252 }
253
109c9204
SN
254
255 if ( isDefaultRequested )
256 {
257 // if we got here it means we hadn't cached it yet - do now
258 gs_fontDefault = new wxFont(font);
0e320a79
DW
259 }
260
109c9204 261 return font;
0e320a79
DW
262}
263
264// Get a system metric, e.g. scrollbar size
6670f564
WS
265int wxSystemSettingsNative::GetMetric( wxSystemMetric index,
266 wxWindow* WXUNUSED(win) )
0e320a79 267{
409c9842
DW
268 switch ( index)
269 {
1d451c5b
RD
270 // TODO case wxSYS_MOUSE_BUTTONS:
271 // TODO case wxSYS_BORDER_X:
272 // TODO case wxSYS_BORDER_Y:
273 // TODO case wxSYS_CURSOR_X:
274 // TODO case wxSYS_CURSOR_Y:
275 // TODO case wxSYS_DCLICK_X:
276 // TODO case wxSYS_DCLICK_Y:
277 // TODO case wxSYS_DRAG_X:
278 // TODO case wxSYS_DRAG_Y:
279 // TODO case wxSYS_EDGE_X:
280 // TODO case wxSYS_EDGE_Y:
281 // TODO case wxSYS_HSCROLL_ARROW_X:
282 // TODO case wxSYS_HSCROLL_ARROW_Y:
283 // TODO case wxSYS_HTHUMB_X:
284 // TODO case wxSYS_ICON_X:
285 // TODO case wxSYS_ICON_Y:
286 // TODO case wxSYS_ICONSPACING_X:
287 // TODO case wxSYS_ICONSPACING_Y:
288 // TODO case wxSYS_WINDOWMIN_X:
289 // TODO case wxSYS_WINDOWMIN_Y:
6670f564 290
0e320a79 291 case wxSYS_SCREEN_X:
68a2e005 292 return ::WinQuerySysValue(HWND_DESKTOP,SV_CXSCREEN);
0e320a79 293 case wxSYS_SCREEN_Y:
68a2e005 294 return ::WinQuerySysValue(HWND_DESKTOP,SV_CYSCREEN);
6670f564 295
1d451c5b
RD
296 // TODO case wxSYS_FRAMESIZE_X:
297 // TODO case wxSYS_FRAMESIZE_Y:
298 // TODO case wxSYS_SMALLICON_X:
299 // TODO case wxSYS_SMALLICON_Y:
a12f4647
SN
300
301 case wxSYS_HSCROLL_Y:
302 return ::WinQuerySysValue(HWND_DESKTOP,SV_CYHSCROLL);
303 case wxSYS_VSCROLL_X:
304 return ::WinQuerySysValue(HWND_DESKTOP,SV_CXVSCROLL);
305
1d451c5b
RD
306 // TODO case wxSYS_VSCROLL_ARROW_X:
307 // TODO case wxSYS_VSCROLL_ARROW_Y:
308 // TODO case wxSYS_VTHUMB_Y:
309 // TODO case wxSYS_CAPTION_Y:
310 // TODO case wxSYS_MENU_Y:
311 // TODO case wxSYS_NETWORK_PRESENT:
312 // TODO case wxSYS_PENWINDOWS_PRESENT:
313 // TODO case wxSYS_SHOW_SOUNDS:
314 // TODO case wxSYS_SWAP_BUTTONS:
63a3cd7a
WS
315
316 default:
63ae3663 317 break;
409c9842 318 }
6670f564 319 return -1; // unsupported metric
0e320a79
DW
320}
321
6670f564 322bool wxSystemSettingsNative::HasFeature( wxSystemFeature index )
253293c1
VS
323{
324 switch (index)
325 {
1a2076a2 326 case wxSYS_CAN_ICONIZE_FRAME:
6670f564 327 return true;
793c7f9b 328
45abfa71
WS
329 // TODO case wxSYS_CAN_DRAW_FRAME_DECORATIONS:
330 // TODO case wxSYS_TABLET_PRESENT:
331
332 default:
333 break;
253293c1 334 }
6670f564
WS
335
336 return false;
253293c1 337}