/src/libreoffice/sc/source/ui/miscdlgs/redcom.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 <unotools/localedatawrapper.hxx> |
21 | | |
22 | | #include <chgtrack.hxx> |
23 | | #include <redcom.hxx> |
24 | | #include <docsh.hxx> |
25 | | #include <dbfunc.hxx> |
26 | | #include <tabview.hxx> |
27 | | #include <viewutil.hxx> |
28 | | #include <svx/svxdlg.hxx> |
29 | | |
30 | | ScRedComDialog::ScRedComDialog( weld::Window* pParent, const SfxItemSet& rCoreSet, |
31 | | ScDocShell *pShell, ScChangeAction *pAction, bool bPrevNext) |
32 | 0 | : pChangeAction(nullptr) |
33 | 0 | , pDocShell(nullptr) |
34 | 0 | , pDlg(nullptr) |
35 | 0 | { |
36 | 0 | SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); |
37 | 0 | pDlg = pFact->CreateSvxPostItDialog( pParent, rCoreSet, bPrevNext ); |
38 | 0 | pDocShell=pShell; |
39 | 0 | pDlg->DontChangeAuthor(); |
40 | 0 | pDlg->HideAuthor(); |
41 | |
|
42 | 0 | pDlg->SetPrevHdl(LINK( this, ScRedComDialog, PrevHdl)); |
43 | 0 | pDlg->SetNextHdl(LINK( this, ScRedComDialog, NextHdl)); |
44 | |
|
45 | 0 | ReInit(pAction); |
46 | 0 | } |
47 | | |
48 | | ScRedComDialog::~ScRedComDialog() |
49 | 0 | { |
50 | 0 | pDlg.disposeAndClear(); |
51 | 0 | } |
52 | | |
53 | | ScChangeAction *ScRedComDialog::FindPrev(ScChangeAction *pAction) |
54 | 0 | { |
55 | 0 | if(pAction!=nullptr && pDocShell !=nullptr) |
56 | 0 | { |
57 | 0 | ScDocument& rDoc = pDocShell->GetDocument(); |
58 | 0 | ScChangeViewSettings* pSettings = rDoc.GetChangeViewSettings(); |
59 | |
|
60 | 0 | pAction=pAction->GetPrev(); |
61 | |
|
62 | 0 | while(pAction!=nullptr) |
63 | 0 | { |
64 | 0 | if( pAction->GetState()==SC_CAS_VIRGIN && |
65 | 0 | pAction->IsDialogRoot() && |
66 | 0 | ScViewUtil::IsActionShown(*pAction,*pSettings,rDoc)) break; |
67 | | |
68 | 0 | pAction=pAction->GetPrev(); |
69 | 0 | } |
70 | 0 | } |
71 | 0 | return pAction; |
72 | 0 | } |
73 | | |
74 | | ScChangeAction *ScRedComDialog::FindNext(ScChangeAction *pAction) |
75 | 0 | { |
76 | 0 | if(pAction!=nullptr && pDocShell !=nullptr) |
77 | 0 | { |
78 | 0 | ScDocument& rDoc = pDocShell->GetDocument(); |
79 | 0 | ScChangeViewSettings* pSettings = rDoc.GetChangeViewSettings(); |
80 | |
|
81 | 0 | pAction=pAction->GetNext(); |
82 | |
|
83 | 0 | while(pAction!=nullptr) |
84 | 0 | { |
85 | 0 | if( pAction->GetState()==SC_CAS_VIRGIN && |
86 | 0 | pAction->IsDialogRoot() && |
87 | 0 | ScViewUtil::IsActionShown(*pAction,*pSettings,rDoc)) break; |
88 | | |
89 | 0 | pAction=pAction->GetNext(); |
90 | 0 | } |
91 | 0 | } |
92 | 0 | return pAction; |
93 | 0 | } |
94 | | |
95 | | void ScRedComDialog::ReInit(ScChangeAction *pAction) |
96 | 0 | { |
97 | 0 | pChangeAction=pAction; |
98 | 0 | if(pChangeAction==nullptr || pDocShell ==nullptr) |
99 | 0 | return; |
100 | | |
101 | 0 | OUString aTitle = pChangeAction->GetDescription(pDocShell->GetDocument()); |
102 | 0 | pDlg->SetText(aTitle); |
103 | 0 | aComment=pChangeAction->GetComment(); |
104 | |
|
105 | 0 | bool bNext=FindNext(pChangeAction)!=nullptr; |
106 | 0 | bool bPrev=FindPrev(pChangeAction)!=nullptr; |
107 | 0 | pDlg->EnableTravel(bNext,bPrev); |
108 | |
|
109 | 0 | OUString aAuthor = pChangeAction->GetUser(); |
110 | |
|
111 | 0 | DateTime aDT = pChangeAction->GetDateTime(); |
112 | 0 | OUString aDate = ScGlobal::getLocaleData().getDate( aDT ) + " " + |
113 | 0 | ScGlobal::getLocaleData().getTime( aDT, false ); |
114 | |
|
115 | 0 | pDlg->ShowLastAuthor(aAuthor, aDate); |
116 | 0 | pDlg->SetNote(aComment); |
117 | 0 | } |
118 | | |
119 | | void ScRedComDialog::Execute() |
120 | 0 | { |
121 | 0 | short nRet=pDlg->Execute(); |
122 | |
|
123 | 0 | if(nRet== RET_OK ) |
124 | 0 | { |
125 | 0 | if ( pDocShell!=nullptr && pDlg->GetNote() != aComment ) |
126 | 0 | pDocShell->SetChangeComment( pChangeAction, pDlg->GetNote()); |
127 | 0 | } |
128 | 0 | } |
129 | | |
130 | | void ScRedComDialog::SelectCell() |
131 | 0 | { |
132 | 0 | if (!pChangeAction || !pDocShell) |
133 | 0 | return; |
134 | | |
135 | 0 | const ScChangeAction* pAction=pChangeAction; |
136 | 0 | const ScBigRange& rRange = pAction->GetBigRange(); |
137 | |
|
138 | 0 | if(rRange.IsValid(pDocShell->GetDocument())) |
139 | 0 | { |
140 | 0 | if (ScViewData* pViewData = ScDocShell::GetViewData()) |
141 | 0 | { |
142 | 0 | ScRange aRef = rRange.MakeRange(pDocShell->GetDocument()); |
143 | 0 | ScTabView* pTabView = pViewData->GetView(); |
144 | 0 | pTabView->MarkRange(aRef); |
145 | 0 | } |
146 | 0 | } |
147 | 0 | } |
148 | | |
149 | | IMPL_LINK(ScRedComDialog, PrevHdl, AbstractSvxPostItDialog&, rDlgP, void ) |
150 | 0 | { |
151 | 0 | if (pDocShell!=nullptr && rDlgP.GetNote() != aComment ) |
152 | 0 | pDocShell->SetChangeComment( pChangeAction, rDlgP.GetNote()); |
153 | |
|
154 | 0 | ReInit(FindPrev(pChangeAction)); |
155 | 0 | SelectCell(); |
156 | 0 | } |
157 | | |
158 | | IMPL_LINK(ScRedComDialog, NextHdl, AbstractSvxPostItDialog&, rDlgP, void ) |
159 | 0 | { |
160 | 0 | if ( pDocShell!=nullptr && rDlgP.GetNote() != aComment ) |
161 | 0 | pDocShell->SetChangeComment( pChangeAction, rDlgP.GetNote()); |
162 | |
|
163 | 0 | ReInit(FindNext(pChangeAction)); |
164 | 0 | SelectCell(); |
165 | 0 | } |
166 | | |
167 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |