xref: /AOO41X/main/toolkit/source/layout/vcl/wcontainer.cxx (revision b0724fc6948542b2496e16ea247f985ee5987cfe)
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 "wrapper.hxx"
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #include <com/sun/star/awt/XLayoutRoot.hpp>
27cdf0e10cSrcweir #include <com/sun/star/awt/XLayoutContainer.hpp>
28cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
29cdf0e10cSrcweir #include <layout/core/helper.hxx>
30cdf0e10cSrcweir #include <tools/debug.hxx>
31cdf0e10cSrcweir 
32cdf0e10cSrcweir using namespace ::com::sun::star;
33cdf0e10cSrcweir 
34cdf0e10cSrcweir namespace layout
35cdf0e10cSrcweir {
36cdf0e10cSrcweir 
Container(Context const * context,char const * pId)37cdf0e10cSrcweir Container::Container( Context const* context, char const* pId )
38cdf0e10cSrcweir     : mxContainer( context->GetPeerHandle( pId ), uno::UNO_QUERY )
39cdf0e10cSrcweir {
40cdf0e10cSrcweir     if ( !mxContainer.is() )
41cdf0e10cSrcweir     {
42cdf0e10cSrcweir         DBG_ERROR1( "Error: failed to associate container with '%s'", pId );
43cdf0e10cSrcweir     }
44cdf0e10cSrcweir }
45cdf0e10cSrcweir 
Container(rtl::OUString const & rName,sal_Int32 nBorder)46cdf0e10cSrcweir Container::Container( rtl::OUString const& rName, sal_Int32 nBorder )
47cdf0e10cSrcweir {
48cdf0e10cSrcweir     mxContainer = layoutimpl::WidgetFactory::createContainer( rName );
49cdf0e10cSrcweir 
50cdf0e10cSrcweir     uno::Reference< beans::XPropertySet > xProps( mxContainer, uno::UNO_QUERY_THROW );
51cdf0e10cSrcweir     xProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Border" ) ),
52cdf0e10cSrcweir                               uno::Any( nBorder ) );
53cdf0e10cSrcweir }
54cdf0e10cSrcweir 
Add(Window * pChild)55cdf0e10cSrcweir void Container::Add( Window *pChild )
56cdf0e10cSrcweir {
57cdf0e10cSrcweir     if ( pChild )
58cdf0e10cSrcweir     {
59cdf0e10cSrcweir         uno::Reference< awt::XLayoutConstrains > xChild( pChild->GetPeer(), uno::UNO_QUERY );
60cdf0e10cSrcweir         mxContainer->addChild( xChild );
61cdf0e10cSrcweir     }
62cdf0e10cSrcweir }
63cdf0e10cSrcweir 
Add(Container * pChild)64cdf0e10cSrcweir void Container::Add( Container *pChild )
65cdf0e10cSrcweir {
66cdf0e10cSrcweir     if ( pChild )
67cdf0e10cSrcweir     {
68cdf0e10cSrcweir         uno::Reference< awt::XLayoutConstrains > xChild( pChild->getImpl(), uno::UNO_QUERY );
69cdf0e10cSrcweir         mxContainer->addChild( xChild );
70cdf0e10cSrcweir     }
71cdf0e10cSrcweir }
72cdf0e10cSrcweir 
Remove(Window * pChild)73cdf0e10cSrcweir void Container::Remove( Window *pChild )
74cdf0e10cSrcweir {
75cdf0e10cSrcweir     if ( pChild )
76cdf0e10cSrcweir     {
77cdf0e10cSrcweir         uno::Reference< awt::XLayoutConstrains > xChild( pChild->GetPeer(), uno::UNO_QUERY );
78cdf0e10cSrcweir         mxContainer->removeChild( xChild );
79cdf0e10cSrcweir     }
80cdf0e10cSrcweir }
81cdf0e10cSrcweir 
Remove(Container * pChild)82cdf0e10cSrcweir void Container::Remove( Container *pChild )
83cdf0e10cSrcweir {
84cdf0e10cSrcweir     if ( pChild )
85cdf0e10cSrcweir     {
86cdf0e10cSrcweir         uno::Reference< awt::XLayoutConstrains > xChild( pChild->getImpl(), uno::UNO_QUERY );
87cdf0e10cSrcweir         mxContainer->removeChild( xChild );
88cdf0e10cSrcweir     }
89cdf0e10cSrcweir }
90cdf0e10cSrcweir 
Clear()91cdf0e10cSrcweir void Container::Clear()
92cdf0e10cSrcweir {
93cdf0e10cSrcweir     css::uno::Sequence< css::uno::Reference < css::awt::XLayoutConstrains > > children;
94cdf0e10cSrcweir     children = mxContainer->getChildren();
95cdf0e10cSrcweir     for (int i = 0; i < children.getLength(); i++)
96cdf0e10cSrcweir         mxContainer->removeChild( children[i] );
97cdf0e10cSrcweir }
98cdf0e10cSrcweir 
ShowAll(bool bShow)99cdf0e10cSrcweir void Container::ShowAll( bool bShow )
100cdf0e10cSrcweir {
101cdf0e10cSrcweir     struct inner
102cdf0e10cSrcweir     {
103cdf0e10cSrcweir         static void setChildrenVisible( uno::Reference < awt::XLayoutContainer > xCont,
104cdf0e10cSrcweir                                         bool bVisible )  /* auxiliary */
105cdf0e10cSrcweir         {
106cdf0e10cSrcweir             if ( xCont.is() )
107cdf0e10cSrcweir             {
108cdf0e10cSrcweir                 uno::Sequence< uno::Reference < awt::XLayoutConstrains > > aChildren;
109cdf0e10cSrcweir                 aChildren = xCont->getChildren();
110cdf0e10cSrcweir                 for (int i = 0; i < aChildren.getLength(); i++)
111cdf0e10cSrcweir                 {
112cdf0e10cSrcweir                     uno::Reference < awt::XLayoutConstrains > xChild( aChildren[ i ] );
113cdf0e10cSrcweir 
114cdf0e10cSrcweir                     uno::Reference< awt::XWindow > xWin( xChild, uno::UNO_QUERY);
115cdf0e10cSrcweir                     if ( xWin.is() )
116cdf0e10cSrcweir                         xWin->setVisible( bVisible );
117cdf0e10cSrcweir 
118cdf0e10cSrcweir                     uno::Reference < awt::XLayoutContainer > xChildCont(
119cdf0e10cSrcweir                         xChild, uno::UNO_QUERY );
120cdf0e10cSrcweir                     setChildrenVisible( xChildCont, bVisible );
121cdf0e10cSrcweir                 }
122cdf0e10cSrcweir             }
123cdf0e10cSrcweir         }
124cdf0e10cSrcweir     };
125cdf0e10cSrcweir 
126cdf0e10cSrcweir     inner::setChildrenVisible( mxContainer, bShow );
127cdf0e10cSrcweir }
128cdf0e10cSrcweir 
Show()129cdf0e10cSrcweir void Container::Show()
130cdf0e10cSrcweir {
131cdf0e10cSrcweir     ShowAll( true );
132cdf0e10cSrcweir }
133cdf0e10cSrcweir 
Hide()134cdf0e10cSrcweir void Container::Hide()
135cdf0e10cSrcweir {
136cdf0e10cSrcweir     ShowAll( false );
137cdf0e10cSrcweir }
138cdf0e10cSrcweir 
Table(sal_Int32 nBorder,sal_Int32 nColumns)139cdf0e10cSrcweir Table::Table( sal_Int32 nBorder, sal_Int32 nColumns )
140cdf0e10cSrcweir     : Container( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "table" ) ), nBorder )
141cdf0e10cSrcweir {
142cdf0e10cSrcweir     uno::Reference< beans::XPropertySet > xProps( mxContainer, uno::UNO_QUERY_THROW );
143cdf0e10cSrcweir     xProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Columns" ) ),
144cdf0e10cSrcweir                               uno::Any( nColumns ) );
145cdf0e10cSrcweir }
146cdf0e10cSrcweir 
Add(Window * window,bool bXExpand,bool bYExpand,sal_Int32 nXSpan,sal_Int32 nYSpan)147cdf0e10cSrcweir void Table::Add( Window *window, bool bXExpand, bool bYExpand,
148cdf0e10cSrcweir                  sal_Int32 nXSpan, sal_Int32 nYSpan )
149cdf0e10cSrcweir {
150cdf0e10cSrcweir     if ( !window )
151cdf0e10cSrcweir         return;
152cdf0e10cSrcweir     WindowImpl &rImpl = window->getImpl();
153cdf0e10cSrcweir     uno::Reference< awt::XLayoutConstrains > xChild( rImpl.mxWindow,
154cdf0e10cSrcweir                                                      uno::UNO_QUERY );
155cdf0e10cSrcweir     mxContainer->addChild( xChild );
156cdf0e10cSrcweir     setProps( xChild, bXExpand, bYExpand, nXSpan, nYSpan );
157cdf0e10cSrcweir }
158cdf0e10cSrcweir 
Add(Container * pContainer,bool bXExpand,bool bYExpand,sal_Int32 nXSpan,sal_Int32 nYSpan)159cdf0e10cSrcweir void Table::Add( Container *pContainer, bool bXExpand, bool bYExpand,
160cdf0e10cSrcweir                  sal_Int32 nXSpan, sal_Int32 nYSpan )
161cdf0e10cSrcweir {
162cdf0e10cSrcweir     if ( !pContainer )
163cdf0e10cSrcweir         return;
164cdf0e10cSrcweir     uno::Reference< awt::XLayoutConstrains > xChild( pContainer->getImpl(),
165cdf0e10cSrcweir                                                      uno::UNO_QUERY );
166cdf0e10cSrcweir     mxContainer->addChild( xChild );
167cdf0e10cSrcweir     setProps( xChild, bXExpand, bYExpand, nXSpan, nYSpan );
168cdf0e10cSrcweir }
169cdf0e10cSrcweir 
setProps(uno::Reference<awt::XLayoutConstrains> xChild,bool bXExpand,bool bYExpand,sal_Int32 nXSpan,sal_Int32 nYSpan)170cdf0e10cSrcweir void Table::setProps( uno::Reference< awt::XLayoutConstrains > xChild,
171cdf0e10cSrcweir                       bool bXExpand, bool bYExpand, sal_Int32 nXSpan, sal_Int32 nYSpan )
172cdf0e10cSrcweir {
173cdf0e10cSrcweir     uno::Reference< beans::XPropertySet > xProps
174cdf0e10cSrcweir         ( mxContainer->getChildProperties( xChild ), uno::UNO_QUERY_THROW );
175cdf0e10cSrcweir     xProps->setPropertyValue( rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM( "XExpand" ) ),
176cdf0e10cSrcweir                               uno::Any( bXExpand ) );
177cdf0e10cSrcweir     xProps->setPropertyValue( rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM( "YExpand" ) ),
178cdf0e10cSrcweir                               uno::Any( bYExpand ) );
179cdf0e10cSrcweir     xProps->setPropertyValue( rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM( "ColSpan" ) ),
180cdf0e10cSrcweir                               uno::Any( nXSpan ) );
181cdf0e10cSrcweir     xProps->setPropertyValue( rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM( "RowSpan" ) ),
182cdf0e10cSrcweir                               uno::Any( nYSpan ) );
183cdf0e10cSrcweir }
184cdf0e10cSrcweir 
Box(rtl::OUString const & rName,sal_Int32 nBorder,bool bHomogeneous)185cdf0e10cSrcweir Box::Box( rtl::OUString const& rName, sal_Int32 nBorder, bool bHomogeneous )
186cdf0e10cSrcweir     : Container( rName, nBorder )
187cdf0e10cSrcweir {
188cdf0e10cSrcweir     uno::Reference< beans::XPropertySet > xProps( mxContainer, uno::UNO_QUERY_THROW );
189cdf0e10cSrcweir     xProps->setPropertyValue( rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM( "Homogeneous" ) ),
190cdf0e10cSrcweir                               uno::Any( bHomogeneous ) );
191cdf0e10cSrcweir }
192cdf0e10cSrcweir 
Add(Window * window,bool bExpand,bool bFill,sal_Int32 nPadding)193cdf0e10cSrcweir void Box::Add( Window *window, bool bExpand, bool bFill, sal_Int32 nPadding)
194cdf0e10cSrcweir {
195cdf0e10cSrcweir     if ( !window )
196cdf0e10cSrcweir         return;
197cdf0e10cSrcweir     WindowImpl &rImpl = window->getImpl();
198cdf0e10cSrcweir     uno::Reference< awt::XLayoutConstrains > xChild( rImpl.mxWindow,
199cdf0e10cSrcweir                                                      uno::UNO_QUERY );
200cdf0e10cSrcweir 
201cdf0e10cSrcweir     mxContainer->addChild( xChild );
202cdf0e10cSrcweir     setProps( xChild, bExpand, bFill, nPadding );
203cdf0e10cSrcweir }
204cdf0e10cSrcweir 
Add(Container * pContainer,bool bExpand,bool bFill,sal_Int32 nPadding)205cdf0e10cSrcweir void Box::Add( Container *pContainer, bool bExpand, bool bFill, sal_Int32 nPadding)
206cdf0e10cSrcweir {
207cdf0e10cSrcweir     if ( !pContainer )
208cdf0e10cSrcweir         return;
209cdf0e10cSrcweir 
210cdf0e10cSrcweir     uno::Reference< awt::XLayoutConstrains > xChild( pContainer->getImpl(),
211cdf0e10cSrcweir                                                      uno::UNO_QUERY );
212cdf0e10cSrcweir     mxContainer->addChild( xChild );
213cdf0e10cSrcweir     setProps( xChild, bExpand, bFill, nPadding );
214cdf0e10cSrcweir }
215cdf0e10cSrcweir 
setProps(uno::Reference<awt::XLayoutConstrains> xChild,bool bExpand,bool bFill,sal_Int32 nPadding)216cdf0e10cSrcweir void Box::setProps( uno::Reference< awt::XLayoutConstrains > xChild,
217cdf0e10cSrcweir                     bool bExpand, bool bFill, sal_Int32 nPadding )
218cdf0e10cSrcweir {
219cdf0e10cSrcweir     uno::Reference< beans::XPropertySet > xProps
220cdf0e10cSrcweir         ( mxContainer->getChildProperties( xChild ), uno::UNO_QUERY_THROW );
221cdf0e10cSrcweir 
222cdf0e10cSrcweir     xProps->setPropertyValue( rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM( "Expand" ) ),
223cdf0e10cSrcweir                               uno::Any( bExpand ) );
224cdf0e10cSrcweir     xProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Fill" ) ),
225cdf0e10cSrcweir                               uno::Any( bFill ) );
226cdf0e10cSrcweir     xProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Padding" ) ),
227cdf0e10cSrcweir                               uno::Any( nPadding ) );
228cdf0e10cSrcweir }
229cdf0e10cSrcweir 
Table(Context const * context,char const * pId)230cdf0e10cSrcweir Table::Table( Context const* context, char const* pId )
231cdf0e10cSrcweir     : Container( context, pId )
232cdf0e10cSrcweir {
233cdf0e10cSrcweir }
234cdf0e10cSrcweir 
Box(Context const * context,char const * pId)235cdf0e10cSrcweir Box::Box( Context const* context, char const* pId )
236cdf0e10cSrcweir     : Container( context, pId )
237cdf0e10cSrcweir {
238cdf0e10cSrcweir }
239cdf0e10cSrcweir 
HBox(sal_Int32 nBorder,bool bHomogeneous)240cdf0e10cSrcweir HBox::HBox( sal_Int32 nBorder, bool bHomogeneous )
241cdf0e10cSrcweir     : Box( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "hbox" ) ),
242cdf0e10cSrcweir            nBorder, bHomogeneous )
243cdf0e10cSrcweir {
244cdf0e10cSrcweir }
245cdf0e10cSrcweir 
HBox(Context const * context,char const * pId)246cdf0e10cSrcweir HBox::HBox( Context const* context, char const* pId )
247cdf0e10cSrcweir     : Box( context, pId )
248cdf0e10cSrcweir {
249cdf0e10cSrcweir }
250cdf0e10cSrcweir 
VBox(sal_Int32 nBorder,bool bHomogeneous)251cdf0e10cSrcweir VBox::VBox( sal_Int32 nBorder, bool bHomogeneous )
252cdf0e10cSrcweir     : Box( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "vbox" ) ),
253cdf0e10cSrcweir            nBorder, bHomogeneous )
254cdf0e10cSrcweir {
255cdf0e10cSrcweir }
256cdf0e10cSrcweir 
VBox(Context const * context,char const * pId)257cdf0e10cSrcweir VBox::VBox( Context const* context, char const* pId )
258cdf0e10cSrcweir     : Box( context, pId )
259cdf0e10cSrcweir {
260cdf0e10cSrcweir }
261cdf0e10cSrcweir 
262cdf0e10cSrcweir } // namespace layout
263