scroll the extended command menu if necessary so that choices extended_cmd_selected through ec_indx will be visible */
| 1687 | /* scroll the extended command menu if necessary |
| 1688 | so that choices extended_cmd_selected through ec_indx will be visible */ |
| 1689 | static void |
| 1690 | ec_scroll_to_view(int ec_indx) /* might be greater than extended_cmd_selected */ |
| 1691 | { |
| 1692 | Widget viewport, scrollbar, tmpw; |
| 1693 | Arg args[5]; |
| 1694 | Cardinal num_args; |
| 1695 | Position lo_y, hi_y; /* ext cmd label y */ |
| 1696 | float s_shown, s_top; /* scrollbar pos */ |
| 1697 | float s_min, s_max; |
| 1698 | Dimension h, hh, wh, vh; /* widget and viewport heights */ |
| 1699 | Dimension border_width; |
| 1700 | int distance = 0; |
| 1701 | boolean force_top = (ec_indx < 0); |
| 1702 | |
| 1703 | /* |
| 1704 | * If the extended command menu needs to be scrolled in order to move |
| 1705 | * either the highlighted entry (extended_cmd_selected) or the target |
| 1706 | * entry (ec_indx) into view, we want to make both end up visible. |
| 1707 | * [Highlighted one is the first matching entry when the user types |
| 1708 | * something, such as "adjust" after typing 'a', and will be chosen |
| 1709 | * by pressing <return>. Target entry is one past the last matching |
| 1710 | * entry (or last matching entry itself if at end of command list), |
| 1711 | * showing the user the other potential matches so far.] |
| 1712 | * |
| 1713 | * If that's not possible (maybe menu has been resized so that it's |
| 1714 | * too small), the highlighted entry takes precedence and the target |
| 1715 | * will be decremented until close enough to fit. |
| 1716 | */ |
| 1717 | |
| 1718 | if (force_top) |
| 1719 | ec_indx = 0; |
| 1720 | |
| 1721 | /* get viewport and scrollbar widgets */ |
| 1722 | tmpw = extended_commands[ec_indx]; |
| 1723 | viewport = XtParent(tmpw); |
| 1724 | do { |
| 1725 | scrollbar = XtNameToWidget(tmpw, "*vertical"); |
| 1726 | if (scrollbar) |
| 1727 | break; |
| 1728 | tmpw = XtParent(tmpw); |
| 1729 | } while (tmpw); |
| 1730 | |
| 1731 | if (scrollbar && viewport) { |
| 1732 | /* get selected ext command label y position and height */ |
| 1733 | num_args = 0; |
| 1734 | XtSetArg(args[num_args], XtNy, &hi_y); num_args++; |
| 1735 | XtSetArg(args[num_args], XtNheight, &h); num_args++; |
| 1736 | XtSetArg(args[num_args], nhStr(XtNborderWidth), &border_width); |
| 1737 | num_args++; |
| 1738 | XtSetArg(args[num_args], nhStr(XtNdefaultDistance), &distance); |
| 1739 | num_args++; |
| 1740 | XtGetValues(extended_commands[ec_indx], args, num_args); |
| 1741 | if (distance < 1 || distance > 32766) /* defaultDistance is weird */ |
| 1742 | distance = 4; |
| 1743 | /* vertical distance between top of one command widget and the next */ |
| 1744 | hh = h + distance + 2 * border_width; |
| 1745 | /* location of the highlighted entry, if any */ |
| 1746 | if (extended_cmd_selected >= 0) { |
no outgoing calls
no test coverage detected