/src/libreoffice/svx/source/svdraw/svdviter.cxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
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/. |
8 | | * |
9 | | * This file incorporates work covered by the following license notice: |
10 | | * |
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 . |
18 | | */ |
19 | | |
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> |
27 | | |
28 | | static bool ImpCheckPageView(const SdrPage* pPage, const SdrObject* pObject, SdrPageView const* pPV) |
29 | 24 | { |
30 | 24 | if (!pPage) |
31 | 0 | return true; |
32 | | |
33 | 24 | bool bMaster(pPage->IsMasterPage()); |
34 | 24 | SdrPage* pPg = pPV->GetPage(); |
35 | | |
36 | 24 | if (pPg == pPage) |
37 | 24 | { |
38 | 24 | if (pObject) |
39 | 24 | { |
40 | | // Looking for an object? First, determine if it visible in |
41 | | // this PageView. |
42 | 24 | return pObject->isVisibleOnAnyOfTheseLayers(pPV->GetVisibleLayers()); |
43 | 24 | } |
44 | 0 | else |
45 | 0 | { |
46 | 0 | return true; |
47 | 0 | } |
48 | 24 | } |
49 | 0 | else if (bMaster && (!pObject || !pObject->IsNotVisibleAsMaster())) |
50 | 0 | { |
51 | 0 | if (pPg->TRG_HasMasterPage()) |
52 | 0 | { |
53 | 0 | SdrPage& rMasterPage = pPg->TRG_GetMasterPage(); |
54 | |
|
55 | 0 | if (&rMasterPage == pPage) |
56 | 0 | { |
57 | | // the page we're looking for is a master page in this PageView |
58 | 0 | if (pObject) |
59 | 0 | { |
60 | | // Looking for an object? First, determine if it visible in |
61 | | // this PageView. |
62 | 0 | SdrLayerIDSet aObjLay = pPV->GetVisibleLayers(); |
63 | 0 | aObjLay &= pPg->TRG_GetMasterPageVisibleLayers(); |
64 | 0 | if (pObject->isVisibleOnAnyOfTheseLayers(aObjLay)) |
65 | 0 | { |
66 | 0 | return true; |
67 | 0 | } // else, look at the next master page of this page... |
68 | 0 | } |
69 | 0 | else |
70 | 0 | { |
71 | 0 | return true; |
72 | 0 | } |
73 | 0 | } |
74 | 0 | } |
75 | 0 | } |
76 | | |
77 | | // master page forbidden or no fitting master page found |
78 | 0 | return false; |
79 | 24 | } |
80 | | |
81 | | namespace SdrViewIter |
82 | | { |
83 | | void ForAllViews(const SdrPage* pPage, std::function<void(SdrView*)> f) |
84 | 0 | { |
85 | 0 | if (!pPage) |
86 | 0 | return; |
87 | 0 | const SdrModel* pModel = &pPage->getSdrModelFromSdrPage(); |
88 | |
|
89 | 0 | pModel->ForAllListeners([&pPage, &f](SfxListener* pLs) { |
90 | 0 | if (!pLs->IsSdrView()) |
91 | 0 | return false; |
92 | 0 | SdrView* pCurrentView = static_cast<SdrView*>(pLs); |
93 | 0 | SdrPageView* pPV = pCurrentView->GetSdrPageView(); |
94 | |
|
95 | 0 | if (pPV && ImpCheckPageView(pPage, nullptr, pPV)) |
96 | 0 | { |
97 | 0 | f(pCurrentView); |
98 | 0 | } |
99 | 0 | return false; |
100 | 0 | }); |
101 | 0 | } |
102 | | |
103 | | void ForAllViews(const SdrObject* pObject, std::function<void(SdrView*)> f) |
104 | 421k | { |
105 | 421k | if (!pObject) |
106 | 0 | return; |
107 | 421k | const SdrModel* pModel = &pObject->getSdrModelFromSdrObject(); |
108 | 421k | const SdrPage* pPage = pObject->getSdrPageFromSdrObject(); |
109 | 421k | if (!pPage) |
110 | 5.13k | return; |
111 | | |
112 | 416k | pModel->ForAllListeners([&pPage, &pObject, &f](SfxListener* pLs) { |
113 | 150k | if (!pLs->IsSdrView()) |
114 | 125k | return false; |
115 | 24.9k | SdrView* pCurrentView = static_cast<SdrView*>(pLs); |
116 | 24.9k | SdrPageView* pPV = pCurrentView->GetSdrPageView(); |
117 | | |
118 | 24.9k | if (pPV && ImpCheckPageView(pPage, pObject, pPV)) |
119 | 24 | { |
120 | 24 | f(pCurrentView); |
121 | 24 | } |
122 | 24.9k | return false; |
123 | 150k | }); |
124 | 416k | } |
125 | | } |
126 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |