1*5b190011SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*5b190011SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*5b190011SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*5b190011SAndrew Rist * distributed with this work for additional information
6*5b190011SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*5b190011SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*5b190011SAndrew Rist * "License"); you may not use this file except in compliance
9*5b190011SAndrew Rist * with the License. You may obtain a copy of the License at
10cdf0e10cSrcweir *
11*5b190011SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
13*5b190011SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*5b190011SAndrew Rist * software distributed under the License is distributed on an
15*5b190011SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*5b190011SAndrew Rist * KIND, either express or implied. See the License for the
17*5b190011SAndrew Rist * specific language governing permissions and limitations
18*5b190011SAndrew Rist * under the License.
19cdf0e10cSrcweir *
20*5b190011SAndrew Rist *************************************************************/
21*5b190011SAndrew Rist
22*5b190011SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sd.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include "PageListWatcher.hxx"
28cdf0e10cSrcweir
29cdf0e10cSrcweir #include "sdpage.hxx"
30cdf0e10cSrcweir #include <tools/debug.hxx>
31cdf0e10cSrcweir #include <svx/svdmodel.hxx>
32cdf0e10cSrcweir
33cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
34cdf0e10cSrcweir // #109538#
35cdf0e10cSrcweir
ImpRecreateSortedPageListOnDemand()36cdf0e10cSrcweir void ImpPageListWatcher::ImpRecreateSortedPageListOnDemand()
37cdf0e10cSrcweir {
38cdf0e10cSrcweir // clear vectors
39cdf0e10cSrcweir maPageVectorStandard.clear();
40cdf0e10cSrcweir maPageVectorNotes.clear();
41cdf0e10cSrcweir mpHandoutPage = 0L;
42cdf0e10cSrcweir
43cdf0e10cSrcweir // build up vectors again
44cdf0e10cSrcweir const sal_uInt32 nPageCount(ImpGetPageCount());
45cdf0e10cSrcweir
46cdf0e10cSrcweir for(sal_uInt32 a(0L); a < nPageCount; a++)
47cdf0e10cSrcweir {
48cdf0e10cSrcweir SdPage* pCandidate = ImpGetPage(a);
49cdf0e10cSrcweir DBG_ASSERT(pCandidate, "ImpPageListWatcher::ImpRecreateSortedPageListOnDemand: Invalid PageList in Model (!)");
50cdf0e10cSrcweir
51cdf0e10cSrcweir switch(pCandidate->GetPageKind())
52cdf0e10cSrcweir {
53cdf0e10cSrcweir case PK_STANDARD:
54cdf0e10cSrcweir {
55cdf0e10cSrcweir maPageVectorStandard.push_back(pCandidate);
56cdf0e10cSrcweir break;
57cdf0e10cSrcweir }
58cdf0e10cSrcweir case PK_NOTES:
59cdf0e10cSrcweir {
60cdf0e10cSrcweir maPageVectorNotes.push_back(pCandidate);
61cdf0e10cSrcweir break;
62cdf0e10cSrcweir }
63cdf0e10cSrcweir case PK_HANDOUT:
64cdf0e10cSrcweir {
65cdf0e10cSrcweir DBG_ASSERT(!mpHandoutPage, "ImpPageListWatcher::ImpRecreateSortedPageListOnDemand: Two Handout pages in PageList of Model (!)");
66cdf0e10cSrcweir mpHandoutPage = pCandidate;
67cdf0e10cSrcweir break;
68cdf0e10cSrcweir }
69cdf0e10cSrcweir }
70cdf0e10cSrcweir }
71cdf0e10cSrcweir
72cdf0e10cSrcweir // set to valid
73cdf0e10cSrcweir mbPageListValid = sal_True;
74cdf0e10cSrcweir }
75cdf0e10cSrcweir
ImpPageListWatcher(const SdrModel & rModel)76cdf0e10cSrcweir ImpPageListWatcher::ImpPageListWatcher(const SdrModel& rModel)
77cdf0e10cSrcweir : mrModel(rModel),
78cdf0e10cSrcweir mpHandoutPage(0L),
79cdf0e10cSrcweir mbPageListValid(sal_False)
80cdf0e10cSrcweir {
81cdf0e10cSrcweir }
82cdf0e10cSrcweir
~ImpPageListWatcher()83cdf0e10cSrcweir ImpPageListWatcher::~ImpPageListWatcher()
84cdf0e10cSrcweir {
85cdf0e10cSrcweir }
86cdf0e10cSrcweir
GetSdPage(PageKind ePgKind,sal_uInt32 nPgNum)87cdf0e10cSrcweir SdPage* ImpPageListWatcher::GetSdPage(PageKind ePgKind, sal_uInt32 nPgNum)
88cdf0e10cSrcweir {
89cdf0e10cSrcweir SdPage* pRetval(0L);
90cdf0e10cSrcweir
91cdf0e10cSrcweir if(!mbPageListValid)
92cdf0e10cSrcweir {
93cdf0e10cSrcweir ImpRecreateSortedPageListOnDemand();
94cdf0e10cSrcweir }
95cdf0e10cSrcweir
96cdf0e10cSrcweir switch(ePgKind)
97cdf0e10cSrcweir {
98cdf0e10cSrcweir case PK_STANDARD:
99cdf0e10cSrcweir {
100cdf0e10cSrcweir if( nPgNum < (sal_uInt32)maPageVectorStandard.size() )
101cdf0e10cSrcweir pRetval = maPageVectorStandard[nPgNum];
102cdf0e10cSrcweir else
103cdf0e10cSrcweir {
104cdf0e10cSrcweir DBG_ASSERT(nPgNum <= maPageVectorStandard.size(),
105cdf0e10cSrcweir "ImpPageListWatcher::GetSdPage(PK_STANDARD): access out of range");
106cdf0e10cSrcweir DBG_WARNING2 (" %d > %d",
107cdf0e10cSrcweir nPgNum, nPgNum<maPageVectorStandard.size());
108cdf0e10cSrcweir }
109cdf0e10cSrcweir break;
110cdf0e10cSrcweir }
111cdf0e10cSrcweir case PK_NOTES:
112cdf0e10cSrcweir {
113cdf0e10cSrcweir if( nPgNum < (sal_uInt32)maPageVectorNotes.size() )
114cdf0e10cSrcweir pRetval = maPageVectorNotes[nPgNum];
115cdf0e10cSrcweir else
116cdf0e10cSrcweir {
117cdf0e10cSrcweir DBG_ASSERT(nPgNum <= maPageVectorNotes.size(),
118cdf0e10cSrcweir "ImpPageListWatcher::GetSdPage(PK_NOTES): access out of range");
119cdf0e10cSrcweir DBG_WARNING2(" %d > %d",
120cdf0e10cSrcweir nPgNum, nPgNum<maPageVectorNotes.size());
121cdf0e10cSrcweir }
122cdf0e10cSrcweir break;
123cdf0e10cSrcweir }
124cdf0e10cSrcweir case PK_HANDOUT:
125cdf0e10cSrcweir {
126cdf0e10cSrcweir // #11420# for models used to transfer drawing shapes via clipboard its
127cdf0e10cSrcweir // ok to not have a handout page
128cdf0e10cSrcweir // DBG_ASSERT(mpHandoutPage, "ImpPageListWatcher::GetSdPage: access to non existing handout page (!)");
129cdf0e10cSrcweir DBG_ASSERT(nPgNum == 0L, "ImpPageListWatcher::GetSdPage: access to non existing handout page (!)");
130cdf0e10cSrcweir if (nPgNum == 0)
131cdf0e10cSrcweir pRetval = mpHandoutPage;
132cdf0e10cSrcweir else
133cdf0e10cSrcweir {
134cdf0e10cSrcweir DBG_ASSERT(nPgNum == 0L,
135cdf0e10cSrcweir "ImpPageListWatcher::GetSdPage: access to non existing handout page (!)");
136cdf0e10cSrcweir }
137cdf0e10cSrcweir break;
138cdf0e10cSrcweir }
139cdf0e10cSrcweir }
140cdf0e10cSrcweir
141cdf0e10cSrcweir return pRetval;
142cdf0e10cSrcweir }
143cdf0e10cSrcweir
GetSdPageCount(PageKind ePgKind)144cdf0e10cSrcweir sal_uInt32 ImpPageListWatcher::GetSdPageCount(PageKind ePgKind)
145cdf0e10cSrcweir {
146cdf0e10cSrcweir sal_uInt32 nRetval(0L);
147cdf0e10cSrcweir
148cdf0e10cSrcweir if(!mbPageListValid)
149cdf0e10cSrcweir {
150cdf0e10cSrcweir ImpRecreateSortedPageListOnDemand();
151cdf0e10cSrcweir }
152cdf0e10cSrcweir
153cdf0e10cSrcweir switch(ePgKind)
154cdf0e10cSrcweir {
155cdf0e10cSrcweir case PK_STANDARD:
156cdf0e10cSrcweir {
157cdf0e10cSrcweir nRetval = maPageVectorStandard.size();
158cdf0e10cSrcweir break;
159cdf0e10cSrcweir }
160cdf0e10cSrcweir case PK_NOTES:
161cdf0e10cSrcweir {
162cdf0e10cSrcweir nRetval = maPageVectorNotes.size();
163cdf0e10cSrcweir break;
164cdf0e10cSrcweir }
165cdf0e10cSrcweir case PK_HANDOUT:
166cdf0e10cSrcweir {
167cdf0e10cSrcweir if(mpHandoutPage)
168cdf0e10cSrcweir {
169cdf0e10cSrcweir nRetval = 1L;
170cdf0e10cSrcweir }
171cdf0e10cSrcweir
172cdf0e10cSrcweir break;
173cdf0e10cSrcweir }
174cdf0e10cSrcweir }
175cdf0e10cSrcweir
176cdf0e10cSrcweir return nRetval;
177cdf0e10cSrcweir }
178cdf0e10cSrcweir
179cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
180cdf0e10cSrcweir
ImpGetPageCount() const181cdf0e10cSrcweir sal_uInt32 ImpDrawPageListWatcher::ImpGetPageCount() const
182cdf0e10cSrcweir {
183cdf0e10cSrcweir return (sal_uInt32)mrModel.GetPageCount();
184cdf0e10cSrcweir }
185cdf0e10cSrcweir
ImpGetPage(sal_uInt32 nIndex) const186cdf0e10cSrcweir SdPage* ImpDrawPageListWatcher::ImpGetPage(sal_uInt32 nIndex) const
187cdf0e10cSrcweir {
188cdf0e10cSrcweir return (SdPage*)mrModel.GetPage((sal_uInt16)nIndex);
189cdf0e10cSrcweir }
190cdf0e10cSrcweir
ImpDrawPageListWatcher(const SdrModel & rModel)191cdf0e10cSrcweir ImpDrawPageListWatcher::ImpDrawPageListWatcher(const SdrModel& rModel)
192cdf0e10cSrcweir : ImpPageListWatcher(rModel)
193cdf0e10cSrcweir {
194cdf0e10cSrcweir }
195cdf0e10cSrcweir
~ImpDrawPageListWatcher()196cdf0e10cSrcweir ImpDrawPageListWatcher::~ImpDrawPageListWatcher()
197cdf0e10cSrcweir {
198cdf0e10cSrcweir }
199cdf0e10cSrcweir
200cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
201cdf0e10cSrcweir
ImpGetPageCount() const202cdf0e10cSrcweir sal_uInt32 ImpMasterPageListWatcher::ImpGetPageCount() const
203cdf0e10cSrcweir {
204cdf0e10cSrcweir return (sal_uInt32)mrModel.GetMasterPageCount();
205cdf0e10cSrcweir }
206cdf0e10cSrcweir
ImpGetPage(sal_uInt32 nIndex) const207cdf0e10cSrcweir SdPage* ImpMasterPageListWatcher::ImpGetPage(sal_uInt32 nIndex) const
208cdf0e10cSrcweir {
209cdf0e10cSrcweir return (SdPage*)mrModel.GetMasterPage((sal_uInt16)nIndex);
210cdf0e10cSrcweir }
211cdf0e10cSrcweir
ImpMasterPageListWatcher(const SdrModel & rModel)212cdf0e10cSrcweir ImpMasterPageListWatcher::ImpMasterPageListWatcher(const SdrModel& rModel)
213cdf0e10cSrcweir : ImpPageListWatcher(rModel)
214cdf0e10cSrcweir {
215cdf0e10cSrcweir }
216cdf0e10cSrcweir
~ImpMasterPageListWatcher()217cdf0e10cSrcweir ImpMasterPageListWatcher::~ImpMasterPageListWatcher()
218cdf0e10cSrcweir {
219cdf0e10cSrcweir }
220