xref: /aoo41x/main/toolkit/source/layout/core/root.cxx (revision 61161268)
1b0724fc6SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3b0724fc6SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4b0724fc6SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5b0724fc6SAndrew Rist  * distributed with this work for additional information
6b0724fc6SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7b0724fc6SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8b0724fc6SAndrew Rist  * "License"); you may not use this file except in compliance
9b0724fc6SAndrew Rist  * with the License.  You may obtain a copy of the License at
10b0724fc6SAndrew Rist  *
11b0724fc6SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12b0724fc6SAndrew Rist  *
13b0724fc6SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14b0724fc6SAndrew Rist  * software distributed under the License is distributed on an
15b0724fc6SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16b0724fc6SAndrew Rist  * KIND, either express or implied.  See the License for the
17b0724fc6SAndrew Rist  * specific language governing permissions and limitations
18b0724fc6SAndrew Rist  * under the License.
19b0724fc6SAndrew Rist  *
20b0724fc6SAndrew Rist  *************************************************************/
21b0724fc6SAndrew Rist 
22b0724fc6SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include "root.hxx"
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #include <cassert>
27cdf0e10cSrcweir 
28cdf0e10cSrcweir #include <com/sun/star/awt/WindowAttribute.hpp>
29cdf0e10cSrcweir #include <com/sun/star/awt/XMessageBox.hpp>
30cdf0e10cSrcweir #include <com/sun/star/awt/MessageBoxButtons.hpp>
31cdf0e10cSrcweir #include <com/sun/star/frame/XDesktop.hpp>
32cdf0e10cSrcweir #include <com/sun/star/awt/XMessageBoxFactory.hpp>
33cdf0e10cSrcweir #include <com/sun/star/xml/sax/SAXParseException.hpp>
34cdf0e10cSrcweir #include <com/sun/star/xml/sax/XParser.hpp>
35cdf0e10cSrcweir 
36cdf0e10cSrcweir #include "helper.hxx"
37cdf0e10cSrcweir #include "import.hxx"
38cdf0e10cSrcweir #include "timer.hxx"
39cdf0e10cSrcweir #include "translate.hxx"
40cdf0e10cSrcweir 
41cdf0e10cSrcweir namespace layoutimpl
42cdf0e10cSrcweir {
43cdf0e10cSrcweir 
44cdf0e10cSrcweir using namespace css;
45cdf0e10cSrcweir using ::rtl::OUString;
46cdf0e10cSrcweir 
LayoutRoot(const uno::Reference<lang::XMultiServiceFactory> & xFactory)47cdf0e10cSrcweir LayoutRoot::LayoutRoot( const uno::Reference< lang::XMultiServiceFactory >& xFactory )
48cdf0e10cSrcweir     : mbDisposed( sal_False )
49cdf0e10cSrcweir     , mxFactory( xFactory )
50cdf0e10cSrcweir     , mpListeners( NULL )
51cdf0e10cSrcweir     , mpToplevel( NULL )
52cdf0e10cSrcweir {
53cdf0e10cSrcweir     if ( !xFactory.is() )
54cdf0e10cSrcweir         throw uno::RuntimeException();
55cdf0e10cSrcweir     mxLayoutUnit = uno::Reference< awt::XLayoutUnit >( new LayoutUnit() );
56cdf0e10cSrcweir }
57cdf0e10cSrcweir 
~LayoutRoot()58cdf0e10cSrcweir LayoutRoot::~LayoutRoot()
59cdf0e10cSrcweir {
60cdf0e10cSrcweir // TODO: we want to delete the top level LayoutWidget...
61cdf0e10cSrcweir     ::osl::MutexGuard aGuard( maMutex );
62cdf0e10cSrcweir     if ( !mbDisposed )
63cdf0e10cSrcweir     {
64cdf0e10cSrcweir         try
65cdf0e10cSrcweir         {
66cdf0e10cSrcweir             m_refCount++; // inhibit multiple destruction
67cdf0e10cSrcweir             dispose();
68cdf0e10cSrcweir         }
69cdf0e10cSrcweir         catch( uno::Exception& )
70cdf0e10cSrcweir         {
71cdf0e10cSrcweir         }
72cdf0e10cSrcweir     }
73cdf0e10cSrcweir }
74cdf0e10cSrcweir 
ShowMessageBox(uno::Reference<lang::XMultiServiceFactory> const & xFactory,uno::Reference<awt::XToolkit> xToolkit,OUString const & aTitle,OUString const & aMessage)75cdf0e10cSrcweir void ShowMessageBox( uno::Reference< lang::XMultiServiceFactory > const& xFactory, uno::Reference< awt::XToolkit > xToolkit, OUString const& aTitle, OUString const& aMessage )
76cdf0e10cSrcweir {
77cdf0e10cSrcweir     uno::Reference< uno::XInterface > iDesktop = xFactory->createInstance
78cdf0e10cSrcweir         ( OUString::createFromAscii( "com.sun.star.frame.Desktop" ) );
79cdf0e10cSrcweir     uno::Reference< frame::XDesktop > xDesktop ( iDesktop, uno::UNO_QUERY );
80cdf0e10cSrcweir     uno::Reference< frame::XFrame > xFrame ( xDesktop->getCurrentFrame() );
81cdf0e10cSrcweir     uno::Reference< awt::XWindow > xContainerWindow( xFrame->getContainerWindow() );
82cdf0e10cSrcweir     uno::Reference< awt::XWindowPeer > xWindowPeer( xContainerWindow, uno::UNO_QUERY_THROW );
83cdf0e10cSrcweir     uno::Reference< awt::XMessageBoxFactory > xMessageBoxFactory( xToolkit, uno::UNO_QUERY );
84cdf0e10cSrcweir 
85cdf0e10cSrcweir     uno::Reference< awt::XMessageBox > xMessageBox
86cdf0e10cSrcweir         = xMessageBoxFactory->createMessageBox
87*61161268SAriel Constenla-Haile         ( xWindowPeer, awt::MessageBoxType_ERRORBOX,
88cdf0e10cSrcweir           awt::MessageBoxButtons::BUTTONS_OK, aTitle, aMessage );
89cdf0e10cSrcweir 
90cdf0e10cSrcweir     if ( xMessageBox.is() )
91cdf0e10cSrcweir         xMessageBox->execute();
92cdf0e10cSrcweir     //FIXME: exceptions not caught and printed at top level??
93cdf0e10cSrcweir     //else
94cdf0e10cSrcweir     //printf( "%s\n", OUSTRING_CSTR( aMessage ) );
95cdf0e10cSrcweir }
96cdf0e10cSrcweir 
error(OUString const & message)97cdf0e10cSrcweir void LayoutRoot::error( OUString const& message )
98cdf0e10cSrcweir {
99cdf0e10cSrcweir     OSL_TRACE( "%s\n", OUSTRING_CSTR( message ) );
100cdf0e10cSrcweir     ShowMessageBox( mxFactory, mxToolkit,
101cdf0e10cSrcweir                     OUString::createFromAscii( "Fatal error" ),
102cdf0e10cSrcweir                     message );
103cdf0e10cSrcweir     throw uno::RuntimeException( message, uno::Reference< uno::XInterface >() );
104cdf0e10cSrcweir }
105cdf0e10cSrcweir 
106cdf0e10cSrcweir // XInitialization
initialize(const uno::Sequence<uno::Any> & aArguments)107cdf0e10cSrcweir void SAL_CALL LayoutRoot::initialize( const uno::Sequence< uno::Any >& aArguments )
108cdf0e10cSrcweir     throw ( uno::Exception,
109cdf0e10cSrcweir             uno::RuntimeException )
110cdf0e10cSrcweir {
111cdf0e10cSrcweir     ::osl::MutexGuard aGuard( maMutex );
112cdf0e10cSrcweir 
113cdf0e10cSrcweir     if ( mbDisposed )
114cdf0e10cSrcweir         throw lang::DisposedException();
115cdf0e10cSrcweir 
116cdf0e10cSrcweir     if ( mxContainer.is() ) // only 1 init ...
117cdf0e10cSrcweir         throw uno::Exception();
118cdf0e10cSrcweir 
119cdf0e10cSrcweir     if ( !aArguments.getLength() )
120cdf0e10cSrcweir         throw lang::IllegalArgumentException();
121cdf0e10cSrcweir 
122cdf0e10cSrcweir     OSL_ENSURE( aArguments.getLength() == 1, "Wrong arg count\n" );
123cdf0e10cSrcweir 
124cdf0e10cSrcweir     OUString aXMLName;
125cdf0e10cSrcweir     if ( !( aArguments[0] >>= aXMLName ) )
126cdf0e10cSrcweir         throw lang::IllegalArgumentException();
127cdf0e10cSrcweir 
128cdf0e10cSrcweir     uno::Reference< xml::sax::XParser > xParser
129cdf0e10cSrcweir         ( mxFactory->createInstance(
130cdf0e10cSrcweir             OUString::createFromAscii( "com.sun.star.xml.sax.Parser" ) ),
131cdf0e10cSrcweir           uno::UNO_QUERY );
132cdf0e10cSrcweir     OSL_ASSERT( xParser.is() );
133cdf0e10cSrcweir     if (! xParser.is())
134cdf0e10cSrcweir     {
135cdf0e10cSrcweir         throw uno::RuntimeException(
136cdf0e10cSrcweir             OUString::createFromAscii( "cannot create sax-parser component" ),
137cdf0e10cSrcweir             uno::Reference< uno::XInterface >() );
138cdf0e10cSrcweir     }
139cdf0e10cSrcweir 
140cdf0e10cSrcweir     // FIXME: quite possibly we want to pass this in ...
141cdf0e10cSrcweir     uno::Reference< awt::XToolkit > xToolkit;
142cdf0e10cSrcweir 
143cdf0e10cSrcweir     mxToolkit = uno::Reference< awt::XToolkit >(
144cdf0e10cSrcweir         mxFactory->createInstance(
145cdf0e10cSrcweir             OUString::createFromAscii( "com.sun.star.awt.Toolkit" ) ),
146cdf0e10cSrcweir         uno::UNO_QUERY );
147cdf0e10cSrcweir 
148cdf0e10cSrcweir     if ( !mxToolkit.is() )
149cdf0e10cSrcweir         throw uno::RuntimeException(
150cdf0e10cSrcweir             OUString::createFromAscii( "failed to create toolkit!" ),
151cdf0e10cSrcweir             uno::Reference< uno::XInterface >() );
152cdf0e10cSrcweir 
153cdf0e10cSrcweir     OUString aXMLFile = readRightTranslation( aXMLName );
154cdf0e10cSrcweir     uno::Reference< io::XInputStream > xStream = getFileAsStream( aXMLFile );
155cdf0e10cSrcweir     if (! xStream.is() )
156cdf0e10cSrcweir         error( OUString::createFromAscii( "Installation problem: cannot find XML file:" ) + aXMLName );
157cdf0e10cSrcweir 
158cdf0e10cSrcweir     // error handler, entity resolver omitted
159cdf0e10cSrcweir 
160cdf0e10cSrcweir     ImportContext *pCtx = new ImportContext( *this );
161cdf0e10cSrcweir 
162cdf0e10cSrcweir     uno::Reference< xml::input::XRoot > xRoot( pCtx );
163cdf0e10cSrcweir     uno::Sequence < uno::Any > aArgs( 1 );
164cdf0e10cSrcweir     aArgs[0] <<= xRoot;
165cdf0e10cSrcweir     uno::Reference< xml::sax::XDocumentHandler > xDocHandler
166cdf0e10cSrcweir         (mxFactory->createInstanceWithArguments
167cdf0e10cSrcweir          ( OUString::createFromAscii( "com.sun.star.xml.input.SaxDocumentHandler" ),
168cdf0e10cSrcweir           aArgs ), uno::UNO_QUERY );
169cdf0e10cSrcweir 
170cdf0e10cSrcweir     if (! xDocHandler.is() )
171cdf0e10cSrcweir         error( OUString::createFromAscii( "cannot find SAx handler for document type of:") + aXMLName );
172cdf0e10cSrcweir 
173cdf0e10cSrcweir     xParser->setDocumentHandler( xDocHandler );
174cdf0e10cSrcweir 
175cdf0e10cSrcweir     xml::sax::InputSource source;
176cdf0e10cSrcweir     source.aInputStream = xStream;
177cdf0e10cSrcweir     source.sSystemId = OUString::createFromAscii( "virtual file" );
178cdf0e10cSrcweir 
179cdf0e10cSrcweir     try
180cdf0e10cSrcweir     {
181cdf0e10cSrcweir         xParser->parseStream( source );
182cdf0e10cSrcweir     }
183cdf0e10cSrcweir     catch ( xml::sax::SAXParseException& e )
184cdf0e10cSrcweir     {
185cdf0e10cSrcweir         OUString c = OUString::createFromAscii( ":" );
186cdf0e10cSrcweir         error( aXMLName
187cdf0e10cSrcweir                + c + OUString::valueOf( e.LineNumber )
188cdf0e10cSrcweir                + c + OUString::valueOf( e.ColumnNumber )
189cdf0e10cSrcweir                + c + OUString::createFromAscii( "Sax parse error" ) );
190cdf0e10cSrcweir     }
191cdf0e10cSrcweir }
192cdf0e10cSrcweir 
193cdf0e10cSrcweir // XLayoutContainer
getLayoutContainer()194cdf0e10cSrcweir uno::Reference< awt::XLayoutContainer > LayoutRoot::getLayoutContainer() throw (uno::RuntimeException)
195cdf0e10cSrcweir {
196cdf0e10cSrcweir     return uno::Reference< awt::XLayoutContainer >();
197cdf0e10cSrcweir }
198cdf0e10cSrcweir 
199cdf0e10cSrcweir // local helper ...
addItem(const OUString & rName,const uno::Reference<awt::XLayoutConstrains> & xRef)200cdf0e10cSrcweir void LayoutRoot::addItem( const OUString &rName,
201cdf0e10cSrcweir                           const uno::Reference< awt::XLayoutConstrains > &xRef )
202cdf0e10cSrcweir {
203cdf0e10cSrcweir     maItems[ rName ] = xRef;
204cdf0e10cSrcweir }
205cdf0e10cSrcweir 
206cdf0e10cSrcweir // XNameAccess
getByName(const OUString & rName)207cdf0e10cSrcweir uno::Any SAL_CALL LayoutRoot::getByName( const OUString &rName )
208cdf0e10cSrcweir     throw ( container::NoSuchElementException,
209cdf0e10cSrcweir             lang::WrappedTargetException,
210cdf0e10cSrcweir             uno::RuntimeException )
211cdf0e10cSrcweir {
212cdf0e10cSrcweir     ::osl::MutexGuard aGuard( maMutex );
213cdf0e10cSrcweir     if ( mbDisposed )
214cdf0e10cSrcweir         throw lang::DisposedException();
215cdf0e10cSrcweir 
216cdf0e10cSrcweir     uno::Reference< awt::XLayoutConstrains > xItem;
217cdf0e10cSrcweir     ItemHash::iterator i = maItems.find( rName );
218cdf0e10cSrcweir     if ( i != maItems.end() )
219cdf0e10cSrcweir         xItem = i->second;
220cdf0e10cSrcweir     return uno::makeAny( xItem );
221cdf0e10cSrcweir }
222cdf0e10cSrcweir 
hasByName(const OUString & rName)223cdf0e10cSrcweir sal_Bool SAL_CALL LayoutRoot::hasByName( const OUString &rName )
224cdf0e10cSrcweir     throw (uno::RuntimeException)
225cdf0e10cSrcweir {
226cdf0e10cSrcweir     ::osl::MutexGuard aGuard( maMutex );
227cdf0e10cSrcweir     if ( mbDisposed ) throw lang::DisposedException();
228cdf0e10cSrcweir 
229cdf0e10cSrcweir     ItemHash::iterator i = maItems.find( rName );
230cdf0e10cSrcweir     return i != maItems.end();
231cdf0e10cSrcweir }
232cdf0e10cSrcweir 
getElementNames()233cdf0e10cSrcweir uno::Sequence< OUString > SAL_CALL LayoutRoot::getElementNames()
234cdf0e10cSrcweir     throw ( uno::RuntimeException )
235cdf0e10cSrcweir {
236cdf0e10cSrcweir     ::osl::MutexGuard aGuard( maMutex );
237cdf0e10cSrcweir     if ( mbDisposed ) throw lang::DisposedException();
238cdf0e10cSrcweir 
239cdf0e10cSrcweir     uno::Sequence< OUString > aNames( maItems.size() );
240cdf0e10cSrcweir     sal_Int32 nPos = 0;
241cdf0e10cSrcweir 
242cdf0e10cSrcweir     for ( ItemHash::const_iterator it = maItems.begin();
243cdf0e10cSrcweir           it != maItems.end(); it++ )
244cdf0e10cSrcweir         aNames[ nPos++ ] = it->first;
245cdf0e10cSrcweir 
246cdf0e10cSrcweir     return aNames;
247cdf0e10cSrcweir }
248cdf0e10cSrcweir 
getElementType()249cdf0e10cSrcweir uno::Type SAL_CALL LayoutRoot::getElementType()
250cdf0e10cSrcweir     throw ( uno::RuntimeException )
251cdf0e10cSrcweir {
252cdf0e10cSrcweir     return getCppuType( ( const uno::Reference< awt::XLayoutConstrains >* )NULL );
253cdf0e10cSrcweir }
254cdf0e10cSrcweir 
hasElements()255cdf0e10cSrcweir sal_Bool SAL_CALL LayoutRoot::hasElements()
256cdf0e10cSrcweir     throw ( uno::RuntimeException )
257cdf0e10cSrcweir {
258cdf0e10cSrcweir     ::osl::MutexGuard aGuard( maMutex );
259cdf0e10cSrcweir 
260cdf0e10cSrcweir     if ( mbDisposed ) throw lang::DisposedException();
261cdf0e10cSrcweir 
262cdf0e10cSrcweir     return maItems.size() > 0;
263cdf0e10cSrcweir }
264cdf0e10cSrcweir 
265cdf0e10cSrcweir // XComponent
dispose()266cdf0e10cSrcweir void SAL_CALL LayoutRoot::dispose()
267cdf0e10cSrcweir     throw ( uno::RuntimeException )
268cdf0e10cSrcweir {
269cdf0e10cSrcweir     ::osl::MutexGuard aGuard( maMutex );
270cdf0e10cSrcweir 
271cdf0e10cSrcweir     if ( mbDisposed ) throw lang::DisposedException();
272cdf0e10cSrcweir 
273cdf0e10cSrcweir     if ( mpListeners )
274cdf0e10cSrcweir     {
275cdf0e10cSrcweir 
276cdf0e10cSrcweir         lang::EventObject aSource( static_cast< ::cppu::OWeakObject* >(this) );
277cdf0e10cSrcweir         mpListeners->disposeAndClear( aSource );
278cdf0e10cSrcweir         delete mpListeners;
279cdf0e10cSrcweir         mpListeners = NULL;
280cdf0e10cSrcweir     }
281cdf0e10cSrcweir 
282cdf0e10cSrcweir     maItems.clear();
283cdf0e10cSrcweir     mbDisposed = sal_True;
284cdf0e10cSrcweir }
285cdf0e10cSrcweir 
addEventListener(const uno::Reference<lang::XEventListener> & xListener)286cdf0e10cSrcweir void SAL_CALL LayoutRoot::addEventListener( const uno::Reference< lang::XEventListener >& xListener )
287cdf0e10cSrcweir     throw ( uno::RuntimeException )
288cdf0e10cSrcweir {
289cdf0e10cSrcweir     ::osl::MutexGuard aGuard( maMutex );
290cdf0e10cSrcweir 
291cdf0e10cSrcweir     if ( mbDisposed ) throw lang::DisposedException();
292cdf0e10cSrcweir 
293cdf0e10cSrcweir     if ( !mpListeners )
294cdf0e10cSrcweir         mpListeners = new ::cppu::OInterfaceContainerHelper( maMutex );
295cdf0e10cSrcweir     mpListeners->addInterface( xListener );
296cdf0e10cSrcweir }
297cdf0e10cSrcweir 
removeEventListener(const uno::Reference<lang::XEventListener> & xListener)298cdf0e10cSrcweir void SAL_CALL LayoutRoot::removeEventListener( const uno::Reference< lang::XEventListener >& xListener )
299cdf0e10cSrcweir     throw ( uno::RuntimeException )
300cdf0e10cSrcweir {
301cdf0e10cSrcweir     ::osl::MutexGuard aGuard( maMutex );
302cdf0e10cSrcweir 
303cdf0e10cSrcweir     if ( mbDisposed ) throw lang::DisposedException();
304cdf0e10cSrcweir 
305cdf0e10cSrcweir     if ( mpListeners )
306cdf0e10cSrcweir         mpListeners->removeInterface( xListener );
307cdf0e10cSrcweir }
308cdf0e10cSrcweir 
309cdf0e10cSrcweir // builder
310cdf0e10cSrcweir 
create(OUString id,const OUString unoName,long attrbs,uno::Reference<awt::XLayoutContainer> xParent)311cdf0e10cSrcweir LayoutWidget *LayoutRoot::create( OUString id, const OUString unoName, long attrbs,uno::Reference< awt::XLayoutContainer > xParent )
312cdf0e10cSrcweir {
313cdf0e10cSrcweir     LayoutWidget *pWidget = new LayoutWidget( mxToolkit, xParent, unoName, attrbs );
314cdf0e10cSrcweir     if ( !mpToplevel )
315cdf0e10cSrcweir     {
316cdf0e10cSrcweir         mpToplevel = pWidget;
317cdf0e10cSrcweir         mxWindow = uno::Reference< awt::XWindow >( pWidget->getPeer(), uno::UNO_QUERY );
318cdf0e10cSrcweir         mxContainer = pWidget->mxContainer;
319cdf0e10cSrcweir     }
320cdf0e10cSrcweir     if ( pWidget->mxContainer.is() )
321cdf0e10cSrcweir         pWidget->mxContainer->setLayoutUnit( mxLayoutUnit );
322cdf0e10cSrcweir     if ( id.getLength() )
323cdf0e10cSrcweir         maItems[ id ] = pWidget->getPeer();
324cdf0e10cSrcweir     return pWidget;
325cdf0e10cSrcweir }
326cdf0e10cSrcweir 
327cdf0e10cSrcweir #if 0
328cdf0e10cSrcweir uno::Reference< awt::XLayoutConstrains > LayoutRoot::getToplevel()
329cdf0e10cSrcweir {
330cdf0e10cSrcweir     if ( mpToplevel )
331cdf0e10cSrcweir         return mpToplevel->getPeer();
332cdf0e10cSrcweir     return uno::Reference< awt::XLayoutConstrains > ();
333cdf0e10cSrcweir }
334cdf0e10cSrcweir 
335cdf0e10cSrcweir uno::Reference< awt::XLayoutConstrains > LayoutRoot::getById( OUString id )
336cdf0e10cSrcweir {
337cdf0e10cSrcweir     uno::Reference< awt::XLayoutConstrains > rRef = 0;
338cdf0e10cSrcweir     ItemHash::iterator it = maItems.find( id );
339cdf0e10cSrcweir     if ( it != maItems.end() )
340cdf0e10cSrcweir         rRef = it->second;
341cdf0e10cSrcweir     return rRef;
342cdf0e10cSrcweir }
343cdf0e10cSrcweir #endif
344cdf0e10cSrcweir 
LayoutWidget(uno::Reference<awt::XToolkit> xToolkit,uno::Reference<awt::XLayoutContainer> xParent,OUString unoName,long attrbs)345cdf0e10cSrcweir LayoutWidget::LayoutWidget( uno::Reference< awt::XToolkit > xToolkit,
346cdf0e10cSrcweir                             uno::Reference< awt::XLayoutContainer > xParent,
347cdf0e10cSrcweir                             OUString unoName, long attrbs )
348cdf0e10cSrcweir {
349cdf0e10cSrcweir     while ( xParent.is() && !uno::Reference< awt::XWindow >( xParent, uno::UNO_QUERY ).is() )
350cdf0e10cSrcweir     {
351cdf0e10cSrcweir         uno::Reference< awt::XLayoutContainer > xContainer( xParent, uno::UNO_QUERY );
352cdf0e10cSrcweir         assert( xContainer.is() );
353cdf0e10cSrcweir         xParent = uno::Reference< awt::XLayoutContainer >( xContainer->getParent(), uno::UNO_QUERY );
354cdf0e10cSrcweir     }
355cdf0e10cSrcweir 
356cdf0e10cSrcweir     mxWidget = WidgetFactory::createWidget( xToolkit, xParent, unoName, attrbs );
357cdf0e10cSrcweir     assert( mxWidget.is() );
358cdf0e10cSrcweir     mxContainer = uno::Reference< awt::XLayoutContainer >( mxWidget, uno::UNO_QUERY );
359cdf0e10cSrcweir }
360cdf0e10cSrcweir 
~LayoutWidget()361cdf0e10cSrcweir LayoutWidget::~LayoutWidget()
362cdf0e10cSrcweir {
363cdf0e10cSrcweir     /* should we dispose of the references...? */
364cdf0e10cSrcweir     // at least of its children... Or should root?
365cdf0e10cSrcweir }
366cdf0e10cSrcweir 
addChild(LayoutWidget * pChild)367cdf0e10cSrcweir bool LayoutWidget::addChild( LayoutWidget *pChild )
368cdf0e10cSrcweir {
369cdf0e10cSrcweir     if ( !mxContainer.is() )
370cdf0e10cSrcweir         return false;
371cdf0e10cSrcweir 
372cdf0e10cSrcweir     try
373cdf0e10cSrcweir     {
374cdf0e10cSrcweir         mxContainer->addChild( pChild->mxWidget );
375cdf0e10cSrcweir     }
376cdf0e10cSrcweir     catch( awt::MaxChildrenException ex )
377cdf0e10cSrcweir     {
378cdf0e10cSrcweir         return false;
379cdf0e10cSrcweir     }
380cdf0e10cSrcweir     return true;
381cdf0e10cSrcweir }
382cdf0e10cSrcweir 
setProperties(PropList const & rProps)383cdf0e10cSrcweir void LayoutWidget::setProperties( PropList const& rProps )
384cdf0e10cSrcweir {
385cdf0e10cSrcweir     ::layoutimpl::setProperties( mxWidget, rProps );
386cdf0e10cSrcweir }
387cdf0e10cSrcweir 
setProperty(OUString const & attr,OUString const & value)388cdf0e10cSrcweir void LayoutWidget::setProperty( OUString const& attr, OUString const& value )
389cdf0e10cSrcweir {
390cdf0e10cSrcweir     ::layoutimpl::setProperty( mxWidget, attr, value );
391cdf0e10cSrcweir }
392cdf0e10cSrcweir 
setChildProperties(LayoutWidget * pChild,PropList const & rProps)393cdf0e10cSrcweir void LayoutWidget::setChildProperties( LayoutWidget *pChild,
394cdf0e10cSrcweir                                        PropList const& rProps )
395cdf0e10cSrcweir {
396cdf0e10cSrcweir     uno::Reference< beans::XPropertySet > xChildPeer;
397cdf0e10cSrcweir     xChildPeer = mxContainer->getChildProperties( pChild->mxWidget );
398cdf0e10cSrcweir 
399cdf0e10cSrcweir     if ( xChildPeer.is() )
400cdf0e10cSrcweir         ::layoutimpl::setProperties( xChildPeer, rProps );
401cdf0e10cSrcweir }
402cdf0e10cSrcweir 
403cdf0e10cSrcweir } // namespace layoutimpl
404cdf0e10cSrcweir 
405