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
19namespace sc {
20
21class StartListeningContext;
22
24{
25public:
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;
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: */
void SetCellGroup(const ScFormulaCellGroupRef &xRef)
const ScFormulaCellGroupRef & GetCellGroup() const
ScFormulaCellGroupRef CreateCellGroup(SCROW nLen, bool bInvariant)
Turn a non-grouped cell into the top of a grouped cell.
CompareState CompareByTokenArray(const ScFormulaCell &rOther) const
static void groupFormulaCells(const Iter &itBeg, const Iter &itEnd)
Group formula cells stored in the passed container.
static void startListeningAsGroup(StartListeningContext &rCxt, ScFormulaCell **ppSharedTop)
Have all formula cells belonging to a group start listening to their references.
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...
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 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 bool joinFormulaCellAbove(const CellStoreType::position_type &aPos)
Merge with an existing formula group (if any) located immediately above if the cell at specified posi...
static bool splitFormulaCellGroup(const CellStoreType::position_type &aPos, sc::EndListeningContext *pCxt)
Split existing shared formula range at specified position.
static bool splitFormulaCellGroups(const ScDocument &rDoc, CellStoreType &rCells, std::vector< SCROW > &rBounds)
Split existing shared formula ranges at specified row positions.
static const ScFormulaCell * getSharedTopFormulaCell(const CellStoreType::position_type &aPos)
Get shared formula top cell from position, if any, else nullptr.
CAUTION! The following defines must be in the same namespace as the respective type.
mdds::mtv::soa::multi_type_vector< CellFunc, CellStoreTrait > CellStoreType
::boost::intrusive_ptr< ScFormulaCellGroup > ScFormulaCellGroupRef
Definition: types.hxx:43