xref: /trunk/main/toolkit/source/layout/core/bin.cxx (revision 91144cd0085a7583d2099b982122deb2184ab956)
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 {
42     if ( mxChild.is() )
43         throw awt::MaxChildrenException();
44     if ( xChild.is() )
45     {
46         mxChild = xChild;
47         setChildParent( xChild );
48         queueResize();
49     }
50 }
51 
52 void SAL_CALL
removeChild(const uno::Reference<awt::XLayoutConstrains> & xChild)53 Bin::removeChild( const uno::Reference< awt::XLayoutConstrains >& xChild )
54 {
55     if ( xChild == mxChild )
56     {
57         mxChild = uno::Reference< awt::XLayoutConstrains >();
58         unsetChildParent( xChild );
59         queueResize();
60     }
61 }
62 
63 uno::Sequence< uno::Reference< awt::XLayoutConstrains > > SAL_CALL
getChildren()64 Bin::getChildren()
65 {
66     return getSingleChild (mxChild);
67 }
68 
69 void SAL_CALL
allocateArea(const awt::Rectangle & rArea)70 Bin::allocateArea( const awt::Rectangle &rArea )
71 {
72     maAllocation = rArea;
73     if ( mxChild.is() )
74         allocateChildAt( mxChild, rArea );
75 }
76 
77 awt::Size SAL_CALL
getMinimumSize()78 Bin::getMinimumSize()
79 {
80     if ( mxChild.is() )
81         return maRequisition = maChildRequisition = mxChild->getMinimumSize();
82     return maRequisition = awt::Size( 0, 0 );
83 }
84 
85 uno::Reference< beans::XPropertySet > SAL_CALL
getChildProperties(const uno::Reference<awt::XLayoutConstrains> &)86 Bin::getChildProperties( const uno::Reference< awt::XLayoutConstrains >& )
87 {
88     return uno::Reference< beans::XPropertySet >();
89 }
90 
91 sal_Bool SAL_CALL
hasHeightForWidth()92 Bin::hasHeightForWidth()
93 {
94     uno::Reference< awt::XLayoutContainer > xChildCont( mxChild, uno::UNO_QUERY );
95     if ( xChildCont.is() )
96         return xChildCont->hasHeightForWidth();
97     return false;
98 }
99 
100 sal_Int32 SAL_CALL
getHeightForWidth(sal_Int32 nWidth)101 Bin::getHeightForWidth( sal_Int32 nWidth )
102 {
103     uno::Reference< awt::XLayoutContainer > xChildCont( mxChild, uno::UNO_QUERY );
104     if ( xChildCont.is() )
105         return xChildCont->getHeightForWidth( nWidth );
106     return maRequisition.Height;
107 }
108 
109 /* Align */
110 
Align()111 Align::Align() : Bin()
112 {
113     addProp( RTL_CONSTASCII_USTRINGPARAM( "Halign" ),
114              ::getCppuType( static_cast< const float* >( NULL ) ),
115              &fHorAlign );
116     addProp( RTL_CONSTASCII_USTRINGPARAM( "Valign" ),
117              ::getCppuType( static_cast< const float* >( NULL ) ),
118              &fVerAlign );
119     addProp( RTL_CONSTASCII_USTRINGPARAM( "Hfill" ),
120              ::getCppuType( static_cast< const float* >( NULL ) ),
121              &fHorFill );
122     addProp( RTL_CONSTASCII_USTRINGPARAM( "Vfill" ),
123              ::getCppuType( static_cast< const float* >( NULL ) ),
124              &fVerFill );
125 
126     fHorAlign = fVerAlign = 0.5;
127     fHorFill = fVerFill = 0;
128 }
129 
130 void SAL_CALL
allocateArea(const awt::Rectangle & rArea)131 Align::allocateArea( const awt::Rectangle &rArea )
132 {
133     maAllocation = rArea;
134     if ( !mxChild.is() )
135         return;
136 
137     awt::Rectangle aChildArea;
138     aChildArea.Width = SAL_MIN( rArea.Width, maChildRequisition.Width );
139     aChildArea.Width += (sal_Int32) SAL_MAX(
140         0, (rArea.Width - maChildRequisition.Width) * fHorFill );
141     aChildArea.Height = SAL_MIN( rArea.Height, maChildRequisition.Height );
142     aChildArea.Height += (sal_Int32) SAL_MAX(
143         0, (rArea.Height - maChildRequisition.Height) * fVerFill );
144 
145     aChildArea.X = rArea.X + (sal_Int32)( (rArea.Width - aChildArea.Width) * fHorAlign );
146     aChildArea.Y = rArea.Y + (sal_Int32)( (rArea.Height - aChildArea.Height) * fVerAlign );
147 
148     allocateChildAt( mxChild, aChildArea );
149 }
150 
151 bool
emptyVisible()152 Align::emptyVisible ()
153 {
154     return true;
155 }
156 
157 /* MinSize */
158 
MinSize()159 MinSize::MinSize() : Bin()
160 {
161     mnMinWidth = mnMinHeight = 0;
162     addProp( RTL_CONSTASCII_USTRINGPARAM( "MinWidth" ),
163              ::getCppuType( static_cast< const long* >( NULL ) ),
164              &mnMinWidth );
165     addProp( RTL_CONSTASCII_USTRINGPARAM( "MinHeight" ),
166              ::getCppuType( static_cast< const long* >( NULL ) ),
167              &mnMinHeight );
168 }
169 
170 bool
emptyVisible()171 MinSize::emptyVisible ()
172 {
173     return true;
174 }
175 
getMinimumSize()176 awt::Size SAL_CALL MinSize::getMinimumSize()
177 {
178     Bin::getMinimumSize();
179     maRequisition.Width = SAL_MAX( maRequisition.Width, mnMinWidth );
180     maRequisition.Height = SAL_MAX( maRequisition.Height, mnMinHeight );
181     return maRequisition;
182 }
183 
184 } // namespace layoutimpl
185