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