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/miscdlgs/highred.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 <reffact.hxx>
21
#include <document.hxx>
22
#include <docsh.hxx>
23
#include <chgtrack.hxx>
24
25
#include <highred.hxx>
26
27
28
ScHighlightChgDlg::ScHighlightChgDlg(SfxBindings* pB, SfxChildWindow* pCW, weld::Window* pParent,
29
                                     ScViewData& rViewData)
30
0
    : ScAnyRefDlgController(pB, pCW, pParent, u"modules/scalc/ui/showchangesdialog.ui"_ustr, u"ShowChangesDialog"_ustr)
31
0
    , m_rViewData(rViewData)
32
0
    , rDoc(rViewData.GetDocument())
33
0
    , m_xHighlightBox(m_xBuilder->weld_check_button(u"showchanges"_ustr))
34
0
    , m_xCbAccept(m_xBuilder->weld_check_button(u"showaccepted"_ustr))
35
0
    , m_xCbReject(m_xBuilder->weld_check_button(u"showrejected"_ustr))
36
0
    , m_xOkButton(m_xBuilder->weld_button(u"ok"_ustr))
37
0
    , m_xEdAssign(new formula::RefEdit(m_xBuilder->weld_entry(u"range"_ustr)))
38
0
    , m_xRbAssign(new formula::RefButton(m_xBuilder->weld_button(u"rangeref"_ustr)))
39
0
    , m_xBox(m_xBuilder->weld_container(u"box"_ustr))
40
0
    , m_xFilterCtr(new SvxTPFilter(m_xBox.get()))
