update dev300-m58
[ooovba.git] / sdext / source / minimizer / pagecollector.cxx
blob7d973e17ef9848086b6bc7aaaa2cf4a6ab72839c
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: pagecollector.cxx,v $
11 * $Revision: 1.4 $
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 ************************************************************************/
32 // MARKER(update_precomp.py): autogen include statement, do not remove
33 #include "precompiled_sdext.hxx"
35 #include "pagecollector.hxx"
36 #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
37 #include <com/sun/star/presentation/XPresentationPage.hpp>
38 #include <com/sun/star/drawing/XMasterPagesSupplier.hpp>
39 #include <com/sun/star/drawing/XMasterPageTarget.hpp>
40 #include <com/sun/star/presentation/XCustomPresentationSupplier.hpp>
41 #include <com/sun/star/container/XNameContainer.hpp>
42 #include <com/sun/star/container/XIndexContainer.hpp>
44 using namespace ::rtl;
45 using namespace ::com::sun::star;
46 using namespace ::com::sun::star::uno;
47 using namespace ::com::sun::star::awt;
48 using namespace ::com::sun::star::drawing;
49 using namespace ::com::sun::star::frame;
50 using namespace ::com::sun::star::beans;
51 using namespace ::com::sun::star::container;
52 using namespace ::com::sun::star::presentation;
54 void PageCollector::CollectCustomShowPages( const com::sun::star::uno::Reference< com::sun::star::frame::XModel >& rxModel, const rtl::OUString& rCustomShowName, std::vector< Reference< XDrawPage > >& rUsedPageList )
56 try
58 Reference< XCustomPresentationSupplier > aXCPSup( rxModel, UNO_QUERY_THROW );
59 Reference< XNameContainer > aXCont( aXCPSup->getCustomPresentations() );
60 if ( aXCont.is() )
62 // creating a list of every page that is used within our customshow
63 Sequence< OUString> aNameSeq( aXCont->getElementNames() );
64 const OUString* pUString = aNameSeq.getArray();
65 sal_Int32 i, nCount = aNameSeq.getLength();
66 for ( i = 0; i < nCount; i++ )
68 if ( pUString[ i ] == rCustomShowName )
70 Reference< container::XIndexContainer > aXIC( aXCont->getByName( pUString[ i ] ), UNO_QUERY_THROW );
71 sal_Int32 j, nSlideCount = aXIC->getCount();
72 for ( j = 0; j < nSlideCount; j++ )
74 Reference< XDrawPage > xDrawPage( aXIC->getByIndex( j ), UNO_QUERY_THROW );
75 std::vector< Reference< XDrawPage > >::iterator aIter( rUsedPageList.begin() );
76 std::vector< Reference< XDrawPage > >::iterator aEnd( rUsedPageList.end() );
77 while( aIter != aEnd )
79 if ( *aIter == xDrawPage )
80 break;
81 aIter++;
83 if ( aIter == aEnd )
84 rUsedPageList.push_back( xDrawPage );
90 catch( Exception& )
96 void PageCollector::CollectNonCustomShowPages( const com::sun::star::uno::Reference< com::sun::star::frame::XModel >& rxModel, const rtl::OUString& rCustomShowName, std::vector< Reference< XDrawPage > >& rNonUsedPageList )
98 try
100 std::vector< Reference< XDrawPage > > vUsedPageList;
101 PageCollector::CollectCustomShowPages( rxModel, rCustomShowName, vUsedPageList );
102 if ( vUsedPageList.size() )
104 Reference< XDrawPagesSupplier > xDrawPagesSupplier( rxModel, UNO_QUERY_THROW );
105 Reference< XDrawPages > xDrawPages( xDrawPagesSupplier->getDrawPages(), UNO_QUERY_THROW );
106 for ( sal_Int32 j = 0; j < xDrawPages->getCount(); j++ )
108 Reference< XDrawPage > xDrawPage( xDrawPages->getByIndex( j ), UNO_QUERY_THROW );
109 std::vector< Reference< XDrawPage > >::iterator aIter( vUsedPageList.begin() );
110 std::vector< Reference< XDrawPage > >::iterator aEnd( vUsedPageList.end() );
111 while( aIter != aEnd )
113 if ( *aIter == xDrawPage )
114 break;
115 aIter++;
117 if ( aIter == aEnd )
118 rNonUsedPageList.push_back( xDrawPage );
122 catch( Exception& )
128 void PageCollector::CollectMasterPages( const Reference< XModel >& rxModel, std::vector< PageCollector::MasterPageEntity >& rMasterPageList )
130 typedef std::vector< MasterPageEntity > MasterPageList;
131 typedef MasterPageList::iterator MasterPageIter;
135 // generating list of all master pages
136 Reference< XMasterPagesSupplier > xMasterPagesSupplier( rxModel, UNO_QUERY_THROW );
137 Reference< XDrawPages > xMasterPages( xMasterPagesSupplier->getMasterPages(), UNO_QUERY_THROW );
138 for ( sal_Int32 i = 0; i < xMasterPages->getCount(); i++ )
140 Reference< XDrawPage > xMasterPage( xMasterPages->getByIndex( i ), UNO_QUERY_THROW );
141 MasterPageIter aIter( rMasterPageList.begin() );
142 MasterPageIter aEnd ( rMasterPageList.end() );
143 while( aIter != aEnd )
145 if ( aIter->xMasterPage == xMasterPage )
146 break;
147 aIter++;
149 if ( aIter == aEnd )
151 MasterPageEntity aMasterPageEntity;
152 aMasterPageEntity.xMasterPage = xMasterPage;
153 aMasterPageEntity.bUsed = sal_False;
154 rMasterPageList.push_back( aMasterPageEntity );
158 // mark masterpages which are referenced by drawpages
159 Reference< XDrawPagesSupplier > xDrawPagesSupplier( rxModel, UNO_QUERY_THROW );
160 Reference< XDrawPages > xDrawPages( xDrawPagesSupplier->getDrawPages(), UNO_QUERY_THROW );
161 for ( sal_Int32 j = 0; j < xDrawPages->getCount(); j++ )
163 Reference< XMasterPageTarget > xMasterPageTarget( xDrawPages->getByIndex( j ), UNO_QUERY_THROW );
164 Reference< XDrawPage > xMasterPage( xMasterPageTarget->getMasterPage(), UNO_QUERY_THROW );
165 MasterPageIter aIter( rMasterPageList.begin() );
166 MasterPageIter aEnd ( rMasterPageList.end() );
167 while( aIter != aEnd )
169 if ( aIter->xMasterPage == xMasterPage )
171 aIter->bUsed = sal_True;
172 break;
174 aIter++;
176 if ( aIter == aEnd )
177 throw uno::RuntimeException();
180 catch( Exception& )