? sc/sc.vpj
Index: sc/inc/attarray.hxx
===================================================================
RCS file: /cvs/sc/sc/inc/attarray.hxx,v
retrieving revision 1.8
diff -u -r1.8 attarray.hxx
--- sc/inc/attarray.hxx	8 Sep 2005 17:22:53 -0000	1.8
+++ sc/inc/attarray.hxx	16 Oct 2007 00:43:54 -0000
@@ -186,8 +186,6 @@
 							SCROW nStartRow, SCROW nEndRow ) const;
 	BOOL	IsAllEqual( const ScAttrArray& rOther, SCROW nStartRow, SCROW nEndRow ) const;
 
-	BOOL	TestInsertCol( SCROW nStartRow, SCROW nEndRow) const;
-	BOOL	TestInsertRow( SCSIZE nSize ) const;
 	void	InsertRow( SCROW nStartRow, SCSIZE nSize );
 	void	DeleteRow( SCROW nStartRow, SCSIZE nSize );
 	void	DeleteRange( SCSIZE nStartIndex, SCSIZE nEndIndex );
Index: sc/inc/column.hxx
===================================================================
RCS file: /cvs/sc/sc/inc/column.hxx,v
retrieving revision 1.18
diff -u -r1.18 column.hxx
--- sc/inc/column.hxx	25 Jan 2007 11:02:48 -0000	1.18
+++ sc/inc/column.hxx	16 Oct 2007 00:43:54 -0000
@@ -209,8 +209,6 @@
 									SCROW nEndRow = MAXROW ) const;
 	BOOL		IsAllAttrEqual( const ScColumn& rCol, SCROW nStartRow, SCROW nEndRow ) const;
 
-	BOOL		TestInsertCol( SCROW nStartRow, SCROW nEndRow) const;
-	BOOL		TestInsertRow( SCSIZE nSize ) const;
 	void		InsertRow( SCROW nStartRow, SCSIZE nSize );
 	void		DeleteRow( SCROW nStartRow, SCSIZE nSize );
 	void		DeleteRange( SCSIZE nStartIndex, SCSIZE nEndIndex, USHORT nDelFlag );
Index: sc/source/core/data/attarray.cxx
===================================================================
RCS file: /cvs/sc/sc/source/core/data/attarray.cxx,v
retrieving revision 1.23
diff -u -r1.23 attarray.cxx
--- sc/source/core/data/attarray.cxx	27 Feb 2007 11:59:23 -0000	1.23
+++ sc/source/core/data/attarray.cxx	16 Oct 2007 00:43:55 -0000
@@ -2016,57 +2016,6 @@
 	return bEqual;
 }
 
-
-BOOL ScAttrArray::TestInsertCol( SCROW nStartRow, SCROW nEndRow) const
-{
-	//	horizontal zusammengefasste duerfen nicht herausgeschoben werden
-	//	(ob die ganze Zusammenfassung betroffen ist, ist hier nicht zu erkennen)
-
-	BOOL bTest = TRUE;
-	if (!IsEmpty())
-	{
-		SCSIZE nIndex = 0;
-		if ( nStartRow > 0 )
-			Search( nStartRow, nIndex );
-
-		for ( ; nIndex < nCount; nIndex++ )
-		{
-			if ( ((const ScMergeFlagAttr&)pData[nIndex].pPattern->
-						GetItem(ATTR_MERGE_FLAG)).IsHorOverlapped() )
-			{
-				bTest = FALSE;						// darf nicht herausgeschoben werden
-				break;
-			}
-			if ( pData[nIndex].nRow >= nEndRow )	// Ende des Bereichs
-				break;
-		}
-	}
-	return bTest;
-}
-
-
-BOOL ScAttrArray::TestInsertRow( SCSIZE nSize ) const
-{
-	//	wenn die erste herausgeschobene Zeile vertikal ueberlappt ist,
-	//	wuerde eine kaputte Zusammenfassung uebrigbleiben
-
-	if (pData)
-	{
-		//	MAXROW + 1 - nSize	= erste herausgeschobene Zeile
-
-		SCSIZE nFirstLost = nCount-1;
-        while ( nFirstLost && pData[nFirstLost-1].nRow >= sal::static_int_cast<SCROW>(MAXROW + 1 - nSize) )
-			--nFirstLost;
-
-		if ( ((const ScMergeFlagAttr&)pData[nFirstLost].pPattern->
-							GetItem(ATTR_MERGE_FLAG)).IsVerOverlapped() )
-			return FALSE;
-	}
-
-	return TRUE;
-}
-
-
 void ScAttrArray::InsertRow( SCROW nStartRow, SCSIZE nSize )
 {
 	if (!pData)
Index: sc/source/core/data/column.cxx
===================================================================
RCS file: /cvs/sc/sc/source/core/data/column.cxx,v
retrieving revision 1.23
diff -u -r1.23 column.cxx
--- sc/source/core/data/column.cxx	6 Sep 2007 14:17:53 -0000	1.23
+++ sc/source/core/data/column.cxx	16 Oct 2007 00:43:55 -0000
@@ -1218,59 +1218,6 @@
 	}
 }
 
-
-BOOL ScColumn::TestInsertCol( SCROW nStartRow, SCROW nEndRow) const
-{
-	if (!IsEmpty())
-	{
-		BOOL bTest = TRUE;
-		if (pItems)
-			for (SCSIZE i=0; (i<nCount) && bTest; i++)
-				bTest = ((pItems[i].nRow < nStartRow) && (pItems[i].nRow > nEndRow))
-						|| !CellVisible(pItems[i].pCell);
-
-		//	AttrArray testet nur zusammengefasste
-
-		if ((bTest) && (pAttrArray))
-			bTest = pAttrArray->TestInsertCol(nStartRow, nEndRow);
-
-		//!		rausgeschobene Attribute bei Undo beruecksichtigen
-
-		return bTest;
-	}
-	else
-		return TRUE;
-}
-
-
-BOOL ScColumn::TestInsertRow( SCSIZE nSize ) const
-{
-    //  AttrArray only looks for merged cells
-
-	if ( pItems && nCount )
-        return ( nSize <= sal::static_int_cast<SCSIZE>(MAXROW) &&
-                 pItems[nCount-1].nRow <= MAXROW-(SCROW)nSize && pAttrArray->TestInsertRow( nSize ) );
-	else
-		return pAttrArray->TestInsertRow( nSize );
-
-#if 0
-	//!		rausgeschobene Attribute bei Undo beruecksichtigen
-
-	if ( nSize > static_cast<SCSIZE>(MAXROW) )
-		return FALSE;
-
-	SCSIZE nVis = nCount;
-	while ( nVis && !CellVisible(pItems[nVis-1].pCell) )
-		--nVis;
-
-	if ( nVis )
-		return ( pItems[nVis-1].nRow <= MAXROW-nSize );
-	else
-		return TRUE;
-#endif
-}
-
-
 void ScColumn::InsertRow( SCROW nStartRow, SCSIZE nSize )
 {
 	pAttrArray->InsertRow( nStartRow, nSize );
Index: sc/source/core/data/table2.cxx
===================================================================
RCS file: /cvs/sc/sc/source/core/data/table2.cxx,v
retrieving revision 1.37
diff -u -r1.37 table2.cxx
--- sc/source/core/data/table2.cxx	27 Feb 2007 12:09:28 -0000	1.37
+++ sc/source/core/data/table2.cxx	16 Oct 2007 00:43:56 -0000
@@ -118,9 +118,6 @@
 	if ( nStartCol==0 && nEndCol==MAXCOL && pOutlineTable )
 		bTest = pOutlineTable->TestInsertRow(nSize);
 
-	for (SCCOL i=nStartCol; (i<=nEndCol) && bTest; i++)
-		bTest = aCol[i].TestInsertRow( nSize );
-
 	return bTest;
 }
 
@@ -184,9 +181,6 @@
 	if ( nSize > static_cast<SCSIZE>(MAXCOL) )
 		bTest = FALSE;
 
-	for (SCCOL i=MAXCOL; (i+static_cast<SCCOL>(nSize)>MAXCOL) && bTest; i--)
-		bTest = aCol[i].TestInsertCol(nStartRow, nEndRow);
-
 	return bTest;
 }
 
Index: sc/source/ui/docshell/docfunc.cxx
===================================================================
RCS file: /cvs/sc/sc/source/ui/docshell/docfunc.cxx,v
retrieving revision 1.66
diff -u -r1.66 docfunc.cxx
--- sc/source/ui/docshell/docfunc.cxx	27 Jun 2007 12:45:25 -0000	1.66
+++ sc/source/ui/docshell/docfunc.cxx	16 Oct 2007 00:43:56 -0000
@@ -59,6 +59,7 @@
 #endif
 
 #include <list>
+#include <queue>
 
 #include "docfunc.hxx"
 
@@ -1271,7 +1272,6 @@
 	if (eCmd==INS_CELLSRIGHT)
 		nMergeTestEndX = MAXCOL;
 
-	BOOL bCanDo = TRUE;
 	BOOL bNeedRefresh = FALSE;
 
 	SCCOL nEditTestEndX = (eCmd==INS_INSCOLS) ? MAXCOL : nMergeTestEndX;
@@ -1284,44 +1284,6 @@
 		return FALSE;
 	}
 
