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 122 : void ImpPageListWatcher::ImpRecreateSortedPageListOnDemand()
30 : {
31 : // clear vectors
32 122 : maPageVectorStandard.clear();
33 122 : maPageVectorNotes.clear();
34 122 : mpHandoutPage = 0L;
35 :
36 : // build up vectors again
37 122 : const sal_uInt32 nPageCount(ImpGetPageCount());
38 :
39 516 : for(sal_uInt32 a(0L); a < nPageCount; a++)
40 : {
41 394 : SdPage* pCandidate = ImpGetPage(a);
42 : DBG_ASSERT(pCandidate, "ImpPageListWatcher::ImpRecreateSortedPageListOnDemand: Invalid PageList in Model (!)");
43 :
44 394 : switch(pCandidate->GetPageKind())
45 : {
46 : case PK_STANDARD:
47 : {
48 168 : maPageVectorStandard.push_back(pCandidate);
49 168 : break;
50 : }
51 : case PK_NOTES:
52 : {
53 168 : maPageVectorNotes.push_back(pCandidate);
54 168 : break;
55 : }
56 : case PK_HANDOUT:
57 : {
58 : DBG_ASSERT(!mpHandoutPage, "ImpPageListWatcher::ImpRecreateSortedPageListOnDemand: Two Handout pages in PageList of Model (!)");
59 58 : mpHandoutPage = pCandidate;
60 58 : break;
61 : }
62 : }
63 : }
64 :
65 : // set to valid
66 122 : mbPageListValid = sal_True;
67 122 : }
68 :
69 80 : ImpPageListWatcher::ImpPageListWatcher(const SdrModel& rModel)
70 : : mrModel(rModel),
71 : mpHandoutPage(0L),
72 80 : mbPageListValid(sal_False)
73 : {
74 80 : }
75 :
76 72 : ImpPageListWatcher::~ImpPageListWatcher()
77 : {
78 72 : }
79 :
80 2742 : SdPage* ImpPageListWatcher::GetSdPage(PageKind ePgKind, sal_uInt32 nPgNum)
81 : {
82 2742 : SdPage* pRetval(0L);
83 :
84 2742 : if(!mbPageListValid)
85 : {
86 36 : ImpRecreateSortedPageListOnDemand();
87 : }
88 :
89 2742 : switch(ePgKind)
90 : {
91 : case PK_STANDARD:
92 : {
93 2608 : if( nPgNum < (sal_uInt32)maPageVectorStandard.size() )
94 660 : 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 2608 : break;
103 : }
104 : case PK_NOTES:
105 : {
106 86 : if( nPgNum < (sal_uInt32)maPageVectorNotes.size() )
107 86 : 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 86 : 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 48 : if (nPgNum == 0)
122 48 : pRetval = mpHandoutPage;
123 : else
124 : {
125 : DBG_ASSERT(nPgNum == 0L,
126 : "ImpPageListWatcher::GetSdPage: access to non existing handout page (!)");
127 : }
128 48 : break;
129 : }
130 : }
131 :
132 2742 : return pRetval;
133 : }
134 :
135 392 : sal_uInt32 ImpPageListWatcher::GetSdPageCount(PageKind ePgKind)
136 : {
137 392 : sal_uInt32 nRetval(0L);
138 :
139 392 : if(!mbPageListValid)
140 : {
141 86 : ImpRecreateSortedPageListOnDemand();
142 : }
143 :
144 392 : switch(ePgKind)
145 : {
146 : case PK_STANDARD:
147 : {
148 364 : nRetval = maPageVectorStandard.size();
149 364 : break;
150 : }
151 : case PK_NOTES:
152 : {
153 28 : nRetval = maPageVectorNotes.size();
154 28 : 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 392 : return nRetval;
168 : }
169 :
170 : //////////////////////////////////////////////////////////////////////////////
171 :
172 60 : sal_uInt32 ImpDrawPageListWatcher::ImpGetPageCount() const
173 : {
174 60 : return (sal_uInt32)mrModel.GetPageCount();
175 : }
176 :
177 328 : SdPage* ImpDrawPageListWatcher::ImpGetPage(sal_uInt32 nIndex) const
178 : {
179 328 : return (SdPage*)mrModel.GetPage((sal_uInt16)nIndex);
180 : }
181 :
182 40 : ImpDrawPageListWatcher::ImpDrawPageListWatcher(const SdrModel& rModel)
183 40 : : ImpPageListWatcher(rModel)
184 : {
185 40 : }
186 :
187 72 : ImpDrawPageListWatcher::~ImpDrawPageListWatcher()
188 : {
189 72 : }
190 :
191 : //////////////////////////////////////////////////////////////////////////////
192 :
193 62 : sal_uInt32 ImpMasterPageListWatcher::ImpGetPageCount() const
194 : {
195 62 : return (sal_uInt32)mrModel.GetMasterPageCount();
196 : }
197 :
198 66 : SdPage* ImpMasterPageListWatcher::ImpGetPage(sal_uInt32 nIndex) const
199 : {
200 66 : return (SdPage*)mrModel.GetMasterPage((sal_uInt16)nIndex);
201 : }
202 :
203 40 : ImpMasterPageListWatcher::ImpMasterPageListWatcher(const SdrModel& rModel)
204 40 : : ImpPageListWatcher(rModel)
205 : {
206 40 : }
207 :
208 72 : ImpMasterPageListWatcher::~ImpMasterPageListWatcher()
209 : {
210 72 : }
211 :
212 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|