summaryrefslogtreecommitdiff
path: root/sc/source
diff options
context:
space:
mode:
authorAttila Szűcs <szucs.attila3@nisz.hu>2020-09-10 16:46:30 +0200
committerLászló Németh <nemeth@numbertext.org>2020-09-30 10:30:08 +0200
commit1ed04c2029218619aab2f3422130c890f67f309c (patch)
tree582192b80c02f17321e71dad8c8030519accafee /sc/source
parentef77a256de527f6d00212839e55f949024f2e7bc (diff)
tdf#40993 tdf#59585 sc fill: copy merged cell structure
like other spreadsheets do. This avoids losing and recreation of merged cell structure again and again after modifying cell content using fill. By dragging the fill handle, cell attributes ATTR_MERGE and ATTR_MERGE_FLAG are copied, too, resulting the same merged cell structure in the selection. See TODOs about the remaining tasks. Co-authored-by: Tibor Nagy (NISZ) Change-Id: Icd4287d4429d3ba27a2ffb062560856d7ad86099 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/102394 Tested-by: László Németh <nemeth@numbertext.org> Reviewed-by: László Németh <nemeth@numbertext.org>
Diffstat (limited to 'sc/source')
-rw-r--r--sc/source/core/data/table4.cxx60
-rw-r--r--sc/source/ui/inc/viewfunc.hxx3
2 files changed, 55 insertions, 8 deletions
diff --git a/sc/source/core/data/table4.cxx b/sc/source/core/data/table4.cxx
index 2bd2076689b0..23175efdcfb2 100644
--- a/sc/source/core/data/table4.cxx
+++ b/sc/source/core/data/table4.cxx
@@ -640,15 +640,61 @@ void ScTable::FillAuto( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
pSrcPattern = aCol[nAtSrc].GetPattern(static_cast<SCROW>(nRow));
bGetPattern = false;
pStyleSheet = pSrcPattern->GetStyleSheet();
- // do not transfer ATTR_MERGE / ATTR_MERGE_FLAG
+ // do transfer ATTR_MERGE / ATTR_MERGE_FLAG
+ //
+ // Note: ATTR_MERGE is an attribute of the top left cell of a merged area
+ // containing the size of the area. ATTR_MERGE_FLAGs are attributes of the
+ // other cells of a merged area, containing the information about also
+ // overlapping, i.e. visibility of their content.
+ //
+ // TODO: extend the similar incomplete selections to a bounding rectangle to
+ // avoid incomplete fill, where not all AUTO_MERGE_FLAGs are synchronized with
+ // the copied ATTR_MERGE, resulting broken grid and visibility during run-time.
+ //
+ // +--+ +--+--+
+ // | | | | |
+ // +--+--+ +--+--+
+ // | | -> | |
+ // +--+--+ +--+--+
+ // | | | | |
+ // +--+ +--+--+
+ //
+ // TODO: protect incompatible merged cells of the destination area, for example
+ // by skipping the fill operation.
+ //
+ // TODO: by dragging the fill handle select only the multiples of the height
+ // of the originally selected area which is merged vertically to avoid of
+ // incomplete fill.
+ //
+ // +--+ +--+
+ // |XX| |XX|
+ // +XX+ +XX+
+ // |XX| -> |XX|
+ // +--+ +--+
+ // | | | |
+ // +--+ +--+
+ // | |
+ // +--+
+ //
+ // Other things stored in ATTR_MERGE_FLAG, like autofilter button, will be
+ // deleted now, but may need to be repaired later, like at ScDocument::Fill.
const SfxItemSet& rSet = pSrcPattern->GetItemSet();
- if ( rSet.GetItemState(ATTR_MERGE, false) == SfxItemState::SET
- || rSet.GetItemState(ATTR_MERGE_FLAG, false) == SfxItemState::SET )
+ if ( rSet.GetItemState(ATTR_MERGE_FLAG, false) == SfxItemState::SET )
{
- pNewPattern.reset( new ScPatternAttr( *pSrcPattern ));
- SfxItemSet& rNewSet = pNewPattern->GetItemSet();
- rNewSet.ClearItem(ATTR_MERGE);
- rNewSet.ClearItem(ATTR_MERGE_FLAG);
+ ScMF nOldValue = pSrcPattern->GetItem(ATTR_MERGE_FLAG).GetValue();
+ ScMF nOldValueMerge = nOldValue & (ScMF::Hor | ScMF::Ver);
+ // keep only the merge flags
+ if ( nOldValue != nOldValueMerge )
+ {
+ pNewPattern.reset(new ScPatternAttr(*pSrcPattern));
+ SfxItemSet& rNewSet = pNewPattern->GetItemSet();
+ if ( nOldValueMerge == ScMF::NONE )
+ rNewSet.ClearItem(ATTR_MERGE_FLAG);
+ else
+ rNewSet.Put(ScMergeFlagAttr(nOldValueMerge));
+ }
+ else
+ pNewPattern.reset();
}
else
pNewPattern.reset();
diff --git a/sc/source/ui/inc/viewfunc.hxx b/sc/source/ui/inc/viewfunc.hxx
index f1ce7196c7e1..7780e74bc790 100644
--- a/sc/source/ui/inc/viewfunc.hxx
+++ b/sc/source/ui/inc/viewfunc.hxx
@@ -242,7 +242,8 @@ public:
FillSimple( FillDir eDir );
void FillSeries( FillDir eDir, FillCmd eCmd, FillDateCmd eDateCmd,
double fStart, double fStep, double fMax );
- void FillAuto( FillDir eDir, SCCOL nStartCol, SCROW nStartRow,
+ SC_DLLPUBLIC void
+ FillAuto( FillDir eDir, SCCOL nStartCol, SCROW nStartRow,
SCCOL nEndCol, SCROW nEndRow, sal_uLong nCount );
void FillCrossDblClick();
void ConvertFormulaToValue();