1 /* 2 * Copyright 2005, Haiku. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Stephan Aßmus <superstippi@gmx.de> 7 * Axel Dörfler, axeld@pinc-software.de 8 */ 9 10 11 #include "DesktopSettings.h" 12 #include "DesktopSettingsPrivate.h" 13 #include "Desktop.h" 14 #include "FontManager.h" 15 #include "ServerConfig.h" 16 17 18 DesktopSettings::Private::Private() 19 : BLocker("desktop settings") 20 { 21 // if the on-disk settings are not complete, the defaults will be kept 22 _SetDefaults(); 23 _Load(); 24 } 25 26 27 DesktopSettings::Private::~Private() 28 { 29 } 30 31 32 void 33 DesktopSettings::Private::_SetDefaults() 34 { 35 _SetFont(fPlainFont, DEFAULT_PLAIN_FONT_FAMILY, DEFAULT_PLAIN_FONT_STYLE, 36 DEFAULT_PLAIN_FONT_SIZE, FALLBACK_PLAIN_FONT_FAMILY, DEFAULT_PLAIN_FONT_STYLE, 37 B_REGULAR_FACE); 38 _SetFont(fBoldFont, DEFAULT_BOLD_FONT_FAMILY, DEFAULT_BOLD_FONT_STYLE, 39 DEFAULT_BOLD_FONT_SIZE, FALLBACK_BOLD_FONT_FAMILY, DEFAULT_BOLD_FONT_STYLE, 40 B_BOLD_FACE); 41 _SetFont(fFixedFont, DEFAULT_FIXED_FONT_FAMILY, DEFAULT_FIXED_FONT_STYLE, 42 DEFAULT_FIXED_FONT_SIZE, FALLBACK_FIXED_FONT_FAMILY, DEFAULT_FIXED_FONT_STYLE, 43 B_REGULAR_FACE); 44 fFixedFont.SetSpacing(B_FIXED_SPACING); 45 46 fMouseMode = B_NORMAL_MOUSE; 47 48 // init scrollbar info 49 fScrollBarInfo.proportional = true; 50 fScrollBarInfo.double_arrows = false; 51 // look of the knob (R5: (0, 1, 2), 1 = default) 52 fScrollBarInfo.knob = 1; 53 fScrollBarInfo.min_knob_size = 15; 54 55 // init menu info 56 fMenuInfo.font_size = 12.0; 57 // TODO: ... 58 // fMenuInfo.f_family; 59 // fMenuInfo.f_style; 60 // fMenuInfo.background_color = gColorSet->menu_background; 61 // look of the separator (R5: (0, 1, 2), default ?) 62 fMenuInfo.separator = 0; 63 fMenuInfo.click_to_open = true; 64 fMenuInfo.triggers_always_shown = false; 65 66 fWorkspacesCount = 1; 67 } 68 69 70 void 71 DesktopSettings::Private::_SetFont(ServerFont &font, const char *familyName, 72 const char *styleName, float size, const char *fallbackFamily, 73 const char *fallbackStyle, uint16 fallbackFace) 74 { 75 BAutolock locker(gFontManager); 76 77 // try to find a matching font 78 79 FontStyle* style = gFontManager->GetStyle(familyName, styleName); 80 if (style == NULL) { 81 style = gFontManager->GetStyle(fallbackFamily, fallbackStyle); 82 if (style == NULL) { 83 style = gFontManager->FindStyleMatchingFace(fallbackFace); 84 } 85 } 86 87 if (style != NULL) 88 font.SetStyle(*style); 89 } 90 91 92 status_t 93 DesktopSettings::Private::_Load() 94 { 95 // TODO: add support for old app_server_settings file as well 96 return B_ERROR; 97 } 98 99 100 status_t 101 DesktopSettings::Private::Save() 102 { 103 return B_ERROR; 104 } 105 106 107 void 108 DesktopSettings::Private::SetDefaultPlainFont(const ServerFont &font) 109 { 110 fPlainFont = font; 111 } 112 113 114 const ServerFont & 115 DesktopSettings::Private::DefaultPlainFont() const 116 { 117 return fPlainFont; 118 } 119 120 121 void 122 DesktopSettings::Private::SetDefaultBoldFont(const ServerFont &font) 123 { 124 fBoldFont = font; 125 } 126 127 128 const ServerFont & 129 DesktopSettings::Private::DefaultBoldFont() const 130 { 131 return fBoldFont; 132 } 133 134 135 void 136 DesktopSettings::Private::SetDefaultFixedFont(const ServerFont &font) 137 { 138 fFixedFont = font; 139 } 140 141 142 const ServerFont & 143 DesktopSettings::Private::DefaultFixedFont() const 144 { 145 return fFixedFont; 146 } 147 148 149 void 150 DesktopSettings::Private::SetScrollBarInfo(const scroll_bar_info& info) 151 { 152 fScrollBarInfo = info; 153 } 154 155 156 const scroll_bar_info& 157 DesktopSettings::Private::ScrollBarInfo() const 158 { 159 return fScrollBarInfo; 160 } 161 162 163 void 164 DesktopSettings::Private::SetMenuInfo(const menu_info& info) 165 { 166 fMenuInfo = info; 167 } 168 169 170 const menu_info& 171 DesktopSettings::Private::MenuInfo() const 172 { 173 return fMenuInfo; 174 } 175 176 177 void 178 DesktopSettings::Private::SetMouseMode(const mode_mouse mode) 179 { 180 fMouseMode = mode; 181 } 182 183 184 mode_mouse 185 DesktopSettings::Private::MouseMode() const 186 { 187 return fMouseMode; 188 } 189 190 191 bool 192 DesktopSettings::Private::FocusFollowsMouse() const 193 { 194 return MouseMode() != B_NORMAL_MOUSE; 195 } 196 197 198 void 199 DesktopSettings::Private::SetWorkspacesCount(int32 number) 200 { 201 if (number < 1) 202 number = 1; 203 else if (number > kMaxWorkspaces) 204 number = kMaxWorkspaces; 205 206 fWorkspacesCount = number; 207 } 208 209 210 int32 211 DesktopSettings::Private::WorkspacesCount() const 212 { 213 return fWorkspacesCount; 214 } 215 216 217 void 218 DesktopSettings::Private::SetWorkspacesMessage(int32 index, BMessage& message) 219 { 220 if (index < 0 || index > kMaxWorkspaces) 221 return; 222 223 fWorkspaceMessages[index] = message; 224 } 225 226 227 const BMessage* 228 DesktopSettings::Private::WorkspacesMessage(int32 index) const 229 { 230 if (index < 0 || index > kMaxWorkspaces) 231 return NULL; 232 233 return &fWorkspaceMessages[index]; 234 } 235 236 237 238 // #pragma mark - 239 240 241 DesktopSettings::DesktopSettings(Desktop* desktop) 242 { 243 fSettings = desktop->fSettings; 244 fSettings->Lock(); 245 } 246 247 248 DesktopSettings::~DesktopSettings() 249 { 250 fSettings->Unlock(); 251 } 252 253 254 void 255 DesktopSettings::SetDefaultPlainFont(const ServerFont &font) 256 { 257 fSettings->SetDefaultPlainFont(font); 258 } 259 260 261 void 262 DesktopSettings::GetDefaultPlainFont(ServerFont &font) const 263 { 264 font = fSettings->DefaultPlainFont(); 265 } 266 267 268 void 269 DesktopSettings::SetDefaultBoldFont(const ServerFont &font) 270 { 271 fSettings->SetDefaultBoldFont(font); 272 } 273 274 275 void 276 DesktopSettings::GetDefaultBoldFont(ServerFont &font) const 277 { 278 font = fSettings->DefaultBoldFont(); 279 } 280 281 282 void 283 DesktopSettings::SetDefaultFixedFont(const ServerFont &font) 284 { 285 fSettings->SetDefaultFixedFont(font); 286 } 287 288 289 void 290 DesktopSettings::GetDefaultFixedFont(ServerFont &font) const 291 { 292 font = fSettings->DefaultFixedFont(); 293 } 294 295 296 void 297 DesktopSettings::SetScrollBarInfo(const scroll_bar_info& info) 298 { 299 fSettings->SetScrollBarInfo(info); 300 } 301 302 303 void 304 DesktopSettings::GetScrollBarInfo(scroll_bar_info& info) const 305 { 306 info = fSettings->ScrollBarInfo(); 307 } 308 309 310 void 311 DesktopSettings::SetMenuInfo(const menu_info& info) 312 { 313 fSettings->SetMenuInfo(info); 314 } 315 316 317 void 318 DesktopSettings::GetMenuInfo(menu_info& info) const 319 { 320 info = fSettings->MenuInfo(); 321 } 322 323 324 void 325 DesktopSettings::SetMouseMode(const mode_mouse mode) 326 { 327 fSettings->SetMouseMode(mode); 328 } 329 330 331 mode_mouse 332 DesktopSettings::MouseMode() const 333 { 334 return fSettings->MouseMode(); 335 } 336 337 338 bool 339 DesktopSettings::FocusFollowsMouse() const 340 { 341 return fSettings->FocusFollowsMouse(); 342 } 343 344 345 void 346 DesktopSettings::SetWorkspacesCount(int32 number) 347 { 348 fSettings->SetWorkspacesCount(number); 349 } 350 351 352 int32 353 DesktopSettings::WorkspacesCount() const 354 { 355 return fSettings->WorkspacesCount(); 356 } 357 358 359 void 360 DesktopSettings::SetWorkspacesMessage(int32 index, BMessage& message) 361 { 362 fSettings->SetWorkspacesMessage(index, message); 363 } 364 365 366 const BMessage* 367 DesktopSettings::WorkspacesMessage(int32 index) const 368 { 369 return fSettings->WorkspacesMessage(index); 370 } 371 372