1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sdext.hxx"
26 
27 #include "pagecollector.hxx"
28 #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
29 #include <com/sun/star/presentation/XPresentationPage.hpp>
30 #include <com/sun/star/drawing/XMasterPagesSupplier.hpp>
31 #include <com/sun/star/drawing/XMasterPageTarget.hpp>
32 #include <com/sun/star/presentation/XCustomPresentationSupplier.hpp>
33 #include <com/sun/star/container/XNameContainer.hpp>
34 #include <com/sun/star/container/XIndexContainer.hpp>
35 
36 using namespace ::com::sun::star;
37 using namespace ::com::sun::star::uno;
38 using namespace ::com::sun::star::awt;
39 using namespace ::com::sun::star::drawing;
40 using namespace ::com::sun::star::frame;
41 using namespace ::com::sun::star::beans;
42 using namespace ::com::sun::star::container;
43 using namespace ::com::sun::star::presentation;
44 
45 using ::rtl::OUString;
46 
CollectCustomShowPages(const com::sun::star::uno::Reference<com::sun::star::frame::XModel> & rxModel,const rtl::OUString & rCustomShowName,std::vector<Reference<XDrawPage>> & rUsedPageList)47 void PageCollector::CollectCustomShowPages( const com::sun::star::uno::Reference< com::sun::star::frame::XModel >& rxModel, const rtl::OUString& rCustomShowName, std::vector< Reference< XDrawPage > >& rUsedPageList )
48 {
49 	try
50 	{
51 		Reference< XCustomPresentationSupplier > aXCPSup( rxModel, UNO_QUERY_THROW );
52 		Reference< XNameContainer > aXCont( aXCPSup->getCustomPresentations() );
53         if ( aXCont.is() )
54         {
55 			// creating a list of every page that is used within our customshow
56             Sequence< OUString> aNameSeq( aXCont->getElementNames() );
57             const OUString* pUString = aNameSeq.getArray();
58             sal_Int32 i, nCount = aNameSeq.getLength();
59             for ( i = 0; i < nCount; i++ )
60             {
61 				if ( pUString[ i ] == rCustomShowName )
62 				{
63 					Reference< container::XIndexContainer > aXIC( aXCont->getByName( pUString[ i ] ), UNO_QUERY_THROW );
64                     sal_Int32 j, nSlideCount = aXIC->getCount();
65                     for ( j = 0; j < nSlideCount; j++ )
66                     {
67 						Reference< XDrawPage > xDrawPage( aXIC->getByIndex( j ), UNO_QUERY_THROW );
68 						std::vector< Reference< XDrawPage > >::iterator aIter( rUsedPageList.begin() );
69 						std::vector< Reference< XDrawPage > >::iterator aEnd( rUsedPageList.end() );
70 						while( aIter != aEnd )
71 						{
72 							if ( *aIter == xDrawPage )
73 								break;
74 							aIter++;
75 						}
76 						if ( aIter == aEnd )
77 							rUsedPageList.push_back( xDrawPage );
78                     }
79                 }
80             }
81         }
82 	}
83 	catch( Exception& )
84 	{
85 
86 	}
87 }
88 
CollectNonCustomShowPages(const com::sun::star::uno::Reference<com::sun::star::frame::XModel> & rxModel,const rtl::OUString & rCustomShowName,std::vector<Reference<XDrawPage>> & rNonUsedPageList)89 void PageCollector::CollectNonCustomShowPages( const com::sun::star::uno::Reference< com::sun::star::frame::XModel >& rxModel, const rtl::OUString& rCustomShowName, std::vector< Reference< XDrawPage > >& rNonUsedPageList )
90 {
91 	try
92 	{
93 		std::vector< Reference< XDrawPage > > vUsedPageList;
94 		PageCollector::CollectCustomShowPages( rxModel, rCustomShowName, vUsedPageList );
95 		if ( vUsedPageList.size() )
96 		{
97 			Reference< XDrawPagesSupplier > xDrawPagesSupplier( rxModel, UNO_QUERY_THROW );
98 			Reference< XDrawPages > xDrawPages( xDrawPagesSupplier->getDrawPages(), UNO_QUERY_THROW );
99 			for ( sal_Int32 j = 0; j < xDrawPages->getCount(); j++ )
100 			{
101 				Reference< XDrawPage > xDrawPage( xDrawPages->getByIndex( j ), UNO_QUERY_THROW );
102 				std::vector< Reference< XDrawPage > >::iterator aIter( vUsedPageList.begin() );
103 				std::vector< Reference< XDrawPage > >::iterator aEnd( vUsedPageList.end() );
104 				while( aIter != aEnd )
105 				{
106 					if ( *aIter == xDrawPage )
107 						break;
108 					aIter++;
109 				}
110 				if ( aIter == aEnd )
111 					rNonUsedPageList.push_back( xDrawPage );
112 			}
113 		}
114 	}
115 	catch( Exception& )
116 	{
117 	}
118 }
119 
120 
CollectMasterPages(const Reference<XModel> & rxModel,std::vector<PageCollector::MasterPageEntity> & rMasterPageList)121 void PageCollector::CollectMasterPages( const Reference< XModel >& rxModel, std::vector< PageCollector::MasterPageEntity >& rMasterPageList )
122 {
123 	typedef std::vector< MasterPageEntity > MasterPageList;
124 	typedef MasterPageList::iterator MasterPageIter;
125 
126 	try
127 	{
128 		// generating list of all master pages
129 		Reference< XMasterPagesSupplier > xMasterPagesSupplier( rxModel, UNO_QUERY_THROW );
130 		Reference< XDrawPages > xMasterPages( xMasterPagesSupplier->getMasterPages(), UNO_QUERY_THROW );
131 		for ( sal_Int32 i = 0; i < xMasterPages->getCount(); i++ )
132 		{
133 			Reference< XDrawPage > xMasterPage( xMasterPages->getByIndex( i ), UNO_QUERY_THROW );
134 			MasterPageIter aIter( rMasterPageList.begin() );
135 			MasterPageIter aEnd ( rMasterPageList.end() );
136 			while( aIter != aEnd )
137 			{
138 				if ( aIter->xMasterPage == xMasterPage )
139 					break;
140 				aIter++;
141 			}
142 			if ( aIter == aEnd )
143 			{
144 				MasterPageEntity aMasterPageEntity;
145 				aMasterPageEntity.xMasterPage = xMasterPage;
146 				aMasterPageEntity.bUsed = sal_False;
147 				rMasterPageList.push_back( aMasterPageEntity );
148 			}
149 		}
150 
151 		// mark masterpages which are referenced by drawpages
152 		Reference< XDrawPagesSupplier > xDrawPagesSupplier( rxModel, UNO_QUERY_THROW );
153 		Reference< XDrawPages > xDrawPages( xDrawPagesSupplier->getDrawPages(), UNO_QUERY_THROW );
154 		for ( sal_Int32 j = 0; j < xDrawPages->getCount(); j++ )
155 		{
156 			Reference< XMasterPageTarget > xMasterPageTarget( xDrawPages->getByIndex( j ), UNO_QUERY_THROW );
157 			Reference< XDrawPage > xMasterPage( xMasterPageTarget->getMasterPage(), UNO_QUERY_THROW );
158 			MasterPageIter aIter( rMasterPageList.begin() );
159 			MasterPageIter aEnd ( rMasterPageList.end() );
160 			while( aIter != aEnd )
161 			{
162 				if ( aIter->xMasterPage == xMasterPage )
163 				{
164 					aIter->bUsed = sal_True;
165 					break;
166 				}
167 				aIter++;
168 			}
169 			if ( aIter == aEnd )
170 				throw uno::RuntimeException();
171 		}
172 	}
173 	catch( Exception& )
174 	{
175 	}
176 }
177 
178