Hello everyone, I've started work on removing all calls to SfxItemSet::Put(SfxPoolItem &, int which) from the code. Attached the first two patches, which contains mostly easy cases: Almost all SfxPoolItems already contained the right WhichID, so the extra argument could just be removed. But there are some slightly more interesting cases in here as well.
I have more patches ready to go, but I'd like to get these reviewed first to check I'm on the right path. The really hard cases are in other parts of the code :) As always, contributed under LGPLv3+/MPL dual license. Kind regards, - Theo van Klaveren
From 4d218bb98afea8c2f3069b936084f3424dffaf2b Mon Sep 17 00:00:00 2001 From: Theo van Klaveren <theo.van.klave...@gmail.com> Date: Mon, 28 Mar 2011 11:18:14 +0200 Subject: [PATCH 1/2] Remove misuse of SfxItemSet API from editeng. --- editeng/source/editeng/editdoc.cxx | 2 +- editeng/source/editeng/editdoc2.cxx | 12 ++++-------- editeng/source/editeng/editview.cxx | 8 ++++---- editeng/source/uno/unoipset.cxx | 3 ++- 4 files changed, 11 insertions(+), 14 deletions(-) diff --git a/editeng/source/editeng/editdoc.cxx b/editeng/source/editeng/editdoc.cxx index 08758a8..6fd88ba 100755 --- a/editeng/source/editeng/editdoc.cxx +++ b/editeng/source/editeng/editdoc.cxx @@ -1548,7 +1548,7 @@ EditPaM EditDoc::InsertParaBreak( EditPaM aPaM, sal_Bool bKeepEndingAttribs ) ContentAttribs aContentAttribs( aPaM.GetNode()->GetContentAttribs() ); // for a new paragraph we like to have the bullet/numbering visible by default - aContentAttribs.GetItems().Put( SfxBoolItem( EE_PARA_BULLETSTATE, sal_True), EE_PARA_BULLETSTATE ); + aContentAttribs.GetItems().Put( SfxBoolItem( EE_PARA_BULLETSTATE, sal_True) ); // ContenNode constructor copies also the paragraph attributes ContentNode* pNode = new ContentNode( aStr, aContentAttribs ); diff --git a/editeng/source/editeng/editdoc2.cxx b/editeng/source/editeng/editdoc2.cxx index 4bf4ef3..9a64195 100755 --- a/editeng/source/editeng/editdoc2.cxx +++ b/editeng/source/editeng/editdoc2.cxx @@ -489,18 +489,14 @@ void ConvertAndPutItems( SfxItemSet& rDest, const SfxItemSet& rSource, const Map { MapUnit eSourceUnit = pSourceUnit ? *pSourceUnit : (MapUnit)pSourcePool->GetMetric( nSourceWhich ); MapUnit eDestUnit = pDestUnit ? *pDestUnit : (MapUnit)pDestPool->GetMetric( nWhich ); + SfxPoolItem* pItem = rSource.Get( nSourceWhich ).Clone(); if ( eSourceUnit != eDestUnit ) { - SfxPoolItem* pItem = rSource.Get( nSourceWhich ).Clone(); -// pItem->SetWhich( nWhich ); ConvertItem( *pItem, eSourceUnit, eDestUnit ); - rDest.Put( *pItem, nWhich ); - delete pItem; - } - else - { - rDest.Put( rSource.Get( nSourceWhich ), nWhich ); } + pItem->SetWhich( nWhich ); + rDest.Put( *pItem ); + delete pItem; } } } diff --git a/editeng/source/editeng/editview.cxx b/editeng/source/editeng/editview.cxx index eb586a4..7526889 100755 --- a/editeng/source/editeng/editview.cxx +++ b/editeng/source/editeng/editview.cxx @@ -1437,9 +1437,9 @@ static void ChangeFontSizeImpl( EditView* pEditView, bool bGrow, const ESelectio if( EditView::ChangeFontSize( bGrow, aSet, pFontList ) ) { SfxItemSet aNewSet( pEditView->GetEmptyItemSet() ); - aNewSet.Put( aSet.Get( EE_CHAR_FONTHEIGHT ), EE_CHAR_FONTHEIGHT ); - aNewSet.Put( aSet.Get( EE_CHAR_FONTHEIGHT_CJK ), EE_CHAR_FONTHEIGHT_CJK ); - aNewSet.Put( aSet.Get( EE_CHAR_FONTHEIGHT_CTL ), EE_CHAR_FONTHEIGHT_CTL ); + aNewSet.Put( aSet.Get( EE_CHAR_FONTHEIGHT ) ); + aNewSet.Put( aSet.Get( EE_CHAR_FONTHEIGHT_CJK ) ); + aNewSet.Put( aSet.Get( EE_CHAR_FONTHEIGHT_CTL ) ); pEditView->SetAttribs( aNewSet ); } } @@ -1576,7 +1576,7 @@ bool EditView::ChangeFontSize( bool bGrow, SfxItemSet& rSet, const FontList* pFo if( nHeight != (long)aFontHeightItem.GetHeight() ) { aFontHeightItem.SetHeight( nHeight ); - rSet.Put( aFontHeightItem, *pWhich ); + rSet.Put( aFontHeightItem ); bRet = true; } } diff --git a/editeng/source/uno/unoipset.cxx b/editeng/source/uno/unoipset.cxx index 1aa2737..0ac0cd4 100644 --- a/editeng/source/uno/unoipset.cxx +++ b/editeng/source/uno/unoipset.cxx @@ -200,6 +200,7 @@ void SvxItemPropertySet::setPropertyValue( const SfxItemPropertySimpleEntry* pMa } pNewItem = pItem->Clone(); + pNewItem->SetWhich( pMap->nWID ); sal_uInt8 nMemberId = pMap->nMemberId & (~SFX_METRIC_ITEM); if( eMapUnit == SFX_MAPUNIT_100TH_MM ) @@ -208,7 +209,7 @@ void SvxItemPropertySet::setPropertyValue( const SfxItemPropertySimpleEntry* pMa if( pNewItem->PutValue( aValue, nMemberId ) ) { // Set new item in item set - rSet.Put( *pNewItem, pMap->nWID ); + rSet.Put( *pNewItem ); } delete pNewItem; } -- 1.7.1
From 2bd335395ec7cdef9c396eddeef463f7325e0324 Mon Sep 17 00:00:00 2001 From: Theo van Klaveren <theo.van.klave...@gmail.com> Date: Mon, 28 Mar 2011 11:18:38 +0200 Subject: [PATCH 2/2] Remove misuse of SfxItemSet API from svx. --- svx/source/dialog/imapwnd.cxx | 2 +- svx/source/svdraw/svdedxv.cxx | 2 +- svx/source/table/tablecontroller.cxx | 2 +- svx/source/unodraw/UnoNameItemTable.cxx | 3 ++- svx/source/unodraw/unomtabl.cxx | 12 ++++++++---- 5 files changed, 13 insertions(+), 8 deletions(-) diff --git a/svx/source/dialog/imapwnd.cxx b/svx/source/dialog/imapwnd.cxx index 68a6e3d..7619786 100755 --- a/svx/source/dialog/imapwnd.cxx +++ b/svx/source/dialog/imapwnd.cxx @@ -684,7 +684,7 @@ void IMapWindow::DoMacroAssign() SvxMacroItem aMacroItem(SID_ATTR_MACROITEM); IMapObject* pIMapObj = GetIMapObj( pSdrObj ); aMacroItem.SetMacroTable( pIMapObj->GetMacroTable() ); - aSet.Put( aMacroItem, SID_ATTR_MACROITEM ); + aSet.Put( aMacroItem ); SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); SfxAbstractDialog* pMacroDlg = pFact->CreateSfxDialog( this, aSet, mxDocumentFrame, SID_EVENTCONFIG ); diff --git a/svx/source/svdraw/svdedxv.cxx b/svx/source/svdraw/svdedxv.cxx index bd6874e..7eb00a2 100755 --- a/svx/source/svdraw/svdedxv.cxx +++ b/svx/source/svdraw/svdedxv.cxx @@ -1470,7 +1470,7 @@ sal_Bool SdrObjEditView::GetAttributes(SfxItemSet& rTargetSet, sal_Bool bOnlyHar { // FALSE= InvalidItems nicht al Default, sondern als "Loecher" betrachten rTargetSet.Put(pTextEditOutlinerView->GetAttribs(), sal_False); - rTargetSet.Put( SvxScriptTypeItem( pTextEditOutlinerView->GetSelectedScriptType() ), sal_False ); + rTargetSet.Put( SvxScriptTypeItem( pTextEditOutlinerView->GetSelectedScriptType() ) ); } if(GetMarkedObjectCount()==1 && GetMarkedObjectByIndex(0)==mxTextEditObj.get()) diff --git a/svx/source/table/tablecontroller.cxx b/svx/source/table/tablecontroller.cxx index 355072b..07c63fc 100755 --- a/svx/source/table/tablecontroller.cxx +++ b/svx/source/table/tablecontroller.cxx @@ -2383,7 +2383,7 @@ bool SvxTableController::GetAttributes(SfxItemSet& rTargetSet, bool bOnlyHardAtt { // FALSE= InvalidItems nicht al Default, sondern als "Loecher" betrachten rTargetSet.Put(pTextEditOutlinerView->GetAttribs(), sal_False); - rTargetSet.Put( SvxScriptTypeItem( pTextEditOutlinerView->GetSelectedScriptType() ), sal_False ); + rTargetSet.Put( SvxScriptTypeItem( pTextEditOutlinerView->GetSelectedScriptType() ) ); } } diff --git a/svx/source/unodraw/UnoNameItemTable.cxx b/svx/source/unodraw/UnoNameItemTable.cxx index 7fbc341..b8d6895 100755 --- a/svx/source/unodraw/UnoNameItemTable.cxx +++ b/svx/source/unodraw/UnoNameItemTable.cxx @@ -108,7 +108,8 @@ void SAL_CALL SvxUnoNameItemTable::ImplInsertByName( const OUString& aName, cons NameOrIndex* pNewItem = createItem(); pNewItem->SetName( String( aName ) ); pNewItem->PutValue( aElement, mnMemberId ); - mpInSet->Put( *pNewItem, mnWhich ); + pNewItem->SetWhich( mnWhich ); + mpInSet->Put( *pNewItem ); delete pNewItem; } diff --git a/svx/source/unodraw/unomtabl.cxx b/svx/source/unodraw/unomtabl.cxx index 8ea424a..20c2620 100755 --- a/svx/source/unodraw/unomtabl.cxx +++ b/svx/source/unodraw/unomtabl.cxx @@ -173,14 +173,16 @@ void SAL_CALL SvxUnoMarkerTable::ImplInsertByName( const OUString& aName, const XLineEndItem aEndMarker; aEndMarker.SetName( String( aName ) ); aEndMarker.PutValue( aElement ); + aEndMarker.SetWhich( XATTR_LINEEND ); - mpInSet->Put( aEndMarker, XATTR_LINEEND ); + mpInSet->Put( aEndMarker ); XLineStartItem aStartMarker; aStartMarker.SetName( String( aName ) ); aStartMarker.PutValue( aElement ); + aStartMarker.SetWhich( XATTR_LINESTART ); - mpInSet->Put( aStartMarker, XATTR_LINESTART ); + mpInSet->Put( aStartMarker ); } // XNameContainer @@ -260,14 +262,16 @@ void SAL_CALL SvxUnoMarkerTable::replaceByName( const OUString& aApiName, const aEndMarker.SetName( aSearchName ); if( !aEndMarker.PutValue( aElement ) ) throw lang::IllegalArgumentException(); + aEndMarker.SetWhich( XATTR_LINEEND ); - (*aIter)->Put( aEndMarker, XATTR_LINEEND ); + (*aIter)->Put( aEndMarker ); XLineStartItem aStartMarker; aStartMarker.SetName( aSearchName ); aStartMarker.PutValue( aElement ); + aStartMarker.SetWhich( XATTR_LINESTART ); - (*aIter)->Put( aStartMarker, XATTR_LINESTART ); + (*aIter)->Put( aStartMarker ); return; } ++aIter; -- 1.7.1
_______________________________________________ LibreOffice mailing list LibreOffice@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice