Stop leaking all ScPostIt instances.
[LibreOffice.git] / sc / source / ui / miscdlgs / acredlin.cxx
blobc6aadee3a21189fe0f01e773a2453f69982a50c2
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 .
21 #include <comphelper/string.hxx>
22 #include <svl/undo.hxx>
23 #include <unotools/textsearch.hxx>
24 #include <unotools/localedatawrapper.hxx>
25 #include <unotools/collatorwrapper.hxx>
26 #include <vcl/msgbox.hxx>
27 #include <sfx2/app.hxx>
28 #include <sfx2/viewfrm.hxx>
30 #include "acredlin.hxx"
31 #include "global.hxx"
32 #include "reffact.hxx"
33 #include "document.hxx"
34 #include "docsh.hxx"
35 #include "scresid.hxx"
36 #include "globstr.hrc"
37 #include "acredlin.hrc"
38 #include "simpref.hxx"
39 #include "scmod.hxx"
40 #include "popmenu.hxx"
41 #include "tabvwsh.hxx"
43 // defines -------------------------------------------------------------------
45 #define ABS_SREF SCA_VALID \
46 | SCA_COL_ABSOLUTE | SCA_ROW_ABSOLUTE | SCA_TAB_ABSOLUTE
47 #define ABS_DREF ABS_SREF \
48 | SCA_COL2_ABSOLUTE | SCA_ROW2_ABSOLUTE | SCA_TAB2_ABSOLUTE
49 #define ABS_DREF3D ABS_DREF | SCA_TAB_3D
51 #define RD_SPECIAL_NONE 0
52 #define RD_SPECIAL_CONTENT 1
53 #define RD_SPECIAL_VISCONTENT 2
55 //============================================================================
56 // class ScRedlinData
57 //----------------------------------------------------------------------------
58 ScRedlinData::ScRedlinData()
59 :RedlinData()
61 nInfo=RD_SPECIAL_NONE;
62 nActionNo=0;
63 pData=NULL;
64 bDisabled=false;
65 bIsRejectable=false;
66 bIsAcceptable=false;
67 nTable=SCTAB_MAX;
68 nCol=SCCOL_MAX;
69 nRow=SCROW_MAX;
72 ScRedlinData::~ScRedlinData()
74 nInfo=RD_SPECIAL_NONE;
75 nActionNo=0;
76 pData=NULL;
77 bDisabled=false;
78 bIsRejectable=false;
79 bIsAcceptable=false;
82 //============================================================================
83 // class ScAcceptChgDlg
84 //----------------------------------------------------------------------------
85 ScAcceptChgDlg::ScAcceptChgDlg(SfxBindings* pB, SfxChildWindow* pCW, Window* pParent,
86 ScViewData* ptrViewData)
87 : SfxModelessDialog(pB, pCW, pParent,
88 "AcceptRejectChangesDialog", "svx/ui/acceptrejectchangesdialog.ui"),
89 pViewData ( ptrViewData ),
90 pDoc ( ptrViewData->GetDocument() ),
91 aLocalRangeName ( *(pDoc->GetRangeName()) ),
92 aStrInsertCols (SC_RESSTR(STR_CHG_INSERT_COLS)),
93 aStrInsertRows (SC_RESSTR(STR_CHG_INSERT_ROWS)),
94 aStrInsertTabs (SC_RESSTR(STR_CHG_INSERT_TABS)),
95 aStrDeleteCols (SC_RESSTR(STR_CHG_DELETE_COLS)),
96 aStrDeleteRows (SC_RESSTR(STR_CHG_DELETE_ROWS)),
97 aStrDeleteTabs (SC_RESSTR(STR_CHG_DELETE_TABS)),
98 aStrMove (SC_RESSTR(STR_CHG_MOVE)),
99 aStrContent (SC_RESSTR(STR_CHG_CONTENT)),
100 aStrReject (SC_RESSTR(STR_CHG_REJECT)),
101 aStrAllAccepted (SC_RESSTR(STR_CHG_ACCEPTED)),
102 aStrAllRejected (SC_RESSTR(STR_CHG_REJECTED)),
103 aStrNoEntry (SC_RESSTR(STR_CHG_NO_ENTRY)),
104 aStrContentWithChild (SC_RESSTR(STR_CHG_CONTENT_WITH_CHILD)),
105 aStrChildContent (SC_RESSTR(STR_CHG_CHILD_CONTENT)),
106 aStrChildOrgContent (SC_RESSTR(STR_CHG_CHILD_ORGCONTENT)),
107 aStrEmpty (SC_RESSTR(STR_CHG_EMPTY)),
108 aUnknown("Unknown"),
109 bAcceptEnableFlag(true),
110 bRejectEnableFlag(true),
111 bNeedsUpdate(false),
112 bIgnoreMsg(false),
113 bNoSelection(false),
114 bHasFilterEntry(false),
115 bUseColor(false)
117 m_pAcceptChgCtr = new SvxAcceptChgCtr(get_content_area());
118 nAcceptCount=0;
119 nRejectCount=0;
120 aReOpenTimer.SetTimeout(50);
121 aReOpenTimer.SetTimeoutHdl(LINK( this, ScAcceptChgDlg, ReOpenTimerHdl ));
123 pTPFilter=m_pAcceptChgCtr->GetFilterPage();
124 pTPView=m_pAcceptChgCtr->GetViewPage();
125 pTheView=pTPView->GetTableControl();
126 aSelectionTimer.SetTimeout(100);
127 aSelectionTimer.SetTimeoutHdl(LINK( this, ScAcceptChgDlg, UpdateSelectionHdl ));
129 pTPFilter->SetReadyHdl(LINK( this, ScAcceptChgDlg, FilterHandle ));
130 pTPFilter->SetRefHdl(LINK( this, ScAcceptChgDlg, RefHandle ));
131 pTPFilter->SetModifyHdl(LINK( this, ScAcceptChgDlg, FilterModified));
132 pTPFilter->HideRange(false);
133 pTPView->InsertCalcHeader();
134 pTPView->SetRejectClickHdl( LINK( this, ScAcceptChgDlg,RejectHandle));
135 pTPView->SetAcceptClickHdl( LINK(this, ScAcceptChgDlg, AcceptHandle));
136 pTPView->SetRejectAllClickHdl( LINK( this, ScAcceptChgDlg,RejectAllHandle));
137 pTPView->SetAcceptAllClickHdl( LINK(this, ScAcceptChgDlg, AcceptAllHandle));
138 pTheView->SetCalcView();
139 pTheView->SetStyle(pTheView->GetStyle()|WB_HASLINES|WB_CLIPCHILDREN|WB_HASBUTTONS|WB_HASBUTTONSATROOT|WB_HSCROLL);
140 pTheView->SetExpandingHdl( LINK(this, ScAcceptChgDlg, ExpandingHandle));
141 pTheView->SetSelectHdl( LINK(this, ScAcceptChgDlg, SelectHandle));
142 pTheView->SetDeselectHdl( LINK(this, ScAcceptChgDlg, SelectHandle));
143 pTheView->SetCommandHdl( LINK(this, ScAcceptChgDlg, CommandHdl));
144 pTheView->SetColCompareHdl( LINK(this, ScAcceptChgDlg,ColCompareHdl));
145 pTheView->SetSelectionMode(MULTIPLE_SELECTION);
146 pTheView->SetHighlightRange(1);
148 Init();
150 UpdateView();
151 SvTreeListEntry* pEntry=pTheView->First();
152 if(pEntry!=NULL)
154 pTheView->Select(pEntry);
158 ScAcceptChgDlg::~ScAcceptChgDlg()
160 ClearView();
161 ScChangeTrack* pChanges=pDoc->GetChangeTrack();
163 if(pChanges!=NULL)
165 Link aLink;
166 pChanges->SetModifiedLink(aLink);
169 delete m_pAcceptChgCtr;
172 void ScAcceptChgDlg::ReInit(ScViewData* ptrViewData)
174 pViewData=ptrViewData;
175 if(pViewData!=NULL)
176 pDoc=ptrViewData->GetDocument();
177 else
178 pDoc=NULL;
180 bNoSelection=false;
181 bNeedsUpdate=false;
182 bIgnoreMsg=false;
183 nAcceptCount=0;
184 nRejectCount=0;
185 bAcceptEnableFlag=true;
186 bRejectEnableFlag=true;
188 // don't call Init here (switching between views), just set link below
189 // (dialog is just hidden, not deleted anymore, when switching views)
190 ClearView();
191 UpdateView();
193 if ( pDoc )
195 ScChangeTrack* pChanges = pDoc->GetChangeTrack();
196 if ( pChanges )
197 pChanges->SetModifiedLink( LINK( this, ScAcceptChgDlg, ChgTrackModHdl ) );
201 void ScAcceptChgDlg::Init()
203 ScRange aRange;
205 OSL_ENSURE( pViewData && pDoc, "ViewData oder Document nicht gefunden!" );
207 ScChangeTrack* pChanges=pDoc->GetChangeTrack();
209 if(pChanges!=NULL)
211 pChanges->SetModifiedLink( LINK( this, ScAcceptChgDlg,ChgTrackModHdl));
212 aChangeViewSet.SetTheAuthorToShow(pChanges->GetUser());
213 pTPFilter->ClearAuthors();
214 const std::set<OUString>& rUserColl = pChanges->GetUserCollection();
215 std::set<OUString>::const_iterator it = rUserColl.begin(), itEnd = rUserColl.end();
216 for (; it != itEnd; ++it)
217 pTPFilter->InsertAuthor(*it);
220 ScChangeViewSettings* pViewSettings=pDoc->GetChangeViewSettings();
221 if ( pViewSettings!=NULL )
222 aChangeViewSet = *pViewSettings;
223 // adjust TimeField for filter tabpage
224 aChangeViewSet.AdjustDateMode( *pDoc );
226 pTPFilter->CheckDate(aChangeViewSet.HasDate());
227 pTPFilter->SetFirstDate(aChangeViewSet.GetTheFirstDateTime());
228 pTPFilter->SetFirstTime(aChangeViewSet.GetTheFirstDateTime());
229 pTPFilter->SetLastDate(aChangeViewSet.GetTheLastDateTime());
230 pTPFilter->SetLastTime(aChangeViewSet.GetTheLastDateTime());
231 pTPFilter->SetDateMode((sal_uInt16)aChangeViewSet.GetTheDateMode());
232 pTPFilter->CheckComment(aChangeViewSet.HasComment());
233 pTPFilter->SetComment(aChangeViewSet.GetTheComment());
235 pTPFilter->CheckAuthor(aChangeViewSet.HasAuthor());
236 OUString aString=aChangeViewSet.GetTheAuthorToShow();
237 if(!aString.isEmpty())
239 pTPFilter->SelectAuthor(aString);
240 if(pTPFilter->GetSelectedAuthor()!=aString)
242 pTPFilter->InsertAuthor(aString);
243 pTPFilter->SelectAuthor(aString);
246 else
247 pTPFilter->SelectedAuthorPos(0);
249 pTPFilter->CheckRange(aChangeViewSet.HasRange());
251 aRangeList=aChangeViewSet.GetTheRangeList();
253 if( !aChangeViewSet.GetTheRangeList().empty() )
255 const ScRange* pRangeEntry = aChangeViewSet.GetTheRangeList().front();
256 OUString aRefStr(pRangeEntry->Format(ABS_DREF3D, pDoc));
257 pTPFilter->SetRange(aRefStr);
260 InitFilter();
263 void ScAcceptChgDlg::ClearView()
265 nAcceptCount=0;
266 nRejectCount=0;
267 pTheView->SetUpdateMode(false);
269 pTheView->Clear();
270 pTheView->SetUpdateMode(true);
273 OUString* ScAcceptChgDlg::MakeTypeString(ScChangeActionType eType)
275 OUString* pStr;
277 switch(eType)
280 case SC_CAT_INSERT_COLS: pStr=&aStrInsertCols;break;
281 case SC_CAT_INSERT_ROWS: pStr=&aStrInsertRows;break;
282 case SC_CAT_INSERT_TABS: pStr=&aStrInsertTabs;break;
283 case SC_CAT_DELETE_COLS: pStr=&aStrDeleteCols;break;
284 case SC_CAT_DELETE_ROWS: pStr=&aStrDeleteRows;break;
285 case SC_CAT_DELETE_TABS: pStr=&aStrDeleteTabs;break;
286 case SC_CAT_MOVE: pStr=&aStrMove;break;
287 case SC_CAT_CONTENT: pStr=&aStrContent;break;
288 case SC_CAT_REJECT: pStr=&aStrReject;break;
289 default: pStr=&aUnknown;break;
291 return pStr;
295 bool ScAcceptChgDlg::IsValidAction(const ScChangeAction* pScChangeAction)
297 if(pScChangeAction==NULL) return false;
299 bool bFlag = false;
301 ScRange aRef=pScChangeAction->GetBigRange().MakeRange();
302 OUString aUser=pScChangeAction->GetUser();
303 DateTime aDateTime=pScChangeAction->GetDateTime();
305 ScChangeActionType eType=pScChangeAction->GetType();
306 OUString aDesc;
308 OUString aComment = comphelper::string::remove(pScChangeAction->GetComment(), '\n');
310 if(eType==SC_CAT_CONTENT)
312 if(!pScChangeAction->IsDialogParent())
313 pScChangeAction->GetDescription(aDesc, pDoc, true);
315 else
316 pScChangeAction->GetDescription(aDesc, pDoc, !pScChangeAction->IsMasterDelete());
318 if (!aDesc.isEmpty())
320 aComment += " (";
321 aComment += aDesc;
322 aComment += ")";
325 if (pTheView->IsValidEntry(aUser, aDateTime, aComment))
327 if(pTPFilter->IsRange())
329 for ( size_t i = 0, nRanges = aRangeList.size(); i < nRanges; ++i )
331 ScRange* pRangeEntry = aRangeList[ i ];
332 if (pRangeEntry->Intersects(aRef)) {
333 bFlag = true;
334 break;
338 else
339 bFlag=true;
342 return bFlag;
345 SvTreeListEntry* ScAcceptChgDlg::InsertChangeAction(
346 const ScChangeAction* pScChangeAction, ScChangeActionState /*eState*/,
347 SvTreeListEntry* pParent, bool bDelMaster,bool bDisabled, sal_uLong nPos)
349 ScChangeTrack* pChanges=pDoc->GetChangeTrack();
351 if(pScChangeAction==NULL || pChanges==NULL) return NULL;
353 SvTreeListEntry* pEntry=NULL;
355 bool bFlag = false;
357 ScRange aRef=pScChangeAction->GetBigRange().MakeRange();
358 OUString aUser=pScChangeAction->GetUser();
359 DateTime aDateTime=pScChangeAction->GetDateTime();
361 OUString aRefStr;
362 ScChangeActionType eType=pScChangeAction->GetType();
363 OUStringBuffer aBuf;
364 OUString aDesc;
366 ScRedlinData* pNewData=new ScRedlinData;
367 pNewData->pData=(void *)pScChangeAction;
368 pNewData->nActionNo=pScChangeAction->GetActionNumber();
369 pNewData->bIsAcceptable=pScChangeAction->IsClickable();
370 pNewData->bIsRejectable=pScChangeAction->IsRejectable();
371 pNewData->bDisabled=!pNewData->bIsAcceptable || bDisabled;
372 pNewData->aDateTime=aDateTime;
373 pNewData->nRow = aRef.aStart.Row();
374 pNewData->nCol = aRef.aStart.Col();
375 pNewData->nTable= aRef.aStart.Tab();
377 if(eType==SC_CAT_CONTENT)
379 if(pScChangeAction->IsDialogParent())
381 aBuf.append(aStrContentWithChild);
382 pNewData->nInfo=RD_SPECIAL_VISCONTENT;
383 pNewData->bIsRejectable=false;
384 pNewData->bIsAcceptable=false;
386 else
388 aBuf.append(*MakeTypeString(eType));
389 pScChangeAction->GetDescription( aDesc, pDoc, true);
392 else
394 aBuf.append(aStrContentWithChild);
396 if(bDelMaster)
398 pScChangeAction->GetDescription( aDesc, pDoc,true);
399 pNewData->bDisabled=true;
400 pNewData->bIsRejectable=false;
402 else
403 pScChangeAction->GetDescription( aDesc, pDoc,!pScChangeAction->IsMasterDelete());
407 pScChangeAction->GetRefString(aRefStr, pDoc, true);
409 aBuf.append('\t');
410 aBuf.append(aRefStr);
411 aBuf.append('\t');
413 bool bIsGenerated = false;
415 if(!pChanges->IsGenerated(pScChangeAction->GetActionNumber()))
417 aBuf.append(aUser);
418 aBuf.append('\t');
419 aBuf.append(ScGlobal::pLocaleData->getDate(aDateTime));
420 aBuf.append(' ');
421 aBuf.append(ScGlobal::pLocaleData->getTime(aDateTime));
422 aBuf.append('\t');
424 bIsGenerated = false;
426 else
428 aBuf.append('\t');
429 aBuf.append('\t');
430 bIsGenerated = true;
433 OUString aComment = comphelper::string::remove(pScChangeAction->GetComment(), '\n');
435 if (!aDesc.isEmpty())
437 aComment += " (";
438 aComment += aDesc;
439 aComment += ")";
442 aBuf.append(aComment);
444 if (pTheView->IsValidEntry(aUser, aDateTime) || bIsGenerated)
446 if (pTheView->IsValidComment(aComment))
448 if(pTPFilter->IsRange())
450 for ( size_t i = 0, nRanges = aRangeList.size(); i < nRanges; ++i )
452 ScRange* pRangeEntry = aRangeList[ i ];
453 if( pRangeEntry->Intersects(aRef) )
455 bHasFilterEntry=true;
456 bFlag=true;
457 break;
461 else if(!bIsGenerated)
463 bHasFilterEntry=true;
464 bFlag=true;
469 if(!bFlag&& bUseColor&& pParent==NULL)
471 pEntry = pTheView->InsertEntry(
472 aBuf.makeStringAndClear() ,pNewData, Color(COL_LIGHTBLUE), pParent, nPos);
474 else if(bFlag&& bUseColor&& pParent!=NULL)
476 pEntry = pTheView->InsertEntry(
477 aBuf.makeStringAndClear(), pNewData, Color(COL_GREEN), pParent, nPos);
478 SvTreeListEntry* pExpEntry=pParent;
480 while(pExpEntry!=NULL && !pTheView->IsExpanded(pExpEntry))
482 SvTreeListEntry* pTmpEntry=pTheView->GetParent(pExpEntry);
484 if(pTmpEntry!=NULL) pTheView->Expand(pExpEntry);
486 pExpEntry=pTmpEntry;
489 else
491 pEntry = pTheView->InsertEntry(
492 aBuf.makeStringAndClear(), pNewData, pParent, nPos);
494 return pEntry;
497 SvTreeListEntry* ScAcceptChgDlg::InsertFilteredAction(
498 const ScChangeAction* pScChangeAction, ScChangeActionState eState,
499 SvTreeListEntry* pParent, bool bDelMaster, bool bDisabled, sal_uLong nPos)
502 ScChangeTrack* pChanges=pDoc->GetChangeTrack();
504 if(pScChangeAction==NULL || pChanges==NULL) return NULL;
506 bool bIsGenerated = pChanges->IsGenerated(pScChangeAction->GetActionNumber());
508 SvTreeListEntry* pEntry=NULL;
510 bool bFlag = false;
512 ScRange aRef=pScChangeAction->GetBigRange().MakeRange();
513 OUString aUser=pScChangeAction->GetUser();
514 DateTime aDateTime=pScChangeAction->GetDateTime();
516 if (pTheView->IsValidEntry(aUser, aDateTime) || bIsGenerated)
518 if(pTPFilter->IsRange())
520 for ( size_t i = 0, nRanges = aRangeList.size(); i < nRanges; ++i )
522 ScRange* pRangeEntry=aRangeList[ i ];
523 if( pRangeEntry->Intersects(aRef) )
525 if( pScChangeAction->GetState()==eState )
526 bFlag = true;
527 break;
531 else if(pScChangeAction->GetState()==eState && !bIsGenerated)
532 bFlag = true;
535 if(bFlag)
538 OUString aRefStr;
539 ScChangeActionType eType=pScChangeAction->GetType();
540 OUString aString;
541 OUString aDesc;
543 ScRedlinData* pNewData=new ScRedlinData;
544 pNewData->pData=(void *)pScChangeAction;
545 pNewData->nActionNo=pScChangeAction->GetActionNumber();
546 pNewData->bIsAcceptable=pScChangeAction->IsClickable();
547 pNewData->bIsRejectable=pScChangeAction->IsRejectable();
548 pNewData->bDisabled=!pNewData->bIsAcceptable || bDisabled;
549 pNewData->aDateTime=aDateTime;
550 pNewData->nRow = aRef.aStart.Row();
551 pNewData->nCol = aRef.aStart.Col();
552 pNewData->nTable= aRef.aStart.Tab();
554 if(eType==SC_CAT_CONTENT)
556 if(pScChangeAction->IsDialogParent())
558 aString=aStrContentWithChild;
559 pNewData->nInfo=RD_SPECIAL_VISCONTENT;
560 pNewData->bIsRejectable=false;
561 pNewData->bIsAcceptable=false;
563 else
565 aString=*MakeTypeString(eType);
566 pScChangeAction->GetDescription( aDesc, pDoc, true);
569 else
571 aString=*MakeTypeString(eType);
573 if(bDelMaster)
575 pScChangeAction->GetDescription( aDesc, pDoc,true);
576 pNewData->bDisabled=true;
577 pNewData->bIsRejectable=false;
579 else
580 pScChangeAction->GetDescription( aDesc, pDoc,!pScChangeAction->IsMasterDelete());
584 aString += "\t";
585 pScChangeAction->GetRefString(aRefStr, pDoc, true);
586 aString += aRefStr;
587 aString += "\t";
589 if(!bIsGenerated)
591 aString += aUser;
592 aString += "\t";
593 aString += ScGlobal::pLocaleData->getDate(aDateTime);
594 aString += " ";
595 aString += ScGlobal::pLocaleData->getTime(aDateTime);
596 aString += "\t";
598 else
600 aString += "\t";
601 aString += "\t";
604 OUString aComment = comphelper::string::remove(pScChangeAction->GetComment(), '\n');
606 if (!aDesc.isEmpty())
608 aComment += " (" ;
609 aComment += aDesc;
610 aComment += ")";
612 if (pTheView->IsValidComment(aComment))
614 aString+=aComment;
615 pEntry=pTheView->InsertEntry(aString,pNewData,pParent,nPos);
617 else
618 delete pNewData;
620 return pEntry;
623 SvTreeListEntry* ScAcceptChgDlg::InsertChangeActionContent(const ScChangeActionContent* pScChangeAction,
624 SvTreeListEntry* pParent, sal_uLong nSpecial)
626 ScChangeTrack* pChanges=pDoc->GetChangeTrack();
627 SvTreeListEntry* pEntry=NULL;
629 if(pScChangeAction==NULL || pChanges==NULL) return NULL;
631 bool bIsGenerated = pChanges->IsGenerated(pScChangeAction->GetActionNumber());
633 bool bFlag = false;
635 ScRange aRef=pScChangeAction->GetBigRange().MakeRange();
636 OUString aUser=pScChangeAction->GetUser();
637 DateTime aDateTime=pScChangeAction->GetDateTime();
639 if (pTheView->IsValidEntry(aUser, aDateTime) || bIsGenerated)
641 if(pTPFilter->IsRange())
643 for ( size_t i = 0, nRanges = aRangeList.size(); i < nRanges; ++i )
645 ScRange* pRangeEntry = aRangeList[ i ];
646 if( pRangeEntry->Intersects(aRef) )
648 bFlag=true;
649 break;
653 else if(!bIsGenerated)
654 bFlag=true;
657 OUString aRefStr;
658 OUString aString;
659 OUString a2String;
660 OUString aDesc;
662 if(nSpecial==RD_SPECIAL_CONTENT)
664 OUString aTmp;
665 pScChangeAction->GetOldString(aTmp, pDoc);
666 a2String = aTmp;
667 if(a2String.isEmpty()) a2String=aStrEmpty;
669 //aString+="\'";
670 aString+=a2String;
671 //aString+="\'";
673 aDesc=aStrChildOrgContent;
674 aDesc += ": ";
676 else
678 OUString aTmp;
679 pScChangeAction->GetNewString(aTmp, pDoc);
680 a2String = aTmp;
681 if(a2String.isEmpty())
683 a2String=aStrEmpty;
684 aString+=a2String;
686 else
688 aString += "\'";
689 aString += a2String;
690 aString += "\'";
691 a2String =aString;
693 aDesc = aStrChildContent;
697 aDesc += a2String;
698 aString += "\t";
699 pScChangeAction->GetRefString(aRefStr, pDoc, true);
700 aString += aRefStr;
701 aString += "\t";
703 if(!bIsGenerated)
705 aString += aUser;
706 aString += "\t";
708 aString += ScGlobal::pLocaleData->getDate(aDateTime);
709 aString += " ";
710 aString += ScGlobal::pLocaleData->getTime(aDateTime);
711 aString += "\t";
713 else
715 aString += "\t";
716 aString += "\t";
719 OUString aComment = comphelper::string::remove(pScChangeAction->GetComment(), '\n');
721 if(!aDesc.isEmpty())
723 aComment += " (" ;
724 aComment += aDesc;
725 aComment += ")";
728 aString+=aComment;
730 ScRedlinData* pNewData=new ScRedlinData;
731 pNewData->nInfo=nSpecial;
732 pNewData->pData=(void *)pScChangeAction;
733 pNewData->nActionNo=pScChangeAction->GetActionNumber();
734 pNewData->bIsAcceptable=pScChangeAction->IsClickable();
735 pNewData->bIsRejectable=false;
736 pNewData->bDisabled=!pNewData->bIsAcceptable;
737 pNewData->aDateTime=aDateTime;
738 pNewData->nRow = aRef.aStart.Row();
739 pNewData->nCol = aRef.aStart.Col();
740 pNewData->nTable= aRef.aStart.Tab();
742 if (pTheView->IsValidComment(aComment) && bFlag)
744 bHasFilterEntry=true;
745 pEntry=pTheView->InsertEntry(aString,pNewData,pParent);
747 else
748 pEntry=pTheView->InsertEntry(aString,pNewData,Color(COL_LIGHTBLUE),pParent);
749 return pEntry;
752 long ScAcceptChgDlg::PreNotify( NotifyEvent& rNEvt )
754 if(rNEvt.GetType()==EVENT_GETFOCUS && bNeedsUpdate)
756 ClearView();
757 UpdateView();
758 bNoSelection=false;
761 return SfxModelessDialog::PreNotify(rNEvt);
765 void ScAcceptChgDlg::UpdateView()
767 bNeedsUpdate=false;
768 SvTreeListEntry* pParent=NULL;
769 ScChangeTrack* pChanges=NULL;
770 const ScChangeAction* pScChangeAction=NULL;
771 bAcceptEnableFlag=true;
772 bRejectEnableFlag=true;
773 SetPointer(Pointer(POINTER_WAIT));
774 pTheView->SetUpdateMode(false);
775 bool bFilterFlag = pTPFilter->IsDate() || pTPFilter->IsRange() ||
776 pTPFilter->IsAuthor() || pTPFilter->IsComment();
778 bUseColor = bFilterFlag;
780 if(pDoc!=NULL)
782 pChanges=pDoc->GetChangeTrack();
783 if(pChanges!=NULL)
784 pScChangeAction=pChanges->GetFirst();
786 bool bTheFlag = false;
788 while(pScChangeAction!=NULL)
790 bHasFilterEntry=false;
791 switch(pScChangeAction->GetState())
793 case SC_CAS_VIRGIN:
795 if(pScChangeAction->IsDialogRoot())
797 if(pScChangeAction->IsDialogParent())
798 pParent=InsertChangeAction(pScChangeAction,SC_CAS_VIRGIN);
799 else
800 pParent=InsertFilteredAction(pScChangeAction,SC_CAS_VIRGIN);
802 else
803 pParent=NULL;
805 bTheFlag=true;
806 break;
808 case SC_CAS_ACCEPTED:
809 pParent=NULL;
810 nAcceptCount++;
811 break;
813 case SC_CAS_REJECTED:
814 pParent=NULL;
815 nRejectCount++;
816 break;
819 if(pParent!=NULL && pScChangeAction->IsDialogParent())
821 if(!bFilterFlag)
822 pParent->EnableChildrenOnDemand(true);
823 else
825 bool bTestFlag = bHasFilterEntry;
826 bHasFilterEntry=false;
827 if(Expand(pChanges,pScChangeAction,pParent,!bTestFlag)&&!bTestFlag)
828 pTheView->RemoveEntry(pParent);
832 pScChangeAction=pScChangeAction->GetNext();
835 if( bTheFlag && (!pDoc->IsDocEditable() || pChanges->IsProtected()) )
836 bTheFlag=false;
838 pTPView->EnableAccept(bTheFlag);
839 pTPView->EnableAcceptAll(bTheFlag);
840 pTPView->EnableReject(bTheFlag);
841 pTPView->EnableRejectAll(bTheFlag);
843 if(nAcceptCount>0)
845 pParent=pTheView->InsertEntry(
846 aStrAllAccepted, static_cast< RedlinData * >(NULL),
847 static_cast< SvTreeListEntry * >(NULL));
848 pParent->EnableChildrenOnDemand(true);
850 if(nRejectCount>0)
852 pParent=pTheView->InsertEntry(
853 aStrAllRejected, static_cast< RedlinData * >(NULL),
854 static_cast< SvTreeListEntry * >(NULL));
855 pParent->EnableChildrenOnDemand(true);
857 pTheView->SetUpdateMode(true);
858 SetPointer(Pointer(POINTER_ARROW));
859 SvTreeListEntry* pEntry=pTheView->First();
860 if(pEntry!=NULL)
861 pTheView->Select(pEntry);
864 IMPL_LINK_NOARG(ScAcceptChgDlg, RefHandle)
866 sal_uInt16 nId =ScSimpleRefDlgWrapper::GetChildWindowId();
868 ScSimpleRefDlgWrapper::SetDefaultPosSize(GetPosPixel(),GetSizePixel(),true);
870 SC_MOD()->SetRefDialog( nId, true );
872 SfxViewFrame* pViewFrm = pViewData->GetViewShell()->GetViewFrame();
873 ScSimpleRefDlgWrapper* pWnd =(ScSimpleRefDlgWrapper*)pViewFrm->GetChildWindow( nId );
875 if(pWnd!=NULL)
877 sal_uInt16 nAcceptId=ScAcceptChgDlgWrapper::GetChildWindowId();
878 pViewFrm->ShowChildWindow(nAcceptId,false);
879 pWnd->SetCloseHdl(LINK( this, ScAcceptChgDlg,RefInfoHandle));
880 pWnd->SetRefString(pTPFilter->GetRange());
881 pWnd->SetAutoReOpen(false);
882 Window* pWin=pWnd->GetWindow();
883 pWin->SetPosSizePixel(GetPosPixel(),GetSizePixel());
884 Hide();
885 pWin->SetText(GetText());
886 pWnd->StartRefInput();
888 return 0;
891 IMPL_LINK( ScAcceptChgDlg, RefInfoHandle, OUString*, pResult)
893 sal_uInt16 nId;
895 ScSimpleRefDlgWrapper::SetAutoReOpen(true);
897 SfxViewFrame* pViewFrm = pViewData->GetViewShell()->GetViewFrame();
898 if(pResult!=NULL)
900 pTPFilter->SetRange(*pResult);
901 FilterHandle(pTPFilter);
903 nId = ScSimpleRefDlgWrapper::GetChildWindowId();
904 ScSimpleRefDlgWrapper* pWnd = (ScSimpleRefDlgWrapper*)pViewFrm->GetChildWindow( nId );
906 if(pWnd!=NULL)
908 Window* pWin=pWnd->GetWindow();
909 Size aWinSize=pWin->GetSizePixel();
910 aWinSize.Width()=GetSizePixel().Width();
911 SetPosSizePixel(pWin->GetPosPixel(),aWinSize);
912 Invalidate();
914 nId = ScAcceptChgDlgWrapper::GetChildWindowId();
915 pViewFrm->ShowChildWindow( nId, true );
917 else
919 nId = ScAcceptChgDlgWrapper::GetChildWindowId();
920 pViewFrm->SetChildWindow( nId, false );
922 return 0;
925 IMPL_LINK( ScAcceptChgDlg, FilterHandle, SvxTPFilter*, pRef )
927 if(pRef!=NULL)
929 ClearView();
930 aRangeList.RemoveAll();
931 aRangeList.Parse(pTPFilter->GetRange(),pDoc);
932 UpdateView();
934 return 0;
937 IMPL_LINK( ScAcceptChgDlg, RejectHandle, SvxTPView*, pRef )
939 SetPointer(Pointer(POINTER_WAIT));
941 bIgnoreMsg=true;
942 ScChangeTrack* pChanges=pDoc->GetChangeTrack();
944 if(pRef!=NULL)
946 SvTreeListEntry* pEntry=pTheView->FirstSelected();
947 while(pEntry!=NULL)
949 ScRedlinData *pEntryData=(ScRedlinData *)(pEntry->GetUserData());
950 if(pEntryData!=NULL)
952 ScChangeAction* pScChangeAction=
953 (ScChangeAction*) pEntryData->pData;
955 if(pScChangeAction->GetType()==SC_CAT_INSERT_TABS)
956 pViewData->SetTabNo(0);
958 pChanges->Reject(pScChangeAction);
960 pEntry = pTheView->NextSelected(pEntry);
962 ScDocShell* pDocSh=pViewData->GetDocShell();
963 pDocSh->PostPaintExtras();
964 pDocSh->PostPaintGridAll();
965 pDocSh->GetUndoManager()->Clear();
966 pDocSh->SetDocumentModified();
967 ClearView();
968 UpdateView();
970 SetPointer(Pointer(POINTER_ARROW));
972 bIgnoreMsg=false;
973 return 0;
975 IMPL_LINK( ScAcceptChgDlg, AcceptHandle, SvxTPView*, pRef )
977 SetPointer(Pointer(POINTER_WAIT));
979 ScChangeTrack* pChanges=pDoc->GetChangeTrack();
980 bIgnoreMsg=true;
981 if(pRef!=NULL)
983 SvTreeListEntry* pEntry=pTheView->FirstSelected();
984 while(pEntry!=NULL)
986 ScRedlinData *pEntryData=(ScRedlinData *)(pEntry->GetUserData());
987 if(pEntryData!=NULL)
989 ScChangeAction* pScChangeAction=
990 (ScChangeAction*) pEntryData->pData;
991 if(pScChangeAction->GetType()==SC_CAT_CONTENT)
993 if(pEntryData->nInfo==RD_SPECIAL_CONTENT)
994 pChanges->SelectContent(pScChangeAction,true);
995 else
996 pChanges->SelectContent(pScChangeAction);
998 else
999 pChanges->Accept(pScChangeAction);
1001 pEntry = pTheView->NextSelected(pEntry);
1003 ScDocShell* pDocSh=pViewData->GetDocShell();
1004 pDocSh->PostPaintExtras();
1005 pDocSh->PostPaintGridAll();
1006 pDocSh->SetDocumentModified();
1007 ClearView();
1008 UpdateView();
1010 bIgnoreMsg=false;
1012 return 0;
1015 void ScAcceptChgDlg::RejectFiltered()
1017 if(pDoc==NULL) return;
1018 ScChangeTrack* pChanges=pDoc->GetChangeTrack();
1019 const ScChangeAction* pScChangeAction=NULL;
1021 if(pChanges!=NULL)
1023 pScChangeAction=pChanges->GetLast();
1026 while(pScChangeAction!=NULL)
1028 if(pScChangeAction->IsDialogRoot())
1029 if(IsValidAction(pScChangeAction))
1030 pChanges->Reject((ScChangeAction*)pScChangeAction);
1032 pScChangeAction=pScChangeAction->GetPrev();
1035 void ScAcceptChgDlg::AcceptFiltered()
1037 if(pDoc==NULL) return;
1038 ScChangeTrack* pChanges=pDoc->GetChangeTrack();
1039 const ScChangeAction* pScChangeAction=NULL;
1041 if(pChanges!=NULL)
1042 pScChangeAction=pChanges->GetLast();
1044 while(pScChangeAction!=NULL)
1046 if(pScChangeAction->IsDialogRoot())
1047 if(IsValidAction(pScChangeAction))
1048 pChanges->Accept((ScChangeAction*)pScChangeAction);
1050 pScChangeAction=pScChangeAction->GetPrev();
1054 IMPL_LINK_NOARG(ScAcceptChgDlg, RejectAllHandle)
1056 SetPointer(Pointer(POINTER_WAIT));
1057 bIgnoreMsg=true;
1058 ScChangeTrack* pChanges=pDoc->GetChangeTrack();
1059 if(pChanges!=NULL)
1061 if(pTPFilter->IsDate()||pTPFilter->IsAuthor()||pTPFilter->IsRange()||pTPFilter->IsComment())
1062 RejectFiltered();
1063 else
1064 pChanges->RejectAll();
1066 pViewData->SetTabNo(0);
1068 ScDocShell* pDocSh=pViewData->GetDocShell();
1069 pDocSh->PostPaintExtras();
1070 pDocSh->PostPaintGridAll();
1071 pDocSh->GetUndoManager()->Clear();
1072 pDocSh->SetDocumentModified();
1073 ClearView();
1074 UpdateView();
1076 SetPointer(Pointer(POINTER_ARROW));
1078 bIgnoreMsg=false;
1080 return 0;
1083 IMPL_LINK_NOARG(ScAcceptChgDlg, AcceptAllHandle)
1085 SetPointer(Pointer(POINTER_WAIT));
1087 bIgnoreMsg=true;
1088 ScChangeTrack* pChanges=pDoc->GetChangeTrack();
1089 if(pChanges!=NULL)
1091 if(pTPFilter->IsDate()||pTPFilter->IsAuthor()||pTPFilter->IsRange()||pTPFilter->IsComment())
1092 AcceptFiltered();
1093 else
1094 pChanges->AcceptAll();
1096 ScDocShell* pDocSh=pViewData->GetDocShell();
1097 pDocSh->PostPaintExtras();
1098 pDocSh->PostPaintGridAll();
1099 pDocSh->SetDocumentModified();
1100 ClearView();
1101 UpdateView();
1103 bIgnoreMsg=false;
1104 SetPointer(Pointer(POINTER_ARROW));
1106 return 0;
1109 IMPL_LINK_NOARG(ScAcceptChgDlg, SelectHandle)
1111 if(!bNoSelection)
1112 aSelectionTimer.Start();
1114 bNoSelection=false;
1115 return 0;
1118 void ScAcceptChgDlg::GetDependents( const ScChangeAction* pScChangeAction,
1119 ScChangeActionMap& aActionMap,
1120 SvTreeListEntry* pEntry)
1122 ScChangeTrack* pChanges=pDoc->GetChangeTrack();
1124 SvTreeListEntry* pParent=pTheView->GetParent(pEntry);
1125 if(pParent!=NULL)
1127 ScRedlinData *pParentData=(ScRedlinData *)(pParent->GetUserData());
1128 ScChangeAction* pParentAction=(ScChangeAction*) pParentData->pData;
1130 if(pParentAction!=pScChangeAction)
1131 pChanges->GetDependents((ScChangeAction*) pScChangeAction,
1132 aActionMap,pScChangeAction->IsMasterDelete());
1133 else
1134 pChanges->GetDependents( (ScChangeAction*) pScChangeAction,
1135 aActionMap );
1137 else
1138 pChanges->GetDependents((ScChangeAction*) pScChangeAction,
1139 aActionMap, pScChangeAction->IsMasterDelete() );
1142 bool ScAcceptChgDlg::InsertContentChildren(ScChangeActionMap* pActionMap,SvTreeListEntry* pParent)
1144 bool bTheTestFlag = true;
1145 ScRedlinData *pEntryData=(ScRedlinData *)(pParent->GetUserData());
1146 const ScChangeAction* pScChangeAction = (ScChangeAction*) pEntryData->pData;
1147 bool bParentInserted = false;
1148 // If the parent is a MatrixOrigin then place it in the right order before
1149 // the MatrixReferences. Also if it is the first content change at this
1150 // position don't insert the first dependent MatrixReference as the special
1151 // content (original value) but insert the predecessor of the MatrixOrigin
1152 // itself instead.
1153 if ( pScChangeAction->GetType() == SC_CAT_CONTENT &&
1154 ((const ScChangeActionContent*)pScChangeAction)->IsMatrixOrigin() )
1156 pActionMap->insert( ::std::make_pair( pScChangeAction->GetActionNumber(),
1157 const_cast<ScChangeAction*>( pScChangeAction ) ) );
1158 bParentInserted = true;
1160 SvTreeListEntry* pEntry=NULL;
1162 ScChangeActionMap::iterator itChangeAction = pActionMap->begin();
1163 while( itChangeAction != pActionMap->end() )
1165 if( itChangeAction->second->GetState()==SC_CAS_VIRGIN )
1166 break;
1167 ++itChangeAction;
1170 if( itChangeAction == pActionMap->end() )
1171 return true;
1173 SvTreeListEntry* pOriginal = InsertChangeActionContent(
1174 dynamic_cast<const ScChangeActionContent*>( itChangeAction->second ),
1175 pParent, RD_SPECIAL_CONTENT );
1177 if(pOriginal!=NULL)
1179 bTheTestFlag=false;
1180 ScRedlinData *pParentData=(ScRedlinData *)(pOriginal->GetUserData());
1181 pParentData->pData=(void *)pScChangeAction;
1182 pParentData->nActionNo=pScChangeAction->GetActionNumber();
1183 pParentData->bIsAcceptable=pScChangeAction->IsRejectable(); // select old value
1184 pParentData->bIsRejectable=false;
1185 pParentData->bDisabled=false;
1187 while( itChangeAction != pActionMap->end() )
1189 if( itChangeAction->second->GetState() == SC_CAS_VIRGIN )
1191 pEntry = InsertChangeActionContent( dynamic_cast<const ScChangeActionContent*>( itChangeAction->second ),
1192 pParent, RD_SPECIAL_NONE );
1194 if(pEntry!=NULL)
1195 bTheTestFlag=false;
1197 ++itChangeAction;
1200 if ( !bParentInserted )
1202 pEntry=InsertChangeActionContent((const ScChangeActionContent*)
1203 pScChangeAction,pParent,RD_SPECIAL_NONE);
1205 if(pEntry!=NULL)
1207 bTheTestFlag=false;
1208 ScRedlinData *pParentData=(ScRedlinData *)(pEntry->GetUserData());
1209 pParentData->pData=(void *)pScChangeAction;
1210 pParentData->nActionNo=pScChangeAction->GetActionNumber();
1211 pParentData->bIsAcceptable=pScChangeAction->IsClickable();
1212 pParentData->bIsRejectable=false;
1213 pParentData->bDisabled=false;
1217 return bTheTestFlag;
1221 bool ScAcceptChgDlg::InsertAcceptedORejected(SvTreeListEntry* pParent)
1223 ScChangeTrack* pChanges=pDoc->GetChangeTrack();
1224 bool bTheTestFlag = true;
1226 ScChangeActionState eState = SC_CAS_VIRGIN;
1227 OUString aString = pTheView->GetEntryText(pParent);
1228 OUString a2String = aString.copy(0, aStrAllAccepted.getLength());
1229 if (a2String.equals(aStrAllAccepted))
1230 eState=SC_CAS_ACCEPTED;
1231 else
1233 a2String = aString.copy(0, aStrAllRejected.getLength());
1234 if (a2String.equals(aStrAllRejected))
1235 eState=SC_CAS_REJECTED;
1238 ScChangeAction* pScChangeAction=pChanges->GetFirst();
1239 while(pScChangeAction!=NULL)
1241 if(pScChangeAction->GetState()==eState &&
1242 InsertFilteredAction(pScChangeAction,eState,pParent)!=NULL)
1243 bTheTestFlag=false;
1244 pScChangeAction=pScChangeAction->GetNext();
1246 return bTheTestFlag;
1249 bool ScAcceptChgDlg::InsertChildren(ScChangeActionMap* pActionMap,SvTreeListEntry* pParent)
1251 ScChangeTrack* pChanges=pDoc->GetChangeTrack();
1252 bool bTheTestFlag = true;
1253 SvTreeListEntry* pEntry=NULL;
1254 ScChangeActionMap::iterator itChangeAction;
1256 for( itChangeAction = pActionMap->begin(); itChangeAction != pActionMap->end(); ++itChangeAction )
1258 pEntry=InsertChangeAction( itChangeAction->second, SC_CAS_VIRGIN, pParent, false, true );
1260 if(pEntry!=NULL)
1262 bTheTestFlag=false;
1264 ScRedlinData *pEntryData=(ScRedlinData *)(pEntry->GetUserData());
1265 pEntryData->bIsRejectable=false;
1266 pEntryData->bIsAcceptable=false;
1267 pEntryData->bDisabled=true;
1269 if( itChangeAction->second->IsDialogParent() )
1270 Expand( pChanges, itChangeAction->second, pEntry );
1273 return bTheTestFlag;
1276 bool ScAcceptChgDlg::InsertDeletedChildren(const ScChangeAction* pScChangeAction,
1277 ScChangeActionMap* pActionMap,SvTreeListEntry* pParent)
1279 ScChangeTrack* pChanges=pDoc->GetChangeTrack();
1280 bool bTheTestFlag = true;
1281 SvTreeListEntry* pEntry=NULL;
1282 ScChangeActionMap::iterator itChangeAction;
1284 for( itChangeAction = pActionMap->begin(); itChangeAction != pActionMap->end(); ++itChangeAction )
1287 if( pScChangeAction != itChangeAction->second )
1288 pEntry = InsertChangeAction( itChangeAction->second, SC_CAS_VIRGIN, pParent, false, true );
1289 else
1290 pEntry = InsertChangeAction( itChangeAction->second, SC_CAS_VIRGIN, pParent, true, true );
1292 if(pEntry!=NULL)
1294 ScRedlinData *pEntryData=(ScRedlinData *)(pEntry->GetUserData());
1295 pEntryData->bIsRejectable=false;
1296 pEntryData->bIsAcceptable=false;
1297 pEntryData->bDisabled=true;
1299 bTheTestFlag=false;
1301 if( itChangeAction->second->IsDialogParent() )
1302 Expand( pChanges, itChangeAction->second, pEntry );
1305 return bTheTestFlag;
1308 bool ScAcceptChgDlg::Expand(
1309 ScChangeTrack* pChanges, const ScChangeAction* pScChangeAction,
1310 SvTreeListEntry* pEntry, bool bFilter)
1312 bool bTheTestFlag = true;
1314 if(pChanges!=NULL &&pEntry!=NULL &&pScChangeAction!=NULL)
1316 ScChangeActionMap aActionMap;
1318 GetDependents( pScChangeAction, aActionMap, pEntry );
1320 switch(pScChangeAction->GetType())
1322 case SC_CAT_CONTENT:
1324 InsertContentChildren( &aActionMap, pEntry );
1325 bTheTestFlag=!bHasFilterEntry;
1326 break;
1328 case SC_CAT_DELETE_COLS:
1329 case SC_CAT_DELETE_ROWS:
1330 case SC_CAT_DELETE_TABS:
1332 InsertDeletedChildren( pScChangeAction, &aActionMap, pEntry );
1333 bTheTestFlag=!bHasFilterEntry;
1334 break;
1336 default:
1338 if(!bFilter)
1339 bTheTestFlag = InsertChildren( &aActionMap, pEntry );
1340 break;
1343 aActionMap.clear();
1345 return bTheTestFlag;
1348 IMPL_LINK( ScAcceptChgDlg, ExpandingHandle, SvxRedlinTable*, pTable )
1350 ScChangeTrack* pChanges=pDoc->GetChangeTrack();
1351 ScChangeAction* pScChangeAction=NULL;
1352 SetPointer(Pointer(POINTER_WAIT));
1353 if(pTable!=NULL && pChanges!=NULL)
1355 ScChangeActionMap aActionMap;
1356 SvTreeListEntry* pEntry=pTheView->GetHdlEntry();
1357 if(pEntry!=NULL)
1359 ScRedlinData *pEntryData=(ScRedlinData *)(pEntry->GetUserData());
1360 if(pEntryData!=NULL)
1361 pScChangeAction=(ScChangeAction*) pEntryData->pData;
1363 if(pEntry->HasChildrenOnDemand())
1365 bool bTheTestFlag = true;
1366 pEntry->EnableChildrenOnDemand(false);
1367 pTheView->RemoveEntry(pTheView->FirstChild(pEntry));
1369 if(pEntryData!=NULL)
1371 pScChangeAction=(ScChangeAction*) pEntryData->pData;
1373 GetDependents( pScChangeAction, aActionMap, pEntry );
1375 switch(pScChangeAction->GetType())
1377 case SC_CAT_CONTENT:
1379 bTheTestFlag = InsertContentChildren( &aActionMap, pEntry );
1380 break;
1382 case SC_CAT_DELETE_COLS:
1383 case SC_CAT_DELETE_ROWS:
1384 case SC_CAT_DELETE_TABS:
1386 bTheTestFlag = InsertDeletedChildren( pScChangeAction, &aActionMap, pEntry );
1387 break;
1389 default:
1391 bTheTestFlag = InsertChildren( &aActionMap, pEntry );
1392 break;
1395 aActionMap.clear();
1398 else
1400 bTheTestFlag=InsertAcceptedORejected(pEntry);
1402 if(bTheTestFlag) pTheView->InsertEntry(aStrNoEntry,NULL,Color(COL_GRAY),pEntry);
1407 SetPointer(Pointer(POINTER_ARROW));
1408 return (sal_uLong) true;
1412 void ScAcceptChgDlg::AppendChanges(ScChangeTrack* pChanges,sal_uLong nStartAction,
1413 sal_uLong nEndAction, sal_uLong /* nPos */)
1415 if(pChanges!=NULL)
1417 SvTreeListEntry* pParent=NULL;
1418 const ScChangeAction* pScChangeAction=NULL;
1419 bAcceptEnableFlag=true;
1420 bRejectEnableFlag=true;
1421 SetPointer(Pointer(POINTER_WAIT));
1422 pTheView->SetUpdateMode(false);
1424 bool bTheFlag = false;
1426 bool bFilterFlag = pTPFilter->IsDate() || pTPFilter->IsRange() ||
1427 pTPFilter->IsAuthor() || pTPFilter->IsComment();
1429 bUseColor = bFilterFlag;
1431 for(sal_uLong i=nStartAction;i<=nEndAction;i++)
1433 pScChangeAction=pChanges->GetAction(i);
1434 if(pScChangeAction==NULL) continue;
1437 switch(pScChangeAction->GetState())
1439 case SC_CAS_VIRGIN:
1441 if(pScChangeAction->IsDialogRoot())
1443 if(pScChangeAction->IsDialogParent())
1444 pParent=InsertChangeAction(pScChangeAction,SC_CAS_VIRGIN);
1445 else
1446 pParent=InsertFilteredAction(pScChangeAction,SC_CAS_VIRGIN);
1448 else
1449 pParent=NULL;
1451 bTheFlag=true;
1452 break;
1454 case SC_CAS_ACCEPTED:
1455 pParent=NULL;
1456 nAcceptCount++;
1457 break;
1459 case SC_CAS_REJECTED:
1460 pParent=NULL;
1461 nRejectCount++;
1462 break;
1465 if(pParent!=NULL && pScChangeAction->IsDialogParent())
1467 if(!bFilterFlag)
1468 pParent->EnableChildrenOnDemand(true);
1469 else
1471 bool bTestFlag = bHasFilterEntry;
1472 bHasFilterEntry = false;
1473 if(Expand(pChanges,pScChangeAction,pParent,!bTestFlag)&&!bTestFlag)
1474 pTheView->RemoveEntry(pParent);
1479 if( bTheFlag && (!pDoc->IsDocEditable() || pChanges->IsProtected()) )
1480 bTheFlag=false;
1482 pTPView->EnableAccept(bTheFlag);
1483 pTPView->EnableAcceptAll(bTheFlag);
1484 pTPView->EnableReject(bTheFlag);
1485 pTPView->EnableRejectAll(bTheFlag);
1487 pTheView->SetUpdateMode(true);
1488 SetPointer(Pointer(POINTER_ARROW));
1492 void ScAcceptChgDlg::RemoveEntrys(sal_uLong nStartAction,sal_uLong nEndAction)
1495 pTheView->SetUpdateMode(false);
1497 SvTreeListEntry* pEntry=pTheView->GetCurEntry();
1499 ScRedlinData *pEntryData=NULL;
1501 if(pEntry!=NULL)
1502 pEntryData=(ScRedlinData *)(pEntry->GetUserData());
1504 sal_uLong nAction=0;
1505 if(pEntryData!=NULL)
1506 nAction=pEntryData->nActionNo;
1508 if(nAction>=nStartAction && nAction<=nEndAction)
1509 pTheView->SetCurEntry(pTheView->GetModel()->GetEntry(0));
1511 bool bRemove = false;
1513 // MUST do it backwards, don't delete parents before children and GPF
1514 pEntry=pTheView->Last();
1515 while(pEntry!=NULL)
1517 bRemove=false;
1518 pEntryData=(ScRedlinData *)(pEntry->GetUserData());
1519 if(pEntryData!=NULL)
1521 nAction=pEntryData->nActionNo;
1523 if(nStartAction<=nAction && nAction<=nEndAction) bRemove=true;
1527 SvTreeListEntry* pPrevEntry = pTheView->Prev(pEntry);
1529 if(bRemove)
1530 pTheView->RemoveEntry(pEntry);
1532 pEntry=pPrevEntry;
1534 pTheView->SetUpdateMode(true);
1538 void ScAcceptChgDlg::UpdateEntrys(ScChangeTrack* pChgTrack, sal_uLong nStartAction,sal_uLong nEndAction)
1540 pTheView->SetUpdateMode(false);
1542 sal_uLong nPos=LIST_APPEND;
1544 bool bRemove = false;
1546 SvTreeListEntry* pEntry=pTheView->First();
1547 SvTreeListEntry* pNextEntry = (pEntry ? pTheView->NextSibling(pEntry) : NULL);
1548 SvTreeListEntry* pLastEntry=NULL;
1549 while(pEntry!=NULL)
1551 bRemove=false;
1552 ScRedlinData *pEntryData=(ScRedlinData *)(pEntry->GetUserData());
1553 if(pEntryData!=NULL)
1555 ScChangeAction* pScChangeAction=
1556 (ScChangeAction*) pEntryData->pData;
1558 sal_uLong nAction=pScChangeAction->GetActionNumber();
1560 if(nStartAction<=nAction && nAction<=nEndAction) bRemove=true;
1563 if(bRemove)
1565 nPos=pEntry->GetChildListPos();
1566 pTheView->RemoveEntry(pEntry);
1568 if(pLastEntry==NULL) pLastEntry=pTheView->First();
1569 if(pLastEntry!=NULL)
1571 pNextEntry=pTheView->Next(pLastEntry);
1573 if(pNextEntry==NULL)
1575 pNextEntry=pLastEntry;
1576 pLastEntry=NULL;
1579 else
1580 pNextEntry=NULL;
1583 else
1585 pLastEntry = pEntry;
1586 pNextEntry = pTheView->Next(pEntry);
1588 pEntry=pNextEntry;
1591 if(nStartAction==nEndAction)
1592 AppendChanges(pChgTrack,nStartAction,nEndAction,nPos);
1593 else
1594 AppendChanges(pChgTrack,nStartAction,nEndAction);
1596 pTheView->SetUpdateMode(true);
1600 IMPL_LINK( ScAcceptChgDlg, ChgTrackModHdl, ScChangeTrack*, pChgTrack)
1602 ScChangeTrackMsgQueue::iterator iter;
1603 ScChangeTrackMsgQueue& aMsgQueue= pChgTrack->GetMsgQueue();
1605 sal_uLong nStartAction;
1606 sal_uLong nEndAction;
1608 for (iter = aMsgQueue.begin(); iter != aMsgQueue.end(); ++iter)
1610 nStartAction=(*iter)->nStartAction;
1611 nEndAction=(*iter)->nEndAction;
1613 if(!bIgnoreMsg)
1615 bNoSelection=true;
1617 switch((*iter)->eMsgType)
1619 case SC_CTM_APPEND: AppendChanges(pChgTrack,nStartAction,nEndAction);
1620 break;
1621 case SC_CTM_REMOVE: RemoveEntrys(nStartAction,nEndAction);
1622 break;
1623 case SC_CTM_PARENT:
1624 case SC_CTM_CHANGE: //bNeedsUpdate=true;
1625 UpdateEntrys(pChgTrack,nStartAction,nEndAction);
1626 break;
1627 default:
1629 // added to avoid warnings
1633 delete *iter;
1636 aMsgQueue.clear();
1638 return 0;
1640 IMPL_LINK_NOARG(ScAcceptChgDlg, ReOpenTimerHdl)
1642 ScSimpleRefDlgWrapper::SetAutoReOpen(true);
1643 m_pAcceptChgCtr->ShowFilterPage();
1644 RefHandle(NULL);
1646 return 0;
1649 IMPL_LINK_NOARG(ScAcceptChgDlg, UpdateSelectionHdl)
1651 ScTabView* pTabView = pViewData->GetView();
1653 bool bAcceptFlag = true;
1654 bool bRejectFlag = true;
1655 bool bContMark = false;
1657 pTabView->DoneBlockMode(); // clears old marking
1658 SvTreeListEntry* pEntry = pTheView->FirstSelected();
1659 while( pEntry )
1661 ScRedlinData* pEntryData = (ScRedlinData*) pEntry->GetUserData();
1662 if( pEntryData )
1664 bRejectFlag &= (bool) pEntryData->bIsRejectable;
1665 bAcceptFlag &= (bool) pEntryData->bIsAcceptable;
1667 const ScChangeAction* pScChangeAction = (ScChangeAction*) pEntryData->pData;
1668 if( pScChangeAction && (pScChangeAction->GetType() != SC_CAT_DELETE_TABS) &&
1669 (!pEntryData->bDisabled || pScChangeAction->IsVisible()) )
1671 const ScBigRange& rBigRange = pScChangeAction->GetBigRange();
1672 if( rBigRange.IsValid( pDoc ) && IsActive() )
1674 bool bSetCursor = !pTheView->NextSelected( pEntry );
1675 pTabView->MarkRange( rBigRange.MakeRange(), bSetCursor, bContMark );
1676 bContMark = true;
1680 else
1682 bAcceptFlag = false;
1683 bRejectFlag = false;
1685 bAcceptEnableFlag = bAcceptFlag;
1686 bRejectEnableFlag = bRejectFlag;
1688 pEntry = pTheView->NextSelected( pEntry );
1691 ScChangeTrack* pChanges = pDoc->GetChangeTrack();
1692 bool bEnable = pDoc->IsDocEditable() && pChanges && !pChanges->IsProtected();
1693 pTPView->EnableAccept( bAcceptFlag && bEnable );
1694 pTPView->EnableReject( bRejectFlag && bEnable );
1696 return 0;
1699 IMPL_LINK_NOARG(ScAcceptChgDlg, CommandHdl)
1702 const CommandEvent aCEvt(pTheView->GetCommandEvent());
1704 if(aCEvt.GetCommand()==COMMAND_CONTEXTMENU)
1706 ScPopupMenu aPopup(ScResId(RID_POPUP_CHANGES));
1708 aPopup.SetMenuFlags(MENU_FLAG_HIDEDISABLEDENTRIES);
1710 SvTreeListEntry* pEntry=pTheView->GetCurEntry();
1711 if(pEntry!=NULL)
1713 pTheView->Select(pEntry);
1715 else
1717 aPopup.Deactivate();
1720 sal_uInt16 nSortedCol= pTheView->GetSortedCol();
1722 if(nSortedCol!=0xFFFF)
1724 sal_uInt16 nItemId=nSortedCol+SC_SUB_SORT+1;
1726 aPopup.CheckItem(nItemId);
1728 PopupMenu *pSubMenu = aPopup.GetPopupMenu(SC_SUB_SORT);
1730 if (pSubMenu)
1731 pSubMenu->CheckItem(nItemId);
1734 aPopup.EnableItem(SC_CHANGES_COMMENT,false);
1736 if(pDoc->IsDocEditable() && pEntry!=NULL)
1738 ScRedlinData *pEntryData=(ScRedlinData *)(pEntry->GetUserData());
1739 if(pEntryData!=NULL)
1741 ScChangeAction* pScChangeAction=
1742 (ScChangeAction*) pEntryData->pData;
1743 if(pScChangeAction!=NULL && !pTheView->GetParent(pEntry))
1744 aPopup.EnableItem(SC_CHANGES_COMMENT);
1748 sal_uInt16 nCommand=aPopup.Execute( this, GetPointerPosPixel() );
1751 if(nCommand)
1753 if(nCommand==SC_CHANGES_COMMENT)
1755 if(pEntry!=NULL)
1757 ScRedlinData *pEntryData=(ScRedlinData *)(pEntry->GetUserData());
1758 if(pEntryData!=NULL)
1760 ScChangeAction* pScChangeAction=
1761 (ScChangeAction*) pEntryData->pData;
1763 pViewData->GetDocShell()->ExecuteChangeCommentDialog( pScChangeAction, this,false);
1767 else
1769 bool bSortDir = pTheView->GetSortDirection();
1770 sal_uInt16 nDialogCol=nCommand-SC_SUB_SORT-1;
1771 if(nSortedCol==nDialogCol) bSortDir=!bSortDir;
1772 pTheView->SortByCol(nDialogCol,bSortDir);
1774 SC_SUB_SORT
1775 SC_SORT_ACTION
1776 SC_SORT_POSITION
1777 SC_SORT_AUTHOR
1778 SC_SORT_DATE
1779 SC_SORT_COMMENT
1784 return 0;
1787 void ScAcceptChgDlg::Initialize(SfxChildWinInfo *pInfo)
1789 OUString aStr;
1790 if(pInfo!=NULL)
1792 if ( !pInfo->aExtraString.isEmpty() )
1794 sal_Int32 nPos = pInfo->aExtraString.indexOf("AcceptChgDat:");
1796 // Versuche, den Alignment-String "ALIGN:(...)" einzulesen; wenn
1797 // er nicht vorhanden ist, liegt eine "altere Version vor
1798 if ( nPos != -1 )
1800 sal_Int32 n1 = pInfo->aExtraString.indexOf('(', nPos);
1801 if ( n1 != -1 )
1803 sal_Int32 n2 = pInfo->aExtraString.indexOf(')', n1);
1804 if ( n2 != -1 )
1806 // Alignment-String herausschneiden
1807 aStr = pInfo->aExtraString.copy(nPos, n2 - nPos + 1);
1808 pInfo->aExtraString = pInfo->aExtraString.replaceAt(nPos, n2 - nPos + 1, "");
1809 aStr = aStr.copy( n1-nPos+1 );
1815 SfxModelessDialog::Initialize(pInfo);
1817 if ( !aStr.isEmpty())
1819 sal_uInt16 nCount=(sal_uInt16)aStr.toInt32();
1821 for(sal_uInt16 i=0;i<nCount;i++)
1823 sal_Int32 n1 = aStr.indexOf(';');
1824 aStr = aStr.copy( n1+1 );
1825 pTheView->SetTab(i, (sal_uInt16)aStr.toInt32(), MAP_PIXEL);
1830 //-------------------------------------------------------------------------
1832 void ScAcceptChgDlg::FillInfo(SfxChildWinInfo& rInfo) const
1834 SfxModelessDialog::FillInfo(rInfo);
1835 rInfo.aExtraString += "AcceptChgDat:(";
1837 sal_uInt16 nCount=pTheView->TabCount();
1839 rInfo.aExtraString += OUString::number(nCount);
1840 rInfo.aExtraString += ";";
1841 for(sal_uInt16 i=0;i<nCount;i++)
1843 rInfo.aExtraString += OUString::number(pTheView->GetTab(i));
1844 rInfo.aExtraString += ";";
1846 rInfo.aExtraString += ")";
1849 void ScAcceptChgDlg::InitFilter()
1851 if(pTPFilter->IsDate()||pTPFilter->IsRange()||
1852 pTPFilter->IsAuthor()||pTPFilter->IsComment())
1854 pTheView->SetFilterDate(pTPFilter->IsDate());
1855 pTheView->SetDateTimeMode(pTPFilter->GetDateMode());
1856 pTheView->SetFirstDate(pTPFilter->GetFirstDate());
1857 pTheView->SetLastDate(pTPFilter->GetLastDate());
1858 pTheView->SetFirstTime(pTPFilter->GetFirstTime());
1859 pTheView->SetLastTime(pTPFilter->GetLastTime());
1860 pTheView->SetFilterAuthor(pTPFilter->IsAuthor());
1861 pTheView->SetAuthor(pTPFilter->GetSelectedAuthor());
1863 pTheView->SetFilterComment(pTPFilter->IsComment());
1865 utl::SearchParam aSearchParam( pTPFilter->GetComment(),
1866 utl::SearchParam::SRCH_REGEXP,false,false,false );
1868 pTheView->SetCommentParams(&aSearchParam);
1870 pTheView->UpdateFilterTest();
1874 IMPL_LINK_NOARG(ScAcceptChgDlg, FilterModified)
1876 return 0;
1879 #define CALC_DATE 3
1880 #define CALC_POS 1
1882 IMPL_LINK( ScAcceptChgDlg, ColCompareHdl, SvSortData*, pSortData )
1884 sal_Int32 nCompare = 0;
1885 SCCOL nSortCol= static_cast<SCCOL>(pTheView->GetSortedCol());
1887 if(pSortData)
1889 SvTreeListEntry* pLeft = (SvTreeListEntry*)(pSortData->pLeft );
1890 SvTreeListEntry* pRight = (SvTreeListEntry*)(pSortData->pRight );
1892 if(CALC_DATE==nSortCol)
1894 RedlinData *pLeftData=(RedlinData *)(pLeft->GetUserData());
1895 RedlinData *pRightData=(RedlinData *)(pRight->GetUserData());
1897 if(pLeftData!=NULL && pRightData!=NULL)
1899 if(pLeftData->aDateTime < pRightData->aDateTime)
1900 nCompare = -1;
1901 else if(pLeftData->aDateTime > pRightData->aDateTime)
1902 nCompare = 1;
1903 return nCompare;
1906 else if(CALC_POS==nSortCol)
1908 ScRedlinData *pLeftData=(ScRedlinData *)(pLeft->GetUserData());
1909 ScRedlinData *pRightData=(ScRedlinData *)(pRight->GetUserData());
1911 if(pLeftData!=NULL && pRightData!=NULL)
1913 nCompare = 1;
1915 if(pLeftData->nTable < pRightData->nTable)
1916 nCompare = -1;
1917 else if(pLeftData->nTable == pRightData->nTable)
1919 if(pLeftData->nRow < pRightData->nRow)
1920 nCompare = -1;
1921 else if(pLeftData->nRow == pRightData->nRow)
1923 if(pLeftData->nCol < pRightData->nCol)
1924 nCompare = -1;
1925 else if(pLeftData->nCol == pRightData->nCol)
1926 nCompare = 0;
1930 return nCompare;
1934 SvLBoxItem* pLeftItem = pTheView->GetEntryAtPos( pLeft, static_cast<sal_uInt16>(nSortCol));
1935 SvLBoxItem* pRightItem = pTheView->GetEntryAtPos( pRight, static_cast<sal_uInt16>(nSortCol));
1937 if(pLeftItem != NULL && pRightItem != NULL)
1939 sal_uInt16 nLeftKind = pLeftItem->GetType();
1940 sal_uInt16 nRightKind = pRightItem->GetType();
1942 if(nRightKind == SV_ITEM_ID_LBOXSTRING &&
1943 nLeftKind == SV_ITEM_ID_LBOXSTRING )
1945 nCompare = ScGlobal::GetCaseCollator()->compareString(
1946 ((SvLBoxString*)pLeftItem)->GetText(),
1947 ((SvLBoxString*)pRightItem)->GetText());
1949 if (nCompare == 0)
1950 nCompare = -1;
1956 return nCompare;
1959 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */