1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #include "bin.hxx" 29 30 #include <sal/macros.h> 31 32 namespace layoutimpl 33 { 34 35 using namespace css; 36 37 /* Bin */ 38 39 Bin::Bin() : Container() 40 { 41 } 42 43 void SAL_CALL 44 Bin::addChild( const uno::Reference< awt::XLayoutConstrains >& xChild ) 45 throw (uno::RuntimeException, awt::MaxChildrenException) 46 { 47 if ( mxChild.is() ) 48 throw awt::MaxChildrenException(); 49 if ( xChild.is() ) 50 { 51 mxChild = xChild; 52 setChildParent( xChild ); 53 queueResize(); 54 } 55 } 56 57 void SAL_CALL 58 Bin::removeChild( const uno::Reference< awt::XLayoutConstrains >& xChild ) 59 throw (uno::RuntimeException) 60 { 61 if ( xChild == mxChild ) 62 { 63 mxChild = uno::Reference< awt::XLayoutConstrains >(); 64 unsetChildParent( xChild ); 65 queueResize(); 66 } 67 } 68 69 uno::Sequence< uno::Reference< awt::XLayoutConstrains > > SAL_CALL 70 Bin::getChildren() 71 throw (uno::RuntimeException) 72 { 73 return getSingleChild (mxChild); 74 } 75 76 void SAL_CALL 77 Bin::allocateArea( const awt::Rectangle &rArea ) 78 throw (uno::RuntimeException) 79 { 80 maAllocation = rArea; 81 if ( mxChild.is() ) 82 allocateChildAt( mxChild, rArea ); 83 } 84 85 awt::Size SAL_CALL 86 Bin::getMinimumSize() 87 throw(uno::RuntimeException) 88 { 89 if ( mxChild.is() ) 90 return maRequisition = maChildRequisition = mxChild->getMinimumSize(); 91 return maRequisition = awt::Size( 0, 0 ); 92 } 93 94 uno::Reference< beans::XPropertySet > SAL_CALL 95 Bin::getChildProperties( const uno::Reference< awt::XLayoutConstrains >& ) 96 throw (uno::RuntimeException) 97 { 98 return uno::Reference< beans::XPropertySet >(); 99 } 100 101 sal_Bool SAL_CALL 102 Bin::hasHeightForWidth() 103 throw(uno::RuntimeException) 104 { 105 uno::Reference< awt::XLayoutContainer > xChildCont( mxChild, uno::UNO_QUERY ); 106 if ( xChildCont.is() ) 107 return xChildCont->hasHeightForWidth(); 108 return false; 109 } 110 111 sal_Int32 SAL_CALL 112 Bin::getHeightForWidth( sal_Int32 nWidth ) 113 throw(uno::RuntimeException) 114 { 115 uno::Reference< awt::XLayoutContainer > xChildCont( mxChild, uno::UNO_QUERY ); 116 if ( xChildCont.is() ) 117 return xChildCont->getHeightForWidth( nWidth ); 118 return maRequisition.Height; 119 } 120 121 /* Align */ 122 123 Align::Align() : Bin() 124 { 125 addProp( RTL_CONSTASCII_USTRINGPARAM( "Halign" ), 126 ::getCppuType( static_cast< const float* >( NULL ) ), 127 &fHorAlign ); 128 addProp( RTL_CONSTASCII_USTRINGPARAM( "Valign" ), 129 ::getCppuType( static_cast< const float* >( NULL ) ), 130 &fVerAlign ); 131 addProp( RTL_CONSTASCII_USTRINGPARAM( "Hfill" ), 132 ::getCppuType( static_cast< const float* >( NULL ) ), 133 &fHorFill ); 134 addProp( RTL_CONSTASCII_USTRINGPARAM( "Vfill" ), 135 ::getCppuType( static_cast< const float* >( NULL ) ), 136 &fVerFill ); 137 138 fHorAlign = fVerAlign = 0.5; 139 fHorFill = fVerFill = 0; 140 } 141 142 void SAL_CALL 143 Align::allocateArea( const awt::Rectangle &rArea ) 144 throw (uno::RuntimeException) 145 { 146 maAllocation = rArea; 147 if ( !mxChild.is() ) 148 return; 149 150 awt::Rectangle aChildArea; 151 aChildArea.Width = SAL_MIN( rArea.Width, maChildRequisition.Width ); 152 aChildArea.Width += (sal_Int32) SAL_MAX( 153 0, (rArea.Width - maChildRequisition.Width) * fHorFill ); 154 aChildArea.Height = SAL_MIN( rArea.Height, maChildRequisition.Height ); 155 aChildArea.Height += (sal_Int32) SAL_MAX( 156 0, (rArea.Height - maChildRequisition.Height) * fVerFill ); 157 158 aChildArea.X = rArea.X + (sal_Int32)( (rArea.Width - aChildArea.Width) * fHorAlign ); 159 aChildArea.Y = rArea.Y + (sal_Int32)( (rArea.Height - aChildArea.Height) * fVerAlign ); 160 161 allocateChildAt( mxChild, aChildArea ); 162 } 163 164 bool 165 Align::emptyVisible () 166 { 167 return true; 168 } 169 170 /* MinSize */ 171 172 MinSize::MinSize() : Bin() 173 { 174 mnMinWidth = mnMinHeight = 0; 175 addProp( RTL_CONSTASCII_USTRINGPARAM( "MinWidth" ), 176 ::getCppuType( static_cast< const long* >( NULL ) ), 177 &mnMinWidth ); 178 addProp( RTL_CONSTASCII_USTRINGPARAM( "MinHeight" ), 179 ::getCppuType( static_cast< const long* >( NULL ) ), 180 &mnMinHeight ); 181 } 182 183 bool 184 MinSize::emptyVisible () 185 { 186 return true; 187 } 188 189 awt::Size SAL_CALL MinSize::getMinimumSize() 190 throw(uno::RuntimeException) 191 { 192 Bin::getMinimumSize(); 193 maRequisition.Width = SAL_MAX( maRequisition.Width, mnMinWidth ); 194 maRequisition.Height = SAL_MAX( maRequisition.Height, mnMinHeight ); 195 return maRequisition; 196 } 197 198 } // namespace layoutimpl 199