cid#1607171 Data race condition
[LibreOffice.git] / sdext / source / minimizer / pagecollector.cxx
blob265922803e7c872e8259c901a5669dc3c794d888
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 .
21 #include "pagecollector.hxx"
22 #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
23 #include <com/sun/star/drawing/XMasterPagesSupplier.hpp>
24 #include <com/sun/star/drawing/XMasterPageTarget.hpp>
25 #include <com/sun/star/presentation/XCustomPresentationSupplier.hpp>
26 #include <com/sun/star/container/XNameContainer.hpp>
27 #include <com/sun/star/container/XIndexContainer.hpp>
29 using namespace ::com::sun::star;
30 using namespace ::com::sun::star::uno;
31 using namespace ::com::sun::star::drawing;
32 using namespace ::com::sun::star::frame;
33 using namespace ::com::sun::star::container;
34 using namespace ::com::sun::star::presentation;
36 void PageCollector::CollectCustomShowPages( const css::uno::Reference< css::frame::XModel >& rxModel, std::u16string_view rCustomShowName, std::vector< Reference< XDrawPage > >& rUsedPageList )
38 try
40 Reference< XCustomPresentationSupplier > aXCPSup( rxModel, UNO_QUERY_THROW );
41 Reference< XNameContainer > aXCont( aXCPSup->getCustomPresentations() );
42 if ( aXCont.is() )
44 // creating a list of every page that is used within our customshow
45 const Sequence< OUString> aNameSeq( aXCont->getElementNames() );
46 for ( OUString const & i :aNameSeq )
48 if ( i == rCustomShowName )
50 Reference< container::XIndexContainer > aXIC( aXCont->getByName( i ), UNO_QUERY_THROW );
51 sal_Int32 j, nSlideCount = aXIC->getCount();
52 for ( j = 0; j < nSlideCount; j++ )
54 Reference< XDrawPage > xDrawPage( aXIC->getByIndex( j ), UNO_QUERY_THROW );
55 auto aIter = std::find(rUsedPageList.begin(), rUsedPageList.end(), xDrawPage);
56 if ( aIter == rUsedPageList.end() )
57 rUsedPageList.push_back( xDrawPage );
63 catch( Exception& )
69 void PageCollector::CollectNonCustomShowPages( const css::uno::Reference< css::frame::XModel >& rxModel, std::u16string_view rCustomShowName, std::vector< Reference< XDrawPage > >& rNonUsedPageList )
71 try
73 std::vector< Reference< XDrawPage > > vUsedPageList;
74 PageCollector::CollectCustomShowPages( rxModel, rCustomShowName, vUsedPageList );
75 if ( !vUsedPageList.empty() )
77 Reference< XDrawPagesSupplier > xDrawPagesSupplier( rxModel, UNO_QUERY_THROW );
78 Reference< XDrawPages > xDrawPages( xDrawPagesSupplier->getDrawPages(), UNO_SET_THROW );
79 for ( sal_Int32 j = 0; j < xDrawPages->getCount(); j++ )
81 Reference< XDrawPage > xDrawPage( xDrawPages->getByIndex( j ), UNO_QUERY_THROW );
82 auto aIter = std::find(vUsedPageList.begin(), vUsedPageList.end(), xDrawPage);
83 if ( aIter == vUsedPageList.end() )
84 rNonUsedPageList.push_back( xDrawPage );
88 catch( Exception& )
94 void PageCollector::CollectMasterPages( const Reference< XModel >& rxModel, std::vector< PageCollector::MasterPageEntity >& rMasterPageList )
96 try
98 // generating list of all master pages
99 Reference< XMasterPagesSupplier > xMasterPagesSupplier( rxModel, UNO_QUERY_THROW );
100 Reference< XDrawPages > xMasterPages( xMasterPagesSupplier->getMasterPages(), UNO_SET_THROW );
101 for ( sal_Int32 i = 0; i < xMasterPages->getCount(); i++ )
103 Reference< XDrawPage > xMasterPage( xMasterPages->getByIndex( i ), UNO_QUERY_THROW );
104 auto aIter = std::find_if(rMasterPageList.begin(), rMasterPageList.end(),
105 [&xMasterPage](const MasterPageEntity& rEntity) { return rEntity.xMasterPage == xMasterPage; });
106 if ( aIter == rMasterPageList.end() )
108 MasterPageEntity aMasterPageEntity;
109 aMasterPageEntity.xMasterPage = std::move(xMasterPage);
110 aMasterPageEntity.bUsed = false;
111 rMasterPageList.push_back( aMasterPageEntity );
115 // mark masterpages which are referenced by drawpages
116 Reference< XDrawPagesSupplier > xDrawPagesSupplier( rxModel, UNO_QUERY_THROW );
117 Reference< XDrawPages > xDrawPages( xDrawPagesSupplier->getDrawPages(), UNO_SET_THROW );
118 for ( sal_Int32 j = 0; j < xDrawPages->getCount(); j++ )
120 Reference< XMasterPageTarget > xMasterPageTarget( xDrawPages->getByIndex( j ), UNO_QUERY_THROW );
121 Reference< XDrawPage > xMasterPage( xMasterPageTarget->getMasterPage(), UNO_SET_THROW );
122 auto aIter = std::find_if(rMasterPageList.begin(), rMasterPageList.end(),
123 [&xMasterPage](const MasterPageEntity& rEntity) { return rEntity.xMasterPage == xMasterPage; });
124 if ( aIter == rMasterPageList.end() )
125 throw uno::RuntimeException();
126 aIter->bUsed = true;
129 catch( Exception& )
134 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */