1998-10-20 01:39:29 +04:00
|
|
|
//
|
|
|
|
// Button header file for the Fast Light Tool Kit (FLTK).
|
|
|
|
//
|
2014-10-20 00:17:17 +04:00
|
|
|
// Copyright 1998-2014 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
|
2014-10-20 00:17:17 +04:00
|
|
|
// the file "COPYING" which should have been included with this file. If this
|
2011-07-19 08:49:30 +04:00
|
|
|
// 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_Button widget . */
|
|
|
|
|
1998-10-06 22:21:25 +04:00
|
|
|
#ifndef Fl_Button_H
|
|
|
|
#define Fl_Button_H
|
|
|
|
|
|
|
|
#ifndef Fl_Widget_H
|
|
|
|
#include "Fl_Widget.H"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// values for type()
|
2020-07-01 19:03:10 +03:00
|
|
|
#define FL_NORMAL_BUTTON 0 /**< value() will be set to 1 during the press of the button and
|
2008-12-26 22:09:44 +03:00
|
|
|
reverts back to 0 when the button is released */
|
2020-07-01 19:03:10 +03:00
|
|
|
#define FL_TOGGLE_BUTTON 1 ///< value() toggles between 0 and 1 at every click of the button
|
|
|
|
#define FL_RADIO_BUTTON (FL_RESERVED_TYPE+2) /**< is set to 1 at button press, and all other
|
|
|
|
buttons in the same group with <tt>type() == FL_RADIO_BUTTON</tt>
|
|
|
|
are set to zero.*/
|
|
|
|
#define FL_HIDDEN_BUTTON 3 ///< for Forms compatibility
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2009-09-18 02:12:24 +04:00
|
|
|
extern FL_EXPORT Fl_Shortcut fl_old_shortcut(const char*);
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2010-11-14 14:02:18 +03:00
|
|
|
class Fl_Widget_Tracker;
|
|
|
|
|
2008-09-16 10:49:08 +04:00
|
|
|
/**
|
|
|
|
\class Fl_Button
|
|
|
|
\brief Buttons generate callbacks when they are clicked by the user.
|
2014-10-20 00:17:17 +04:00
|
|
|
|
2023-02-05 18:07:14 +03:00
|
|
|
You control exactly when and how by changing the values for type(uchar) and
|
|
|
|
when(uchar). Buttons can also generate callbacks in response to \c FL_SHORTCUT
|
2008-09-16 10:49:08 +04:00
|
|
|
events. The button can either have an explicit shortcut(int s) value or a
|
|
|
|
letter shortcut can be indicated in the label() with an '\&' character
|
|
|
|
before it. For the label shortcut it does not matter if \e Alt is held
|
|
|
|
down, but if you have an input field in the same window, the user will have
|
|
|
|
to hold down the \e Alt key so that the input field does not eat the event
|
|
|
|
first as an \c FL_KEYBOARD event.
|
2020-01-26 21:14:45 +03:00
|
|
|
\see Fl_Widget::shortcut_label(int)
|
2008-09-16 10:49:08 +04:00
|
|
|
|
|
|
|
For an Fl_Button object, the type() call returns one of:
|
|
|
|
\li \c FL_NORMAL_BUTTON (0): value() remains unchanged after button press.
|
|
|
|
\li \c FL_TOGGLE_BUTTON: value() is inverted after button press.
|
|
|
|
\li \c FL_RADIO_BUTTON: value() is set to 1 after button press, and all other
|
|
|
|
buttons in the current group with <tt>type() == FL_RADIO_BUTTON</tt>
|
2020-07-01 19:03:10 +03:00
|
|
|
are set to zero.
|
2008-09-16 10:49:08 +04:00
|
|
|
|
|
|
|
For an Fl_Button object, the following when() values are useful, the default
|
|
|
|
being \c FL_WHEN_RELEASE:
|
|
|
|
\li \c 0: The callback is not done, instead changed() is turned on.
|
|
|
|
\li \c FL_WHEN_RELEASE: The callback is done after the user successfully
|
2023-01-05 15:51:30 +03:00
|
|
|
clicks the button, or when a shortcut is typed. The reason is
|
|
|
|
\p FL_REASON_RELEASED.
|
2008-09-16 10:49:08 +04:00
|
|
|
\li \c FL_WHEN_CHANGED: The callback is done each time the value() changes
|
|
|
|
(when the user pushes and releases the button, and as the mouse is
|
2023-01-05 15:51:30 +03:00
|
|
|
dragged around in and out of the button). The reason is set to
|
|
|
|
\p FL_REASON_CHANGED
|
|
|
|
\li \c FL_WHEN_NOT_CHANGED: The callback is done when the mouse button is
|
|
|
|
released, but the value did not changed. The reason is set to
|
|
|
|
\p FL_REASON_SELECTED
|
2008-09-16 10:49:08 +04:00
|
|
|
*/
|
2014-10-20 00:17:17 +04:00
|
|
|
|
2002-08-14 20:49:38 +04:00
|
|
|
class FL_EXPORT Fl_Button : public Fl_Widget {
|
1998-10-06 22:21:25 +04:00
|
|
|
|
|
|
|
int shortcut_;
|
|
|
|
char value_;
|
|
|
|
char oldval;
|
|
|
|
uchar down_box_;
|
2023-09-03 01:09:32 +03:00
|
|
|
uchar compact_;
|
1998-10-06 22:21:25 +04:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
2010-11-14 14:02:18 +03:00
|
|
|
static Fl_Widget_Tracker *key_release_tracker;
|
|
|
|
static void key_release_timeout(void*);
|
|
|
|
void simulate_key_action();
|
2014-10-20 00:17:17 +04:00
|
|
|
|
2022-12-30 21:14:36 +03:00
|
|
|
void draw() FL_OVERRIDE;
|
1998-10-06 22:21:25 +04:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2022-12-30 21:14:36 +03:00
|
|
|
int handle(int) FL_OVERRIDE;
|
2008-09-16 10:49:08 +04:00
|
|
|
|
|
|
|
Fl_Button(int X, int Y, int W, int H, const char *L = 0);
|
|
|
|
|
|
|
|
int value(int v);
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the current value of the button (0 or 1).
|
|
|
|
*/
|
1998-10-06 22:21:25 +04:00
|
|
|
char value() const {return value_;}
|
2008-09-16 10:49:08 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
Same as \c value(1).
|
|
|
|
\see value(int v)
|
|
|
|
*/
|
1998-10-06 22:21:25 +04:00
|
|
|
int set() {return value(1);}
|
2008-09-16 10:49:08 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
Same as \c value(0).
|
|
|
|
\see value(int v)
|
|
|
|
*/
|
1998-10-06 22:21:25 +04:00
|
|
|
int clear() {return value(0);}
|
2008-09-16 10:49:08 +04:00
|
|
|
|
2002-08-14 20:49:38 +04:00
|
|
|
void setonly(); // this should only be called on FL_RADIO_BUTTONs
|
2008-09-16 10:49:08 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the current shortcut key for the button.
|
|
|
|
\retval int
|
|
|
|
*/
|
1998-10-06 22:21:25 +04:00
|
|
|
int shortcut() const {return shortcut_;}
|
2008-09-16 10:49:08 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
Sets the shortcut key to \c s.
|
|
|
|
Setting this overrides the use of '\&' in the label().
|
|
|
|
The value is a bitwise OR of a key and a set of shift flags, for example:
|
|
|
|
<tt>FL_ALT | 'a'</tt>, or
|
|
|
|
<tt>FL_ALT | (FL_F + 10)</tt>, or just
|
|
|
|
<tt>'a'</tt>.
|
|
|
|
A value of 0 disables the shortcut.
|
|
|
|
|
|
|
|
The key can be any value returned by Fl::event_key(), but will usually be
|
|
|
|
an ASCII letter. Use a lower-case letter unless you require the shift key
|
|
|
|
to be held down.
|
|
|
|
|
|
|
|
The shift flags can be any set of values accepted by Fl::event_state().
|
|
|
|
If the bit is on, that shift key must be pushed. Meta, Alt, Ctrl, and
|
|
|
|
Shift must be off if they are not in the shift flags (zero for the other
|
|
|
|
bits indicates a "don't care" setting).
|
|
|
|
\param[in] s bitwise OR of key and shift flags
|
|
|
|
*/
|
1998-10-06 22:21:25 +04:00
|
|
|
void shortcut(int s) {shortcut_ = s;}
|
2008-09-16 10:49:08 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns the current down box type, which is drawn when value() is non-zero.
|
|
|
|
\retval Fl_Boxtype
|
|
|
|
*/
|
1998-10-06 22:21:25 +04:00
|
|
|
Fl_Boxtype down_box() const {return (Fl_Boxtype)down_box_;}
|
2008-09-16 10:49:08 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
Sets the down box type. The default value of 0 causes FLTK to figure out
|
|
|
|
the correct matching down version of box().
|
2014-10-20 00:17:17 +04:00
|
|
|
|
|
|
|
Some derived classes (e.g. Fl_Round_Button and Fl_Light_Button use
|
|
|
|
down_box() for special purposes. See docs of these classes.
|
|
|
|
|
2008-09-16 10:49:08 +04:00
|
|
|
\param[in] b down box type
|
|
|
|
*/
|
1998-10-06 22:21:25 +04:00
|
|
|
void down_box(Fl_Boxtype b) {down_box_ = b;}
|
|
|
|
|
2008-09-16 10:49:08 +04:00
|
|
|
/// (for backwards compatibility)
|
1998-10-06 22:21:25 +04:00
|
|
|
void shortcut(const char *s) {shortcut(fl_old_shortcut(s));}
|
2008-09-16 10:49:08 +04:00
|
|
|
|
|
|
|
/// (for backwards compatibility)
|
1998-10-06 22:21:25 +04:00
|
|
|
Fl_Color down_color() const {return selection_color();}
|
2008-09-16 10:49:08 +04:00
|
|
|
|
|
|
|
/// (for backwards compatibility)
|
2001-10-29 06:44:33 +03:00
|
|
|
void down_color(unsigned c) {selection_color(c);}
|
2023-09-03 01:09:32 +03:00
|
|
|
|
|
|
|
// handle flag for compact buttons, documentation in source code
|
|
|
|
void compact(uchar v);
|
|
|
|
|
|
|
|
/// Return true if buttons are rendered as compact buttons.
|
|
|
|
/// \return 0 if compact mode is off, 1 if it is on
|
|
|
|
/// \see compact(bool)
|
|
|
|
uchar compact() { return compact_; }
|
1998-10-06 22:21:25 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|