Bump version to 4.3-4
[LibreOffice.git] / sc / inc / sharedformula.hxx
blobb29843f8547a6fa7a4d574687ad03df7cff18639
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 namespace sc {
20 class SharedFormulaUtil
22 public:
24 /**
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)
31 _Iter it = itBeg;
32 ScFormulaCell* pPrev = *it;
33 ScFormulaCell* pCur = NULL;
34 for (++it; it != itEnd; ++it, pPrev = pCur)
36 pCur = *it;
37 ScFormulaCell::CompareState eState = pCur->CompareByTokenArray(*pPrev);
38 if (eState == ScFormulaCell::NotEqual)
39 continue;
41 ScFormulaCellGroupRef xGroup = pPrev->GetCellGroup();
42 if (xGroup)
44 // Extend the group.
45 ++xGroup->mnLength;
46 pCur->SetCellGroup(xGroup);
47 continue;
50 // Create a new group.
51 xGroup = pPrev->CreateCellGroup(2, eState == ScFormulaCell::EqualInvariant);
52 pCur->SetCellGroup(xGroup);
56 /**
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);
66 /**
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);
76 /**
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);
86 /**
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);
95 /**
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);
105 * Make specified formula cells non-shared ones, and split them off from
106 * their respective adjacent formula cell groups.
108 * @param rCells cell storage container
109 * @param rRows row positions at which to unshare formula cells.
111 static void unshareFormulaCells(CellStoreType& rCells, std::vector<SCROW>& rRows);
116 #endif
118 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */