1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
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
{
42 Container::Container()
47 addProp( RTL_CONSTASCII_USTRINGPARAM( "Border" ),
48 ::getCppuType( static_cast< const sal_Int32
* >( NULL
) ),
50 setChangeListener( this );
54 Container::emptyVisible ()
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
);
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
);
73 xCont
->allocateArea( rArea
);
76 uno::Reference
< awt::XWindow
> xWindow( xChild
, uno::UNO_QUERY
);
78 xWindow
->setPosSize( rArea
.X
, rArea
.Y
, rArea
.Width
, rArea
.Height
,
79 awt::PosSize::POSSIZE
);
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
;
97 Container::queueResize()
99 if ( mxLayoutUnit
.is() )
100 mxLayoutUnit
->queueResize( uno::Reference
< awt::XLayoutContainer
>( this ) );
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 ) );
111 assert( !mxLayoutUnit
.is() );
112 xContChild
->setLayoutUnit( mxLayoutUnit
);
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
>() );
125 xContChild
->setLayoutUnit( uno::Reference
< awt::XLayoutUnit
>() );
132 Container::getLabel() // debug label
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();
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
)
151 snprintf( str
, 8, "%d", node
);
153 depth
= std::string( str
);
155 depth
= std::string( str
) + ":" + depth
;
157 xContainer
= xParent
;
160 return std::string( getName() ) + " (" + depth
+ ")";
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
);