- if (_children.size() == 0)
- return;
-
- OtkWidget *tmp;
- OtkWidgetList::iterator it, end = _children.end();
-
- int widest = 0;
- int height = _bevel_width;
- OtkWidgetList stretchable;
-
- for (it = _children.begin(); it != end; ++it) {
- tmp = *it;
- if (tmp->isStretchableVert() && _fixed_height)
- stretchable.push_back(tmp);
- else
- height += tmp->_rect.height() + _bevel_width;
-
- if (tmp->_rect.width() > widest)
- widest = tmp->_rect.width();
+ std::list<Widget*>::iterator it, end;
+
+ // work with just the visible children
+ std::list<Widget*> visible;
+ for (it = _children.begin(), end = _children.end(); it != end; ++it)
+ if ((*it)->visible())
+ visible.push_back(*it);
+
+ if (visible.empty()) return;
+
+ int x, y, w, h; // working area
+ x = y = _bevel;
+ w = _area.width() - _borderwidth * 2 - _bevel * 2;
+ h = _area.height() - _borderwidth * 2 - _bevel * 2;
+ if (w < 0 || h < 0) return; // not worth laying anything out!
+
+ int free = h - (visible.size() - 1) * _bevel;
+ if (free < 0) free = 0;
+ int each;
+
+ std::list<Widget*> adjustable;
+
+ // find the 'free' space, and how many children will be using it
+ for (it = visible.begin(), end = visible.end(); it != end; ++it) {
+ free -= (*it)->minSize().height();
+ if (free < 0) free = 0;
+ if ((*it)->maxSize().height() - (*it)->minSize().height() > 0)
+ adjustable.push_back(*it);
+ }
+ // some widgets may have max heights that restrict them, find the 'true'
+ // amount of free space after these widgets are not included
+ if (!adjustable.empty()) {
+ do {
+ each = free / adjustable.size();
+ for (it = adjustable.begin(), end = adjustable.end(); it != end;) {
+ std::list<Widget*>::iterator next = it; ++next;
+ int m = (*it)->maxSize().height() - (*it)->minSize().height();
+ if (m > 0 && m < each) {
+ free -= m;
+ if (free < 0) free = 0;
+ adjustable.erase(it);
+ break; // if one is found to be fixed, then the free space needs to
+ // change, and the rest need to be reexamined
+ }
+ it = next;
+ }
+ } while (it != end && !adjustable.empty());