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