Changes in uspace/app/uidemo/uidemo.c [2d879f7:9a07ee3] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/uidemo/uidemo.c
r2d879f7 r9a07ee3 1 1 /* 2 * Copyright (c) 202 0Jiri Svoboda2 * Copyright (c) 2024 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 37 37 #include <io/pixelmap.h> 38 38 #include <stdio.h> 39 #include <stdlib.h> 39 40 #include <str.h> 40 41 #include <ui/entry.h> 42 #include <ui/filedialog.h> 41 43 #include <ui/fixed.h> 42 44 #include <ui/image.h> 43 45 #include <ui/label.h> 46 #include <ui/list.h> 47 #include <ui/menu.h> 48 #include <ui/menubar.h> 49 #include <ui/menudd.h> 50 #include <ui/menuentry.h> 51 #include <ui/msgdialog.h> 44 52 #include <ui/pbutton.h> 53 #include <ui/promptdialog.h> 45 54 #include <ui/resource.h> 55 #include <ui/selectdialog.h> 56 #include <ui/tab.h> 57 #include <ui/tabset.h> 46 58 #include <ui/ui.h> 47 59 #include <ui/window.h> … … 60 72 static ui_pbutton_cb_t pbutton_cb = { 61 73 .clicked = pb_clicked 74 }; 75 76 static void checkbox_switched(ui_checkbox_t *, void *, bool); 77 78 static ui_checkbox_cb_t checkbox_cb = { 79 .switched = checkbox_switched 80 }; 81 82 static void rb_selected(ui_rbutton_group_t *, void *, void *); 83 84 static ui_rbutton_group_cb_t rbutton_group_cb = { 85 .selected = rb_selected 86 }; 87 88 static void slider_moved(ui_slider_t *, void *, gfx_coord_t); 89 90 static ui_slider_cb_t slider_cb = { 91 .moved = slider_moved 92 }; 93 94 static void scrollbar_up(ui_scrollbar_t *, void *); 95 static void scrollbar_down(ui_scrollbar_t *, void *); 96 static void scrollbar_page_up(ui_scrollbar_t *, void *); 97 static void scrollbar_page_down(ui_scrollbar_t *, void *); 98 static void scrollbar_moved(ui_scrollbar_t *, void *, gfx_coord_t); 99 100 static ui_scrollbar_cb_t scrollbar_cb = { 101 .up = scrollbar_up, 102 .down = scrollbar_down, 103 .page_up = scrollbar_page_up, 104 .page_down = scrollbar_page_down, 105 .moved = scrollbar_moved 106 }; 107 108 static void uidemo_file_load(ui_menu_entry_t *, void *); 109 static void uidemo_file_message(ui_menu_entry_t *, void *); 110 static void uidemo_file_confirmation(ui_menu_entry_t *, void *); 111 static void uidemo_file_exit(ui_menu_entry_t *, void *); 112 static void uidemo_edit_modify(ui_menu_entry_t *, void *); 113 static void uidemo_edit_insert_character(ui_menu_entry_t *, void *); 114 115 static void file_dialog_bok(ui_file_dialog_t *, void *, const char *); 116 static void file_dialog_bcancel(ui_file_dialog_t *, void *); 117 static void file_dialog_close(ui_file_dialog_t *, void *); 118 119 static ui_file_dialog_cb_t file_dialog_cb = { 120 .bok = file_dialog_bok, 121 .bcancel = file_dialog_bcancel, 122 .close = file_dialog_close 123 }; 124 125 static void prompt_dialog_bok(ui_prompt_dialog_t *, void *, const char *); 126 static void prompt_dialog_bcancel(ui_prompt_dialog_t *, void *); 127 static void prompt_dialog_close(ui_prompt_dialog_t *, void *); 128 129 static ui_prompt_dialog_cb_t prompt_dialog_cb = { 130 .bok = prompt_dialog_bok, 131 .bcancel = prompt_dialog_bcancel, 132 .close = prompt_dialog_close 133 }; 134 135 static void select_dialog_bok(ui_select_dialog_t *, void *, void *); 136 static void select_dialog_bcancel(ui_select_dialog_t *, void *); 137 static void select_dialog_close(ui_select_dialog_t *, void *); 138 139 static ui_select_dialog_cb_t select_dialog_cb = { 140 .bok = select_dialog_bok, 141 .bcancel = select_dialog_bcancel, 142 .close = select_dialog_close 143 }; 144 145 static void msg_dialog_button(ui_msg_dialog_t *, void *, unsigned); 146 static void msg_dialog_close(ui_msg_dialog_t *, void *); 147 148 static ui_msg_dialog_cb_t msg_dialog_cb = { 149 .button = msg_dialog_button, 150 .close = msg_dialog_close 151 }; 152 153 /** Horizontal alignment selected by each radio button */ 154 static const gfx_halign_t uidemo_halign[3] = { 155 gfx_halign_left, 156 gfx_halign_center, 157 gfx_halign_right 62 158 }; 63 159 … … 88 184 if (rc != EOK) 89 185 printf("Error changing entry text.\n"); 90 (void) ui_entry_paint(demo->entry);91 186 } else { 92 187 rc = ui_entry_set_text(demo->entry, "Cancel pressed"); 93 188 if (rc != EOK) 94 189 printf("Error changing entry text.\n"); 95 (void) ui_entry_paint(demo->entry); 96 } 190 } 191 } 192 193 /** Check box was switched. 194 * 195 * @param checkbox Check box 196 * @param arg Argument (demo) 197 */ 198 static void checkbox_switched(ui_checkbox_t *checkbox, void *arg, bool enable) 199 { 200 ui_demo_t *demo = (ui_demo_t *) arg; 201 202 ui_entry_set_read_only(demo->entry, enable); 203 } 204 205 /** Radio button was selected. 206 * 207 * @param rbgroup Radio button group 208 * @param garg Group argument (demo) 209 * @param barg Button argument 210 */ 211 static void rb_selected(ui_rbutton_group_t *rbgroup, void *garg, void *barg) 212 { 213 ui_demo_t *demo = (ui_demo_t *) garg; 214 gfx_halign_t halign = *(gfx_halign_t *) barg; 215 216 ui_entry_set_halign(demo->entry, halign); 217 (void) ui_entry_paint(demo->entry); 218 } 219 220 /** Slider was moved. 221 * 222 * @param slider Slider 223 * @param arg Argument (demo) 224 * @param pos Position 225 */ 226 static void slider_moved(ui_slider_t *slider, void *arg, gfx_coord_t pos) 227 { 228 ui_demo_t *demo = (ui_demo_t *) arg; 229 char *str; 230 errno_t rc; 231 int rv; 232 233 rv = asprintf(&str, "Slider at %d of %d", (int) pos, 234 ui_slider_length(slider)); 235 if (rv < 0) { 236 printf("Out of memory.\n"); 237 return; 238 } 239 240 rc = ui_entry_set_text(demo->entry, str); 241 if (rc != EOK) 242 printf("Error changing entry text.\n"); 243 (void) ui_entry_paint(demo->entry); 244 245 free(str); 246 } 247 248 /** Scrollbar up button pressed. 249 * 250 * @param scrollbar Scrollbar 251 * @param arg Argument (demo) 252 */ 253 static void scrollbar_up(ui_scrollbar_t *scrollbar, void *arg) 254 { 255 gfx_coord_t pos; 256 257 pos = ui_scrollbar_get_pos(scrollbar); 258 ui_scrollbar_set_pos(scrollbar, pos - 1); 259 260 pos = ui_scrollbar_get_pos(scrollbar); 261 scrollbar_moved(scrollbar, arg, pos); 262 } 263 264 /** Scrollbar down button pressed. 265 * 266 * @param scrollbar Scrollbar 267 * @param arg Argument (demo) 268 */ 269 static void scrollbar_down(ui_scrollbar_t *scrollbar, void *arg) 270 { 271 gfx_coord_t pos; 272 273 pos = ui_scrollbar_get_pos(scrollbar); 274 ui_scrollbar_set_pos(scrollbar, pos + 1); 275 276 pos = ui_scrollbar_get_pos(scrollbar); 277 scrollbar_moved(scrollbar, arg, pos); 278 } 279 280 /** Scrollbar page up event. 281 * 282 * @param scrollbar Scrollbar 283 * @param arg Argument (demo) 284 */ 285 static void scrollbar_page_up(ui_scrollbar_t *scrollbar, void *arg) 286 { 287 gfx_coord_t pos; 288 289 pos = ui_scrollbar_get_pos(scrollbar); 290 ui_scrollbar_set_pos(scrollbar, pos - 291 ui_scrollbar_trough_length(scrollbar) / 4); 292 293 pos = ui_scrollbar_get_pos(scrollbar); 294 scrollbar_moved(scrollbar, arg, pos); 295 } 296 297 /** Scrollbar page down event. 298 * 299 * @param scrollbar Scrollbar 300 * @param arg Argument (demo) 301 */ 302 static void scrollbar_page_down(ui_scrollbar_t *scrollbar, void *arg) 303 { 304 gfx_coord_t pos; 305 306 pos = ui_scrollbar_get_pos(scrollbar); 307 ui_scrollbar_set_pos(scrollbar, pos + 308 ui_scrollbar_trough_length(scrollbar) / 4); 309 310 pos = ui_scrollbar_get_pos(scrollbar); 311 scrollbar_moved(scrollbar, arg, pos); 312 } 313 314 /** Scrollbar was moved. 315 * 316 * @param scrollbar Scrollbar 317 * @param arg Argument (demo) 318 * @param pos Position 319 */ 320 static void scrollbar_moved(ui_scrollbar_t *scrollbar, void *arg, 321 gfx_coord_t pos) 322 { 323 ui_demo_t *demo = (ui_demo_t *) arg; 324 char *str; 325 errno_t rc; 326 int rv; 327 328 rv = asprintf(&str, "Scrollbar: %d of %d", (int) pos, 329 ui_scrollbar_move_length(scrollbar)); 330 if (rv < 0) { 331 printf("Out of memory.\n"); 332 return; 333 } 334 335 rc = ui_entry_set_text(demo->entry, str); 336 if (rc != EOK) 337 printf("Error changing entry text.\n"); 338 (void) ui_entry_paint(demo->entry); 339 340 free(str); 341 } 342 343 /** Display a message window with OK button. 344 * 345 * @param demo UI demo 346 * @param caption Window caption 347 * @param text Message text 348 */ 349 static void uidemo_show_message(ui_demo_t *demo, const char *caption, 350 const char *text) 351 { 352 ui_msg_dialog_params_t mdparams; 353 ui_msg_dialog_t *dialog; 354 errno_t rc; 355 356 ui_msg_dialog_params_init(&mdparams); 357 mdparams.caption = caption; 358 mdparams.text = text; 359 360 rc = ui_msg_dialog_create(demo->ui, &mdparams, &dialog); 361 if (rc != EOK) { 362 printf("Error creating message dialog.\n"); 363 return; 364 } 365 366 ui_msg_dialog_set_cb(dialog, &msg_dialog_cb, &demo); 367 } 368 369 /** File / Load menu entry selected. 370 * 371 * @param mentry Menu entry 372 * @param arg Argument (demo) 373 */ 374 static void uidemo_file_load(ui_menu_entry_t *mentry, void *arg) 375 { 376 ui_demo_t *demo = (ui_demo_t *) arg; 377 ui_file_dialog_params_t fdparams; 378 ui_file_dialog_t *dialog; 379 errno_t rc; 380 381 ui_file_dialog_params_init(&fdparams); 382 fdparams.caption = "Load File"; 383 384 rc = ui_file_dialog_create(demo->ui, &fdparams, &dialog); 385 if (rc != EOK) { 386 printf("Error creating message dialog.\n"); 387 return; 388 } 389 390 ui_file_dialog_set_cb(dialog, &file_dialog_cb, demo); 391 } 392 393 /** File / Message menu entry selected. 394 * 395 * @param mentry Menu entry 396 * @param arg Argument (demo) 397 */ 398 static void uidemo_file_message(ui_menu_entry_t *mentry, void *arg) 399 { 400 ui_demo_t *demo = (ui_demo_t *) arg; 401 ui_msg_dialog_params_t mdparams; 402 ui_msg_dialog_t *dialog; 403 errno_t rc; 404 405 ui_msg_dialog_params_init(&mdparams); 406 mdparams.caption = "Message For You"; 407 mdparams.text = "Hello, world!"; 408 409 rc = ui_msg_dialog_create(demo->ui, &mdparams, &dialog); 410 if (rc != EOK) { 411 printf("Error creating message dialog.\n"); 412 return; 413 } 414 415 ui_msg_dialog_set_cb(dialog, &msg_dialog_cb, &demo); 416 } 417 418 /** File / Confirmation menu entry selected. 419 * 420 * @param mentry Menu entry 421 * @param arg Argument (demo) 422 */ 423 static void uidemo_file_confirmation(ui_menu_entry_t *mentry, void *arg) 424 { 425 ui_demo_t *demo = (ui_demo_t *) arg; 426 ui_msg_dialog_params_t mdparams; 427 ui_msg_dialog_t *dialog; 428 errno_t rc; 429 430 ui_msg_dialog_params_init(&mdparams); 431 mdparams.caption = "Confirmation"; 432 mdparams.text = "This will not actually do anything. Proceed?"; 433 mdparams.choice = umdc_ok_cancel; 434 435 rc = ui_msg_dialog_create(demo->ui, &mdparams, &dialog); 436 if (rc != EOK) { 437 printf("Error creating message dialog.\n"); 438 return; 439 } 440 441 ui_msg_dialog_set_cb(dialog, &msg_dialog_cb, &demo); 442 } 443 444 /** File / Exit menu entry selected. 445 * 446 * @param mentry Menu entry 447 * @param arg Argument (demo) 448 */ 449 static void uidemo_file_exit(ui_menu_entry_t *mentry, void *arg) 450 { 451 ui_demo_t *demo = (ui_demo_t *) arg; 452 453 ui_quit(demo->ui); 454 } 455 456 /** Edit / Modify menu entry selected. 457 * 458 * @param mentry Menu entry 459 * @param arg Argument (demo) 460 */ 461 static void uidemo_edit_modify(ui_menu_entry_t *mentry, void *arg) 462 { 463 ui_demo_t *demo = (ui_demo_t *) arg; 464 ui_prompt_dialog_params_t pdparams; 465 ui_prompt_dialog_t *dialog; 466 errno_t rc; 467 468 ui_prompt_dialog_params_init(&pdparams); 469 pdparams.caption = "Modify Entry Text"; 470 pdparams.prompt = "Enter New Text"; 471 472 rc = ui_prompt_dialog_create(demo->ui, &pdparams, &dialog); 473 if (rc != EOK) { 474 printf("Error creating prompt dialog.\n"); 475 return; 476 } 477 478 ui_prompt_dialog_set_cb(dialog, &prompt_dialog_cb, demo); 479 } 480 481 /** Edit / Insert Character menu entry selected. 482 * 483 * @param mentry Menu entry 484 * @param arg Argument (demo) 485 */ 486 static void uidemo_edit_insert_character(ui_menu_entry_t *mentry, void *arg) 487 { 488 ui_demo_t *demo = (ui_demo_t *) arg; 489 ui_select_dialog_params_t sdparams; 490 ui_select_dialog_t *dialog; 491 ui_list_entry_attr_t attr; 492 errno_t rc; 493 494 ui_select_dialog_params_init(&sdparams); 495 sdparams.caption = "Insert Character"; 496 sdparams.prompt = "Select character to insert"; 497 498 rc = ui_select_dialog_create(demo->ui, &sdparams, &dialog); 499 if (rc != EOK) { 500 printf("Error creating select dialog.\n"); 501 return; 502 } 503 504 ui_list_entry_attr_init(&attr); 505 attr.caption = "Dollar sign ($)"; 506 attr.arg = (void *)'$'; 507 rc = ui_select_dialog_append(dialog, &attr); 508 if (rc != EOK) { 509 printf("Error appending entry to list.\n"); 510 return; 511 } 512 513 ui_list_entry_attr_init(&attr); 514 attr.caption = "Hash sign (#)"; 515 attr.arg = (void *)'#'; 516 rc = ui_select_dialog_append(dialog, &attr); 517 if (rc != EOK) { 518 printf("Error appending entry to list.\n"); 519 return; 520 } 521 522 ui_list_entry_attr_init(&attr); 523 attr.caption = "Question mark (?)"; 524 attr.arg = (void *)'?'; 525 rc = ui_select_dialog_append(dialog, &attr); 526 if (rc != EOK) { 527 printf("Error appending entry to list.\n"); 528 return; 529 } 530 531 ui_select_dialog_set_cb(dialog, &select_dialog_cb, demo); 532 533 (void) ui_select_dialog_paint(dialog); 534 } 535 536 /** File dialog OK button press. 537 * 538 * @param dialog File dialog 539 * @param arg Argument (ui_demo_t *) 540 * @param fname File name 541 */ 542 static void file_dialog_bok(ui_file_dialog_t *dialog, void *arg, 543 const char *fname) 544 { 545 ui_demo_t *demo = (ui_demo_t *) arg; 546 char buf[128]; 547 char *p; 548 FILE *f; 549 550 ui_file_dialog_destroy(dialog); 551 552 f = fopen(fname, "rt"); 553 if (f == NULL) { 554 uidemo_show_message(demo, "Error", "Error opening file."); 555 return; 556 } 557 558 p = fgets(buf, sizeof(buf), f); 559 if (p == NULL) { 560 uidemo_show_message(demo, "Error", "Error reading file."); 561 fclose(f); 562 return; 563 } 564 565 /* Cut string off at the first non-printable character */ 566 p = buf; 567 while (*p != '\0') { 568 if (*p < ' ') { 569 *p = '\0'; 570 break; 571 } 572 ++p; 573 } 574 575 ui_entry_set_text(demo->entry, buf); 576 fclose(f); 577 } 578 579 /** File dialog cancel button press. 580 * 581 * @param dialog File dialog 582 * @param arg Argument (ui_demo_t *) 583 */ 584 static void file_dialog_bcancel(ui_file_dialog_t *dialog, void *arg) 585 { 586 ui_demo_t *demo = (ui_demo_t *) arg; 587 588 (void) demo; 589 ui_file_dialog_destroy(dialog); 590 } 591 592 /** File dialog close request. 593 * 594 * @param dialog File dialog 595 * @param arg Argument (ui_demo_t *) 596 */ 597 static void file_dialog_close(ui_file_dialog_t *dialog, void *arg) 598 { 599 ui_demo_t *demo = (ui_demo_t *) arg; 600 601 (void) demo; 602 ui_file_dialog_destroy(dialog); 603 } 604 605 /** Prompt dialog OK button press. 606 * 607 * @param dialog Prompt dialog 608 * @param arg Argument (ui_demo_t *) 609 * @param text Submitted text 610 */ 611 static void prompt_dialog_bok(ui_prompt_dialog_t *dialog, void *arg, 612 const char *text) 613 { 614 ui_demo_t *demo = (ui_demo_t *) arg; 615 616 ui_prompt_dialog_destroy(dialog); 617 ui_entry_set_text(demo->entry, text); 618 } 619 620 /** Prompt dialog cancel button press. 621 * 622 * @param dialog Prompt dialog 623 * @param arg Argument (ui_demo_t *) 624 */ 625 static void prompt_dialog_bcancel(ui_prompt_dialog_t *dialog, void *arg) 626 { 627 ui_demo_t *demo = (ui_demo_t *) arg; 628 629 (void) demo; 630 ui_prompt_dialog_destroy(dialog); 631 } 632 633 /** Prompt dialog close request. 634 * 635 * @param dialog Prompt dialog 636 * @param arg Argument (ui_demo_t *) 637 */ 638 static void prompt_dialog_close(ui_prompt_dialog_t *dialog, void *arg) 639 { 640 ui_demo_t *demo = (ui_demo_t *) arg; 641 642 (void) demo; 643 ui_prompt_dialog_destroy(dialog); 644 } 645 646 /** Select dialog OK button press. 647 * 648 * @param dialog Select dialog 649 * @param arg Argument (ui_demo_t *) 650 * @param text Submitted text 651 */ 652 static void select_dialog_bok(ui_select_dialog_t *dialog, void *arg, 653 void *earg) 654 { 655 ui_demo_t *demo = (ui_demo_t *) arg; 656 char str[2]; 657 658 ui_select_dialog_destroy(dialog); 659 str[0] = (char)(intptr_t)earg; 660 str[1] = '\0'; 661 (void) ui_entry_insert_str(demo->entry, str); 662 } 663 664 /** Select dialog cancel button press. 665 * 666 * @param dialog Select dialog 667 * @param arg Argument (ui_demo_t *) 668 */ 669 static void select_dialog_bcancel(ui_select_dialog_t *dialog, void *arg) 670 { 671 ui_demo_t *demo = (ui_demo_t *) arg; 672 673 (void) demo; 674 ui_select_dialog_destroy(dialog); 675 } 676 677 /** Select dialog close request. 678 * 679 * @param dialog Select dialog 680 * @param arg Argument (ui_demo_t *) 681 */ 682 static void select_dialog_close(ui_select_dialog_t *dialog, void *arg) 683 { 684 ui_demo_t *demo = (ui_demo_t *) arg; 685 686 (void) demo; 687 ui_select_dialog_destroy(dialog); 688 } 689 690 /** Message dialog button press. 691 * 692 * @param dialog Message dialog 693 * @param arg Argument (ui_demo_t *) 694 * @param bnum Button number 695 */ 696 static void msg_dialog_button(ui_msg_dialog_t *dialog, void *arg, 697 unsigned bnum) 698 { 699 ui_demo_t *demo = (ui_demo_t *) arg; 700 701 (void) demo; 702 ui_msg_dialog_destroy(dialog); 703 } 704 705 /** Message dialog close request. 706 * 707 * @param dialog Message dialog 708 * @param arg Argument (ui_demo_t *) 709 */ 710 static void msg_dialog_close(ui_msg_dialog_t *dialog, void *arg) 711 { 712 ui_demo_t *demo = (ui_demo_t *) arg; 713 714 (void) demo; 715 ui_msg_dialog_destroy(dialog); 97 716 } 98 717 … … 110 729 gfx_bitmap_t *bitmap; 111 730 gfx_coord2_t off; 731 ui_menu_entry_t *mmsg; 732 ui_menu_entry_t *mload; 733 ui_menu_entry_t *mfoo; 734 ui_menu_entry_t *mbar; 735 ui_menu_entry_t *mfoobar; 736 ui_menu_entry_t *msep; 737 ui_menu_entry_t *mexit; 738 ui_menu_entry_t *mmodify; 739 ui_menu_entry_t *minsert_char; 740 ui_menu_entry_t *mabout; 741 ui_list_entry_attr_t eattr; 112 742 errno_t rc; 113 743 … … 117 747 return rc; 118 748 } 749 750 memset((void *) &demo, 0, sizeof(demo)); 751 demo.ui = ui; 119 752 120 753 ui_wnd_params_init(¶ms); 121 754 params.caption = "UI Demo"; 122 params.style |= ui_wds_resizable; 123 params.rect.p0.x = 0; 124 params.rect.p0.y = 0; 125 params.rect.p1.x = 220; 126 params.rect.p1.y = 180; 127 128 memset((void *) &demo, 0, sizeof(demo)); 129 demo.ui = ui; 755 params.style |= ui_wds_maximize_btn | ui_wds_resizable; 756 757 /* FIXME: Auto layout */ 758 if (ui_is_textmode(ui)) { 759 params.rect.p0.x = 0; 760 params.rect.p0.y = 0; 761 params.rect.p1.x = 46; 762 params.rect.p1.y = 25; 763 } else { 764 params.rect.p0.x = 0; 765 params.rect.p0.y = 0; 766 params.rect.p1.x = 255; 767 params.rect.p1.y = 410; 768 } 769 770 /* Only allow making the window larger */ 771 gfx_rect_dims(¶ms.rect, ¶ms.min_size); 130 772 131 773 rc = ui_window_create(ui, ¶ms, &window); … … 147 789 } 148 790 791 rc = ui_menu_bar_create(ui, window, &demo.mbar); 792 if (rc != EOK) { 793 printf("Error creating menu bar.\n"); 794 return rc; 795 } 796 797 rc = ui_menu_dd_create(demo.mbar, "~F~ile", NULL, &demo.mfile); 798 if (rc != EOK) { 799 printf("Error creating menu.\n"); 800 return rc; 801 } 802 803 rc = ui_menu_entry_create(demo.mfile, "~M~essage", "", &mmsg); 804 if (rc != EOK) { 805 printf("Error creating menu.\n"); 806 return rc; 807 } 808 809 ui_menu_entry_set_cb(mmsg, uidemo_file_message, (void *) &demo); 810 811 rc = ui_menu_entry_create(demo.mfile, "~C~onfirmation", "", &mmsg); 812 if (rc != EOK) { 813 printf("Error creating menu.\n"); 814 return rc; 815 } 816 817 ui_menu_entry_set_cb(mmsg, uidemo_file_confirmation, (void *) &demo); 818 819 rc = ui_menu_entry_create(demo.mfile, "~L~oad", "", &mload); 820 if (rc != EOK) { 821 printf("Error creating menu.\n"); 822 return rc; 823 } 824 825 ui_menu_entry_set_cb(mload, uidemo_file_load, (void *) &demo); 826 827 rc = ui_menu_entry_create(demo.mfile, "~F~oo", "Ctrl-Alt-Del", &mfoo); 828 if (rc != EOK) { 829 printf("Error creating menu.\n"); 830 return rc; 831 } 832 833 rc = ui_menu_entry_create(demo.mfile, "~B~ar", "", &mbar); 834 if (rc != EOK) { 835 printf("Error creating menu.\n"); 836 return rc; 837 } 838 839 rc = ui_menu_entry_create(demo.mfile, "F~o~obar", "", &mfoobar); 840 if (rc != EOK) { 841 printf("Error creating menu.\n"); 842 return rc; 843 } 844 845 ui_menu_entry_set_disabled(mfoobar, true); 846 847 rc = ui_menu_entry_sep_create(demo.mfile, &msep); 848 if (rc != EOK) { 849 printf("Error creating menu.\n"); 850 return rc; 851 } 852 853 rc = ui_menu_entry_create(demo.mfile, "E~x~it", "Alt-F4", &mexit); 854 if (rc != EOK) { 855 printf("Error creating menu.\n"); 856 return rc; 857 } 858 859 ui_menu_entry_set_cb(mexit, uidemo_file_exit, (void *) &demo); 860 861 rc = ui_menu_dd_create(demo.mbar, "~E~dit", NULL, &demo.medit); 862 if (rc != EOK) { 863 printf("Error creating menu.\n"); 864 return rc; 865 } 866 867 rc = ui_menu_entry_create(demo.medit, "~M~odify", "", &mmodify); 868 if (rc != EOK) { 869 printf("Error creating menu.\n"); 870 return rc; 871 } 872 873 ui_menu_entry_set_cb(mmodify, uidemo_edit_modify, (void *) &demo); 874 875 rc = ui_menu_entry_create(demo.medit, "~I~nsert Character", 876 "", &minsert_char); 877 if (rc != EOK) { 878 printf("Error creating menu.\n"); 879 return rc; 880 } 881 882 ui_menu_entry_set_cb(minsert_char, uidemo_edit_insert_character, 883 (void *) &demo); 884 885 rc = ui_menu_dd_create(demo.mbar, "~P~references", NULL, 886 &demo.mpreferences); 887 if (rc != EOK) { 888 printf("Error creating menu.\n"); 889 return rc; 890 } 891 892 rc = ui_menu_dd_create(demo.mbar, "~H~elp", NULL, &demo.mhelp); 893 if (rc != EOK) { 894 printf("Error creating menu.\n"); 895 return rc; 896 } 897 898 rc = ui_menu_entry_create(demo.mhelp, "~A~bout", "Ctrl-H, F1", &mabout); 899 if (rc != EOK) { 900 printf("Error creating menu.\n"); 901 return rc; 902 } 903 904 /* FIXME: Auto layout */ 905 if (ui_is_textmode(ui)) { 906 rect.p0.x = 1; 907 rect.p0.y = 1; 908 rect.p1.x = 43; 909 rect.p1.y = 2; 910 } else { 911 rect.p0.x = 4; 912 rect.p0.y = 30; 913 rect.p1.x = 251; 914 rect.p1.y = 52; 915 } 916 917 ui_menu_bar_set_rect(demo.mbar, &rect); 918 919 rc = ui_fixed_add(demo.fixed, ui_menu_bar_ctl(demo.mbar)); 920 if (rc != EOK) { 921 printf("Error adding control to layout.\n"); 922 return rc; 923 } 924 925 rc = ui_tab_set_create(ui_res, &demo.tabset); 926 if (rc != EOK) { 927 printf("Error creating tab set.\n"); 928 return rc; 929 } 930 931 /* FIXME: Auto layout */ 932 if (ui_is_textmode(ui)) { 933 rect.p0.x = 2; 934 rect.p0.y = 2; 935 rect.p1.x = 44; 936 rect.p1.y = 24; 937 } else { 938 rect.p0.x = 8; 939 rect.p0.y = 53; 940 rect.p1.x = 250; 941 rect.p1.y = 405; 942 } 943 944 ui_tab_set_set_rect(demo.tabset, &rect); 945 946 rc = ui_tab_create(demo.tabset, "Basic", &demo.tbasic); 947 if (rc != EOK) { 948 printf("Error creating tab.\n"); 949 return rc; 950 } 951 952 rc = ui_tab_create(demo.tabset, "Lists", &demo.tlists); 953 if (rc != EOK) { 954 printf("Error creating tab.\n"); 955 return rc; 956 } 957 958 rc = ui_fixed_add(demo.fixed, ui_tab_set_ctl(demo.tabset)); 959 if (rc != EOK) { 960 printf("Error adding control to layout.\n"); 961 return rc; 962 } 963 964 rc = ui_fixed_create(&demo.bfixed); 965 if (rc != EOK) { 966 printf("Error creating fixed layout.\n"); 967 return rc; 968 } 969 970 rc = ui_entry_create(window, "", &demo.entry); 971 if (rc != EOK) { 972 printf("Error creating entry.\n"); 973 return rc; 974 } 975 976 /* FIXME: Auto layout */ 977 if (ui_is_textmode(ui)) { 978 rect.p0.x = 4; 979 rect.p0.y = 5; 980 rect.p1.x = 41; 981 rect.p1.y = 6; 982 } else { 983 rect.p0.x = 15; 984 rect.p0.y = 88; 985 rect.p1.x = 205; 986 rect.p1.y = 113; 987 } 988 989 ui_entry_set_rect(demo.entry, &rect); 990 ui_entry_set_halign(demo.entry, gfx_halign_center); 991 992 rc = ui_fixed_add(demo.bfixed, ui_entry_ctl(demo.entry)); 993 if (rc != EOK) { 994 printf("Error adding control to layout.\n"); 995 return rc; 996 } 997 149 998 rc = ui_label_create(ui_res, "Text label", &demo.label); 150 999 if (rc != EOK) { … … 153 1002 } 154 1003 155 rect.p0.x = 60; 156 rect.p0.y = 37; 157 rect.p1.x = 160; 158 rect.p1.y = 50; 1004 /* FIXME: Auto layout */ 1005 if (ui_is_textmode(ui)) { 1006 rect.p0.x = 4; 1007 rect.p0.y = 7; 1008 rect.p1.x = 41; 1009 rect.p1.y = 8; 1010 } else { 1011 rect.p0.x = 60; 1012 rect.p0.y = 123; 1013 rect.p1.x = 160; 1014 rect.p1.y = 136; 1015 } 1016 159 1017 ui_label_set_rect(demo.label, &rect); 160 1018 ui_label_set_halign(demo.label, gfx_halign_center); 161 1019 162 rc = ui_fixed_add(demo. fixed, ui_label_ctl(demo.label));1020 rc = ui_fixed_add(demo.bfixed, ui_label_ctl(demo.label)); 163 1021 if (rc != EOK) { 164 1022 printf("Error adding control to layout.\n"); … … 174 1032 ui_pbutton_set_cb(demo.pb1, &pbutton_cb, (void *) &demo); 175 1033 176 rect.p0.x = 15; 177 rect.p0.y = 70; 178 rect.p1.x = 105; 179 rect.p1.y = 98; 1034 /* FIXME: Auto layout */ 1035 if (ui_is_textmode(ui)) { 1036 rect.p0.x = 4; 1037 rect.p0.y = 9; 1038 rect.p1.x = 15; 1039 rect.p1.y = 10; 1040 } else { 1041 rect.p0.x = 15; 1042 rect.p0.y = 146; 1043 rect.p1.x = 105; 1044 rect.p1.y = 174; 1045 } 1046 180 1047 ui_pbutton_set_rect(demo.pb1, &rect); 181 1048 182 1049 ui_pbutton_set_default(demo.pb1, true); 183 1050 184 rc = ui_fixed_add(demo. fixed, ui_pbutton_ctl(demo.pb1));1051 rc = ui_fixed_add(demo.bfixed, ui_pbutton_ctl(demo.pb1)); 185 1052 if (rc != EOK) { 186 1053 printf("Error adding control to layout.\n"); … … 196 1063 ui_pbutton_set_cb(demo.pb2, &pbutton_cb, (void *) &demo); 197 1064 198 rect.p0.x = 115; 199 rect.p0.y = 70; 200 rect.p1.x = 205; 201 rect.p1.y = 98; 1065 if (ui_is_textmode(ui)) { 1066 rect.p0.x = 30; 1067 rect.p0.y = 9; 1068 rect.p1.x = 41; 1069 rect.p1.y = 10; 1070 } else { 1071 rect.p0.x = 115; 1072 rect.p0.y = 146; 1073 rect.p1.x = 205; 1074 rect.p1.y = 174; 1075 } 1076 202 1077 ui_pbutton_set_rect(demo.pb2, &rect); 203 1078 204 rc = ui_fixed_add(demo. fixed, ui_pbutton_ctl(demo.pb2));1079 rc = ui_fixed_add(demo.bfixed, ui_pbutton_ctl(demo.pb2)); 205 1080 if (rc != EOK) { 206 1081 printf("Error adding control to layout.\n"); … … 208 1083 } 209 1084 210 rc = ui_entry_create(ui_res, "", &demo.entry);211 if (rc != EOK) {212 printf("Error creating entry.\n");213 return rc;214 }215 216 rect.p0.x = 15;217 rect.p0.y = 110;218 rect.p1.x = 205;219 rect.p1.y = 135;220 ui_entry_set_rect(demo.entry, &rect);221 ui_entry_set_halign(demo.entry, gfx_halign_center);222 223 rc = ui_fixed_add(demo.fixed, ui_entry_ctl(demo.entry));224 if (rc != EOK) {225 printf("Error adding control to layout.\n");226 return rc;227 }228 229 1085 gfx_bitmap_params_init(&bparams); 230 bparams.rect.p0.x = 0; 231 bparams.rect.p0.y = 0; 232 bparams.rect.p1.x = 188; 233 bparams.rect.p1.y = 24; 1086 if (ui_is_textmode(ui)) { 1087 bparams.rect.p0.x = 0; 1088 bparams.rect.p0.y = 0; 1089 bparams.rect.p1.x = 37; 1090 bparams.rect.p1.y = 2; 1091 } else { 1092 bparams.rect.p0.x = 0; 1093 bparams.rect.p0.y = 0; 1094 bparams.rect.p1.x = 188; 1095 bparams.rect.p1.y = 24; 1096 } 234 1097 235 1098 rc = gfx_bitmap_create(gc, &bparams, NULL, &bitmap); … … 247 1110 } 248 1111 249 off.x = 15; 250 off.y = 145; 1112 if (ui_is_textmode(ui)) { 1113 off.x = 4; 1114 off.y = 11; 1115 } else { 1116 off.x = 15; 1117 off.y = 190; 1118 } 1119 251 1120 gfx_rect_translate(&off, &bparams.rect, &rect); 252 1121 253 1122 /* Adjust for frame width (2 x 1 pixel) */ 254 rect.p1.x += 2; 255 rect.p1.y += 2; 1123 if (!ui_is_textmode(ui)) { 1124 ui_image_set_flags(demo.image, ui_imgf_frame); 1125 rect.p1.x += 2; 1126 rect.p1.y += 2; 1127 } 1128 256 1129 ui_image_set_rect(demo.image, &rect); 257 ui_image_set_flags(demo.image, ui_imgf_frame); 258 259 rc = ui_fixed_add(demo.fixed, ui_image_ctl(demo.image)); 1130 1131 rc = ui_fixed_add(demo.bfixed, ui_image_ctl(demo.image)); 260 1132 if (rc != EOK) { 261 1133 printf("Error adding control to layout.\n"); 262 1134 return rc; 263 1135 } 1136 1137 rc = ui_checkbox_create(ui_res, "Read only", &demo.checkbox); 1138 if (rc != EOK) { 1139 printf("Error creating check box.\n"); 1140 return rc; 1141 } 1142 1143 ui_checkbox_set_cb(demo.checkbox, &checkbox_cb, (void *) &demo); 1144 1145 /* FIXME: Auto layout */ 1146 if (ui_is_textmode(ui)) { 1147 rect.p0.x = 4; 1148 rect.p0.y = 14; 1149 rect.p1.x = 14; 1150 rect.p1.y = 15; 1151 } else { 1152 rect.p0.x = 15; 1153 rect.p0.y = 225; 1154 rect.p1.x = 140; 1155 rect.p1.y = 245; 1156 } 1157 1158 ui_checkbox_set_rect(demo.checkbox, &rect); 1159 1160 rc = ui_fixed_add(demo.bfixed, ui_checkbox_ctl(demo.checkbox)); 1161 if (rc != EOK) { 1162 printf("Error adding control to layout.\n"); 1163 return rc; 1164 } 1165 1166 rc = ui_rbutton_group_create(ui_res, &demo.rbgroup); 1167 if (rc != EOK) { 1168 printf("Error creating radio button group.\n"); 1169 return rc; 1170 } 1171 1172 rc = ui_rbutton_create(demo.rbgroup, "Left", (void *) &uidemo_halign[0], 1173 &demo.rbleft); 1174 if (rc != EOK) { 1175 printf("Error creating radio button.\n"); 1176 return rc; 1177 } 1178 1179 ui_rbutton_group_set_cb(demo.rbgroup, &rbutton_group_cb, 1180 (void *) &demo); 1181 1182 /* FIXME: Auto layout */ 1183 if (ui_is_textmode(ui)) { 1184 rect.p0.x = 4; 1185 rect.p0.y = 16; 1186 rect.p1.x = 14; 1187 rect.p1.y = 17; 1188 } else { 1189 rect.p0.x = 15; 1190 rect.p0.y = 255; 1191 rect.p1.x = 140; 1192 rect.p1.y = 275; 1193 } 1194 ui_rbutton_set_rect(demo.rbleft, &rect); 1195 1196 rc = ui_fixed_add(demo.bfixed, ui_rbutton_ctl(demo.rbleft)); 1197 if (rc != EOK) { 1198 printf("Error adding control to layout.\n"); 1199 return rc; 1200 } 1201 1202 rc = ui_rbutton_create(demo.rbgroup, "Center", (void *) &uidemo_halign[1], 1203 &demo.rbcenter); 1204 if (rc != EOK) { 1205 printf("Error creating radio button.\n"); 1206 return rc; 1207 } 1208 1209 /* FIXME: Auto layout */ 1210 if (ui_is_textmode(ui)) { 1211 rect.p0.x = 4; 1212 rect.p0.y = 17; 1213 rect.p1.x = 14; 1214 rect.p1.y = 18; 1215 } else { 1216 rect.p0.x = 15; 1217 rect.p0.y = 285; 1218 rect.p1.x = 140; 1219 rect.p1.y = 305; 1220 } 1221 ui_rbutton_set_rect(demo.rbcenter, &rect); 1222 ui_rbutton_select(demo.rbcenter); 1223 1224 rc = ui_fixed_add(demo.bfixed, ui_rbutton_ctl(demo.rbcenter)); 1225 if (rc != EOK) { 1226 printf("Error adding control to layout.\n"); 1227 return rc; 1228 } 1229 1230 rc = ui_rbutton_create(demo.rbgroup, "Right", (void *) &uidemo_halign[2], 1231 &demo.rbright); 1232 if (rc != EOK) { 1233 printf("Error creating radio button.\n"); 1234 return rc; 1235 } 1236 1237 /* FIXME: Auto layout */ 1238 if (ui_is_textmode(ui)) { 1239 rect.p0.x = 4; 1240 rect.p0.y = 18; 1241 rect.p1.x = 14; 1242 rect.p1.y = 19; 1243 } else { 1244 rect.p0.x = 15; 1245 rect.p0.y = 315; 1246 rect.p1.x = 140; 1247 rect.p1.y = 335; 1248 } 1249 ui_rbutton_set_rect(demo.rbright, &rect); 1250 1251 rc = ui_fixed_add(demo.bfixed, ui_rbutton_ctl(demo.rbright)); 1252 if (rc != EOK) { 1253 printf("Error adding control to layout.\n"); 1254 return rc; 1255 } 1256 1257 rc = ui_slider_create(ui_res, &demo.slider); 1258 if (rc != EOK) { 1259 printf("Error creating button.\n"); 1260 return rc; 1261 } 1262 1263 ui_slider_set_cb(demo.slider, &slider_cb, (void *) &demo); 1264 1265 /* FIXME: Auto layout */ 1266 if (ui_is_textmode(ui)) { 1267 rect.p0.x = 4; 1268 rect.p0.y = 20; 1269 rect.p1.x = 32; 1270 rect.p1.y = 21; 1271 } else { 1272 rect.p0.x = 15; 1273 rect.p0.y = 345; 1274 rect.p1.x = 130; 1275 rect.p1.y = 365; 1276 } 1277 1278 ui_slider_set_rect(demo.slider, &rect); 1279 1280 rc = ui_fixed_add(demo.bfixed, ui_slider_ctl(demo.slider)); 1281 if (rc != EOK) { 1282 printf("Error adding control to layout.\n"); 1283 return rc; 1284 } 1285 1286 rc = ui_scrollbar_create(ui, window, ui_sbd_horiz, &demo.hscrollbar); 1287 if (rc != EOK) { 1288 printf("Error creating scrollbar.\n"); 1289 return rc; 1290 } 1291 1292 ui_scrollbar_set_cb(demo.hscrollbar, &scrollbar_cb, (void *) &demo); 1293 1294 /* FIXME: Auto layout */ 1295 if (ui_is_textmode(ui)) { 1296 rect.p0.x = 4; 1297 rect.p0.y = 22; 1298 rect.p1.x = 42; 1299 rect.p1.y = 23; 1300 } else { 1301 rect.p0.x = 15; 1302 rect.p0.y = 375; 1303 rect.p1.x = 220; 1304 rect.p1.y = 398; 1305 } 1306 1307 ui_scrollbar_set_rect(demo.hscrollbar, &rect); 1308 1309 ui_scrollbar_set_thumb_length(demo.hscrollbar, 1310 ui_scrollbar_trough_length(demo.hscrollbar) / 4); 1311 1312 rc = ui_fixed_add(demo.bfixed, ui_scrollbar_ctl(demo.hscrollbar)); 1313 if (rc != EOK) { 1314 printf("Error adding control to layout.\n"); 1315 return rc; 1316 } 1317 1318 rc = ui_scrollbar_create(ui, window, ui_sbd_vert, &demo.vscrollbar); 1319 if (rc != EOK) { 1320 printf("Error creating button.\n"); 1321 return rc; 1322 } 1323 1324 ui_scrollbar_set_cb(demo.vscrollbar, &scrollbar_cb, (void *) &demo); 1325 1326 /* FIXME: Auto layout */ 1327 if (ui_is_textmode(ui)) { 1328 rect.p0.x = 42; 1329 rect.p0.y = 5; 1330 rect.p1.x = 43; 1331 rect.p1.y = 22; 1332 } else { 1333 rect.p0.x = 220; 1334 rect.p0.y = 88; 1335 rect.p1.x = 243; 1336 rect.p1.y = 375; 1337 } 1338 1339 ui_scrollbar_set_rect(demo.vscrollbar, &rect); 1340 1341 ui_scrollbar_set_thumb_length(demo.vscrollbar, 1342 ui_scrollbar_trough_length(demo.vscrollbar) / 4); 1343 1344 rc = ui_fixed_add(demo.bfixed, ui_scrollbar_ctl(demo.vscrollbar)); 1345 if (rc != EOK) { 1346 printf("Error adding control to layout.\n"); 1347 return rc; 1348 } 1349 1350 ui_tab_add(demo.tbasic, ui_fixed_ctl(demo.bfixed)); 1351 1352 rc = ui_fixed_create(&demo.lfixed); 1353 if (rc != EOK) { 1354 printf("Error creating fixed layout.\n"); 1355 return rc; 1356 } 1357 1358 rc = ui_list_create(window, false, &demo.list); 1359 if (rc != EOK) { 1360 printf("Error creating list.\n"); 1361 return rc; 1362 } 1363 1364 ui_list_entry_attr_init(&eattr); 1365 1366 eattr.caption = "One"; 1367 rc = ui_list_entry_append(demo.list, &eattr, NULL); 1368 if (rc != EOK) { 1369 printf("Error adding list entry.\n"); 1370 return rc; 1371 } 1372 1373 eattr.caption = "Two"; 1374 rc = ui_list_entry_append(demo.list, &eattr, NULL); 1375 if (rc != EOK) { 1376 printf("Error adding list entry.\n"); 1377 return rc; 1378 } 1379 1380 eattr.caption = "Three"; 1381 rc = ui_list_entry_append(demo.list, &eattr, NULL); 1382 if (rc != EOK) { 1383 printf("Error adding list entry.\n"); 1384 return rc; 1385 } 1386 1387 eattr.caption = "Four"; 1388 rc = ui_list_entry_append(demo.list, &eattr, NULL); 1389 if (rc != EOK) { 1390 printf("Error adding list entry.\n"); 1391 return rc; 1392 } 1393 1394 eattr.caption = "Five"; 1395 rc = ui_list_entry_append(demo.list, &eattr, NULL); 1396 if (rc != EOK) { 1397 printf("Error adding list entry.\n"); 1398 return rc; 1399 } 1400 1401 eattr.caption = "Six"; 1402 rc = ui_list_entry_append(demo.list, &eattr, NULL); 1403 if (rc != EOK) { 1404 printf("Error adding list entry.\n"); 1405 return rc; 1406 } 1407 1408 /* FIXME: Auto layout */ 1409 if (ui_is_textmode(ui)) { 1410 rect.p0.x = 4; 1411 rect.p0.y = 5; 1412 rect.p1.x = 41; 1413 rect.p1.y = 10; 1414 } else { 1415 rect.p0.x = 15; 1416 rect.p0.y = 88; 1417 rect.p1.x = 245; 1418 rect.p1.y = 173; 1419 } 1420 1421 ui_list_set_rect(demo.list, &rect); 1422 1423 rc = ui_fixed_add(demo.lfixed, ui_list_ctl(demo.list)); 1424 if (rc != EOK) { 1425 printf("Error adding control to layout.\n"); 1426 return rc; 1427 } 1428 1429 ui_tab_add(demo.tlists, ui_fixed_ctl(demo.lfixed)); 264 1430 265 1431 ui_window_add(window, ui_fixed_ctl(demo.fixed)); … … 307 1473 k = i * i + j * j; 308 1474 pixelmap_put_pixel(&pixelmap, i, j, 309 PIXEL( 255, k, k, 255 - k));1475 PIXEL(0, k, k, 255 - k)); 310 1476 } 311 1477 } … … 321 1487 int main(int argc, char *argv[]) 322 1488 { 323 const char *display_spec = UI_ DISPLAY_DEFAULT;1489 const char *display_spec = UI_ANY_DEFAULT; 324 1490 errno_t rc; 325 1491 int i;
Note:
See TracChangeset
for help on using the changeset viewer.