xref: /AOO41X/main/toolkit/source/layout/core/bin.cxx (revision b0724fc6948542b2496e16ea247f985ee5987cfe)
1*b0724fc6SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*b0724fc6SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*b0724fc6SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*b0724fc6SAndrew Rist  * distributed with this work for additional information
6*b0724fc6SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*b0724fc6SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*b0724fc6SAndrew Rist  * "License"); you may not use this file except in compliance
9*b0724fc6SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*b0724fc6SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*b0724fc6SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*b0724fc6SAndrew Rist  * software distributed under the License is distributed on an
15*b0724fc6SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b0724fc6SAndrew Rist  * KIND, either express or implied.  See the License for the
17*b0724fc6SAndrew Rist  * specific language governing permissions and limitations
18*b0724fc6SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*b0724fc6SAndrew Rist  *************************************************************/
21*b0724fc6SAndrew Rist 
22*b0724fc6SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include "bin.hxx"
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #include <sal/macros.h>
27cdf0e10cSrcweir 
28cdf0e10cSrcweir namespace layoutimpl
29cdf0e10cSrcweir {
30cdf0e10cSrcweir 
31cdf0e10cSrcweir using namespace css;
32cdf0e10cSrcweir 
33cdf0e10cSrcweir /* Bin */
34cdf0e10cSrcweir 
Bin()35cdf0e10cSrcweir Bin::Bin() : Container()
36cdf0e10cSrcweir {
37cdf0e10cSrcweir }
38cdf0e10cSrcweir 
39cdf0e10cSrcweir void SAL_CALL
addChild(const uno::Reference<awt::XLayoutConstrains> & xChild)40cdf0e10cSrcweir Bin::addChild( const uno::Reference< awt::XLayoutConstrains >& xChild )
41cdf0e10cSrcweir     throw (uno::RuntimeException, awt::MaxChildrenException)
42cdf0e10cSrcweir {
43cdf0e10cSrcweir     if ( mxChild.is() )
44cdf0e10cSrcweir         throw awt::MaxChildrenException();
45cdf0e10cSrcweir     if ( xChild.is() )
46cdf0e10cSrcweir     {
47cdf0e10cSrcweir         mxChild = xChild;
48cdf0e10cSrcweir         setChildParent( xChild );
49cdf0e10cSrcweir         queueResize();
50cdf0e10cSrcweir     }
51cdf0e10cSrcweir }
52cdf0e10cSrcweir 
53cdf0e10cSrcweir void SAL_CALL
removeChild(const uno::Reference<awt::XLayoutConstrains> & xChild)54cdf0e10cSrcweir Bin::removeChild( const uno::Reference< awt::XLayoutConstrains >& xChild )
55cdf0e10cSrcweir     throw (uno::RuntimeException)
56cdf0e10cSrcweir {
57cdf0e10cSrcweir     if ( xChild == mxChild )
58cdf0e10cSrcweir     {
59cdf0e10cSrcweir         mxChild = uno::Reference< awt::XLayoutConstrains >();
60cdf0e10cSrcweir         unsetChildParent( xChild );
61cdf0e10cSrcweir         queueResize();
62cdf0e10cSrcweir     }
63cdf0e10cSrcweir }
64cdf0e10cSrcweir 
65cdf0e10cSrcweir uno::Sequence< uno::Reference< awt::XLayoutConstrains > > SAL_CALL
getChildren()66cdf0e10cSrcweir Bin::getChildren()
67cdf0e10cSrcweir     throw (uno::RuntimeException)
68cdf0e10cSrcweir {
69cdf0e10cSrcweir     return getSingleChild (mxChild);
70cdf0e10cSrcweir }
71cdf0e10cSrcweir 
72cdf0e10cSrcweir void SAL_CALL
allocateArea(const awt::Rectangle & rArea)73cdf0e10cSrcweir Bin::allocateArea( const awt::Rectangle &rArea )
74cdf0e10cSrcweir     throw (uno::RuntimeException)
75cdf0e10cSrcweir {
76cdf0e10cSrcweir     maAllocation = rArea;
77cdf0e10cSrcweir     if ( mxChild.is() )
78cdf0e10cSrcweir         allocateChildAt( mxChild, rArea );
79cdf0e10cSrcweir }
80cdf0e10cSrcweir 
81cdf0e10cSrcweir awt::Size SAL_CALL
getMinimumSize()82cdf0e10cSrcweir Bin::getMinimumSize()
83cdf0e10cSrcweir     throw(uno::RuntimeException)
84cdf0e10cSrcweir {
85cdf0e10cSrcweir     if ( mxChild.is() )
86cdf0e10cSrcweir         return maRequisition = maChildRequisition = mxChild->getMinimumSize();
87cdf0e10cSrcweir     return maRequisition = awt::Size( 0, 0 );
88cdf0e10cSrcweir }
89cdf0e10cSrcweir 
90cdf0e10cSrcweir uno::Reference< beans::XPropertySet > SAL_CALL
getChildProperties(const uno::Reference<awt::XLayoutConstrains> &)91cdf0e10cSrcweir Bin::getChildProperties( const uno::Reference< awt::XLayoutConstrains >& )
92cdf0e10cSrcweir     throw (uno::RuntimeException)
93cdf0e10cSrcweir {
94cdf0e10cSrcweir     return uno::Reference< beans::XPropertySet >();
95cdf0e10cSrcweir }
96cdf0e10cSrcweir 
97cdf0e10cSrcweir sal_Bool SAL_CALL
hasHeightForWidth()98cdf0e10cSrcweir Bin::hasHeightForWidth()
99cdf0e10cSrcweir     throw(uno::RuntimeException)
100cdf0e10cSrcweir {
101cdf0e10cSrcweir     uno::Reference< awt::XLayoutContainer > xChildCont( mxChild, uno::UNO_QUERY );
102cdf0e10cSrcweir     if ( xChildCont.is() )
103cdf0e10cSrcweir         return xChildCont->hasHeightForWidth();
104cdf0e10cSrcweir     return false;
105cdf0e10cSrcweir }
106cdf0e10cSrcweir 
107cdf0e10cSrcweir sal_Int32 SAL_CALL
getHeightForWidth(sal_Int32 nWidth)108cdf0e10cSrcweir Bin::getHeightForWidth( sal_Int32 nWidth )
109cdf0e10cSrcweir     throw(uno::RuntimeException)
110cdf0e10cSrcweir {
111cdf0e10cSrcweir     uno::Reference< awt::XLayoutContainer > xChildCont( mxChild, uno::UNO_QUERY );
112cdf0e10cSrcweir     if ( xChildCont.is() )
113cdf0e10cSrcweir         return xChildCont->getHeightForWidth( nWidth );
114cdf0e10cSrcweir     return maRequisition.Height;
115cdf0e10cSrcweir }
116cdf0e10cSrcweir 
117cdf0e10cSrcweir /* Align */
118cdf0e10cSrcweir 
Align()119cdf0e10cSrcweir Align::Align() : Bin()
120cdf0e10cSrcweir {
121cdf0e10cSrcweir     addProp( RTL_CONSTASCII_USTRINGPARAM( "Halign" ),
122cdf0e10cSrcweir              ::getCppuType( static_cast< const float* >( NULL ) ),
123cdf0e10cSrcweir              &fHorAlign );
124cdf0e10cSrcweir     addProp( RTL_CONSTASCII_USTRINGPARAM( "Valign" ),
125cdf0e10cSrcweir              ::getCppuType( static_cast< const float* >( NULL ) ),
126cdf0e10cSrcweir              &fVerAlign );
127cdf0e10cSrcweir     addProp( RTL_CONSTASCII_USTRINGPARAM( "Hfill" ),
128cdf0e10cSrcweir              ::getCppuType( static_cast< const float* >( NULL ) ),
129cdf0e10cSrcweir              &fHorFill );
130cdf0e10cSrcweir     addProp( RTL_CONSTASCII_USTRINGPARAM( "Vfill" ),
131cdf0e10cSrcweir              ::getCppuType( static_cast< const float* >( NULL ) ),
132cdf0e10cSrcweir              &fVerFill );
133cdf0e10cSrcweir 
134cdf0e10cSrcweir     fHorAlign = fVerAlign = 0.5;
135cdf0e10cSrcweir     fHorFill = fVerFill = 0;
136cdf0e10cSrcweir }
137cdf0e10cSrcweir 
138cdf0e10cSrcweir void SAL_CALL
allocateArea(const awt::Rectangle & rArea)139cdf0e10cSrcweir Align::allocateArea( const awt::Rectangle &rArea )
140cdf0e10cSrcweir     throw (uno::RuntimeException)
141cdf0e10cSrcweir {
142cdf0e10cSrcweir     maAllocation = rArea;
143cdf0e10cSrcweir     if ( !mxChild.is() )
144cdf0e10cSrcweir         return;
145cdf0e10cSrcweir 
146cdf0e10cSrcweir     awt::Rectangle aChildArea;
147cdf0e10cSrcweir     aChildArea.Width = SAL_MIN( rArea.Width, maChildRequisition.Width );
148cdf0e10cSrcweir     aChildArea.Width += (sal_Int32) SAL_MAX(
149cdf0e10cSrcweir         0, (rArea.Width - maChildRequisition.Width) * fHorFill );
150cdf0e10cSrcweir     aChildArea.Height = SAL_MIN( rArea.Height, maChildRequisition.Height );
151cdf0e10cSrcweir     aChildArea.Height += (sal_Int32) SAL_MAX(
152cdf0e10cSrcweir         0, (rArea.Height - maChildRequisition.Height) * fVerFill );
153cdf0e10cSrcweir 
154cdf0e10cSrcweir     aChildArea.X = rArea.X + (sal_Int32)( (rArea.Width - aChildArea.Width) * fHorAlign );
155cdf0e10cSrcweir     aChildArea.Y = rArea.Y + (sal_Int32)( (rArea.Height - aChildArea.Height) * fVerAlign );
156cdf0e10cSrcweir 
157cdf0e10cSrcweir     allocateChildAt( mxChild, aChildArea );
158cdf0e10cSrcweir }
159cdf0e10cSrcweir 
160cdf0e10cSrcweir bool
emptyVisible()161cdf0e10cSrcweir Align::emptyVisible ()
162cdf0e10cSrcweir {
163cdf0e10cSrcweir     return true;
164cdf0e10cSrcweir }
165cdf0e10cSrcweir 
166cdf0e10cSrcweir /* MinSize */
167cdf0e10cSrcweir 
MinSize()168cdf0e10cSrcweir MinSize::MinSize() : Bin()
169cdf0e10cSrcweir {
170cdf0e10cSrcweir     mnMinWidth = mnMinHeight = 0;
171cdf0e10cSrcweir     addProp( RTL_CONSTASCII_USTRINGPARAM( "MinWidth" ),
172cdf0e10cSrcweir              ::getCppuType( static_cast< const long* >( NULL ) ),
173cdf0e10cSrcweir              &mnMinWidth );
174cdf0e10cSrcweir     addProp( RTL_CONSTASCII_USTRINGPARAM( "MinHeight" ),
175cdf0e10cSrcweir              ::getCppuType( static_cast< const long* >( NULL ) ),
176cdf0e10cSrcweir              &mnMinHeight );
177cdf0e10cSrcweir }
178cdf0e10cSrcweir 
179cdf0e10cSrcweir bool
emptyVisible()180cdf0e10cSrcweir MinSize::emptyVisible ()
181cdf0e10cSrcweir {
182cdf0e10cSrcweir     return true;
183cdf0e10cSrcweir }
184cdf0e10cSrcweir 
getMinimumSize()185cdf0e10cSrcweir awt::Size SAL_CALL MinSize::getMinimumSize()
186cdf0e10cSrcweir     throw(uno::RuntimeException)
187cdf0e10cSrcweir {
188cdf0e10cSrcweir     Bin::getMinimumSize();
189cdf0e10cSrcweir     maRequisition.Width = SAL_MAX( maRequisition.Width, mnMinWidth );
190cdf0e10cSrcweir     maRequisition.Height = SAL_MAX( maRequisition.Height, mnMinHeight );
191cdf0e10cSrcweir     return maRequisition;
192cdf0e10cSrcweir }
193cdf0e10cSrcweir 
194cdf0e10cSrcweir } // namespace layoutimpl
195