[Libreoffice-commits] .: Branch 'feature/layout' - vcl/inc vcl/Library_vcl.mk vcl/source

Ricardo Cruz rpmcruz at kemper.freedesktop.org
Tue Aug 16 16:35:42 PDT 2011


 vcl/Library_vcl.mk            |    4 +
 vcl/inc/vcl/window.hxx        |   27 ++++++++++
 vcl/source/window/window4.cxx |  111 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 142 insertions(+)

New commits:
commit 6faa1efa0620cf16ea7c307ae3c2bbd766410bce
Author: Ricardo Cruz <rpmcruz at alunos.dcc.fc.up.pt>
Date:   Wed Aug 17 00:35:15 2011 +0100

    Initial layout work.

diff --git a/vcl/Library_vcl.mk b/vcl/Library_vcl.mk
index 66d003c..e38d8ad 100644
--- a/vcl/Library_vcl.mk
+++ b/vcl/Library_vcl.mk
@@ -78,6 +78,7 @@ $(eval $(call gb_Library_add_linked_libs,vcl,\
     jvmaccess \
     cppu \
     sal \
+    xmlreader \
     $(gb_STDLIBS) \
 ))
 
@@ -265,6 +266,9 @@ $(eval $(call gb_Library_add_exception_objects,vcl,\
     vcl/source/window/winproc \
     vcl/source/window/wpropset \
     vcl/source/window/wrkwin \
+    vcl/source/layout/ldialog \
+    vcl/source/layout/grid \
+    vcl/source/layout/xmlparser \
 ))
 
 # optional parts
diff --git a/vcl/inc/vcl/window.hxx b/vcl/inc/vcl/window.hxx
index bc93404..2eadb47 100644
--- a/vcl/inc/vcl/window.hxx
+++ b/vcl/inc/vcl/window.hxx
@@ -1130,6 +1130,33 @@ public:
     /*
     */
     virtual void setProperties( const com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >& );
+
+    //** feature/layout stuff
+
+    // to be over-loaded by containers
+
+    virtual com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >
+                getChildProperties( Window *pChild ) const;
+    virtual void setChildProperties( Window *pChild,
+        const com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue > &rProps );
+
+    virtual Size requestSize();
+    virtual void allocateSize( long nX, long nY, long nWidth, long nHeight );
+
+    // containers whose size does not respond to that of its children may return true
+    // (for optimization and possibly to contain layout handling to a branch)
+
+    virtual bool isResizeRoot()   { return false; }
+
+    // call when the widget size may have changed
+    // (usually to be used by the widget implementation code only)
+
+    void invalidateSize();
+
+    // tell the container to re-arrange its children (will trickle down)
+    // (usually called automatically at initialization and after a invalidateSize())
+
+    void doLayout();
 };
 
 
diff --git a/vcl/source/window/window4.cxx b/vcl/source/window/window4.cxx
index 91157a9..0c6b953 100644
--- a/vcl/source/window/window4.cxx
+++ b/vcl/source/window/window4.cxx
@@ -196,4 +196,115 @@ uno::Sequence< beans::PropertyValue > Window::getProperties() const
     return aProps;
 }
 
+// feature/layout
+
+com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >
+    Window::getChildProperties( Window * ) const
+{
+    uno::Sequence< beans::PropertyValue > aProps( 0 );
+    return aProps;
+}
+
+void Window::setChildProperties( Window *,
+    const com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue > & )
+{
+}
+
+Size Window::requestSize()
+{
+    return GetOptimalSize( WINDOWSIZE_PREFERRED );
+}
+
+void Window::allocateSize( long x, long y, long width, long height )
+{
+    SetPosSizePixel( x, y, width, height, WINDOW_POSSIZE_ALL );
+}
+
+static Window *getResizeRoot( Window *pWindow )
+{
+    while( pWindow->GetParent() ) {
+        pWindow = pWindow->GetParent();
+        if( pWindow->isResizeRoot() )
+            break;
+    }
+    return pWindow;
+}
+
+static bool isAncestor( Window *parent, Window *child )
+{
+    for( Window *w = child->GetParent(); w; w = w->GetParent() )
+        if( w == parent )
+            return true;
+    return false;
+}
+
+/*
+ * Automatic layout handler: aggregates and defers widget size
+ * request changes.
+ */
+
+#include <set>
+
+struct LayoutTimer : public Timer
+{
+    static const int TIMEOUT = 50;
+    typedef std::set < Window * > WidgetList;
+    WidgetList invalidated;
+
+    LayoutTimer() : Timer() {
+        SetTimeout( TIMEOUT );
+    }
+
+    void add( Window *pWindow ) {
+        invalidated.insert( pWindow );
+        Start();
+    }
+
+    void validateTree( Window *pWindow ) {
+        for( WidgetList::iterator it = invalidated.begin(); it != invalidated.end(); )
+            if( pWindow == *it || isAncestor( pWindow, *it ) )
+                it = invalidated.erase( it );
+            else
+                it++;
+    }
+
+    static bool isInvalidated( WidgetList &list, Window *w ) {
+        for( WidgetList::iterator it = list.begin(); it != list.end(); it++ )
+            if( isAncestor( *it, w ) )
+                return true;
+        return false;
+    }
+
+    virtual void Timeout() {
+fprintf(stderr, "re-layout\n");
+        // re-layout the top-ancestor layout 'root' container
+        WidgetList roots;
+        for( WidgetList::iterator it = invalidated.begin(); it != invalidated.end(); it++ )
+            roots.insert( getResizeRoot( *it ) );
+        for( WidgetList::iterator it = roots.begin(); it != roots.end(); it++ )
+            if( ! isInvalidated( roots, *it ) )
+//                if( (*it)->IsReallyVisible() )
+                    (*it)->doLayout();
+        invalidated.clear();
+    }
+};
+
+static LayoutTimer timer;
+
+void Window::invalidateSize()
+{
+    if( ! IsReallyVisible() )
+        return;
+    timer.add( this );
+}
+
+void Window::doLayout()
+{
+    timer.validateTree( this );
+
+    Point p = GetPosPixel();
+    Size s = GetSizePixel();
+    allocateSize( p.getX(), p.getY(), s.getWidth(), s.getHeight() );
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list