diff options
author | Armin Le Grand <Armin.Le.Grand@cib.de> | 2018-04-06 22:32:24 +0200 |
---|---|---|
committer | Armin Le Grand <Armin.Le.Grand@cib.de> | 2018-04-06 22:32:24 +0200 |
commit | eba4d5b2b76cefde90cb3d6638c736f435023a45 (patch) | |
tree | 43befa620475c11f3dde00e5ea141e1efd95a334 /svx/source/table | |
parent | 6c14c27c75a03e2363f2b363ddf0a6f2f46cfa91 (diff) |
Revert "SOSAW080: Added first bunch of basic changes to helpers"
This reverts commit 6c14c27c75a03e2363f2b363ddf0a6f2f46cfa91.
Diffstat (limited to 'svx/source/table')
-rw-r--r-- | svx/source/table/cell.cxx | 120 | ||||
-rw-r--r-- | svx/source/table/cellcursor.cxx | 23 | ||||
-rw-r--r-- | svx/source/table/svdotable.cxx | 125 | ||||
-rw-r--r-- | svx/source/table/tablecolumn.cxx | 8 | ||||
-rw-r--r-- | svx/source/table/tablecontroller.cxx | 981 | ||||
-rw-r--r-- | svx/source/table/tablemodel.cxx | 74 | ||||
-rw-r--r-- | svx/source/table/tablerow.cxx | 18 | ||||
-rw-r--r-- | svx/source/table/tablertfimporter.cxx | 4 | ||||
-rw-r--r-- | svx/source/table/tableundo.cxx | 54 |
9 files changed, 702 insertions, 705 deletions
diff --git a/svx/source/table/cell.cxx b/svx/source/table/cell.cxx index 0f733d0c6e5d..cd1973848746 100644 --- a/svx/source/table/cell.cxx +++ b/svx/source/table/cell.cxx @@ -392,31 +392,21 @@ rtl::Reference< Cell > Cell::create( SdrTableObj& rTableObj ) } -Cell::Cell( - SdrTableObj& rTableObj) -: SdrText(rTableObj) - ,SvxUnoTextBase( ImplGetSvxUnoOutlinerTextCursorSvxPropertySet() ) - ,mpPropSet( ImplGetSvxCellPropertySet() ) - ,mpProperties( new sdr::properties::CellProperties( rTableObj, this ) ) - ,mnCellContentType( CellContentType_EMPTY ) - ,mfValue( 0.0 ) - ,mnError( 0 ) - ,mbMerged( false ) - ,mnRowSpan( 1 ) - ,mnColSpan( 1 ) - ,mxTable( rTableObj.getTable() ) -{ - // Caution: Old SetModel() indirectly did a very necessary thing here, - // it created a valid SvxTextEditSource which is needed to bind contained - // Text to the UNO API and thus to save/load and more. Added version without - // model change. - // Also done was (not needed, for reference): - // SetStyleSheet( nullptr, true ); - // ForceOutlinerParaObject( OutlinerMode::TextObject ); - if(nullptr == GetEditSource()) - { - SetEditSource(new SvxTextEditSource(&GetObject(), this)); - } +Cell::Cell( SdrTableObj& rTableObj ) +: SdrText( rTableObj ) +, SvxUnoTextBase( ImplGetSvxUnoOutlinerTextCursorSvxPropertySet() ) +, mpPropSet( ImplGetSvxCellPropertySet() ) +, mpProperties( new sdr::properties::CellProperties( rTableObj, this ) ) +, mnCellContentType( CellContentType_EMPTY ) +, mfValue( 0.0 ) +, mnError( 0 ) +, mbMerged( false ) +, mnRowSpan( 1 ) +, mnColSpan( 1 ) +, mxTable( rTableObj.getTable() ) +{ + if( rTableObj.GetModel() ) + SetModel( rTableObj.GetModel() ); } @@ -450,6 +440,37 @@ void Cell::dispose() SetOutlinerParaObject( nullptr ); } + +void Cell::SetModel(SdrModel* pNewModel) +{ + SvxTextEditSource* pTextEditSource = dynamic_cast< SvxTextEditSource* >( GetEditSource() ); + if( (GetModel() != pNewModel) || ( pNewModel && !pTextEditSource) ) + { + if( mpProperties ) + { + SfxItemPool* pItemPool = mpProperties->GetObjectItemSet().GetPool(); + + // test for correct pool in ItemSet; move to new pool if necessary + if( pNewModel && pItemPool && pItemPool != &pNewModel->GetItemPool()) + mpProperties->MoveToItemPool(pItemPool, &pNewModel->GetItemPool(), pNewModel); + } + + if( pTextEditSource ) + { + pTextEditSource->ChangeModel( pNewModel ); + } + else + { + SetEditSource( new SvxTextEditSource( &GetObject(), this ) ); + } + + SetStyleSheet( nullptr, true ); + SdrText::SetModel( pNewModel ); + ForceOutlinerParaObject( OutlinerMode::TextObject ); + } +} + + void Cell::merge( sal_Int32 nColumnSpan, sal_Int32 nRowSpan ) { if ((mnColSpan != nColumnSpan) || (mnRowSpan != nRowSpan) || mbMerged) @@ -516,13 +537,12 @@ void Cell::replaceContentAndFormating( const CellRef& xSourceCell ) { mpProperties->SetMergedItemSet( xSourceCell->GetObjectItemSet() ); SetOutlinerParaObject( new OutlinerParaObject(*xSourceCell->GetOutlinerParaObject()) ); + SdrTableObj& rTableObj = dynamic_cast< SdrTableObj& >( GetObject() ); SdrTableObj& rSourceTableObj = dynamic_cast< SdrTableObj& >( xSourceCell->GetObject() ); - if(&rSourceTableObj.getSdrModelFromSdrObject() != &rTableObj.getSdrModelFromSdrObject()) + if(rSourceTableObj.GetModel() != rTableObj.GetModel()) { - // TTTT should not happen - if, then a clone may be needed - // Maybe add a assertion here later SetStyleSheet( nullptr, true ); } } @@ -544,13 +564,12 @@ void Cell::copyFormatFrom( const CellRef& xSourceCell ) if( xSourceCell.is() && mpProperties ) { mpProperties->SetMergedItemSet( xSourceCell->GetObjectItemSet() ); + SdrTableObj& rTableObj = dynamic_cast< SdrTableObj& >( GetObject() ); SdrTableObj& rSourceTableObj = dynamic_cast< SdrTableObj& >( xSourceCell->GetObject() ); - if(&rSourceTableObj.getSdrModelFromSdrObject() != &rTableObj.getSdrModelFromSdrObject()) + if(rSourceTableObj.GetModel() != rTableObj.GetModel()) { - // TTTT should not happen - if, then a clone may be needed - // Maybe add a assertion here later SetStyleSheet( nullptr, true ); } @@ -793,11 +812,10 @@ void Cell::SetOutlinerParaObject( OutlinerParaObject* pTextObject ) void Cell::AddUndo() { SdrObject& rObj = GetObject(); - - if( rObj.IsInserted() && rObj.getSdrModelFromSdrObject().IsUndoEnabled() ) + if( rObj.IsInserted() && GetModel() && GetModel()->IsUndoEnabled() ) { CellRef xCell( this ); - rObj.getSdrModelFromSdrObject().AddUndo( new CellUndo( &rObj, xCell ) ); + GetModel()->AddUndo( new CellUndo( &rObj, xCell ) ); // Undo action for the after-text-edit-ended stack. SdrTableObj* pTableObj = dynamic_cast<sdr::table::SdrTableObj*>(&rObj); @@ -1001,7 +1019,7 @@ void SAL_CALL Cell::setPropertyValue( const OUString& rPropertyName, const Any& { ::SolarMutexGuard aGuard; - if(mpProperties == nullptr) + if( (mpProperties == nullptr) || (GetModel() == nullptr) ) throw DisposedException(); const SfxItemPropertySimpleEntry* pMap = mpPropSet->getPropertyMapEntry(rPropertyName); @@ -1093,7 +1111,7 @@ void SAL_CALL Cell::setPropertyValue( const OUString& rPropertyName, const Any& } default: { - SfxItemSet aSet(GetObject().getSdrModelFromSdrObject().GetItemPool(), {{pMap->nWID, pMap->nWID}}); + SfxItemSet aSet( GetModel()->GetItemPool(), {{pMap->nWID, pMap->nWID}}); aSet.Put(mpProperties->GetItem(pMap->nWID)); bool bSpecial = false; @@ -1113,7 +1131,7 @@ void SAL_CALL Cell::setPropertyValue( const OUString& rPropertyName, const Any& OUString aApiName; if( rValue >>= aApiName ) { - if(SvxShape::SetFillAttribute(pMap->nWID, aApiName, aSet, &GetObject().getSdrModelFromSdrObject())) + if( SvxShape::SetFillAttribute( pMap->nWID, aApiName, aSet, GetModel() ) ) bSpecial = true; } } @@ -1130,7 +1148,7 @@ void SAL_CALL Cell::setPropertyValue( const OUString& rPropertyName, const Any& { // fetch the default from ItemPool if(SfxItemPool::IsWhich(pMap->nWID)) - aSet.Put(GetObject().getSdrModelFromSdrObject().GetItemPool().GetDefaultItem(pMap->nWID)); + aSet.Put(GetModel()->GetItemPool().GetDefaultItem(pMap->nWID)); } if( aSet.GetItemState( pMap->nWID ) == SfxItemState::SET ) @@ -1140,7 +1158,7 @@ void SAL_CALL Cell::setPropertyValue( const OUString& rPropertyName, const Any& } } - GetObject().getSdrModelFromSdrObject().SetChanged(); + GetModel()->SetChanged(); mpProperties->SetMergedItemSetAndBroadcast( aSet ); return; } @@ -1154,7 +1172,7 @@ Any SAL_CALL Cell::getPropertyValue( const OUString& PropertyName ) { ::SolarMutexGuard aGuard; - if(mpProperties == nullptr) + if( (mpProperties == nullptr) || (GetModel() == nullptr) ) throw DisposedException(); const SfxItemPropertySimpleEntry* pMap = mpPropSet->getPropertyMapEntry(PropertyName); @@ -1213,7 +1231,7 @@ Any SAL_CALL Cell::getPropertyValue( const OUString& PropertyName ) } default: { - SfxItemSet aSet(GetObject().getSdrModelFromSdrObject().GetItemPool(), {{pMap->nWID, pMap->nWID}}); + SfxItemSet aSet( GetModel()->GetItemPool(), {{pMap->nWID, pMap->nWID}}); aSet.Put(mpProperties->GetItem(pMap->nWID)); Any aAny; @@ -1223,7 +1241,7 @@ Any SAL_CALL Cell::getPropertyValue( const OUString& PropertyName ) { // fetch the default from ItemPool if(SfxItemPool::IsWhich(pMap->nWID)) - aSet.Put(GetObject().getSdrModelFromSdrObject().GetItemPool().GetDefaultItem(pMap->nWID)); + aSet.Put(GetModel()->GetItemPool().GetDefaultItem(pMap->nWID)); } if( aSet.Count() ) @@ -1265,7 +1283,7 @@ void SAL_CALL Cell::setPropertyValues( const Sequence< OUString >& aPropertyName { ::SolarMutexGuard aSolarGuard; - if(mpProperties == nullptr) + if( (mpProperties == nullptr) || (GetModel() == nullptr) ) throw DisposedException(); const sal_Int32 nCount = aPropertyNames.getLength(); @@ -1295,7 +1313,7 @@ Sequence< Any > SAL_CALL Cell::getPropertyValues( const Sequence< OUString >& aP { ::SolarMutexGuard aSolarGuard; - if(mpProperties == nullptr) + if( (mpProperties == nullptr) || (GetModel() == nullptr) ) throw DisposedException(); const sal_Int32 nCount = aPropertyNames.getLength(); @@ -1346,7 +1364,7 @@ PropertyState SAL_CALL Cell::getPropertyState( const OUString& PropertyName ) { ::SolarMutexGuard aGuard; - if(mpProperties == nullptr) + if( (mpProperties == nullptr) || (GetModel() == nullptr) ) throw DisposedException(); const SfxItemPropertySimpleEntry* pMap = mpPropSet->getPropertyMapEntry(PropertyName); @@ -1449,7 +1467,7 @@ Sequence< PropertyState > SAL_CALL Cell::getPropertyStates( const Sequence< OUSt { ::SolarMutexGuard aGuard; - if(mpProperties == nullptr) + if( (mpProperties == nullptr) || (GetModel() == nullptr) ) throw DisposedException(); const sal_Int32 nCount = aPropertyName.getLength(); @@ -1479,7 +1497,7 @@ void SAL_CALL Cell::setPropertyToDefault( const OUString& PropertyName ) { ::SolarMutexGuard aGuard; - if(mpProperties == nullptr) + if( (mpProperties == nullptr) || (GetModel() == nullptr) ) throw DisposedException(); const SfxItemPropertySimpleEntry* pMap = mpPropSet->getPropertyMapEntry(PropertyName); @@ -1509,7 +1527,7 @@ void SAL_CALL Cell::setPropertyToDefault( const OUString& PropertyName ) } } - GetObject().getSdrModelFromSdrObject().SetChanged(); + GetModel()->SetChanged(); return; } throw UnknownPropertyException( PropertyName, static_cast<cppu::OWeakObject*>(this)); @@ -1520,7 +1538,7 @@ Any SAL_CALL Cell::getPropertyDefault( const OUString& aPropertyName ) { ::SolarMutexGuard aGuard; - if(mpProperties == nullptr) + if( (mpProperties == nullptr) || (GetModel() == nullptr) ) throw DisposedException(); const SfxItemPropertySimpleEntry* pMap = mpPropSet->getPropertyMapEntry(aPropertyName); @@ -1547,8 +1565,8 @@ Any SAL_CALL Cell::getPropertyDefault( const OUString& aPropertyName ) { if( SfxItemPool::IsWhich(pMap->nWID) ) { - SfxItemSet aSet(GetObject().getSdrModelFromSdrObject().GetItemPool(), {{pMap->nWID, pMap->nWID}}); - aSet.Put(GetObject().getSdrModelFromSdrObject().GetItemPool().GetDefaultItem(pMap->nWID)); + SfxItemSet aSet( GetModel()->GetItemPool(), {{pMap->nWID, pMap->nWID}}); + aSet.Put(GetModel()->GetItemPool().GetDefaultItem(pMap->nWID)); return GetAnyForItem( aSet, pMap ); } } diff --git a/svx/source/table/cellcursor.cxx b/svx/source/table/cellcursor.cxx index b6368837cfc5..db68fdb61ab4 100644 --- a/svx/source/table/cellcursor.cxx +++ b/svx/source/table/cellcursor.cxx @@ -242,11 +242,11 @@ void SAL_CALL CellCursor::merge( ) if( !mxTable.is() || (mxTable->getSdrTableObj() == nullptr) ) throw DisposedException(); - SdrModel& rModel(mxTable->getSdrTableObj()->getSdrModelFromSdrObject()); - const bool bUndo(mxTable->getSdrTableObj()->IsInserted() && rModel.IsUndoEnabled()); + SdrModel* pModel = mxTable->getSdrTableObj()->GetModel(); + const bool bUndo = pModel && mxTable->getSdrTableObj()->IsInserted() && pModel->IsUndoEnabled(); if( bUndo ) - rModel.BegUndo( ImpGetResStr(STR_TABLE_MERGE) ); + pModel->BegUndo( ImpGetResStr(STR_TABLE_MERGE) ); try { @@ -260,9 +260,10 @@ void SAL_CALL CellCursor::merge( ) } if( bUndo ) - rModel.EndUndo(); + pModel->EndUndo(); - rModel.SetChanged(); + if( pModel ) + pModel->SetChanged(); } @@ -502,11 +503,10 @@ void SAL_CALL CellCursor::split( sal_Int32 nColumns, sal_Int32 nRows ) if( !mxTable.is() || (mxTable->getSdrTableObj() == nullptr) ) throw DisposedException(); - SdrModel& rModel(mxTable->getSdrTableObj()->getSdrModelFromSdrObject()); - const bool bUndo(mxTable->getSdrTableObj()->IsInserted() && rModel.IsUndoEnabled()); - + SdrModel* pModel = mxTable->getSdrTableObj()->GetModel(); + const bool bUndo = pModel && mxTable->getSdrTableObj()->IsInserted() && pModel->IsUndoEnabled(); if( bUndo ) - rModel.BegUndo( ImpGetResStr(STR_TABLE_SPLIT) ); + pModel->BegUndo( ImpGetResStr(STR_TABLE_SPLIT) ); try { @@ -526,9 +526,10 @@ void SAL_CALL CellCursor::split( sal_Int32 nColumns, sal_Int32 nRows ) } if( bUndo ) - rModel.EndUndo(); + pModel->EndUndo(); - rModel.SetChanged(); + if( pModel ) + pModel->SetChanged(); } diff --git a/svx/source/table/svdotable.cxx b/svx/source/table/svdotable.cxx index f8b23626b281..dab61a948e33 100644 --- a/svx/source/table/svdotable.cxx +++ b/svx/source/table/svdotable.cxx @@ -684,7 +684,7 @@ sal_Int32 SdrTableObjImpl::getRowCount() const void SdrTableObjImpl::LayoutTable( tools::Rectangle& rArea, bool bFitWidth, bool bFitHeight ) { - if(mpLayouter) + if( mpLayouter && mpTableObj->GetModel() ) { // Optimization: SdrTableObj::SetChanged() can call this very often, repeatedly // with the same settings, noticeably increasing load time. Skip if already done. @@ -749,20 +749,20 @@ sdr::contact::ViewContact* SdrTableObj::CreateObjectSpecificViewContact() return new sdr::contact::ViewContactOfTableObj(*this); } -SdrTableObj::SdrTableObj(SdrModel& rSdrModel) -: SdrTextObj(rSdrModel) + +SdrTableObj::SdrTableObj(SdrModel* _pModel) { + pModel = _pModel; init( 1, 1 ); } -SdrTableObj::SdrTableObj( - SdrModel& rSdrModel, - const ::tools::Rectangle& rNewRect, - sal_Int32 nColumns, - sal_Int32 nRows) -: SdrTextObj(rSdrModel, rNewRect) - ,maLogicRect(rNewRect) + +SdrTableObj::SdrTableObj(SdrModel* _pModel, const ::tools::Rectangle& rNewRect, sal_Int32 nColumns, sal_Int32 nRows) +: SdrTextObj( rNewRect ) +, maLogicRect( rNewRect ) { + pModel = _pModel; + if( nColumns <= 0 ) nColumns = 1; @@ -779,16 +779,6 @@ void SdrTableObj::init( sal_Int32 nColumns, sal_Int32 nRows ) mpImpl = new SdrTableObjImpl; mpImpl->init( this, nColumns, nRows ); - - // Stuff done from old SetModel: - if( !maLogicRect.IsEmpty() ) - { - maRect = maLogicRect; - mpImpl->LayoutTable( maRect, false, false ); - } - - // Also init from old SetModel: - mpImpl->SetModel(&getSdrModelFromSdrObject()); } @@ -1359,6 +1349,28 @@ sal_uInt16 SdrTableObj::GetObjIdentifier() const return static_cast<sal_uInt16>(OBJ_TABLE); } + +void SdrTableObj::SetModel(SdrModel* pNewModel) +{ + SdrModel* pOldModel = GetModel(); + if( pNewModel != pOldModel ) + { + SdrTextObj::SetModel(pNewModel); + + if( mpImpl.is() ) + { + mpImpl->SetModel( pNewModel ); + + if( !maLogicRect.IsEmpty() ) + { + maRect = maLogicRect; + mpImpl->LayoutTable( maRect, false, false ); + } + } + } +} + + void SdrTableObj::TakeTextRect( SdrOutliner& rOutliner, tools::Rectangle& rTextRect, bool bNoEditText, tools::Rectangle* pAnchorRect, bool /*bLineWidth*/ ) const { if( mpImpl.is() ) @@ -1406,9 +1418,9 @@ void SdrTableObj::TakeTextRect( const CellPos& rPos, SdrOutliner& rOutliner, too if (pPara) { - const bool bHitTest(&getSdrModelFromSdrObject().GetHitTestOutliner() == &rOutliner); - const SdrTextObj* pTestObj(rOutliner.GetTextObj()); + const bool bHitTest = pModel && (&pModel->GetHitTestOutliner() == &rOutliner); + const SdrTextObj* pTestObj = rOutliner.GetTextObj(); if( !pTestObj || !bHitTest || (pTestObj != this) || (pTestObj->GetOutlinerParaObject() != xCell->GetOutlinerParaObject()) ) { if( bHitTest ) // #i33696# take back fix #i27510# @@ -1553,9 +1565,12 @@ void SdrTableObj::TakeTextEditArea( const CellPos& rPos, Size* pPaperMin, Size* aAnkSiz.AdjustWidth( -1 ); aAnkSiz.AdjustHeight( -1 ); // because GetSize() increments by one Size aMaxSiz(aAnkSiz.Width(),1000000); - Size aTmpSiz(getSdrModelFromSdrObject().GetMaxObjSize()); - if (aTmpSiz.Height()!=0) - aMaxSiz.setHeight(aTmpSiz.Height() ); + if (pModel!=nullptr) + { + Size aTmpSiz(pModel->GetMaxObjSize()); + if (aTmpSiz.Height()!=0) + aMaxSiz.setHeight(aTmpSiz.Height() ); + } CellRef xCell( mpImpl->getCell( rPos ) ); SdrTextVertAdjust eVAdj = xCell.is() ? xCell->GetTextVerticalAdjust() : SDRTEXTVERTADJUST_TOP; @@ -1646,9 +1661,9 @@ OUString SdrTableObj::TakeObjNamePlural() const } -SdrTableObj* SdrTableObj::Clone(SdrModel* pTargetModel) const +SdrTableObj* SdrTableObj::Clone() const { - return CloneHelper< SdrTableObj >(pTargetModel); + return CloneHelper< SdrTableObj >(); } SdrTableObj& SdrTableObj::operator=(const SdrTableObj& rObj) @@ -1709,20 +1724,20 @@ bool SdrTableObj::BegTextEdit(SdrOutliner& rOutl) mbInEditMode = true; rOutl.Init( OutlinerMode::TextObject ); - rOutl.SetRefDevice(getSdrModelFromSdrObject().GetRefDevice()); + rOutl.SetRefDevice( pModel->GetRefDevice() ); - bool bUpdMerk=rOutl.GetUpdateMode(); - if (bUpdMerk) rOutl.SetUpdateMode(false); - Size aPaperMin; - Size aPaperMax; - tools::Rectangle aEditArea; - TakeTextEditArea(&aPaperMin,&aPaperMax,&aEditArea,nullptr); + bool bUpdMerk=rOutl.GetUpdateMode(); + if (bUpdMerk) rOutl.SetUpdateMode(false); + Size aPaperMin; + Size aPaperMax; + tools::Rectangle aEditArea; + TakeTextEditArea(&aPaperMin,&aPaperMax,&aEditArea,nullptr); - rOutl.SetMinAutoPaperSize(aPaperMin); - rOutl.SetMaxAutoPaperSize(aPaperMax); - rOutl.SetPaperSize(aPaperMax); + rOutl.SetMinAutoPaperSize(aPaperMin); + rOutl.SetMaxAutoPaperSize(aPaperMax); + rOutl.SetPaperSize(aPaperMax); - if (bUpdMerk) rOutl.SetUpdateMode(true); + if (bUpdMerk) rOutl.SetUpdateMode(true); EEControlBits nStat=rOutl.GetControlWord(); nStat |= EEControlBits::AUTOPAGESIZE; @@ -1743,14 +1758,14 @@ bool SdrTableObj::BegTextEdit(SdrOutliner& rOutl) void SdrTableObj::EndTextEdit(SdrOutliner& rOutl) { - if (getSdrModelFromSdrObject().IsUndoEnabled() && !mpImpl->maUndos.empty()) + if (GetModel() && GetModel()->IsUndoEnabled() && !mpImpl->maUndos.empty()) { // These actions should be on the undo stack after text edit. for (std::unique_ptr<SdrUndoAction>& pAction : mpImpl->maUndos) - getSdrModelFromSdrObject().AddUndo(pAction.release()); + GetModel()->AddUndo(pAction.release()); mpImpl->maUndos.clear(); - getSdrModelFromSdrObject().AddUndo(getSdrModelFromSdrObject().GetSdrUndoFactory().CreateUndoGeoObject(*this)); + GetModel()->AddUndo(GetModel()->GetSdrUndoFactory().CreateUndoGeoObject(*this)); } if(rOutl.IsModified()) @@ -1795,15 +1810,16 @@ void SdrTableObj::NbcSetOutlinerParaObject( OutlinerParaObject* pTextObject) CellRef xCell( getActiveCell() ); if( xCell.is() ) { - // Update HitTestOutliner - const SdrTextObj* pTestObj(getSdrModelFromSdrObject().GetHitTestOutliner().GetTextObj()); - - if(pTestObj && pTestObj->GetOutlinerParaObject() == xCell->GetOutlinerParaObject()) + if( pModel ) { - getSdrModelFromSdrObject().GetHitTestOutliner().SetTextObj(nullptr); + // Update HitTestOutliner + const SdrTextObj* pTestObj = pModel->GetHitTestOutliner().GetTextObj(); + if( pTestObj && pTestObj->GetOutlinerParaObject() == xCell->GetOutlinerParaObject() ) + pModel->GetHitTestOutliner().SetTextObj( nullptr ); } xCell->SetOutlinerParaObject( pTextObject ); + SetTextSizeDirty(); NbcAdjustTextFrameWidthAndHeight(); } @@ -1875,7 +1891,7 @@ bool SdrTableObj::AdjustTextFrameWidthAndHeight() bool SdrTableObj::AdjustTextFrameWidthAndHeight(tools::Rectangle& rR, bool bHeight, bool bWidth) const { - if(rR.IsEmpty() || !mpImpl.is() || !mpImpl->mxTable.is()) + if((pModel == nullptr) || rR.IsEmpty() || !mpImpl.is() || !mpImpl->mxTable.is() ) return false; tools::Rectangle aRectangle( rR ); @@ -2187,7 +2203,7 @@ bool SdrTableObj::applySpecialDrag(SdrDragStat& rDrag) if( pEdgeHdl ) { - if( IsInserted() ) + if( GetModel() && IsInserted() ) { rDrag.SetEndDragChangesAttributes(true); rDrag.SetEndDragChangesLayout(true); @@ -2325,21 +2341,12 @@ void SdrTableObj::RestGeoData(const SdrObjGeoData& rGeo) } -SdrTableObj* SdrTableObj::CloneRange( - const CellPos& rStart, - const CellPos& rEnd, - SdrModel& rTargetModel) +SdrTableObj* SdrTableObj::CloneRange( const CellPos& rStart, const CellPos& rEnd ) { const sal_Int32 nColumns = rEnd.mnCol - rStart.mnCol + 1; const sal_Int32 nRows = rEnd.mnRow - rStart.mnRow + 1; - SdrTableObj* pNewTableObj( - new SdrTableObj( - rTargetModel, - GetCurrentBoundRect(), - nColumns, - nRows)); - + SdrTableObj* pNewTableObj = new SdrTableObj( GetModel(), GetCurrentBoundRect(), nColumns, nRows); pNewTableObj->setTableStyleSettings( getTableStyleSettings() ); pNewTableObj->setTableStyle( getTableStyle() ); diff --git a/svx/source/table/tablecolumn.cxx b/svx/source/table/tablecolumn.cxx index e4007b3b35cf..e6f1c4a77b6b 100644 --- a/svx/source/table/tablecolumn.cxx +++ b/svx/source/table/tablecolumn.cxx @@ -141,10 +141,10 @@ void SAL_CALL TableColumn::setFastPropertyValue( sal_Int32 nHandle, const Any& a bool bOk = false; bool bChange = false; - SdrModel& rModel(mxTableModel->getSdrTableObj()->getSdrModelFromSdrObject()); - TableColumnUndo* pUndo = nullptr; + SdrModel* pModel = mxTableModel->getSdrTableObj()->GetModel(); - if( mxTableModel.is() && mxTableModel->getSdrTableObj() && mxTableModel->getSdrTableObj()->IsInserted() && rModel.IsUndoEnabled() ) + TableColumnUndo* pUndo = nullptr; + if( mxTableModel.is() && mxTableModel->getSdrTableObj() && mxTableModel->getSdrTableObj()->IsInserted() && pModel && pModel->IsUndoEnabled() ) { TableColumnRef xThis( this ); pUndo = new TableColumnUndo( xThis ); @@ -214,7 +214,7 @@ void SAL_CALL TableColumn::setFastPropertyValue( sal_Int32 nHandle, const Any& a { if( pUndo ) { - rModel.AddUndo( pUndo ); + pModel->AddUndo( pUndo ); pUndo = nullptr; } mxTableModel->setModified(true); diff --git a/svx/source/table/tablecontroller.cxx b/svx/source/table/tablecontroller.cxx index aaf4af78bc8f..cc0b6de54254 100644 --- a/svx/source/table/tablecontroller.cxx +++ b/svx/source/table/tablecontroller.cxx @@ -140,44 +140,35 @@ void SAL_CALL SvxTableControllerModifyListener::disposing( const css::lang::Even // class SvxTableController -rtl::Reference< sdr::SelectionController > CreateTableController( - SdrView& rView, - const SdrTableObj& rObj, - const rtl::Reference< sdr::SelectionController >& xRefController ) +rtl::Reference< sdr::SelectionController > CreateTableController( SdrObjEditView* pView, const SdrTableObj* pObj, const rtl::Reference< sdr::SelectionController >& xRefController ) { - return SvxTableController::create(rView, rObj, xRefController); + return SvxTableController::create( pView, pObj, xRefController ); } -rtl::Reference< sdr::SelectionController > SvxTableController::create( - SdrView& rView, - const SdrTableObj& rObj, - const rtl::Reference< sdr::SelectionController >& xRefController ) +rtl::Reference< sdr::SelectionController > SvxTableController::create( SdrObjEditView* pView, const SdrTableObj* pObj, const rtl::Reference< sdr::SelectionController >& xRefController ) { if( xRefController.is() ) { SvxTableController* pController = dynamic_cast< SvxTableController* >( xRefController.get() ); - - if(pController && (pController->mxTableObj.get() == &rObj) && (&pController->mrView == &rView)) - { + if( pController && (pController->mxTableObj.get() == pObj) && (pController->mpView == pView) ) return xRefController; - } } - - return new SvxTableController(rView, rObj); + return new SvxTableController( pView, pObj ); } -SvxTableController::SvxTableController( - SdrView& rView, - const SdrTableObj& rObj) -: mbCellSelectionMode(false) - ,mbLeftButtonDown(false) - ,mpSelectionOverlay(nullptr) - ,mrView(rView) - ,mxTableObj(const_cast< SdrTableObj* >(&rObj)) - ,mnUpdateEvent( nullptr ) +SvxTableController::SvxTableController( SdrObjEditView* pView, const SdrTableObj* pObj ) +: mbCellSelectionMode(false) +, mbLeftButtonDown(false) +, mpSelectionOverlay(nullptr) +, mpView( dynamic_cast< SdrView* >( pView ) ) +, mxTableObj( const_cast< SdrTableObj* >( pObj ) ) +, mpModel( nullptr ) +, mnUpdateEvent( nullptr ) { + mpModel = mxTableObj->GetModel(); + mxTableObj->getActiveCellPos( maCursorFirstPos ); maCursorLastPos = maCursorFirstPos; @@ -211,14 +202,11 @@ SvxTableController::~SvxTableController() bool SvxTableController::onKeyInput(const KeyEvent& rKEvt, vcl::Window* pWindow ) { - if(!checkTableObject()) + if( !checkTableObject() ) return false; - SdrTableObj& rTableObj(*mxTableObj.get()); - SdrModel& rModel(rTableObj.getSdrModelFromSdrObject()); - // check if we are read only - if( rModel.IsReadOnly()) + if( mpModel && mpModel->IsReadOnly()) { switch( rKEvt.GetKeyCode().GetCode() ) { @@ -264,7 +252,7 @@ bool SvxTableController::onMouseButtonDown(const MouseEvent& rMEvt, vcl::Window* if (comphelper::LibreOfficeKit::isActive() && !pWindow) { // Tiled rendering: get the window that has the disabled map mode. - if (OutputDevice* pOutputDevice = mrView.GetFirstOutputDevice()) + if (OutputDevice* pOutputDevice = mpView->GetFirstOutputDevice()) { if (pOutputDevice->GetOutDevType() == OUTDEV_WINDOW) pWindow = static_cast<vcl::Window*>(pOutputDevice); @@ -275,7 +263,7 @@ bool SvxTableController::onMouseButtonDown(const MouseEvent& rMEvt, vcl::Window* return false; SdrViewEvent aVEvt; - if( !rMEvt.IsRight() && mrView.PickAnything(rMEvt,SdrMouseEventKind::BUTTONDOWN, aVEvt) == SdrHitKind::Handle ) + if( !rMEvt.IsRight() && mpView->PickAnything(rMEvt,SdrMouseEventKind::BUTTONDOWN, aVEvt) == SdrHitKind::Handle ) return false; TableHitKind eHit = mxTableObj->CheckTableHit(pixelToLogic(rMEvt.GetPosPixel(), pWindow), maMouseDownPos.mnCol, maMouseDownPos.mnRow); @@ -296,7 +284,7 @@ bool SvxTableController::onMouseButtonDown(const MouseEvent& rMEvt, vcl::Window* { RemoveSelection(); - SdrHdl* pHdl = mrView.PickHandle(pixelToLogic(rMEvt.GetPosPixel(), pWindow)); + SdrHdl* pHdl = mpView->PickHandle(pixelToLogic(rMEvt.GetPosPixel(), pWindow)); if( pHdl ) { @@ -316,7 +304,7 @@ bool SvxTableController::onMouseButtonDown(const MouseEvent& rMEvt, vcl::Window* if (comphelper::LibreOfficeKit::isActive() && rMEvt.GetClicks() == 2 && rMEvt.IsLeft() && eHit == TableHitKind::CellTextArea) { bool bEmptyOutliner = false; - if (Outliner* pOutliner = mrView.GetTextEditOutliner()) + if (Outliner* pOutliner = mpView->GetTextEditOutliner()) { if (pOutliner->GetParagraphCount() == 1) { @@ -330,7 +318,7 @@ bool SvxTableController::onMouseButtonDown(const MouseEvent& rMEvt, vcl::Window* StartSelection(maMouseDownPos); setSelectedCells(maMouseDownPos, maMouseDownPos); // Update graphic selection, should be hidden now. - mrView.AdjustMarkHdl(); + mpView->AdjustMarkHdl(); return true; } } @@ -394,7 +382,7 @@ void SvxTableController::onSelectionHasChanged() } else { - const SdrMarkList& rMarkList= mrView.GetMarkedObjectList(); + const SdrMarkList& rMarkList= mpView->GetMarkedObjectList(); if( rMarkList.GetMarkCount() == 1 ) bSelected = mxTableObj.get() == rMarkList.GetMark(0)->GetMarkedSdrObj(); /* fdo#46186 Selecting the table means selecting the entire cells */ @@ -419,13 +407,12 @@ void SvxTableController::onSelectionHasChanged() void SvxTableController::GetState( SfxItemSet& rSet ) { - if(!mxTable.is() || !mxTableObj.is()) + if( !mxTable.is() || !mxTableObj.is() || !mxTableObj->GetModel() ) return; - SdrTableObj& rTableObj(*mxTableObj.get()); - SdrModel& rModel(rTableObj.getSdrModelFromSdrObject()); std::unique_ptr<SfxItemSet> xSet; - bool bVertDone(false); + + bool bVertDone = false; // Iterate over all requested items in the set. SfxWhichIter aIter( rSet ); @@ -438,11 +425,15 @@ void SvxTableController::GetState( SfxItemSet& rSet ) case SID_TABLE_VERT_CENTER: case SID_TABLE_VERT_NONE: { - if(!bVertDone) + if( !mxTable.is() || !mxTableObj->GetModel() ) + { + rSet.DisableItem(nWhich); + } + else if(!bVertDone) { if (!xSet) { - xSet.reset(new SfxItemSet(rModel.GetItemPool())); + xSet.reset(new SfxItemSet( mxTableObj->GetModel()->GetItemPool() )); MergeAttrFromSelectedCells(*xSet, false); } @@ -514,270 +505,277 @@ void SvxTableController::GetState( SfxItemSet& rSet ) void SvxTableController::onInsert( sal_uInt16 nSId, const SfxItemSet* pArgs ) { - if(!checkTableObject()) + sdr::table::SdrTableObj* pTableObj = mxTableObj.get(); + if( !pTableObj ) return; - SdrTableObj& rTableObj(*mxTableObj.get()); - SdrModel& rModel(rTableObj.getSdrModelFromSdrObject()); - bool bInsertAfter = true; - sal_uInt16 nCount = 0; - - if( pArgs ) + if( mxTable.is() ) try { - const SfxPoolItem* pItem = nullptr; - pArgs->GetItemState(nSId, false, &pItem); - if (pItem) + + bool bInsertAfter = true; + sal_uInt16 nCount = 0; + if( pArgs ) { - nCount = static_cast<const SfxInt16Item*>(pItem)->GetValue(); - if(SfxItemState::SET == pArgs->GetItemState(SID_TABLE_PARAM_INSERT_AFTER, true, &pItem)) - bInsertAfter = static_cast<const SfxBoolItem*>(pItem)->GetValue(); + const SfxPoolItem* pItem = nullptr; + pArgs->GetItemState(nSId, false, &pItem); + if (pItem) + { + nCount = static_cast<const SfxInt16Item*>(pItem)->GetValue(); + if(SfxItemState::SET == pArgs->GetItemState(SID_TABLE_PARAM_INSERT_AFTER, true, &pItem)) + bInsertAfter = static_cast<const SfxBoolItem*>(pItem)->GetValue(); + } } - } - CellPos aStart, aEnd; - if( hasSelectedCells() ) - { - getSelectedCells( aStart, aEnd ); - } - else - { - if( bInsertAfter ) + CellPos aStart, aEnd; + if( hasSelectedCells() ) { - aStart.mnCol = mxTable->getColumnCount() - 1; - aStart.mnRow = mxTable->getRowCount() - 1; - aEnd = aStart; + getSelectedCells( aStart, aEnd ); + } + else + { + if( bInsertAfter ) + { + aStart.mnCol = mxTable->getColumnCount() - 1; + aStart.mnRow = mxTable->getRowCount() - 1; + aEnd = aStart; + } } - } - if( rTableObj.IsTextEditActive() ) - mrView.SdrEndTextEdit(true); + if( pTableObj->IsTextEditActive() ) + mpView->SdrEndTextEdit(true); - RemoveSelection(); + RemoveSelection(); - const OUString sSize( "Size" ); - const bool bUndo(rModel.IsUndoEnabled()); + const OUString sSize( "Size" ); - switch( nSId ) - { - case SID_TABLE_INSERT_COL: - { - TableModelNotifyGuard aGuard( mxTable.get() ); + const bool bUndo = mpModel && mpModel->IsUndoEnabled(); - if( bUndo ) + switch( nSId ) { - rModel.BegUndo( ImpGetResStr(STR_TABLE_INSCOL) ); - rModel.AddUndo(rModel.GetSdrUndoFactory().CreateUndoGeoObject(rTableObj)); - } + case SID_TABLE_INSERT_COL: + { + TableModelNotifyGuard aGuard( mxTable.get() ); - Reference< XTableColumns > xCols( mxTable->getColumns() ); - const sal_Int32 nNewColumns = (nCount == 0) ? (aEnd.mnCol - aStart.mnCol + 1) : nCount; - const sal_Int32 nNewStartColumn = aEnd.mnCol + (bInsertAfter ? 1 : 0); - xCols->insertByIndex( nNewStartColumn, nNewColumns ); + if( bUndo ) + { + mpModel->BegUndo( ImpGetResStr(STR_TABLE_INSCOL) ); + mpModel->AddUndo( mpModel->GetSdrUndoFactory().CreateUndoGeoObject(*pTableObj) ); + } - for( sal_Int32 nOffset = 0; nOffset < nNewColumns; nOffset++ ) - { - // Resolves fdo#61540 - // On Insert before, the reference column whose size is going to be - // used for newly created column(s) is wrong. As the new columns are - // inserted before the reference column, the reference column moved - // to the new position by no., of new columns i.e (earlier+newcolumns). - Reference< XPropertySet >(xCols->getByIndex(nNewStartColumn+nOffset), UNO_QUERY_THROW )-> - setPropertyValue( sSize, - Reference< XPropertySet >(xCols->getByIndex( bInsertAfter?nNewStartColumn-1:nNewStartColumn+nNewColumns ), UNO_QUERY_THROW )-> - getPropertyValue( sSize ) ); - } + Reference< XTableColumns > xCols( mxTable->getColumns() ); + const sal_Int32 nNewColumns = (nCount == 0) ? (aEnd.mnCol - aStart.mnCol + 1) : nCount; + const sal_Int32 nNewStartColumn = aEnd.mnCol + (bInsertAfter ? 1 : 0); + xCols->insertByIndex( nNewStartColumn, nNewColumns ); - // Copy cell properties - sal_Int32 nPropSrcCol = (bInsertAfter ? aEnd.mnCol : aStart.mnCol + nNewColumns); - sal_Int32 nRowSpan = 0; - bool bNewSpan = false; + for( sal_Int32 nOffset = 0; nOffset < nNewColumns; nOffset++ ) + { + // Resolves fdo#61540 + // On Insert before, the reference column whose size is going to be + // used for newly created column(s) is wrong. As the new columns are + // inserted before the reference column, the reference column moved + // to the new position by no., of new columns i.e (earlier+newcolumns). + Reference< XPropertySet >(xCols->getByIndex(nNewStartColumn+nOffset), UNO_QUERY_THROW )-> + setPropertyValue( sSize, + Reference< XPropertySet >(xCols->getByIndex( bInsertAfter?nNewStartColumn-1:nNewStartColumn+nNewColumns ), UNO_QUERY_THROW )-> + getPropertyValue( sSize ) ); + } - for( sal_Int32 nRow = 0; nRow < mxTable->getRowCount(); ++nRow ) - { - CellRef xSourceCell( dynamic_cast< Cell* >( mxTable->getCellByPosition( nPropSrcCol, nRow ).get() ) ); + // Copy cell properties + sal_Int32 nPropSrcCol = (bInsertAfter ? aEnd.mnCol : aStart.mnCol + nNewColumns); + sal_Int32 nRowSpan = 0; + bool bNewSpan = false; - // When we insert new COLUMNs, we want to copy ROW spans. - if (xSourceCell.is() && nRowSpan == 0) + for( sal_Int32 nRow = 0; nRow < mxTable->getRowCount(); ++nRow ) { - // we are not in a span yet. Let's find out if the current cell is in a span. - sal_Int32 nColSpan = sal_Int32(); - sal_Int32 nSpanInfoCol = sal_Int32(); + CellRef xSourceCell( dynamic_cast< Cell* >( mxTable->getCellByPosition( nPropSrcCol, nRow ).get() ) ); - if( xSourceCell->getRowSpan() > 1 ) - { - // The current cell is the top-left cell in a span. - // Get the span info and propagate it to the target. - nRowSpan = xSourceCell->getRowSpan(); - nColSpan = xSourceCell->getColumnSpan(); - nSpanInfoCol = nPropSrcCol; - } - else if( xSourceCell->isMerged() ) + // When we insert new COLUMNs, we want to copy ROW spans. + if (xSourceCell.is() && nRowSpan == 0) { - // The current cell is a middle cell in a 2D span. - // Look for the top-left cell in the span. - for( nSpanInfoCol = nPropSrcCol - 1; nSpanInfoCol >= 0; --nSpanInfoCol ) + // we are not in a span yet. Let's find out if the current cell is in a span. + sal_Int32 nColSpan = sal_Int32(); + sal_Int32 nSpanInfoCol = sal_Int32(); + + if( xSourceCell->getRowSpan() > 1 ) { - CellRef xMergeInfoCell( dynamic_cast< Cell* >( mxTable->getCellByPosition( nSpanInfoCol, nRow ).get() ) ); - if (xMergeInfoCell.is() && !xMergeInfoCell->isMerged()) + // The current cell is the top-left cell in a span. + // Get the span info and propagate it to the target. + nRowSpan = xSourceCell->getRowSpan(); + nColSpan = xSourceCell->getColumnSpan(); + nSpanInfoCol = nPropSrcCol; + } + else if( xSourceCell->isMerged() ) + { + // The current cell is a middle cell in a 2D span. + // Look for the top-left cell in the span. + for( nSpanInfoCol = nPropSrcCol - 1; nSpanInfoCol >= 0; --nSpanInfoCol ) { - nRowSpan = xMergeInfoCell->getRowSpan(); - nColSpan = xMergeInfoCell->getColumnSpan(); - break; + CellRef xMergeInfoCell( dynamic_cast< Cell* >( mxTable->getCellByPosition( nSpanInfoCol, nRow ).get() ) ); + if (xMergeInfoCell.is() && !xMergeInfoCell->isMerged()) + { + nRowSpan = xMergeInfoCell->getRowSpan(); + nColSpan = xMergeInfoCell->getColumnSpan(); + break; + } } + if( nRowSpan == 1 ) + nRowSpan = 0; } - if( nRowSpan == 1 ) - nRowSpan = 0; - } - // The target columns are outside the span; Start a new span. - if( nRowSpan > 0 && ( nNewStartColumn < nSpanInfoCol || nSpanInfoCol + nColSpan <= nNewStartColumn ) ) - bNewSpan = true; - } + // The target columns are outside the span; Start a new span. + if( nRowSpan > 0 && ( nNewStartColumn < nSpanInfoCol || nSpanInfoCol + nColSpan <= nNewStartColumn ) ) + bNewSpan = true; + } - // Now copy the properties from the source to the targets - for( sal_Int32 nOffset = 0; nOffset < nNewColumns; nOffset++ ) - { - CellRef xTargetCell( dynamic_cast< Cell* >( mxTable->getCellByPosition( nNewStartColumn + nOffset, nRow ).get() ) ); - if( xTargetCell.is() ) + // Now copy the properties from the source to the targets + for( sal_Int32 nOffset = 0; nOffset < nNewColumns; nOffset++ ) { - if( nRowSpan > 0 ) + CellRef xTargetCell( dynamic_cast< Cell* >( mxTable->getCellByPosition( nNewStartColumn + nOffset, nRow ).get() ) ); + if( xTargetCell.is() ) { - if( bNewSpan ) - xTargetCell->merge( 1, nRowSpan ); - else - xTargetCell->setMerged(); + if( nRowSpan > 0 ) + { + if( bNewSpan ) + xTargetCell->merge( 1, nRowSpan ); + else + xTargetCell->setMerged(); + } + xTargetCell->copyFormatFrom( xSourceCell ); } - xTargetCell->copyFormatFrom( xSourceCell ); } - } - if( nRowSpan > 0 ) - { - --nRowSpan; - bNewSpan = false; + if( nRowSpan > 0 ) + { + --nRowSpan; + bNewSpan = false; + } } - } - if( bUndo ) - rModel.EndUndo(); - - aStart.mnCol = nNewStartColumn; - aStart.mnRow = 0; - aEnd.mnCol = aStart.mnCol + nNewColumns - 1; - aEnd.mnRow = mxTable->getRowCount() - 1; - break; - } - - case SID_TABLE_INSERT_ROW: - { - TableModelNotifyGuard aGuard( mxTable.get() ); + if( bUndo ) + mpModel->EndUndo(); - if( bUndo ) - { - rModel.BegUndo( ImpGetResStr(STR_TABLE_INSROW ) ); - rModel.AddUndo(rModel.GetSdrUndoFactory().CreateUndoGeoObject(rTableObj)); + aStart.mnCol = nNewStartColumn; + aStart.mnRow = 0; + aEnd.mnCol = aStart.mnCol + nNewColumns - 1; + aEnd.mnRow = mxTable->getRowCount() - 1; + break; } - Reference< XTableRows > xRows( mxTable->getRows() ); - const sal_Int32 nNewRows = (nCount == 0) ? (aEnd.mnRow - aStart.mnRow + 1) : nCount; - const sal_Int32 nNewRowStart = aEnd.mnRow + (bInsertAfter ? 1 : 0); - xRows->insertByIndex( nNewRowStart, nNewRows ); - - for( sal_Int32 nOffset = 0; nOffset < nNewRows; nOffset++ ) + case SID_TABLE_INSERT_ROW: { - Reference< XPropertySet >( xRows->getByIndex( aEnd.mnRow + nOffset + 1 ), UNO_QUERY_THROW )-> - setPropertyValue( sSize, - Reference< XPropertySet >( xRows->getByIndex( aStart.mnRow + nOffset ), UNO_QUERY_THROW )-> - getPropertyValue( sSize ) ); - } + TableModelNotifyGuard aGuard( mxTable.get() ); - // Copy the cell properties - sal_Int32 nPropSrcRow = (bInsertAfter ? aEnd.mnRow : aStart.mnRow + nNewRows); - sal_Int32 nColSpan = 0; - bool bNewSpan = false; + if( bUndo ) + { + mpModel->BegUndo( ImpGetResStr(STR_TABLE_INSROW ) ); + mpModel->AddUndo( mpModel->GetSdrUndoFactory().CreateUndoGeoObject(*pTableObj) ); + } - for( sal_Int32 nCol = 0; nCol < mxTable->getColumnCount(); ++nCol ) - { - CellRef xSourceCell( dynamic_cast< Cell* >( mxTable->getCellByPosition( nCol, nPropSrcRow ).get() ) ); + Reference< XTableRows > xRows( mxTable->getRows() ); + const sal_Int32 nNewRows = (nCount == 0) ? (aEnd.mnRow - aStart.mnRow + 1) : nCount; + const sal_Int32 nNewRowStart = aEnd.mnRow + (bInsertAfter ? 1 : 0); + xRows->insertByIndex( nNewRowStart, nNewRows ); - if (!xSourceCell.is()) - continue; + for( sal_Int32 nOffset = 0; nOffset < nNewRows; nOffset++ ) + { + Reference< XPropertySet >( xRows->getByIndex( aEnd.mnRow + nOffset + 1 ), UNO_QUERY_THROW )-> + setPropertyValue( sSize, + Reference< XPropertySet >( xRows->getByIndex( aStart.mnRow + nOffset ), UNO_QUERY_THROW )-> + getPropertyValue( sSize ) ); + } + + // Copy the cell properties + sal_Int32 nPropSrcRow = (bInsertAfter ? aEnd.mnRow : aStart.mnRow + nNewRows); + sal_Int32 nColSpan = 0; + bool bNewSpan = false; - // When we insert new ROWs, we want to copy COLUMN spans. - if( nColSpan == 0 ) + for( sal_Int32 nCol = 0; nCol < mxTable->getColumnCount(); ++nCol ) { - // we are not in a span yet. Let's find out if the current cell is in a span. - sal_Int32 nRowSpan = sal_Int32(); - sal_Int32 nSpanInfoRow = sal_Int32(); + CellRef xSourceCell( dynamic_cast< Cell* >( mxTable->getCellByPosition( nCol, nPropSrcRow ).get() ) ); - if( xSourceCell->getColumnSpan() > 1 ) - { - // The current cell is the top-left cell in a span. - // Get the span info and propagate it to the target. - nColSpan = xSourceCell->getColumnSpan(); - nRowSpan = xSourceCell->getRowSpan(); - nSpanInfoRow = nPropSrcRow; - } - else if( xSourceCell->isMerged() ) + if (!xSourceCell.is()) + continue; + + // When we insert new ROWs, we want to copy COLUMN spans. + if( nColSpan == 0 ) { - // The current cell is a middle cell in a 2D span. - // Look for the top-left cell in the span. - for( nSpanInfoRow = nPropSrcRow - 1; nSpanInfoRow >= 0; --nSpanInfoRow ) + // we are not in a span yet. Let's find out if the current cell is in a span. + sal_Int32 nRowSpan = sal_Int32(); + sal_Int32 nSpanInfoRow = sal_Int32(); + + if( xSourceCell->getColumnSpan() > 1 ) + { + // The current cell is the top-left cell in a span. + // Get the span info and propagate it to the target. + nColSpan = xSourceCell->getColumnSpan(); + nRowSpan = xSourceCell->getRowSpan(); + nSpanInfoRow = nPropSrcRow; + } + else if( xSourceCell->isMerged() ) { - CellRef xMergeInfoCell( dynamic_cast< Cell* >( mxTable->getCellByPosition( nCol, nSpanInfoRow ).get() ) ); - if (xMergeInfoCell.is() && !xMergeInfoCell->isMerged()) + // The current cell is a middle cell in a 2D span. + // Look for the top-left cell in the span. + for( nSpanInfoRow = nPropSrcRow - 1; nSpanInfoRow >= 0; --nSpanInfoRow ) { - nColSpan = xMergeInfoCell->getColumnSpan(); - nRowSpan = xMergeInfoCell->getRowSpan(); - break; + CellRef xMergeInfoCell( dynamic_cast< Cell* >( mxTable->getCellByPosition( nCol, nSpanInfoRow ).get() ) ); + if (xMergeInfoCell.is() && !xMergeInfoCell->isMerged()) + { + nColSpan = xMergeInfoCell->getColumnSpan(); + nRowSpan = xMergeInfoCell->getRowSpan(); + break; + } } + if( nColSpan == 1 ) + nColSpan = 0; } - if( nColSpan == 1 ) - nColSpan = 0; - } - // Inserted rows are outside the span; Start a new span. - if( nColSpan > 0 && ( nNewRowStart < nSpanInfoRow || nSpanInfoRow + nRowSpan <= nNewRowStart ) ) - bNewSpan = true; - } + // Inserted rows are outside the span; Start a new span. + if( nColSpan > 0 && ( nNewRowStart < nSpanInfoRow || nSpanInfoRow + nRowSpan <= nNewRowStart ) ) + bNewSpan = true; + } - // Now copy the properties from the source to the targets - for( sal_Int32 nOffset = 0; nOffset < nNewRows; ++nOffset ) - { - CellRef xTargetCell( dynamic_cast< Cell* >( mxTable->getCellByPosition( nCol, nNewRowStart + nOffset ).get() ) ); - if( xTargetCell.is() ) + // Now copy the properties from the source to the targets + for( sal_Int32 nOffset = 0; nOffset < nNewRows; ++nOffset ) { - if( nColSpan > 0 ) + CellRef xTargetCell( dynamic_cast< Cell* >( mxTable->getCellByPosition( nCol, nNewRowStart + nOffset ).get() ) ); + if( xTargetCell.is() ) { - if( bNewSpan ) - xTargetCell->merge( nColSpan, 1 ); - else - xTargetCell->setMerged(); + if( nColSpan > 0 ) + { + if( bNewSpan ) + xTargetCell->merge( nColSpan, 1 ); + else + xTargetCell->setMerged(); + } + xTargetCell->copyFormatFrom( xSourceCell ); } - xTargetCell->copyFormatFrom( xSourceCell ); } - } - if( nColSpan > 0 ) - { - --nColSpan; - bNewSpan = false; + if( nColSpan > 0 ) + { + --nColSpan; + bNewSpan = false; + } } - } - if( bUndo ) - rModel.EndUndo(); + if( bUndo ) + mpModel->EndUndo(); - aStart.mnCol = 0; - aStart.mnRow = nNewRowStart; - aEnd.mnCol = mxTable->getColumnCount() - 1; - aEnd.mnRow = aStart.mnRow + nNewRows - 1; - break; + aStart.mnCol = 0; + aStart.mnRow = nNewRowStart; + aEnd.mnCol = mxTable->getColumnCount() - 1; + aEnd.mnRow = aStart.mnRow + nNewRows - 1; + break; + } + } + + StartSelection( aStart ); + UpdateSelection( aEnd ); } + catch( Exception& ) + { + OSL_FAIL("svx::SvxTableController::onInsert(), exception caught!"); } - - StartSelection( aStart ); - UpdateSelection( aEnd ); } @@ -793,7 +791,7 @@ void SvxTableController::onDelete( sal_uInt16 nSId ) getSelectedCells( aStart, aEnd ); if( pTableObj->IsTextEditActive() ) - mrView.SdrEndTextEdit(true); + mpView->SdrEndTextEdit(true); RemoveSelection(); @@ -832,7 +830,7 @@ void SvxTableController::onDelete( sal_uInt16 nSId ) } if( bDeleteTable ) - mrView.DeleteMarkedObj(); + mpView->DeleteMarkedObj(); else UpdateTableShape(); } @@ -888,16 +886,15 @@ namespace void SvxTableController::onFormatTable( SfxRequest const & rReq ) { - if(!mxTableObj.is()) + sdr::table::SdrTableObj* pTableObj = mxTableObj.get(); + if( !pTableObj ) return; - SdrTableObj& rTableObj(*mxTableObj.get()); - SdrModel& rModel(rTableObj.getSdrModelFromSdrObject()); const SfxItemSet* pArgs = rReq.GetArgs(); - if(!pArgs) + if( !pArgs && pTableObj->GetModel() ) { - SfxItemSet aNewAttr(rModel.GetItemPool()); + SfxItemSet aNewAttr( pTableObj->GetModel()->GetItemPool() ); // merge drawing layer text distance items into SvxBoxItem used by the dialog SvxBoxItem aBoxItem(mergeDrawinglayerTextDistancesAndSvxBoxItem(aNewAttr)); @@ -910,11 +907,7 @@ void SvxTableController::onFormatTable( SfxRequest const & rReq ) aNewAttr.Put( aBoxInfoItem ); SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); - ScopedVclPtr<SfxAbstractTabDialog> xDlg( pFact ? pFact->CreateSvxFormatCellsDialog( - &aNewAttr, - rModel, - &rTableObj) : nullptr ); - + ScopedVclPtr<SfxAbstractTabDialog> xDlg( pFact ? pFact->CreateSvxFormatCellsDialog( &aNewAttr, pTableObj->GetModel(), pTableObj) : nullptr ); // Even Cancel Button is returning positive(101) value, if (xDlg.get() && xDlg->Execute() == RET_OK) { @@ -1033,19 +1026,16 @@ void SvxTableController::Execute( SfxRequest& rReq ) void SvxTableController::SetTableStyle( const SfxItemSet* pArgs ) { - if(!checkTableObject()) - return; - - SdrTableObj& rTableObj(*mxTableObj.get()); - SdrModel& rModel(rTableObj.getSdrModelFromSdrObject()); + SdrTableObj* pTableObj = mxTableObj.get(); + SdrModel* pModel = pTableObj ? pTableObj->GetModel() : nullptr; - if(!pArgs || (SfxItemState::SET != pArgs->GetItemState(SID_TABLE_STYLE, false))) + if( !pTableObj || !pModel || !pArgs || (SfxItemState::SET != pArgs->GetItemState(SID_TABLE_STYLE, false)) ) return; const SfxStringItem* pArg = dynamic_cast< const SfxStringItem* >( &pArgs->Get( SID_TABLE_STYLE ) ); if( pArg && mxTable.is() ) try { - Reference< XStyleFamiliesSupplier > xSFS( rModel.getUnoModel(), UNO_QUERY_THROW ); + Reference< XStyleFamiliesSupplier > xSFS( pModel->getUnoModel(), UNO_QUERY_THROW ); Reference< XNameAccess > xFamilyNameAccess( xSFS->getStyleFamilies(), UNO_QUERY_THROW ); const OUString sFamilyName( "table" ); Reference< XNameAccess > xTableFamilyAccess( xFamilyNameAccess->getByName( sFamilyName ), UNO_QUERY_THROW ); @@ -1055,15 +1045,15 @@ void SvxTableController::SetTableStyle( const SfxItemSet* pArgs ) // found table style with the same name Reference< XIndexAccess > xNewTableStyle( xTableFamilyAccess->getByName( pArg->GetValue() ), UNO_QUERY_THROW ); - const bool bUndo = rModel.IsUndoEnabled(); + const bool bUndo = pModel->IsUndoEnabled(); if( bUndo ) { - rModel.BegUndo(ImpGetResStr(STR_TABLE_STYLE)); - rModel.AddUndo(new TableStyleUndo(rTableObj)); + pModel->BegUndo( ImpGetResStr(STR_TABLE_STYLE) ); + pModel->AddUndo( new TableStyleUndo( *pTableObj ) ); } - rTableObj.setTableStyle( xNewTableStyle ); + pTableObj->setTableStyle( xNewTableStyle ); const sal_Int32 nRowCount = mxTable->getRowCount(); const sal_Int32 nColCount = mxTable->getColumnCount(); @@ -1108,7 +1098,7 @@ void SvxTableController::SetTableStyle( const SfxItemSet* pArgs ) } if( bUndo ) - rModel.EndUndo(); + pModel->EndUndo(); } } catch( Exception& ) @@ -1119,13 +1109,14 @@ void SvxTableController::SetTableStyle( const SfxItemSet* pArgs ) void SvxTableController::SetTableStyleSettings( const SfxItemSet* pArgs ) { - if(!checkTableObject()) + SdrTableObj* pTableObj = mxTableObj.get(); + SdrModel* pModel = pTableObj ? pTableObj->GetModel() : nullptr; + + if( !pTableObj || !pModel ) return; - SdrTableObj& rTableObj(*mxTableObj.get()); - SdrModel& rModel(rTableObj.getSdrModelFromSdrObject()); + TableStyleSettings aSettings( pTableObj->getTableStyleSettings() ); - TableStyleSettings aSettings(rTableObj.getTableStyleSettings() ); const SfxPoolItem *pPoolItem=nullptr; if( SfxItemState::SET == pArgs->GetItemState(ID_VAL_USEFIRSTROWSTYLE, false,&pPoolItem) ) @@ -1146,38 +1137,36 @@ void SvxTableController::SetTableStyleSettings( const SfxItemSet* pArgs ) if( SfxItemState::SET == pArgs->GetItemState(ID_VAL_USEBANDINGCOLUMNSTYLE, false,&pPoolItem) ) aSettings.mbUseColumnBanding = static_cast< const SfxBoolItem* >(pPoolItem)->GetValue(); - if( aSettings == rTableObj.getTableStyleSettings() ) + if( aSettings == pTableObj->getTableStyleSettings() ) return; - const bool bUndo(rModel.IsUndoEnabled()); + const bool bUndo = pModel->IsUndoEnabled(); if( bUndo ) { - rModel.BegUndo( ImpGetResStr(STR_TABLE_STYLE_SETTINGS) ); - rModel.AddUndo(new TableStyleUndo(rTableObj)); + pModel->BegUndo( ImpGetResStr(STR_TABLE_STYLE_SETTINGS) ); + pModel->AddUndo( new TableStyleUndo( *pTableObj ) ); } - rTableObj.setTableStyleSettings( aSettings ); + pTableObj->setTableStyleSettings( aSettings ); if( bUndo ) - rModel.EndUndo(); + pModel->EndUndo(); } void SvxTableController::SetVertical( sal_uInt16 nSId ) { - if(!checkTableObject()) + SdrTableObj* pTableObj = mxTableObj.get(); + if( !mxTable.is() || !pTableObj ) return; - SdrTableObj& rTableObj(*mxTableObj.get()); - SdrModel& rModel(rTableObj.getSdrModelFromSdrObject()); - TableModelNotifyGuard aGuard( mxTable.get() ); - const bool bUndo(rModel.IsUndoEnabled()); + bool bUndo = mpModel && mpModel->IsUndoEnabled(); if (bUndo) { - rModel.BegUndo(ImpGetResStr(STR_TABLE_NUMFORMAT)); - rModel.AddUndo(rModel.GetSdrUndoFactory().CreateUndoAttrObject(rTableObj)); + mpModel->BegUndo(ImpGetResStr(STR_TABLE_NUMFORMAT)); + mpModel->AddUndo(mpModel->GetSdrUndoFactory().CreateUndoAttrObject(*pTableObj)); } CellPos aStart, aEnd; @@ -1219,7 +1208,7 @@ void SvxTableController::SetVertical( sal_uInt16 nSId ) UpdateTableShape(); if (bUndo) - rModel.EndUndo(); + mpModel->EndUndo(); } void SvxTableController::MergeMarkedCells() @@ -1230,7 +1219,7 @@ void SvxTableController::MergeMarkedCells() if( pTableObj ) { if( pTableObj->IsTextEditActive() ) - mrView.SdrEndTextEdit(true); + mpView->SdrEndTextEdit(true); TableModelNotifyGuard aGuard( mxTable.get() ); MergeRange( aStart.mnCol, aStart.mnRow, aEnd.mnCol, aEnd.mnRow ); @@ -1239,102 +1228,102 @@ void SvxTableController::MergeMarkedCells() void SvxTableController::SplitMarkedCells() { - if(!checkTableObject() || !mxTable.is()) - return; + if( mxTable.is() ) + { + CellPos aStart, aEnd; + getSelectedCells( aStart, aEnd ); - SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); - ScopedVclPtr< SvxAbstractSplitTableDialog > xDlg( pFact ? pFact->CreateSvxSplitTableDialog( nullptr, false, 99 ) : nullptr ); + SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); + ScopedVclPtr< SvxAbstractSplitTableDialog > xDlg( pFact ? pFact->CreateSvxSplitTableDialog( nullptr, false, 99 ) : nullptr ); + if( xDlg.get() && xDlg->Execute() ) + { + const sal_Int32 nCount = xDlg->GetCount() - 1; + if( nCount < 1 ) + return; - if( xDlg.get() && xDlg->Execute() ) - { - const sal_Int32 nCount = xDlg->GetCount() - 1; + getSelectedCells( aStart, aEnd ); - if( nCount < 1 ) - return; + Reference< XMergeableCellRange > xRange( mxTable->createCursorByRange( mxTable->getCellRangeByPosition( aStart.mnCol, aStart.mnRow, aEnd.mnCol, aEnd.mnRow ) ), UNO_QUERY_THROW ); - CellPos aStart, aEnd; - getSelectedCells( aStart, aEnd ); - Reference< XMergeableCellRange > xRange( mxTable->createCursorByRange( mxTable->getCellRangeByPosition( aStart.mnCol, aStart.mnRow, aEnd.mnCol, aEnd.mnRow ) ), UNO_QUERY_THROW ); - const sal_Int32 nRowCount = mxTable->getRowCount(); - const sal_Int32 nColCount = mxTable->getColumnCount(); - SdrTableObj& rTableObj(*mxTableObj.get()); + const sal_Int32 nRowCount = mxTable->getRowCount(); + const sal_Int32 nColCount = mxTable->getColumnCount(); - if( rTableObj.IsTextEditActive() ) - mrView.SdrEndTextEdit(true); - TableModelNotifyGuard aGuard( mxTable.get() ); - SdrModel& rModel(rTableObj.getSdrModelFromSdrObject()); - const bool bUndo(rModel.IsUndoEnabled()); + SdrTableObj* pTableObj = mxTableObj.get(); + if( pTableObj ) + { + if( pTableObj->IsTextEditActive() ) + mpView->SdrEndTextEdit(true); - if( bUndo ) - { - rModel.BegUndo( ImpGetResStr(STR_TABLE_SPLIT) ); - rModel.AddUndo(rModel.GetSdrUndoFactory().CreateUndoGeoObject(rTableObj)); - } + TableModelNotifyGuard aGuard( mxTable.get() ); - if( xDlg->IsHorizontal() ) - { - xRange->split( 0, nCount ); - } - else - { - xRange->split( nCount, 0 ); - } + const bool bUndo = mpModel && mpModel->IsUndoEnabled(); + if( bUndo ) + { + mpModel->BegUndo( ImpGetResStr(STR_TABLE_SPLIT) ); + mpModel->AddUndo( mpModel->GetSdrUndoFactory().CreateUndoGeoObject(*pTableObj) ); + } - if( bUndo ) - rModel.EndUndo(); + if( xDlg->IsHorizontal() ) + { + xRange->split( 0, nCount ); + } + else + { + xRange->split( nCount, 0 ); + } - aEnd.mnRow += mxTable->getRowCount() - nRowCount; - aEnd.mnCol += mxTable->getColumnCount() - nColCount; + if( bUndo ) + mpModel->EndUndo(); + } + aEnd.mnRow += mxTable->getRowCount() - nRowCount; + aEnd.mnCol += mxTable->getColumnCount() - nColCount; - setSelectedCells( aStart, aEnd ); + setSelectedCells( aStart, aEnd ); + } } } void SvxTableController::DistributeColumns() { - if(!checkTableObject()) - return; - - SdrTableObj& rTableObj(*mxTableObj.get()); - SdrModel& rModel(rTableObj.getSdrModelFromSdrObject()); - const bool bUndo(rModel.IsUndoEnabled()); - - if( bUndo ) + SdrTableObj* pTableObj = mxTableObj.get(); + if( pTableObj ) { - rModel.BegUndo( ImpGetResStr(STR_TABLE_DISTRIBUTE_COLUMNS) ); - rModel.AddUndo(rModel.GetSdrUndoFactory().CreateUndoGeoObject(rTableObj)); - } + const bool bUndo = mpModel && mpModel->IsUndoEnabled(); + if( bUndo ) + { + mpModel->BegUndo( ImpGetResStr(STR_TABLE_DISTRIBUTE_COLUMNS) ); + mpModel->AddUndo( mpModel->GetSdrUndoFactory().CreateUndoGeoObject(*pTableObj) ); + } - CellPos aStart, aEnd; - getSelectedCells( aStart, aEnd ); - rTableObj.DistributeColumns( aStart.mnCol, aEnd.mnCol ); + CellPos aStart, aEnd; + getSelectedCells( aStart, aEnd ); + pTableObj->DistributeColumns( aStart.mnCol, aEnd.mnCol ); - if( bUndo ) - rModel.EndUndo(); + if( bUndo ) + mpModel->EndUndo(); + } } void SvxTableController::DistributeRows() { - if(!checkTableObject()) - return; - - SdrTableObj& rTableObj(*mxTableObj.get()); - SdrModel& rModel(rTableObj.getSdrModelFromSdrObject()); - const bool bUndo(rModel.IsUndoEnabled()); - - if( bUndo ) + SdrTableObj* pTableObj = mxTableObj.get(); + if( pTableObj ) { - rModel.BegUndo( ImpGetResStr(STR_TABLE_DISTRIBUTE_ROWS) ); - rModel.AddUndo(rModel.GetSdrUndoFactory().CreateUndoGeoObject(rTableObj)); - } + const bool bUndo = mpModel && mpModel->IsUndoEnabled(); + if( bUndo ) + { + mpModel->BegUndo( ImpGetResStr(STR_TABLE_DISTRIBUTE_ROWS) ); + mpModel->AddUndo( mpModel->GetSdrUndoFactory().CreateUndoGeoObject(*pTableObj) ); + } - CellPos aStart, aEnd; - getSelectedCells( aStart, aEnd ); - rTableObj.DistributeRows( aStart.mnRow, aEnd.mnRow ); + CellPos aStart, aEnd; + getSelectedCells( aStart, aEnd ); + pTableObj->DistributeRows( aStart.mnRow, aEnd.mnRow ); - if( bUndo ) - rModel.EndUndo(); + if( bUndo ) + mpModel->EndUndo(); + } } bool SvxTableController::HasMarked() @@ -1344,15 +1333,12 @@ bool SvxTableController::HasMarked() bool SvxTableController::DeleteMarked() { - if(!checkTableObject() || !HasMarked()) + if (!HasMarked()) return false; - SdrTableObj& rTableObj(*mxTableObj.get()); - SdrModel& rModel(rTableObj.getSdrModelFromSdrObject()); - const bool bUndo(rModel.IsUndoEnabled()); - + const bool bUndo = mpModel && mpModel->IsUndoEnabled(); if (bUndo) - rModel.BegUndo(ImpGetResStr(STR_TABLE_DELETE_CELL_CONTENTS)); + mpModel->BegUndo(ImpGetResStr(STR_TABLE_DELETE_CELL_CONTENTS)); CellPos aStart, aEnd; getSelectedCells( aStart, aEnd ); @@ -1371,7 +1357,7 @@ bool SvxTableController::DeleteMarked() } if (bUndo) - rModel.EndUndo(); + mpModel->EndUndo(); UpdateTableShape(); return true; @@ -1458,7 +1444,8 @@ SvxTableController::TblAction SvxTableController::getKeyboardAction(const KeyEve { const bool bMod1 = rKEvt.GetKeyCode().IsMod1(); // ctrl const bool bMod2 = rKEvt.GetKeyCode().IsMod2(); // Alt - const bool bTextEdit = mrView.IsTextEdit(); + + const bool bTextEdit = mpView->IsTextEdit(); TblAction nAction = TblAction::HandledByView; @@ -1589,7 +1576,7 @@ SvxTableController::TblAction SvxTableController::getKeyboardAction(const KeyEve } bool bTextMove = false; - OutlinerView* pOLV = mrView.GetTextEditOutlinerView(); + OutlinerView* pOLV = mpView->GetTextEditOutlinerView(); if( pOLV ) { RemoveSelection(); @@ -1753,7 +1740,7 @@ bool SvxTableController::executeAction(TblAction nAction, bool bSelect, vcl::Win void SvxTableController::gotoCell(const CellPos& rPos, bool bSelect, vcl::Window* pWindow, TblAction nAction /*= TblAction::NONE */) { if( mxTableObj.is() && mxTableObj->IsTextEditActive() ) - mrView.SdrEndTextEdit(true); + mpView->SdrEndTextEdit(true); if( bSelect ) { @@ -1800,29 +1787,22 @@ const CellPos& SvxTableController::getSelectionEnd() void SvxTableController::MergeRange( sal_Int32 nFirstCol, sal_Int32 nFirstRow, sal_Int32 nLastCol, sal_Int32 nLastRow ) { - if(!checkTableObject() || !mxTable.is()) - return; - - try + if( mxTable.is() ) try { Reference< XMergeableCellRange > xRange( mxTable->createCursorByRange( mxTable->getCellRangeByPosition( nFirstCol, nFirstRow,nLastCol, nLastRow ) ), UNO_QUERY_THROW ); - if( xRange->isMergeable() ) { - SdrTableObj& rTableObj(*mxTableObj.get()); - SdrModel& rModel(rTableObj.getSdrModelFromSdrObject()); - const bool bUndo(rModel.IsUndoEnabled()); - + const bool bUndo = mpModel && mpModel->IsUndoEnabled(); if( bUndo ) { - rModel.BegUndo( ImpGetResStr(STR_TABLE_MERGE) ); - rModel.AddUndo(rModel.GetSdrUndoFactory().CreateUndoGeoObject(rTableObj)); + mpModel->BegUndo( ImpGetResStr(STR_TABLE_MERGE) ); + mpModel->AddUndo( mpModel->GetSdrUndoFactory().CreateUndoGeoObject(*mxTableObj.get()) ); } xRange->merge(); if( bUndo ) - rModel.EndUndo(); + mpModel->EndUndo(); } } catch( Exception& ) @@ -1868,20 +1848,16 @@ void SvxTableController::findMergeOrigin( CellPos& rPos ) void SvxTableController::EditCell(const CellPos& rPos, vcl::Window* pWindow, TblAction nAction /*= TblAction::NONE */) { - SdrPageView* pPV(mrView.GetSdrPageView()); + SdrPageView* pPV = mpView->GetSdrPageView(); - if(nullptr == pPV || !checkTableObject()) - return; - - SdrTableObj& rTableObj(*mxTableObj.get()); - - if(rTableObj.GetPage() == pPV->GetPage()) + sdr::table::SdrTableObj* pTableObj = mxTableObj.get(); + if( pTableObj && pTableObj->GetPage() == pPV->GetPage() ) { bool bEmptyOutliner = false; - if(!rTableObj.GetOutlinerParaObject() && mrView.GetTextEditOutliner()) + if(!pTableObj->GetOutlinerParaObject() && mpView->GetTextEditOutliner()) { - ::Outliner* pOutl = mrView.GetTextEditOutliner(); + ::Outliner* pOutl = mpView->GetTextEditOutliner(); sal_Int32 nParaCnt = pOutl->GetParagraphCount(); Paragraph* p1stPara = pOutl->GetParagraph( 0 ); @@ -1898,30 +1874,28 @@ void SvxTableController::EditCell(const CellPos& rPos, vcl::Window* pWindow, Tbl CellPos aPos( rPos ); findMergeOrigin( aPos ); - if( &rTableObj != mrView.GetTextEditObject() || bEmptyOutliner || !rTableObj.IsTextEditActive( aPos ) ) + if( pTableObj != mpView->GetTextEditObject() || bEmptyOutliner || !pTableObj->IsTextEditActive( aPos ) ) { - if( rTableObj.IsTextEditActive() ) - mrView.SdrEndTextEdit(true); + if( pTableObj->IsTextEditActive() ) + mpView->SdrEndTextEdit(true); - rTableObj.setActiveCell( aPos ); + pTableObj->setActiveCell( aPos ); // create new outliner, owner will be the SdrObjEditView - SdrModel& rModel(rTableObj.getSdrModelFromSdrObject()); - SdrOutliner* pOutl(SdrMakeOutliner(OutlinerMode::OutlineObject, rModel)); - - if (pOutl && rTableObj.IsVerticalWriting()) + SdrOutliner* pOutl = mpModel ? SdrMakeOutliner(OutlinerMode::OutlineObject, *mpModel) : nullptr; + if (pOutl && pTableObj->IsVerticalWriting()) pOutl->SetVertical( true ); - if (mrView.SdrBeginTextEdit(&rTableObj, pPV, pWindow, true, pOutl)) + if (mpView->SdrBeginTextEdit(pTableObj, pPV, pWindow, true, pOutl)) { maCursorLastPos = maCursorFirstPos = rPos; - OutlinerView* pOLV = mrView.GetTextEditOutlinerView(); + OutlinerView* pOLV = mpView->GetTextEditOutlinerView(); // Move cursor to end of text ESelection aNewSelection; - const WritingMode eMode = rTableObj.GetWritingMode(); + const WritingMode eMode = pTableObj->GetWritingMode(); if (((nAction == TblAction::GotoLeftCell) || (nAction == TblAction::GotoRightCell)) && (eMode != WritingMode_TB_RL)) { const bool bLast = ((nAction == TblAction::GotoLeftCell) && (eMode == WritingMode_LR_TB)) || @@ -1939,11 +1913,11 @@ void SvxTableController::EditCell(const CellPos& rPos, vcl::Window* pWindow, Tbl void SvxTableController::StopTextEdit() { - if(mrView.IsTextEdit()) + if(mpView->IsTextEdit()) { - mrView.SdrEndTextEdit(); - mrView.SetCurrentObj(OBJ_TABLE); - mrView.SetEditMode(SdrViewEditMode::Edit); + mpView->SdrEndTextEdit(); + mpView->SetCurrentObj(OBJ_TABLE); + mpView->SetEditMode(SdrViewEditMode::Edit); } } @@ -1997,7 +1971,7 @@ void SvxTableController::getSelectedCells( CellPos& rFirst, CellPos& rLast ) } while(bExt); } - else if(mrView.IsTextEdit()) + else if( mpView && mpView->IsTextEdit() ) { rFirst = getSelectionStart(); findMergeOrigin( rFirst ); @@ -2036,7 +2010,7 @@ void SvxTableController::StartSelection( const CellPos& rPos ) StopTextEdit(); mbCellSelectionMode = true; maCursorLastPos = maCursorFirstPos = rPos; - mrView.MarkListHasChanged(); + mpView->MarkListHasChanged(); } @@ -2051,58 +2025,53 @@ void SvxTableController::setSelectedCells( const CellPos& rStart, const CellPos& bool SvxTableController::ChangeFontSize(bool bGrow, const FontList* pFontList) { - if(!checkTableObject() || !mxTable.is()) - return false; - - SdrTableObj& rTableObj(*mxTableObj.get()); - SdrModel& rModel(rTableObj.getSdrModelFromSdrObject()); - - if (mrView.IsTextEdit()) - return true; - - CellPos aStart, aEnd; - - if(hasSelectedCells()) - { - getSelectedCells(aStart, aEnd); - } - else + if (mxTable.is()) { - aStart.mnRow = 0; - aStart.mnCol = 0; - aEnd.mnRow = mxTable->getRowCount() - 1; - aEnd.mnCol = mxTable->getColumnCount() - 1; - } + if (mpView->IsTextEdit()) + return true; - for (sal_Int32 nRow = aStart.mnRow; nRow <= aEnd.mnRow; nRow++) - { - for (sal_Int32 nCol = aStart.mnCol; nCol <= aEnd.mnCol; nCol++) + CellPos aStart, aEnd; + if(hasSelectedCells()) { - CellRef xCell(dynamic_cast< Cell* >(mxTable->getCellByPosition(nCol, nRow).get())); - if (xCell.is()) - { - if (rModel.IsUndoEnabled()) - xCell->AddUndo(); + getSelectedCells(aStart, aEnd); + } + else + { + aStart.mnRow = 0; + aStart.mnCol = 0; + aEnd.mnRow = mxTable->getRowCount() - 1; + aEnd.mnCol = mxTable->getColumnCount() - 1; + } - SfxItemSet aCellSet(xCell->GetItemSet()); - if (EditView::ChangeFontSize(bGrow, aCellSet, pFontList)) + for (sal_Int32 nRow = aStart.mnRow; nRow <= aEnd.mnRow; nRow++) + { + for (sal_Int32 nCol = aStart.mnCol; nCol <= aEnd.mnCol; nCol++) + { + CellRef xCell(dynamic_cast< Cell* >(mxTable->getCellByPosition(nCol, nRow).get())); + if (xCell.is()) { - xCell->SetMergedItemSetAndBroadcast(aCellSet, false); + if (mpModel && mpModel->IsUndoEnabled()) + xCell->AddUndo(); + + SfxItemSet aCellSet(xCell->GetItemSet()); + if (EditView::ChangeFontSize(bGrow, aCellSet, pFontList)) + { + xCell->SetMergedItemSetAndBroadcast(aCellSet, false); + } } } } + UpdateTableShape(); + return true; } - - UpdateTableShape(); - - return true; + return false; } void SvxTableController::UpdateSelection( const CellPos& rPos ) { maCursorLastPos = rPos; - mrView.MarkListHasChanged(); + mpView->MarkListHasChanged(); } @@ -2130,7 +2099,7 @@ void SvxTableController::RemoveSelection() if( mbCellSelectionMode ) { mbCellSelectionMode = false; - mrView.MarkListHasChanged(); + mpView->MarkListHasChanged(); } } @@ -2167,14 +2136,14 @@ void SvxTableController::updateSelectionOverlay() aRanges.push_back( a2DRange ); ::Color aHighlight( COL_BLUE ); - OutputDevice* pOutDev = mrView.GetFirstOutputDevice(); + OutputDevice* pOutDev = mpView->GetFirstOutputDevice(); if( pOutDev ) aHighlight = pOutDev->GetSettings().GetStyleSettings().GetHighlightColor(); - const sal_uInt32 nCount = mrView.PaintWindowCount(); + const sal_uInt32 nCount = mpView->PaintWindowCount(); for( sal_uInt32 nIndex = 0; nIndex < nCount; nIndex++ ) { - SdrPaintWindow* pPaintWindow = mrView.GetPaintWindow(nIndex); + SdrPaintWindow* pPaintWindow = mpView->GetPaintWindow(nIndex); if( pPaintWindow ) { rtl::Reference < sdr::overlay::OverlayManager > xOverlayManager = pPaintWindow->GetOverlayManager(); @@ -2531,15 +2500,13 @@ void SvxTableController::UpdateTableShape() void SvxTableController::SetAttrToSelectedCells(const SfxItemSet& rAttr, bool bReplaceAll) { - if(!checkTableObject() || !mxTable.is()) + if( !mxTable.is() ) return; - SdrTableObj& rTableObj(*mxTableObj.get()); - SdrModel& rModel(rTableObj.getSdrModelFromSdrObject()); - const bool bUndo(rModel.IsUndoEnabled()); + const bool bUndo = mpModel && mpModel->IsUndoEnabled(); if( bUndo ) - rModel.BegUndo( ImpGetResStr(STR_TABLE_NUMFORMAT) ); + mpModel->BegUndo( ImpGetResStr(STR_TABLE_NUMFORMAT) ); CellPos aStart, aEnd; getSelectedCells( aStart, aEnd ); @@ -2577,7 +2544,7 @@ void SvxTableController::SetAttrToSelectedCells(const SfxItemSet& rAttr, bool bR UpdateTableShape(); if( bUndo ) - rModel.EndUndo(); + mpModel->EndUndo(); } @@ -2587,9 +2554,9 @@ bool SvxTableController::GetAttributes(SfxItemSet& rTargetSet, bool bOnlyHardAtt { MergeAttrFromSelectedCells( rTargetSet, bOnlyHardAttr ); - if( mrView.IsTextEdit() ) + if( mpView->IsTextEdit() ) { - OutlinerView* pTextEditOutlinerView = mrView.GetTextEditOutlinerView(); + OutlinerView* pTextEditOutlinerView = mpView->GetTextEditOutlinerView(); if(pTextEditOutlinerView) { // FALSE= consider InvalidItems not as the default, but as "holes" @@ -2608,7 +2575,7 @@ bool SvxTableController::GetAttributes(SfxItemSet& rTargetSet, bool bOnlyHardAtt bool SvxTableController::SetAttributes(const SfxItemSet& rSet, bool bReplaceAll) { - if( mbCellSelectionMode || mrView.IsTextEdit() ) + if( mbCellSelectionMode || mpView->IsTextEdit() ) { SetAttrToSelectedCells( rSet, bReplaceAll ); return true; @@ -2621,17 +2588,16 @@ bool SvxTableController::GetMarkedObjModel( SdrPage* pNewPage ) { if( mxTableObj.is() && mbCellSelectionMode && pNewPage ) try { - sdr::table::SdrTableObj& rTableObj(*mxTableObj.get()); + sdr::table::SdrTableObj& rTableObj = *mxTableObj.get(); + CellPos aStart, aEnd; - getSelectedCells(aStart, aEnd); - - // Clone to new SdrModel - SdrTableObj* pNewTableObj( - rTableObj.CloneRange( - aStart, - aEnd, - pNewPage->getSdrModelFromSdrPage())); - pNewTableObj->SetPage(pNewPage); + getSelectedCells( aStart, aEnd ); + + SdrTableObj* pNewTableObj = rTableObj.CloneRange( aStart, aEnd ); + + pNewTableObj->SetPage( pNewPage ); + pNewTableObj->SetModel( pNewPage->GetModel() ); + pNewPage->InsertObject(pNewTableObj, SAL_MAX_SIZE); return true; @@ -2640,14 +2606,13 @@ bool SvxTableController::GetMarkedObjModel( SdrPage* pNewPage ) { OSL_FAIL( "svx::SvxTableController::GetMarkedObjModel(), exception caught!" ); } - return false; } bool SvxTableController::PasteObjModel( const SdrModel& rModel ) { - if( mxTableObj.is() && (rModel.GetPageCount() >= 1) ) + if( mxTableObj.is() && mpView && (rModel.GetPageCount() >= 1) ) { const SdrPage* pPastePage = rModel.GetPage(0); if( pPastePage && pPastePage->GetObjCount() == 1 ) @@ -2682,8 +2647,8 @@ bool SvxTableController::PasteObject( SdrTableObj const * pPasteTableObj ) CellPos aStart, aEnd; getSelectedCells( aStart, aEnd ); - if( mrView.IsTextEdit() ) - mrView.SdrEndTextEdit(true); + if( mpView->IsTextEdit() ) + mpView->SdrEndTextEdit(true); sal_Int32 nColumns = mxTable->getColumnCount(); sal_Int32 nRows = mxTable->getRowCount(); @@ -2727,51 +2692,51 @@ bool SvxTableController::TakeFormatPaintBrush( std::shared_ptr< SfxItemSet >& /* bool SvxTableController::ApplyFormatPaintBrush( SfxItemSet& rFormatSet, bool bNoCharacterFormats, bool bNoParagraphFormats ) { - if(!mbCellSelectionMode) + if( mbCellSelectionMode ) { - return false; - } + SdrTextObj* pTableObj = dynamic_cast<SdrTextObj*>( mxTableObj.get() ); + if( !pTableObj ) + return false; - if(!checkTableObject()) - return false; + const bool bUndo = mpModel && mpModel->IsUndoEnabled(); - SdrTableObj& rTableObj(*mxTableObj.get()); - SdrModel& rModel(rTableObj.getSdrModelFromSdrObject()); - const bool bUndo(rModel.IsUndoEnabled()); + if( bUndo ) + mpModel->BegUndo( ImpGetResStr(STR_TABLE_NUMFORMAT) ); - if( bUndo ) - rModel.BegUndo(ImpGetResStr(STR_TABLE_NUMFORMAT)); + CellPos aStart, aEnd; + getSelectedCells( aStart, aEnd ); - CellPos aStart, aEnd; - getSelectedCells( aStart, aEnd ); - const bool bFrame = (rFormatSet.GetItemState( SDRATTR_TABLE_BORDER ) == SfxItemState::SET) || (rFormatSet.GetItemState( SDRATTR_TABLE_BORDER_INNER ) == SfxItemState::SET); + const bool bFrame = (rFormatSet.GetItemState( SDRATTR_TABLE_BORDER ) == SfxItemState::SET) || (rFormatSet.GetItemState( SDRATTR_TABLE_BORDER_INNER ) == SfxItemState::SET); - for( sal_Int32 nRow = aStart.mnRow; nRow <= aEnd.mnRow; nRow++ ) - { - for( sal_Int32 nCol = aStart.mnCol; nCol <= aEnd.mnCol; nCol++ ) + for( sal_Int32 nRow = aStart.mnRow; nRow <= aEnd.mnRow; nRow++ ) { - CellRef xCell( dynamic_cast< Cell* >( mxTable->getCellByPosition( nCol, nRow ).get() ) ); - if( xCell.is() ) + for( sal_Int32 nCol = aStart.mnCol; nCol <= aEnd.mnCol; nCol++ ) { - if (bUndo) - xCell->AddUndo(); - SdrText* pText = static_cast< SdrText* >( xCell.get() ); - SdrObjEditView::ApplyFormatPaintBrushToText( rFormatSet, rTableObj, pText, bNoCharacterFormats, bNoParagraphFormats ); + CellRef xCell( dynamic_cast< Cell* >( mxTable->getCellByPosition( nCol, nRow ).get() ) ); + if( xCell.is() ) + { + if (bUndo) + xCell->AddUndo(); + SdrText* pText = static_cast< SdrText* >( xCell.get() ); + SdrObjEditView::ApplyFormatPaintBrushToText( rFormatSet, *pTableObj, pText, bNoCharacterFormats, bNoParagraphFormats ); + } } } - } - if( bFrame ) - { - ApplyBorderAttr( rFormatSet ); - } + if( bFrame ) + { + ApplyBorderAttr( rFormatSet ); + } - UpdateTableShape(); + UpdateTableShape(); - if( bUndo ) - rModel.EndUndo(); + if( bUndo ) + mpModel->EndUndo(); - return true; + return true; + + } + return false; } @@ -3112,22 +3077,26 @@ bool SvxTableController::isColumnSelected( sal_Int32 nColumn ) bool SvxTableController::isRowHeader() { - if(!checkTableObject()) + SdrTableObj* pTableObj = mxTableObj.get(); + SdrModel* pModel = pTableObj ? pTableObj->GetModel() : nullptr; + + if( !pTableObj || !pModel ) return false; - SdrTableObj& rTableObj(*mxTableObj.get()); - TableStyleSettings aSettings(rTableObj.getTableStyleSettings()); + TableStyleSettings aSettings( pTableObj->getTableStyleSettings() ); return aSettings.mbUseFirstRow; } bool SvxTableController::isColumnHeader() { - if(!checkTableObject()) + SdrTableObj* pTableObj = mxTableObj.get(); + SdrModel* pModel = pTableObj ? pTableObj->GetModel() : nullptr; + + if( !pTableObj || !pModel ) return false; - SdrTableObj& rTableObj(*mxTableObj.get()); - TableStyleSettings aSettings(rTableObj.getTableStyleSettings()); + TableStyleSettings aSettings( pTableObj->getTableStyleSettings() ); return aSettings.mbUseFirstColumn; } @@ -3156,7 +3125,7 @@ bool SvxTableController::setCursorLogicPosition(const Point& rPosition, bool bPo // No selection, but rPosition is at an other cell: start table selection. StartSelection(maMouseDownPos); // Update graphic selection, should be hidden now. - mrView.AdjustMarkHdl(); + mpView->AdjustMarkHdl(); } } diff --git a/svx/source/table/tablemodel.cxx b/svx/source/table/tablemodel.cxx index 812e3de7fe26..033af2477a45 100644 --- a/svx/source/table/tablemodel.cxx +++ b/svx/source/table/tablemodel.cxx @@ -554,7 +554,7 @@ void TableModel::unlockBroadcasts() void TableModel::notifyModification() { ::osl::MutexGuard guard( m_aMutex ); - if( (mnNotifyLock == 0) && mpTableObj ) + if( (mnNotifyLock == 0) && mpTableObj && mpTableObj->GetModel() ) { mbNotifyPending = false; @@ -602,7 +602,8 @@ void TableModel::insertColumns( sal_Int32 nIndex, sal_Int32 nCount ) { try { - SdrModel& rModel(mpTableObj->getSdrModelFromSdrObject()); + SdrModel* pModel = mpTableObj->GetModel(); + TableModelNotifyGuard aGuard( this ); nIndex = insert_range<ColumnVector,ColumnVector::iterator,TableColumnRef>( maColumns, nIndex, nCount ); @@ -618,12 +619,11 @@ void TableModel::insertColumns( sal_Int32 nIndex, sal_Int32 nCount ) aNewColumns[nOffset] = xNewCol; } - const bool bUndo(mpTableObj->IsInserted() && rModel.IsUndoEnabled()); - + const bool bUndo = pModel && mpTableObj->IsInserted() && pModel->IsUndoEnabled(); if( bUndo ) { - rModel.BegUndo( ImpGetResStr(STR_TABLE_INSCOL) ); - rModel.AddUndo( rModel.GetSdrUndoFactory().CreateUndoGeoObject(*mpTableObj) ); + pModel->BegUndo( ImpGetResStr(STR_TABLE_INSCOL) ); + pModel->AddUndo( pModel->GetSdrUndoFactory().CreateUndoGeoObject(*mpTableObj) ); TableModelRef xThis( this ); @@ -638,7 +638,7 @@ void TableModel::insertColumns( sal_Int32 nIndex, sal_Int32 nCount ) (*aCellIter++) = getCell( nIndex + nOffset, nRow ); } - rModel.AddUndo( new InsertColUndo( xThis, nIndex, aNewColumns, aNewCells ) ); + pModel->AddUndo( new InsertColUndo( xThis, nIndex, aNewColumns, aNewCells ) ); } const sal_Int32 nRowCount = getRowCountImpl(); @@ -660,9 +660,11 @@ void TableModel::insertColumns( sal_Int32 nIndex, sal_Int32 nCount ) } if( bUndo ) - rModel.EndUndo(); + pModel->EndUndo(); + + if( pModel ) + pModel->SetChanged(); - rModel.SetChanged(); } catch( Exception& ) { @@ -689,13 +691,14 @@ void TableModel::removeColumns( sal_Int32 nIndex, sal_Int32 nCount ) nCount = nColCount - nIndex; sal_Int32 nRows = getRowCountImpl(); - SdrModel& rModel(mpTableObj->getSdrModelFromSdrObject()); - const bool bUndo(mpTableObj->IsInserted() && rModel.IsUndoEnabled()); + SdrModel* pModel = mpTableObj->GetModel(); + + const bool bUndo = pModel && mpTableObj->IsInserted() && pModel->IsUndoEnabled(); if( bUndo ) { - rModel.BegUndo( ImpGetResStr(STR_UNDO_COL_DELETE) ); - rModel.AddUndo( rModel.GetSdrUndoFactory().CreateUndoGeoObject(*mpTableObj) ); + pModel->BegUndo( ImpGetResStr(STR_UNDO_COL_DELETE) ); + pModel->AddUndo( pModel->GetSdrUndoFactory().CreateUndoGeoObject(*mpTableObj) ); TableModelRef xThis( this ); ColumnVector aRemovedCols( nCount ); @@ -713,7 +716,7 @@ void TableModel::removeColumns( sal_Int32 nIndex, sal_Int32 nCount ) (*aCellIter++) = getCell( nIndex + nOffset, nRow ); } - rModel.AddUndo( new RemoveColUndo( xThis, nIndex, aRemovedCols, aRemovedCells ) ); + pModel->AddUndo( new RemoveColUndo( xThis, nIndex, aRemovedCols, aRemovedCells ) ); } // only rows before and inside the removed rows are considered @@ -766,9 +769,10 @@ void TableModel::removeColumns( sal_Int32 nIndex, sal_Int32 nCount ) maRows[nRows]->removeColumns( nIndex, nCount ); if( bUndo ) - rModel.EndUndo(); + pModel->EndUndo(); - rModel.SetChanged(); + if( pModel ) + pModel->SetChanged(); } catch( Exception& ) { @@ -785,9 +789,8 @@ void TableModel::insertRows( sal_Int32 nIndex, sal_Int32 nCount ) { if( nCount && mpTableObj ) { - SdrModel& rModel(mpTableObj->getSdrModelFromSdrObject()); - const bool bUndo(mpTableObj->IsInserted() && rModel.IsUndoEnabled()); - + SdrModel* pModel = mpTableObj->GetModel(); + const bool bUndo = pModel && mpTableObj->IsInserted() && pModel->IsUndoEnabled(); try { TableModelNotifyGuard aGuard( this ); @@ -805,10 +808,10 @@ void TableModel::insertRows( sal_Int32 nIndex, sal_Int32 nCount ) if( bUndo ) { - rModel.BegUndo( ImpGetResStr(STR_TABLE_INSROW) ); - rModel.AddUndo( rModel.GetSdrUndoFactory().CreateUndoGeoObject(*mpTableObj) ); + pModel->BegUndo( ImpGetResStr(STR_TABLE_INSROW) ); + pModel->AddUndo( pModel->GetSdrUndoFactory().CreateUndoGeoObject(*mpTableObj) ); TableModelRef xThis( this ); - rModel.AddUndo( new InsertRowUndo( xThis, nIndex, aNewRows ) ); + pModel->AddUndo( new InsertRowUndo( xThis, nIndex, aNewRows ) ); } // check if cells merge over new columns @@ -833,9 +836,10 @@ void TableModel::insertRows( sal_Int32 nIndex, sal_Int32 nCount ) OSL_FAIL("sdr::table::TableModel::insertRows(), exception caught!"); } if( bUndo ) - rModel.EndUndo(); + pModel->EndUndo(); - rModel.SetChanged(); + if( pModel ) + pModel->SetChanged(); updateRows(); setModified(true); @@ -849,8 +853,8 @@ void TableModel::removeRows( sal_Int32 nIndex, sal_Int32 nCount ) if( mpTableObj && nCount && (nIndex >= 0) && (nIndex < nRowCount) ) { - SdrModel& rModel(mpTableObj->getSdrModelFromSdrObject()); - const bool bUndo(mpTableObj->IsInserted() && rModel.IsUndoEnabled()); + SdrModel* pModel = mpTableObj->GetModel(); + const bool bUndo = pModel && mpTableObj->IsInserted()&& pModel->IsUndoEnabled(); try { @@ -862,8 +866,8 @@ void TableModel::removeRows( sal_Int32 nIndex, sal_Int32 nCount ) if( bUndo ) { - rModel.BegUndo( ImpGetResStr(STR_UNDO_ROW_DELETE) ); - rModel.AddUndo( rModel.GetSdrUndoFactory().CreateUndoGeoObject(*mpTableObj) ); + pModel->BegUndo( ImpGetResStr(STR_UNDO_ROW_DELETE) ); + pModel->AddUndo( pModel->GetSdrUndoFactory().CreateUndoGeoObject(*mpTableObj) ); TableModelRef xThis( this ); @@ -871,7 +875,7 @@ void TableModel::removeRows( sal_Int32 nIndex, sal_Int32 nCount ) for( sal_Int32 nOffset = 0; nOffset < nCount; ++nOffset ) aRemovedRows[nOffset] = maRows[nIndex+nOffset]; - rModel.AddUndo( new RemoveRowUndo( xThis, nIndex, aRemovedRows ) ); + pModel->AddUndo( new RemoveRowUndo( xThis, nIndex, aRemovedRows ) ); } // only rows before and inside the removed rows are considered @@ -922,9 +926,10 @@ void TableModel::removeRows( sal_Int32 nIndex, sal_Int32 nCount ) remove_range<RowVector,RowVector::iterator>( maRows, nIndex, nCount ); if( bUndo ) - rModel.EndUndo(); + pModel->EndUndo(); - rModel.SetChanged(); + if( pModel ) + pModel->SetChanged(); } catch( Exception& ) { @@ -1045,11 +1050,10 @@ void TableModel::optimize() void TableModel::merge( sal_Int32 nCol, sal_Int32 nRow, sal_Int32 nColSpan, sal_Int32 nRowSpan ) { - if(nullptr == mpTableObj) - return; + SdrModel* pModel = mpTableObj->GetModel(); + + const bool bUndo = pModel && mpTableObj->IsInserted() && pModel->IsUndoEnabled(); - SdrModel& rModel(mpTableObj->getSdrModelFromSdrObject()); - const bool bUndo(mpTableObj->IsInserted() && rModel.IsUndoEnabled()); const sal_Int32 nLastRow = nRow + nRowSpan; const sal_Int32 nLastCol = nCol + nColSpan; diff --git a/svx/source/table/tablerow.cxx b/svx/source/table/tablerow.cxx index cf765b47830a..43010ad698fe 100644 --- a/svx/source/table/tablerow.cxx +++ b/svx/source/table/tablerow.cxx @@ -206,15 +206,14 @@ void SAL_CALL TableRow::setName( const OUString& aName ) void SAL_CALL TableRow::setFastPropertyValue( sal_Int32 nHandle, const Any& aValue ) { - if(!mxTableModel.is() || nullptr == mxTableModel->getSdrTableObj()) - return; + bool bOk = false; + bool bChange = false; - SdrTableObj& rTableObj(*mxTableModel->getSdrTableObj()); - SdrModel& rModel(rTableObj.getSdrModelFromSdrObject()); - bool bOk(false); - bool bChange(false); - TableRowUndo* pUndo(nullptr); - const bool bUndo(rTableObj.IsInserted() && rModel.IsUndoEnabled()); + TableRowUndo* pUndo = nullptr; + + SdrModel* pModel = mxTableModel->getSdrTableObj()->GetModel(); + + const bool bUndo = mxTableModel.is() && mxTableModel->getSdrTableObj() && mxTableModel->getSdrTableObj()->IsInserted() && pModel && pModel->IsUndoEnabled(); if( bUndo ) { @@ -277,7 +276,6 @@ void SAL_CALL TableRow::setFastPropertyValue( sal_Int32 nHandle, const Any& aVal delete pUndo; throw UnknownPropertyException( OUString::number(nHandle), static_cast<cppu::OWeakObject*>(this)); } - if( !bOk ) { delete pUndo; @@ -288,7 +286,7 @@ void SAL_CALL TableRow::setFastPropertyValue( sal_Int32 nHandle, const Any& aVal { if( pUndo ) { - rModel.AddUndo( pUndo ); + pModel->AddUndo( pUndo ); pUndo = nullptr; } mxTableModel->setModified(true); diff --git a/svx/source/table/tablertfimporter.cxx b/svx/source/table/tablertfimporter.cxx index b50efb35bc3a..714e0c62c4ed 100644 --- a/svx/source/table/tablertfimporter.cxx +++ b/svx/source/table/tablertfimporter.cxx @@ -132,8 +132,8 @@ private: SdrTableRTFParser::SdrTableRTFParser( SdrTableObj& rTableObj ) : mrTableObj( rTableObj ) -, mpOutliner( SdrMakeOutliner( OutlinerMode::TextObject, rTableObj.getSdrModelFromSdrObject() ) ) -, mrItemPool( rTableObj.getSdrModelFromSdrObject().GetItemPool() ) +, mpOutliner( SdrMakeOutliner( OutlinerMode::TextObject, *rTableObj.GetModel() ) ) +, mrItemPool( rTableObj.GetModel()->GetItemPool() ) , mnLastToken( 0 ) , mbNewDef( false ) , mnStartPara( 0 ) diff --git a/svx/source/table/tableundo.cxx b/svx/source/table/tableundo.cxx index 493c895057dc..9a14948b1dfe 100644 --- a/svx/source/table/tableundo.cxx +++ b/svx/source/table/tableundo.cxx @@ -35,10 +35,10 @@ using namespace ::com::sun::star::table; namespace sdr { namespace table { CellUndo::CellUndo( const tools::WeakReference<SdrObject>& xObjRef, const CellRef& xCell ) -: SdrUndoAction(xCell->GetObject().getSdrModelFromSdrObject()) - ,mxObjRef( xObjRef ) - ,mxCell( xCell ) - ,mbUndo( true ) + : SdrUndoAction( *xCell->GetModel() ) + , mxObjRef( xObjRef ) + , mxCell( xCell ) + , mbUndo( true ) { if( mxCell.is() && mxObjRef.is() ) { @@ -162,10 +162,10 @@ static void Dispose( RowVector& rRows ) InsertRowUndo::InsertRowUndo( const TableModelRef& xTable, sal_Int32 nIndex, RowVector& aNewRows ) -: SdrUndoAction(xTable->getSdrTableObj()->getSdrModelFromSdrObject()) - ,mxTable( xTable ) - ,mnIndex( nIndex ) - ,mbUndo( true ) + : SdrUndoAction( *xTable->getSdrTableObj()->GetModel() ) + , mxTable( xTable ) + , mnIndex( nIndex ) + , mbUndo( true ) { maRows.swap( aNewRows ); } @@ -202,10 +202,10 @@ void InsertRowUndo::Redo() RemoveRowUndo::RemoveRowUndo( const TableModelRef& xTable, sal_Int32 nIndex, RowVector& aRemovedRows ) -: SdrUndoAction(xTable->getSdrTableObj()->getSdrModelFromSdrObject()) - ,mxTable( xTable ) - ,mnIndex( nIndex ) - ,mbUndo( true ) + : SdrUndoAction( *xTable->getSdrTableObj()->GetModel() ) + , mxTable( xTable ) + , mnIndex( nIndex ) + , mbUndo( true ) { maRows.swap( aRemovedRows ); } @@ -258,10 +258,10 @@ static void Dispose( CellVector& rCells ) InsertColUndo::InsertColUndo( const TableModelRef& xTable, sal_Int32 nIndex, ColumnVector& aNewCols, CellVector& aCells ) -: SdrUndoAction(xTable->getSdrTableObj()->getSdrModelFromSdrObject()) - ,mxTable( xTable ) - ,mnIndex( nIndex ) - ,mbUndo( true ) + : SdrUndoAction( *xTable->getSdrTableObj()->GetModel() ) + , mxTable( xTable ) + , mnIndex( nIndex ) + , mbUndo( true ) { maColumns.swap( aNewCols ); maCells.swap( aCells ); @@ -302,10 +302,10 @@ void InsertColUndo::Redo() RemoveColUndo::RemoveColUndo( const TableModelRef& xTable, sal_Int32 nIndex, ColumnVector& aNewCols, CellVector& aCells ) -: SdrUndoAction(xTable->getSdrTableObj()->getSdrModelFromSdrObject()) - ,mxTable( xTable ) - ,mnIndex( nIndex ) - ,mbUndo( true ) + : SdrUndoAction( *xTable->getSdrTableObj()->GetModel() ) + , mxTable( xTable ) + , mnIndex( nIndex ) + , mbUndo( true ) { maColumns.swap( aNewCols ); maCells.swap( aCells ); @@ -346,9 +346,9 @@ void RemoveColUndo::Redo() TableColumnUndo::TableColumnUndo( const TableColumnRef& xCol ) -: SdrUndoAction(xCol->mxTableModel->getSdrTableObj()->getSdrModelFromSdrObject()) - ,mxCol( xCol ) - ,mbHasRedoData( false ) + : SdrUndoAction( *xCol->mxTableModel->getSdrTableObj()->GetModel() ) + , mxCol( xCol ) + , mbHasRedoData( false ) { getData( maUndoData ); } @@ -412,7 +412,7 @@ void TableColumnUndo::getData( Data& rData ) TableRowUndo::TableRowUndo( const TableRowRef& xRow ) -: SdrUndoAction(xRow->mxTableModel->getSdrTableObj()->getSdrModelFromSdrObject()) + : SdrUndoAction( *xRow->mxTableModel->getSdrTableObj()->GetModel() ) , mxRow( xRow ) , mbHasRedoData( false ) { @@ -475,9 +475,9 @@ void TableRowUndo::getData( Data& rData ) TableStyleUndo::TableStyleUndo( const SdrTableObj& rTableObj ) -: SdrUndoAction(rTableObj.getSdrModelFromSdrObject()) - ,mxObjRef( const_cast< sdr::table::SdrTableObj*>( &rTableObj ) ) - ,mbHasRedoData(false) + : SdrUndoAction( *rTableObj.GetModel() ) + , mxObjRef( const_cast< sdr::table::SdrTableObj*>( &rTableObj ) ) + , mbHasRedoData(false) { getData( maUndoData ); } |