Update ooo320-m1
[ooovba.git] / applied_patches / 0158-calc-enhanced-merge-cells-sc.diff
blob3320a3be3d0f1f5d5645151489622b78193b5e10
1 diff --git sc/source/ui/docshell/docfunc.cxx sc/source/ui/docshell/docfunc.cxx
2 index 123a716..fde95e5 100644
3 --- sc/source/ui/docshell/docfunc.cxx
4 +++ sc/source/ui/docshell/docfunc.cxx
5 @@ -67,6 +67,7 @@
6 #include "attrib.hxx"
7 #include "autoform.hxx"
8 #include "cell.hxx"
9 +#include "cellmergeoption.hxx"
10 #include "detdata.hxx"
11 #include "detfunc.hxx"
12 #include "docpool.hxx"
13 @@ -101,6 +102,7 @@
14 #include "tabprotection.hxx"
16 #include <memory>
17 +#include <set>
19 using namespace com::sun::star;
20 using ::com::sun::star::uno::Sequence;
21 @@ -1693,7 +1693,11 @@ BOOL ScDocFunc::InsertCells( const ScRange& rRange, const ScMarkData* pTabMark,
22 default:
23 break;
25 - MergeCells(aRange, FALSE, TRUE, TRUE);
26 + ScCellMergeOption aMergeOption(
27 + aRange.aStart.Col(), aRange.aStart.Row(),
28 + aRange.aEnd.Col(), aRange.aEnd.Row() );
29 + aMergeOption.maTabs.insert(aRange.aStart.Tab());
30 + MergeCells(aMergeOption, FALSE, TRUE, TRUE);
32 qIncreaseRange.pop_back();
34 @@ -1742,7 +1746,10 @@ BOOL ScDocFunc::InsertCells( const ScRange& rRange, const ScMarkData* pTabMark,
35 while( !qIncreaseRange.empty() )
37 ScRange aRange = qIncreaseRange.back();
38 - MergeCells(aRange, FALSE, TRUE, TRUE);
39 + ScCellMergeOption aMergeOption(
40 + aRange.aStart.Col(), aRange.aStart.Row(),
41 + aRange.aEnd.Col(), aRange.aEnd.Row() );
42 + MergeCells(aMergeOption, FALSE, TRUE, TRUE);
43 qIncreaseRange.pop_back();
46 @@ -2180,7 +2187,10 @@ BOOL ScDocFunc::DeleteCells( const ScRange& rRange, const ScMarkData* pTabMark,
48 if( !pDoc->HasAttrib( aRange, HASATTR_OVERLAPPED | HASATTR_MERGED ) )
50 - MergeCells( aRange, FALSE, TRUE, TRUE );
51 + ScCellMergeOption aMergeOption(
52 + aRange.aStart.Col(), aRange.aStart.Row(),
53 + aRange.aEnd.Col(), aRange.aEnd.Row() );
54 + MergeCells( aMergeOption, FALSE, TRUE, TRUE );
56 qDecreaseRange.pop_back();
58 @@ -3974,86 +3976,110 @@ BOOL ScDocFunc::FillAuto( ScRange& rRange, const ScMarkData* pTabMark, FillDir e
60 //------------------------------------------------------------------------
62 -BOOL ScDocFunc::MergeCells( const ScRange& rRange, BOOL bContents, BOOL bRecord, BOOL bApi )
63 +BOOL ScDocFunc::MergeCells( const ScCellMergeOption& rOption, BOOL bContents, BOOL bRecord, BOOL bApi )
65 + using ::std::set;
67 ScDocShellModificator aModificator( rDocShell );
69 - ScDocument* pDoc = rDocShell.GetDocument();
70 - SCCOL nStartCol = rRange.aStart.Col();
71 - SCROW nStartRow = rRange.aStart.Row();
72 - SCCOL nEndCol = rRange.aEnd.Col();
73 - SCROW nEndRow = rRange.aEnd.Row();
74 - SCTAB nTab = rRange.aStart.Tab();
75 + SCCOL nStartCol = rOption.mnStartCol;
76 + SCROW nStartRow = rOption.mnStartRow;
77 + SCCOL nEndCol = rOption.mnEndCol;
78 + SCROW nEndRow = rOption.mnEndRow;
79 + if ((nStartCol == nEndCol && nStartRow == nEndRow) || rOption.maTabs.empty())
80 + {
81 + // Nothing to do. Bail out quick.
82 + return TRUE;
83 + }
85 + ScDocument* pDoc = rDocShell.GetDocument();
86 + set<SCTAB>::const_iterator itrBeg = rOption.maTabs.begin(), itrEnd = rOption.maTabs.end();
87 + SCTAB nTab1 = *itrBeg, nTab2 = *rOption.maTabs.rbegin();
89 if (bRecord && !pDoc->IsUndoEnabled())
90 bRecord = FALSE;
92 - ScEditableTester aTester( pDoc, nTab, nStartCol, nStartRow, nEndCol, nEndRow );
93 - if (!aTester.IsEditable())
94 - {
95 - if (!bApi)
96 - rDocShell.ErrorMessage(aTester.GetMessageId());
97 - return FALSE;
98 - }
99 + for (set<SCTAB>::const_iterator itr = itrBeg; itr != itrEnd; ++itr)
101 + ScEditableTester aTester( pDoc, *itr, nStartCol, nStartRow, nEndCol, nEndRow );
102 + if (!aTester.IsEditable())
104 + if (!bApi)
105 + rDocShell.ErrorMessage(aTester.GetMessageId());
106 + return FALSE;
109 - if ( nStartCol == nEndCol && nStartRow == nEndRow )
111 - // nichts zu tun
112 - return TRUE;
114 + if ( pDoc->HasAttrib( nStartCol, nStartRow, *itr, nEndCol, nEndRow, *itr,
115 + HASATTR_MERGED | HASATTR_OVERLAPPED ) )
117 + // "Zusammenfassen nicht verschachteln !"
118 + if (!bApi)
119 + rDocShell.ErrorMessage(STR_MSSG_MERGECELLS_0);
120 + return FALSE;
124 - if ( pDoc->HasAttrib( nStartCol, nStartRow, nTab, nEndCol, nEndRow, nTab,
125 - HASATTR_MERGED | HASATTR_OVERLAPPED ) )
127 - // "Zusammenfassen nicht verschachteln !"
128 - if (!bApi)
129 - rDocShell.ErrorMessage(STR_MSSG_MERGECELLS_0);
130 - return FALSE;
132 + ScDocument* pUndoDoc = NULL;
133 + bool bNeedContentsUndo = false;
134 + for (set<SCTAB>::const_iterator itr = itrBeg; itr != itrEnd; ++itr)
136 + SCTAB nTab = *itr;
137 + bool bNeedContents = bContents &&
138 + ( !pDoc->IsBlockEmpty( nTab, nStartCol,nStartRow+1, nStartCol,nEndRow, true ) ||
139 + !pDoc->IsBlockEmpty( nTab, nStartCol+1,nStartRow, nEndCol,nEndRow, true ) );
141 + if (bRecord)
143 + // test if the range contains other notes which also implies that we need an undo document
144 + bool bHasNotes = false;
145 + for( ScAddress aPos( nStartCol, nStartRow, nTab ); !bHasNotes && (aPos.Col() <= nEndCol); aPos.IncCol() )
146 + for( aPos.SetRow( nStartRow ); !bHasNotes && (aPos.Row() <= nEndRow); aPos.IncRow() )
147 + bHasNotes = ((aPos.Col() != nStartCol) || (aPos.Row() != nStartRow)) && (pDoc->GetNote( aPos ) != 0);
149 - BOOL bNeedContents = bContents &&
150 - ( !pDoc->IsBlockEmpty( nTab, nStartCol,nStartRow+1, nStartCol,nEndRow, true ) ||
151 - !pDoc->IsBlockEmpty( nTab, nStartCol+1,nStartRow, nEndCol,nEndRow, true ) );
152 + if (bNeedContents || bHasNotes || rOption.mbCenter)
154 + if (!pUndoDoc)
156 + pUndoDoc = new ScDocument( SCDOCMODE_UNDO );
157 + pUndoDoc->InitUndo(pDoc, nTab1, nTab2);
159 + // note captions are collected by drawing undo
160 + pDoc->CopyToDocument( nStartCol, nStartRow, nTab, nEndCol, nEndRow, nTab,
161 + IDF_ALL|IDF_NOCAPTIONS, FALSE, pUndoDoc );
163 + if( bHasNotes )
164 + pDoc->BeginDrawUndo();
167 - ScDocument* pUndoDoc = 0;
168 - if (bRecord)
170 - // test if the range contains other notes which also implies that we need an undo document
171 - bool bHasNotes = false;
172 - for( ScAddress aPos( nStartCol, nStartRow, nTab ); !bHasNotes && (aPos.Col() <= nEndCol); aPos.IncCol() )
173 - for( aPos.SetRow( nStartRow ); !bHasNotes && (aPos.Row() <= nEndRow); aPos.IncRow() )
174 - bHasNotes = ((aPos.Col() != nStartCol) || (aPos.Row() != nStartRow)) && (pDoc->GetNote( aPos ) != 0);
175 + if (bNeedContents)
176 + pDoc->DoMergeContents( nTab, nStartCol,nStartRow, nEndCol,nEndRow );
177 + pDoc->DoMerge( nTab, nStartCol,nStartRow, nEndCol,nEndRow );
179 + if (rOption.mbCenter)
181 + pDoc->ApplyAttr( nStartCol, nStartRow, nTab, SvxHorJustifyItem( SVX_HOR_JUSTIFY_CENTER, ATTR_HOR_JUSTIFY ) );
182 + pDoc->ApplyAttr( nStartCol, nStartRow, nTab, SvxVerJustifyItem( SVX_VER_JUSTIFY_CENTER, ATTR_VER_JUSTIFY ) );
185 - if (bNeedContents || bHasNotes)
187 - pUndoDoc = new ScDocument( SCDOCMODE_UNDO );
188 - pUndoDoc->InitUndo( pDoc, nTab, nTab );
189 - // note captions are collected by drawing undo
190 - pDoc->CopyToDocument( nStartCol, nStartRow, nTab, nEndCol, nEndRow, nTab,
191 - IDF_ALL|IDF_NOCAPTIONS, FALSE, pUndoDoc );
193 - if( bHasNotes )
194 - pDoc->BeginDrawUndo();
196 + if ( !AdjustRowHeight( ScRange( 0,nStartRow,nTab, MAXCOL,nEndRow,nTab ) ) )
197 + rDocShell.PostPaint( nStartCol, nStartRow, nTab,
198 + nEndCol, nEndRow, nTab, PAINT_GRID );
199 + if (bNeedContents || rOption.mbCenter)
200 + {
201 + ScRange aRange(nStartCol, nStartRow, nTab, nEndCol, nEndRow, nTab);
202 + pDoc->SetDirty(aRange);
205 - if (bNeedContents)
206 - pDoc->DoMergeContents( nTab, nStartCol,nStartRow, nEndCol,nEndRow );
207 - pDoc->DoMerge( nTab, nStartCol,nStartRow, nEndCol,nEndRow );
208 + bNeedContentsUndo |= bNeedContents;
211 - if( bRecord )
212 + if (pUndoDoc)
214 - SdrUndoGroup* pDrawUndo = pDoc->GetDrawLayer() ? pDoc->GetDrawLayer()->GetCalcUndo() : 0;
215 + SdrUndoGroup* pDrawUndo = pDoc->GetDrawLayer() ? pDoc->GetDrawLayer()->GetCalcUndo() : NULL;
216 rDocShell.GetUndoManager()->AddUndoAction(
217 - new ScUndoMerge( &rDocShell,
218 - nStartCol, nStartRow, nTab,
219 - nEndCol, nEndRow, nTab, bNeedContents, pUndoDoc, pDrawUndo ) );
220 + new ScUndoMerge(&rDocShell, rOption, bNeedContentsUndo, pUndoDoc, pDrawUndo) );
223 - if ( !AdjustRowHeight( ScRange( 0,nStartRow,nTab, MAXCOL,nEndRow,nTab ) ) )
224 - rDocShell.PostPaint( nStartCol, nStartRow, nTab,
225 - nEndCol, nEndRow, nTab, PAINT_GRID );
226 - if (bNeedContents)
227 - pDoc->SetDirty( rRange );
228 aModificator.SetDocumentModified();
230 SfxBindings* pBindings = rDocShell.GetViewBindings();
231 @@ -4069,49 +4095,81 @@ BOOL ScDocFunc::MergeCells( const ScRange& rRange, BOOL bContents, BOOL bRecord,
233 BOOL ScDocFunc::UnmergeCells( const ScRange& rRange, BOOL bRecord, BOOL bApi )
235 - ScDocShellModificator aModificator( rDocShell );
236 + ScCellMergeOption aOption(rRange.aStart.Col(), rRange.aStart.Row(), rRange.aEnd.Col(), rRange.aEnd.Row());
237 + SCTAB nTab1 = rRange.aStart.Tab(), nTab2 = rRange.aEnd.Tab();
238 + for (SCTAB i = nTab1; i <= nTab2; ++i)
239 + aOption.maTabs.insert(i);
241 + return UnmergeCells(aOption, bRecord, bApi);
244 +bool ScDocFunc::UnmergeCells( const ScCellMergeOption& rOption, BOOL bRecord, BOOL bApi )
246 + using ::std::set;
248 + if (rOption.maTabs.empty())
249 + // Nothing to unmerge.
250 + return true;
252 + ScDocShellModificator aModificator( rDocShell );
253 ScDocument* pDoc = rDocShell.GetDocument();
254 - SCTAB nTab = rRange.aStart.Tab();
256 if (bRecord && !pDoc->IsUndoEnabled())
257 bRecord = FALSE;
259 - if ( pDoc->HasAttrib( rRange, HASATTR_MERGED ) )
261 - ScRange aExtended = rRange;
262 - pDoc->ExtendMerge( aExtended );
263 - ScRange aRefresh = aExtended;
264 - pDoc->ExtendOverlapped( aRefresh );
265 + ScDocument* pUndoDoc = NULL;
266 + bool bBeep = false;
267 + for (set<SCTAB>::const_iterator itr = rOption.maTabs.begin(), itrEnd = rOption.maTabs.end();
268 + itr != itrEnd; ++itr)
270 + SCTAB nTab = *itr;
271 + ScRange aRange = rOption.getSingleRange(nTab);
272 + if ( !pDoc->HasAttrib(aRange, HASATTR_MERGED) )
274 + bBeep = true;
275 + continue;
278 - if (bRecord)
280 - ScDocument* pUndoDoc = new ScDocument( SCDOCMODE_UNDO );
281 - pUndoDoc->InitUndo( pDoc, nTab, nTab );
282 - pDoc->CopyToDocument( aExtended, IDF_ATTRIB, FALSE, pUndoDoc );
283 - rDocShell.GetUndoManager()->AddUndoAction(
284 - new ScUndoRemoveMerge( &rDocShell, rRange, pUndoDoc ) );
286 + ScRange aExtended = aRange;
287 + pDoc->ExtendMerge(aExtended);
288 + ScRange aRefresh = aExtended;
289 + pDoc->ExtendOverlapped(aRefresh);
291 - const SfxPoolItem& rDefAttr = pDoc->GetPool()->GetDefaultItem( ATTR_MERGE );
292 - ScPatternAttr aPattern( pDoc->GetPool() );
293 - aPattern.GetItemSet().Put( rDefAttr );
294 - pDoc->ApplyPatternAreaTab( rRange.aStart.Col(), rRange.aStart.Row(),
295 - rRange.aEnd.Col(), rRange.aEnd.Row(), nTab,
296 - aPattern );
297 + if (bRecord)
299 + if (!pUndoDoc)
301 + pUndoDoc = new ScDocument( SCDOCMODE_UNDO );
302 + pUndoDoc->InitUndo(pDoc, *rOption.maTabs.begin(), *rOption.maTabs.rbegin());
304 + pDoc->CopyToDocument(aExtended, IDF_ATTRIB, FALSE, pUndoDoc);
307 - pDoc->RemoveFlagsTab( aExtended.aStart.Col(), aExtended.aStart.Row(),
308 - aExtended.aEnd.Col(), aExtended.aEnd.Row(), nTab,
309 - SC_MF_HOR | SC_MF_VER );
310 + const SfxPoolItem& rDefAttr = pDoc->GetPool()->GetDefaultItem( ATTR_MERGE );
311 + ScPatternAttr aPattern( pDoc->GetPool() );
312 + aPattern.GetItemSet().Put( rDefAttr );
313 + pDoc->ApplyPatternAreaTab( aRange.aStart.Col(), aRange.aStart.Row(),
314 + aRange.aEnd.Col(), aRange.aEnd.Row(), nTab,
315 + aPattern );
317 - pDoc->ExtendMerge( aRefresh, TRUE, FALSE );
318 + pDoc->RemoveFlagsTab( aExtended.aStart.Col(), aExtended.aStart.Row(),
319 + aExtended.aEnd.Col(), aExtended.aEnd.Row(), nTab,
320 + SC_MF_HOR | SC_MF_VER );
322 - if ( !AdjustRowHeight( aExtended ) )
323 - rDocShell.PostPaint( aExtended, PAINT_GRID );
324 - aModificator.SetDocumentModified();
326 - else if (!bApi)
327 - Sound::Beep(); //! FALSE zurueck???
328 + pDoc->ExtendMerge( aRefresh, TRUE, FALSE );
330 + if ( !AdjustRowHeight( aExtended ) )
331 + rDocShell.PostPaint( aExtended, PAINT_GRID );
333 + if (bBeep && !bApi)
334 + Sound::Beep();
336 + if (bRecord)
338 + rDocShell.GetUndoManager()->AddUndoAction(
339 + new ScUndoRemoveMerge( &rDocShell, rOption, pUndoDoc ) );
341 + aModificator.SetDocumentModified();
343 return TRUE;
345 diff --git sc/source/ui/inc/cellmergeoption.hxx sc/source/ui/inc/cellmergeoption.hxx
346 new file mode 100644
347 index 0000000..2e2dff2
348 --- /dev/null
349 +++ sc/source/ui/inc/cellmergeoption.hxx
350 @@ -0,0 +1,60 @@
351 +/*************************************************************************
353 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
354 + *
355 + * Copyright 2008 by Sun Microsystems, Inc.
357 + * OpenOffice.org - a multi-platform office productivity suite
359 + * $RCSfile: docfunc.hxx,v $
360 + * $Revision: 1.18.30.2 $
362 + * This file is part of OpenOffice.org.
364 + * OpenOffice.org is free software: you can redistribute it and/or modify
365 + * it under the terms of the GNU Lesser General Public License version 3
366 + * only, as published by the Free Software Foundation.
368 + * OpenOffice.org is distributed in the hope that it will be useful,
369 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
370 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
371 + * GNU Lesser General Public License version 3 for more details
372 + * (a copy is included in the LICENSE file that accompanied this code).
374 + * You should have received a copy of the GNU Lesser General Public License
375 + * version 3 along with OpenOffice.org. If not, see
376 + * <http://www.openoffice.org/license.html>
377 + * for a copy of the LGPLv3 License.
379 + ************************************************************************/
381 +#ifndef SC_CELLMERGEOPTION_HXX
382 +#define SC_CELLMERGEOPTION_HXX
384 +#include "address.hxx"
386 +#include <set>
388 +class ScRange;
390 +struct ScCellMergeOption
392 + ::std::set<SCTAB> maTabs;
393 + SCCOL mnStartCol;
394 + SCROW mnStartRow;
395 + SCCOL mnEndCol;
396 + SCROW mnEndRow;
397 + bool mbCenter;
399 + explicit ScCellMergeOption();
400 + explicit ScCellMergeOption(SCCOL nStartCol, SCROW nStartRow,
401 + SCCOL nEndCol, SCROW nEndRow,
402 + bool bCenter = false);
403 + explicit ScCellMergeOption(const ScCellMergeOption& r);
405 + ScRange getSingleRange(SCTAB nTab) const;
406 + ScRange getFirstSingleRange() const;
410 +#endif
411 diff --git sc/source/ui/inc/docfunc.hxx sc/source/ui/inc/docfunc.hxx
412 index 8490bab..9976230 100644
413 --- sc/source/ui/inc/docfunc.hxx
414 +++ sc/source/ui/inc/docfunc.hxx
415 @@ -49,6 +49,7 @@ class ScBaseCell;
416 class ScTokenArray;
417 struct ScTabOpParam;
418 class ScTableProtection;
419 +struct ScCellMergeOption;
421 // ---------------------------------------------------------------------------
423 @@ -172,9 +173,10 @@ public:
425 BOOL ResizeMatrix( const ScRange& rOldRange, const ScAddress& rNewEnd, BOOL bApi );
427 - BOOL MergeCells( const ScRange& rRange, BOOL bContents,
428 + BOOL MergeCells( const ScCellMergeOption& rOption, BOOL bContents,
429 BOOL bRecord, BOOL bApi );
430 - BOOL UnmergeCells( const ScRange& rRange, BOOL bRecord, BOOL bApi );
431 + BOOL UnmergeCells( const ScRange& rRange, BOOL bRecord, BOOL bApi );
432 + bool UnmergeCells( const ScCellMergeOption& rOption, BOOL bRecord, BOOL bApi );
434 BOOL SetNewRangeNames( ScRangeName* pNewRanges, BOOL bApi ); // takes ownership of pNewRanges
435 BOOL ModifyRangeNames( const ScRangeName& rNewRanges, BOOL bApi );
436 diff --git sc/source/ui/inc/undoblk.hxx sc/source/ui/inc/undoblk.hxx
437 index 31932fd..2320502 100644
438 --- sc/source/ui/inc/undoblk.hxx
439 +++ sc/source/ui/inc/undoblk.hxx
440 @@ -34,6 +34,7 @@
441 #include "markdata.hxx"
442 #include "viewutil.hxx"
443 #include "spellparam.hxx"
444 +#include "cellmergeoption.hxx"
446 #include "cell.hxx"
448 @@ -454,10 +455,8 @@ class ScUndoMerge: public ScSimpleUndo
450 public:
451 TYPEINFO();
452 - ScUndoMerge( ScDocShell* pNewDocShell,
453 - SCCOL nStartX, SCROW nStartY, SCTAB nStartZ,
454 - SCCOL nEndX, SCROW nEndY, SCTAB nEndZ,
455 - bool bMergeContents, ScDocument* pUndoDoc, SdrUndoAction* pDrawUndo );
456 + ScUndoMerge( ScDocShell* pNewDocShell, const ScCellMergeOption& rOption,
457 + bool bMergeContents, ScDocument* pUndoDoc, SdrUndoAction* pDrawUndo);
458 virtual ~ScUndoMerge();
460 virtual void Undo();
461 @@ -468,7 +467,7 @@ public:
462 virtual String GetComment() const;
464 private:
465 - ScRange maRange;
466 + ScCellMergeOption maOption;
467 bool mbMergeContents; // Merge contents in Redo().
468 ScDocument* mpUndoDoc; // wenn Daten zusammengefasst
469 SdrUndoAction* mpDrawUndo;
470 @@ -920,7 +919,7 @@ class ScUndoRemoveMerge: public ScBlockUndo
471 public:
472 TYPEINFO();
473 ScUndoRemoveMerge( ScDocShell* pNewDocShell,
474 - const ScRange& rArea,
475 + const ScCellMergeOption& rOption,
476 ScDocument* pNewUndoDoc );
477 virtual ~ScUndoRemoveMerge();
479 @@ -932,6 +931,9 @@ public:
480 virtual String GetComment() const;
482 private:
483 + void SetCurTab();
485 + ScCellMergeOption maOption;
486 ScDocument* pUndoDoc;
489 diff --git sc/source/ui/inc/viewfunc.hxx sc/source/ui/inc/viewfunc.hxx
490 index 1f5102e..051a705 100644
491 --- sc/source/ui/inc/viewfunc.hxx
492 +++ sc/source/ui/inc/viewfunc.hxx
493 @@ -242,7 +242,7 @@ public:
494 BOOL TestMergeCells();
495 BOOL TestRemoveMerge();
497 - BOOL MergeCells( BOOL bApi, BOOL& rDoContents, BOOL bRecord = TRUE );
498 + BOOL MergeCells( BOOL bApi, BOOL& rDoContents, BOOL bRecord = TRUE, BOOL bCenter = FALSE );
499 BOOL RemoveMerge( BOOL bRecord = TRUE );
501 void FillSimple( FillDir eDir, BOOL bRecord = TRUE );
502 diff --git sc/source/ui/undo/undoblk.cxx sc/source/ui/undo/undoblk.cxx
503 index 5b3e219..fe2c7bc 100644
504 --- sc/source/ui/undo/undoblk.cxx
505 +++ sc/source/ui/undo/undoblk.cxx
506 @@ -66,6 +66,7 @@
507 #include "undoolk.hxx"
508 #include "sc.hrc"
510 +#include <set>
512 // STATIC DATA -----------------------------------------------------------
514 @@ -2066,8 +2067,9 @@ BOOL __EXPORT ScUndoRemoveBreaks::CanRepeat(SfxRepeatTarget& rTarget) const
517 ScUndoRemoveMerge::ScUndoRemoveMerge( ScDocShell* pNewDocShell,
518 - const ScRange& rArea, ScDocument* pNewUndoDoc ) :
519 - ScBlockUndo( pNewDocShell, rArea, SC_UNDO_SIMPLE ),
520 + const ScCellMergeOption& rOption, ScDocument* pNewUndoDoc ) :
521 + ScBlockUndo( pNewDocShell, rOption.getFirstSingleRange(), SC_UNDO_SIMPLE ),
522 + maOption(rOption),
523 pUndoDoc( pNewUndoDoc )
526 @@ -2084,66 +2086,78 @@ String __EXPORT ScUndoRemoveMerge::GetComment() const
528 void __EXPORT ScUndoRemoveMerge::Undo()
530 - BeginUndo();
532 - ScDocument* pDoc = pDocShell->GetDocument();
533 + using ::std::set;
535 - ScRange aExtended = aBlockRange;
536 - pUndoDoc->ExtendMerge( aExtended );
537 + SetCurTab();
538 + BeginUndo();
540 - pDoc->DeleteAreaTab( aExtended, IDF_ATTRIB );
541 - pUndoDoc->CopyToDocument( aExtended, IDF_ATTRIB, FALSE, pDoc );
542 + ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
544 - BOOL bDidPaint = FALSE;
545 - ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
546 - if ( pViewShell )
548 - pViewShell->SetTabNo( aExtended.aStart.Tab() );
549 - bDidPaint = pViewShell->AdjustRowHeight( aExtended.aStart.Row(), aExtended.aEnd.Row() );
551 - if (!bDidPaint)
552 - ScUndoUtil::PaintMore( pDocShell, aExtended );
553 + ScDocument* pDoc = pDocShell->GetDocument();
554 + for (set<SCTAB>::const_iterator itr = maOption.maTabs.begin(), itrEnd = maOption.maTabs.end();
555 + itr != itrEnd; ++itr)
557 + // There is no need to extend merge area because it's already been extended.
558 + ScRange aRange = maOption.getSingleRange(*itr);
559 + pDoc->DeleteAreaTab(aRange, IDF_ATTRIB);
560 + pUndoDoc->CopyToDocument(aRange, IDF_ATTRIB, FALSE, pDoc);
562 + bool bDidPaint = false;
563 + if ( pViewShell )
565 + pViewShell->SetTabNo(*itr);
566 + bDidPaint = pViewShell->AdjustRowHeight(maOption.mnStartRow, maOption.mnEndRow);
568 + if (!bDidPaint)
569 + ScUndoUtil::PaintMore(pDocShell, aRange);
572 EndUndo();
575 void __EXPORT ScUndoRemoveMerge::Redo()
577 + using ::std::set;
579 + SetCurTab();
580 BeginRedo();
582 - SCTAB nTab = aBlockRange.aStart.Tab();
583 ScDocument* pDoc = pDocShell->GetDocument();
584 - ScRange aExtended = aBlockRange;
585 - pDoc->ExtendMerge( aExtended );
586 - ScRange aRefresh = aExtended;
587 - pDoc->ExtendOverlapped( aRefresh );
589 - // ausfuehren
591 - const SfxPoolItem& rDefAttr = pDoc->GetPool()->GetDefaultItem( ATTR_MERGE );
592 - ScPatternAttr aPattern( pDoc->GetPool() );
593 - aPattern.GetItemSet().Put( rDefAttr );
594 - pDoc->ApplyPatternAreaTab( aBlockRange.aStart.Col(), aBlockRange.aStart.Row(),
595 - aBlockRange.aEnd.Col(), aBlockRange.aEnd.Row(), nTab,
596 - aPattern );
598 - pDoc->RemoveFlagsTab( aExtended.aStart.Col(), aExtended.aStart.Row(),
599 - aExtended.aEnd.Col(), aExtended.aEnd.Row(), nTab,
600 - SC_MF_HOR | SC_MF_VER );
602 - pDoc->ExtendMerge( aRefresh, TRUE, FALSE );
604 - // Paint
605 + ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
607 - BOOL bDidPaint = FALSE;
608 - ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
609 - if ( pViewShell )
611 - pViewShell->SetTabNo( aExtended.aStart.Tab() );
612 - bDidPaint = pViewShell->AdjustRowHeight( aExtended.aStart.Row(), aExtended.aEnd.Row() );
614 - if (!bDidPaint)
615 - ScUndoUtil::PaintMore( pDocShell, aExtended );
616 + for (set<SCTAB>::const_iterator itr = maOption.maTabs.begin(), itrEnd = maOption.maTabs.end();
617 + itr != itrEnd; ++itr)
619 + SCTAB nTab = *itr;
620 + // There is no need to extend merge area because it's already been extended.
621 + ScRange aRange = maOption.getSingleRange(nTab);
623 + // ausfuehren
625 + const SfxPoolItem& rDefAttr = pDoc->GetPool()->GetDefaultItem( ATTR_MERGE );
626 + ScPatternAttr aPattern( pDoc->GetPool() );
627 + aPattern.GetItemSet().Put( rDefAttr );
628 + pDoc->ApplyPatternAreaTab( maOption.mnStartCol, maOption.mnStartRow,
629 + maOption.mnEndCol, maOption.mnEndRow, nTab,
630 + aPattern );
632 + pDoc->RemoveFlagsTab( maOption.mnStartCol, maOption.mnStartRow,
633 + maOption.mnEndCol, maOption.mnEndRow, nTab,
634 + SC_MF_HOR | SC_MF_VER );
636 + pDoc->ExtendMerge(aRange, TRUE, FALSE);
638 + // Paint
640 + BOOL bDidPaint = FALSE;
641 + if ( pViewShell )
643 + pViewShell->SetTabNo(nTab);
644 + bDidPaint = pViewShell->AdjustRowHeight(maOption.mnStartRow, maOption.mnEndRow);
646 + if (!bDidPaint)
647 + ScUndoUtil::PaintMore(pDocShell, aRange);
650 EndRedo();
652 @@ -2159,6 +2173,13 @@ BOOL __EXPORT ScUndoRemoveMerge::CanRepeat(SfxRepeatTarget& rTarget) const
653 return (rTarget.ISA(ScTabViewTarget));
656 +void ScUndoRemoveMerge::SetCurTab()
658 + SCTAB nCurTab = pDocShell->GetCurTab();
659 + aBlockRange.aStart.SetTab(nCurTab);
660 + aBlockRange.aEnd.SetTab(nCurTab);
663 // -----------------------------------------------------------------------
665 // nur Umrandung setzen, per ScRangeList (StarOne)
666 diff --git sc/source/ui/undo/undoblk3.cxx sc/source/ui/undo/undoblk3.cxx
667 index 5521813..f3f006c 100644
668 --- sc/source/ui/undo/undoblk3.cxx
669 +++ sc/source/ui/undo/undoblk3.cxx
670 @@ -34,6 +34,7 @@
671 // INCLUDE -------------------------------------------------------------------
673 #include "scitems.hxx"
674 +#include <svx/algitem.hxx>
675 #include <svx/boxitem.hxx>
676 #include <svx/srchitem.hxx>
677 #include <svx/linkmgr.hxx>
678 @@ -814,14 +815,12 @@ BOOL __EXPORT ScUndoAutoFill::CanRepeat(SfxRepeatTarget& rTarget) const
680 //----------------------------------------------------------------------------
682 -ScUndoMerge::ScUndoMerge( ScDocShell* pNewDocShell,
683 - SCCOL nStartX, SCROW nStartY, SCTAB nStartZ,
684 - SCCOL nEndX, SCROW nEndY, SCTAB nEndZ,
685 - bool bMergeContents, ScDocument* pUndoDoc, SdrUndoAction* pDrawUndo )
686 +ScUndoMerge::ScUndoMerge( ScDocShell* pNewDocShell, const ScCellMergeOption& rOption,
687 + bool bMergeContents, ScDocument* pUndoDoc, SdrUndoAction* pDrawUndo )
689 : ScSimpleUndo( pNewDocShell ),
691 - maRange( nStartX, nStartY, nStartZ, nEndX, nEndY, nEndZ ),
692 + maOption(rOption),
693 mbMergeContents( bMergeContents ),
694 mpUndoDoc( pUndoDoc ),
695 mpDrawUndo( pDrawUndo )
696 @@ -850,51 +849,77 @@ String ScUndoMerge::GetComment() const
698 void ScUndoMerge::DoChange( bool bUndo ) const
700 - ScDocument* pDoc = pDocShell->GetDocument();
701 + using ::std::set;
703 - ScUndoUtil::MarkSimpleBlock( pDocShell, maRange );
704 + if (maOption.maTabs.empty())
705 + // Nothing to do.
706 + return;
708 - if (bUndo)
709 - // remove merge (contents are copied back below from undo document)
710 - pDoc->RemoveMerge( maRange.aStart.Col(), maRange.aStart.Row(), maRange.aStart.Tab() );
711 - else
712 - // repeat merge, but do not remove note captions (will be done by drawing redo below)
713 -/*!*/ pDoc->DoMerge( maRange.aStart.Tab(),
714 - maRange.aStart.Col(), maRange.aStart.Row(),
715 - maRange.aEnd.Col(), maRange.aEnd.Row(), false );
716 + ScDocument* pDoc = pDocShell->GetDocument();
717 + ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
719 - // undo -> copy back deleted contents
720 - if (bUndo && mpUndoDoc)
722 - pDoc->DeleteAreaTab( maRange, IDF_CONTENTS|IDF_NOCAPTIONS );
723 - mpUndoDoc->CopyToDocument( maRange, IDF_ALL|IDF_NOCAPTIONS, FALSE, pDoc );
725 + ScRange aCurRange = maOption.getSingleRange(pDocShell->GetCurTab());
726 + ScUndoUtil::MarkSimpleBlock(pDocShell, aCurRange);
728 + for (set<SCTAB>::const_iterator itr = maOption.maTabs.begin(), itrEnd = maOption.maTabs.end();
729 + itr != itrEnd; ++itr)
730 + {
731 + SCTAB nTab = *itr;
732 + ScRange aRange = maOption.getSingleRange(nTab);
734 - // redo -> merge contents again
735 - else if (!bUndo && mbMergeContents)
737 -/*!*/ pDoc->DoMergeContents( maRange.aStart.Tab(),
738 - maRange.aStart.Col(), maRange.aStart.Row(),
739 - maRange.aEnd.Col(), maRange.aEnd.Row() );
740 + if (bUndo)
741 + // remove merge (contents are copied back below from undo document)
742 + pDoc->RemoveMerge( aRange.aStart.Col(), aRange.aStart.Row(), aRange.aStart.Tab() );
743 + else
744 + {
745 + // repeat merge, but do not remove note captions (will be done by drawing redo below)
746 + pDoc->DoMerge( aRange.aStart.Tab(),
747 + aRange.aStart.Col(), aRange.aStart.Row(),
748 + aRange.aEnd.Col(), aRange.aEnd.Row(), false );
750 + if (maOption.mbCenter)
752 + pDoc->ApplyAttr( aRange.aStart.Col(), aRange.aStart.Row(),
753 + aRange.aStart.Tab(),
754 + SvxHorJustifyItem( SVX_HOR_JUSTIFY_CENTER, ATTR_HOR_JUSTIFY ) );
755 + pDoc->ApplyAttr( aRange.aStart.Col(), aRange.aStart.Row(),
756 + aRange.aStart.Tab(),
757 + SvxVerJustifyItem( SVX_VER_JUSTIFY_CENTER, ATTR_VER_JUSTIFY ) );
761 + // undo -> copy back deleted contents
762 + if (bUndo && mpUndoDoc)
764 + pDoc->DeleteAreaTab( aRange, IDF_CONTENTS|IDF_NOCAPTIONS );
765 + mpUndoDoc->CopyToDocument( aRange, IDF_ALL|IDF_NOCAPTIONS, FALSE, pDoc );
768 + // redo -> merge contents again
769 + else if (!bUndo && mbMergeContents)
771 + pDoc->DoMergeContents( aRange.aStart.Tab(),
772 + aRange.aStart.Col(), aRange.aStart.Row(),
773 + aRange.aEnd.Col(), aRange.aEnd.Row() );
776 + if (bUndo)
777 + DoSdrUndoAction( mpDrawUndo, pDoc );
778 + else
779 + RedoSdrUndoAction( mpDrawUndo );
781 + bool bDidPaint = false;
782 + if ( pViewShell )
784 + pViewShell->SetTabNo(nTab);
785 + bDidPaint = pViewShell->AdjustRowHeight(maOption.mnStartRow, maOption.mnEndRow);
788 + if (!bDidPaint)
789 + ScUndoUtil::PaintMore(pDocShell, aRange);
792 - if (bUndo)
793 - DoSdrUndoAction( mpDrawUndo, pDoc );
794 - else
795 - RedoSdrUndoAction( mpDrawUndo );
797 - BOOL bDidPaint = FALSE;
798 - ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
799 - if ( pViewShell )
801 - pViewShell->SetTabNo( maRange.aStart.Tab() );
802 - bDidPaint = pViewShell->AdjustRowHeight( maRange.aStart.Row(), maRange.aEnd.Row() );
805 - if (!bDidPaint)
806 - ScUndoUtil::PaintMore( pDocShell, maRange );
808 - ShowTable( maRange );
809 + ShowTable(aCurRange);
813 diff --git sc/source/ui/unoobj/cellsuno.cxx sc/source/ui/unoobj/cellsuno.cxx
814 index c2eb810..d4cfb42 100644
815 --- sc/source/ui/unoobj/cellsuno.cxx
816 +++ sc/source/ui/unoobj/cellsuno.cxx
817 @@ -71,6 +71,7 @@
818 #include <com/sun/star/text/WritingMode2.hpp>
820 #include "autoform.hxx"
821 +#include "cellmergeoption.hxx"
822 #include "cellsuno.hxx"
823 #include "cursuno.hxx"
824 #include "textuno.hxx"
825 @@ -5404,10 +5405,14 @@ void SAL_CALL ScCellRangeObj::merge( sal_Bool bMerge ) throw(uno::RuntimeExcepti
826 if ( pDocSh )
828 ScDocFunc aFunc(*pDocSh);
829 + ScCellMergeOption aMergeOption(
830 + aRange.aStart.Col(), aRange.aStart.Row(),
831 + aRange.aEnd.Col(), aRange.aEnd.Row(), false);
832 + aMergeOption.maTabs.insert(aRange.aStart.Tab());
833 if ( bMerge )
834 - aFunc.MergeCells( aRange, FALSE, TRUE, TRUE );
835 + aFunc.MergeCells( aMergeOption, FALSE, TRUE, TRUE );
836 else
837 - aFunc.UnmergeCells( aRange, TRUE, TRUE );
838 + aFunc.UnmergeCells( aMergeOption, TRUE, TRUE );
840 //! Fehler abfangen?
842 diff --git sc/source/ui/view/cellmergeoption.cxx sc/source/ui/view/cellmergeoption.cxx
843 new file mode 100644
844 index 0000000..ed6b8cb
845 --- /dev/null
846 +++ sc/source/ui/view/cellmergeoption.cxx
847 @@ -0,0 +1,74 @@
848 +/*************************************************************************
850 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
851 + *
852 + * Copyright 2008 by Sun Microsystems, Inc.
854 + * OpenOffice.org - a multi-platform office productivity suite
856 + * $RCSfile: docfunc.hxx,v $
857 + * $Revision: 1.18.30.2 $
859 + * This file is part of OpenOffice.org.
861 + * OpenOffice.org is free software: you can redistribute it and/or modify
862 + * it under the terms of the GNU Lesser General Public License version 3
863 + * only, as published by the Free Software Foundation.
865 + * OpenOffice.org is distributed in the hope that it will be useful,
866 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
867 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
868 + * GNU Lesser General Public License version 3 for more details
869 + * (a copy is included in the LICENSE file that accompanied this code).
871 + * You should have received a copy of the GNU Lesser General Public License
872 + * version 3 along with OpenOffice.org. If not, see
873 + * <http://www.openoffice.org/license.html>
874 + * for a copy of the LGPLv3 License.
876 + ************************************************************************/
878 +#include "cellmergeoption.hxx"
879 +#include "address.hxx"
881 +ScCellMergeOption::ScCellMergeOption() :
882 + mnStartCol(0),
883 + mnStartRow(0),
884 + mnEndCol(0),
885 + mnEndRow(0),
886 + mbCenter(false)
890 +ScCellMergeOption::ScCellMergeOption(SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, bool bCenter) :
891 + mnStartCol(nStartCol),
892 + mnStartRow(nStartRow),
893 + mnEndCol(nEndCol),
894 + mnEndRow(nEndRow),
895 + mbCenter(bCenter)
899 +ScCellMergeOption::ScCellMergeOption(const ScCellMergeOption& r) :
900 + maTabs(r.maTabs),
901 + mnStartCol(r.mnStartCol),
902 + mnStartRow(r.mnStartRow),
903 + mnEndCol(r.mnEndCol),
904 + mnEndRow(r.mnEndRow),
905 + mbCenter(r.mbCenter)
909 +ScRange ScCellMergeOption::getSingleRange(SCTAB nTab) const
911 + return ScRange(mnStartCol, mnStartRow, nTab, mnEndCol, mnEndRow, nTab);
914 +ScRange ScCellMergeOption::getFirstSingleRange() const
916 + SCTAB nTab = 0;
917 + if (!maTabs.empty())
918 + nTab = *maTabs.begin();
920 + return getSingleRange(nTab);
922 diff --git sc/source/ui/view/cellsh3.cxx sc/source/ui/view/cellsh3.cxx
923 index 57309e3..c689fa1 100644
924 --- sc/source/ui/view/cellsh3.cxx
925 +++ sc/source/ui/view/cellsh3.cxx
926 @@ -772,6 +772,7 @@ void ScCellShell::Execute( SfxRequest& rReq )
928 // test whether to merge or to split
929 bool bMerge = false;
930 + BOOL bCenter = FALSE;
931 switch( nSlot )
933 case FID_MERGE_ON:
934 @@ -782,6 +783,7 @@ void ScCellShell::Execute( SfxRequest& rReq )
935 break;
936 case FID_MERGE_TOGGLE:
938 + bCenter = TRUE;
939 SfxPoolItem* pItem = 0;
940 if( rBindings.QueryState( nSlot, pItem ) >= SFX_ITEM_DEFAULT )
941 bMerge = !static_cast< SfxBoolItem* >( pItem )->GetValue();
942 @@ -802,7 +804,7 @@ void ScCellShell::Execute( SfxRequest& rReq )
943 bMoveContents = ((const SfxBoolItem*)pItem)->GetValue();
946 - if (pTabViewShell->MergeCells( bApi, bMoveContents ))
947 + if (pTabViewShell->MergeCells( bApi, bMoveContents, TRUE, bCenter ))
949 if (!bApi && bMoveContents) // "ja" im Dialog geklickt
950 rReq.AppendItem( SfxBoolItem( nSlot, bMoveContents ) );
951 diff --git sc/source/ui/view/makefile.mk sc/source/ui/view/makefile.mk
952 index 48395f3..46b8122 100644
953 --- sc/source/ui/view/makefile.mk
954 +++ sc/source/ui/view/makefile.mk
955 @@ -100,6 +100,7 @@ SLOFILES = \
956 $(SLO)$/output3.obj \
957 $(SLO)$/gridmerg.obj \
958 $(SLO)$/invmerge.obj \
959 + $(SLO)$/cellmergeoption.obj \
960 $(SLO)$/select.obj \
961 $(SLO)$/olinewin.obj \
962 $(SLO)$/hintwin.obj \
963 diff --git sc/source/ui/view/viewfun2.cxx sc/source/ui/view/viewfun2.cxx
964 index c563b9a..d6fd25d 100644
965 --- sc/source/ui/view/viewfun2.cxx
966 +++ sc/source/ui/view/viewfun2.cxx
967 @@ -70,6 +70,7 @@ using namespace com::sun::star;
968 #include "attrib.hxx"
969 #include "autoform.hxx"
970 #include "cell.hxx" // EnterAutoSum
971 +#include "cellmergeoption.hxx"
972 #include "compiler.hxx"
973 #include "docfunc.hxx"
974 #include "docpool.hxx"
975 @@ -1087,7 +1088,7 @@ BOOL ScViewFunc::TestMergeCells() // Vorab-Test (fuer Menue)
977 //----------------------------------------------------------------------------
979 -BOOL ScViewFunc::MergeCells( BOOL bApi, BOOL& rDoContents, BOOL bRecord )
980 +BOOL ScViewFunc::MergeCells( BOOL bApi, BOOL& rDoContents, BOOL bRecord, BOOL bCenter )
982 // Editable- und Verschachtelungs-Abfrage muss vorneweg sein (auch in DocFunc),
983 // damit dann nicht die Inhalte-QueryBox kommt
984 @@ -1130,10 +1131,26 @@ BOOL ScViewFunc::MergeCells( BOOL bApi, BOOL& rDoContents, BOOL bRecord )
985 return FALSE;
988 + // Check for the contents of all selected tables.
989 + bool bAskDialog = false;
990 + SCTAB nTabCount = pDoc->GetTableCount();
991 + ScCellMergeOption aMergeOption(nStartCol, nStartRow, nEndCol, nEndRow, bCenter);
992 + for (SCTAB i = 0; i < nTabCount; ++i)
994 + if (!rMark.GetTableSelect(i))
995 + // this table is not selected.
996 + continue;
998 + aMergeOption.maTabs.insert(i);
1000 + if (!pDoc->IsBlockEmpty(i, nStartCol, nStartRow+1, nStartCol, nEndRow) ||
1001 + !pDoc->IsBlockEmpty(i, nStartCol+1, nStartRow, nEndCol, nEndRow))
1002 + bAskDialog = true;
1005 BOOL bOk = TRUE;
1007 - if ( !pDoc->IsBlockEmpty( nStartTab, nStartCol,nStartRow+1, nStartCol,nEndRow, true ) ||
1008 - !pDoc->IsBlockEmpty( nStartTab, nStartCol+1,nStartRow, nEndCol,nEndRow, true ) )
1009 + if (bAskDialog)
1011 if (!bApi)
1013 @@ -1153,7 +1170,7 @@ BOOL ScViewFunc::MergeCells( BOOL bApi, BOOL& rDoContents, BOOL bRecord )
1014 if (bOk)
1016 HideCursor();
1017 - bOk = pDocSh->GetDocFunc().MergeCells( aMarkRange, rDoContents, bRecord, bApi );
1018 + bOk = pDocSh->GetDocFunc().MergeCells( aMergeOption, rDoContents, bRecord, bApi );
1019 ShowCursor();
1021 if (bOk)
1022 @@ -1189,6 +1206,32 @@ BOOL ScViewFunc::TestRemoveMerge()
1024 //----------------------------------------------------------------------------
1026 +static bool lcl_extendMergeRange(ScCellMergeOption& rOption, const ScRange& rRange)
1028 + bool bExtended = false;
1029 + if (rOption.mnStartCol > rRange.aStart.Col())
1030 + {
1031 + rOption.mnStartCol = rRange.aStart.Col();
1032 + bExtended = true;
1034 + if (rOption.mnStartRow > rRange.aStart.Row())
1035 + {
1036 + rOption.mnStartRow = rRange.aStart.Row();
1037 + bExtended = true;
1039 + if (rOption.mnEndCol < rRange.aEnd.Col())
1040 + {
1041 + rOption.mnEndCol = rRange.aEnd.Col();
1042 + bExtended = true;
1044 + if (rOption.mnEndRow < rRange.aEnd.Row())
1045 + {
1046 + rOption.mnEndRow = rRange.aEnd.Row();
1047 + bExtended = true;
1049 + return bExtended;
1052 BOOL ScViewFunc::RemoveMerge( BOOL bRecord )
1054 ScRange aRange;
1055 @@ -1200,12 +1243,39 @@ BOOL ScViewFunc::RemoveMerge( BOOL bRecord )
1057 else if (GetViewData()->GetSimpleArea( aRange ) == SC_MARK_SIMPLE)
1059 + ScDocument* pDoc = GetViewData()->GetDocument();
1060 ScRange aExtended( aRange );
1061 - GetViewData()->GetDocument()->ExtendMerge( aExtended );
1062 + pDoc->ExtendMerge( aExtended );
1063 ScDocShell* pDocSh = GetViewData()->GetDocShell();
1064 + const ScMarkData& rMark = GetViewData()->GetMarkData();
1065 + SCTAB nTabCount = pDoc->GetTableCount();
1066 + ScCellMergeOption aOption(aRange.aStart.Col(), aRange.aStart.Row(), aRange.aEnd.Col(), aRange.aEnd.Row());
1067 + bool bExtended = false;
1068 + do
1070 + bExtended = false;
1071 + for (SCTAB i = 0; i < nTabCount; ++i)
1073 + if (!rMark.GetTableSelect(i))
1074 + // This table is not selected.
1075 + continue;
1077 + aOption.maTabs.insert(i);
1078 + aExtended.aStart.SetTab(i);
1079 + aExtended.aEnd.SetTab(i);
1080 + pDoc->ExtendMerge(aExtended);
1081 + pDoc->ExtendOverlapped(aExtended);
1083 + // Expand the current range to be inclusive of all merged
1084 + // areas on all sheets.
1085 + bExtended = lcl_extendMergeRange(aOption, aExtended);
1088 + while (bExtended);
1090 HideCursor();
1091 - BOOL bOk = pDocSh->GetDocFunc().UnmergeCells( aRange, bRecord, FALSE );
1092 + BOOL bOk = pDocSh->GetDocFunc().UnmergeCells(aOption, bRecord, FALSE );
1093 + aExtended = aOption.getFirstSingleRange();
1094 MarkRange( aExtended );
1095 ShowCursor();
1097 diff --git sc/uiconfig/scalc/menubar/menubar.xml sc/uiconfig/scalc/menubar/menubar.xml
1098 index 118fac7..322d448 100644
1099 --- sc/uiconfig/scalc/menubar/menubar.xml
1100 +++ sc/uiconfig/scalc/menubar/menubar.xml
1101 @@ -218,7 +218,13 @@
1102 <menu:menuitem menu:id=".uno:SetTabBgColor"/>
1103 </menu:menupopup>
1104 </menu:menu>
1105 - <menu:menuitem menu:id=".uno:ToggleMergeCells"/>
1106 + <menu:menu menu:id=".uno:MergeCellsMenu">
1107 + <menu:menupopup>
1108 + <menu:menuitem menu:id=".uno:ToggleMergeCells"/>
1109 + <menu:menuitem menu:id=".uno:MergeCells"/>
1110 + <menu:menuitem menu:id=".uno:SplitCell"/>
1111 + </menu:menupopup>
1112 + </menu:menu>
1113 <menu:menuseparator/>
1114 <menu:menuitem menu:id=".uno:PageFormatDialog"/>
1115 <menu:menu menu:id=".uno:PrintRangesMenu">