From 20f479c134fbfa43ac4ea536265957dfd15d84aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= Date: Thu, 20 Nov 2014 15:53:14 +0000 Subject: [PATCH] this seems to work better now Change-Id: Id414e09faa221d151f393971654b17bbe9f46d81 --- svx/source/table/tablecontroller.cxx | 60 +++++++++++++++++++++++++++--------- 1 file changed, 45 insertions(+), 15 deletions(-) diff --git a/svx/source/table/tablecontroller.cxx b/svx/source/table/tablecontroller.cxx index f5b4c99..d2411242 100644 --- a/svx/source/table/tablecontroller.cxx +++ b/svx/source/table/tablecontroller.cxx @@ -856,6 +856,19 @@ void SvxTableController::onSelect( sal_uInt16 nSId ) } } +namespace +{ + SvxBoxItem mergeDrawinglayerTextDistancesAndSvxBoxItem(const SfxItemSet& rAttrSet) + { + // merge drawing layer text distance items into SvxBoxItem used by the dialog + SvxBoxItem aBoxItem( static_cast< const SvxBoxItem& >( rAttrSet.Get( SDRATTR_TABLE_BORDER ) ) ); + aBoxItem.SetDistance( sal::static_int_cast< sal_uInt16 >( static_cast(rAttrSet.Get(SDRATTR_TEXT_LEFTDIST)).GetValue()), BOX_LINE_LEFT ); + aBoxItem.SetDistance( sal::static_int_cast< sal_uInt16 >( static_cast(rAttrSet.Get(SDRATTR_TEXT_RIGHTDIST)).GetValue()), BOX_LINE_RIGHT ); + aBoxItem.SetDistance( sal::static_int_cast< sal_uInt16 >( static_cast(rAttrSet.Get(SDRATTR_TEXT_UPPERDIST)).GetValue()), BOX_LINE_TOP ); + aBoxItem.SetDistance( sal::static_int_cast< sal_uInt16 >( static_cast(rAttrSet.Get(SDRATTR_TEXT_LOWERDIST)).GetValue()), BOX_LINE_BOTTOM ); + return aBoxItem; + } +} void SvxTableController::onFormatTable( SfxRequest& rReq ) { @@ -869,30 +882,42 @@ void SvxTableController::onFormatTable( SfxRequest& rReq ) { SfxItemSet aNewAttr( pTableObj->GetModel()->GetItemPool() ); - // merge drawing layer text distance items into SvxBoxItem used by the dialog - SvxBoxItem aBoxItem( static_cast< const SvxBoxItem& >( aNewAttr.Get( SDRATTR_TABLE_BORDER ) ) ); - aBoxItem.SetDistance( sal::static_int_cast< sal_uInt16 >( static_cast(aNewAttr.Get(SDRATTR_TEXT_LEFTDIST)).GetValue()), BOX_LINE_LEFT ); - aBoxItem.SetDistance( sal::static_int_cast< sal_uInt16 >( static_cast(aNewAttr.Get(SDRATTR_TEXT_RIGHTDIST)).GetValue()), BOX_LINE_RIGHT ); - aBoxItem.SetDistance( sal::static_int_cast< sal_uInt16 >( static_cast(aNewAttr.Get(SDRATTR_TEXT_UPPERDIST)).GetValue()), BOX_LINE_TOP ); - aBoxItem.SetDistance( sal::static_int_cast< sal_uInt16 >( static_cast(aNewAttr.Get(SDRATTR_TEXT_LOWERDIST)).GetValue()), BOX_LINE_BOTTOM ); + MergeAttrFromSelectedCells(aNewAttr, false); - SvxBoxInfoItem aBoxInfoItem( static_cast< const SvxBoxInfoItem& >( aNewAttr.Get( SDRATTR_TABLE_BORDER_INNER ) ) ); + SvxBoxItem aBoxItem(mergeDrawinglayerTextDistancesAndSvxBoxItem(aNewAttr)); - MergeAttrFromSelectedCells(aNewAttr, true); + fprintf(stderr, "so default top is %d\n", aBoxItem.GetDistance(BOX_LINE_TOP)); + SvxBoxInfoItem aBoxInfoItem( static_cast< const SvxBoxInfoItem& >( aNewAttr.Get( SDRATTR_TABLE_BORDER_INNER ) ) ); FillCommonBorderAttrFromSelectedCells( aBoxItem, aBoxInfoItem ); - aNewAttr.Put( aBoxItem ); + fprintf(stderr, "stage two top is %d\n", aBoxItem.GetDistance(BOX_LINE_TOP)); aNewAttr.Put( aBoxInfoItem ); + aNewAttr.Put( aBoxItem ); SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); boost::scoped_ptr< SfxAbstractTabDialog > pDlg( pFact ? pFact->CreateSvxFormatCellsDialog( NULL, &aNewAttr, pTableObj->GetModel(), pTableObj) : 0 ); // Even Cancel Button is returning positive(101) value, if( pDlg.get() && ( pDlg->Execute() == RET_OK ) ) { - SfxItemSet aNewSet( aNewAttr ); - aNewSet.Put( *(pDlg->GetOutputItemSet ()) ); + SfxItemSet aNewSet( *(pDlg->GetOutputItemSet ()) ); + + //Only properties that were unchanged by the dialog appear in this + //itemset. We bad constructed these two properties from other + //ones, so if they were not changed, then forcible set them back to + //their originals in the new result set so we can decompose that + //unchanged state back to their input properties + if (aNewSet.GetItemState(SDRATTR_TABLE_BORDER, false) != SfxItemState::SET) + { + aNewSet.Put(aBoxItem); + } + if (aNewSet.GetItemState(SDRATTR_TABLE_BORDER_INNER, false) != SfxItemState::SET) + { + aNewSet.Put(aBoxInfoItem); + } SvxBoxItem aNewBoxItem( static_cast< const SvxBoxItem& >( aNewSet.Get( SDRATTR_TABLE_BORDER ) ) ); + fprintf(stderr, "so final top is %d\n", aNewBoxItem.GetDistance(BOX_LINE_TOP)); + if( aNewBoxItem.GetDistance( BOX_LINE_LEFT ) != aBoxItem.GetDistance( BOX_LINE_LEFT ) ) aNewSet.Put(makeSdrTextLeftDistItem( aNewBoxItem.GetDistance( BOX_LINE_LEFT ) ) ); @@ -910,8 +935,6 @@ void SvxTableController::onFormatTable( SfxRequest& rReq ) } } - - void SvxTableController::Execute( SfxRequest& rReq ) { const sal_uInt16 nSId = rReq.GetSlot(); @@ -2884,6 +2907,8 @@ void lcl_MergeCommonBorderAttr(LinesState& rLinesState, const SvxBoxItem& rCellB } else { + fprintf(stderr, "top distance for selected cell is %d\n", rCellBoxItem.GetDistance(BOX_LINE_TOP)); + // current cell is inside the selection lcl_MergeBorderOrInnerLine(rLinesState, rCellBoxItem.GetTop(), BOX_LINE_TOP, VALID_TOP, (nCellFlags & CELL_TOP) != 0); @@ -2948,9 +2973,11 @@ void SvxTableController::FillCommonBorderAttrFromSelectedCells( SvxBoxItem& rBox nCellFlags |= (nCol < aStart.mnCol) ? CELL_BEFORE : 0; nCellFlags |= (nCol > aEnd.mnCol) ? CELL_AFTER : 0; + fprintf(stderr, "lcl_MergeCommonBorderAttr for %d %d\n", nCol, nRow); + const SfxItemSet& rSet = xCell->GetItemSet(); - const SvxBoxItem& rCellBoxItem = static_cast< const SvxBoxItem& >( rSet.Get(SDRATTR_TABLE_BORDER ) ); - lcl_MergeCommonBorderAttr( aLinesState, rCellBoxItem, nCellFlags ); + SvxBoxItem aCellBoxItem(mergeDrawinglayerTextDistancesAndSvxBoxItem(rSet)); + lcl_MergeCommonBorderAttr( aLinesState, aCellBoxItem, nCellFlags ); } } @@ -2970,7 +2997,10 @@ void SvxTableController::FillCommonBorderAttrFromSelectedCells( SvxBoxItem& rBox if (!aLinesState.bDistanceIndeterminate) { if (aLinesState.aDistanceSet[BOX_LINE_TOP]) + { + fprintf(stderr, "top is set, and to %d\n", aLinesState.aDistance[BOX_LINE_TOP]); aLinesState.rBoxItem.SetDistance(aLinesState.aDistance[BOX_LINE_TOP], BOX_LINE_TOP); + } if (aLinesState.aDistanceSet[BOX_LINE_BOTTOM]) aLinesState.rBoxItem.SetDistance(aLinesState.aDistance[BOX_LINE_BOTTOM], BOX_LINE_BOTTOM); if (aLinesState.aDistanceSet[BOX_LINE_LEFT]) -- 1.9.3