Buttons
\c{
Buttons come in a number of varieties,
such as ordinary (push) buttons, that simply invoke
an action, checkbuttons, that toggle between
an on and off state, and radiobuttons, that
may be used to constrain buttons to
allow the selection of only a single alternative.
}
\sly{test-}{
Button1
-- with a bitmap
\epsfbox{button-1.eps}
The example shows a button with a bitmap.
}
\c{
Checkbuttons and radiobuttons are implemented as
subclasses of the class button, and will not
be further discussed here.
}
\sli{
interface button : widget { \fbox{button}
button(char* p, char* options = "");
button(widget* w, char* p, char* options = "");
void text(char* s); to display text
void bitmap(char* s); to display a bitmap
void state(char *s); to change the buttons state
void flash();
char* invoke();
protected:
install(action&,char* args);
};
}
\c{
In addition to the constructors, which have the same
format for each widget class,
the button class offers the function text
to define the text displayed by the button and the
function bitmap, which takes as argument
the name of a file containing a bitmap,
to have a bitmap displayed instead.
The function state may be used to change the state of the button.
Legal arguments are either normal, active or disabled.
Further, the button class defines the function
flash and invoke that
result respectively in flashing the button and in invoking
the action associated with the button by means of
the function.
(Note that is defined, albeit protected.)
}
\c{
Example
As an example of the definition and use of a button
look at the following program fragment.
}
\sli{
Example
void program( kit* tk, int, char** ) {
tk->trace();
button* b1 = new button(".b1");
b1->text("ok");
b1->handler(browse,b1,"first button");
button* b2 = new button(".b2","-bg blue");
b2->bitmap("bitmaps/queen.bm");
b2->handler(browse,b2,"second button");
tk->pack(b1)->pack(b2);
tk->pack(".quit");
}
}
\c{
Two buttons are created.
The first button displays some text and the second
a bitmap.
The second button is given a colored background
by using the options argument of the constructor.
For both buttons, the function browse
is installed as the (default) handler,
with as client the appropriate pointer.
See slide slide [button-display].
}
\sli{
Button
-- with a bitmap
\hspace*{1cm}
\epsfbox{button-1.eps}
The example shows a button with a bitmap.
}
\c{
For each button, arguments
are defined that will be given to
browse when invoking the action.
Both buttons are subsequently appended to the root.
In addition, a third (system-defined) button
is appended to the root.
This button has been defined in Tk as
button .quit -text quit -command { destroy . }
which results in a button {\em .quit} that, when pressed,
destroys the toplevel root window of the application
and all its subordinate windows.
}