Nmenu Interaction (XForms (Forms Library) - Version 1.2 (Rev. 4) A Graphical User Interface Toolkit for X)

Next: Other Nmenu Routines, Previous: Adding Nmenu Objects, Up: Nmenu Object [Contents][Index]

#### 19.2.2 Nmenu Interaction

There are, if seen interaction-wise, two types of nmenu objects, normal ones and touch nmenus. For normal nmenus a popup is opened when the user clicks on the area of the nmenu object while for touch nmenus the popup already is shown when the user moves the mouse unto the area. In other respects they behave identical: the user just selects one of the items in the popup (or one of the sub-popups) and then the popup is closed again. The selection can now be handled within a callback function and/or reported back to the main loop of the program.

The popup is always shown directly below the nmenu object (except for the case that the popup is that long that it wouldn’t fit on the screen, in which case the popup is drawn above the nmenu’s area.

The most natural way to deal with a selection by the user is probably via a callback for the item that was selected. But also a callback for the popup as a whole or the object itself can be used. Item and popup callback functions are of type `FL_POPUP_CB` described above (and in even more detail in Part III Popups), while object callbacks are "normal" XForms callback functions.

The condition under which a `FL_NMENU` object gets returned to the application (or an associate callback is invoked) can be influenced by calling the function

    int fl_set_object_return(FL_OBJECT *obj, unsigned int when)

where `when` can have the following values

`FL_RETURN_NONE`

  Never return or invoke a callback.

`FL_RETURN_END_CHANGED`

  Return or invoke callback if end of interaction and selection of an item coincide.

`FL_RETURN_CHANGED`

  Return or invoke callback whenever an item is selected (this is the default).

`FL_RETURN_END`

  Return or invoke callback on end of an interaction.

`FL_RETURN_ALWAYS`

  Return (or invoke callback) whenever the interaction ends and/or an item is selected.

One detail of the interaction that can be adjusted is under which conditions the nmenu’s popup gets closed. Per default the popup is closed when an item is selected or (without a selection) when the user clicks somehwere outside of the popups area. This can be changed so that the popup also gets closed (without a selection) when the mouse button is clicked or released on a non-selectable item (giving the impression of a "pull-down" menu). For this purpose there’s the

    int fl_set_nmenu_policy(FL_OBJECT *obj, int policy);

function where `policy` can be one of two values:

`FL_POPUP_NORMAL_SELECT`

  Default, popup stays open until mouse button is released on a selectable entry or button is clicked outside the popups area.

`FL_POPUP_DRAG_SELECT`

  Popup is closed when the mouse button is released.

The function returns on success the previous setting of the "policy" and -1 on error.

Next: Other Nmenu Routines, Previous: Adding Nmenu Objects, Up: Nmenu Object [Contents][Index]