Coverage Report

Created: 2026-11-06 11:29

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/toolkit/source/controls/table/TableFunctionSet.cxx
Line
Count
Source
1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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
 * This file incorporates work covered by the following license notice:
10
 *
11
 *   Licensed to the Apache Software Foundation (ASF) under one or more
12
 *   contributor license agreements. See the NOTICE file distributed
13
 *   with this work for additional information regarding copyright
14
 *   ownership. The ASF licenses this file to you under the Apache
15
 *   License, Version 2.0 (the "License"); you may not use this file
16
 *   except in compliance with the License. You may obtain a copy of
17
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18
 */
19
20
#include <controls/table/TableFunctionSet.hxx>
21
#include <controls/table/TableControl.hxx>
22
23
namespace svt::table
24
{
25
TableFunctionSet::TableFunctionSet(TableControl& rTableControl)
26
0
    : m_rTableControl(rTableControl)
27
0
    , m_nCurrentRow(ROW_INVALID)
28
0
{
29
0
}
30
31
0
TableFunctionSet::~TableFunctionSet() {}
32
33
0
void TableFunctionSet::BeginDrag() {}
34
35
0
void TableFunctionSet::CreateAnchor() { m_rTableControl.setAnchor(m_rTableControl.getCurRow()); }
36
37
0
void TableFunctionSet::DestroyAnchor() { m_rTableControl.setAnchor(ROW_INVALID); }
38
39
void TableFunctionSet::SetCursorAtPoint(const Point& rPoint, bool bDontSelectAtCursor)
40
0
{
41
    // newRow is the row which includes the point, getCurRow() is the last selected row, before the mouse click
42
0
    sal_Int32 newRow = m_rTableControl.getRowAtPoint(rPoint);
43
0
    if (newRow == ROW_COL_HEADERS)
44
0
        newRow = m_rTableControl.getTopRow();
45
46
0
    sal_Int32 newCol = m_rTableControl.getColAtPoint(rPoint);
47
0
    if (newCol == COL_ROW_HEADERS)
48
0
        newCol = m_rTableControl.getLeftColumn();
49
50
0
    if ((newRow == ROW_INVALID) || (newCol == COL_INVALID))
51
0
        return;
52
53
0
    if (bDontSelectAtCursor)
54
0
    {
55
0
        if (m_rTableControl.GetSelectedRowCount() > 1)
56
0
            m_rTableControl.getSelEngine()->AddAlways(true);
57
0
    }
58
0
    else if (m_rTableControl.getAnchor() == m_rTableControl.getCurRow())
59
0
    {
60
        //selected region lies above the last selection
61
0
        if (m_rTableControl.getCurRow() >= newRow)
62
0
        {
63
            //put selected rows in vector
64
0
            while (m_rTableControl.getAnchor() >= newRow)
65
0
            {
66
0
                m_rTableControl.markRowAsSelected(m_rTableControl.getAnchor());
67
0
                m_rTableControl.setAnchor(m_rTableControl.getAnchor() - 1);
68
0
            }
69
0
            m_rTableControl.setAnchor(m_rTableControl.getAnchor() + 1);
70
0
        }
71
        //selected region lies beneath the last selected row
72
0
        else
73
0
        {
74
0
            while (m_rTableControl.getAnchor() <= newRow)
75
0
            {
76
0
                m_rTableControl.markRowAsSelected(m_rTableControl.getAnchor());
77
0
                m_rTableControl.setAnchor(m_rTableControl.getAnchor() + 1);
78
0
            }
79
0
            m_rTableControl.setAnchor(m_rTableControl.getAnchor() - 1);
80
0
        }
81
0
        m_rTableControl.invalidateSelectedRegion(m_rTableControl.getCurRow(), newRow);
82
0
    }
83
    //no region selected
84
0
    else
85
0
    {
86
0
        if (!m_rTableControl.hasRowSelection())
87
0
            m_rTableControl.markRowAsSelected(newRow);
88
0
        else
89
0
        {
90
0
            if (m_rTableControl.getSelEngine()->GetSelectionMode() == SelectionMode::Single)
91
0
            {
92
0
                DeselectAll();
93
0
                m_rTableControl.markRowAsSelected(newRow);
94
0
            }
95
0
            else
96
0
            {
97
0
                m_rTableControl.markRowAsSelected(newRow);
98
0
            }
99
0
        }
100
0
        if (m_rTableControl.GetSelectedRowCount() > 1
101
0
            && m_rTableControl.getSelEngine()->GetSelectionMode() != SelectionMode::Single)
102
0
            m_rTableControl.getSelEngine()->AddAlways(true);
103
104
0
        m_rTableControl.invalidateRow(newRow);
105
0
    }
106
0
    m_rTableControl.GoToCell(newCol, newRow);
107
0
}
108
109
bool TableFunctionSet::IsSelectionAtPoint(const Point& rPoint)
110
0
{
111
0
    m_rTableControl.getSelEngine()->AddAlways(false);
112
0
    if (!m_rTableControl.hasRowSelection())
113
0
        return false;
114
0
    else
115
0
    {
116
0
        sal_Int32 curRow = m_rTableControl.getRowAtPoint(rPoint);
117
0
        m_rTableControl.setAnchor(ROW_INVALID);
118
0
        bool selected = m_rTableControl.IsRowSelected(curRow);
119
0
        m_nCurrentRow = curRow;
120
0
        return selected;
121
0
    }
122
0
}
123
124
void TableFunctionSet::DeselectAtPoint(const Point&)
125
0
{
126
0
    m_rTableControl.invalidateRow(m_nCurrentRow);
127
0
    m_rTableControl.markRowAsDeselected(m_nCurrentRow);
128
0
}
129
130
void TableFunctionSet::DeselectAll()
131
0
{
132
0
    if (m_rTableControl.hasRowSelection())
133
0
    {
134
0
        for (size_t i = 0; i < m_rTableControl.GetSelectedRowCount(); ++i)
135
0
        {
136
0
            sal_Int32 const rowIndex = m_rTableControl.GetSelectedRowIndex(i);
137
0
            m_rTableControl.invalidateRow(rowIndex);
138
0
        }
139
140
0
        m_rTableControl.markAllRowsAsDeselected();
141
0
    }
142
0
}
143
144
} // namespace svt::table
145
146
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */