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