merge the formfield patch from ooo-build
[ooovba.git] / sd / source / core / PageListWatcher.cxx
blob8659c098edfee0e1b8f0331fb781d08dc4caf193
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: PageListWatcher.cxx,v $
10 * $Revision: 1.8 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sd.hxx"
34 #include "PageListWatcher.hxx"
36 #include "sdpage.hxx"
37 #include <tools/debug.hxx>
38 #include <svx/svdmodel.hxx>
40 //////////////////////////////////////////////////////////////////////////////
41 // #109538#
43 void ImpPageListWatcher::ImpRecreateSortedPageListOnDemand()
45 // clear vectors
46 maPageVectorStandard.clear();
47 maPageVectorNotes.clear();
48 mpHandoutPage = 0L;
50 // build up vectors again
51 const sal_uInt32 nPageCount(ImpGetPageCount());
53 for(sal_uInt32 a(0L); a < nPageCount; a++)
55 SdPage* pCandidate = ImpGetPage(a);
56 DBG_ASSERT(pCandidate, "ImpPageListWatcher::ImpRecreateSortedPageListOnDemand: Invalid PageList in Model (!)");
58 switch(pCandidate->GetPageKind())
60 case PK_STANDARD:
62 maPageVectorStandard.push_back(pCandidate);
63 break;
65 case PK_NOTES:
67 maPageVectorNotes.push_back(pCandidate);
68 break;
70 case PK_HANDOUT:
72 DBG_ASSERT(!mpHandoutPage, "ImpPageListWatcher::ImpRecreateSortedPageListOnDemand: Two Handout pages in PageList of Model (!)");
73 mpHandoutPage = pCandidate;
74 break;
79 // set to valid
80 mbPageListValid = sal_True;
83 ImpPageListWatcher::ImpPageListWatcher(const SdrModel& rModel)
84 : mrModel(rModel),
85 mpHandoutPage(0L),
86 mbPageListValid(sal_False)
90 ImpPageListWatcher::~ImpPageListWatcher()
94 SdPage* ImpPageListWatcher::GetSdPage(PageKind ePgKind, sal_uInt32 nPgNum)
96 SdPage* pRetval(0L);
98 if(!mbPageListValid)
100 ImpRecreateSortedPageListOnDemand();
103 switch(ePgKind)
105 case PK_STANDARD:
107 if( nPgNum < (sal_uInt32)maPageVectorStandard.size() )
108 pRetval = maPageVectorStandard[nPgNum];
109 else
111 DBG_ASSERT(nPgNum <= maPageVectorStandard.size(),
112 "ImpPageListWatcher::GetSdPage(PK_STANDARD): access out of range");
113 DBG_WARNING2 (" %d > %d",
114 nPgNum, nPgNum<maPageVectorStandard.size());
116 break;
118 case PK_NOTES:
120 if( nPgNum < (sal_uInt32)maPageVectorNotes.size() )
121 pRetval = maPageVectorNotes[nPgNum];
122 else
124 DBG_ASSERT(nPgNum <= maPageVectorNotes.size(),
125 "ImpPageListWatcher::GetSdPage(PK_NOTES): access out of range");
126 DBG_WARNING2(" %d > %d",
127 nPgNum, nPgNum<maPageVectorNotes.size());
129 break;
131 case PK_HANDOUT:
133 // #11420# for models used to transfer drawing shapes via clipboard its
134 // ok to not have a handout page
135 // DBG_ASSERT(mpHandoutPage, "ImpPageListWatcher::GetSdPage: access to non existing handout page (!)");
136 DBG_ASSERT(nPgNum == 0L, "ImpPageListWatcher::GetSdPage: access to non existing handout page (!)");
137 if (nPgNum == 0)
138 pRetval = mpHandoutPage;
139 else
141 DBG_ASSERT(nPgNum == 0L,
142 "ImpPageListWatcher::GetSdPage: access to non existing handout page (!)");
144 break;
148 return pRetval;
151 sal_uInt32 ImpPageListWatcher::GetSdPageCount(PageKind ePgKind)
153 sal_uInt32 nRetval(0L);
155 if(!mbPageListValid)
157 ImpRecreateSortedPageListOnDemand();
160 switch(ePgKind)
162 case PK_STANDARD:
164 nRetval = maPageVectorStandard.size();
165 break;
167 case PK_NOTES:
169 nRetval = maPageVectorNotes.size();
170 break;
172 case PK_HANDOUT:
174 if(mpHandoutPage)
176 nRetval = 1L;
179 break;
183 return nRetval;
186 //////////////////////////////////////////////////////////////////////////////
188 sal_uInt32 ImpDrawPageListWatcher::ImpGetPageCount() const
190 return (sal_uInt32)mrModel.GetPageCount();
193 SdPage* ImpDrawPageListWatcher::ImpGetPage(sal_uInt32 nIndex) const
195 return (SdPage*)mrModel.GetPage((sal_uInt16)nIndex);
198 ImpDrawPageListWatcher::ImpDrawPageListWatcher(const SdrModel& rModel)
199 : ImpPageListWatcher(rModel)
203 ImpDrawPageListWatcher::~ImpDrawPageListWatcher()
207 //////////////////////////////////////////////////////////////////////////////
209 sal_uInt32 ImpMasterPageListWatcher::ImpGetPageCount() const
211 return (sal_uInt32)mrModel.GetMasterPageCount();
214 SdPage* ImpMasterPageListWatcher::ImpGetPage(sal_uInt32 nIndex) const
216 return (SdPage*)mrModel.GetMasterPage((sal_uInt16)nIndex);
219 ImpMasterPageListWatcher::ImpMasterPageListWatcher(const SdrModel& rModel)
220 : ImpPageListWatcher(rModel)
224 ImpMasterPageListWatcher::~ImpMasterPageListWatcher()