tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sc / source / ui / miscdlgs / highred.cxx
blobe207c2b5cf79424afe3dfbc3f94024b92a1d90f0
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <reffact.hxx>
21 #include <document.hxx>
22 #include <docsh.hxx>
23 #include <chgtrack.hxx>
25 #include <highred.hxx>
28 ScHighlightChgDlg::ScHighlightChgDlg(SfxBindings* pB, SfxChildWindow* pCW, weld::Window* pParent,
29 ScViewData& rViewData)
30 : ScAnyRefDlgController(pB, pCW, pParent, u"modules/scalc/ui/showchangesdialog.ui"_ustr, u"ShowChangesDialog"_ustr)
31 , m_rViewData(rViewData)
32 , rDoc(rViewData.GetDocument())
33 , m_xHighlightBox(m_xBuilder->weld_check_button(u"showchanges"_ustr))
34 , m_xCbAccept(m_xBuilder->weld_check_button(u"showaccepted"_ustr))
35 , m_xCbReject(m_xBuilder->weld_check_button(u"showrejected"_ustr))
36 , m_xOkButton(m_xBuilder->weld_button(u"ok"_ustr))
37 , m_xEdAssign(new formula::RefEdit(m_xBuilder->weld_entry(u"range"_ustr)))
38 , m_xRbAssign(new formula::RefButton(m_xBuilder->weld_button(u"rangeref"_ustr)))
39 , m_xBox(m_xBuilder->weld_container(u"box"_ustr))
40 , m_xFilterCtr(new SvxTPFilter(m_xBox.get()))
42 m_xEdAssign->SetReferences(this, nullptr);
43 m_xRbAssign->SetReferences(this, m_xEdAssign.get());
45 m_xOkButton->connect_clicked(LINK( this, ScHighlightChgDlg, OKBtnHdl));
46 m_xHighlightBox->connect_toggled(LINK( this, ScHighlightChgDlg, HighlightHandle ));
47 m_xFilterCtr->SetRefHdl(LINK( this, ScHighlightChgDlg, RefHandle ));
48 m_xFilterCtr->HideRange(false);
49 m_xFilterCtr->Show();
50 SetDispatcherLock( true );
52 Init();
55 ScHighlightChgDlg::~ScHighlightChgDlg()
57 SetDispatcherLock( false );
60 void ScHighlightChgDlg::Init()
62 ScChangeTrack* pChanges = rDoc.GetChangeTrack();
63 if(pChanges!=nullptr)
65 aChangeViewSet.SetTheAuthorToShow(pChanges->GetUser());
66 m_xFilterCtr->ClearAuthors();
67 const std::set<OUString>& rUserColl = pChanges->GetUserCollection();
68 for (const auto& rItem : rUserColl)
69 m_xFilterCtr->InsertAuthor(rItem);
72 ScChangeViewSettings* pViewSettings = rDoc.GetChangeViewSettings();
74 if(pViewSettings!=nullptr)
75 aChangeViewSet=*pViewSettings;
76 m_xHighlightBox->set_active(aChangeViewSet.ShowChanges());
77 m_xFilterCtr->CheckDate(aChangeViewSet.HasDate());
79 DateTime aEmpty(DateTime::EMPTY);
81 DateTime aDateTime(aChangeViewSet.GetTheFirstDateTime());
82 if (aDateTime != aEmpty)
84 m_xFilterCtr->SetFirstDate(aDateTime);
85 m_xFilterCtr->SetFirstTime(aDateTime);
87 aDateTime = aChangeViewSet.GetTheLastDateTime();
88 if (aDateTime != aEmpty)
90 m_xFilterCtr->SetLastDate(aDateTime);
91 m_xFilterCtr->SetLastTime(aDateTime);
94 m_xFilterCtr->SetDateMode(static_cast<sal_uInt16>(aChangeViewSet.GetTheDateMode()));
95 m_xFilterCtr->CheckAuthor(aChangeViewSet.HasAuthor());
96 m_xFilterCtr->CheckComment(aChangeViewSet.HasComment());
97 m_xFilterCtr->SetComment(aChangeViewSet.GetTheComment());
99 m_xCbAccept->set_active(aChangeViewSet.IsShowAccepted());
100 m_xCbReject->set_active(aChangeViewSet.IsShowRejected());
102 OUString aString=aChangeViewSet.GetTheAuthorToShow();
103 if(!aString.isEmpty())
105 m_xFilterCtr->SelectAuthor(aString);
107 else
109 m_xFilterCtr->SelectedAuthorPos(0);
112 m_xFilterCtr->CheckRange(aChangeViewSet.HasRange());
114 if ( !aChangeViewSet.GetTheRangeList().empty() )
116 const ScRange & rRangeEntry = aChangeViewSet.GetTheRangeList().front();
117 OUString aRefStr(rRangeEntry.Format(rDoc, ScRefFlags::RANGE_ABS_3D));
118 m_xFilterCtr->SetRange(aRefStr);
120 m_xFilterCtr->Enable(true);
121 HighlightHandle(*m_xHighlightBox);
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 )
128 if (m_xEdAssign->GetWidget()->get_visible())
130 if ( rRef.aStart != rRef.aEnd )
131 RefInputStart(m_xEdAssign.get());
132 OUString aRefStr(rRef.Format(rDocP, ScRefFlags::RANGE_ABS_3D, rDocP.GetAddressConvention()));
133 m_xEdAssign->SetRefString( aRefStr );
134 m_xFilterCtr->SetRange(aRefStr);
138 void ScHighlightChgDlg::Close()
140 DoClose( ScHighlightChgDlgWrapper::GetChildWindowId() );
143 void ScHighlightChgDlg::RefInputDone( bool bForced)
145 ScAnyRefDlgController::RefInputDone(bForced);
146 if (bForced || !m_xRbAssign->GetWidget()->get_visible())
148 m_xFilterCtr->SetRange(m_xEdAssign->GetText());
149 m_xFilterCtr->SetFocusToRange();
150 m_xEdAssign->GetWidget()->hide();
151 m_xRbAssign->GetWidget()->hide();
155 void ScHighlightChgDlg::SetActive()
159 bool ScHighlightChgDlg::IsRefInputMode() const
161 return m_xEdAssign->GetWidget()->get_visible();
164 IMPL_LINK_NOARG(ScHighlightChgDlg, HighlightHandle, weld::Toggleable&, void)
166 if (m_xHighlightBox->get_active())
168 m_xFilterCtr->Enable(true);
169 m_xCbAccept->set_sensitive(true);
170 m_xCbReject->set_sensitive(true);
172 else
174 m_xFilterCtr->Enable(false);
175 m_xCbAccept->set_sensitive(false);
176 m_xCbReject->set_sensitive(false);
180 IMPL_LINK( ScHighlightChgDlg, RefHandle, SvxTPFilter*, pRef, void )
182 if(pRef!=nullptr)
184 SetDispatcherLock( true );
185 m_xEdAssign->GetWidget()->show();
186 m_xRbAssign->GetWidget()->show();
187 m_xEdAssign->SetText(m_xFilterCtr->GetRange());
188 m_xEdAssign->GrabFocus();
189 ScAnyRefDlgController::RefInputStart(m_xEdAssign.get(), m_xRbAssign.get());
193 IMPL_LINK_NOARG(ScHighlightChgDlg, OKBtnHdl, weld::Button&, void)
195 aChangeViewSet.SetShowChanges(m_xHighlightBox->get_active());
196 aChangeViewSet.SetHasDate(m_xFilterCtr->IsDate());
197 SvxRedlinDateMode eMode = m_xFilterCtr->GetDateMode();
198 aChangeViewSet.SetTheDateMode( eMode );
199 Date aFirstDate( m_xFilterCtr->GetFirstDate() );
200 tools::Time aFirstTime( m_xFilterCtr->GetFirstTime() );
201 Date aLastDate( m_xFilterCtr->GetLastDate() );
202 tools::Time aLastTime( m_xFilterCtr->GetLastTime() );
203 aChangeViewSet.SetTheFirstDateTime( DateTime( aFirstDate, aFirstTime ) );
204 aChangeViewSet.SetTheLastDateTime( DateTime( aLastDate, aLastTime ) );
205 aChangeViewSet.SetHasAuthor(m_xFilterCtr->IsAuthor());
206 aChangeViewSet.SetTheAuthorToShow(m_xFilterCtr->GetSelectedAuthor());
207 aChangeViewSet.SetHasRange(m_xFilterCtr->IsRange());
208 aChangeViewSet.SetShowAccepted(m_xCbAccept->get_active());
209 aChangeViewSet.SetShowRejected(m_xCbReject->get_active());
210 aChangeViewSet.SetHasComment(m_xFilterCtr->IsComment());
211 aChangeViewSet.SetTheComment(m_xFilterCtr->GetComment());
212 ScRangeList aLocalRangeList;
213 aLocalRangeList.Parse(m_xFilterCtr->GetRange(), rDoc);
214 aChangeViewSet.SetTheRangeList(aLocalRangeList);
215 aChangeViewSet.AdjustDateMode( rDoc );
216 rDoc.SetChangeViewSettings(aChangeViewSet);
217 m_rViewData.GetDocShell()->PostPaintGridAll();
218 response(RET_OK);
221 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */