LibreOffice Module sw (master) 1
redlndlg.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 <redline.hxx>
21#include <tools/datetime.hxx>
22#include <tools/lineend.hxx>
23#include <svl/eitem.hxx>
24#include <sfx2/viewfrm.hxx>
25#include <sfx2/dispatch.hxx>
26#include <svx/ctredlin.hxx>
27#include <svx/postattr.hxx>
28#include <utility>
29#include <vcl/commandevent.hxx>
30#include <swtypes.hxx>
31#include <wrtsh.hxx>
32#include <view.hxx>
33#include <swmodule.hxx>
34#include <redlndlg.hxx>
35#include <swwait.hxx>
36#include <uitool.hxx>
37#include <o3tl/string_view.hxx>
38
39#include <cmdid.h>
40#include <strings.hrc>
41
42// -> #111827#
43#include <swundo.hxx>
44#include <SwRewriter.hxx>
45// <- #111827#
46
47#include <vector>
48#include <svx/svxdlg.hxx>
49#include <osl/diagnose.h>
50#include <bitmaps.hlst>
51
52#include <docsh.hxx>
53
55#include <usrpref.hxx>
56#include <memory>
57
59
61 sal_uInt16 nId,
62 SfxBindings* pBindings,
63 SfxChildWinInfo* pInfo)
64 : SwChildWinWrapper(_pParent, nId)
65{
66 auto xDlg = std::make_shared<SwModelessRedlineAcceptDlg>(pBindings, this, _pParent->GetFrameWeld());
67 SetController(xDlg);
68 xDlg->Initialize(pInfo);
69}
70
71// newly initialise dialog after document switch
73{
74 bool bRet = SwChildWinWrapper::ReInitDlg(pDocSh);
75 if (bRet) // update immediately, doc switch!
76 static_cast<SwModelessRedlineAcceptDlg*>(GetController().get())->Activate();
77
78 return bRet;
79}
80
82 SfxBindings* _pBindings, SwChildWinWrapper* pChild, weld::Window *pParent)
83 : SfxModelessDialogController(_pBindings, pChild, pParent,
84 "svx/ui/acceptrejectchangesdialog.ui", "AcceptRejectChangesDialog")
85 , m_xContentArea(m_xDialog->weld_content_area())
86 , m_pChildWin(pChild)
87{
88 m_xImplDlg.reset(new SwRedlineAcceptDlg(m_xDialog, m_xBuilder.get(), m_xContentArea.get()));
89}
90
92{
93 SwView *pView = ::GetActiveView();
94 if (!pView) // can happen when switching to another app, when a Listbox in dialog
95 return; // had the focus previously (actually THs Bug)
96
97 SwDocShell *pDocSh = pView->GetDocShell();
98
99 if (m_pChildWin->GetOldDocShell() != pDocSh)
100 { // doc-switch
101 SwWait aWait( *pDocSh, false );
102 SwWrtShell* pSh = pView->GetWrtShellPtr();
103
104 m_pChildWin->SetOldDocShell(pDocSh); // avoid recursion (using modified-Hdl)
105
106 bool bMod = pSh->IsModified();
107 SfxBoolItem aShow(FN_REDLINE_SHOW, true);
109 FN_REDLINE_SHOW, SfxCallMode::SYNCHRON|SfxCallMode::RECORD,
110 { &aShow });
111 if (!bMod)
112 pSh->ResetModified();
113 m_xImplDlg->Init();
115
116 return;
117 }
118
120 m_xImplDlg->Activate();
121}
122
124{
125 if (pInfo != nullptr)
126 m_xImplDlg->Initialize(pInfo->aExtraString);
127
129}
130
132{
134 m_xImplDlg->FillInfo(rInfo.aExtraString);
135}
136
138{
139}
140
141SwRedlineAcceptDlg::SwRedlineAcceptDlg(std::shared_ptr<weld::Window> xParent, weld::Builder *pBuilder,
142 weld::Container *pContentArea, bool bAutoFormat)
143 : m_xParentDlg(std::move(xParent))
144 , m_aSelectTimer("SwRedlineAcceptDlg m_aSelectTimer")
145 , m_sInserted(SwResId(STR_REDLINE_INSERTED))
146 , m_sDeleted(SwResId(STR_REDLINE_DELETED))
147 , m_sFormated(SwResId(STR_REDLINE_FORMATTED))
148 , m_sTableChgd(SwResId(STR_REDLINE_TABLECHG))
149 , m_sFormatCollSet(SwResId(STR_REDLINE_FMTCOLLSET))
150 , m_sAutoFormat(SwResId(STR_REDLINE_AUTOFMT))
151 , m_bOnlyFormatedRedlines(false)
152 , m_bRedlnAutoFormat(bAutoFormat)
153 , m_bInhibitActivate(false)
154 , m_xTabPagesCTRL(new SvxAcceptChgCtr(pContentArea))
155 , m_xPopup(pBuilder->weld_menu("writermenu"))
156 , m_xSortMenu(pBuilder->weld_menu("writersortmenu"))
157{
158 m_pTPView = m_xTabPagesCTRL->GetViewPage();
159
162
168 //tdf#89227 default to disabled, and only enable if possible to accept/reject
169 m_pTPView->EnableAccept(false);
170 m_pTPView->EnableReject(false);
175
176 m_xTabPagesCTRL->GetFilterPage()->SetReadyHdl(LINK(this, SwRedlineAcceptDlg, FilterChangedHdl));
177
178 weld::ComboBox* pActLB = m_xTabPagesCTRL->GetFilterPage()->GetLbAction();
179 pActLB->append_text(m_sInserted);
180 pActLB->append_text(m_sDeleted);
181 pActLB->append_text(m_sFormated);
182 pActLB->append_text(m_sTableChgd);
183
185 {
187 pActLB->append_text(m_sAutoFormat);
189 m_pTPView->DisableUndo(); // no UNDO events yet
190 }
191
192 pActLB->set_active(0);
193
194 weld::TreeView& rTreeView = m_pTable->GetWidget();
195 rTreeView.set_selection_mode(SelectionMode::Multiple);
196
197 rTreeView.connect_changed(LINK(this, SwRedlineAcceptDlg, SelectHdl));
198 rTreeView.connect_popup_menu(LINK(this, SwRedlineAcceptDlg, CommandHdl));
199
200 // avoid multiple selection of the same texts:
203}
204
206{
207}
208
210{
211 SwView *pView = ::GetActiveView();
212 std::optional<SwWait> oWait;
213 if (pView)
214 oWait.emplace(*pView->GetDocShell(), false);
215 weld::TreeView& rTreeView = m_pTable->GetWidget();
217
218 rTreeView.freeze();
219 if (nStart)
220 RemoveParents(nStart, m_RedlineParents.size() - 1);
221 else
222 {
223 rTreeView.clear();
224 m_RedlinData.clear();
225 m_RedlineChildren.clear();
226 m_RedlineParents.erase(m_RedlineParents.begin() + nStart, m_RedlineParents.end());
227 }
228 rTreeView.thaw();
229
230 // insert parents
231 InsertParents(nStart);
232 InitAuthors();
233
234 // #i69618# this moves the list box to the right position, visually
235 std::unique_ptr<weld::TreeIter> xSelEntry(rTreeView.make_iterator());
236 if (rTreeView.get_selected(xSelEntry.get()))
237 rTreeView.scroll_to_row(*xSelEntry); //#i70937#, force the scroll
238}
239
241{
242 if (!m_xTabPagesCTRL)
243 return;
244
245 SwView *pView = ::GetActiveView();
246 SwWrtShell* pSh = pView ? pView->GetWrtShellPtr() : nullptr;
247
248 SvxTPFilter *pFilterPage = m_xTabPagesCTRL->GetFilterPage();
249
250 std::vector<OUString> aStrings;
251 OUString sOldAuthor(pFilterPage->GetSelectedAuthor());
252 pFilterPage->ClearAuthors();
253
255
257 bool bIsNotFormated = false;
258
259 // determine authors
260 for ( SwRedlineTable::size_type i = 0; i < nCount; i++)
261 {
262 const SwRangeRedline& rRedln = pSh->GetRedline(i);
263
264 if( m_bOnlyFormatedRedlines && RedlineType::Format != rRedln.GetType() )
266
267 aStrings.push_back(rRedln.GetAuthorString());
268
269 for (sal_uInt16 nStack = 1; nStack < rRedln.GetStackCount(); nStack++)
270 {
271 aStrings.push_back(rRedln.GetAuthorString(nStack));
272 }
273 }
274
275 std::sort(aStrings.begin(), aStrings.end());
276 aStrings.erase(std::unique(aStrings.begin(), aStrings.end()), aStrings.end());
277
278 for (auto const & i: aStrings)
279 pFilterPage->InsertAuthor(i);
280
281 if (pFilterPage->SelectAuthor(sOldAuthor) == -1 && !aStrings.empty())
282 pFilterPage->SelectAuthor(aStrings[0]);
283
284 weld::TreeView& rTreeView = m_pTable->GetWidget();
285 bool const bEnable = pSh && !pSh->GetDoc()->GetDocShell()->IsReadOnly()
286 && rTreeView.n_children() != 0
287 && !pSh->getIDocumentRedlineAccess().GetRedlinePassword().hasElements();
288 bool bSel = rTreeView.get_selected(nullptr);
289
290 rTreeView.selected_foreach([this, pSh, &bIsNotFormated](weld::TreeIter& rEntry){
291 // find the selected redline
292 // (fdo#57874: ignore, if the redline is already gone)
295 {
296 const SwRangeRedline& rRedln = pSh->GetRedline( nPos );
297
298 bIsNotFormated |= RedlineType::Format != rRedln.GetType();
299 }
300 return false;
301 });
302
303 m_pTPView->EnableAccept( bEnable && bSel );
304 m_pTPView->EnableReject( bEnable && bSel );
305 m_pTPView->EnableClearFormat( bEnable && !bIsNotFormated && bSel );
306 m_pTPView->EnableAcceptAll( bEnable );
307 m_pTPView->EnableRejectAll( bEnable );
310}
311
312OUString SwRedlineAcceptDlg::GetActionImage(const SwRangeRedline& rRedln, sal_uInt16 nStack, bool bRowChanges)
313{
314 switch (rRedln.GetType(nStack))
315 {
316 case RedlineType::Insert: return bRowChanges
317 ? OUString(BMP_REDLINE_ROW_INSERTION)
318 : rRedln.IsMoved()
319 ? OUString(BMP_REDLINE_MOVED_INSERTION)
320 : rRedln.IsAnnotation()
321 ? OUString(BMP_REDLINE_COMMENT_INSERTION)
322 : OUString(BMP_REDLINE_INSERTED);
323 case RedlineType::Delete: return bRowChanges
324 ? OUString(BMP_REDLINE_ROW_DELETION)
325 : rRedln.IsMoved()
326 ? OUString(BMP_REDLINE_MOVED_DELETION)
327 : rRedln.IsAnnotation()
328 ? OUString(BMP_REDLINE_COMMENT_DELETION)
329 : OUString(BMP_REDLINE_DELETED);
330 case RedlineType::Format: return BMP_REDLINE_FORMATTED;
331 case RedlineType::ParagraphFormat: return BMP_REDLINE_FORMATTED;
332 case RedlineType::Table: return BMP_REDLINE_TABLECHG;
333 case RedlineType::FmtColl: return BMP_REDLINE_FMTCOLLSET;
334 default: break;
335 }
336
337 return OUString();
338}
339
340OUString SwRedlineAcceptDlg::GetActionText(const SwRangeRedline& rRedln, sal_uInt16 nStack)
341{
342 switch( rRedln.GetType(nStack) )
343 {
344 case RedlineType::Insert: return m_sInserted;
345 case RedlineType::Delete: return m_sDeleted;
346 case RedlineType::Format: return m_sFormated;
347 case RedlineType::ParagraphFormat: return m_sFormated;
348 case RedlineType::Table: return m_sTableChgd;
349 case RedlineType::FmtColl: return m_sFormatCollSet;
350 default:;//prevent warning
351 }
352
353 return OUString();
354}
355
356// newly initialise after activation
358{
359 // prevent update if flag is set (#102547#)
361 return;
362
363 SwView *pView = ::GetActiveView();
364 if (!pView) // can happen when switching to another app
365 {
366 m_pTPView->EnableAccept(false);
367 m_pTPView->EnableReject(false);
372 return; // had the focus previously
373 }
374
375 SwWait aWait( *pView->GetDocShell(), false );
376
377 if (pView->GetDocShell()->IsReadOnly())
378 {
379 m_pTPView->EnableAccept(false);
380 m_pTPView->EnableReject(false);
385 // note: enabling is done in InitAuthors below
386 }
387
389
390 // did something change?
391 SwWrtShell* pSh = pView->GetWrtShellPtr();
393
394 // check the number of pointers
395 for ( SwRedlineTable::size_type i = 0; i < nCount; i++)
396 {
397 const SwRangeRedline& rRedln = pSh->GetRedline(i);
398
399 if (i >= m_RedlineParents.size())
400 {
401 // new entries have been appended
402 Init(i);
403 return;
404 }
405
406 SwRedlineDataParent *const pParent = m_RedlineParents[i].get();
407 if (&rRedln.GetRedlineData() != pParent->pData)
408 {
409 // Redline-Parents were inserted, changed or deleted
410 i = CalcDiff(i, false);
411 if (i == SwRedlineTable::npos)
412 return;
413 continue;
414 }
415
416 const SwRedlineData *pRedlineData = rRedln.GetRedlineData().Next();
417 const SwRedlineDataChild *pBackupData = pParent->pNext;
418
419 if (!pRedlineData && pBackupData)
420 {
421 // Redline-Children were deleted
422 i = CalcDiff(i, true);
423 if (i == SwRedlineTable::npos)
424 return;
425 continue;
426 }
427 else
428 {
429 while (pRedlineData)
430 {
431 if (pRedlineData != pBackupData->pChild)
432 {
433 // Redline-Children were inserted, changed or deleted
434 i = CalcDiff(i, true);
435 if (i == SwRedlineTable::npos)
436 return;
437 continue;
438 }
439 pBackupData = pBackupData->pNext;
440 pRedlineData = pRedlineData->Next();
441 }
442 }
443 }
444
445 if (nCount != m_RedlineParents.size())
446 {
447 // Redlines were deleted at the end
448 Init(nCount);
449 return;
450 }
451
452 // check comment
453 weld::TreeView& rTreeView = m_pTable->GetWidget();
454 bool bIsShowChangesInMargin = SW_MOD()->GetUsrPref(false)->IsShowChangesInMargin();
455 for (SwRedlineTable::size_type i = 0; i < nCount; i++)
456 {
457 const SwRangeRedline& rRedln = pSh->GetRedline(i);
458 SwRedlineDataParent *const pParent = m_RedlineParents[i].get();
459
460 if(rRedln.GetComment() != pParent->sComment)
461 {
462 bool bShowDeletedTextAsComment = bIsShowChangesInMargin &&
463 RedlineType::Delete == rRedln.GetType() && rRedln.GetComment().isEmpty();
464 const OUString sComment = bShowDeletedTextAsComment
465 ? const_cast<SwRangeRedline&>(rRedln).GetDescr()
466 : rRedln.GetComment();
467 if (pParent->xTLBParent)
468 {
469 // update only comment
470 rTreeView.set_text(*pParent->xTLBParent, sComment.replace('\n', ' '), 3);
471 }
472 pParent->sComment = sComment;
473 }
474 }
475
476 InitAuthors();
477}
478
480{
481 if (!nStart)
482 {
483 Init();
485 }
486
487 weld::TreeView& rTreeView = m_pTable->GetWidget();
488 rTreeView.freeze();
489 SwView *pView = ::GetActiveView();
490 SwWrtShell* pSh = pView->GetWrtShellPtr();
491 bool bHasRedlineAutoFormat = HasRedlineAutoFormat();
492 SwRedlineDataParent *const pParent = m_RedlineParents[nStart].get();
493 const SwRangeRedline& rRedln = pSh->GetRedline(nStart);
494
495 if (bChild) // should actually never happen, but just in case...
496 {
497 // throw away all entry's children and initialise newly
498 SwRedlineDataChild* pBackupData = const_cast<SwRedlineDataChild*>(pParent->pNext);
499 SwRedlineDataChild* pNext;
500
501 while (pBackupData)
502 {
503 pNext = const_cast<SwRedlineDataChild*>(pBackupData->pNext);
504 if (pBackupData->xTLBChild)
505 rTreeView.remove(*pBackupData->xTLBChild);
506
507 auto it = std::find_if(m_RedlineChildren.begin(), m_RedlineChildren.end(),
508 [&pBackupData](const std::unique_ptr<SwRedlineDataChild>& rChildPtr) { return rChildPtr.get() == pBackupData; });
509 if (it != m_RedlineChildren.end())
510 m_RedlineChildren.erase(it);
511
512 pBackupData = pNext;
513 }
514 pParent->pNext = nullptr;
515
516 // insert new children
517 InsertChildren(pParent, rRedln, bHasRedlineAutoFormat);
518
519 rTreeView.thaw();
520 return nStart;
521 }
522
523 // have entries been deleted?
524 const SwRedlineData *pRedlineData = &rRedln.GetRedlineData();
525 for (SwRedlineTable::size_type i = nStart + 1; i < m_RedlineParents.size(); i++)
526 {
527 if (m_RedlineParents[i]->pData == pRedlineData)
528 {
529 // remove entries from nStart to i-1
530 RemoveParents(nStart, i - 1);
531 rTreeView.thaw();
532 return nStart - 1;
533 }
534 }
535
536 // entries been inserted?
538 pRedlineData = m_RedlineParents[nStart]->pData;
539
540 for (SwRedlineTable::size_type i = nStart + 1; i < nCount; i++)
541 {
542 if (&pSh->GetRedline(i).GetRedlineData() == pRedlineData)
543 {
544 // insert entries from nStart to i-1
545 InsertParents(nStart, i - 1);
546 rTreeView.thaw();
547 return nStart - 1;
548 }
549 }
550
551 rTreeView.thaw();
552 Init(nStart); // adjust all entries until the end
554}
555
556void SwRedlineAcceptDlg::InsertChildren(SwRedlineDataParent *pParent, const SwRangeRedline& rRedln, bool bHasRedlineAutoFormat)
557{
558 SwRedlineDataChild *pLastRedlineChild = nullptr;
559 const SwRedlineData *pRedlineData = &rRedln.GetRedlineData();
560 bool bAutoFormatRedline = rRedln.IsAutoFormat();
561
562 weld::TreeView& rTreeView = m_pTable->GetWidget();
563
564 OUString sAction = GetActionText(rRedln);
565 bool bValidParent = m_sFilterAction.isEmpty() || m_sFilterAction == sAction;
566 bValidParent = bValidParent && m_pTable->IsValidEntry(rRedln.GetAuthorString(), rRedln.GetTimeStamp(), rRedln.GetComment());
567 if (bHasRedlineAutoFormat)
568 {
569
570 if (pParent->pData->GetSeqNo())
571 {
572 std::pair<SwRedlineDataParentSortArr::const_iterator,bool> const ret
573 = m_aUsedSeqNo.insert(pParent);
574 if (ret.second) // already there
575 {
576 if (pParent->xTLBParent)
577 {
578 rTreeView.set_text(*(*ret.first)->xTLBParent, m_sAutoFormat, 0);
579 rTreeView.remove(*pParent->xTLBParent);
580 pParent->xTLBParent.reset();
581 }
582 return;
583 }
584 }
585 bValidParent = bValidParent && bAutoFormatRedline;
586 }
587 bool bValidTree = bValidParent;
588
589 for (sal_uInt16 nStack = 1; nStack < rRedln.GetStackCount(); nStack++)
590 {
591 pRedlineData = pRedlineData->Next();
592
593 SwRedlineDataChild* pRedlineChild = new SwRedlineDataChild;
594 pRedlineChild->pChild = pRedlineData;
595 m_RedlineChildren.push_back(std::unique_ptr<SwRedlineDataChild>(pRedlineChild));
596
597 if ( pLastRedlineChild )
598 pLastRedlineChild->pNext = pRedlineChild;
599 else
600 pParent->pNext = pRedlineChild;
601
602 sAction = GetActionText(rRedln, nStack);
603 bool bValidChild = m_sFilterAction.isEmpty() || m_sFilterAction == sAction;
604 bValidChild = bValidChild && m_pTable->IsValidEntry(rRedln.GetAuthorString(nStack), rRedln.GetTimeStamp(nStack), rRedln.GetComment());
605 if (bHasRedlineAutoFormat)
606 bValidChild = bValidChild && bAutoFormatRedline;
607 bValidTree |= bValidChild;
608
609 if (bValidChild)
610 {
611 std::unique_ptr<RedlinData> pData(new RedlinData);
612 pData->pData = pRedlineChild;
613 pData->bDisabled = true;
614
615 OUString sImage(GetActionImage(rRedln, nStack));
616 OUString sAuthor = rRedln.GetAuthorString(nStack);
617 pData->aDateTime = rRedln.GetTimeStamp(nStack);
618 pData->eType = rRedln.GetType(nStack);
619 OUString sDateEntry = GetAppLangDateTimeString(pData->aDateTime);
620 OUString sComment = rRedln.GetComment(nStack);
621
622 std::unique_ptr<weld::TreeIter> xChild(rTreeView.make_iterator());
623 OUString sId(weld::toId(pData.get()));
624 rTreeView.insert(pParent->xTLBParent.get(), -1, nullptr, &sId, nullptr, nullptr,
625 false, xChild.get());
626 m_RedlinData.push_back(std::move(pData));
627
628 rTreeView.set_image(*xChild, sImage, -1);
629 rTreeView.set_text(*xChild, sAuthor, 1);
630 rTreeView.set_text(*xChild, sDateEntry, 2);
631 rTreeView.set_text(*xChild, sComment, 3);
632
633 pRedlineChild->xTLBChild = std::move(xChild);
634 if (!bValidParent)
635 rTreeView.expand_row(*pParent->xTLBParent);
636 }
637 else
638 pRedlineChild->xTLBChild.reset();
639
640 pLastRedlineChild = pRedlineChild;
641 }
642
643 if (pLastRedlineChild)
644 pLastRedlineChild->pNext = nullptr;
645
646 if (!bValidTree && pParent->xTLBParent)
647 {
648 rTreeView.remove(*pParent->xTLBParent);
649 pParent->xTLBParent.reset();
650 if (bHasRedlineAutoFormat)
651 m_aUsedSeqNo.erase(pParent);
652 }
653}
654
656{
659
660 std::vector<const weld::TreeIter*> aLBoxArr;
661
662 weld::TreeView& rTreeView = m_pTable->GetWidget();
663
664 // because of Bug of TLB that ALWAYS calls the SelectHandler at Remove:
666
667 bool bChildrenRemoved = false;
668 rTreeView.thaw();
669 rTreeView.unselect_all();
670
671 // set the cursor after the last entry because otherwise performance problem in TLB.
672 // TLB would otherwise reset the cursor at every Remove (expensive)
674 weld::TreeIter *pCurEntry = nullptr;
675 while( ( pCurEntry == nullptr ) && ( nPos > 0 ) )
676 {
677 --nPos;
678 pCurEntry = m_RedlineParents[nPos]->xTLBParent.get();
679 }
680
681 if (pCurEntry)
682 rTreeView.set_cursor(*pCurEntry);
683
684 rTreeView.freeze();
685
686 for (SwRedlineTable::size_type i = nStart; i <= nEnd; i++)
687 {
688 if (!bChildrenRemoved && m_RedlineParents[i]->pNext)
689 {
690 SwRedlineDataChild * pChildPtr =
691 const_cast<SwRedlineDataChild*>(m_RedlineParents[i]->pNext);
692 auto it = std::find_if(m_RedlineChildren.begin(), m_RedlineChildren.end(),
693 [&pChildPtr](const std::unique_ptr<SwRedlineDataChild>& rChildPtr) { return rChildPtr.get() == pChildPtr; });
694 if (it != m_RedlineChildren.end())
695 {
696 sal_uInt16 nChildren = 0;
697 while (pChildPtr)
698 {
699 pChildPtr = const_cast<SwRedlineDataChild*>(pChildPtr->pNext);
700 nChildren++;
701 }
702
703 m_RedlineChildren.erase(it, it + nChildren);
704 bChildrenRemoved = true;
705 }
706 }
707 weld::TreeIter *const pEntry = m_RedlineParents[i]->xTLBParent.get();
708 if (pEntry)
709 aLBoxArr.push_back(pEntry);
710 }
711
712 std::sort(aLBoxArr.begin(), aLBoxArr.end(), [&rTreeView](const weld::TreeIter* a, const weld::TreeIter* b) {
713 return rTreeView.iter_compare(*a, *b) == -1;
714 });
715 // clear TLB from behind
716 for (auto it = aLBoxArr.rbegin(); it != aLBoxArr.rend(); ++it)
717 {
718 const weld::TreeIter* pIter = *it;
719 rTreeView.remove(*pIter);
720 }
721
722 rTreeView.thaw();
723 rTreeView.connect_changed(LINK(this, SwRedlineAcceptDlg, SelectHdl));
724 // unfortunately by Remove it was selected from the TLB always again ...
725 rTreeView.unselect_all();
726 rTreeView.freeze();
727
728 m_RedlineParents.erase(m_RedlineParents.begin() + nStart, m_RedlineParents.begin() + nEnd + 1);
729}
730
732{
733 SwView *pView = ::GetActiveView();
734 if (!pView)
735 return;
736
737 SwWrtShell* pSh = pView->GetWrtShellPtr();
738 bool bHasRedlineAutoFormat = HasRedlineAutoFormat();
739
741 nEnd = std::min(nEnd, (nCount - 1)); // also treats nEnd=SwRedlineTable::npos (until the end)
742
743 if (nEnd == SwRedlineTable::npos)
744 return; // no redlines in the document
745
746 weld::TreeView& rTreeView = m_pTable->GetWidget();
747
748 SwRedlineDataParent* pRedlineParent;
749 const SwRangeRedline* pCurrRedline;
750 if (!nStart && !rTreeView.get_selected(nullptr))
751 {
752 pCurrRedline = pSh->GetCurrRedline();
753 if( !pCurrRedline )
754 {
755 pSh->SwCursorShell::Push();
756 pCurrRedline = pSh->SelNextRedline();
757 if( nullptr == pCurrRedline )
758 pCurrRedline = pSh->SelPrevRedline();
759 pSh->SwCursorShell::Pop(SwCursorShell::PopMode::DeleteCurrent);
760 }
761 }
762 else
763 pCurrRedline = nullptr;
764
765 rTreeView.freeze();
766 if (m_pTable->IsSorted())
767 rTreeView.make_unsorted();
768
769 bool bIsShowChangesInMargin = SW_MOD()->GetUsrPref(false)->IsShowChangesInMargin();
770
771 // collect redlines of tracked table or table row insertion/deletions under a single tree list
772 // item to accept/reject table (row) insertion/deletion with a single click on Accept/Reject
773 // Note: because update of the tree list depends on parent count, we don't modify
774 // m_RedlineParents, only store the 2nd and more redlines as children of the tree list
775 // item of the first redline
776
777 // count of items stored as children (to adjust parent position)
778 sal_Int32 nSkipRedlines = 0;
779 // count of items of the actual table row (or joined table rows) stored as children =
780 // redlines of the row(s) - 1 (first redline is associated to the parent tree list item)
781 sal_Int32 nSkipRedline = 0;
782 // nSkipRedline of the previous table row (to join multiple table rows, if it's possible)
783 sal_Int32 nPrevSkipRedline = 0;
784
785 // last SwRangeRedline in the table row
787 // descriptor redline of the tracked table row
789 // descriptor redline of the previous table row to join the table rows
791
792 // show all redlines as tree list items,
793 // redlines of a tracked table (row) insertion/deletion showed as children of a single parent
794 for (SwRedlineTable::size_type i = nStart; i <= nEnd; i++)
795 {
796 const SwRangeRedline& rRedln = pSh->GetRedline(i);
797 const SwRedlineData *pRedlineData = &rRedln.GetRedlineData();
798
799 pRedlineParent = new SwRedlineDataParent;
800 pRedlineParent->pData = pRedlineData;
801 pRedlineParent->pNext = nullptr;
802
803 // handle tracked table row changes
804 const SwTableBox* pTableBox;
805 const SwTableLine* pTableLine;
806 // first SwRangeRedline of the tracked table row(s), base of the parent tree list
807 // of the other SwRangeRedlines of the tracked table row(s)
809 if ( // not recognized yet as tracked table row change
810 nLastChangeInRow == SwRedlineTable::npos &&
811 nullptr != ( pTableBox = pSh->GetRedline(i).Start()->GetNode().GetTableBox() ) &&
812 nullptr != ( pTableLine = pTableBox->GetUpper() ) &&
813 // it's a tracked row change based on the cached row data
814 RedlineType::None != pTableLine->GetRedlineType() )
815 {
816 SwRedlineTable::size_type nRedline = i;
817 nRowChange = pTableLine->UpdateTextChangesOnly(nRedline);
818 if ( SwRedlineTable::npos != nRowChange )
819 {
820 nSkipRedline = nRedline - i - 1;
821 nLastChangeInRow = nRedline - 1;
822 // join the consecutive deleted/inserted rows under a single treebox item,
823 // if they have the same redline data (equal type, author and time stamp)
824 if ( nPrevRowChange != SwRedlineTable::npos &&
825 pSh->GetRedline(nRowChange).GetRedlineData() == pSh->GetRedline(nPrevRowChange).GetRedlineData() )
826 {
827 nSkipRedline += nPrevSkipRedline + 1;
828 nPrevSkipRedline = 0;
829 nPrevRowChange = SwRedlineTable::npos;
830 }
831 else
832 nNewTableParent = i;
833 }
834 else
835 nPrevRowChange = SwRedlineTable::npos;
836 }
837 else
838 nPrevRowChange = SwRedlineTable::npos;
839
840 bool bRowChange(SwRedlineTable::npos != nLastChangeInRow);
841
842 bool bShowDeletedTextAsComment = bIsShowChangesInMargin &&
843 RedlineType::Delete == rRedln.GetType() && rRedln.GetComment().isEmpty();
844 const OUString& sComment = bShowDeletedTextAsComment
845 ? const_cast<SwRangeRedline&>(rRedln).GetDescr()
846 : rRedln.GetComment();
847 pRedlineParent->sComment = sComment.replace('\n', ' ');
848 m_RedlineParents.insert(m_RedlineParents.begin() + i,
849 std::unique_ptr<SwRedlineDataParent>(pRedlineParent));
850
851 std::unique_ptr<RedlinData> pData(new RedlinData);
852 pData->pData = pRedlineParent;
853 pData->bDisabled = false;
854
855 // use descriptor SwRangeRedline of the changed row, if needed to show
856 // the correct redline type, author and time stamp of the tracked row change
857 const SwRangeRedline& rChangeRedln = pSh->GetRedline(bRowChange ? nRowChange : i);
858
859 OUString sImage = GetActionImage(rChangeRedln, 0, bRowChange && nNewTableParent != SwRedlineTable::npos );
860 OUString sAuthor = rChangeRedln.GetAuthorString(0);
861 pData->aDateTime = rChangeRedln.GetTimeStamp(0);
862 pData->eType = rChangeRedln.GetType(0);
863 OUString sDateEntry = GetAppLangDateTimeString(pData->aDateTime);
864
865 OUString sId = weld::toId(pData.get());
866 std::unique_ptr<weld::TreeIter> xParent(rTreeView.make_iterator());
867
868 if ( !bRowChange || nNewTableParent != SwRedlineTable::npos )
869 rTreeView.insert(nullptr, i - nSkipRedlines, nullptr, &sId, nullptr, nullptr, false, xParent.get());
870 else
871 {
872 // put 2nd or more redlines of deleted/inserted rows as children of their first redline
873 SwRedlineDataParent *const pParent = m_RedlineParents[nLastChangeInRow - nSkipRedline].get();
874 rTreeView.insert(pParent->xTLBParent.get(), -1, nullptr, &sId, nullptr, nullptr, false, xParent.get());
875 }
876
877 m_RedlinData.push_back(std::move(pData));
878
879 rTreeView.set_image(*xParent, sImage, -1);
880 rTreeView.set_text(*xParent, sAuthor, 1);
881 rTreeView.set_text(*xParent, sDateEntry, 2);
882 rTreeView.set_text(*xParent, sComment, 3);
883
884 if (pCurrRedline == &rRedln)
885 {
886 rTreeView.thaw();
887 rTreeView.set_cursor(*xParent);
888 rTreeView.select(*xParent);
889 rTreeView.scroll_to_row(*xParent);
890 rTreeView.freeze();
891 }
892
893 pRedlineParent->xTLBParent = std::move(xParent);
894
895 InsertChildren(pRedlineParent, rRedln, bHasRedlineAutoFormat);
896
897 // end of a tracked deletion/insertion of a table row
898 if ( nLastChangeInRow != SwRedlineTable::npos && i == nLastChangeInRow )
899 {
900 nSkipRedlines += nSkipRedline;
901 nPrevSkipRedline = nSkipRedline;
902 nSkipRedline = 0;
903 nPrevRowChange = nRowChange;
904 nNewTableParent = SwRedlineTable::npos;
905 nLastChangeInRow = SwRedlineTable::npos;
906 }
907 }
908 rTreeView.thaw();
909 if (m_pTable->IsSorted())
910 rTreeView.make_sorted();
911}
912
913void SwRedlineAcceptDlg::CallAcceptReject( bool bSelect, bool bAccept )
914{
916 int nPos = -1;
917
918 typedef std::vector<std::unique_ptr<weld::TreeIter>> ListBoxEntries_t;
919 ListBoxEntries_t aRedlines;
920
921 // don't activate
922 OSL_ENSURE( !m_bInhibitActivate,
923 "recursive call of CallAcceptReject?");
924 m_bInhibitActivate = true;
925
926 weld::TreeView& rTreeView = m_pTable->GetWidget();
927
928 auto lambda = [this, pSh, bSelect, bAccept, &rTreeView, &nPos, &aRedlines](weld::TreeIter& rEntry) {
929 if (!rTreeView.get_iter_depth(rEntry))
930 {
931 if (bSelect && nPos == -1)
932 nPos = rTreeView.get_iter_index_in_parent(rEntry);
933
934 RedlinData *pData = weld::fromId<RedlinData*>(rTreeView.get_id(rEntry));
935
936 bool bIsNotFormatted = true;
937
938 // first remove only changes with insertion/deletion, if they exist
939 // (format-only changes haven't had real rejection yet, only an
940 // approximation: clear direct formatting, so try to warn
941 // with the extended button label "Reject All/Clear formatting")
942 if ( !bSelect && !bAccept && !m_bOnlyFormatedRedlines )
943 {
944 SwRedlineTable::size_type nPosition = GetRedlinePos(rEntry);
945 const SwRangeRedline& rRedln = pSh->GetRedline(nPosition);
946
947 if( RedlineType::Format == rRedln.GetType() )
948 bIsNotFormatted = false;
949 }
950
951 if (!pData->bDisabled && bIsNotFormatted)
952 aRedlines.emplace_back(rTreeView.make_iterator(&rEntry));
953 }
954 return false;
955 };
956
957 // collect redlines-to-be-accepted/rejected in aRedlines vector
958 if (bSelect)
959 rTreeView.selected_foreach(lambda);
960 else
961 rTreeView.all_foreach(lambda);
962
964 if( !bAccept )
965 FnAccRej = &SwEditShell::RejectRedline;
966
967 SwWait aWait( *pSh->GetView().GetDocShell(), true );
968 pSh->StartAction();
969
970 bool bMoreRedlines( aRedlines.size() > 1 ||
971 // single item with children, e.g. multiple redlines of a table or table row deletion/insertion
972 ( aRedlines.size() == 1 && rTreeView.iter_n_children(*aRedlines[0]) > 0 ) );
973
974 // don't add extra Undo label to a single item only with redline stack (i.e. old changes
975 // on the same text range, stored only in OOXML)
976 if ( bMoreRedlines && aRedlines.size() == 1 )
977 {
978 std::unique_ptr<weld::TreeIter> xChild(rTreeView.make_iterator( &*aRedlines[0] ));
979 RedlinData *pData = weld::fromId<RedlinData*>(rTreeView.get_id(*xChild));
980 if ( pData->bDisabled )
981 bMoreRedlines = false;
982 }
983
984 if ( bMoreRedlines )
985 {
986 OUString aTmpStr;
987 {
988 SwRewriter aRewriter;
989 aRewriter.AddRule(UndoArg1,
990 OUString::number(aRedlines.size()));
991 aTmpStr = aRewriter.Apply(SwResId(STR_N_REDLINES));
992 }
993
994 SwRewriter aRewriter;
995 aRewriter.AddRule(UndoArg1, aTmpStr);
996
998 &aRewriter);
999 }
1000
1001 // accept/reject the redlines in aRedlines. The absolute
1002 // position may change during the process (e.g. when two redlines
1003 // are merged in result of another one being deleted), so the
1004 // position must be resolved late and checked before using it.
1005 // (cf #102547#)
1006 for (const auto& rRedLine : aRedlines)
1007 {
1008 SwRedlineTable::size_type nPosition = GetRedlinePos( *rRedLine );
1009 if( nPosition != SwRedlineTable::npos )
1010 (pSh->*FnAccRej)( nPosition );
1011
1012 // handle redlines of table rows, stored as children of the item associated
1013 // to the deleted/inserted table row(s)
1014 std::unique_ptr<weld::TreeIter> xChild(rTreeView.make_iterator( &*rRedLine ));
1015 if ( rTreeView.iter_children(*xChild) )
1016 {
1017 RedlinData *pData = weld::fromId<RedlinData*>(rTreeView.get_id(*xChild));
1018 // disabled for redline stack, but not for redlines of table rows
1019 if ( !pData->bDisabled )
1020 {
1021 do
1022 {
1023 nPosition = GetRedlinePos( *xChild );
1024 if( nPosition != SwRedlineTable::npos )
1025 (pSh->*FnAccRej)( nPosition );
1026 }
1027 while ( rTreeView.iter_next_sibling(*xChild) );
1028 }
1029 }
1030 }
1031
1032 if ( bMoreRedlines )
1033 {
1034 pSh->EndUndo();
1035 }
1036
1037 pSh->EndAction();
1038
1039 m_bInhibitActivate = false;
1040 Activate();
1041
1042 if (nPos != -1 && rTreeView.n_children())
1043 {
1044 if (nPos >= rTreeView.n_children())
1045 nPos = rTreeView.n_children() - 1;
1046 rTreeView.select(nPos);
1047 rTreeView.scroll_to_row(nPos);
1048 rTreeView.set_cursor(nPos);
1049 SelectHdl(rTreeView);
1050 }
1052}
1053
1055{
1057 weld::TreeView& rTreeView = m_pTable->GetWidget();
1058 return pSh->FindRedlineOfData( *static_cast<SwRedlineDataParent*>(weld::fromId<RedlinData*>(
1059 rTreeView.get_id(rEntry))->pData)->pData );
1060}
1061
1063{
1064 CallAcceptReject( true, true );
1065}
1066
1068{
1069 CallAcceptReject( false, true );
1070}
1071
1073{
1074 CallAcceptReject( true, false );
1075}
1076
1078{
1079 CallAcceptReject( false, false );
1080}
1081
1083{
1084 SwView * pView = ::GetActiveView();
1085 pView->GetViewFrame()->GetDispatcher()->
1086 Execute(SID_UNDO, SfxCallMode::SYNCHRON);
1087 m_pTPView->EnableUndo(pView->GetSlotState(SID_UNDO) != nullptr);
1088
1089 Activate();
1090}
1091
1093{
1094 SvxTPFilter *pFilterTP = m_xTabPagesCTRL->GetFilterPage();
1095
1096 if (pFilterTP->IsAction())
1097 m_sFilterAction = pFilterTP->GetLbAction()->get_active_text();
1098 else
1099 m_sFilterAction.clear();
1100
1101 Init();
1102}
1103
1105{
1106 m_aSelectTimer.Start();
1107}
1108
1110{
1112 m_aSelectTimer.Stop();
1113
1114 bool bIsNotFormated = false;
1115 bool bSel = false;
1116
1117 //#98883# don't select redlines while the dialog is not focused
1118 //#107938# But not only ask pTable if it has the focus. To move
1119 // the selection to the selected redline any child of pParentDlg
1120 // may the focus.
1121 if (!m_xParentDlg || m_xParentDlg->has_toplevel_focus())
1122 {
1123 weld::TreeView& rTreeView = m_pTable->GetWidget();
1124 std::unique_ptr<weld::TreeIter> xActEntry(rTreeView.make_iterator());
1125 if (rTreeView.get_selected(xActEntry.get()))
1126 {
1127 pSh->StartAction();
1128 pSh->EnterStdMode();
1129 SwViewShell::SetCareDialog(m_xParentDlg);
1130
1131 rTreeView.selected_foreach([this, pSh, &rTreeView, &xActEntry, &bIsNotFormated, &bSel](weld::TreeIter& rEntry){
1132 rTreeView.copy_iterator(rEntry, *xActEntry);
1133 if (rTreeView.get_iter_depth(rEntry))
1134 {
1135 rTreeView.iter_parent(*xActEntry);
1136 if (rTreeView.is_selected(*xActEntry))
1137 return false; // don't select twice
1138 }
1139 else
1140 bSel = true;
1141
1142 // #98864# find the selected redline (ignore, if the redline is already gone)
1143 SwRedlineTable::size_type nPos = GetRedlinePos(*xActEntry);
1145 {
1146
1147 const SwRangeRedline& rRedln = pSh->GetRedline( nPos );
1148 bIsNotFormated |= RedlineType::Format != rRedln.GetType();
1149
1150 if (pSh->GotoRedline(nPos, true))
1151 {
1152 pSh->SetInSelect();
1153 pSh->EnterAddMode();
1154 }
1155 }
1156
1157 // select all redlines of tracked table rows
1158 std::unique_ptr<weld::TreeIter> xChild(rTreeView.make_iterator( &*xActEntry ));
1159 if ( rTreeView.iter_children(*xChild) )
1160 {
1161 RedlinData *pData = reinterpret_cast<RedlinData*>(rTreeView.get_id(*xChild).toInt64());
1162 // disabled for redline stack, but not for redlines of table rows
1163 if ( !pData->bDisabled )
1164 {
1165 do
1166 {
1167 nPos = GetRedlinePos(*xChild);
1169 {
1170 const SwRangeRedline& rRedln = pSh->GetRedline( nPos );
1171 bIsNotFormated |= RedlineType::Format != rRedln.GetType();
1172
1173 if (pSh->GotoRedline(nPos, true))
1174 {
1175 pSh->SetInSelect();
1176 pSh->EnterAddMode();
1177 }
1178 }
1179 }
1180 while ( rTreeView.iter_next_sibling(*xChild) );
1181 }
1182 }
1183 return false;
1184 });
1185
1186 pSh->LeaveAddMode();
1187 pSh->EndAction();
1189 }
1190 }
1191
1192 bool const bEnable = !pSh->GetDoc()->GetDocShell()->IsReadOnly()
1193 && !pSh->getIDocumentRedlineAccess().GetRedlinePassword().hasElements();
1194 m_pTPView->EnableAccept( bEnable && bSel /*&& !bReadonlySel*/ );
1195 m_pTPView->EnableReject( bEnable && bSel /*&& !bReadonlySel*/ );
1196 m_pTPView->EnableClearFormat( bEnable && bSel && !bIsNotFormated /*&& !bReadonlySel*/ );
1197 m_pTPView->EnableAcceptAll( bEnable );
1198 m_pTPView->EnableRejectAll( bEnable );
1199 m_pTPView->EnableClearFormatAll( bEnable && m_bOnlyFormatedRedlines );
1200}
1201
1202IMPL_LINK(SwRedlineAcceptDlg, CommandHdl, const CommandEvent&, rCEvt, bool)
1203{
1204 if (rCEvt.GetCommand() != CommandEventId::ContextMenu)
1205 return false;
1206
1208 const SwRangeRedline *pRed = nullptr;
1209
1210 weld::TreeView& rTreeView = m_pTable->GetWidget();
1211 std::unique_ptr<weld::TreeIter> xEntry(rTreeView.make_iterator());
1212 bool bEntry = rTreeView.get_selected(xEntry.get());
1213 if (bEntry)
1214 {
1215 std::unique_ptr<weld::TreeIter> xTopEntry(rTreeView.make_iterator(xEntry.get()));
1216
1217 if (rTreeView.get_iter_depth(*xTopEntry))
1218 rTreeView.iter_parent(*xTopEntry);
1219
1220 SwRedlineTable::size_type nPos = GetRedlinePos(*xTopEntry);
1221
1222 // disable commenting for protected areas
1223 if (nPos != SwRedlineTable::npos && (pRed = pSh->GotoRedline(nPos, true)) != nullptr)
1224 {
1225 if( pSh->IsCursorPtAtEnd() )
1226 pSh->SwapPam();
1227 pSh->SetInSelect();
1228 }
1229 }
1230
1231 m_xPopup->set_sensitive("writeredit", bEntry && pRed &&
1232 !rTreeView.get_iter_depth(*xEntry) &&
1233 rTreeView.count_selected_rows() == 1);
1234 m_xPopup->set_sensitive("writersort", rTreeView.n_children() != 0);
1235 int nColumn = rTreeView.get_sort_column();
1236 if (nColumn == -1)
1237 nColumn = 4;
1238 for (sal_Int32 i = 0; i < 5; ++i)
1239 m_xSortMenu->set_active("writersort" + OString::number(i), i == nColumn);
1240
1241 OString sCommand = m_xPopup->popup_at_rect(&rTreeView, tools::Rectangle(rCEvt.GetMousePosPixel(), Size(1,1)));
1242
1243 if (sCommand == "writeredit")
1244 {
1245 if (bEntry)
1246 {
1247 if (rTreeView.get_iter_depth(*xEntry))
1248 rTreeView.iter_parent(*xEntry);
1249
1250 SwRedlineTable::size_type nPos = GetRedlinePos(*xEntry);
1251
1253 return true;
1254
1255 const SwRangeRedline &rRedline = pSh->GetRedline(nPos);
1256
1257 /* enable again once we have redline comments in the margin
1258 sComment = rRedline.GetComment();
1259 if ( !sComment.Len() )
1260 GetActiveView()->GetDocShell()->Broadcast(SwRedlineHint(&rRedline,SWREDLINE_INSERTED));
1261 const_cast<SwRangeRedline&>(rRedline).Broadcast(SwRedlineHint(&rRedline,SWREDLINE_FOCUS));
1262 */
1263
1264 OUString sComment = convertLineEnd(rRedline.GetComment(), GetSystemLineEnd());
1266 ::DialogGetRanges fnGetRange = pFact->GetDialogGetRangesFunc();
1267 SfxItemSet aSet( pSh->GetAttrPool(), fnGetRange() );
1268
1269 aSet.Put(SvxPostItTextItem(sComment, SID_ATTR_POSTIT_TEXT));
1270 aSet.Put(SvxPostItAuthorItem(rRedline.GetAuthorString(), SID_ATTR_POSTIT_AUTHOR));
1271
1273 rRedline.GetRedlineData().GetTimeStamp() ),
1274 SID_ATTR_POSTIT_DATE ));
1275
1276 ScopedVclPtr<AbstractSvxPostItDialog> pDlg(pFact->CreateSvxPostItDialog(&rTreeView, aSet));
1277
1278 pDlg->HideAuthor();
1279
1280 TranslateId pResId;
1281 switch( rRedline.GetType() )
1282 {
1283 case RedlineType::Insert:
1284 pResId = STR_REDLINE_INSERTED;
1285 break;
1286 case RedlineType::Delete:
1287 pResId = STR_REDLINE_DELETED;
1288 break;
1289 case RedlineType::Format:
1290 case RedlineType::ParagraphFormat:
1291 pResId = STR_REDLINE_FORMATTED;
1292 break;
1293 case RedlineType::Table:
1294 pResId = STR_REDLINE_TABLECHG;
1295 break;
1296 default:;//prevent warning
1297 }
1298 OUString sTitle(SwResId(STR_REDLINE_COMMENT));
1299 if (pResId)
1300 sTitle += SwResId(pResId);
1301 pDlg->SetText(sTitle);
1302
1303 SwViewShell::SetCareDialog(pDlg->GetDialog());
1304
1305 if ( pDlg->Execute() == RET_OK )
1306 {
1307 const SfxItemSet* pOutSet = pDlg->GetOutputItemSet();
1308 OUString sMsg(pOutSet->Get(SID_ATTR_POSTIT_TEXT).GetValue());
1309
1310 // insert / change comment
1311 pSh->SetRedlineComment(sMsg);
1312 rTreeView.set_text(*xEntry, sMsg.replace('\n', ' '), 3);
1313 Init();
1314 }
1315
1317 pDlg.disposeAndClear();
1318 }
1319 }
1320 else if (!sCommand.isEmpty())
1321 {
1322 int nSortMode = o3tl::toInt32(sCommand.subView(10));
1323
1324 if (nSortMode == 4 && nColumn == 4)
1325 return true; // we already have it
1326 if (nSortMode == 4)
1327 nSortMode = -1; // unsorted / sorted by position
1328
1329 SwWait aWait( *::GetActiveView()->GetDocShell(), false );
1330 m_pTable->HeaderBarClick(nSortMode);
1331 if (nSortMode == -1)
1332 Init(); // newly fill everything
1333 }
1334 return true;
1335}
1336
1337namespace
1338{
1339 OUString lcl_StripAcceptChgDat(OUString &rExtraString)
1340 {
1341 OUString aStr;
1342 while(true)
1343 {
1344 sal_Int32 nPos = rExtraString.indexOf("AcceptChgDat:");
1345 if (nPos == -1)
1346 break;
1347 // try to read the alignment string "ALIGN:(...)"; if none existing,
1348 // it's an old version
1349 sal_Int32 n1 = rExtraString.indexOf('(', nPos);
1350 if (n1 != -1)
1351 {
1352 sal_Int32 n2 = rExtraString.indexOf(')', n1);
1353 if (n2 != -1)
1354 {
1355 // cut out the alignment string
1356 aStr = rExtraString.copy(nPos, n2 - nPos + 1);
1357 rExtraString = rExtraString.replaceAt(nPos, n2 - nPos + 1, u"");
1358 aStr = aStr.copy(n1 - nPos + 1);
1359 }
1360 }
1361 }
1362 return aStr;
1363 }
1364}
1365
1366void SwRedlineAcceptDlg::Initialize(OUString& rExtraString)
1367{
1368 if (rExtraString.isEmpty())
1369 return;
1370
1371 OUString aStr = lcl_StripAcceptChgDat(rExtraString);
1372 if (aStr.isEmpty())
1373 return;
1374
1375 int nCount = aStr.toInt32();
1376 if (nCount <= 2)
1377 return;
1378
1379 std::vector<int> aEndPos;
1380
1381 for (int i = 0; i < nCount; ++i)
1382 {
1383 sal_Int32 n1 = aStr.indexOf(';');
1384 aStr = aStr.copy( n1+1 );
1385 aEndPos.push_back(aStr.toInt32());
1386 }
1387
1388 bool bUseless = false;
1389
1390 std::vector<int> aWidths;
1391 for (int i = 1; i < nCount; ++i)
1392 {
1393 aWidths.push_back(aEndPos[i] - aEndPos[i - 1]);
1394 if (aWidths.back() <= 0)
1395 bUseless = true;
1396 }
1397
1398 if (!bUseless)
1399 {
1400 // turn column end points back to column widths, ignoring the small
1401 // value used for the expander column
1402 weld::TreeView& rTreeView = m_pTable->GetWidget();
1403 rTreeView.set_column_fixed_widths(aWidths);
1404 }
1405}
1406
1407void SwRedlineAcceptDlg::FillInfo(OUString &rExtraData) const
1408{
1409 //remove any old one before adding a new one
1410 lcl_StripAcceptChgDat(rExtraData);
1411 rExtraData += "AcceptChgDat:(";
1412
1413 const int nTabCount = 4;
1414
1415 rExtraData += OUString::number(nTabCount);
1416 rExtraData += ";";
1417
1418 weld::TreeView& rTreeView = m_pTable->GetWidget();
1419 std::vector<int> aWidths;
1420 // turn column widths back into column end points for compatibility
1421 // with how they used to be stored, including a small value for the
1422 // expander column
1423 aWidths.push_back(rTreeView.get_checkbox_column_width());
1424 for (int i = 0; i < nTabCount - 1; ++i)
1425 {
1426 int nWidth = rTreeView.get_column_width(i);
1427 assert(nWidth > 0 && "suspicious to get a value like this");
1428 aWidths.push_back(aWidths.back() + nWidth);
1429 }
1430
1431 for (auto a : aWidths)
1432 {
1433 rExtraData += OUString::number(a);
1434 rExtraData += ";";
1435 }
1436 rExtraData += ")";
1437}
1438
1440 : PanelLayout(pParent, "ManageChangesPanel", "modules/swriter/ui/managechangessidebar.ui")
1441 , mxContentArea(m_xBuilder->weld_container("content_area"))
1442{
1443 mpImplDlg.reset(new SwRedlineAcceptDlg(nullptr, m_xBuilder.get(), mxContentArea.get()));
1444
1445 mpImplDlg->Init();
1446
1447 // we want to receive SfxHintId::DocChanged
1448 StartListening(*(SW_MOD()->GetView()->GetDocShell()));
1449}
1450
1452{
1453}
1454
1456{
1457 if (mpImplDlg && rHint.GetId() == SfxHintId::DocChanged)
1458 mpImplDlg->Activate();
1459}
1460
1461/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
@ UndoArg1
Definition: SwRewriter.hxx:29
SFX_IMPL_MODELESSDIALOGCONTOLLER_WITHID(SvxContourDlgChildWindow, SID_CONTOUR_DLG)
Reference< XExecutableDialog > m_xDialog
virtual const css::uno::Sequence< sal_Int8 > & GetRedlinePassword() const =0
std::unique_ptr< weld::Builder > m_xBuilder
std::shared_ptr< SfxDialogController > & GetController()
const SfxPoolItem * ExecuteList(sal_uInt16 nSlot, SfxCallMode nCall, std::initializer_list< SfxPoolItem const * > args, std::initializer_list< SfxPoolItem const * > internalargs=std::initializer_list< SfxPoolItem const * >())
SfxHintId GetId() const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
void StartListening(SfxBroadcaster &rBroadcaster, DuplicateHandling eDuplicateHanding=DuplicateHandling::Unexpected)
virtual void FillInfo(SfxChildWinInfo &) const
void Initialize(SfxChildWinInfo const *pInfo)
virtual void Activate() override
bool IsReadOnly() const
const SfxPoolItem * GetSlotState(sal_uInt16 nSlotId, const SfxInterface *pIF=nullptr, SfxItemSet *pStateSet=nullptr)
SfxDispatcher * GetDispatcher()
SfxViewFrame * GetViewFrame() const
virtual VclPtr< AbstractSvxPostItDialog > CreateSvxPostItDialog(weld::Widget *pParent, const SfxItemSet &rCoreSet, bool bPrevNext=false)=0
static SvxAbstractDialogFactory * Create()
virtual DialogGetRanges GetDialogGetRangesFunc()=0
bool IsSorted() const
bool IsValidEntry(std::u16string_view rAuthor, const DateTime &rDateTime, const OUString &rComment)
void SetWriterView()
weld::TreeView & GetWidget()
void ClearAuthors()
OUString GetSelectedAuthor() const
weld::ComboBox * GetLbAction()
void InsertAuthor(const OUString &rString)
bool IsAction() const
sal_Int32 SelectAuthor(const OUString &aString)
void EnableRejectAll(bool bFlag)
void EnableAccept(bool bFlag)
void EnableClearFormat(bool bFlag)
SvxRedlinTable * GetTableControl()
void SetRejectClickHdl(const Link< SvxTPView *, void > &rLink)
void EnableUndo(bool bFlag=true)
void EnableAcceptAll(bool bFlag)
void SetUndoClickHdl(const Link< SvxTPView *, void > &rLink)
void SetRejectAllClickHdl(const Link< SvxTPView *, void > &rLink)
void SetAcceptClickHdl(const Link< SvxTPView *, void > &rLink)
void EnableReject(bool bFlag)
void DisableUndo()
void ShowUndo()
void SetAcceptAllClickHdl(const Link< SvxTPView *, void > &rLink)
void EnableClearFormatAll(bool bFlag)
virtual bool ReInitDlg(SwDocShell *pDocSh)
Definition: fldwrap.cxx:46
void SetOldDocShell(SwDocShell *pDcSh)
Definition: chldwrap.hxx:42
SwDocShell * GetOldDocShell()
Definition: chldwrap.hxx:41
void StartAction()
Definition: crsrsh.cxx:226
void SwapPam()
Definition: crsrsh.cxx:976
void EndAction(const bool bIdleEnd=false)
Definition: crsrsh.cxx:243
const SwRangeRedline * SelNextRedline()
Definition: crstrvl.cxx:2313
const SwRangeRedline * SelPrevRedline()
Definition: crstrvl.cxx:2340
bool IsCursorPtAtEnd() const
Definition: crsrsh.hxx:914
SwDocShell * GetDocShell()
Definition: doc.hxx:1359
bool IsModified() const
Changes in document?
Definition: edws.cxx:65
bool AcceptRedline(SwRedlineTable::size_type nPos)
Definition: edredln.cxx:67
bool SetRedlineComment(const OUString &rS)
Set comment to Redline at position.
Definition: edredln.cxx:150
SwUndoId StartUndo(SwUndoId eUndoId=SwUndoId::EMPTY, const SwRewriter *pRewriter=nullptr)
Undo: set up Undo parenthesis, return nUndoId of this parenthesis.
Definition: edws.cxx:223
bool RejectRedline(SwRedlineTable::size_type nPos)
Definition: edredln.cxx:78
void ResetModified()
Definition: edws.cxx:75
const SwRangeRedline & GetRedline(SwRedlineTable::size_type nPos) const
Definition: edredln.cxx:53
const SwRangeRedline * GetCurrRedline() const
Definition: edredln.cxx:161
SwUndoId EndUndo(SwUndoId eUndoId=SwUndoId::EMPTY, const SwRewriter *pRewriter=nullptr)
Closes parenthesis of nUndoId, not used by UI.
Definition: edws.cxx:234
SwRedlineTable::size_type GetRedlineCount() const
Definition: edredln.cxx:48
SwRedlineTable::size_type FindRedlineOfData(const SwRedlineData &) const
Search Redline for this Data and.
Definition: edredln.cxx:186
SwModelessRedlineAcceptDlg(SfxBindings *, SwChildWinWrapper *, weld::Window *pParent)
Definition: redlndlg.cxx:81
virtual void FillInfo(SfxChildWinInfo &) const override
Definition: redlndlg.cxx:131
void Initialize(SfxChildWinInfo *pInfo)
Definition: redlndlg.cxx:123
virtual void Activate() override
Definition: redlndlg.cxx:91
std::unique_ptr< SwRedlineAcceptDlg > m_xImplDlg
Definition: redlndlg.hxx:128
std::unique_ptr< weld::Container > m_xContentArea
Definition: redlndlg.hxx:127
SwChildWinWrapper * m_pChildWin
Definition: redlndlg.hxx:129
virtual ~SwModelessRedlineAcceptDlg() override
Definition: redlndlg.cxx:137
SwTableBox * GetTableBox() const
If node is in a table return the respective table box.
Definition: node.cxx:774
const SwPosition * Start() const
Definition: pam.hxx:266
bool IsAutoFormat() const
Definition: redline.hxx:207
const OUString & GetComment(sal_uInt16 nPos=0) const
Definition: docredln.cxx:1950
sal_uInt16 GetStackCount() const
Definition: docredln.cxx:1917
OUString const & GetAuthorString(sal_uInt16 nPos=0) const
Definition: docredln.cxx:1930
bool IsAnnotation() const
Definition: docredln.cxx:1945
bool IsMoved() const
Definition: redline.hxx:276
const DateTime & GetTimeStamp(sal_uInt16 nPos=0) const
Definition: docredln.cxx:1935
RedlineType GetType(sal_uInt16 nPos=0) const
Definition: docredln.cxx:1940
const SwRedlineData & GetRedlineData(sal_uInt16 nPos=0) const
Definition: docredln.cxx:1963
virtual bool ReInitDlg(SwDocShell *pDocSh) override
Definition: redlndlg.cxx:72
bool HasRedlineAutoFormat() const
Definition: redlndlg.hxx:114
OUString m_sFormated
Definition: redlndlg.hxx:69
void FillInfo(OUString &rExtraData) const
Definition: redlndlg.cxx:1407
OUString m_sFilterAction
Definition: redlndlg.hxx:72
SAL_DLLPRIVATE void InitAuthors()
Definition: redlndlg.cxx:240
OUString m_sInserted
Definition: redlndlg.hxx:67
void Init(SwRedlineTable::size_type nStart=0)
Definition: redlndlg.cxx:209
OUString m_sDeleted
Definition: redlndlg.hxx:68
std::vector< std::unique_ptr< SwRedlineDataChild > > m_RedlineChildren
Definition: redlndlg.hxx:61
SAL_DLLPRIVATE OUString GetActionText(const SwRangeRedline &rRedln, sal_uInt16 nStack=0)
Definition: redlndlg.cxx:340
SvxTPView * m_pTPView
Definition: redlndlg.hxx:82
OUString m_sAutoFormat
Definition: redlndlg.hxx:73
static SAL_DLLPRIVATE OUString GetActionImage(const SwRangeRedline &rRedln, sal_uInt16 nStack=0, bool bRowChanges=false)
Definition: redlndlg.cxx:312
void Initialize(OUString &rExtraData)
Definition: redlndlg.cxx:1366
SAL_DLLPRIVATE void RemoveParents(SwRedlineTable::size_type nStart, SwRedlineTable::size_type nEnd)
Definition: redlndlg.cxx:655
void CallAcceptReject(bool bSelect, bool bAccept)
Definition: redlndlg.cxx:913
bool m_bOnlyFormatedRedlines
Definition: redlndlg.hxx:74
OUString m_sFormatCollSet
Definition: redlndlg.hxx:71
SAL_DLLPRIVATE void InsertChildren(SwRedlineDataParent *pParent, const SwRangeRedline &rRedln, bool bHasRedlineAutoFormat)
Definition: redlndlg.cxx:556
SAL_DLLPRIVATE SwRedlineTable::size_type GetRedlinePos(const weld::TreeIter &rEntry)
Definition: redlndlg.cxx:1054
std::unique_ptr< SvxAcceptChgCtr > m_xTabPagesCTRL
Definition: redlndlg.hxx:80
SAL_DLLPRIVATE SwRedlineTable::size_type CalcDiff(SwRedlineTable::size_type nStart, bool bChild)
Definition: redlndlg.cxx:479
SwRedlineAcceptDlg(SwRedlineAcceptDlg const &)=delete
SAL_DLLPRIVATE void InsertParents(SwRedlineTable::size_type nStart, SwRedlineTable::size_type nEnd=SwRedlineTable::npos)
Definition: redlndlg.cxx:731
OUString m_sTableChgd
Definition: redlndlg.hxx:70
SwRedlineDataParentSortArr m_aUsedSeqNo
Definition: redlndlg.hxx:65
std::vector< std::unique_ptr< SwRedlineDataParent > > m_RedlineParents
Definition: redlndlg.hxx:59
std::vector< std::unique_ptr< RedlinData > > m_RedlinData
Definition: redlndlg.hxx:64
SvxRedlinTable * m_pTable
Definition: redlndlg.hxx:83
std::unique_ptr< SwRedlineAcceptDlg > mpImplDlg
Definition: redlndlg.hxx:156
SwRedlineAcceptPanel(weld::Widget *pParent)
Definition: redlndlg.cxx:1439
std::unique_ptr< weld::Container > mxContentArea
Definition: redlndlg.hxx:157
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
We need to be a SfxListener to be able to update the list of changes when we get SfxHintId::DocChange...
Definition: redlndlg.cxx:1455
virtual ~SwRedlineAcceptPanel() override
Definition: redlndlg.cxx:1451
sal_uInt16 GetSeqNo() const
Definition: redline.hxx:150
const SwRedlineData * Next() const
Definition: redline.hxx:131
const DateTime & GetTimeStamp() const
Definition: redline.hxx:130
static constexpr size_type npos
Definition: docary.hxx:223
vector_type::size_type size_type
Definition: docary.hxx:222
void AddRule(SwUndoArg eWhat, const OUString &rWith)
Definition: SwRewriter.cxx:25
OUString Apply(const OUString &rStr) const
Definition: SwRewriter.cxx:39
SwTableBox is one table cell in the document model.
Definition: swtable.hxx:426
SwTableLine * GetUpper()
Definition: swtable.hxx:460
SwTableLine is one table row in the document model.
Definition: swtable.hxx:364
SwRedlineTable::size_type UpdateTextChangesOnly(SwRedlineTable::size_type &rRedlinePos, bool bUpdateProperty=true) const
Definition: swtable.cxx:1618
RedlineType GetRedlineType() const
Definition: swtable.cxx:1782
static void SetCareDialog(const std::shared_ptr< weld::Window > &rNew)
Definition: viewsh.cxx:2655
SwDoc * GetDoc() const
Definition: viewsh.hxx:290
const IDocumentRedlineAccess & getIDocumentRedlineAccess() const
Provides access to the document redline interface.
Definition: viewsh.cxx:2811
const SfxItemPool & GetAttrPool() const
Definition: viewsh.hxx:624
Definition: view.hxx:146
SwWrtShell * GetWrtShellPtr() const
Definition: view.hxx:417
SwDocShell * GetDocShell()
Definition: view.cxx:1160
Used by the UI to modify the document model.
Definition: wrtsh.hxx:97
const SwRangeRedline * GotoRedline(SwRedlineTable::size_type nArrPos, bool bSelect)
Definition: move.cxx:717
void LeaveAddMode()
Definition: select.cxx:641
void EnterStdMode()
Definition: select.cxx:551
void SetInSelect()
Definition: wrtsh.hxx:145
void EnterAddMode()
Definition: select.cxx:626
const SwView & GetView() const
Definition: wrtsh.hxx:443
void SetTimeout(sal_uInt64 nTimeoutMs)
void SetInvokeHandler(const Link< Timer *, void > &rLink)
void disposeAndClear()
size_type erase(const Value &x)
std::pair< const_iterator, bool > insert(Value &&x)
virtual OUString get_active_text() const=0
virtual void set_active(int pos)=0
void append_text(const OUString &rStr)
virtual void scroll_to_row(int row)=0
virtual std::unique_ptr< TreeIter > make_iterator(const TreeIter *pOrig=nullptr) const=0
virtual bool get_selected(TreeIter *pIter) const=0
virtual void connect_popup_menu(const Link< const CommandEvent &, bool > &rLink)
virtual void make_sorted()=0
virtual void expand_row(const TreeIter &rIter)=0
virtual int get_iter_index_in_parent(const TreeIter &rIter) const=0
virtual void set_text(int row, const OUString &rText, int col=-1)=0
int get_checkbox_column_width() const
virtual int n_children() const=0
void unselect_all()
virtual void set_selection_mode(SelectionMode eMode)=0
virtual int get_sort_column() const=0
virtual void insert(const TreeIter *pParent, int pos, const OUString *pStr, const OUString *pId, const OUString *pIconName, VirtualDevice *pImageSurface, bool bChildrenOnDemand, TreeIter *pRet)=0
virtual void clear()=0
virtual int iter_n_children(const TreeIter &rIter) const=0
virtual void selected_foreach(const std::function< bool(TreeIter &)> &func)=0
void connect_changed(const Link< TreeView &, void > &rLink)
virtual void set_image(int row, const OUString &rImage, int col=-1)=0
virtual void copy_iterator(const TreeIter &rSource, TreeIter &rDest) const=0
virtual void remove(int pos)=0
virtual bool iter_next_sibling(TreeIter &rIter) const=0
virtual void select(int pos)=0
virtual bool iter_parent(TreeIter &rIter) const=0
virtual void set_column_fixed_widths(const std::vector< int > &rWidths)=0
virtual bool iter_children(TreeIter &rIter) const=0
virtual int get_column_width(int nCol) const=0
virtual void set_cursor(int pos)=0
virtual int get_iter_depth(const TreeIter &rIter) const=0
virtual void all_foreach(const std::function< bool(TreeIter &)> &func)=0
virtual void make_unsorted()=0
virtual int count_selected_rows() const=0
virtual OUString get_id(int pos) const=0
virtual void freeze()=0
virtual void thaw()=0
#define FN_REDLINE_ACCEPT
Definition: cmdid.h:134
#define FN_REDLINE_SHOW
Definition: cmdid.h:129
void Init()
int nCount
uno_Any a
LineEnd GetSystemLineEnd()
TOOLS_DLLPUBLIC OString convertLineEnd(const OString &rIn, LineEnd eLineEnd)
sal_uInt16 nPos
aStr
std::unique_ptr< sal_Int32[]> pData
int n2
int n1
int i
sal_Int32 toInt32(std::u16string_view str, sal_Int16 radix=10)
const ::avmedia::MediaItem * Execute(const SdrMarkView *pSdrView, SfxRequest const &rReq)
OUString toId(const void *pValue)
SwNodeOffset min(const SwNodeOffset &a, const SwNodeOffset &b)
Definition: nodeoffset.hxx:35
IMPL_LINK_NOARG(SwRedlineAcceptDlg, AcceptHdl, SvxTPView *, void)
Definition: redlndlg.cxx:1062
IMPL_LINK(SwRedlineAcceptDlg, CommandHdl, const CommandEvent &, rCEvt, bool)
Definition: redlndlg.cxx:1202
OUString aExtraString
SwNode & GetNode() const
Definition: pam.hxx:80
const SwRedlineData * pChild
Definition: redlndlg.hxx:38
std::unique_ptr< weld::TreeIter > xTLBChild
Definition: redlndlg.hxx:40
const SwRedlineDataChild * pNext
Definition: redlndlg.hxx:39
std::unique_ptr< weld::TreeIter > xTLBParent
Definition: redlndlg.hxx:47
const SwRedlineDataChild * pNext
Definition: redlndlg.hxx:46
const SwRedlineData * pData
Definition: redlndlg.hxx:45
SwView * GetActiveView()
Definition: swmodul1.cxx:116
OUString SwResId(TranslateId aId)
Definition: swmodule.cxx:165
#define SW_MOD()
Definition: swmodule.hxx:256
@ REJECT_REDLINE
@ ACCEPT_REDLINE
OUString GetAppLangDateTimeString(const DateTime &)
Definition: uitool.cxx:862
OUString sId
RET_OK