Coverage Report

Created: 2025-11-16 09:57

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sc/source/ui/undo/undoblk2.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
 * 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 <undoblk.hxx>
21
#include <document.hxx>
22
#include <docsh.hxx>
23
#include <tabvwsh.hxx>
24
#include <olinetab.hxx>
25
#include <globstr.hrc>
26
#include <scresid.hxx>
27
#include <global.hxx>
28
#include <target.hxx>
29
#include <columnspanset.hxx>
30
31
#include <undoolk.hxx>
32
33
#include <svx/svdundo.hxx>
34
35
/** Change column widths or row heights */
36
ScUndoWidthOrHeight::ScUndoWidthOrHeight( ScDocShell& rNewDocShell,
37
                const ScMarkData& rMark,
38
                SCCOLROW nNewStart, SCTAB nNewStartTab, SCCOLROW nNewEnd, SCTAB nNewEndTab,
39
                ScDocumentUniquePtr pNewUndoDoc, std::vector<sc::ColRowSpan>&& rRanges,
40
                std::unique_ptr<ScOutlineTable> pNewUndoTab,
41
                ScSizeMode eNewMode, sal_uInt16 nNewSizeTwips, bool bNewWidth ) :
42
0
    ScSimpleUndo( rNewDocShell ),
43
0
    aMarkData( rMark ),
44
0
    nStart( nNewStart ),
45
0
    nEnd( nNewEnd ),
46
0
    nStartTab( nNewStartTab ),
47
0
    nEndTab( nNewEndTab ),
48
0
    pUndoDoc( std::move(pNewUndoDoc) ),
49
0
    pUndoTab( std::move(pNewUndoTab) ),
50
0
    maRanges( std::move(rRanges) ),
51
0
    nNewSize( nNewSizeTwips ),
52
0
    bWidth( bNewWidth ),
53
0
    eMode( eNewMode )
