summaryrefslogtreecommitdiff
path: root/sc/source/ui/view
diff options
context:
space:
mode:
authorKohei Yoshida <kyoshida@novell.com>2010-09-16 11:43:15 +0200
committerFridrich Štrba <fridrich.strba@bluewin.ch>2010-09-16 11:43:15 +0200
commitca1582d4eb83c8b9ab732fc7ea7d7e69400a3cf7 (patch)
tree5c2ed4d7dd212001acb634d65b5594c2ca19536f /sc/source/ui/view
parente278e19136f252ef8c0dfe451b7d31417bd65b09 (diff)
calc-enhanced-merge-cells-sc.diff
n#213205, i#67243, i#101042 Merging/unmerging of cells on multiple sheets & merge center icon.
Diffstat (limited to 'sc/source/ui/view')
-rw-r--r--sc/source/ui/view/cellmergeoption.cxx74
-rw-r--r--sc/source/ui/view/cellsh3.cxx4
-rw-r--r--sc/source/ui/view/makefile.mk1
-rw-r--r--sc/source/ui/view/viewfun2.cxx82
4 files changed, 154 insertions, 7 deletions
diff --git a/sc/source/ui/view/cellmergeoption.cxx b/sc/source/ui/view/cellmergeoption.cxx
new file mode 100644
index 000000000000..da531966cb19
--- /dev/null
+++ b/sc/source/ui/view/cellmergeoption.cxx
@@ -0,0 +1,74 @@
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2010 by Novell, Inc.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * $RCSfile: docfunc.hxx,v $
+ * $Revision: 1.18.30.2 $
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#include "cellmergeoption.hxx"
+#include "address.hxx"
+
+ScCellMergeOption::ScCellMergeOption() :
+ mnStartCol(0),
+ mnStartRow(0),
+ mnEndCol(0),
+ mnEndRow(0),
+ mbCenter(false)
+{
+}
+
+ScCellMergeOption::ScCellMergeOption(SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, bool bCenter) :
+ mnStartCol(nStartCol),
+ mnStartRow(nStartRow),
+ mnEndCol(nEndCol),
+ mnEndRow(nEndRow),
+ mbCenter(bCenter)
+{
+}
+
+ScCellMergeOption::ScCellMergeOption(const ScCellMergeOption& r) :
+ maTabs(r.maTabs),
+ mnStartCol(r.mnStartCol),
+ mnStartRow(r.mnStartRow),
+ mnEndCol(r.mnEndCol),
+ mnEndRow(r.mnEndRow),
+ mbCenter(r.mbCenter)
+{
+}
+
+ScRange ScCellMergeOption::getSingleRange(SCTAB nTab) const
+{
+ return ScRange(mnStartCol, mnStartRow, nTab, mnEndCol, mnEndRow, nTab);
+}
+
+ScRange ScCellMergeOption::getFirstSingleRange() const
+{
+ SCTAB nTab = 0;
+ if (!maTabs.empty())
+ nTab = *maTabs.begin();
+
+ return getSingleRange(nTab);
+}
diff --git a/sc/source/ui/view/cellsh3.cxx b/sc/source/ui/view/cellsh3.cxx
index ed391f154892..f8985748302c 100644
--- a/sc/source/ui/view/cellsh3.cxx
+++ b/sc/source/ui/view/cellsh3.cxx
@@ -769,6 +769,7 @@ void ScCellShell::Execute( SfxRequest& rReq )
{
// test whether to merge or to split
bool bMerge = false;
+ BOOL bCenter = FALSE;
switch( nSlot )
{
case FID_MERGE_ON:
@@ -779,6 +780,7 @@ void ScCellShell::Execute( SfxRequest& rReq )
break;
case FID_MERGE_TOGGLE:
{
+ bCenter = TRUE;
SfxPoolItem* pItem = 0;
if( rBindings.QueryState( nSlot, pItem ) >= SFX_ITEM_DEFAULT )
bMerge = !static_cast< SfxBoolItem* >( pItem )->GetValue();
@@ -799,7 +801,7 @@ void ScCellShell::Execute( SfxRequest& rReq )
bMoveContents = ((const SfxBoolItem*)pItem)->GetValue();
}
- if (pTabViewShell->MergeCells( bApi, bMoveContents ))
+ if (pTabViewShell->MergeCells( bApi, bMoveContents, TRUE, bCenter ))
{
if (!bApi && bMoveContents) // "ja" im Dialog geklickt
rReq.AppendItem( SfxBoolItem( nSlot, bMoveContents ) );
diff --git a/sc/source/ui/view/makefile.mk b/sc/source/ui/view/makefile.mk
index 1b2fef913fc2..521c5bda91fc 100644
--- a/sc/source/ui/view/makefile.mk
+++ b/sc/source/ui/view/makefile.mk
@@ -96,6 +96,7 @@ SLOFILES = \
$(SLO)$/output3.obj \
$(SLO)$/gridmerg.obj \
$(SLO)$/invmerge.obj \
+ $(SLO)$/cellmergeoption.obj \
$(SLO)$/select.obj \
$(SLO)$/olinewin.obj \
$(SLO)$/hintwin.obj \
diff --git a/sc/source/ui/view/viewfun2.cxx b/sc/source/ui/view/viewfun2.cxx
index a125cbea6f50..d3a83ad6bde5 100644
--- a/sc/source/ui/view/viewfun2.cxx
+++ b/sc/source/ui/view/viewfun2.cxx
@@ -60,6 +60,7 @@
#include "attrib.hxx"
#include "autoform.hxx"
#include "cell.hxx" // EnterAutoSum
+#include "cellmergeoption.hxx"
#include "compiler.hxx"
#include "docfunc.hxx"
#include "docpool.hxx"
@@ -1085,7 +1086,7 @@ BOOL ScViewFunc::TestMergeCells() // Vorab-Test (fuer Menue)
//----------------------------------------------------------------------------
-BOOL ScViewFunc::MergeCells( BOOL bApi, BOOL& rDoContents, BOOL bRecord )
+BOOL ScViewFunc::MergeCells( BOOL bApi, BOOL& rDoContents, BOOL bRecord, BOOL bCenter )
{
// Editable- und Verschachtelungs-Abfrage muss vorneweg sein (auch in DocFunc),
// damit dann nicht die Inhalte-QueryBox kommt
@@ -1128,10 +1129,26 @@ BOOL ScViewFunc::MergeCells( BOOL bApi, BOOL& rDoContents, BOOL bRecord )
return FALSE;
}
+ // Check for the contents of all selected tables.
+ bool bAskDialog = false;
+ SCTAB nTabCount = pDoc->GetTableCount();
+ ScCellMergeOption aMergeOption(nStartCol, nStartRow, nEndCol, nEndRow, bCenter);
+ for (SCTAB i = 0; i < nTabCount; ++i)
+ {
+ if (!rMark.GetTableSelect(i))
+ // this table is not selected.
+ continue;
+
+ aMergeOption.maTabs.insert(i);
+
+ if (!pDoc->IsBlockEmpty(i, nStartCol, nStartRow+1, nStartCol, nEndRow) ||
+ !pDoc->IsBlockEmpty(i, nStartCol+1, nStartRow, nEndCol, nEndRow))
+ bAskDialog = true;
+ }
+
BOOL bOk = TRUE;
- if ( !pDoc->IsBlockEmpty( nStartTab, nStartCol,nStartRow+1, nStartCol,nEndRow, true ) ||
- !pDoc->IsBlockEmpty( nStartTab, nStartCol+1,nStartRow, nEndCol,nEndRow, true ) )
+ if (bAskDialog)
{
if (!bApi)
{
@@ -1151,7 +1168,7 @@ BOOL ScViewFunc::MergeCells( BOOL bApi, BOOL& rDoContents, BOOL bRecord )
if (bOk)
{
HideCursor();
- bOk = pDocSh->GetDocFunc().MergeCells( aMarkRange, rDoContents, bRecord, bApi );
+ bOk = pDocSh->GetDocFunc().MergeCells( aMergeOption, rDoContents, bRecord, bApi );
ShowCursor();
if (bOk)
@@ -1187,6 +1204,32 @@ BOOL ScViewFunc::TestRemoveMerge()
//----------------------------------------------------------------------------
+static bool lcl_extendMergeRange(ScCellMergeOption& rOption, const ScRange& rRange)
+{
+ bool bExtended = false;
+ if (rOption.mnStartCol > rRange.aStart.Col())
+ {
+ rOption.mnStartCol = rRange.aStart.Col();
+ bExtended = true;
+ }
+ if (rOption.mnStartRow > rRange.aStart.Row())
+ {
+ rOption.mnStartRow = rRange.aStart.Row();
+ bExtended = true;
+ }
+ if (rOption.mnEndCol < rRange.aEnd.Col())
+ {
+ rOption.mnEndCol = rRange.aEnd.Col();
+ bExtended = true;
+ }
+ if (rOption.mnEndRow < rRange.aEnd.Row())
+ {
+ rOption.mnEndRow = rRange.aEnd.Row();
+ bExtended = true;
+ }
+ return bExtended;
+}
+
BOOL ScViewFunc::RemoveMerge( BOOL bRecord )
{
ScRange aRange;
@@ -1198,12 +1241,39 @@ BOOL ScViewFunc::RemoveMerge( BOOL bRecord )
}
else if (GetViewData()->GetSimpleArea( aRange ) == SC_MARK_SIMPLE)
{
+ ScDocument* pDoc = GetViewData()->GetDocument();
ScRange aExtended( aRange );
- GetViewData()->GetDocument()->ExtendMerge( aExtended );
+ pDoc->ExtendMerge( aExtended );
ScDocShell* pDocSh = GetViewData()->GetDocShell();
+ const ScMarkData& rMark = GetViewData()->GetMarkData();
+ SCTAB nTabCount = pDoc->GetTableCount();
+ ScCellMergeOption aOption(aRange.aStart.Col(), aRange.aStart.Row(), aRange.aEnd.Col(), aRange.aEnd.Row());
+ bool bExtended = false;
+ do
+ {
+ bExtended = false;
+ for (SCTAB i = 0; i < nTabCount; ++i)
+ {
+ if (!rMark.GetTableSelect(i))
+ // This table is not selected.
+ continue;
+
+ aOption.maTabs.insert(i);
+ aExtended.aStart.SetTab(i);
+ aExtended.aEnd.SetTab(i);
+ pDoc->ExtendMerge(aExtended);
+ pDoc->ExtendOverlapped(aExtended);
+
+ // Expand the current range to be inclusive of all merged
+ // areas on all sheets.
+ bExtended = lcl_extendMergeRange(aOption, aExtended);
+ }
+ }
+ while (bExtended);
HideCursor();
- BOOL bOk = pDocSh->GetDocFunc().UnmergeCells( aRange, bRecord, FALSE );
+ BOOL bOk = pDocSh->GetDocFunc().UnmergeCells(aOption, bRecord, FALSE );
+ aExtended = aOption.getFirstSingleRange();
MarkRange( aExtended );
ShowCursor();