include/sfx2/objsh.hxx | 6 ++-- include/svl/itemset.hxx | 20 +++++++++++---- sfx2/source/doc/objserv.cxx | 20 ++++----------- sfx2/source/doc/objstor.cxx | 52 ++++++++++++--------------------------- sfx2/source/doc/sfxbasemodel.cxx | 20 +++++++-------- svl/source/items/itemset.cxx | 35 +++----------------------- 6 files changed, 55 insertions(+), 98 deletions(-)
New commits: commit 25d1447fcfe7d3fcdf8792d1cf426aaa2e578875 Author: Jan Holesovsky <ke...@collabora.com> Date: Mon Oct 19 09:54:12 2015 +0200 sfx items: Some cleanup. Change-Id: I8fdd710b4248de03db6591665489146cb2674aab diff --git a/include/sfx2/objsh.hxx b/include/sfx2/objsh.hxx index a7466f1..ff04e3c 100644 --- a/include/sfx2/objsh.hxx +++ b/include/sfx2/objsh.hxx @@ -684,9 +684,9 @@ public: SAL_DLLPRIVATE void SetNamedVisibility_Impl(); SAL_DLLPRIVATE bool DoSave_Impl( const SfxItemSet* pSet=0 ); SAL_DLLPRIVATE bool Save_Impl( const SfxItemSet* pSet=0 ); - SAL_DLLPRIVATE bool PreDoSaveAs_Impl(const OUString &rFileName, const OUString &rFiltName, SfxItemSet *); - SAL_DLLPRIVATE bool APISaveAs_Impl ( const OUString& aFileName, SfxItemSet* aParams ); - SAL_DLLPRIVATE bool CommonSaveAs_Impl ( const INetURLObject& aURL, const OUString& aFilterName, SfxItemSet* aParams ); + SAL_DLLPRIVATE bool PreDoSaveAs_Impl(const OUString& rFileName, const OUString& rFiltName, SfxItemSet& rItemSet); + SAL_DLLPRIVATE bool APISaveAs_Impl(const OUString& aFileName, SfxItemSet& rItemSet); + SAL_DLLPRIVATE bool CommonSaveAs_Impl(const INetURLObject& aURL, const OUString& aFilterName, SfxItemSet& rItemSet); SAL_DLLPRIVATE bool GeneralInit_Impl( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage, bool bTypeMustBeSetAlready ); diff --git a/sfx2/source/doc/objserv.cxx b/sfx2/source/doc/objserv.cxx index f263356..fd16f1b 100644 --- a/sfx2/source/doc/objserv.cxx +++ b/sfx2/source/doc/objserv.cxx @@ -263,13 +263,7 @@ void SfxObjectShell::PrintState_Impl(SfxItemSet &rSet) rSet.Put( SfxBoolItem( SID_PRINTOUT, bPrinting ) ); } - - -bool SfxObjectShell::APISaveAs_Impl -( - const OUString& aFileName, - SfxItemSet* aParams -) +bool SfxObjectShell::APISaveAs_Impl(const OUString& aFileName, SfxItemSet& rItemSet) { bool bOk = false; @@ -277,14 +271,14 @@ bool SfxObjectShell::APISaveAs_Impl if ( GetMedium() ) { OUString aFilterName; - const SfxStringItem* pFilterNameItem = SfxItemSet::GetItem<SfxStringItem>(aParams, SID_FILTER_NAME, false); + const SfxStringItem* pFilterNameItem = rItemSet.GetItem<SfxStringItem>(SID_FILTER_NAME, false); if( pFilterNameItem ) { aFilterName = pFilterNameItem->GetValue(); } else { - const SfxStringItem* pContentTypeItem = SfxItemSet::GetItem<SfxStringItem>(aParams, SID_CONTENTTYPE, false); + const SfxStringItem* pContentTypeItem = rItemSet.GetItem<SfxStringItem>(SID_CONTENTTYPE, false); if ( pContentTypeItem ) { const SfxFilter* pFilter = SfxFilterMatcher( OUString::createFromAscii(GetFactory().GetShortName()) ).GetFilter4Mime( pContentTypeItem->GetValue(), SfxFilterFlags::EXPORT ); @@ -302,7 +296,7 @@ bool SfxObjectShell::APISaveAs_Impl if( pFilt ) aFilterName = pFilt->GetFilterName(); - aParams->Put(SfxStringItem( SID_FILTER_NAME, aFilterName)); + rItemSet.Put(SfxStringItem(SID_FILTER_NAME, aFilterName)); } @@ -310,13 +304,11 @@ bool SfxObjectShell::APISaveAs_Impl SfxObjectShellRef xLock( this ); // ??? // use the title that is provided in the media descriptor - const SfxStringItem* pDocTitleItem = SfxItemSet::GetItem<SfxStringItem>(aParams, SID_DOCINFO_TITLE, false); + const SfxStringItem* pDocTitleItem = rItemSet.GetItem<SfxStringItem>(SID_DOCINFO_TITLE, false); if ( pDocTitleItem ) getDocProperties()->setTitle( pDocTitleItem->GetValue() ); - bOk = CommonSaveAs_Impl( INetURLObject(aFileName), aFilterName, - aParams ); - + bOk = CommonSaveAs_Impl(INetURLObject(aFileName), aFilterName, rItemSet); } } diff --git a/sfx2/source/doc/objstor.cxx b/sfx2/source/doc/objstor.cxx index e97bd2e..190b733 100644 --- a/sfx2/source/doc/objstor.cxx +++ b/sfx2/source/doc/objstor.cxx @@ -2606,14 +2606,7 @@ bool SfxObjectShell::Save_Impl( const SfxItemSet* pSet ) return bSaved; } - - -bool SfxObjectShell::CommonSaveAs_Impl -( - const INetURLObject& aURL, - const OUString& aFilterName, - SfxItemSet* aParams -) +bool SfxObjectShell::CommonSaveAs_Impl(const INetURLObject& aURL, const OUString& aFilterName, SfxItemSet& rItemSet) { if( aURL.HasError() ) { @@ -2645,9 +2638,9 @@ bool SfxObjectShell::CommonSaveAs_Impl } DBG_ASSERT( aURL.GetProtocol() != INetProtocol::NotValid, "Illegal URL!" ); - DBG_ASSERT( aParams->Count() != 0, "Incorrect Parameter"); + DBG_ASSERT( rItemSet.Count() != 0, "Incorrect Parameter"); - const SfxBoolItem* pSaveToItem = SfxItemSet::GetItem<SfxBoolItem>(aParams, SID_SAVETO, false); + const SfxBoolItem* pSaveToItem = rItemSet.GetItem<SfxBoolItem>(SID_SAVETO, false); bool bSaveTo = pSaveToItem && pSaveToItem->GetValue(); const SfxFilter* pFilter = GetFactory().GetFilterContainer()->GetFilter4FilterName( aFilterName ); @@ -2659,15 +2652,15 @@ bool SfxObjectShell::CommonSaveAs_Impl return false; } - const SfxBoolItem* pCopyStreamItem = SfxItemSet::GetItem<SfxBoolItem>(aParams, SID_COPY_STREAM_IF_POSSIBLE, false); + const SfxBoolItem* pCopyStreamItem = rItemSet.GetItem<SfxBoolItem>(SID_COPY_STREAM_IF_POSSIBLE, false); if ( bSaveTo && pCopyStreamItem && pCopyStreamItem->GetValue() && !IsModified() ) { - if ( pMedium->TryDirectTransfer( aURL.GetMainURL( INetURLObject::NO_DECODE ), *aParams ) ) + if (pMedium->TryDirectTransfer(aURL.GetMainURL(INetURLObject::NO_DECODE), rItemSet)) return true; } - aParams->ClearItem( SID_COPY_STREAM_IF_POSSIBLE ); + rItemSet.ClearItem( SID_COPY_STREAM_IF_POSSIBLE ); - pImp->bPasswd = SfxItemState::SET == aParams->GetItemState(SID_PASSWORD); + pImp->bPasswd = SfxItemState::SET == rItemSet.GetItemState(SID_PASSWORD); SfxMedium *pActMed = GetMedium(); const INetURLObject aActName(pActMed->GetName()); @@ -2681,14 +2674,14 @@ bool SfxObjectShell::CommonSaveAs_Impl return false; } - if( SfxItemState::SET != aParams->GetItemState(SID_UNPACK) && SvtSaveOptions().IsSaveUnpacked() ) - aParams->Put( SfxBoolItem( SID_UNPACK, false ) ); + if (SfxItemState::SET != rItemSet.GetItemState(SID_UNPACK) && SvtSaveOptions().IsSaveUnpacked()) + rItemSet.Put(SfxBoolItem(SID_UNPACK, false)); OUString aTempFileURL; if ( IsDocShared() ) aTempFileURL = pMedium->GetURLObject().GetMainURL( INetURLObject::NO_DECODE ); - if ( PreDoSaveAs_Impl(aURL.GetMainURL( INetURLObject::NO_DECODE ),aFilterName,aParams)) + if (PreDoSaveAs_Impl(aURL.GetMainURL(INetURLObject::NO_DECODE), aFilterName, rItemSet)) { // Update Data on media SfxItemSet *pSet = GetMedium()->GetItemSet(); @@ -2713,15 +2706,15 @@ bool SfxObjectShell::CommonSaveAs_Impl pSet->ClearItem( SID_DEFAULTFILEPATH ); pSet->ClearItem( SID_DEFAULTFILENAME ); - const SfxStringItem* pFilterItem = aParams->GetItem<SfxStringItem>(SID_FILTER_NAME, false); + const SfxStringItem* pFilterItem = rItemSet.GetItem<SfxStringItem>(SID_FILTER_NAME, false); if ( pFilterItem ) pSet->Put( *pFilterItem ); - const SfxStringItem* pOptionsItem = aParams->GetItem<SfxStringItem>(SID_OPTIONS, false); + const SfxStringItem* pOptionsItem = rItemSet.GetItem<SfxStringItem>(SID_OPTIONS, false); if ( pOptionsItem ) pSet->Put( *pOptionsItem ); - const SfxStringItem* pFilterOptItem = aParams->GetItem<SfxStringItem>(SID_FILE_FILTEROPTIONS, false); + const SfxStringItem* pFilterOptItem = rItemSet.GetItem<SfxStringItem>(SID_FILE_FILTEROPTIONS, false); if ( pFilterOptItem ) pSet->Put( *pFilterOptItem ); @@ -2752,14 +2745,7 @@ bool SfxObjectShell::CommonSaveAs_Impl return false; } - - -bool SfxObjectShell::PreDoSaveAs_Impl -( - const OUString& rFileName, - const OUString& aFilterName, - SfxItemSet* pParams -) +bool SfxObjectShell::PreDoSaveAs_Impl(const OUString& rFileName, const OUString& aFilterName, SfxItemSet& rItemSet) { // copy all items stored in the itemset of the current medium SfxAllItemSet* pMergedParams = new SfxAllItemSet( *pMedium->GetItemSet() ); @@ -2785,8 +2771,7 @@ bool SfxObjectShell::PreDoSaveAs_Impl // merge the new parameters into the copy // all values present in both itemsets will be overwritten by the new parameters - if( pParams ) - pMergedParams->Put( *pParams ); + pMergedParams->Put(rItemSet); #ifdef DBG_UTIL if ( pMergedParams->GetItemState( SID_DOC_SALVAGE) >= SfxItemState::SET ) @@ -2796,11 +2781,8 @@ bool SfxObjectShell::PreDoSaveAs_Impl // should be unnecessary - too hot to handle! pMergedParams->ClearItem( SID_DOC_SALVAGE ); - // take over the new merged itemset - pParams = pMergedParams; - // create a medium for the target URL - SfxMedium *pNewFile = new SfxMedium( rFileName, STREAM_READWRITE | StreamMode::SHARE_DENYWRITE | StreamMode::TRUNC, 0, pParams ); + SfxMedium *pNewFile = new SfxMedium( rFileName, STREAM_READWRITE | StreamMode::SHARE_DENYWRITE | StreamMode::TRUNC, 0, pMergedParams ); // set filter; if no filter is given, take the default filter of the factory if ( !aFilterName.isEmpty() ) @@ -2817,7 +2799,7 @@ bool SfxObjectShell::PreDoSaveAs_Impl } // check if a "SaveTo" is wanted, no "SaveAs" - const SfxBoolItem* pSaveToItem = SfxItemSet::GetItem<SfxBoolItem>(pParams, SID_SAVETO, false); + const SfxBoolItem* pSaveToItem = pMergedParams->GetItem<SfxBoolItem>(SID_SAVETO, false); bool bCopyTo = GetCreateMode() == SfxObjectCreateMode::EMBEDDED || (pSaveToItem && pSaveToItem->GetValue()); // distinguish between "Save" and "SaveAs" diff --git a/sfx2/source/doc/sfxbasemodel.cxx b/sfx2/source/doc/sfxbasemodel.cxx index ed11d79..c6dbe54 100644 --- a/sfx2/source/doc/sfxbasemodel.cxx +++ b/sfx2/source/doc/sfxbasemodel.cxx @@ -3012,14 +3012,14 @@ void SfxBaseModel::impl_store( const OUString& sURL SfxGetpApp()->NotifyEvent( SfxEventHint( bSaveTo ? SFX_EVENT_SAVETODOC : SFX_EVENT_SAVEASDOC, GlobalEventConfig::GetEventName( bSaveTo ? GlobalEventId::SAVETODOC : GlobalEventId::SAVEASDOC ), m_pData->m_pObjectShell ) ); - SfxAllItemSet *aParams = new SfxAllItemSet( SfxGetpApp()->GetPool() ); - aParams->Put( SfxStringItem( SID_FILE_NAME, sURL ) ); + std::unique_ptr<SfxAllItemSet> pItemSet(new SfxAllItemSet(SfxGetpApp()->GetPool())); + pItemSet->Put(SfxStringItem(SID_FILE_NAME, sURL)); if ( bSaveTo ) - aParams->Put( SfxBoolItem( SID_SAVETO, true ) ); + pItemSet->Put(SfxBoolItem(SID_SAVETO, true)); - TransformParameters( SID_SAVEASDOC, seqArguments, *aParams ); + TransformParameters(SID_SAVEASDOC, seqArguments, *pItemSet); - const SfxBoolItem* pCopyStreamItem = SfxItemSet::GetItem<SfxBoolItem>(aParams, SID_COPY_STREAM_IF_POSSIBLE, false); + const SfxBoolItem* pCopyStreamItem = pItemSet->GetItem<SfxBoolItem>(SID_COPY_STREAM_IF_POSSIBLE, false); if ( pCopyStreamItem && pCopyStreamItem->GetValue() && !bSaveTo ) { @@ -3032,7 +3032,7 @@ void SfxBaseModel::impl_store( const OUString& sURL sal_uInt32 nModifyPasswordHash = 0; Sequence< beans::PropertyValue > aModifyPasswordInfo; - const SfxUnoAnyItem* pModifyPasswordInfoItem = SfxItemSet::GetItem<SfxUnoAnyItem>(aParams, SID_MODIFYPASSWORDINFO, false); + const SfxUnoAnyItem* pModifyPasswordInfoItem = pItemSet->GetItem<SfxUnoAnyItem>(SID_MODIFYPASSWORDINFO, false); if ( pModifyPasswordInfoItem ) { // it contains either a simple hash or a set of PropertyValues @@ -3042,7 +3042,7 @@ void SfxBaseModel::impl_store( const OUString& sURL nModifyPasswordHash = (sal_uInt32)nMPHTmp; pModifyPasswordInfoItem->GetValue() >>= aModifyPasswordInfo; } - aParams->ClearItem( SID_MODIFYPASSWORDINFO ); + pItemSet->ClearItem(SID_MODIFYPASSWORDINFO); sal_uInt32 nOldModifyPasswordHash = m_pData->m_pObjectShell->GetModifyPasswordHash(); m_pData->m_pObjectShell->SetModifyPasswordHash( nModifyPasswordHash ); Sequence< beans::PropertyValue > aOldModifyPasswordInfo = m_pData->m_pObjectShell->GetModifyPasswordInfo(); @@ -3064,7 +3064,7 @@ void SfxBaseModel::impl_store( const OUString& sURL m_pData->m_xDocumentProperties = xNewDocProps; } - bool bRet = m_pData->m_pObjectShell->APISaveAs_Impl( sURL, aParams ); + bool bRet = m_pData->m_pObjectShell->APISaveAs_Impl(sURL, *pItemSet); if ( bCopyTo ) { @@ -3073,11 +3073,11 @@ void SfxBaseModel::impl_store( const OUString& sURL } Reference < task::XInteractionHandler > xHandler; - const SfxUnoAnyItem* pItem = SfxItemSet::GetItem<SfxUnoAnyItem>(aParams, SID_INTERACTIONHANDLER, false); + const SfxUnoAnyItem* pItem = pItemSet->GetItem<SfxUnoAnyItem>(SID_INTERACTIONHANDLER, false); if ( pItem ) pItem->GetValue() >>= xHandler; - DELETEZ( aParams ); + pItemSet.reset(); sal_uInt32 nErrCode = m_pData->m_pObjectShell->GetErrorCode(); if ( !bRet && !nErrCode ) commit f6f32e8eabb2e09fbe2b70dfb540bb1ea1ee75a9 Author: Jan Holesovsky <ke...@collabora.com> Date: Mon Oct 19 08:43:28 2015 +0200 sfx items: Get rid of the TypeId check, nobody uses that any more. And introduce the appropriate assert() in the templatized version instead. Change-Id: I3e5b01e5e5ee49049fa6f35e3d05ef65a1890dc1 diff --git a/include/svl/itemset.hxx b/include/svl/itemset.hxx index 7520d0d..a070eab 100644 --- a/include/svl/itemset.hxx +++ b/include/svl/itemset.hxx @@ -80,16 +80,26 @@ public: sal_uInt16 TotalCount() const; const SfxPoolItem& Get( sal_uInt16 nWhich, bool bSrchInParent = true ) const; - const SfxPoolItem* GetItem( sal_uInt16 nWhich, bool bSearchInParent = true, - TypeId aItemType = 0 ) const; - /// Templatized version to directly return the correct type. + /** This method eases accessing single Items in the SfxItemSet. + + @param nId SlotId or the Item's WhichId + @param bSearchInParent also search in parent ItemSets + @returns 0 if the ItemSet does not contain an Item with the Id 'nWhich' + */ + const SfxPoolItem* GetItem(sal_uInt16 nWhich, bool bSearchInParent = true) const; + + /// Templatized version of GetItem() to directly return the correct type. template<class T> const T* GetItem(sal_uInt16 nWhich, bool bSearchInParent = true) const { - return dynamic_cast<const T*>(GetItem(nWhich, bSearchInParent)); + const SfxPoolItem* pItem = GetItem(nWhich, bSearchInParent); + const T* pCastedItem = dynamic_cast<const T*>(pItem); + + assert(!pItem || pCastedItem); // if it exists, must have the correct type + return pCastedItem; } - /// Templatized static version to directly return the correct type if the SfxItemSet is available. + /// Templatized static version of GetItem() to directly return the correct type if the SfxItemSet is available. template<class T> static const T* GetItem(const SfxItemSet* pItemSet, sal_uInt16 nWhich, bool bSearchInParent = true) { if (pItemSet) diff --git a/svl/source/items/itemset.cxx b/svl/source/items/itemset.cxx index d9363c1..1e72cf6 100644 --- a/svl/source/items/itemset.cxx +++ b/svl/source/items/itemset.cxx @@ -812,47 +812,20 @@ bool SfxItemSet::Set return bRet; } -/** - * This method eases accessing single Items in the SfxItemSet. - * Type checking is done via assertion, which makes client code - * much more readable. - * - * The PRODUCT version returns 0, if the Item found is not of the - * specified class. - * - * @returns 0 if the ItemSet does not contain an Item with the Id 'nWhich' - */ -const SfxPoolItem* SfxItemSet::GetItem -( - sal_uInt16 nId, // SlotId or the Item's WhichId - bool bSrchInParent, // sal_True: also search in Parent ItemSets - TypeId aItemType // != 0 => RTTI check using assertion -) const +const SfxPoolItem* SfxItemSet::GetItem(sal_uInt16 nId, bool bSearchInParent) const { // Convert to WhichId sal_uInt16 nWhich = GetPool()->GetWhich(nId); // Is the Item set or 'bDeep == true' available? const SfxPoolItem *pItem = 0; - SfxItemState eState = GetItemState( nWhich, bSrchInParent, &pItem ); - if ( bSrchInParent && SfxItemState::DEFAULT == eState && - nWhich <= SFX_WHICH_MAX ) + SfxItemState eState = GetItemState(nWhich, bSearchInParent, &pItem); + if (bSearchInParent && SfxItemState::DEFAULT == eState && nWhich <= SFX_WHICH_MAX) { pItem = &m_pPool->GetDefaultItem(nWhich); } - if ( pItem ) - { - // Does the type match? - if ( !aItemType || pItem->IsA(aItemType) ) - return pItem; - - // Else report error - assert(!"invalid argument type"); - } - - // No Item of wrong type found - return 0; + return pItem; } const SfxPoolItem& SfxItemSet::Get( sal_uInt16 nWhich, bool bSrchInParent) const _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits