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