bump product version to 6.4.0.3
[LibreOffice.git] / sd / source / core / PageListWatcher.cxx
blob322d592f2b2d8af4e27b8dfb85dea3218a167652
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>
25 #include <sal/log.hxx>
27 void ImpPageListWatcher::ImpRecreateSortedPageListOnDemand()
29 // clear vectors
30 maPageVectorStandard.clear();
31 maPageVectorNotes.clear();
32 mpHandoutPage = nullptr;
34 // build up vectors again
35 const sal_uInt32 nPageCount(ImpGetPageCount());
37 for(sal_uInt32 a(0); a < nPageCount; a++)
39 SdPage* pCandidate = ImpGetPage(a);
40 DBG_ASSERT(pCandidate, "ImpPageListWatcher::ImpRecreateSortedPageListOnDemand: Invalid PageList in Model (!)");
42 switch(pCandidate->GetPageKind())
44 case PageKind::Standard:
46 maPageVectorStandard.push_back(pCandidate);
47 break;
49 case PageKind::Notes:
51 maPageVectorNotes.push_back(pCandidate);
52 break;
54 case PageKind::Handout:
56 DBG_ASSERT(!mpHandoutPage, "ImpPageListWatcher::ImpRecreateSortedPageListOnDemand: Two Handout pages in PageList of Model (!)");
57 mpHandoutPage = pCandidate;
58 break;
63 // set to valid
64 mbPageListValid = true;
67 ImpPageListWatcher::ImpPageListWatcher(const SdrModel& rModel)
68 : mrModel(rModel)
69 , mpHandoutPage(nullptr)
70 , mbPageListValid(false)
74 ImpPageListWatcher::~ImpPageListWatcher()
78 SdPage* ImpPageListWatcher::GetSdPage(PageKind ePgKind, sal_uInt32 nPgNum)
80 SdPage* pRetval(nullptr);
82 if(!mbPageListValid)
84 ImpRecreateSortedPageListOnDemand();
87 switch(ePgKind)
89 case PageKind::Standard:
91 if( nPgNum < static_cast<sal_uInt32>(maPageVectorStandard.size()) )
92 pRetval = maPageVectorStandard[nPgNum];
93 else
95 SAL_WARN( "sd.core",
96 "ImpPageListWatcher::GetSdPage(PageKind::Standard): page number " << nPgNum << " >= " << maPageVectorStandard.size() );
98 break;
100 case PageKind::Notes:
102 if( nPgNum < static_cast<sal_uInt32>(maPageVectorNotes.size()) )
103 pRetval = maPageVectorNotes[nPgNum];
104 else
106 SAL_WARN( "sd.core",
107 "ImpPageListWatcher::GetSdPage(PageKind::Notes): page number " << nPgNum << " >= " << maPageVectorNotes.size() );
109 break;
111 case PageKind::Handout:
113 // #11420# for models used to transfer drawing shapes via clipboard it's ok to not have a handout page
114 DBG_ASSERT(nPgNum == 0, "ImpPageListWatcher::GetSdPage: access to non existing handout page (!)");
115 if (nPgNum == 0)
116 pRetval = mpHandoutPage;
117 else
119 DBG_ASSERT(nPgNum == 0,
120 "ImpPageListWatcher::GetSdPage: access to non existing handout page (!)");
122 break;
126 return pRetval;
129 sal_uInt32 ImpPageListWatcher::GetSdPageCount(PageKind ePgKind)
131 sal_uInt32 nRetval(0);
133 if(!mbPageListValid)
135 ImpRecreateSortedPageListOnDemand();
138 switch(ePgKind)
140 case PageKind::Standard:
142 nRetval = maPageVectorStandard.size();
143 break;
145 case PageKind::Notes:
147 nRetval = maPageVectorNotes.size();
148 break;
150 case PageKind::Handout:
152 if(mpHandoutPage)
154 nRetval = 1;
157 break;
161 return nRetval;
164 sal_uInt32 ImpPageListWatcher::GetVisibleSdPageCount() const
166 sal_uInt32 nVisiblePageCount = 0;
168 // build up vectors again
169 const sal_uInt32 nPageCount(ImpGetPageCount());
171 for(sal_uInt32 a(0); a < nPageCount; a++)
173 SdPage* pCandidate = ImpGetPage(a);
174 if ((pCandidate->GetPageKind() == PageKind::Standard)&&(!pCandidate->IsExcluded())) nVisiblePageCount++;
176 return nVisiblePageCount;
179 sal_uInt32 ImpDrawPageListWatcher::ImpGetPageCount() const
181 return static_cast<sal_uInt32>(mrModel.GetPageCount());
184 SdPage* ImpDrawPageListWatcher::ImpGetPage(sal_uInt32 nIndex) const
186 return const_cast<SdPage*>(static_cast<const SdPage*>(mrModel.GetPage(static_cast<sal_uInt16>(nIndex))));
189 ImpDrawPageListWatcher::ImpDrawPageListWatcher(const SdrModel& rModel)
190 : ImpPageListWatcher(rModel)
194 ImpDrawPageListWatcher::~ImpDrawPageListWatcher()
198 sal_uInt32 ImpMasterPageListWatcher::ImpGetPageCount() const
200 return static_cast<sal_uInt32>(mrModel.GetMasterPageCount());
203 SdPage* ImpMasterPageListWatcher::ImpGetPage(sal_uInt32 nIndex) const
205 return const_cast<SdPage*>(static_cast<const SdPage*>(mrModel.GetMasterPage(static_cast<sal_uInt16>(nIndex))));
208 ImpMasterPageListWatcher::ImpMasterPageListWatcher(const SdrModel& rModel)
209 : ImpPageListWatcher(rModel)
213 ImpMasterPageListWatcher::~ImpMasterPageListWatcher()
217 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */