xref: /AOO41X/main/sc/source/ui/miscdlgs/redcom.cxx (revision b3f79822e811ac3493b185030a72c3c5a51f32d8)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sc.hxx"
26 
27 
28 #include <vcl/msgbox.hxx>
29 #include <unotools/localedatawrapper.hxx>
30 
31 #include "redcom.hxx"
32 #include "docsh.hxx"
33 #include "tabvwsh.hxx"
34 #include <svx/svxdlg.hxx> //CHINA001
35 #include <svx/dialogs.hrc> //CHINA001
36 //------------------------------------------------------------------------
37 
ScRedComDialog(Window * pParent,const SfxItemSet & rCoreSet,ScDocShell * pShell,ScChangeAction * pAction,sal_Bool bPrevNext)38 ScRedComDialog::ScRedComDialog( Window* pParent, const SfxItemSet& rCoreSet,
39                     ScDocShell *pShell,ScChangeAction *pAction,sal_Bool bPrevNext)
40 {
41     //CHINA001 pDlg = new SvxPostItDialog(pParent,rCoreSet,bPrevNext,sal_True);
42     SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
43     if(pFact)
44     {
45         pDlg = pFact->CreateSvxPostItDialog( pParent, rCoreSet, bPrevNext, sal_True );
46         DBG_ASSERT(pDlg, "Dialogdiet fail!");//CHINA001
47         pDocShell=pShell;
48         pDlg->DontChangeAuthor();
49         pDlg->HideAuthor();
50 
51         pDlg->SetPrevHdl(LINK( this, ScRedComDialog, PrevHdl));
52         pDlg->SetNextHdl(LINK( this, ScRedComDialog, NextHdl));
53 
54         ReInit(pAction);
55     }
56 }
57 
~ScRedComDialog()58 ScRedComDialog::~ScRedComDialog()
59 {
60     delete pDlg;
61 }
62 
FindPrev(ScChangeAction * pAction)63 ScChangeAction *ScRedComDialog::FindPrev(ScChangeAction *pAction)
64 {
65     if(pAction!=NULL && pDocShell !=NULL)
66     {
67         ScDocument* pDoc = pDocShell->GetDocument();
68         ScChangeViewSettings* pSettings = pDoc->GetChangeViewSettings();
69 
70         pAction=pAction->GetPrev();
71 
72         while(pAction!=NULL)
73         {
74             if( pAction->GetState()==SC_CAS_VIRGIN &&
75                 pAction->IsDialogRoot() &&
76                 ScViewUtil::IsActionShown(*pAction,*pSettings,*pDoc)) break;
77 
78             pAction=pAction->GetPrev();
79         }
80     }
81     return pAction;
82 }
83 
FindNext(ScChangeAction * pAction)84 ScChangeAction *ScRedComDialog::FindNext(ScChangeAction *pAction)
85 {
86     if(pAction!=NULL && pDocShell !=NULL)
87     {
88         ScDocument* pDoc = pDocShell->GetDocument();
89         ScChangeViewSettings* pSettings = pDoc->GetChangeViewSettings();
90 
91         pAction=pAction->GetNext();
92 
93         while(pAction!=NULL)
94         {
95             if( pAction->GetState()==SC_CAS_VIRGIN &&
96                 pAction->IsDialogRoot() &&
97                 ScViewUtil::IsActionShown(*pAction,*pSettings,*pDoc)) break;
98 
99             pAction=pAction->GetNext();
100         }
101     }
102     return pAction;
103 }
104 
ReInit(ScChangeAction * pAction)105 void ScRedComDialog::ReInit(ScChangeAction *pAction)
106 {
107     pChangeAction=pAction;
108     if(pChangeAction!=NULL && pDocShell !=NULL)
109     {
110         String aTitle;
111         pChangeAction->GetDescription( aTitle, pDocShell->GetDocument());
112         pDlg->SetText(aTitle);
113         aComment=pChangeAction->GetComment();
114 
115         sal_Bool bNext=FindNext(pChangeAction)!=NULL;
116         sal_Bool bPrev=FindPrev(pChangeAction)!=NULL;
117         pDlg->EnableTravel(bNext,bPrev);
118 
119         String aAuthor = pChangeAction->GetUser();
120 
121         DateTime aDT = pChangeAction->GetDateTime();
122         String aDate = ScGlobal::pLocaleData->getDate( aDT );
123         aDate += ' ';
124         aDate += ScGlobal::pLocaleData->getTime( aDT, sal_False, sal_False );
125 
126         pDlg->ShowLastAuthor(aAuthor, aDate);
127         pDlg->SetNote(aComment);
128     }
129 }
130 
Execute()131 short ScRedComDialog::Execute()
132 {
133     short nRet=pDlg->Execute();
134 
135     if(nRet== RET_OK )
136     {
137         if ( pDocShell!=NULL && pDlg->GetNote() != aComment )
138             pDocShell->SetChangeComment( pChangeAction, pDlg->GetNote());
139     }
140 
141     return nRet;
142 }
143 
SelectCell()144 void ScRedComDialog::SelectCell()
145 {
146     if(pChangeAction!=NULL)
147     {
148         const ScChangeAction* pAction=pChangeAction;
149         const ScBigRange& rRange = pAction->GetBigRange();
150 
151         if(rRange.IsValid(pDocShell->GetDocument()))
152         {
153             ScViewData* pViewData=pDocShell->GetViewData();
154             ScRange aRef=rRange.MakeRange();
155             ScTabView* pTabView=pViewData->GetView();
156             pTabView->MarkRange(aRef);
157         }
158     }
159 }
160 
IMPL_LINK(ScRedComDialog,PrevHdl,AbstractSvxPostItDialog *,pDlgP)161 IMPL_LINK(ScRedComDialog, PrevHdl, AbstractSvxPostItDialog*, pDlgP )
162 {
163     if (pDocShell!=NULL && pDlgP->GetNote() != aComment )
164         pDocShell->SetChangeComment( pChangeAction, pDlgP->GetNote());
165 
166     ReInit(FindPrev(pChangeAction));
167     SelectCell();
168 
169     return 0;
170 }
171 
IMPL_LINK(ScRedComDialog,NextHdl,AbstractSvxPostItDialog *,pDlgP)172 IMPL_LINK(ScRedComDialog, NextHdl, AbstractSvxPostItDialog*, pDlgP )
173 {
174     if ( pDocShell!=NULL && pDlgP->GetNote() != aComment )
175         pDocShell->SetChangeComment( pChangeAction, pDlgP->GetNote());
176 
177     ReInit(FindNext(pChangeAction));
178     SelectCell();
179 
180     return 0;
181 }
182 
183