merge the formfield patch from ooo-build
[ooovba.git] / toolkit / source / layout / vcl / wcontainer.cxx
blob092e1b0730e4551b0476fbe760f583cf5af89d29
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile$
11 * $Revision$
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 "wrapper.hxx"
34 #include <com/sun/star/awt/XLayoutRoot.hpp>
35 #include <com/sun/star/awt/XLayoutContainer.hpp>
36 #include <comphelper/processfactory.hxx>
37 #include <layout/core/helper.hxx>
38 #include <tools/debug.hxx>
40 using namespace ::com::sun::star;
42 namespace layout
45 Container::Container( Context const* context, char const* pId )
46 : mxContainer( context->GetPeerHandle( pId ), uno::UNO_QUERY )
48 if ( !mxContainer.is() )
50 DBG_ERROR1( "Error: failed to associate container with '%s'", pId );
54 Container::Container( rtl::OUString const& rName, sal_Int32 nBorder )
56 mxContainer = layoutimpl::WidgetFactory::createContainer( rName );
58 uno::Reference< beans::XPropertySet > xProps( mxContainer, uno::UNO_QUERY_THROW );
59 xProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Border" ) ),
60 uno::Any( nBorder ) );
63 void Container::Add( Window *pChild )
65 if ( pChild )
67 uno::Reference< awt::XLayoutConstrains > xChild( pChild->GetPeer(), uno::UNO_QUERY );
68 mxContainer->addChild( xChild );
72 void Container::Add( Container *pChild )
74 if ( pChild )
76 uno::Reference< awt::XLayoutConstrains > xChild( pChild->getImpl(), uno::UNO_QUERY );
77 mxContainer->addChild( xChild );
81 void Container::Remove( Window *pChild )
83 if ( pChild )
85 uno::Reference< awt::XLayoutConstrains > xChild( pChild->GetPeer(), uno::UNO_QUERY );
86 mxContainer->removeChild( xChild );
90 void Container::Remove( Container *pChild )
92 if ( pChild )
94 uno::Reference< awt::XLayoutConstrains > xChild( pChild->getImpl(), uno::UNO_QUERY );
95 mxContainer->removeChild( xChild );
99 void Container::Clear()
101 css::uno::Sequence< css::uno::Reference < css::awt::XLayoutConstrains > > children;
102 children = mxContainer->getChildren();
103 for (int i = 0; i < children.getLength(); i++)
104 mxContainer->removeChild( children[i] );
107 void Container::ShowAll( bool bShow )
109 struct inner
111 static void setChildrenVisible( uno::Reference < awt::XLayoutContainer > xCont,
112 bool bVisible ) /* auxiliary */
114 if ( xCont.is() )
116 uno::Sequence< uno::Reference < awt::XLayoutConstrains > > aChildren;
117 aChildren = xCont->getChildren();
118 for (int i = 0; i < aChildren.getLength(); i++)
120 uno::Reference < awt::XLayoutConstrains > xChild( aChildren[ i ] );
122 uno::Reference< awt::XWindow > xWin( xChild, uno::UNO_QUERY);
123 if ( xWin.is() )
124 xWin->setVisible( bVisible );
126 uno::Reference < awt::XLayoutContainer > xChildCont(
127 xChild, uno::UNO_QUERY );
128 setChildrenVisible( xChildCont, bVisible );
134 inner::setChildrenVisible( mxContainer, bShow );
137 void Container::Show()
139 ShowAll( true );
142 void Container::Hide()
144 ShowAll( false );
147 Table::Table( sal_Int32 nBorder, sal_Int32 nColumns )
148 : Container( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "table" ) ), nBorder )
150 uno::Reference< beans::XPropertySet > xProps( mxContainer, uno::UNO_QUERY_THROW );
151 xProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Columns" ) ),
152 uno::Any( nColumns ) );
155 void Table::Add( Window *window, bool bXExpand, bool bYExpand,
156 sal_Int32 nXSpan, sal_Int32 nYSpan )
158 if ( !window )
159 return;
160 WindowImpl &rImpl = window->getImpl();
161 uno::Reference< awt::XLayoutConstrains > xChild( rImpl.mxWindow,
162 uno::UNO_QUERY );
163 mxContainer->addChild( xChild );
164 setProps( xChild, bXExpand, bYExpand, nXSpan, nYSpan );
167 void Table::Add( Container *pContainer, bool bXExpand, bool bYExpand,
168 sal_Int32 nXSpan, sal_Int32 nYSpan )
170 if ( !pContainer )
171 return;
172 uno::Reference< awt::XLayoutConstrains > xChild( pContainer->getImpl(),
173 uno::UNO_QUERY );
174 mxContainer->addChild( xChild );
175 setProps( xChild, bXExpand, bYExpand, nXSpan, nYSpan );
178 void Table::setProps( uno::Reference< awt::XLayoutConstrains > xChild,
179 bool bXExpand, bool bYExpand, sal_Int32 nXSpan, sal_Int32 nYSpan )
181 uno::Reference< beans::XPropertySet > xProps
182 ( mxContainer->getChildProperties( xChild ), uno::UNO_QUERY_THROW );
183 xProps->setPropertyValue( rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM( "XExpand" ) ),
184 uno::Any( bXExpand ) );
185 xProps->setPropertyValue( rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM( "YExpand" ) ),
186 uno::Any( bYExpand ) );
187 xProps->setPropertyValue( rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM( "ColSpan" ) ),
188 uno::Any( nXSpan ) );
189 xProps->setPropertyValue( rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM( "RowSpan" ) ),
190 uno::Any( nYSpan ) );
193 Box::Box( rtl::OUString const& rName, sal_Int32 nBorder, bool bHomogeneous )
194 : Container( rName, nBorder )
196 uno::Reference< beans::XPropertySet > xProps( mxContainer, uno::UNO_QUERY_THROW );
197 xProps->setPropertyValue( rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM( "Homogeneous" ) ),
198 uno::Any( bHomogeneous ) );
201 void Box::Add( Window *window, bool bExpand, bool bFill, sal_Int32 nPadding)
203 if ( !window )
204 return;
205 WindowImpl &rImpl = window->getImpl();
206 uno::Reference< awt::XLayoutConstrains > xChild( rImpl.mxWindow,
207 uno::UNO_QUERY );
209 mxContainer->addChild( xChild );
210 setProps( xChild, bExpand, bFill, nPadding );
213 void Box::Add( Container *pContainer, bool bExpand, bool bFill, sal_Int32 nPadding)
215 if ( !pContainer )
216 return;
218 uno::Reference< awt::XLayoutConstrains > xChild( pContainer->getImpl(),
219 uno::UNO_QUERY );
220 mxContainer->addChild( xChild );
221 setProps( xChild, bExpand, bFill, nPadding );
224 void Box::setProps( uno::Reference< awt::XLayoutConstrains > xChild,
225 bool bExpand, bool bFill, sal_Int32 nPadding )
227 uno::Reference< beans::XPropertySet > xProps
228 ( mxContainer->getChildProperties( xChild ), uno::UNO_QUERY_THROW );
230 xProps->setPropertyValue( rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM( "Expand" ) ),
231 uno::Any( bExpand ) );
232 xProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Fill" ) ),
233 uno::Any( bFill ) );
234 xProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Padding" ) ),
235 uno::Any( nPadding ) );
238 Table::Table( Context const* context, char const* pId )
239 : Container( context, pId )
243 Box::Box( Context const* context, char const* pId )
244 : Container( context, pId )
248 HBox::HBox( sal_Int32 nBorder, bool bHomogeneous )
249 : Box( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "hbox" ) ),
250 nBorder, bHomogeneous )
254 HBox::HBox( Context const* context, char const* pId )
255 : Box( context, pId )
259 VBox::VBox( sal_Int32 nBorder, bool bHomogeneous )
260 : Box( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "vbox" ) ),
261 nBorder, bHomogeneous )
265 VBox::VBox( Context const* context, char const* pId )
266 : Box( context, pId )
270 } // namespace layout