fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / core / tool / chartlock.cxx
blob82b82400b7aecdb5b02db450480d38ce72d6acd1
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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
37 namespace
40 std::vector< WeakReference< frame::XModel > > lcl_getAllLivingCharts( ScDocument* pDoc )
42 std::vector< WeakReference< frame::XModel > > aRet;
43 if( !pDoc )
44 return aRet;
45 ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer();
46 if (!pDrawLayer)
47 return aRet;
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();
58 while (pObject)
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 );
64 if( xCompSupp.is())
66 Reference< frame::XModel > xModel( xCompSupp->getComponent(), uno::UNO_QUERY );
67 if( xModel.is() )
68 aRet.push_back( xModel );
71 pObject = aIter.Next();
75 return aRet;
78 }//end anonymous namespace
80 // ScChartLockGuard
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 )
88 try
90 Reference< frame::XModel > xModel( *aIter );
91 if( xModel.is())
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 );
110 if( xModel.is())
111 xModel->unlockControllers();
113 catch ( uno::Exception& )
115 OSL_FAIL("Unexpected exception in ScChartLockGuard");
120 void ScChartLockGuard::AlsoLockThisChart( const Reference< frame::XModel >& xModel )
122 if(!xModel.is())
123 return;
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 ) :
146 mpDoc( pDocP )
148 maTimer.SetTimeout( SC_CHARTLOCKTIMEOUT );
149 maTimer.SetTimeoutHdl( LINK( this, ScTemporaryChartLock, TimeoutHdl ) );
152 ScTemporaryChartLock::~ScTemporaryChartLock()
154 mpDoc = 0;
155 StopLocking();
158 void ScTemporaryChartLock::StartOrContinueLocking()
160 if(!mapScChartLockGuard.get())
161 mapScChartLockGuard.reset( new ScChartLockGuard(mpDoc) );
162 maTimer.Start();
165 void ScTemporaryChartLock::StopLocking()
167 maTimer.Stop();
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: */