1998-10-20 00:46:58 +04:00
|
|
|
//
|
2004-04-11 08:39:01 +04:00
|
|
|
// "$Id: Fl_Group.cxx,v 1.8.2.8.2.24 2004/04/11 04:38:57 easysw Exp $"
|
1998-10-20 00:46:58 +04:00
|
|
|
//
|
|
|
|
// Group widget for the Fast Light Tool Kit (FLTK).
|
|
|
|
//
|
2004-04-11 08:39:01 +04:00
|
|
|
// Copyright 1998-2004 by Bill Spitzak and others.
|
1998-10-20 00:46:58 +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.
|
|
|
|
//
|
2000-06-06 01:21:24 +04:00
|
|
|
// Please report all bugs and problems to "fltk-bugs@fltk.org".
|
1998-10-20 00:46:58 +04:00
|
|
|
//
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2001-12-19 21:40:13 +03:00
|
|
|
// The Fl_Group is the only defined container type in FLTK.
|
1998-10-06 22:21:25 +04:00
|
|
|
|
|
|
|
// Fl_Window itself is a subclass of this, and most of the event
|
|
|
|
// handling is designed so windows themselves work correctly.
|
|
|
|
|
2002-04-09 21:20:24 +04:00
|
|
|
#include <stdio.h>
|
1998-10-06 22:21:25 +04:00
|
|
|
#include <FL/Fl.H>
|
|
|
|
#include <FL/Fl_Group.H>
|
|
|
|
#include <FL/Fl_Window.H>
|
|
|
|
#include <FL/fl_draw.H>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
Fl_Group* Fl_Group::current_;
|
|
|
|
|
|
|
|
// Hack: A single child is stored in the pointer to the array, while
|
|
|
|
// multiple children are stored in an allocated array:
|
|
|
|
Fl_Widget*const* Fl_Group::array() const {
|
|
|
|
return children_ <= 1 ? (Fl_Widget**)(&array_) : array_;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Fl_Group::find(const Fl_Widget* o) const {
|
|
|
|
Fl_Widget*const* a = array();
|
|
|
|
int i; for (i=0; i < children_; i++) if (*a++ == o) break;
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2002-07-14 21:03:31 +04:00
|
|
|
// Metrowerks CodeWarrior and others can't export the static
|
|
|
|
// class member: current_, so these methods can't be inlined...
|
2002-07-12 02:43:53 +04:00
|
|
|
void Fl_Group::begin() {current_ = this;}
|
|
|
|
void Fl_Group::end() {current_ = (Fl_Group*)parent();}
|
2002-07-14 21:03:31 +04:00
|
|
|
Fl_Group *Fl_Group::current() {return current_;}
|
|
|
|
void Fl_Group::current(Fl_Group *g) {current_ = g;}
|
2002-07-12 02:43:53 +04:00
|
|
|
|
1998-10-06 22:21:25 +04:00
|
|
|
extern Fl_Widget* fl_oldfocus; // set by Fl::focus
|
|
|
|
|
|
|
|
// For back-compatability, we must adjust all events sent to child
|
|
|
|
// windows so they are relative to that window.
|
|
|
|
|
|
|
|
static int send(Fl_Widget* o, int event) {
|
|
|
|
if (o->type() < FL_WINDOW) return o->handle(event);
|
2002-02-24 20:52:18 +03:00
|
|
|
switch ( event )
|
|
|
|
{
|
|
|
|
case FL_DND_ENTER:
|
|
|
|
case FL_DND_DRAG:
|
|
|
|
// figure out correct type of event:
|
|
|
|
event = (o->contains(Fl::belowmouse())) ? FL_DND_DRAG : FL_DND_ENTER;
|
|
|
|
}
|
1998-10-06 22:21:25 +04:00
|
|
|
int save_x = Fl::e_x; Fl::e_x -= o->x();
|
|
|
|
int save_y = Fl::e_y; Fl::e_y -= o->y();
|
|
|
|
int ret = o->handle(event);
|
|
|
|
Fl::e_y = save_y;
|
|
|
|
Fl::e_x = save_x;
|
2002-02-24 20:52:18 +03:00
|
|
|
switch ( event )
|
|
|
|
{
|
|
|
|
case FL_ENTER:
|
|
|
|
case FL_DND_ENTER:
|
|
|
|
// Successful completion of FL_ENTER means the widget is now the
|
|
|
|
// belowmouse widget, but only call Fl::belowmouse if the child
|
|
|
|
// widget did not do so:
|
|
|
|
if (!o->contains(Fl::belowmouse())) Fl::belowmouse(o);
|
|
|
|
break;
|
|
|
|
}
|
1998-10-06 22:21:25 +04:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
1999-01-27 00:37:14 +03:00
|
|
|
// translate the current keystroke into up/down/left/right for navigation:
|
|
|
|
#define ctrl(x) (x^0x40)
|
|
|
|
static int navkey() {
|
|
|
|
switch (Fl::event_key()) {
|
2000-02-18 10:11:09 +03:00
|
|
|
case 0: // not an FL_KEYBOARD/FL_SHORTCUT event
|
|
|
|
break;
|
1999-01-27 00:37:14 +03:00
|
|
|
case FL_Tab:
|
|
|
|
if (!Fl::event_state(FL_SHIFT)) return FL_Right;
|
|
|
|
case 0xfe20: // XK_ISO_Left_Tab
|
|
|
|
return FL_Left;
|
|
|
|
case FL_Right:
|
|
|
|
return FL_Right;
|
|
|
|
case FL_Left:
|
|
|
|
return FL_Left;
|
|
|
|
case FL_Up:
|
|
|
|
return FL_Up;
|
|
|
|
case FL_Down:
|
|
|
|
return FL_Down;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1998-10-06 22:21:25 +04:00
|
|
|
int Fl_Group::handle(int event) {
|
|
|
|
|
|
|
|
Fl_Widget*const* a = array();
|
|
|
|
int i;
|
|
|
|
Fl_Widget* o;
|
|
|
|
|
|
|
|
switch (event) {
|
|
|
|
|
|
|
|
case FL_FOCUS:
|
1999-01-27 00:37:14 +03:00
|
|
|
switch (navkey()) {
|
|
|
|
default:
|
|
|
|
if (savedfocus_ && savedfocus_->take_focus()) return 1;
|
|
|
|
case FL_Right:
|
|
|
|
case FL_Down:
|
|
|
|
for (i = children(); i--;) if ((*a++)->take_focus()) return 1;
|
|
|
|
break;
|
|
|
|
case FL_Left:
|
|
|
|
case FL_Up:
|
|
|
|
for (i = children(); i--;) if (a[i]->take_focus()) return 1;
|
|
|
|
break;
|
|
|
|
}
|
1998-10-06 22:21:25 +04:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
case FL_UNFOCUS:
|
|
|
|
savedfocus_ = fl_oldfocus;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case FL_KEYBOARD:
|
1999-01-27 00:37:14 +03:00
|
|
|
return navigation(navkey());
|
1998-10-06 22:21:25 +04:00
|
|
|
|
|
|
|
case FL_SHORTCUT:
|
|
|
|
for (i = children(); i--;) {
|
|
|
|
o = a[i];
|
|
|
|
if (o->takesevents() && Fl::event_inside(o) && send(o,FL_SHORTCUT))
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
for (i = children(); i--;) {
|
|
|
|
o = a[i];
|
|
|
|
if (o->takesevents() && !Fl::event_inside(o) && send(o,FL_SHORTCUT))
|
|
|
|
return 1;
|
|
|
|
}
|
2003-11-01 04:49:35 +03:00
|
|
|
if ((Fl::event_key() == FL_Enter || Fl::event_key() == FL_KP_Enter)) return navigation(FL_Down);
|
1998-10-06 22:21:25 +04:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
case FL_ENTER:
|
|
|
|
case FL_MOVE:
|
|
|
|
for (i = children(); i--;) {
|
|
|
|
o = a[i];
|
2002-04-09 21:20:24 +04:00
|
|
|
if (o->visible() && Fl::event_inside(o)) {
|
1998-10-06 22:21:25 +04:00
|
|
|
if (o->contains(Fl::belowmouse())) {
|
|
|
|
return send(o,FL_MOVE);
|
2002-07-30 22:40:50 +04:00
|
|
|
} else {
|
1998-10-06 22:21:25 +04:00
|
|
|
if (!o->contains(Fl::belowmouse())) Fl::belowmouse(o);
|
2002-07-30 22:40:50 +04:00
|
|
|
if (send(o,FL_ENTER)) return 1;
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Fl::belowmouse(this);
|
|
|
|
return 1;
|
|
|
|
|
2002-02-24 20:52:18 +03:00
|
|
|
case FL_DND_ENTER:
|
|
|
|
case FL_DND_DRAG:
|
|
|
|
for (i = children(); i--;) {
|
|
|
|
o = a[i];
|
|
|
|
if (o->takesevents() && Fl::event_inside(o)) {
|
|
|
|
if (o->contains(Fl::belowmouse())) {
|
|
|
|
return send(o,FL_DND_DRAG);
|
|
|
|
} else if (send(o,FL_DND_ENTER)) {
|
|
|
|
if (!o->contains(Fl::belowmouse())) Fl::belowmouse(o);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Fl::belowmouse(this);
|
|
|
|
return 0;
|
|
|
|
|
1998-10-06 22:21:25 +04:00
|
|
|
case FL_PUSH:
|
|
|
|
for (i = children(); i--;) {
|
|
|
|
o = a[i];
|
|
|
|
if (o->takesevents() && Fl::event_inside(o)) {
|
|
|
|
if (send(o,FL_PUSH)) {
|
|
|
|
if (Fl::pushed() && !o->contains(Fl::pushed())) Fl::pushed(o);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
|
2001-08-03 19:48:20 +04:00
|
|
|
case FL_RELEASE:
|
2001-08-04 16:21:34 +04:00
|
|
|
case FL_DRAG:
|
|
|
|
o = Fl::pushed();
|
|
|
|
if (o == this) return 0;
|
|
|
|
else if (o) send(o,event);
|
|
|
|
else {
|
|
|
|
for (i = children(); i--;) {
|
|
|
|
o = a[i];
|
|
|
|
if (o->takesevents() && Fl::event_inside(o)) {
|
|
|
|
if (send(o,event)) return 1;
|
|
|
|
}
|
2001-08-03 19:48:20 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
|
1998-10-06 22:21:25 +04:00
|
|
|
case FL_DEACTIVATE:
|
|
|
|
case FL_ACTIVATE:
|
|
|
|
for (i = children(); i--;) {
|
|
|
|
o = *a++;
|
|
|
|
if (o->active()) o->handle(event);
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
case FL_SHOW:
|
|
|
|
case FL_HIDE:
|
|
|
|
for (i = children(); i--;) {
|
|
|
|
o = *a++;
|
|
|
|
if (o->visible()) o->handle(event);
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
default:
|
2001-08-03 01:11:43 +04:00
|
|
|
// For all other events, try to give to each child, starting at focus:
|
|
|
|
for (i = 0; i < children(); i ++)
|
2002-04-09 21:20:24 +04:00
|
|
|
if (Fl::focus_ == a[i]) break;
|
2001-08-03 01:11:43 +04:00
|
|
|
|
|
|
|
if (i >= children()) i = 0;
|
|
|
|
|
|
|
|
if (children()) {
|
|
|
|
for (int j = i;;) {
|
2002-05-10 04:18:37 +04:00
|
|
|
if (a[j]->takesevents() || event != FL_MOUSEWHEEL) {
|
|
|
|
if (send(a[j], event)) return 1;
|
|
|
|
}
|
2001-08-03 01:11:43 +04:00
|
|
|
j++;
|
|
|
|
if (j >= children()) j = 0;
|
|
|
|
if (j == i) break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-10-06 22:21:25 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//void Fl_Group::focus(Fl_Widget *o) {Fl::focus(o); o->handle(FL_FOCUS);}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
const char *nameof(Fl_Widget *o) {
|
|
|
|
if (!o) return "NULL";
|
|
|
|
if (!o->label()) return "<no label>";
|
|
|
|
return o->label();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// try to move the focus in response to a keystroke:
|
|
|
|
int Fl_Group::navigation(int key) {
|
|
|
|
if (children() <= 1) return 0;
|
1999-01-27 00:37:14 +03:00
|
|
|
int i;
|
|
|
|
for (i = 0; ; i++) {
|
|
|
|
if (i >= children_) return 0;
|
|
|
|
if (array_[i]->contains(Fl::focus())) break;
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
1999-01-27 00:37:14 +03:00
|
|
|
Fl_Widget *previous = array_[i];
|
1998-10-06 22:21:25 +04:00
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
switch (key) {
|
|
|
|
case FL_Right:
|
|
|
|
case FL_Down:
|
1999-01-27 00:37:14 +03:00
|
|
|
i++;
|
|
|
|
if (i >= children_) {
|
|
|
|
if (parent()) return 0;
|
|
|
|
i = 0;
|
|
|
|
}
|
1998-10-06 22:21:25 +04:00
|
|
|
break;
|
|
|
|
case FL_Left:
|
|
|
|
case FL_Up:
|
1999-01-27 00:37:14 +03:00
|
|
|
if (i) i--;
|
|
|
|
else {
|
|
|
|
if (parent()) return 0;
|
|
|
|
i = children_-1;
|
|
|
|
}
|
1998-10-06 22:21:25 +04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
Fl_Widget* o = array_[i];
|
1999-01-27 00:37:14 +03:00
|
|
|
if (o == previous) return 0;
|
1998-10-06 22:21:25 +04:00
|
|
|
switch (key) {
|
|
|
|
case FL_Down:
|
|
|
|
case FL_Up:
|
1999-01-27 00:37:14 +03:00
|
|
|
// for up/down, the widgets have to overlap horizontally:
|
|
|
|
if (o->x() >= previous->x()+previous->w() ||
|
|
|
|
o->x()+o->w() <= previous->x()) continue;
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
|
|
|
if (o->take_focus()) return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
Fl_Group::Fl_Group(int X,int Y,int W,int H,const char *l)
|
|
|
|
: Fl_Widget(X,Y,W,H,l) {
|
|
|
|
align(FL_ALIGN_TOP);
|
|
|
|
children_ = 0;
|
|
|
|
array_ = 0;
|
|
|
|
savedfocus_ = 0;
|
|
|
|
resizable_ = this;
|
|
|
|
sizes_ = 0; // this is allocated when first resize() is done
|
|
|
|
// Subclasses may want to construct child objects as part of their
|
|
|
|
// constructor, so make sure they are add()'d to this object.
|
|
|
|
// But you must end() the object!
|
|
|
|
begin();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Fl_Group::clear() {
|
1999-07-22 11:27:12 +04:00
|
|
|
Fl_Widget*const* old_array = array();
|
|
|
|
int old_children = children();
|
|
|
|
// clear everything now, in case fl_fix_focus recursively calls us:
|
1998-10-06 22:21:25 +04:00
|
|
|
children_ = 0;
|
2001-12-20 17:41:44 +03:00
|
|
|
//array_ = 0; //dont do this, it will clobber old_array if only one child
|
1998-10-06 22:21:25 +04:00
|
|
|
savedfocus_ = 0;
|
|
|
|
resizable_ = this;
|
|
|
|
init_sizes();
|
1999-07-22 11:27:12 +04:00
|
|
|
// okay, now it is safe to destroy the children:
|
|
|
|
Fl_Widget*const* a = old_array;
|
|
|
|
for (int i=old_children; i--;) {
|
|
|
|
Fl_Widget* o = *a++;
|
2001-12-20 17:41:44 +03:00
|
|
|
if (o->parent() == this) delete o;
|
1999-07-22 11:27:12 +04:00
|
|
|
}
|
|
|
|
if (old_children > 1) free((void*)old_array);
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
|
|
|
|
2001-08-02 01:24:49 +04:00
|
|
|
Fl_Group::~Fl_Group() {
|
|
|
|
clear();
|
|
|
|
}
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2000-10-22 00:01:56 +04:00
|
|
|
void Fl_Group::insert(Fl_Widget &o, int index) {
|
|
|
|
if (o.parent()) {
|
|
|
|
Fl_Group* g = (Fl_Group*)(o.parent());
|
|
|
|
int n = g->find(o);
|
|
|
|
if (g == this) {
|
|
|
|
if (index > n) index--;
|
|
|
|
if (index == n) return;
|
|
|
|
}
|
|
|
|
g->remove(o);
|
|
|
|
}
|
1998-10-06 22:21:25 +04:00
|
|
|
o.parent_ = this;
|
|
|
|
if (children_ == 0) { // use array pointer to point at single child
|
|
|
|
array_ = (Fl_Widget**)&o;
|
|
|
|
} else if (children_ == 1) { // go from 1 to 2 children
|
|
|
|
Fl_Widget* t = (Fl_Widget*)array_;
|
|
|
|
array_ = (Fl_Widget**)malloc(2*sizeof(Fl_Widget*));
|
2000-10-22 00:01:56 +04:00
|
|
|
if (index) {array_[0] = t; array_[1] = &o;}
|
1998-12-29 16:59:48 +03:00
|
|
|
else {array_[0] = &o; array_[1] = t;}
|
1998-10-06 22:21:25 +04:00
|
|
|
} else {
|
|
|
|
if (!(children_ & (children_-1))) // double number of children
|
|
|
|
array_ = (Fl_Widget**)realloc((void*)array_,
|
|
|
|
2*children_*sizeof(Fl_Widget*));
|
2000-10-22 00:01:56 +04:00
|
|
|
int j; for (j = children_; j > index; j--) array_[j] = array_[j-1];
|
1998-12-29 16:59:48 +03:00
|
|
|
array_[j] = &o;
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
|
|
|
children_++;
|
|
|
|
init_sizes();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Fl_Group::add(Fl_Widget &o) {insert(o, children_);}
|
|
|
|
|
|
|
|
void Fl_Group::remove(Fl_Widget &o) {
|
2001-12-20 17:41:44 +03:00
|
|
|
if (!children_) return;
|
1998-10-06 22:21:25 +04:00
|
|
|
int i = find(o);
|
|
|
|
if (i >= children_) return;
|
|
|
|
if (&o == savedfocus_) savedfocus_ = 0;
|
|
|
|
o.parent_ = 0;
|
|
|
|
children_--;
|
|
|
|
if (children_ == 1) { // go from 2 to 1 child
|
|
|
|
Fl_Widget *t = array_[!i];
|
|
|
|
free((void*)array_);
|
|
|
|
array_ = (Fl_Widget**)t;
|
|
|
|
} else if (children_ > 1) { // delete from array
|
|
|
|
for (; i < children_; i++) array_[i] = array_[i+1];
|
|
|
|
}
|
|
|
|
init_sizes();
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// Rather lame kludge here, I need to detect windows and ignore the
|
|
|
|
// changes to X,Y, since all children are relative to X,Y. That
|
|
|
|
// is why I check type():
|
|
|
|
|
|
|
|
// sizes array stores the initial positions of widgets as
|
|
|
|
// left,right,top,bottom quads. The first quad is the group, the
|
|
|
|
// second is the resizable (clipped to the group), and the
|
|
|
|
// rest are the children. This is a convienent order for the
|
|
|
|
// algorithim. If you change this be sure to fix Fl_Tile which
|
|
|
|
// also uses this array!
|
|
|
|
|
|
|
|
void Fl_Group::init_sizes() {
|
|
|
|
delete[] sizes_; sizes_ = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
short* Fl_Group::sizes() {
|
|
|
|
if (!sizes_) {
|
|
|
|
short* p = sizes_ = new short[4*(children_+2)];
|
|
|
|
// first thing in sizes array is the group's size:
|
|
|
|
if (type() < FL_WINDOW) {p[0] = x(); p[2] = y();} else {p[0] = p[2] = 0;}
|
|
|
|
p[1] = p[0]+w(); p[3] = p[2]+h();
|
|
|
|
// next is the resizable's size:
|
|
|
|
p[4] = p[0]; // init to the group's size
|
|
|
|
p[5] = p[1];
|
|
|
|
p[6] = p[2];
|
|
|
|
p[7] = p[3];
|
|
|
|
Fl_Widget* r = resizable();
|
|
|
|
if (r && r != this) { // then clip the resizable to it
|
|
|
|
int t;
|
|
|
|
t = r->x(); if (t > p[0]) p[4] = t;
|
|
|
|
t +=r->w(); if (t < p[1]) p[5] = t;
|
|
|
|
t = r->y(); if (t > p[2]) p[6] = t;
|
|
|
|
t +=r->h(); if (t < p[3]) p[7] = t;
|
|
|
|
}
|
|
|
|
// next is all the children's sizes:
|
|
|
|
p += 8;
|
|
|
|
Fl_Widget*const* a = array();
|
|
|
|
for (int i=children_; i--;) {
|
|
|
|
Fl_Widget* o = *a++;
|
|
|
|
*p++ = o->x();
|
|
|
|
*p++ = o->x()+o->w();
|
|
|
|
*p++ = o->y();
|
|
|
|
*p++ = o->y()+o->h();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return sizes_;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Fl_Group::resize(int X, int Y, int W, int H) {
|
|
|
|
|
2002-02-24 20:52:18 +03:00
|
|
|
if (!resizable() || W==w() && H==h() ) {
|
1998-10-06 22:21:25 +04:00
|
|
|
|
|
|
|
if (type() < FL_WINDOW) {
|
|
|
|
int dx = X-x();
|
|
|
|
int dy = Y-y();
|
|
|
|
Fl_Widget*const* a = array();
|
|
|
|
for (int i=children_; i--;) {
|
|
|
|
Fl_Widget* o = *a++;
|
|
|
|
o->resize(o->x()+dx, o->y()+dy, o->w(), o->h());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (children_) {
|
|
|
|
|
|
|
|
short* p = sizes();
|
|
|
|
|
|
|
|
// get changes in size/position from the initial size:
|
|
|
|
int dx = X - p[0];
|
|
|
|
int dw = W - (p[1]-p[0]);
|
|
|
|
int dy = Y - p[2];
|
|
|
|
int dh = H - (p[3]-p[2]);
|
|
|
|
if (type() >= FL_WINDOW) dx = dy = 0;
|
|
|
|
p += 4;
|
|
|
|
|
|
|
|
// get initial size of resizable():
|
|
|
|
int IX = *p++;
|
|
|
|
int IR = *p++;
|
|
|
|
int IY = *p++;
|
|
|
|
int IB = *p++;
|
|
|
|
|
|
|
|
Fl_Widget*const* a = array();
|
|
|
|
for (int i=children_; i--;) {
|
|
|
|
Fl_Widget* o = *a++;
|
1999-07-23 01:37:04 +04:00
|
|
|
#if 1
|
2002-08-09 05:09:49 +04:00
|
|
|
int XX = *p++;
|
|
|
|
if (XX >= IR) XX += dw;
|
|
|
|
else if (XX > IX) XX = IX+((XX-IX)*(IR+dw-IX)+(IR-IX)/2)/(IR-IX);
|
1998-10-06 22:21:25 +04:00
|
|
|
int R = *p++;
|
|
|
|
if (R >= IR) R += dw;
|
|
|
|
else if (R > IX) R = IX+((R-IX)*(IR+dw-IX)+(IR-IX)/2)/(IR-IX);
|
|
|
|
|
2002-08-09 05:09:49 +04:00
|
|
|
int YY = *p++;
|
|
|
|
if (YY >= IB) YY += dh;
|
|
|
|
else if (YY > IY) YY = IY+((YY-IY)*(IB+dh-IY)+(IB-IY)/2)/(IB-IY);
|
1998-10-06 22:21:25 +04:00
|
|
|
int B = *p++;
|
|
|
|
if (B >= IB) B += dh;
|
|
|
|
else if (B > IY) B = IY+((B-IY)*(IB+dh-IY)+(IB-IY)/2)/(IB-IY);
|
1999-07-23 01:37:04 +04:00
|
|
|
#else // much simpler code from Francois Ostiguy:
|
2002-08-09 05:09:49 +04:00
|
|
|
int XX = *p++;
|
|
|
|
if (XX >= IR) XX += dw;
|
|
|
|
else if (XX > IX) XX += dw * (XX-IX)/(IR-IX);
|
1999-07-23 01:37:04 +04:00
|
|
|
int R = *p++;
|
|
|
|
if (R >= IR) R += dw;
|
|
|
|
else if (R > IX) R = R + dw * (R-IX)/(IR-IX);
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2002-08-09 05:09:49 +04:00
|
|
|
int YY = *p++;
|
|
|
|
if (YY >= IB) YY += dh;
|
|
|
|
else if (YY > IY) YY = YY + dh*(YY-IY)/(IB-IY);
|
1999-07-23 01:37:04 +04:00
|
|
|
int B = *p++;
|
|
|
|
if (B >= IB) B += dh;
|
|
|
|
else if (B > IY) B = B + dh*(B-IY)/(IB-IY);
|
|
|
|
#endif
|
2002-08-09 05:09:49 +04:00
|
|
|
o->resize(XX+dx, YY+dy, R-XX, B-YY);
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Fl_Widget::resize(X,Y,W,H);
|
|
|
|
}
|
|
|
|
|
2002-11-08 18:22:15 +03:00
|
|
|
void Fl_Group::draw_children() {
|
1998-10-06 22:21:25 +04:00
|
|
|
Fl_Widget*const* a = array();
|
1998-10-19 21:53:09 +04:00
|
|
|
if (damage() & ~FL_DAMAGE_CHILD) { // redraw the entire thing:
|
1998-10-06 22:21:25 +04:00
|
|
|
for (int i=children_; i--;) {
|
|
|
|
Fl_Widget& o = **a++;
|
|
|
|
draw_child(o);
|
|
|
|
draw_outside_label(o);
|
|
|
|
}
|
|
|
|
} else { // only redraw the children that need it:
|
|
|
|
for (int i=children_; i--;) update_child(**a++);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-11-08 18:22:15 +03:00
|
|
|
void Fl_Group::draw() {
|
|
|
|
if (damage() & ~FL_DAMAGE_CHILD) { // redraw the entire thing:
|
|
|
|
draw_box();
|
|
|
|
draw_label();
|
|
|
|
}
|
|
|
|
draw_children();
|
|
|
|
}
|
|
|
|
|
1998-10-06 22:21:25 +04:00
|
|
|
// Draw a child only if it needs it:
|
2002-08-09 05:09:49 +04:00
|
|
|
void Fl_Group::update_child(Fl_Widget& widget) const {
|
|
|
|
if (widget.damage() && widget.visible() && widget.type() < FL_WINDOW &&
|
|
|
|
fl_not_clipped(widget.x(), widget.y(), widget.w(), widget.h())) {
|
|
|
|
widget.draw();
|
|
|
|
widget.clear_damage();
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Force a child to redraw:
|
2002-08-09 05:09:49 +04:00
|
|
|
void Fl_Group::draw_child(Fl_Widget& widget) const {
|
|
|
|
if (widget.visible() && widget.type() < FL_WINDOW &&
|
|
|
|
fl_not_clipped(widget.x(), widget.y(), widget.w(), widget.h())) {
|
|
|
|
widget.clear_damage(FL_DAMAGE_ALL);
|
|
|
|
widget.draw();
|
|
|
|
widget.clear_damage();
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extern char fl_draw_shortcut;
|
|
|
|
|
|
|
|
// Parents normally call this to draw outside labels:
|
2002-08-09 05:09:49 +04:00
|
|
|
void Fl_Group::draw_outside_label(const Fl_Widget& widget) const {
|
|
|
|
if (!widget.visible()) return;
|
1998-10-06 22:21:25 +04:00
|
|
|
// skip any labels that are inside the widget:
|
2002-08-09 05:09:49 +04:00
|
|
|
if (!(widget.align()&15) || (widget.align() & FL_ALIGN_INSIDE)) return;
|
1998-10-06 22:21:25 +04:00
|
|
|
// invent a box that is outside the widget:
|
2002-08-09 05:09:49 +04:00
|
|
|
int a = widget.align();
|
|
|
|
int X = widget.x();
|
|
|
|
int Y = widget.y();
|
|
|
|
int W = widget.w();
|
|
|
|
int H = widget.h();
|
|
|
|
if (a & FL_ALIGN_TOP) {
|
|
|
|
a ^= (FL_ALIGN_BOTTOM|FL_ALIGN_TOP);
|
1998-10-06 22:21:25 +04:00
|
|
|
Y = y();
|
2002-08-09 05:09:49 +04:00
|
|
|
H = widget.y()-Y;
|
|
|
|
} else if (a & FL_ALIGN_BOTTOM) {
|
|
|
|
a ^= (FL_ALIGN_BOTTOM|FL_ALIGN_TOP);
|
1998-10-06 22:21:25 +04:00
|
|
|
Y = Y+H;
|
|
|
|
H = y()+h()-Y;
|
2002-08-09 05:09:49 +04:00
|
|
|
} else if (a & FL_ALIGN_LEFT) {
|
|
|
|
a ^= (FL_ALIGN_LEFT|FL_ALIGN_RIGHT);
|
1998-10-06 22:21:25 +04:00
|
|
|
X = x();
|
2002-08-09 05:09:49 +04:00
|
|
|
W = widget.x()-X-3;
|
|
|
|
} else if (a & FL_ALIGN_RIGHT) {
|
|
|
|
a ^= (FL_ALIGN_LEFT|FL_ALIGN_RIGHT);
|
1998-10-06 22:21:25 +04:00
|
|
|
X = X+W+3;
|
|
|
|
W = x()+this->w()-X;
|
|
|
|
}
|
2002-08-09 05:09:49 +04:00
|
|
|
widget.draw_label(X,Y,W,H,(Fl_Align)a);
|
1998-10-06 22:21:25 +04:00
|
|
|
}
|
|
|
|
|
1998-10-20 00:46:58 +04:00
|
|
|
//
|
2004-04-11 08:39:01 +04:00
|
|
|
// End of "$Id: Fl_Group.cxx,v 1.8.2.8.2.24 2004/04/11 04:38:57 easysw Exp $".
|
1998-10-20 00:46:58 +04:00
|
|
|
//
|