1*b0724fc6SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*b0724fc6SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*b0724fc6SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*b0724fc6SAndrew Rist  * distributed with this work for additional information
6*b0724fc6SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*b0724fc6SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*b0724fc6SAndrew Rist  * "License"); you may not use this file except in compliance
9*b0724fc6SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*b0724fc6SAndrew Rist  *
11*b0724fc6SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*b0724fc6SAndrew Rist  *
13*b0724fc6SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*b0724fc6SAndrew Rist  * software distributed under the License is distributed on an
15*b0724fc6SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b0724fc6SAndrew Rist  * KIND, either express or implied.  See the License for the
17*b0724fc6SAndrew Rist  * specific language governing permissions and limitations
18*b0724fc6SAndrew Rist  * under the License.
19*b0724fc6SAndrew Rist  *
20*b0724fc6SAndrew Rist  *************************************************************/
21*b0724fc6SAndrew Rist 
22*b0724fc6SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include "container.hxx"
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #include <com/sun/star/awt/XWindow.hpp>
27cdf0e10cSrcweir #include <com/sun/star/awt/PosSize.hpp>
28cdf0e10cSrcweir #include <tools/debug.hxx>
29cdf0e10cSrcweir 
30cdf0e10cSrcweir namespace layoutimpl {
31cdf0e10cSrcweir 
32cdf0e10cSrcweir using namespace css;
33cdf0e10cSrcweir 
Container()34cdf0e10cSrcweir Container::Container()
35cdf0e10cSrcweir     : Container_Base()
36cdf0e10cSrcweir     , PropHelper()
37cdf0e10cSrcweir     , mnBorderWidth( 0 )
38cdf0e10cSrcweir {
39cdf0e10cSrcweir     addProp( RTL_CONSTASCII_USTRINGPARAM( "Border" ),
40cdf0e10cSrcweir              ::getCppuType( static_cast< const sal_Int32* >( NULL ) ),
41cdf0e10cSrcweir              &mnBorderWidth );
42cdf0e10cSrcweir     setChangeListener( this );
43cdf0e10cSrcweir }
44cdf0e10cSrcweir 
45cdf0e10cSrcweir bool
emptyVisible()46cdf0e10cSrcweir Container::emptyVisible ()
47cdf0e10cSrcweir {
48cdf0e10cSrcweir     return false;
49cdf0e10cSrcweir }
50cdf0e10cSrcweir 
51cdf0e10cSrcweir uno::Any
queryInterface(const uno::Type & rType)52cdf0e10cSrcweir Container::queryInterface( const uno::Type & rType ) throw (uno::RuntimeException)
53cdf0e10cSrcweir {
54cdf0e10cSrcweir     uno::Any aRet = Container_Base::queryInterface( rType );
55cdf0e10cSrcweir     return aRet.hasValue() ? aRet : PropHelper::queryInterface( rType );
56cdf0e10cSrcweir }
57cdf0e10cSrcweir 
58cdf0e10cSrcweir void
allocateChildAt(const uno::Reference<awt::XLayoutConstrains> & xChild,const awt::Rectangle & rArea)59cdf0e10cSrcweir Container::allocateChildAt( const uno::Reference< awt::XLayoutConstrains > &xChild,
60cdf0e10cSrcweir                             const awt::Rectangle &rArea )
61cdf0e10cSrcweir     throw( uno::RuntimeException )
62cdf0e10cSrcweir {
63cdf0e10cSrcweir     uno::Reference< awt::XLayoutContainer > xCont( xChild, uno::UNO_QUERY );
64cdf0e10cSrcweir     if ( xCont.is() )
65cdf0e10cSrcweir         xCont->allocateArea( rArea );
66cdf0e10cSrcweir     else
67cdf0e10cSrcweir     {
68cdf0e10cSrcweir         uno::Reference< awt::XWindow > xWindow( xChild, uno::UNO_QUERY );
69cdf0e10cSrcweir         if ( xWindow.is() )
70cdf0e10cSrcweir             xWindow->setPosSize( rArea.X, rArea.Y, rArea.Width, rArea.Height,
71cdf0e10cSrcweir                                  awt::PosSize::POSSIZE );
72cdf0e10cSrcweir         else
73cdf0e10cSrcweir         {
74cdf0e10cSrcweir             DBG_ERROR( "Error: non-sizeable child" );
75cdf0e10cSrcweir         }
76cdf0e10cSrcweir     }
77cdf0e10cSrcweir }
78cdf0e10cSrcweir 
79cdf0e10cSrcweir uno::Sequence< uno::Reference< awt::XLayoutConstrains > >
getSingleChild(uno::Reference<awt::XLayoutConstrains> const & xChildOrNil)80cdf0e10cSrcweir Container::getSingleChild ( uno::Reference< awt::XLayoutConstrains >const &xChildOrNil )
81cdf0e10cSrcweir {
82cdf0e10cSrcweir     uno::Sequence< uno::Reference< awt::XLayoutConstrains > > aSeq( ( xChildOrNil.is() ? 1 : 0 ) );
83cdf0e10cSrcweir     if ( xChildOrNil.is() )
84cdf0e10cSrcweir         aSeq[0] = xChildOrNil;
85cdf0e10cSrcweir     return aSeq;
86cdf0e10cSrcweir }
87cdf0e10cSrcweir 
88cdf0e10cSrcweir void
queueResize()89cdf0e10cSrcweir Container::queueResize()
90cdf0e10cSrcweir {
91cdf0e10cSrcweir     if ( mxLayoutUnit.is() )
92cdf0e10cSrcweir         mxLayoutUnit->queueResize( uno::Reference< awt::XLayoutContainer >( this ) );
93cdf0e10cSrcweir }
94cdf0e10cSrcweir 
95cdf0e10cSrcweir void
setChildParent(const uno::Reference<awt::XLayoutConstrains> & xChild)96cdf0e10cSrcweir Container::setChildParent( const uno::Reference< awt::XLayoutConstrains >& xChild )
97cdf0e10cSrcweir {
98cdf0e10cSrcweir     uno::Reference< awt::XLayoutContainer > xContChild( xChild, uno::UNO_QUERY );
99cdf0e10cSrcweir     if ( xContChild.is() )
100cdf0e10cSrcweir     {
101cdf0e10cSrcweir         xContChild->setParent( uno::Reference< awt::XLayoutContainer >( this ) );
102cdf0e10cSrcweir #if 0
103cdf0e10cSrcweir         assert( !mxLayoutUnit.is() );
104cdf0e10cSrcweir         xContChild->setLayoutUnit( mxLayoutUnit );
105cdf0e10cSrcweir #endif
106cdf0e10cSrcweir     }
107cdf0e10cSrcweir }
108cdf0e10cSrcweir 
109cdf0e10cSrcweir void
unsetChildParent(const uno::Reference<awt::XLayoutConstrains> & xChild)110cdf0e10cSrcweir Container::unsetChildParent( const uno::Reference< awt::XLayoutConstrains >& xChild )
111cdf0e10cSrcweir {
112cdf0e10cSrcweir     uno::Reference< awt::XLayoutContainer > xContChild( xChild, uno::UNO_QUERY );
113cdf0e10cSrcweir     if ( xContChild.is() )
114cdf0e10cSrcweir     {
115cdf0e10cSrcweir         xContChild->setParent( uno::Reference< awt::XLayoutContainer >() );
116cdf0e10cSrcweir #if 0
117cdf0e10cSrcweir         xContChild->setLayoutUnit( uno::Reference< awt::XLayoutUnit >() );
118cdf0e10cSrcweir #endif
119cdf0e10cSrcweir     }
120cdf0e10cSrcweir }
121cdf0e10cSrcweir 
122cdf0e10cSrcweir #if 0
123cdf0e10cSrcweir std::string
124cdf0e10cSrcweir Container::getLabel()  // debug label
125cdf0e10cSrcweir {
126cdf0e10cSrcweir     std::string depth;
127cdf0e10cSrcweir     uno::Reference< awt::XLayoutContainer > xContainer( this );
128cdf0e10cSrcweir     while ( xContainer.is() )
129cdf0e10cSrcweir     {
130cdf0e10cSrcweir         int node = 0;  // child nb
131cdf0e10cSrcweir         uno::Reference< awt::XLayoutContainer > xParent = xContainer->getContainerParent();
132cdf0e10cSrcweir         if ( xParent.is() )
133cdf0e10cSrcweir         {
134cdf0e10cSrcweir 
135cdf0e10cSrcweir             uno::Sequence< uno::Reference< awt::XLayoutConstrains > > aChildren;
136cdf0e10cSrcweir             aChildren = xParent->getChildren();
137cdf0e10cSrcweir             for ( node = 0; node < aChildren.getLength(); node++ )
138cdf0e10cSrcweir                 if ( aChildren[ node ] == xContainer )
139cdf0e10cSrcweir                     break;
140cdf0e10cSrcweir         }
141cdf0e10cSrcweir 
142cdf0e10cSrcweir         char str[ 8 ];
143cdf0e10cSrcweir         snprintf( str, 8, "%d", node );
144cdf0e10cSrcweir         if ( depth.empty() )
145cdf0e10cSrcweir             depth = std::string( str );
146cdf0e10cSrcweir         else
147cdf0e10cSrcweir             depth = std::string( str ) + ":" + depth;
148cdf0e10cSrcweir 
149cdf0e10cSrcweir         xContainer = xParent;
150cdf0e10cSrcweir     }
151cdf0e10cSrcweir 
152cdf0e10cSrcweir     return std::string( getName() ) + " (" + depth + ")";
153cdf0e10cSrcweir }
154cdf0e10cSrcweir #endif
155cdf0e10cSrcweir 
propertiesChanged()156cdf0e10cSrcweir void Container::propertiesChanged()
157cdf0e10cSrcweir {
158cdf0e10cSrcweir     // cl: why this assertion? This is also called to set properties at the top level widget which has no parent!?
159cdf0e10cSrcweir     // DBG_ASSERT( mxParent.is(), "Properties listener: error container doesn't have parent" );
160cdf0e10cSrcweir 
161cdf0e10cSrcweir     if ( mxLayoutUnit.is() && mxParent.is() )
162cdf0e10cSrcweir         mxLayoutUnit->queueResize( mxParent );
163cdf0e10cSrcweir }
164cdf0e10cSrcweir 
165cdf0e10cSrcweir }
166