1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "PageListWatcher.hxx"
23 #include <tools/debug.hxx>
24 #include <svx/svdmodel.hxx>
25 #include <sal/log.hxx>
27 void ImpPageListWatcher::ImpRecreateSortedPageListOnDemand()
30 maPageVectorStandard
.clear();
31 maPageVectorNotes
.clear();
32 mpHandoutPage
= nullptr;
34 // build up vectors again
35 const sal_uInt32
nPageCount(ImpGetPageCount());
37 for(sal_uInt32
a(0); a
< nPageCount
; a
++)
39 SdPage
* pCandidate
= ImpGetPage(a
);
40 DBG_ASSERT(pCandidate
, "ImpPageListWatcher::ImpRecreateSortedPageListOnDemand: Invalid PageList in Model (!)");
42 switch(pCandidate
->GetPageKind())
44 case PageKind::Standard
:
46 maPageVectorStandard
.push_back(pCandidate
);
51 maPageVectorNotes
.push_back(pCandidate
);
54 case PageKind::Handout
:
56 DBG_ASSERT(!mpHandoutPage
, "ImpPageListWatcher::ImpRecreateSortedPageListOnDemand: Two Handout pages in PageList of Model (!)");
57 mpHandoutPage
= pCandidate
;
64 mbPageListValid
= true;
67 ImpPageListWatcher::ImpPageListWatcher(const SdrModel
& rModel
)
69 , mpHandoutPage(nullptr)
70 , mbPageListValid(false)
74 ImpPageListWatcher::~ImpPageListWatcher()
78 SdPage
* ImpPageListWatcher::GetSdPage(PageKind ePgKind
, sal_uInt32 nPgNum
)
80 SdPage
* pRetval(nullptr);
84 ImpRecreateSortedPageListOnDemand();
89 case PageKind::Standard
:
91 if( nPgNum
< static_cast<sal_uInt32
>(maPageVectorStandard
.size()) )
92 pRetval
= maPageVectorStandard
[nPgNum
];
96 "ImpPageListWatcher::GetSdPage(PageKind::Standard): page number " << nPgNum
<< " >= " << maPageVectorStandard
.size() );
100 case PageKind::Notes
:
102 if( nPgNum
< static_cast<sal_uInt32
>(maPageVectorNotes
.size()) )
103 pRetval
= maPageVectorNotes
[nPgNum
];
107 "ImpPageListWatcher::GetSdPage(PageKind::Notes): page number " << nPgNum
<< " >= " << maPageVectorNotes
.size() );
111 case PageKind::Handout
:
113 // #11420# for models used to transfer drawing shapes via clipboard it's ok to not have a handout page
114 DBG_ASSERT(nPgNum
== 0, "ImpPageListWatcher::GetSdPage: access to non existing handout page (!)");
116 pRetval
= mpHandoutPage
;
119 DBG_ASSERT(nPgNum
== 0,
120 "ImpPageListWatcher::GetSdPage: access to non existing handout page (!)");
129 sal_uInt32
ImpPageListWatcher::GetSdPageCount(PageKind ePgKind
)
131 sal_uInt32
nRetval(0);
135 ImpRecreateSortedPageListOnDemand();
140 case PageKind::Standard
:
142 nRetval
= maPageVectorStandard
.size();
145 case PageKind::Notes
:
147 nRetval
= maPageVectorNotes
.size();
150 case PageKind::Handout
:
164 sal_uInt32
ImpPageListWatcher::GetVisibleSdPageCount() const
166 sal_uInt32 nVisiblePageCount
= 0;
168 // build up vectors again
169 const sal_uInt32
nPageCount(ImpGetPageCount());
171 for(sal_uInt32
a(0); a
< nPageCount
; a
++)
173 SdPage
* pCandidate
= ImpGetPage(a
);
174 if ((pCandidate
->GetPageKind() == PageKind::Standard
)&&(!pCandidate
->IsExcluded())) nVisiblePageCount
++;
176 return nVisiblePageCount
;
179 sal_uInt32
ImpDrawPageListWatcher::ImpGetPageCount() const
181 return static_cast<sal_uInt32
>(mrModel
.GetPageCount());
184 SdPage
* ImpDrawPageListWatcher::ImpGetPage(sal_uInt32 nIndex
) const
186 return const_cast<SdPage
*>(static_cast<const SdPage
*>(mrModel
.GetPage(static_cast<sal_uInt16
>(nIndex
))));
189 ImpDrawPageListWatcher::ImpDrawPageListWatcher(const SdrModel
& rModel
)
190 : ImpPageListWatcher(rModel
)
194 ImpDrawPageListWatcher::~ImpDrawPageListWatcher()
198 sal_uInt32
ImpMasterPageListWatcher::ImpGetPageCount() const
200 return static_cast<sal_uInt32
>(mrModel
.GetMasterPageCount());
203 SdPage
* ImpMasterPageListWatcher::ImpGetPage(sal_uInt32 nIndex
) const
205 return const_cast<SdPage
*>(static_cast<const SdPage
*>(mrModel
.GetMasterPage(static_cast<sal_uInt16
>(nIndex
))));
208 ImpMasterPageListWatcher::ImpMasterPageListWatcher(const SdrModel
& rModel
)
209 : ImpPageListWatcher(rModel
)
213 ImpMasterPageListWatcher::~ImpMasterPageListWatcher()
217 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */