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
10cdf0e10cSrcweir *
11*b0724fc6SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
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.
19cdf0e10cSrcweir *
20*b0724fc6SAndrew Rist *************************************************************/
21*b0724fc6SAndrew Rist
22*b0724fc6SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir #include "box.hxx"
25cdf0e10cSrcweir
26cdf0e10cSrcweir #include <tools/debug.hxx>
27cdf0e10cSrcweir #include <sal/macros.h>
28cdf0e10cSrcweir
29cdf0e10cSrcweir #include <com/sun/star/awt/XWindow2.hpp>
30cdf0e10cSrcweir
31cdf0e10cSrcweir // fixed point precision for distributing error
32cdf0e10cSrcweir #define FIXED_PT 16
33cdf0e10cSrcweir
34cdf0e10cSrcweir namespace layoutimpl
35cdf0e10cSrcweir {
36cdf0e10cSrcweir
37cdf0e10cSrcweir using namespace css;
38cdf0e10cSrcweir
ChildData(uno::Reference<awt::XLayoutConstrains> const & xChild)39cdf0e10cSrcweir Box_Base::ChildData::ChildData( uno::Reference< awt::XLayoutConstrains > const& xChild )
40cdf0e10cSrcweir : mxChild( xChild )
41cdf0e10cSrcweir , mxProps()
42cdf0e10cSrcweir , maRequisition()
43cdf0e10cSrcweir {
44cdf0e10cSrcweir }
45cdf0e10cSrcweir
isVisible(uno::Reference<awt::XLayoutConstrains> xWidget)46cdf0e10cSrcweir static bool isVisible( uno::Reference< awt::XLayoutConstrains > xWidget )
47cdf0e10cSrcweir {
48cdf0e10cSrcweir if ( !xWidget.is() )
49cdf0e10cSrcweir {
50cdf0e10cSrcweir DBG_ERROR( "FIXME: invalid child !" );
51cdf0e10cSrcweir return true;
52cdf0e10cSrcweir }
53cdf0e10cSrcweir
54cdf0e10cSrcweir uno::Reference< awt::XWindow2 > xWindow( xWidget, uno::UNO_QUERY );
55cdf0e10cSrcweir if ( xWindow.is() && !xWindow->isVisible() )
56cdf0e10cSrcweir return false;
57cdf0e10cSrcweir
58cdf0e10cSrcweir uno::Reference< awt::XLayoutContainer > xContainer( xWidget, uno::UNO_QUERY );
59cdf0e10cSrcweir if ( xContainer.is() )
60cdf0e10cSrcweir {
61cdf0e10cSrcweir uno::Sequence< uno::Reference< awt::XLayoutConstrains > > aChildren
62cdf0e10cSrcweir = xContainer->getChildren();
63cdf0e10cSrcweir
64cdf0e10cSrcweir if (!aChildren.getLength ())
65cdf0e10cSrcweir if (Container *c = dynamic_cast <Container*> (xWidget.get ()))
66cdf0e10cSrcweir return c->emptyVisible ();
67cdf0e10cSrcweir
68cdf0e10cSrcweir for ( int i = 0; i < aChildren.getLength(); i++ )
69cdf0e10cSrcweir if ( isVisible( aChildren[i] ) )
70cdf0e10cSrcweir return true;
71cdf0e10cSrcweir return false; // this would kill flow without workaround above
72cdf0e10cSrcweir }
73cdf0e10cSrcweir
74cdf0e10cSrcweir return true;
75cdf0e10cSrcweir }
76cdf0e10cSrcweir
isVisible()77cdf0e10cSrcweir bool Box_Base::ChildData::isVisible()
78cdf0e10cSrcweir {
79cdf0e10cSrcweir // FIXME: call the 'isVisible' method on it ?
80cdf0e10cSrcweir return layoutimpl::isVisible( mxChild );
81cdf0e10cSrcweir }
82cdf0e10cSrcweir
83cdf0e10cSrcweir void
AddChild(uno::Reference<awt::XLayoutConstrains> const & xChild)84cdf0e10cSrcweir Box_Base::AddChild (uno::Reference <awt::XLayoutConstrains> const& xChild)
85cdf0e10cSrcweir {
86cdf0e10cSrcweir ChildData *pData = createChild (xChild);
87cdf0e10cSrcweir maChildren.push_back (pData);
88cdf0e10cSrcweir queueResize ();
89cdf0e10cSrcweir }
90cdf0e10cSrcweir
91cdf0e10cSrcweir void SAL_CALL
addChild(uno::Reference<awt::XLayoutConstrains> const & xChild)92cdf0e10cSrcweir Box_Base::addChild (uno::Reference <awt::XLayoutConstrains> const& xChild)
93cdf0e10cSrcweir throw (uno::RuntimeException, awt::MaxChildrenException)
94cdf0e10cSrcweir {
95cdf0e10cSrcweir if (xChild.is ())
96cdf0e10cSrcweir {
97cdf0e10cSrcweir AddChild (xChild);
98cdf0e10cSrcweir setChildParent (xChild);
99cdf0e10cSrcweir }
100cdf0e10cSrcweir }
101cdf0e10cSrcweir
102cdf0e10cSrcweir Box_Base::ChildData*
removeChildData(std::list<ChildData * > & lst,css::uno::Reference<css::awt::XLayoutConstrains> const & xChild)103cdf0e10cSrcweir Box_Base::removeChildData( std::list< ChildData* >& lst, css::uno::Reference< css::awt::XLayoutConstrains > const& xChild )
104cdf0e10cSrcweir {
105cdf0e10cSrcweir for ( std::list< ChildData* >::iterator it = lst.begin();
106cdf0e10cSrcweir it != lst.end(); it++ )
107cdf0e10cSrcweir {
108cdf0e10cSrcweir if ( (*it)->mxChild == xChild )
109cdf0e10cSrcweir {
110cdf0e10cSrcweir ChildData* pRet = *it;
111cdf0e10cSrcweir lst.erase( it );
112cdf0e10cSrcweir return pRet;
113cdf0e10cSrcweir }
114cdf0e10cSrcweir }
115cdf0e10cSrcweir return 0;
116cdf0e10cSrcweir }
117cdf0e10cSrcweir
118cdf0e10cSrcweir void SAL_CALL
removeChild(const uno::Reference<awt::XLayoutConstrains> & xChild)119cdf0e10cSrcweir Box_Base::removeChild( const uno::Reference< awt::XLayoutConstrains >& xChild )
120cdf0e10cSrcweir throw (uno::RuntimeException)
121cdf0e10cSrcweir {
122cdf0e10cSrcweir if ( ChildData* p = removeChildData( maChildren, xChild ) )
123cdf0e10cSrcweir {
124cdf0e10cSrcweir delete p;
125cdf0e10cSrcweir unsetChildParent( xChild );
126cdf0e10cSrcweir queueResize();
127cdf0e10cSrcweir }
128cdf0e10cSrcweir else
129cdf0e10cSrcweir {
130cdf0e10cSrcweir DBG_ERROR( "Box_Base: removeChild: no such child" );
131cdf0e10cSrcweir }
132cdf0e10cSrcweir }
133cdf0e10cSrcweir
134cdf0e10cSrcweir uno::Sequence< uno::Reference < awt::XLayoutConstrains > > SAL_CALL
getChildren()135cdf0e10cSrcweir Box_Base::getChildren()
136cdf0e10cSrcweir throw (uno::RuntimeException)
137cdf0e10cSrcweir {
138cdf0e10cSrcweir uno::Sequence< uno::Reference< awt::XLayoutConstrains > > children( maChildren.size() );
139cdf0e10cSrcweir unsigned int index = 0;
140cdf0e10cSrcweir for ( std::list< ChildData* >::iterator it = maChildren.begin();
141cdf0e10cSrcweir it != maChildren.end(); it++, index++ )
142cdf0e10cSrcweir children[index] = ( *it )->mxChild;
143cdf0e10cSrcweir
144cdf0e10cSrcweir return children;
145cdf0e10cSrcweir }
146cdf0e10cSrcweir
147cdf0e10cSrcweir uno::Reference< beans::XPropertySet > SAL_CALL
getChildProperties(const uno::Reference<awt::XLayoutConstrains> & xChild)148cdf0e10cSrcweir Box_Base::getChildProperties( const uno::Reference< awt::XLayoutConstrains >& xChild )
149cdf0e10cSrcweir throw (uno::RuntimeException)
150cdf0e10cSrcweir {
151cdf0e10cSrcweir
152cdf0e10cSrcweir for ( std::list< ChildData * >::iterator it = maChildren.begin();
153cdf0e10cSrcweir it != maChildren.end(); it++)
154cdf0e10cSrcweir {
155cdf0e10cSrcweir if ( ( *it )->mxChild == xChild )
156cdf0e10cSrcweir {
157cdf0e10cSrcweir if ( !( *it )->mxProps.is() )
158cdf0e10cSrcweir {
159cdf0e10cSrcweir PropHelper *pProps = createChildProps( *it );
160cdf0e10cSrcweir pProps->setChangeListener( this );
161cdf0e10cSrcweir ( *it )->mxProps = pProps;
162cdf0e10cSrcweir }
163cdf0e10cSrcweir return (*it)->mxProps;
164cdf0e10cSrcweir }
165cdf0e10cSrcweir }
166cdf0e10cSrcweir return uno::Reference< beans::XPropertySet >();
167cdf0e10cSrcweir }
168cdf0e10cSrcweir
169cdf0e10cSrcweir } // namespace layoutimpl
170