1998-10-20 01:39:29 +04:00
|
|
|
//
|
|
|
|
// Choice header file for the Fast Light Tool Kit (FLTK).
|
|
|
|
//
|
2010-11-29 00:06:39 +03:00
|
|
|
// Copyright 1998-2010 by Bill Spitzak and others.
|
1998-10-20 01:39:29 +04:00
|
|
|
//
|
2011-07-19 08:49:30 +04:00
|
|
|
// This library is free software. Distribution and use rights are outlined in
|
|
|
|
// the file "COPYING" which should have been included with this file. If this
|
|
|
|
// file is missing or damaged, see the license at:
|
|
|
|
//
|
2020-07-01 19:03:10 +03:00
|
|
|
// https://www.fltk.org/COPYING.php
|
1998-10-20 01:39:29 +04:00
|
|
|
//
|
2020-07-01 19:03:10 +03:00
|
|
|
// Please see the following page on how to report bugs and issues:
|
2005-04-16 04:13:17 +04:00
|
|
|
//
|
2020-07-01 19:03:10 +03:00
|
|
|
// https://www.fltk.org/bugs.php
|
1998-10-20 01:39:29 +04:00
|
|
|
//
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2008-10-15 17:46:06 +04:00
|
|
|
/* \file
|
2008-09-16 11:26:22 +04:00
|
|
|
Fl_Choice widget . */
|
|
|
|
|
1998-10-06 22:21:25 +04:00
|
|
|
#ifndef Fl_Choice_H
|
|
|
|
#define Fl_Choice_H
|
|
|
|
|
|
|
|
#include "Fl_Menu_.H"
|
|
|
|
|
2008-09-16 10:49:08 +04:00
|
|
|
/**
|
|
|
|
\class Fl_Choice
|
|
|
|
\brief A button that is used to pop up a menu.
|
|
|
|
|
2019-07-26 22:14:49 +03:00
|
|
|
\image html choice.png
|
|
|
|
\image latex choice.png "Fl_Choice" width=4cm
|
|
|
|
|
2008-09-16 10:49:08 +04:00
|
|
|
This is a button that, when pushed, pops up a menu (or hierarchy of menus)
|
|
|
|
defined by an array of Fl_Menu_Item objects.
|
|
|
|
Motif calls this an OptionButton.
|
|
|
|
|
|
|
|
The only difference between this and a Fl_Menu_Button is that the name of
|
|
|
|
the most recent chosen menu item is displayed inside the box, while the
|
|
|
|
label is displayed outside the box. However, since the use of this is most
|
|
|
|
often to control a single variable rather than do individual callbacks,
|
|
|
|
some of the Fl_Menu_Button methods are redescribed here in those terms.
|
|
|
|
|
2015-01-11 01:05:15 +03:00
|
|
|
When the user clicks a menu item, value() is set to that item
|
|
|
|
and then:
|
|
|
|
|
|
|
|
- The item's callback is done if one has been set; the
|
2020-07-01 19:03:10 +03:00
|
|
|
Fl_Choice is passed as the Fl_Widget* argument,
|
2015-01-11 01:05:15 +03:00
|
|
|
along with any userdata configured for the callback.
|
|
|
|
|
|
|
|
- If the item does not have a callback, the Fl_Choice widget's
|
|
|
|
callback is done instead, along with any userdata configured
|
|
|
|
for it. The callback can determine which item was picked using
|
|
|
|
value(), mvalue(), item_pathname(), etc.
|
2008-09-16 10:49:08 +04:00
|
|
|
|
|
|
|
All three mouse buttons pop up the menu. The Forms behavior of the first
|
|
|
|
two buttons to increment/decrement the choice is not implemented. This
|
|
|
|
could be added with a subclass, however.
|
|
|
|
|
|
|
|
The menu will also pop up in response to shortcuts indicated by putting
|
|
|
|
a '\&' character in the label(). See Fl_Button::shortcut(int s) for a
|
|
|
|
description of this.
|
|
|
|
|
|
|
|
Typing the shortcut() of any of the items will do exactly the same as when
|
|
|
|
you pick the item with the mouse. The '\&' character in item names are
|
|
|
|
only looked at when the menu is popped up, however.
|
|
|
|
|
|
|
|
\todo Refactor the doxygen comments for Fl_Choice changed() documentation.
|
|
|
|
|
|
|
|
\li <tt>int Fl_Widget::changed() const</tt>
|
|
|
|
This value is true the user picks a different value. <em>It is turned
|
|
|
|
off by value() and just before doing a callback (the callback can turn
|
|
|
|
it back on if desired).</em>
|
|
|
|
\li <tt>void Fl_Widget::set_changed()</tt>
|
|
|
|
This method sets the changed() flag.
|
|
|
|
\li <tt>void Fl_Widget::clear_changed()</tt>
|
|
|
|
This method clears the changed() flag.
|
|
|
|
\li <tt>Fl_Boxtype Fl_Choice::down_box() const</tt>
|
|
|
|
Gets the current down box, which is used when the menu is popped up.
|
|
|
|
The default down box type is \c FL_DOWN_BOX.
|
|
|
|
\li <tt>void Fl_Choice::down_box(Fl_Boxtype b)</tt>
|
|
|
|
Sets the current down box type to \p b.
|
2019-07-26 22:14:49 +03:00
|
|
|
|
|
|
|
Simple example:
|
|
|
|
\par
|
|
|
|
\code
|
|
|
|
#include <FL/Fl.H>
|
|
|
|
#include <FL/Fl_Window.H>
|
|
|
|
#include <FL/Fl_Choice.H>
|
|
|
|
int main() {
|
|
|
|
Fl_Window *win = new Fl_Window(300,200);
|
|
|
|
Fl_Choice *choice = new Fl_Choice(100,10,100,25,"Choice:");
|
|
|
|
choice->add("Zero");
|
|
|
|
choice->add("One");
|
|
|
|
choice->add("Two");
|
|
|
|
choice->add("Three");
|
|
|
|
choice->value(2); // make "Two" selected by default (zero based!)
|
|
|
|
win->end();
|
|
|
|
win->show();
|
|
|
|
return Fl::run();
|
|
|
|
}
|
|
|
|
\endcode
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2008-09-16 10:49:08 +04:00
|
|
|
*/
|
2002-08-14 20:49:38 +04:00
|
|
|
class FL_EXPORT Fl_Choice : public Fl_Menu_ {
|
1998-10-06 22:21:25 +04:00
|
|
|
protected:
|
2002-08-14 20:49:38 +04:00
|
|
|
void draw();
|
1998-10-06 22:21:25 +04:00
|
|
|
public:
|
2002-08-14 20:49:38 +04:00
|
|
|
int handle(int);
|
2008-09-16 10:49:08 +04:00
|
|
|
|
|
|
|
Fl_Choice(int X, int Y, int W, int H, const char *L = 0);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Gets the index of the last item chosen by the user.
|
2020-02-13 17:38:52 +03:00
|
|
|
The index is -1 initially.
|
2008-09-16 10:49:08 +04:00
|
|
|
*/
|
2002-08-14 20:49:38 +04:00
|
|
|
int value() const {return Fl_Menu_::value();}
|
2008-09-16 10:49:08 +04:00
|
|
|
|
|
|
|
int value(int v);
|
|
|
|
|
|
|
|
int value(const Fl_Menu_Item* v);
|
1998-10-06 22:21:25 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|