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