#include <FL/Fl_Object.H>
class Fl_Object
This is the base class for Fl_Window, Fl_Group, and all the ui objects
in Fl. You can't create one of these because the constructor is not
public. However you can subclass it.
All "property" accessing methods, such as color() or parent() or
argument() are implemented as trivial inline functions and thus are as
fast and small as accessing fields in a structure. Unless otherwise
noted (by saying the method causes a redraw()), the property setting
methods such as color(n) or label(s) are also trivial inline
functions, even if they change the objects appearance. It is up to
the user code to call redraw() after these.
Fl_Object(int x, int y, int w, int h, const char* label=0);
This is the protected constructor for an Fl_Object, but all derived
objects have a matching public constructor. It takes a value for
x(), y(), w(), h(), and an optional value for label().
virtual ~Fl_Object();
Destroying single objects is not very common. It is your
responsibility to either remove() them from any enclosing group, or to
destroy that group immediately after destroying the children.
uchar type() const;
This value is used for Forms compatability and to simulate RTTI.
short x() const;
short y() const;
short w() const;
short h() const;
The position of the upper-left corner of the object in its enclosing
Fl_Window (not its parent if that is not an Fl_Window), and its
width and height.
virtual void resize(int,int,int,int);
void position(short x,short y);
void size(short w,short h);
Change the size or position of the object. This will cause it to
redraw. Also the object may implement it's own handling of resizing.
position(x,y) is a shortcut for resize(x,y,w(),h()), and size(w,h) is
a shortcut for resize(x(),y(),w,h).
void size_range(int minw, int minh, int maxw=0, int
maxh=0, int dw=0, int dh=0, int aspect=0);
Set the allowable range the user can resize this object to. Usually
the object is a top-level window.
minw and minh are the smallest this object can be.
maxw and maxh are the largest this object can be. If
either is equal to the minimum then you cannot resize in that
direction. If either is less than the minimum then FL picks a
maximum size in that direction such that the window will fill the
screen.
dw and dh are size increments. The object will be
constrained to widths of minw+N*dw (where N is any integer >= 0). If
these are less or equal to 1 they are ignored.
aspect indicates that this object should preserve it's
aspect ratio. I wanted this to mean that the allowable sizes are on a
straight line between the minimum and maximum sizes. Unfortunately X is
stupid so this only works if this object completely fills the window
and both the maximum and minimum have the same aspect ratio.
The object does not have to be a window. If not then this simply
adds the "border" of area around the object to the sizes and sets the
range on the top-level window. This will produce the desired result
if this object is the resizeable()
of the window, or if it completely encloses the resizeable().
Fl_Window* window() const;
Return a pointer to the Fl_Window that this
object is in (it will skip any and all Fl_Group objects between this
and the window). Returns NULL if none. Note: for an Fl_Window, this
returns it's parent window (if any), not the object itself.
uchar box() const;
void box(uchar a);
The box() identifies a routine that draws the background of the
object. See Boxtypes for the available
types. The default depends on the object, but is usually FL_NO_BOX
(0) or FL_UP_BOX (2).
uchar color() const;
void color(uchar a);
This color is passed to the box routine. Color is an index into an
internal table of rgb colors. For most objects this defaults to
FL_GRAY (47). See the enumeration list
for predefined colors. Use Fl::set_color() to redefine colors.
uchar color2() const;
void color2(uchar a);
void color(uchar a,uchar b);
For Forms compatibility a second color is defined. This is usually
used to color the object when it is selected. You can set both colors
at once with color(a,b).
const char* label() const;
void label(const char*);
The label is printed somewhere on the object or next to it. The
string is not copied, the passed pointer is stored unchanged in
the object.
void label(uchar,const char*);
uchar labeltype() const;
void labeltype(uchar);
The labeltype identifies a routine that draws the label of the object.
This is a routine that takes the label() pointer as an argument.
Typically it is no longer a string, but a pointer to some other data
structure. Usually you set both the labeltype and the label at once
with the two-argument label(a,b) method. You can also change the
labeltype directly. See Fl_bitmap for
some code that uses this. The value FL_NORMAL_LABEL (0) prints the
label as text, and FL_NO_LABEL (1) does not print anything.
uchar align() const;
void align(uchar);
How the label is printed next to or inside the object. The value is
arrived at by or'ing together the following constants: FL_ALIGN_CENTER
(0), FL_ALIGN_TOP (1), FL_ALIGN_BOTTOM (2), FL_ALIGN_LEFT (4),
FL_ALIGN_RIGHT (8), FL_ALIGN_INSIDE (16).
FL_ALIGN_INSIDE makes the label print inside the bounding box.
uchar labelcolor() const;
void labelcolor(uchar a);
This color is passed to the labeltype routine, and is typically the
color of the label text. This defaults to FL_BLACK (0).
uchar labelfont() const;
void labelfont(uchar a);
Fonts are identified by small 8-bit indexes into a table. See the enumeration list for predefined fontss.
The default value (0) uses a Helvetica font. The function
Fl::set_font() can define new fonts.
uchar labelsize() const;
void labelsize(uchar a);
Fonts are further identified by a point size. This sets the actual
point size field of the X font name. The default is FL_NORMAL_SIZE
(14). See the enumeration list for
predefined sizes.
typedef void (Fl_Callback)(Fl_Object*, void*);
Fl_Callback* callback() const;
void callback(Fl_Callback*, void* = 0);
Each object has a single callback. You can set it or examine it with
these methods.
void* user_data() const;
void user_data(void*);
You can also just change the void* second argument to the callback
with the user_data methods.
void callback(void (*)(Fl_Object*, long), long = 0);
long argument() const;
void argument(long);
For convenience you can also define the callback as taking a long
argument. This is implemented by casting this to a Fl_Callback and
casting the long to a void* and may not be portable to some machines.
void callback(void (*)(Fl_Object*));
For convenience you can also define the callback as taking only one
argument. This is implemented by casting this to a Fl_Callback and
may not be portable to some machines.
void do_callback();
void do_callback(Fl_Object* o, void* arg=0);
void do_callback(Fl_Object* o, long arg);
You can cause an object to do its callback at any time, and even pass
arbitrary arguments.
int changed() const;
void set_changed();
void clear_changed();
changed() is a flag that is turned on when the user changes the value
stored in the object. This is only used by subclasses of Fl_Object
that store values, but is in the base class so it is easier to scan
all the objects in a panel and do_callback() on the changed ones in
response to an "OK" button.
Most objects turn this flag off when they do the callback, and when
the program sets the stored value.
uchar when() const;
void when(uchar i);
when() is a set of bitflags used by subclasses of Fl_Object to decide
when to do the callback. If the value is zero then the callback is
never done. Other values are described in the individual objects.
This field is in the base class so that you can scan a panel and
do_callback() on all the ones that don't do their own callbacks in
response to an "OK" button.
static void default_callback(Fl_Object*, void*);
The default callback, which puts a pointer to the object on the queue
returned by Fl::readqueue(). You may want to call this from your own
callback.
int visible() const;
void show();
void hide();
An invisible object never gets redrawn and does not get events. An
object is really visible if visible() is true on it and all it's
parents. Changing it will send FL_SHOW or FL_HIDE events to the
object. Do not change it if the parent is not visible, as this
will send false FL_SHOW or FL_HIDE events to the object. You
probably need to redraw() the parent object if you change this.
int active() const;
void activate();
void deactivate();
int activevisible() const;
This is the same as active()&&visible() but is faster.
void redraw();
Mark the object as needing its draw() routine called.
uchar damage() const;
Non-zero if draw() needs to be called. Actually this is a bit field
that the object subclass can use to figure out what parts to draw.
Fl_Group* parent() const;
Returns a pointer to the Fl_Group (or Fl_Window) that contains this object. Returns
null if none.
int contains(Fl_Object* b) const;
Returns true if b is a child of this object, or is equal to this
object. Returns false if b is null.
int inside(const Fl_Object* a) const;
Returns true if this is a child of a, or is equal to a. Returns false
if a is null.
(back to contents)