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