1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: chartlock.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
34 #include <vcl/svapp.hxx>
35 #include <svx/svditer.hxx>
36 #include <svx/svdoole2.hxx>
37 #include <svx/svdpage.hxx>
39 #include "chartlock.hxx"
40 #include "document.hxx"
41 #include "drwlayer.hxx"
43 using namespace com::sun::star
;
44 using ::com::sun::star::uno::Reference
;
45 using ::com::sun::star::uno::WeakReference
;
47 #define SC_CHARTLOCKTIMEOUT 660
49 // ====================================================================
54 std::vector
< WeakReference
< frame::XModel
> > lcl_getAllLivingCharts( ScDocument
* pDoc
)
56 std::vector
< WeakReference
< frame::XModel
> > aRet
;
59 ScDrawLayer
* pDrawLayer
= pDoc
->GetDrawLayer();
63 for (SCTAB nTab
=0; nTab
<=pDoc
->GetMaxTableNumber(); nTab
++)
65 if (pDoc
->HasTable(nTab
))
67 SdrPage
* pPage
= pDrawLayer
->GetPage(static_cast<sal_uInt16
>(nTab
));
68 DBG_ASSERT(pPage
,"Page ?");
70 SdrObjListIter
aIter( *pPage
, IM_DEEPNOGROUPS
);
71 SdrObject
* pObject
= aIter
.Next();
74 if( pDoc
->IsChart( pObject
) )
76 uno::Reference
< embed::XEmbeddedObject
> xIPObj
= ((SdrOle2Obj
*)pObject
)->GetObjRef();
77 uno::Reference
< embed::XComponentSupplier
> xCompSupp( xIPObj
, uno::UNO_QUERY
);
80 Reference
< frame::XModel
> xModel( xCompSupp
->getComponent(), uno::UNO_QUERY
);
82 aRet
.push_back( xModel
);
85 pObject
= aIter
.Next();
92 }//end anonymous namespace
94 // === ScChartLockGuard ======================================
96 ScChartLockGuard::ScChartLockGuard( ScDocument
* pDoc
) :
97 maChartModels( lcl_getAllLivingCharts( pDoc
) )
99 std::vector
< WeakReference
< frame::XModel
> >::const_iterator aIter
= maChartModels
.begin();
100 const std::vector
< WeakReference
< frame::XModel
> >::const_iterator aEnd
= maChartModels
.end();
101 for( ; aIter
!= aEnd
; ++aIter
)
105 Reference
< frame::XModel
> xModel( *aIter
);
107 xModel
->lockControllers();
109 catch ( uno::Exception
& )
111 DBG_ERROR("Unexpected exception in ScChartLockGuard");
116 ScChartLockGuard::~ScChartLockGuard()
118 std::vector
< WeakReference
< frame::XModel
> >::const_iterator aIter
= maChartModels
.begin();
119 const std::vector
< WeakReference
< frame::XModel
> >::const_iterator aEnd
= maChartModels
.end();
120 for( ; aIter
!= aEnd
; ++aIter
)
124 Reference
< frame::XModel
> xModel( *aIter
);
126 xModel
->unlockControllers();
128 catch ( uno::Exception
& )
130 DBG_ERROR("Unexpected exception in ScChartLockGuard");
135 void ScChartLockGuard::AlsoLockThisChart( const Reference
< frame::XModel
>& xModel
)
140 WeakReference
< frame::XModel
> xWeakModel(xModel
);
142 std::vector
< WeakReference
< frame::XModel
> >::iterator
aFindIter(
143 ::std::find( maChartModels
.begin(), maChartModels
.end(), xWeakModel
) );
145 if( aFindIter
== maChartModels
.end() )
149 xModel
->lockControllers();
150 maChartModels
.push_back( xModel
);
152 catch ( uno::Exception
& )
154 DBG_ERROR("Unexpected exception in ScChartLockGuard");
159 // === ScTemporaryChartLock ======================================
161 ScTemporaryChartLock::ScTemporaryChartLock( ScDocument
* pDocP
) :
164 maTimer
.SetTimeout( SC_CHARTLOCKTIMEOUT
);
165 maTimer
.SetTimeoutHdl( LINK( this, ScTemporaryChartLock
, TimeoutHdl
) );
169 ScTemporaryChartLock::~ScTemporaryChartLock()
175 void ScTemporaryChartLock::StartOrContinueLocking()
177 if(!mapScChartLockGuard
.get())
178 mapScChartLockGuard
= std::auto_ptr
< ScChartLockGuard
>( new ScChartLockGuard(mpDoc
) );
182 void ScTemporaryChartLock::StopLocking()
185 mapScChartLockGuard
.reset();
188 void ScTemporaryChartLock::AlsoLockThisChart( const Reference
< frame::XModel
>& xModel
)
190 if(mapScChartLockGuard
.get())
191 mapScChartLockGuard
->AlsoLockThisChart( xModel
);
194 IMPL_LINK( ScTemporaryChartLock
, TimeoutHdl
, Timer
*, EMPTYARG
)
196 mapScChartLockGuard
.reset();