]> git.saurik.com Git - wxWidgets.git/blob - src/os2/settings.cpp
add support for alpha in color dialog on OSX, see #14127
[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/gdicmn.h"
20 #include "wx/window.h"
21 #include "wx/settings.h"
22 #include "wx/module.h"
23 #endif
24
25 #include "wx/fontutil.h"
26
27 #include "wx/os2/private.h"
28
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)
31 class wxSystemSettingsModule : public wxModule
32 {
33 friend class wxSystemSettings;
34 public:
35 virtual bool OnInit();
36 virtual void OnExit();
37
38 private:
39 DECLARE_DYNAMIC_CLASS(wxSystemSettingsModule)
40
41 static wxArrayString sm_optionNames;
42 static wxArrayString sm_optionValues;
43 };
44
45 // ----------------------------------------------------------------------------
46 // global data
47 // ----------------------------------------------------------------------------
48
49 static wxFont *gs_fontDefault = NULL;
50
51 // ============================================================================
52 // implementation
53 // ============================================================================
54
55 // ----------------------------------------------------------------------------
56 // wxSystemSettingsModule
57 // ----------------------------------------------------------------------------
58
59 IMPLEMENT_DYNAMIC_CLASS(wxSystemSettingsModule, wxModule)
60
61 wxArrayString wxSystemSettingsModule::sm_optionNames;
62 wxArrayString wxSystemSettingsModule::sm_optionValues;
63
64 bool wxSystemSettingsModule::OnInit()
65 {
66 return true;
67 }
68
69 void wxSystemSettingsModule::OnExit()
70 {
71 sm_optionNames.Clear();
72 sm_optionValues.Clear();
73 wxDELETE(gs_fontDefault);
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 case wxSYS_COLOUR_LISTBOXHIGHLIGHTTEXT:
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)
184 case wxSYS_COLOUR_GRAYTEXT:
185 case wxSYS_COLOUR_3DDKSHADOW:
186 case wxSYS_COLOUR_3DLIGHT:
187 case wxSYS_COLOUR_HOTLIGHT:
188 case wxSYS_COLOUR_GRADIENTACTIVECAPTION:
189 case wxSYS_COLOUR_GRADIENTINACTIVECAPTION:
190 vSysClr = SYSCLR_BUTTONMIDDLE;
191 break;
192
193 default:
194 vSysClr = SYSCLR_WINDOW;
195 break;
196 }
197 vRef = (ULONG)::WinQuerySysColor( HWND_DESKTOP,
198 vSysClr,
199 0L );
200 vCol.Set( GetRValue(vRef),
201 GetGValue(vRef),
202 GetBValue(vRef) );
203 return(vCol);
204 } // end of wxSystemSettingsNative::GetColour
205
206 // ----------------------------------------------------------------------------
207 // fonts
208 // ----------------------------------------------------------------------------
209
210 wxFont wxSystemSettingsNative::GetFont(
211 wxSystemFont index
212 )
213 {
214 const bool isDefaultRequested = index == wxSYS_DEFAULT_GUI_FONT;
215 if ( isDefaultRequested )
216 {
217 if ( gs_fontDefault )
218 return *gs_fontDefault;
219 }
220
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( wxT("stock font not found") );
252 return GetFont(wxSYS_ANSI_VAR_FONT);
253 }
254
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);
260 }
261
262 return font;
263 }
264
265 // Get a system metric, e.g. scrollbar size
266 int wxSystemSettingsNative::GetMetric( wxSystemMetric index,
267 wxWindow* WXUNUSED(win) )
268 {
269 switch ( index)
270 {
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:
291
292 case wxSYS_SCREEN_X:
293 return ::WinQuerySysValue(HWND_DESKTOP,SV_CXSCREEN);
294 case wxSYS_SCREEN_Y:
295 return ::WinQuerySysValue(HWND_DESKTOP,SV_CYSCREEN);
296
297 // TODO case wxSYS_FRAMESIZE_X:
298 // TODO case wxSYS_FRAMESIZE_Y:
299 // TODO case wxSYS_SMALLICON_X:
300 // TODO case wxSYS_SMALLICON_Y:
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
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:
316
317 default:
318 break;
319 }
320 return -1; // unsupported metric
321 }
322
323 bool wxSystemSettingsNative::HasFeature( wxSystemFeature index )
324 {
325 switch (index)
326 {
327 case wxSYS_CAN_ICONIZE_FRAME:
328 return true;
329
330 // TODO case wxSYS_CAN_DRAW_FRAME_DECORATIONS:
331 // TODO case wxSYS_TABLET_PRESENT:
332
333 default:
334 break;
335 }
336
337 return false;
338 }