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 <sal/macros.h>
41 bool Flow::ChildData::isVisible()
49 , mbHomogeneous( false )
51 addProp( RTL_CONSTASCII_USTRINGPARAM( "Homogeneous" ),
52 ::getCppuType( static_cast< const sal_Bool
* >( NULL
) ),
54 addProp( RTL_CONSTASCII_USTRINGPARAM( "Spacing" ),
55 ::getCppuType( static_cast< const sal_Int32
* >( NULL
) ),
66 Flow::addChild( const uno::Reference
< awt::XLayoutConstrains
>& xChild
)
67 throw (uno::RuntimeException
, css::awt::MaxChildrenException
)
71 ChildData
*pData
= new ChildData();
72 pData
->xChild
= xChild
;
73 maChildren
.push_back( pData
);
75 setChildParent( xChild
);
81 Flow::removeChild( const css::uno::Reference
< css::awt::XLayoutConstrains
>& xChild
)
82 throw (css::uno::RuntimeException
)
84 for ( std::list
< ChildData
* >::iterator it
= maChildren
.begin();
85 it
!= maChildren
.end(); it
++ )
87 if ( (*it
)->xChild
== xChild
)
90 maChildren
.erase( it
);
92 unsetChildParent( xChild
);
99 css::uno::Sequence
< css::uno::Reference
< css::awt::XLayoutConstrains
> > SAL_CALL
101 throw (css::uno::RuntimeException
)
103 uno::Sequence
< uno::Reference
< awt::XLayoutConstrains
> > children( maChildren
.size() );
105 for ( std::list
< ChildData
* >::iterator it
= maChildren
.begin();
106 it
!= maChildren
.end(); it
++, i
++ )
107 children
[i
] = (*it
)->xChild
;
112 uno::Reference
< beans::XPropertySet
> SAL_CALL
113 Flow::getChildProperties( const uno::Reference
< awt::XLayoutConstrains
>& /*xChild*/ )
114 throw (uno::RuntimeException
)
116 return uno::Reference
< beans::XPropertySet
>();
120 Flow::calculateSize( long nMaxWidth
)
122 long nNeedHeight
= 0;
124 std::list
<ChildData
*>::const_iterator it
;
126 // first pass, for homogeneous property
127 for (it
= maChildren
.begin(); it
!= maChildren
.end(); it
++)
129 if ( !(*it
)->isVisible() )
131 (*it
)->aRequisition
= (*it
)->xChild
->getMinimumSize();
133 mnEachWidth
= SAL_MAX( mnEachWidth
, (*it
)->aRequisition
.Width
);
136 long nRowWidth
= 0, nRowHeight
= 0;
137 for (it
= maChildren
.begin(); it
!= maChildren
.end(); it
++)
139 if ( !(*it
)->isVisible() )
142 awt::Size aChildSize
= (*it
)->aRequisition
;
144 aChildSize
.Width
= mnEachWidth
;
146 if ( nMaxWidth
&& nRowWidth
> 0 && nRowWidth
+ aChildSize
.Width
> nMaxWidth
)
149 nNeedHeight
+= nRowHeight
;
152 nRowHeight
= SAL_MAX( nRowHeight
, aChildSize
.Height
);
153 nRowWidth
+= aChildSize
.Width
;
155 nNeedHeight
+= nRowHeight
;
157 return awt::Size( nRowWidth
, nNeedHeight
);
161 Flow::getMinimumSize() throw(uno::RuntimeException
)
163 return maRequisition
= calculateSize( 0 );
167 Flow::hasHeightForWidth()
168 throw(css::uno::RuntimeException
)
174 Flow::getHeightForWidth( sal_Int32 nWidth
)
175 throw(css::uno::RuntimeException
)
177 return calculateSize( nWidth
).Height
;
181 Flow::allocateArea( const css::awt::Rectangle
&rArea
)
182 throw (css::uno::RuntimeException
)
184 maAllocation
= rArea
;
186 std::list
<ChildData
*>::const_iterator it
;
187 long nX
= 0, nY
= 0, nRowHeight
= 0;
188 for (it
= maChildren
.begin(); it
!= maChildren
.end(); it
++)
190 ChildData
*child
= *it
;
191 if ( !child
->isVisible() )
194 awt::Size
aChildSize( child
->aRequisition
);
196 aChildSize
.Width
= mnEachWidth
;
198 if ( nX
> 0 && nX
+ aChildSize
.Width
> rArea
.Width
)
204 nRowHeight
= SAL_MAX( nRowHeight
, aChildSize
.Height
);
206 allocateChildAt( child
->xChild
,
207 awt::Rectangle( rArea
.X
+ nX
, rArea
.Y
+ nY
, aChildSize
.Width
, aChildSize
.Height
) );
209 nX
+= aChildSize
.Width
;
213 } // namespace layoutimpl