54
0
{
55
0
    pDrawUndo = GetSdrUndoAction( &rDocShell.GetDocument() );
56
0
}
57
58
ScUndoWidthOrHeight::~ScUndoWidthOrHeight()
59
0
{
60
0
    pUndoDoc.reset();
61
0
    pUndoTab.reset();
62
0
    pDrawUndo.reset();
63
0
}
64
65
OUString ScUndoWidthOrHeight::GetComment() const
66
0
{
67
    // [ "optimal " ] "Column width" | "row height"
68
0
    return ( bWidth ?
69
0
        ( ( eMode == SC_SIZE_OPTIMAL )?
70
0
        ScResId( STR_UNDO_OPTCOLWIDTH ) :
71
0
        ScResId( STR_UNDO_COLWIDTH )
72
0
        ) :
73
0
        ( ( eMode == SC_SIZE_OPTIMAL )?
74
0
        ScResId( STR_UNDO_OPTROWHEIGHT ) :
75
0
        ScResId( STR_UNDO_ROWHEIGHT )
76
0
        ) );
77
0
}
78
79
void ScUndoWidthOrHeight::Undo()
80
0
{
81
0
    BeginUndo();
82
83
0
    ScDocument& rDoc = rDocShell.GetDocument();
84
85
0
    SCCOLROW nPaintStart = nStart > 0 ? nStart-1 : static_cast<SCCOLROW>(0);
86
87
0
    if (eMode==SC_SIZE_OPTIMAL)
88
0
    {
89
0
        if ( SetViewMarkData( aMarkData ) )
90
0
            nPaintStart = 0;        // paint all, because of changed selection
91
0
    }
92
93
    //! outlines from all tables?
94
0
    if (pUndoTab)                                           // Outlines are included when saving ?
95
0
        rDoc.SetOutlineTable( nStartTab, pUndoTab.get() );
96
97
0
    ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
98
0
    SCTAB nTabCount = rDoc.GetTableCount();
99
0
    for (const auto& rTab : aMarkData)
100
0
    {
101
0
        if (rTab >= nTabCount)
102
0
            break;
103
104
0
        if (pViewShell)
105
0
            pViewShell->OnLOKSetWidthOrHeight(nStart, bWidth);
106
107
0
        if (bWidth) // Width
108
0
        {
109
0
            pUndoDoc->CopyToDocument(static_cast<SCCOL>(nStart), 0, rTab,
110
0
                                     static_cast<SCCOL>(nEnd), rDoc.MaxRow(), rTab, InsertDeleteFlags::NONE,
111
0
                                     false, rDoc);
112
0
            rDoc.UpdatePageBreaks( rTab );
113
0
            rDocShell.PostPaint( static_cast<SCCOL>(nPaintStart), 0, rTab,
114
0
                    rDoc.MaxCol(), rDoc.MaxRow(), rTab, PaintPartFlags::Grid | PaintPartFlags::Top );
115
0
        }
116
0
        else        // Height
117
0
        {
118
0
            pUndoDoc->CopyToDocument(0, nStart, rTab, rDoc.MaxCol(), nEnd, rTab, InsertDeleteFlags::NONE, false, rDoc);
119
0
            rDoc.UpdatePageBreaks( rTab );
120
0
            rDocShell.PostPaint( 0, nPaintStart, rTab, rDoc.MaxCol(), rDoc.MaxRow(), rTab, PaintPartFlags::Grid | PaintPartFlags::Left );
121
0
        }
122
0
    }
123
124
0
    DoSdrUndoAction( pDrawUndo.get(), &rDoc );
125
126
0
    if (pViewShell)
127
0
    {
128
0
        SCTAB nCurrentTab = pViewShell->GetViewData().GetTabNumber();
129
0
        bool bAffectsVisibility = (eMode != SC_SIZE_ORIGINAL && eMode != SC_SIZE_VISOPT);
130
0
        ScTabViewShell::notifyAllViewsSheetGeomInvalidation(
131
0
                pViewShell, bWidth /* bColumns */, !bWidth /* bRows */,
132
0
                true /* bSizes*/, bAffectsVisibility /* bHidden */, bAffectsVisibility /* bFiltered */,
133
0
                false /* bGroups */, nCurrentTab);
134
0
        pViewShell->UpdateScrollBars(bWidth ? COLUMN_HEADER : ROW_HEADER);
135
136
0
        if ( nCurrentTab < nStartTab || nCurrentTab > nEndTab )
137
0
            pViewShell->SetTabNo( nStartTab );
138
0
    }
139
140
0
    EndUndo();
141
0
}
142
143
void ScUndoWidthOrHeight::Redo()
144
0
{
145
0
    BeginRedo();
146
147
0
    ScDocument& rDoc = rDocShell.GetDocument();
148
149
0
    bool bPaintAll = false;
150
0
    if (eMode==SC_SIZE_OPTIMAL)
151
0
    {
152
0
        if ( SetViewMarkData( aMarkData ) )
153
0
            bPaintAll = true;       // paint all, because of changed selection
154
0
    }
155
156
0
    ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
157
0
    if (pViewShell)
158
0
    {
159
0
        SCTAB nTab = pViewShell->GetViewData().GetTabNumber();
160
0
        if ( nTab < nStartTab || nTab > nEndTab )
161
0
            pViewShell->SetTabNo( nStartTab );
162
163
        // SetWidthOrHeight changes current sheet!
164
0
        pViewShell->SetWidthOrHeight(
165
0
            bWidth, maRanges, eMode, nNewSize, false, &aMarkData);
166
0
    }
167
168
    // paint grid if selection was changed directly at the MarkData
169
0
    if (bPaintAll)
170
0
        rDocShell.PostPaint( 0, 0, nStartTab, rDoc.MaxCol(), rDoc.MaxRow(), nEndTab, PaintPartFlags::Grid );
171
172
0
    EndRedo();
173
0
}
174
175
void ScUndoWidthOrHeight::Repeat(SfxRepeatTarget& rTarget)
176
0
{
177
0
    if (auto pViewTarget = dynamic_cast<ScTabViewTarget*>( &rTarget))
178
0
        pViewTarget->GetViewShell().SetMarkedWidthOrHeight( bWidth, eMode, nNewSize );
179
0
}
180
181
bool ScUndoWidthOrHeight::CanRepeat(SfxRepeatTarget& rTarget) const
182
0
{
183
0
    return dynamic_cast<const ScTabViewTarget*>( &rTarget) !=  nullptr;
184
0
}
185
186
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */