update dev300-m58
[ooovba.git] / sc / source / ui / miscdlgs / redcom.cxx
blob3f778478f47d80547a2084a0d7a59dfaaf814c60
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: redcom.cxx,v $
10 * $Revision: 1.11 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
35 #include <vcl/msgbox.hxx>
36 #include <unotools/localedatawrapper.hxx>
38 #include "redcom.hxx"
39 #include "docsh.hxx"
40 #include "tabvwsh.hxx"
41 #include <svx/svxdlg.hxx> //CHINA001
42 #include <svx/dialogs.hrc> //CHINA001
43 //------------------------------------------------------------------------
45 ScRedComDialog::ScRedComDialog( Window* pParent, const SfxItemSet& rCoreSet,
46 ScDocShell *pShell,ScChangeAction *pAction,BOOL bPrevNext)
48 //CHINA001 pDlg = new SvxPostItDialog(pParent,rCoreSet,bPrevNext,TRUE);
49 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
50 if(pFact)
52 pDlg = pFact->CreateSvxPostItDialog( pParent, rCoreSet, RID_SVXDLG_POSTIT, bPrevNext, TRUE );
53 DBG_ASSERT(pDlg, "Dialogdiet fail!");//CHINA001
54 pDocShell=pShell;
55 pDlg->DontChangeAuthor();
56 pDlg->HideAuthor();
58 pDlg->SetPrevHdl(LINK( this, ScRedComDialog, PrevHdl));
59 pDlg->SetNextHdl(LINK( this, ScRedComDialog, NextHdl));
61 ReInit(pAction);
65 ScRedComDialog::~ScRedComDialog()
67 delete pDlg;
70 ScChangeAction *ScRedComDialog::FindPrev(ScChangeAction *pAction)
72 if(pAction!=NULL && pDocShell !=NULL)
74 ScDocument* pDoc = pDocShell->GetDocument();
75 ScChangeViewSettings* pSettings = pDoc->GetChangeViewSettings();
77 pAction=pAction->GetPrev();
79 while(pAction!=NULL)
81 if( pAction->GetState()==SC_CAS_VIRGIN &&
82 pAction->IsDialogRoot() &&
83 ScViewUtil::IsActionShown(*pAction,*pSettings,*pDoc)) break;
85 pAction=pAction->GetPrev();
88 return pAction;
91 ScChangeAction *ScRedComDialog::FindNext(ScChangeAction *pAction)
93 if(pAction!=NULL && pDocShell !=NULL)
95 ScDocument* pDoc = pDocShell->GetDocument();
96 ScChangeViewSettings* pSettings = pDoc->GetChangeViewSettings();
98 pAction=pAction->GetNext();
100 while(pAction!=NULL)
102 if( pAction->GetState()==SC_CAS_VIRGIN &&
103 pAction->IsDialogRoot() &&
104 ScViewUtil::IsActionShown(*pAction,*pSettings,*pDoc)) break;
106 pAction=pAction->GetNext();
109 return pAction;
112 void ScRedComDialog::ReInit(ScChangeAction *pAction)
114 pChangeAction=pAction;
115 if(pChangeAction!=NULL && pDocShell !=NULL)
117 String aTitle;
118 pChangeAction->GetDescription( aTitle, pDocShell->GetDocument());
119 pDlg->SetText(aTitle);
120 aComment=pChangeAction->GetComment();
122 BOOL bNext=FindNext(pChangeAction)!=NULL;
123 BOOL bPrev=FindPrev(pChangeAction)!=NULL;
124 pDlg->EnableTravel(bNext,bPrev);
126 String aAuthor = pChangeAction->GetUser();
128 DateTime aDT = pChangeAction->GetDateTime();
129 String aDate = ScGlobal::pLocaleData->getDate( aDT );
130 aDate += ' ';
131 aDate += ScGlobal::pLocaleData->getTime( aDT, FALSE, FALSE );
133 pDlg->ShowLastAuthor(aAuthor, aDate);
134 pDlg->SetNote(aComment);
138 short ScRedComDialog::Execute()
140 short nRet=pDlg->Execute();
142 if(nRet== RET_OK )
144 if ( pDocShell!=NULL && pDlg->GetNote() != aComment )
145 pDocShell->SetChangeComment( pChangeAction, pDlg->GetNote());
148 return nRet;
151 void ScRedComDialog::SelectCell()
153 if(pChangeAction!=NULL)
155 const ScChangeAction* pAction=pChangeAction;
156 const ScBigRange& rRange = pAction->GetBigRange();
158 if(rRange.IsValid(pDocShell->GetDocument()))
160 ScViewData* pViewData=pDocShell->GetViewData();
161 ScRange aRef=rRange.MakeRange();
162 ScTabView* pTabView=pViewData->GetView();
163 pTabView->MarkRange(aRef);
168 IMPL_LINK(ScRedComDialog, PrevHdl, AbstractSvxPostItDialog*, pDlgP )
170 if (pDocShell!=NULL && pDlgP->GetNote() != aComment )
171 pDocShell->SetChangeComment( pChangeAction, pDlgP->GetNote());
173 ReInit(FindPrev(pChangeAction));
174 SelectCell();
176 return 0;
179 IMPL_LINK(ScRedComDialog, NextHdl, AbstractSvxPostItDialog*, pDlgP )
181 if ( pDocShell!=NULL && pDlgP->GetNote() != aComment )
182 pDocShell->SetChangeComment( pChangeAction, pDlgP->GetNote());
184 ReInit(FindNext(pChangeAction));
185 SelectCell();
187 return 0;