1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <unotools/localedatawrapper.hxx>
22 #include <chgtrack.hxx>
26 #include <tabview.hxx>
27 #include <viewutil.hxx>
28 #include <svx/svxdlg.hxx>
30 ScRedComDialog::ScRedComDialog( weld::Window
* pParent
, const SfxItemSet
& rCoreSet
,
31 ScDocShell
*pShell
, ScChangeAction
*pAction
, bool bPrevNext
)
32 : pChangeAction(nullptr)
36 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
37 pDlg
= pFact
->CreateSvxPostItDialog( pParent
, rCoreSet
, bPrevNext
);
39 pDlg
->DontChangeAuthor();
42 pDlg
->SetPrevHdl(LINK( this, ScRedComDialog
, PrevHdl
));
43 pDlg
->SetNextHdl(LINK( this, ScRedComDialog
, NextHdl
));
48 ScRedComDialog::~ScRedComDialog()
50 pDlg
.disposeAndClear();
53 ScChangeAction
*ScRedComDialog::FindPrev(ScChangeAction
*pAction
)
55 if(pAction
!=nullptr && pDocShell
!=nullptr)
57 ScDocument
& rDoc
= pDocShell
->GetDocument();
58 ScChangeViewSettings
* pSettings
= rDoc
.GetChangeViewSettings();
60 pAction
=pAction
->GetPrev();
62 while(pAction
!=nullptr)
64 if( pAction
->GetState()==SC_CAS_VIRGIN
&&
65 pAction
->IsDialogRoot() &&
66 ScViewUtil::IsActionShown(*pAction
,*pSettings
,rDoc
)) break;
68 pAction
=pAction
->GetPrev();
74 ScChangeAction
*ScRedComDialog::FindNext(ScChangeAction
*pAction
)
76 if(pAction
!=nullptr && pDocShell
!=nullptr)
78 ScDocument
& rDoc
= pDocShell
->GetDocument();
79 ScChangeViewSettings
* pSettings
= rDoc
.GetChangeViewSettings();
81 pAction
=pAction
->GetNext();
83 while(pAction
!=nullptr)
85 if( pAction
->GetState()==SC_CAS_VIRGIN
&&
86 pAction
->IsDialogRoot() &&
87 ScViewUtil::IsActionShown(*pAction
,*pSettings
,rDoc
)) break;
89 pAction
=pAction
->GetNext();
95 void ScRedComDialog::ReInit(ScChangeAction
*pAction
)
97 pChangeAction
=pAction
;
98 if(pChangeAction
==nullptr || pDocShell
==nullptr)
101 OUString aTitle
= pChangeAction
->GetDescription(pDocShell
->GetDocument());
102 pDlg
->SetText(aTitle
);
103 aComment
=pChangeAction
->GetComment();
105 bool bNext
=FindNext(pChangeAction
)!=nullptr;
106 bool bPrev
=FindPrev(pChangeAction
)!=nullptr;
107 pDlg
->EnableTravel(bNext
,bPrev
);
109 OUString aAuthor
= pChangeAction
->GetUser();
111 DateTime aDT
= pChangeAction
->GetDateTime();
112 OUString aDate
= ScGlobal::getLocaleData().getDate( aDT
) + " " +
113 ScGlobal::getLocaleData().getTime( aDT
, false );
115 pDlg
->ShowLastAuthor(aAuthor
, aDate
);
116 pDlg
->SetNote(aComment
);
119 void ScRedComDialog::Execute()
121 short nRet
=pDlg
->Execute();
125 if ( pDocShell
!=nullptr && pDlg
->GetNote() != aComment
)
126 pDocShell
->SetChangeComment( pChangeAction
, pDlg
->GetNote());
130 void ScRedComDialog::SelectCell()
132 if (!pChangeAction
|| !pDocShell
)
135 const ScChangeAction
* pAction
=pChangeAction
;
136 const ScBigRange
& rRange
= pAction
->GetBigRange();
138 if(rRange
.IsValid(pDocShell
->GetDocument()))
140 if (ScViewData
* pViewData
= ScDocShell::GetViewData())
142 ScRange aRef
= rRange
.MakeRange(pDocShell
->GetDocument());
143 ScTabView
* pTabView
= pViewData
->GetView();
144 pTabView
->MarkRange(aRef
);
149 IMPL_LINK(ScRedComDialog
, PrevHdl
, AbstractSvxPostItDialog
&, rDlgP
, void )
151 if (pDocShell
!=nullptr && rDlgP
.GetNote() != aComment
)
152 pDocShell
->SetChangeComment( pChangeAction
, rDlgP
.GetNote());
154 ReInit(FindPrev(pChangeAction
));
158 IMPL_LINK(ScRedComDialog
, NextHdl
, AbstractSvxPostItDialog
&, rDlgP
, void )
160 if ( pDocShell
!=nullptr && rDlgP
.GetNote() != aComment
)
161 pDocShell
->SetChangeComment( pChangeAction
, rDlgP
.GetNote());
163 ReInit(FindNext(pChangeAction
));
167 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */