xref: /AOO41X/main/toolkit/source/layout/vcl/wcontainer.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir #include "wrapper.hxx"
29*cdf0e10cSrcweir 
30*cdf0e10cSrcweir #include <com/sun/star/awt/XLayoutRoot.hpp>
31*cdf0e10cSrcweir #include <com/sun/star/awt/XLayoutContainer.hpp>
32*cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
33*cdf0e10cSrcweir #include <layout/core/helper.hxx>
34*cdf0e10cSrcweir #include <tools/debug.hxx>
35*cdf0e10cSrcweir 
36*cdf0e10cSrcweir using namespace ::com::sun::star;
37*cdf0e10cSrcweir 
38*cdf0e10cSrcweir namespace layout
39*cdf0e10cSrcweir {
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir Container::Container( Context const* context, char const* pId )
42*cdf0e10cSrcweir     : mxContainer( context->GetPeerHandle( pId ), uno::UNO_QUERY )
43*cdf0e10cSrcweir {
44*cdf0e10cSrcweir     if ( !mxContainer.is() )
45*cdf0e10cSrcweir     {
46*cdf0e10cSrcweir         DBG_ERROR1( "Error: failed to associate container with '%s'", pId );
47*cdf0e10cSrcweir     }
48*cdf0e10cSrcweir }
49*cdf0e10cSrcweir 
50*cdf0e10cSrcweir Container::Container( rtl::OUString const& rName, sal_Int32 nBorder )
51*cdf0e10cSrcweir {
52*cdf0e10cSrcweir     mxContainer = layoutimpl::WidgetFactory::createContainer( rName );
53*cdf0e10cSrcweir 
54*cdf0e10cSrcweir     uno::Reference< beans::XPropertySet > xProps( mxContainer, uno::UNO_QUERY_THROW );
55*cdf0e10cSrcweir     xProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Border" ) ),
56*cdf0e10cSrcweir                               uno::Any( nBorder ) );
57*cdf0e10cSrcweir }
58*cdf0e10cSrcweir 
59*cdf0e10cSrcweir void Container::Add( Window *pChild )
60*cdf0e10cSrcweir {
61*cdf0e10cSrcweir     if ( pChild )
62*cdf0e10cSrcweir     {
63*cdf0e10cSrcweir         uno::Reference< awt::XLayoutConstrains > xChild( pChild->GetPeer(), uno::UNO_QUERY );
64*cdf0e10cSrcweir         mxContainer->addChild( xChild );
65*cdf0e10cSrcweir     }
66*cdf0e10cSrcweir }
67*cdf0e10cSrcweir 
68*cdf0e10cSrcweir void Container::Add( Container *pChild )
69*cdf0e10cSrcweir {
70*cdf0e10cSrcweir     if ( pChild )
71*cdf0e10cSrcweir     {
72*cdf0e10cSrcweir         uno::Reference< awt::XLayoutConstrains > xChild( pChild->getImpl(), uno::UNO_QUERY );
73*cdf0e10cSrcweir         mxContainer->addChild( xChild );
74*cdf0e10cSrcweir     }
75*cdf0e10cSrcweir }
76*cdf0e10cSrcweir 
77*cdf0e10cSrcweir void Container::Remove( Window *pChild )
78*cdf0e10cSrcweir {
79*cdf0e10cSrcweir     if ( pChild )
80*cdf0e10cSrcweir     {
81*cdf0e10cSrcweir         uno::Reference< awt::XLayoutConstrains > xChild( pChild->GetPeer(), uno::UNO_QUERY );
82*cdf0e10cSrcweir         mxContainer->removeChild( xChild );
83*cdf0e10cSrcweir     }
84*cdf0e10cSrcweir }
85*cdf0e10cSrcweir 
86*cdf0e10cSrcweir void Container::Remove( Container *pChild )
87*cdf0e10cSrcweir {
88*cdf0e10cSrcweir     if ( pChild )
89*cdf0e10cSrcweir     {
90*cdf0e10cSrcweir         uno::Reference< awt::XLayoutConstrains > xChild( pChild->getImpl(), uno::UNO_QUERY );
91*cdf0e10cSrcweir         mxContainer->removeChild( xChild );
92*cdf0e10cSrcweir     }
93*cdf0e10cSrcweir }
94*cdf0e10cSrcweir 
95*cdf0e10cSrcweir void Container::Clear()
96*cdf0e10cSrcweir {
97*cdf0e10cSrcweir     css::uno::Sequence< css::uno::Reference < css::awt::XLayoutConstrains > > children;
98*cdf0e10cSrcweir     children = mxContainer->getChildren();
99*cdf0e10cSrcweir     for (int i = 0; i < children.getLength(); i++)
100*cdf0e10cSrcweir         mxContainer->removeChild( children[i] );
101*cdf0e10cSrcweir }
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir void Container::ShowAll( bool bShow )
104*cdf0e10cSrcweir {
105*cdf0e10cSrcweir     struct inner
106*cdf0e10cSrcweir     {
107*cdf0e10cSrcweir         static void setChildrenVisible( uno::Reference < awt::XLayoutContainer > xCont,
108*cdf0e10cSrcweir                                         bool bVisible )  /* auxiliary */
109*cdf0e10cSrcweir         {
110*cdf0e10cSrcweir             if ( xCont.is() )
111*cdf0e10cSrcweir             {
112*cdf0e10cSrcweir                 uno::Sequence< uno::Reference < awt::XLayoutConstrains > > aChildren;
113*cdf0e10cSrcweir                 aChildren = xCont->getChildren();
114*cdf0e10cSrcweir                 for (int i = 0; i < aChildren.getLength(); i++)
115*cdf0e10cSrcweir                 {
116*cdf0e10cSrcweir                     uno::Reference < awt::XLayoutConstrains > xChild( aChildren[ i ] );
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir                     uno::Reference< awt::XWindow > xWin( xChild, uno::UNO_QUERY);
119*cdf0e10cSrcweir                     if ( xWin.is() )
120*cdf0e10cSrcweir                         xWin->setVisible( bVisible );
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir                     uno::Reference < awt::XLayoutContainer > xChildCont(
123*cdf0e10cSrcweir                         xChild, uno::UNO_QUERY );
124*cdf0e10cSrcweir                     setChildrenVisible( xChildCont, bVisible );
125*cdf0e10cSrcweir                 }
126*cdf0e10cSrcweir             }
127*cdf0e10cSrcweir         }
128*cdf0e10cSrcweir     };
129*cdf0e10cSrcweir 
130*cdf0e10cSrcweir     inner::setChildrenVisible( mxContainer, bShow );
131*cdf0e10cSrcweir }
132*cdf0e10cSrcweir 
133*cdf0e10cSrcweir void Container::Show()
134*cdf0e10cSrcweir {
135*cdf0e10cSrcweir     ShowAll( true );
136*cdf0e10cSrcweir }
137*cdf0e10cSrcweir 
138*cdf0e10cSrcweir void Container::Hide()
139*cdf0e10cSrcweir {
140*cdf0e10cSrcweir     ShowAll( false );
141*cdf0e10cSrcweir }
142*cdf0e10cSrcweir 
143*cdf0e10cSrcweir Table::Table( sal_Int32 nBorder, sal_Int32 nColumns )
144*cdf0e10cSrcweir     : Container( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "table" ) ), nBorder )
145*cdf0e10cSrcweir {
146*cdf0e10cSrcweir     uno::Reference< beans::XPropertySet > xProps( mxContainer, uno::UNO_QUERY_THROW );
147*cdf0e10cSrcweir     xProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Columns" ) ),
148*cdf0e10cSrcweir                               uno::Any( nColumns ) );
149*cdf0e10cSrcweir }
150*cdf0e10cSrcweir 
151*cdf0e10cSrcweir void Table::Add( Window *window, bool bXExpand, bool bYExpand,
152*cdf0e10cSrcweir                  sal_Int32 nXSpan, sal_Int32 nYSpan )
153*cdf0e10cSrcweir {
154*cdf0e10cSrcweir     if ( !window )
155*cdf0e10cSrcweir         return;
156*cdf0e10cSrcweir     WindowImpl &rImpl = window->getImpl();
157*cdf0e10cSrcweir     uno::Reference< awt::XLayoutConstrains > xChild( rImpl.mxWindow,
158*cdf0e10cSrcweir                                                      uno::UNO_QUERY );
159*cdf0e10cSrcweir     mxContainer->addChild( xChild );
160*cdf0e10cSrcweir     setProps( xChild, bXExpand, bYExpand, nXSpan, nYSpan );
161*cdf0e10cSrcweir }
162*cdf0e10cSrcweir 
163*cdf0e10cSrcweir void Table::Add( Container *pContainer, bool bXExpand, bool bYExpand,
164*cdf0e10cSrcweir                  sal_Int32 nXSpan, sal_Int32 nYSpan )
165*cdf0e10cSrcweir {
166*cdf0e10cSrcweir     if ( !pContainer )
167*cdf0e10cSrcweir         return;
168*cdf0e10cSrcweir     uno::Reference< awt::XLayoutConstrains > xChild( pContainer->getImpl(),
169*cdf0e10cSrcweir                                                      uno::UNO_QUERY );
170*cdf0e10cSrcweir     mxContainer->addChild( xChild );
171*cdf0e10cSrcweir     setProps( xChild, bXExpand, bYExpand, nXSpan, nYSpan );
172*cdf0e10cSrcweir }
173*cdf0e10cSrcweir 
174*cdf0e10cSrcweir void Table::setProps( uno::Reference< awt::XLayoutConstrains > xChild,
175*cdf0e10cSrcweir                       bool bXExpand, bool bYExpand, sal_Int32 nXSpan, sal_Int32 nYSpan )
176*cdf0e10cSrcweir {
177*cdf0e10cSrcweir     uno::Reference< beans::XPropertySet > xProps
178*cdf0e10cSrcweir         ( mxContainer->getChildProperties( xChild ), uno::UNO_QUERY_THROW );
179*cdf0e10cSrcweir     xProps->setPropertyValue( rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM( "XExpand" ) ),
180*cdf0e10cSrcweir                               uno::Any( bXExpand ) );
181*cdf0e10cSrcweir     xProps->setPropertyValue( rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM( "YExpand" ) ),
182*cdf0e10cSrcweir                               uno::Any( bYExpand ) );
183*cdf0e10cSrcweir     xProps->setPropertyValue( rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM( "ColSpan" ) ),
184*cdf0e10cSrcweir                               uno::Any( nXSpan ) );
185*cdf0e10cSrcweir     xProps->setPropertyValue( rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM( "RowSpan" ) ),
186*cdf0e10cSrcweir                               uno::Any( nYSpan ) );
187*cdf0e10cSrcweir }
188*cdf0e10cSrcweir 
189*cdf0e10cSrcweir Box::Box( rtl::OUString const& rName, sal_Int32 nBorder, bool bHomogeneous )
190*cdf0e10cSrcweir     : Container( rName, nBorder )
191*cdf0e10cSrcweir {
192*cdf0e10cSrcweir     uno::Reference< beans::XPropertySet > xProps( mxContainer, uno::UNO_QUERY_THROW );
193*cdf0e10cSrcweir     xProps->setPropertyValue( rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM( "Homogeneous" ) ),
194*cdf0e10cSrcweir                               uno::Any( bHomogeneous ) );
195*cdf0e10cSrcweir }
196*cdf0e10cSrcweir 
197*cdf0e10cSrcweir void Box::Add( Window *window, bool bExpand, bool bFill, sal_Int32 nPadding)
198*cdf0e10cSrcweir {
199*cdf0e10cSrcweir     if ( !window )
200*cdf0e10cSrcweir         return;
201*cdf0e10cSrcweir     WindowImpl &rImpl = window->getImpl();
202*cdf0e10cSrcweir     uno::Reference< awt::XLayoutConstrains > xChild( rImpl.mxWindow,
203*cdf0e10cSrcweir                                                      uno::UNO_QUERY );
204*cdf0e10cSrcweir 
205*cdf0e10cSrcweir     mxContainer->addChild( xChild );
206*cdf0e10cSrcweir     setProps( xChild, bExpand, bFill, nPadding );
207*cdf0e10cSrcweir }
208*cdf0e10cSrcweir 
209*cdf0e10cSrcweir void Box::Add( Container *pContainer, bool bExpand, bool bFill, sal_Int32 nPadding)
210*cdf0e10cSrcweir {
211*cdf0e10cSrcweir     if ( !pContainer )
212*cdf0e10cSrcweir         return;
213*cdf0e10cSrcweir 
214*cdf0e10cSrcweir     uno::Reference< awt::XLayoutConstrains > xChild( pContainer->getImpl(),
215*cdf0e10cSrcweir                                                      uno::UNO_QUERY );
216*cdf0e10cSrcweir     mxContainer->addChild( xChild );
217*cdf0e10cSrcweir     setProps( xChild, bExpand, bFill, nPadding );
218*cdf0e10cSrcweir }
219*cdf0e10cSrcweir 
220*cdf0e10cSrcweir void Box::setProps( uno::Reference< awt::XLayoutConstrains > xChild,
221*cdf0e10cSrcweir                     bool bExpand, bool bFill, sal_Int32 nPadding )
222*cdf0e10cSrcweir {
223*cdf0e10cSrcweir     uno::Reference< beans::XPropertySet > xProps
224*cdf0e10cSrcweir         ( mxContainer->getChildProperties( xChild ), uno::UNO_QUERY_THROW );
225*cdf0e10cSrcweir 
226*cdf0e10cSrcweir     xProps->setPropertyValue( rtl::OUString ( RTL_CONSTASCII_USTRINGPARAM( "Expand" ) ),
227*cdf0e10cSrcweir                               uno::Any( bExpand ) );
228*cdf0e10cSrcweir     xProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Fill" ) ),
229*cdf0e10cSrcweir                               uno::Any( bFill ) );
230*cdf0e10cSrcweir     xProps->setPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Padding" ) ),
231*cdf0e10cSrcweir                               uno::Any( nPadding ) );
232*cdf0e10cSrcweir }
233*cdf0e10cSrcweir 
234*cdf0e10cSrcweir Table::Table( Context const* context, char const* pId )
235*cdf0e10cSrcweir     : Container( context, pId )
236*cdf0e10cSrcweir {
237*cdf0e10cSrcweir }
238*cdf0e10cSrcweir 
239*cdf0e10cSrcweir Box::Box( Context const* context, char const* pId )
240*cdf0e10cSrcweir     : Container( context, pId )
241*cdf0e10cSrcweir {
242*cdf0e10cSrcweir }
243*cdf0e10cSrcweir 
244*cdf0e10cSrcweir HBox::HBox( sal_Int32 nBorder, bool bHomogeneous )
245*cdf0e10cSrcweir     : Box( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "hbox" ) ),
246*cdf0e10cSrcweir            nBorder, bHomogeneous )
247*cdf0e10cSrcweir {
248*cdf0e10cSrcweir }
249*cdf0e10cSrcweir 
250*cdf0e10cSrcweir HBox::HBox( Context const* context, char const* pId )
251*cdf0e10cSrcweir     : Box( context, pId )
252*cdf0e10cSrcweir {
253*cdf0e10cSrcweir }
254*cdf0e10cSrcweir 
255*cdf0e10cSrcweir VBox::VBox( sal_Int32 nBorder, bool bHomogeneous )
256*cdf0e10cSrcweir     : Box( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "vbox" ) ),
257*cdf0e10cSrcweir            nBorder, bHomogeneous )
258*cdf0e10cSrcweir {
259*cdf0e10cSrcweir }
260*cdf0e10cSrcweir 
261*cdf0e10cSrcweir VBox::VBox( Context const* context, char const* pId )
262*cdf0e10cSrcweir     : Box( context, pId )
263*cdf0e10cSrcweir {
264*cdf0e10cSrcweir }
265*cdf0e10cSrcweir 
266*cdf0e10cSrcweir } // namespace layout
267