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 "container.hxx" 29 30 #include <com/sun/star/awt/XWindow.hpp> 31 #include <com/sun/star/awt/PosSize.hpp> 32 #include <tools/debug.hxx> 33 34 namespace layoutimpl { 35 36 using namespace css; 37 38 Container::Container() 39 : Container_Base() 40 , PropHelper() 41 , mnBorderWidth( 0 ) 42 { 43 addProp( RTL_CONSTASCII_USTRINGPARAM( "Border" ), 44 ::getCppuType( static_cast< const sal_Int32* >( NULL ) ), 45 &mnBorderWidth ); 46 setChangeListener( this ); 47 } 48 49 bool 50 Container::emptyVisible () 51 { 52 return false; 53 } 54 55 uno::Any 56 Container::queryInterface( const uno::Type & rType ) throw (uno::RuntimeException) 57 { 58 uno::Any aRet = Container_Base::queryInterface( rType ); 59 return aRet.hasValue() ? aRet : PropHelper::queryInterface( rType ); 60 } 61 62 void 63 Container::allocateChildAt( const uno::Reference< awt::XLayoutConstrains > &xChild, 64 const awt::Rectangle &rArea ) 65 throw( uno::RuntimeException ) 66 { 67 uno::Reference< awt::XLayoutContainer > xCont( xChild, uno::UNO_QUERY ); 68 if ( xCont.is() ) 69 xCont->allocateArea( rArea ); 70 else 71 { 72 uno::Reference< awt::XWindow > xWindow( xChild, uno::UNO_QUERY ); 73 if ( xWindow.is() ) 74 xWindow->setPosSize( rArea.X, rArea.Y, rArea.Width, rArea.Height, 75 awt::PosSize::POSSIZE ); 76 else 77 { 78 DBG_ERROR( "Error: non-sizeable child" ); 79 } 80 } 81 } 82 83 uno::Sequence< uno::Reference< awt::XLayoutConstrains > > 84 Container::getSingleChild ( uno::Reference< awt::XLayoutConstrains >const &xChildOrNil ) 85 { 86 uno::Sequence< uno::Reference< awt::XLayoutConstrains > > aSeq( ( xChildOrNil.is() ? 1 : 0 ) ); 87 if ( xChildOrNil.is() ) 88 aSeq[0] = xChildOrNil; 89 return aSeq; 90 } 91 92 void 93 Container::queueResize() 94 { 95 if ( mxLayoutUnit.is() ) 96 mxLayoutUnit->queueResize( uno::Reference< awt::XLayoutContainer >( this ) ); 97 } 98 99 void 100 Container::setChildParent( const uno::Reference< awt::XLayoutConstrains >& xChild ) 101 { 102 uno::Reference< awt::XLayoutContainer > xContChild( xChild, uno::UNO_QUERY ); 103 if ( xContChild.is() ) 104 { 105 xContChild->setParent( uno::Reference< awt::XLayoutContainer >( this ) ); 106 #if 0 107 assert( !mxLayoutUnit.is() ); 108 xContChild->setLayoutUnit( mxLayoutUnit ); 109 #endif 110 } 111 } 112 113 void 114 Container::unsetChildParent( const uno::Reference< awt::XLayoutConstrains >& xChild ) 115 { 116 uno::Reference< awt::XLayoutContainer > xContChild( xChild, uno::UNO_QUERY ); 117 if ( xContChild.is() ) 118 { 119 xContChild->setParent( uno::Reference< awt::XLayoutContainer >() ); 120 #if 0 121 xContChild->setLayoutUnit( uno::Reference< awt::XLayoutUnit >() ); 122 #endif 123 } 124 } 125 126 #if 0 127 std::string 128 Container::getLabel() // debug label 129 { 130 std::string depth; 131 uno::Reference< awt::XLayoutContainer > xContainer( this ); 132 while ( xContainer.is() ) 133 { 134 int node = 0; // child nb 135 uno::Reference< awt::XLayoutContainer > xParent = xContainer->getContainerParent(); 136 if ( xParent.is() ) 137 { 138 139 uno::Sequence< uno::Reference< awt::XLayoutConstrains > > aChildren; 140 aChildren = xParent->getChildren(); 141 for ( node = 0; node < aChildren.getLength(); node++ ) 142 if ( aChildren[ node ] == xContainer ) 143 break; 144 } 145 146 char str[ 8 ]; 147 snprintf( str, 8, "%d", node ); 148 if ( depth.empty() ) 149 depth = std::string( str ); 150 else 151 depth = std::string( str ) + ":" + depth; 152 153 xContainer = xParent; 154 } 155 156 return std::string( getName() ) + " (" + depth + ")"; 157 } 158 #endif 159 160 void Container::propertiesChanged() 161 { 162 // cl: why this assertion? This is also called to set properties at the top level widget which has no parent!? 163 // DBG_ASSERT( mxParent.is(), "Properties listener: error container doesn't have parent" ); 164 165 if ( mxLayoutUnit.is() && mxParent.is() ) 166 mxLayoutUnit->queueResize( mxParent ); 167 } 168 169 } 170