]> git.saurik.com Git - wxWidgets.git/blame - src/cocoa/settings.mm
using common GetContentScaleFactor throughout part 2/2
[wxWidgets.git] / src / cocoa / settings.mm
CommitLineData
a24aff65 1/////////////////////////////////////////////////////////////////////////////
0c28d824 2// Name: src/cocoa/settings.mm
a24aff65 3// Purpose: wxSettings
0c28d824 4// Author: David Elliott
a24aff65 5// Modified by:
0c28d824 6// Created: 2005/01/11
a24aff65 7// RCS-ID: $Id$
0c28d824 8// Copyright: (c) 2005 David Elliott
65571936 9// Licence: wxWindows licence
a24aff65
DE
10/////////////////////////////////////////////////////////////////////////////
11
7ec69821 12#include "wx/wxprec.h"
de6185e2 13
9eddec69
WS
14#include "wx/settings.h"
15
0c28d824 16#ifndef WX_PRECOMP
de6185e2 17 #include "wx/utils.h"
dd05139a 18 #include "wx/gdicmn.h"
a24aff65
DE
19#endif
20
0c28d824 21#include "wx/cocoa/autorelease.h"
51146826 22#include "wx/cocoa/private/fontfactory.h"
0c28d824
DE
23
24#import <AppKit/NSColor.h>
51146826 25#import <AppKit/NSFont.h>
0c28d824 26
a24aff65
DE
27// ----------------------------------------------------------------------------
28// wxSystemSettingsNative
29// ----------------------------------------------------------------------------
30
31// ----------------------------------------------------------------------------
32// colours
33// ----------------------------------------------------------------------------
34
35wxColour wxSystemSettingsNative::GetColour(wxSystemColour index)
36{
0c28d824 37 wxAutoNSAutoreleasePool pool;
a24aff65
DE
38 switch( index )
39 {
c3c916e3 40 case wxSYS_COLOUR_SCROLLBAR:
0c28d824
DE
41 return wxColour([NSColor scrollBarColor]); // color of slot
42 case wxSYS_COLOUR_BACKGROUND: // No idea how to get desktop background
43 break; // break so we return an invalid colour.
44 case wxSYS_COLOUR_ACTIVECAPTION: // No idea how to get this
45 // fall through, window background is reasonable
46 case wxSYS_COLOUR_INACTIVECAPTION: // No idea how to get this
47 // fall through, window background is reasonable
c3c916e3 48 case wxSYS_COLOUR_MENU:
0c28d824 49 case wxSYS_COLOUR_MENUBAR:
c3c916e3
DE
50 case wxSYS_COLOUR_WINDOW:
51 case wxSYS_COLOUR_WINDOWFRAME:
52 case wxSYS_COLOUR_ACTIVEBORDER:
53 case wxSYS_COLOUR_INACTIVEBORDER:
0c28d824 54 return wxColour([NSColor windowFrameColor]);
c3c916e3 55 case wxSYS_COLOUR_BTNFACE:
0c28d824 56 return wxColour([NSColor knobColor]); // close enough?
c3c916e3 57 case wxSYS_COLOUR_LISTBOX:
0c28d824 58 return wxColour([NSColor controlBackgroundColor]);
c3c916e3 59 case wxSYS_COLOUR_BTNSHADOW:
0c28d824 60 return wxColour([NSColor controlShadowColor]);
c3c916e3
DE
61 case wxSYS_COLOUR_BTNTEXT:
62 case wxSYS_COLOUR_MENUTEXT:
63 case wxSYS_COLOUR_WINDOWTEXT:
64 case wxSYS_COLOUR_CAPTIONTEXT:
65 case wxSYS_COLOUR_INFOTEXT:
66 case wxSYS_COLOUR_INACTIVECAPTIONTEXT:
0c28d824 67 return wxColour([NSColor controlTextColor]);
c3c916e3 68 case wxSYS_COLOUR_HIGHLIGHT:
0c28d824 69 return wxColour([NSColor selectedControlColor]);
c3c916e3 70 case wxSYS_COLOUR_BTNHIGHLIGHT:
0c28d824 71 return wxColour([NSColor controlHighlightColor]);
c3c916e3 72 case wxSYS_COLOUR_GRAYTEXT:
0c28d824 73 return wxColour([NSColor disabledControlTextColor]);
c3c916e3 74 case wxSYS_COLOUR_3DDKSHADOW:
0c28d824 75 return wxColour([NSColor controlShadowColor]);
c3c916e3 76 case wxSYS_COLOUR_3DLIGHT:
0c28d824 77 return wxColour([NSColor controlHighlightColor]);
c3c916e3 78 case wxSYS_COLOUR_HIGHLIGHTTEXT:
0c28d824 79 return wxColour([NSColor selectedControlTextColor]);
c3c916e3 80 case wxSYS_COLOUR_INFOBK:
0c28d824
DE
81 // tooltip (bogus)
82 return wxColour([NSColor controlBackgroundColor]);
c3c916e3 83 case wxSYS_COLOUR_APPWORKSPACE:
0c28d824
DE
84 // MDI window color (bogus)
85 return wxColour([NSColor windowBackgroundColor]);
c3c916e3 86 case wxSYS_COLOUR_HOTLIGHT:
0c28d824 87 break; // what is this?
c3c916e3
DE
88 case wxSYS_COLOUR_GRADIENTACTIVECAPTION:
89 case wxSYS_COLOUR_GRADIENTINACTIVECAPTION:
0c28d824 90 break; // Doesn't really apply to Cocoa.
c3c916e3 91 case wxSYS_COLOUR_MENUHILIGHT:
0c28d824 92 return wxColour([NSColor selectedMenuItemColor]);
c3c916e3 93 case wxSYS_COLOUR_MAX:
0c28d824
DE
94 default:
95 if(index>=wxSYS_COLOUR_MAX)
96 {
97 wxFAIL_MSG(wxT("Invalid system colour index"));
98 return wxColour();
99 }
a24aff65 100 }
0c28d824
DE
101 wxFAIL_MSG(wxT("Unimplemented system colour index"));
102 return wxColour();
a24aff65
DE
103}
104
105// ----------------------------------------------------------------------------
106// fonts
107// ----------------------------------------------------------------------------
108
109wxFont wxSystemSettingsNative::GetFont(wxSystemFont index)
110{
51146826
DE
111 // Return the system font for now
112 { wxAutoNSAutoreleasePool pool;
113 return wxCocoaFontFactory::InstanceForNSFont([NSFont systemFontOfSize:0.0], false);
114 }
a24aff65
DE
115 switch (index)
116 {
117 case wxSYS_ANSI_VAR_FONT :
118 case wxSYS_SYSTEM_FONT :
119 case wxSYS_DEVICE_DEFAULT_FONT :
120 case wxSYS_DEFAULT_GUI_FONT :
121 {
122 return *wxSMALL_FONT ;
123 } ;
124 break ;
125 case wxSYS_OEM_FIXED_FONT :
126 case wxSYS_ANSI_FIXED_FONT :
127 case wxSYS_SYSTEM_FIXED_FONT :
128 default :
129 {
130 return *wxNORMAL_FONT ;
131 } ;
132 break ;
7ec69821 133
a24aff65
DE
134 }
135 return *wxNORMAL_FONT;
136}
137
138// ----------------------------------------------------------------------------
139// system metrics/features
140// ----------------------------------------------------------------------------
141
142// Get a system metric, e.g. scrollbar size
9b0b5ba7 143int wxSystemSettingsNative::GetMetric(wxSystemMetric index, wxWindow *WXUNUSED(win))
a24aff65
DE
144{
145 switch ( index)
146 {
147 case wxSYS_MOUSE_BUTTONS:
148 return 2; // we emulate a two button mouse (ctrl + click = right button )
7ec69821 149
1d451c5b
RD
150 // TODO case wxSYS_BORDER_X:
151 // TODO case wxSYS_BORDER_Y:
152 // TODO case wxSYS_CURSOR_X:
153 // TODO case wxSYS_CURSOR_Y:
154 // TODO case wxSYS_DCLICK_X:
155 // TODO case wxSYS_DCLICK_Y:
156 // TODO case wxSYS_DRAG_X:
157 // TODO case wxSYS_DRAG_Y:
158 // TODO case wxSYS_EDGE_X:
159 // TODO case wxSYS_EDGE_Y:
160
a24aff65
DE
161 case wxSYS_HSCROLL_ARROW_X:
162 return 16;
163 case wxSYS_HSCROLL_ARROW_Y:
164 return 16;
165 case wxSYS_HTHUMB_X:
166 return 16;
7ec69821 167
1d451c5b
RD
168 // TODO case wxSYS_ICON_X:
169 // TODO case wxSYS_ICON_Y:
170 // TODO case wxSYS_ICONSPACING_X:
171 // TODO case wxSYS_ICONSPACING_Y:
172 // TODO case wxSYS_WINDOWMIN_X:
173 // TODO case wxSYS_WINDOWMIN_Y:
174 // TODO case wxSYS_SCREEN_X:
175 // TODO case wxSYS_SCREEN_Y:
176 // TODO case wxSYS_FRAMESIZE_X:
177 // TODO case wxSYS_FRAMESIZE_Y:
178 // TODO case wxSYS_SMALLICON_X:
179 // TODO case wxSYS_SMALLICON_Y:
7ec69821 180
a24aff65
DE
181 case wxSYS_HSCROLL_Y:
182 return 16;
183 case wxSYS_VSCROLL_X:
184 return 16;
185 case wxSYS_VSCROLL_ARROW_X:
186 return 16;
187 case wxSYS_VSCROLL_ARROW_Y:
188 return 16;
189 case wxSYS_VTHUMB_Y:
190 return 16;
7ec69821 191
1d451c5b
RD
192 // TODO case wxSYS_CAPTION_Y:
193 // TODO case wxSYS_MENU_Y:
194 // TODO case wxSYS_NETWORK_PRESENT:
7ec69821 195
a24aff65
DE
196 case wxSYS_PENWINDOWS_PRESENT:
197 return 0;
7ec69821 198
1d451c5b
RD
199 // TODO case wxSYS_SHOW_SOUNDS:
200
a24aff65
DE
201 case wxSYS_SWAP_BUTTONS:
202 return 0;
7ec69821 203
a24aff65 204 default:
1d451c5b 205 return -1; // unsupported metric
a24aff65
DE
206 }
207 return 0;
208}
209
210bool wxSystemSettingsNative::HasFeature(wxSystemFeature index)
211{
212 switch (index)
213 {
7ec69821 214 case wxSYS_CAN_ICONIZE_FRAME:
a24aff65 215 case wxSYS_CAN_DRAW_FRAME_DECORATIONS:
7ec69821
WS
216 return true;
217
a24aff65 218 default:
7ec69821 219 return false;
a24aff65
DE
220 }
221}