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/.
10 #ifndef SC_SHAREDFORMULA_HXX
11 #define SC_SHAREDFORMULA_HXX
13 #include "formulacell.hxx"
14 #include "mtvelements.hxx"
20 class SharedFormulaUtil
25 * Group formula cells stored in the passed container. The formula cells
26 * in the container are assumed to be all <b>non-shared</b>.
28 template<typename _Iter
>
29 static void groupFormulaCells(const _Iter
& itBeg
, const _Iter
& itEnd
)
32 ScFormulaCell
* pPrev
= *it
;
33 ScFormulaCell
* pCur
= NULL
;
34 for (++it
; it
!= itEnd
; ++it
, pPrev
= pCur
)
37 ScFormulaCell::CompareState eState
= pCur
->CompareByTokenArray(*pPrev
);
38 if (eState
== ScFormulaCell::NotEqual
)
41 ScFormulaCellGroupRef xGroup
= pPrev
->GetCellGroup();
46 pCur
->SetCellGroup(xGroup
);
50 // Create a new group.
51 xGroup
= pPrev
->CreateCellGroup(2, eState
== ScFormulaCell::EqualInvariant
);
52 pCur
->SetCellGroup(xGroup
);
57 * Split existing shared formula range at specified position. The cell at
58 * specified position becomes the top cell of the lower shared formula
59 * range after this call. This method does nothing if the cell at
60 * specified position is not a formula cell.
62 * @param aPos position of cell to examine.
64 static void splitFormulaCellGroup(const CellStoreType::position_type
& aPos
);
67 * Split existing shared formula ranges at specified row positions.
69 * @param rCells cell storage container
70 * @param rBounds row positions at which to split existing shared formula
71 * ranges. Note that this method will directly modify this
72 * parameter to sort and remove duplicates.
74 static void splitFormulaCellGroups(CellStoreType
& rCells
, std::vector
<SCROW
>& rBounds
);
77 * See if two specified adjacent formula cells can be merged, and if they
78 * can, merge them into the same group.
80 * @param rPos position object of the first cell
81 * @param rCell1 first cell
82 * @param rCell2 second cell located immediately below the first cell.
84 static void joinFormulaCells(
85 const CellStoreType::position_type
& rPos
, ScFormulaCell
& rCell1
, ScFormulaCell
& rCell2
);
87 * Merge with an existing formula group (if any) located immediately above
88 * if the cell at specified position is a formula cell, and its formula
89 * tokens are identical to that of the above formula group.
91 * @param aPos position of cell to examine.
93 static void joinFormulaCellAbove(const CellStoreType::position_type
& aPos
);
96 * Turn a shared formula cell into a non-shared one, and split it off from
97 * the adjacent formula cell groups.
99 * @param aPos position of cell to examine
100 * @param rCell formula cell instance
102 static void unshareFormulaCell(const CellStoreType::position_type
& aPos
, ScFormulaCell
& rCell
);
109 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */