LibreOffice Module sdext (master)  1
pagecollector.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 
21 #include "pagecollector.hxx"
22 #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
23 #include <com/sun/star/drawing/XMasterPagesSupplier.hpp>
24 #include <com/sun/star/drawing/XMasterPageTarget.hpp>
25 #include <com/sun/star/presentation/XCustomPresentationSupplier.hpp>
26 #include <com/sun/star/container/XNameContainer.hpp>
27 #include <com/sun/star/container/XIndexContainer.hpp>
28 
29 using namespace ::com::sun::star;
30 using namespace ::com::sun::star::uno;
31 using namespace ::com::sun::star::awt;
32 using namespace ::com::sun::star::drawing;
33 using namespace ::com::sun::star::frame;
34 using namespace ::com::sun::star::beans;
35 using namespace ::com::sun::star::container;
36 using namespace ::com::sun::star::presentation;
37 
38 void PageCollector::CollectCustomShowPages( const css::uno::Reference< css::frame::XModel >& rxModel, const OUString& rCustomShowName, std::vector< Reference< XDrawPage > >& rUsedPageList )
39 {
40  try
41  {
42  Reference< XCustomPresentationSupplier > aXCPSup( rxModel, UNO_QUERY_THROW );
43  Reference< XNameContainer > aXCont( aXCPSup->getCustomPresentations() );
44  if ( aXCont.is() )
45  {
46  // creating a list of every page that is used within our customshow
47  const Sequence< OUString> aNameSeq( aXCont->getElementNames() );
48  for ( OUString const & i :aNameSeq )
49  {
50  if ( i == rCustomShowName )
51  {
52  Reference< container::XIndexContainer > aXIC( aXCont->getByName( i ), UNO_QUERY_THROW );
53  sal_Int32 j, nSlideCount = aXIC->getCount();
54  for ( j = 0; j < nSlideCount; j++ )
55  {
56  Reference< XDrawPage > xDrawPage( aXIC->getByIndex( j ), UNO_QUERY_THROW );
57  auto aIter = std::find(rUsedPageList.begin(), rUsedPageList.end(), xDrawPage);
58  if ( aIter == rUsedPageList.end() )
59  rUsedPageList.push_back( xDrawPage );
60  }
61  }
62  }
63  }
64  }
65  catch( Exception& )
66  {
67 
68  }
69 }
70 
71 void PageCollector::CollectNonCustomShowPages( const css::uno::Reference< css::frame::XModel >& rxModel, const OUString& rCustomShowName, std::vector< Reference< XDrawPage > >& rNonUsedPageList )
72 {
73  try
74  {
75  std::vector< Reference< XDrawPage > > vUsedPageList;
76  PageCollector::CollectCustomShowPages( rxModel, rCustomShowName, vUsedPageList );
77  if ( !vUsedPageList.empty() )
78  {
79  Reference< XDrawPagesSupplier > xDrawPagesSupplier( rxModel, UNO_QUERY_THROW );
80  Reference< XDrawPages > xDrawPages( xDrawPagesSupplier->getDrawPages(), UNO_SET_THROW );
81  for ( sal_Int32 j = 0; j < xDrawPages->getCount(); j++ )
82  {
83  Reference< XDrawPage > xDrawPage( xDrawPages->getByIndex( j ), UNO_QUERY_THROW );
84  auto aIter = std::find(vUsedPageList.begin(), vUsedPageList.end(), xDrawPage);
85  if ( aIter == vUsedPageList.end() )
86  rNonUsedPageList.push_back( xDrawPage );
87  }
88  }
89  }
90  catch( Exception& )
91  {
92  }
93 }
94 
95 
96 void PageCollector::CollectMasterPages( const Reference< XModel >& rxModel, std::vector< PageCollector::MasterPageEntity >& rMasterPageList )
97 {
98  try
99  {
100  // generating list of all master pages
101  Reference< XMasterPagesSupplier > xMasterPagesSupplier( rxModel, UNO_QUERY_THROW );
102  Reference< XDrawPages > xMasterPages( xMasterPagesSupplier->getMasterPages(), UNO_SET_THROW );
103  for ( sal_Int32 i = 0; i < xMasterPages->getCount(); i++ )
104  {
105  Reference< XDrawPage > xMasterPage( xMasterPages->getByIndex( i ), UNO_QUERY_THROW );
106  auto aIter = std::find_if(rMasterPageList.begin(), rMasterPageList.end(),
107  [&xMasterPage](const MasterPageEntity& rEntity) { return rEntity.xMasterPage == xMasterPage; });
108  if ( aIter == rMasterPageList.end() )
109  {
110  MasterPageEntity aMasterPageEntity;
111  aMasterPageEntity.xMasterPage = xMasterPage;
112  aMasterPageEntity.bUsed = false;
113  rMasterPageList.push_back( aMasterPageEntity );
114  }
115  }
116 
117  // mark masterpages which are referenced by drawpages
118  Reference< XDrawPagesSupplier > xDrawPagesSupplier( rxModel, UNO_QUERY_THROW );
119  Reference< XDrawPages > xDrawPages( xDrawPagesSupplier->getDrawPages(), UNO_SET_THROW );
120  for ( sal_Int32 j = 0; j < xDrawPages->getCount(); j++ )
121  {
122  Reference< XMasterPageTarget > xMasterPageTarget( xDrawPages->getByIndex( j ), UNO_QUERY_THROW );
123  Reference< XDrawPage > xMasterPage( xMasterPageTarget->getMasterPage(), UNO_SET_THROW );
124  auto aIter = std::find_if(rMasterPageList.begin(), rMasterPageList.end(),
125  [&xMasterPage](const MasterPageEntity& rEntity) { return rEntity.xMasterPage == xMasterPage; });
126  if ( aIter == rMasterPageList.end() )
127  throw uno::RuntimeException();
128  aIter->bUsed = true;
129  }
130  }
131  catch( Exception& )
132  {
133  }
134 }
135 
136 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Reference< css::drawing::XDrawPage > xMasterPage
int i
static void CollectMasterPages(const css::uno::Reference< css::frame::XModel > &, std::vector< MasterPageEntity > &)
static void CollectCustomShowPages(const css::uno::Reference< css::frame::XModel > &, const OUString &rCustomShow, std::vector< css::uno::Reference< css::drawing::XDrawPage > > &)
static void CollectNonCustomShowPages(const css::uno::Reference< css::frame::XModel > &, const OUString &rCustomShow, std::vector< css::uno::Reference< css::drawing::XDrawPage > > &)