tdf#125181 maxY is 50000 in prstGeom for star24 and star32
[LibreOffice.git] / sc / inc / sharedformula.hxx
blobb7c9577b2dfa20a5385653719919ce2dade0df26
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/.
8 */
10 #ifndef INCLUDED_SC_INC_SHAREDFORMULA_HXX
11 #define INCLUDED_SC_INC_SHAREDFORMULA_HXX
13 #include "formulacell.hxx"
14 #include "mtvelements.hxx"
16 #include <vector>
18 #define USE_FORMULA_GROUP_LISTENER 1
20 namespace sc {
22 class StartListeningContext;
24 class SharedFormulaUtil
26 public:
28 /**
29 * Group formula cells stored in the passed container. The formula cells
30 * in the container are assumed to be all <b>non-shared</b>.
32 template<typename Iter>
33 static void groupFormulaCells(const Iter& itBeg, const Iter& itEnd)
35 Iter it = itBeg;
36 ScFormulaCell* pPrev = *it;
37 ScFormulaCell* pCur = nullptr;
38 for (++it; it != itEnd; ++it, pPrev = pCur)
40 pCur = *it;
41 ScFormulaCell::CompareState eState = pCur->CompareByTokenArray(*pPrev);
42 if (eState == ScFormulaCell::NotEqual)
43 continue;
45 ScFormulaCellGroupRef xGroup = pPrev->GetCellGroup();
46 if (xGroup)
48 // Extend the group.
49 ++xGroup->mnLength;
50 pCur->SetCellGroup(xGroup);
51 continue;
54 // Create a new group.
55 xGroup = pPrev->CreateCellGroup(2, eState == ScFormulaCell::EqualInvariant);
56 pCur->SetCellGroup(xGroup);
60 /** Get shared formula top cell from position, if any, else nullptr. */
61 static const ScFormulaCell* getSharedTopFormulaCell(const CellStoreType::position_type& aPos);
63 /**
64 * Split existing shared formula range at specified position. The cell at
65 * specified position becomes the top cell of the lower shared formula
66 * range after this call. This method does nothing if the cell at
67 * specified position is not a formula cell.
69 * @param aPos position of cell to examine.
70 * @param pCxt context to be used, if any, may be nullptr.
72 * @return TRUE if there indeed was a split, else FALSE (e.g. split
73 * position was top or bottom cell or no formula group).
75 static bool splitFormulaCellGroup(const CellStoreType::position_type& aPos, sc::EndListeningContext* pCxt);
77 /**
78 * Split existing shared formula ranges at specified row positions.
80 * @param rCells cell storage container
81 * @param rBounds row positions at which to split existing shared formula
82 * ranges. Note that this method will directly modify this
83 * parameter to sort and remove duplicates.
85 * @return TRUE if there indeed was a split, else FALSE (e.g. split
86 * positions were only top or bottom cells or no formula group).
88 static bool splitFormulaCellGroups(CellStoreType& rCells, std::vector<SCROW>& rBounds);
90 /**
91 * See if two specified adjacent formula cells can be merged, and if they
92 * can, merge them into the same group.
94 * @param rPos position object of the first cell
95 * @param rCell1 first cell
96 * @param rCell2 second cell located immediately below the first cell.
98 * @return true if the cells are merged, false otherwise. If the two
99 * cells already belong to the same group, it returns false.
101 static bool joinFormulaCells(
102 const CellStoreType::position_type& rPos, ScFormulaCell& rCell1, ScFormulaCell& rCell2 );
104 * Merge with an existing formula group (if any) located immediately above
105 * if the cell at specified position is a formula cell, and its formula
106 * tokens are identical to that of the above formula group.
108 * @param aPos position of cell to examine.
110 * @return true if the cells are merged, false otherwise. If the two
111 * cells already belong to the same group, it returns false.
113 static bool joinFormulaCellAbove( const CellStoreType::position_type& aPos );
116 * Turn a shared formula cell into a non-shared one, and split it off from
117 * the adjacent formula cell groups.
119 * @param aPos position of cell to examine
120 * @param rCell formula cell instance
122 static void unshareFormulaCell(const CellStoreType::position_type& aPos, ScFormulaCell& rCell);
125 * Make specified formula cells non-shared ones, and split them off from
126 * their respective adjacent formula cell groups.
128 * @param rCells cell storage container
129 * @param rRows row positions at which to unshare formula cells.
131 static void unshareFormulaCells(CellStoreType& rCells, std::vector<SCROW>& rRows);
134 * Have all formula cells belonging to a group start listening to their
135 * references.
137 * @param rCxt context object.
138 * @param ppSharedTop memory position of the pointer of the topmost
139 * formula cell instance in the cell storage. The
140 * caller is responsible for ensuring that it is indeed
141 * the topmost cell of a shared formula group.
143 static void startListeningAsGroup( StartListeningContext& rCxt, ScFormulaCell** ppSharedTop );
148 #endif
150 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */