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>
26 void ImpPageListWatcher::ImpRecreateSortedPageListOnDemand()
29 maPageVectorStandard
.clear();
30 maPageVectorNotes
.clear();
31 mpHandoutPage
= nullptr;
33 // build up vectors again
34 const sal_uInt32
nPageCount(ImpGetPageCount());
36 for(sal_uInt32
a(0); a
< nPageCount
; a
++)
38 SdPage
* pCandidate
= ImpGetPage(a
);
39 DBG_ASSERT(pCandidate
, "ImpPageListWatcher::ImpRecreateSortedPageListOnDemand: Invalid PageList in Model (!)");
41 switch(pCandidate
->GetPageKind())
43 case PageKind::Standard
:
45 maPageVectorStandard
.push_back(pCandidate
);
50 maPageVectorNotes
.push_back(pCandidate
);
53 case PageKind::Handout
:
55 DBG_ASSERT(!mpHandoutPage
, "ImpPageListWatcher::ImpRecreateSortedPageListOnDemand: Two Handout pages in PageList of Model (!)");
56 mpHandoutPage
= pCandidate
;
63 mbPageListValid
= true;
66 ImpPageListWatcher::ImpPageListWatcher(const SdrModel
& rModel
)
68 , mpHandoutPage(nullptr)
69 , mbPageListValid(false)
73 ImpPageListWatcher::~ImpPageListWatcher()
77 SdPage
* ImpPageListWatcher::GetSdPage(PageKind ePgKind
, sal_uInt32 nPgNum
)
79 SdPage
* pRetval(nullptr);
83 ImpRecreateSortedPageListOnDemand();
88 case PageKind::Standard
:
90 if( nPgNum
< static_cast<sal_uInt32
>(maPageVectorStandard
.size()) )
91 pRetval
= maPageVectorStandard
[nPgNum
];
95 "ImpPageListWatcher::GetSdPage(PageKind::Standard): page number " << nPgNum
<< " >= " << maPageVectorStandard
.size() );
101 if( nPgNum
< static_cast<sal_uInt32
>(maPageVectorNotes
.size()) )
102 pRetval
= maPageVectorNotes
[nPgNum
];
106 "ImpPageListWatcher::GetSdPage(PageKind::Notes): page number " << nPgNum
<< " >= " << maPageVectorNotes
.size() );
110 case PageKind::Handout
:
112 // #11420# for models used to transfer drawing shapes via clipboard it's ok to not have a handout page
113 DBG_ASSERT(nPgNum
== 0, "ImpPageListWatcher::GetSdPage: access to non existing handout page (!)");
115 pRetval
= mpHandoutPage
;
118 DBG_ASSERT(nPgNum
== 0,
119 "ImpPageListWatcher::GetSdPage: access to non existing handout page (!)");
128 sal_uInt32
ImpPageListWatcher::GetSdPageCount(PageKind ePgKind
)
130 sal_uInt32
nRetval(0);
134 ImpRecreateSortedPageListOnDemand();
139 case PageKind::Standard
:
141 nRetval
= maPageVectorStandard
.size();
144 case PageKind::Notes
:
146 nRetval
= maPageVectorNotes
.size();
149 case PageKind::Handout
:
163 sal_uInt32
ImpPageListWatcher::GetVisibleSdPageCount()
165 sal_uInt32 nVisiblePageCount
= 0;
167 // build up vectors again
168 const sal_uInt32
nPageCount(ImpGetPageCount());
170 for(sal_uInt32
a(0); a
< nPageCount
; a
++)
172 SdPage
* pCandidate
= ImpGetPage(a
);
173 if ((pCandidate
->GetPageKind() == PageKind::Standard
)&&(!pCandidate
->IsExcluded())) nVisiblePageCount
++;
175 return nVisiblePageCount
;
178 sal_uInt32
ImpDrawPageListWatcher::ImpGetPageCount() const
180 return static_cast<sal_uInt32
>(mrModel
.GetPageCount());
183 SdPage
* ImpDrawPageListWatcher::ImpGetPage(sal_uInt32 nIndex
) const
185 return const_cast<SdPage
*>(static_cast<const SdPage
*>(mrModel
.GetPage(static_cast<sal_uInt16
>(nIndex
))));
188 ImpDrawPageListWatcher::ImpDrawPageListWatcher(const SdrModel
& rModel
)
189 : ImpPageListWatcher(rModel
)
193 ImpDrawPageListWatcher::~ImpDrawPageListWatcher()
197 sal_uInt32
ImpMasterPageListWatcher::ImpGetPageCount() const
199 return static_cast<sal_uInt32
>(mrModel
.GetMasterPageCount());
202 SdPage
* ImpMasterPageListWatcher::ImpGetPage(sal_uInt32 nIndex
) const
204 return const_cast<SdPage
*>(static_cast<const SdPage
*>(mrModel
.GetMasterPage(static_cast<sal_uInt16
>(nIndex
))));
207 ImpMasterPageListWatcher::ImpMasterPageListWatcher(const SdrModel
& rModel
)
208 : ImpPageListWatcher(rModel
)
212 ImpMasterPageListWatcher::~ImpMasterPageListWatcher()
216 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */