1998-10-20 01:39:29 +04:00
|
|
|
//
|
|
|
|
// Group header file for the Fast Light Tool Kit (FLTK).
|
|
|
|
//
|
2022-10-28 18:37:18 +03:00
|
|
|
// Copyright 1998-2022 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_Group, Fl_End classes . */
|
|
|
|
|
1998-10-06 22:21:25 +04:00
|
|
|
#ifndef Fl_Group_H
|
|
|
|
#define Fl_Group_H
|
|
|
|
|
|
|
|
#include "Fl_Widget.H"
|
2018-04-12 15:58:10 +03:00
|
|
|
|
|
|
|
// Don't #include Fl_Rect.H because this would introduce lots
|
|
|
|
// of unnecessary dependencies on Fl_Rect.H
|
|
|
|
class Fl_Rect;
|
|
|
|
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2008-09-14 02:33:03 +04:00
|
|
|
/**
|
|
|
|
The Fl_Group class is the FLTK container widget. It maintains
|
|
|
|
an array of child widgets. These children can themselves be any widget
|
|
|
|
including Fl_Group. The most important subclass of Fl_Group
|
2014-08-29 16:10:11 +04:00
|
|
|
is Fl_Window, however groups can also be used to control radio buttons
|
2009-02-08 20:26:02 +03:00
|
|
|
or to enforce resize behavior.
|
2014-08-29 16:10:11 +04:00
|
|
|
|
|
|
|
The tab and arrow keys are used to move the focus between widgets of
|
|
|
|
this group, and to other groups. The only modifier grabbed is shift
|
|
|
|
(for shift-tab), so that ctrl-tab, alt-up, and such are free
|
|
|
|
for the app to use as shortcuts.
|
2022-10-22 09:44:08 +03:00
|
|
|
|
|
|
|
To remove a widget from the group and destroy it, in 1.3.x (and up)
|
|
|
|
you can simply use:
|
|
|
|
\code
|
|
|
|
delete some_widget;
|
|
|
|
\endcode
|
|
|
|
..and this will trigger proper scheduling of the widget's removal
|
|
|
|
from its parent group.
|
2008-09-14 02:33:03 +04:00
|
|
|
*/
|
2002-07-14 23:08:25 +04:00
|
|
|
class FL_EXPORT Fl_Group : public Fl_Widget {
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2020-07-09 04:07:50 +03:00
|
|
|
union {
|
|
|
|
Fl_Widget** array_; // used if group has two or more children or NULL
|
|
|
|
Fl_Widget* child1_; // used if group has one child or NULL
|
|
|
|
};
|
1998-10-06 22:21:25 +04:00
|
|
|
Fl_Widget* savedfocus_;
|
|
|
|
Fl_Widget* resizable_;
|
|
|
|
int children_;
|
2017-07-07 22:16:40 +03:00
|
|
|
Fl_Rect *bounds_; // remembered initial sizes of children
|
|
|
|
int *sizes_; // remembered initial sizes of children (FLTK 1.3 compat.)
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2001-08-07 03:51:39 +04:00
|
|
|
int navigation(int);
|
2002-07-14 23:08:25 +04:00
|
|
|
static Fl_Group *current_;
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2005-07-15 13:34:53 +04:00
|
|
|
// unimplemented copy ctor and assignment operator
|
|
|
|
Fl_Group(const Fl_Group&);
|
|
|
|
Fl_Group& operator=(const Fl_Group&);
|
1998-10-06 22:21:25 +04:00
|
|
|
|
|
|
|
protected:
|
2022-12-30 21:14:36 +03:00
|
|
|
void draw() FL_OVERRIDE;
|
2009-03-21 20:08:23 +03:00
|
|
|
void draw_child(Fl_Widget& widget) const;
|
2002-11-08 18:22:15 +03:00
|
|
|
void draw_children();
|
2009-03-21 20:08:23 +03:00
|
|
|
void draw_outside_label(const Fl_Widget& widget) const ;
|
|
|
|
void update_child(Fl_Widget& widget) const;
|
2017-07-07 22:16:40 +03:00
|
|
|
Fl_Rect *bounds();
|
|
|
|
int *sizes(); // FLTK 1.3 compatibility
|
2022-11-01 22:45:31 +03:00
|
|
|
virtual int on_insert(Fl_Widget*, int);
|
|
|
|
virtual int on_move(int, int);
|
|
|
|
virtual void on_remove(int);
|
1998-10-06 22:21:25 +04:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2022-12-30 21:14:36 +03:00
|
|
|
int handle(int) FL_OVERRIDE;
|
2002-07-14 23:08:25 +04:00
|
|
|
void begin();
|
|
|
|
void end();
|
|
|
|
static Fl_Group *current();
|
|
|
|
static void current(Fl_Group *g);
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2008-09-14 02:33:03 +04:00
|
|
|
/**
|
|
|
|
Returns how many child widgets the group has.
|
|
|
|
*/
|
1998-10-06 22:21:25 +04:00
|
|
|
int children() const {return children_;}
|
2008-09-14 02:33:03 +04:00
|
|
|
/**
|
|
|
|
Returns array()[n]. <i>No range checking is done!</i>
|
|
|
|
*/
|
1998-10-06 22:21:25 +04:00
|
|
|
Fl_Widget* child(int n) const {return array()[n];}
|
2002-07-14 23:08:25 +04:00
|
|
|
int find(const Fl_Widget*) const;
|
2008-09-14 02:33:03 +04:00
|
|
|
/**
|
2020-07-01 19:03:10 +03:00
|
|
|
See int Fl_Group::find(const Fl_Widget *w) const
|
2008-09-14 02:33:03 +04:00
|
|
|
*/
|
1998-10-06 22:21:25 +04:00
|
|
|
int find(const Fl_Widget& o) const {return find(&o);}
|
2002-07-14 23:08:25 +04:00
|
|
|
Fl_Widget* const* array() const;
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2022-12-30 21:14:36 +03:00
|
|
|
void resize(int,int,int,int) FL_OVERRIDE;
|
2008-09-14 02:33:03 +04:00
|
|
|
/**
|
|
|
|
Creates a new Fl_Group widget using the given position, size,
|
|
|
|
and label string. The default boxtype is FL_NO_BOX.
|
|
|
|
*/
|
2002-07-14 23:08:25 +04:00
|
|
|
Fl_Group(int,int,int,int, const char * = 0);
|
|
|
|
virtual ~Fl_Group();
|
|
|
|
void add(Fl_Widget&);
|
2008-09-14 02:33:03 +04:00
|
|
|
/**
|
2020-07-01 19:03:10 +03:00
|
|
|
See void Fl_Group::add(Fl_Widget &w)
|
2008-09-14 02:33:03 +04:00
|
|
|
*/
|
1998-10-06 22:21:25 +04:00
|
|
|
void add(Fl_Widget* o) {add(*o);}
|
2002-07-14 23:08:25 +04:00
|
|
|
void insert(Fl_Widget&, int i);
|
2008-09-14 02:33:03 +04:00
|
|
|
/**
|
2009-02-08 20:26:02 +03:00
|
|
|
This does insert(w, find(before)). This will append the
|
2009-03-24 04:40:44 +03:00
|
|
|
widget if \p before is not in the group.
|
2008-09-14 02:33:03 +04:00
|
|
|
*/
|
1998-10-06 22:21:25 +04:00
|
|
|
void insert(Fl_Widget& o, Fl_Widget* before) {insert(o,find(before));}
|
2010-08-31 14:01:59 +04:00
|
|
|
void remove(int index);
|
2002-07-14 23:08:25 +04:00
|
|
|
void remove(Fl_Widget&);
|
2008-09-21 04:35:54 +04:00
|
|
|
/**
|
2009-03-24 04:40:44 +03:00
|
|
|
Removes the widget \p o from the group.
|
2008-09-21 04:35:54 +04:00
|
|
|
\sa void remove(Fl_Widget&)
|
|
|
|
*/
|
1998-10-06 22:21:25 +04:00
|
|
|
void remove(Fl_Widget* o) {remove(*o);}
|
2002-07-14 23:08:25 +04:00
|
|
|
void clear();
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2021-05-25 18:39:20 +03:00
|
|
|
/* delete child n (by index) */
|
|
|
|
virtual int delete_child(int n);
|
|
|
|
|
2008-09-14 02:33:03 +04:00
|
|
|
/**
|
2020-07-15 19:53:12 +03:00
|
|
|
Sets the group's resizable widget.
|
|
|
|
See void Fl_Group::resizable(Fl_Widget *o)
|
2008-09-14 02:33:03 +04:00
|
|
|
*/
|
1998-10-06 22:21:25 +04:00
|
|
|
void resizable(Fl_Widget& o) {resizable_ = &o;}
|
2008-09-14 02:33:03 +04:00
|
|
|
/**
|
2020-07-15 19:53:12 +03:00
|
|
|
The resizable widget defines both the resizing box and the resizing
|
|
|
|
behavior of the group and its children.
|
|
|
|
|
|
|
|
If the resizable is NULL the group's size is fixed and all of the widgets
|
|
|
|
in the group remain a fixed size and distance from the top-left corner.
|
|
|
|
This is the default for groups derived from Fl_Window and Fl_Pack.
|
|
|
|
|
|
|
|
The resizable may be set to the group itself, in which case all of the
|
|
|
|
widgets that are its direct children are resized proportionally.
|
|
|
|
This is the default value for Fl_Group.
|
|
|
|
|
|
|
|
The resizable widget defines the resizing box for the group, which could
|
|
|
|
be the group itself or one of the group's direct children. When the
|
2008-09-14 02:33:03 +04:00
|
|
|
group is resized it calculates a new size and position for all of its
|
|
|
|
children. Widgets that are horizontally or vertically inside the
|
|
|
|
dimensions of the box are scaled to the new size. Widgets outside the
|
|
|
|
box are moved.
|
2009-02-08 20:26:02 +03:00
|
|
|
|
2022-10-28 18:37:18 +03:00
|
|
|
\note The resizable of a group \b must be one of
|
|
|
|
- NULL
|
|
|
|
- the group itself
|
|
|
|
- a direct child of the group.
|
|
|
|
\note If you set any other widget that is not a direct child of the group as
|
|
|
|
its resizable then the behavior is undefined. This is \b not checked by
|
|
|
|
Fl_Group for historical reasons.
|
|
|
|
|
2009-02-08 20:26:02 +03:00
|
|
|
In these examples the gray area is the resizable:
|
|
|
|
|
2010-12-09 02:53:04 +03:00
|
|
|
\image html resizebox1.png
|
2014-11-11 01:09:11 +03:00
|
|
|
|
|
|
|
<br>
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2010-12-09 02:53:04 +03:00
|
|
|
\image html resizebox2.png
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2010-12-09 02:53:04 +03:00
|
|
|
\image latex resizebox1.png "before resize" width=4cm
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2014-11-11 01:09:11 +03:00
|
|
|
\image latex resizebox2.png "after resize" width=4.85cm
|
2009-02-08 20:26:02 +03:00
|
|
|
|
2020-07-15 19:53:12 +03:00
|
|
|
It is possible to achieve any type of resize behavior by using an
|
|
|
|
invisible Fl_Box as the resizable and/or by using a hierarchy of
|
|
|
|
Fl_Group widgets, each with their own resizing strategies.
|
2009-02-08 20:26:02 +03:00
|
|
|
|
2020-07-15 19:53:12 +03:00
|
|
|
See the \ref resize chapter for more examples and detailed explanation.
|
2009-02-08 20:26:02 +03:00
|
|
|
|
2021-12-06 21:49:16 +03:00
|
|
|
\note The resizable() widget of a window can also affect the window's
|
2022-02-23 01:28:04 +03:00
|
|
|
resizing behavior if Fl_Window::size_range() is not called. Please
|
|
|
|
see Fl_Window::default_size_range() for more information on how the
|
|
|
|
default size range is calculated.
|
2021-12-06 21:49:16 +03:00
|
|
|
|
|
|
|
\see Fl_Window::size_range()
|
2022-02-23 01:28:04 +03:00
|
|
|
\see Fl_Window::default_size_range()
|
2008-09-14 02:33:03 +04:00
|
|
|
*/
|
1998-10-06 22:21:25 +04:00
|
|
|
void resizable(Fl_Widget* o) {resizable_ = o;}
|
2008-09-14 02:33:03 +04:00
|
|
|
/**
|
2020-07-15 19:53:12 +03:00
|
|
|
Returns the group's resizable widget.
|
|
|
|
See void Fl_Group::resizable(Fl_Widget *o)
|
2008-09-14 02:33:03 +04:00
|
|
|
*/
|
1998-10-06 22:21:25 +04:00
|
|
|
Fl_Widget* resizable() const {return resizable_;}
|
2008-09-14 02:33:03 +04:00
|
|
|
/**
|
|
|
|
Adds a widget to the group and makes it the resizable widget.
|
|
|
|
*/
|
1998-10-06 22:21:25 +04:00
|
|
|
void add_resizable(Fl_Widget& o) {resizable_ = &o; add(o);}
|
2002-07-14 23:08:25 +04:00
|
|
|
void init_sizes();
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2008-10-19 14:23:37 +04:00
|
|
|
/**
|
|
|
|
Controls whether the group widget clips the drawing of
|
|
|
|
child widgets to its bounding box.
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2009-03-24 04:40:44 +03:00
|
|
|
Set \p c to 1 if you want to clip the child widgets to the
|
2008-10-19 14:23:37 +04:00
|
|
|
bounding box.
|
|
|
|
|
|
|
|
The default is to not clip (0) the drawing of child widgets.
|
|
|
|
*/
|
|
|
|
void clip_children(int c) { if (c) set_flag(CLIP_CHILDREN); else clear_flag(CLIP_CHILDREN); }
|
|
|
|
/**
|
|
|
|
Returns the current clipping mode.
|
|
|
|
|
|
|
|
\return true, if clipping is enabled, false otherwise.
|
|
|
|
|
|
|
|
\see void Fl_Group::clip_children(int c)
|
|
|
|
*/
|
2009-09-28 18:34:52 +04:00
|
|
|
unsigned int clip_children() { return (flags() & CLIP_CHILDREN) != 0; }
|
2008-10-19 14:23:37 +04:00
|
|
|
|
2011-01-01 17:01:53 +03:00
|
|
|
// Note: Doxygen docs in Fl_Widget.H to avoid redundancy.
|
2022-12-30 21:14:36 +03:00
|
|
|
Fl_Group* as_group() FL_OVERRIDE { return this; }
|
2010-02-13 15:25:58 +03:00
|
|
|
|
2008-09-29 02:25:23 +04:00
|
|
|
// back compatibility functions:
|
|
|
|
|
|
|
|
/**
|
|
|
|
\deprecated This is for backwards compatibility only. You should use
|
|
|
|
\e W->%take_focus() instead.
|
|
|
|
\sa Fl_Widget::take_focus();
|
|
|
|
*/
|
|
|
|
void focus(Fl_Widget* W) {W->take_focus();}
|
2009-02-08 20:26:02 +03:00
|
|
|
|
2008-09-29 02:25:23 +04:00
|
|
|
/** This is for forms compatibility only */
|
1998-10-06 22:21:25 +04:00
|
|
|
Fl_Widget* & _ddfdesign_kludge() {return resizable_;}
|
2009-02-08 20:26:02 +03:00
|
|
|
|
2008-09-29 02:25:23 +04:00
|
|
|
/** This is for forms compatibility only */
|
2002-07-14 23:08:25 +04:00
|
|
|
void forms_end();
|
1998-10-06 22:21:25 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
// dummy class used to end child groups in constructors for complex
|
|
|
|
// subclasses of Fl_Group:
|
2008-09-14 19:45:27 +04:00
|
|
|
/**
|
|
|
|
This is a dummy class that allows you to end a Fl_Group in a constructor list of a
|
|
|
|
class:
|
2020-07-01 19:03:10 +03:00
|
|
|
\code
|
2019-07-26 22:18:52 +03:00
|
|
|
class MyClass {
|
|
|
|
Fl_Group group;
|
|
|
|
Fl_Button button_in_group;
|
|
|
|
Fl_End end;
|
|
|
|
Fl_Button button_outside_group;
|
|
|
|
MyClass();
|
2008-09-14 19:45:27 +04:00
|
|
|
};
|
|
|
|
MyClass::MyClass() :
|
2019-07-26 22:18:52 +03:00
|
|
|
group(10,10,100,100),
|
|
|
|
button_in_group(20,20,60,30),
|
|
|
|
end(),
|
|
|
|
button_outside_group(10,120,60,30) {
|
|
|
|
[..ctor code..]
|
2020-07-01 19:03:10 +03:00
|
|
|
}
|
2008-09-15 23:21:20 +04:00
|
|
|
\endcode
|
2008-09-14 19:45:27 +04:00
|
|
|
*/
|
2002-08-14 20:19:48 +04:00
|
|
|
class FL_EXPORT Fl_End {
|
1998-10-06 22:21:25 +04:00
|
|
|
public:
|
2008-09-14 19:45:27 +04:00
|
|
|
/** All it does is calling Fl_Group::current()->end() */
|
1998-10-06 22:21:25 +04:00
|
|
|
Fl_End() {Fl_Group::current()->end();}
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|