1  /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sdext.hxx"
30 
31 #include "pagecollector.hxx"
32 #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
33 #include <com/sun/star/presentation/XPresentationPage.hpp>
34 #include <com/sun/star/drawing/XMasterPagesSupplier.hpp>
35 #include <com/sun/star/drawing/XMasterPageTarget.hpp>
36 #include <com/sun/star/presentation/XCustomPresentationSupplier.hpp>
37 #include <com/sun/star/container/XNameContainer.hpp>
38 #include <com/sun/star/container/XIndexContainer.hpp>
39 
40 using namespace ::rtl;
41 using namespace ::com::sun::star;
42 using namespace ::com::sun::star::uno;
43 using namespace ::com::sun::star::awt;
44 using namespace ::com::sun::star::drawing;
45 using namespace ::com::sun::star::frame;
46 using namespace ::com::sun::star::beans;
47 using namespace ::com::sun::star::container;
48 using namespace ::com::sun::star::presentation;
49 
50 void PageCollector::CollectCustomShowPages( const com::sun::star::uno::Reference< com::sun::star::frame::XModel >& rxModel, const rtl::OUString& rCustomShowName, std::vector< Reference< XDrawPage > >& rUsedPageList )
51 {
52 	try
53 	{
54 		Reference< XCustomPresentationSupplier > aXCPSup( rxModel, UNO_QUERY_THROW );
55 		Reference< XNameContainer > aXCont( aXCPSup->getCustomPresentations() );
56         if ( aXCont.is() )
57         {
58 			// creating a list of every page that is used within our customshow
59             Sequence< OUString> aNameSeq( aXCont->getElementNames() );
60             const OUString* pUString = aNameSeq.getArray();
61             sal_Int32 i, nCount = aNameSeq.getLength();
62             for ( i = 0; i < nCount; i++ )
63             {
64 				if ( pUString[ i ] == rCustomShowName )
65 				{
66 					Reference< container::XIndexContainer > aXIC( aXCont->getByName( pUString[ i ] ), UNO_QUERY_THROW );
67                     sal_Int32 j, nSlideCount = aXIC->getCount();
68                     for ( j = 0; j < nSlideCount; j++ )
69                     {
70 						Reference< XDrawPage > xDrawPage( aXIC->getByIndex( j ), UNO_QUERY_THROW );
71 						std::vector< Reference< XDrawPage > >::iterator aIter( rUsedPageList.begin() );
72 						std::vector< Reference< XDrawPage > >::iterator aEnd( rUsedPageList.end() );
73 						while( aIter != aEnd )
74 						{
75 							if ( *aIter == xDrawPage )
76 								break;
77 							aIter++;
78 						}
79 						if ( aIter == aEnd )
80 							rUsedPageList.push_back( xDrawPage );
81                     }
82                 }
83             }
84         }
85 	}
86 	catch( Exception& )
87 	{
88 
89 	}
90 }
91 
92 void PageCollector::CollectNonCustomShowPages( const com::sun::star::uno::Reference< com::sun::star::frame::XModel >& rxModel, const rtl::OUString& rCustomShowName, std::vector< Reference< XDrawPage > >& rNonUsedPageList )
93 {
94 	try
95 	{
96 		std::vector< Reference< XDrawPage > > vUsedPageList;
97 		PageCollector::CollectCustomShowPages( rxModel, rCustomShowName, vUsedPageList );
98 		if ( vUsedPageList.size() )
99 		{
100 			Reference< XDrawPagesSupplier > xDrawPagesSupplier( rxModel, UNO_QUERY_THROW );
101 			Reference< XDrawPages > xDrawPages( xDrawPagesSupplier->getDrawPages(), UNO_QUERY_THROW );
102 			for ( sal_Int32 j = 0; j < xDrawPages->getCount(); j++ )
103 			{
104 				Reference< XDrawPage > xDrawPage( xDrawPages->getByIndex( j ), UNO_QUERY_THROW );
105 				std::vector< Reference< XDrawPage > >::iterator aIter( vUsedPageList.begin() );
106 				std::vector< Reference< XDrawPage > >::iterator aEnd( vUsedPageList.end() );
107 				while( aIter != aEnd )
108 				{
109 					if ( *aIter == xDrawPage )
110 						break;
111 					aIter++;
112 				}
113 				if ( aIter == aEnd )
114 					rNonUsedPageList.push_back( xDrawPage );
115 			}
116 		}
117 	}
118 	catch( Exception& )
119 	{
120 	}
121 }
122 
123 
124 void PageCollector::CollectMasterPages( const Reference< XModel >& rxModel, std::vector< PageCollector::MasterPageEntity >& rMasterPageList )
125 {
126 	typedef std::vector< MasterPageEntity > MasterPageList;
127 	typedef MasterPageList::iterator MasterPageIter;
128 
129 	try
130 	{
131 		// generating list of all master pages
132 		Reference< XMasterPagesSupplier > xMasterPagesSupplier( rxModel, UNO_QUERY_THROW );
133 		Reference< XDrawPages > xMasterPages( xMasterPagesSupplier->getMasterPages(), UNO_QUERY_THROW );
134 		for ( sal_Int32 i = 0; i < xMasterPages->getCount(); i++ )
135 		{
136 			Reference< XDrawPage > xMasterPage( xMasterPages->getByIndex( i ), UNO_QUERY_THROW );
137 			MasterPageIter aIter( rMasterPageList.begin() );
138 			MasterPageIter aEnd ( rMasterPageList.end() );
139 			while( aIter != aEnd )
140 			{
141 				if ( aIter->xMasterPage == xMasterPage )
142 					break;
143 				aIter++;
144 			}
145 			if ( aIter == aEnd )
146 			{
147 				MasterPageEntity aMasterPageEntity;
148 				aMasterPageEntity.xMasterPage = xMasterPage;
149 				aMasterPageEntity.bUsed = sal_False;
150 				rMasterPageList.push_back( aMasterPageEntity );
151 			}
152 		}
153 
154 		// mark masterpages which are referenced by drawpages
155 		Reference< XDrawPagesSupplier > xDrawPagesSupplier( rxModel, UNO_QUERY_THROW );
156 		Reference< XDrawPages > xDrawPages( xDrawPagesSupplier->getDrawPages(), UNO_QUERY_THROW );
157 		for ( sal_Int32 j = 0; j < xDrawPages->getCount(); j++ )
158 		{
159 			Reference< XMasterPageTarget > xMasterPageTarget( xDrawPages->getByIndex( j ), UNO_QUERY_THROW );
160 			Reference< XDrawPage > xMasterPage( xMasterPageTarget->getMasterPage(), UNO_QUERY_THROW );
161 			MasterPageIter aIter( rMasterPageList.begin() );
162 			MasterPageIter aEnd ( rMasterPageList.end() );
163 			while( aIter != aEnd )
164 			{
165 				if ( aIter->xMasterPage == xMasterPage )
166 				{
167 					aIter->bUsed = sal_True;
168 					break;
169 				}
170 				aIter++;
171 			}
172 			if ( aIter == aEnd )
173 				throw uno::RuntimeException();
174 		}
175 	}
176 	catch( Exception& )
177 	{
178 	}
179 }
180 
181