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