merge the formfield patch from ooo-build
[ooovba.git] / toolkit / source / layout / core / container.cxx
blob608d5a4a09245b618466f511eae16271f381e3c2
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile$
11 * $Revision$
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 ************************************************************************/
32 #include "container.hxx"
34 #include <com/sun/star/awt/XWindow.hpp>
35 #include <com/sun/star/awt/PosSize.hpp>
36 #include <tools/debug.hxx>
38 namespace layoutimpl {
40 using namespace css;
42 Container::Container()
43 : Container_Base()
44 , PropHelper()
45 , mnBorderWidth( 0 )
47 addProp( RTL_CONSTASCII_USTRINGPARAM( "Border" ),
48 ::getCppuType( static_cast< const sal_Int32* >( NULL ) ),
49 &mnBorderWidth );
50 setChangeListener( this );
53 bool
54 Container::emptyVisible ()
56 return false;
59 uno::Any
60 Container::queryInterface( const uno::Type & rType ) throw (uno::RuntimeException)
62 uno::Any aRet = Container_Base::queryInterface( rType );
63 return aRet.hasValue() ? aRet : PropHelper::queryInterface( rType );
66 void
67 Container::allocateChildAt( const uno::Reference< awt::XLayoutConstrains > &xChild,
68 const awt::Rectangle &rArea )
69 throw( uno::RuntimeException )
71 uno::Reference< awt::XLayoutContainer > xCont( xChild, uno::UNO_QUERY );
72 if ( xCont.is() )
73 xCont->allocateArea( rArea );
74 else
76 uno::Reference< awt::XWindow > xWindow( xChild, uno::UNO_QUERY );
77 if ( xWindow.is() )
78 xWindow->setPosSize( rArea.X, rArea.Y, rArea.Width, rArea.Height,
79 awt::PosSize::POSSIZE );
80 else
82 DBG_ERROR( "Error: non-sizeable child" );
87 uno::Sequence< uno::Reference< awt::XLayoutConstrains > >
88 Container::getSingleChild ( uno::Reference< awt::XLayoutConstrains >const &xChildOrNil )
90 uno::Sequence< uno::Reference< awt::XLayoutConstrains > > aSeq( ( xChildOrNil.is() ? 1 : 0 ) );
91 if ( xChildOrNil.is() )
92 aSeq[0] = xChildOrNil;
93 return aSeq;
96 void
97 Container::queueResize()
99 if ( mxLayoutUnit.is() )
100 mxLayoutUnit->queueResize( uno::Reference< awt::XLayoutContainer >( this ) );
103 void
104 Container::setChildParent( const uno::Reference< awt::XLayoutConstrains >& xChild )
106 uno::Reference< awt::XLayoutContainer > xContChild( xChild, uno::UNO_QUERY );
107 if ( xContChild.is() )
109 xContChild->setParent( uno::Reference< awt::XLayoutContainer >( this ) );
110 #if 0
111 assert( !mxLayoutUnit.is() );
112 xContChild->setLayoutUnit( mxLayoutUnit );
113 #endif
117 void
118 Container::unsetChildParent( const uno::Reference< awt::XLayoutConstrains >& xChild )
120 uno::Reference< awt::XLayoutContainer > xContChild( xChild, uno::UNO_QUERY );
121 if ( xContChild.is() )
123 xContChild->setParent( uno::Reference< awt::XLayoutContainer >() );
124 #if 0
125 xContChild->setLayoutUnit( uno::Reference< awt::XLayoutUnit >() );
126 #endif
130 #if 0
131 std::string
132 Container::getLabel() // debug label
134 std::string depth;
135 uno::Reference< awt::XLayoutContainer > xContainer( this );
136 while ( xContainer.is() )
138 int node = 0; // child nb
139 uno::Reference< awt::XLayoutContainer > xParent = xContainer->getContainerParent();
140 if ( xParent.is() )
143 uno::Sequence< uno::Reference< awt::XLayoutConstrains > > aChildren;
144 aChildren = xParent->getChildren();
145 for ( node = 0; node < aChildren.getLength(); node++ )
146 if ( aChildren[ node ] == xContainer )
147 break;
150 char str[ 8 ];
151 snprintf( str, 8, "%d", node );
152 if ( depth.empty() )
153 depth = std::string( str );
154 else
155 depth = std::string( str ) + ":" + depth;
157 xContainer = xParent;
160 return std::string( getName() ) + " (" + depth + ")";
162 #endif
164 void Container::propertiesChanged()
166 // cl: why this assertion? This is also called to set properties at the top level widget which has no parent!?
167 // DBG_ASSERT( mxParent.is(), "Properties listener: error container doesn't have parent" );
169 if ( mxLayoutUnit.is() && mxParent.is() )
170 mxLayoutUnit->queueResize( mxParent );