merge the formfield patch from ooo-build
[ooovba.git] / toolkit / source / layout / core / box-base.cxx
blobf03cd5c686fc46ee1727afb478f5f59d708da0cd
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile$
11 * $Revision$
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 ************************************************************************/
32 #include "box.hxx"
34 #include <tools/debug.hxx>
35 #include <sal/macros.h>
37 #include <com/sun/star/awt/XWindow2.hpp>
39 // fixed point precision for distributing error
40 #define FIXED_PT 16
42 namespace layoutimpl
45 using namespace css;
47 Box_Base::ChildData::ChildData( uno::Reference< awt::XLayoutConstrains > const& xChild )
48 : mxChild( xChild )
49 , mxProps()
50 , maRequisition()
54 static bool isVisible( uno::Reference< awt::XLayoutConstrains > xWidget )
56 if ( !xWidget.is() )
58 DBG_ERROR( "FIXME: invalid child !" );
59 return true;
62 uno::Reference< awt::XWindow2 > xWindow( xWidget, uno::UNO_QUERY );
63 if ( xWindow.is() && !xWindow->isVisible() )
64 return false;
66 uno::Reference< awt::XLayoutContainer > xContainer( xWidget, uno::UNO_QUERY );
67 if ( xContainer.is() )
69 uno::Sequence< uno::Reference< awt::XLayoutConstrains > > aChildren
70 = xContainer->getChildren();
72 if (!aChildren.getLength ())
73 if (Container *c = dynamic_cast <Container*> (xWidget.get ()))
74 return c->emptyVisible ();
76 for ( int i = 0; i < aChildren.getLength(); i++ )
77 if ( isVisible( aChildren[i] ) )
78 return true;
79 return false; // this would kill flow without workaround above
82 return true;
85 bool Box_Base::ChildData::isVisible()
87 // FIXME: call the 'isVisible' method on it ?
88 return layoutimpl::isVisible( mxChild );
91 void
92 Box_Base::AddChild (uno::Reference <awt::XLayoutConstrains> const& xChild)
94 ChildData *pData = createChild (xChild);
95 maChildren.push_back (pData);
96 queueResize ();
99 void SAL_CALL
100 Box_Base::addChild (uno::Reference <awt::XLayoutConstrains> const& xChild)
101 throw (uno::RuntimeException, awt::MaxChildrenException)
103 if (xChild.is ())
105 AddChild (xChild);
106 setChildParent (xChild);
110 Box_Base::ChildData*
111 Box_Base::removeChildData( std::list< ChildData* > lst, css::uno::Reference< css::awt::XLayoutConstrains > const& xChild )
113 for ( std::list< ChildData* >::iterator it = lst.begin();
114 it != lst.end(); it++ )
116 if ( (*it)->mxChild == xChild )
118 lst.erase( it );
119 return *it;
122 return 0;
125 void SAL_CALL
126 Box_Base::removeChild( const uno::Reference< awt::XLayoutConstrains >& xChild )
127 throw (uno::RuntimeException)
129 if ( ChildData* p = removeChildData( maChildren, xChild ) )
131 delete p;
132 unsetChildParent( xChild );
133 queueResize();
135 else
137 DBG_ERROR( "Box_Base: removeChild: no such child" );
141 uno::Sequence< uno::Reference < awt::XLayoutConstrains > > SAL_CALL
142 Box_Base::getChildren()
143 throw (uno::RuntimeException)
145 uno::Sequence< uno::Reference< awt::XLayoutConstrains > > children( maChildren.size() );
146 unsigned int index = 0;
147 for ( std::list< ChildData* >::iterator it = maChildren.begin();
148 it != maChildren.end(); it++, index++ )
149 children[index] = ( *it )->mxChild;
151 return children;
154 uno::Reference< beans::XPropertySet > SAL_CALL
155 Box_Base::getChildProperties( const uno::Reference< awt::XLayoutConstrains >& xChild )
156 throw (uno::RuntimeException)
159 for ( std::list< ChildData * >::iterator it = maChildren.begin();
160 it != maChildren.end(); it++)
162 if ( ( *it )->mxChild == xChild )
164 if ( !( *it )->mxProps.is() )
166 PropHelper *pProps = createChildProps( *it );
167 pProps->setChangeListener( this );
168 ( *it )->mxProps = pProps;
170 return (*it)->mxProps;
173 return uno::Reference< beans::XPropertySet >();
176 } // namespace layoutimpl