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