summaryrefslogtreecommitdiff
path: root/sc/source/core/data/listenercontext.cxx
blob: dcdffac65710aca72bff192ea3eccce6673b4481 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

#include "listenercontext.hxx"
#include "document.hxx"
#include "mtvelements.hxx"

namespace sc {

StartListeningContext::StartListeningContext(ScDocument& rDoc) :
    mrDoc(rDoc), mpSet(new ColumnBlockPositionSet(rDoc)) {}

StartListeningContext::StartListeningContext(
    ScDocument& rDoc, const boost::shared_ptr<ColumnBlockPositionSet>& pSet) :
    mrDoc(rDoc), mpSet(pSet) {}

ScDocument& StartListeningContext::getDoc()
{
    return mrDoc;
}

ColumnBlockPosition* StartListeningContext::getBlockPosition(SCTAB nTab, SCCOL nCol)
{
    return mpSet->getBlockPosition(nTab, nCol);
}

EndListeningContext::EndListeningContext(ScDocument& rDoc, ScTokenArray* pOldCode) :
    mrDoc(rDoc), maSet(false), mpPosSet(new ColumnBlockPositionSet(rDoc)),
    mpOldCode(pOldCode), maPosDelta(0,0,0) {}

EndListeningContext::EndListeningContext(
    ScDocument& rDoc, const boost::shared_ptr<ColumnBlockPositionSet>& pSet, ScTokenArray* pOldCode) :
    mrDoc(rDoc), maSet(false), mpPosSet(pSet),
    mpOldCode(pOldCode), maPosDelta(0,0,0) {}

void EndListeningContext::setPositionDelta( const ScAddress& rDelta )
{
    maPosDelta = rDelta;
}

ScDocument& EndListeningContext::getDoc()
{
    return mrDoc;
}

ScTokenArray* EndListeningContext::getOldCode()
{
    return mpOldCode;
}

ScAddress EndListeningContext::getOldPosition( const ScAddress& rPos ) const
{
    ScAddress aOldPos = rPos;
    aOldPos.IncCol(maPosDelta.Col());
    aOldPos.IncRow(maPosDelta.Row());
    aOldPos.IncTab(maPosDelta.Tab());
    return aOldPos;
}

ColumnBlockPosition* EndListeningContext::getBlockPosition(SCTAB nTab, SCCOL nCol)
{
    return mpPosSet->getBlockPosition(nTab, nCol);
}

void EndListeningContext::addEmptyBroadcasterPosition(SCTAB nTab, SCCOL nCol, SCROW nRow)
{
    maSet.set(nTab, nCol, nRow, true);
}

void EndListeningContext::purgeEmptyBroadcasters()
{
    PurgeListenerAction aAction(mrDoc);
    maSet.executeAction(aAction);
}

PurgeListenerAction::PurgeListenerAction(ScDocument& rDoc) :
    mrDoc(rDoc), mpBlockPos(new ColumnBlockPosition) {}

void PurgeListenerAction::startColumn( SCTAB nTab, SCCOL nCol )
{
    mrDoc.InitColumnBlockPosition(*mpBlockPos, nTab, nCol);
}

void PurgeListenerAction::execute( const ScAddress& rPos, SCROW nLength, bool bVal )
{
    if (bVal)
    {
        mrDoc.DeleteBroadcasters(*mpBlockPos, rPos, nLength);
    }
};

}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */