merge the formfield patch from ooo-build
[ooovba.git] / toolkit / source / layout / core / bin.cxx
blobdad845dae1d3df6814627f9f8940c4f3dc2b10c0
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 "bin.hxx"
34 #include <sal/macros.h>
36 namespace layoutimpl
39 using namespace css;
41 /* Bin */
43 Bin::Bin() : Container()
47 void SAL_CALL
48 Bin::addChild( const uno::Reference< awt::XLayoutConstrains >& xChild )
49 throw (uno::RuntimeException, awt::MaxChildrenException)
51 if ( mxChild.is() )
52 throw awt::MaxChildrenException();
53 if ( xChild.is() )
55 mxChild = xChild;
56 setChildParent( xChild );
57 queueResize();
61 void SAL_CALL
62 Bin::removeChild( const uno::Reference< awt::XLayoutConstrains >& xChild )
63 throw (uno::RuntimeException)
65 if ( xChild == mxChild )
67 mxChild = uno::Reference< awt::XLayoutConstrains >();
68 unsetChildParent( xChild );
69 queueResize();
73 uno::Sequence< uno::Reference< awt::XLayoutConstrains > > SAL_CALL
74 Bin::getChildren()
75 throw (uno::RuntimeException)
77 return getSingleChild (mxChild);
80 void SAL_CALL
81 Bin::allocateArea( const awt::Rectangle &rArea )
82 throw (uno::RuntimeException)
84 maAllocation = rArea;
85 if ( mxChild.is() )
86 allocateChildAt( mxChild, rArea );
89 awt::Size SAL_CALL
90 Bin::getMinimumSize()
91 throw(uno::RuntimeException)
93 if ( mxChild.is() )
94 return maRequisition = maChildRequisition = mxChild->getMinimumSize();
95 return maRequisition = awt::Size( 0, 0 );
98 uno::Reference< beans::XPropertySet > SAL_CALL
99 Bin::getChildProperties( const uno::Reference< awt::XLayoutConstrains >& )
100 throw (uno::RuntimeException)
102 return uno::Reference< beans::XPropertySet >();
105 sal_Bool SAL_CALL
106 Bin::hasHeightForWidth()
107 throw(uno::RuntimeException)
109 uno::Reference< awt::XLayoutContainer > xChildCont( mxChild, uno::UNO_QUERY );
110 if ( xChildCont.is() )
111 return xChildCont->hasHeightForWidth();
112 return false;
115 sal_Int32 SAL_CALL
116 Bin::getHeightForWidth( sal_Int32 nWidth )
117 throw(uno::RuntimeException)
119 uno::Reference< awt::XLayoutContainer > xChildCont( mxChild, uno::UNO_QUERY );
120 if ( xChildCont.is() )
121 return xChildCont->getHeightForWidth( nWidth );
122 return maRequisition.Height;
125 /* Align */
127 Align::Align() : Bin()
129 addProp( RTL_CONSTASCII_USTRINGPARAM( "Halign" ),
130 ::getCppuType( static_cast< const float* >( NULL ) ),
131 &fHorAlign );
132 addProp( RTL_CONSTASCII_USTRINGPARAM( "Valign" ),
133 ::getCppuType( static_cast< const float* >( NULL ) ),
134 &fVerAlign );
135 addProp( RTL_CONSTASCII_USTRINGPARAM( "Hfill" ),
136 ::getCppuType( static_cast< const float* >( NULL ) ),
137 &fHorFill );
138 addProp( RTL_CONSTASCII_USTRINGPARAM( "Vfill" ),
139 ::getCppuType( static_cast< const float* >( NULL ) ),
140 &fVerFill );
142 fHorAlign = fVerAlign = 0.5;
143 fHorFill = fVerFill = 0;
146 void SAL_CALL
147 Align::allocateArea( const awt::Rectangle &rArea )
148 throw (uno::RuntimeException)
150 maAllocation = rArea;
151 if ( !mxChild.is() )
152 return;
154 awt::Rectangle aChildArea;
155 aChildArea.Width = SAL_MIN( rArea.Width, maChildRequisition.Width );
156 aChildArea.Width += (sal_Int32) SAL_MAX(
157 0, (rArea.Width - maChildRequisition.Width) * fHorFill );
158 aChildArea.Height = SAL_MIN( rArea.Height, maChildRequisition.Height );
159 aChildArea.Height += (sal_Int32) SAL_MAX(
160 0, (rArea.Height - maChildRequisition.Height) * fVerFill );
162 aChildArea.X = rArea.X + (sal_Int32)( (rArea.Width - aChildArea.Width) * fHorAlign );
163 aChildArea.Y = rArea.Y + (sal_Int32)( (rArea.Height - aChildArea.Height) * fVerAlign );
165 allocateChildAt( mxChild, aChildArea );
168 bool
169 Align::emptyVisible ()
171 return true;
174 /* MinSize */
176 MinSize::MinSize() : Bin()
178 mnMinWidth = mnMinHeight = 0;
179 addProp( RTL_CONSTASCII_USTRINGPARAM( "MinWidth" ),
180 ::getCppuType( static_cast< const long* >( NULL ) ),
181 &mnMinWidth );
182 addProp( RTL_CONSTASCII_USTRINGPARAM( "MinHeight" ),
183 ::getCppuType( static_cast< const long* >( NULL ) ),
184 &mnMinHeight );
187 bool
188 MinSize::emptyVisible ()
190 return true;
193 awt::Size SAL_CALL MinSize::getMinimumSize()
194 throw(uno::RuntimeException)
196 Bin::getMinimumSize();
197 maRequisition.Width = SAL_MAX( maRequisition.Width, mnMinWidth );
198 maRequisition.Height = SAL_MAX( maRequisition.Height, mnMinHeight );
199 return maRequisition;
202 } // namespace layoutimpl