1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <vcl/svapp.hxx>
21 #include <svx/svditer.hxx>
22 #include <svx/svdoole2.hxx>
23 #include <svx/svdpage.hxx>
25 #include "chartlock.hxx"
26 #include "document.hxx"
27 #include "drwlayer.hxx"
29 #include <com/sun/star/embed/XComponentSupplier.hpp>
31 using namespace com::sun::star
;
32 using ::com::sun::star::uno::Reference
;
33 using ::com::sun::star::uno::WeakReference
;
35 #define SC_CHARTLOCKTIMEOUT 660
40 std::vector
< WeakReference
< frame::XModel
> > lcl_getAllLivingCharts( ScDocument
* pDoc
)
42 std::vector
< WeakReference
< frame::XModel
> > aRet
;
45 ScDrawLayer
* pDrawLayer
= pDoc
->GetDrawLayer();
49 for (SCTAB nTab
=0; nTab
<=pDoc
->GetMaxTableNumber(); nTab
++)
51 if (pDoc
->HasTable(nTab
))
53 SdrPage
* pPage
= pDrawLayer
->GetPage(static_cast<sal_uInt16
>(nTab
));
54 OSL_ENSURE(pPage
,"Page ?");
56 SdrObjListIter
aIter( *pPage
, IM_DEEPNOGROUPS
);
57 SdrObject
* pObject
= aIter
.Next();
60 if( ScDocument::IsChart( pObject
) )
62 uno::Reference
< embed::XEmbeddedObject
> xIPObj
= static_cast<SdrOle2Obj
*>(pObject
)->GetObjRef();
63 uno::Reference
< embed::XComponentSupplier
> xCompSupp( xIPObj
, uno::UNO_QUERY
);
66 Reference
< frame::XModel
> xModel( xCompSupp
->getComponent(), uno::UNO_QUERY
);
68 aRet
.push_back( xModel
);
71 pObject
= aIter
.Next();
78 }//end anonymous namespace
81 ScChartLockGuard::ScChartLockGuard( ScDocument
* pDoc
) :
82 maChartModels( lcl_getAllLivingCharts( pDoc
) )
84 std::vector
< WeakReference
< frame::XModel
> >::const_iterator aIter
= maChartModels
.begin();
85 const std::vector
< WeakReference
< frame::XModel
> >::const_iterator aEnd
= maChartModels
.end();
86 for( ; aIter
!= aEnd
; ++aIter
)
90 Reference
< frame::XModel
> xModel( *aIter
);
92 xModel
->lockControllers();
94 catch ( uno::Exception
& )
96 OSL_FAIL("Unexpected exception in ScChartLockGuard");
101 ScChartLockGuard::~ScChartLockGuard()
103 std::vector
< WeakReference
< frame::XModel
> >::const_iterator aIter
= maChartModels
.begin();
104 const std::vector
< WeakReference
< frame::XModel
> >::const_iterator aEnd
= maChartModels
.end();
105 for( ; aIter
!= aEnd
; ++aIter
)
109 Reference
< frame::XModel
> xModel( *aIter
);
111 xModel
->unlockControllers();
113 catch ( uno::Exception
& )
115 OSL_FAIL("Unexpected exception in ScChartLockGuard");
120 void ScChartLockGuard::AlsoLockThisChart( const Reference
< frame::XModel
>& xModel
)
125 WeakReference
< frame::XModel
> xWeakModel(xModel
);
127 std::vector
< WeakReference
< frame::XModel
> >::iterator
aFindIter(
128 ::std::find( maChartModels
.begin(), maChartModels
.end(), xWeakModel
) );
130 if( aFindIter
== maChartModels
.end() )
134 xModel
->lockControllers();
135 maChartModels
.push_back( xModel
);
137 catch ( uno::Exception
& )
139 OSL_FAIL("Unexpected exception in ScChartLockGuard");
144 // ScTemporaryChartLock
145 ScTemporaryChartLock::ScTemporaryChartLock( ScDocument
* pDocP
) :
148 maTimer
.SetTimeout( SC_CHARTLOCKTIMEOUT
);
149 maTimer
.SetTimeoutHdl( LINK( this, ScTemporaryChartLock
, TimeoutHdl
) );
152 ScTemporaryChartLock::~ScTemporaryChartLock()
158 void ScTemporaryChartLock::StartOrContinueLocking()
160 if(!mapScChartLockGuard
.get())
161 mapScChartLockGuard
.reset( new ScChartLockGuard(mpDoc
) );
165 void ScTemporaryChartLock::StopLocking()
168 mapScChartLockGuard
.reset();
171 void ScTemporaryChartLock::AlsoLockThisChart( const Reference
< frame::XModel
>& xModel
)
173 if(mapScChartLockGuard
.get())
174 mapScChartLockGuard
->AlsoLockThisChart( xModel
);
177 IMPL_LINK_NOARG_TYPED(ScTemporaryChartLock
, TimeoutHdl
, Timer
*, void)
179 mapScChartLockGuard
.reset();
182 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */