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