bump product version to 4.1.6.2
[LibreOffice.git] / sdext / source / minimizer / pagecollector.cxx
blob0e592eab4c6a5513eb6b068079edb7b4004cc766
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/presentation/XPresentationPage.hpp>
24 #include <com/sun/star/drawing/XMasterPagesSupplier.hpp>
25 #include <com/sun/star/drawing/XMasterPageTarget.hpp>
26 #include <com/sun/star/presentation/XCustomPresentationSupplier.hpp>
27 #include <com/sun/star/container/XNameContainer.hpp>
28 #include <com/sun/star/container/XIndexContainer.hpp>
30 using namespace ::rtl;
31 using namespace ::com::sun::star;
32 using namespace ::com::sun::star::uno;
33 using namespace ::com::sun::star::awt;
34 using namespace ::com::sun::star::drawing;
35 using namespace ::com::sun::star::frame;
36 using namespace ::com::sun::star::beans;
37 using namespace ::com::sun::star::container;
38 using namespace ::com::sun::star::presentation;
40 void PageCollector::CollectCustomShowPages( const com::sun::star::uno::Reference< com::sun::star::frame::XModel >& rxModel, const OUString& rCustomShowName, std::vector< Reference< XDrawPage > >& rUsedPageList )
42 try
44 Reference< XCustomPresentationSupplier > aXCPSup( rxModel, UNO_QUERY_THROW );
45 Reference< XNameContainer > aXCont( aXCPSup->getCustomPresentations() );
46 if ( aXCont.is() )
48 // creating a list of every page that is used within our customshow
49 Sequence< OUString> aNameSeq( aXCont->getElementNames() );
50 const OUString* pUString = aNameSeq.getArray();
51 sal_Int32 i, nCount = aNameSeq.getLength();
52 for ( i = 0; i < nCount; i++ )
54 if ( pUString[ i ] == rCustomShowName )
56 Reference< container::XIndexContainer > aXIC( aXCont->getByName( pUString[ i ] ), UNO_QUERY_THROW );
57 sal_Int32 j, nSlideCount = aXIC->getCount();
58 for ( j = 0; j < nSlideCount; j++ )
60 Reference< XDrawPage > xDrawPage( aXIC->getByIndex( j ), UNO_QUERY_THROW );
61 std::vector< Reference< XDrawPage > >::iterator aIter( rUsedPageList.begin() );
62 std::vector< Reference< XDrawPage > >::iterator aEnd( rUsedPageList.end() );
63 while( aIter != aEnd )
65 if ( *aIter == xDrawPage )
66 break;
67 ++aIter;
69 if ( aIter == aEnd )
70 rUsedPageList.push_back( xDrawPage );
76 catch( Exception& )
82 void PageCollector::CollectNonCustomShowPages( const com::sun::star::uno::Reference< com::sun::star::frame::XModel >& rxModel, const OUString& rCustomShowName, std::vector< Reference< XDrawPage > >& rNonUsedPageList )
84 try
86 std::vector< Reference< XDrawPage > > vUsedPageList;
87 PageCollector::CollectCustomShowPages( rxModel, rCustomShowName, vUsedPageList );
88 if ( !vUsedPageList.empty() )
90 Reference< XDrawPagesSupplier > xDrawPagesSupplier( rxModel, UNO_QUERY_THROW );
91 Reference< XDrawPages > xDrawPages( xDrawPagesSupplier->getDrawPages(), UNO_QUERY_THROW );
92 for ( sal_Int32 j = 0; j < xDrawPages->getCount(); j++ )
94 Reference< XDrawPage > xDrawPage( xDrawPages->getByIndex( j ), UNO_QUERY_THROW );
95 std::vector< Reference< XDrawPage > >::iterator aIter( vUsedPageList.begin() );
96 std::vector< Reference< XDrawPage > >::iterator aEnd( vUsedPageList.end() );
97 while( aIter != aEnd )
99 if ( *aIter == xDrawPage )
100 break;
101 ++aIter;
103 if ( aIter == aEnd )
104 rNonUsedPageList.push_back( xDrawPage );
108 catch( Exception& )
114 void PageCollector::CollectMasterPages( const Reference< XModel >& rxModel, std::vector< PageCollector::MasterPageEntity >& rMasterPageList )
116 typedef std::vector< MasterPageEntity > MasterPageList;
117 typedef MasterPageList::iterator MasterPageIter;
121 // generating list of all master pages
122 Reference< XMasterPagesSupplier > xMasterPagesSupplier( rxModel, UNO_QUERY_THROW );
123 Reference< XDrawPages > xMasterPages( xMasterPagesSupplier->getMasterPages(), UNO_QUERY_THROW );
124 for ( sal_Int32 i = 0; i < xMasterPages->getCount(); i++ )
126 Reference< XDrawPage > xMasterPage( xMasterPages->getByIndex( i ), UNO_QUERY_THROW );
127 MasterPageIter aIter( rMasterPageList.begin() );
128 MasterPageIter aEnd ( rMasterPageList.end() );
129 while( aIter != aEnd )
131 if ( aIter->xMasterPage == xMasterPage )
132 break;
133 ++aIter;
135 if ( aIter == aEnd )
137 MasterPageEntity aMasterPageEntity;
138 aMasterPageEntity.xMasterPage = xMasterPage;
139 aMasterPageEntity.bUsed = false;
140 rMasterPageList.push_back( aMasterPageEntity );
144 // mark masterpages which are referenced by drawpages
145 Reference< XDrawPagesSupplier > xDrawPagesSupplier( rxModel, UNO_QUERY_THROW );
146 Reference< XDrawPages > xDrawPages( xDrawPagesSupplier->getDrawPages(), UNO_QUERY_THROW );
147 for ( sal_Int32 j = 0; j < xDrawPages->getCount(); j++ )
149 Reference< XMasterPageTarget > xMasterPageTarget( xDrawPages->getByIndex( j ), UNO_QUERY_THROW );
150 Reference< XDrawPage > xMasterPage( xMasterPageTarget->getMasterPage(), UNO_QUERY_THROW );
151 MasterPageIter aIter( rMasterPageList.begin() );
152 MasterPageIter aEnd ( rMasterPageList.end() );
153 while( aIter != aEnd )
155 if ( aIter->xMasterPage == xMasterPage )
157 aIter->bUsed = true;
158 break;
160 ++aIter;
162 if ( aIter == aEnd )
163 throw uno::RuntimeException();
166 catch( Exception& )
171 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */