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