bump product version to 4.1.6.2
[LibreOffice.git] / sc / source / ui / miscdlgs / acredlin.cxx
blob7c5f54b8a280b605349360d7ec360c645d4daf8f
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 String aString=aChangeViewSet.GetTheAuthorToShow();
237 if(aString.Len()!=0)
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 String aRefStr;
257 pRangeEntry->Format( aRefStr, ABS_DREF3D, pDoc );
258 pTPFilter->SetRange(aRefStr);
261 InitFilter();
264 void ScAcceptChgDlg::ClearView()
266 nAcceptCount=0;
267 nRejectCount=0;
268 pTheView->SetUpdateMode(false);
270 pTheView->Clear();
271 pTheView->SetUpdateMode(true);
274 OUString* ScAcceptChgDlg::MakeTypeString(ScChangeActionType eType)
276 OUString* pStr;
278 switch(eType)
281 case SC_CAT_INSERT_COLS: pStr=&aStrInsertCols;break;
282 case SC_CAT_INSERT_ROWS: pStr=&aStrInsertRows;break;
283 case SC_CAT_INSERT_TABS: pStr=&aStrInsertTabs;break;
284 case SC_CAT_DELETE_COLS: pStr=&aStrDeleteCols;break;
285 case SC_CAT_DELETE_ROWS: pStr=&aStrDeleteRows;break;
286 case SC_CAT_DELETE_TABS: pStr=&aStrDeleteTabs;break;
287 case SC_CAT_MOVE: pStr=&aStrMove;break;
288 case SC_CAT_CONTENT: pStr=&aStrContent;break;
289 case SC_CAT_REJECT: pStr=&aStrReject;break;
290 default: pStr=&aUnknown;break;
292 return pStr;
296 bool ScAcceptChgDlg::IsValidAction(const ScChangeAction* pScChangeAction)
298 if(pScChangeAction==NULL) return false;
300 bool bFlag = false;
302 ScRange aRef=pScChangeAction->GetBigRange().MakeRange();
303 String aUser=pScChangeAction->GetUser();
304 DateTime aDateTime=pScChangeAction->GetDateTime();
306 ScChangeActionType eType=pScChangeAction->GetType();
307 OUString aDesc;
309 String aComment = comphelper::string::remove(pScChangeAction->GetComment(), '\n');
311 if(eType==SC_CAT_CONTENT)
313 if(!pScChangeAction->IsDialogParent())
314 pScChangeAction->GetDescription(aDesc, pDoc, true);
316 else
317 pScChangeAction->GetDescription(aDesc, pDoc, !pScChangeAction->IsMasterDelete());
319 if (!aDesc.isEmpty())
321 aComment.AppendAscii(RTL_CONSTASCII_STRINGPARAM( " (" ));
322 aComment += String(aDesc);
323 aComment += ')';
326 if(pTheView->IsValidEntry(&aUser,&aDateTime,&aComment))
328 if(pTPFilter->IsRange())
330 for ( size_t i = 0, nRanges = aRangeList.size(); i < nRanges; ++i )
332 ScRange* pRangeEntry = aRangeList[ i ];
333 if (pRangeEntry->Intersects(aRef)) {
334 bFlag = true;
335 break;
339 else
340 bFlag=true;
343 return bFlag;
346 SvTreeListEntry* ScAcceptChgDlg::InsertChangeAction(
347 const ScChangeAction* pScChangeAction, ScChangeActionState /*eState*/,
348 SvTreeListEntry* pParent, bool bDelMaster,bool bDisabled, sal_uLong nPos)
350 ScChangeTrack* pChanges=pDoc->GetChangeTrack();
352 if(pScChangeAction==NULL || pChanges==NULL) return NULL;
354 SvTreeListEntry* pEntry=NULL;
356 bool bFlag = false;
358 ScRange aRef=pScChangeAction->GetBigRange().MakeRange();
359 String aUser=pScChangeAction->GetUser();
360 DateTime aDateTime=pScChangeAction->GetDateTime();
362 OUString aRefStr;
363 ScChangeActionType eType=pScChangeAction->GetType();
364 OUStringBuffer aBuf;
365 OUString aDesc;
367 ScRedlinData* pNewData=new ScRedlinData;
368 pNewData->pData=(void *)pScChangeAction;
369 pNewData->nActionNo=pScChangeAction->GetActionNumber();
370 pNewData->bIsAcceptable=pScChangeAction->IsClickable();
371 pNewData->bIsRejectable=pScChangeAction->IsRejectable();
372 pNewData->bDisabled=!pNewData->bIsAcceptable || bDisabled;
373 pNewData->aDateTime=aDateTime;
374 pNewData->nRow = aRef.aStart.Row();
375 pNewData->nCol = aRef.aStart.Col();
376 pNewData->nTable= aRef.aStart.Tab();
378 if(eType==SC_CAT_CONTENT)
380 if(pScChangeAction->IsDialogParent())
382 aBuf.append(aStrContentWithChild);
383 pNewData->nInfo=RD_SPECIAL_VISCONTENT;
384 pNewData->bIsRejectable=false;
385 pNewData->bIsAcceptable=false;
387 else
389 aBuf.append(*MakeTypeString(eType));
390 pScChangeAction->GetDescription( aDesc, pDoc, true);
393 else
395 aBuf.append(aStrContentWithChild);
397 if(bDelMaster)
399 pScChangeAction->GetDescription( aDesc, pDoc,true);
400 pNewData->bDisabled=true;
401 pNewData->bIsRejectable=false;
403 else
404 pScChangeAction->GetDescription( aDesc, pDoc,!pScChangeAction->IsMasterDelete());
408 pScChangeAction->GetRefString(aRefStr, pDoc, true);
410 aBuf.append(sal_Unicode('\t'));
411 aBuf.append(aRefStr);
412 aBuf.append(sal_Unicode('\t'));
414 bool bIsGenerated = false;
416 if(!pChanges->IsGenerated(pScChangeAction->GetActionNumber()))
418 aBuf.append(aUser);
419 aBuf.append(sal_Unicode('\t'));
420 aBuf.append(ScGlobal::pLocaleData->getDate(aDateTime));
421 aBuf.append(sal_Unicode(' '));
422 aBuf.append(ScGlobal::pLocaleData->getTime(aDateTime));
423 aBuf.append(sal_Unicode('\t'));
425 bIsGenerated = false;
427 else
429 aBuf.append(sal_Unicode('\t'));
430 aBuf.append(sal_Unicode('\t'));
431 bIsGenerated = true;
434 String aComment = comphelper::string::remove(pScChangeAction->GetComment(), '\n');
436 if (!aDesc.isEmpty())
438 aComment.AppendAscii(RTL_CONSTASCII_STRINGPARAM( " (" ));
439 aComment += String(aDesc);
440 aComment += ')';
443 aBuf.append(aComment);
445 if(pTheView->IsValidEntry(&aUser,&aDateTime)|| bIsGenerated)
447 if(pTheView->IsValidComment(&aComment))
449 if(pTPFilter->IsRange())
451 for ( size_t i = 0, nRanges = aRangeList.size(); i < nRanges; ++i )
453 ScRange* pRangeEntry = aRangeList[ i ];
454 if( pRangeEntry->Intersects(aRef) )
456 bHasFilterEntry=true;
457 bFlag=true;
458 break;
462 else if(!bIsGenerated)
464 bHasFilterEntry=true;
465 bFlag=true;
470 if(!bFlag&& bUseColor&& pParent==NULL)
472 pEntry = pTheView->InsertEntry(
473 aBuf.makeStringAndClear() ,pNewData, Color(COL_LIGHTBLUE), pParent, nPos);
475 else if(bFlag&& bUseColor&& pParent!=NULL)
477 pEntry = pTheView->InsertEntry(
478 aBuf.makeStringAndClear(), pNewData, Color(COL_GREEN), pParent, nPos);
479 SvTreeListEntry* pExpEntry=pParent;
481 while(pExpEntry!=NULL && !pTheView->IsExpanded(pExpEntry))
483 SvTreeListEntry* pTmpEntry=pTheView->GetParent(pExpEntry);
485 if(pTmpEntry!=NULL) pTheView->Expand(pExpEntry);
487 pExpEntry=pTmpEntry;
490 else
492 pEntry = pTheView->InsertEntry(
493 aBuf.makeStringAndClear(), pNewData, pParent, nPos);
495 return pEntry;
498 SvTreeListEntry* ScAcceptChgDlg::InsertFilteredAction(
499 const ScChangeAction* pScChangeAction, ScChangeActionState eState,
500 SvTreeListEntry* pParent, bool bDelMaster, bool bDisabled, sal_uLong nPos)
503 ScChangeTrack* pChanges=pDoc->GetChangeTrack();
505 if(pScChangeAction==NULL || pChanges==NULL) return NULL;
507 bool bIsGenerated = pChanges->IsGenerated(pScChangeAction->GetActionNumber());
509 SvTreeListEntry* pEntry=NULL;
511 bool bFlag = false;
513 ScRange aRef=pScChangeAction->GetBigRange().MakeRange();
514 String aUser=pScChangeAction->GetUser();
515 DateTime aDateTime=pScChangeAction->GetDateTime();
517 if(pTheView->IsValidEntry(&aUser,&aDateTime)||bIsGenerated)
519 if(pTPFilter->IsRange())
521 for ( size_t i = 0, nRanges = aRangeList.size(); i < nRanges; ++i )
523 ScRange* pRangeEntry=aRangeList[ i ];
524 if( pRangeEntry->Intersects(aRef) )
526 if( pScChangeAction->GetState()==eState )
527 bFlag = true;
528 break;
532 else if(pScChangeAction->GetState()==eState && !bIsGenerated)
533 bFlag = true;
536 if(bFlag)
539 OUString aRefStr;
540 ScChangeActionType eType=pScChangeAction->GetType();
541 String aString;
542 OUString aDesc;
544 ScRedlinData* pNewData=new ScRedlinData;
545 pNewData->pData=(void *)pScChangeAction;
546 pNewData->nActionNo=pScChangeAction->GetActionNumber();
547 pNewData->bIsAcceptable=pScChangeAction->IsClickable();
548 pNewData->bIsRejectable=pScChangeAction->IsRejectable();
549 pNewData->bDisabled=!pNewData->bIsAcceptable || bDisabled;
550 pNewData->aDateTime=aDateTime;
551 pNewData->nRow = aRef.aStart.Row();
552 pNewData->nCol = aRef.aStart.Col();
553 pNewData->nTable= aRef.aStart.Tab();
555 if(eType==SC_CAT_CONTENT)
557 if(pScChangeAction->IsDialogParent())
559 aString=aStrContentWithChild;
560 pNewData->nInfo=RD_SPECIAL_VISCONTENT;
561 pNewData->bIsRejectable=false;
562 pNewData->bIsAcceptable=false;
564 else
566 aString=*MakeTypeString(eType);
567 pScChangeAction->GetDescription( aDesc, pDoc, true);
570 else
572 aString=*MakeTypeString(eType);
574 if(bDelMaster)
576 pScChangeAction->GetDescription( aDesc, pDoc,true);
577 pNewData->bDisabled=true;
578 pNewData->bIsRejectable=false;
580 else
581 pScChangeAction->GetDescription( aDesc, pDoc,!pScChangeAction->IsMasterDelete());
585 aString+='\t';
586 pScChangeAction->GetRefString(aRefStr, pDoc, true);
587 aString+=aRefStr;
588 aString+='\t';
590 if(!bIsGenerated)
592 aString+=aUser;
593 aString+='\t';
594 aString+=ScGlobal::pLocaleData->getDate(aDateTime);
595 aString+=' ';
596 aString+=ScGlobal::pLocaleData->getTime(aDateTime);
597 aString+='\t';
599 else
601 aString+='\t';
602 aString+='\t';
605 String aComment = comphelper::string::remove(pScChangeAction->GetComment(), '\n');
607 if (!aDesc.isEmpty())
609 aComment.AppendAscii(RTL_CONSTASCII_STRINGPARAM( " (" ));
610 aComment += String(aDesc);
611 aComment += ')';
613 if(pTheView->IsValidComment(&aComment))
615 aString+=aComment;
616 pEntry=pTheView->InsertEntry(aString,pNewData,pParent,nPos);
618 else
619 delete pNewData;
621 return pEntry;
624 SvTreeListEntry* ScAcceptChgDlg::InsertChangeActionContent(const ScChangeActionContent* pScChangeAction,
625 SvTreeListEntry* pParent, sal_uLong nSpecial)
627 ScChangeTrack* pChanges=pDoc->GetChangeTrack();
628 SvTreeListEntry* pEntry=NULL;
630 if(pScChangeAction==NULL || pChanges==NULL) return NULL;
632 bool bIsGenerated = pChanges->IsGenerated(pScChangeAction->GetActionNumber());
634 bool bFlag = false;
636 ScRange aRef=pScChangeAction->GetBigRange().MakeRange();
637 String aUser=pScChangeAction->GetUser();
638 DateTime aDateTime=pScChangeAction->GetDateTime();
640 if(pTheView->IsValidEntry(&aUser,&aDateTime)||bIsGenerated)
642 if(pTPFilter->IsRange())
644 for ( size_t i = 0, nRanges = aRangeList.size(); i < nRanges; ++i )
646 ScRange* pRangeEntry = aRangeList[ i ];
647 if( pRangeEntry->Intersects(aRef) )
649 bFlag=true;
650 break;
654 else if(!bIsGenerated)
655 bFlag=true;
658 OUString aRefStr;
659 String aString;
660 String a2String;
661 String aDesc;
663 if(nSpecial==RD_SPECIAL_CONTENT)
665 OUString aTmp;
666 pScChangeAction->GetOldString(aTmp, pDoc);
667 a2String = aTmp;
668 if(a2String.Len()==0) a2String=aStrEmpty;
670 //aString+="\'";
671 aString+=a2String;
672 //aString+="\'";
674 aDesc=aStrChildOrgContent;
675 aDesc.AppendAscii(RTL_CONSTASCII_STRINGPARAM( ": " ));
677 else
679 OUString aTmp;
680 pScChangeAction->GetNewString(aTmp, pDoc);
681 a2String = aTmp;
682 if(a2String.Len()==0)
684 a2String=aStrEmpty;
685 aString+=a2String;
687 else
689 aString+='\'';
690 aString+=a2String;
691 aString+='\'';
692 a2String=aString;
694 aDesc=aStrChildContent;
698 aDesc+=a2String;
699 aString+='\t';
700 pScChangeAction->GetRefString(aRefStr, pDoc, true);
701 aString+=aRefStr;
702 aString+='\t';
704 if(!bIsGenerated)
706 aString+=aUser;
707 aString+='\t';
709 aString+=ScGlobal::pLocaleData->getDate(aDateTime);
710 aString+=' ';
711 aString+=ScGlobal::pLocaleData->getTime(aDateTime);
712 aString+='\t';
714 else
716 aString+='\t';
717 aString+='\t';
720 String aComment = comphelper::string::remove(pScChangeAction->GetComment(), '\n');
722 if(aDesc.Len()>0)
724 aComment.AppendAscii(RTL_CONSTASCII_STRINGPARAM( " (" ));
725 aComment+=aDesc;
726 aComment+=')';
729 aString+=aComment;
731 ScRedlinData* pNewData=new ScRedlinData;
732 pNewData->nInfo=nSpecial;
733 pNewData->pData=(void *)pScChangeAction;
734 pNewData->nActionNo=pScChangeAction->GetActionNumber();
735 pNewData->bIsAcceptable=pScChangeAction->IsClickable();
736 pNewData->bIsRejectable=false;
737 pNewData->bDisabled=!pNewData->bIsAcceptable;
738 pNewData->aDateTime=aDateTime;
739 pNewData->nRow = aRef.aStart.Row();
740 pNewData->nCol = aRef.aStart.Col();
741 pNewData->nTable= aRef.aStart.Tab();
743 if(pTheView->IsValidComment(&aComment) && bFlag)
745 bHasFilterEntry=true;
746 pEntry=pTheView->InsertEntry(aString,pNewData,pParent);
748 else
749 pEntry=pTheView->InsertEntry(aString,pNewData,Color(COL_LIGHTBLUE),pParent);
750 return pEntry;
753 long ScAcceptChgDlg::PreNotify( NotifyEvent& rNEvt )
755 if(rNEvt.GetType()==EVENT_GETFOCUS && bNeedsUpdate)
757 ClearView();
758 UpdateView();
759 bNoSelection=false;
762 return SfxModelessDialog::PreNotify(rNEvt);
766 void ScAcceptChgDlg::UpdateView()
768 bNeedsUpdate=false;
769 SvTreeListEntry* pParent=NULL;
770 ScChangeTrack* pChanges=NULL;
771 const ScChangeAction* pScChangeAction=NULL;
772 bAcceptEnableFlag=true;
773 bRejectEnableFlag=true;
774 SetPointer(Pointer(POINTER_WAIT));
775 pTheView->SetUpdateMode(false);
776 bool bFilterFlag = pTPFilter->IsDate() || pTPFilter->IsRange() ||
777 pTPFilter->IsAuthor() || pTPFilter->IsComment();
779 bUseColor = bFilterFlag;
781 if(pDoc!=NULL)
783 pChanges=pDoc->GetChangeTrack();
784 if(pChanges!=NULL)
785 pScChangeAction=pChanges->GetFirst();
787 bool bTheFlag = false;
789 while(pScChangeAction!=NULL)
791 bHasFilterEntry=false;
792 switch(pScChangeAction->GetState())
794 case SC_CAS_VIRGIN:
796 if(pScChangeAction->IsDialogRoot())
798 if(pScChangeAction->IsDialogParent())
799 pParent=InsertChangeAction(pScChangeAction,SC_CAS_VIRGIN);
800 else
801 pParent=InsertFilteredAction(pScChangeAction,SC_CAS_VIRGIN);
803 else
804 pParent=NULL;
806 bTheFlag=true;
807 break;
809 case SC_CAS_ACCEPTED:
810 pParent=NULL;
811 nAcceptCount++;
812 break;
814 case SC_CAS_REJECTED:
815 pParent=NULL;
816 nRejectCount++;
817 break;
820 if(pParent!=NULL && pScChangeAction->IsDialogParent())
822 if(!bFilterFlag)
823 pParent->EnableChildrenOnDemand(true);
824 else
826 bool bTestFlag = bHasFilterEntry;
827 bHasFilterEntry=false;
828 if(Expand(pChanges,pScChangeAction,pParent,!bTestFlag)&&!bTestFlag)
829 pTheView->RemoveEntry(pParent);
833 pScChangeAction=pScChangeAction->GetNext();
836 if( bTheFlag && (!pDoc->IsDocEditable() || pChanges->IsProtected()) )
837 bTheFlag=false;
839 pTPView->EnableAccept(bTheFlag);
840 pTPView->EnableAcceptAll(bTheFlag);
841 pTPView->EnableReject(bTheFlag);
842 pTPView->EnableRejectAll(bTheFlag);
844 if(nAcceptCount>0)
846 pParent=pTheView->InsertEntry(
847 aStrAllAccepted, static_cast< RedlinData * >(NULL),
848 static_cast< SvTreeListEntry * >(NULL));
849 pParent->EnableChildrenOnDemand(true);
851 if(nRejectCount>0)
853 pParent=pTheView->InsertEntry(
854 aStrAllRejected, static_cast< RedlinData * >(NULL),
855 static_cast< SvTreeListEntry * >(NULL));
856 pParent->EnableChildrenOnDemand(true);
858 pTheView->SetUpdateMode(true);
859 SetPointer(Pointer(POINTER_ARROW));
860 SvTreeListEntry* pEntry=pTheView->First();
861 if(pEntry!=NULL)
862 pTheView->Select(pEntry);
865 IMPL_LINK_NOARG(ScAcceptChgDlg, RefHandle)
867 sal_uInt16 nId =ScSimpleRefDlgWrapper::GetChildWindowId();
869 ScSimpleRefDlgWrapper::SetDefaultPosSize(GetPosPixel(),GetSizePixel(),true);
871 SC_MOD()->SetRefDialog( nId, true );
873 SfxViewFrame* pViewFrm = pViewData->GetViewShell()->GetViewFrame();
874 ScSimpleRefDlgWrapper* pWnd =(ScSimpleRefDlgWrapper*)pViewFrm->GetChildWindow( nId );
876 if(pWnd!=NULL)
878 sal_uInt16 nAcceptId=ScAcceptChgDlgWrapper::GetChildWindowId();
879 pViewFrm->ShowChildWindow(nAcceptId,false);
880 pWnd->SetCloseHdl(LINK( this, ScAcceptChgDlg,RefInfoHandle));
881 pWnd->SetRefString(pTPFilter->GetRange());
882 pWnd->SetAutoReOpen(false);
883 Window* pWin=pWnd->GetWindow();
884 pWin->SetPosSizePixel(GetPosPixel(),GetSizePixel());
885 Hide();
886 pWin->SetText(GetText());
887 pWnd->StartRefInput();
889 return 0;
892 IMPL_LINK( ScAcceptChgDlg, RefInfoHandle, String*, pResult)
894 sal_uInt16 nId;
896 ScSimpleRefDlgWrapper::SetAutoReOpen(true);
898 SfxViewFrame* pViewFrm = pViewData->GetViewShell()->GetViewFrame();
899 if(pResult!=NULL)
901 pTPFilter->SetRange(*pResult);
902 FilterHandle(pTPFilter);
904 nId = ScSimpleRefDlgWrapper::GetChildWindowId();
905 ScSimpleRefDlgWrapper* pWnd = (ScSimpleRefDlgWrapper*)pViewFrm->GetChildWindow( nId );
907 if(pWnd!=NULL)
909 Window* pWin=pWnd->GetWindow();
910 Size aWinSize=pWin->GetSizePixel();
911 aWinSize.Width()=GetSizePixel().Width();
912 SetPosSizePixel(pWin->GetPosPixel(),aWinSize);
913 Invalidate();
915 nId = ScAcceptChgDlgWrapper::GetChildWindowId();
916 pViewFrm->ShowChildWindow( nId, true );
918 else
920 nId = ScAcceptChgDlgWrapper::GetChildWindowId();
921 pViewFrm->SetChildWindow( nId, false );
923 return 0;
926 IMPL_LINK( ScAcceptChgDlg, FilterHandle, SvxTPFilter*, pRef )
928 if(pRef!=NULL)
930 ClearView();
931 aRangeList.RemoveAll();
932 aRangeList.Parse(pTPFilter->GetRange(),pDoc);
933 UpdateView();
935 return 0;
938 IMPL_LINK( ScAcceptChgDlg, RejectHandle, SvxTPView*, pRef )
940 SetPointer(Pointer(POINTER_WAIT));
942 bIgnoreMsg=true;
943 ScChangeTrack* pChanges=pDoc->GetChangeTrack();
945 if(pRef!=NULL)
947 SvTreeListEntry* pEntry=pTheView->FirstSelected();
948 while(pEntry!=NULL)
950 ScRedlinData *pEntryData=(ScRedlinData *)(pEntry->GetUserData());
951 if(pEntryData!=NULL)
953 ScChangeAction* pScChangeAction=
954 (ScChangeAction*) pEntryData->pData;
956 if(pScChangeAction->GetType()==SC_CAT_INSERT_TABS)
957 pViewData->SetTabNo(0);
959 pChanges->Reject(pScChangeAction);
961 pEntry = pTheView->NextSelected(pEntry);
963 ScDocShell* pDocSh=pViewData->GetDocShell();
964 pDocSh->PostPaintExtras();
965 pDocSh->PostPaintGridAll();
966 pDocSh->GetUndoManager()->Clear();
967 pDocSh->SetDocumentModified();
968 ClearView();
969 UpdateView();
971 SetPointer(Pointer(POINTER_ARROW));
973 bIgnoreMsg=false;
974 return 0;
976 IMPL_LINK( ScAcceptChgDlg, AcceptHandle, SvxTPView*, pRef )
978 SetPointer(Pointer(POINTER_WAIT));
980 ScChangeTrack* pChanges=pDoc->GetChangeTrack();
981 bIgnoreMsg=true;
982 if(pRef!=NULL)
984 SvTreeListEntry* pEntry=pTheView->FirstSelected();
985 while(pEntry!=NULL)
987 ScRedlinData *pEntryData=(ScRedlinData *)(pEntry->GetUserData());
988 if(pEntryData!=NULL)
990 ScChangeAction* pScChangeAction=
991 (ScChangeAction*) pEntryData->pData;
992 if(pScChangeAction->GetType()==SC_CAT_CONTENT)
994 if(pEntryData->nInfo==RD_SPECIAL_CONTENT)
995 pChanges->SelectContent(pScChangeAction,true);
996 else
997 pChanges->SelectContent(pScChangeAction);
999 else
1000 pChanges->Accept(pScChangeAction);
1002 pEntry = pTheView->NextSelected(pEntry);
1004 ScDocShell* pDocSh=pViewData->GetDocShell();
1005 pDocSh->PostPaintExtras();
1006 pDocSh->PostPaintGridAll();
1007 pDocSh->SetDocumentModified();
1008 ClearView();
1009 UpdateView();
1011 bIgnoreMsg=false;
1013 return 0;
1016 void ScAcceptChgDlg::RejectFiltered()
1018 if(pDoc==NULL) return;
1019 ScChangeTrack* pChanges=pDoc->GetChangeTrack();
1020 const ScChangeAction* pScChangeAction=NULL;
1022 if(pChanges!=NULL)
1024 pScChangeAction=pChanges->GetLast();
1027 while(pScChangeAction!=NULL)
1029 if(pScChangeAction->IsDialogRoot())
1030 if(IsValidAction(pScChangeAction))
1031 pChanges->Reject((ScChangeAction*)pScChangeAction);
1033 pScChangeAction=pScChangeAction->GetPrev();
1036 void ScAcceptChgDlg::AcceptFiltered()
1038 if(pDoc==NULL) return;
1039 ScChangeTrack* pChanges=pDoc->GetChangeTrack();
1040 const ScChangeAction* pScChangeAction=NULL;
1042 if(pChanges!=NULL)
1043 pScChangeAction=pChanges->GetLast();
1045 while(pScChangeAction!=NULL)
1047 if(pScChangeAction->IsDialogRoot())
1048 if(IsValidAction(pScChangeAction))
1049 pChanges->Accept((ScChangeAction*)pScChangeAction);
1051 pScChangeAction=pScChangeAction->GetPrev();
1055 IMPL_LINK_NOARG(ScAcceptChgDlg, RejectAllHandle)
1057 SetPointer(Pointer(POINTER_WAIT));
1058 bIgnoreMsg=true;
1059 ScChangeTrack* pChanges=pDoc->GetChangeTrack();
1060 if(pChanges!=NULL)
1062 if(pTPFilter->IsDate()||pTPFilter->IsAuthor()||pTPFilter->IsRange()||pTPFilter->IsComment())
1063 RejectFiltered();
1064 else
1065 pChanges->RejectAll();
1067 pViewData->SetTabNo(0);
1069 ScDocShell* pDocSh=pViewData->GetDocShell();
1070 pDocSh->PostPaintExtras();
1071 pDocSh->PostPaintGridAll();
1072 pDocSh->GetUndoManager()->Clear();
1073 pDocSh->SetDocumentModified();
1074 ClearView();
1075 UpdateView();
1077 SetPointer(Pointer(POINTER_ARROW));
1079 bIgnoreMsg=false;
1081 return 0;
1084 IMPL_LINK_NOARG(ScAcceptChgDlg, AcceptAllHandle)
1086 SetPointer(Pointer(POINTER_WAIT));
1088 bIgnoreMsg=true;
1089 ScChangeTrack* pChanges=pDoc->GetChangeTrack();
1090 if(pChanges!=NULL)
1092 if(pTPFilter->IsDate()||pTPFilter->IsAuthor()||pTPFilter->IsRange()||pTPFilter->IsComment())
1093 AcceptFiltered();
1094 else
1095 pChanges->AcceptAll();
1097 ScDocShell* pDocSh=pViewData->GetDocShell();
1098 pDocSh->PostPaintExtras();
1099 pDocSh->PostPaintGridAll();
1100 pDocSh->SetDocumentModified();
1101 ClearView();
1102 UpdateView();
1104 bIgnoreMsg=false;
1105 SetPointer(Pointer(POINTER_ARROW));
1107 return 0;
1110 IMPL_LINK_NOARG(ScAcceptChgDlg, SelectHandle)
1112 if(!bNoSelection)
1113 aSelectionTimer.Start();
1115 bNoSelection=false;
1116 return 0;
1119 void ScAcceptChgDlg::GetDependents( const ScChangeAction* pScChangeAction,
1120 ScChangeActionMap& aActionMap,
1121 SvTreeListEntry* pEntry)
1123 ScChangeTrack* pChanges=pDoc->GetChangeTrack();
1125 SvTreeListEntry* pParent=pTheView->GetParent(pEntry);
1126 if(pParent!=NULL)
1128 ScRedlinData *pParentData=(ScRedlinData *)(pParent->GetUserData());
1129 ScChangeAction* pParentAction=(ScChangeAction*) pParentData->pData;
1131 if(pParentAction!=pScChangeAction)
1132 pChanges->GetDependents((ScChangeAction*) pScChangeAction,
1133 aActionMap,pScChangeAction->IsMasterDelete());
1134 else
1135 pChanges->GetDependents( (ScChangeAction*) pScChangeAction,
1136 aActionMap );
1138 else
1139 pChanges->GetDependents((ScChangeAction*) pScChangeAction,
1140 aActionMap, pScChangeAction->IsMasterDelete() );
1143 bool ScAcceptChgDlg::InsertContentChildren(ScChangeActionMap* pActionMap,SvTreeListEntry* pParent)
1145 bool bTheTestFlag = true;
1146 ScRedlinData *pEntryData=(ScRedlinData *)(pParent->GetUserData());
1147 const ScChangeAction* pScChangeAction = (ScChangeAction*) pEntryData->pData;
1148 bool bParentInserted = false;
1149 // If the parent is a MatrixOrigin then place it in the right order before
1150 // the MatrixReferences. Also if it is the first content change at this
1151 // position don't insert the first dependent MatrixReference as the special
1152 // content (original value) but insert the predecessor of the MatrixOrigin
1153 // itself instead.
1154 if ( pScChangeAction->GetType() == SC_CAT_CONTENT &&
1155 ((const ScChangeActionContent*)pScChangeAction)->IsMatrixOrigin() )
1157 pActionMap->insert( ::std::make_pair( pScChangeAction->GetActionNumber(),
1158 const_cast<ScChangeAction*>( pScChangeAction ) ) );
1159 bParentInserted = true;
1161 SvTreeListEntry* pEntry=NULL;
1163 ScChangeActionMap::iterator itChangeAction = pActionMap->begin();
1164 while( itChangeAction != pActionMap->end() )
1166 if( itChangeAction->second->GetState()==SC_CAS_VIRGIN )
1167 break;
1168 ++itChangeAction;
1171 if( itChangeAction == pActionMap->end() )
1172 return true;
1174 SvTreeListEntry* pOriginal = InsertChangeActionContent(
1175 dynamic_cast<const ScChangeActionContent*>( itChangeAction->second ),
1176 pParent, RD_SPECIAL_CONTENT );
1178 if(pOriginal!=NULL)
1180 bTheTestFlag=false;
1181 ScRedlinData *pParentData=(ScRedlinData *)(pOriginal->GetUserData());
1182 pParentData->pData=(void *)pScChangeAction;
1183 pParentData->nActionNo=pScChangeAction->GetActionNumber();
1184 pParentData->bIsAcceptable=pScChangeAction->IsRejectable(); // select old value
1185 pParentData->bIsRejectable=false;
1186 pParentData->bDisabled=false;
1188 while( itChangeAction != pActionMap->end() )
1190 if( itChangeAction->second->GetState() == SC_CAS_VIRGIN )
1192 pEntry = InsertChangeActionContent( dynamic_cast<const ScChangeActionContent*>( itChangeAction->second ),
1193 pParent, RD_SPECIAL_NONE );
1195 if(pEntry!=NULL)
1196 bTheTestFlag=false;
1198 ++itChangeAction;
1201 if ( !bParentInserted )
1203 pEntry=InsertChangeActionContent((const ScChangeActionContent*)
1204 pScChangeAction,pParent,RD_SPECIAL_NONE);
1206 if(pEntry!=NULL)
1208 bTheTestFlag=false;
1209 ScRedlinData *pParentData=(ScRedlinData *)(pEntry->GetUserData());
1210 pParentData->pData=(void *)pScChangeAction;
1211 pParentData->nActionNo=pScChangeAction->GetActionNumber();
1212 pParentData->bIsAcceptable=pScChangeAction->IsClickable();
1213 pParentData->bIsRejectable=false;
1214 pParentData->bDisabled=false;
1218 return bTheTestFlag;
1222 bool ScAcceptChgDlg::InsertAcceptedORejected(SvTreeListEntry* pParent)
1224 ScChangeTrack* pChanges=pDoc->GetChangeTrack();
1225 bool bTheTestFlag = true;
1227 ScChangeActionState eState = SC_CAS_VIRGIN;
1228 OUString aString = pTheView->GetEntryText(pParent);
1229 OUString a2String = aString.copy(0, aStrAllAccepted.getLength());
1230 if (a2String.equals(aStrAllAccepted))
1231 eState=SC_CAS_ACCEPTED;
1232 else
1234 a2String = aString.copy(0, aStrAllRejected.getLength());
1235 if (a2String.equals(aStrAllRejected))
1236 eState=SC_CAS_REJECTED;
1239 ScChangeAction* pScChangeAction=pChanges->GetFirst();
1240 while(pScChangeAction!=NULL)
1242 if(pScChangeAction->GetState()==eState &&
1243 InsertFilteredAction(pScChangeAction,eState,pParent)!=NULL)
1244 bTheTestFlag=false;
1245 pScChangeAction=pScChangeAction->GetNext();
1247 return bTheTestFlag;
1250 bool ScAcceptChgDlg::InsertChildren(ScChangeActionMap* pActionMap,SvTreeListEntry* pParent)
1252 ScChangeTrack* pChanges=pDoc->GetChangeTrack();
1253 bool bTheTestFlag = true;
1254 SvTreeListEntry* pEntry=NULL;
1255 ScChangeActionMap::iterator itChangeAction;
1257 for( itChangeAction = pActionMap->begin(); itChangeAction != pActionMap->end(); ++itChangeAction )
1259 pEntry=InsertChangeAction( itChangeAction->second, SC_CAS_VIRGIN, pParent, false, true );
1261 if(pEntry!=NULL)
1263 bTheTestFlag=false;
1265 ScRedlinData *pEntryData=(ScRedlinData *)(pEntry->GetUserData());
1266 pEntryData->bIsRejectable=false;
1267 pEntryData->bIsAcceptable=false;
1268 pEntryData->bDisabled=true;
1270 if( itChangeAction->second->IsDialogParent() )
1271 Expand( pChanges, itChangeAction->second, pEntry );
1274 return bTheTestFlag;
1277 bool ScAcceptChgDlg::InsertDeletedChildren(const ScChangeAction* pScChangeAction,
1278 ScChangeActionMap* pActionMap,SvTreeListEntry* pParent)
1280 ScChangeTrack* pChanges=pDoc->GetChangeTrack();
1281 bool bTheTestFlag = true;
1282 SvTreeListEntry* pEntry=NULL;
1283 ScChangeActionMap::iterator itChangeAction;
1285 for( itChangeAction = pActionMap->begin(); itChangeAction != pActionMap->end(); ++itChangeAction )
1288 if( pScChangeAction != itChangeAction->second )
1289 pEntry = InsertChangeAction( itChangeAction->second, SC_CAS_VIRGIN, pParent, false, true );
1290 else
1291 pEntry = InsertChangeAction( itChangeAction->second, SC_CAS_VIRGIN, pParent, true, true );
1293 if(pEntry!=NULL)
1295 ScRedlinData *pEntryData=(ScRedlinData *)(pEntry->GetUserData());
1296 pEntryData->bIsRejectable=false;
1297 pEntryData->bIsAcceptable=false;
1298 pEntryData->bDisabled=true;
1300 bTheTestFlag=false;
1302 if( itChangeAction->second->IsDialogParent() )
1303 Expand( pChanges, itChangeAction->second, pEntry );
1306 return bTheTestFlag;
1309 bool ScAcceptChgDlg::Expand(
1310 ScChangeTrack* pChanges, const ScChangeAction* pScChangeAction,
1311 SvTreeListEntry* pEntry, bool bFilter)
1313 bool bTheTestFlag = true;
1315 if(pChanges!=NULL &&pEntry!=NULL &&pScChangeAction!=NULL)
1317 ScChangeActionMap aActionMap;
1319 GetDependents( pScChangeAction, aActionMap, pEntry );
1321 switch(pScChangeAction->GetType())
1323 case SC_CAT_CONTENT:
1325 InsertContentChildren( &aActionMap, pEntry );
1326 bTheTestFlag=!bHasFilterEntry;
1327 break;
1329 case SC_CAT_DELETE_COLS:
1330 case SC_CAT_DELETE_ROWS:
1331 case SC_CAT_DELETE_TABS:
1333 InsertDeletedChildren( pScChangeAction, &aActionMap, pEntry );
1334 bTheTestFlag=!bHasFilterEntry;
1335 break;
1337 default:
1339 if(!bFilter)
1340 bTheTestFlag = InsertChildren( &aActionMap, pEntry );
1341 break;
1344 aActionMap.clear();
1346 return bTheTestFlag;
1349 IMPL_LINK( ScAcceptChgDlg, ExpandingHandle, SvxRedlinTable*, pTable )
1351 ScChangeTrack* pChanges=pDoc->GetChangeTrack();
1352 ScChangeAction* pScChangeAction=NULL;
1353 SetPointer(Pointer(POINTER_WAIT));
1354 if(pTable!=NULL && pChanges!=NULL)
1356 ScChangeActionMap aActionMap;
1357 SvTreeListEntry* pEntry=pTheView->GetHdlEntry();
1358 if(pEntry!=NULL)
1360 ScRedlinData *pEntryData=(ScRedlinData *)(pEntry->GetUserData());
1361 if(pEntryData!=NULL)
1362 pScChangeAction=(ScChangeAction*) pEntryData->pData;
1364 if(pEntry->HasChildrenOnDemand())
1366 bool bTheTestFlag = true;
1367 pEntry->EnableChildrenOnDemand(false);
1368 pTheView->RemoveEntry(pTheView->FirstChild(pEntry));
1370 if(pEntryData!=NULL)
1372 pScChangeAction=(ScChangeAction*) pEntryData->pData;
1374 GetDependents( pScChangeAction, aActionMap, pEntry );
1376 switch(pScChangeAction->GetType())
1378 case SC_CAT_CONTENT:
1380 bTheTestFlag = InsertContentChildren( &aActionMap, pEntry );
1381 break;
1383 case SC_CAT_DELETE_COLS:
1384 case SC_CAT_DELETE_ROWS:
1385 case SC_CAT_DELETE_TABS:
1387 bTheTestFlag = InsertDeletedChildren( pScChangeAction, &aActionMap, pEntry );
1388 break;
1390 default:
1392 bTheTestFlag = InsertChildren( &aActionMap, pEntry );
1393 break;
1396 aActionMap.clear();
1399 else
1401 bTheTestFlag=InsertAcceptedORejected(pEntry);
1403 if(bTheTestFlag) pTheView->InsertEntry(aStrNoEntry,NULL,Color(COL_GRAY),pEntry);
1408 SetPointer(Pointer(POINTER_ARROW));
1409 return (sal_uLong) true;
1413 void ScAcceptChgDlg::AppendChanges(ScChangeTrack* pChanges,sal_uLong nStartAction,
1414 sal_uLong nEndAction, sal_uLong /* nPos */)
1416 if(pChanges!=NULL)
1418 SvTreeListEntry* pParent=NULL;
1419 const ScChangeAction* pScChangeAction=NULL;
1420 bAcceptEnableFlag=true;
1421 bRejectEnableFlag=true;
1422 SetPointer(Pointer(POINTER_WAIT));
1423 pTheView->SetUpdateMode(false);
1425 bool bTheFlag = false;
1427 bool bFilterFlag = pTPFilter->IsDate() || pTPFilter->IsRange() ||
1428 pTPFilter->IsAuthor() || pTPFilter->IsComment();
1430 bUseColor = bFilterFlag;
1432 for(sal_uLong i=nStartAction;i<=nEndAction;i++)
1434 pScChangeAction=pChanges->GetAction(i);
1435 if(pScChangeAction==NULL) continue;
1438 switch(pScChangeAction->GetState())
1440 case SC_CAS_VIRGIN:
1442 if(pScChangeAction->IsDialogRoot())
1444 if(pScChangeAction->IsDialogParent())
1445 pParent=InsertChangeAction(pScChangeAction,SC_CAS_VIRGIN);
1446 else
1447 pParent=InsertFilteredAction(pScChangeAction,SC_CAS_VIRGIN);
1449 else
1450 pParent=NULL;
1452 bTheFlag=true;
1453 break;
1455 case SC_CAS_ACCEPTED:
1456 pParent=NULL;
1457 nAcceptCount++;
1458 break;
1460 case SC_CAS_REJECTED:
1461 pParent=NULL;
1462 nRejectCount++;
1463 break;
1466 if(pParent!=NULL && pScChangeAction->IsDialogParent())
1468 if(!bFilterFlag)
1469 pParent->EnableChildrenOnDemand(true);
1470 else
1472 bool bTestFlag = bHasFilterEntry;
1473 bHasFilterEntry = false;
1474 if(Expand(pChanges,pScChangeAction,pParent,!bTestFlag)&&!bTestFlag)
1475 pTheView->RemoveEntry(pParent);
1480 if( bTheFlag && (!pDoc->IsDocEditable() || pChanges->IsProtected()) )
1481 bTheFlag=false;
1483 pTPView->EnableAccept(bTheFlag);
1484 pTPView->EnableAcceptAll(bTheFlag);
1485 pTPView->EnableReject(bTheFlag);
1486 pTPView->EnableRejectAll(bTheFlag);
1488 pTheView->SetUpdateMode(true);
1489 SetPointer(Pointer(POINTER_ARROW));
1493 void ScAcceptChgDlg::RemoveEntrys(sal_uLong nStartAction,sal_uLong nEndAction)
1496 pTheView->SetUpdateMode(false);
1498 SvTreeListEntry* pEntry=pTheView->GetCurEntry();
1500 ScRedlinData *pEntryData=NULL;
1502 if(pEntry!=NULL)
1503 pEntryData=(ScRedlinData *)(pEntry->GetUserData());
1505 sal_uLong nAction=0;
1506 if(pEntryData!=NULL)
1507 nAction=pEntryData->nActionNo;
1509 if(nAction>=nStartAction && nAction<=nEndAction)
1510 pTheView->SetCurEntry(pTheView->GetModel()->GetEntry(0));
1512 bool bRemove = false;
1514 // MUST do it backwards, don't delete parents before children and GPF
1515 pEntry=pTheView->Last();
1516 while(pEntry!=NULL)
1518 bRemove=false;
1519 pEntryData=(ScRedlinData *)(pEntry->GetUserData());
1520 if(pEntryData!=NULL)
1522 nAction=pEntryData->nActionNo;
1524 if(nStartAction<=nAction && nAction<=nEndAction) bRemove=true;
1528 SvTreeListEntry* pPrevEntry = pTheView->Prev(pEntry);
1530 if(bRemove)
1531 pTheView->RemoveEntry(pEntry);
1533 pEntry=pPrevEntry;
1535 pTheView->SetUpdateMode(true);
1539 void ScAcceptChgDlg::UpdateEntrys(ScChangeTrack* pChgTrack, sal_uLong nStartAction,sal_uLong nEndAction)
1541 pTheView->SetUpdateMode(false);
1543 sal_uLong nPos=LIST_APPEND;
1545 bool bRemove = false;
1547 SvTreeListEntry* pEntry=pTheView->First();
1548 SvTreeListEntry* pNextEntry = (pEntry ? pTheView->NextSibling(pEntry) : NULL);
1549 SvTreeListEntry* pLastEntry=NULL;
1550 while(pEntry!=NULL)
1552 bRemove=false;
1553 ScRedlinData *pEntryData=(ScRedlinData *)(pEntry->GetUserData());
1554 if(pEntryData!=NULL)
1556 ScChangeAction* pScChangeAction=
1557 (ScChangeAction*) pEntryData->pData;
1559 sal_uLong nAction=pScChangeAction->GetActionNumber();
1561 if(nStartAction<=nAction && nAction<=nEndAction) bRemove=true;
1564 if(bRemove)
1566 nPos=pEntry->GetChildListPos();
1567 pTheView->RemoveEntry(pEntry);
1569 if(pLastEntry==NULL) pLastEntry=pTheView->First();
1570 if(pLastEntry!=NULL)
1572 pNextEntry=pTheView->Next(pLastEntry);
1574 if(pNextEntry==NULL)
1576 pNextEntry=pLastEntry;
1577 pLastEntry=NULL;
1580 else
1581 pNextEntry=NULL;
1584 else
1586 pLastEntry = pEntry;
1587 pNextEntry = pTheView->Next(pEntry);
1589 pEntry=pNextEntry;
1592 if(nStartAction==nEndAction)
1593 AppendChanges(pChgTrack,nStartAction,nEndAction,nPos);
1594 else
1595 AppendChanges(pChgTrack,nStartAction,nEndAction);
1597 pTheView->SetUpdateMode(true);
1601 IMPL_LINK( ScAcceptChgDlg, ChgTrackModHdl, ScChangeTrack*, pChgTrack)
1603 ScChangeTrackMsgQueue::iterator iter;
1604 ScChangeTrackMsgQueue& aMsgQueue= pChgTrack->GetMsgQueue();
1606 sal_uLong nStartAction;
1607 sal_uLong nEndAction;
1609 for (iter = aMsgQueue.begin(); iter != aMsgQueue.end(); ++iter)
1611 nStartAction=(*iter)->nStartAction;
1612 nEndAction=(*iter)->nEndAction;
1614 if(!bIgnoreMsg)
1616 bNoSelection=true;
1618 switch((*iter)->eMsgType)
1620 case SC_CTM_APPEND: AppendChanges(pChgTrack,nStartAction,nEndAction);
1621 break;
1622 case SC_CTM_REMOVE: RemoveEntrys(nStartAction,nEndAction);
1623 break;
1624 case SC_CTM_PARENT:
1625 case SC_CTM_CHANGE: //bNeedsUpdate=true;
1626 UpdateEntrys(pChgTrack,nStartAction,nEndAction);
1627 break;
1628 default:
1630 // added to avoid warnings
1634 delete *iter;
1637 aMsgQueue.clear();
1639 return 0;
1641 IMPL_LINK_NOARG(ScAcceptChgDlg, ReOpenTimerHdl)
1643 ScSimpleRefDlgWrapper::SetAutoReOpen(true);
1644 m_pAcceptChgCtr->ShowFilterPage();
1645 RefHandle(NULL);
1647 return 0;
1650 IMPL_LINK_NOARG(ScAcceptChgDlg, UpdateSelectionHdl)
1652 ScTabView* pTabView = pViewData->GetView();
1654 bool bAcceptFlag = true;
1655 bool bRejectFlag = true;
1656 bool bContMark = false;
1658 pTabView->DoneBlockMode(); // clears old marking
1659 SvTreeListEntry* pEntry = pTheView->FirstSelected();
1660 while( pEntry )
1662 ScRedlinData* pEntryData = (ScRedlinData*) pEntry->GetUserData();
1663 if( pEntryData )
1665 bRejectFlag &= (bool) pEntryData->bIsRejectable;
1666 bAcceptFlag &= (bool) pEntryData->bIsAcceptable;
1668 const ScChangeAction* pScChangeAction = (ScChangeAction*) pEntryData->pData;
1669 if( pScChangeAction && (pScChangeAction->GetType() != SC_CAT_DELETE_TABS) &&
1670 (!pEntryData->bDisabled || pScChangeAction->IsVisible()) )
1672 const ScBigRange& rBigRange = pScChangeAction->GetBigRange();
1673 if( rBigRange.IsValid( pDoc ) && IsActive() )
1675 bool bSetCursor = !pTheView->NextSelected( pEntry );
1676 pTabView->MarkRange( rBigRange.MakeRange(), bSetCursor, bContMark );
1677 bContMark = true;
1681 else
1683 bAcceptFlag = false;
1684 bRejectFlag = false;
1686 bAcceptEnableFlag = bAcceptFlag;
1687 bRejectEnableFlag = bRejectFlag;
1689 pEntry = pTheView->NextSelected( pEntry );
1692 ScChangeTrack* pChanges = pDoc->GetChangeTrack();
1693 bool bEnable = pDoc->IsDocEditable() && pChanges && !pChanges->IsProtected();
1694 pTPView->EnableAccept( bAcceptFlag && bEnable );
1695 pTPView->EnableReject( bRejectFlag && bEnable );
1697 return 0;
1700 IMPL_LINK_NOARG(ScAcceptChgDlg, CommandHdl)
1703 const CommandEvent aCEvt(pTheView->GetCommandEvent());
1705 if(aCEvt.GetCommand()==COMMAND_CONTEXTMENU)
1707 ScPopupMenu aPopup(ScResId(RID_POPUP_CHANGES));
1709 aPopup.SetMenuFlags(MENU_FLAG_HIDEDISABLEDENTRIES);
1711 SvTreeListEntry* pEntry=pTheView->GetCurEntry();
1712 if(pEntry!=NULL)
1714 pTheView->Select(pEntry);
1716 else
1718 aPopup.Deactivate();
1721 sal_uInt16 nSortedCol= pTheView->GetSortedCol();
1723 if(nSortedCol!=0xFFFF)
1725 sal_uInt16 nItemId=nSortedCol+SC_SUB_SORT+1;
1727 aPopup.CheckItem(nItemId);
1729 PopupMenu *pSubMenu = aPopup.GetPopupMenu(SC_SUB_SORT);
1731 if (pSubMenu)
1732 pSubMenu->CheckItem(nItemId);
1735 aPopup.EnableItem(SC_CHANGES_COMMENT,false);
1737 if(pDoc->IsDocEditable() && pEntry!=NULL)
1739 ScRedlinData *pEntryData=(ScRedlinData *)(pEntry->GetUserData());
1740 if(pEntryData!=NULL)
1742 ScChangeAction* pScChangeAction=
1743 (ScChangeAction*) pEntryData->pData;
1744 if(pScChangeAction!=NULL && !pTheView->GetParent(pEntry))
1745 aPopup.EnableItem(SC_CHANGES_COMMENT);
1749 sal_uInt16 nCommand=aPopup.Execute( this, GetPointerPosPixel() );
1752 if(nCommand)
1754 if(nCommand==SC_CHANGES_COMMENT)
1756 if(pEntry!=NULL)
1758 ScRedlinData *pEntryData=(ScRedlinData *)(pEntry->GetUserData());
1759 if(pEntryData!=NULL)
1761 ScChangeAction* pScChangeAction=
1762 (ScChangeAction*) pEntryData->pData;
1764 pViewData->GetDocShell()->ExecuteChangeCommentDialog( pScChangeAction, this,false);
1768 else
1770 bool bSortDir = pTheView->GetSortDirection();
1771 sal_uInt16 nDialogCol=nCommand-SC_SUB_SORT-1;
1772 if(nSortedCol==nDialogCol) bSortDir=!bSortDir;
1773 pTheView->SortByCol(nDialogCol,bSortDir);
1775 SC_SUB_SORT
1776 SC_SORT_ACTION
1777 SC_SORT_POSITION
1778 SC_SORT_AUTHOR
1779 SC_SORT_DATE
1780 SC_SORT_COMMENT
1785 return 0;
1788 void ScAcceptChgDlg::Initialize(SfxChildWinInfo *pInfo)
1790 String aStr;
1791 if(pInfo!=NULL)
1793 if ( pInfo->aExtraString.Len() )
1795 xub_StrLen nPos = pInfo->aExtraString.Search(
1796 OUString("AcceptChgDat:"));
1798 // Versuche, den Alignment-String "ALIGN:(...)" einzulesen; wenn
1799 // er nicht vorhanden ist, liegt eine "altere Version vor
1800 if ( nPos != STRING_NOTFOUND )
1802 xub_StrLen n1 = pInfo->aExtraString.Search('(', nPos);
1803 if ( n1 != STRING_NOTFOUND )
1805 xub_StrLen n2 = pInfo->aExtraString.Search(')', n1);
1806 if ( n2 != STRING_NOTFOUND )
1808 // Alignment-String herausschneiden
1809 aStr = pInfo->aExtraString.Copy(nPos, n2 - nPos + 1);
1810 pInfo->aExtraString.Erase(nPos, n2 - nPos + 1);
1811 aStr.Erase(0, n1-nPos+1);
1817 SfxModelessDialog::Initialize(pInfo);
1819 if ( aStr.Len())
1821 sal_uInt16 nCount=(sal_uInt16)aStr.ToInt32();
1823 for(sal_uInt16 i=0;i<nCount;i++)
1825 xub_StrLen n1 = aStr.Search(';');
1826 aStr.Erase(0, n1+1);
1827 pTheView->SetTab(i,(sal_uInt16)aStr.ToInt32(),MAP_PIXEL);
1832 //-------------------------------------------------------------------------
1834 void ScAcceptChgDlg::FillInfo(SfxChildWinInfo& rInfo) const
1836 SfxModelessDialog::FillInfo(rInfo);
1837 rInfo.aExtraString.AppendAscii(RTL_CONSTASCII_STRINGPARAM( "AcceptChgDat:(" ));
1839 sal_uInt16 nCount=pTheView->TabCount();
1841 rInfo.aExtraString += OUString::number(nCount);
1842 rInfo.aExtraString += ';';
1843 for(sal_uInt16 i=0;i<nCount;i++)
1845 rInfo.aExtraString += OUString::number(pTheView->GetTab(i));
1846 rInfo.aExtraString += ';';
1848 rInfo.aExtraString += ')';
1851 void ScAcceptChgDlg::InitFilter()
1853 if(pTPFilter->IsDate()||pTPFilter->IsRange()||
1854 pTPFilter->IsAuthor()||pTPFilter->IsComment())
1856 pTheView->SetFilterDate(pTPFilter->IsDate());
1857 pTheView->SetDateTimeMode(pTPFilter->GetDateMode());
1858 pTheView->SetFirstDate(pTPFilter->GetFirstDate());
1859 pTheView->SetLastDate(pTPFilter->GetLastDate());
1860 pTheView->SetFirstTime(pTPFilter->GetFirstTime());
1861 pTheView->SetLastTime(pTPFilter->GetLastTime());
1862 pTheView->SetFilterAuthor(pTPFilter->IsAuthor());
1863 pTheView->SetAuthor(pTPFilter->GetSelectedAuthor());
1865 pTheView->SetFilterComment(pTPFilter->IsComment());
1867 utl::SearchParam aSearchParam( pTPFilter->GetComment(),
1868 utl::SearchParam::SRCH_REGEXP,false,false,false );
1870 pTheView->SetCommentParams(&aSearchParam);
1872 pTheView->UpdateFilterTest();
1876 IMPL_LINK_NOARG(ScAcceptChgDlg, FilterModified)
1878 return 0;
1881 #define CALC_DATE 3
1882 #define CALC_POS 1
1884 IMPL_LINK( ScAcceptChgDlg, ColCompareHdl, SvSortData*, pSortData )
1886 StringCompare eCompare=COMPARE_EQUAL;
1887 SCCOL nSortCol= static_cast<SCCOL>(pTheView->GetSortedCol());
1889 if(pSortData)
1891 SvTreeListEntry* pLeft = (SvTreeListEntry*)(pSortData->pLeft );
1892 SvTreeListEntry* pRight = (SvTreeListEntry*)(pSortData->pRight );
1894 if(CALC_DATE==nSortCol)
1896 RedlinData *pLeftData=(RedlinData *)(pLeft->GetUserData());
1897 RedlinData *pRightData=(RedlinData *)(pRight->GetUserData());
1899 if(pLeftData!=NULL && pRightData!=NULL)
1901 if(pLeftData->aDateTime < pRightData->aDateTime)
1902 eCompare=COMPARE_LESS;
1903 else if(pLeftData->aDateTime > pRightData->aDateTime)
1904 eCompare=COMPARE_GREATER;
1906 return eCompare;
1909 else if(CALC_POS==nSortCol)
1911 ScRedlinData *pLeftData=(ScRedlinData *)(pLeft->GetUserData());
1912 ScRedlinData *pRightData=(ScRedlinData *)(pRight->GetUserData());
1914 if(pLeftData!=NULL && pRightData!=NULL)
1916 eCompare=COMPARE_GREATER;
1918 if(pLeftData->nTable < pRightData->nTable)
1919 eCompare=COMPARE_LESS;
1920 else if(pLeftData->nTable == pRightData->nTable)
1922 if(pLeftData->nRow < pRightData->nRow)
1923 eCompare=COMPARE_LESS;
1924 else if(pLeftData->nRow == pRightData->nRow)
1926 if(pLeftData->nCol < pRightData->nCol)
1927 eCompare=COMPARE_LESS;
1928 else if(pLeftData->nCol == pRightData->nCol)
1929 eCompare=COMPARE_EQUAL;
1933 return eCompare;
1937 SvLBoxItem* pLeftItem = pTheView->GetEntryAtPos( pLeft, static_cast<sal_uInt16>(nSortCol));
1938 SvLBoxItem* pRightItem = pTheView->GetEntryAtPos( pRight, static_cast<sal_uInt16>(nSortCol));
1940 if(pLeftItem != NULL && pRightItem != NULL)
1942 sal_uInt16 nLeftKind = pLeftItem->GetType();
1943 sal_uInt16 nRightKind = pRightItem->GetType();
1945 if(nRightKind == SV_ITEM_ID_LBOXSTRING &&
1946 nLeftKind == SV_ITEM_ID_LBOXSTRING )
1948 eCompare= (StringCompare) ScGlobal::GetCaseCollator()->compareString(
1949 ((SvLBoxString*)pLeftItem)->GetText(),
1950 ((SvLBoxString*)pRightItem)->GetText());
1952 if(eCompare==COMPARE_EQUAL) eCompare=COMPARE_LESS;
1958 return eCompare;
1961 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */