Bump version to 24.04.3.4
[LibreOffice.git] / svx / source / svdraw / svdviter.cxx
blob65450efb42a54b857b0aae2526828abfc522df6e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <svx/svdviter.hxx>
21 #include <svx/svdobj.hxx>
22 #include <svx/svdpage.hxx>
23 #include <svx/svdmodel.hxx>
24 #include <svx/svdview.hxx>
25 #include <svx/svdpagv.hxx>
26 #include <svx/svdsob.hxx>
28 static bool ImpCheckPageView(const SdrPage* pPage, const SdrObject* pObject, SdrPageView const* pPV)
30 if (!pPage)
31 return true;
33 bool bMaster(pPage->IsMasterPage());
34 SdrPage* pPg = pPV->GetPage();
36 if (pPg == pPage)
38 if (pObject)
40 // Looking for an object? First, determine if it visible in
41 // this PageView.
42 return pObject->isVisibleOnAnyOfTheseLayers(pPV->GetVisibleLayers());
44 else
46 return true;
49 else if (bMaster && (!pObject || !pObject->IsNotVisibleAsMaster()))
51 if (pPg->TRG_HasMasterPage())
53 SdrPage& rMasterPage = pPg->TRG_GetMasterPage();
55 if (&rMasterPage == pPage)
57 // the page we're looking for is a master page in this PageView
58 if (pObject)
60 // Looking for an object? First, determine if it visible in
61 // this PageView.
62 SdrLayerIDSet aObjLay = pPV->GetVisibleLayers();
63 aObjLay &= pPg->TRG_GetMasterPageVisibleLayers();
64 if (pObject->isVisibleOnAnyOfTheseLayers(aObjLay))
66 return true;
67 } // else, look at the next master page of this page...
69 else
71 return true;
77 // master page forbidden or no fitting master page found
78 return false;
81 namespace SdrViewIter
83 void ForAllViews(const SdrPage* pPage, std::function<void(SdrView*)> f)
85 if (!pPage)
86 return;
87 const SdrModel* pModel = &pPage->getSdrModelFromSdrPage();
89 pModel->ForAllListeners([&pPage, &f](SfxListener* pLs) {
90 if (!pLs->IsSdrView())
91 return false;
92 SdrView* pCurrentView = static_cast<SdrView*>(pLs);
93 SdrPageView* pPV = pCurrentView->GetSdrPageView();
95 if (pPV && ImpCheckPageView(pPage, nullptr, pPV))
97 f(pCurrentView);
99 return false;
103 void ForAllViews(const SdrObject* pObject, std::function<void(SdrView*)> f)
105 if (!pObject)
106 return;
107 const SdrModel* pModel = &pObject->getSdrModelFromSdrObject();
108 const SdrPage* pPage = pObject->getSdrPageFromSdrObject();
109 if (!pPage)
110 return;
112 pModel->ForAllListeners([&pPage, &pObject, &f](SfxListener* pLs) {
113 if (!pLs->IsSdrView())
114 return false;
115 SdrView* pCurrentView = static_cast<SdrView*>(pLs);
116 SdrPageView* pPV = pCurrentView->GetSdrPageView();
118 if (pPV && ImpCheckPageView(pPage, pObject, pPV))
120 f(pCurrentView);
122 return false;
126 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */