1 //------------------------------------------------------------------------------ 2 // Copyright (c) 2001-2004, Haiku 3 // 4 // Permission is hereby granted, free of charge, to any person obtaining a 5 // copy of this software and associated documentation files (the "Software"), 6 // to deal in the Software without restriction, including without limitation 7 // the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 // and/or sell copies of the Software, and to permit persons to whom the 9 // Software is furnished to do so, subject to the following conditions: 10 // 11 // The above copyright notice and this permission notice shall be included in 12 // all copies or substantial portions of the Software. 13 // 14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 20 // DEALINGS IN THE SOFTWARE. 21 // 22 // File Name: InterfaceDefs.cpp 23 // Author: DarkWyrm <bpmagic@columbus.rr.com> 24 // Caz <turok2@currantbun.com> 25 // Axel Dörfler <axeld@pinc-software.de> 26 // Description: Global functions and variables for the Interface Kit 27 // 28 //------------------------------------------------------------------------------ 29 30 #include <AppServerLink.h> 31 #include <InterfaceDefs.h> 32 #include <ServerProtocol.h> 33 #include <ScrollBar.h> 34 #include <Screen.h> 35 #include <Roster.h> 36 #include <Menu.h> 37 #include <stdlib.h> 38 #include <TextView.h> 39 40 #include <WidthBuffer.h> 41 42 // Private definitions not placed in public headers 43 extern "C" void _init_global_fonts(); 44 extern "C" status_t _fini_interface_kit_(); 45 46 #include "InputServerTypes.h" 47 extern status_t _control_input_server_(BMessage *command, BMessage *reply); 48 49 using namespace BPrivate; 50 51 // InterfaceDefs.h 52 53 _IMPEXP_BE const color_map * 54 system_colors() 55 { 56 return BScreen(B_MAIN_SCREEN_ID).ColorMap(); 57 } 58 59 #ifndef COMPILE_FOR_R5 60 61 _IMPEXP_BE status_t 62 set_screen_space(int32 index, uint32 res, bool stick) 63 { 64 BAppServerLink link; 65 int32 code = SERVER_FALSE; 66 67 link.StartMessage(AS_SET_SCREEN_MODE); 68 link.Attach<int32>(index); 69 link.Attach<int32>((int32)res); 70 link.Attach<bool>(stick); 71 link.FlushWithReply(&code); 72 73 return ((code==SERVER_TRUE)?B_OK:B_ERROR); 74 } 75 76 77 _IMPEXP_BE status_t 78 get_scroll_bar_info(scroll_bar_info *info) 79 { 80 if (info == NULL) 81 return B_BAD_VALUE; 82 83 BAppServerLink link; 84 int32 code; 85 link.StartMessage(AS_GET_SCROLLBAR_INFO); 86 link.FlushWithReply(&code); 87 link.Read<scroll_bar_info>(info); 88 89 return B_OK; 90 } 91 92 _IMPEXP_BE status_t 93 set_scroll_bar_info(scroll_bar_info *info) 94 { 95 if (info == NULL) 96 return B_BAD_VALUE; 97 98 BAppServerLink link; 99 int32 code; 100 101 link.StartMessage(AS_SET_SCROLLBAR_INFO); 102 link.Attach<scroll_bar_info>(*info); 103 link.FlushWithReply(&code); 104 return B_OK; 105 } 106 107 #endif // COMPILE_FOR_R5 108 109 _IMPEXP_BE status_t 110 get_mouse_type(int32 *type) 111 { 112 BMessage command(IS_GET_MOUSE_TYPE); 113 BMessage reply; 114 115 _control_input_server_(&command, &reply); 116 117 if(reply.FindInt32("mouse_type", type) != B_OK) 118 return B_ERROR; 119 120 return B_OK; 121 } 122 123 124 _IMPEXP_BE status_t 125 set_mouse_type(int32 type) 126 { 127 BMessage command(IS_SET_MOUSE_TYPE); 128 BMessage reply; 129 130 command.AddInt32("mouse_type", type); 131 return _control_input_server_(&command, &reply) == B_OK; 132 } 133 134 135 _IMPEXP_BE status_t 136 get_mouse_map(mouse_map *map) 137 { 138 BMessage command(IS_GET_MOUSE_MAP); 139 BMessage reply; 140 const void *data = 0; 141 ssize_t count; 142 143 _control_input_server_(&command, &reply); 144 145 if(reply.FindData("mousemap", B_ANY_TYPE, &data, &count) != B_OK) 146 return B_ERROR; 147 148 memcpy(map, data, count); 149 150 return B_OK; 151 } 152 153 154 _IMPEXP_BE status_t 155 set_mouse_map(mouse_map *map) 156 { 157 BMessage command(IS_SET_MOUSE_MAP); 158 BMessage reply; 159 160 command.AddData("mousemap", B_ANY_TYPE, map, sizeof(mouse_map)); 161 return _control_input_server_(&command, &reply) == B_OK; 162 } 163 164 _IMPEXP_BE status_t 165 get_click_speed(bigtime_t *speed) 166 { 167 BMessage command(IS_GET_CLICK_SPEED); 168 BMessage reply; 169 170 _control_input_server_(&command, &reply); 171 172 if(reply.FindInt64("speed", speed) != B_OK) 173 return B_ERROR; 174 175 return B_OK; 176 } 177 178 179 _IMPEXP_BE status_t 180 set_click_speed(bigtime_t speed) 181 { 182 BMessage command(IS_SET_CLICK_SPEED); 183 BMessage reply; 184 command.AddInt64("speed", speed); 185 return _control_input_server_(&command, &reply) == B_OK; 186 } 187 188 189 _IMPEXP_BE status_t 190 get_mouse_speed(int32 *speed) 191 { 192 BMessage command(IS_GET_MOUSE_SPEED); 193 BMessage reply; 194 195 _control_input_server_(&command, &reply); 196 197 if(reply.FindInt32("speed", speed) != B_OK) 198 return B_ERROR; 199 200 return B_OK; 201 } 202 203 204 _IMPEXP_BE status_t 205 set_mouse_speed(int32 speed) 206 { 207 BMessage command(IS_SET_MOUSE_SPEED); 208 BMessage reply; 209 command.AddInt32("speed", speed); 210 return _control_input_server_(&command, &reply) == B_OK; 211 } 212 213 214 _IMPEXP_BE status_t 215 get_mouse_acceleration(int32 *speed) 216 { 217 BMessage command(IS_GET_MOUSE_ACCELERATION); 218 BMessage reply; 219 220 _control_input_server_(&command, &reply); 221 222 if(reply.FindInt32("speed", speed) != B_OK) 223 return B_ERROR; 224 225 return B_OK; 226 } 227 228 229 _IMPEXP_BE status_t 230 set_mouse_acceleration(int32 speed) 231 { 232 BMessage command(IS_SET_MOUSE_ACCELERATION); 233 BMessage reply; 234 command.AddInt32("speed", speed); 235 return _control_input_server_(&command, &reply) == B_OK; 236 } 237 238 239 _IMPEXP_BE status_t 240 get_key_repeat_rate(int32 *rate) 241 { 242 BMessage command(IS_GET_KEY_REPEAT_RATE); 243 BMessage reply; 244 245 _control_input_server_(&command, &reply); 246 247 if(reply.FindInt32("rate", rate) != B_OK) 248 return B_ERROR; 249 250 return B_OK; 251 } 252 253 254 _IMPEXP_BE status_t 255 set_key_repeat_rate(int32 rate) 256 { 257 BMessage command(IS_SET_KEY_REPEAT_RATE); 258 BMessage reply; 259 command.AddInt32("rate", rate); 260 return _control_input_server_(&command, &reply) == B_OK; 261 } 262 263 264 _IMPEXP_BE status_t 265 get_key_repeat_delay(bigtime_t *delay) 266 { 267 BMessage command(IS_GET_KEY_REPEAT_DELAY); 268 BMessage reply; 269 270 _control_input_server_(&command, &reply); 271 272 if(reply.FindInt64("delay", delay) != B_OK) 273 return B_ERROR; 274 275 return B_OK; 276 } 277 278 279 _IMPEXP_BE status_t 280 set_key_repeat_delay(bigtime_t delay) 281 { 282 BMessage command(IS_SET_KEY_REPEAT_DELAY); 283 BMessage reply; 284 command.AddInt64("delay", delay); 285 return _control_input_server_(&command, &reply) == B_OK; 286 } 287 288 289 _IMPEXP_BE uint32 290 modifiers() 291 { 292 BMessage command(IS_GET_MODIFIERS); 293 BMessage reply; 294 int32 err, modifier; 295 296 _control_input_server_(&command, &reply); 297 298 if(reply.FindInt32("status", &err) != B_OK) 299 return 0; 300 301 if(reply.FindInt32("modifiers", &modifier) != B_OK) 302 return 0; 303 304 return modifier; 305 } 306 307 308 _IMPEXP_BE status_t 309 get_key_info(key_info *info) 310 { 311 BMessage command(IS_GET_KEY_INFO); 312 BMessage reply; 313 const void *data = 0; 314 int32 err; 315 ssize_t count; 316 317 _control_input_server_(&command, &reply); 318 319 if(reply.FindInt32("status", &err) != B_OK) 320 return B_ERROR; 321 322 if(reply.FindData("key_info", B_ANY_TYPE, &data, &count) != B_OK) 323 return B_ERROR; 324 325 memcpy(info, data, count); 326 return B_OK; 327 } 328 329 330 _IMPEXP_BE void 331 get_key_map(key_map **map, char **key_buffer) 332 { 333 BMessage command(IS_GET_KEY_MAP); 334 BMessage reply; 335 ssize_t map_count, key_count; 336 const void *map_array = 0, *key_array = 0; 337 338 _control_input_server_(&command, &reply); 339 340 if(reply.FindData("keymap", B_ANY_TYPE, &map_array, &map_count) != B_OK) 341 { 342 *map = 0; *key_buffer = 0; 343 return; 344 } 345 346 if(reply.FindData("key_buffer", B_ANY_TYPE, &key_array, &key_count) != B_OK) 347 { 348 *map = 0; *key_buffer = 0; 349 return; 350 } 351 352 *map = (key_map *)malloc(map_count); 353 memcpy(*map, map_array, map_count); 354 *key_buffer = (char *)malloc(key_count); 355 memcpy(*key_buffer, key_array, key_count); 356 } 357 358 359 _IMPEXP_BE status_t 360 get_keyboard_id(uint16 *id) 361 { 362 BMessage command(IS_GET_KEYBOARD_ID); 363 BMessage reply; 364 uint16 kid; 365 366 _control_input_server_(&command, &reply); 367 368 reply.FindInt16("id", (int16 *)&kid); 369 *id = kid; 370 371 return B_OK; 372 } 373 374 375 _IMPEXP_BE void 376 set_modifier_key(uint32 modifier, uint32 key) 377 { 378 BMessage command(IS_SET_MODIFIER_KEY); 379 BMessage reply; 380 381 command.AddInt32("modifier", modifier); 382 command.AddInt32("key", key); 383 _control_input_server_(&command, &reply); 384 } 385 386 387 _IMPEXP_BE void 388 set_keyboard_locks(uint32 modifiers) 389 { 390 BMessage command(IS_SET_KEYBOARD_LOCKS); 391 BMessage reply; 392 393 command.AddInt32("locks", modifiers); 394 _control_input_server_(&command, &reply); 395 } 396 397 398 _IMPEXP_BE status_t 399 _restore_key_map_() 400 { 401 BMessage message(IS_RESTORE_KEY_MAP); 402 BMessage reply; 403 404 return _control_input_server_(&message, &reply); 405 } 406 407 408 _IMPEXP_BE rgb_color 409 keyboard_navigation_color() 410 { 411 // Queries the app_server 412 return ui_color(B_KEYBOARD_NAVIGATION_COLOR); 413 } 414 415 416 #ifndef COMPILE_FOR_R5 417 418 _IMPEXP_BE int32 419 count_workspaces() 420 { 421 int32 count; 422 423 BAppServerLink link; 424 int32 code; 425 link.StartMessage(AS_COUNT_WORKSPACES); 426 link.FlushWithReply(&code); 427 link.Read<int32>(&count); 428 return count; 429 } 430 431 432 _IMPEXP_BE void 433 set_workspace_count(int32 count) 434 { 435 BAppServerLink link; 436 link.StartMessage(AS_SET_WORKSPACE_COUNT); 437 link.Attach<int32>(count); 438 link.Flush(); 439 } 440 441 442 _IMPEXP_BE int32 443 current_workspace() 444 { 445 int32 index; 446 447 BAppServerLink link; 448 int32 code; 449 link.StartMessage(AS_CURRENT_WORKSPACE); 450 link.FlushWithReply(&code); 451 link.Read<int32>(&index); 452 453 return index; 454 } 455 456 457 _IMPEXP_BE void 458 activate_workspace(int32 workspace) 459 { 460 BAppServerLink link; 461 link.StartMessage(AS_ACTIVATE_WORKSPACE); 462 link.Attach<int32>(workspace); 463 link.Flush(); 464 } 465 466 467 _IMPEXP_BE bigtime_t 468 idle_time() 469 { 470 bigtime_t idletime; 471 472 BAppServerLink link; 473 int32 code; 474 link.StartMessage(AS_IDLE_TIME); 475 link.FlushWithReply(&code); 476 link.Read<int64>(&idletime); 477 478 return idletime; 479 } 480 481 482 _IMPEXP_BE void 483 run_select_printer_panel() 484 { 485 // Launches the Printer prefs app via the Roster 486 be_roster->Launch("application/x-vnd.Be-PRNT"); 487 } 488 489 490 _IMPEXP_BE void 491 run_add_printer_panel() 492 { 493 // Launches the Printer prefs app via the Roster and asks it to 494 // add a printer 495 // TODO: Implement 496 } 497 498 499 _IMPEXP_BE void 500 run_be_about() 501 { 502 // Unsure about how to implement this. 503 // TODO: Implement 504 } 505 506 507 _IMPEXP_BE void 508 set_focus_follows_mouse(bool follow) 509 { 510 BAppServerLink link; 511 link.StartMessage(AS_SET_FOCUS_FOLLOWS_MOUSE); 512 link.Attach<bool>(follow); 513 link.Flush(); 514 } 515 516 517 _IMPEXP_BE bool 518 focus_follows_mouse() 519 { 520 bool ffm; 521 522 BAppServerLink link; 523 int32 code; 524 link.StartMessage(AS_FOCUS_FOLLOWS_MOUSE); 525 link.FlushWithReply(&code); 526 link.Read<bool>(&ffm); 527 return ffm; 528 } 529 530 531 _IMPEXP_BE void 532 set_mouse_mode(mode_mouse mode) 533 { 534 BAppServerLink link; 535 link.StartMessage(AS_SET_MOUSE_MODE); 536 link.Attach<mode_mouse>(mode); 537 link.Flush(); 538 } 539 540 541 _IMPEXP_BE mode_mouse 542 mouse_mode() 543 { 544 mode_mouse mode; 545 546 BAppServerLink link; 547 int32 code; 548 link.StartMessage(AS_GET_MOUSE_MODE); 549 link.FlushWithReply(&code); 550 link.Read<mode_mouse>(&mode); 551 return mode; 552 } 553 554 555 _IMPEXP_BE rgb_color 556 ui_color(color_which which) 557 { 558 rgb_color color; 559 560 BAppServerLink link; 561 int32 code; 562 link.StartMessage(AS_GET_UI_COLOR); 563 link.Attach<color_which>(which); 564 link.FlushWithReply(&code); 565 if(code==SERVER_TRUE) 566 link.Read<rgb_color>(&color); 567 return color; 568 } 569 570 _IMPEXP_BE rgb_color 571 tint_color(rgb_color color, float tint) 572 { 573 rgb_color result; 574 575 #define LIGHTEN(x) ((uint8)(255.0f - (255.0f - x) * tint)) 576 #define DARKEN(x) ((uint8)(x * (2 - tint))) 577 578 if (tint < 1.0f) 579 { 580 result.red = LIGHTEN(color.red); 581 result.green = LIGHTEN(color.green); 582 result.blue = LIGHTEN(color.blue); 583 result.alpha = color.alpha; 584 } 585 else 586 { 587 result.red = DARKEN(color.red); 588 result.green = DARKEN(color.green); 589 result.blue = DARKEN(color.blue); 590 result.alpha = color.alpha; 591 } 592 593 #undef LIGHTEN 594 #undef DARKEN 595 596 return result; 597 } 598 599 600 extern "C" status_t 601 _init_interface_kit_() 602 { 603 sem_id widthSem = create_sem(1, "TextView WidthBuffer Sem"); 604 if (widthSem < 0) 605 return widthSem; 606 BTextView::sWidthSem = widthSem; 607 BTextView::sWidthAtom = 0; 608 BTextView::sWidths = new _BWidthBuffer_; 609 610 status_t result = get_menu_info(&BMenu::sMenuInfo); 611 if (result != B_OK) 612 return result; 613 614 //TODO: fill the other static members 615 616 return B_OK; 617 } 618 619 620 extern "C" status_t 621 _fini_interface_kit_() 622 { 623 //TODO: Implement ? 624 625 return B_OK; 626 } 627 628 629 extern "C" void 630 _init_global_fonts() 631 { 632 // This function will initialize the client-side font list 633 // TODO: Implement 634 } 635 636 637 /*! 638 \brief private function used by Tracker to set window decor 639 \param theme The theme to choose 640 641 - \c 0: BeOS 642 - \c 1: AmigaOS 643 - \c 2: Win95 644 - \c 3: MacOS 645 */ 646 void __set_window_decor(int32 theme) 647 { 648 BAppServerLink link; 649 link.StartMessage(AS_R5_SET_DECORATOR); 650 link.Attach<int32>(theme); 651 link.Flush(); 652 } 653 654 #endif // COMPILE_FOR_R5 655