| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257 |
- //
- // "$Id: Fl_Group.H 12302 2017-07-07 19:16:40Z AlbrechtS $"
- //
- // Group header file for the Fast Light Tool Kit (FLTK).
- //
- // Copyright 1998-2017 by Bill Spitzak and others.
- //
- // 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:
- //
- // http://www.fltk.org/COPYING.php
- //
- // Please report all bugs and problems on the following page:
- //
- // http://www.fltk.org/str.php
- //
- /* \file
- Fl_Group, Fl_End classes . */
- #ifndef Fl_Group_H
- #define Fl_Group_H
- #include "Fl_Widget.H"
- //#include "Fl_Rect.H"
- typedef int (*Fl_User_Event_Handler)(Fl_Widget *w, int event);
- struct st_widget_sizes {
- int x,y,w,h;
- Fl_Fontsize labelsize, textsize;
- };
- /**
- 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
- is Fl_Window, however groups can also be used to control radio buttons
- or to enforce resize behavior.
- 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.
- */
- class FL_EXPORT Fl_Group : public Fl_Widget {
- Fl_Widget** array_;
- Fl_Widget* savedfocus_;
- Fl_Widget* resizable_;
- int children_;
- st_widget_sizes *sizes_; // remembered initial sizes of children
- int navigation(int);
- static Fl_Group *current_;
- Fl_User_Event_Handler user_handler_;
- // unimplemented copy ctor and assignment operator
- Fl_Group(const Fl_Group&);
- Fl_Group& operator=(const Fl_Group&);
- public:
- void draw();
- protected:
- void draw_child(Fl_Widget& widget) const;
- void draw_children();
- void draw_outside_label(const Fl_Widget& widget) const ;
- void update_child(Fl_Widget& widget) const;
- st_widget_sizes *sizes();
- public:
- int handle(int);
- void user_handler(Fl_User_Event_Handler uh) {user_handler_ = uh;};
- Fl_User_Event_Handler user_handler() {return user_handler_;};
- void begin();
- void end();
- static Fl_Group *current();
- static void current(Fl_Group *g);
- /**
- Returns how many child widgets the group has.
- */
- int children() const {return children_;}
- /**
- Returns array()[n]. <i>No range checking is done!</i>
- */
- Fl_Widget* child(int n) const {return array()[n];}
- int find(const Fl_Widget*) const;
- /**
- See int Fl_Group::find(const Fl_Widget *w) const
- */
- int find(const Fl_Widget& o) const {return find(&o);}
- Fl_Widget* const* array() const;
- void resize(int,int,int,int);
- /**
- Creates a new Fl_Group widget using the given position, size,
- and label string. The default boxtype is FL_NO_BOX.
- */
- Fl_Group(int,int,int,int, const char * = 0);
- virtual ~Fl_Group();
- void add(Fl_Widget&);
- /**
- See void Fl_Group::add(Fl_Widget &w)
- */
- void add(Fl_Widget* o) {add(*o);}
- void insert(Fl_Widget&, int i);
- /**
- This does insert(w, find(before)). This will append the
- widget if \p before is not in the group.
- */
- void insert(Fl_Widget& o, Fl_Widget* before) {insert(o,find(before));}
- void remove(int index);
- void remove(Fl_Widget&);
- /**
- Removes the widget \p o from the group.
- \sa void remove(Fl_Widget&)
- */
- void remove(Fl_Widget* o) {remove(*o);}
- virtual void clear(); //make it virtual so derived classes will work properly when casted to Fl_Group
- /**
- See void Fl_Group::resizable(Fl_Widget *box)
- */
- void resizable(Fl_Widget& o) {resizable_ = &o;}
- /**
- The resizable widget defines the resizing box for the group. When the
- 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.
- In these examples the gray area is the resizable:
- \image html resizebox1.png
- <br>
- \image html resizebox2.png
- \image latex resizebox1.png "before resize" width=4cm
- \image latex resizebox2.png "after resize" width=4.85cm
- The resizable may be set to the group itself, in which case all the
- contents are resized. This is the default value for Fl_Group,
- although NULL is the default for Fl_Window and Fl_Pack.
- If the resizable is NULL then all widgets remain a fixed size
- and distance from the top-left corner.
- 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 child Fl_Group's.
- */
- void resizable(Fl_Widget* o) {resizable_ = o;}
- /**
- See void Fl_Group::resizable(Fl_Widget *box)
- */
- Fl_Widget* resizable() const {return resizable_;}
- /**
- Adds a widget to the group and makes it the resizable widget.
- */
- void add_resizable(Fl_Widget& o) {resizable_ = &o; add(o);}
- void init_sizes();
- /**
- Controls whether the group widget clips the drawing of
- child widgets to its bounding box.
- Set \p c to 1 if you want to clip the child widgets to the
- 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)
- */
- unsigned int clip_children() { return (flags() & CLIP_CHILDREN) != 0; }
- // Note: Doxygen docs in Fl_Widget.H to avoid redundancy.
- virtual Fl_Group* as_group() { return this; }
- // 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();}
- /** This is for forms compatibility only */
- Fl_Widget* & _ddfdesign_kludge() {return resizable_;}
- /** This is for forms compatibility only */
- void forms_end();
- /** Resize the label and font size of its children */
- void resizefont(float font_scale);
- protected:
- /*!
- Inner implementation of layout(). The child widgets are resized
- and positioned so that the area that was initially surrounded by this
- widget now fits inside the rectangle.
- \a r is a rectangle, in the coordinate system of this Fl_Group (ie 0,0
- is the top-left corner of the Fl_Group).
- \a layout_damage controls what is done. If FL_LAYOUT_W or FL_LAYOUT_H are
- off then no resizing or moving of widgets in that direction is done.
- This is used by Fl_Scroll to resize the widgets to fit inside the
- scrollbars.
- */
- DECLARE_CLASS_CHEAP_RTTI_2(Fl_Group, Fl_Widget)
- };
- // dummy class used to end child groups in constructors for complex
- // subclasses of Fl_Group:
- /**
- This is a dummy class that allows you to end a Fl_Group in a constructor list of a
- class:
- \code
- class MyClass {
- Fl_Group group;
- Fl_Button button_in_group;
- Fl_End end;
- Fl_Button button_outside_group;
- MyClass();
- };
- MyClass::MyClass() :
- group(10,10,100,100),
- button_in_group(20,20,60,30),
- end(),
- button_outside_group(10,120,60,30)
- {}
- \endcode
- */
- class FL_EXPORT Fl_End {
- public:
- /** All it does is calling Fl_Group::current()->end() */
- Fl_End() {Fl_Group::current()->end();}
- };
- #endif
- //
- // End of "$Id: Fl_Group.H 12302 2017-07-07 19:16:40Z AlbrechtS $".
- //
|