1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
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 ************************************************************************/
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
47 Box_Base::ChildData::ChildData( uno::Reference
< awt::XLayoutConstrains
> const& xChild
)
54 static bool isVisible( uno::Reference
< awt::XLayoutConstrains
> xWidget
)
58 DBG_ERROR( "FIXME: invalid child !" );
62 uno::Reference
< awt::XWindow2
> xWindow( xWidget
, uno::UNO_QUERY
);
63 if ( xWindow
.is() && !xWindow
->isVisible() )
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
] ) )
79 return false; // this would kill flow without workaround above
85 bool Box_Base::ChildData::isVisible()
87 // FIXME: call the 'isVisible' method on it ?
88 return layoutimpl::isVisible( mxChild
);
92 Box_Base::AddChild (uno::Reference
<awt::XLayoutConstrains
> const& xChild
)
94 ChildData
*pData
= createChild (xChild
);
95 maChildren
.push_back (pData
);
100 Box_Base::addChild (uno::Reference
<awt::XLayoutConstrains
> const& xChild
)
101 throw (uno::RuntimeException
, awt::MaxChildrenException
)
106 setChildParent (xChild
);
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
)
126 Box_Base::removeChild( const uno::Reference
< awt::XLayoutConstrains
>& xChild
)
127 throw (uno::RuntimeException
)
129 if ( ChildData
* p
= removeChildData( maChildren
, xChild
) )
132 unsetChildParent( xChild
);
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
;
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