-	if (pDoc->HasAttrib( nMergeTestStartX,nMergeTestStartY,nTab,
-							nMergeTestEndX,nMergeTestEndY,nTab,
-							HASATTR_MERGED | HASATTR_OVERLAPPED ))
-	{
-		if (eCmd==INS_CELLSRIGHT)
-			bNeedRefresh = TRUE;
-
-		SCCOL nMergeStartX = nMergeTestStartX;
-		SCROW nMergeStartY = nMergeTestStartY;
-		SCCOL nMergeEndX   = nMergeTestEndX;
-		SCROW nMergeEndY   = nMergeTestEndY;
-
-		pDoc->ExtendMerge( nMergeStartX, nMergeStartY, nMergeEndX, nMergeEndY, nTab );
-		pDoc->ExtendOverlapped( nMergeStartX, nMergeStartY, nMergeEndX, nMergeEndY, nTab );
-		if ( nMergeStartX != nMergeTestStartX || nMergeStartY != nMergeTestStartY ||
-			 nMergeEndX   != nMergeTestEndX   || nMergeEndY   != nMergeTestEndY )
-			bCanDo = FALSE;
-
-		//!		? nur Start testen ?
-
-		if (!bCanDo)
-			if ( eCmd==INS_INSCOLS || eCmd==INS_INSROWS )
-				if ( nMergeStartX == nMergeTestStartX && nMergeStartY == nMergeTestStartY )
-				{
-					bCanDo = TRUE;
-//					bNeedRefresh = TRUE;
-				}
-	}
-
-	if (!bCanDo)
-	{
-		//!			auf Verschieben (Drag&Drop) zurueckfuehren !!!
-		//	"Kann nicht in zusammengefasste Bereiche einfuegen"
-		if (!bApi)
-			rDocShell.ErrorMessage(STR_MSSG_INSERTCELLS_0);
-		return FALSE;
-	}
-
 	//
 	//		ausfuehren
 	//
@@ -1342,6 +1304,30 @@
 		pDoc->BeginDrawUndo();
 	}
 
+    // #i8302 : we unmerge overwhelming ranges, before insertion
+    // all the actions are put in the same ListAction
+    String aUndo = ScGlobal::GetRscString( STR_UNDO_RESIZEMATRIX );
+    if (bRecord)
+      rDocShell.GetUndoManager()->EnterListAction( aUndo, aUndo );
+
+    std::queue<ScRange> qRange;
+    for (SCCOL i = nStartCol; i <= nEndCol; i++)
+        for (SCCOL j = nStartRow; j <= nEndRow; j++) 
+        {
+            ScRange rrRange (i, j, nTab);
+            pDoc->ExtendOverlapped(rrRange);
+            pDoc->ExtendMerge(rrRange);
+            // we can have merged range in the selection, 
+            // so we take only those which are in the way
+            if (rrRange.aStart.Col() < nStartCol || rrRange.aEnd.Col() > nEndCol || 
+                rrRange.aStart.Row() < nStartRow || rrRange.aEnd.Row() > nEndRow) 
+            {
+                qRange.push(rrRange);
+                UnmergeCells(rrRange, TRUE, TRUE);
+            }
+        }
+
+
 	switch (eCmd)
 	{
 		case INS_CELLSDOWN:
@@ -1370,6 +1356,7 @@
 			nPaintEndX = MAXCOL;
 			nPaintFlags |= PAINT_TOP;
 			break;
+		case INS_NONE:
 		default:
 			DBG_ERROR("Falscher Code beim Einfuegen");
 			bSuccess = FALSE;
@@ -1378,6 +1365,28 @@
 
 	if ( bSuccess )
 	{
+        // #i8302 : we remerge overwhelming ranges, with the new part inserted
+        while( !qRange.empty() ) 
+        {
+            ScRange rrRange = qRange.front();
+            switch (eCmd)
+            {
+                case INS_CELLSDOWN:
+                case INS_INSROWS:
+                    rrRange.aEnd.IncRow(static_cast<SCsCOL>(nEndRow-nStartRow+1));
+                    break;
+                case INS_CELLSRIGHT:
+                case INS_INSCOLS:
+                    rrRange.aEnd.IncCol(static_cast<SCsCOL>(nEndCol-nStartCol+1));
+                    break;
+                case INS_NONE:
+                default:
+                    break;
+            }
+            MergeCells(rrRange, FALSE, TRUE, TRUE, FALSE);
+            qRange.pop();
+        }
+
 		if ( bRecord )
 		{
 			rDocShell.GetUndoManager()->AddUndoAction(
@@ -1416,6 +1425,8 @@
 								 nPaintEndX,   nPaintEndY,   nEndTab,
 								 nPaintFlags,  nExtFlags);
 		aModificator.SetDocumentModified();
+        if (bRecord)
+            rDocShell.GetUndoManager()->LeaveListAction();
 
 //!		pDocSh->UpdateOle(GetViewData());	// muss an der View bleiben
 //!		CellContentChanged();				// muss an der View bleiben
