formbox.c (224014) | formbox.c (241818) |
---|---|
1/* | 1/* |
2 * $Id: formbox.c,v 1.73 2011/06/29 09:48:08 tom Exp $ | 2 * $Id: formbox.c,v 1.81 2012/07/01 18:13:51 Zoltan.Kelemen Exp $ |
3 * 4 * formbox.c -- implements the form (i.e, some pairs label/editbox) 5 * | 3 * 4 * formbox.c -- implements the form (i.e, some pairs label/editbox) 5 * |
6 * Copyright 2003-2010,2011 Thomas E. Dickey | 6 * Copyright 2003-2011,2012 Thomas E. Dickey |
7 * 8 * This program is free software; you can redistribute it and/or modify 9 * it under the terms of the GNU Lesser General Public License, version 2.1 10 * as published by the Free Software Foundation. 11 * 12 * This program is distributed in the hope that it will be useful, but 13 * WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU --- 168 unchanged lines hidden (view full) --- 183 if (limit < item[n].name_y) 184 limit = item[n].name_y; 185 if (limit < item[n].text_y) 186 limit = item[n].text_y; 187 } 188 return limit; 189} 190 | 7 * 8 * This program is free software; you can redistribute it and/or modify 9 * it under the terms of the GNU Lesser General Public License, version 2.1 10 * as published by the Free Software Foundation. 11 * 12 * This program is distributed in the hope that it will be useful, but 13 * WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU --- 168 unchanged lines hidden (view full) --- 183 if (limit < item[n].name_y) 184 limit = item[n].name_y; 185 if (limit < item[n].text_y) 186 limit = item[n].text_y; 187 } 188 return limit; 189} 190 |
191static int 192is_first_field(DIALOG_FORMITEM item[], int choice) 193{ 194 int count = 0; 195 while (choice >= 0) { 196 if (item[choice].text_flen > 0) { 197 ++count; 198 } 199 --choice; 200 } 201 202 return (count == 1); 203} 204 205static int 206is_last_field(DIALOG_FORMITEM item[], int choice, int item_no) 207{ 208 int count = 0; 209 while (choice < item_no) { 210 if (item[choice].text_flen > 0) { 211 ++count; 212 } 213 ++choice; 214 } 215 216 return (count == 1); 217} 218 |
|
191/* 192 * Tab to the next field. 193 */ 194static bool 195tab_next(WINDOW *win, 196 DIALOG_FORMITEM item[], 197 int item_no, 198 int stepsize, --- 250 unchanged lines hidden (view full) --- 449 450#ifdef KEY_RESIZE 451 int old_height = height; 452 int old_width = width; 453#endif 454 455 int form_width; 456 int first = TRUE; | 219/* 220 * Tab to the next field. 221 */ 222static bool 223tab_next(WINDOW *win, 224 DIALOG_FORMITEM item[], 225 int item_no, 226 int stepsize, --- 250 unchanged lines hidden (view full) --- 477 478#ifdef KEY_RESIZE 479 int old_height = height; 480 int old_width = width; 481#endif 482 483 int form_width; 484 int first = TRUE; |
485 int first_trace = TRUE; |
|
457 int chr_offset = 0; | 486 int chr_offset = 0; |
458 int state = dialog_vars.defaultno ? dlg_defaultno_button() : sTEXT; | 487 int state = dialog_vars.default_button >=0 ? dlg_default_button() : sTEXT; |
459 int x, y, cur_x, cur_y, box_x, box_y; 460 int code; 461 int key = 0; 462 int fkey; 463 int choice = dlg_default_formitem(items); 464 int new_choice, new_scroll; 465 int scrollamt = 0; 466 int result = DLG_EXIT_UNKNOWN; --- 38 unchanged lines hidden (view full) --- 505 dlg_print_size(height, width); 506 dlg_ctl_size(height, width); 507 508 x = dlg_box_x_ordinate(width); 509 y = dlg_box_y_ordinate(height); 510 511 dialog = dlg_new_window(height, width, y, x); 512 dlg_register_window(dialog, "formbox", binding); | 488 int x, y, cur_x, cur_y, box_x, box_y; 489 int code; 490 int key = 0; 491 int fkey; 492 int choice = dlg_default_formitem(items); 493 int new_choice, new_scroll; 494 int scrollamt = 0; 495 int result = DLG_EXIT_UNKNOWN; --- 38 unchanged lines hidden (view full) --- 534 dlg_print_size(height, width); 535 dlg_ctl_size(height, width); 536 537 x = dlg_box_x_ordinate(width); 538 y = dlg_box_y_ordinate(height); 539 540 dialog = dlg_new_window(height, width, y, x); 541 dlg_register_window(dialog, "formbox", binding); |
513 dlg_register_window(dialog, "formfield", binding2); | |
514 dlg_register_buttons(dialog, "formbox", buttons); 515 516 dlg_mouse_setbase(x, y); 517 | 542 dlg_register_buttons(dialog, "formbox", buttons); 543 544 dlg_mouse_setbase(x, y); 545 |
518 dlg_draw_box(dialog, 0, 0, height, width, dialog_attr, border_attr); 519 dlg_draw_bottom_box(dialog); | 546 dlg_draw_box2(dialog, 0, 0, height, width, dialog_attr, border_attr, border2_attr); 547 dlg_draw_bottom_box2(dialog, border_attr, border2_attr, dialog_attr); |
520 dlg_draw_title(dialog, title); 521 | 548 dlg_draw_title(dialog, title); 549 |
522 wattrset(dialog, dialog_attr); | 550 (void) wattrset(dialog, dialog_attr); |
523 dlg_print_autowrap(dialog, prompt, height, width); 524 525 form_width = width - 6; 526 getyx(dialog, cur_y, cur_x); | 551 dlg_print_autowrap(dialog, prompt, height, width); 552 553 form_width = width - 6; 554 getyx(dialog, cur_y, cur_x); |
555 (void) cur_x; |
|
527 box_y = cur_y + 1; 528 box_x = (width - form_width) / 2 - 1; 529 530 /* create new window for the form */ 531 form = dlg_sub_window(dialog, form_height, form_width, y + box_y + 1, 532 x + box_x + 1); | 556 box_y = cur_y + 1; 557 box_x = (width - form_width) / 2 - 1; 558 559 /* create new window for the form */ 560 form = dlg_sub_window(dialog, form_height, form_width, y + box_y + 1, 561 x + box_x + 1); |
562 dlg_register_window(form, "formfield", binding2); |
|
533 534 /* draw a box around the form items */ 535 dlg_draw_box(dialog, box_y, box_x, form_height + 2, form_width + 2, | 563 564 /* draw a box around the form items */ 565 dlg_draw_box(dialog, box_y, box_x, form_height + 2, form_width + 2, |
536 menubox_border_attr, menubox_attr); | 566 menubox_border_attr, menubox_border2_attr); |
537 538 /* register the new window, along with its borders */ 539 dlg_mouse_mkbigregion(getbegy(form) - getbegy(dialog), 540 getbegx(form) - getbegx(dialog), 541 getmaxy(form), 542 getmaxx(form), 543 KEY_MAX, 1, 1, 3 /* by cells */ ); 544 --- 14 unchanged lines hidden (view full) --- 559 scrollamt, 560 scrollamt, 561 scrollamt + form_height + 1, 562 min_height, 563 box_x + 1, 564 box_x + form_width, 565 box_y, 566 box_y + form_height + 1, | 567 568 /* register the new window, along with its borders */ 569 dlg_mouse_mkbigregion(getbegy(form) - getbegy(dialog), 570 getbegx(form) - getbegx(dialog), 571 getmaxy(form), 572 getmaxx(form), 573 KEY_MAX, 1, 1, 3 /* by cells */ ); 574 --- 14 unchanged lines hidden (view full) --- 589 scrollamt, 590 scrollamt, 591 scrollamt + form_height + 1, 592 min_height, 593 box_x + 1, 594 box_x + form_width, 595 box_y, 596 box_y + form_height + 1, |
567 menubox_attr, | 597 menubox_border2_attr, |
568 menubox_border_attr); 569 scroll_changed = FALSE; 570 } 571 572 if (show_buttons) { 573 dlg_item_help(""); 574 dlg_draw_buttons(dialog, height - 2, 0, buttons, 575 ((state < 0) 576 ? 1000 /* no such button, not highlighted */ 577 : state), 578 FALSE, width); 579 show_buttons = FALSE; 580 } 581 | 598 menubox_border_attr); 599 scroll_changed = FALSE; 600 } 601 602 if (show_buttons) { 603 dlg_item_help(""); 604 dlg_draw_buttons(dialog, height - 2, 0, buttons, 605 ((state < 0) 606 ? 1000 /* no such button, not highlighted */ 607 : state), 608 FALSE, width); 609 show_buttons = FALSE; 610 } 611 |
612 if (first_trace) { 613 first_trace = FALSE; 614 dlg_trace_win(dialog); 615 } 616 |
|
582 if (field_changed || state == sTEXT) { 583 if (field_changed) 584 chr_offset = 0; 585 current = &items[choice]; 586 dialog_vars.max_input = current->text_ilen; 587 dlg_item_help(current->help); 588 dlg_show_string(form, current->text, chr_offset, 589 form_active_text_attr, 590 current->text_y - scrollamt, 591 current->text_x, 592 current->text_len, 593 is_hidden(current), first); 594 field_changed = FALSE; 595 } 596 | 617 if (field_changed || state == sTEXT) { 618 if (field_changed) 619 chr_offset = 0; 620 current = &items[choice]; 621 dialog_vars.max_input = current->text_ilen; 622 dlg_item_help(current->help); 623 dlg_show_string(form, current->text, chr_offset, 624 form_active_text_attr, 625 current->text_y - scrollamt, 626 current->text_x, 627 current->text_len, 628 is_hidden(current), first); 629 field_changed = FALSE; 630 } 631 |
597 key = dlg_mouse_wgetch(dialog, &fkey); | 632 key = dlg_mouse_wgetch((state == sTEXT) ? form : dialog, &fkey); |
598 if (dlg_result_key(key, fkey, &result)) 599 break; 600 601 /* handle non-functionkeys */ 602 if (!fkey) { 603 if (state != sTEXT) { 604 code = dlg_char_to_button(key, buttons); 605 if (code >= 0) { --- 42 unchanged lines hidden (view full) --- 648 move_by = -1; 649 break; 650 } else { 651 state = prev_valid_buttonindex(state, 0, non_editable); 652 show_buttons = TRUE; 653 continue; 654 } 655 | 633 if (dlg_result_key(key, fkey, &result)) 634 break; 635 636 /* handle non-functionkeys */ 637 if (!fkey) { 638 if (state != sTEXT) { 639 code = dlg_char_to_button(key, buttons); 640 if (code >= 0) { --- 42 unchanged lines hidden (view full) --- 683 move_by = -1; 684 break; 685 } else { 686 state = prev_valid_buttonindex(state, 0, non_editable); 687 show_buttons = TRUE; 688 continue; 689 } 690 |
691 case DLGK_FORM_PREV: 692 if (state == sTEXT && !is_first_field(items, choice)) { 693 do_tab = TRUE; 694 move_by = -1; 695 break; 696 } else { 697 int old_state = state; 698 state = prev_valid_buttonindex(state, sTEXT, non_editable); 699 show_buttons = TRUE; 700 if (old_state >= 0 && state == sTEXT) { 701 new_choice = item_no - 1; 702 if (choice != new_choice) { 703 print_item(form, items + choice, scrollamt, FALSE); 704 choice = new_choice; 705 } 706 } 707 continue; 708 } 709 |
|
656 case DLGK_FIELD_PREV: 657 state = prev_valid_buttonindex(state, sTEXT, non_editable); 658 show_buttons = TRUE; 659 continue; 660 661 case DLGK_FIELD_NEXT: 662 state = next_valid_buttonindex(state, sTEXT, non_editable); 663 show_buttons = TRUE; --- 10 unchanged lines hidden (view full) --- 674 move_by = 1; 675 break; 676 } else { 677 state = next_valid_buttonindex(state, 0, non_editable); 678 show_buttons = TRUE; 679 continue; 680 } 681 | 710 case DLGK_FIELD_PREV: 711 state = prev_valid_buttonindex(state, sTEXT, non_editable); 712 show_buttons = TRUE; 713 continue; 714 715 case DLGK_FIELD_NEXT: 716 state = next_valid_buttonindex(state, sTEXT, non_editable); 717 show_buttons = TRUE; --- 10 unchanged lines hidden (view full) --- 728 move_by = 1; 729 break; 730 } else { 731 state = next_valid_buttonindex(state, 0, non_editable); 732 show_buttons = TRUE; 733 continue; 734 } 735 |
736 case DLGK_FORM_NEXT: 737 if (state == sTEXT && !is_last_field(items, choice, item_no)) { 738 do_tab = TRUE; 739 move_by = 1; 740 break; 741 } else { 742 state = next_valid_buttonindex(state, sTEXT, non_editable); 743 show_buttons = TRUE; 744 if (state == sTEXT && choice) { 745 print_item(form, items + choice, scrollamt, FALSE); 746 choice = 0; 747 } 748 continue; 749 } 750 |
|
682#ifdef KEY_RESIZE 683 case KEY_RESIZE: 684 /* reset data */ 685 height = old_height; 686 width = old_width; 687 /* repaint */ 688 dlg_clear(); 689 dlg_del_window(dialog); --- 215 unchanged lines hidden --- | 751#ifdef KEY_RESIZE 752 case KEY_RESIZE: 753 /* reset data */ 754 height = old_height; 755 width = old_width; 756 /* repaint */ 757 dlg_clear(); 758 dlg_del_window(dialog); --- 215 unchanged lines hidden --- |