LibreOffice Module sc (master)  1
sharedformula.hxx
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 #pragma once
11 
12 #include "formulacell.hxx"
13 #include "mtvelements.hxx"
14 
15 #include <vector>
16 
17 #define USE_FORMULA_GROUP_LISTENER 1
18 
19 namespace sc {
20 
21 class StartListeningContext;
22 
24 {
25 public:
26 
31  template<typename Iter>
32  static void groupFormulaCells(const Iter& itBeg, const Iter& itEnd)
33  {
34  Iter it = itBeg;
35  ScFormulaCell* pPrev = *it;
36  ScFormulaCell* pCur = nullptr;
37  for (++it; it != itEnd; ++it, pPrev = pCur)
38  {
39  pCur = *it;
40  ScFormulaCell::CompareState eState = pCur->CompareByTokenArray(*pPrev);
41  if (eState == ScFormulaCell::NotEqual)
42  continue;
43 
44  ScFormulaCellGroupRef xGroup = pPrev->GetCellGroup();
45  if (xGroup)
46  {
47  // Extend the group.
48  ++xGroup->mnLength;
49  pCur->SetCellGroup(xGroup);
50  continue;
51  }
52 
53  // Create a new group.
54  xGroup = pPrev->CreateCellGroup(2, eState == ScFormulaCell::EqualInvariant);
55  pCur->SetCellGroup(xGroup);
56  }
57  }
58 
60  static const ScFormulaCell* getSharedTopFormulaCell(const CellStoreType::position_type& aPos);
61 
74  static bool splitFormulaCellGroup(const CellStoreType::position_type& aPos, sc::EndListeningContext* pCxt);
75 
87  static bool splitFormulaCellGroups(const ScDocument& rDoc, CellStoreType& rCells, std::vector<SCROW>& rBounds);
88 
100  static bool joinFormulaCells(
101  const CellStoreType::position_type& rPos, ScFormulaCell& rCell1, ScFormulaCell& rCell2 );
112  static bool joinFormulaCellAbove( const CellStoreType::position_type& aPos );
113 
121  static void unshareFormulaCell(const CellStoreType::position_type& aPos, ScFormulaCell& rCell);
122 
130  static void unshareFormulaCells(const ScDocument& rDoc, CellStoreType& rCells, std::vector<SCROW>& rRows);
131 
142  static void startListeningAsGroup( StartListeningContext& rCxt, ScFormulaCell** ppSharedTop );
143 };
144 
145 }
146 
147 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
::boost::intrusive_ptr< ScFormulaCellGroup > ScFormulaCellGroupRef
Definition: types.hxx:43
static void startListeningAsGroup(StartListeningContext &rCxt, ScFormulaCell **ppSharedTop)
Have all formula cells belonging to a group start listening to their references.
static const ScFormulaCell * getSharedTopFormulaCell(const CellStoreType::position_type &aPos)
Get shared formula top cell from position, if any, else nullptr.
mdds::multi_type_vector< CellFunc, CellStoreEvent > CellStoreType
static bool splitFormulaCellGroup(const CellStoreType::position_type &aPos, sc::EndListeningContext *pCxt)
Split existing shared formula range at specified position.
static bool joinFormulaCellAbove(const CellStoreType::position_type &aPos)
Merge with an existing formula group (if any) located immediately above if the cell at specified posi...
void SetCellGroup(const ScFormulaCellGroupRef &xRef)
static void unshareFormulaCell(const CellStoreType::position_type &aPos, ScFormulaCell &rCell)
Turn a shared formula cell into a non-shared one, and split it off from the adjacent formula cell gro...
static void groupFormulaCells(const Iter &itBeg, const Iter &itEnd)
Group formula cells stored in the passed container.
static bool splitFormulaCellGroups(const ScDocument &rDoc, CellStoreType &rCells, std::vector< SCROW > &rBounds)
Split existing shared formula ranges at specified row positions.
CompareState CompareByTokenArray(const ScFormulaCell &rOther) const
static bool joinFormulaCells(const CellStoreType::position_type &rPos, ScFormulaCell &rCell1, ScFormulaCell &rCell2)
See if two specified adjacent formula cells can be merged, and if they can, merge them into the same ...
static void unshareFormulaCells(const ScDocument &rDoc, CellStoreType &rCells, std::vector< SCROW > &rRows)
Make specified formula cells non-shared ones, and split them off from their respective adjacent formu...