Next: Button Attributes, Previous: Button Interaction, Up: Part III Button-like Objects [Contents][Index]
The application program can also set a button to be pushed or not itself without a user action. To this end use the routine
void fl_set_button(FL_OBJECT *obj, int pushed);
pushed
indicates whether the button should be set to be pushed
(1) or released (0). When setting a FL_RADIO_BUTTON
to be
pushed this automatically releases the currently pushed radio button
in the same form (or group). Also note that this routine only
simulates the visual appearance but does not affect the program flow
in any way, i.e., setting a button as being pushed does not invoke
its callback or results in the button becoming returned to the
program. For that follow up the call of fl_set_button()
with a call of fl_trigger_object()
(or
fl_call_object_callback()
).
To figure out whether a button is pushed or not use12
int fl_get_button(FL_OBJECT *obj);
Sometimes you want to give the button a different meaning depending on which mouse button gets pressed on it. To find out which mouse button was used at the last push (or release) use the routine
int fl_get_button_numb(FL_OBJECT *obj);
It returns one of the constants FL_LEFT_MOUSE
,
FL_MIDDLE_MOUSE
, FL_RIGHT_MOUSE
,
FL_SCROLLUP_MOUSE
or FL_SCROLLDOWN_MOUSE
(the latter two are from the scroll wheel of the mouse). If the last
push was triggered by a shortcut (see below), the function returns the
keysym
(ASCII value if the key used is between 0 and 127)
of the key plus
FL_SHORTCUT
. For example, if a button has <Ctrl>-C
as its shortcut the button number returned upon activation of the
shortcut will be FL_SHORTCUT + 3
(the ASCII value of
<Ctrl>-C
is 3).
It can also be controlled which mouse buttons a buttons reacts to (per default a button reacts to all mouse buttons, including the scroll wheel). To set which mouse buttons the button reacts to use
void fl_set_button_mouse_buttons(FL_OBJECT *obj, int mbuttons);
mbuttons
is the bitwise OR of the numbers 1 for the left
mouse button, 2 for the middle, 4 for the right mouse button, 8 for
moving the scroll wheel up "button" and 16 for scrolling down
"button". Per default a button reacts to all mouse buttons.
To determine which mouse buttons a button is reacting to use
void fl_get_button_mouse_buttons(FL_OBJECT *obj, unsigned int *mbuttons);
The value returned via mbuttons
is the same value as would
be used in fl_set_button_mouse_buttons()
.
In a number of situations it is useful to define a keyboard equivalent
for a button. You might e.g., want to define that <Ctrl>Q
has
the same meaning as pressing the "Quit" button. This can be achieved
using the following call:
void fl_set_button_shortcut(FL_OBJECT *obj, const char *str, int showUL);
Note that str
is a string, not a single character. This string
is a list of all the characters to become keyboard shortcuts for the
button. E.g., if you use string "^QQq" the button will react on the
keys q
, Q
and <Ctrl>Q
. (As you see you can use
the symbol ^
to indicate the control key. Similarly you can use
the symbol #
to indicate the <Alt>
key.) Be careful with
your choices. When the form also contains input fields you probably
don’t want to use the normal printable characters because they can no
longer be used for input in the input fields. Shortcuts are always
evaluated before input fields. Other special keys, such as <F1>
etc., can also be used as shortcuts. See Shortcuts, for details.
Finally, keep in mind that a button of type FL_RETURN_BUTTON
is
in fact nothing more than a normal button, just with the
<Return>
key set as the shortcut. So don’t change the shortcuts
for such a button.
If the third parameter showUL
is true and one of the letters in
the object label matches the shortcut the matching letter will be
underlined. This applies to non-printable characters (such as
#A
) as well in the sense that if the label contains the letter
a
or A
it will be underlined (i.e., special characters
such as #
and ^
are ignored when matching). A false
value (0) for showUL
turns off underlining without affecting
the shortcut. Note that although the entire object label is searched
for matching character to underline of the shortcut string itself only
the first (non-special) character is considered, thus a shortcut
string of "Yy"
for the label "Yes"
will result in the
letter Y
becoming underlined while for "yY"
it won’t.
To set the bitmap to use for a bitmap button the following functions can be used:
void fl_set_bitmapbutton_data(FL_OBJECT *obj, int w, int h, unsigned char *bits); void fl_set_bitmapbutton_file(FL_OBJECT *obj, const char *filename);
Similarly, to set the pixmap to use for a pixmap button the following routines can be used:
void fl_set_pixmapbutton_data(FL_OBJECT *obj, unsigned char **bits); void fl_set_pixmapbutton_file(FL_OBJECT *obj, const char *file); void fl_set_pixmapbutton_pixmap(FL_OBJECT *obj, Pixmap id, Pixmap mask);
To use the first routine, you #include
the pixmap file into
your source code and use the pixmap definition data (an array of char
pointers) directly. For the second routine the filename file
that contains the pixmap definition is used to specify the pixmap. The
last routine assumes that you already have a X Pixmap resource ID for
the pixmap you want to use. Note that these routines do not free a
pixmap already associated with the button. To free the pixmaps use
the function
void fl_free_pixmapbutton_pixmap(FL_OBJECT *obj);
This function frees the pixmap and mask together with all the colors allocated for them.
To get the pixmap and mask that is currently being displayed, use the following routine
Pixmap fl_get_pixmapbutton_pixmap(FL_OBJECT *obj, Pixmap &pixmap, Pixmap &mask);
Pixmaps are by default displayed centered inside the bounding box. However, this can be changed using the following routine
void fl_set_pixmapbutton_align(FL_OBJECT *obj, int align, int xmargin, int ymargin);
where align
is the same as that used for labels. See Label Attributes and Fonts, for a list. xmargin
and ymargin
are extra margins to leave in addition to the object border width.
Note that although you can place a pixmap outside of the bounding box,
it probably is not a good idea.
When the mouse enters a pixmap button an outline of the button is shown. If required, a different pixmap (the focus pixmap) can also be shown. To set such a focus pixmap the following functions are available:
void fl_set_pixmapbutton_focus_data(FL_OBJECT *obj, unsigned char **bits); void fl_set_pixmapbutton_focus_file(FL_OBJECT *obj, const char *file); void fl_set_pixmapbutton_focus_pixmap(FL_OBJECT *obj, Pixmap id, Pixmap mask);
The meanings of the parameters are the same as that in the regular pixmap routines.
Finally, there’s a function that can be used to enable or disable the focus outline
void fl_set_pixmapbutton_focus_outline(FL_OBJECT *obj, int yes_no);
See also Pixmap Object, for pixmap color and transparency handling.
To get rid of a focus pixmap of a pixmap button use the function
void fl_free_pixmap_focus_pixmap(FL_OBJECT *obj);
Next: Button Attributes, Previous: Button Interaction, Up: Part III Button-like Objects [Contents][Index]