Stop leaking all ScPostIt instances.
[LibreOffice.git] / sc / source / ui / miscdlgs / redcom.cxx
blob18411075a7ee9741d5785b608f7d25f1e502f624
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <vcl/msgbox.hxx>
21 #include <unotools/localedatawrapper.hxx>
23 #include "redcom.hxx"
24 #include "docsh.hxx"
25 #include "tabvwsh.hxx"
26 #include <svx/svxdlg.hxx>
27 #include <svx/dialogs.hrc>
28 //------------------------------------------------------------------------
30 ScRedComDialog::ScRedComDialog( Window* pParent, const SfxItemSet& rCoreSet,
31 ScDocShell *pShell,ScChangeAction *pAction,sal_Bool bPrevNext)
33 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
34 if(pFact)
36 pDlg = pFact->CreateSvxPostItDialog( pParent, rCoreSet, bPrevNext );
37 OSL_ENSURE(pDlg, "Dialog creation failed!");
38 pDocShell=pShell;
39 pDlg->DontChangeAuthor();
40 pDlg->HideAuthor();
42 pDlg->SetPrevHdl(LINK( this, ScRedComDialog, PrevHdl));
43 pDlg->SetNextHdl(LINK( this, ScRedComDialog, NextHdl));
45 ReInit(pAction);
49 ScRedComDialog::~ScRedComDialog()
51 delete pDlg;
54 ScChangeAction *ScRedComDialog::FindPrev(ScChangeAction *pAction)
56 if(pAction!=NULL && pDocShell !=NULL)
58 ScDocument* pDoc = pDocShell->GetDocument();
59 ScChangeViewSettings* pSettings = pDoc->GetChangeViewSettings();
61 pAction=pAction->GetPrev();
63 while(pAction!=NULL)
65 if( pAction->GetState()==SC_CAS_VIRGIN &&
66 pAction->IsDialogRoot() &&
67 ScViewUtil::IsActionShown(*pAction,*pSettings,*pDoc)) break;
69 pAction=pAction->GetPrev();
72 return pAction;
75 ScChangeAction *ScRedComDialog::FindNext(ScChangeAction *pAction)
77 if(pAction!=NULL && pDocShell !=NULL)
79 ScDocument* pDoc = pDocShell->GetDocument();
80 ScChangeViewSettings* pSettings = pDoc->GetChangeViewSettings();
82 pAction=pAction->GetNext();
84 while(pAction!=NULL)
86 if( pAction->GetState()==SC_CAS_VIRGIN &&
87 pAction->IsDialogRoot() &&
88 ScViewUtil::IsActionShown(*pAction,*pSettings,*pDoc)) break;
90 pAction=pAction->GetNext();
93 return pAction;
96 void ScRedComDialog::ReInit(ScChangeAction *pAction)
98 pChangeAction=pAction;
99 if(pChangeAction!=NULL && pDocShell !=NULL)
101 OUString aTitle;
102 pChangeAction->GetDescription( aTitle, pDocShell->GetDocument());
103 pDlg->SetText(aTitle);
104 aComment=pChangeAction->GetComment();
106 sal_Bool bNext=FindNext(pChangeAction)!=NULL;
107 sal_Bool bPrev=FindPrev(pChangeAction)!=NULL;
108 pDlg->EnableTravel(bNext,bPrev);
110 OUString aAuthor = pChangeAction->GetUser();
112 DateTime aDT = pChangeAction->GetDateTime();
113 OUString aDate = ScGlobal::pLocaleData->getDate( aDT );
114 aDate += " ";
115 aDate += ScGlobal::pLocaleData->getTime( aDT, false, false );
117 pDlg->ShowLastAuthor(aAuthor, aDate);
118 pDlg->SetNote(aComment);
122 short ScRedComDialog::Execute()
124 short nRet=pDlg->Execute();
126 if(nRet== RET_OK )
128 if ( pDocShell!=NULL && pDlg->GetNote() != aComment )
129 pDocShell->SetChangeComment( pChangeAction, pDlg->GetNote());
132 return nRet;
135 void ScRedComDialog::SelectCell()
137 if(pChangeAction!=NULL)
139 const ScChangeAction* pAction=pChangeAction;
140 const ScBigRange& rRange = pAction->GetBigRange();
142 if(rRange.IsValid(pDocShell->GetDocument()))
144 ScViewData* pViewData=pDocShell->GetViewData();
145 ScRange aRef=rRange.MakeRange();
146 ScTabView* pTabView=pViewData->GetView();
147 pTabView->MarkRange(aRef);
152 IMPL_LINK(ScRedComDialog, PrevHdl, AbstractSvxPostItDialog*, pDlgP )
154 if (pDocShell!=NULL && pDlgP->GetNote() != aComment )
155 pDocShell->SetChangeComment( pChangeAction, pDlgP->GetNote());
157 ReInit(FindPrev(pChangeAction));
158 SelectCell();
160 return 0;
163 IMPL_LINK(ScRedComDialog, NextHdl, AbstractSvxPostItDialog*, pDlgP )
165 if ( pDocShell!=NULL && pDlgP->GetNote() != aComment )
166 pDocShell->SetChangeComment( pChangeAction, pDlgP->GetNote());
168 ReInit(FindNext(pChangeAction));
169 SelectCell();
171 return 0;
174 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */