xref: /AOO41X/main/sdext/source/minimizer/pagecollector.cxx (revision 8809db7a87f97847b57a57f4cd2b0104b2b83182)
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 ::rtl;
37 using namespace ::com::sun::star;
38 using namespace ::com::sun::star::uno;
39 using namespace ::com::sun::star::awt;
40 using namespace ::com::sun::star::drawing;
41 using namespace ::com::sun::star::frame;
42 using namespace ::com::sun::star::beans;
43 using namespace ::com::sun::star::container;
44 using namespace ::com::sun::star::presentation;
45 
46 void PageCollector::CollectCustomShowPages( const com::sun::star::uno::Reference< com::sun::star::frame::XModel >& rxModel, const rtl::OUString& rCustomShowName, std::vector< Reference< XDrawPage > >& rUsedPageList )
47 {
48     try
49     {
50         Reference< XCustomPresentationSupplier > aXCPSup( rxModel, UNO_QUERY_THROW );
51         Reference< XNameContainer > aXCont( aXCPSup->getCustomPresentations() );
52         if ( aXCont.is() )
53         {
54             // creating a list of every page that is used within our customshow
55             Sequence< OUString> aNameSeq( aXCont->getElementNames() );
56             const OUString* pUString = aNameSeq.getArray();
57             sal_Int32 i, nCount = aNameSeq.getLength();
58             for ( i = 0; i < nCount; i++ )
59             {
60                 if ( pUString[ i ] == rCustomShowName )
61                 {
62                     Reference< container::XIndexContainer > aXIC( aXCont->getByName( pUString[ i ] ), UNO_QUERY_THROW );
63                     sal_Int32 j, nSlideCount = aXIC->getCount();
64                     for ( j = 0; j < nSlideCount; j++ )
65                     {
66                         Reference< XDrawPage > xDrawPage( aXIC->getByIndex( j ), UNO_QUERY_THROW );
67                         std::vector< Reference< XDrawPage > >::iterator aIter( rUsedPageList.begin() );
68                         std::vector< Reference< XDrawPage > >::iterator aEnd( rUsedPageList.end() );
69                         while( aIter != aEnd )
70                         {
71                             if ( *aIter == xDrawPage )
72                                 break;
73                             aIter++;
74                         }
75                         if ( aIter == aEnd )
76                             rUsedPageList.push_back( xDrawPage );
77                     }
78                 }
79             }
80         }
81     }
82     catch( Exception& )
83     {
84 
85     }
86 }
87 
88 void PageCollector::CollectNonCustomShowPages( const com::sun::star::uno::Reference< com::sun::star::frame::XModel >& rxModel, const rtl::OUString& rCustomShowName, std::vector< Reference< XDrawPage > >& rNonUsedPageList )
89 {
90     try
91     {
92         std::vector< Reference< XDrawPage > > vUsedPageList;
93         PageCollector::CollectCustomShowPages( rxModel, rCustomShowName, vUsedPageList );
94         if ( vUsedPageList.size() )
95         {
96             Reference< XDrawPagesSupplier > xDrawPagesSupplier( rxModel, UNO_QUERY_THROW );
97             Reference< XDrawPages > xDrawPages( xDrawPagesSupplier->getDrawPages(), UNO_QUERY_THROW );
98             for ( sal_Int32 j = 0; j < xDrawPages->getCount(); j++ )
99             {
100                 Reference< XDrawPage > xDrawPage( xDrawPages->getByIndex( j ), UNO_QUERY_THROW );
101                 std::vector< Reference< XDrawPage > >::iterator aIter( vUsedPageList.begin() );
102                 std::vector< Reference< XDrawPage > >::iterator aEnd( vUsedPageList.end() );
103                 while( aIter != aEnd )
104                 {
105                     if ( *aIter == xDrawPage )
106                         break;
107                     aIter++;
108                 }
109                 if ( aIter == aEnd )
110                     rNonUsedPageList.push_back( xDrawPage );
111             }
112         }
113     }
114     catch( Exception& )
115     {
116     }
117 }
118 
119 
120 void PageCollector::CollectMasterPages( const Reference< XModel >& rxModel, std::vector< PageCollector::MasterPageEntity >& rMasterPageList )
121 {
122     typedef std::vector< MasterPageEntity > MasterPageList;
123     typedef MasterPageList::iterator MasterPageIter;
124 
125     try
126     {
127         // generating list of all master pages
128         Reference< XMasterPagesSupplier > xMasterPagesSupplier( rxModel, UNO_QUERY_THROW );
129         Reference< XDrawPages > xMasterPages( xMasterPagesSupplier->getMasterPages(), UNO_QUERY_THROW );
130         for ( sal_Int32 i = 0; i < xMasterPages->getCount(); i++ )
131         {
132             Reference< XDrawPage > xMasterPage( xMasterPages->getByIndex( i ), UNO_QUERY_THROW );
133             MasterPageIter aIter( rMasterPageList.begin() );
134             MasterPageIter aEnd ( rMasterPageList.end() );
135             while( aIter != aEnd )
136             {
137                 if ( aIter->xMasterPage == xMasterPage )
138                     break;
139                 aIter++;
140             }
141             if ( aIter == aEnd )
142             {
143                 MasterPageEntity aMasterPageEntity;
144                 aMasterPageEntity.xMasterPage = xMasterPage;
145                 aMasterPageEntity.bUsed = sal_False;
146                 rMasterPageList.push_back( aMasterPageEntity );
147             }
148         }
149 
150         // mark masterpages which are referenced by drawpages
151         Reference< XDrawPagesSupplier > xDrawPagesSupplier( rxModel, UNO_QUERY_THROW );
152         Reference< XDrawPages > xDrawPages( xDrawPagesSupplier->getDrawPages(), UNO_QUERY_THROW );
153         for ( sal_Int32 j = 0; j < xDrawPages->getCount(); j++ )
154         {
155             Reference< XMasterPageTarget > xMasterPageTarget( xDrawPages->getByIndex( j ), UNO_QUERY_THROW );
156             Reference< XDrawPage > xMasterPage( xMasterPageTarget->getMasterPage(), UNO_QUERY_THROW );
157             MasterPageIter aIter( rMasterPageList.begin() );
158             MasterPageIter aEnd ( rMasterPageList.end() );
159             while( aIter != aEnd )
160             {
161                 if ( aIter->xMasterPage == xMasterPage )
162                 {
163                     aIter->bUsed = sal_True;
164                     break;
165                 }
166                 aIter++;
167             }
168             if ( aIter == aEnd )
169                 throw uno::RuntimeException();
170         }
171     }
172     catch( Exception& )
173     {
174     }
175 }
176 
177