Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : : #include "UndoActions.hxx"
29 : : #include "UndoEnv.hxx"
30 : : #include "formatnormalizer.hxx"
31 : : #include "conditionupdater.hxx"
32 : : #include "corestrings.hrc"
33 : : #include "rptui_slotid.hrc"
34 : : #include "RptDef.hxx"
35 : : #include "ModuleHelper.hxx"
36 : : #include "RptObject.hxx"
37 : : #include "RptPage.hxx"
38 : : #include "RptResId.hrc"
39 : : #include "RptModel.hxx"
40 : :
41 : : #include <com/sun/star/script/XEventAttacherManager.hpp>
42 : : #include <com/sun/star/container/XChild.hpp>
43 : : #include <com/sun/star/container/XNameContainer.hpp>
44 : : #include <com/sun/star/beans/PropertyAttribute.hpp>
45 : : #include <com/sun/star/util/XModifyBroadcaster.hpp>
46 : : #include <com/sun/star/beans/XIntrospectionAccess.hpp>
47 : : #include <com/sun/star/beans/XIntrospection.hpp>
48 : :
49 : : #include <connectivity/dbtools.hxx>
50 : : #include <svl/smplhint.hxx>
51 : : #include <tools/diagnose_ex.h>
52 : : #include <comphelper/stl_types.hxx>
53 : : #include <comphelper/componentcontext.hxx>
54 : : #include <vcl/svapp.hxx>
55 : : #include <dbaccess/dbsubcomponentcontroller.hxx>
56 : : #include <svx/unoshape.hxx>
57 : : #include <osl/mutex.hxx>
58 : :
59 : : namespace rptui
60 : : {
61 : : using namespace ::com::sun::star;
62 : : using namespace uno;
63 : : using namespace lang;
64 : : using namespace script;
65 : : using namespace beans;
66 : : using namespace awt;
67 : : using namespace util;
68 : : using namespace container;
69 : : using namespace report;
70 : : //----------------------------------------------------------------------------
71 : :
72 : :
73 : : struct PropertyInfo
74 : : {
75 : : bool bIsReadonlyOrTransient;
76 : :
77 : : PropertyInfo()
78 : : :bIsReadonlyOrTransient( false )
79 : : {
80 : : }
81 : :
82 : 0 : PropertyInfo( const bool i_bIsTransientOrReadOnly )
83 : 0 : :bIsReadonlyOrTransient( i_bIsTransientOrReadOnly )
84 : : {
85 : 0 : }
86 : : };
87 : :
88 : : typedef ::boost::unordered_map< ::rtl::OUString, PropertyInfo, ::rtl::OUStringHash > PropertiesInfo;
89 : :
90 : 0 : struct ObjectInfo
91 : : {
92 : : PropertiesInfo aProperties;
93 : : Reference< XPropertySet > xPropertyIntrospection;
94 : :
95 : 0 : ObjectInfo()
96 : : :aProperties()
97 [ # # ]: 0 : ,xPropertyIntrospection()
98 : : {
99 : 0 : }
100 : : };
101 : :
102 : : typedef ::std::map< Reference< XPropertySet >, ObjectInfo, ::comphelper::OInterfaceCompare< XPropertySet > > PropertySetInfoCache;
103 : :
104 : : // -----------------------------------------------------------------------------
105 : :
106 [ # # ][ # # ]: 0 : class OXUndoEnvironmentImpl
[ # # ]
107 : : {
108 : : OXUndoEnvironmentImpl(OXUndoEnvironmentImpl&);
109 : : void operator =(OXUndoEnvironmentImpl&);
110 : : public:
111 : : OReportModel& m_rModel;
112 : : PropertySetInfoCache m_aPropertySetCache;
113 : : FormatNormalizer m_aFormatNormalizer;
114 : : ConditionUpdater m_aConditionUpdater;
115 : : ::osl::Mutex m_aMutex;
116 : : ::std::vector< uno::Reference< container::XChild> > m_aSections;
117 : : Reference< XIntrospection > m_xIntrospection;
118 : : oslInterlockedCount m_nLocks;
119 : : sal_Bool m_bReadOnly;
120 : : sal_Bool m_bIsUndo;
121 : :
122 : : OXUndoEnvironmentImpl(OReportModel& _rModel);
123 : : };
124 : :
125 : 0 : OXUndoEnvironmentImpl::OXUndoEnvironmentImpl(OReportModel& _rModel) : m_rModel(_rModel)
126 : : ,m_aFormatNormalizer( _rModel )
127 : : ,m_aConditionUpdater()
128 : : ,m_nLocks(0)
129 : : ,m_bReadOnly(sal_False)
130 [ # # ][ # # ]: 0 : ,m_bIsUndo(sal_False)
[ # # ][ # # ]
131 : : {
132 : 0 : }
133 : :
134 : : //------------------------------------------------------------------------------
135 : : DBG_NAME( rpt_OXUndoEnvironment );
136 : : //------------------------------------------------------------------------------
137 : 0 : OXUndoEnvironment::OXUndoEnvironment(OReportModel& _rModel)
138 [ # # ][ # # ]: 0 : :m_pImpl(new OXUndoEnvironmentImpl(_rModel) )
[ # # ]
139 : : {
140 : : DBG_CTOR( rpt_OXUndoEnvironment,NULL);
141 [ # # ]: 0 : StartListening(m_pImpl->m_rModel);
142 : 0 : }
143 : :
144 : : //------------------------------------------------------------------------------
145 [ # # ][ # # ]: 0 : OXUndoEnvironment::~OXUndoEnvironment()
146 : : {
147 : : DBG_DTOR( rpt_OXUndoEnvironment,NULL);
148 [ # # ]: 0 : }
149 : : // -----------------------------------------------------------------------------
150 : 0 : void OXUndoEnvironment::Lock()
151 : : {
152 : : OSL_ENSURE(m_refCount,"Illegal call to dead object!");
153 : 0 : osl_incrementInterlockedCount( &m_pImpl->m_nLocks );
154 : 0 : }
155 : 0 : void OXUndoEnvironment::UnLock()
156 : : {
157 : : OSL_ENSURE(m_refCount,"Illegal call to dead object!");
158 : :
159 : 0 : osl_decrementInterlockedCount( &m_pImpl->m_nLocks );
160 : 0 : }
161 : 0 : sal_Bool OXUndoEnvironment::IsLocked() const { return m_pImpl->m_nLocks != 0; }
162 : : // -----------------------------------------------------------------------------
163 : 0 : void OXUndoEnvironment::RemoveSection(OReportPage* _pPage)
164 : : {
165 [ # # ]: 0 : if ( _pPage )
166 : : {
167 [ # # ]: 0 : Reference< XInterface > xSection(_pPage->getSection());
168 [ # # ]: 0 : if ( xSection.is() )
169 [ # # ]: 0 : RemoveElement( xSection );
170 : : }
171 : 0 : }
172 : : //------------------------------------------------------------------------------
173 : 0 : void OXUndoEnvironment::Clear(const Accessor& /*_r*/)
174 : : {
175 [ # # ]: 0 : OUndoEnvLock aLock(*this);
176 : :
177 : 0 : m_pImpl->m_aPropertySetCache.clear();
178 : :
179 [ # # ]: 0 : sal_uInt16 nCount = m_pImpl->m_rModel.GetPageCount();
180 : : sal_uInt16 i;
181 [ # # ]: 0 : for (i = 0; i < nCount; i++)
182 : : {
183 [ # # ][ # # ]: 0 : OReportPage* pPage = PTR_CAST( OReportPage, m_pImpl->m_rModel.GetPage(i) );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
184 [ # # ]: 0 : RemoveSection(pPage);
185 : : }
186 : :
187 [ # # ]: 0 : nCount = m_pImpl->m_rModel.GetMasterPageCount();
188 [ # # ]: 0 : for (i = 0; i < nCount; i++)
189 : : {
190 [ # # ][ # # ]: 0 : OReportPage* pPage = PTR_CAST( OReportPage, m_pImpl->m_rModel.GetMasterPage(i) );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
191 [ # # ]: 0 : RemoveSection(pPage);
192 : : }
193 : :
194 : 0 : m_pImpl->m_aSections.clear();
195 : :
196 [ # # ][ # # ]: 0 : if (IsListening(m_pImpl->m_rModel))
197 [ # # ][ # # ]: 0 : EndListening(m_pImpl->m_rModel);
198 : 0 : }
199 : :
200 : : //------------------------------------------------------------------------------
201 : 0 : void OXUndoEnvironment::ModeChanged()
202 : : {
203 : 0 : m_pImpl->m_bReadOnly = !m_pImpl->m_bReadOnly;
204 : :
205 [ # # ]: 0 : if (!m_pImpl->m_bReadOnly)
206 : 0 : StartListening(m_pImpl->m_rModel);
207 : : else
208 : 0 : EndListening(m_pImpl->m_rModel);
209 : 0 : }
210 : :
211 : : //------------------------------------------------------------------------------
212 : 0 : void OXUndoEnvironment::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint )
213 : : {
214 [ # # ][ # # ]: 0 : if (rHint.ISA(SfxSimpleHint) && ((SfxSimpleHint&)rHint).GetId() == SFX_HINT_MODECHANGED )
[ # # ]
215 : 0 : ModeChanged();
216 : 0 : }
217 : : // -----------------------------------------------------------------------------
218 : : // XEventListener
219 : : //------------------------------------------------------------------------------
220 : 0 : void SAL_CALL OXUndoEnvironment::disposing(const EventObject& e) throw( RuntimeException )
221 : : {
222 : : // check if it's an object we have cached informations about
223 [ # # ]: 0 : Reference< XPropertySet > xSourceSet(e.Source, UNO_QUERY);
224 [ # # ]: 0 : if ( xSourceSet.is() )
225 : : {
226 [ # # ]: 0 : uno::Reference< report::XSection> xSection(xSourceSet,uno::UNO_QUERY);
227 [ # # ]: 0 : if ( xSection.is() )
228 [ # # ]: 0 : RemoveSection(xSection);
229 : : else
230 [ # # ]: 0 : RemoveElement(xSourceSet);
231 : 0 : }
232 : 0 : }
233 : :
234 : : // XPropertyChangeListener
235 : : //------------------------------------------------------------------------------
236 : 0 : void SAL_CALL OXUndoEnvironment::propertyChange( const PropertyChangeEvent& _rEvent ) throw(uno::RuntimeException)
237 : : {
238 : :
239 [ # # ]: 0 : ::osl::ClearableMutexGuard aGuard( m_pImpl->m_aMutex );
240 : :
241 [ # # ][ # # ]: 0 : if ( IsLocked() )
242 : : return;
243 : :
244 [ # # ]: 0 : Reference< XPropertySet > xSet( _rEvent.Source, UNO_QUERY );
245 [ # # ]: 0 : if (!xSet.is())
246 : : return;
247 : :
248 : 0 : dbaui::DBSubComponentController* pController = m_pImpl->m_rModel.getController();
249 [ # # ]: 0 : if ( !pController )
250 : : return;
251 : :
252 : : // no Undo for transient and readonly props.
253 : : // let's see if we know something about the set
254 [ # # ]: 0 : PropertySetInfoCache::iterator objectPos = m_pImpl->m_aPropertySetCache.find(xSet);
255 [ # # ]: 0 : if (objectPos == m_pImpl->m_aPropertySetCache.end())
256 : : {
257 : 0 : objectPos = m_pImpl->m_aPropertySetCache.insert( PropertySetInfoCache::value_type(
258 : : xSet, ObjectInfo()
259 [ # # ]: 0 : ) ).first;
[ # # # # ]
[ # # ][ # # ]
260 : : DBG_ASSERT(objectPos != m_pImpl->m_aPropertySetCache.end(), "OXUndoEnvironment::propertyChange : just inserted it ... why it's not there ?");
261 : : }
262 [ # # ]: 0 : if ( objectPos == m_pImpl->m_aPropertySetCache.end() )
263 : : return;
264 : :
265 : : // now we have access to the cached info about the set
266 : : // let's see what we know about the property
267 : 0 : ObjectInfo& rObjectInfo = objectPos->second;
268 [ # # ]: 0 : PropertiesInfo::iterator aPropertyPos = rObjectInfo.aProperties.find( _rEvent.PropertyName );
269 [ # # ][ # # ]: 0 : if ( aPropertyPos == rObjectInfo.aProperties.end() )
270 : : { // nothing 'til now ... have to change this ....
271 : : // the attributes
272 [ # # ][ # # ]: 0 : Reference< XPropertySetInfo > xPSI( xSet->getPropertySetInfo(), UNO_SET_THROW );
[ # # ]
273 : 0 : sal_Int32 nPropertyAttributes = 0;
274 : : try
275 : : {
276 [ # # ][ # # ]: 0 : if ( xPSI->hasPropertyByName( _rEvent.PropertyName ) )
[ # # ]
277 : : {
278 [ # # ][ # # ]: 0 : nPropertyAttributes = xPSI->getPropertyByName( _rEvent.PropertyName ).Attributes;
279 : : }
280 : : else
281 : : {
282 : : // it's perfectly valid for a component to notify a change in a property which it doesn't have - as long
283 : : // as it has an attribute with this name
284 [ # # ]: 0 : if ( !rObjectInfo.xPropertyIntrospection.is() )
285 : : {
286 [ # # ]: 0 : if ( !m_pImpl->m_xIntrospection.is() )
287 : : {
288 [ # # ][ # # ]: 0 : ::comphelper::ComponentContext aContext( m_pImpl->m_rModel.getController()->getORB() );
289 [ # # ][ # # ]: 0 : OSL_VERIFY( aContext.createComponent( "com.sun.star.beans.Introspection", m_pImpl->m_xIntrospection ) );
290 : : }
291 [ # # ]: 0 : if ( m_pImpl->m_xIntrospection.is() )
292 : : {
293 : : Reference< XIntrospectionAccess > xIntrospection(
294 [ # # ]: 0 : m_pImpl->m_xIntrospection->inspect( makeAny( _rEvent.Source ) ),
295 : : UNO_SET_THROW
296 [ # # ][ # # ]: 0 : );
[ # # ]
297 [ # # ][ # # ]: 0 : rObjectInfo.xPropertyIntrospection.set( xIntrospection->queryAdapter( XPropertySet::static_type() ), UNO_QUERY_THROW );
[ # # ][ # # ]
298 : : }
299 : : }
300 [ # # ]: 0 : if ( rObjectInfo.xPropertyIntrospection.is() )
301 : : {
302 [ # # ][ # # ]: 0 : xPSI.set( rObjectInfo.xPropertyIntrospection->getPropertySetInfo(), UNO_SET_THROW );
[ # # ][ # # ]
303 [ # # ][ # # ]: 0 : nPropertyAttributes = xPSI->getPropertyByName( _rEvent.PropertyName ).Attributes;
304 : : }
305 : : }
306 : : }
307 [ # # ]: 0 : catch( const Exception& )
308 : : {
309 : : DBG_UNHANDLED_EXCEPTION();
310 : : }
311 : : const bool bTransReadOnly =
312 : : ( ( nPropertyAttributes & PropertyAttribute::READONLY ) != 0 )
313 [ # # ][ # # ]: 0 : || ( ( nPropertyAttributes & PropertyAttribute::TRANSIENT ) != 0 );
314 : :
315 : : // insert the new entry
316 : : aPropertyPos = rObjectInfo.aProperties.insert( PropertiesInfo::value_type(
317 : : _rEvent.PropertyName,
318 : : PropertyInfo( bTransReadOnly )
319 [ # # ]: 0 : ) ).first;
320 : 0 : DBG_ASSERT(aPropertyPos != rObjectInfo.aProperties.end(), "OXUndoEnvironment::propertyChange : just inserted it ... why it's not there ?");
321 : : }
322 : :
323 [ # # ]: 0 : implSetModified();
324 : :
325 : : // now we have access to the cached info about the property affected
326 : : // and are able to decide whether or not we need an undo action
327 : :
328 : : // no UNDO for transient/readonly properties
329 [ # # ][ # # ]: 0 : if ( aPropertyPos->second.bIsReadonlyOrTransient )
330 : : return;
331 : :
332 : : // give components with sub responsibilities a chance
333 [ # # ]: 0 : m_pImpl->m_aFormatNormalizer.notifyPropertyChange( _rEvent );
334 [ # # ]: 0 : m_pImpl->m_aConditionUpdater.notifyPropertyChange( _rEvent );
335 : :
336 [ # # ]: 0 : aGuard.clear();
337 : : // TODO: this is a potential race condition: two threads here could in theory
338 : : // add their undo actions out-of-order
339 : :
340 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
341 : 0 : ORptUndoPropertyAction* pUndo = NULL;
342 : : try
343 : : {
344 [ # # ]: 0 : uno::Reference< report::XSection> xSection( xSet, uno::UNO_QUERY );
345 [ # # ]: 0 : if ( xSection.is() )
346 : : {
347 [ # # ][ # # ]: 0 : uno::Reference< report::XGroup> xGroup = xSection->getGroup();
348 [ # # ]: 0 : if ( xGroup.is() )
349 [ # # ][ # # ]: 0 : pUndo = new OUndoPropertyGroupSectionAction( m_pImpl->m_rModel, _rEvent, OGroupHelper::getMemberFunction( xSection ), xGroup );
[ # # ]
350 : : else
351 [ # # ][ # # ]: 0 : pUndo = new OUndoPropertyReportSectionAction( m_pImpl->m_rModel, _rEvent, OReportHelper::getMemberFunction( xSection ), xSection->getReportDefinition() );
[ # # ][ # # ]
[ # # ]
352 [ # # ]: 0 : }
353 : : }
354 [ # # ]: 0 : catch(const Exception&)
355 : : {
356 : : DBG_UNHANDLED_EXCEPTION();
357 : : }
358 : :
359 [ # # ]: 0 : if ( pUndo == NULL )
360 [ # # ][ # # ]: 0 : pUndo = new ORptUndoPropertyAction( m_pImpl->m_rModel, _rEvent );
361 : :
362 [ # # ][ # # ]: 0 : m_pImpl->m_rModel.GetSdrUndoManager()->AddUndoAction( pUndo );
363 [ # # ][ # # ]: 0 : pController->InvalidateAll();
[ # # ][ # # ]
[ # # ]
364 : : }
365 : : // -----------------------------------------------------------------------------
366 : 0 : ::std::vector< uno::Reference< container::XChild> >::const_iterator OXUndoEnvironment::getSection(const Reference<container::XChild>& _xContainer) const
367 : : {
368 [ # # ]: 0 : ::std::vector< uno::Reference< container::XChild> >::const_iterator aFind = m_pImpl->m_aSections.end();
369 [ # # ]: 0 : if ( _xContainer.is() )
370 : : {
371 [ # # ]: 0 : aFind = ::std::find(m_pImpl->m_aSections.begin(),m_pImpl->m_aSections.end(),_xContainer);
372 : :
373 [ # # ][ # # ]: 0 : if ( aFind == m_pImpl->m_aSections.end() )
374 : : {
375 [ # # ][ # # ]: 0 : Reference<container::XChild> xParent(_xContainer->getParent(),uno::UNO_QUERY);
[ # # ]
376 [ # # ]: 0 : aFind = getSection(xParent);
377 : : }
378 : : }
379 : 0 : return aFind;
380 : : }
381 : : // XContainerListener
382 : : //------------------------------------------------------------------------------
383 : 0 : void SAL_CALL OXUndoEnvironment::elementInserted(const ContainerEvent& evt) throw(uno::RuntimeException)
384 : : {
385 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
386 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_pImpl->m_aMutex );
387 : :
388 : : // neues Object zum lauschen
389 [ # # ]: 0 : Reference< uno::XInterface > xIface( evt.Element, UNO_QUERY );
390 [ # # ][ # # ]: 0 : if ( !IsLocked() )
391 : : {
392 [ # # ]: 0 : Reference< report::XReportComponent > xReportComponent( xIface, UNO_QUERY );
393 [ # # ]: 0 : if ( xReportComponent.is() )
394 : : {
395 [ # # ]: 0 : Reference< report::XSection > xContainer(evt.Source,uno::UNO_QUERY);
396 : :
397 [ # # ][ # # ]: 0 : ::std::vector< uno::Reference< container::XChild> >::const_iterator aFind = getSection(xContainer.get());
[ # # ]
398 : :
399 [ # # ][ # # ]: 0 : if ( aFind != m_pImpl->m_aSections.end() )
400 : : {
401 [ # # ]: 0 : OUndoEnvLock aLock(*this);
402 : : try
403 : : {
404 [ # # ][ # # ]: 0 : OReportPage* pPage = m_pImpl->m_rModel.getPage(uno::Reference< report::XSection>(*aFind,uno::UNO_QUERY));
[ # # ]
405 : : OSL_ENSURE(pPage,"No page could be found for section!");
406 [ # # ]: 0 : if ( pPage )
407 [ # # ]: 0 : pPage->insertObject(xReportComponent);
408 : : }
409 [ # # ]: 0 : catch(uno::Exception&)
410 : : {
411 : : DBG_UNHANDLED_EXCEPTION();
412 [ # # ]: 0 : }
413 : :
414 : 0 : }
415 : : }
416 : : else
417 : : {
418 [ # # ]: 0 : uno::Reference< report::XFunctions> xContainer(evt.Source,uno::UNO_QUERY);
419 [ # # ]: 0 : if ( xContainer.is() )
420 : : {
421 [ # # ]: 0 : m_pImpl->m_rModel.GetSdrUndoManager()->AddUndoAction(
422 [ # # ]: 0 : new OUndoContainerAction( m_pImpl->m_rModel, rptui::Inserted, xContainer.get(),
423 [ # # ][ # # ]: 0 : xIface, RID_STR_UNDO_ADDFUNCTION ) );
[ # # ][ # # ]
[ # # ]
424 : 0 : }
425 : 0 : }
426 : : }
427 : :
428 [ # # ]: 0 : AddElement(xIface);
429 : :
430 [ # # ][ # # ]: 0 : implSetModified();
[ # # ]
431 : 0 : }
432 : :
433 : : //------------------------------------------------------------------------------
434 : 0 : void OXUndoEnvironment::implSetModified()
435 : : {
436 : 0 : m_pImpl->m_rModel.SetModified( sal_True );
437 : 0 : }
438 : :
439 : : //------------------------------------------------------------------------------
440 : 0 : void SAL_CALL OXUndoEnvironment::elementReplaced(const ContainerEvent& evt) throw(uno::RuntimeException)
441 : : {
442 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
443 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_pImpl->m_aMutex );
444 : :
445 [ # # ]: 0 : Reference< XInterface > xIface(evt.ReplacedElement,uno::UNO_QUERY);
446 : : OSL_ENSURE(xIface.is(), "OXUndoEnvironment::elementReplaced: invalid container notification!");
447 [ # # ]: 0 : RemoveElement(xIface);
448 : :
449 [ # # ]: 0 : xIface.set(evt.Element,uno::UNO_QUERY);
450 [ # # ]: 0 : AddElement(xIface);
451 : :
452 [ # # ][ # # ]: 0 : implSetModified();
[ # # ]
453 : 0 : }
454 : :
455 : : //------------------------------------------------------------------------------
456 : 0 : void SAL_CALL OXUndoEnvironment::elementRemoved(const ContainerEvent& evt) throw(uno::RuntimeException)
457 : : {
458 [ # # ]: 0 : SolarMutexGuard aSolarGuard;
459 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_pImpl->m_aMutex );
460 : :
461 [ # # ]: 0 : Reference< uno::XInterface > xIface( evt.Element, UNO_QUERY );
462 [ # # ][ # # ]: 0 : if ( !IsLocked() )
463 : : {
464 [ # # ]: 0 : Reference< report::XSection > xContainer(evt.Source,uno::UNO_QUERY);
465 [ # # ][ # # ]: 0 : ::std::vector< uno::Reference< container::XChild> >::const_iterator aFind = getSection(xContainer.get());
[ # # ]
466 : :
467 [ # # ]: 0 : Reference< report::XReportComponent > xReportComponent( xIface, UNO_QUERY );
468 [ # # ][ # # ]: 0 : if ( aFind != m_pImpl->m_aSections.end() && xReportComponent.is() )
[ # # ][ # # ]
[ # # # # ]
469 : : {
470 [ # # ]: 0 : OXUndoEnvironment::OUndoEnvLock aLock(*this);
471 : : try
472 : : {
473 [ # # ][ # # ]: 0 : OReportPage* pPage = m_pImpl->m_rModel.getPage(uno::Reference< report::XSection >( *aFind, uno::UNO_QUERY_THROW ) );
[ # # ]
474 : : OSL_ENSURE( pPage, "OXUndoEnvironment::elementRemoved: no page for the section!" );
475 [ # # ]: 0 : if ( pPage )
476 [ # # ]: 0 : pPage->removeSdrObject(xReportComponent);
477 : : }
478 [ # # ]: 0 : catch(const uno::Exception&)
479 : : {
480 : : DBG_UNHANDLED_EXCEPTION();
481 [ # # ]: 0 : }
482 : : }
483 : : else
484 : : {
485 [ # # ]: 0 : uno::Reference< report::XFunctions> xFunctions(evt.Source,uno::UNO_QUERY);
486 [ # # ]: 0 : if ( xFunctions.is() )
487 : : {
488 [ # # ]: 0 : m_pImpl->m_rModel.GetSdrUndoManager()->AddUndoAction( new OUndoContainerAction(
489 [ # # ][ # # ]: 0 : m_pImpl->m_rModel, rptui::Removed, xFunctions.get(), xIface, RID_STR_UNDO_ADDFUNCTION ) );
[ # # ][ # # ]
[ # # ][ # # ]
490 : 0 : }
491 : 0 : }
492 : : }
493 : :
494 [ # # ]: 0 : if ( xIface.is() )
495 [ # # ]: 0 : RemoveElement(xIface);
496 : :
497 [ # # ][ # # ]: 0 : implSetModified();
[ # # ]
498 : 0 : }
499 : :
500 : : //------------------------------------------------------------------------------
501 : 0 : void SAL_CALL OXUndoEnvironment::modified( const EventObject& /*aEvent*/ ) throw (RuntimeException)
502 : : {
503 : 0 : implSetModified();
504 : 0 : }
505 : :
506 : : //------------------------------------------------------------------------------
507 : 0 : void OXUndoEnvironment::AddSection(const Reference< report::XSection > & _xSection)
508 : : {
509 [ # # ]: 0 : OUndoEnvLock aLock(*this);
510 : : try
511 : : {
512 [ # # ][ # # ]: 0 : uno::Reference<container::XChild> xChild = _xSection.get();
513 [ # # ][ # # ]: 0 : uno::Reference<report::XGroup> xGroup(xChild->getParent(),uno::UNO_QUERY);
[ # # ]
514 [ # # ]: 0 : m_pImpl->m_aSections.push_back(xChild);
515 : 0 : Reference< XInterface > xInt(_xSection);
516 [ # # ][ # # ]: 0 : AddElement(xInt);
517 : : }
518 [ # # ]: 0 : catch(const uno::Exception&)
519 : : {
520 : : DBG_UNHANDLED_EXCEPTION();
521 [ # # ]: 0 : }
522 : 0 : }
523 : :
524 : : //------------------------------------------------------------------------------
525 : 0 : void OXUndoEnvironment::RemoveSection(const Reference< report::XSection > & _xSection)
526 : : {
527 [ # # ]: 0 : OUndoEnvLock aLock(*this);
528 : : try
529 : : {
530 [ # # ][ # # ]: 0 : uno::Reference<container::XChild> xChild(_xSection.get());
531 : 0 : m_pImpl->m_aSections.erase(::std::remove(m_pImpl->m_aSections.begin(),m_pImpl->m_aSections.end(),
532 [ # # # # ]: 0 : xChild), m_pImpl->m_aSections.end());
533 : 0 : Reference< XInterface > xInt(_xSection);
534 [ # # ][ # # ]: 0 : RemoveElement(xInt);
535 : : }
536 [ # # # # ]: 0 : catch(uno::Exception&){}
537 : 0 : }
538 : :
539 : : //------------------------------------------------------------------------------
540 : 0 : void OXUndoEnvironment::TogglePropertyListening(const Reference< XInterface > & Element)
541 : : {
542 : : // am Container horchen
543 [ # # ]: 0 : Reference< XIndexAccess > xContainer(Element, UNO_QUERY);
544 [ # # ]: 0 : if (xContainer.is())
545 : : {
546 : 0 : Reference< XInterface > xInterface;
547 [ # # ][ # # ]: 0 : sal_Int32 nCount = xContainer->getCount();
548 [ # # ]: 0 : for(sal_Int32 i = 0;i != nCount;++i)
549 : : {
550 [ # # ][ # # ]: 0 : xInterface.set(xContainer->getByIndex( i ),uno::UNO_QUERY);
[ # # ]
551 [ # # ]: 0 : TogglePropertyListening(xInterface);
552 : 0 : }
553 : : }
554 : :
555 [ # # ]: 0 : Reference< XPropertySet > xSet(Element, UNO_QUERY);
556 [ # # ]: 0 : if (xSet.is())
557 : : {
558 [ # # ]: 0 : if (!m_pImpl->m_bReadOnly)
559 [ # # ][ # # ]: 0 : xSet->addPropertyChangeListener( ::rtl::OUString(), this );
[ # # ]
560 : : else
561 [ # # ][ # # ]: 0 : xSet->removePropertyChangeListener( ::rtl::OUString(), this );
[ # # ]
562 : 0 : }
563 : 0 : }
564 : :
565 : :
566 : : //------------------------------------------------------------------------------
567 : 0 : void OXUndoEnvironment::switchListening( const Reference< XIndexAccess >& _rxContainer, bool _bStartListening ) SAL_THROW(())
568 : : {
569 : : OSL_PRECOND( _rxContainer.is(), "OXUndoEnvironment::switchListening: invalid container!" );
570 [ # # ]: 0 : if ( !_rxContainer.is() )
571 : 0 : return;
572 : :
573 : : try
574 : : {
575 : : // also handle all children of this element
576 : 0 : Reference< XInterface > xInterface;
577 [ # # ][ # # ]: 0 : sal_Int32 nCount = _rxContainer->getCount();
578 [ # # ]: 0 : for(sal_Int32 i = 0;i != nCount;++i)
579 : : {
580 [ # # ][ # # ]: 0 : xInterface.set(_rxContainer->getByIndex( i ),uno::UNO_QUERY);
[ # # ]
581 [ # # ]: 0 : if ( _bStartListening )
582 [ # # ]: 0 : AddElement( xInterface );
583 : : else
584 [ # # ]: 0 : RemoveElement( xInterface );
585 : : }
586 : :
587 : : // be notified of any changes in the container elements
588 [ # # ]: 0 : Reference< XContainer > xSimpleContainer( _rxContainer, UNO_QUERY );
589 [ # # ]: 0 : if ( xSimpleContainer.is() )
590 : : {
591 [ # # ]: 0 : if ( _bStartListening )
592 [ # # ][ # # ]: 0 : xSimpleContainer->addContainerListener( this );
[ # # ]
593 : : else
594 [ # # ][ # # ]: 0 : xSimpleContainer->removeContainerListener( this );
[ # # ]
595 [ # # ]: 0 : }
596 : : }
597 : 0 : catch( const Exception& )
598 : : {
599 : : DBG_UNHANDLED_EXCEPTION();
600 : : }
601 : : }
602 : :
603 : : //------------------------------------------------------------------------------
604 : 0 : void OXUndoEnvironment::switchListening( const Reference< XInterface >& _rxObject, bool _bStartListening ) SAL_THROW(())
605 : : {
606 : : OSL_PRECOND( _rxObject.is(), "OXUndoEnvironment::switchListening: how should I listen at a NULL object?" );
607 : :
608 : : try
609 : : {
610 [ # # ]: 0 : if ( !m_pImpl->m_bReadOnly )
611 : : {
612 [ # # ]: 0 : Reference< XPropertySet > xProps( _rxObject, UNO_QUERY );
613 [ # # ]: 0 : if ( xProps.is() )
614 : : {
615 [ # # ]: 0 : if ( _bStartListening )
616 [ # # ][ # # ]: 0 : xProps->addPropertyChangeListener( ::rtl::OUString(), this );
[ # # ]
617 : : else
618 [ # # ][ # # ]: 0 : xProps->removePropertyChangeListener( ::rtl::OUString(), this );
[ # # ]
619 : 0 : }
620 : : }
621 : :
622 [ # # ]: 0 : Reference< XModifyBroadcaster > xBroadcaster( _rxObject, UNO_QUERY );
623 [ # # ]: 0 : if ( xBroadcaster.is() )
624 : : {
625 [ # # ]: 0 : if ( _bStartListening )
626 [ # # ][ # # ]: 0 : xBroadcaster->addModifyListener( this );
[ # # ]
627 : : else
628 [ # # ][ # # ]: 0 : xBroadcaster->removeModifyListener( this );
[ # # ]
629 [ # # ]: 0 : }
630 : : }
631 : 0 : catch( const Exception& )
632 : : {
633 : : }
634 : 0 : }
635 : :
636 : : //------------------------------------------------------------------------------
637 : 0 : void OXUndoEnvironment::AddElement(const Reference< XInterface >& _rxElement )
638 : : {
639 [ # # ][ # # ]: 0 : if ( !IsLocked() )
640 [ # # ]: 0 : m_pImpl->m_aFormatNormalizer.notifyElementInserted( _rxElement );
641 : :
642 : : // if it's a container, start listening at all elements
643 [ # # ]: 0 : Reference< XIndexAccess > xContainer( _rxElement, UNO_QUERY );
644 [ # # ]: 0 : if ( xContainer.is() )
645 [ # # ]: 0 : switchListening( xContainer, true );
646 : :
647 [ # # ]: 0 : switchListening( _rxElement, true );
648 : 0 : }
649 : :
650 : : //------------------------------------------------------------------------------
651 : 0 : void OXUndoEnvironment::RemoveElement(const Reference< XInterface >& _rxElement)
652 : : {
653 [ # # ]: 0 : uno::Reference<beans::XPropertySet> xProp(_rxElement,uno::UNO_QUERY);
654 [ # # ]: 0 : if (!m_pImpl->m_aPropertySetCache.empty())
655 [ # # ]: 0 : m_pImpl->m_aPropertySetCache.erase(xProp);
656 [ # # ]: 0 : switchListening( _rxElement, false );
657 : :
658 [ # # ]: 0 : Reference< XIndexAccess > xContainer( _rxElement, UNO_QUERY );
659 [ # # ]: 0 : if ( xContainer.is() )
660 [ # # ]: 0 : switchListening( xContainer, false );
661 : 0 : }
662 : :
663 : 0 : void OXUndoEnvironment::SetUndoMode(sal_Bool _bUndo)
664 : : {
665 : 0 : m_pImpl->m_bIsUndo = _bUndo;
666 : 0 : }
667 : :
668 : 0 : sal_Bool OXUndoEnvironment::IsUndoMode() const
669 : : {
670 : 0 : return m_pImpl->m_bIsUndo;
671 : : }
672 : : //============================================================================
673 : : } // rptui
674 : : //============================================================================
675 : :
676 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|