Coverage Report

Created: 2026-02-14 09:37

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sw/source/uibase/wrtsh/wrtundo.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 <svl/slstitm.hxx>
21
#include <rtl/ustrbuf.hxx>
22
#include <wrtsh.hxx>
23
#include <swundo.hxx>
24
#include <IDocumentUndoRedo.hxx>
25
#include <swdtflvr.hxx>
26
#include <svtools/svtresid.hxx>
27
#include <svtools/strings.hrc>
28
#include <osl/diagnose.h>
29
30
// Undo ends all modes. If a selection is emerged by the Undo,
31
// this must be considered for further action.
32
33
void SwWrtShell::Do(DoType eDoType, sal_uInt16 nCnt, sal_uInt16 nOffset)
34
0
{
35
    // #105332# save current state of DoesUndo()
36
0
    bool bSaveDoesUndo = DoesUndo();
37
38
0
    StartAllAction();
39
0
    switch (eDoType)
40
0
    {
41
0
        case UNDO:
42
0
            DoUndo(false); // #i21739#
43
            // Reset modes
44
0
            EnterStdMode();
45
0
            SwEditShell::Undo(nCnt, nOffset);
46
0
            break;
47
0
        case REDO:
48
0
            DoUndo(false); // #i21739#
49
            // Reset modes
50
0
            EnterStdMode();
51
0
            SwEditShell::Redo( nCnt );
52
0
            break;
53
0
        case REPEAT:
54
            // #i21739# do not touch undo flag here !!!
55
0
            SwEditShell::Repeat( nCnt );
56
0
            break;
57
0
    }
58
0
    EndAllAction();
59
    // #105332# restore undo state
60
0
    DoUndo(bSaveDoesUndo);
61
62
0
    bool bCreateXSelection = false;
63
0
    const bool bFrameSelected = IsFrameSelected() || GetSelectedObjCount();
64
0
    if ( IsSelection() )
65
0
    {
66
0
        if ( bFrameSelected )
67
0
            UnSelectFrame();
68
69
        // Set the function pointer for canceling the selection at the
70
        // cursor position.
71
0
        m_fnKillSel = &SwWrtShell::ResetSelect;
72
0
        m_fnSetCursor = &SwWrtShell::SetCursorKillSel;
73
0
        bCreateXSelection = true;
74
0
    }
75
0
    else if ( bFrameSelected )
76
0
    {
77
0
        EnterSelFrameMode();
78
0
        bCreateXSelection = true;
79
0
    }
80
0
    else if( (CNT_GRF | CNT_OLE ) & GetCntType() )
81
0
    {
82
0
        SelectObj( GetCharRect().Pos() );
83
0
        EnterSelFrameMode();
84
0
        bCreateXSelection = true;
85
0
    }
86
87
0
    if( bCreateXSelection )
88
0
        SwTransferable::CreateSelection( *this );
89
90
    // Bug 32918: After deleting of the numbering the object panel remains.
91
    //            Why is not here always a CallChgLink called?
92
0
    CallChgLnk();
93
0
}
94
95
OUString SwWrtShell::GetDoString( DoType eDoType ) const
96
0
{
97
0
    OUString aUndoStr;
98
0
    TranslateId pResStr = STR_UNDO;
99
0
    switch( eDoType )
100
0
    {
101
0
    case UNDO:
102
0
        pResStr = STR_UNDO;
103
0
        (void)GetLastUndoInfo(&aUndoStr, nullptr, &m_rView);
104
0
        break;
105
0
    case REDO:
106
0
        pResStr = STR_REDO;
107
0
        (void)GetFirstRedoInfo(&aUndoStr, nullptr, &m_rView);
108
0
        break;
109
0
    default:;//prevent warning
110
0
    }
111
112
0
    return SvtResId(pResStr) + aUndoStr;
113
0
}
114
115
void SwWrtShell::GetDoStrings( DoType eDoType, SfxStringListItem& rStrs ) const
116
0
{
117
0
    SwUndoComments_t comments;
118
0
    switch( eDoType )
119
0
    {
120
0
    case UNDO:
121
0
        comments = GetIDocumentUndoRedo().GetUndoComments();
122
0
        break;
123
0
    case REDO:
124
0
        comments = GetIDocumentUndoRedo().GetRedoComments();
125
0
        break;
126
0
    default:;//prevent warning
127
0
    }
128
129
0
    OUStringBuffer buf;
130
0
    for (const OUString & comment : comments)
131
0
    {
132
0
        OSL_ENSURE(!comment.isEmpty(), "no Undo/Redo Text set");
133
0
        buf.append(comment + "\n");
134
0
    }
135
0
    rStrs.SetString(buf.makeStringAndClear());
136
0
}
137
138
OUString SwWrtShell::GetRepeatString() const
139
0
{
140
0
    OUString str;
141
0
    GetRepeatInfo(& str);
142
143
0
    if (str.isEmpty())
144
0
    {
145
0
        return str;
146
0
    }
147
148
0
    return SvtResId(STR_REPEAT) + str;
149
0
}
150
151
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */