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 ) throw (uno::RuntimeException) 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 throw( uno::RuntimeException ) 62 { 63 uno::Reference< awt::XLayoutContainer > xCont( xChild, uno::UNO_QUERY ); 64 if ( xCont.is() ) 65 xCont->allocateArea( rArea ); 66 else 67 { 68 uno::Reference< awt::XWindow > xWindow( xChild, uno::UNO_QUERY ); 69 if ( xWindow.is() ) 70 xWindow->setPosSize( rArea.X, rArea.Y, rArea.Width, rArea.Height, 71 awt::PosSize::POSSIZE ); 72 else 73 { 74 DBG_ERROR( "Error: non-sizeable child" ); 75 } 76 } 77 } 78 79 uno::Sequence< uno::Reference< awt::XLayoutConstrains > > 80 Container::getSingleChild ( uno::Reference< awt::XLayoutConstrains >const &xChildOrNil ) 81 { 82 uno::Sequence< uno::Reference< awt::XLayoutConstrains > > aSeq( ( xChildOrNil.is() ? 1 : 0 ) ); 83 if ( xChildOrNil.is() ) 84 aSeq[0] = xChildOrNil; 85 return aSeq; 86 } 87 88 void 89 Container::queueResize() 90 { 91 if ( mxLayoutUnit.is() ) 92 mxLayoutUnit->queueResize( uno::Reference< awt::XLayoutContainer >( this ) ); 93 } 94 95 void 96 Container::setChildParent( const uno::Reference< awt::XLayoutConstrains >& xChild ) 97 { 98 uno::Reference< awt::XLayoutContainer > xContChild( xChild, uno::UNO_QUERY ); 99 if ( xContChild.is() ) 100 { 101 xContChild->setParent( uno::Reference< awt::XLayoutContainer >( this ) ); 102 #if 0 103 assert( !mxLayoutUnit.is() ); 104 xContChild->setLayoutUnit( mxLayoutUnit ); 105 #endif 106 } 107 } 108 109 void 110 Container::unsetChildParent( const uno::Reference< awt::XLayoutConstrains >& xChild ) 111 { 112 uno::Reference< awt::XLayoutContainer > xContChild( xChild, uno::UNO_QUERY ); 113 if ( xContChild.is() ) 114 { 115 xContChild->setParent( uno::Reference< awt::XLayoutContainer >() ); 116 #if 0 117 xContChild->setLayoutUnit( uno::Reference< awt::XLayoutUnit >() ); 118 #endif 119 } 120 } 121 122 #if 0 123 std::string 124 Container::getLabel() // debug label 125 { 126 std::string depth; 127 uno::Reference< awt::XLayoutContainer > xContainer( this ); 128 while ( xContainer.is() ) 129 { 130 int node = 0; // child nb 131 uno::Reference< awt::XLayoutContainer > xParent = xContainer->getContainerParent(); 132 if ( xParent.is() ) 133 { 134 135 uno::Sequence< uno::Reference< awt::XLayoutConstrains > > aChildren; 136 aChildren = xParent->getChildren(); 137 for ( node = 0; node < aChildren.getLength(); node++ ) 138 if ( aChildren[ node ] == xContainer ) 139 break; 140 } 141 142 char str[ 8 ]; 143 snprintf( str, 8, "%d", node ); 144 if ( depth.empty() ) 145 depth = std::string( str ); 146 else 147 depth = std::string( str ) + ":" + depth; 148 149 xContainer = xParent; 150 } 151 152 return std::string( getName() ) + " (" + depth + ")"; 153 } 154 #endif 155 156 void Container::propertiesChanged() 157 { 158 // cl: why this assertion? This is also called to set properties at the top level widget which has no parent!? 159 // DBG_ASSERT( mxParent.is(), "Properties listener: error container doesn't have parent" ); 160 161 if ( mxLayoutUnit.is() && mxParent.is() ) 162 mxLayoutUnit->queueResize( mxParent ); 163 } 164 165 } 166