LibreOffice Module sc (master) 1
broadcast.cxx
Go to the documentation of this file.
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
10#include <broadcast.hxx>
11#include <address.hxx>
12#include <formulacell.hxx>
13
14namespace sc
15{
17 : eType(CellListenerType::FormulaCell)
18 , pData(p)
19{
20}
21
24 , pData(p)
25{
26}
27
29 : eType(AreaListenerType::FormulaCell)
30 , pData(p)
31{
32}
33
35 : eType(AreaListenerType::FormulaGroup)
36 , pData(p)
37{
38}
39
42 , pData(p)
43{
44}
45
47 const ScAddress& rFormulaPos) const
48{
49 auto it = aCellListenerStore.find(rBroadcasterPos);
50 if (it == aCellListenerStore.end())
51 return false;
52
53 for (const auto& rLis : it->second)
54 {
55 if (rLis.eType == CellListenerType::FormulaCell)
56 {
57 auto pFC = std::get<const ScFormulaCell*>(rLis.pData);
58 if (pFC->aPos == rFormulaPos)
59 return true;
60 }
61 }
62
63 return false;
64}
65
67 const ScAddress& rFormulaPos) const
68{
69 auto it = aAreaListenerStore.find(rBroadcasterRange);
70 if (it == aAreaListenerStore.end())
71 return false;
72
73 for (const auto& rLis : it->second)
74 {
75 if (rLis.eType == AreaListenerType::FormulaCell)
76 {
77 auto pFC = std::get<const ScFormulaCell*>(rLis.pData);
78 if (pFC->aPos == rFormulaPos)
79 return true;
80 }
81 }
82
83 return false;
84}
85
86void BroadcasterState::dump(std::ostream& rStrm, const ScDocument* pDoc) const
87{
88 constexpr ScRefFlags nPosFlags = ScRefFlags::VALID | ScRefFlags::TAB_3D;
89
90 rStrm << "---" << std::endl;
91
92 for (const auto & [ rPos, rListeners ] : aCellListenerStore)
93 {
94 rStrm << "- type: cell-broadcaster\n";
95 rStrm << " position: " << rPos.Format(nPosFlags, pDoc) << std::endl;
96
97 if (!rListeners.empty())
98 rStrm << " listeners:\n";
99
100 for (const auto& rLis : rListeners)
101 {
102 switch (rLis.eType)
103 {
105 {
106 auto* pFC = std::get<const ScFormulaCell*>(rLis.pData);
107 rStrm << " - type: formula-cell\n";
108 rStrm << " position: " << pFC->aPos.Format(nPosFlags, pDoc) << std::endl;
109 break;
110 }
112 {
113 rStrm << " - type: unknown" << std::endl;
114 break;
115 }
116 }
117 }
118 }
119
120 for (const auto & [ rRange, rListeners ] : aAreaListenerStore)
121 {
122 rStrm << "- type: area-broadcaster\n";
123 rStrm << " range: " << rRange.Format(*pDoc, nPosFlags) << std::endl;
124
125 if (!rListeners.empty())
126 rStrm << " listeners:\n";
127
128 for (const auto& rLis : rListeners)
129 {
130 switch (rLis.eType)
131 {
133 {
134 auto* pFC = std::get<const ScFormulaCell*>(rLis.pData);
135 rStrm << " - type: formula-cell\n";
136 rStrm << " position: " << pFC->aPos.Format(nPosFlags, pDoc) << std::endl;
137 break;
138 }
140 {
141 auto* pFGL = std::get<const sc::FormulaGroupAreaListener*>(rLis.pData);
142
143 auto pTopCell = pFGL->getTopCell();
144 if (auto xFG = pTopCell->GetCellGroup(); xFG)
145 {
146 ScRange aGR(pTopCell->aPos);
147 aGR.aEnd.IncRow(xFG->mnLength - 1);
148 rStrm << " - type: formula-group\n";
149 rStrm << " range: " << aGR.Format(*pDoc, nPosFlags) << std::endl;
150 }
151 break;
152 }
154 {
155 rStrm << " - type: unknown" << std::endl;
156 break;
157 }
158 }
159 }
160 }
161}
162}
163
164/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ScRefFlags
Definition: address.hxx:158
void IncRow(SCROW nDelta=1)
Definition: address.hxx:312
OUString Format(const ScDocument &rDocument, ScRefFlags nFlags=ScRefFlags::ZERO, const ScAddress::Details &rDetails=ScAddress::detailsOOOa1, bool bFullAddressNotation=false) const
Returns string with formatted cell range from aStart to aEnd, according to provided address conventio...
Definition: address.cxx:2170
ScAddress aEnd
Definition: address.hxx:498
DocumentType eType
void * p
std::unique_ptr< sal_Int32[]> pData
void SvStream & rStrm
CAUTION! The following defines must be in the same namespace as the respective type.
Definition: broadcast.cxx:15
AreaListener(const ScFormulaCell *p)
Definition: broadcast.cxx:28
CellListener(const ScFormulaCell *p)
Definition: broadcast.cxx:16
bool hasFormulaCellListener(const ScAddress &rBroadcasterPos, const ScAddress &rFormulaPos) const
Check if a formula cell listens on a single cell.
Definition: broadcast.cxx:46
std::map< ScAddress, std::vector< CellListener > > aCellListenerStore
Definition: broadcast.hxx:64
std::map< ScRange, std::vector< AreaListener > > aAreaListenerStore
Definition: broadcast.hxx:65
void dump(std::ostream &rStrm, const ScDocument *pDoc=nullptr) const
Dump all broadcaster state in YAML format.
Definition: broadcast.cxx:86