<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">\documentstyle[11pt,twoside,manpage]{report}
\begin{document}
\pagestyle{headings}
 
\begin{manpage}{OIM C++ Library}{Choice}{Version 1.0}
 
\subtitle{Name}
    Choice --- a set of boxes representing the choices available. 
 
\subtitle{Declaration}
    \#include \&lt;choice.h\&gt;
 
\function{Choice(Point origin, Point corner,
		int foreground_color, int background_color,
		int frame_style, int space_in_between,
                int number_of_choices,
                const~char\* first_label, $...$)}
    Constructs a choice object.  Each choice object is a set of boxes
    representing the choices available.  "Origin" and "corner" define the
    rectangular area inside which the boxes are displayed. 
    The "space_in_between" (in pixels)
    defines the distance between two adjacent boxes.  Depending on 
    whether there is enough room to put all the choices horizontally
    or vertically in the designated area,
    the choices will be laid out accordingly.  The
    attributes "foreground_color", "background_color" and "frame_style"
    define the colors for each box that represents each choice.
    The number of labels starting with "first_label" must match the
    number given by "number_of_choices".  Each label is displayed within
    its corresponding box.  The choices are displayed 
    as soon as they are created.
 
\function{Choice(int number_of_choices, Boolean is_horizontal = VIRTICAL)}
    Constructs an array of choices or 
    a choice object with boxes of different sizes.  The attributes
    of the actual choices will be defined later using the
    addItem() operation. Note: It is forbidden to have arguments
    in the constructors of array objects in C++. 
 
\subtitle{Description}
    A Choice object is a set of related boxes. It is used to display
    multiple choices on the screen. 
    A choice may either be selected by pressing a hot key
    (when mouse is not enabled) or by pressing a mouse button when the mouse
    cursor is within the intended choice box.  
    The first highlighted character in the text label will be the 
    hot key if the mouse is not enabled, otherwise, the highlighted
    character will have no effect. For example, label "@N@ext" designates
    "N" as the hot key for the button if the mouse is not enabled.
    By default, if the mouse driver is loaded before program execution,
    the mouse is enabled.
    When using the mouse to select
    a choice, the selection is immediate; a hot key must be confirmed
    by pressing ENTER (carriage return key).  Arrow keys can also be used
    to move the current selection in the direction indicated by the arrows,
    this also requires an ENTER to confirm.
 
\subtitle{Public \\ Operations}
 
\function{void addItem(Point origin, Point corner,
		 int foreground_color, int background_color,
		 int frame_style, const~char\* label,
		 int text_color = WHITE,
		 int text_highlight_color = LIGHT_WHITE)}
    Defines the attributes of a choice box in the array declared by the
    Choice(int "number_of_choices", Boolean "is_horizontal" = VIRTICAL) 
    constructor. 
    It must be called exactly "number_of_choices"
    times.  The first call specifies the first choice, second call specifies
    the second choice, and so on.  The attributes "origin" and "corner"
    define a box area where the choice item is located on the screen.  Other
    attributes are self-explanatory.  This call is particularly useful
    on program setup pages.
 
\function{void disable(int index)}
    Disables a choice box designated by "index". This means that the choice
    can still be seen on the screen but can not be selected any more.
    The hot key for the choice is rendered as in the normal text color rather
    than in the highlight color.  This call is often useful on a setup page,
    where it is often necessary to have a few choices contingent upon 
    others, i.e., they are disabled first until the choices that they 
    depend upon have been initialized and then they are enabled again.
 
\function{void enable(int index)}
    Enables a choice box designated by "index".
    All choices are enabled when created.
    
\function{Boolean hasValue()}
    Returns TRUE if the designated choice object has been selected at
    least once.  Graphically,
    it means one of the choices is rendered in reverse colors.  It is
    sometimes necessary to check if all choice objects on a screen have
    been selected, so that a program can go on to the next page of screen.
    If a previous select() call is returned abnormally by pressing an ESC key,
    this function will return FALSE. Should this occur, the previous 
    value, if any, will also be lost.
 
\function{int selectNext()}
    Steps through each choice of the choice object in sequential order.
    This function is often used in implementing parameter 
    initialization screens in a controlled order. The order that the 
    choices are steped through is the same as the order of the choice
    array.  This is operator is valid only for keyboard mode. If the
    mouse is enabled, it behaves exactly as select().
 
\function{void setCurrent(int index)}
    Resets the current (default) choice to the choice box indicated by
    "index".  The default choice is
    set to the first choice box ("index" $=$ 0) when a choice object is created,
    or the choice selected last time.  This call can
    change the default choice without having to select anything first.  It will
    affect the behavior of a selectNext() call.
 
\function{void reset()}
    Erases the default choice and resets the internal pointers as if this
    choice object had never been selected before.
 
\subtitle{Virtual \\ Operations}
 
\function{void action(int status)}
    Defines the behaviors of the choice object when a choice handler
    has been bonded to the object.  This function is called by the
    event handler when it detects that the choice object has been
    selected.  The default action is to do nothing if no choice handler
    presents, otherwise, it invokes the choice handler 
    and passes it along with the current status 
    (whatever has been returned from a status() call).  
    Do not modify this function unless it is absolutely necessary because
    it redefines the sematics of all choice objects.
 
\function{void bind(void \hbox{\rm (\*{\it handler})(int)})}
    Associates a choice handler function with the choice object.  Every
    time this choice object is invoked, the choice handler is called
    immediately.  
    The handler is passed along with the current "status"
    (return value of status() call) as its argument. The default 
    action taken by the event handler can be modified by changing
    the next function action().
 
\function{Boolean isSelected(Point cursor)}
    Returns TRUE if a legal hot key is pressed for the
    the indicated choice object. It also returns TRUE if 
    a mouse button is pressed within the range of the choice object area.
    This call is used by the event handler to check if this choice object
    has been selected.  It is hardly needed in regular applications.
    The "cursor" is for mouse cursor in mouse mode or faked with the
    current keyboard input as the cursor's x coordinate.
 
\function{int select()}
    Picks a choice from the choice object.  If the mouse is not enabled,
    the default choice (the one picked last time or the first one if
    this is the first time this function is called) is displayed in
    highlight colors. The arrow key can be used to move the 
    default choice. The ENTER key must be used to confirm the selection.  
    If the mouse is enabled,
    this call checks if a mouse button has been pressed while the mouse
    cursor is inside one of the choice boxes. The return value is the index 
    of the choice box selected. 
    A ESC key may be pressed
    to leave the current select() call without actually selecting anything.
    In this case, $-1$ will be returned.  
    Note: With no mouse enabled,
    select() waits for either an Enter key or ESC key to return,  whereas
    with the mouse enabled, the return is immediate.
 
\function{int status()}
    Returns the current choice index (the one in reverse color on the screen).
    If there is no current choice (either it has not been selected or has
    been reset) the return value is $-1$.
 
\subtitle{See Also}
     Event, Button, Box
 
\subtitle{Author}
    Ron Chen at the Office for Information Management, UIUC. 9-1-89.
 
\end{manpage}
\newpage
\begin{verbatim}
    /* EXAMPLE 1 */
    #include &lt;stdlib.h&gt;
    #include "choice.h"
 
    void handler1(int choice) {
        Box box(500, 30, 600, 60, LIGHT_CYAN, LIGHT_MAGENTA);
        box &lt;&lt; choice + 1;
    }
 
    void handler2(int choice) {
        Box box(500, 30, 600, 60, LIGHT_CYAN, LIGHT_MAGENTA);
        box &lt;&lt; (choice==0 ? "Ape" : (choice==1 ? "Bob" : "Car"));
    }
 
    void handler3(int choice) {
        Box box(500, 30, 600, 60, LIGHT_CYAN, LIGHT_MAGENTA);
        switch (choice) {
            case 0: box &lt;&lt; "D"; break; case 1: box &lt;&lt; "E"; break;
            case 2: box &lt;&lt; "F"; break; case 3: box &lt;&lt; "G"; break;
            case 4: exit(0);
        }
    }
 
    main() {
        Point a(100, 100), b(220, 130);
        Choice c1(a,b,BROWN,RED,ON_BORDER,0,4,"@1@","@2@","@3@","@4@");
 
        a = Point(200, 200); b = Point(400, 230);
        Choice c2(a,b,WHITE,BLUE,IN_BORDER,10,3,"@A@pe","@B@ob","@C@ar");
 
        a = Point(500, 230); b = Point(550, 330);
        Choice c3(a,b,GREEN,GRAY,NO_BORDER,10,5,"@D@","@E@","@F@","@G@","@H@");
 
        for (int pick;;) {
            if ((pick = c1.select()) != -1) handler1(pick);
            if ((pick = c2.select()) != -1) handler2(pick);
            if ((pick = c3.select()) != -1) handler3(pick);
        }
    }
\end{verbatim}
\newpage
\begin{verbatim}
    /* EXAMPLE 2 */
    #include &lt;stdlib.h&gt;
    #include "choice.h"
 
    void handler1(int pick) {
        Box box(500, 30, 600, 60, LIGHT_CYAN, LIGHT_MAGENTA);
        box &lt;&lt; pick + 1;
    }
 
    void handler2(int pick) {
        Box box(500, 30, 600, 60, LIGHT_CYAN, LIGHT_MAGENTA);
        box &lt;&lt; (pick==0 ? "Ape" : (pick==1 ? "Bob" : "Car"));
    }
 
    void handler3(int pick) {
        Box box(500, 30, 600, 60, LIGHT_CYAN, LIGHT_MAGENTA);
        switch (pick) {
            case 0: box &lt;&lt; "D"; break; case 1: box &lt;&lt; "E"; break;
            case 2: box &lt;&lt; "F"; break; case 3: box &lt;&lt; "G"; break;
            case 4: exit(0);
        }
    }
 
    main() {
        Point a(100, 100), b(220, 130);
        Choice c1(a,b,BROWN,RED,ON_BORDER,0,4,"@1@","@2@","@3@","@4@");
        Choice c2(3, HORIZONTAL);
        c2.addItem(Point(200, 200), Point(260,230),
                   WHITE, BLUE, IN_BORDER, "@A@pe");
        c2.addItem(Point(270, 200), Point(330,230),
                   WHITE, BLUE, IN_BORDER, "@B@ob");
        c2.addItem(Point(340, 200), Point(400,230),
                   WHITE, BLUE, IN_BORDER, "@C@ar");
        a = Point(500, 230); b = Point(550, 330);
        Choice c3(a,b,GREEN,GRAY,NO_BORDER,10,5,"@D@","@E@","@F@","@G@","@H@");
 
        c1.bind(handler1);
        c2.bind(handler2);
        c3.bind(handler3);
        Event::waitForEvents();
    }
\end{verbatim}
\end{document}
</pre></body></html>