]> git.tdb.fi Git - libs/gltk.git/blobdiff - source/container.cpp
Implement mouse wheel scrolling in List
[libs/gltk.git] / source / container.cpp
index e8b666d67344e854cedf0d948fe6f38d2874eab8..7c2e3fb4e8c8afb87b1aa41b49972575a27ffa62 100644 (file)
@@ -1,4 +1,5 @@
 #include "container.h"
+#include "part.h"
 
 using namespace std;
 
@@ -51,6 +52,36 @@ Container::Child *Container::create_child(Widget *wdg)
        return new Child(*this, wdg);
 }
 
+Geometry Container::determine_child_geometry(const Widget &child, const Part &part) const
+{
+       Geometry pgeom = part.get_geometry();
+       if(!pgeom.w || !pgeom.h)
+       {
+               Geometry cgeom;
+               child.autosize(cgeom);
+               if(!pgeom.w)
+                       pgeom.w = cgeom.w;
+               if(!pgeom.h)
+                       pgeom.h = cgeom.h;
+       }
+
+       part.get_alignment().apply(pgeom, geom, part.get_margin());
+       return pgeom;
+}
+
+void Container::autosize_child(const Widget &child, const Part &part, Geometry &ageom) const
+{
+       Geometry cgeom = determine_child_geometry(child, part);
+       const Sides &margin = part.get_margin();
+       ageom.w = max(ageom.w, cgeom.w+margin.left+margin.right);
+       ageom.h = max(ageom.h, cgeom.h+margin.top+margin.bottom);
+}
+
+void Container::reposition_child(Widget &child, const Part &part) const
+{
+       child.set_geometry(determine_child_geometry(child, part));
+}
+
 list<Widget *> Container::get_children() const
 {
        list<Widget *> result;
@@ -188,7 +219,13 @@ Widget *Container::get_pointer_target(int x, int y)
        else if(click_focus)
                return click_focus;
        else
-               return get_child_at(x, y);
+       {
+               Widget *child = get_child_at(x, y);
+               if(child && child->is_enabled())
+                       return child;
+               else
+                       return 0;
+       }
 }
 
 void Container::pointer_leave()