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 #ifndef INCLUDED_SC_INC_SHAREDFORMULA_HXX
11 #define INCLUDED_SC_INC_SHAREDFORMULA_HXX
12 
13 #include "formulacell.hxx"
14 #include "mtvelements.hxx"
15 
16 #include <vector>
17 
18 #define USE_FORMULA_GROUP_LISTENER 1
19 
20 namespace sc {
21 
22 class StartListeningContext;
23 
25 {
26 public:
27 
32  template<typename Iter>
33  static void groupFormulaCells(const Iter& itBeg, const Iter& itEnd)
34  {
35  Iter it = itBeg;
36  ScFormulaCell* pPrev = *it;
37  ScFormulaCell* pCur = nullptr;
38  for (++it; it != itEnd; ++it, pPrev = pCur)
39  {
40  pCur = *it;
41  ScFormulaCell::CompareState eState = pCur->CompareByTokenArray(*pPrev);
42  if (eState == ScFormulaCell::NotEqual)
43  continue;
44 
45  ScFormulaCellGroupRef xGroup = pPrev->GetCellGroup();
46  if (xGroup)
47  {
48  // Extend the group.
49  ++xGroup->mnLength;
50  pCur->SetCellGroup(xGroup);
51  continue;
52  }
53 
54  // Create a new group.
55  xGroup = pPrev->CreateCellGroup(2, eState == ScFormulaCell::EqualInvariant);
56  pCur->SetCellGroup(xGroup);
57  }
58  }
59 
61  static const ScFormulaCell* getSharedTopFormulaCell(const CellStoreType::position_type& aPos);
62 
75  static bool splitFormulaCellGroup(const CellStoreType::position_type& aPos, sc::EndListeningContext* pCxt);
76 
88  static bool splitFormulaCellGroups(const ScDocument* pDoc, CellStoreType& rCells, std::vector<SCROW>& rBounds);
89 
101  static bool joinFormulaCells(
102  const CellStoreType::position_type& rPos, ScFormulaCell& rCell1, ScFormulaCell& rCell2 );
113  static bool joinFormulaCellAbove( const CellStoreType::position_type& aPos );
114 
122  static void unshareFormulaCell(const CellStoreType::position_type& aPos, ScFormulaCell& rCell);
123 
131  static void unshareFormulaCells(const ScDocument* pDoc, CellStoreType& rCells, std::vector<SCROW>& rRows);
132 
143  static void startListeningAsGroup( StartListeningContext& rCxt, ScFormulaCell** ppSharedTop );
144 };
145 
146 }
147 
148 #endif
149 
150 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
::boost::intrusive_ptr< ScFormulaCellGroup > ScFormulaCellGroupRef
Definition: types.hxx:44
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 splitFormulaCellGroups(const ScDocument *pDoc, CellStoreType &rCells, std::vector< SCROW > &rBounds)
Split existing shared formula ranges at specified row positions.
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 unshareFormulaCells(const ScDocument *pDoc, CellStoreType &rCells, std::vector< SCROW > &rRows)
Make specified formula cells non-shared ones, and split them off from their respective adjacent formu...
static void groupFormulaCells(const Iter &itBeg, const Iter &itEnd)
Group formula cells stored in the passed container.
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 ...