Changes in uspace/app/uidemo/uidemo.c [a977e37:9a07ee3] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/uidemo/uidemo.c
ra977e37 r9a07ee3 1 1 /* 2 * Copyright (c) 202 1Jiri Svoboda2 * Copyright (c) 2024 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 40 40 #include <str.h> 41 41 #include <ui/entry.h> 42 #include <ui/filedialog.h> 42 43 #include <ui/fixed.h> 43 44 #include <ui/image.h> 44 45 #include <ui/label.h> 46 #include <ui/list.h> 47 #include <ui/menu.h> 45 48 #include <ui/menubar.h> 49 #include <ui/menudd.h> 46 50 #include <ui/menuentry.h> 47 #include <ui/menu.h>48 51 #include <ui/msgdialog.h> 49 52 #include <ui/pbutton.h> 53 #include <ui/promptdialog.h> 50 54 #include <ui/resource.h> 55 #include <ui/selectdialog.h> 56 #include <ui/tab.h> 57 #include <ui/tabset.h> 51 58 #include <ui/ui.h> 52 59 #include <ui/window.h> … … 85 92 }; 86 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 *); 87 109 static void uidemo_file_message(ui_menu_entry_t *, void *); 110 static void uidemo_file_confirmation(ui_menu_entry_t *, void *); 88 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 }; 89 144 90 145 static void msg_dialog_button(ui_msg_dialog_t *, void *, unsigned); … … 96 151 }; 97 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 158 }; 159 98 160 /** Window close button was clicked. 99 161 * … … 122 184 if (rc != EOK) 123 185 printf("Error changing entry text.\n"); 124 (void) ui_entry_paint(demo->entry);125 186 } else { 126 187 rc = ui_entry_set_text(demo->entry, "Cancel pressed"); 127 188 if (rc != EOK) 128 189 printf("Error changing entry text.\n"); 129 (void) ui_entry_paint(demo->entry);130 190 } 131 191 } … … 139 199 { 140 200 ui_demo_t *demo = (ui_demo_t *) arg; 141 errno_t rc; 142 143 if (enable) { 144 rc = ui_entry_set_text(demo->entry, "Checked"); 145 if (rc != EOK) 146 printf("Error changing entry text.\n"); 147 (void) ui_entry_paint(demo->entry); 148 } else { 149 rc = ui_entry_set_text(demo->entry, "Unchecked"); 150 if (rc != EOK) 151 printf("Error changing entry text.\n"); 152 (void) ui_entry_paint(demo->entry); 153 } 201 202 ui_entry_set_read_only(demo->entry, enable); 154 203 } 155 204 … … 163 212 { 164 213 ui_demo_t *demo = (ui_demo_t *) garg; 165 const char *text = (const char *) barg; 166 errno_t rc; 167 168 rc = ui_entry_set_text(demo->entry, text); 169 if (rc != EOK) 170 printf("Error changing entry text.\n"); 214 gfx_halign_t halign = *(gfx_halign_t *) barg; 215 216 ui_entry_set_halign(demo->entry, halign); 171 217 (void) ui_entry_paint(demo->entry); 172 218 } … … 200 246 } 201 247 202 /** File/message menu entry selected.203 * 204 * @param mentry Menu entry248 /** Scrollbar up button pressed. 249 * 250 * @param scrollbar Scrollbar 205 251 * @param arg Argument (demo) 206 252 */ 207 static void uidemo_file_message(ui_menu_entry_t *mentry, void *arg) 208 { 209 ui_demo_t *demo = (ui_demo_t *) arg; 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 { 210 352 ui_msg_dialog_params_t mdparams; 211 353 ui_msg_dialog_t *dialog; … … 213 355 214 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); 215 406 mdparams.caption = "Message For You"; 216 407 mdparams.text = "Hello, world!"; … … 223 414 224 415 ui_msg_dialog_set_cb(dialog, &msg_dialog_cb, &demo); 225 226 } 227 228 /** File/exit menu entry selected. 416 } 417 418 /** File / Confirmation menu entry selected. 229 419 * 230 420 * @param mentry Menu entry 231 421 * @param arg Argument (demo) 232 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 */ 233 449 static void uidemo_file_exit(ui_menu_entry_t *mentry, void *arg) 234 450 { … … 236 452 237 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); 238 688 } 239 689 … … 280 730 gfx_coord2_t off; 281 731 ui_menu_entry_t *mmsg; 732 ui_menu_entry_t *mload; 282 733 ui_menu_entry_t *mfoo; 283 734 ui_menu_entry_t *mbar; 284 735 ui_menu_entry_t *mfoobar; 736 ui_menu_entry_t *msep; 285 737 ui_menu_entry_t *mexit; 738 ui_menu_entry_t *mmodify; 739 ui_menu_entry_t *minsert_char; 286 740 ui_menu_entry_t *mabout; 741 ui_list_entry_attr_t eattr; 287 742 errno_t rc; 288 743 … … 298 753 ui_wnd_params_init(¶ms); 299 754 params.caption = "UI Demo"; 300 params.style |= ui_wds_ resizable;755 params.style |= ui_wds_maximize_btn | ui_wds_resizable; 301 756 302 757 /* FIXME: Auto layout */ … … 304 759 params.rect.p0.x = 0; 305 760 params.rect.p0.y = 0; 306 params.rect.p1.x = 80;761 params.rect.p1.x = 46; 307 762 params.rect.p1.y = 25; 308 763 } else { 309 764 params.rect.p0.x = 0; 310 765 params.rect.p0.y = 0; 311 params.rect.p1.x = 220; 312 params.rect.p1.y = 350; 313 } 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); 314 772 315 773 rc = ui_window_create(ui, ¶ms, &window); … … 337 795 } 338 796 339 rc = ui_menu_ create(demo.mbar, "File", &demo.mfile);797 rc = ui_menu_dd_create(demo.mbar, "~F~ile", NULL, &demo.mfile); 340 798 if (rc != EOK) { 341 799 printf("Error creating menu.\n"); … … 343 801 } 344 802 345 rc = ui_menu_entry_create(demo.mfile, " Message", "", &mmsg);803 rc = ui_menu_entry_create(demo.mfile, "~M~essage", "", &mmsg); 346 804 if (rc != EOK) { 347 805 printf("Error creating menu.\n"); … … 351 809 ui_menu_entry_set_cb(mmsg, uidemo_file_message, (void *) &demo); 352 810 353 rc = ui_menu_entry_create(demo.mfile, " Foo", "Ctrl-Alt-Del", &mfoo);811 rc = ui_menu_entry_create(demo.mfile, "~C~onfirmation", "", &mmsg); 354 812 if (rc != EOK) { 355 813 printf("Error creating menu.\n"); … … 357 815 } 358 816 359 rc = ui_menu_entry_create(demo.mfile, "Bar", "", &mbar); 817 ui_menu_entry_set_cb(mmsg, uidemo_file_confirmation, (void *) &demo); 818 819 rc = ui_menu_entry_create(demo.mfile, "~L~oad", "", &mload); 360 820 if (rc != EOK) { 361 821 printf("Error creating menu.\n"); … … 363 823 } 364 824 365 rc = ui_menu_entry_create(demo.mfile, "Foobar", "", &mfoobar); 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); 366 828 if (rc != EOK) { 367 829 printf("Error creating menu.\n"); … … 369 831 } 370 832 371 rc = ui_menu_entry_ sep_create(demo.mfile, &mexit);833 rc = ui_menu_entry_create(demo.mfile, "~B~ar", "", &mbar); 372 834 if (rc != EOK) { 373 835 printf("Error creating menu.\n"); … … 375 837 } 376 838 377 rc = ui_menu_entry_create(demo.mfile, " Exit", "Alt-F4", &mexit);839 rc = ui_menu_entry_create(demo.mfile, "F~o~obar", "", &mfoobar); 378 840 if (rc != EOK) { 379 841 printf("Error creating menu.\n"); … … 381 843 } 382 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 383 859 ui_menu_entry_set_cb(mexit, uidemo_file_exit, (void *) &demo); 384 860 385 rc = ui_menu_ create(demo.mbar, "Edit", &demo.medit);861 rc = ui_menu_dd_create(demo.mbar, "~E~dit", NULL, &demo.medit); 386 862 if (rc != EOK) { 387 863 printf("Error creating menu.\n"); … … 389 865 } 390 866 391 rc = ui_menu_ create(demo.mbar, "Preferences", &demo.mpreferences);867 rc = ui_menu_entry_create(demo.medit, "~M~odify", "", &mmodify); 392 868 if (rc != EOK) { 393 869 printf("Error creating menu.\n"); … … 395 871 } 396 872 397 rc = ui_menu_create(demo.mbar, "Help", &demo.mhelp); 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); 398 877 if (rc != EOK) { 399 878 printf("Error creating menu.\n"); … … 401 880 } 402 881 403 rc = ui_menu_entry_create(demo.mhelp, "About", "Ctrl-H, F1", &mabout); 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); 404 887 if (rc != EOK) { 405 888 printf("Error creating menu.\n"); … … 407 890 } 408 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 409 904 /* FIXME: Auto layout */ 410 905 if (ui_is_textmode(ui)) { 411 906 rect.p0.x = 1; 412 rect.p0.y = 2;413 rect.p1.x = 79;414 rect.p1.y = 3;907 rect.p0.y = 1; 908 rect.p1.x = 43; 909 rect.p1.y = 2; 415 910 } else { 416 911 rect.p0.x = 4; 417 912 rect.p0.y = 30; 418 rect.p1.x = 2 16;913 rect.p1.x = 251; 419 914 rect.p1.y = 52; 420 915 } 916 421 917 ui_menu_bar_set_rect(demo.mbar, &rect); 422 918 … … 427 923 } 428 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 429 970 rc = ui_entry_create(window, "", &demo.entry); 430 971 if (rc != EOK) { … … 435 976 /* FIXME: Auto layout */ 436 977 if (ui_is_textmode(ui)) { 437 rect.p0.x = 20;438 rect.p0.y = 4;439 rect.p1.x = 60;440 rect.p1.y = 5;978 rect.p0.x = 4; 979 rect.p0.y = 5; 980 rect.p1.x = 41; 981 rect.p1.y = 6; 441 982 } else { 442 983 rect.p0.x = 15; 443 rect.p0.y = 53;984 rect.p0.y = 88; 444 985 rect.p1.x = 205; 445 rect.p1.y = 78;986 rect.p1.y = 113; 446 987 } 447 988 … … 449 990 ui_entry_set_halign(demo.entry, gfx_halign_center); 450 991 451 rc = ui_fixed_add(demo. fixed, ui_entry_ctl(demo.entry));992 rc = ui_fixed_add(demo.bfixed, ui_entry_ctl(demo.entry)); 452 993 if (rc != EOK) { 453 994 printf("Error adding control to layout.\n"); … … 463 1004 /* FIXME: Auto layout */ 464 1005 if (ui_is_textmode(ui)) { 465 rect.p0.x = 20;466 rect.p0.y = 6;467 rect.p1.x = 60;468 rect.p1.y = 7;1006 rect.p0.x = 4; 1007 rect.p0.y = 7; 1008 rect.p1.x = 41; 1009 rect.p1.y = 8; 469 1010 } else { 470 1011 rect.p0.x = 60; 471 rect.p0.y = 88;1012 rect.p0.y = 123; 472 1013 rect.p1.x = 160; 473 rect.p1.y = 1 01;1014 rect.p1.y = 136; 474 1015 } 475 1016 … … 477 1018 ui_label_set_halign(demo.label, gfx_halign_center); 478 1019 479 rc = ui_fixed_add(demo. fixed, ui_label_ctl(demo.label));1020 rc = ui_fixed_add(demo.bfixed, ui_label_ctl(demo.label)); 480 1021 if (rc != EOK) { 481 1022 printf("Error adding control to layout.\n"); … … 493 1034 /* FIXME: Auto layout */ 494 1035 if (ui_is_textmode(ui)) { 495 rect.p0.x = 20;496 rect.p0.y = 8;497 rect.p1.x = 30;498 rect.p1.y = 9;1036 rect.p0.x = 4; 1037 rect.p0.y = 9; 1038 rect.p1.x = 15; 1039 rect.p1.y = 10; 499 1040 } else { 500 1041 rect.p0.x = 15; 501 rect.p0.y = 1 11;1042 rect.p0.y = 146; 502 1043 rect.p1.x = 105; 503 rect.p1.y = 1 39;1044 rect.p1.y = 174; 504 1045 } 505 1046 … … 508 1049 ui_pbutton_set_default(demo.pb1, true); 509 1050 510 rc = ui_fixed_add(demo. fixed, ui_pbutton_ctl(demo.pb1));1051 rc = ui_fixed_add(demo.bfixed, ui_pbutton_ctl(demo.pb1)); 511 1052 if (rc != EOK) { 512 1053 printf("Error adding control to layout.\n"); … … 523 1064 524 1065 if (ui_is_textmode(ui)) { 525 rect.p0.x = 50;526 rect.p0.y = 8;527 rect.p1.x = 60;528 rect.p1.y = 9;1066 rect.p0.x = 30; 1067 rect.p0.y = 9; 1068 rect.p1.x = 41; 1069 rect.p1.y = 10; 529 1070 } else { 530 1071 rect.p0.x = 115; 531 rect.p0.y = 1 11;1072 rect.p0.y = 146; 532 1073 rect.p1.x = 205; 533 rect.p1.y = 1 39;1074 rect.p1.y = 174; 534 1075 } 535 1076 536 1077 ui_pbutton_set_rect(demo.pb2, &rect); 537 1078 538 rc = ui_fixed_add(demo. fixed, ui_pbutton_ctl(demo.pb2));1079 rc = ui_fixed_add(demo.bfixed, ui_pbutton_ctl(demo.pb2)); 539 1080 if (rc != EOK) { 540 1081 printf("Error adding control to layout.\n"); … … 543 1084 544 1085 gfx_bitmap_params_init(&bparams); 545 bparams.rect.p0.x = 0; 546 bparams.rect.p0.y = 0; 547 bparams.rect.p1.x = 188; 548 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 } 549 1097 550 1098 rc = gfx_bitmap_create(gc, &bparams, NULL, &bitmap); … … 562 1110 } 563 1111 564 off.x = 15; 565 off.y = 155; 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 566 1120 gfx_rect_translate(&off, &bparams.rect, &rect); 567 1121 568 1122 /* Adjust for frame width (2 x 1 pixel) */ 569 rect.p1.x += 2; 570 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 571 1129 ui_image_set_rect(demo.image, &rect); 572 ui_image_set_flags(demo.image, ui_imgf_frame); 573 574 rc = ui_fixed_add(demo.fixed, ui_image_ctl(demo.image)); 1130 1131 rc = ui_fixed_add(demo.bfixed, ui_image_ctl(demo.image)); 575 1132 if (rc != EOK) { 576 1133 printf("Error adding control to layout.\n"); … … 578 1135 } 579 1136 580 rc = ui_checkbox_create(ui_res, " Check me", &demo.checkbox);1137 rc = ui_checkbox_create(ui_res, "Read only", &demo.checkbox); 581 1138 if (rc != EOK) { 582 1139 printf("Error creating check box.\n"); … … 586 1143 ui_checkbox_set_cb(demo.checkbox, &checkbox_cb, (void *) &demo); 587 1144 588 rect.p0.x = 15; 589 rect.p0.y = 190; 590 rect.p1.x = 140; 591 rect.p1.y = 210; 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 592 1158 ui_checkbox_set_rect(demo.checkbox, &rect); 593 1159 594 rc = ui_fixed_add(demo. fixed, ui_checkbox_ctl(demo.checkbox));1160 rc = ui_fixed_add(demo.bfixed, ui_checkbox_ctl(demo.checkbox)); 595 1161 if (rc != EOK) { 596 1162 printf("Error adding control to layout.\n"); … … 604 1170 } 605 1171 606 rc = ui_rbutton_create(demo.rbgroup, " Option 1", (void *) "First",607 &demo.rb 1);1172 rc = ui_rbutton_create(demo.rbgroup, "Left", (void *) &uidemo_halign[0], 1173 &demo.rbleft); 608 1174 if (rc != EOK) { 609 1175 printf("Error creating radio button.\n"); … … 614 1180 (void *) &demo); 615 1181 616 rect.p0.x = 15; 617 rect.p0.y = 220; 618 rect.p1.x = 140; 619 rect.p1.y = 240; 620 ui_rbutton_set_rect(demo.rb1, &rect); 621 622 rc = ui_fixed_add(demo.fixed, ui_rbutton_ctl(demo.rb1)); 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)); 623 1197 if (rc != EOK) { 624 1198 printf("Error adding control to layout.\n"); … … 626 1200 } 627 1201 628 rc = ui_rbutton_create(demo.rbgroup, " Option 2", (void *) "Second",629 &demo.rb 2);1202 rc = ui_rbutton_create(demo.rbgroup, "Center", (void *) &uidemo_halign[1], 1203 &demo.rbcenter); 630 1204 if (rc != EOK) { 631 1205 printf("Error creating radio button.\n"); … … 633 1207 } 634 1208 635 rect.p0.x = 15; 636 rect.p0.y = 250; 637 rect.p1.x = 140; 638 rect.p1.y = 270; 639 ui_rbutton_set_rect(demo.rb2, &rect); 640 641 rc = ui_fixed_add(demo.fixed, ui_rbutton_ctl(demo.rb2)); 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)); 642 1225 if (rc != EOK) { 643 1226 printf("Error adding control to layout.\n"); … … 645 1228 } 646 1229 647 rc = ui_rbutton_create(demo.rbgroup, " Option 3", (void *) "Third",648 &demo.rb 3);1230 rc = ui_rbutton_create(demo.rbgroup, "Right", (void *) &uidemo_halign[2], 1231 &demo.rbright); 649 1232 if (rc != EOK) { 650 1233 printf("Error creating radio button.\n"); … … 652 1235 } 653 1236 654 rect.p0.x = 15; 655 rect.p0.y = 280; 656 rect.p1.x = 140; 657 rect.p1.y = 300; 658 ui_rbutton_set_rect(demo.rb3, &rect); 659 660 rc = ui_fixed_add(demo.fixed, ui_rbutton_ctl(demo.rb3)); 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)); 661 1252 if (rc != EOK) { 662 1253 printf("Error adding control to layout.\n"); … … 664 1255 } 665 1256 666 rc = ui_slider_create(ui_res, "Slide!",&demo.slider);1257 rc = ui_slider_create(ui_res, &demo.slider); 667 1258 if (rc != EOK) { 668 1259 printf("Error creating button.\n"); … … 672 1263 ui_slider_set_cb(demo.slider, &slider_cb, (void *) &demo); 673 1264 674 rect.p0.x = 15; 675 rect.p0.y = 310; 676 rect.p1.x = 130; 677 rect.p1.y = 330; 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 678 1278 ui_slider_set_rect(demo.slider, &rect); 679 1279 680 rc = ui_fixed_add(demo. fixed, ui_slider_ctl(demo.slider));1280 rc = ui_fixed_add(demo.bfixed, ui_slider_ctl(demo.slider)); 681 1281 if (rc != EOK) { 682 1282 printf("Error adding control to layout.\n"); 683 1283 return rc; 684 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)); 685 1430 686 1431 ui_window_add(window, ui_fixed_ctl(demo.fixed)); … … 728 1473 k = i * i + j * j; 729 1474 pixelmap_put_pixel(&pixelmap, i, j, 730 PIXEL( 255, k, k, 255 - k));1475 PIXEL(0, k, k, 255 - k)); 731 1476 } 732 1477 } … … 742 1487 int main(int argc, char *argv[]) 743 1488 { 744 const char *display_spec = UI_ DISPLAY_DEFAULT;1489 const char *display_spec = UI_ANY_DEFAULT; 745 1490 errno_t rc; 746 1491 int i;
Note:
See TracChangeset
for help on using the changeset viewer.