]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/xforms/LayoutEngine.C
Change glob() API to accept a dir parameter.
[lyx.git] / src / frontends / xforms / LayoutEngine.C
index 1d1d61e5c91513ad8e1bdf1ac08562b9eef0232b..84687d1677ab9099bd2f3e6b5b57c9627615ad9f 100644 (file)
 
 #include "LayoutEngine.h"
 #include "lyx_forms.h"
+
 #include <boost/assert.hpp>
+#include <boost/bind.hpp>
+
+using boost::bind;
+using boost::shared_ptr;
 
+using std::for_each;
 
 namespace lyx {
 namespace frontend {
@@ -49,9 +55,9 @@ void BoxList::clear()
 }
 
 
-Box & BoxList::push_back(Box const & box)
+shared_ptr<Box> BoxList::push_back(Box const & box)
 {
-       data_.push_back(box);
+       data_.push_back(shared_ptr<Box>(new Box(box)));
        return data_.back();
 }
 
@@ -97,7 +103,7 @@ Box::Packing Box::default_packing_ = Box::Shrink;
 
 
 Box::Box(dimension_t min_w, dimension_t min_h)
-       : visible_(false),
+       : visible_(true),
          min_w_(min_w),
          min_h_(min_h),
          w_(min_w),
@@ -116,7 +122,7 @@ void Box::setMinimumDimensions(dimension_t min_w, dimension_t min_h)
        min_h_ = min_h;
 }
 
-       
+
 Box::Orientation Box::orientation() const
 {
        return orientation_;
@@ -176,7 +182,7 @@ bool Box::expandable() const
        BoxList::const_iterator it = children_.begin();
        BoxList::const_iterator const end = children_.end();
        for (; it != end; ++it) {
-               if (it->visible() && it->packing() == Expand)
+               if ((*it)->visible() && (*it)->packing() == Expand)
                        return true;
        }
 
@@ -193,7 +199,7 @@ Box::PreferedVisibility Box::preferedVisibility() const
 void Box::set(PreferedVisibility pv)
 {
        prefered_visibility_ = pv;
-       if (pv == Invisible)
+       if (pv == Invisible && visible_)
                hide();
 }
 
@@ -211,10 +217,8 @@ void Box::show()
 
        visible_ = true;
 
-       BoxList::iterator it = children_.begin();
-       BoxList::iterator const end = children_.end();
-       for (; it != end; ++it)
-               it->show();
+       for_each(children_.begin(), children_.end(),
+               bind(&Box::show, _1));
 }
 
 
@@ -222,10 +226,8 @@ void Box::hide()
 {
        visible_ = false;
 
-       BoxList::iterator it = children_.begin();
-       BoxList::iterator const end = children_.end();
-       for (; it != end; ++it)
-               it->hide();
+       for_each(children_.begin(), children_.end(),
+                bind(&Box::hide, _1));
 }
 
 
