Changed font generation to follow new pattern of other ports more closely.
[wxWidgets.git] / src / os2 / settings.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/os2/settings.cpp
3 // Purpose: wxSettings
4 // Author: David Webster
5 // Modified by:
6 // Created: 10/15/99
7 // RCS-ID: $Id$
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
14
15 #ifndef WX_PRECOMP
16 #include <stdio.h>
17 #include "wx/pen.h"
18 #include "wx/brush.h"
19 #include "wx/fontutil.h"
20 #include "wx/gdicmn.h"
21 #include "wx/window.h"
22 #include "wx/settings.h"
23 #endif
24
25 #include "wx/module.h"
26 #include "wx/os2/private.h"
27
28 // the module which is used to clean up wxSystemSettings data (this is a
29 // singleton class so it can't be done in the dtor)
30 class wxSystemSettingsModule : public wxModule
31 {
32 friend class wxSystemSettings;
33 public:
34 virtual bool OnInit();
35 virtual void OnExit();
36
37 private:
38 DECLARE_DYNAMIC_CLASS(wxSystemSettingsModule)
39
40 static wxArrayString sm_optionNames;
41 static wxArrayString sm_optionValues;
42 };
43
44 // ----------------------------------------------------------------------------
45 // global data
46 // ----------------------------------------------------------------------------
47
48 static wxFont *gs_fontDefault = NULL;
49
50 // ============================================================================
51 // implementation
52 // ============================================================================
53
54 // ----------------------------------------------------------------------------
55 // wxSystemSettingsModule
56 // ----------------------------------------------------------------------------
57
58 IMPLEMENT_DYNAMIC_CLASS(wxSystemSettingsModule, wxModule)
59
60 wxArrayString wxSystemSettingsModule::sm_optionNames;
61 wxArrayString wxSystemSettingsModule::sm_optionValues;
62
63 bool wxSystemSettingsModule::OnInit()
64 {
65 return true;
66 }
67
68 void wxSystemSettingsModule::OnExit()
69 {
70 sm_optionNames.Clear();
71 sm_optionValues.Clear();
72 delete gs_fontDefault;
73 gs_fontDefault = NULL;
74 }
75
76 wxColour wxSystemSettingsNative::GetColour(
77 wxSystemColour nIndex
78 )
79 {
80 COLORREF vRef;
81 wxColour vCol;
82 LONG vSysClr;
83 switch (nIndex)
84 {
85 //
86 // PM actually has values for these
87 //
88 case wxSYS_COLOUR_WINDOW:
89 vSysClr = SYSCLR_WINDOW;
90 break;
91
92 case wxSYS_COLOUR_WINDOWFRAME:
93 vSysClr = SYSCLR_WINDOWFRAME;
94 break;
95
96 case wxSYS_COLOUR_MENUTEXT:
97 vSysClr = SYSCLR_MENUTEXT;
98 break;
99
100 case wxSYS_COLOUR_MENUHILIGHT:
101 vSysClr = SYSCLR_MENUHILITE;
102 break;
103
104 case wxSYS_COLOUR_BTNFACE:
105 vSysClr = SYSCLR_BUTTONMIDDLE;
106 break;
107
108 case wxSYS_COLOUR_BTNSHADOW:
109 vSysClr = SYSCLR_BUTTONDARK;
110 break;
111
112 case wxSYS_COLOUR_BTNHIGHLIGHT:
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;
122 break;
123
124 case wxSYS_COLOUR_MENUBAR:
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;
135 break;
136
137 case wxSYS_COLOUR_LISTBOX:
138 vSysClr = SYSCLR_ENTRYFIELD;
139 break;
140
141 case wxSYS_COLOUR_CAPTIONTEXT:
142 vSysClr = SYSCLR_TITLETEXT;
143 break;
144
145 case wxSYS_COLOUR_INACTIVECAPTIONTEXT:
146 vSysClr = SYSCLR_INACTIVETITLETEXT;
147 break;
148
149 case wxSYS_COLOUR_WINDOWTEXT:
150 case wxSYS_COLOUR_BTNTEXT:
151 vSysClr = SYSCLR_WINDOWTEXT;
152 break;
153
154 case wxSYS_COLOUR_INFOTEXT:
155 vSysClr = SYSCLR_HELPTEXT;
156 break;
157
158 case wxSYS_COLOUR_ACTIVECAPTION:
159 vSysClr = SYSCLR_ACTIVETITLE;
160 break;
161
162 case wxSYS_COLOUR_ACTIVEBORDER:
163 vSysClr = SYSCLR_ACTIVEBORDER;
164 break;
165
166 case wxSYS_COLOUR_HIGHLIGHT:
167 vSysClr = SYSCLR_HILITEBACKGROUND;
168 break;
169
170 case wxSYS_COLOUR_SCROLLBAR:
171 vSysClr = SYSCLR_SCROLLBAR;
172 break;
173
174 case wxSYS_COLOUR_HIGHLIGHTTEXT:
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)
183 case wxSYS_COLOUR_GRAYTEXT:
184 case wxSYS_COLOUR_3DDKSHADOW:
185 case wxSYS_COLOUR_3DLIGHT:
186 case wxSYS_COLOUR_HOTLIGHT:
187 case wxSYS_COLOUR_GRADIENTACTIVECAPTION:
188 case wxSYS_COLOUR_GRADIENTINACTIVECAPTION:
189 vSysClr = SYSCLR_BUTTONMIDDLE;
190 break;
191
192 default:
193 vSysClr = SYSCLR_WINDOW;
194 break;
195 }
196 vRef = (ULONG)::WinQuerySysColor( HWND_DESKTOP,
197 vSysClr,
198 0L );
199 vCol.Set( GetRValue(vRef),
200 GetGValue(vRef),
201 GetBValue(vRef) );
202 return(vCol);
203 } // end of wxSystemSettingsNative::GetColour
204
205 // ----------------------------------------------------------------------------
206 // fonts
207 // ----------------------------------------------------------------------------
208
209 wxFont wxCreateFontFromStockObject(int index)
210 {
211 wxFont font;
212
213 FONTMETRICS metrics;
214 HPS hPS = ::WinGetScreenPS(HWND_DESKTOP);
215 if (::GpiQueryFontMetrics(hPS, sizeof(FONTMETRICS), &metrics))
216 {
217 wxNativeFontInfo info;
218 info.fm = metrics;
219 font.Create(info);
220 }
221 else // GetStockObject() failed
222 {
223 wxFAIL_MSG( _T("stock font not found") );
224 }
225
226 return font;
227 }
228
229 wxFont wxSystemSettingsNative::GetFont(
230 wxSystemFont index
231 )
232 {
233 const bool isDefaultRequested = index == wxSYS_DEFAULT_GUI_FONT;
234 if ( isDefaultRequested )
235 {
236 if ( gs_fontDefault )
237 return *gs_fontDefault;
238 }
239
240 wxFont font = wxCreateFontFromStockObject(index);
241
242 if ( isDefaultRequested )
243 {
244 // if we got here it means we hadn't cached it yet - do now
245 gs_fontDefault = new wxFont(font);
246 }
247
248 return font;
249 }
250
251 // Get a system metric, e.g. scrollbar size
252 int wxSystemSettingsNative::GetMetric( wxSystemMetric index,
253 wxWindow* WXUNUSED(win) )
254 {
255 switch ( index)
256 {
257 // TODO case wxSYS_MOUSE_BUTTONS:
258 // TODO case wxSYS_BORDER_X:
259 // TODO case wxSYS_BORDER_Y:
260 // TODO case wxSYS_CURSOR_X:
261 // TODO case wxSYS_CURSOR_Y:
262 // TODO case wxSYS_DCLICK_X:
263 // TODO case wxSYS_DCLICK_Y:
264 // TODO case wxSYS_DRAG_X:
265 // TODO case wxSYS_DRAG_Y:
266 // TODO case wxSYS_EDGE_X:
267 // TODO case wxSYS_EDGE_Y:
268 // TODO case wxSYS_HSCROLL_ARROW_X:
269 // TODO case wxSYS_HSCROLL_ARROW_Y:
270 // TODO case wxSYS_HTHUMB_X:
271 // TODO case wxSYS_ICON_X:
272 // TODO case wxSYS_ICON_Y:
273 // TODO case wxSYS_ICONSPACING_X:
274 // TODO case wxSYS_ICONSPACING_Y:
275 // TODO case wxSYS_WINDOWMIN_X:
276 // TODO case wxSYS_WINDOWMIN_Y:
277
278 case wxSYS_SCREEN_X:
279 return ::WinQuerySysValue(HWND_DESKTOP,SV_CXSCREEN);
280 case wxSYS_SCREEN_Y:
281 return ::WinQuerySysValue(HWND_DESKTOP,SV_CYSCREEN);
282
283 // TODO case wxSYS_FRAMESIZE_X:
284 // TODO case wxSYS_FRAMESIZE_Y:
285 // TODO case wxSYS_SMALLICON_X:
286 // TODO case wxSYS_SMALLICON_Y:
287
288 case wxSYS_HSCROLL_Y:
289 return ::WinQuerySysValue(HWND_DESKTOP,SV_CYHSCROLL);
290 case wxSYS_VSCROLL_X:
291 return ::WinQuerySysValue(HWND_DESKTOP,SV_CXVSCROLL);
292
293 // TODO case wxSYS_VSCROLL_ARROW_X:
294 // TODO case wxSYS_VSCROLL_ARROW_Y:
295 // TODO case wxSYS_VTHUMB_Y:
296 // TODO case wxSYS_CAPTION_Y:
297 // TODO case wxSYS_MENU_Y:
298 // TODO case wxSYS_NETWORK_PRESENT:
299 // TODO case wxSYS_PENWINDOWS_PRESENT:
300 // TODO case wxSYS_SHOW_SOUNDS:
301 // TODO case wxSYS_SWAP_BUTTONS:
302
303 default:
304 break;
305 }
306 return -1; // unsupported metric
307 }
308
309 bool wxSystemSettingsNative::HasFeature( wxSystemFeature index )
310 {
311 switch (index)
312 {
313 case wxSYS_CAN_ICONIZE_FRAME:
314 return true;
315
316 // TODO case wxSYS_CAN_DRAW_FRAME_DECORATIONS:
317 // TODO case wxSYS_TABLET_PRESENT:
318
319 default:
320 break;
321 }
322
323 return false;
324 }