Version 6.1.0.2, tag libreoffice-6.1.0.2
[LibreOffice.git] / sd / source / core / PageListWatcher.cxx
blob9dfd01e97e8a8cccd7a1ea8a4bdd1e299d3cd5b1
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "PageListWatcher.hxx"
22 #include <sdpage.hxx>
23 #include <tools/debug.hxx>
24 #include <svx/svdmodel.hxx>
26 void ImpPageListWatcher::ImpRecreateSortedPageListOnDemand()
28 // clear vectors
29 maPageVectorStandard.clear();
30 maPageVectorNotes.clear();
31 mpHandoutPage = nullptr;
33 // build up vectors again
34 const sal_uInt32 nPageCount(ImpGetPageCount());
36 for(sal_uInt32 a(0); a < nPageCount; a++)
38 SdPage* pCandidate = ImpGetPage(a);
39 DBG_ASSERT(pCandidate, "ImpPageListWatcher::ImpRecreateSortedPageListOnDemand: Invalid PageList in Model (!)");
41 switch(pCandidate->GetPageKind())
43 case PageKind::Standard:
45 maPageVectorStandard.push_back(pCandidate);
46 break;
48 case PageKind::Notes:
50 maPageVectorNotes.push_back(pCandidate);
51 break;
53 case PageKind::Handout:
55 DBG_ASSERT(!mpHandoutPage, "ImpPageListWatcher::ImpRecreateSortedPageListOnDemand: Two Handout pages in PageList of Model (!)");
56 mpHandoutPage = pCandidate;
57 break;
62 // set to valid
63 mbPageListValid = true;
66 ImpPageListWatcher::ImpPageListWatcher(const SdrModel& rModel)
67 : mrModel(rModel)
68 , mpHandoutPage(nullptr)
69 , mbPageListValid(false)
73 ImpPageListWatcher::~ImpPageListWatcher()
77 SdPage* ImpPageListWatcher::GetSdPage(PageKind ePgKind, sal_uInt32 nPgNum)
79 SdPage* pRetval(nullptr);
81 if(!mbPageListValid)
83 ImpRecreateSortedPageListOnDemand();
86 switch(ePgKind)
88 case PageKind::Standard:
90 if( nPgNum < static_cast<sal_uInt32>(maPageVectorStandard.size()) )
91 pRetval = maPageVectorStandard[nPgNum];
92 else
94 SAL_WARN( "sd.core",
95 "ImpPageListWatcher::GetSdPage(PageKind::Standard): page number " << nPgNum << " >= " << maPageVectorStandard.size() );
97 break;
99 case PageKind::Notes:
101 if( nPgNum < static_cast<sal_uInt32>(maPageVectorNotes.size()) )
102 pRetval = maPageVectorNotes[nPgNum];
103 else
105 SAL_WARN( "sd.core",
106 "ImpPageListWatcher::GetSdPage(PageKind::Notes): page number " << nPgNum << " >= " << maPageVectorNotes.size() );
108 break;
110 case PageKind::Handout:
112 // #11420# for models used to transfer drawing shapes via clipboard it's ok to not have a handout page
113 DBG_ASSERT(nPgNum == 0, "ImpPageListWatcher::GetSdPage: access to non existing handout page (!)");
114 if (nPgNum == 0)
115 pRetval = mpHandoutPage;
116 else
118 DBG_ASSERT(nPgNum == 0,
119 "ImpPageListWatcher::GetSdPage: access to non existing handout page (!)");
121 break;
125 return pRetval;
128 sal_uInt32 ImpPageListWatcher::GetSdPageCount(PageKind ePgKind)
130 sal_uInt32 nRetval(0);
132 if(!mbPageListValid)
134 ImpRecreateSortedPageListOnDemand();
137 switch(ePgKind)
139 case PageKind::Standard:
141 nRetval = maPageVectorStandard.size();
142 break;
144 case PageKind::Notes:
146 nRetval = maPageVectorNotes.size();
147 break;
149 case PageKind::Handout:
151 if(mpHandoutPage)
153 nRetval = 1;
156 break;
160 return nRetval;
163 sal_uInt32 ImpPageListWatcher::GetVisibleSdPageCount()
165 sal_uInt32 nVisiblePageCount = 0;
167 // build up vectors again
168 const sal_uInt32 nPageCount(ImpGetPageCount());
170 for(sal_uInt32 a(0); a < nPageCount; a++)
172 SdPage* pCandidate = ImpGetPage(a);
173 if ((pCandidate->GetPageKind() == PageKind::Standard)&&(!pCandidate->IsExcluded())) nVisiblePageCount++;
175 return nVisiblePageCount;
178 sal_uInt32 ImpDrawPageListWatcher::ImpGetPageCount() const
180 return static_cast<sal_uInt32>(mrModel.GetPageCount());
183 SdPage* ImpDrawPageListWatcher::ImpGetPage(sal_uInt32 nIndex) const
185 return const_cast<SdPage*>(static_cast<const SdPage*>(mrModel.GetPage(static_cast<sal_uInt16>(nIndex))));
188 ImpDrawPageListWatcher::ImpDrawPageListWatcher(const SdrModel& rModel)
189 : ImpPageListWatcher(rModel)
193 ImpDrawPageListWatcher::~ImpDrawPageListWatcher()
197 sal_uInt32 ImpMasterPageListWatcher::ImpGetPageCount() const
199 return static_cast<sal_uInt32>(mrModel.GetMasterPageCount());
202 SdPage* ImpMasterPageListWatcher::ImpGetPage(sal_uInt32 nIndex) const
204 return const_cast<SdPage*>(static_cast<const SdPage*>(mrModel.GetMasterPage(static_cast<sal_uInt16>(nIndex))));
207 ImpMasterPageListWatcher::ImpMasterPageListWatcher(const SdrModel& rModel)
208 : ImpPageListWatcher(rModel)
212 ImpMasterPageListWatcher::~ImpMasterPageListWatcher()
216 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */