xref: /AOO41X/main/sd/source/core/PageListWatcher.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sd.hxx"
30 
31 #include "PageListWatcher.hxx"
32 
33 #include "sdpage.hxx"
34 #include <tools/debug.hxx>
35 #include <svx/svdmodel.hxx>
36 
37 //////////////////////////////////////////////////////////////////////////////
38 // #109538#
39 
40 void ImpPageListWatcher::ImpRecreateSortedPageListOnDemand()
41 {
42     // clear vectors
43     maPageVectorStandard.clear();
44     maPageVectorNotes.clear();
45     mpHandoutPage = 0L;
46 
47     // build up vectors again
48     const sal_uInt32 nPageCount(ImpGetPageCount());
49 
50     for(sal_uInt32 a(0L); a < nPageCount; a++)
51     {
52         SdPage* pCandidate = ImpGetPage(a);
53         DBG_ASSERT(pCandidate, "ImpPageListWatcher::ImpRecreateSortedPageListOnDemand: Invalid PageList in Model (!)");
54 
55         switch(pCandidate->GetPageKind())
56         {
57             case PK_STANDARD:
58             {
59                 maPageVectorStandard.push_back(pCandidate);
60                 break;
61             }
62             case PK_NOTES:
63             {
64                 maPageVectorNotes.push_back(pCandidate);
65                 break;
66             }
67             case PK_HANDOUT:
68             {
69                 DBG_ASSERT(!mpHandoutPage, "ImpPageListWatcher::ImpRecreateSortedPageListOnDemand: Two Handout pages in PageList of Model (!)");
70                 mpHandoutPage = pCandidate;
71                 break;
72             }
73         }
74     }
75 
76     // set to valid
77     mbPageListValid = sal_True;
78 }
79 
80 ImpPageListWatcher::ImpPageListWatcher(const SdrModel& rModel)
81 :   mrModel(rModel),
82     mpHandoutPage(0L),
83     mbPageListValid(sal_False)
84 {
85 }
86 
87 ImpPageListWatcher::~ImpPageListWatcher()
88 {
89 }
90 
91 SdPage* ImpPageListWatcher::GetSdPage(PageKind ePgKind, sal_uInt32 nPgNum)
92 {
93     SdPage* pRetval(0L);
94 
95     if(!mbPageListValid)
96     {
97         ImpRecreateSortedPageListOnDemand();
98     }
99 
100     switch(ePgKind)
101     {
102         case PK_STANDARD:
103         {
104             if( nPgNum < (sal_uInt32)maPageVectorStandard.size() )
105                 pRetval = maPageVectorStandard[nPgNum];
106             else
107             {
108                 DBG_ASSERT(nPgNum <= maPageVectorStandard.size(),
109                     "ImpPageListWatcher::GetSdPage(PK_STANDARD): access out of range");
110                 DBG_WARNING2 ("    %d  > %d",
111                     nPgNum, nPgNum<maPageVectorStandard.size());
112             }
113             break;
114         }
115         case PK_NOTES:
116         {
117             if( nPgNum < (sal_uInt32)maPageVectorNotes.size() )
118                 pRetval = maPageVectorNotes[nPgNum];
119             else
120             {
121                 DBG_ASSERT(nPgNum <= maPageVectorNotes.size(),
122                     "ImpPageListWatcher::GetSdPage(PK_NOTES): access out of range");
123                 DBG_WARNING2("    %d > %d",
124                     nPgNum, nPgNum<maPageVectorNotes.size());
125             }
126             break;
127         }
128 		case PK_HANDOUT:
129 		{
130 //			#11420# for models used to transfer drawing shapes via clipboard its
131 //			ok to not have a handout page
132 //			DBG_ASSERT(mpHandoutPage, "ImpPageListWatcher::GetSdPage: access to non existing handout page (!)");
133 			DBG_ASSERT(nPgNum == 0L, "ImpPageListWatcher::GetSdPage: access to non existing handout page (!)");
134             if (nPgNum == 0)
135                 pRetval = mpHandoutPage;
136             else
137             {
138                 DBG_ASSERT(nPgNum == 0L,
139                     "ImpPageListWatcher::GetSdPage: access to non existing handout page (!)");
140             }
141             break;
142         }
143     }
144 
145     return pRetval;
146 }
147 
148 sal_uInt32 ImpPageListWatcher::GetSdPageCount(PageKind ePgKind)
149 {
150     sal_uInt32 nRetval(0L);
151 
152     if(!mbPageListValid)
153     {
154         ImpRecreateSortedPageListOnDemand();
155     }
156 
157     switch(ePgKind)
158     {
159         case PK_STANDARD:
160         {
161             nRetval = maPageVectorStandard.size();
162             break;
163         }
164         case PK_NOTES:
165         {
166             nRetval = maPageVectorNotes.size();
167             break;
168         }
169         case PK_HANDOUT:
170         {
171             if(mpHandoutPage)
172             {
173                 nRetval = 1L;
174             }
175 
176             break;
177         }
178     }
179 
180     return nRetval;
181 }
182 
183 //////////////////////////////////////////////////////////////////////////////
184 
185 sal_uInt32 ImpDrawPageListWatcher::ImpGetPageCount() const
186 {
187     return (sal_uInt32)mrModel.GetPageCount();
188 }
189 
190 SdPage* ImpDrawPageListWatcher::ImpGetPage(sal_uInt32 nIndex) const
191 {
192     return (SdPage*)mrModel.GetPage((sal_uInt16)nIndex);
193 }
194 
195 ImpDrawPageListWatcher::ImpDrawPageListWatcher(const SdrModel& rModel)
196 :   ImpPageListWatcher(rModel)
197 {
198 }
199 
200 ImpDrawPageListWatcher::~ImpDrawPageListWatcher()
201 {
202 }
203 
204 //////////////////////////////////////////////////////////////////////////////
205 
206 sal_uInt32 ImpMasterPageListWatcher::ImpGetPageCount() const
207 {
208     return (sal_uInt32)mrModel.GetMasterPageCount();
209 }
210 
211 SdPage* ImpMasterPageListWatcher::ImpGetPage(sal_uInt32 nIndex) const
212 {
213     return (SdPage*)mrModel.GetMasterPage((sal_uInt16)nIndex);
214 }
215 
216 ImpMasterPageListWatcher::ImpMasterPageListWatcher(const SdrModel& rModel)
217 :   ImpPageListWatcher(rModel)
218 {
219 }
220 
221 ImpMasterPageListWatcher::~ImpMasterPageListWatcher()
222 {
223 }
224