1998-10-20 01:39:29 +04:00
|
|
|
//
|
2005-02-25 00:55:12 +03:00
|
|
|
// "$Id$"
|
1998-10-20 01:39:29 +04:00
|
|
|
//
|
|
|
|
// Button header file for the Fast Light Tool Kit (FLTK).
|
|
|
|
//
|
2008-09-16 10:49:08 +04:00
|
|
|
// Copyright 1998-2008 by Bill Spitzak and others.
|
1998-10-20 01:39:29 +04:00
|
|
|
//
|
|
|
|
// This library is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU Library General Public
|
|
|
|
// License as published by the Free Software Foundation; either
|
|
|
|
// version 2 of the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This library is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// Library General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Library General Public
|
|
|
|
// License along with this library; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
// USA.
|
|
|
|
//
|
2005-04-16 04:13:17 +04:00
|
|
|
// Please report all bugs and problems on the following page:
|
|
|
|
//
|
|
|
|
// http://www.fltk.org/str.php
|
1998-10-20 01:39:29 +04:00
|
|
|
//
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2008-09-16 11:26:22 +04:00
|
|
|
/** \file
|
|
|
|
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()
|
2008-09-18 23:09:34 +04:00
|
|
|
#define FL_NORMAL_BUTTON 0 ///< value() remains unchanged after button press.
|
|
|
|
#define FL_TOGGLE_BUTTON 1 ///< value() is inverted after button press.
|
|
|
|
#define FL_RADIO_BUTTON (FL_RESERVED_TYPE+2) /**< is set to 1 after button press, and all other
|
|
|
|
buttons in the current 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
|
|
|
|
2008-10-03 15:20:50 +04:00
|
|
|
#ifndef FL_DOXYGEN
|
1999-02-17 01:00:04 +03:00
|
|
|
extern FL_EXPORT int fl_old_shortcut(const char*);
|
2008-10-03 15:20:50 +04:00
|
|
|
#endif
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2008-09-16 10:49:08 +04:00
|
|
|
/**
|
|
|
|
\class Fl_Button
|
|
|
|
\brief Buttons generate callbacks when they are clicked by the user.
|
|
|
|
|
|
|
|
You control exactly when and how by changing the values for type() and
|
|
|
|
when(). Buttons can also generate callbacks in response to \c FL_SHORTCUT
|
|
|
|
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.
|
|
|
|
|
|
|
|
\todo Refactor the doxygen comments for Fl_Button type() documentation.
|
|
|
|
|
|
|
|
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>
|
|
|
|
are set to zero.
|
|
|
|
|
|
|
|
\todo Refactor the doxygen comments for Fl_Button when() documentation.
|
|
|
|
|
|
|
|
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
|
|
|
|
clicks the button, or when a shortcut is typed.
|
|
|
|
\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
|
|
|
|
dragged around in and out of the button).
|
|
|
|
*/
|
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_;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
2002-08-14 20:49:38 +04:00
|
|
|
virtual void draw();
|
1998-10-06 22:21:25 +04:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2002-08-14 20:49:38 +04:00
|
|
|
virtual int handle(int);
|
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().
|
|
|
|
\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);}
|
1998-10-06 22:21:25 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
1998-10-20 01:39:29 +04:00
|
|
|
|
|
|
|
//
|
2005-02-25 00:55:12 +03:00
|
|
|
// End of "$Id$".
|
1998-10-20 01:39:29 +04:00
|
|
|
//
|