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