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