1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_sc.hxx" 30 31 32 #include <vcl/msgbox.hxx> 33 #include <unotools/localedatawrapper.hxx> 34 35 #include "redcom.hxx" 36 #include "docsh.hxx" 37 #include "tabvwsh.hxx" 38 #include <svx/svxdlg.hxx> //CHINA001 39 #include <svx/dialogs.hrc> //CHINA001 40 //------------------------------------------------------------------------ 41 42 ScRedComDialog::ScRedComDialog( Window* pParent, const SfxItemSet& rCoreSet, 43 ScDocShell *pShell,ScChangeAction *pAction,sal_Bool bPrevNext) 44 { 45 //CHINA001 pDlg = new SvxPostItDialog(pParent,rCoreSet,bPrevNext,sal_True); 46 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); 47 if(pFact) 48 { 49 pDlg = pFact->CreateSvxPostItDialog( pParent, rCoreSet, bPrevNext, sal_True ); 50 DBG_ASSERT(pDlg, "Dialogdiet fail!");//CHINA001 51 pDocShell=pShell; 52 pDlg->DontChangeAuthor(); 53 pDlg->HideAuthor(); 54 55 pDlg->SetPrevHdl(LINK( this, ScRedComDialog, PrevHdl)); 56 pDlg->SetNextHdl(LINK( this, ScRedComDialog, NextHdl)); 57 58 ReInit(pAction); 59 } 60 } 61 62 ScRedComDialog::~ScRedComDialog() 63 { 64 delete pDlg; 65 } 66 67 ScChangeAction *ScRedComDialog::FindPrev(ScChangeAction *pAction) 68 { 69 if(pAction!=NULL && pDocShell !=NULL) 70 { 71 ScDocument* pDoc = pDocShell->GetDocument(); 72 ScChangeViewSettings* pSettings = pDoc->GetChangeViewSettings(); 73 74 pAction=pAction->GetPrev(); 75 76 while(pAction!=NULL) 77 { 78 if( pAction->GetState()==SC_CAS_VIRGIN && 79 pAction->IsDialogRoot() && 80 ScViewUtil::IsActionShown(*pAction,*pSettings,*pDoc)) break; 81 82 pAction=pAction->GetPrev(); 83 } 84 } 85 return pAction; 86 } 87 88 ScChangeAction *ScRedComDialog::FindNext(ScChangeAction *pAction) 89 { 90 if(pAction!=NULL && pDocShell !=NULL) 91 { 92 ScDocument* pDoc = pDocShell->GetDocument(); 93 ScChangeViewSettings* pSettings = pDoc->GetChangeViewSettings(); 94 95 pAction=pAction->GetNext(); 96 97 while(pAction!=NULL) 98 { 99 if( pAction->GetState()==SC_CAS_VIRGIN && 100 pAction->IsDialogRoot() && 101 ScViewUtil::IsActionShown(*pAction,*pSettings,*pDoc)) break; 102 103 pAction=pAction->GetNext(); 104 } 105 } 106 return pAction; 107 } 108 109 void ScRedComDialog::ReInit(ScChangeAction *pAction) 110 { 111 pChangeAction=pAction; 112 if(pChangeAction!=NULL && pDocShell !=NULL) 113 { 114 String aTitle; 115 pChangeAction->GetDescription( aTitle, pDocShell->GetDocument()); 116 pDlg->SetText(aTitle); 117 aComment=pChangeAction->GetComment(); 118 119 sal_Bool bNext=FindNext(pChangeAction)!=NULL; 120 sal_Bool bPrev=FindPrev(pChangeAction)!=NULL; 121 pDlg->EnableTravel(bNext,bPrev); 122 123 String aAuthor = pChangeAction->GetUser(); 124 125 DateTime aDT = pChangeAction->GetDateTime(); 126 String aDate = ScGlobal::pLocaleData->getDate( aDT ); 127 aDate += ' '; 128 aDate += ScGlobal::pLocaleData->getTime( aDT, sal_False, sal_False ); 129 130 pDlg->ShowLastAuthor(aAuthor, aDate); 131 pDlg->SetNote(aComment); 132 } 133 } 134 135 short ScRedComDialog::Execute() 136 { 137 short nRet=pDlg->Execute(); 138 139 if(nRet== RET_OK ) 140 { 141 if ( pDocShell!=NULL && pDlg->GetNote() != aComment ) 142 pDocShell->SetChangeComment( pChangeAction, pDlg->GetNote()); 143 } 144 145 return nRet; 146 } 147 148 void ScRedComDialog::SelectCell() 149 { 150 if(pChangeAction!=NULL) 151 { 152 const ScChangeAction* pAction=pChangeAction; 153 const ScBigRange& rRange = pAction->GetBigRange(); 154 155 if(rRange.IsValid(pDocShell->GetDocument())) 156 { 157 ScViewData* pViewData=pDocShell->GetViewData(); 158 ScRange aRef=rRange.MakeRange(); 159 ScTabView* pTabView=pViewData->GetView(); 160 pTabView->MarkRange(aRef); 161 } 162 } 163 } 164 165 IMPL_LINK(ScRedComDialog, PrevHdl, AbstractSvxPostItDialog*, pDlgP ) 166 { 167 if (pDocShell!=NULL && pDlgP->GetNote() != aComment ) 168 pDocShell->SetChangeComment( pChangeAction, pDlgP->GetNote()); 169 170 ReInit(FindPrev(pChangeAction)); 171 SelectCell(); 172 173 return 0; 174 } 175 176 IMPL_LINK(ScRedComDialog, NextHdl, AbstractSvxPostItDialog*, pDlgP ) 177 { 178 if ( pDocShell!=NULL && pDlgP->GetNote() != aComment ) 179 pDocShell->SetChangeComment( pChangeAction, pDlgP->GetNote()); 180 181 ReInit(FindNext(pChangeAction)); 182 SelectCell(); 183 184 return 0; 185 } 186 187