Version 4.0.2.1, tag libreoffice-4.0.2.1
[LibreOffice.git] / sc / source / ui / miscdlgs / acredlin.cxx
blobaaeb225c6d31737ecf01a74c79905d36dc583d19
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_SREF3D ABS_SREF | SCA_TAB_3D
50 #define ABS_DREF3D ABS_DREF | SCA_TAB_3D
52 #define ERRORBOX(s) ErrorBox(this,WinBits(WB_OK|WB_DEF_OK),s).Execute();
54 inline void EnableDisable( Window& rWin, bool bEnable )
56 if (bEnable)
57 rWin.Enable();
58 else
59 rWin.Disable();
62 #define RD_SPECIAL_NONE 0
63 #define RD_SPECIAL_CONTENT 1
64 #define RD_SPECIAL_VISCONTENT 2
66 //============================================================================
67 // class ScRedlinData
68 //----------------------------------------------------------------------------
69 ScRedlinData::ScRedlinData()
70 :RedlinData()
72 nInfo=RD_SPECIAL_NONE;
73 nActionNo=0;
74 pData=NULL;
75 bDisabled=false;
76 bIsRejectable=false;
77 bIsAcceptable=false;
78 nTable=SCTAB_MAX;
79 nCol=SCCOL_MAX;
80 nRow=SCROW_MAX;
83 ScRedlinData::~ScRedlinData()
85 nInfo=RD_SPECIAL_NONE;
86 nActionNo=0;
87 pData=NULL;
88 bDisabled=false;
89 bIsRejectable=false;
90 bIsAcceptable=false;
93 //============================================================================
94 // class ScAcceptChgDlg
95 //----------------------------------------------------------------------------
96 ScAcceptChgDlg::ScAcceptChgDlg( SfxBindings* pB, SfxChildWindow* pCW, Window* pParent,
97 ScViewData* ptrViewData)
99 : SfxModelessDialog( pB, pCW, pParent, ScResId(RID_SCDLG_CHANGES) ),
100 aAcceptChgCtr ( this, ScResId( CTR_REDLINING ) ),
101 pViewData ( ptrViewData ),
102 pDoc ( ptrViewData->GetDocument() ),
103 aLocalRangeName ( *(pDoc->GetRangeName()) ),
104 aStrInsertCols (SC_RESSTR(STR_INSERT_COLS)),
105 aStrInsertRows (SC_RESSTR(STR_INSERT_ROWS)),
106 aStrInsertTabs (SC_RESSTR(STR_INSERT_TABS)),
107 aStrDeleteCols (SC_RESSTR(STR_DELETE_COLS)),
108 aStrDeleteRows (SC_RESSTR(STR_DELETE_ROWS)),
109 aStrDeleteTabs (SC_RESSTR(STR_DELETE_TABS)),
110 aStrMove (SC_RESSTR(STR_MOVE)),
111 aStrContent (SC_RESSTR(STR_CONTENT)),
112 aStrReject (SC_RESSTR(STR_REJECT)),
113 aStrAllAccepted (SC_RESSTR(STR_ACCEPTED)),
114 aStrAllRejected (SC_RESSTR(STR_REJECTED)),
115 aStrNoEntry (SC_RESSTR(STR_NO_ENTRY)),
116 aStrContentWithChild (SC_RESSTR(STR_CONTENT_WITH_CHILD)),
117 aStrChildContent (SC_RESSTR(STR_CHILD_CONTENT)),
118 aStrChildOrgContent (SC_RESSTR(STR_CHILD_ORGCONTENT)),
119 aStrEmpty (SC_RESSTR(STR_EMPTY)),
120 aUnknown(RTL_CONSTASCII_USTRINGPARAM("Unknown")),
121 bAcceptEnableFlag(true),
122 bRejectEnableFlag(true),
123 bNeedsUpdate(false),
124 bIgnoreMsg(false),
125 bNoSelection(false),
126 bHasFilterEntry(false),
127 bUseColor(false)
129 FreeResource();
130 nAcceptCount=0;
131 nRejectCount=0;
132 aReOpenTimer.SetTimeout(50);
133 aReOpenTimer.SetTimeoutHdl(LINK( this, ScAcceptChgDlg, ReOpenTimerHdl ));
135 // dialog is now only hidden, not deleted, on switching views,
136 // so there's no need to restore settings when reopening
137 MinSize=aAcceptChgCtr.GetMinSizePixel();
138 MinSize.Height()+=2;
139 MinSize.Width()+=2;
140 SetMinOutputSizePixel(MinSize);
142 pTPFilter=aAcceptChgCtr.GetFilterPage();
143 pTPView=aAcceptChgCtr.GetViewPage();
144 pTheView=pTPView->GetTableControl();
145 aSelectionTimer.SetTimeout(100);
146 aSelectionTimer.SetTimeoutHdl(LINK( this, ScAcceptChgDlg, UpdateSelectionHdl ));
148 pTPFilter->SetReadyHdl(LINK( this, ScAcceptChgDlg, FilterHandle ));
149 pTPFilter->SetRefHdl(LINK( this, ScAcceptChgDlg, RefHandle ));
150 pTPFilter->SetModifyHdl(LINK( this, ScAcceptChgDlg, FilterModified));
151 pTPFilter->HideRange(false);
152 pTPView->InsertCalcHeader();
153 pTPView->SetRejectClickHdl( LINK( this, ScAcceptChgDlg,RejectHandle));
154 pTPView->SetAcceptClickHdl( LINK(this, ScAcceptChgDlg, AcceptHandle));
155 pTPView->SetRejectAllClickHdl( LINK( this, ScAcceptChgDlg,RejectAllHandle));
156 pTPView->SetAcceptAllClickHdl( LINK(this, ScAcceptChgDlg, AcceptAllHandle));
157 pTheView->SetCalcView();
158 pTheView->SetStyle(pTheView->GetStyle()|WB_HASLINES|WB_CLIPCHILDREN|WB_HASBUTTONS|WB_HASBUTTONSATROOT|WB_HSCROLL);
159 pTheView->SetExpandingHdl( LINK(this, ScAcceptChgDlg, ExpandingHandle));
160 pTheView->SetSelectHdl( LINK(this, ScAcceptChgDlg, SelectHandle));
161 pTheView->SetDeselectHdl( LINK(this, ScAcceptChgDlg, SelectHandle));
162 pTheView->SetCommandHdl( LINK(this, ScAcceptChgDlg, CommandHdl));
163 pTheView->SetColCompareHdl( LINK(this, ScAcceptChgDlg,ColCompareHdl));
164 pTheView->SetSelectionMode(MULTIPLE_SELECTION);
165 pTheView->SetHighlightRange(1);
167 Init();
169 aAcceptChgCtr.SetMinSizeHdl( LINK( this, ScAcceptChgDlg, MinSizeHandle ));
171 UpdateView();
172 SvTreeListEntry* pEntry=pTheView->First();
173 if(pEntry!=NULL)
175 pTheView->Select(pEntry);
178 ScAcceptChgDlg::~ScAcceptChgDlg()
180 ClearView();
181 ScChangeTrack* pChanges=pDoc->GetChangeTrack();
183 if(pChanges!=NULL)
185 Link aLink;
186 pChanges->SetModifiedLink(aLink);
190 void ScAcceptChgDlg::ReInit(ScViewData* ptrViewData)
192 pViewData=ptrViewData;
193 if(pViewData!=NULL)
194 pDoc=ptrViewData->GetDocument();
195 else
196 pDoc=NULL;
198 bNoSelection=false;
199 bNeedsUpdate=false;
200 bIgnoreMsg=false;
201 nAcceptCount=0;
202 nRejectCount=0;
203 bAcceptEnableFlag=true;
204 bRejectEnableFlag=true;
206 // don't call Init here (switching between views), just set link below
207 // (dialog is just hidden, not deleted anymore, when switching views)
208 ClearView();
209 UpdateView();
211 if ( pDoc )
213 ScChangeTrack* pChanges = pDoc->GetChangeTrack();
214 if ( pChanges )
215 pChanges->SetModifiedLink( LINK( this, ScAcceptChgDlg, ChgTrackModHdl ) );
219 void ScAcceptChgDlg::Init()
221 String aAreaStr;
222 ScRange aRange;
224 OSL_ENSURE( pViewData && pDoc, "ViewData oder Document nicht gefunden!" );
226 ScChangeTrack* pChanges=pDoc->GetChangeTrack();
228 if(pChanges!=NULL)
230 pChanges->SetModifiedLink( LINK( this, ScAcceptChgDlg,ChgTrackModHdl));
231 aChangeViewSet.SetTheAuthorToShow(pChanges->GetUser());
232 pTPFilter->ClearAuthors();
233 const std::set<rtl::OUString>& rUserColl = pChanges->GetUserCollection();
234 std::set<rtl::OUString>::const_iterator it = rUserColl.begin(), itEnd = rUserColl.end();
235 for (; it != itEnd; ++it)
236 pTPFilter->InsertAuthor(*it);
239 ScChangeViewSettings* pViewSettings=pDoc->GetChangeViewSettings();
240 if ( pViewSettings!=NULL )
241 aChangeViewSet = *pViewSettings;
242 // adjust TimeField for filter tabpage
243 aChangeViewSet.AdjustDateMode( *pDoc );
245 pTPFilter->CheckDate(aChangeViewSet.HasDate());
246 pTPFilter->SetFirstDate(aChangeViewSet.GetTheFirstDateTime());
247 pTPFilter->SetFirstTime(aChangeViewSet.GetTheFirstDateTime());
248 pTPFilter->SetLastDate(aChangeViewSet.GetTheLastDateTime());
249 pTPFilter->SetLastTime(aChangeViewSet.GetTheLastDateTime());
250 pTPFilter->SetDateMode((sal_uInt16)aChangeViewSet.GetTheDateMode());
251 pTPFilter->CheckComment(aChangeViewSet.HasComment());
252 pTPFilter->SetComment(aChangeViewSet.GetTheComment());
254 pTPFilter->CheckAuthor(aChangeViewSet.HasAuthor());
255 String aString=aChangeViewSet.GetTheAuthorToShow();
256 if(aString.Len()!=0)
258 pTPFilter->SelectAuthor(aString);
259 if(pTPFilter->GetSelectedAuthor()!=aString)
261 pTPFilter->InsertAuthor(aString);
262 pTPFilter->SelectAuthor(aString);
265 else
266 pTPFilter->SelectedAuthorPos(0);
268 pTPFilter->CheckRange(aChangeViewSet.HasRange());
270 aRangeList=aChangeViewSet.GetTheRangeList();
272 if( !aChangeViewSet.GetTheRangeList().empty() )
274 const ScRange* pRangeEntry = aChangeViewSet.GetTheRangeList().front();
275 String aRefStr;
276 pRangeEntry->Format( aRefStr, ABS_DREF3D, pDoc );
277 pTPFilter->SetRange(aRefStr);
280 Point aPoint(1,1);
281 aAcceptChgCtr.SetPosPixel(aPoint);
282 InitFilter();
287 void ScAcceptChgDlg::ClearView()
289 nAcceptCount=0;
290 nRejectCount=0;
291 pTheView->SetUpdateMode(false);
293 pTheView->Clear();
294 pTheView->SetUpdateMode(true);
297 rtl::OUString* ScAcceptChgDlg::MakeTypeString(ScChangeActionType eType)
299 rtl::OUString* pStr;
301 switch(eType)
304 case SC_CAT_INSERT_COLS: pStr=&aStrInsertCols;break;
305 case SC_CAT_INSERT_ROWS: pStr=&aStrInsertRows;break;
306 case SC_CAT_INSERT_TABS: pStr=&aStrInsertTabs;break;
307 case SC_CAT_DELETE_COLS: pStr=&aStrDeleteCols;break;
308 case SC_CAT_DELETE_ROWS: pStr=&aStrDeleteRows;break;
309 case SC_CAT_DELETE_TABS: pStr=&aStrDeleteTabs;break;
310 case SC_CAT_MOVE: pStr=&aStrMove;break;
311 case SC_CAT_CONTENT: pStr=&aStrContent;break;
312 case SC_CAT_REJECT: pStr=&aStrReject;break;
313 default: pStr=&aUnknown;break;
315 return pStr;
319 bool ScAcceptChgDlg::IsValidAction(const ScChangeAction* pScChangeAction)
321 if(pScChangeAction==NULL) return false;
323 bool bFlag = false;
325 ScRange aRef=pScChangeAction->GetBigRange().MakeRange();
326 String aUser=pScChangeAction->GetUser();
327 DateTime aDateTime=pScChangeAction->GetDateTime();
329 ScChangeActionType eType=pScChangeAction->GetType();
330 String aString;
331 rtl::OUString aDesc;
333 String aComment = comphelper::string::remove(pScChangeAction->GetComment(), '\n');
335 if(eType==SC_CAT_CONTENT)
337 if(!pScChangeAction->IsDialogParent())
338 pScChangeAction->GetDescription(aDesc, pDoc, true);
340 else
341 pScChangeAction->GetDescription(aDesc, pDoc, !pScChangeAction->IsMasterDelete());
343 if (!aDesc.isEmpty())
345 aComment.AppendAscii(RTL_CONSTASCII_STRINGPARAM( " (" ));
346 aComment += String(aDesc);
347 aComment += ')';
350 if(pTheView->IsValidEntry(&aUser,&aDateTime,&aComment))
352 if(pTPFilter->IsRange())
354 for ( size_t i = 0, nRanges = aRangeList.size(); i < nRanges; ++i )
356 ScRange* pRangeEntry = aRangeList[ i ];
357 if (pRangeEntry->Intersects(aRef)) {
358 bFlag = true;
359 break;
363 else
364 bFlag=true;
367 return bFlag;
370 SvTreeListEntry* ScAcceptChgDlg::InsertChangeAction(
371 const ScChangeAction* pScChangeAction, ScChangeActionState /*eState*/,
372 SvTreeListEntry* pParent, bool bDelMaster,bool bDisabled, sal_uLong nPos)
374 ScChangeTrack* pChanges=pDoc->GetChangeTrack();
376 if(pScChangeAction==NULL || pChanges==NULL) return NULL;
378 SvTreeListEntry* pEntry=NULL;
380 bool bFlag = false;
382 ScRange aRef=pScChangeAction->GetBigRange().MakeRange();
383 String aUser=pScChangeAction->GetUser();
384 DateTime aDateTime=pScChangeAction->GetDateTime();
386 rtl::OUString aRefStr;
387 ScChangeActionType eType=pScChangeAction->GetType();
388 rtl::OUStringBuffer aBuf;
389 rtl::OUString aDesc;
391 ScRedlinData* pNewData=new ScRedlinData;
392 pNewData->pData=(void *)pScChangeAction;
393 pNewData->nActionNo=pScChangeAction->GetActionNumber();
394 pNewData->bIsAcceptable=pScChangeAction->IsClickable();
395 pNewData->bIsRejectable=pScChangeAction->IsRejectable();
396 pNewData->bDisabled=!pNewData->bIsAcceptable || bDisabled;
397 pNewData->aDateTime=aDateTime;
398 pNewData->nRow = aRef.aStart.Row();
399 pNewData->nCol = aRef.aStart.Col();
400 pNewData->nTable= aRef.aStart.Tab();
402 if(eType==SC_CAT_CONTENT)
404 if(pScChangeAction->IsDialogParent())
406 aBuf.append(aStrContentWithChild);
407 pNewData->nInfo=RD_SPECIAL_VISCONTENT;
408 pNewData->bIsRejectable=false;
409 pNewData->bIsAcceptable=false;
411 else
413 aBuf.append(*MakeTypeString(eType));
414 pScChangeAction->GetDescription( aDesc, pDoc, true);
417 else
419 aBuf.append(aStrContentWithChild);
421 if(bDelMaster)
423 pScChangeAction->GetDescription( aDesc, pDoc,true);
424 pNewData->bDisabled=true;
425 pNewData->bIsRejectable=false;
427 else
428 pScChangeAction->GetDescription( aDesc, pDoc,!pScChangeAction->IsMasterDelete());
432 pScChangeAction->GetRefString(aRefStr, pDoc, true);
434 aBuf.append(sal_Unicode('\t'));
435 aBuf.append(aRefStr);
436 aBuf.append(sal_Unicode('\t'));
438 bool bIsGenerated = false;
440 if(!pChanges->IsGenerated(pScChangeAction->GetActionNumber()))
442 aBuf.append(aUser);
443 aBuf.append(sal_Unicode('\t'));
444 aBuf.append(ScGlobal::pLocaleData->getDate(aDateTime));
445 aBuf.append(sal_Unicode(' '));
446 aBuf.append(ScGlobal::pLocaleData->getTime(aDateTime));
447 aBuf.append(sal_Unicode('\t'));
449 bIsGenerated = false;
451 else
453 aBuf.append(sal_Unicode('\t'));
454 aBuf.append(sal_Unicode('\t'));
455 bIsGenerated = true;
458 String aComment = comphelper::string::remove(pScChangeAction->GetComment(), '\n');
460 if (!aDesc.isEmpty())
462 aComment.AppendAscii(RTL_CONSTASCII_STRINGPARAM( " (" ));
463 aComment += String(aDesc);
464 aComment += ')';
467 aBuf.append(aComment);
469 if(pTheView->IsValidEntry(&aUser,&aDateTime)|| bIsGenerated)
471 if(pTheView->IsValidComment(&aComment))
473 if(pTPFilter->IsRange())
475 for ( size_t i = 0, nRanges = aRangeList.size(); i < nRanges; ++i )
477 ScRange* pRangeEntry = aRangeList[ i ];
478 if( pRangeEntry->Intersects(aRef) )
480 bHasFilterEntry=true;
481 bFlag=true;
482 break;
486 else if(!bIsGenerated)
488 bHasFilterEntry=true;
489 bFlag=true;
494 if(!bFlag&& bUseColor&& pParent==NULL)
496 pEntry = pTheView->InsertEntry(
497 aBuf.makeStringAndClear() ,pNewData, Color(COL_LIGHTBLUE), pParent, nPos);
499 else if(bFlag&& bUseColor&& pParent!=NULL)
501 pEntry = pTheView->InsertEntry(
502 aBuf.makeStringAndClear(), pNewData, Color(COL_GREEN), pParent, nPos);
503 SvTreeListEntry* pExpEntry=pParent;
505 while(pExpEntry!=NULL && !pTheView->IsExpanded(pExpEntry))
507 SvTreeListEntry* pTmpEntry=pTheView->GetParent(pExpEntry);
509 if(pTmpEntry!=NULL) pTheView->Expand(pExpEntry);
511 pExpEntry=pTmpEntry;
514 else
516 pEntry = pTheView->InsertEntry(
517 aBuf.makeStringAndClear(), pNewData, pParent, nPos);
519 return pEntry;
522 SvTreeListEntry* ScAcceptChgDlg::InsertFilteredAction(
523 const ScChangeAction* pScChangeAction, ScChangeActionState eState,
524 SvTreeListEntry* pParent, bool bDelMaster, bool bDisabled, sal_uLong nPos)
527 ScChangeTrack* pChanges=pDoc->GetChangeTrack();
529 if(pScChangeAction==NULL || pChanges==NULL) return NULL;
531 bool bIsGenerated = pChanges->IsGenerated(pScChangeAction->GetActionNumber());
533 SvTreeListEntry* pEntry=NULL;
535 bool bFlag = false;
537 ScRange aRef=pScChangeAction->GetBigRange().MakeRange();
538 String aUser=pScChangeAction->GetUser();
539 DateTime aDateTime=pScChangeAction->GetDateTime();
541 if(pTheView->IsValidEntry(&aUser,&aDateTime)||bIsGenerated)
543 if(pTPFilter->IsRange())
545 for ( size_t i = 0, nRanges = aRangeList.size(); i < nRanges; ++i )
547 ScRange* pRangeEntry=aRangeList[ i ];
548 if( pRangeEntry->Intersects(aRef) )
550 if( pScChangeAction->GetState()==eState )
551 bFlag = true;
552 break;
556 else if(pScChangeAction->GetState()==eState && !bIsGenerated)
557 bFlag = true;
560 if(bFlag)
563 rtl::OUString aRefStr;
564 ScChangeActionType eType=pScChangeAction->GetType();
565 String aString;
566 rtl::OUString aDesc;
568 ScRedlinData* pNewData=new ScRedlinData;
569 pNewData->pData=(void *)pScChangeAction;
570 pNewData->nActionNo=pScChangeAction->GetActionNumber();
571 pNewData->bIsAcceptable=pScChangeAction->IsClickable();
572 pNewData->bIsRejectable=pScChangeAction->IsRejectable();
573 pNewData->bDisabled=!pNewData->bIsAcceptable || bDisabled;
574 pNewData->aDateTime=aDateTime;
575 pNewData->nRow = aRef.aStart.Row();
576 pNewData->nCol = aRef.aStart.Col();
577 pNewData->nTable= aRef.aStart.Tab();
579 if(eType==SC_CAT_CONTENT)
581 if(pScChangeAction->IsDialogParent())
583 aString=aStrContentWithChild;
584 pNewData->nInfo=RD_SPECIAL_VISCONTENT;
585 pNewData->bIsRejectable=false;
586 pNewData->bIsAcceptable=false;
588 else
590 aString=*MakeTypeString(eType);
591 pScChangeAction->GetDescription( aDesc, pDoc, true);
594 else
596 aString=*MakeTypeString(eType);
598 if(bDelMaster)
600 pScChangeAction->GetDescription( aDesc, pDoc,true);
601 pNewData->bDisabled=true;
602 pNewData->bIsRejectable=false;
604 else
605 pScChangeAction->GetDescription( aDesc, pDoc,!pScChangeAction->IsMasterDelete());
609 aString+='\t';
610 pScChangeAction->GetRefString(aRefStr, pDoc, true);
611 aString+=aRefStr;
612 aString+='\t';
614 if(!bIsGenerated)
616 aString+=aUser;
617 aString+='\t';
618 aString+=ScGlobal::pLocaleData->getDate(aDateTime);
619 aString+=' ';
620 aString+=ScGlobal::pLocaleData->getTime(aDateTime);
621 aString+='\t';
623 else
625 aString+='\t';
626 aString+='\t';
629 String aComment = comphelper::string::remove(pScChangeAction->GetComment(), '\n');
631 if (!aDesc.isEmpty())
633 aComment.AppendAscii(RTL_CONSTASCII_STRINGPARAM( " (" ));
634 aComment += String(aDesc);
635 aComment += ')';
637 if(pTheView->IsValidComment(&aComment))
639 aString+=aComment;
640 pEntry=pTheView->InsertEntry(aString,pNewData,pParent,nPos);
642 else
643 delete pNewData;
645 return pEntry;
648 SvTreeListEntry* ScAcceptChgDlg::InsertChangeActionContent(const ScChangeActionContent* pScChangeAction,
649 SvTreeListEntry* pParent, sal_uLong nSpecial)
651 ScChangeTrack* pChanges=pDoc->GetChangeTrack();
652 SvTreeListEntry* pEntry=NULL;
654 if(pScChangeAction==NULL || pChanges==NULL) return NULL;
656 bool bIsGenerated = pChanges->IsGenerated(pScChangeAction->GetActionNumber());
658 bool bFlag = false;
660 ScRange aRef=pScChangeAction->GetBigRange().MakeRange();
661 String aUser=pScChangeAction->GetUser();
662 DateTime aDateTime=pScChangeAction->GetDateTime();
664 if(pTheView->IsValidEntry(&aUser,&aDateTime)||bIsGenerated)
666 if(pTPFilter->IsRange())
668 for ( size_t i = 0, nRanges = aRangeList.size(); i < nRanges; ++i )
670 ScRange* pRangeEntry = aRangeList[ i ];
671 if( pRangeEntry->Intersects(aRef) )
673 bFlag=true;
674 break;
678 else if(!bIsGenerated)
679 bFlag=true;
682 rtl::OUString aRefStr;
683 String aString;
684 String a2String;
685 String aDesc;
687 if(nSpecial==RD_SPECIAL_CONTENT)
689 rtl::OUString aTmp;
690 pScChangeAction->GetOldString(aTmp);
691 a2String = aTmp;
692 if(a2String.Len()==0) a2String=aStrEmpty;
694 //aString+="\'";
695 aString+=a2String;
696 //aString+="\'";
698 aDesc=aStrChildOrgContent;
699 aDesc.AppendAscii(RTL_CONSTASCII_STRINGPARAM( ": " ));
701 else
703 rtl::OUString aTmp;
704 pScChangeAction->GetNewString(aTmp);
705 a2String = aTmp;
706 if(a2String.Len()==0)
708 a2String=aStrEmpty;
709 aString+=a2String;
711 else
713 aString+='\'';
714 aString+=a2String;
715 aString+='\'';
716 a2String=aString;
718 aDesc=aStrChildContent;
722 aDesc+=a2String;
723 aString+='\t';
724 pScChangeAction->GetRefString(aRefStr, pDoc, true);
725 aString+=aRefStr;
726 aString+='\t';
728 if(!bIsGenerated)
730 aString+=aUser;
731 aString+='\t';
733 aString+=ScGlobal::pLocaleData->getDate(aDateTime);
734 aString+=' ';
735 aString+=ScGlobal::pLocaleData->getTime(aDateTime);
736 aString+='\t';
738 else
740 aString+='\t';
741 aString+='\t';
744 String aComment = comphelper::string::remove(pScChangeAction->GetComment(), '\n');
746 if(aDesc.Len()>0)
748 aComment.AppendAscii(RTL_CONSTASCII_STRINGPARAM( " (" ));
749 aComment+=aDesc;
750 aComment+=')';
753 aString+=aComment;
755 ScRedlinData* pNewData=new ScRedlinData;
756 pNewData->nInfo=nSpecial;
757 pNewData->pData=(void *)pScChangeAction;
758 pNewData->nActionNo=pScChangeAction->GetActionNumber();
759 pNewData->bIsAcceptable=pScChangeAction->IsClickable();
760 pNewData->bIsRejectable=false;
761 pNewData->bDisabled=!pNewData->bIsAcceptable;
762 pNewData->aDateTime=aDateTime;
763 pNewData->nRow = aRef.aStart.Row();
764 pNewData->nCol = aRef.aStart.Col();
765 pNewData->nTable= aRef.aStart.Tab();
767 if(pTheView->IsValidComment(&aComment) && bFlag)
769 bHasFilterEntry=true;
770 pEntry=pTheView->InsertEntry(aString,pNewData,pParent);
772 else
773 pEntry=pTheView->InsertEntry(aString,pNewData,Color(COL_LIGHTBLUE),pParent);
774 return pEntry;
777 long ScAcceptChgDlg::PreNotify( NotifyEvent& rNEvt )
779 if(rNEvt.GetType()==EVENT_GETFOCUS && bNeedsUpdate)
781 ClearView();
782 UpdateView();
783 bNoSelection=false;
786 return SfxModelessDialog::PreNotify(rNEvt);
790 void ScAcceptChgDlg::UpdateView()
792 bNeedsUpdate=false;
793 SvTreeListEntry* pParent=NULL;
794 ScChangeTrack* pChanges=NULL;
795 const ScChangeAction* pScChangeAction=NULL;
796 bAcceptEnableFlag=true;
797 bRejectEnableFlag=true;
798 SetPointer(Pointer(POINTER_WAIT));
799 pTheView->SetUpdateMode(false);
800 bool bFilterFlag = pTPFilter->IsDate() || pTPFilter->IsRange() ||
801 pTPFilter->IsAuthor() || pTPFilter->IsComment();
803 bUseColor = bFilterFlag;
805 if(pDoc!=NULL)
807 pChanges=pDoc->GetChangeTrack();
808 if(pChanges!=NULL)
809 pScChangeAction=pChanges->GetFirst();
811 bool bTheFlag = false;
813 while(pScChangeAction!=NULL)
815 bHasFilterEntry=false;
816 switch(pScChangeAction->GetState())
818 case SC_CAS_VIRGIN:
820 if(pScChangeAction->IsDialogRoot())
822 if(pScChangeAction->IsDialogParent())
823 pParent=InsertChangeAction(pScChangeAction,SC_CAS_VIRGIN);
824 else
825 pParent=InsertFilteredAction(pScChangeAction,SC_CAS_VIRGIN);
827 else
828 pParent=NULL;
830 bTheFlag=true;
831 break;
833 case SC_CAS_ACCEPTED:
834 pParent=NULL;
835 nAcceptCount++;
836 break;
838 case SC_CAS_REJECTED:
839 pParent=NULL;
840 nRejectCount++;
841 break;
844 if(pParent!=NULL && pScChangeAction->IsDialogParent())
846 if(!bFilterFlag)
847 pParent->EnableChildrenOnDemand(true);
848 else
850 bool bTestFlag = bHasFilterEntry;
851 bHasFilterEntry=false;
852 if(Expand(pChanges,pScChangeAction,pParent,!bTestFlag)&&!bTestFlag)
853 pTheView->RemoveEntry(pParent);
857 pScChangeAction=pScChangeAction->GetNext();
860 if( bTheFlag && (!pDoc->IsDocEditable() || pChanges->IsProtected()) )
861 bTheFlag=false;
863 pTPView->EnableAccept(bTheFlag);
864 pTPView->EnableAcceptAll(bTheFlag);
865 pTPView->EnableReject(bTheFlag);
866 pTPView->EnableRejectAll(bTheFlag);
868 if(nAcceptCount>0)
870 pParent=pTheView->InsertEntry(
871 aStrAllAccepted, static_cast< RedlinData * >(NULL),
872 static_cast< SvTreeListEntry * >(NULL));
873 pParent->EnableChildrenOnDemand(true);
875 if(nRejectCount>0)
877 pParent=pTheView->InsertEntry(
878 aStrAllRejected, static_cast< RedlinData * >(NULL),
879 static_cast< SvTreeListEntry * >(NULL));
880 pParent->EnableChildrenOnDemand(true);
882 pTheView->SetUpdateMode(true);
883 SetPointer(Pointer(POINTER_ARROW));
884 SvTreeListEntry* pEntry=pTheView->First();
885 if(pEntry!=NULL)
886 pTheView->Select(pEntry);
889 //----------------------------------------------------------------------------
890 sal_Bool ScAcceptChgDlg::Close()
892 return SfxModelessDialog::Close();
895 void ScAcceptChgDlg::Resize()
897 SfxModelessDialog::Resize();
898 Size aOutSize=GetOutputSizePixel();
899 aAcceptChgCtr.SetSizePixel(aOutSize);
902 IMPL_LINK( ScAcceptChgDlg, MinSizeHandle, SvxAcceptChgCtr*, pCtr )
904 if(pCtr==&aAcceptChgCtr)
905 if(!IsRollUp())
906 SetOutputSizePixel(MinSize);
907 return 0;
910 IMPL_LINK_NOARG(ScAcceptChgDlg, RefHandle)
912 sal_uInt16 nId =ScSimpleRefDlgWrapper::GetChildWindowId();
914 ScSimpleRefDlgWrapper::SetDefaultPosSize(GetPosPixel(),GetSizePixel(),true);
916 SC_MOD()->SetRefDialog( nId, true );
918 SfxViewFrame* pViewFrm = pViewData->GetViewShell()->GetViewFrame();
919 ScSimpleRefDlgWrapper* pWnd =(ScSimpleRefDlgWrapper*)pViewFrm->GetChildWindow( nId );
921 if(pWnd!=NULL)
923 sal_uInt16 nAcceptId=ScAcceptChgDlgWrapper::GetChildWindowId();
924 pViewFrm->ShowChildWindow(nAcceptId,false);
925 pWnd->SetCloseHdl(LINK( this, ScAcceptChgDlg,RefInfoHandle));
926 pWnd->SetRefString(pTPFilter->GetRange());
927 pWnd->SetAutoReOpen(false);
928 Window* pWin=pWnd->GetWindow();
929 pWin->SetPosSizePixel(GetPosPixel(),GetSizePixel());
930 Hide();
931 pWin->SetText(GetText());
932 pWnd->StartRefInput();
934 return 0;
937 IMPL_LINK( ScAcceptChgDlg, RefInfoHandle, String*, pResult)
939 sal_uInt16 nId;
941 ScSimpleRefDlgWrapper::SetAutoReOpen(true);
943 SfxViewFrame* pViewFrm = pViewData->GetViewShell()->GetViewFrame();
944 if(pResult!=NULL)
946 pTPFilter->SetRange(*pResult);
947 FilterHandle(pTPFilter);
949 nId = ScSimpleRefDlgWrapper::GetChildWindowId();
950 ScSimpleRefDlgWrapper* pWnd = (ScSimpleRefDlgWrapper*)pViewFrm->GetChildWindow( nId );
952 if(pWnd!=NULL)
954 Window* pWin=pWnd->GetWindow();
955 Size aWinSize=pWin->GetSizePixel();
956 aWinSize.Width()=GetSizePixel().Width();
957 SetPosSizePixel(pWin->GetPosPixel(),aWinSize);
958 Invalidate();
960 nId = ScAcceptChgDlgWrapper::GetChildWindowId();
961 pViewFrm->ShowChildWindow( nId, true );
963 else
965 nId = ScAcceptChgDlgWrapper::GetChildWindowId();
966 pViewFrm->SetChildWindow( nId, false );
968 return 0;
971 IMPL_LINK( ScAcceptChgDlg, FilterHandle, SvxTPFilter*, pRef )
973 if(pRef!=NULL)
975 ClearView();
976 aRangeList.RemoveAll();
977 aRangeList.Parse(pTPFilter->GetRange(),pDoc);
978 UpdateView();
980 return 0;
983 IMPL_LINK( ScAcceptChgDlg, RejectHandle, SvxTPView*, pRef )
985 SetPointer(Pointer(POINTER_WAIT));
987 bIgnoreMsg=true;
988 ScChangeTrack* pChanges=pDoc->GetChangeTrack();
990 if(pRef!=NULL)
992 SvTreeListEntry* pEntry=pTheView->FirstSelected();
993 while(pEntry!=NULL)
995 ScRedlinData *pEntryData=(ScRedlinData *)(pEntry->GetUserData());
996 if(pEntryData!=NULL)
998 ScChangeAction* pScChangeAction=
999 (ScChangeAction*) pEntryData->pData;
1001 if(pScChangeAction->GetType()==SC_CAT_INSERT_TABS)
1002 pViewData->SetTabNo(0);
1004 pChanges->Reject(pScChangeAction);
1006 pEntry = pTheView->NextSelected(pEntry);
1008 ScDocShell* pDocSh=pViewData->GetDocShell();
1009 pDocSh->PostPaintExtras();
1010 pDocSh->PostPaintGridAll();
1011 pDocSh->GetUndoManager()->Clear();
1012 pDocSh->SetDocumentModified();
1013 ClearView();
1014 UpdateView();
1016 SetPointer(Pointer(POINTER_ARROW));
1018 bIgnoreMsg=false;
1019 return 0;
1021 IMPL_LINK( ScAcceptChgDlg, AcceptHandle, SvxTPView*, pRef )
1023 SetPointer(Pointer(POINTER_WAIT));
1025 ScChangeTrack* pChanges=pDoc->GetChangeTrack();
1026 bIgnoreMsg=true;
1027 if(pRef!=NULL)
1029 SvTreeListEntry* pEntry=pTheView->FirstSelected();
1030 while(pEntry!=NULL)
1032 ScRedlinData *pEntryData=(ScRedlinData *)(pEntry->GetUserData());
1033 if(pEntryData!=NULL)
1035 ScChangeAction* pScChangeAction=
1036 (ScChangeAction*) pEntryData->pData;
1037 if(pScChangeAction->GetType()==SC_CAT_CONTENT)
1039 if(pEntryData->nInfo==RD_SPECIAL_CONTENT)
1040 pChanges->SelectContent(pScChangeAction,true);
1041 else
1042 pChanges->SelectContent(pScChangeAction);
1044 else
1045 pChanges->Accept(pScChangeAction);
1047 pEntry = pTheView->NextSelected(pEntry);
1049 ScDocShell* pDocSh=pViewData->GetDocShell();
1050 pDocSh->PostPaintExtras();
1051 pDocSh->PostPaintGridAll();
1052 pDocSh->SetDocumentModified();
1053 ClearView();
1054 UpdateView();
1056 bIgnoreMsg=false;
1058 return 0;
1061 void ScAcceptChgDlg::RejectFiltered()
1063 if(pDoc==NULL) return;
1064 ScChangeTrack* pChanges=pDoc->GetChangeTrack();
1065 const ScChangeAction* pScChangeAction=NULL;
1067 if(pChanges!=NULL)
1069 pScChangeAction=pChanges->GetLast();
1072 while(pScChangeAction!=NULL)
1074 if(pScChangeAction->IsDialogRoot())
1075 if(IsValidAction(pScChangeAction))
1076 pChanges->Reject((ScChangeAction*)pScChangeAction);
1078 pScChangeAction=pScChangeAction->GetPrev();
1081 void ScAcceptChgDlg::AcceptFiltered()
1083 if(pDoc==NULL) return;
1084 ScChangeTrack* pChanges=pDoc->GetChangeTrack();
1085 const ScChangeAction* pScChangeAction=NULL;
1087 if(pChanges!=NULL)
1088 pScChangeAction=pChanges->GetLast();
1090 while(pScChangeAction!=NULL)
1092 if(pScChangeAction->IsDialogRoot())
1093 if(IsValidAction(pScChangeAction))
1094 pChanges->Accept((ScChangeAction*)pScChangeAction);
1096 pScChangeAction=pScChangeAction->GetPrev();
1100 IMPL_LINK_NOARG(ScAcceptChgDlg, RejectAllHandle)
1102 SetPointer(Pointer(POINTER_WAIT));
1103 bIgnoreMsg=true;
1104 ScChangeTrack* pChanges=pDoc->GetChangeTrack();
1105 if(pChanges!=NULL)
1107 if(pTPFilter->IsDate()||pTPFilter->IsAuthor()||pTPFilter->IsRange()||pTPFilter->IsComment())
1108 RejectFiltered();
1109 else
1110 pChanges->RejectAll();
1112 pViewData->SetTabNo(0);
1114 ScDocShell* pDocSh=pViewData->GetDocShell();
1115 pDocSh->PostPaintExtras();
1116 pDocSh->PostPaintGridAll();
1117 pDocSh->GetUndoManager()->Clear();
1118 pDocSh->SetDocumentModified();
1119 ClearView();
1120 UpdateView();
1122 SetPointer(Pointer(POINTER_ARROW));
1124 bIgnoreMsg=false;
1126 return 0;
1129 IMPL_LINK_NOARG(ScAcceptChgDlg, AcceptAllHandle)
1131 SetPointer(Pointer(POINTER_WAIT));
1133 bIgnoreMsg=true;
1134 ScChangeTrack* pChanges=pDoc->GetChangeTrack();
1135 if(pChanges!=NULL)
1137 if(pTPFilter->IsDate()||pTPFilter->IsAuthor()||pTPFilter->IsRange()||pTPFilter->IsComment())
1138 AcceptFiltered();
1139 else
1140 pChanges->AcceptAll();
1142 ScDocShell* pDocSh=pViewData->GetDocShell();
1143 pDocSh->PostPaintExtras();
1144 pDocSh->PostPaintGridAll();
1145 pDocSh->SetDocumentModified();
1146 ClearView();
1147 UpdateView();
1149 bIgnoreMsg=false;
1150 SetPointer(Pointer(POINTER_ARROW));
1152 return 0;
1155 IMPL_LINK_NOARG(ScAcceptChgDlg, SelectHandle)
1157 if(!bNoSelection)
1158 aSelectionTimer.Start();
1160 bNoSelection=false;
1161 return 0;
1164 void ScAcceptChgDlg::GetDependents( const ScChangeAction* pScChangeAction,
1165 ScChangeActionMap& aActionMap,
1166 SvTreeListEntry* pEntry)
1168 ScChangeTrack* pChanges=pDoc->GetChangeTrack();
1170 SvTreeListEntry* pParent=pTheView->GetParent(pEntry);
1171 if(pParent!=NULL)
1173 ScRedlinData *pParentData=(ScRedlinData *)(pParent->GetUserData());
1174 ScChangeAction* pParentAction=(ScChangeAction*) pParentData->pData;
1176 if(pParentAction!=pScChangeAction)
1177 pChanges->GetDependents((ScChangeAction*) pScChangeAction,
1178 aActionMap,pScChangeAction->IsMasterDelete());
1179 else
1180 pChanges->GetDependents( (ScChangeAction*) pScChangeAction,
1181 aActionMap );
1183 else
1184 pChanges->GetDependents((ScChangeAction*) pScChangeAction,
1185 aActionMap, pScChangeAction->IsMasterDelete() );
1188 bool ScAcceptChgDlg::InsertContentChildren(ScChangeActionMap* pActionMap,SvTreeListEntry* pParent)
1190 bool bTheTestFlag = true;
1191 ScRedlinData *pEntryData=(ScRedlinData *)(pParent->GetUserData());
1192 const ScChangeAction* pScChangeAction = (ScChangeAction*) pEntryData->pData;
1193 bool bParentInserted = false;
1194 // If the parent is a MatrixOrigin then place it in the right order before
1195 // the MatrixReferences. Also if it is the first content change at this
1196 // position don't insert the first dependent MatrixReference as the special
1197 // content (original value) but insert the predecessor of the MatrixOrigin
1198 // itself instead.
1199 if ( pScChangeAction->GetType() == SC_CAT_CONTENT &&
1200 ((const ScChangeActionContent*)pScChangeAction)->IsMatrixOrigin() )
1202 pActionMap->insert( ::std::make_pair( pScChangeAction->GetActionNumber(),
1203 const_cast<ScChangeAction*>( pScChangeAction ) ) );
1204 bParentInserted = true;
1206 SvTreeListEntry* pEntry=NULL;
1208 ScChangeActionMap::iterator itChangeAction = pActionMap->begin();
1209 while( itChangeAction != pActionMap->end() )
1211 if( itChangeAction->second->GetState()==SC_CAS_VIRGIN )
1212 break;
1213 ++itChangeAction;
1216 if( itChangeAction == pActionMap->end() )
1217 return true;
1219 SvTreeListEntry* pOriginal = InsertChangeActionContent(
1220 dynamic_cast<const ScChangeActionContent*>( itChangeAction->second ),
1221 pParent, RD_SPECIAL_CONTENT );
1223 if(pOriginal!=NULL)
1225 bTheTestFlag=false;
1226 ScRedlinData *pParentData=(ScRedlinData *)(pOriginal->GetUserData());
1227 pParentData->pData=(void *)pScChangeAction;
1228 pParentData->nActionNo=pScChangeAction->GetActionNumber();
1229 pParentData->bIsAcceptable=pScChangeAction->IsRejectable(); // select old value
1230 pParentData->bIsRejectable=false;
1231 pParentData->bDisabled=false;
1233 while( itChangeAction != pActionMap->end() )
1235 if( itChangeAction->second->GetState() == SC_CAS_VIRGIN )
1237 pEntry = InsertChangeActionContent( dynamic_cast<const ScChangeActionContent*>( itChangeAction->second ),
1238 pParent, RD_SPECIAL_NONE );
1240 if(pEntry!=NULL)
1241 bTheTestFlag=false;
1243 ++itChangeAction;
1246 if ( !bParentInserted )
1248 pEntry=InsertChangeActionContent((const ScChangeActionContent*)
1249 pScChangeAction,pParent,RD_SPECIAL_NONE);
1251 if(pEntry!=NULL)
1253 bTheTestFlag=false;
1254 ScRedlinData *pParentData=(ScRedlinData *)(pEntry->GetUserData());
1255 pParentData->pData=(void *)pScChangeAction;
1256 pParentData->nActionNo=pScChangeAction->GetActionNumber();
1257 pParentData->bIsAcceptable=pScChangeAction->IsClickable();
1258 pParentData->bIsRejectable=false;
1259 pParentData->bDisabled=false;
1263 return bTheTestFlag;
1267 bool ScAcceptChgDlg::InsertAcceptedORejected(SvTreeListEntry* pParent)
1269 ScChangeTrack* pChanges=pDoc->GetChangeTrack();
1270 bool bTheTestFlag = true;
1272 ScChangeActionState eState = SC_CAS_VIRGIN;
1273 rtl::OUString aString = pTheView->GetEntryText(pParent);
1274 rtl::OUString a2String = aString.copy(0, aStrAllAccepted.getLength());
1275 if (a2String.equals(aStrAllAccepted))
1276 eState=SC_CAS_ACCEPTED;
1277 else
1279 a2String = aString.copy(0, aStrAllRejected.getLength());
1280 if (a2String.equals(aStrAllRejected))
1281 eState=SC_CAS_REJECTED;
1284 ScChangeAction* pScChangeAction=pChanges->GetFirst();
1285 while(pScChangeAction!=NULL)
1287 if(pScChangeAction->GetState()==eState &&
1288 InsertFilteredAction(pScChangeAction,eState,pParent)!=NULL)
1289 bTheTestFlag=false;
1290 pScChangeAction=pScChangeAction->GetNext();
1292 return bTheTestFlag;
1295 bool ScAcceptChgDlg::InsertChildren(ScChangeActionMap* pActionMap,SvTreeListEntry* pParent)
1297 ScChangeTrack* pChanges=pDoc->GetChangeTrack();
1298 bool bTheTestFlag = true;
1299 SvTreeListEntry* pEntry=NULL;
1300 ScChangeActionMap::iterator itChangeAction;
1302 for( itChangeAction = pActionMap->begin(); itChangeAction != pActionMap->end(); ++itChangeAction )
1304 pEntry=InsertChangeAction( itChangeAction->second, SC_CAS_VIRGIN, pParent, false, true );
1306 if(pEntry!=NULL)
1308 bTheTestFlag=false;
1310 ScRedlinData *pEntryData=(ScRedlinData *)(pEntry->GetUserData());
1311 pEntryData->bIsRejectable=false;
1312 pEntryData->bIsAcceptable=false;
1313 pEntryData->bDisabled=true;
1315 if( itChangeAction->second->IsDialogParent() )
1316 Expand( pChanges, itChangeAction->second, pEntry );
1319 return bTheTestFlag;
1322 bool ScAcceptChgDlg::InsertDeletedChildren(const ScChangeAction* pScChangeAction,
1323 ScChangeActionMap* pActionMap,SvTreeListEntry* pParent)
1325 ScChangeTrack* pChanges=pDoc->GetChangeTrack();
1326 bool bTheTestFlag = true;
1327 SvTreeListEntry* pEntry=NULL;
1328 ScChangeActionMap::iterator itChangeAction;
1330 for( itChangeAction = pActionMap->begin(); itChangeAction != pActionMap->end(); ++itChangeAction )
1333 if( pScChangeAction != itChangeAction->second )
1334 pEntry = InsertChangeAction( itChangeAction->second, SC_CAS_VIRGIN, pParent, false, true );
1335 else
1336 pEntry = InsertChangeAction( itChangeAction->second, SC_CAS_VIRGIN, pParent, true, true );
1338 if(pEntry!=NULL)
1340 ScRedlinData *pEntryData=(ScRedlinData *)(pEntry->GetUserData());
1341 pEntryData->bIsRejectable=false;
1342 pEntryData->bIsAcceptable=false;
1343 pEntryData->bDisabled=true;
1345 bTheTestFlag=false;
1347 if( itChangeAction->second->IsDialogParent() )
1348 Expand( pChanges, itChangeAction->second, pEntry );
1351 return bTheTestFlag;
1354 bool ScAcceptChgDlg::Expand(
1355 ScChangeTrack* pChanges, const ScChangeAction* pScChangeAction,
1356 SvTreeListEntry* pEntry, bool bFilter)
1358 bool bTheTestFlag = true;
1360 if(pChanges!=NULL &&pEntry!=NULL &&pScChangeAction!=NULL)
1362 ScChangeActionMap aActionMap;
1364 GetDependents( pScChangeAction, aActionMap, pEntry );
1366 switch(pScChangeAction->GetType())
1368 case SC_CAT_CONTENT:
1370 InsertContentChildren( &aActionMap, pEntry );
1371 bTheTestFlag=!bHasFilterEntry;
1372 break;
1374 case SC_CAT_DELETE_COLS:
1375 case SC_CAT_DELETE_ROWS:
1376 case SC_CAT_DELETE_TABS:
1378 InsertDeletedChildren( pScChangeAction, &aActionMap, pEntry );
1379 bTheTestFlag=!bHasFilterEntry;
1380 break;
1382 default:
1384 if(!bFilter)
1385 bTheTestFlag = InsertChildren( &aActionMap, pEntry );
1386 break;
1389 aActionMap.clear();
1391 return bTheTestFlag;
1394 IMPL_LINK( ScAcceptChgDlg, ExpandingHandle, SvxRedlinTable*, pTable )
1396 ScChangeTrack* pChanges=pDoc->GetChangeTrack();
1397 ScChangeAction* pScChangeAction=NULL;
1398 SetPointer(Pointer(POINTER_WAIT));
1399 if(pTable!=NULL && pChanges!=NULL)
1401 ScChangeActionMap aActionMap;
1402 SvTreeListEntry* pEntry=pTheView->GetHdlEntry();
1403 if(pEntry!=NULL)
1405 ScRedlinData *pEntryData=(ScRedlinData *)(pEntry->GetUserData());
1406 if(pEntryData!=NULL)
1407 pScChangeAction=(ScChangeAction*) pEntryData->pData;
1409 if(pEntry->HasChildrenOnDemand())
1411 bool bTheTestFlag = true;
1412 pEntry->EnableChildrenOnDemand(false);
1413 pTheView->RemoveEntry(pTheView->FirstChild(pEntry));
1415 if(pEntryData!=NULL)
1417 pScChangeAction=(ScChangeAction*) pEntryData->pData;
1419 GetDependents( pScChangeAction, aActionMap, pEntry );
1421 switch(pScChangeAction->GetType())
1423 case SC_CAT_CONTENT:
1425 bTheTestFlag = InsertContentChildren( &aActionMap, pEntry );
1426 break;
1428 case SC_CAT_DELETE_COLS:
1429 case SC_CAT_DELETE_ROWS:
1430 case SC_CAT_DELETE_TABS:
1432 bTheTestFlag = InsertDeletedChildren( pScChangeAction, &aActionMap, pEntry );
1433 break;
1435 default:
1437 bTheTestFlag = InsertChildren( &aActionMap, pEntry );
1438 break;
1441 aActionMap.clear();
1444 else
1446 bTheTestFlag=InsertAcceptedORejected(pEntry);
1448 if(bTheTestFlag) pTheView->InsertEntry(aStrNoEntry,NULL,Color(COL_GRAY),pEntry);
1453 SetPointer(Pointer(POINTER_ARROW));
1454 return (sal_uLong) true;
1458 void ScAcceptChgDlg::AppendChanges(ScChangeTrack* pChanges,sal_uLong nStartAction,
1459 sal_uLong nEndAction, sal_uLong /* nPos */)
1461 if(pChanges!=NULL)
1463 SvTreeListEntry* pParent=NULL;
1464 const ScChangeAction* pScChangeAction=NULL;
1465 bAcceptEnableFlag=true;
1466 bRejectEnableFlag=true;
1467 SetPointer(Pointer(POINTER_WAIT));
1468 pTheView->SetUpdateMode(false);
1470 bool bTheFlag = false;
1472 bool bFilterFlag = pTPFilter->IsDate() || pTPFilter->IsRange() ||
1473 pTPFilter->IsAuthor() || pTPFilter->IsComment();
1475 bUseColor = bFilterFlag;
1477 for(sal_uLong i=nStartAction;i<=nEndAction;i++)
1479 pScChangeAction=pChanges->GetAction(i);
1480 if(pScChangeAction==NULL) continue;
1483 switch(pScChangeAction->GetState())
1485 case SC_CAS_VIRGIN:
1487 if(pScChangeAction->IsDialogRoot())
1489 if(pScChangeAction->IsDialogParent())
1490 pParent=InsertChangeAction(pScChangeAction,SC_CAS_VIRGIN);
1491 else
1492 pParent=InsertFilteredAction(pScChangeAction,SC_CAS_VIRGIN);
1494 else
1495 pParent=NULL;
1497 bTheFlag=true;
1498 break;
1500 case SC_CAS_ACCEPTED:
1501 pParent=NULL;
1502 nAcceptCount++;
1503 break;
1505 case SC_CAS_REJECTED:
1506 pParent=NULL;
1507 nRejectCount++;
1508 break;
1511 if(pParent!=NULL && pScChangeAction->IsDialogParent())
1513 if(!bFilterFlag)
1514 pParent->EnableChildrenOnDemand(true);
1515 else
1517 bool bTestFlag = bHasFilterEntry;
1518 bHasFilterEntry = false;
1519 if(Expand(pChanges,pScChangeAction,pParent,!bTestFlag)&&!bTestFlag)
1520 pTheView->RemoveEntry(pParent);
1524 pScChangeAction=pScChangeAction->GetNext();
1527 if( bTheFlag && (!pDoc->IsDocEditable() || pChanges->IsProtected()) )
1528 bTheFlag=false;
1530 pTPView->EnableAccept(bTheFlag);
1531 pTPView->EnableAcceptAll(bTheFlag);
1532 pTPView->EnableReject(bTheFlag);
1533 pTPView->EnableRejectAll(bTheFlag);
1535 pTheView->SetUpdateMode(true);
1536 SetPointer(Pointer(POINTER_ARROW));
1540 void ScAcceptChgDlg::RemoveEntrys(sal_uLong nStartAction,sal_uLong nEndAction)
1543 pTheView->SetUpdateMode(false);
1545 SvTreeListEntry* pEntry=pTheView->GetCurEntry();
1547 ScRedlinData *pEntryData=NULL;
1549 if(pEntry!=NULL)
1550 pEntryData=(ScRedlinData *)(pEntry->GetUserData());
1552 sal_uLong nAction=0;
1553 if(pEntryData!=NULL)
1554 nAction=pEntryData->nActionNo;
1556 if(nAction>=nStartAction && nAction<=nEndAction)
1557 pTheView->SetCurEntry(pTheView->GetModel()->GetEntry(0));
1559 bool bRemove = false;
1561 // MUST do it backwards, don't delete parents before children and GPF
1562 pEntry=pTheView->Last();
1563 while(pEntry!=NULL)
1565 bRemove=false;
1566 pEntryData=(ScRedlinData *)(pEntry->GetUserData());
1567 if(pEntryData!=NULL)
1569 nAction=pEntryData->nActionNo;
1571 if(nStartAction<=nAction && nAction<=nEndAction) bRemove=true;
1575 SvTreeListEntry* pPrevEntry = pTheView->Prev(pEntry);
1577 if(bRemove)
1578 pTheView->RemoveEntry(pEntry);
1580 pEntry=pPrevEntry;
1582 pTheView->SetUpdateMode(true);
1586 void ScAcceptChgDlg::UpdateEntrys(ScChangeTrack* pChgTrack, sal_uLong nStartAction,sal_uLong nEndAction)
1588 pTheView->SetUpdateMode(false);
1590 sal_uLong nPos=LIST_APPEND;
1592 bool bRemove = false;
1594 SvTreeListEntry* pEntry=pTheView->First();
1595 SvTreeListEntry* pNextEntry = (pEntry ? pTheView->NextSibling(pEntry) : NULL);
1596 SvTreeListEntry* pLastEntry=NULL;
1597 while(pEntry!=NULL)
1599 bRemove=false;
1600 ScRedlinData *pEntryData=(ScRedlinData *)(pEntry->GetUserData());
1601 if(pEntryData!=NULL)
1603 ScChangeAction* pScChangeAction=
1604 (ScChangeAction*) pEntryData->pData;
1606 sal_uLong nAction=pScChangeAction->GetActionNumber();
1608 if(nStartAction<=nAction && nAction<=nEndAction) bRemove=true;
1611 if(bRemove)
1613 nPos=pEntry->GetChildListPos();
1614 pTheView->RemoveEntry(pEntry);
1616 if(pLastEntry==NULL) pLastEntry=pTheView->First();
1617 if(pLastEntry!=NULL)
1619 pNextEntry=pTheView->Next(pLastEntry);
1621 if(pNextEntry==NULL)
1623 pNextEntry=pLastEntry;
1624 pLastEntry=NULL;
1627 else
1628 pNextEntry=NULL;
1631 else
1633 pLastEntry = pEntry;
1634 pNextEntry = pTheView->Next(pEntry);
1636 pEntry=pNextEntry;
1639 if(nStartAction==nEndAction)
1640 AppendChanges(pChgTrack,nStartAction,nEndAction,nPos);
1641 else
1642 AppendChanges(pChgTrack,nStartAction,nEndAction);
1644 pTheView->SetUpdateMode(true);
1648 IMPL_LINK( ScAcceptChgDlg, ChgTrackModHdl, ScChangeTrack*, pChgTrack)
1650 ScChangeTrackMsgQueue::iterator iter;
1651 ScChangeTrackMsgQueue& aMsgQueue= pChgTrack->GetMsgQueue();
1653 sal_uLong nStartAction;
1654 sal_uLong nEndAction;
1656 for (iter = aMsgQueue.begin(); iter != aMsgQueue.end(); ++iter)
1658 nStartAction=(*iter)->nStartAction;
1659 nEndAction=(*iter)->nEndAction;
1661 if(!bIgnoreMsg)
1663 bNoSelection=true;
1665 switch((*iter)->eMsgType)
1667 case SC_CTM_APPEND: AppendChanges(pChgTrack,nStartAction,nEndAction);
1668 break;
1669 case SC_CTM_REMOVE: RemoveEntrys(nStartAction,nEndAction);
1670 break;
1671 case SC_CTM_PARENT:
1672 case SC_CTM_CHANGE: //bNeedsUpdate=true;
1673 UpdateEntrys(pChgTrack,nStartAction,nEndAction);
1674 break;
1675 default:
1677 // added to avoid warnings
1681 delete *iter;
1684 aMsgQueue.clear();
1686 return 0;
1688 IMPL_LINK_NOARG(ScAcceptChgDlg, ReOpenTimerHdl)
1690 ScSimpleRefDlgWrapper::SetAutoReOpen(true);
1691 aAcceptChgCtr.ShowFilterPage();
1692 RefHandle(NULL);
1694 return 0;
1697 IMPL_LINK_NOARG(ScAcceptChgDlg, UpdateSelectionHdl)
1699 ScTabView* pTabView = pViewData->GetView();
1701 bool bAcceptFlag = true;
1702 bool bRejectFlag = true;
1703 bool bContMark = false;
1705 pTabView->DoneBlockMode(); // clears old marking
1706 SvTreeListEntry* pEntry = pTheView->FirstSelected();
1707 while( pEntry )
1709 ScRedlinData* pEntryData = (ScRedlinData*) pEntry->GetUserData();
1710 if( pEntryData )
1712 bRejectFlag &= (bool) pEntryData->bIsRejectable;
1713 bAcceptFlag &= (bool) pEntryData->bIsAcceptable;
1715 const ScChangeAction* pScChangeAction = (ScChangeAction*) pEntryData->pData;
1716 if( pScChangeAction && (pScChangeAction->GetType() != SC_CAT_DELETE_TABS) &&
1717 (!pEntryData->bDisabled || pScChangeAction->IsVisible()) )
1719 const ScBigRange& rBigRange = pScChangeAction->GetBigRange();
1720 if( rBigRange.IsValid( pDoc ) && IsActive() )
1722 bool bSetCursor = !pTheView->NextSelected( pEntry );
1723 pTabView->MarkRange( rBigRange.MakeRange(), bSetCursor, bContMark );
1724 bContMark = true;
1728 else
1730 bAcceptFlag = false;
1731 bRejectFlag = false;
1733 bAcceptEnableFlag = bAcceptFlag;
1734 bRejectEnableFlag = bRejectFlag;
1736 pEntry = pTheView->NextSelected( pEntry );
1739 ScChangeTrack* pChanges = pDoc->GetChangeTrack();
1740 bool bEnable = pDoc->IsDocEditable() && pChanges && !pChanges->IsProtected();
1741 pTPView->EnableAccept( bAcceptFlag && bEnable );
1742 pTPView->EnableReject( bRejectFlag && bEnable );
1744 return 0;
1747 IMPL_LINK_NOARG(ScAcceptChgDlg, CommandHdl)
1750 const CommandEvent aCEvt(pTheView->GetCommandEvent());
1752 if(aCEvt.GetCommand()==COMMAND_CONTEXTMENU)
1754 ScPopupMenu aPopup(ScResId(RID_POPUP_CHANGES));
1756 aPopup.SetMenuFlags(MENU_FLAG_HIDEDISABLEDENTRIES);
1758 SvTreeListEntry* pEntry=pTheView->GetCurEntry();
1759 if(pEntry!=NULL)
1761 pTheView->Select(pEntry);
1763 else
1765 aPopup.Deactivate();
1768 sal_uInt16 nSortedCol= pTheView->GetSortedCol();
1770 if(nSortedCol!=0xFFFF)
1772 sal_uInt16 nItemId=nSortedCol+SC_SUB_SORT+1;
1774 aPopup.CheckItem(nItemId);
1776 PopupMenu *pSubMenu = aPopup.GetPopupMenu(SC_SUB_SORT);
1778 if (pSubMenu)
1779 pSubMenu->CheckItem(nItemId);
1782 aPopup.EnableItem(SC_CHANGES_COMMENT,false);
1784 if(pDoc->IsDocEditable() && pEntry!=NULL)
1786 ScRedlinData *pEntryData=(ScRedlinData *)(pEntry->GetUserData());
1787 if(pEntryData!=NULL)
1789 ScChangeAction* pScChangeAction=
1790 (ScChangeAction*) pEntryData->pData;
1791 if(pScChangeAction!=NULL && !pTheView->GetParent(pEntry))
1792 aPopup.EnableItem(SC_CHANGES_COMMENT);
1796 sal_uInt16 nCommand=aPopup.Execute( this, GetPointerPosPixel() );
1799 if(nCommand)
1801 if(nCommand==SC_CHANGES_COMMENT)
1803 if(pEntry!=NULL)
1805 ScRedlinData *pEntryData=(ScRedlinData *)(pEntry->GetUserData());
1806 if(pEntryData!=NULL)
1808 ScChangeAction* pScChangeAction=
1809 (ScChangeAction*) pEntryData->pData;
1811 pViewData->GetDocShell()->ExecuteChangeCommentDialog( pScChangeAction, this,false);
1815 else
1817 bool bSortDir = pTheView->GetSortDirection();
1818 sal_uInt16 nDialogCol=nCommand-SC_SUB_SORT-1;
1819 if(nSortedCol==nDialogCol) bSortDir=!bSortDir;
1820 pTheView->SortByCol(nDialogCol,bSortDir);
1822 SC_SUB_SORT
1823 SC_SORT_ACTION
1824 SC_SORT_POSITION
1825 SC_SORT_AUTHOR
1826 SC_SORT_DATE
1827 SC_SORT_COMMENT
1832 return 0;
1835 void ScAcceptChgDlg::Initialize(SfxChildWinInfo *pInfo)
1837 String aStr;
1838 if(pInfo!=NULL)
1840 if ( pInfo->aExtraString.Len() )
1842 xub_StrLen nPos = pInfo->aExtraString.Search(
1843 rtl::OUString("AcceptChgDat:"));
1845 // Versuche, den Alignment-String "ALIGN:(...)" einzulesen; wenn
1846 // er nicht vorhanden ist, liegt eine "altere Version vor
1847 if ( nPos != STRING_NOTFOUND )
1849 xub_StrLen n1 = pInfo->aExtraString.Search('(', nPos);
1850 if ( n1 != STRING_NOTFOUND )
1852 xub_StrLen n2 = pInfo->aExtraString.Search(')', n1);
1853 if ( n2 != STRING_NOTFOUND )
1855 // Alignment-String herausschneiden
1856 aStr = pInfo->aExtraString.Copy(nPos, n2 - nPos + 1);
1857 pInfo->aExtraString.Erase(nPos, n2 - nPos + 1);
1858 aStr.Erase(0, n1-nPos+1);
1864 SfxModelessDialog::Initialize(pInfo);
1866 if ( aStr.Len())
1868 sal_uInt16 nCount=(sal_uInt16)aStr.ToInt32();
1870 for(sal_uInt16 i=0;i<nCount;i++)
1872 xub_StrLen n1 = aStr.Search(';');
1873 aStr.Erase(0, n1+1);
1874 pTheView->SetTab(i,(sal_uInt16)aStr.ToInt32(),MAP_PIXEL);
1879 //-------------------------------------------------------------------------
1881 void ScAcceptChgDlg::FillInfo(SfxChildWinInfo& rInfo) const
1883 SfxModelessDialog::FillInfo(rInfo);
1884 rInfo.aExtraString.AppendAscii(RTL_CONSTASCII_STRINGPARAM( "AcceptChgDat:(" ));
1886 sal_uInt16 nCount=pTheView->TabCount();
1888 rInfo.aExtraString += String::CreateFromInt32(nCount);
1889 rInfo.aExtraString += ';';
1890 for(sal_uInt16 i=0;i<nCount;i++)
1892 rInfo.aExtraString += String::CreateFromInt32(pTheView->GetTab(i));
1893 rInfo.aExtraString += ';';
1895 rInfo.aExtraString += ')';
1898 void ScAcceptChgDlg::InitFilter()
1900 if(pTPFilter->IsDate()||pTPFilter->IsRange()||
1901 pTPFilter->IsAuthor()||pTPFilter->IsComment())
1903 pTheView->SetFilterDate(pTPFilter->IsDate());
1904 pTheView->SetDateTimeMode(pTPFilter->GetDateMode());
1905 pTheView->SetFirstDate(pTPFilter->GetFirstDate());
1906 pTheView->SetLastDate(pTPFilter->GetLastDate());
1907 pTheView->SetFirstTime(pTPFilter->GetFirstTime());
1908 pTheView->SetLastTime(pTPFilter->GetLastTime());
1909 pTheView->SetFilterAuthor(pTPFilter->IsAuthor());
1910 pTheView->SetAuthor(pTPFilter->GetSelectedAuthor());
1912 pTheView->SetFilterComment(pTPFilter->IsComment());
1914 utl::SearchParam aSearchParam( pTPFilter->GetComment(),
1915 utl::SearchParam::SRCH_REGEXP,false,false,false );
1917 pTheView->SetCommentParams(&aSearchParam);
1919 pTheView->UpdateFilterTest();
1923 IMPL_LINK_NOARG(ScAcceptChgDlg, FilterModified)
1925 return 0;
1928 #define CALC_DATE 3
1929 #define CALC_POS 1
1931 IMPL_LINK( ScAcceptChgDlg, ColCompareHdl, SvSortData*, pSortData )
1933 StringCompare eCompare=COMPARE_EQUAL;
1934 SCCOL nSortCol= static_cast<SCCOL>(pTheView->GetSortedCol());
1936 if(pSortData)
1938 SvTreeListEntry* pLeft = (SvTreeListEntry*)(pSortData->pLeft );
1939 SvTreeListEntry* pRight = (SvTreeListEntry*)(pSortData->pRight );
1941 if(CALC_DATE==nSortCol)
1943 RedlinData *pLeftData=(RedlinData *)(pLeft->GetUserData());
1944 RedlinData *pRightData=(RedlinData *)(pRight->GetUserData());
1946 if(pLeftData!=NULL && pRightData!=NULL)
1948 if(pLeftData->aDateTime < pRightData->aDateTime)
1949 eCompare=COMPARE_LESS;
1950 else if(pLeftData->aDateTime > pRightData->aDateTime)
1951 eCompare=COMPARE_GREATER;
1953 return eCompare;
1956 else if(CALC_POS==nSortCol)
1958 ScRedlinData *pLeftData=(ScRedlinData *)(pLeft->GetUserData());
1959 ScRedlinData *pRightData=(ScRedlinData *)(pRight->GetUserData());
1961 if(pLeftData!=NULL && pRightData!=NULL)
1963 eCompare=COMPARE_GREATER;
1965 if(pLeftData->nTable < pRightData->nTable)
1966 eCompare=COMPARE_LESS;
1967 else if(pLeftData->nTable == pRightData->nTable)
1969 if(pLeftData->nRow < pRightData->nRow)
1970 eCompare=COMPARE_LESS;
1971 else if(pLeftData->nRow == pRightData->nRow)
1973 if(pLeftData->nCol < pRightData->nCol)
1974 eCompare=COMPARE_LESS;
1975 else if(pLeftData->nCol == pRightData->nCol)
1976 eCompare=COMPARE_EQUAL;
1980 return eCompare;
1984 SvLBoxItem* pLeftItem = pTheView->GetEntryAtPos( pLeft, static_cast<sal_uInt16>(nSortCol));
1985 SvLBoxItem* pRightItem = pTheView->GetEntryAtPos( pRight, static_cast<sal_uInt16>(nSortCol));
1987 if(pLeftItem != NULL && pRightItem != NULL)
1989 sal_uInt16 nLeftKind = pLeftItem->GetType();
1990 sal_uInt16 nRightKind = pRightItem->GetType();
1992 if(nRightKind == SV_ITEM_ID_LBOXSTRING &&
1993 nLeftKind == SV_ITEM_ID_LBOXSTRING )
1995 eCompare= (StringCompare) ScGlobal::GetCaseCollator()->compareString(
1996 ((SvLBoxString*)pLeftItem)->GetText(),
1997 ((SvLBoxString*)pRightItem)->GetText());
1999 if(eCompare==COMPARE_EQUAL) eCompare=COMPARE_LESS;
2005 return eCompare;
2008 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */