1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sc.hxx"
26
27 //-----------------------------------------------------------------------------
28
29 #include <vcl/msgbox.hxx>
30
31 #include "conflictsdlg.hxx"
32 #include "conflictsdlg.hrc"
33 #include "scresid.hxx"
34 #include "viewdata.hxx"
35 #include "dbfunc.hxx"
36
37
38 //=============================================================================
39 // struct ScConflictsListEntry
40 //=============================================================================
41
HasSharedAction(sal_uLong nSharedAction) const42 bool ScConflictsListEntry::HasSharedAction( sal_uLong nSharedAction ) const
43 {
44 ScChangeActionList::const_iterator aEnd = maSharedActions.end();
45 for ( ScChangeActionList::const_iterator aItr = maSharedActions.begin(); aItr != aEnd; ++aItr )
46 {
47 if ( *aItr == nSharedAction )
48 {
49 return true;
50 }
51 }
52
53 return false;
54 }
55
HasOwnAction(sal_uLong nOwnAction) const56 bool ScConflictsListEntry::HasOwnAction( sal_uLong nOwnAction ) const
57 {
58 ScChangeActionList::const_iterator aEnd = maOwnActions.end();
59 for ( ScChangeActionList::const_iterator aItr = maOwnActions.begin(); aItr != aEnd; ++aItr )
60 {
61 if ( *aItr == nOwnAction )
62 {
63 return true;
64 }
65 }
66
67 return false;
68 }
69
70
71 //=============================================================================
72 // class ScConflictsListHelper
73 //=============================================================================
74
75 //UNUSED2008-05 bool ScConflictsListHelper::HasSharedAction( ScConflictsList& rConflictsList, sal_uLong nSharedAction )
76 //UNUSED2008-05 {
77 //UNUSED2008-05 ScConflictsList::const_iterator aEnd = rConflictsList.end();
78 //UNUSED2008-05 for ( ScConflictsList::const_iterator aItr = rConflictsList.begin(); aItr != aEnd; ++aItr )
79 //UNUSED2008-05 {
80 //UNUSED2008-05 if ( aItr->HasSharedAction( nSharedAction ) )
81 //UNUSED2008-05 {
82 //UNUSED2008-05 return true;
83 //UNUSED2008-05 }
84 //UNUSED2008-05 }
85 //UNUSED2008-05
86 //UNUSED2008-05 return false;
87 //UNUSED2008-05 }
88
HasOwnAction(ScConflictsList & rConflictsList,sal_uLong nOwnAction)89 bool ScConflictsListHelper::HasOwnAction( ScConflictsList& rConflictsList, sal_uLong nOwnAction )
90 {
91 ScConflictsList::const_iterator aEnd = rConflictsList.end();
92 for ( ScConflictsList::const_iterator aItr = rConflictsList.begin(); aItr != aEnd; ++aItr )
93 {
94 if ( aItr->HasOwnAction( nOwnAction ) )
95 {
96 return true;
97 }
98 }
99
100 return false;
101 }
102
GetSharedActionEntry(ScConflictsList & rConflictsList,sal_uLong nSharedAction)103 ScConflictsListEntry* ScConflictsListHelper::GetSharedActionEntry( ScConflictsList& rConflictsList, sal_uLong nSharedAction )
104 {
105 ScConflictsList::iterator aEnd = rConflictsList.end();
106 for ( ScConflictsList::iterator aItr = rConflictsList.begin(); aItr != aEnd; ++aItr )
107 {
108 if ( aItr->HasSharedAction( nSharedAction ) )
109 {
110 return &(*aItr);
111 }
112 }
113
114 return NULL;
115 }
116
GetOwnActionEntry(ScConflictsList & rConflictsList,sal_uLong nOwnAction)117 ScConflictsListEntry* ScConflictsListHelper::GetOwnActionEntry( ScConflictsList& rConflictsList, sal_uLong nOwnAction )
118 {
119 ScConflictsList::iterator aEnd = rConflictsList.end();
120 for ( ScConflictsList::iterator aItr = rConflictsList.begin(); aItr != aEnd; ++aItr )
121 {
122 if ( aItr->HasOwnAction( nOwnAction ) )
123 {
124 return &(*aItr);
125 }
126 }
127
128 return NULL;
129 }
130
Transform_Impl(ScChangeActionList & rActionList,ScChangeActionMergeMap * pMergeMap)131 void ScConflictsListHelper::Transform_Impl( ScChangeActionList& rActionList, ScChangeActionMergeMap* pMergeMap )
132 {
133 if ( !pMergeMap )
134 {
135 return;
136 }
137
138 for ( ScChangeActionList::iterator aItr = rActionList.begin(); aItr != rActionList.end(); )
139 {
140 ScChangeActionMergeMap::iterator aItrMap = pMergeMap->find( *aItr );
141 if ( aItrMap != pMergeMap->end() )
142 {
143 *aItr = aItrMap->second;
144 aItr++;
145 }
146 else
147 {
148 aItr = rActionList.erase( aItr );
149 DBG_ERROR( "ScConflictsListHelper::Transform_Impl: erased action from conflicts list!" );
150 }
151 }
152 }
153
TransformConflictsList(ScConflictsList & rConflictsList,ScChangeActionMergeMap * pSharedMap,ScChangeActionMergeMap * pOwnMap)154 void ScConflictsListHelper::TransformConflictsList( ScConflictsList& rConflictsList,
155 ScChangeActionMergeMap* pSharedMap, ScChangeActionMergeMap* pOwnMap )
156 {
157 ScConflictsList::iterator aEnd = rConflictsList.end();
158 for ( ScConflictsList::iterator aItr = rConflictsList.begin(); aItr != aEnd; ++aItr )
159 {
160 if ( pSharedMap )
161 {
162 ScConflictsListHelper::Transform_Impl( aItr->maSharedActions, pSharedMap );
163 }
164
165 if ( pOwnMap )
166 {
167 ScConflictsListHelper::Transform_Impl( aItr->maOwnActions, pOwnMap );
168 }
169 }
170 }
171
172
173 //=============================================================================
174 // class ScConflictsFinder
175 //=============================================================================
176
ScConflictsFinder(ScChangeTrack * pTrack,sal_uLong nStartShared,sal_uLong nEndShared,sal_uLong nStartOwn,sal_uLong nEndOwn,ScConflictsList & rConflictsList)177 ScConflictsFinder::ScConflictsFinder( ScChangeTrack* pTrack, sal_uLong nStartShared, sal_uLong nEndShared,
178 sal_uLong nStartOwn, sal_uLong nEndOwn, ScConflictsList& rConflictsList )
179 :mpTrack( pTrack )
180 ,mnStartShared( nStartShared )
181 ,mnEndShared( nEndShared )
182 ,mnStartOwn( nStartOwn )
183 ,mnEndOwn( nEndOwn )
184 ,mrConflictsList( rConflictsList )
185 {
186 }
187
~ScConflictsFinder()188 ScConflictsFinder::~ScConflictsFinder()
189 {
190 }
191
DoActionsIntersect(const ScChangeAction * pAction1,const ScChangeAction * pAction2)192 bool ScConflictsFinder::DoActionsIntersect( const ScChangeAction* pAction1, const ScChangeAction* pAction2 )
193 {
194 if ( pAction1 && pAction2 && pAction1->GetBigRange().Intersects( pAction2->GetBigRange() ) )
195 {
196 return true;
197 }
198 return false;
199 }
200
GetIntersectingEntry(const ScChangeAction * pAction) const201 ScConflictsListEntry* ScConflictsFinder::GetIntersectingEntry( const ScChangeAction* pAction ) const
202 {
203 ScConflictsList::iterator aEnd = mrConflictsList.end();
204 for ( ScConflictsList::iterator aItr = mrConflictsList.begin(); aItr != aEnd; ++aItr )
205 {
206 ScChangeActionList::const_iterator aEndShared = aItr->maSharedActions.end();
207 for ( ScChangeActionList::const_iterator aItrShared = aItr->maSharedActions.begin(); aItrShared != aEndShared; ++aItrShared )
208 {
209 if ( DoActionsIntersect( mpTrack->GetAction( *aItrShared ), pAction ) )
210 {
211 return &(*aItr);
212 }
213 }
214
215 ScChangeActionList::const_iterator aEndOwn = aItr->maOwnActions.end();
216 for ( ScChangeActionList::const_iterator aItrOwn = aItr->maOwnActions.begin(); aItrOwn != aEndOwn; ++aItrOwn )
217 {
218 if ( DoActionsIntersect( mpTrack->GetAction( *aItrOwn ), pAction ) )
219 {
220 return &(*aItr);
221 }
222 }
223 }
224
225 return NULL;
226 }
227
GetEntry(sal_uLong nSharedAction,const ScChangeActionList & rOwnActions)228 ScConflictsListEntry* ScConflictsFinder::GetEntry( sal_uLong nSharedAction, const ScChangeActionList& rOwnActions )
229 {
230 // try to get a list entry which already contains the shared action
231 ScConflictsListEntry* pEntry = ScConflictsListHelper::GetSharedActionEntry( mrConflictsList, nSharedAction );
232 if ( pEntry )
233 {
234 return pEntry;
235 }
236
237 // try to get a list entry for which the shared action intersects with any
238 // other action of this entry
239 pEntry = GetIntersectingEntry( mpTrack->GetAction( nSharedAction ) );
240 if ( pEntry )
241 {
242 pEntry->maSharedActions.push_back( nSharedAction );
243 return pEntry;
244 }
245
246 // try to get a list entry for which any of the own actions intersects with
247 // any other action of this entry
248 ScChangeActionList::const_iterator aEnd = rOwnActions.end();
249 for ( ScChangeActionList::const_iterator aItr = rOwnActions.begin(); aItr != aEnd; ++aItr )
250 {
251 pEntry = GetIntersectingEntry( mpTrack->GetAction( *aItr ) );
252 if ( pEntry )
253 {
254 pEntry->maSharedActions.push_back( nSharedAction );
255 return pEntry;
256 }
257 }
258
259 // if no entry was found, create a new one
260 ScConflictsListEntry aEntry;
261 aEntry.meConflictAction = SC_CONFLICT_ACTION_NONE;
262 aEntry.maSharedActions.push_back( nSharedAction );
263 mrConflictsList.push_back( aEntry );
264 return &(mrConflictsList.back());
265 }
266
Find()267 bool ScConflictsFinder::Find()
268 {
269 if ( !mpTrack )
270 {
271 return false;
272 }
273
274 bool bReturn = false;
275 ScChangeAction* pSharedAction = mpTrack->GetAction( mnStartShared );
276 while ( pSharedAction && pSharedAction->GetActionNumber() <= mnEndShared )
277 {
278 ScChangeActionList aOwnActions;
279 ScChangeAction* pOwnAction = mpTrack->GetAction( mnStartOwn );
280 while ( pOwnAction && pOwnAction->GetActionNumber() <= mnEndOwn )
281 {
282 if ( DoActionsIntersect( pSharedAction, pOwnAction ) )
283 {
284 aOwnActions.push_back( pOwnAction->GetActionNumber() );
285 }
286 pOwnAction = pOwnAction->GetNext();
287 }
288
289 if ( aOwnActions.size() )
290 {
291 ScConflictsListEntry* pEntry = GetEntry( pSharedAction->GetActionNumber(), aOwnActions );;
292 ScChangeActionList::iterator aEnd = aOwnActions.end();
293 for ( ScChangeActionList::iterator aItr = aOwnActions.begin(); aItr != aEnd; ++aItr )
294 {
295 if ( pEntry && !ScConflictsListHelper::HasOwnAction( mrConflictsList, *aItr ) )
296 {
297 pEntry->maOwnActions.push_back( *aItr );
298 }
299 }
300 bReturn = true;
301 }
302
303 pSharedAction = pSharedAction->GetNext();
304 }
305
306 return bReturn;
307 }
308
309 //=============================================================================
310 // class ScConflictsResolver
311 //=============================================================================
312
ScConflictsResolver(ScChangeTrack * pTrack,ScConflictsList & rConflictsList)313 ScConflictsResolver::ScConflictsResolver( ScChangeTrack* pTrack, ScConflictsList& rConflictsList )
314 :mpTrack ( pTrack )
315 ,mrConflictsList ( rConflictsList )
316 {
317 DBG_ASSERT( mpTrack, "ScConflictsResolver CTOR: mpTrack is null!" );
318 }
319
~ScConflictsResolver()320 ScConflictsResolver::~ScConflictsResolver()
321 {
322 }
323
HandleAction(ScChangeAction * pAction,bool bIsSharedAction,bool bHandleContentAction,bool bHandleNonContentAction)324 void ScConflictsResolver::HandleAction( ScChangeAction* pAction, bool bIsSharedAction,
325 bool bHandleContentAction, bool bHandleNonContentAction )
326 {
327 if ( !mpTrack || !pAction )
328 {
329 return;
330 }
331
332 if ( bIsSharedAction )
333 {
334 ScConflictsListEntry* pConflictEntry = ScConflictsListHelper::GetSharedActionEntry(
335 mrConflictsList, pAction->GetActionNumber() );
336 if ( pConflictEntry )
337 {
338 ScConflictAction eConflictAction = pConflictEntry->meConflictAction;
339 if ( eConflictAction == SC_CONFLICT_ACTION_KEEP_MINE )
340 {
341 if ( pAction->GetType() == SC_CAT_CONTENT )
342 {
343 if ( bHandleContentAction )
344 {
345 mpTrack->Reject( pAction );
346 }
347 }
348 else
349 {
350 if ( bHandleNonContentAction )
351 {
352 mpTrack->Reject( pAction );
353 }
354 }
355 }
356 else if ( eConflictAction == SC_CONFLICT_ACTION_KEEP_OTHER )
357 {
358 if ( pAction->GetType() == SC_CAT_CONTENT )
359 {
360 if ( bHandleContentAction )
361 {
362 // do nothing
363 //mpTrack->SelectContent( pAction );
364 }
365 }
366 else
367 {
368 if ( bHandleNonContentAction )
369 {
370 // do nothing
371 //mpTrack->Accept( pAction );
372 }
373 }
374 }
375 }
376 }
377 else
378 {
379 ScConflictsListEntry* pConflictEntry = ScConflictsListHelper::GetOwnActionEntry(
380 mrConflictsList, pAction->GetActionNumber() );
381 if ( pConflictEntry )
382 {
383 ScConflictAction eConflictAction = pConflictEntry->meConflictAction;
384 if ( eConflictAction == SC_CONFLICT_ACTION_KEEP_MINE )
385 {
386 if ( pAction->GetType() == SC_CAT_CONTENT )
387 {
388 if ( bHandleContentAction )
389 {
390 // do nothing
391 //mpTrack->SelectContent( pAction );
392 }
393 }
394 else
395 {
396 if ( bHandleNonContentAction )
397 {
398 // do nothing
399 //mpTrack->Accept( pAction );
400 }
401 }
402 }
403 else if ( eConflictAction == SC_CONFLICT_ACTION_KEEP_OTHER )
404 {
405 if ( pAction->GetType() == SC_CAT_CONTENT )
406 {
407 if ( bHandleContentAction )
408 {
409 mpTrack->Reject( pAction );
410 }
411 }
412 else
413 {
414 if ( bHandleNonContentAction )
415 {
416 mpTrack->Reject( pAction );
417 }
418 }
419 }
420 }
421 }
422 }
423
424
425 //=============================================================================
426 // class ScConflictsListBox
427 //=============================================================================
428
429 //UNUSED2008-05 ScConflictsListBox::ScConflictsListBox( Window* pParent, WinBits nBits )
430 //UNUSED2008-05 :SvxRedlinTable( pParent, nBits )
431 //UNUSED2008-05 {
432 //UNUSED2008-05 }
433
ScConflictsListBox(Window * pParent,const ResId & rResId)434 ScConflictsListBox::ScConflictsListBox( Window* pParent, const ResId& rResId )
435 :SvxRedlinTable( pParent, rResId )
436 {
437 }
438
~ScConflictsListBox()439 ScConflictsListBox::~ScConflictsListBox()
440 {
441 }
442
443 //UNUSED2008-05 sal_uLong ScConflictsListBox::GetRootEntryPos( const SvLBoxEntry* pRootEntry ) const
444 //UNUSED2008-05 {
445 //UNUSED2008-05 sal_uLong nPos = 0;
446 //UNUSED2008-05 SvLBoxEntry* pEntry = GetRootLevelParent( First() );
447 //UNUSED2008-05 while ( pEntry )
448 //UNUSED2008-05 {
449 //UNUSED2008-05 if ( pEntry == pRootEntry )
450 //UNUSED2008-05 {
451 //UNUSED2008-05 return nPos;
452 //UNUSED2008-05 }
453 //UNUSED2008-05 pEntry = NextSibling( pEntry );
454 //UNUSED2008-05 ++nPos;
455 //UNUSED2008-05 }
456 //UNUSED2008-05 return 0xffffffff;
457 //UNUSED2008-05 }
458
459
460 //=============================================================================
461 // class ScConflictsDlg
462 //=============================================================================
463
ScConflictsDlg(Window * pParent,ScViewData * pViewData,ScDocument * pSharedDoc,ScConflictsList & rConflictsList)464 ScConflictsDlg::ScConflictsDlg( Window* pParent, ScViewData* pViewData, ScDocument* pSharedDoc, ScConflictsList& rConflictsList )
465 :ModalDialog( pParent, ScResId( RID_SCDLG_CONFLICTS ) )
466 ,maFtConflicts ( this, ScResId( FT_CONFLICTS ) )
467 ,maLbConflicts ( this, ScResId( LB_CONFLICTS ) )
468 ,maBtnKeepMine ( this, ScResId( BTN_KEEPMINE ) )
469 ,maBtnKeepOther ( this, ScResId( BTN_KEEPOTHER ) )
470 ,maFlConflicts ( this, ScResId( FL_CONFLICTS ) )
471 ,maBtnKeepAllMine ( this, ScResId( BTN_KEEPALLMINE ) )
472 ,maBtnKeepAllOthers ( this, ScResId( BTN_KEEPALLOTHERS ) )
473 ,maBtnCancel ( this, ScResId( BTN_CANCEL ) )
474 ,maBtnHelp ( this, ScResId( BTN_HELP ) )
475 ,maStrTitleConflict ( ScResId( STR_TITLE_CONFLICT ) )
476 ,maStrTitleAuthor ( ScResId( STR_TITLE_AUTHOR ) )
477 ,maStrTitleDate ( ScResId( STR_TITLE_DATE ) )
478 ,maStrUnknownUser ( ScResId( STR_UNKNOWN_USER ) )
479 ,mpViewData ( pViewData )
480 ,mpOwnDoc ( NULL )
481 ,mpOwnTrack ( NULL )
482 ,mpSharedDoc ( pSharedDoc )
483 ,mpSharedTrack ( NULL )
484 ,mrConflictsList ( rConflictsList )
485 ,maDialogSize ( GetSizePixel() )
486 ,mbInSelectHdl ( false )
487 ,mbInDeselectHdl ( false )
488 {
489 DBG_ASSERT( mpViewData, "ScConflictsDlg CTOR: mpViewData is null!" );
490 mpOwnDoc = ( mpViewData ? mpViewData->GetDocument() : NULL );
491 DBG_ASSERT( mpOwnDoc, "ScConflictsDlg CTOR: mpOwnDoc is null!" );
492 mpOwnTrack = ( mpOwnDoc ? mpOwnDoc->GetChangeTrack() : NULL );
493 DBG_ASSERT( mpOwnTrack, "ScConflictsDlg CTOR: mpOwnTrack is null!" );
494 DBG_ASSERT( mpSharedDoc, "ScConflictsDlg CTOR: mpSharedDoc is null!" );
495 mpSharedTrack = ( mpSharedDoc ? mpSharedDoc->GetChangeTrack() : NULL );
496 DBG_ASSERT( mpSharedTrack, "ScConflictsDlg CTOR: mpSharedTrack is null!" );
497
498 FreeResource();
499
500 SetMinOutputSizePixel( maDialogSize );
501
502 long nTabs[] = { 3, 10, 216, 266 };
503 maLbConflicts.SetTabs( nTabs );
504
505 String aTab( sal_Unicode( '\t' ) );
506 String aHeader( maStrTitleConflict );
507 aHeader += aTab;
508 aHeader += maStrTitleAuthor;
509 aHeader += aTab;
510 aHeader += maStrTitleDate;
511 maLbConflicts.InsertHeaderEntry( aHeader, HEADERBAR_APPEND, HIB_LEFT | HIB_LEFTIMAGE | HIB_VCENTER );
512
513 maLbConflicts.SetStyle( maLbConflicts.GetStyle() | WB_HASLINES | WB_CLIPCHILDREN | WB_HASBUTTONS | WB_HASBUTTONSATROOT | WB_HSCROLL );
514 maLbConflicts.SetSelectionMode( MULTIPLE_SELECTION );
515 maLbConflicts.SetHighlightRange();
516
517 maSelectionTimer.SetTimeout( 100 );
518 maSelectionTimer.SetTimeoutHdl( LINK( this, ScConflictsDlg, UpdateSelectionHdl ) );
519
520 maLbConflicts.SetSelectHdl( LINK( this, ScConflictsDlg, SelectHandle ) );
521 maLbConflicts.SetDeselectHdl( LINK( this, ScConflictsDlg, DeselectHandle ) );
522
523 maBtnKeepMine.SetClickHdl( LINK( this, ScConflictsDlg, KeepMineHandle ) );
524 maBtnKeepOther.SetClickHdl( LINK( this, ScConflictsDlg, KeepOtherHandle ) );
525 maBtnKeepAllMine.SetClickHdl( LINK( this, ScConflictsDlg, KeepAllMineHandle ) );
526 maBtnKeepAllOthers.SetClickHdl( LINK( this, ScConflictsDlg, KeepAllOthersHandle ) );
527
528 UpdateView();
529
530 SvLBoxEntry* pEntry = maLbConflicts.First();
531 if ( pEntry != NULL )
532 {
533 maLbConflicts.Select( pEntry );
534 }
535 }
536
~ScConflictsDlg()537 ScConflictsDlg::~ScConflictsDlg()
538 {
539 }
540
GetConflictString(const ScConflictsListEntry & rConflictEntry)541 String ScConflictsDlg::GetConflictString( const ScConflictsListEntry& rConflictEntry )
542 {
543 String aString;
544 if ( mpOwnTrack )
545 {
546 const ScChangeAction* pAction = mpOwnTrack->GetAction( rConflictEntry.maOwnActions[ 0 ] );
547 if ( pAction && mpOwnDoc )
548 {
549 SCTAB nTab = pAction->GetBigRange().MakeRange().aStart.Tab();
550 mpOwnDoc->GetName( nTab, aString );
551 }
552 }
553 return aString;
554 }
555
GetActionString(const ScChangeAction * pAction,ScDocument * pDoc)556 String ScConflictsDlg::GetActionString( const ScChangeAction* pAction, ScDocument* pDoc )
557 {
558 String aString;
559
560 DBG_ASSERT( pAction, "ScConflictsDlg::GetActionString(): pAction is null!" );
561 DBG_ASSERT( pDoc, "ScConflictsDlg::GetActionString(): pDoc is null!" );
562 if ( pAction && pDoc )
563 {
564 String aDesc;
565 pAction->GetDescription( aDesc, pDoc, sal_True, false );
566 aString += aDesc;
567 aString += '\t';
568
569 String aUser = pAction->GetUser();
570 aUser.EraseLeadingAndTrailingChars();
571 if ( aUser.Len() == 0 )
572 {
573 aUser = maStrUnknownUser;
574 }
575 aString += aUser;
576 aString += '\t';
577
578 DateTime aDateTime = pAction->GetDateTime();
579 aString += ScGlobal::pLocaleData->getDate( aDateTime );
580 aString += ' ';
581 aString += ScGlobal::pLocaleData->getTime( aDateTime, sal_False );
582 aString += '\t';
583 }
584
585 return aString;
586 }
587
HandleListBoxSelection(bool bSelectHandle)588 void ScConflictsDlg::HandleListBoxSelection( bool bSelectHandle )
589 {
590 SvLBoxEntry* pSelEntry = maLbConflicts.GetCurEntry();
591 if ( !pSelEntry )
592 {
593 pSelEntry = maLbConflicts.FirstSelected();
594 }
595 if ( !pSelEntry )
596 {
597 return;
598 }
599
600 SvLBoxEntry* pRootEntry = maLbConflicts.GetRootLevelParent( pSelEntry );
601 if ( pRootEntry )
602 {
603 if ( bSelectHandle )
604 {
605 maLbConflicts.SelectAll( sal_False );
606 }
607 if ( !maLbConflicts.IsSelected( pRootEntry ) )
608 {
609 maLbConflicts.Select( pRootEntry );
610 }
611 SvLBoxEntry* pEntry = maLbConflicts.FirstChild( pRootEntry );
612 while ( pEntry )
613 {
614 if ( !maLbConflicts.IsSelected( pEntry ) )
615 {
616 maLbConflicts.Select( pEntry );
617 }
618 pEntry = maLbConflicts.NextSibling( pEntry );
619 }
620 }
621 }
622
IMPL_LINK(ScConflictsDlg,SelectHandle,SvxRedlinTable *,EMPTYARG)623 IMPL_LINK( ScConflictsDlg, SelectHandle, SvxRedlinTable*, EMPTYARG )
624 {
625 if ( mbInSelectHdl || mbInDeselectHdl )
626 {
627 return 0;
628 }
629
630 mbInSelectHdl = true;
631 HandleListBoxSelection( true );
632 maSelectionTimer.Start();
633 mbInSelectHdl = false;
634
635 return 0;
636 }
637
IMPL_LINK(ScConflictsDlg,DeselectHandle,SvxRedlinTable *,EMPTYARG)638 IMPL_LINK( ScConflictsDlg, DeselectHandle, SvxRedlinTable*, EMPTYARG )
639 {
640 if ( mbInDeselectHdl || mbInSelectHdl )
641 {
642 return 0;
643 }
644
645 mbInDeselectHdl = true;
646 HandleListBoxSelection( false );
647 mbInDeselectHdl = false;
648
649 return 0;
650 }
651
IMPL_LINK(ScConflictsDlg,UpdateSelectionHdl,Timer *,EMPTYARG)652 IMPL_LINK( ScConflictsDlg, UpdateSelectionHdl, Timer*, EMPTYARG )
653 {
654 if ( !mpViewData || !mpOwnDoc )
655 {
656 return 0;
657 }
658
659 ScTabView* pTabView = mpViewData->GetView();
660 pTabView->DoneBlockMode();
661 sal_Bool bContMark = sal_False;
662 SvLBoxEntry* pEntry = maLbConflicts.FirstSelected();
663 while ( pEntry )
664 {
665 if ( pEntry != maLbConflicts.GetRootLevelParent( pEntry ) )
666 {
667 RedlinData* pUserData = static_cast< RedlinData* >( pEntry->GetUserData() );
668 if ( pUserData )
669 {
670 ScChangeAction* pAction = static_cast< ScChangeAction* >( pUserData->pData );
671 if ( pAction && ( pAction->GetType() != SC_CAT_DELETE_TABS ) &&
672 ( pAction->IsClickable() || pAction->IsVisible() ) )
673 {
674 const ScBigRange& rBigRange = ( static_cast< const ScChangeAction* >( pAction ) )->GetBigRange();
675 if ( rBigRange.IsValid( mpOwnDoc ) )
676 {
677 sal_Bool bSetCursor = !maLbConflicts.NextSelected( pEntry );
678 pTabView->MarkRange( rBigRange.MakeRange(), bSetCursor, bContMark );
679 bContMark = sal_True;
680 }
681 }
682 }
683 }
684 pEntry = maLbConflicts.NextSelected( pEntry );
685 }
686
687 return 0;
688 }
689
SetConflictAction(SvLBoxEntry * pRootEntry,ScConflictAction eConflictAction)690 void ScConflictsDlg::SetConflictAction( SvLBoxEntry* pRootEntry, ScConflictAction eConflictAction )
691 {
692 RedlinData* pUserData = static_cast< RedlinData* >( pRootEntry ? pRootEntry->GetUserData() : NULL );
693 ScConflictsListEntry* pConflictEntry = static_cast< ScConflictsListEntry* >( pUserData ? pUserData->pData : NULL );
694 if ( pConflictEntry )
695 {
696 pConflictEntry->meConflictAction = eConflictAction;
697 }
698 }
699
KeepHandler(bool bMine)700 void ScConflictsDlg::KeepHandler( bool bMine )
701 {
702 SvLBoxEntry* pEntry = maLbConflicts.FirstSelected();
703 SvLBoxEntry* pRootEntry = ( pEntry ? maLbConflicts.GetRootLevelParent( pEntry ) : NULL );
704 if ( !pRootEntry )
705 {
706 return;
707 }
708 SetPointer( Pointer( POINTER_WAIT ) );
709 ScConflictAction eConflictAction = ( bMine ? SC_CONFLICT_ACTION_KEEP_MINE : SC_CONFLICT_ACTION_KEEP_OTHER );
710 SetConflictAction( pRootEntry, eConflictAction );
711 maLbConflicts.RemoveEntry( pRootEntry );
712 SetPointer( Pointer( POINTER_ARROW ) );
713 if ( maLbConflicts.GetEntryCount() == 0 )
714 {
715 EndDialog( RET_OK );
716 }
717 }
718
KeepAllHandler(bool bMine)719 void ScConflictsDlg::KeepAllHandler( bool bMine )
720 {
721 SvLBoxEntry* pEntry = maLbConflicts.First();
722 SvLBoxEntry* pRootEntry = ( pEntry ? maLbConflicts.GetRootLevelParent( pEntry ) : NULL );
723 if ( !pRootEntry )
724 {
725 return;
726 }
727 SetPointer( Pointer( POINTER_WAIT ) );
728 ScConflictAction eConflictAction = ( bMine ? SC_CONFLICT_ACTION_KEEP_MINE : SC_CONFLICT_ACTION_KEEP_OTHER );
729 while ( pRootEntry )
730 {
731 SetConflictAction( pRootEntry, eConflictAction );
732 pRootEntry = maLbConflicts.NextSibling( pRootEntry );
733 }
734 maLbConflicts.SetUpdateMode( sal_False );
735 maLbConflicts.Clear();
736 maLbConflicts.SetUpdateMode( sal_True );
737 SetPointer( Pointer( POINTER_ARROW ) );
738 EndDialog( RET_OK );
739 }
740
IMPL_LINK(ScConflictsDlg,KeepMineHandle,void *,EMPTYARG)741 IMPL_LINK( ScConflictsDlg, KeepMineHandle, void*, EMPTYARG )
742 {
743 KeepHandler( true );
744
745 return 0;
746 }
747
IMPL_LINK(ScConflictsDlg,KeepOtherHandle,void *,EMPTYARG)748 IMPL_LINK( ScConflictsDlg, KeepOtherHandle, void*, EMPTYARG )
749 {
750 KeepHandler( false );
751
752 return 0;
753 }
754
IMPL_LINK(ScConflictsDlg,KeepAllMineHandle,void *,EMPTYARG)755 IMPL_LINK( ScConflictsDlg, KeepAllMineHandle, void*, EMPTYARG )
756 {
757 KeepAllHandler( true );
758
759 return 0;
760 }
761
IMPL_LINK(ScConflictsDlg,KeepAllOthersHandle,void *,EMPTYARG)762 IMPL_LINK( ScConflictsDlg, KeepAllOthersHandle, void*, EMPTYARG )
763 {
764 KeepAllHandler( false );
765
766 return 0;
767 }
768
lcl_MoveControlX(Window & rWindow,long nDelta)769 void lcl_MoveControlX( Window& rWindow, long nDelta )
770 {
771 Point aPos( rWindow.GetPosPixel() );
772 aPos.X() += nDelta;
773 rWindow.SetPosPixel( aPos );
774 }
775
lcl_MoveControlY(Window & rWindow,long nDelta)776 void lcl_MoveControlY( Window& rWindow, long nDelta )
777 {
778 Point aPos( rWindow.GetPosPixel() );
779 aPos.Y() += nDelta;
780 rWindow.SetPosPixel( aPos );
781 }
782
lcl_ChangeControlWidth(Window & rWindow,long nDelta)783 void lcl_ChangeControlWidth( Window& rWindow, long nDelta )
784 {
785 Size aSize( rWindow.GetSizePixel() );
786 aSize.Width() += nDelta;
787 rWindow.SetSizePixel( aSize );
788 }
789
lcl_ChangeControlHeight(Window & rWindow,long nDelta)790 void lcl_ChangeControlHeight( Window& rWindow, long nDelta )
791 {
792 Size aSize( rWindow.GetSizePixel() );
793 aSize.Height() += nDelta;
794 rWindow.SetSizePixel( aSize );
795 }
796
Resize()797 void ScConflictsDlg::Resize()
798 {
799 Size aSize( GetSizePixel() );
800 long nDeltaWidth = aSize.Width() - maDialogSize.Width();
801 long nDeltaHeight = aSize.Height() - maDialogSize.Height();
802 maDialogSize = aSize;
803
804 lcl_ChangeControlWidth( maFtConflicts, nDeltaWidth );
805
806 lcl_ChangeControlWidth( maLbConflicts, nDeltaWidth );
807 lcl_ChangeControlHeight( maLbConflicts, nDeltaHeight );
808
809 lcl_MoveControlX( maBtnKeepMine, nDeltaWidth / 2 );
810 lcl_MoveControlY( maBtnKeepMine, nDeltaHeight );
811
812 lcl_MoveControlX( maBtnKeepOther, nDeltaWidth / 2 );
813 lcl_MoveControlY( maBtnKeepOther, nDeltaHeight );
814
815 lcl_MoveControlY( maFlConflicts, nDeltaHeight );
816 lcl_ChangeControlWidth( maFlConflicts, nDeltaWidth );
817
818 lcl_MoveControlX( maBtnKeepAllMine, nDeltaWidth );
819 lcl_MoveControlY( maBtnKeepAllMine, nDeltaHeight );
820
821 lcl_MoveControlX( maBtnKeepAllOthers, nDeltaWidth );
822 lcl_MoveControlY( maBtnKeepAllOthers, nDeltaHeight );
823
824 lcl_MoveControlX( maBtnCancel, nDeltaWidth );
825 lcl_MoveControlY( maBtnCancel, nDeltaHeight );
826
827 lcl_MoveControlX( maBtnHelp, nDeltaWidth );
828 lcl_MoveControlY( maBtnHelp, nDeltaHeight );
829 }
830
UpdateView()831 void ScConflictsDlg::UpdateView()
832 {
833 ScConflictsList::iterator aEndItr = mrConflictsList.end();
834 for ( ScConflictsList::iterator aItr = mrConflictsList.begin(); aItr != aEndItr; ++aItr )
835 {
836 ScConflictsListEntry* pConflictEntry = &(*aItr);
837 if ( pConflictEntry && pConflictEntry->meConflictAction == SC_CONFLICT_ACTION_NONE )
838 {
839 RedlinData* pRootUserData = new RedlinData();
840 pRootUserData->pData = static_cast< void* >( pConflictEntry );
841 SvLBoxEntry* pRootEntry = maLbConflicts.InsertEntry( GetConflictString( *aItr ), pRootUserData );
842
843 ScChangeActionList::const_iterator aEndShared = aItr->maSharedActions.end();
844 for ( ScChangeActionList::const_iterator aItrShared = aItr->maSharedActions.begin(); aItrShared != aEndShared; ++aItrShared )
845 {
846 ScChangeAction* pAction = mpSharedTrack->GetAction( *aItrShared );
847 if ( pAction )
848 {
849 // only display shared top content entries
850 if ( pAction->GetType() == SC_CAT_CONTENT )
851 {
852 ScChangeActionContent* pNextContent = ( dynamic_cast< ScChangeActionContent* >( pAction ) )->GetNextContent();
853 if ( pNextContent && aItr->HasSharedAction( pNextContent->GetActionNumber() ) )
854 {
855 continue;
856 }
857 }
858
859 String aString( GetActionString( pAction, mpSharedDoc ) );
860 maLbConflicts.InsertEntry( aString, static_cast< RedlinData* >( NULL ), pRootEntry );
861 }
862 }
863
864 ScChangeActionList::const_iterator aEndOwn = aItr->maOwnActions.end();
865 for ( ScChangeActionList::const_iterator aItrOwn = aItr->maOwnActions.begin(); aItrOwn != aEndOwn; ++aItrOwn )
866 {
867 ScChangeAction* pAction = mpOwnTrack->GetAction( *aItrOwn );
868 if ( pAction )
869 {
870 // only display own top content entries
871 if ( pAction->GetType() == SC_CAT_CONTENT )
872 {
873 ScChangeActionContent* pNextContent = ( dynamic_cast< ScChangeActionContent* >( pAction ) )->GetNextContent();
874 if ( pNextContent && aItr->HasOwnAction( pNextContent->GetActionNumber() ) )
875 {
876 continue;
877 }
878 }
879
880 String aString( GetActionString( pAction, mpOwnDoc ) );
881 RedlinData* pUserData = new RedlinData();
882 pUserData->pData = static_cast< void* >( pAction );
883 maLbConflicts.InsertEntry( aString, pUserData, pRootEntry );
884 }
885 }
886
887 maLbConflicts.Expand( pRootEntry );
888 }
889 }
890 }
891