1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 #include "Section.hxx"
28 #include <comphelper/enumhelper.hxx>
29 #include <connectivity/dbtools.hxx>
30 #include <com/sun/star/report/XReportComponent.hpp>
31 #include <com/sun/star/report/ForceNewPage.hpp>
32 #include <com/sun/star/beans/PropertyAttribute.hpp>
33 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
34 #ifndef REPORTDESIGN_SHARED_CORESTRINGS_HRC
35 #include "corestrings.hrc"
36 #endif
37 #include "core_resource.hxx"
38 #ifndef REPORTDESIGN_CORE_RESOURCE_HRC_
39 #include "core_resource.hrc"
40 #endif
41 #include <tools/debug.hxx>
42 #include "Tools.hxx"
43 #include "RptModel.hxx"
44 #include "RptPage.hxx"
45 #include "ReportDefinition.hxx"
46 #include "Shape.hxx"
47 #include <svx/unoshape.hxx>
48 #include "RptObject.hxx"
49 #include "ReportDrawPage.hxx"
50 #include <comphelper/property.hxx>
51 // =============================================================================
52 namespace reportdesign
53 {
54 // =============================================================================
55 	using namespace com::sun::star;
56 	using namespace comphelper;
57 DBG_NAME( rpt_OSection )
58 // -----------------------------------------------------------------------------
59 uno::Sequence< ::rtl::OUString> lcl_getGroupAbsent()
60 {
61     ::rtl::OUString pProps[] = {
62                 PROPERTY_CANGROW
63                 ,PROPERTY_CANSHRINK
64 	    };
65 
66 	return uno::Sequence< ::rtl::OUString >(pProps,sizeof(pProps)/sizeof(pProps[0]));
67 }
68 
69 // -----------------------------------------------------------------------------
70 OSection::OSection( const uno::Reference< report::XGroup >& _xParent
71 				   ,const uno::Reference< uno::XComponentContext >& context
72                    ,bool /*_bPageSection*/)
73 :SectionBase(m_aMutex)
74 ,SectionPropertySet(context,static_cast< Implements >(IMPLEMENTS_PROPERTY_SET),lcl_getGroupAbsent())
75 ,m_aContainerListeners(m_aMutex)
76 ,m_xContext(context)
77 ,m_xGroup(_xParent)
78 ,m_nHeight(3000)
79 ,m_nBackgroundColor(COL_TRANSPARENT)
80 ,m_nForceNewPage(report::ForceNewPage::NONE)
81 ,m_nNewRowOrCol(report::ForceNewPage::NONE)
82 ,m_bKeepTogether(sal_False)
83 ,m_bCanGrow(sal_False)
84 ,m_bCanShrink(sal_False)
85 ,m_bRepeatSection(sal_False)
86 ,m_bVisible(sal_True)
87 ,m_bBacktransparent(sal_True)
88 ,m_bInRemoveNotify(false)
89 ,m_bInInsertNotify(false)
90 {
91 	DBG_CTOR( rpt_OSection,NULL);
92     init();
93 }
94 // -----------------------------------------------------------------------------
95 uno::Sequence< ::rtl::OUString> lcl_getAbsent(bool _bPageSection)
96 {
97     if ( _bPageSection )
98     {
99         ::rtl::OUString pProps[] = {
100 			    PROPERTY_FORCENEWPAGE
101 			    ,PROPERTY_NEWROWORCOL
102 			    ,PROPERTY_KEEPTOGETHER
103                 ,PROPERTY_CANGROW
104                 ,PROPERTY_CANSHRINK
105                 ,PROPERTY_REPEATSECTION
106 	    };
107         return uno::Sequence< ::rtl::OUString >(pProps,sizeof(pProps)/sizeof(pProps[0]));
108     }
109 
110     ::rtl::OUString pProps[] = {
111                 PROPERTY_CANGROW
112                 ,PROPERTY_CANSHRINK
113                 ,PROPERTY_REPEATSECTION
114 	    };
115 
116 	return uno::Sequence< ::rtl::OUString >(pProps,sizeof(pProps)/sizeof(pProps[0]));
117 }
118 // -----------------------------------------------------------------------------
119 OSection::OSection(const uno::Reference< report::XReportDefinition >& _xParent
120 				   ,const uno::Reference< uno::XComponentContext >& context
121                    ,bool _bPageSection)
122 :SectionBase(m_aMutex)
123 ,SectionPropertySet(context,SectionPropertySet::IMPLEMENTS_PROPERTY_SET,lcl_getAbsent(_bPageSection))
124 ,m_aContainerListeners(m_aMutex)
125 ,m_xContext(context)
126 ,m_xReportDefinition(_xParent)
127 ,m_nHeight(3000)
128 ,m_nBackgroundColor(COL_TRANSPARENT)
129 ,m_nForceNewPage(report::ForceNewPage::NONE)
130 ,m_nNewRowOrCol(report::ForceNewPage::NONE)
131 ,m_bKeepTogether(sal_False)
132 ,m_bCanGrow(sal_False)
133 ,m_bCanShrink(sal_False)
134 ,m_bRepeatSection(sal_False)
135 ,m_bVisible(sal_True)
136 ,m_bBacktransparent(sal_True)
137 ,m_bInRemoveNotify(false)
138 ,m_bInInsertNotify(false)
139 {
140 	DBG_CTOR( rpt_OSection,NULL);
141     init();
142     //.getSdrModel()->createNewPage(m_xSection);
143 }
144 //--------------------------------------------------------------------------
145 // TODO: VirtualFunctionFinder: This is virtual function!
146 //
147 OSection::~OSection()
148 {
149     DBG_DTOR( rpt_OSection,NULL);
150     if ( m_xProxy.is() )
151         m_xProxy->setDelegator( NULL );
152 }
153 //--------------------------------------------------------------------------
154 //IMPLEMENT_FORWARD_XINTERFACE2(OSection,SectionBase,SectionPropertySet)
155 IMPLEMENT_FORWARD_REFCOUNT( OSection, SectionBase )
156 // --------------------------------------------------------------------------------
157 uno::Any SAL_CALL OSection::queryInterface( const uno::Type& _rType ) throw (uno::RuntimeException)
158 {
159 	uno::Any aReturn = SectionBase::queryInterface(_rType);
160     if ( !aReturn.hasValue() )
161         aReturn = SectionPropertySet::queryInterface(_rType);
162 
163     if ( !aReturn.hasValue() && OReportControlModel::isInterfaceForbidden(_rType) )
164         return aReturn;
165 
166 	return aReturn.hasValue() ? aReturn : (m_xProxy.is() ? m_xProxy->queryAggregation(_rType) : aReturn);
167 }
168 
169 // -----------------------------------------------------------------------------
170 void SAL_CALL OSection::dispose() throw(uno::RuntimeException)
171 {
172     OSL_ENSURE(!rBHelper.bDisposed,"Already disposed!");
173 	SectionPropertySet::dispose();
174 	cppu::WeakComponentImplHelperBase::dispose();
175 
176 }
177 // -----------------------------------------------------------------------------
178 // TODO: VirtualFunctionFinder: This is virtual function!
179 //
180 void SAL_CALL OSection::disposing()
181 {
182     lang::EventObject aDisposeEvent( static_cast< ::cppu::OWeakObject* >( this ) );
183     m_aContainerListeners.disposeAndClear( aDisposeEvent );
184     m_xContext.clear();
185     //m_xDrawPage.clear();
186 
187     /*uno::Reference< report::XReportDefinition> xReport = getReportDefinition();
188     ::boost::shared_ptr<rptui::OReportModel> pModel = OReportDefinition::getSdrModel(xReport);
189     osl_incrementInterlockedCount( &m_refCount );
190     while( m_xDrawPage.is() && m_xDrawPage->hasElements() )
191     {
192         try
193         {
194             uno::Reference< drawing::XShape> xShape(m_xDrawPage->getByIndex(0),uno::UNO_QUERY);
195             m_xDrawPage->remove(xShape);
196             ::comphelper::disposeComponent(xShape);
197         }
198         catch(const uno::Exception&)
199         {}
200     }
201     if ( pModel )
202     {
203         uno::Reference< report::XSection> xSection = this;
204         pModel->DeletePage(pModel->getPage(xSection)->GetPageNum());
205     }
206     osl_decrementInterlockedCount( &m_refCount );*/
207 }
208 //--------------------------------------------------------------------------
209 ::rtl::OUString SAL_CALL OSection::getImplementationName(  ) throw(uno::RuntimeException)
210 {
211     return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.report.Section"));
212 }
213 //------------------------------------------------------------------------------
214 uno::Sequence< ::rtl::OUString> OSection::getSupportedServiceNames_Static(void) throw( uno::RuntimeException )
215 {
216 	uno::Sequence< ::rtl::OUString> aSupported(1);
217 	aSupported.getArray()[0] = SERVICE_SECTION;
218 	return aSupported;
219 }
220 //-------------------------------------------------------------------------
221 uno::Sequence< ::rtl::OUString> SAL_CALL OSection::getSupportedServiceNames() throw(uno::RuntimeException)
222 {
223 	return getSupportedServiceNames_Static();
224 }
225 // -----------------------------------------------------------------------------
226 sal_Bool SAL_CALL OSection::supportsService( const ::rtl::OUString& _rServiceName ) throw(uno::RuntimeException)
227 {
228 	return ::comphelper::existsValue(_rServiceName,getSupportedServiceNames_Static());
229 }
230 // -----------------------------------------------------------------------------
231 void OSection::init()
232 {
233     uno::Reference< report::XReportDefinition> xReport = getReportDefinition();
234     ::boost::shared_ptr<rptui::OReportModel> pModel = OReportDefinition::getSdrModel(xReport);
235     OSL_ENSURE(pModel,"No odel set at the report definition!");
236     if ( pModel )
237     {
238 // DO NOT TOUCH THIS BLOCKS, WE HAVE A COMPILER PROBLEM UNDER SOLARIS X86
239         osl_incrementInterlockedCount( &m_refCount );
240         {
241 			uno::Reference<report::XSection> xTemp = this;
242 			{
243 				{
244             		m_xProxy.set(pModel->createNewPage(xTemp)->getUnoPage(),uno::UNO_QUERY);
245 				}
246 				{
247 		            ::comphelper::query_aggregation(m_xProxy,m_xDrawPage);
248 				}
249 
250         	    // set ourself as delegator
251 				{
252     		        if ( m_xProxy.is() )
253 					{
254                 		m_xProxy->setDelegator( xTemp );
255 					}
256 				}
257 			}
258 			xTemp.clear();
259         }
260 // DO NOT TOUCH THIS BLOCKS, WE HAVE A COMPILER PROBLEM UNDER SOLARIS X86
261         osl_decrementInterlockedCount( &m_refCount );
262     }
263 }
264 // -----------------------------------------------------------------------------
265 // XSection
266 // -----------------------------------------------------------------------------
267 ::sal_Bool SAL_CALL OSection::getVisible() throw (uno::RuntimeException)
268 {
269 	::osl::MutexGuard aGuard(m_aMutex);
270 	return m_bVisible;
271 }
272 // -----------------------------------------------------------------------------
273 void SAL_CALL OSection::setVisible( ::sal_Bool _visible ) throw (uno::RuntimeException)
274 {
275 	set(PROPERTY_VISIBLE,_visible,m_bVisible);
276 }
277 // -----------------------------------------------------------------------------
278 ::rtl::OUString SAL_CALL OSection::getName() throw (uno::RuntimeException)
279 {
280 	::osl::MutexGuard aGuard(m_aMutex);
281 	return m_sName;
282 }
283 // -----------------------------------------------------------------------------
284 void SAL_CALL OSection::setName( const ::rtl::OUString& _name ) throw (uno::RuntimeException)
285 {
286 	set(PROPERTY_NAME,_name,m_sName);
287 }
288 // -----------------------------------------------------------------------------
289 ::sal_uInt32 SAL_CALL OSection::getHeight() throw (uno::RuntimeException)
290 {
291 	::osl::MutexGuard aGuard(m_aMutex);
292 	return m_nHeight;
293 }
294 // -----------------------------------------------------------------------------
295 void SAL_CALL OSection::setHeight( ::sal_uInt32 _height ) throw (uno::RuntimeException)
296 {
297 	set(PROPERTY_HEIGHT,_height,m_nHeight);
298 }
299 // -----------------------------------------------------------------------------
300 ::sal_Int32 SAL_CALL OSection::getBackColor() throw (uno::RuntimeException)
301 {
302 	::osl::MutexGuard aGuard(m_aMutex);
303     return m_bBacktransparent ? COL_TRANSPARENT : m_nBackgroundColor;
304 }
305 // -----------------------------------------------------------------------------
306 void SAL_CALL OSection::setBackColor( ::sal_Int32 _backgroundcolor ) throw (uno::RuntimeException)
307 {
308     sal_Bool bTransparent = _backgroundcolor == static_cast<sal_Int32>(COL_TRANSPARENT);
309     setBackTransparent(bTransparent);
310     if ( !bTransparent )
311 	    set(PROPERTY_BACKCOLOR,_backgroundcolor,m_nBackgroundColor);
312 }
313 // -----------------------------------------------------------------------------
314 ::sal_Bool SAL_CALL OSection::getBackTransparent() throw (uno::RuntimeException)
315 {
316     ::osl::MutexGuard aGuard(m_aMutex);
317     return m_bBacktransparent;
318 }
319 // -----------------------------------------------------------------------------
320 void SAL_CALL OSection::setBackTransparent( ::sal_Bool _backtransparent ) throw (uno::RuntimeException)
321 {
322     set(PROPERTY_BACKTRANSPARENT,_backtransparent,m_bBacktransparent);
323     if ( _backtransparent )
324         set(PROPERTY_BACKCOLOR,static_cast<sal_Int32>(COL_TRANSPARENT),m_nBackgroundColor);
325 }
326 // -----------------------------------------------------------------------------
327 ::rtl::OUString SAL_CALL OSection::getConditionalPrintExpression() throw (uno::RuntimeException)
328 {
329 	::osl::MutexGuard aGuard(m_aMutex);
330 	return m_sConditionalPrintExpression;
331 }
332 // -----------------------------------------------------------------------------
333 void SAL_CALL OSection::setConditionalPrintExpression( const ::rtl::OUString& _conditionalprintexpression ) throw (uno::RuntimeException)
334 {
335 	set(PROPERTY_CONDITIONALPRINTEXPRESSION,_conditionalprintexpression,m_sConditionalPrintExpression);
336 }
337 // -----------------------------------------------------------------------------
338 void OSection::checkNotPageHeaderFooter()
339 {
340     ::osl::MutexGuard aGuard(m_aMutex);
341     uno::Reference< report::XReportDefinition > xRet = m_xReportDefinition;
342     if ( xRet.is() )
343     {
344         if ( xRet->getPageHeaderOn() && xRet->getPageHeader() == *this )
345             throw beans::UnknownPropertyException();
346         if ( xRet->getPageFooterOn() && xRet->getPageFooter() == *this )
347             throw beans::UnknownPropertyException();
348     }
349 }
350 // -----------------------------------------------------------------------------
351 ::sal_Int16 SAL_CALL OSection::getForceNewPage() throw (beans::UnknownPropertyException, uno::RuntimeException)
352 {
353 	::osl::MutexGuard aGuard(m_aMutex);
354 
355     checkNotPageHeaderFooter();
356 	return m_nForceNewPage;
357 }
358 // -----------------------------------------------------------------------------
359 void SAL_CALL OSection::setForceNewPage( ::sal_Int16 _forcenewpage ) throw (lang::IllegalArgumentException, beans::UnknownPropertyException, uno::RuntimeException)
360 {
361 	if ( _forcenewpage < report::ForceNewPage::NONE || _forcenewpage > report::ForceNewPage::BEFORE_AFTER_SECTION )
362 		throwIllegallArgumentException(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com::sun::star::report::ForceNewPage"))
363                         ,*this
364                         ,1
365                         ,m_xContext);
366     checkNotPageHeaderFooter();
367 	set(PROPERTY_FORCENEWPAGE,_forcenewpage,m_nForceNewPage);
368 }
369 // -----------------------------------------------------------------------------
370 ::sal_Int16 SAL_CALL OSection::getNewRowOrCol() throw (beans::UnknownPropertyException, uno::RuntimeException)
371 {
372 	::osl::MutexGuard aGuard(m_aMutex);
373     checkNotPageHeaderFooter();
374 	return m_nNewRowOrCol;
375 }
376 // -----------------------------------------------------------------------------
377 void SAL_CALL OSection::setNewRowOrCol( ::sal_Int16 _newroworcol ) throw (lang::IllegalArgumentException, beans::UnknownPropertyException, uno::RuntimeException)
378 {
379 	if ( _newroworcol < report::ForceNewPage::NONE || _newroworcol > report::ForceNewPage::BEFORE_AFTER_SECTION )
380 		throwIllegallArgumentException(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com::sun::star::report::ForceNewPage"))
381                         ,*this
382                         ,1
383                         ,m_xContext);
384     checkNotPageHeaderFooter();
385 
386 	set(PROPERTY_NEWROWORCOL,_newroworcol,m_nNewRowOrCol);
387 }
388 // -----------------------------------------------------------------------------
389 ::sal_Bool SAL_CALL OSection::getKeepTogether() throw (beans::UnknownPropertyException, uno::RuntimeException)
390 {
391 	::osl::MutexGuard aGuard(m_aMutex);
392     checkNotPageHeaderFooter();
393 	return m_bKeepTogether;
394 }
395 // -----------------------------------------------------------------------------
396 void SAL_CALL OSection::setKeepTogether( ::sal_Bool _keeptogether ) throw (lang::IllegalArgumentException, beans::UnknownPropertyException, uno::RuntimeException)
397 {
398     {
399         ::osl::MutexGuard aGuard(m_aMutex);
400         checkNotPageHeaderFooter();
401     }
402 
403 	set(PROPERTY_KEEPTOGETHER,_keeptogether,m_bKeepTogether);
404 }
405 // -----------------------------------------------------------------------------
406 ::sal_Bool SAL_CALL OSection::getCanGrow() throw (beans::UnknownPropertyException, uno::RuntimeException)
407 {
408     throw beans::UnknownPropertyException(); ///TODO: unsupported at the moment
409 }
410 // -----------------------------------------------------------------------------
411 void SAL_CALL OSection::setCanGrow( ::sal_Bool /*_cangrow*/ ) throw (lang::IllegalArgumentException, beans::UnknownPropertyException, uno::RuntimeException)
412 {
413     throw beans::UnknownPropertyException(); ///TODO: unsupported at the moment
414 }
415 // -----------------------------------------------------------------------------
416 ::sal_Bool SAL_CALL OSection::getCanShrink() throw (beans::UnknownPropertyException, uno::RuntimeException)
417 {
418     throw beans::UnknownPropertyException(); ///TODO: unsupported at the moment
419 }
420 // -----------------------------------------------------------------------------
421 void SAL_CALL OSection::setCanShrink( ::sal_Bool /*_canshrink*/ ) throw (lang::IllegalArgumentException, beans::UnknownPropertyException, uno::RuntimeException)
422 {
423     throw beans::UnknownPropertyException(); ///TODO: unsupported at the moment
424 }
425 // -----------------------------------------------------------------------------
426 ::sal_Bool SAL_CALL OSection::getRepeatSection() throw (beans::UnknownPropertyException, uno::RuntimeException)
427 {
428 	::osl::MutexGuard aGuard(m_aMutex);
429     uno::Reference< report::XGroup > xGroup = m_xGroup;
430     if ( !xGroup.is() )
431         throw beans::UnknownPropertyException();
432 	return m_bRepeatSection;
433 }
434 // -----------------------------------------------------------------------------
435 void SAL_CALL OSection::setRepeatSection( ::sal_Bool _repeatsection ) throw (lang::IllegalArgumentException, beans::UnknownPropertyException, uno::RuntimeException)
436 {
437     {
438         ::osl::MutexGuard aGuard(m_aMutex);
439         uno::Reference< report::XGroup > xGroup = m_xGroup;
440         if ( !xGroup.is() )
441             throw beans::UnknownPropertyException();
442     }
443 	set(PROPERTY_REPEATSECTION,_repeatsection,m_bRepeatSection);
444 }
445 // -----------------------------------------------------------------------------
446 uno::Reference< report::XGroup > SAL_CALL OSection::getGroup() throw (uno::RuntimeException)
447 {
448 	::osl::MutexGuard aGuard(m_aMutex);
449 	return m_xGroup;
450 }
451 // -----------------------------------------------------------------------------
452 uno::Reference< report::XReportDefinition > SAL_CALL OSection::getReportDefinition() throw (uno::RuntimeException)
453 {
454 	::osl::MutexGuard aGuard(m_aMutex);
455 	uno::Reference< report::XReportDefinition > xRet = m_xReportDefinition;
456 	uno::Reference< report::XGroup > xGroup = m_xGroup;
457 	if ( !xRet.is() && xGroup.is() )
458 	{
459 		uno::Reference< report::XGroups> xGroups(xGroup->getGroups());
460 		if ( xGroups.is() )
461 			xRet = xGroups->getReportDefinition();
462 	}
463 
464 	return xRet;
465 }
466 // -----------------------------------------------------------------------------
467 const ::std::vector< ::rtl::OUString >& lcl_getControlModelMap()
468 {
469 	static ::std::vector< ::rtl::OUString > s_sControlModels;
470 	if ( s_sControlModels.empty() )
471 	{
472 		s_sControlModels.push_back( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FixedText")) );
473         s_sControlModels.push_back( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FixedLine")) );
474 		s_sControlModels.push_back( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ImageControl")) );
475 		s_sControlModels.push_back( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FormattedField")) );
476         s_sControlModels.push_back( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Shape")) );
477 	} // if ( s_sMap.empty() )
478 	return s_sControlModels;
479 
480 }
481 // -----------------------------------------------------------------------------
482 uno::Reference< report::XReportComponent > SAL_CALL OSection::createReportComponent( const ::rtl::OUString& _sReportComponentSpecifier ) throw (uno::Exception, lang::IllegalArgumentException,uno::RuntimeException)
483 {
484 	::osl::ResettableMutexGuard aGuard(m_aMutex);
485 	const ::std::vector< ::rtl::OUString >& aRet = lcl_getControlModelMap();
486 	::std::vector< ::rtl::OUString >::const_iterator aFind = ::std::find(aRet.begin(),aRet.end(),_sReportComponentSpecifier);
487 	if ( aFind == aRet.end() )
488 		throw lang::IllegalArgumentException();
489 
490 	uno::Reference< report::XReportComponent > xRet;
491     uno::Reference< lang::XMultiServiceFactory> xFac(getReportDefinition(),uno::UNO_QUERY_THROW);
492 	switch( aFind - aRet.begin()  )
493 	{
494 		case 0:
495             xRet.set(xFac->createInstance(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.form.component.FixedText"))),uno::UNO_QUERY);
496 			break;
497         case 1:
498             xRet.set(xFac->createInstance(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoControlFixedLineModel"))),uno::UNO_QUERY);
499 			break;
500 		case 2:
501             xRet.set(xFac->createInstance(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.form.component.DatabaseImageControl"))),uno::UNO_QUERY);
502 			break;
503 		case 3:
504 			xRet.set(xFac->createInstance(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.form.component.FormattedField"))),uno::UNO_QUERY);
505 			break;
506         case 4:
507 			xRet.set(xFac->createInstance(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.ControlShape"))),uno::UNO_QUERY);
508 			break;
509         default:
510 			//xRet = new OShape(m_xContext);
511 			break;
512 	} // switch( aRet.begin() - aFind  )
513 	return xRet;
514 }
515 // -----------------------------------------------------------------------------
516 uno::Sequence< ::rtl::OUString > SAL_CALL OSection::getAvailableReportComponentNames(  ) throw (uno::RuntimeException)
517 {
518 	::osl::MutexGuard aGuard(m_aMutex);
519 
520 	const ::std::vector< ::rtl::OUString >& aRet = lcl_getControlModelMap();
521 	const ::rtl::OUString* pRet = aRet.empty() ? 0 : &aRet[0];
522 	return uno::Sequence< ::rtl::OUString >(pRet, aRet.size());
523 }
524 // -----------------------------------------------------------------------------
525 // XChild
526 uno::Reference< uno::XInterface > SAL_CALL OSection::getParent(  ) throw (uno::RuntimeException)
527 {
528 	uno::Reference< uno::XInterface > xRet;
529 	{
530 		::osl::MutexGuard aGuard(m_aMutex);
531 		xRet = m_xReportDefinition;
532 		if ( !xRet.is() )
533 			xRet = m_xGroup;
534 	}
535 	return  xRet;
536 }
537 // -----------------------------------------------------------------------------
538 void SAL_CALL OSection::setParent( const uno::Reference< uno::XInterface >& /*Parent*/ ) throw (lang::NoSupportException, uno::RuntimeException)
539 {
540 	throw lang::NoSupportException();
541 }
542 // -----------------------------------------------------------------------------
543 // XContainer
544 void SAL_CALL OSection::addContainerListener( const uno::Reference< container::XContainerListener >& xListener ) throw (uno::RuntimeException)
545 {
546 	m_aContainerListeners.addInterface(xListener);
547 }
548 // -----------------------------------------------------------------------------
549 void SAL_CALL OSection::removeContainerListener( const uno::Reference< container::XContainerListener >& xListener ) throw (uno::RuntimeException)
550 {
551 	m_aContainerListeners.removeInterface(xListener);
552 }
553 // -----------------------------------------------------------------------------
554 // XElementAccess
555 uno::Type SAL_CALL OSection::getElementType(  ) throw (uno::RuntimeException)
556 {
557 	return ::getCppuType(static_cast< uno::Reference<report::XReportComponent>*>(NULL));
558 }
559 // -----------------------------------------------------------------------------
560 ::sal_Bool SAL_CALL OSection::hasElements(  ) throw (uno::RuntimeException)
561 {
562 	::osl::MutexGuard aGuard(m_aMutex);
563     return m_xDrawPage.is() ? m_xDrawPage->hasElements() : sal_False;
564 }
565 // -----------------------------------------------------------------------------
566 // XIndexAccess
567 ::sal_Int32 SAL_CALL OSection::getCount(  ) throw (uno::RuntimeException)
568 {
569 	::osl::MutexGuard aGuard(m_aMutex);
570     return m_xDrawPage.is() ? m_xDrawPage->getCount() : 0;
571 }
572 // -----------------------------------------------------------------------------
573 uno::Any SAL_CALL OSection::getByIndex( ::sal_Int32 Index ) throw (lang::IndexOutOfBoundsException, lang::WrappedTargetException, uno::RuntimeException)
574 {
575 	::osl::MutexGuard aGuard(m_aMutex);
576     return m_xDrawPage->getByIndex(Index);
577 }
578 // -----------------------------------------------------------------------------
579 // XEnumerationAccess
580 uno::Reference< container::XEnumeration > SAL_CALL OSection::createEnumeration(  ) throw (uno::RuntimeException)
581 {
582 	::osl::MutexGuard aGuard(m_aMutex);
583 	return new ::comphelper::OEnumerationByIndex(static_cast<XIndexAccess*>(this));
584 }
585 // -----------------------------------------------------------------------------
586 uno::Reference< beans::XPropertySetInfo > SAL_CALL OSection::getPropertySetInfo(  ) throw(uno::RuntimeException)
587 {
588 	return SectionPropertySet::getPropertySetInfo();
589 }
590 // -------------------------------------------------------------------------
591 void SAL_CALL OSection::setPropertyValue( const ::rtl::OUString& aPropertyName, const uno::Any& aValue ) throw (beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
592 {
593 	SectionPropertySet::setPropertyValue( aPropertyName, aValue );
594 }
595 // -----------------------------------------------------------------------------
596 uno::Any SAL_CALL OSection::getPropertyValue( const ::rtl::OUString& PropertyName ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
597 {
598 	return SectionPropertySet::getPropertyValue( PropertyName);
599 }
600 // -----------------------------------------------------------------------------
601 void SAL_CALL OSection::addPropertyChangeListener( const ::rtl::OUString& aPropertyName, const uno::Reference< beans::XPropertyChangeListener >& xListener ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
602 {
603 	SectionPropertySet::addPropertyChangeListener( aPropertyName, xListener );
604 }
605 // -----------------------------------------------------------------------------
606 void SAL_CALL OSection::removePropertyChangeListener( const ::rtl::OUString& aPropertyName, const uno::Reference< beans::XPropertyChangeListener >& aListener ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
607 {
608 	SectionPropertySet::removePropertyChangeListener( aPropertyName, aListener );
609 }
610 // -----------------------------------------------------------------------------
611 void SAL_CALL OSection::addVetoableChangeListener( const ::rtl::OUString& PropertyName, const uno::Reference< beans::XVetoableChangeListener >& aListener ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
612 {
613 	SectionPropertySet::addVetoableChangeListener( PropertyName, aListener );
614 }
615 // -----------------------------------------------------------------------------
616 void SAL_CALL OSection::removeVetoableChangeListener( const ::rtl::OUString& PropertyName, const uno::Reference< beans::XVetoableChangeListener >& aListener ) throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
617 {
618 	SectionPropertySet::removeVetoableChangeListener( PropertyName, aListener );
619 }
620 // -----------------------------------------------------------------------------
621 void OSection::lcl_copySection(const uno::Reference< report::XSection>& _xSource,uno::Reference< report::XSection>& _xDest)
622 {
623 	if ( _xSource.is() )
624 	{
625 		::comphelper::copyProperties(_xSource.get(),_xDest.get());
626 		sal_Int32 nCount = _xSource->getCount();
627 		for(sal_Int32 i = 0;i != nCount;++i)
628 		{
629 			uno::Reference<util::XCloneable> xClone(_xSource->getByIndex(i),uno::UNO_QUERY);
630 			OSL_ENSURE(xClone.is(),"No XCloneable interface found!");
631 			if ( xClone.is() )
632             {
633                 uno::Reference< drawing::XShape> xShape(xClone->createClone(),uno::UNO_QUERY);
634                 _xDest->add(xShape);
635             }
636 		}
637 	}
638 }
639 // -----------------------------------------------------------------------------
640 void SAL_CALL OSection::add( const uno::Reference< drawing::XShape >& xShape ) throw (uno::RuntimeException)
641 {
642     {
643         ::osl::MutexGuard aGuard(m_aMutex);
644         m_bInInsertNotify = true;
645         OSL_ENSURE(m_xDrawPage.is(),"No DrawPage!");
646         m_xDrawPage->add(xShape);
647         m_bInInsertNotify = false;
648     }
649     notifyElementAdded(xShape);
650 }
651 // -----------------------------------------------------------------------------
652 void SAL_CALL OSection::remove( const uno::Reference< drawing::XShape >& xShape ) throw (uno::RuntimeException)
653 {
654     {
655         ::osl::MutexGuard aGuard(m_aMutex);
656         m_bInRemoveNotify = true;
657         OSL_ENSURE(m_xDrawPage.is(),"No DrawPage!");
658         m_xDrawPage->remove(xShape);
659         m_bInRemoveNotify = false;
660     }
661     notifyElementRemoved(xShape);
662 }
663 // -----------------------------------------------------------------------------
664 // -----------------------------------------------------------------------------
665 // com::sun::star::lang::XUnoTunnel
666 //------------------------------------------------------------------
667 sal_Int64 OSection::getSomething( const uno::Sequence< sal_Int8 > & rId ) throw (uno::RuntimeException)
668 {
669 	if (rId.getLength() == 16 && 0 == rtl_compareMemory(getUnoTunnelImplementationId().getConstArray(),  rId.getConstArray(), 16 ) )
670 		return reinterpret_cast<sal_Int64>(this);
671     uno::Reference< lang::XUnoTunnel> xTunnel;
672     ::comphelper::query_aggregation(m_xProxy,xTunnel);
673 	return xTunnel->getSomething(rId);
674 }
675 
676 // -----------------------------------------------------------------------------
677 OSection* OSection::getImplementation( const uno::Reference< uno::XInterface >& _rxComponent )
678 {
679 	OSection* pContent( NULL );
680 
681     uno::Reference< lang::XUnoTunnel > xUnoTunnel( _rxComponent, uno::UNO_QUERY );
682 	if ( xUnoTunnel.is() )
683 		pContent = reinterpret_cast< OSection* >( xUnoTunnel->getSomething( getUnoTunnelImplementationId() ) );
684 
685     return pContent;
686 }
687 //------------------------------------------------------------------------
688 uno::Sequence< sal_Int8 > OSection::getUnoTunnelImplementationId()
689 {
690 	static ::cppu::OImplementationId * pId = 0;
691 	if (! pId)
692 	{
693 		::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
694 		if (! pId)
695 		{
696 			static ::cppu::OImplementationId aId;
697 			pId = &aId;
698 		}
699 	}
700 	return pId->getImplementationId();
701 }
702 // -----------------------------------------------------------------------------
703 void OSection::notifyElementAdded(const uno::Reference< drawing::XShape >& xShape )
704 {
705     if ( !m_bInInsertNotify )
706     {
707         container::ContainerEvent aEvent(static_cast<container::XContainer*>(this), uno::Any(), uno::makeAny(xShape), uno::Any());
708 	    m_aContainerListeners.notifyEach(&container::XContainerListener::elementInserted,aEvent);
709     }
710 }
711 // -----------------------------------------------------------------------------
712 void OSection::notifyElementRemoved(const uno::Reference< drawing::XShape >& xShape)
713 {
714     if ( !m_bInRemoveNotify )
715     {
716         // notify our container listeners
717         container::ContainerEvent aEvent(static_cast<container::XContainer*>(this), uno::Any(), uno::makeAny(xShape), uno::Any());
718 	    m_aContainerListeners.notifyEach(&container::XContainerListener::elementRemoved,aEvent);
719     }
720 }
721 // =============================================================================
722 } // namespace reportdesign
723 // =============================================================================
724