diff options
author | Kohei Yoshida <kohei.yoshida@suse.com> | 2012-02-15 14:06:48 -0500 |
---|---|---|
committer | Kohei Yoshida <kohei.yoshida@suse.com> | 2012-02-15 14:08:08 -0500 |
commit | ab0096ed68cdc08906f518d3499a8e1afc5ba80c (patch) | |
tree | ddcf6aec5572df28904ae114c2b6ec4f010f607b /sc/source/ui/docshell | |
parent | 843eafc765a3d1d0ea4c9a89855c73e81784aa8b (diff) |
fdo#46070: Allow copying of adjacent cells via Fill Down/Up/Left/Right.
Diffstat (limited to 'sc/source/ui/docshell')
-rw-r--r-- | sc/source/ui/docshell/docfunc.cxx | 100 |
1 files changed, 86 insertions, 14 deletions
diff --git a/sc/source/ui/docshell/docfunc.cxx b/sc/source/ui/docshell/docfunc.cxx index 8b9d0688f275..58041904a991 100644 --- a/sc/source/ui/docshell/docfunc.cxx +++ b/sc/source/ui/docshell/docfunc.cxx @@ -3933,19 +3933,91 @@ inline ScDirection DirFromFillDir( FillDir eDir ) return DIR_LEFT; } -sal_Bool ScDocFunc::FillSimple( const ScRange& rRange, const ScMarkData* pTabMark, - FillDir eDir, sal_Bool bRecord, sal_Bool bApi ) +namespace { + +/** + * Expand the fill range as necessary, to allow copying of adjacent cell(s) + * even when those cells are not in the original range. + */ +void adjustFillRangeForAdjacentCopy(ScRange& rRange, FillDir eDir) { - ScDocShellModificator aModificator( rDocShell ); + switch (eDir) + { + case FILL_TO_BOTTOM: + { + if (rRange.aStart.Row() == 0) + return; - sal_Bool bSuccess = false; + if (rRange.aStart.Row() != rRange.aEnd.Row()) + return; + + // Include the above row. + ScAddress& s = rRange.aStart; + s.SetRow(s.Row()-1); + } + break; + case FILL_TO_TOP: + { + if (rRange.aStart.Row() == MAXROW) + return; + + if (rRange.aStart.Row() != rRange.aEnd.Row()) + return; + + // Include the row below. + ScAddress& e = rRange.aEnd; + e.SetRow(e.Row()+1); + } + break; + case FILL_TO_LEFT: + { + if (rRange.aStart.Col() == MAXCOL) + return; + + if (rRange.aStart.Col() != rRange.aEnd.Col()) + return; + + // Include the column to the right. + ScAddress& e = rRange.aEnd; + e.SetCol(e.Col()+1); + } + break; + case FILL_TO_RIGHT: + { + if (rRange.aStart.Col() == 0) + return; + + if (rRange.aStart.Col() != rRange.aEnd.Col()) + return; + + // Include the column to the left. + ScAddress& s = rRange.aStart; + s.SetCol(s.Col()-1); + } + break; + default: + ; + } +} + +} + +bool ScDocFunc::FillSimple( const ScRange& rRange, const ScMarkData* pTabMark, + FillDir eDir, bool bRecord, bool bApi ) +{ + ScDocShellModificator aModificator( rDocShell ); ScDocument* pDoc = rDocShell.GetDocument(); - SCCOL nStartCol = rRange.aStart.Col(); - SCROW nStartRow = rRange.aStart.Row(); - SCTAB nStartTab = rRange.aStart.Tab(); - SCCOL nEndCol = rRange.aEnd.Col(); - SCROW nEndRow = rRange.aEnd.Row(); - SCTAB nEndTab = rRange.aEnd.Tab(); + + bool bSuccess = false; + ScRange aRange = rRange; + adjustFillRangeForAdjacentCopy(aRange, eDir); + + SCCOL nStartCol = aRange.aStart.Col(); + SCROW nStartRow = aRange.aStart.Row(); + SCTAB nStartTab = aRange.aStart.Tab(); + SCCOL nEndCol = aRange.aEnd.Col(); + SCROW nEndRow = aRange.aEnd.Row(); + SCTAB nEndTab = aRange.aEnd.Tab(); if (bRecord && !pDoc->IsUndoEnabled()) bRecord = false; @@ -3964,8 +4036,8 @@ sal_Bool ScDocFunc::FillSimple( const ScRange& rRange, const ScMarkData* pTabMar { WaitObject aWait( rDocShell.GetActiveDialogParent() ); - ScRange aSourceArea = rRange; - ScRange aDestArea = rRange; + ScRange aSourceArea = aRange; + ScRange aDestArea = aRange; SCCOLROW nCount = 0; switch (eDir) @@ -4010,7 +4082,7 @@ sal_Bool ScDocFunc::FillSimple( const ScRange& rRange, const ScMarkData* pTabMar pDoc->Fill( aSourceArea.aStart.Col(), aSourceArea.aStart.Row(), aSourceArea.aEnd.Col(), aSourceArea.aEnd.Row(), aMark, nCount, eDir, FILL_SIMPLE ); - AdjustRowHeight(rRange); + AdjustRowHeight(aRange); if ( bRecord ) // Draw-Undo erst jetzt verfuegbar { @@ -4022,7 +4094,7 @@ sal_Bool ScDocFunc::FillSimple( const ScRange& rRange, const ScMarkData* pTabMar rDocShell.PostPaintGridAll(); aModificator.SetDocumentModified(); - bSuccess = sal_True; + bSuccess = true; } else if (!bApi) rDocShell.ErrorMessage(aTester.GetMessageId()); |