@@ -280,12 +282,12 @@ void Box::shrinkMetrics()
        BoxList::iterator it = children_.begin();
        BoxList::iterator const end = children_.end();
        for (; it != end; ++it) {
-               if (!it->visible())
+               if (!(*it)->visible())
                        continue;
 
-               it->shrinkMetrics();
-               dimension_t child_width = it->width();
-               dimension_t child_height = it->height();
+               (*it)->shrinkMetrics();
+               dimension_t child_width = (*it)->width();
+               dimension_t child_height = (*it)->height();
 
                if (orientation_ == Horizontal) {
                        width += child_width;
@@ -326,12 +328,12 @@ void Box::expandHbox(dimension_t x_in, dimension_t y_in,
        BoxList::const_iterator cit = children_.begin();
        BoxList::const_iterator const cend = children_.end();
        for (; cit != cend; ++cit) {
-               if (cit->visible()) {
+               if ((*cit)->visible()) {
                        nvisible_children += 1;
-                       if (cit->expandable())
+                       if ((*cit)->expandable())
                                nexpanded_children += 1;
                        else
-                               w_fixed += cit->width();
+                               w_fixed += (*cit)->width();
                }
        }
 
@@ -352,11 +354,11 @@ void Box::expandHbox(dimension_t x_in, dimension_t y_in,
        BoxList::iterator it = children_.begin();
        BoxList::iterator const end = children_.end();
        for (; it != end; ++it) {
-               if (!it->visible())
+               if (!(*it)->visible())
                        continue;
 
-               dimension_t w_child = it->width();
-               if (it->expandable()) {
+               dimension_t w_child = (*it)->width();
+               if ((*it)->expandable()) {
                        if (nexpanded_children == 1)
                                w_child = std::max(w_child, width);
                        else
@@ -366,7 +368,7 @@ void Box::expandHbox(dimension_t x_in, dimension_t y_in,
                        width -= w_child;
                }
 
-               it->expandMetrics(x_child, y_child, w_child, h_child);
+               (*it)->expandMetrics(x_child, y_child, w_child, h_child);
                x_child += w_child;
        }
 }
@@ -382,12 +384,12 @@ void Box::expandVbox(dimension_t x_in, dimension_t y_in,
        BoxList::const_iterator cit = children_.begin();
        BoxList::const_iterator const cend = children_.end();
        for (; cit != cend; ++cit) {
-               if (cit->visible()) {
+               if ((*cit)->visible()) {
                        nvisible_children += 1;
-                       if (cit->expandable())
+                       if ((*cit)->expandable())
                                nexpanded_children += 1;
                        else
-                               h_fixed += cit->height();
+                               h_fixed += (*cit)->height();
                }
        }
 
@@ -408,11 +410,11 @@ void Box::expandVbox(dimension_t x_in, dimension_t y_in,
        BoxList::iterator it = children_.begin();
        BoxList::iterator const end = children_.end();
        for (; it != end; ++it) {
-               if (!it->visible())
+               if (!(*it)->visible())
                        continue;
 
-               dimension_t h_child = it->height();
-               if (it->expandable()) {
+               dimension_t h_child = (*it)->height();
+               if ((*it)->expandable()) {
                        if (nexpanded_children == 1)
                                h_child = std::max(h_child, height);
                        else
@@ -421,17 +423,17 @@ void Box::expandVbox(dimension_t x_in, dimension_t y_in,
                        height -= h_child;
                }
 
-               it->expandMetrics(x_child, y_child, w_child, h_child);
+               (*it)->expandMetrics(x_child, y_child, w_child, h_child);
                y_child += h_child;
        }
 }
 
 
-Box & WidgetMap::add(FL_OBJECT * ob, BoxList & container,
+shared_ptr<Box> WidgetMap::add(FL_OBJECT * ob, BoxList & container,
                     dimension_t min_w, dimension_t min_h)
 {
-       Box & box = container.push_back(Box(min_w, min_h));
-       widgets_[ob] = &box;
+       shared_ptr<Box> box = container.push_back(Box(min_w, min_h));
+       widgets_[ob] = box;
        return box;
 }
 
@@ -443,23 +445,32 @@ void WidgetMap::updateMetrics() const
        for (; it != end; ++it) {
                FL_OBJECT * ob = it->first;
                Box & box = *it->second;
-               fl_set_object_geometry(ob,
-                                      box.xorigin(), box.yorigin(),
-                                      box.width(), box.height());
+
+               if (box.visible()) {
+                       fl_set_object_geometry(ob,
+                                              box.xorigin(), box.yorigin(),
+                                              box.width(), box.height());
+                       if (!ob->visible)
+                               fl_show_object(ob);
+               } else {
+                       if (ob->visible)
+                               fl_hide_object(ob);
+               }
        }
 }
 
 
-Box & embed(FL_OBJECT * ob, BoxList & container, WidgetMap & widgets, int bw)
+shared_ptr<Box>
+embed(FL_OBJECT * ob, BoxList & container, WidgetMap & widgets, int bw)
 {
        container.push_back(Box(0, bw));
-       Box & middle = container.push_back(Box(0, 0));
-       middle.set(Box::Horizontal);
+       shared_ptr<Box> middle = container.push_back(Box(0, 0));
+       middle->set(Box::Horizontal);
        container.push_back(Box(0, bw));
 
-       middle.children().push_back(Box(bw, 0));
-       Box & center = widgets.add(ob, middle.children(), 0, 0);
-       middle.children().push_back(Box(bw, 0));
+       middle->children().push_back(Box(bw, 0));
+       shared_ptr<Box> center = widgets.add(ob, middle->children(), 0, 0);
+       middle->children().push_back(Box(bw, 0));
 
        return center;
 }