41
0
{
42
0
    m_xEdAssign->SetReferences(this);
43
0
    m_xRbAssign->SetReferences(this, m_xEdAssign.get());
44
45
0
    m_xOkButton->connect_clicked(LINK( this, ScHighlightChgDlg, OKBtnHdl));
46
0
    m_xHighlightBox->connect_toggled(LINK( this, ScHighlightChgDlg, HighlightHandle ));
47
0
    m_xFilterCtr->SetRefHdl(LINK( this, ScHighlightChgDlg, RefHandle ));
48
0
    m_xFilterCtr->HideRange(false);
49
0
    m_xFilterCtr->Show();
50
0
    SetDispatcherLock( true );
51
52
0
    Init();
53
0
}
54
55
ScHighlightChgDlg::~ScHighlightChgDlg()
56
0
{
57
0
    SetDispatcherLock( false );
58
0
}
59
60
void ScHighlightChgDlg::Init()
61
0
{
62
0
    ScChangeTrack* pChanges = rDoc.GetChangeTrack();
63
0
    if(pChanges!=nullptr)
64
0
    {
65
0
        aChangeViewSet.SetTheAuthorToShow(pChanges->GetUser());
66
0
        m_xFilterCtr->ClearAuthors();
67
0
        const std::set<OUString>& rUserColl = pChanges->GetUserCollection();
68
0
        for (const auto& rItem : rUserColl)
69
0
            m_xFilterCtr->InsertAuthor(rItem);
70
0
    }
71
72
0
    ScChangeViewSettings* pViewSettings = rDoc.GetChangeViewSettings();
73
74
0
    if(pViewSettings!=nullptr)
75
0
        aChangeViewSet=*pViewSettings;
76
0
    m_xHighlightBox->set_active(aChangeViewSet.ShowChanges());
77
0
    m_xFilterCtr->CheckDate(aChangeViewSet.HasDate());
78
79
0
    DateTime aEmpty(DateTime::EMPTY);
80
81
0
    DateTime aDateTime(aChangeViewSet.GetTheFirstDateTime());
82
0
    if (aDateTime != aEmpty)
83
0
    {
84
0
        m_xFilterCtr->SetFirstDate(aDateTime);
85
0
        m_xFilterCtr->SetFirstTime(aDateTime);
86
0
    }
87
0
    aDateTime = aChangeViewSet.GetTheLastDateTime();
88
0
    if (aDateTime != aEmpty)
89
0
    {
90
0
        m_xFilterCtr->SetLastDate(aDateTime);
91
0
        m_xFilterCtr->SetLastTime(aDateTime);
92
0
    }
93
94
0
    m_xFilterCtr->SetDateMode(static_cast<sal_uInt16>(aChangeViewSet.GetTheDateMode()));
95
0
    m_xFilterCtr->CheckAuthor(aChangeViewSet.HasAuthor());
96
0
    m_xFilterCtr->CheckComment(aChangeViewSet.HasComment());
97
0
    m_xFilterCtr->SetComment(aChangeViewSet.GetTheComment());
98
99
0
    m_xCbAccept->set_active(aChangeViewSet.IsShowAccepted());
100
0
    m_xCbReject->set_active(aChangeViewSet.IsShowRejected());
101
102
0
    OUString aString=aChangeViewSet.GetTheAuthorToShow();
103
0
    if(!aString.isEmpty())
104
0
    {
105
0
        m_xFilterCtr->SelectAuthor(aString);
106
0
    }
107
0
    else
108
0
    {
109
0
        m_xFilterCtr->SelectedAuthorPos(0);
110
0
    }
111
112
0
    m_xFilterCtr->CheckRange(aChangeViewSet.HasRange());
113
114
0
    if ( !aChangeViewSet.GetTheRangeList().empty() )
115
0
    {
116
0
        const ScRange & rRangeEntry = aChangeViewSet.GetTheRangeList().front();
117
0
        OUString aRefStr(rRangeEntry.Format(rDoc, ScRefFlags::RANGE_ABS_3D));
118
0
        m_xFilterCtr->SetRange(aRefStr);
119
0
    }
120
0
    m_xFilterCtr->Enable(true);
121
0
    HighlightHandle(*m_xHighlightBox);
122
0
}
123
124
// Set the reference to a cell range selected with the mouse. This is then
125
// shown as the new selection in the reference field.
126
void ScHighlightChgDlg::SetReference( const ScRange& rRef, ScDocument& rDocP )
127
0
{
128
0
    if (m_xEdAssign->GetWidget()->get_visible())
129
0
    {
130
0
        if ( rRef.aStart != rRef.aEnd )
131
0
            RefInputStart(m_xEdAssign.get());
132
0
        OUString aRefStr(rRef.Format(rDocP, ScRefFlags::RANGE_ABS_3D, rDocP.GetAddressConvention()));
133
0
        m_xEdAssign->SetRefString( aRefStr );
134
0
        m_xFilterCtr->SetRange(aRefStr);
135
0
    }
136
0
}
137
138
void ScHighlightChgDlg::Close()
139
0
{
140
0
    DoClose( ScHighlightChgDlgWrapper::GetChildWindowId() );
141
0
}
142
143
void ScHighlightChgDlg::RefInputDone( bool bForced)
144
0
{
145
0
    ScAnyRefDlgController::RefInputDone(bForced);
146
0
    if (bForced || !m_xRbAssign->GetWidget()->get_visible())
147
0
    {
148
0
        m_xFilterCtr->SetRange(m_xEdAssign->GetText());
149
0
        m_xFilterCtr->SetFocusToRange();
150
0
        m_xEdAssign->GetWidget()->hide();
151
0
        m_xRbAssign->GetWidget()->hide();
152
0
    }
153
0
}
154
155
void ScHighlightChgDlg::SetActive()
156
0
{
157
0
}
158
159
bool ScHighlightChgDlg::IsRefInputMode() const
160
0
{
161
0
    return m_xEdAssign->GetWidget()->get_visible();
162
0
}
163
164
IMPL_LINK_NOARG(ScHighlightChgDlg, HighlightHandle, weld::Toggleable&, void)
165
0
{
166
0
    if (m_xHighlightBox->get_active())
167
0
    {
168
0
        m_xFilterCtr->Enable(true);
169
0
        m_xCbAccept->set_sensitive(true);
170
0
        m_xCbReject->set_sensitive(true);
171
0
    }
172
0
    else
173
0
    {
174
0
        m_xFilterCtr->Enable(false);
175
0
        m_xCbAccept->set_sensitive(false);
176
0
        m_xCbReject->set_sensitive(false);
177
0
    }
178
0
}
179
180
IMPL_LINK( ScHighlightChgDlg, RefHandle, SvxTPFilter*, pRef, void )
181
0
{
182
0
    if(pRef!=nullptr)
183
0
    {
184
0
        SetDispatcherLock( true );
185
0
        m_xEdAssign->GetWidget()->show();
186
0
        m_xRbAssign->GetWidget()->show();
187
0
        m_xEdAssign->SetText(m_xFilterCtr->GetRange());
188
0
        m_xEdAssign->GrabFocus();
189
0
        ScAnyRefDlgController::RefInputStart(m_xEdAssign.get(), m_xRbAssign.get());
190
0
    }
191
0
}
192
193
IMPL_LINK_NOARG(ScHighlightChgDlg, OKBtnHdl, weld::Button&, void)
194
0
{
195
0
    aChangeViewSet.SetShowChanges(m_xHighlightBox->get_active());
196
0
    aChangeViewSet.SetHasDate(m_xFilterCtr->IsDate());
197
0
    SvxRedlineDateMode eMode = m_xFilterCtr->GetDateMode();
198
0
    aChangeViewSet.SetTheDateMode( eMode );
199
0
    Date aFirstDate( m_xFilterCtr->GetFirstDate() );
200
0
    tools::Time aFirstTime( m_xFilterCtr->GetFirstTime() );
201
0
    Date aLastDate( m_xFilterCtr->GetLastDate() );
202
0
    tools::Time aLastTime( m_xFilterCtr->GetLastTime() );
203
0
    aChangeViewSet.SetTheFirstDateTime( DateTime( aFirstDate, aFirstTime ) );
204
0
    aChangeViewSet.SetTheLastDateTime( DateTime( aLastDate, aLastTime ) );
205
0
    aChangeViewSet.SetHasAuthor(m_xFilterCtr->IsAuthor());
206
0
    aChangeViewSet.SetTheAuthorToShow(m_xFilterCtr->GetSelectedAuthor());
207
0
    aChangeViewSet.SetHasRange(m_xFilterCtr->IsRange());
208
0
    aChangeViewSet.SetShowAccepted(m_xCbAccept->get_active());
209
0
    aChangeViewSet.SetShowRejected(m_xCbReject->get_active());
210
0
    aChangeViewSet.SetHasComment(m_xFilterCtr->IsComment());
211
0
    aChangeViewSet.SetTheComment(m_xFilterCtr->GetComment());
212
0
    ScRangeList aLocalRangeList;
213
0
    aLocalRangeList.Parse(m_xFilterCtr->GetRange(), rDoc);
214
0
    aChangeViewSet.SetTheRangeList(aLocalRangeList);
215
0
    aChangeViewSet.AdjustDateMode( rDoc );
216
0
    rDoc.SetChangeViewSettings(aChangeViewSet);
217
0
    m_rViewData.GetDocShell()->PostPaintGridAll();
218
0
    response(RET_OK);
219
0
}
220
221
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */