Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 : #include "RptObject.hxx"
20 : #include <vector>
21 : #include <algorithm>
22 :
23 : #include <RptDef.hxx>
24 : #include <svx/unoshape.hxx>
25 : #include "RptModel.hxx"
26 : #include "RptObjectListener.hxx"
27 : #include <toolkit/helper/vclunohelper.hxx>
28 : #include <toolkit/helper/convert.hxx>
29 : #include "RptPage.hxx"
30 : #include "corestrings.hrc"
31 : #include <dbaccess/dbsubcomponentcontroller.hxx>
32 : #include "ModuleHelper.hxx"
33 :
34 : #include <RptResId.hrc>
35 : #include <svx/xflclit.hxx>
36 : #include <svx/xlnclit.hxx>
37 : #include <svx/xlndsit.hxx>
38 : #include <svx/xlineit0.hxx>
39 : #include <svx/sderitm.hxx>
40 : #include <svx/xlnwtit.hxx>
41 : #include <svx/xlntrit.hxx>
42 : #include <com/sun/star/style/XStyle.hpp>
43 : #include <com/sun/star/awt/XTabControllerModel.hpp>
44 : #include <com/sun/star/awt/XUnoControlContainer.hpp>
45 : #include <com/sun/star/awt/XVclContainerPeer.hpp>
46 : #include <com/sun/star/awt/XWindow.hpp>
47 : #include <com/sun/star/awt/TextAlign.hpp>
48 : #include <com/sun/star/beans/XPropertySet.hpp>
49 : #include <com/sun/star/beans/PropertyAttribute.hpp>
50 : #include <com/sun/star/embed/XComponentSupplier.hpp>
51 : #include <com/sun/star/script/XScriptEventsSupplier.hpp>
52 : #include <com/sun/star/container/XContainer.hpp>
53 : #include <com/sun/star/lang/XServiceInfo.hpp>
54 : #include <com/sun/star/report/XShape.hpp>
55 : #include <com/sun/star/report/XFixedLine.hpp>
56 : #include <com/sun/star/chart/ChartDataRowSource.hpp>
57 : #include <com/sun/star/chart2/data/XDataReceiver.hpp>
58 : #include <com/sun/star/chart2/data/DatabaseDataProvider.hpp>
59 : #include <com/sun/star/chart2/XChartDocument.hpp>
60 : #include <com/sun/star/style/VerticalAlignment.hpp>
61 : #include <com/sun/star/style/ParagraphAdjust.hpp>
62 : #include <com/sun/star/report/XFormattedField.hpp>
63 : #include <comphelper/genericpropertyset.hxx>
64 : #include <comphelper/processfactory.hxx>
65 : #include <comphelper/property.hxx>
66 : #include <tools/diagnose_ex.h>
67 : #include "PropertyForward.hxx"
68 : #include <connectivity/dbtools.hxx>
69 : #include <connectivity/dbconversion.hxx>
70 : #include "UndoActions.hxx"
71 : #include "UndoEnv.hxx"
72 : #include <functional>
73 :
74 : namespace rptui
75 : {
76 :
77 : using namespace ::com::sun::star;
78 : using namespace uno;
79 : using namespace beans;
80 : using namespace reportdesign;
81 : using namespace container;
82 : using namespace script;
83 : using namespace report;
84 : //----------------------------------------------------------------------------
85 0 : sal_uInt16 OObjectBase::getObjectType(const uno::Reference< report::XReportComponent>& _xComponent)
86 : {
87 0 : uno::Reference< lang::XServiceInfo > xServiceInfo( _xComponent , uno::UNO_QUERY );
88 : OSL_ENSURE(xServiceInfo.is(),"Who deletes the XServiceInfo interface!");
89 0 : if ( xServiceInfo.is() )
90 : {
91 0 : if ( xServiceInfo->supportsService( SERVICE_FIXEDTEXT ))
92 0 : return OBJ_DLG_FIXEDTEXT;
93 0 : if ( xServiceInfo->supportsService( SERVICE_FIXEDLINE ))
94 : {
95 0 : uno::Reference< report::XFixedLine> xFixedLine(_xComponent,uno::UNO_QUERY);
96 0 : return xFixedLine->getOrientation() ? OBJ_DLG_HFIXEDLINE : OBJ_DLG_VFIXEDLINE;
97 : }
98 0 : if ( xServiceInfo->supportsService( SERVICE_IMAGECONTROL))
99 0 : return OBJ_DLG_IMAGECONTROL;
100 0 : if ( xServiceInfo->supportsService( SERVICE_FORMATTEDFIELD ))
101 0 : return OBJ_DLG_FORMATTEDFIELD;
102 0 : if ( xServiceInfo->supportsService("com.sun.star.drawing.OLE2Shape") )
103 0 : return OBJ_OLE2;
104 0 : if ( xServiceInfo->supportsService( SERVICE_SHAPE ))
105 0 : return OBJ_CUSTOMSHAPE;
106 0 : if ( xServiceInfo->supportsService( SERVICE_REPORTDEFINITION ) )
107 0 : return OBJ_DLG_SUBREPORT;
108 0 : return OBJ_OLE2;
109 : }
110 0 : return 0;
111 : }
112 : // -----------------------------------------------------------------------------
113 0 : SdrObject* OObjectBase::createObject(const uno::Reference< report::XReportComponent>& _xComponent)
114 : {
115 0 : SdrObject* pNewObj = NULL;
116 0 : sal_uInt16 nType = OObjectBase::getObjectType(_xComponent);
117 0 : switch( nType )
118 : {
119 : case OBJ_DLG_FIXEDTEXT:
120 : {
121 : OUnoObject* pUnoObj = new OUnoObject( _xComponent
122 : ,OUString("com.sun.star.form.component.FixedText")
123 0 : ,OBJ_DLG_FIXEDTEXT);
124 0 : pNewObj = pUnoObj;
125 :
126 0 : uno::Reference<beans::XPropertySet> xControlModel(pUnoObj->GetUnoControlModel(),uno::UNO_QUERY);
127 0 : if ( xControlModel.is() )
128 0 : xControlModel->setPropertyValue( PROPERTY_MULTILINE,uno::makeAny(sal_True));
129 : }
130 0 : break;
131 : case OBJ_DLG_IMAGECONTROL:
132 : pNewObj = new OUnoObject(_xComponent
133 : ,OUString("com.sun.star.form.component.DatabaseImageControl")
134 0 : ,OBJ_DLG_IMAGECONTROL);
135 0 : break;
136 : case OBJ_DLG_FORMATTEDFIELD:
137 : pNewObj = new OUnoObject( _xComponent
138 : ,OUString("com.sun.star.form.component.FormattedField")
139 0 : ,OBJ_DLG_FORMATTEDFIELD);
140 0 : break;
141 : case OBJ_DLG_HFIXEDLINE:
142 : case OBJ_DLG_VFIXEDLINE:
143 : pNewObj = new OUnoObject( _xComponent
144 : ,OUString("com.sun.star.awt.UnoControlFixedLineModel")
145 0 : ,nType);
146 0 : break;
147 : case OBJ_CUSTOMSHAPE:
148 0 : pNewObj = OCustomShape::Create( _xComponent );
149 : try
150 : {
151 0 : sal_Bool bOpaque = sal_False;
152 0 : _xComponent->getPropertyValue(PROPERTY_OPAQUE) >>= bOpaque;
153 0 : pNewObj->SetLayer(bOpaque ? RPT_LAYER_FRONT : RPT_LAYER_BACK);
154 : }
155 0 : catch(const uno::Exception&)
156 : {
157 : DBG_UNHANDLED_EXCEPTION();
158 : }
159 0 : break;
160 : case OBJ_DLG_SUBREPORT:
161 : case OBJ_OLE2:
162 0 : pNewObj = OOle2Obj::Create( _xComponent,nType );
163 0 : break;
164 : default:
165 : OSL_FAIL("Unknown object id");
166 0 : break;
167 : }
168 :
169 0 : if ( pNewObj )
170 0 : pNewObj->SetDoNotInsertIntoPageAutomatically( true );
171 :
172 0 : ensureSdrObjectOwnership( _xComponent );
173 :
174 0 : return pNewObj;
175 : }
176 : // -----------------------------------------------------------------------------
177 : namespace
178 : {
179 0 : class ParaAdjust : public AnyConverter
180 : {
181 : public:
182 0 : virtual ::com::sun::star::uno::Any operator() (const OUString& _sPropertyName,const ::com::sun::star::uno::Any& lhs) const
183 : {
184 0 : uno::Any aRet;
185 0 : if (_sPropertyName == PROPERTY_PARAADJUST)
186 : {
187 0 : sal_Int16 nTextAlign = 0;
188 0 : lhs >>= nTextAlign;
189 0 : switch(nTextAlign)
190 : {
191 : case awt::TextAlign::LEFT:
192 0 : nTextAlign = style::ParagraphAdjust_LEFT;
193 0 : break;
194 : case awt::TextAlign::CENTER:
195 0 : nTextAlign = style::ParagraphAdjust_CENTER;
196 0 : break;
197 : case awt::TextAlign::RIGHT:
198 0 : nTextAlign = style::ParagraphAdjust_RIGHT;
199 0 : break;
200 : default:
201 : OSL_FAIL("Illegal text alignment value!");
202 0 : break;
203 : }
204 0 : aRet <<= (style::ParagraphAdjust)nTextAlign;
205 : }
206 : else
207 : {
208 0 : sal_Int16 nTextAlign = 0;
209 0 : sal_Int16 eParagraphAdjust = 0;
210 0 : lhs >>= eParagraphAdjust;
211 0 : switch(eParagraphAdjust)
212 : {
213 : case style::ParagraphAdjust_LEFT:
214 : case style::ParagraphAdjust_BLOCK:
215 0 : nTextAlign = awt::TextAlign::LEFT;
216 0 : break;
217 : case style::ParagraphAdjust_CENTER:
218 0 : nTextAlign = awt::TextAlign::CENTER;
219 0 : break;
220 : case style::ParagraphAdjust_RIGHT:
221 0 : nTextAlign = awt::TextAlign::RIGHT;
222 0 : break;
223 : default:
224 : OSL_FAIL("Illegal text alignment value!");
225 0 : break;
226 : }
227 0 : aRet <<= nTextAlign;
228 : }
229 0 : return aRet;
230 : }
231 : };
232 : }
233 : // -----------------------------------------------------------------------------
234 0 : const TPropertyNamePair& getPropertyNameMap(sal_uInt16 _nObjectId)
235 : {
236 0 : switch(_nObjectId)
237 : {
238 : case OBJ_DLG_IMAGECONTROL:
239 : {
240 0 : static TPropertyNamePair s_aNameMap;
241 0 : if ( s_aNameMap.empty() )
242 : {
243 0 : ::boost::shared_ptr<AnyConverter> aNoConverter(new AnyConverter());
244 0 : s_aNameMap.insert(TPropertyNamePair::value_type(PROPERTY_CONTROLBACKGROUND,TPropertyConverter(PROPERTY_BACKGROUNDCOLOR,aNoConverter)));
245 0 : s_aNameMap.insert(TPropertyNamePair::value_type(PROPERTY_CONTROLBORDER,TPropertyConverter(PROPERTY_BORDER,aNoConverter)));
246 0 : s_aNameMap.insert(TPropertyNamePair::value_type(PROPERTY_CONTROLBORDERCOLOR,TPropertyConverter(PROPERTY_BORDERCOLOR,aNoConverter)));
247 : }
248 0 : return s_aNameMap;
249 : }
250 :
251 : case OBJ_DLG_FIXEDTEXT:
252 : {
253 0 : static TPropertyNamePair s_aNameMap;
254 0 : if ( s_aNameMap.empty() )
255 : {
256 0 : ::boost::shared_ptr<AnyConverter> aNoConverter(new AnyConverter());
257 0 : s_aNameMap.insert(TPropertyNamePair::value_type(PROPERTY_CHARCOLOR,TPropertyConverter(PROPERTY_TEXTCOLOR,aNoConverter)));
258 0 : s_aNameMap.insert(TPropertyNamePair::value_type(PROPERTY_CONTROLBACKGROUND,TPropertyConverter(PROPERTY_BACKGROUNDCOLOR,aNoConverter)));
259 0 : s_aNameMap.insert(TPropertyNamePair::value_type(PROPERTY_CHARUNDERLINECOLOR,TPropertyConverter(PROPERTY_TEXTLINECOLOR,aNoConverter)));
260 0 : s_aNameMap.insert(TPropertyNamePair::value_type(PROPERTY_CHARRELIEF,TPropertyConverter(PROPERTY_FONTRELIEF,aNoConverter)));
261 0 : s_aNameMap.insert(TPropertyNamePair::value_type(PROPERTY_CHARFONTHEIGHT,TPropertyConverter(PROPERTY_FONTHEIGHT,aNoConverter)));
262 0 : s_aNameMap.insert(TPropertyNamePair::value_type(PROPERTY_CHARSTRIKEOUT,TPropertyConverter(PROPERTY_FONTSTRIKEOUT,aNoConverter)));
263 0 : s_aNameMap.insert(TPropertyNamePair::value_type(PROPERTY_CONTROLTEXTEMPHASISMARK,TPropertyConverter(PROPERTY_FONTEMPHASISMARK,aNoConverter)));
264 0 : s_aNameMap.insert(TPropertyNamePair::value_type(PROPERTY_CONTROLBORDER,TPropertyConverter(PROPERTY_BORDER,aNoConverter)));
265 0 : s_aNameMap.insert(TPropertyNamePair::value_type(PROPERTY_CONTROLBORDERCOLOR,TPropertyConverter(PROPERTY_BORDERCOLOR,aNoConverter)));
266 :
267 0 : ::boost::shared_ptr<AnyConverter> aParaAdjust(new ParaAdjust());
268 0 : s_aNameMap.insert(TPropertyNamePair::value_type(PROPERTY_PARAADJUST,TPropertyConverter(PROPERTY_ALIGN,aParaAdjust)));
269 : }
270 0 : return s_aNameMap;
271 : }
272 : case OBJ_DLG_FORMATTEDFIELD:
273 : {
274 0 : static TPropertyNamePair s_aNameMap;
275 0 : if ( s_aNameMap.empty() )
276 : {
277 0 : ::boost::shared_ptr<AnyConverter> aNoConverter(new AnyConverter());
278 0 : s_aNameMap.insert(TPropertyNamePair::value_type(PROPERTY_CHARCOLOR,TPropertyConverter(PROPERTY_TEXTCOLOR,aNoConverter)));
279 0 : s_aNameMap.insert(TPropertyNamePair::value_type(PROPERTY_CONTROLBACKGROUND,TPropertyConverter(PROPERTY_BACKGROUNDCOLOR,aNoConverter)));
280 0 : s_aNameMap.insert(TPropertyNamePair::value_type(PROPERTY_CHARUNDERLINECOLOR,TPropertyConverter(PROPERTY_TEXTLINECOLOR,aNoConverter)));
281 0 : s_aNameMap.insert(TPropertyNamePair::value_type(PROPERTY_CHARRELIEF,TPropertyConverter(PROPERTY_FONTRELIEF,aNoConverter)));
282 0 : s_aNameMap.insert(TPropertyNamePair::value_type(PROPERTY_CHARFONTHEIGHT,TPropertyConverter(PROPERTY_FONTHEIGHT,aNoConverter)));
283 0 : s_aNameMap.insert(TPropertyNamePair::value_type(PROPERTY_CHARSTRIKEOUT,TPropertyConverter(PROPERTY_FONTSTRIKEOUT,aNoConverter)));
284 0 : s_aNameMap.insert(TPropertyNamePair::value_type(PROPERTY_CONTROLTEXTEMPHASISMARK,TPropertyConverter(PROPERTY_FONTEMPHASISMARK,aNoConverter)));
285 0 : s_aNameMap.insert(TPropertyNamePair::value_type(PROPERTY_CONTROLBORDER,TPropertyConverter(PROPERTY_BORDER,aNoConverter)));
286 0 : s_aNameMap.insert(TPropertyNamePair::value_type(PROPERTY_CONTROLBORDERCOLOR,TPropertyConverter(PROPERTY_BORDERCOLOR,aNoConverter)));
287 0 : ::boost::shared_ptr<AnyConverter> aParaAdjust(new ParaAdjust());
288 0 : s_aNameMap.insert(TPropertyNamePair::value_type(PROPERTY_PARAADJUST,TPropertyConverter(PROPERTY_ALIGN,aParaAdjust)));
289 : }
290 0 : return s_aNameMap;
291 : }
292 :
293 : case OBJ_CUSTOMSHAPE:
294 : {
295 0 : static TPropertyNamePair s_aNameMap;
296 0 : if ( s_aNameMap.empty() )
297 : {
298 0 : ::boost::shared_ptr<AnyConverter> aNoConverter(new AnyConverter());
299 0 : s_aNameMap.insert(TPropertyNamePair::value_type(OUString("FillColor"),TPropertyConverter(PROPERTY_CONTROLBACKGROUND,aNoConverter)));
300 0 : s_aNameMap.insert(TPropertyNamePair::value_type(PROPERTY_PARAADJUST,TPropertyConverter(PROPERTY_ALIGN,aNoConverter)));
301 : }
302 0 : return s_aNameMap;
303 : }
304 :
305 : default:
306 0 : break;
307 : }
308 0 : static TPropertyNamePair s_aEmptyNameMap;
309 0 : return s_aEmptyNameMap;
310 : }
311 : // -----------------------------------------------------------------------------
312 :
313 : DBG_NAME( rpt_OObjectBase )
314 0 : OObjectBase::OObjectBase(const uno::Reference< report::XReportComponent>& _xComponent)
315 0 : :m_bIsListening(sal_False)
316 : {
317 : DBG_CTOR( rpt_OObjectBase,NULL);
318 0 : m_xReportComponent = _xComponent;
319 0 : }
320 : //----------------------------------------------------------------------------
321 0 : OObjectBase::OObjectBase(const OUString& _sComponentName)
322 : :m_sComponentName(_sComponentName)
323 0 : ,m_bIsListening(sal_False)
324 : {
325 : DBG_CTOR( rpt_OObjectBase,NULL);
326 0 : }
327 : //----------------------------------------------------------------------------
328 0 : OObjectBase::~OObjectBase()
329 : {
330 : DBG_DTOR( rpt_OObjectBase,NULL);
331 0 : m_xMediator.reset();
332 0 : if ( isListening() )
333 0 : EndListening();
334 0 : m_xReportComponent.clear();
335 0 : }
336 : // -----------------------------------------------------------------------------
337 0 : uno::Reference< report::XSection> OObjectBase::getSection() const
338 : {
339 0 : uno::Reference< report::XSection> xSection;
340 0 : OReportPage* pPage = dynamic_cast<OReportPage*>(GetImplPage());
341 0 : if ( pPage )
342 0 : xSection = pPage->getSection();
343 0 : return xSection;
344 : }
345 : // -----------------------------------------------------------------------------
346 0 : uno::Reference< report::XReportComponent> OObjectBase::getReportComponent() const
347 : {
348 0 : return m_xReportComponent;
349 : }
350 : // -----------------------------------------------------------------------------
351 0 : uno::Reference< beans::XPropertySet> OObjectBase::getAwtComponent()
352 : {
353 0 : return uno::Reference< beans::XPropertySet>();
354 : }
355 : //----------------------------------------------------------------------------
356 0 : void OObjectBase::StartListening()
357 : {
358 : DBG_CHKTHIS( rpt_OObjectBase,NULL);
359 : OSL_ENSURE(!isListening(), "OUnoObject::StartListening: already listening!");
360 :
361 0 : if ( !isListening() && m_xReportComponent.is() )
362 : {
363 0 : m_bIsListening = sal_True;
364 :
365 0 : if ( !m_xPropertyChangeListener.is() )
366 : {
367 0 : m_xPropertyChangeListener = new OObjectListener( this );
368 : // register listener to all properties
369 0 : m_xReportComponent->addPropertyChangeListener( OUString() , m_xPropertyChangeListener );
370 : }
371 : }
372 0 : }
373 : //----------------------------------------------------------------------------
374 0 : void OObjectBase::EndListening(sal_Bool /*bRemoveListener*/)
375 : {
376 : DBG_CHKTHIS( rpt_OObjectBase,NULL);
377 : OSL_ENSURE(!m_xReportComponent.is() || isListening(), "OUnoObject::EndListening: not listening currently!");
378 :
379 0 : m_bIsListening = sal_False;
380 0 : if ( isListening() && m_xReportComponent.is() )
381 : {
382 : // XPropertyChangeListener
383 0 : if ( m_xPropertyChangeListener.is() )
384 : {
385 : // remove listener
386 : try
387 : {
388 0 : m_xReportComponent->removePropertyChangeListener( OUString() , m_xPropertyChangeListener );
389 : }
390 0 : catch(const uno::Exception &)
391 : {
392 : OSL_FAIL("OObjectBase::EndListening: Exception caught!");
393 : }
394 : }
395 0 : m_xPropertyChangeListener.clear();
396 : }
397 0 : }
398 : //----------------------------------------------------------------------------
399 0 : void OObjectBase::SetPropsFromRect(const Rectangle& _rRect)
400 : {
401 : DBG_CHKTHIS( rpt_OObjectBase,NULL);
402 : // set properties
403 0 : OReportPage* pPage = dynamic_cast<OReportPage*>(GetImplPage());
404 0 : if ( pPage && !_rRect.IsEmpty() )
405 : {
406 0 : uno::Reference<report::XSection> xSection = pPage->getSection();
407 : assert(_rRect.getHeight() >= 0);
408 0 : const sal_uInt32 newHeight( ::std::max(0l, _rRect.getHeight()+_rRect.Top()) );
409 0 : if ( xSection.is() && ( newHeight > xSection->getHeight() ) )
410 0 : xSection->setHeight( newHeight );
411 :
412 : // TODO
413 : //pModel->GetRefDevice()->Invalidate(INVALIDATE_CHILDREN);
414 : }
415 0 : }
416 : //----------------------------------------------------------------------------
417 0 : void OObjectBase::_propertyChange( const beans::PropertyChangeEvent& /*evt*/ ) throw( uno::RuntimeException)
418 : {
419 : DBG_CHKTHIS( rpt_OObjectBase,NULL);
420 0 : }
421 : //----------------------------------------------------------------------------
422 0 : void OObjectBase::SetObjectItemHelper(const SfxPoolItem& /*rItem*/)
423 : {
424 : // do nothing
425 0 : }
426 :
427 : //----------------------------------------------------------------------------
428 0 : sal_Bool OObjectBase::supportsService( const OUString& _sServiceName ) const
429 : {
430 : DBG_CHKTHIS( rpt_OObjectBase,NULL);
431 0 : sal_Bool bSupports = sal_False;
432 :
433 0 : Reference< lang::XServiceInfo > xServiceInfo( m_xReportComponent , UNO_QUERY );
434 : // TODO: cache xServiceInfo as member?
435 0 : if ( xServiceInfo.is() )
436 0 : bSupports = xServiceInfo->supportsService( _sServiceName );
437 :
438 0 : return bSupports;
439 : }
440 :
441 : //----------------------------------------------------------------------------
442 0 : void OObjectBase::ensureSdrObjectOwnership( const uno::Reference< uno::XInterface >& _rxShape )
443 : {
444 : // UNDO in the report designer is implemented at the level of the XShapes, not
445 : // at the level of SdrObjects. That is, if an object is removed from the report
446 : // design, then this happens by removing the XShape from the UNO DrawPage, and
447 : // putting this XShape (resp. the ReportComponent which wraps it) into an UNDO
448 : // action.
449 : // Unfortunately, the SvxDrawPage implementation usually deletes SdrObjects
450 : // which are removed from it, which is deadly for us. To prevent this,
451 : // we give the XShape implementation the ownership of the SdrObject, which
452 : // ensures the SvxDrawPage won't delete it.
453 0 : SvxShape* pShape = SvxShape::getImplementation( _rxShape );
454 : OSL_ENSURE( pShape, "OObjectBase::ensureSdrObjectOwnership: can't access the SvxShape!" );
455 0 : if ( pShape )
456 : {
457 : OSL_ENSURE( !pShape->HasSdrObjectOwnership(), "OObjectBase::ensureSdrObjectOwnership: called twice?" );
458 0 : pShape->TakeSdrObjectOwnership();
459 : }
460 0 : }
461 :
462 : //----------------------------------------------------------------------------
463 0 : uno::Reference< uno::XInterface > OObjectBase::getUnoShapeOf( SdrObject& _rSdrObject )
464 : {
465 0 : uno::Reference< uno::XInterface > xShape( _rSdrObject.getWeakUnoShape() );
466 0 : if ( xShape.is() )
467 0 : return xShape;
468 :
469 0 : xShape = _rSdrObject.SdrObject::getUnoShape();
470 0 : if ( !xShape.is() )
471 0 : return xShape;
472 :
473 0 : ensureSdrObjectOwnership( xShape );
474 :
475 0 : m_xKeepShapeAlive = xShape;
476 0 : return xShape;
477 : }
478 :
479 : //----------------------------------------------------------------------------
480 0 : TYPEINIT1(OCustomShape, SdrObjCustomShape);
481 : DBG_NAME( rpt_OCustomShape );
482 0 : OCustomShape::OCustomShape(const uno::Reference< report::XReportComponent>& _xComponent
483 : )
484 : :SdrObjCustomShape()
485 0 : ,OObjectBase(_xComponent)
486 : {
487 : DBG_CTOR( rpt_OCustomShape, NULL);
488 0 : impl_setUnoShape( uno::Reference< uno::XInterface >(_xComponent,uno::UNO_QUERY) );
489 0 : m_bIsListening = sal_True;
490 0 : }
491 : //----------------------------------------------------------------------------
492 0 : OCustomShape::OCustomShape(const OUString& _sComponentName)
493 : :SdrObjCustomShape()
494 0 : ,OObjectBase(_sComponentName)
495 : {
496 : DBG_CTOR( rpt_OCustomShape, NULL);
497 0 : m_bIsListening = sal_True;
498 0 : }
499 :
500 : //----------------------------------------------------------------------------
501 0 : OCustomShape::~OCustomShape()
502 : {
503 : DBG_DTOR( rpt_OCustomShape, NULL);
504 0 : }
505 : // -----------------------------------------------------------------------------
506 0 : sal_uInt16 OCustomShape::GetObjIdentifier() const
507 : {
508 0 : return sal_uInt16(OBJ_CUSTOMSHAPE);
509 : }
510 : //----------------------------------------------------------------------------
511 0 : sal_uInt32 OCustomShape::GetObjInventor() const
512 : {
513 0 : return ReportInventor;
514 : }
515 : //----------------------------------------------------------------------------
516 0 : SdrPage* OCustomShape::GetImplPage() const
517 : {
518 0 : return GetPage();
519 : }
520 : //----------------------------------------------------------------------------
521 0 : void OCustomShape::SetSnapRectImpl(const Rectangle& _rRect)
522 : {
523 0 : SetSnapRect( _rRect );
524 0 : }
525 : //----------------------------------------------------------------------------
526 0 : sal_Int32 OCustomShape::GetStep() const
527 : {
528 : // get step property
529 0 : sal_Int32 nStep = 0;
530 : OSL_FAIL("Who called me!");
531 0 : return nStep;
532 : }
533 : //----------------------------------------------------------------------------
534 0 : void OCustomShape::NbcMove( const Size& rSize )
535 : {
536 0 : if ( m_bIsListening )
537 : {
538 0 : m_bIsListening = sal_False;
539 :
540 0 : if ( m_xReportComponent.is() )
541 : {
542 0 : OReportModel* pRptModel = static_cast<OReportModel*>(GetModel());
543 0 : OXUndoEnvironment::OUndoEnvLock aLock(pRptModel->GetUndoEnv());
544 0 : m_xReportComponent->setPositionX(m_xReportComponent->getPositionX() + rSize.A());
545 0 : m_xReportComponent->setPositionY(m_xReportComponent->getPositionY() + rSize.B());
546 : }
547 :
548 : // set geometry properties
549 0 : SetPropsFromRect(GetSnapRect());
550 :
551 0 : m_bIsListening = sal_True;
552 : }
553 : else
554 0 : SdrObjCustomShape::NbcMove( rSize );
555 0 : }
556 : //----------------------------------------------------------------------------
557 0 : void OCustomShape::NbcResize(const Point& rRef, const Fraction& xFract, const Fraction& yFract)
558 : {
559 0 : SdrObjCustomShape::NbcResize( rRef, xFract, yFract );
560 :
561 0 : SetPropsFromRect(GetSnapRect());
562 0 : }
563 : //----------------------------------------------------------------------------
564 0 : void OCustomShape::NbcSetLogicRect(const Rectangle& rRect)
565 : {
566 0 : SdrObjCustomShape::NbcSetLogicRect(rRect);
567 0 : SetPropsFromRect(rRect);
568 0 : }
569 : //----------------------------------------------------------------------------
570 0 : bool OCustomShape::EndCreate(SdrDragStat& rStat, SdrCreateCmd eCmd)
571 : {
572 0 : bool bResult = SdrObjCustomShape::EndCreate(rStat, eCmd);
573 0 : if ( bResult )
574 : {
575 0 : OReportModel* pRptModel = static_cast<OReportModel*>(GetModel());
576 0 : if ( pRptModel )
577 : {
578 0 : OXUndoEnvironment::OUndoEnvLock aLock(pRptModel->GetUndoEnv());
579 0 : if ( !m_xReportComponent.is() )
580 0 : m_xReportComponent.set(getUnoShape(),uno::UNO_QUERY);
581 : }
582 0 : SetPropsFromRect(GetSnapRect());
583 : }
584 :
585 0 : return bResult;
586 : }
587 :
588 : //----------------------------------------------------------------------------
589 0 : void OCustomShape::SetObjectItemHelper(const SfxPoolItem& rItem)
590 : {
591 0 : SetObjectItem(rItem);
592 : // TODO
593 : //getSectionWindow()->getView()->AdjustMarkHdl();
594 0 : }
595 :
596 : // -----------------------------------------------------------------------------
597 0 : uno::Reference< beans::XPropertySet> OCustomShape::getAwtComponent()
598 : {
599 0 : return uno::Reference< beans::XPropertySet>(m_xReportComponent,uno::UNO_QUERY);
600 : }
601 :
602 : //----------------------------------------------------------------------------
603 0 : uno::Reference< uno::XInterface > OCustomShape::getUnoShape()
604 : {
605 0 : uno::Reference< uno::XInterface> xShape = OObjectBase::getUnoShapeOf( *this );
606 0 : if ( !m_xReportComponent.is() )
607 : {
608 0 : OReportModel* pRptModel = static_cast<OReportModel*>(GetModel());
609 0 : OXUndoEnvironment::OUndoEnvLock aLock(pRptModel->GetUndoEnv());
610 0 : m_xReportComponent.set(xShape,uno::UNO_QUERY);
611 : }
612 0 : return xShape;
613 : }
614 :
615 0 : void OCustomShape::impl_setUnoShape( const uno::Reference< uno::XInterface >& rxUnoShape )
616 : {
617 0 : SdrObjCustomShape::impl_setUnoShape( rxUnoShape );
618 0 : releaseUnoShape();
619 0 : m_xReportComponent.clear();
620 0 : }
621 :
622 : //----------------------------------------------------------------------------
623 : //----------------------------------------------------------------------------
624 0 : TYPEINIT1(OUnoObject, SdrUnoObj);
625 : DBG_NAME( rpt_OUnoObject );
626 : //----------------------------------------------------------------------------
627 0 : OUnoObject::OUnoObject(const OUString& _sComponentName
628 : ,const OUString& rModelName
629 : ,sal_uInt16 _nObjectType)
630 : :SdrUnoObj(rModelName, sal_True)
631 : ,OObjectBase(_sComponentName)
632 0 : ,m_nObjectType(_nObjectType)
633 : {
634 : DBG_CTOR( rpt_OUnoObject, NULL);
635 0 : if ( !rModelName.isEmpty() )
636 0 : impl_initializeModel_nothrow();
637 0 : }
638 : //----------------------------------------------------------------------------
639 0 : OUnoObject::OUnoObject(const uno::Reference< report::XReportComponent>& _xComponent
640 : ,const OUString& rModelName
641 : ,sal_uInt16 _nObjectType)
642 : :SdrUnoObj(rModelName, sal_True)
643 : ,OObjectBase(_xComponent)
644 0 : ,m_nObjectType(_nObjectType)
645 : {
646 : DBG_CTOR( rpt_OUnoObject, NULL);
647 0 : impl_setUnoShape( uno::Reference< uno::XInterface >( _xComponent, uno::UNO_QUERY ) );
648 :
649 0 : if ( !rModelName.isEmpty() )
650 0 : impl_initializeModel_nothrow();
651 :
652 0 : }
653 : //----------------------------------------------------------------------------
654 0 : OUnoObject::~OUnoObject()
655 : {
656 : DBG_DTOR( rpt_OUnoObject, NULL);
657 0 : }
658 : // -----------------------------------------------------------------------------
659 0 : void OUnoObject::impl_initializeModel_nothrow()
660 : {
661 : try
662 : {
663 0 : Reference< XFormattedField > xFormatted( m_xReportComponent, UNO_QUERY );
664 0 : if ( xFormatted.is() )
665 : {
666 0 : const Reference< XPropertySet > xModelProps( GetUnoControlModel(), UNO_QUERY_THROW );
667 0 : const OUString sTreatAsNumberProperty = OUString( "TreatAsNumber" );
668 0 : xModelProps->setPropertyValue( sTreatAsNumberProperty, makeAny( sal_False ) );
669 0 : xModelProps->setPropertyValue( PROPERTY_VERTICALALIGN,m_xReportComponent->getPropertyValue(PROPERTY_VERTICALALIGN));
670 0 : }
671 : }
672 0 : catch( const Exception& )
673 : {
674 : DBG_UNHANDLED_EXCEPTION();
675 : }
676 0 : }
677 : // -----------------------------------------------------------------------------
678 0 : void OUnoObject::impl_setReportComponent_nothrow()
679 : {
680 0 : if ( m_xReportComponent.is() )
681 0 : return;
682 :
683 0 : OReportModel* pReportModel = static_cast<OReportModel*>(GetModel());
684 : OSL_ENSURE( pReportModel, "OUnoObject::impl_setReportComponent_nothrow: no report model!" );
685 0 : if ( !pReportModel )
686 0 : return;
687 :
688 0 : OXUndoEnvironment::OUndoEnvLock aLock( pReportModel->GetUndoEnv() );
689 0 : m_xReportComponent.set(getUnoShape(),uno::UNO_QUERY);
690 :
691 0 : impl_initializeModel_nothrow();
692 : }
693 : // -----------------------------------------------------------------------------
694 0 : sal_uInt16 OUnoObject::GetObjIdentifier() const
695 : {
696 0 : return sal_uInt16(m_nObjectType);
697 : }
698 : //----------------------------------------------------------------------------
699 0 : sal_uInt32 OUnoObject::GetObjInventor() const
700 : {
701 0 : return ReportInventor;
702 : }
703 : //----------------------------------------------------------------------------
704 0 : SdrPage* OUnoObject::GetImplPage() const
705 : {
706 : DBG_CHKTHIS( rpt_OUnoObject,NULL);
707 0 : return GetPage();
708 : }
709 : //----------------------------------------------------------------------------
710 0 : void OUnoObject::SetSnapRectImpl(const Rectangle& _rRect)
711 : {
712 : DBG_CHKTHIS( rpt_OUnoObject,NULL);
713 0 : SetSnapRect( _rRect );
714 0 : }
715 : //----------------------------------------------------------------------------
716 0 : sal_Int32 OUnoObject::GetStep() const
717 : {
718 : DBG_CHKTHIS( rpt_OUnoObject,NULL);
719 : // get step property
720 0 : sal_Int32 nStep = 0;
721 : OSL_FAIL("Who called me!");
722 0 : return nStep;
723 : }
724 :
725 : //----------------------------------------------------------------------------
726 0 : void OUnoObject::NbcMove( const Size& rSize )
727 : {
728 : DBG_CHKTHIS( rpt_OUnoObject,NULL);
729 :
730 0 : if ( m_bIsListening )
731 : {
732 : // stop listening
733 0 : OObjectBase::EndListening(sal_False);
734 :
735 0 : bool bPositionFixed = false;
736 0 : Size aUndoSize(0,0);
737 0 : bool bUndoMode = false;
738 0 : if ( m_xReportComponent.is() )
739 : {
740 0 : OReportModel* pRptModel = static_cast<OReportModel*>(GetModel());
741 0 : if (pRptModel->GetUndoEnv().IsUndoMode())
742 : {
743 : // if we are locked from outside, then we must not handle wrong moves, we are in UNDO mode
744 0 : bUndoMode = true;
745 : }
746 0 : OXUndoEnvironment::OUndoEnvLock aLock(pRptModel->GetUndoEnv());
747 :
748 : // LLA: why there exists getPositionX and getPositionY and NOT getPosition() which return a Point?
749 0 : int nNewX = m_xReportComponent->getPositionX() + rSize.A();
750 0 : m_xReportComponent->setPositionX(nNewX);
751 0 : int nNewY = m_xReportComponent->getPositionY() + rSize.B();
752 0 : if (nNewY < 0 && !bUndoMode)
753 : {
754 0 : aUndoSize.B() = abs(nNewY);
755 0 : bPositionFixed = true;
756 0 : nNewY = 0;
757 : }
758 0 : m_xReportComponent->setPositionY(nNewY);
759 : }
760 0 : if (bPositionFixed)
761 : {
762 0 : GetModel()->AddUndo(GetModel()->GetSdrUndoFactory().CreateUndoMoveObject(*this, aUndoSize));
763 : }
764 : // set geometry properties
765 0 : SetPropsFromRect(GetLogicRect());
766 :
767 : // start listening
768 0 : OObjectBase::StartListening();
769 : }
770 : else
771 0 : SdrUnoObj::NbcMove( rSize );
772 0 : }
773 :
774 : //----------------------------------------------------------------------------
775 :
776 0 : void OUnoObject::NbcResize(const Point& rRef, const Fraction& xFract, const Fraction& yFract)
777 : {
778 : DBG_CHKTHIS( rpt_OUnoObject,NULL);
779 0 : SdrUnoObj::NbcResize( rRef, xFract, yFract );
780 :
781 : // stop listening
782 0 : OObjectBase::EndListening(sal_False);
783 :
784 : // set geometry properties
785 0 : SetPropsFromRect(GetLogicRect());
786 :
787 : // start listening
788 0 : OObjectBase::StartListening();
789 0 : }
790 : //----------------------------------------------------------------------------
791 0 : void OUnoObject::NbcSetLogicRect(const Rectangle& rRect)
792 : {
793 0 : SdrUnoObj::NbcSetLogicRect(rRect);
794 : // stop listening
795 0 : OObjectBase::EndListening(sal_False);
796 :
797 : // set geometry properties
798 0 : SetPropsFromRect(rRect);
799 :
800 : // start listening
801 0 : OObjectBase::StartListening();
802 0 : }
803 : //----------------------------------------------------------------------------
804 :
805 0 : bool OUnoObject::EndCreate(SdrDragStat& rStat, SdrCreateCmd eCmd)
806 : {
807 : DBG_CHKTHIS( rpt_OUnoObject,NULL);
808 0 : bool bResult = SdrUnoObj::EndCreate(rStat, eCmd);
809 0 : if ( bResult )
810 : {
811 0 : impl_setReportComponent_nothrow();
812 : // set labels
813 0 : if ( m_xReportComponent.is() )
814 : {
815 : try
816 : {
817 0 : if ( supportsService( SERVICE_FIXEDTEXT ) )
818 : {
819 0 : m_xReportComponent->setPropertyValue( PROPERTY_LABEL, uno::makeAny(GetDefaultName(this)) );
820 : }
821 : }
822 0 : catch(const uno::Exception&)
823 : {
824 : DBG_UNHANDLED_EXCEPTION();
825 : }
826 :
827 0 : impl_initializeModel_nothrow();
828 : }
829 : // set geometry properties
830 0 : SetPropsFromRect(GetLogicRect());
831 : }
832 :
833 0 : return bResult;
834 : }
835 : //----------------------------------------------------------------------------
836 0 : OUString OUnoObject::GetDefaultName(const OUnoObject* _pObj)
837 : {
838 0 : sal_uInt16 nResId = 0;
839 0 : OUString aDefaultName = OUString("HERE WE HAVE TO INSERT OUR NAME!");
840 0 : if ( _pObj->supportsService( SERVICE_FIXEDTEXT ) )
841 : {
842 0 : nResId = RID_STR_CLASS_FIXEDTEXT;
843 : }
844 0 : else if ( _pObj->supportsService( SERVICE_FIXEDLINE ) )
845 : {
846 0 : nResId = RID_STR_CLASS_FIXEDLINE;
847 : }
848 0 : else if ( _pObj->supportsService( SERVICE_IMAGECONTROL ) )
849 : {
850 0 : nResId = RID_STR_CLASS_IMAGECONTROL;
851 : }
852 0 : else if ( _pObj->supportsService( SERVICE_FORMATTEDFIELD ) )
853 : {
854 0 : nResId = RID_STR_CLASS_FORMATTEDFIELD;
855 : }
856 :
857 0 : if (nResId)
858 0 : aDefaultName = OUString( String(ModuleRes(nResId)) );
859 :
860 0 : return aDefaultName;
861 : }
862 :
863 : // -----------------------------------------------------------------------------
864 0 : void OUnoObject::_propertyChange( const beans::PropertyChangeEvent& evt ) throw( uno::RuntimeException)
865 : {
866 : DBG_CHKTHIS( rpt_OUnoObject,NULL);
867 0 : OObjectBase::_propertyChange(evt);
868 0 : if (isListening())
869 : {
870 0 : if ( evt.PropertyName == PROPERTY_CHARCOLOR )
871 : {
872 0 : Reference<XPropertySet> xControlModel(GetUnoControlModel(),uno::UNO_QUERY);
873 0 : if ( xControlModel.is() )
874 : {
875 0 : OObjectBase::EndListening(sal_False);
876 : try
877 : {
878 0 : xControlModel->setPropertyValue(PROPERTY_TEXTCOLOR,evt.NewValue);
879 : }
880 0 : catch(uno::Exception&)
881 : {
882 : }
883 0 : OObjectBase::StartListening();
884 0 : }
885 : }
886 0 : else if ( evt.PropertyName == PROPERTY_NAME )
887 : {
888 0 : Reference<XPropertySet> xControlModel(GetUnoControlModel(),uno::UNO_QUERY);
889 0 : if ( xControlModel.is() && xControlModel->getPropertySetInfo()->hasPropertyByName(PROPERTY_NAME) )
890 : {
891 : // get old name
892 0 : OUString aOldName;
893 0 : evt.OldValue >>= aOldName;
894 :
895 : // get new name
896 0 : OUString aNewName;
897 0 : evt.NewValue >>= aNewName;
898 :
899 0 : if ( !aNewName.equals(aOldName) )
900 : {
901 : // set old name property
902 0 : OObjectBase::EndListening(sal_False);
903 0 : if ( m_xMediator.is() )
904 0 : m_xMediator.get()->stopListening();
905 : try
906 : {
907 0 : xControlModel->setPropertyValue( PROPERTY_NAME, evt.NewValue );
908 : }
909 0 : catch(uno::Exception&)
910 : {
911 : }
912 0 : if ( m_xMediator.is() )
913 0 : m_xMediator.get()->startListening();
914 0 : OObjectBase::StartListening();
915 0 : }
916 0 : }
917 : }
918 : }
919 0 : }
920 : // -----------------------------------------------------------------------------
921 0 : void OUnoObject::CreateMediator(sal_Bool _bReverse)
922 : {
923 0 : if ( !m_xMediator.is() )
924 : {
925 0 : impl_setReportComponent_nothrow();
926 :
927 0 : Reference<XPropertySet> xControlModel(GetUnoControlModel(),uno::UNO_QUERY);
928 0 : if ( !m_xMediator.is() && m_xReportComponent.is() && xControlModel.is() )
929 0 : m_xMediator = TMediator::createFromQuery(new OPropertyMediator(m_xReportComponent.get(),xControlModel,getPropertyNameMap(GetObjIdentifier()),_bReverse));
930 0 : OObjectBase::StartListening();
931 : }
932 0 : }
933 : // -----------------------------------------------------------------------------
934 0 : uno::Reference< beans::XPropertySet> OUnoObject::getAwtComponent()
935 : {
936 0 : return Reference<XPropertySet>(GetUnoControlModel(),uno::UNO_QUERY);
937 : }
938 :
939 : // -----------------------------------------------------------------------------
940 0 : uno::Reference< uno::XInterface > OUnoObject::getUnoShape()
941 : {
942 0 : return OObjectBase::getUnoShapeOf( *this );
943 : }
944 :
945 0 : void OUnoObject::impl_setUnoShape( const uno::Reference< uno::XInterface >& rxUnoShape )
946 : {
947 0 : SdrUnoObj::impl_setUnoShape( rxUnoShape );
948 0 : releaseUnoShape();
949 0 : }
950 :
951 0 : OUnoObject& OUnoObject::operator=(const OUnoObject& rObj)
952 : {
953 0 : if( this == &rObj )
954 0 : return *this;
955 0 : SdrUnoObj::operator=(rObj);
956 :
957 0 : Reference<XPropertySet> xSource(const_cast<OUnoObject&>(rObj).getUnoShape(), uno::UNO_QUERY);
958 0 : Reference<XPropertySet> xDest(getUnoShape(), uno::UNO_QUERY);
959 0 : if ( xSource.is() && xDest.is() )
960 0 : comphelper::copyProperties(xSource.get(), xDest.get());
961 :
962 0 : return *this;
963 : }
964 :
965 0 : OUnoObject* OUnoObject::Clone() const
966 : {
967 0 : return CloneHelper< OUnoObject >();
968 : }
969 : //----------------------------------------------------------------------------
970 : // OOle2Obj
971 : //----------------------------------------------------------------------------
972 0 : TYPEINIT1(OOle2Obj, SdrOle2Obj);
973 : DBG_NAME( rpt_OOle2Obj );
974 0 : OOle2Obj::OOle2Obj(const uno::Reference< report::XReportComponent>& _xComponent,sal_uInt16 _nType)
975 : :SdrOle2Obj()
976 : ,OObjectBase(_xComponent)
977 : ,m_nType(_nType)
978 0 : ,m_bOnlyOnce(true)
979 : {
980 : DBG_CTOR( rpt_OOle2Obj, NULL);
981 :
982 0 : impl_setUnoShape( uno::Reference< uno::XInterface >( _xComponent, uno::UNO_QUERY ) );
983 0 : m_bIsListening = sal_True;
984 0 : }
985 : //----------------------------------------------------------------------------
986 0 : OOle2Obj::OOle2Obj(const OUString& _sComponentName,sal_uInt16 _nType)
987 : :SdrOle2Obj()
988 : ,OObjectBase(_sComponentName)
989 : ,m_nType(_nType)
990 0 : ,m_bOnlyOnce(true)
991 : {
992 : DBG_CTOR( rpt_OOle2Obj, NULL);
993 0 : m_bIsListening = sal_True;
994 0 : }
995 : //----------------------------------------------------------------------------
996 0 : OOle2Obj::~OOle2Obj()
997 : {
998 : DBG_DTOR( rpt_OOle2Obj, NULL);
999 0 : }
1000 : // -----------------------------------------------------------------------------
1001 0 : sal_uInt16 OOle2Obj::GetObjIdentifier() const
1002 : {
1003 0 : return m_nType;
1004 : }
1005 : //----------------------------------------------------------------------------
1006 0 : sal_uInt32 OOle2Obj::GetObjInventor() const
1007 : {
1008 0 : return ReportInventor;
1009 : }
1010 : //----------------------------------------------------------------------------
1011 0 : SdrPage* OOle2Obj::GetImplPage() const
1012 : {
1013 : DBG_CHKTHIS( rpt_OOle2Obj,NULL);
1014 0 : return GetPage();
1015 : }
1016 : //----------------------------------------------------------------------------
1017 0 : void OOle2Obj::SetSnapRectImpl(const Rectangle& _rRect)
1018 : {
1019 : DBG_CHKTHIS( rpt_OOle2Obj,NULL);
1020 0 : SetSnapRect( _rRect );
1021 0 : }
1022 : //----------------------------------------------------------------------------
1023 0 : sal_Int32 OOle2Obj::GetStep() const
1024 : {
1025 : DBG_CHKTHIS( rpt_OOle2Obj,NULL);
1026 : // get step property
1027 0 : sal_Int32 nStep = 0;
1028 : OSL_FAIL("Who called me!");
1029 0 : return nStep;
1030 : }
1031 :
1032 : //----------------------------------------------------------------------------
1033 0 : void OOle2Obj::NbcMove( const Size& rSize )
1034 : {
1035 : DBG_CHKTHIS( rpt_OOle2Obj,NULL);
1036 :
1037 0 : if ( m_bIsListening )
1038 : {
1039 : // stop listening
1040 0 : OObjectBase::EndListening(sal_False);
1041 :
1042 0 : bool bPositionFixed = false;
1043 0 : Size aUndoSize(0,0);
1044 0 : bool bUndoMode = false;
1045 0 : if ( m_xReportComponent.is() )
1046 : {
1047 0 : OReportModel* pRptModel = static_cast<OReportModel*>(GetModel());
1048 0 : if (pRptModel->GetUndoEnv().IsUndoMode())
1049 : {
1050 : // if we are locked from outside, then we must not handle wrong moves, we are in UNDO mode
1051 0 : bUndoMode = true;
1052 : }
1053 0 : OXUndoEnvironment::OUndoEnvLock aLock(pRptModel->GetUndoEnv());
1054 :
1055 : // LLA: why there exists getPositionX and getPositionY and NOT getPosition() which return a Point?
1056 0 : int nNewX = m_xReportComponent->getPositionX() + rSize.A();
1057 : // can this hinder us to set components outside the area?
1058 : // if (nNewX < 0)
1059 : // {
1060 : // nNewX = 0;
1061 : // }
1062 0 : m_xReportComponent->setPositionX(nNewX);
1063 0 : int nNewY = m_xReportComponent->getPositionY() + rSize.B();
1064 0 : if (nNewY < 0 && !bUndoMode)
1065 : {
1066 0 : aUndoSize.B() = abs(nNewY);
1067 0 : bPositionFixed = true;
1068 0 : nNewY = 0;
1069 : }
1070 0 : m_xReportComponent->setPositionY(nNewY);
1071 : }
1072 0 : if (bPositionFixed)
1073 : {
1074 0 : GetModel()->AddUndo(GetModel()->GetSdrUndoFactory().CreateUndoMoveObject(*this, aUndoSize));
1075 : }
1076 : // set geometry properties
1077 0 : SetPropsFromRect(GetLogicRect());
1078 :
1079 : // start listening
1080 0 : OObjectBase::StartListening();
1081 : }
1082 : else
1083 0 : SdrOle2Obj::NbcMove( rSize );
1084 0 : }
1085 :
1086 : //----------------------------------------------------------------------------
1087 :
1088 0 : void OOle2Obj::NbcResize(const Point& rRef, const Fraction& xFract, const Fraction& yFract)
1089 : {
1090 : DBG_CHKTHIS( rpt_OOle2Obj,NULL);
1091 0 : SdrOle2Obj::NbcResize( rRef, xFract, yFract );
1092 :
1093 : // stop listening
1094 0 : OObjectBase::EndListening(sal_False);
1095 :
1096 : // set geometry properties
1097 0 : SetPropsFromRect(GetLogicRect());
1098 :
1099 : // start listening
1100 0 : OObjectBase::StartListening();
1101 0 : }
1102 : //----------------------------------------------------------------------------
1103 0 : void OOle2Obj::NbcSetLogicRect(const Rectangle& rRect)
1104 : {
1105 0 : SdrOle2Obj::NbcSetLogicRect(rRect);
1106 : // stop listening
1107 0 : OObjectBase::EndListening(sal_False);
1108 :
1109 : // set geometry properties
1110 0 : SetPropsFromRect(rRect);
1111 :
1112 : // start listening
1113 0 : OObjectBase::StartListening();
1114 0 : }
1115 : //----------------------------------------------------------------------------
1116 :
1117 0 : bool OOle2Obj::EndCreate(SdrDragStat& rStat, SdrCreateCmd eCmd)
1118 : {
1119 : DBG_CHKTHIS( rpt_OOle2Obj,NULL);
1120 0 : bool bResult = SdrOle2Obj::EndCreate(rStat, eCmd);
1121 0 : if ( bResult )
1122 : {
1123 0 : OReportModel* pRptModel = static_cast<OReportModel*>(GetModel());
1124 0 : if ( pRptModel )
1125 : {
1126 0 : OXUndoEnvironment::OUndoEnvLock aLock(pRptModel->GetUndoEnv());
1127 0 : if ( !m_xReportComponent.is() )
1128 0 : m_xReportComponent.set(getUnoShape(),uno::UNO_QUERY);
1129 : }
1130 : // set geometry properties
1131 0 : SetPropsFromRect(GetLogicRect());
1132 : }
1133 :
1134 0 : return bResult;
1135 : }
1136 :
1137 0 : uno::Reference< beans::XPropertySet> OOle2Obj::getAwtComponent()
1138 : {
1139 0 : return uno::Reference< beans::XPropertySet>(m_xReportComponent,uno::UNO_QUERY);
1140 : }
1141 :
1142 : // -----------------------------------------------------------------------------
1143 0 : uno::Reference< uno::XInterface > OOle2Obj::getUnoShape()
1144 : {
1145 0 : uno::Reference< uno::XInterface> xShape = OObjectBase::getUnoShapeOf( *this );
1146 0 : if ( !m_xReportComponent.is() )
1147 : {
1148 0 : OReportModel* pRptModel = static_cast<OReportModel*>(GetModel());
1149 0 : OXUndoEnvironment::OUndoEnvLock aLock(pRptModel->GetUndoEnv());
1150 0 : m_xReportComponent.set(xShape,uno::UNO_QUERY);
1151 : }
1152 0 : return xShape;
1153 : }
1154 :
1155 0 : void OOle2Obj::impl_setUnoShape( const uno::Reference< uno::XInterface >& rxUnoShape )
1156 : {
1157 0 : SdrOle2Obj::impl_setUnoShape( rxUnoShape );
1158 0 : releaseUnoShape();
1159 0 : m_xReportComponent.clear();
1160 0 : }
1161 :
1162 : // -----------------------------------------------------------------------------
1163 0 : uno::Reference< chart2::data::XDatabaseDataProvider > lcl_getDataProvider(const uno::Reference < embed::XEmbeddedObject >& _xObj)
1164 : {
1165 0 : uno::Reference< chart2::data::XDatabaseDataProvider > xSource;
1166 0 : uno::Reference< embed::XComponentSupplier > xCompSupp(_xObj,uno::UNO_QUERY);
1167 0 : if( xCompSupp.is())
1168 : {
1169 0 : uno::Reference< chart2::XChartDocument> xChartDoc( xCompSupp->getComponent(), uno::UNO_QUERY );
1170 0 : if ( xChartDoc.is() )
1171 : {
1172 0 : xSource.set(xChartDoc->getDataProvider(),uno::UNO_QUERY);
1173 0 : }
1174 : }
1175 0 : return xSource;
1176 : }
1177 :
1178 0 : OOle2Obj& OOle2Obj::operator=(const OOle2Obj& rObj)
1179 : {
1180 0 : if( this == &rObj )
1181 0 : return *this;
1182 0 : SdrOle2Obj::operator=(rObj);
1183 :
1184 0 : OReportModel* pRptModel = static_cast<OReportModel*>(rObj.GetModel());
1185 0 : svt::EmbeddedObjectRef::TryRunningState( GetObjRef() );
1186 0 : impl_createDataProvider_nothrow(pRptModel->getReportDefinition().get());
1187 :
1188 0 : uno::Reference< chart2::data::XDatabaseDataProvider > xSource( lcl_getDataProvider(rObj.GetObjRef()) );
1189 0 : uno::Reference< chart2::data::XDatabaseDataProvider > xDest( lcl_getDataProvider(GetObjRef()) );
1190 0 : if ( xSource.is() && xDest.is() )
1191 0 : comphelper::copyProperties(xSource.get(),xDest.get());
1192 :
1193 0 : initializeChart(pRptModel->getReportDefinition().get());
1194 :
1195 0 : return *this;
1196 : }
1197 :
1198 : // -----------------------------------------------------------------------------
1199 : // Clone() soll eine komplette Kopie des Objektes erzeugen.
1200 0 : OOle2Obj* OOle2Obj::Clone() const
1201 : {
1202 0 : return CloneHelper< OOle2Obj >();
1203 : }
1204 : // -----------------------------------------------------------------------------
1205 0 : void OOle2Obj::impl_createDataProvider_nothrow(const uno::Reference< frame::XModel>& _xModel)
1206 : {
1207 : try
1208 : {
1209 0 : uno::Reference < embed::XEmbeddedObject > xObj = GetObjRef();
1210 0 : uno::Reference< chart2::data::XDataReceiver > xReceiver;
1211 0 : uno::Reference< embed::XComponentSupplier > xCompSupp( xObj, uno::UNO_QUERY );
1212 0 : if( xCompSupp.is())
1213 0 : xReceiver.set( xCompSupp->getComponent(), uno::UNO_QUERY );
1214 : OSL_ASSERT( xReceiver.is());
1215 0 : if( xReceiver.is() )
1216 : {
1217 0 : uno::Reference< lang::XMultiServiceFactory> xFac(_xModel,uno::UNO_QUERY);
1218 0 : uno::Reference< chart2::data::XDatabaseDataProvider > xDataProvider( xFac->createInstance("com.sun.star.chart2.data.DataProvider"),uno::UNO_QUERY);
1219 0 : xReceiver->attachDataProvider( xDataProvider.get() );
1220 0 : }
1221 : }
1222 0 : catch(const uno::Exception &)
1223 : {
1224 : }
1225 0 : }
1226 : // -----------------------------------------------------------------------------
1227 0 : void OOle2Obj::initializeOle()
1228 : {
1229 0 : if ( m_bOnlyOnce )
1230 : {
1231 0 : m_bOnlyOnce = false;
1232 0 : uno::Reference < embed::XEmbeddedObject > xObj = GetObjRef();
1233 0 : OReportModel* pRptModel = static_cast<OReportModel*>(GetModel());
1234 0 : pRptModel->GetUndoEnv().AddElement(lcl_getDataProvider(xObj));
1235 :
1236 0 : uno::Reference< embed::XComponentSupplier > xCompSupp( xObj, uno::UNO_QUERY );
1237 0 : if( xCompSupp.is() )
1238 : {
1239 0 : uno::Reference< beans::XPropertySet > xChartProps( xCompSupp->getComponent(), uno::UNO_QUERY );
1240 0 : if ( xChartProps.is() )
1241 0 : xChartProps->setPropertyValue("NullDate",uno::makeAny(util::DateTime(0,0,0,0,1,1,1900)));
1242 0 : }
1243 : }
1244 0 : }
1245 : // -----------------------------------------------------------------------------
1246 0 : void OOle2Obj::initializeChart( const uno::Reference< frame::XModel>& _xModel)
1247 : {
1248 0 : uno::Reference < embed::XEmbeddedObject > xObj = GetObjRef();
1249 0 : uno::Reference< chart2::data::XDataReceiver > xReceiver;
1250 0 : uno::Reference< embed::XComponentSupplier > xCompSupp( xObj, uno::UNO_QUERY );
1251 0 : if( xCompSupp.is())
1252 0 : xReceiver.set( xCompSupp->getComponent(), uno::UNO_QUERY );
1253 : OSL_ASSERT( xReceiver.is());
1254 0 : if( xReceiver.is() )
1255 : {
1256 : // lock the model to suppress any internal updates
1257 0 : uno::Reference< frame::XModel > xChartModel( xReceiver, uno::UNO_QUERY );
1258 0 : if( xChartModel.is() )
1259 0 : xChartModel->lockControllers();
1260 :
1261 0 : if ( !lcl_getDataProvider(xObj).is() )
1262 0 : impl_createDataProvider_nothrow(_xModel);
1263 :
1264 0 : OReportModel* pRptModel = static_cast<OReportModel*>(GetModel());
1265 0 : pRptModel->GetUndoEnv().AddElement(lcl_getDataProvider(xObj));
1266 :
1267 0 : ::comphelper::NamedValueCollection aArgs;
1268 0 : aArgs.put( "CellRangeRepresentation", uno::makeAny( OUString( "all" ) ) );
1269 0 : aArgs.put( "HasCategories", uno::makeAny( sal_True ) );
1270 0 : aArgs.put( "FirstCellAsLabel", uno::makeAny( sal_True ) );
1271 0 : aArgs.put( "DataRowSource", uno::makeAny( chart::ChartDataRowSource_COLUMNS ) );
1272 0 : xReceiver->setArguments( aArgs.getPropertyValues() );
1273 :
1274 0 : if( xChartModel.is() )
1275 0 : xChartModel->unlockControllers();
1276 0 : }
1277 0 : }
1278 : // -----------------------------------------------------------------------------
1279 0 : uno::Reference< style::XStyle> getUsedStyle(const uno::Reference< report::XReportDefinition>& _xReport)
1280 : {
1281 0 : uno::Reference<container::XNameAccess> xStyles = _xReport->getStyleFamilies();
1282 0 : uno::Reference<container::XNameAccess> xPageStyles(xStyles->getByName("PageStyles"),uno::UNO_QUERY);
1283 :
1284 0 : uno::Reference< style::XStyle> xReturn;
1285 0 : uno::Sequence< OUString> aSeq = xPageStyles->getElementNames();
1286 0 : const OUString* pIter = aSeq.getConstArray();
1287 0 : const OUString* pEnd = pIter + aSeq.getLength();
1288 0 : for(;pIter != pEnd && !xReturn.is() ;++pIter)
1289 : {
1290 0 : uno::Reference< style::XStyle> xStyle(xPageStyles->getByName(*pIter),uno::UNO_QUERY);
1291 0 : if ( xStyle->isInUse() )
1292 0 : xReturn = xStyle;
1293 0 : }
1294 0 : return xReturn;
1295 : }
1296 : //----------------------------------------------------------------------------
1297 : //============================================================================
1298 0 : } // rptui
1299 : //============================================================================
1300 :
1301 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|