Coverage Report

Created: 2026-03-31 11:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sc/source/ui/view/tableshell.cxx
Line
Count
Source
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
11
#include <scitems.hxx>
12
#include <sfx2/objface.hxx>
13
#include <sfx2/objsh.hxx>
14
#include <sfx2/bindings.hxx>
15
#include <sfx2/request.hxx>
16
#include <svl/whiter.hxx>
17
#include <vcl/EnumContext.hxx>
18
19
#include <sc.hrc>
20
#include <tableshell.hxx>
21
#include <tabvwsh.hxx>
22
#include <docsh.hxx>
23
#include <document.hxx>
24
#include <dbdata.hxx>
25
#include <dbdocfun.hxx>
26
#include <subtotalparam.hxx>
27
28
#define ShellClass_ScTableShell
29
#include <scslots.hxx>
30
31
SFX_IMPL_INTERFACE(ScTableShell, SfxShell)
32
33
11
void ScTableShell::InitInterface_Impl() {}
34
35
ScTableShell::ScTableShell(ScTabViewShell* pViewShell)
36
0
    : SfxShell(pViewShell)
37
0
    , m_pViewShell(pViewShell)
38
0
{
39
0
    SetPool(&m_pViewShell->GetPool());
40
0
    ScViewData& rViewData = m_pViewShell->GetViewData();
41
0
    SfxUndoManager* pUndoManager = rViewData.GetSfxDocShell()->GetUndoManager();
42
0
    SetUndoManager(pUndoManager);
43
0
    if (!rViewData.GetDocument().IsUndoEnabled())
44
0
    {
45
0
        pUndoManager->SetMaxUndoActionCount(0);
46
0
    }
47
0
    SetName("Table");
48
0
    SfxShell::SetContextName(vcl::EnumContext::GetContextName(vcl::EnumContext::Context::Table));
49
0
}
50
51
0
ScTableShell::~ScTableShell() = default;
52
53
const ScDBData* ScTableShell::GetTableDBDataAtCursor()
54
0
{
55
0
    ScViewData& rViewData = m_pViewShell->GetViewData();
56
0
    const ScAddress aAddr = rViewData.GetCurPos();
57
0
    return rViewData.GetDocument().GetTableDBAtCursor(aAddr.Col(), aAddr.Row(), aAddr.Tab(),
58
0
                                                      ScDBDataPortion::AREA);
59
0
}
60
61
void ScTableShell::ExecuteDatabaseSettings(const SfxRequest& rReq)
62
0
{
63
0
    const SfxItemSet* pSet = rReq.GetArgs();
64
0
    sal_uInt16 nSlot = rReq.GetSlot();
65
0
    ScViewData& rViewData = m_pViewShell->GetViewData();
66
0
    SfxBindings& rBindings = rViewData.GetBindings();
67
68
0
    switch (nSlot)
69
0
    {
70
0
        case SID_DATABASE_SETTINGS:
71
0
        {
72
0
            const SfxPoolItem* pItem;
73
0
            SfxItemState eItemState = pSet->GetItemState(SCITEM_DATABASE_SETTING, true, &pItem);
74
0
            if (eItemState == SfxItemState::SET
75
0
                && dynamic_cast<const ScDatabaseSettingItem*>(pItem))
76
0
            {
77
0
                const ScDatabaseSettingItem* pDBItem
78
0
                    = static_cast<const ScDatabaseSettingItem*>(pItem);
79
0
                if (const ScDBData* pDBData = GetTableDBDataAtCursor())
80
0
                {
81
0
                    ScDBData aNewDBData(*pDBData);
82
0
                    aNewDBData.SetAutoFilter(pDBItem->HasShowFilters());
83
0
                    aNewDBData.SetHeader(pDBItem->HasHeaderRow());
84
0
                    aNewDBData.SetTotals(pDBItem->HasTotalRow());
85
86
0
                    ScTableStyleParam aNewParam(*pDBData->GetTableStyleInfo());
87
0
                    aNewParam.mbRowStripes = pDBItem->HasStripedRows();
88
0
                    aNewParam.mbColumnStripes = pDBItem->HasStripedCols();
89
0
                    aNewParam.mbFirstColumn = pDBItem->HasFirstCol();
90
0
                    aNewParam.mbLastColumn = pDBItem->HasLastCol();
91
0
                    aNewParam.maStyleID = pDBItem->GetStyleID();
92
0
                    aNewDBData.SetTableStyleInfo(aNewParam);
93
94
0
                    ScDBDocFunc aFunc(*rViewData.GetDocShell());
95
                    // Set new area if size changed
96
0
                    if (pDBData->HasTotals() != aNewDBData.HasTotals())
97
0
                    {
98
                        // Subtotals
99
0
                        ScSubTotalParam aSubTotalParam;
100
0
                        aNewDBData.GetSubTotalParam(aSubTotalParam);
101
0
                        aSubTotalParam.bHasHeader = aNewDBData.HasHeader();
102
103
0
                        if (!aNewDBData.HasTotals())
104
0
                        {
105
                            // store current subtotal settings before removing total row
106
0
                            pDBData->CreateTotalRowParam(aSubTotalParam);
107
0
                            aNewDBData.SetSubTotalParam(aSubTotalParam);
108
0
                            aSubTotalParam.bRemoveOnly = true;
109
0
                            aSubTotalParam.bReplace = true;
110
0
                            aFunc.DoTableSubTotals(aNewDBData.GetTab(), aNewDBData, aSubTotalParam,
111
0
                                                   true, false);
112
0
                        }
113
0
                        else
114
0
                        {
115
                            // add/replace total row
116
0
                            aSubTotalParam.bRemoveOnly = false;
117
0
                            aSubTotalParam.bReplace = false;
118
0
                            aFunc.DoTableSubTotals(aNewDBData.GetTab(), aNewDBData, aSubTotalParam,
119
0
                                                   true, false);
120
0
                        }
121
0
                    }
122
0
                    else
123
0
                    {
124
0
                        aFunc.ModifyDBData(aNewDBData);
125
0
                    }
126
0
                }
127
0
            }
128
0
        }
129
0
        break;
130
0
        case SID_REMOVE_CALCTABLE:
131
0
        {
132
0
            m_pViewShell->DeleteCalcTable();
133
0
        }
134
0
        break;
135
0
    }
136
137
0
    rBindings.Invalidate(SID_DATABASE_SETTINGS);
138
0
}
139
140
void ScTableShell::GetDatabaseSettings(SfxItemSet& rSet)
141
0
{
142
0
    SfxWhichIter aIter(rSet);
143
0
    sal_uInt16 nWhich = aIter.FirstWhich();
144
0
    while (nWhich)
145
0
    {
146
0
        switch (nWhich)
147
0
        {
148
0
            case SCITEM_DATABASE_SETTING:
149
0
            {
150
0
                if (const ScDBData* pDBData = GetTableDBDataAtCursor())
151
0
                {
152
0
                    const ScTableStyleParam* pParam = pDBData->GetTableStyleInfo();
153
0
                    rSet.Put(ScDatabaseSettingItem(pDBData->HasHeader(), pDBData->HasTotals(),
154
0
                                                   pParam->mbFirstColumn, pParam->mbLastColumn,
155
0
                                                   pParam->mbRowStripes, pParam->mbColumnStripes,
156
0
                                                   pDBData->HasAutoFilter(), pParam->maStyleID));
157
0
                }
158
0
            }
159
0
            break;
160
0
            case SID_REMOVE_CALCTABLE:
161
0
                break;
162
0
        }
163
0
        nWhich = aIter.NextWhich();
164
0
    }
165
0
}
166
167
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */