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