Line data Source code
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 "PageListWatcher.hxx"
22 :
23 : #include "sdpage.hxx"
24 : #include <tools/debug.hxx>
25 : #include <svx/svdmodel.hxx>
26 :
27 : //////////////////////////////////////////////////////////////////////////////
28 :
29 401 : void ImpPageListWatcher::ImpRecreateSortedPageListOnDemand()
30 : {
31 : // clear vectors
32 401 : maPageVectorStandard.clear();
33 401 : maPageVectorNotes.clear();
34 401 : mpHandoutPage = 0L;
35 401 : mnVisiblePageCount = -1;
36 :
37 : // build up vectors again
38 401 : const sal_uInt32 nPageCount(ImpGetPageCount());
39 :
40 1255 : for(sal_uInt32 a(0L); a < nPageCount; a++)
41 : {
42 854 : SdPage* pCandidate = ImpGetPage(a);
43 : DBG_ASSERT(pCandidate, "ImpPageListWatcher::ImpRecreateSortedPageListOnDemand: Invalid PageList in Model (!)");
44 :
45 854 : switch(pCandidate->GetPageKind())
46 : {
47 : case PK_STANDARD:
48 : {
49 325 : maPageVectorStandard.push_back(pCandidate);
50 325 : if (!pCandidate->IsExcluded()) mnVisiblePageCount++;
51 325 : break;
52 : }
53 : case PK_NOTES:
54 : {
55 302 : maPageVectorNotes.push_back(pCandidate);
56 302 : break;
57 : }
58 : case PK_HANDOUT:
59 : {
60 : DBG_ASSERT(!mpHandoutPage, "ImpPageListWatcher::ImpRecreateSortedPageListOnDemand: Two Handout pages in PageList of Model (!)");
61 227 : mpHandoutPage = pCandidate;
62 227 : break;
63 : }
64 : }
65 : }
66 :
67 : // set to valid
68 401 : mbPageListValid = sal_True;
69 401 : }
70 :
71 182 : ImpPageListWatcher::ImpPageListWatcher(const SdrModel& rModel)
72 : : mrModel(rModel),
73 : mpHandoutPage(0L),
74 182 : mbPageListValid(sal_False)
75 : {
76 182 : }
77 :
78 176 : ImpPageListWatcher::~ImpPageListWatcher()
79 : {
80 176 : }
81 :
82 3692 : SdPage* ImpPageListWatcher::GetSdPage(PageKind ePgKind, sal_uInt32 nPgNum)
83 : {
84 3692 : SdPage* pRetval(0L);
85 :
86 3692 : if(!mbPageListValid)
87 : {
88 148 : ImpRecreateSortedPageListOnDemand();
89 : }
90 :
91 3692 : switch(ePgKind)
92 : {
93 : case PK_STANDARD:
94 : {
95 3346 : if( nPgNum < (sal_uInt32)maPageVectorStandard.size() )
96 2590 : pRetval = maPageVectorStandard[nPgNum];
97 : else
98 : {
99 : DBG_ASSERT(nPgNum <= maPageVectorStandard.size(),
100 : "ImpPageListWatcher::GetSdPage(PK_STANDARD): access out of range");
101 : DBG_WARNING2 (" %d > %d",
102 : nPgNum, nPgNum<maPageVectorStandard.size());
103 : }
104 3346 : break;
105 : }
106 : case PK_NOTES:
107 : {
108 202 : if( nPgNum < (sal_uInt32)maPageVectorNotes.size() )
109 202 : pRetval = maPageVectorNotes[nPgNum];
110 : else
111 : {
112 : DBG_ASSERT(nPgNum <= maPageVectorNotes.size(),
113 : "ImpPageListWatcher::GetSdPage(PK_NOTES): access out of range");
114 : DBG_WARNING2(" %d > %d",
115 : nPgNum, nPgNum<maPageVectorNotes.size());
116 : }
117 202 : break;
118 : }
119 : case PK_HANDOUT:
120 : {
121 : // #11420# for models used to transfer drawing shapes via clipboard its ok to not have a handout page
122 : DBG_ASSERT(nPgNum == 0L, "ImpPageListWatcher::GetSdPage: access to non existing handout page (!)");
123 144 : if (nPgNum == 0)
124 144 : pRetval = mpHandoutPage;
125 : else
126 : {
127 : DBG_ASSERT(nPgNum == 0L,
128 : "ImpPageListWatcher::GetSdPage: access to non existing handout page (!)");
129 : }
130 144 : break;
131 : }
132 : }
133 :
134 3692 : return pRetval;
135 : }
136 :
137 3745 : sal_uInt32 ImpPageListWatcher::GetSdPageCount(PageKind ePgKind)
138 : {
139 3745 : sal_uInt32 nRetval(0L);
140 :
141 3745 : if(!mbPageListValid)
142 : {
143 253 : ImpRecreateSortedPageListOnDemand();
144 : }
145 :
146 3745 : switch(ePgKind)
147 : {
148 : case PK_STANDARD:
149 : {
150 3542 : nRetval = maPageVectorStandard.size();
151 3542 : break;
152 : }
153 : case PK_NOTES:
154 : {
155 199 : nRetval = maPageVectorNotes.size();
156 199 : break;
157 : }
158 : case PK_HANDOUT:
159 : {
160 4 : if(mpHandoutPage)
161 : {
162 4 : nRetval = 1L;
163 : }
164 :
165 4 : break;
166 : }
167 : }
168 :
169 3745 : return nRetval;
170 : }
171 :
172 :
173 141 : sal_uInt32 ImpPageListWatcher::GetVisibleSdPageCount()
174 : {
175 141 : sal_uInt32 nVisiblePageCount = 0;
176 :
177 : // build up vectors again
178 141 : const sal_uInt32 nPageCount(ImpGetPageCount());
179 :
180 590 : for(sal_uInt32 a(0L); a < nPageCount; a++)
181 : {
182 449 : SdPage* pCandidate = ImpGetPage(a);
183 449 : if ((pCandidate->GetPageKind() == PK_STANDARD)&&(!pCandidate->IsExcluded())) nVisiblePageCount++;
184 : }
185 141 : return nVisiblePageCount;
186 : }
187 :
188 : //////////////////////////////////////////////////////////////////////////////
189 :
190 336 : sal_uInt32 ImpDrawPageListWatcher::ImpGetPageCount() const
191 : {
192 336 : return (sal_uInt32)mrModel.GetPageCount();
193 : }
194 :
195 954 : SdPage* ImpDrawPageListWatcher::ImpGetPage(sal_uInt32 nIndex) const
196 : {
197 954 : return (SdPage*)mrModel.GetPage((sal_uInt16)nIndex);
198 : }
199 :
200 91 : ImpDrawPageListWatcher::ImpDrawPageListWatcher(const SdrModel& rModel)
201 91 : : ImpPageListWatcher(rModel)
202 : {
203 91 : }
204 :
205 176 : ImpDrawPageListWatcher::~ImpDrawPageListWatcher()
206 : {
207 176 : }
208 :
209 : //////////////////////////////////////////////////////////////////////////////
210 :
211 206 : sal_uInt32 ImpMasterPageListWatcher::ImpGetPageCount() const
212 : {
213 206 : return (sal_uInt32)mrModel.GetMasterPageCount();
214 : }
215 :
216 349 : SdPage* ImpMasterPageListWatcher::ImpGetPage(sal_uInt32 nIndex) const
217 : {
218 349 : return (SdPage*)mrModel.GetMasterPage((sal_uInt16)nIndex);
219 : }
220 :
221 91 : ImpMasterPageListWatcher::ImpMasterPageListWatcher(const SdrModel& rModel)
222 91 : : ImpPageListWatcher(rModel)
223 : {
224 91 : }
225 :
226 176 : ImpMasterPageListWatcher::~ImpMasterPageListWatcher()
227 : {
228 209 : }
229 :
230 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|