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 #include "PageListWatcher.hxx"
21
22 #include <sdpage.hxx>
23 #include <tools/debug.hxx>
24 #include <svx/svdmodel.hxx>
25 #include <sal/log.hxx>
26
ImpRecreateSortedPageListOnDemand()27 void ImpPageListWatcher::ImpRecreateSortedPageListOnDemand()
28 {
29 // clear vectors
30 maPageVectorStandard.clear();
31 maPageVectorNotes.clear();
32 mpHandoutPage = nullptr;
33
34 // build up vectors again
35 const sal_uInt32 nPageCount(ImpGetPageCount());
36
37 for(sal_uInt32 a(0); a < nPageCount; a++)
38 {
39 SdPage* pCandidate = ImpGetPage(a);
40 DBG_ASSERT(pCandidate, "ImpPageListWatcher::ImpRecreateSortedPageListOnDemand: Invalid PageList in Model (!)");
41
42 switch(pCandidate->GetPageKind())
43 {
44 case PageKind::Standard:
45 {
46 maPageVectorStandard.push_back(pCandidate);
47 break;
48 }
49 case PageKind::Notes:
50 {
51 maPageVectorNotes.push_back(pCandidate);
52 break;
53 }
54 case PageKind::Handout:
55 {
56 DBG_ASSERT(!mpHandoutPage, "ImpPageListWatcher::ImpRecreateSortedPageListOnDemand: Two Handout pages in PageList of Model (!)");
57 mpHandoutPage = pCandidate;
58 break;
59 }
60 }
61 }
62
63 // set to valid
64 mbPageListValid = true;
65 }
66
ImpPageListWatcher(const SdrModel & rModel)67 ImpPageListWatcher::ImpPageListWatcher(const SdrModel& rModel)
68 : mrModel(rModel)
69 , mpHandoutPage(nullptr)
70 , mbPageListValid(false)
71 {
72 }
73
~ImpPageListWatcher()74 ImpPageListWatcher::~ImpPageListWatcher()
75 {
76 }
77
GetSdPage(PageKind ePgKind,sal_uInt32 nPgNum)78 SdPage* ImpPageListWatcher::GetSdPage(PageKind ePgKind, sal_uInt32 nPgNum)
79 {
80 SdPage* pRetval(nullptr);
81
82 if(!mbPageListValid)
83 {
84 ImpRecreateSortedPageListOnDemand();
85 }
86
87 switch(ePgKind)
88 {
89 case PageKind::Standard:
90 {
91 if( nPgNum < static_cast<sal_uInt32>(maPageVectorStandard.size()) )
92 pRetval = maPageVectorStandard[nPgNum];
93 else
94 {
95 SAL_WARN( "sd.core",
96 "ImpPageListWatcher::GetSdPage(PageKind::Standard): page number " << nPgNum << " >= " << maPageVectorStandard.size() );
97 }
98 break;
99 }
100 case PageKind::Notes:
101 {
102 if( nPgNum < static_cast<sal_uInt32>(maPageVectorNotes.size()) )
103 pRetval = maPageVectorNotes[nPgNum];
104 else
105 {
106 SAL_WARN( "sd.core",
107 "ImpPageListWatcher::GetSdPage(PageKind::Notes): page number " << nPgNum << " >= " << maPageVectorNotes.size() );
108 }
109 break;
110 }
111 case PageKind::Handout:
112 {
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
118 {
119 DBG_ASSERT(nPgNum == 0,
120 "ImpPageListWatcher::GetSdPage: access to non existing handout page (!)");
121 }
122 break;
123 }
124 }
125
126 return pRetval;
127 }
128
GetSdPageCount(PageKind ePgKind)129 sal_uInt32 ImpPageListWatcher::GetSdPageCount(PageKind ePgKind)
130 {
131 sal_uInt32 nRetval(0);
132
133 if(!mbPageListValid)
134 {
135 ImpRecreateSortedPageListOnDemand();
136 }
137
138 switch(ePgKind)
139 {
140 case PageKind::Standard:
141 {
142 nRetval = maPageVectorStandard.size();
143 break;
144 }
145 case PageKind::Notes:
146 {
147 nRetval = maPageVectorNotes.size();
148 break;
149 }
150 case PageKind::Handout:
151 {
152 if(mpHandoutPage)
153 {
154 nRetval = 1;
155 }
156
157 break;
158 }
159 }
160
161 return nRetval;
162 }
163
GetVisibleSdPageCount() const164 sal_uInt32 ImpPageListWatcher::GetVisibleSdPageCount() const
165 {
166 sal_uInt32 nVisiblePageCount = 0;
167
168 // build up vectors again
169 const sal_uInt32 nPageCount(ImpGetPageCount());
170
171 for(sal_uInt32 a(0); a < nPageCount; a++)
172 {
173 SdPage* pCandidate = ImpGetPage(a);
174 if ((pCandidate->GetPageKind() == PageKind::Standard)&&(!pCandidate->IsExcluded())) nVisiblePageCount++;
175 }
176 return nVisiblePageCount;
177 }
178
ImpGetPageCount() const179 sal_uInt32 ImpDrawPageListWatcher::ImpGetPageCount() const
180 {
181 return static_cast<sal_uInt32>(mrModel.GetPageCount());
182 }
183
ImpGetPage(sal_uInt32 nIndex) const184 SdPage* ImpDrawPageListWatcher::ImpGetPage(sal_uInt32 nIndex) const
185 {
186 return const_cast<SdPage*>(static_cast<const SdPage*>(mrModel.GetPage(static_cast<sal_uInt16>(nIndex))));
187 }
188
ImpDrawPageListWatcher(const SdrModel & rModel)189 ImpDrawPageListWatcher::ImpDrawPageListWatcher(const SdrModel& rModel)
190 : ImpPageListWatcher(rModel)
191 {
192 }
193
~ImpDrawPageListWatcher()194 ImpDrawPageListWatcher::~ImpDrawPageListWatcher()
195 {
196 }
197
ImpGetPageCount() const198 sal_uInt32 ImpMasterPageListWatcher::ImpGetPageCount() const
199 {
200 return static_cast<sal_uInt32>(mrModel.GetMasterPageCount());
201 }
202
ImpGetPage(sal_uInt32 nIndex) const203 SdPage* ImpMasterPageListWatcher::ImpGetPage(sal_uInt32 nIndex) const
204 {
205 return const_cast<SdPage*>(static_cast<const SdPage*>(mrModel.GetMasterPage(static_cast<sal_uInt16>(nIndex))));
206 }
207
ImpMasterPageListWatcher(const SdrModel & rModel)208 ImpMasterPageListWatcher::ImpMasterPageListWatcher(const SdrModel& rModel)
209 : ImpPageListWatcher(rModel)
210 {
211 }
212
~ImpMasterPageListWatcher()213 ImpMasterPageListWatcher::~ImpMasterPageListWatcher()
214 {
215 }
216
217 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
218