2005-02-25 00:14:22 +03:00
|
|
|
//
|
|
|
|
// An input/chooser widget.
|
|
|
|
// ______________ ____
|
|
|
|
// | || __ |
|
|
|
|
// | input area || \/ |
|
|
|
|
// |______________||____|
|
|
|
|
//
|
|
|
|
// Copyright 2004 by Greg Ercolano.
|
2021-03-20 23:39:28 +03:00
|
|
|
// Copyright 1998-2021 by Bill Spitzak and others.
|
2005-02-25 00:14:22 +03: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:
|
2005-02-25 00:14:22 +03:00
|
|
|
//
|
2020-07-01 19:03:10 +03:00
|
|
|
// https://www.fltk.org/COPYING.php
|
2005-02-25 00:14:22 +03: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
|
2005-02-25 00:14:22 +03:00
|
|
|
//
|
|
|
|
|
2008-10-15 17:46:06 +04:00
|
|
|
/* \file
|
2008-09-16 11:26:22 +04:00
|
|
|
Fl_Input_Choice widget . */
|
|
|
|
|
2005-02-25 00:14:22 +03:00
|
|
|
#ifndef Fl_Input_Choice_H
|
|
|
|
#define Fl_Input_Choice_H
|
|
|
|
|
|
|
|
#include <FL/Fl.H>
|
2007-05-06 19:57:40 +04:00
|
|
|
#include <FL/Fl_Group.H>
|
2005-02-25 00:14:22 +03:00
|
|
|
#include <FL/Fl_Input.H>
|
|
|
|
#include <FL/Fl_Menu_Button.H>
|
|
|
|
|
2017-03-12 02:26:32 +03:00
|
|
|
/*
|
|
|
|
A combination of the input widget and a menu button.
|
2011-12-08 22:18:51 +04:00
|
|
|
|
2008-09-15 15:10:51 +04:00
|
|
|
The user can either type into the input area, or use the
|
2011-12-08 22:18:51 +04:00
|
|
|
menu button chooser on the right to choose an item which loads
|
|
|
|
the input area with the selected text.
|
2015-01-11 01:05:15 +03:00
|
|
|
|
2017-03-12 02:26:32 +03:00
|
|
|
Note: doxygen docs in src/Fl_Input_Choice.cxx
|
2008-09-15 15:10:51 +04:00
|
|
|
*/
|
2017-03-12 02:26:32 +03:00
|
|
|
|
2010-12-13 02:21:03 +03:00
|
|
|
class FL_EXPORT Fl_Input_Choice : public Fl_Group {
|
2017-03-12 02:26:32 +03:00
|
|
|
|
2005-02-25 00:14:22 +03:00
|
|
|
// Private class to handle slightly 'special' behavior of menu button
|
|
|
|
class InputMenuButton : public Fl_Menu_Button {
|
2022-12-30 21:14:36 +03:00
|
|
|
void draw() FL_OVERRIDE;
|
2022-01-14 02:26:27 +03:00
|
|
|
const Fl_Menu_Item* popup();
|
2005-02-25 00:14:22 +03:00
|
|
|
public:
|
2017-03-12 02:26:32 +03:00
|
|
|
InputMenuButton(int X, int Y, int W, int H, const char *L=0);
|
2022-12-30 21:14:36 +03:00
|
|
|
int handle(int e) FL_OVERRIDE;
|
2005-02-25 00:14:22 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
Fl_Input *inp_;
|
|
|
|
InputMenuButton *menu_;
|
|
|
|
|
2017-03-12 02:26:32 +03:00
|
|
|
// note: this is used by the Fl_Input_Choice ctor.
|
|
|
|
static void menu_cb(Fl_Widget*, void *data);
|
2008-02-20 20:59:13 +03:00
|
|
|
|
2017-03-12 02:26:32 +03:00
|
|
|
// note: this is used by the Fl_Input_Choice ctor.
|
|
|
|
static void inp_cb(Fl_Widget*, void *data);
|
2005-02-25 00:14:22 +03:00
|
|
|
|
2022-01-13 18:28:00 +03:00
|
|
|
protected:
|
2005-02-25 00:14:22 +03:00
|
|
|
// Custom resize behavior -- input stretches, menu button doesn't
|
2022-01-13 18:28:00 +03:00
|
|
|
|
|
|
|
/** The methods inp_x(), inp_y(), inp_w() and inp_h() return the
|
|
|
|
desired position and size of the internal Fl_Input widget.
|
|
|
|
These can be overridden by a subclass to redefine positioning.
|
|
|
|
See code example in the Description for subclassing details.
|
|
|
|
*/
|
|
|
|
virtual int inp_x() const { return(x() + Fl::box_dx(box())); }
|
|
|
|
/** See inp_x() for info. */
|
|
|
|
virtual int inp_y() const { return(y() + Fl::box_dy(box())); }
|
|
|
|
/** See inp_x() for info. */
|
|
|
|
virtual int inp_w() const { return(w() - Fl::box_dw(box()) - 20); }
|
|
|
|
/** See inp_x() for info. */
|
|
|
|
virtual int inp_h() const { return(h() - Fl::box_dh(box())); }
|
|
|
|
|
|
|
|
/** The methods menu_x(), menu_y(), menu_w() and menu_h() return the
|
|
|
|
desired position and size of the internal Fl_Menu_Button widget.
|
|
|
|
These can be overridden by a subclass to redefine positioning.
|
|
|
|
See code example in the Description for subclassing details.
|
|
|
|
*/
|
|
|
|
virtual int menu_x() const { return(x() + w() - 20 - Fl::box_dx(box())); }
|
|
|
|
/** See menu_x() for info. */
|
|
|
|
virtual int menu_y() const { return(y() + Fl::box_dy(box())); }
|
|
|
|
/** See menu_x() for info. */
|
|
|
|
virtual int menu_w() const { return(20); }
|
|
|
|
/** See menu_x() for info. */
|
|
|
|
virtual int menu_h() const { return(h() - Fl::box_dh(box())); }
|
2005-02-25 00:14:22 +03:00
|
|
|
|
|
|
|
public:
|
2017-03-12 02:26:32 +03:00
|
|
|
|
|
|
|
Fl_Input_Choice(int X, int Y, int W, int H, const char *L=0);
|
|
|
|
|
2022-12-30 21:14:36 +03:00
|
|
|
void resize(int X, int Y, int W, int H) FL_OVERRIDE;
|
2017-03-12 02:26:32 +03:00
|
|
|
|
2012-12-09 21:45:24 +04:00
|
|
|
/** Adds an item to the menu.
|
2018-05-08 00:24:06 +03:00
|
|
|
When any item is selected, the Fl_Input_Choice callback() is invoked,
|
|
|
|
which can do something with the selected item.
|
|
|
|
|
2017-03-12 02:26:32 +03:00
|
|
|
You can access the more complex Fl_Menu_Button::add() methods
|
2018-05-08 00:24:06 +03:00
|
|
|
(setting item-specific callbacks, userdata, etc), via menubutton(). Example:
|
2017-03-12 02:26:32 +03:00
|
|
|
\code
|
|
|
|
Fl_Input_Choice *choice = new Fl_Input_Choice(100,10,120,25,"Fonts");
|
|
|
|
Fl_Menu_Button *mb = choice->menubutton(); // use Fl_Input_Choice's Fl_Menu_Button
|
|
|
|
mb->add("Helvetica", 0, MyFont_CB, (void*)mydata); // use Fl_Menu_Button's add() methods
|
|
|
|
mb->add("Courier", 0, MyFont_CB, (void*)mydata);
|
|
|
|
mb->add("More..", 0, FontDialog_CB, (void*)mydata);
|
|
|
|
\endcode
|
|
|
|
*/
|
|
|
|
void add(const char *s) { menu_->add(s); }
|
|
|
|
|
2012-12-09 21:45:24 +04:00
|
|
|
/** Returns the combined changed() state of the input and menu button widget. */
|
2011-12-08 22:18:51 +04:00
|
|
|
int changed() const { return inp_->changed() | Fl_Widget::changed(); }
|
2017-03-12 02:26:32 +03:00
|
|
|
|
|
|
|
// Clears the changed() state of both input and menu button widgets.
|
|
|
|
void clear_changed();
|
|
|
|
|
|
|
|
// Sets the changed() state of both input and menu button widgets.
|
|
|
|
void set_changed();
|
|
|
|
|
2008-09-15 15:10:51 +04:00
|
|
|
/** Removes all items from the menu. */
|
|
|
|
void clear() { menu_->clear(); }
|
2017-03-12 02:26:32 +03:00
|
|
|
|
2008-09-15 15:10:51 +04:00
|
|
|
/** Gets the box type of the menu button */
|
|
|
|
Fl_Boxtype down_box() const { return (menu_->down_box()); }
|
2017-03-12 02:26:32 +03:00
|
|
|
|
2008-09-15 15:10:51 +04:00
|
|
|
/** Sets the box type of the menu button */
|
|
|
|
void down_box(Fl_Boxtype b) { menu_->down_box(b); }
|
2017-03-12 02:26:32 +03:00
|
|
|
|
2008-09-15 15:10:51 +04:00
|
|
|
/** Gets the Fl_Menu_Item array used for the menu. */
|
|
|
|
const Fl_Menu_Item *menu() { return (menu_->menu()); }
|
2017-03-12 02:26:32 +03:00
|
|
|
|
2008-09-15 15:10:51 +04:00
|
|
|
/** Sets the Fl_Menu_Item array used for the menu. */
|
|
|
|
void menu(const Fl_Menu_Item *m) { menu_->menu(m); }
|
2017-03-12 02:26:32 +03:00
|
|
|
|
2011-12-08 22:18:51 +04:00
|
|
|
/// Gets the Fl_Input text field's text color.
|
2008-09-15 15:10:51 +04:00
|
|
|
Fl_Color textcolor() const { return (inp_->textcolor());}
|
2017-03-12 02:26:32 +03:00
|
|
|
|
2011-12-08 22:18:51 +04:00
|
|
|
/// Sets the Fl_Input text field's text color to \p c.
|
2008-09-15 15:10:51 +04:00
|
|
|
void textcolor(Fl_Color c) { inp_->textcolor(c);}
|
2017-03-12 02:26:32 +03:00
|
|
|
|
2011-12-08 22:18:51 +04:00
|
|
|
/// Gets the Fl_Input text field's font style.
|
2008-09-15 15:10:51 +04:00
|
|
|
Fl_Font textfont() const { return (inp_->textfont());}
|
2017-03-12 02:26:32 +03:00
|
|
|
|
2011-12-08 22:18:51 +04:00
|
|
|
/// Sets the Fl_Input text field's font style to \p f.
|
2008-09-15 15:10:51 +04:00
|
|
|
void textfont(Fl_Font f) { inp_->textfont(f);}
|
2017-03-12 02:26:32 +03:00
|
|
|
|
2011-12-08 22:18:51 +04:00
|
|
|
/// Gets the Fl_Input text field's font size
|
2008-09-15 15:10:51 +04:00
|
|
|
Fl_Fontsize textsize() const { return (inp_->textsize()); }
|
2017-03-12 02:26:32 +03:00
|
|
|
|
2011-12-08 22:18:51 +04:00
|
|
|
/// Sets the Fl_Input text field's font size to \p s.
|
2008-09-15 15:10:51 +04:00
|
|
|
void textsize(Fl_Fontsize s) { inp_->textsize(s); }
|
2017-03-12 02:26:32 +03:00
|
|
|
|
2011-12-08 22:18:51 +04:00
|
|
|
/// Returns the Fl_Input text field's current contents.
|
2008-09-15 15:10:51 +04:00
|
|
|
const char* value() const { return (inp_->value()); }
|
2017-03-12 02:26:32 +03:00
|
|
|
|
2012-12-09 21:45:24 +04:00
|
|
|
/** Sets the Fl_Input text field's contents to \p val.
|
2018-05-08 00:24:06 +03:00
|
|
|
|
|
|
|
Note it is possible to set the value() to one that is not
|
|
|
|
in the menubutton's list of choices.
|
|
|
|
|
|
|
|
Setting the value() does NOT affect the menubutton's selection.
|
|
|
|
If that's needed, call update_menubutton() after setting value().
|
|
|
|
|
|
|
|
\see void value(int val), update_menubutton()
|
2017-03-12 02:26:32 +03:00
|
|
|
*/
|
2008-09-15 15:10:51 +04:00
|
|
|
void value(const char *val) { inp_->value(val); }
|
2017-03-12 02:26:32 +03:00
|
|
|
|
|
|
|
/* Chooses item# \p val in the menu, and sets the Fl_Input text field
|
|
|
|
to that value. Any previous text is cleared. */
|
|
|
|
void value(int val);
|
|
|
|
|
2018-05-08 00:24:06 +03:00
|
|
|
int update_menubutton();
|
|
|
|
|
2012-12-09 21:45:24 +04:00
|
|
|
/** Returns a pointer to the internal Fl_Menu_Button widget.
|
2017-03-12 02:26:32 +03:00
|
|
|
This can be used to access any of the methods of the menu button, e.g.
|
|
|
|
\code
|
|
|
|
Fl_Input_Choice *choice = new Fl_Input_Choice(100,10,120,25,"Choice:");
|
|
|
|
[..]
|
|
|
|
// Print all the items in the choice menu
|
|
|
|
for ( int t=0; t<choice->menubutton()->size(); t++ ) {
|
2012-12-09 21:45:24 +04:00
|
|
|
const Fl_Menu_Item &item = choice->menubutton()->menu()[t];
|
|
|
|
printf("item %d -- label=%s\n", t, item.label() ? item.label() : "(Null)");
|
2017-03-12 02:26:32 +03:00
|
|
|
}
|
|
|
|
\endcode
|
2012-12-09 21:45:24 +04:00
|
|
|
*/
|
2005-02-25 00:14:22 +03:00
|
|
|
Fl_Menu_Button *menubutton() { return menu_; }
|
2017-03-12 02:26:32 +03:00
|
|
|
|
2012-12-09 21:45:24 +04:00
|
|
|
/** Returns a pointer to the internal Fl_Input widget.
|
2017-03-12 02:26:32 +03:00
|
|
|
This can be used to directly access all of the Fl_Input widget's methods.
|
|
|
|
*/
|
2005-02-25 00:14:22 +03:00
|
|
|
Fl_Input *input() { return inp_; }
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // !Fl_Input_Choice_H
|