avmedia/source/framework/mediaplayer.cxx | 1 basctl/source/basicide/IDEComboBox.cxx | 1 basctl/source/basicide/baside2b.cxx | 1 basctl/source/basicide/bastype2.cxx | 1 basctl/source/basicide/bastypes.cxx | 1 basctl/source/basicide/brkdlg.cxx | 1 cui/source/dialogs/hldocntp.cxx | 8 - cui/source/options/treeopt.cxx | 37 ++++--- desktop/source/lib/init.cxx | 17 +-- include/sfx2/bindings.hxx | 5 - include/sfx2/dispatch.hxx | 16 +-- include/sfx2/request.hxx | 2 include/sfx2/shell.hxx | 5 - include/svl/itemset.hxx | 14 ++- include/svl/poolitem.hxx | 15 +-- sc/source/ui/cctrl/cbnumberformat.cxx | 1 sc/source/ui/dbgui/PivotLayoutDialog.cxx | 6 - sc/source/ui/navipi/scenwnd.cxx | 1 sc/source/ui/sidebar/AlignmentPropertyPanel.cxx | 1 sc/source/ui/sidebar/CellBorderStyleControl.cxx | 1 sc/source/ui/sidebar/CellLineStyleControl.cxx | 1 sc/source/ui/sidebar/NumberFormatPropertyPanel.cxx | 1 sc/source/ui/view/viewfun2.cxx | 12 +- sc/source/ui/view/viewfun4.cxx | 14 +-- sd/qa/unit/tiledrendering/tiledrendering.cxx | 4 sd/source/ui/app/sdmod1.cxx | 12 +- sd/source/ui/dlg/NavigatorChildWindow.cxx | 1 sd/source/ui/sidebar/LayoutMenu.cxx | 4 sd/source/ui/unoidl/unomodel.cxx | 5 - sd/source/ui/unoidl/unomodule.cxx | 4 sfx2/Library_sfx.mk | 1 sfx2/inc/pch/precompiled_sfx.hxx | 1 sfx2/source/appl/appdde.cxx | 9 - sfx2/source/appl/appopen.cxx | 27 ++--- sfx2/source/appl/appserv.cxx | 14 +-- sfx2/source/control/bindings.cxx | 55 +++++------ sfx2/source/control/dispatch.cxx | 49 +++++----- sfx2/source/control/itemdel.cxx | 56 ------------ sfx2/source/control/request.cxx | 15 +-- sfx2/source/control/shell.cxx | 25 ++--- sfx2/source/control/unoctitm.cxx | 30 +++--- sfx2/source/dialog/StyleList.cxx | 1 sfx2/source/dialog/dockwin.cxx | 1 sfx2/source/dialog/mgetempl.cxx | 6 - sfx2/source/dialog/recfloat.cxx | 1 sfx2/source/dialog/securitypage.cxx | 16 +-- sfx2/source/dialog/templdlg.cxx | 9 + sfx2/source/dialog/versdlg.cxx | 6 - sfx2/source/doc/objmisc.cxx | 4 sfx2/source/doc/objserv.cxx | 11 +- sfx2/source/doc/objxtor.cxx | 12 +- sfx2/source/inc/itemdel.hxx | 30 ------ sfx2/source/view/frmload.cxx | 8 - sfx2/source/view/viewfrm.cxx | 16 +-- sfx2/source/view/viewfrm2.cxx | 11 +- starmath/source/SmElementsPanel.cxx | 1 starmath/source/edit.cxx | 1 svl/source/items/itemset.cxx | 46 ++++++++- svl/source/items/poolitem.cxx | 1 svx/source/dialog/_bmpmask.cxx | 1 svx/source/dialog/fontwork.cxx | 1 svx/source/dialog/rubydialog.cxx | 1 svx/source/dialog/srchdlg.cxx | 16 +-- svx/source/dialog/svxruler.cxx | 1 svx/source/gallery2/galctrl.cxx | 1 svx/source/sidebar/area/AreaPropertyPanel.cxx | 5 - svx/source/sidebar/effect/EffectPropertyPanel.cxx | 1 svx/source/sidebar/graphic/GraphicPropertyPanel.cxx | 1 svx/source/sidebar/line/LinePropertyPanel.cxx | 1 svx/source/sidebar/media/MediaPlaybackPanel.cxx | 1 svx/source/sidebar/paragraph/ParaLineSpacingControl.cxx | 15 +-- svx/source/sidebar/paragraph/ParaSpacingWindow.cxx | 1 svx/source/sidebar/shadow/ShadowPropertyPanel.cxx | 1 svx/source/sidebar/text/TextCharacterSpacingControl.cxx | 7 - svx/source/sidebar/text/TextUnderlineControl.cxx | 6 - svx/source/sidebar/textcolumns/TextColumnsPropertyPanel.cxx | 1 svx/source/tbxctrls/fillctrl.cxx | 1 sw/qa/extras/tiledrendering/tiledrendering.cxx | 5 - sw/qa/extras/uiwriter/uiwriter.cxx | 5 - sw/source/core/access/AccessibilityCheck.cxx | 22 +++- sw/source/core/doc/docglbl.cxx | 3 sw/source/ui/fldui/fldtdlg.cxx | 6 - sw/source/uibase/app/apphdl.cxx | 14 +-- sw/source/uibase/app/docsh2.cxx | 9 + sw/source/uibase/dialog/watermarkdialog.cxx | 6 - sw/source/uibase/misc/glshell.cxx | 7 - sw/source/uibase/misc/redlndlg.cxx | 3 sw/source/uibase/shells/annotsh.cxx | 6 - sw/source/uibase/shells/drwtxtex.cxx | 6 - sw/source/uibase/sidebar/PageColumnControl.cxx | 5 - sw/source/uibase/sidebar/PageFooterPanel.cxx | 1 sw/source/uibase/sidebar/PageHeaderPanel.cxx | 1 sw/source/uibase/sidebar/PageMarginControl.cxx | 22 +++- sw/source/uibase/sidebar/PageOrientationControl.cxx | 16 +-- sw/source/uibase/sidebar/PageSizeControl.cxx | 22 ++-- sw/source/uibase/sidebar/WrapPropertyPanel.cxx | 1 sw/source/uibase/uiview/srcview.cxx | 3 sw/source/uibase/uiview/view.cxx | 6 - sw/source/uibase/uiview/viewstat.cxx | 14 +-- sw/source/uibase/uno/unomodule.cxx | 4 sw/source/uibase/uno/unotxvw.cxx | 8 - sw/source/uibase/utlui/glbltree.cxx | 13 +- 102 files changed, 474 insertions(+), 452 deletions(-)
New commits: commit 12223767bb156cfa5269ffd9b44626a36dbb8972 Author: Xisco Fauli <xiscofa...@libreoffice.org> AuthorDate: Fri Dec 22 10:38:52 2023 +0100 Commit: Xisco Fauli <xiscofa...@libreoffice.org> CommitDate: Fri Dec 22 20:33:23 2023 +0100 sw: fix another null deref in a11y check similar to author Caolán McNamara <caolan.mcnam...@collabora.com> 2023-12-21 16:47:18 +0000 committer Caolán McNamara <caolan.mcnam...@collabora.com> 2023-12-21 21:15:03 +0100 commit ba712e9a35179c480cdc6f9d600d79040a273d53 (patch) tree 88e237265eb6ce884d2807b4c178a761d4c73956 parent 8cd01e5278b2be25a1186139e431591a85a5080f (diff) crashreporting: apparent null deref in a11y check Change-Id: I3fb6a916fcbcce4b599a925dcc7d39a12e60a972 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/161149 Tested-by: Jenkins Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org> (cherry picked from commit ca4aa82e2a0a97a63f51820247aa4e59e645992a) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/161166 diff --git a/sw/source/core/access/AccessibilityCheck.cxx b/sw/source/core/access/AccessibilityCheck.cxx index 36226b028937..e4eaa089ef2f 100644 --- a/sw/source/core/access/AccessibilityCheck.cxx +++ b/sw/source/core/access/AccessibilityCheck.cxx @@ -132,7 +132,7 @@ class NoTextNodeAltTextCheck : public NodeCheck sfx::AccessibilityIssueID::LINKED_GRAPHIC); pIssue->setDoc(pNoTextNode->GetDoc()); pIssue->setIssueObject(IssueObject::LINKED); - pIssue->setObjectID(pNoTextNode->GetFlyFormat()->GetName()); + pIssue->setObjectID(pFrameFormat->GetName()); pIssue->setNode(pNoTextNode); pIssue->setAdditionalInfo({ aSystemPath }); } @@ -161,7 +161,7 @@ class NoTextNodeAltTextCheck : public NodeCheck sfx::AccessibilityIssueID::NO_ALT_GRAPHIC); pIssue->setDoc(pNoTextNode->GetDoc()); pIssue->setIssueObject(IssueObject::GRAPHIC); - pIssue->setObjectID(pNoTextNode->GetFlyFormat()->GetName()); + pIssue->setObjectID(pFrameFormat->GetName()); pIssue->setNode(pNoTextNode); } } @@ -1226,14 +1226,20 @@ public: return; // If a node is in fly and if it is not anchored as char, throw warning. - const SwNode* startFly = pCurrent->FindFlyStartNode(); - if (startFly - && startFly->GetFlyFormat()->GetAnchor().GetAnchorId() != RndStdIds::FLY_AS_CHAR) + const SwNode* pStartFly = pCurrent->FindFlyStartNode(); + if (!pStartFly) + return; + + const SwFrameFormat* pFormat = pStartFly->GetFlyFormat(); + if (!pFormat) + return; + + if (pFormat->GetAnchor().GetAnchorId() != RndStdIds::FLY_AS_CHAR) { SwNodeIndex aCurrentIdx(*pCurrent); - SwNodeIndex aIdx(*startFly); + SwNodeIndex aIdx(*pStartFly); SwNode* pFirstTextNode = &aIdx.GetNode(); - SwNodeOffset nEnd = startFly->EndOfSectionIndex(); + SwNodeOffset nEnd = pStartFly->EndOfSectionIndex(); while (aIdx < nEnd) { if (pFirstTextNode->IsContentNode() && pFirstTextNode->IsTextNode()) @@ -1242,7 +1248,7 @@ public: { auto pIssue = lclAddIssue(m_rIssueCollection, SwResId(STR_FLOATING_TEXT)); pIssue->setIssueObject(IssueObject::TEXTFRAME); - pIssue->setObjectID(startFly->GetFlyFormat()->GetName()); + pIssue->setObjectID(pFormat->GetName()); pIssue->setDoc(pCurrent->GetDoc()); pIssue->setNode(pCurrent); } commit eb518fc1d20628d7ee691fb7a24cd20dd4c88020 Author: Armin Le Grand (allotropia) <armin.le.grand.ext...@allotropia.de> AuthorDate: Wed Dec 20 19:42:28 2023 +0100 Commit: Xisco Fauli <xiscofa...@libreoffice.org> CommitDate: Fri Dec 22 20:33:18 2023 +0100 Remove DeleteItemOnIdlex There are some CrashReports in 7.6 which have DeleteItemOnIdle on the stack, but there is nothing reproducable. So I took a look... I first thought it's a MCGR regression, due to classes on the stack. But the Item involved is just random, can happen with any Item. Then I thought it may have to do with ITEM refactorings, but it happens with DeleteItemOnIdle involved, so also not the case. I already saw DeleteItemOnIdle when doing these and qualified as 'hack' in the way. already It is only on Windows and DeleteItemOnIdle is involved. This again (took a deeper look now) is an old hack to keep an SfxPoolItem 'alive' for some 'time'. For that, it triggers an async reschedule which then deletes the Item when being called. If the Item will be used after that is pure coincidence - seems to work in most cases. It seems as if for Windows the timing slightly changed for some scenarios, so a reschedule is too early. This can happen with this hack anytime. DeleteItemOnIdle is used in scenarios where SfxPoolItem* is e.g. returned, but is *not* anchored, so e.g. not member of an SfxItemSet. Or in short: Lifetime is not safe. DeleteItemOnIdle exists since 1st import, but was changed to AsyncEvent ca. 4 months ago (see 57145acf9ec47c23e307b7a5c0029d21d937cc35), so that may have caused it. It is possible that these errors happen on Windows since then. Before something more complicated was used to delete it late, but surely also not really safe. Due to ITEM refactor I have the knowledge/tooling to solve this. It will not be a 1-5 lines fix, but it is a hack and in the way for further ITEM refactor anyways. What we have nowadays is a SfxPoolItemHolder -> it's like an SfxItemSet for a single Item. It safely holds/ controls the lifetime of an SfxPoolItem. It is already used in quite some places. It helps to solve many hacks, also the ones putting Items directly to the Pool - due to there never was an alternative for that. In principle the ItemPool/ItemSet/Item paradigm was never complete without SfxPoolItemHolder. Thus I started to fix that (and remove that hack for good, sooo many changes over the years, sigh), but as said is not straightforward. Will have to change retvals of involved stuff to SfxPoolItemHolder - it's just two pointers and designed to be copied (one is a Pool, needed to cleanup when destructing). CopyConstruct/destroy just counts the RefCnt up/down, so cheap. 1st version compiling, let's check on gerrit... Corrected one error in QueryState for securitypage, also added some security features/asserts. Change-Id: Ida49fd35ca88ead84b11d93e18b978cb9e395090 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/161083 Tested-by: Jenkins Reviewed-by: Armin Le Grand <armin.le.gr...@me.com> (cherry picked from commit 789a737ac92c4f2b0eb9820b99c43cc8253c8b29) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/161158 Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org> diff --git a/avmedia/source/framework/mediaplayer.cxx b/avmedia/source/framework/mediaplayer.cxx index 258f23ff4645..b4acad37c741 100644 --- a/avmedia/source/framework/mediaplayer.cxx +++ b/avmedia/source/framework/mediaplayer.cxx @@ -25,6 +25,7 @@ #include <helpids.h> #include <svl/stritem.hxx> +#include <svl/itemset.hxx> #include <sfx2/sfxsids.hrc> #include <sfx2/bindings.hxx> #include <sfx2/dispatch.hxx> diff --git a/basctl/source/basicide/IDEComboBox.cxx b/basctl/source/basicide/IDEComboBox.cxx index 423e5c5d1cda..d25e143d62fa 100644 --- a/basctl/source/basicide/IDEComboBox.cxx +++ b/basctl/source/basicide/IDEComboBox.cxx @@ -34,6 +34,7 @@ #include <vcl/svapp.hxx> #include <vcl/toolbox.hxx> #include <vcl/event.hxx> +#include <svl/itemset.hxx> namespace basctl { diff --git a/basctl/source/basicide/baside2b.cxx b/basctl/source/basicide/baside2b.cxx index d410a5e325d6..0cb13161178b 100644 --- a/basctl/source/basicide/baside2b.cxx +++ b/basctl/source/basicide/baside2b.cxx @@ -70,6 +70,7 @@ #include "textwindowpeer.hxx" #include "uiobject.hxx" #include <basegfx/utils/zoomtools.hxx> +#include <svl/itemset.hxx> namespace basctl { diff --git a/basctl/source/basicide/bastype2.cxx b/basctl/source/basicide/bastype2.cxx index 8040c25f32c1..18ca75e01bfe 100644 --- a/basctl/source/basicide/bastype2.cxx +++ b/basctl/source/basicide/bastype2.cxx @@ -32,6 +32,7 @@ #include <comphelper/processfactory.hxx> #include <sfx2/dispatch.hxx> #include <sfx2/sfxsids.hrc> +#include <svl/itemset.hxx> #include <initializer_list> #include <memory> diff --git a/basctl/source/basicide/bastypes.cxx b/basctl/source/basicide/bastypes.cxx index 8c523e2bdb04..e436bc9f7e0a 100644 --- a/basctl/source/basicide/bastypes.cxx +++ b/basctl/source/basicide/bastypes.cxx @@ -42,6 +42,7 @@ #include <svl/intitem.hxx> #include <svl/stritem.hxx> #include <svl/srchdefs.hxx> +#include <svl/itemset.hxx> #include <utility> #include <vcl/commandevent.hxx> #include <vcl/event.hxx> diff --git a/basctl/source/basicide/brkdlg.cxx b/basctl/source/basicide/brkdlg.cxx index 48522d11ac37..f39255371b19 100644 --- a/basctl/source/basicide/brkdlg.cxx +++ b/basctl/source/basicide/brkdlg.cxx @@ -25,6 +25,7 @@ #include <sfx2/dispatch.hxx> #include <sfx2/sfxsids.hrc> +#include <svl/itemset.hxx> namespace basctl { diff --git a/cui/source/dialogs/hldocntp.cxx b/cui/source/dialogs/hldocntp.cxx index 4bdb56ea0658..3b3352315dd1 100644 --- a/cui/source/dialogs/hldocntp.cxx +++ b/cui/source/dialogs/hldocntp.cxx @@ -274,12 +274,12 @@ IMPL_STATIC_LINK(SvxHyperlinkNewDocTp, DispatchDocument, void*, p, void) SfxStringItem aFlags (SID_OPTIONS, aStrFlags); // open url - const SfxPoolItem* pReturn = xExecuteInfo->pDispatcher->ExecuteList( - SID_OPENDOC, SfxCallMode::SYNCHRON, - { &aName, &aFlags, &aFrame, &aReferer }); + const SfxPoolItemHolder aResult(xExecuteInfo->pDispatcher->ExecuteList( + SID_OPENDOC, SfxCallMode::SYNCHRON, + { &aName, &aFlags, &aFrame, &aReferer })); // save new doc - const SfxViewFrameItem *pItem = dynamic_cast<const SfxViewFrameItem*>( pReturn ); // SJ: pReturn is NULL if the Hyperlink + const SfxViewFrameItem *pItem = dynamic_cast<const SfxViewFrameItem*>(aResult.getItem()); // aResult is NULL if the Hyperlink if ( pItem ) // creation is cancelled #106216# { pViewFrame = pItem->GetFrame(); diff --git a/cui/source/options/treeopt.cxx b/cui/source/options/treeopt.cxx index b4b9e986019d..d8fe793e10b7 100644 --- a/cui/source/options/treeopt.cxx +++ b/cui/source/options/treeopt.cxx @@ -1424,11 +1424,12 @@ std::optional<SfxItemSet> OfaTreeOptionsDialog::CreateItemSet( sal_uInt16 nId ) SfxViewFrame* pViewFrame = SfxViewFrame::Current(); if ( pViewFrame ) { - const SfxUInt16Item* pItem = nullptr; - SfxDispatcher* pDispatch = pViewFrame->GetDispatcher(); + SfxPoolItemHolder aResult; + const SfxItemState aState(pViewFrame->GetDispatcher()->QueryState(SID_ATTR_YEAR2000, aResult)); + const SfxUInt16Item* pItem(static_cast<const SfxUInt16Item*>(aResult.getItem())); // miscellaneous - Year2000 - if( SfxItemState::DEFAULT <= pDispatch->QueryState( SID_ATTR_YEAR2000, pItem ) ) + if(SfxItemState::DEFAULT <= aState && nullptr != pItem) pRet->Put( SfxUInt16Item( SID_ATTR_YEAR2000, pItem->GetValue() ) ); else pRet->Put( SfxUInt16Item( SID_ATTR_YEAR2000, officecfg::Office::Common::DateFormat::TwoDigitYear::get() ) ); @@ -1474,20 +1475,28 @@ std::optional<SfxItemSet> OfaTreeOptionsDialog::CreateItemSet( sal_uInt16 nId ) SfxViewFrame* pViewFrame = SfxViewFrame::Current(); if ( pViewFrame ) { - const SvxLanguageItem* pLangItem = nullptr; - SfxDispatcher* pDispatch = pViewFrame->GetDispatcher(); - if(SfxItemState::DEFAULT <= pDispatch->QueryState(SID_ATTR_LANGUAGE, pLangItem)) - pRet->Put(*pLangItem, SID_ATTR_LANGUAGE); - if(SfxItemState::DEFAULT <= pDispatch->QueryState(SID_ATTR_CHAR_CJK_LANGUAGE, pLangItem)) - pRet->Put(*pLangItem, SID_ATTR_CHAR_CJK_LANGUAGE); - if(SfxItemState::DEFAULT <= pDispatch->QueryState(SID_ATTR_CHAR_CTL_LANGUAGE, pLangItem)) - pRet->Put(*pLangItem, SID_ATTR_CHAR_CTL_LANGUAGE); + SfxPoolItemHolder aResult; + SfxDispatcher* pDispatch(pViewFrame->GetDispatcher()); + + SfxItemState aState(pDispatch->QueryState(SID_ATTR_LANGUAGE, aResult)); + if(SfxItemState::DEFAULT <= aState) + pRet->Put(*aResult.getItem(), SID_ATTR_LANGUAGE); + + aState = pDispatch->QueryState(SID_ATTR_CHAR_CJK_LANGUAGE, aResult); + if(SfxItemState::DEFAULT <= aState) + pRet->Put(*aResult.getItem(), SID_ATTR_CHAR_CJK_LANGUAGE); + + aState = pDispatch->QueryState(SID_ATTR_CHAR_CTL_LANGUAGE, aResult); + if(SfxItemState::DEFAULT <= aState) + pRet->Put(*aResult.getItem(), SID_ATTR_CHAR_CTL_LANGUAGE); pRet->Put(aHyphen); - const SfxPoolItem* pItem = nullptr; - if(SfxItemState::DEFAULT <= pDispatch->QueryState(SID_AUTOSPELL_CHECK, pItem)) + + aState = pDispatch->QueryState(SID_AUTOSPELL_CHECK, aResult); + if(SfxItemState::DEFAULT <= aState) { - pRet->Put(std::unique_ptr<SfxPoolItem>(pItem->Clone())); + pRet->Put(*aResult.getItem()); // allow share/refcounting + // pRet->Put(std::unique_ptr<SfxPoolItem>(aResult.getItem()->Clone())); } else { diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index e5aaa66ddb35..ab12a160b97a 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -909,18 +909,15 @@ void ExecuteOrientationChange() if ( mxUndoManager.is() ) mxUndoManager->enterUndoContext( "" ); + SfxPoolItemHolder aResult; + pViewFrm->GetBindings().GetDispatcher()->QueryState(SID_ATTR_PAGE_SIZE, aResult); + std::unique_ptr<SvxSizeItem> pPageSizeItem(static_cast<const SvxSizeItem*>(aResult.getItem())->Clone()); - const SvxSizeItem* pSizeItem; - pViewFrm->GetBindings().GetDispatcher()->QueryState(SID_ATTR_PAGE_SIZE, pSizeItem); - std::unique_ptr<SvxSizeItem> pPageSizeItem(pSizeItem->Clone()); + pViewFrm->GetBindings().GetDispatcher()->QueryState(SID_ATTR_PAGE_LRSPACE, aResult); + std::unique_ptr<SvxLongLRSpaceItem> pPageLRMarginItem(static_cast<const SvxLongLRSpaceItem*>(aResult.getItem())->Clone()); - const SvxLongLRSpaceItem* pLRSpaceItem; - pViewFrm->GetBindings().GetDispatcher()->QueryState(SID_ATTR_PAGE_LRSPACE, pLRSpaceItem); - std::unique_ptr<SvxLongLRSpaceItem> pPageLRMarginItem(pLRSpaceItem->Clone()); - - const SvxLongULSpaceItem* pULSpaceItem; - pViewFrm->GetBindings().GetDispatcher()->QueryState(SID_ATTR_PAGE_ULSPACE, pULSpaceItem); - std::unique_ptr<SvxLongULSpaceItem> pPageULMarginItem(pULSpaceItem->Clone()); + pViewFrm->GetBindings().GetDispatcher()->QueryState(SID_ATTR_PAGE_ULSPACE, aResult); + std::unique_ptr<SvxLongULSpaceItem> pPageULMarginItem(static_cast<const SvxLongULSpaceItem*>(aResult.getItem())->Clone()); { bool bIsLandscape = false; diff --git a/include/sfx2/bindings.hxx b/include/sfx2/bindings.hxx index 7e5369126803..8cd92a24108d 100644 --- a/include/sfx2/bindings.hxx +++ b/include/sfx2/bindings.hxx @@ -52,6 +52,7 @@ class Timer; class SfxWorkWindow; struct SfxFoundCache_Impl; class SfxFoundCacheArr_Impl; +class SfxPoolItemHolder; enum class SfxCallMode : sal_uInt16 { @@ -99,7 +100,7 @@ friend class SfxBindings_Impl; sal_uInt16 nRegLevel; // Lock-Level while Reconfig private: - SAL_DLLPRIVATE const SfxPoolItem* Execute_Impl( sal_uInt16 nSlot, const SfxPoolItem **pArgs, sal_uInt16 nModi, + SAL_DLLPRIVATE SfxPoolItemHolder Execute_Impl( sal_uInt16 nSlot, const SfxPoolItem **pArgs, sal_uInt16 nModi, SfxCallMode nCall, const SfxPoolItem **pInternalArgs, bool bGlobalOnly=false); SAL_DLLPRIVATE void SetSubBindings_Impl( SfxBindings* ); SAL_DLLPRIVATE void UpdateSlotServer_Impl(); // Update SlotServer @@ -155,7 +156,7 @@ public: sal_uInt16 QuerySlotId( const css::util::URL& aURL ); - const SfxPoolItem* ExecuteSynchron( sal_uInt16 nSlot, + SfxPoolItemHolder ExecuteSynchron( sal_uInt16 nSlot, const SfxPoolItem **pArgs = nullptr); bool Execute( sal_uInt16 nSlot, const SfxPoolItem **pArgs = nullptr, diff --git a/include/sfx2/dispatch.hxx b/include/sfx2/dispatch.hxx index cfa94a318d5f..7216fc92badc 100644 --- a/include/sfx2/dispatch.hxx +++ b/include/sfx2/dispatch.hxx @@ -41,6 +41,7 @@ class SfxModule; class Point; struct SfxDispatcher_Impl; class VCLXPopupMenu; +class SfxPoolItemHolder; namespace com::sun::star::awt { class XPopupMenu; } namespace vcl { class Window; } @@ -104,24 +105,24 @@ public: ~SfxDispatcher(); - const SfxPoolItem* Execute( sal_uInt16 nSlot, + SfxPoolItemHolder Execute( sal_uInt16 nSlot, SfxCallMode nCall = SfxCallMode::SLOT, const SfxPoolItem **pArgs = nullptr, sal_uInt16 nModi = 0, const SfxPoolItem **pInternalArgs = nullptr); - const SfxPoolItem* Execute(sal_uInt16 nSlot, + SfxPoolItemHolder Execute(sal_uInt16 nSlot, SfxCallMode nCall, SfxItemSet const * pArgs, SfxItemSet const * pInternalArgs, sal_uInt16 nModi); - const SfxPoolItem* ExecuteList(sal_uInt16 nSlot, + SfxPoolItemHolder ExecuteList(sal_uInt16 nSlot, SfxCallMode nCall, std::initializer_list<SfxPoolItem const*> args, std::initializer_list<SfxPoolItem const*> internalargs = std::initializer_list<SfxPoolItem const*>()); - const SfxPoolItem* Execute( sal_uInt16 nSlot, + SfxPoolItemHolder Execute( sal_uInt16 nSlot, SfxCallMode nCall, const SfxItemSet &rArgs ); @@ -152,12 +153,7 @@ public: void HideUI( bool bHide = true ); ToolbarId GetObjectBarId( sal_uInt16 nPos ) const; - SfxItemState QueryState( sal_uInt16 nSID, const SfxPoolItem* &rpState ); - template<class T> - SfxItemState QueryState( TypedWhichId<T> nSID, const T* &rpState ) - { - return QueryState(sal_uInt16(nSID), reinterpret_cast<SfxPoolItem const*&>(rpState)); - } + SfxItemState QueryState( sal_uInt16 nSID, SfxPoolItemHolder& rState ); SfxItemState QueryState( sal_uInt16 nSID, css::uno::Any& rAny ); void SetDisableFlags( SfxDisableFlags nFlags ); diff --git a/include/sfx2/request.hxx b/include/sfx2/request.hxx index 5c7db9925560..63c6544bfe43 100644 --- a/include/sfx2/request.hxx +++ b/include/sfx2/request.hxx @@ -95,7 +95,7 @@ public: void ReleaseArgs(); void SetReturnValue(const SfxPoolItem &); - const SfxPoolItem* GetReturnValue() const; + const SfxPoolItemHolder& GetReturnValue() const; static css::uno::Reference< css::frame::XDispatchRecorder > GetMacroRecorder(const SfxViewFrame& rFrame); static bool HasMacroRecorder(const SfxViewFrame& rFrame); diff --git a/include/sfx2/shell.hxx b/include/sfx2/shell.hxx index 2da1472a800f..b454547970a5 100644 --- a/include/sfx2/shell.hxx +++ b/include/sfx2/shell.hxx @@ -50,6 +50,7 @@ class SfxRepeatTarget; class SfxBindings; class SfxModule; class SfxUndoManager; +class SfxPoolItemHolder; /** Id for <SfxInterface>s, gives a quasi-static access to the interface @@ -231,7 +232,7 @@ public: <SfxShell::ExecuteSlot(SfxRequest&)> */ - const SfxPoolItem* GetSlotState( sal_uInt16 nSlotId, const SfxInterface *pIF = nullptr, SfxItemSet *pStateSet = nullptr ); + SfxPoolItemHolder GetSlotState( sal_uInt16 nSlotId, const SfxInterface *pIF = nullptr, SfxItemSet *pStateSet = nullptr ); /** This method allows you to forward a <SfxRequest> to the specified @@ -263,7 +264,7 @@ public: <SfxShell::GetSlotState(sal_uInt16,const SfxInterface*,SfxItemSet*)> */ - const SfxPoolItem* ExecuteSlot( SfxRequest &rReq, const SfxInterface *pIF = nullptr ); + const SfxPoolItemHolder& ExecuteSlot( SfxRequest &rReq, const SfxInterface *pIF = nullptr ); /** Asynchronous ExecuteSlot for the RELOAD diff --git a/include/svl/itemset.hxx b/include/svl/itemset.hxx index 599afc7ab5bd..0a28d429c142 100644 --- a/include/svl/itemset.hxx +++ b/include/svl/itemset.hxx @@ -46,15 +46,23 @@ class SAL_WARN_UNUSED SVL_DLLPUBLIC SfxPoolItemHolder { SfxItemPool* m_pPool; const SfxPoolItem* m_pItem; +#ifdef DBG_UTIL + bool m_bDeleted; +#endif public: - SfxPoolItemHolder(SfxItemPool&, const SfxPoolItem* = nullptr); + SfxPoolItemHolder(); + SfxPoolItemHolder(SfxItemPool&, const SfxPoolItem*, bool bPassingOwnership = false); SfxPoolItemHolder(const SfxPoolItemHolder&); ~SfxPoolItemHolder(); +#ifdef DBG_UTIL + bool isDeleted() const { return m_bDeleted; } +#endif + const SfxPoolItemHolder& operator=(const SfxPoolItemHolder&); bool operator==(const SfxPoolItemHolder &) const; - SfxItemPool& getPool() const { return *m_pPool; } - const SfxPoolItem* getItem() const { return m_pItem; } + SfxItemPool& getPool() const { assert(!isDeleted() && "Destructed instance used (!)"); return *m_pPool; } + const SfxPoolItem* getItem() const { assert(!isDeleted() && "Destructed instance used (!)"); return m_pItem; } sal_uInt16 Which() const { if(nullptr != m_pItem) return m_pItem->Which(); return 0; } }; diff --git a/include/svl/poolitem.hxx b/include/svl/poolitem.hxx index 38e6e44edc93..af993096e655 100644 --- a/include/svl/poolitem.hxx +++ b/include/svl/poolitem.hxx @@ -131,17 +131,16 @@ class SVL_DLLPUBLIC SfxPoolItem // bitfield for flags (instead of SfxItemKind) bool m_bIsVoidItem : 1; // bit 0 - bool m_bDeleteOnIdle : 1; // bit 1 - bool m_bStaticDefault : 1; // bit 2 - bool m_bPoolDefault : 1; // bit 3 - bool m_bRegisteredAtPool : 1; // bit 4 - bool m_bExceptionalSCItem : 1; // bit 5 - bool m_bIsSetItem : 1; // bit 6 + bool m_bStaticDefault : 1; // bit 1 + bool m_bPoolDefault : 1; // bit 2 + bool m_bRegisteredAtPool : 1; // bit 3 + bool m_bExceptionalSCItem : 1; // bit 4 + bool m_bIsSetItem : 1; // bit 5 protected: #ifdef DBG_UTIL // this flag will make debugging item stuff much simpler - bool m_bDeleted : 1; // bit 7 + bool m_bDeleted : 1; // bit 6 #endif private: @@ -153,7 +152,6 @@ private: protected: void setIsVoidItem() { m_bIsVoidItem = true; } - void setDeleteOnIdle() { m_bDeleteOnIdle = true; } void setStaticDefault() { m_bStaticDefault = true; } void setPoolDefault() { m_bPoolDefault = true; } void setRegisteredAtPool(bool bNew) { m_bRegisteredAtPool = bNew; } @@ -173,7 +171,6 @@ public: #endif bool isVoidItem() const { return m_bIsVoidItem; } - bool isDeleteOnIdle() const { return m_bDeleteOnIdle; } bool isStaticDefault() const { return m_bStaticDefault; } bool isPoolDefault() const { return m_bPoolDefault; } bool isRegisteredAtPool() const { return m_bRegisteredAtPool; } diff --git a/sc/source/ui/cctrl/cbnumberformat.cxx b/sc/source/ui/cctrl/cbnumberformat.cxx index 29ab64e84e75..760d6a7f9ca1 100644 --- a/sc/source/ui/cctrl/cbnumberformat.cxx +++ b/sc/source/ui/cctrl/cbnumberformat.cxx @@ -24,6 +24,7 @@ #include <sfx2/viewfrm.hxx> #include <sfx2/viewsh.hxx> #include <svl/intitem.hxx> +#include <svl/itemset.hxx> #include <sc.hrc> ScNumberFormat::ScNumberFormat(vcl::Window* pParent) diff --git a/sc/source/ui/dbgui/PivotLayoutDialog.cxx b/sc/source/ui/dbgui/PivotLayoutDialog.cxx index 17165eac6867..de1f6b3b6f8e 100644 --- a/sc/source/ui/dbgui/PivotLayoutDialog.cxx +++ b/sc/source/ui/dbgui/PivotLayoutDialog.cxx @@ -484,10 +484,10 @@ void ScPivotLayoutDialog::ApplyChanges() SfxDispatcher* pDispatcher = GetBindings().GetDispatcher(); SfxCallMode const nCallMode = SfxCallMode::SLOT | SfxCallMode::RECORD; - const SfxPoolItem* pResult = pDispatcher->ExecuteList(SID_PIVOT_TABLE, - nCallMode, { &aPivotItem }); + const SfxPoolItemHolder aResult(pDispatcher->ExecuteList(SID_PIVOT_TABLE, + nCallMode, { &aPivotItem })); - if (pResult != nullptr) + if (nullptr != aResult.getItem()) { // existing pivot table might have moved to a new range or a new sheet if ( pOldDPObj != nullptr ) diff --git a/sc/source/ui/navipi/scenwnd.cxx b/sc/source/ui/navipi/scenwnd.cxx index 5ca601d2e64c..22ee5148fc7b 100644 --- a/sc/source/ui/navipi/scenwnd.cxx +++ b/sc/source/ui/navipi/scenwnd.cxx @@ -22,6 +22,7 @@ #include <sfx2/viewfrm.hxx> #include <svl/slstitm.hxx> #include <svl/stritem.hxx> +#include <svl/itemset.hxx> #include <vcl/commandevent.hxx> #include <vcl/event.hxx> #include <vcl/svapp.hxx> diff --git a/sc/source/ui/sidebar/AlignmentPropertyPanel.cxx b/sc/source/ui/sidebar/AlignmentPropertyPanel.cxx index 370b791573ed..66f7e35871cb 100644 --- a/sc/source/ui/sidebar/AlignmentPropertyPanel.cxx +++ b/sc/source/ui/sidebar/AlignmentPropertyPanel.cxx @@ -25,6 +25,7 @@ #include <sfx2/bindings.hxx> #include <sfx2/dispatch.hxx> #include <svl/intitem.hxx> +#include <svl/itemset.hxx> #include <svx/rotmodit.hxx> #include <svtools/unitconv.hxx> #include <com/sun/star/lang/IllegalArgumentException.hpp> diff --git a/sc/source/ui/sidebar/CellBorderStyleControl.cxx b/sc/source/ui/sidebar/CellBorderStyleControl.cxx index 1c75a4a9ae34..e3b9e6a0232e 100644 --- a/sc/source/ui/sidebar/CellBorderStyleControl.cxx +++ b/sc/source/ui/sidebar/CellBorderStyleControl.cxx @@ -25,6 +25,7 @@ #include <svx/svxids.hrc> #include <vcl/settings.hxx> #include <editeng/lineitem.hxx> +#include <svl/itemset.hxx> #include <memory> namespace sc::sidebar { diff --git a/sc/source/ui/sidebar/CellLineStyleControl.cxx b/sc/source/ui/sidebar/CellLineStyleControl.cxx index b6510ffa393d..e9ea1ad34e66 100644 --- a/sc/source/ui/sidebar/CellLineStyleControl.cxx +++ b/sc/source/ui/sidebar/CellLineStyleControl.cxx @@ -27,6 +27,7 @@ #include <sfx2/bindings.hxx> #include <sfx2/dispatch.hxx> #include <svx/svxids.hrc> +#include <svl/itemset.hxx> #include <scresid.hxx> #include <strings.hrc> diff --git a/sc/source/ui/sidebar/NumberFormatPropertyPanel.cxx b/sc/source/ui/sidebar/NumberFormatPropertyPanel.cxx index 753e4ec5392b..c604d41b06fb 100644 --- a/sc/source/ui/sidebar/NumberFormatPropertyPanel.cxx +++ b/sc/source/ui/sidebar/NumberFormatPropertyPanel.cxx @@ -23,6 +23,7 @@ #include <sfx2/dispatch.hxx> #include <svl/intitem.hxx> #include <svl/stritem.hxx> +#include <svl/itemset.hxx> #include <svx/numfmtsh.hxx> #include <o3tl/string_view.hxx> #include <com/sun/star/lang/IllegalArgumentException.hpp> diff --git a/sc/source/ui/view/viewfun2.cxx b/sc/source/ui/view/viewfun2.cxx index 42c3ba2a62cd..224bb722e0dd 100644 --- a/sc/source/ui/view/viewfun2.cxx +++ b/sc/source/ui/view/viewfun2.cxx @@ -2882,14 +2882,14 @@ void ScViewFunc::MoveTable( SfxStringItem aItem( SID_FILE_NAME, "private:factory/" + STRING_SCAPP ); SfxStringItem aTarget( SID_TARGETNAME, "_blank" ); - const SfxPoolItem* pRetItem = GetViewData().GetDispatcher().ExecuteList( - SID_OPENDOC, SfxCallMode::API|SfxCallMode::SYNCHRON, - { &aItem, &aTarget }); - if ( pRetItem ) + const SfxPoolItemHolder aResult(GetViewData().GetDispatcher().ExecuteList( + SID_OPENDOC, SfxCallMode::API|SfxCallMode::SYNCHRON, + { &aItem, &aTarget })); + if (nullptr != aResult.getItem()) { - if ( auto pObjectItem = dynamic_cast<const SfxObjectItem*>(pRetItem) ) + if ( auto pObjectItem = dynamic_cast<const SfxObjectItem*>(aResult.getItem()) ) pDestShell = dynamic_cast<ScDocShell*>( pObjectItem->GetShell() ); - else if ( auto pViewFrameItem = dynamic_cast<const SfxViewFrameItem*>( pRetItem) ) + else if ( auto pViewFrameItem = dynamic_cast<const SfxViewFrameItem*>(aResult.getItem())) { SfxViewFrame* pFrm = pViewFrameItem->GetFrame(); if (pFrm) diff --git a/sc/source/ui/view/viewfun4.cxx b/sc/source/ui/view/viewfun4.cxx index 8db1f1e2c85b..d75541b30234 100644 --- a/sc/source/ui/view/viewfun4.cxx +++ b/sc/source/ui/view/viewfun4.cxx @@ -587,9 +587,10 @@ bool ScViewFunc::PasteFile( const Point& rPos, const OUString& rFile, bool bLink if( ::avmedia::MediaWindow::isMediaURL( aStrURL, ""/*TODO?*/ ) ) { const SfxStringItem aMediaURLItem( SID_INSERT_AVMEDIA, aStrURL ); - return ( nullptr != GetViewData().GetDispatcher().ExecuteList( - SID_INSERT_AVMEDIA, SfxCallMode::SYNCHRON, - { &aMediaURLItem }) ); + const SfxPoolItemHolder aResult(GetViewData().GetDispatcher().ExecuteList( + SID_INSERT_AVMEDIA, SfxCallMode::SYNCHRON, + { &aMediaURLItem })); + return (nullptr != aResult.getItem()); } #endif @@ -617,9 +618,10 @@ bool ScViewFunc::PasteFile( const Point& rPos, const OUString& rFile, bool bLink // Open Asynchronously, because it can also happen from D&D // and that is not so good for the MAC... - return (nullptr != rDispatcher.ExecuteList(SID_OPENDOC, - SfxCallMode::ASYNCHRON, - { &aFileNameItem, &aFilterItem, &aTargetItem})); + const SfxPoolItemHolder aResult(rDispatcher.ExecuteList(SID_OPENDOC, + SfxCallMode::ASYNCHRON, + { &aFileNameItem, &aFilterItem, &aTargetItem})); + return (nullptr != aResult.getItem()); } } diff --git a/sd/qa/unit/tiledrendering/tiledrendering.cxx b/sd/qa/unit/tiledrendering/tiledrendering.cxx index 23d96e7595bd..2136cd378aba 100644 --- a/sd/qa/unit/tiledrendering/tiledrendering.cxx +++ b/sd/qa/unit/tiledrendering/tiledrendering.cxx @@ -1217,7 +1217,7 @@ CPPUNIT_TEST_FIXTURE(SdTiledRenderingTest, testUndoLimiting) SfxRequest aReq2(SID_UNDO, SfxCallMode::SLOT, pXImpressDocument->GetDocShell()->GetDoc()->GetPool()); aReq2.AppendItem(SfxUInt16Item(SID_UNDO, 1)); pViewShell2->ExecuteSlot(aReq2); - const auto* pReturnValue = aReq2.GetReturnValue(); + const auto* pReturnValue = aReq2.GetReturnValue().getItem(); CPPUNIT_ASSERT(!pReturnValue); } @@ -1249,7 +1249,7 @@ CPPUNIT_TEST_FIXTURE(SdTiledRenderingTest, testUndoLimiting) SfxRequest aReq2(SID_UNDO, SfxCallMode::SLOT, pXImpressDocument->GetDocShell()->GetDoc()->GetPool()); aReq2.AppendItem(SfxUInt16Item(SID_UNDO, 1)); pViewShell2->ExecuteSlot(aReq2); - const SfxUInt32Item* pUInt32Item = dynamic_cast<const SfxUInt32Item*>(aReq2.GetReturnValue()); + const SfxUInt32Item* pUInt32Item = dynamic_cast<const SfxUInt32Item*>(aReq2.GetReturnValue().getItem()); CPPUNIT_ASSERT(pUInt32Item); CPPUNIT_ASSERT_EQUAL(static_cast< sal_uInt32 >(SID_REPAIRPACKAGE), pUInt32Item->GetValue()); } diff --git a/sd/source/ui/app/sdmod1.cxx b/sd/source/ui/app/sdmod1.cxx index b211d9c95f94..0d9e82f27802 100644 --- a/sd/source/ui/app/sdmod1.cxx +++ b/sd/source/ui/app/sdmod1.cxx @@ -322,17 +322,17 @@ void SdModule::GetState(SfxItemSet& rItemSet) // state of SID_OPENDOC is determined by the base class if (rItemSet.GetItemState(SID_OPENDOC) != SfxItemState::UNKNOWN) { - const SfxPoolItem* pItem = SfxGetpApp()->GetSlotState(SID_OPENDOC, SfxGetpApp()->GetInterface()); - if (pItem) - rItemSet.Put(*pItem); + const SfxPoolItemHolder aItem(SfxGetpApp()->GetSlotState(SID_OPENDOC, SfxGetpApp()->GetInterface())); + if (nullptr != aItem.getItem()) + rItemSet.Put(*aItem.getItem()); } // state of SID_OPENHYPERLINK is determined by the base class if (rItemSet.GetItemState(SID_OPENHYPERLINK) != SfxItemState::UNKNOWN) { - const SfxPoolItem* pItem = SfxGetpApp()->GetSlotState(SID_OPENHYPERLINK, SfxGetpApp()->GetInterface()); - if (pItem) - rItemSet.Put(*pItem); + const SfxPoolItemHolder aItem(SfxGetpApp()->GetSlotState(SID_OPENHYPERLINK, SfxGetpApp()->GetInterface())); + if (nullptr != aItem.getItem()) + rItemSet.Put(*aItem.getItem()); } if( SfxItemState::DEFAULT == rItemSet.GetItemState( SID_AUTOSPELL_CHECK ) ) diff --git a/sd/source/ui/dlg/NavigatorChildWindow.cxx b/sd/source/ui/dlg/NavigatorChildWindow.cxx index 6055c238a3c9..a9746b607601 100644 --- a/sd/source/ui/dlg/NavigatorChildWindow.cxx +++ b/sd/source/ui/dlg/NavigatorChildWindow.cxx @@ -24,6 +24,7 @@ #include <sfx2/dispatch.hxx> #include <sfx2/sfxsids.hrc> #include <svl/eitem.hxx> +#include <svl/itemset.hxx> namespace sd { diff --git a/sd/source/ui/sidebar/LayoutMenu.cxx b/sd/source/ui/sidebar/LayoutMenu.cxx index 8a730bb65a61..98ab853fb5bf 100644 --- a/sd/source/ui/sidebar/LayoutMenu.cxx +++ b/sd/source/ui/sidebar/LayoutMenu.cxx @@ -588,9 +588,9 @@ void LayoutMenu::ShowContextMenu(const Point* pPos) // Disable the SID_INSERTPAGE_LAYOUT_MENU item when // the document is read-only. - const SfxPoolItem* pItem = nullptr; + SfxPoolItemHolder aResult; const SfxItemState aState ( - mrBase.GetViewFrame().GetDispatcher()->QueryState(SID_INSERTPAGE, pItem)); + mrBase.GetViewFrame().GetDispatcher()->QueryState(SID_INSERTPAGE, aResult)); if (aState == SfxItemState::DISABLED) xMenu->set_sensitive("insert", false); diff --git a/sd/source/ui/unoidl/unomodel.cxx b/sd/source/ui/unoidl/unomodel.cxx index 8ae4cd0818da..dd9d5739555b 100644 --- a/sd/source/ui/unoidl/unomodel.cxx +++ b/sd/source/ui/unoidl/unomodel.cxx @@ -2459,8 +2459,9 @@ bool SdXImpressDocument::isMasterViewMode() if (pViewSh->GetDispatcher()) { - const SfxBoolItem* isMasterViewMode = nullptr; - pViewSh->GetDispatcher()->QueryState(SID_SLIDE_MASTER_MODE, isMasterViewMode); + SfxPoolItemHolder aResult; + pViewSh->GetDispatcher()->QueryState(SID_SLIDE_MASTER_MODE, aResult); + const SfxBoolItem* isMasterViewMode(static_cast<const SfxBoolItem*>(aResult.getItem())); if (isMasterViewMode && isMasterViewMode->GetValue()) return true; } diff --git a/sd/source/ui/unoidl/unomodule.cxx b/sd/source/ui/unoidl/unomodule.cxx index d862f7c9dd36..5ee3cab40d7e 100644 --- a/sd/source/ui/unoidl/unomodule.cxx +++ b/sd/source/ui/unoidl/unomodule.cxx @@ -48,8 +48,8 @@ void SAL_CALL SdUnoModule::dispatchWithNotification( const util::URL& aURL, cons else { SfxRequest aReq( pSlot, aArgs, SfxCallMode::SYNCHRON, SD_MOD()->GetPool() ); - const SfxPoolItem* pResult = SD_MOD()->ExecuteSlot( aReq ); - if ( pResult ) + const SfxPoolItemHolder aResult(SD_MOD()->ExecuteSlot(aReq)); + if (nullptr != aResult.getItem()) aState = frame::DispatchResultState::SUCCESS; else aState = frame::DispatchResultState::FAILURE; diff --git a/sfx2/Library_sfx.mk b/sfx2/Library_sfx.mk index a9f503f3ad8a..5013ebc7a318 100644 --- a/sfx2/Library_sfx.mk +++ b/sfx2/Library_sfx.mk @@ -149,7 +149,6 @@ $(eval $(call gb_Library_add_exception_objects,sfx,\ sfx2/source/control/bindings \ sfx2/source/control/ctrlitem \ sfx2/source/control/dispatch \ - sfx2/source/control/itemdel \ sfx2/source/control/minfitem \ sfx2/source/control/msg \ sfx2/source/control/msgpool \ diff --git a/sfx2/inc/pch/precompiled_sfx.hxx b/sfx2/inc/pch/precompiled_sfx.hxx index 4c7ef0985d00..1f92a21a34ea 100644 --- a/sfx2/inc/pch/precompiled_sfx.hxx +++ b/sfx2/inc/pch/precompiled_sfx.hxx @@ -399,7 +399,6 @@ #include <eventsupplier.hxx> #include <helper.hxx> #include <helpids.h> -#include <itemdel.hxx> #include <nochaos.hxx> #include <objshimp.hxx> #include <openflag.hxx> diff --git a/sfx2/source/appl/appdde.cxx b/sfx2/source/appl/appdde.cxx index 6fe5888009dc..2f013cfc6342 100644 --- a/sfx2/source/appl/appdde.cxx +++ b/sfx2/source/appl/appdde.cxx @@ -144,12 +144,11 @@ bool ImplDdeService::MakeTopic( const OUString& rNm ) SfxBoolItem aNewView(SID_OPEN_NEW_VIEW, true); SfxBoolItem aSilent(SID_SILENT, true); - SfxDispatcher* pDispatcher = SfxGetpApp()->GetDispatcher_Impl(); - const SfxPoolItem* pRet = pDispatcher->ExecuteList(SID_OPENDOC, - SfxCallMode::SYNCHRON, - { &aName, &aNewView, &aSilent }); + const SfxPoolItemHolder aResult(SfxGetpApp()->GetDispatcher_Impl()->ExecuteList(SID_OPENDOC, + SfxCallMode::SYNCHRON, + { &aName, &aNewView, &aSilent })); - if( auto const item = dynamic_cast< const SfxViewFrameItem *>( pRet ); + if( auto const item = dynamic_cast< const SfxViewFrameItem *>(aResult.getItem()); item && item->GetFrame() && nullptr != ( pShell = item->GetFrame()->GetObjectShell() ) ) diff --git a/sfx2/source/appl/appopen.cxx b/sfx2/source/appl/appopen.cxx index 9693a5f74b04..4e1b06e52268 100644 --- a/sfx2/source/appl/appopen.cxx +++ b/sfx2/source/appl/appopen.cxx @@ -327,15 +327,15 @@ ErrCodeMsg SfxApplication::LoadTemplate( SfxObjectShellLock& xDoc, const OUStrin SfxStringItem aReferer( SID_REFERER, "private:user" ); SfxStringItem aFlags( SID_OPTIONS, "T" ); SfxBoolItem aHidden( SID_HIDDEN, true ); - const SfxPoolItem *pRet = GetDispatcher_Impl()->ExecuteList( + const SfxPoolItemHolder aRet(GetDispatcher_Impl()->ExecuteList( SID_OPENDOC, SfxCallMode::SYNCHRON, - { &aName, &aHidden, &aReferer, &aFlags } ); - const SfxObjectItem *pObj = dynamic_cast<const SfxObjectItem*>( pRet ); + { &aName, &aHidden, &aReferer, &aFlags } )); + const SfxObjectItem* pObj(dynamic_cast<const SfxObjectItem*>(aRet.getItem())); if ( pObj ) xDoc = dynamic_cast<SfxObjectShell*>( pObj->GetShell() ); else { - const SfxViewFrameItem *pView = dynamic_cast<const SfxViewFrameItem*>( pRet ); + const SfxViewFrameItem* pView(dynamic_cast<const SfxViewFrameItem*>(aRet.getItem())); if ( pView ) { SfxViewFrame *pFrame = pView->GetFrame(); @@ -435,9 +435,9 @@ void SfxApplication::NewDocDirectExec_Impl( SfxRequest& rReq ) aReq.AppendItem( *pDefaultNameItem ); SfxGetpApp()->ExecuteSlot( aReq ); - const SfxViewFrameItem* pItem = dynamic_cast<const SfxViewFrameItem*>( aReq.GetReturnValue() ); - if ( pItem ) - rReq.SetReturnValue( SfxFrameItem( 0, pItem->GetFrame() ) ); + const SfxViewFrameItem* pItem(dynamic_cast<const SfxViewFrameItem*>(aReq.GetReturnValue().getItem())); + if (nullptr != pItem) + rReq.SetReturnValue(SfxFrameItem(0, pItem->GetFrame())); } void SfxApplication::NewDocDirectState_Impl( SfxItemSet &rSet ) @@ -534,8 +534,7 @@ void SfxApplication::NewDocExec_Impl( SfxRequest& rReq ) else { SfxCallMode eMode = SfxCallMode::SYNCHRON; - - const SfxPoolItem *pRet=nullptr; + SfxPoolItemHolder aRet; SfxStringItem aReferer( SID_REFERER, "private:user" ); SfxStringItem aTarget( SID_TARGETNAME, "_default" ); if ( !aTemplateFileName.isEmpty() ) @@ -545,18 +544,18 @@ void SfxApplication::NewDocExec_Impl( SfxRequest& rReq ) SfxStringItem aName( SID_FILE_NAME, aObj.GetMainURL( INetURLObject::DecodeMechanism::NONE ) ); SfxStringItem aTemplName( SID_TEMPLATE_NAME, aTemplateName ); SfxStringItem aTemplRegionName( SID_TEMPLATE_REGIONNAME, aTemplateRegion ); - pRet = GetDispatcher_Impl()->ExecuteList(SID_OPENDOC, eMode, + aRet = GetDispatcher_Impl()->ExecuteList(SID_OPENDOC, eMode, {&aName, &aTarget, &aReferer, &aTemplName, &aTemplRegionName}); } else { SfxStringItem aName( SID_FILE_NAME, "private:factory" ); - pRet = GetDispatcher_Impl()->ExecuteList(SID_OPENDOC, eMode, + aRet = GetDispatcher_Impl()->ExecuteList(SID_OPENDOC, eMode, { &aName, &aTarget, &aReferer } ); } - if ( pRet ) - rReq.SetReturnValue( *pRet ); + if ( nullptr != aRet.getItem() ) + rReq.SetReturnValue( *aRet.getItem() ); } } @@ -1132,7 +1131,7 @@ void SfxApplication::OpenDocExec_Impl( SfxRequest& rReq ) if (pLinkItem) { - const SfxPoolItem* pRetValue = rReq.GetReturnValue(); + const SfxPoolItem* pRetValue(rReq.GetReturnValue().getItem()); if (pRetValue) { pLinkItem->GetValue().Call(pRetValue); diff --git a/sfx2/source/appl/appserv.cxx b/sfx2/source/appl/appserv.cxx index aa0699e78137..cccc2abc1a57 100644 --- a/sfx2/source/appl/appserv.cxx +++ b/sfx2/source/appl/appserv.cxx @@ -494,7 +494,7 @@ void SfxApplication::MiscExec_Impl( SfxRequest& rReq ) if ( pObjSh->IsModified() && !pObjSh->isSaveLocked()) { pObjSh->ExecuteSlot( aReq ); - const SfxBoolItem *pItem = dynamic_cast<const SfxBoolItem*>( aReq.GetReturnValue() ); + const SfxBoolItem* pItem(dynamic_cast<const SfxBoolItem*>(aReq.GetReturnValue().getItem())); if ( !pItem || !pItem->GetValue() ) bOK = false; } @@ -945,8 +945,8 @@ void SfxApplication::MiscExec_Impl( SfxRequest& rReq ) // Show/Hide the Notebookbar const SfxStringItem pItem(SID_NOTEBOOKBAR, aNewName); pViewFrame->GetDispatcher()->ExecuteList(SID_NOTEBOOKBAR, SfxCallMode::SYNCHRON, {&pItem}); - const SfxPoolItem *pNbItem; - pViewFrame->GetDispatcher()->QueryState(SID_NOTEBOOKBAR, pNbItem); + SfxPoolItemHolder aNbItem; + pViewFrame->GetDispatcher()->QueryState(SID_NOTEBOOKBAR, aNbItem); // Show toolbars for ( const OUString& rName : std::as_const(aMandatoryToolbars) ) @@ -1254,11 +1254,11 @@ void SfxApplication::MiscState_Impl(SfxItemSet &rSet) case SID_ZOOM_ENTIRE_PAGE: case SID_ZOOM_PAGE_WIDTH: { - SfxObjectShell* pCurrentShell = SfxObjectShell::Current(); + SfxObjectShell* pCurrentShell(SfxObjectShell::Current()); - const SfxPoolItem *pItem; - SfxItemState aState = pCurrentShell ? - pCurrentShell->GetDispatcher()->QueryState(SID_ATTR_ZOOM, pItem) : SfxItemState::DISABLED; + SfxPoolItemHolder aResult; + const SfxItemState aState(pCurrentShell ? + pCurrentShell->GetDispatcher()->QueryState(SID_ATTR_ZOOM, aResult) : SfxItemState::DISABLED); if ( aState == SfxItemState::DISABLED ) rSet.DisableItem( nWhich ); } diff --git a/sfx2/source/control/bindings.cxx b/sfx2/source/control/bindings.cxx index dcba259627ab..47ddda28136f 100644 --- a/sfx2/source/control/bindings.cxx +++ b/sfx2/source/control/bindings.cxx @@ -35,7 +35,6 @@ #include <com/sun/star/frame/XDispatch.hpp> #include <com/sun/star/frame/XDispatchProvider.hpp> #include <com/sun/star/frame/DispatchResultState.hpp> -#include <itemdel.hxx> //Includes below due to nInReschedule #include <sfx2/bindings.hxx> @@ -856,10 +855,10 @@ void SfxBindings::Release( SfxControllerItem& rItem ) } -const SfxPoolItem* SfxBindings::ExecuteSynchron( sal_uInt16 nId, const SfxPoolItem** ppItems ) +SfxPoolItemHolder SfxBindings::ExecuteSynchron( sal_uInt16 nId, const SfxPoolItem** ppItems ) { if( !nId || !pDispatcher ) - return nullptr; + return SfxPoolItemHolder(); return Execute_Impl( nId, ppItems, 0, SfxCallMode::SYNCHRON, nullptr ); } @@ -869,11 +868,11 @@ bool SfxBindings::Execute( sal_uInt16 nId, const SfxPoolItem** ppItems, SfxCallM if( !nId || !pDispatcher ) return false; - const SfxPoolItem* pRet = Execute_Impl( nId, ppItems, 0, nCallMode, nullptr ); - return ( pRet != nullptr ); + const SfxPoolItemHolder aRet(Execute_Impl(nId, ppItems, 0, nCallMode, nullptr)); + return (nullptr != aRet.getItem()); } -const SfxPoolItem* SfxBindings::Execute_Impl( sal_uInt16 nId, const SfxPoolItem** ppItems, sal_uInt16 nModi, SfxCallMode nCallMode, +SfxPoolItemHolder SfxBindings::Execute_Impl( sal_uInt16 nId, const SfxPoolItem** ppItems, sal_uInt16 nModi, SfxCallMode nCallMode, const SfxPoolItem **ppInternalArgs, bool bGlobalOnly ) { SfxStateCache *pCache = GetStateCache( nId ); @@ -915,15 +914,13 @@ const SfxPoolItem* SfxBindings::Execute_Impl( sal_uInt16 nId, const SfxPoolItem* // cache binds to an external dispatch provider sal_Int16 eRet = pCache->Dispatch( aReq.GetArgs(), nCallMode == SfxCallMode::SYNCHRON ); - std::unique_ptr<SfxPoolItem> pPool; + SfxPoolItem* pPoolItem(nullptr); if ( eRet == css::frame::DispatchResultState::DONTKNOW ) - pPool.reset( new SfxVoidItem( nId ) ); + pPoolItem = new SfxVoidItem( nId ); else - pPool.reset( new SfxBoolItem( nId, eRet == css::frame::DispatchResultState::SUCCESS) ); + pPoolItem = new SfxBoolItem( nId, eRet == css::frame::DispatchResultState::SUCCESS); - auto pTemp = pPool.get(); - DeleteItemOnIdle( std::move(pPool) ); - return pTemp; + return SfxPoolItemHolder(rPool, pPoolItem, true); } // slot is handled internally by SfxDispatcher @@ -936,7 +933,7 @@ const SfxPoolItem* SfxBindings::Execute_Impl( sal_uInt16 nId, const SfxPoolItem* const SfxSlotServer* pServer = pCache->GetSlotServer( rDispatcher, pImpl->xProv ); if ( !pServer ) { - return nullptr; + return SfxPoolItemHolder(); } else { @@ -946,7 +943,7 @@ const SfxPoolItem* SfxBindings::Execute_Impl( sal_uInt16 nId, const SfxPoolItem* if ( bGlobalOnly ) if ( dynamic_cast< const SfxModule *>( pShell ) == nullptr && dynamic_cast< const SfxApplication *>( pShell ) == nullptr && dynamic_cast< const SfxViewFrame *>( pShell ) == nullptr ) - return nullptr; + return SfxPoolItemHolder(); SfxItemPool &rPool = pShell->GetPool(); SfxRequest aReq( nId, nCallMode, rPool ); @@ -964,15 +961,12 @@ const SfxPoolItem* SfxBindings::Execute_Impl( sal_uInt16 nId, const SfxPoolItem* Execute_Impl( aReq, pSlot, pShell ); - const SfxPoolItem* pRet = aReq.GetReturnValue(); - if ( !pRet ) - { - std::unique_ptr<SfxPoolItem> pVoid(new SfxVoidItem( nId )); - pRet = pVoid.get(); - DeleteItemOnIdle( std::move(pVoid) ); - } + const SfxPoolItemHolder& rRetval(aReq.GetReturnValue()); - return pRet; + if (nullptr == rRetval.getItem()) + return SfxPoolItemHolder(rPool, new SfxVoidItem( nId ), true); + + return rRetval; } void SfxBindings::Execute_Impl( SfxRequest& aReq, const SfxSlot* pSlot, SfxShell* pShell ) @@ -1596,17 +1590,18 @@ SfxItemState SfxBindings::QueryState( sal_uInt16 nSlot, std::unique_ptr<SfxPoolI // Then test at the dispatcher to check if the returned items from // there are always DELETE_ON_IDLE, a copy of it has to be made in // order to allow for transition of ownership. - const SfxPoolItem *pItem = nullptr; - SfxItemState eState = pDispatcher->QueryState( nSlot, pItem ); - if ( eState == SfxItemState::SET ) + SfxPoolItemHolder aResult; + const SfxItemState eState(pDispatcher->QueryState(nSlot, aResult)); + + if (SfxItemState::SET == eState) { - DBG_ASSERT( pItem, "SfxItemState::SET but no item!" ); - if ( pItem ) - rpState.reset(pItem->Clone()); + DBG_ASSERT( aResult.getItem(), "SfxItemState::SET but no item!" ); + if ( nullptr != aResult.getItem() ) + rpState.reset(aResult.getItem()->Clone()); } - else if ( eState == SfxItemState::DEFAULT && pItem ) + else if (SfxItemState::DEFAULT == eState && nullptr != aResult.getItem()) { - rpState.reset(pItem->Clone()); + rpState.reset(aResult.getItem()->Clone()); } return eState; diff --git a/sfx2/source/control/dispatch.cxx b/sfx2/source/control/dispatch.cxx index 6a492bffda7e..fe7271677fbf 100644 --- a/sfx2/source/control/dispatch.cxx +++ b/sfx2/source/control/dispatch.cxx @@ -786,11 +786,11 @@ const SfxSlot* SfxDispatcher::GetSlot( const OUString& rCommand ) return nullptr; } -const SfxPoolItem* SfxDispatcher::Execute(sal_uInt16 nSlot, SfxCallMode nCall, +SfxPoolItemHolder SfxDispatcher::Execute(sal_uInt16 nSlot, SfxCallMode nCall, SfxItemSet const * pArgs, SfxItemSet const * pInternalArgs, sal_uInt16 nModi) { if ( IsLocked() ) - return nullptr; + return SfxPoolItemHolder(); SfxShell *pShell = nullptr; const SfxSlot *pSlot = nullptr; @@ -813,7 +813,8 @@ const SfxPoolItem* SfxDispatcher::Execute(sal_uInt16 nSlot, SfxCallMode nCall, Execute_( *pShell, *pSlot, aReq, nCall ); return aReq.GetReturnValue(); } - return nullptr; + + return SfxPoolItemHolder(); } /** Method to execute a <SfxSlot>s over the Slot-Id. @@ -830,11 +831,11 @@ const SfxPoolItem* SfxDispatcher::Execute(sal_uInt16 nSlot, SfxCallMode nCall, Or a NULL-Pointer, when the function was not executed (for example canceled by the user). */ -const SfxPoolItem* SfxDispatcher::Execute(sal_uInt16 nSlot, SfxCallMode eCall, +SfxPoolItemHolder SfxDispatcher::Execute(sal_uInt16 nSlot, SfxCallMode eCall, const SfxPoolItem **pArgs, sal_uInt16 nModi, const SfxPoolItem **pInternalArgs) { if ( IsLocked() ) - return nullptr; + return SfxPoolItemHolder(); SfxShell *pShell = nullptr; const SfxSlot *pSlot = nullptr; @@ -859,10 +860,10 @@ const SfxPoolItem* SfxDispatcher::Execute(sal_uInt16 nSlot, SfxCallMode eCall, pReq->SetInternalArgs_Impl( aSet ); } Execute_( *pShell, *pSlot, *pReq, eCall ); - const SfxPoolItem* pRet = pReq->GetReturnValue(); - return pRet; + return pReq->GetReturnValue(); } - return nullptr; + + return SfxPoolItemHolder(); } /** Method to execute a <SfxSlot>s over the Slot-Id. @@ -878,11 +879,11 @@ const SfxPoolItem* SfxDispatcher::Execute(sal_uInt16 nSlot, SfxCallMode eCall, Or a NULL-Pointer, when the function was not executed (for example canceled by the user). */ -const SfxPoolItem* SfxDispatcher::Execute(sal_uInt16 nSlot, SfxCallMode eCall, +SfxPoolItemHolder SfxDispatcher::Execute(sal_uInt16 nSlot, SfxCallMode eCall, const SfxItemSet &rArgs) { if ( IsLocked() ) - return nullptr; + return SfxPoolItemHolder(); SfxShell *pShell = nullptr; const SfxSlot *pSlot = nullptr; @@ -899,7 +900,8 @@ const SfxPoolItem* SfxDispatcher::Execute(sal_uInt16 nSlot, SfxCallMode eCall, Execute_( *pShell, *pSlot, aReq, eCall ); return aReq.GetReturnValue(); } - return nullptr; + + return SfxPoolItemHolder(); } /** Method to execute a <SfxSlot>s over the Slot-Id. @@ -928,12 +930,12 @@ const SfxPoolItem* SfxDispatcher::Execute(sal_uInt16 nSlot, SfxCallMode eCall, &SfxBoolItem( SID_DOC_READONLY, sal_False ), }); */ -const SfxPoolItem* SfxDispatcher::ExecuteList(sal_uInt16 nSlot, SfxCallMode eCall, +SfxPoolItemHolder SfxDispatcher::ExecuteList(sal_uInt16 nSlot, SfxCallMode eCall, std::initializer_list<SfxPoolItem const*> args, std::initializer_list<SfxPoolItem const*> internalargs) { if ( IsLocked() ) - return nullptr; + return SfxPoolItemHolder(); SfxShell *pShell = nullptr; const SfxSlot *pSlot = nullptr; @@ -963,7 +965,8 @@ const SfxPoolItem* SfxDispatcher::ExecuteList(sal_uInt16 nSlot, SfxCallMode eCal Execute_( *pShell, *pSlot, aReq, eCall ); return aReq.GetReturnValue(); } - return nullptr; + + return SfxPoolItemHolder(); } /** Helper method to receive the asynchronously executed <SfxRequest>s. @@ -1122,8 +1125,8 @@ void SfxDispatcher::Update_Impl( bool bForce ) if ( SfxViewShell::Current() && SfxViewShell::Current()->GetDispatcher() ) { - const SfxPoolItem *pItem; - SfxViewShell::Current()->GetDispatcher()->QueryState(SID_NOTEBOOKBAR, pItem); + SfxPoolItemHolder aItem; + SfxViewShell::Current()->GetDispatcher()->QueryState(SID_NOTEBOOKBAR, aItem); } } @@ -1967,14 +1970,14 @@ void SfxDispatcher::SetQuietMode_Impl( bool bOn ) pBindings->InvalidateAll(true); } -SfxItemState SfxDispatcher::QueryState( sal_uInt16 nSlot, const SfxPoolItem* &rpState ) +SfxItemState SfxDispatcher::QueryState( sal_uInt16 nSlot, SfxPoolItemHolder& rState ) { SfxShell *pShell = nullptr; const SfxSlot *pSlot = nullptr; if ( GetShellAndSlot_Impl( nSlot, &pShell, &pSlot, false, true ) ) { - rpState = pShell->GetSlotState(nSlot); - if ( !rpState ) + rState = pShell->GetSlotState(nSlot); + if ( nullptr == rState.getItem() ) return SfxItemState::DISABLED; else return SfxItemState::DEFAULT; @@ -1989,20 +1992,20 @@ SfxItemState SfxDispatcher::QueryState( sal_uInt16 nSID, css::uno::Any& rAny ) const SfxSlot *pSlot = nullptr; if ( GetShellAndSlot_Impl( nSID, &pShell, &pSlot, false, true ) ) { - const SfxPoolItem* pItem = pShell->GetSlotState( nSID ); - if ( !pItem ) + SfxPoolItemHolder aItem(pShell->GetSlotState(nSID)); + if (nullptr == aItem.getItem()) return SfxItemState::DISABLED; else { css::uno::Any aState; - if ( !pItem->isVoidItem() ) + if ( !aItem.getItem()->isVoidItem() ) { sal_uInt16 nSubId( 0 ); SfxItemPool& rPool = pShell->GetPool(); sal_uInt16 nWhich = rPool.GetWhich( nSID ); if ( rPool.GetMetric( nWhich ) == MapUnit::MapTwip ) nSubId |= CONVERT_TWIPS; - pItem->QueryValue( aState, static_cast<sal_uInt8>(nSubId) ); + aItem.getItem()->QueryValue( aState, static_cast<sal_uInt8>(nSubId) ); } rAny = aState; diff --git a/sfx2/source/control/itemdel.cxx b/sfx2/source/control/itemdel.cxx deleted file mode 100644 index ce6f4e1b9303..000000000000 --- a/sfx2/source/control/itemdel.cxx +++ /dev/null @@ -1,56 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -#include <sal/config.h> - -#include <itemdel.hxx> -#include <svl/poolitem.hxx> -#include <vcl/idle.hxx> -#include <vcl/svapp.hxx> - -#include <tools/debug.hxx> - -class SfxItemDisruptor_Impl -{ -public: - static void DeleteItemOnIdle(std::unique_ptr<SfxPoolItem> pItem) - { - pItem->setDeleteOnIdle(); - Application::PostUserEvent(LINK(nullptr, SfxItemDisruptor_Impl, Delete), pItem.release()); - // coverity[leaked_storage] - pDisruptor takes care of its own destruction at idle time - } - - DECL_STATIC_LINK(SfxItemDisruptor_Impl, Delete, void*, void); -}; - -IMPL_STATIC_LINK(SfxItemDisruptor_Impl, Delete, void*, p, void) -{ - SfxPoolItem* pItem = static_cast<SfxPoolItem*>(p); - // reset RefCount (was set to SFX_ITEMS_SPECIAL before!) - pItem->SetRefCount(0); - delete pItem; -} - -void DeleteItemOnIdle(std::unique_ptr<SfxPoolItem> pItem) -{ - DBG_ASSERT(0 == pItem->GetRefCount(), "deleting item in use"); - SfxItemDisruptor_Impl::DeleteItemOnIdle(std::move(pItem)); -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sfx2/source/control/request.cxx b/sfx2/source/control/request.cxx index 5da3517df107..89f446d388d6 100644 --- a/sfx2/source/control/request.cxx +++ b/sfx2/source/control/request.cxx @@ -32,7 +32,6 @@ #include <tools/debug.hxx> #include <svl/itempool.hxx> -#include <itemdel.hxx> #include <comphelper/processfactory.hxx> @@ -59,7 +58,7 @@ struct SfxRequest_Impl: public SfxListener SfxRequest* pAnti; // Owner because of dying pool OUString aTarget; // if possible from target object set by App SfxItemPool* pPool; // ItemSet build with this pool - std::unique_ptr<SfxPoolItem> pRetVal; // Return value belongs to itself + SfxPoolItemHolder aRetVal; // Return value belongs to itself SfxShell* pShell; // run from this shell const SfxSlot* pSlot; // executed Slot sal_uInt16 nModifier; // which Modifier was pressed? @@ -124,8 +123,6 @@ SfxRequest::~SfxRequest() // Clear object pArgs.reset(); - if ( pImpl->pRetVal ) - DeleteItemOnIdle(std::move(pImpl->pRetVal)); } @@ -420,14 +417,16 @@ void SfxRequest::RemoveItem( sal_uInt16 nID ) void SfxRequest::SetReturnValue(const SfxPoolItem &rItem) { - DBG_ASSERT(!pImpl->pRetVal, "Set Return value multiple times?"); - pImpl->pRetVal.reset(rItem.Clone()); + DBG_ASSERT(nullptr == pImpl->aRetVal.getItem(), "Set Return value multiple times?"); + DBG_ASSERT(nullptr != pImpl->pPool, "Missing SfxItemPool (!)"); + if (nullptr != pImpl->pPool) + pImpl->aRetVal = SfxPoolItemHolder(*pImpl->pPool, &rItem); } -const SfxPoolItem* SfxRequest::GetReturnValue() const +const SfxPoolItemHolder& SfxRequest::GetReturnValue() const { - return pImpl->pRetVal.get(); + return pImpl->aRetVal; } diff --git a/sfx2/source/control/shell.cxx b/sfx2/source/control/shell.cxx index f4b2960da34b..4b1457af50df 100644 --- a/sfx2/source/control/shell.cxx +++ b/sfx2/source/control/shell.cxx @@ -27,7 +27,6 @@ #include <svl/setitem.hxx> #include <svl/voiditem.hxx> #include <svl/undo.hxx> -#include <itemdel.hxx> #include <svtools/asynclink.hxx> #include <unotools/configmgr.hxx> #include <comphelper/lok.hxx> @@ -435,7 +434,7 @@ void SfxShell::ExecuteSlot( SfxRequest& rReq, bool bAsync ) } } -const SfxPoolItem* SfxShell::ExecuteSlot +const SfxPoolItemHolder& SfxShell::ExecuteSlot ( SfxRequest &rReq, // the relayed <SfxRequest> const SfxInterface* pIF // default = 0 means get virtually @@ -459,7 +458,7 @@ const SfxPoolItem* SfxShell::ExecuteSlot return rReq.GetReturnValue(); } -const SfxPoolItem* SfxShell::GetSlotState +SfxPoolItemHolder SfxShell::GetSlotState ( sal_uInt16 nSlotId, // Slot-Id to the Slots in question const SfxInterface* pIF, // default = 0 means get virtually @@ -505,29 +504,27 @@ const SfxPoolItem* SfxShell::GetSlotState } // Evaluate Item and item status and possibly maintain them in pStateSet - std::unique_ptr<SfxPoolItem> pRetItem; if ( !bItemStateSet || eState <= SfxItemState::DISABLED ) { if ( pStateSet ) pStateSet->DisableItem(nSlotId); - return nullptr; + return SfxPoolItemHolder(); } - else if ( bItemStateSet && eState == SfxItemState::DONTCARE ) + + if ( bItemStateSet && eState == SfxItemState::DONTCARE ) { if ( pStateSet ) pStateSet->ClearItem(nSlotId); - pRetItem.reset( new SfxVoidItem(0) ); + return SfxPoolItemHolder(rPool, new SfxVoidItem(0), true); } - else // bItemStateSet && eState >= SfxItemState::DEFAULT + + // bItemStateSet && eState >= SfxItemState::DEFAULT + if ( pStateSet && pStateSet->Put( *pItem ) ) { - if ( pStateSet && pStateSet->Put( *pItem ) ) - return &pStateSet->Get( pItem->Which() ); - pRetItem.reset(pItem->Clone()); + return SfxPoolItemHolder(rPool, &pStateSet->Get(pItem->Which())); } - auto pTemp = pRetItem.get(); - DeleteItemOnIdle(std::move(pRetItem)); - return pTemp; + return SfxPoolItemHolder(rPool, pItem); } static SFX_EXEC_STUB(SfxShell, VerbExec) diff --git a/sfx2/source/control/unoctitm.cxx b/sfx2/source/control/unoctitm.cxx index 1f3f37f5fc1b..c37544b2ecbd 100644 --- a/sfx2/source/control/unoctitm.cxx +++ b/sfx2/source/control/unoctitm.cxx @@ -626,7 +626,7 @@ void SfxDispatchController_Impl::dispatch( const css::util::URL& aURL, } bool bSuccess = false; - const SfxPoolItem* pItem = nullptr; + SfxPoolItemHolder aItem; MapUnit eMapUnit( MapUnit::Map100thMM ); // Extra scope so that aInternalSet is destroyed before @@ -665,12 +665,12 @@ void SfxDispatchController_Impl::dispatch( const css::util::URL& aURL, if (xSet->Count()) { // execute with arguments - call directly - pItem = pDispatcher->Execute(GetId(), nCall, &*xSet, &aInternalSet, nModifier); - if ( pItem != nullptr ) + aItem = pDispatcher->Execute(GetId(), nCall, &*xSet, &aInternalSet, nModifier); + if (nullptr != aItem.getItem()) { - if (const SfxBoolItem* pBoolItem = dynamic_cast<const SfxBoolItem*>(pItem)) + if (const SfxBoolItem* pBoolItem = dynamic_cast<const SfxBoolItem*>(aItem.getItem())) bSuccess = pBoolItem->GetValue(); - else if ( !pItem->isVoidItem() ) + else if ( !aItem.getItem()->isVoidItem() ) bSuccess = true; // all other types are true } // else bSuccess = false look to line 664 it is false @@ -686,8 +686,8 @@ void SfxDispatchController_Impl::dispatch( const css::util::URL& aURL, aReq.SetModifier( nModifier ); aReq.SetInternalArgs_Impl(aInternalSet); pDispatcher->GetBindings()->Execute_Impl( aReq, pSlot, pShell ); - pItem = aReq.GetReturnValue(); - bSuccess = aReq.IsDone() || pItem != nullptr; + aItem = aReq.GetReturnValue(); + bSuccess = aReq.IsDone() || nullptr != aItem.getItem(); } } else @@ -702,10 +702,10 @@ void SfxDispatchController_Impl::dispatch( const css::util::URL& aURL, TransformParameters( GetId(), lNewArgs, aSet ); if ( aSet.Count() ) - pItem = pDispatcher->Execute(GetId(), nCall, &aSet, &aInternalSet, nModifier); + aItem = pDispatcher->Execute(GetId(), nCall, &aSet, &aInternalSet, nModifier); else // SfxRequests take empty sets as argument sets, GetArgs() returning non-zero! - pItem = pDispatcher->Execute(GetId(), nCall, nullptr, &aInternalSet, nModifier); + aItem = pDispatcher->Execute(GetId(), nCall, nullptr, &aInternalSet, nModifier); // no bindings, no invalidate ( usually done in SfxDispatcher::Call_Impl()! ) if (SfxApplication* pApp = SfxApplication::Get()) @@ -713,13 +713,13 @@ void SfxDispatchController_Impl::dispatch( const css::util::URL& aURL, SfxDispatcher* pAppDispat = pApp->GetAppDispatcher_Impl(); if ( pAppDispat ) { - const SfxPoolItem* pState=nullptr; - SfxItemState eState = pDispatcher->QueryState( GetId(), pState ); - StateChangedAtToolBoxControl( GetId(), eState, pState ); + SfxPoolItemHolder aResult; + SfxItemState eState(pDispatcher->QueryState(GetId(), aResult)); + StateChangedAtToolBoxControl(GetId(), eState, aResult.getItem()); } } - bSuccess = (pItem != nullptr); + bSuccess = (nullptr != aItem.getItem()); } } @@ -733,12 +733,12 @@ void SfxDispatchController_Impl::dispatch( const css::util::URL& aURL, aEvent.State = css::frame::DispatchResultState::FAILURE; aEvent.Source = static_cast<css::frame::XDispatch*>(pDispatch); - if ( bSuccess && pItem && !pItem->isVoidItem() ) + if ( bSuccess && nullptr != aItem.getItem() && !aItem.getItem()->isVoidItem() ) { sal_uInt16 nSubId( 0 ); if ( eMapUnit == MapUnit::MapTwip ) nSubId |= CONVERT_TWIPS; - pItem->QueryValue( aEvent.Result, static_cast<sal_uInt8>(nSubId) ); + aItem.getItem()->QueryValue( aEvent.Result, static_cast<sal_uInt8>(nSubId) ); } rListener->dispatchFinished( aEvent ); diff --git a/sfx2/source/dialog/StyleList.cxx b/sfx2/source/dialog/StyleList.cxx index 7e7cd347e429..e7bdd9e3b4a3 100644 --- a/sfx2/source/dialog/StyleList.cxx +++ b/sfx2/source/dialog/StyleList.cxx @@ -33,6 +33,7 @@ #include <vcl/window.hxx> #include <svl/intitem.hxx> #include <svl/style.hxx> +#include <svl/itemset.hxx> #include <comphelper/processfactory.hxx> #include <officecfg/Office/Common.hxx> diff --git a/sfx2/source/dialog/dockwin.cxx b/sfx2/source/dialog/dockwin.cxx index dcf50ee5d304..f71501642fe8 100644 --- a/sfx2/source/dialog/dockwin.cxx +++ b/sfx2/source/dialog/dockwin.cxx @@ -32,6 +32,7 @@ #include <tools/debug.hxx> #include <comphelper/processfactory.hxx> #include <comphelper/propertysequence.hxx> +#include <svl/itemset.hxx> #include <sfx2/dockwin.hxx> #include <sfx2/bindings.hxx> diff --git a/sfx2/source/dialog/mgetempl.cxx b/sfx2/source/dialog/mgetempl.cxx index 624caf17f8fd..a9b62452591e 100644 --- a/sfx2/source/dialog/mgetempl.cxx +++ b/sfx2/source/dialog/mgetempl.cxx @@ -369,11 +369,11 @@ bool SfxManageStyleSheetPage::Execute_Impl( pItems[ nCount++ ] = nullptr; - const SfxPoolItem* pItem = rDispatcher.Execute( + const SfxPoolItemHolder aResult(rDispatcher.Execute( nId, SfxCallMode::SYNCHRON | SfxCallMode::RECORD, - pItems ); + pItems )); - return pItem != nullptr; + return nullptr != aResult.getItem(); } diff --git a/sfx2/source/dialog/recfloat.cxx b/sfx2/source/dialog/recfloat.cxx index 1b674f602b71..4240afeac669 100644 --- a/sfx2/source/dialog/recfloat.cxx +++ b/sfx2/source/dialog/recfloat.cxx @@ -33,6 +33,7 @@ #include <sfx2/sfxsids.hrc> #include <sfx2/viewfrm.hxx> #include <sfx2/viewsh.hxx> +#include <svl/itemset.hxx> SFX_IMPL_MODELESSDIALOGCONTOLLER(SfxRecordingFloatWrapper_Impl, SID_RECORDING_FLOATWINDOW); diff --git a/sfx2/source/dialog/securitypage.cxx b/sfx2/source/dialog/securitypage.cxx index 6dfb94d3da2f..9e7d16a8ad48 100644 --- a/sfx2/source/dialog/securitypage.cxx +++ b/sfx2/source/dialog/securitypage.cxx @@ -51,12 +51,11 @@ namespace SfxViewShell* pViewSh = SfxViewShell::Current(); if (pViewSh) { - const SfxBoolItem* pItem; - SfxDispatcher* pDisp = pViewSh->GetDispatcher(); - SfxItemState nState = pDisp->QueryState( _nSlot, pItem ); + SfxPoolItemHolder aResult; + const SfxItemState nState(pViewSh->GetDispatcher()->QueryState(_nSlot, aResult)); bRet = SfxItemState::DEFAULT <= nState; if (bRet) - _rValue = pItem->GetValue(); + _rValue = static_cast<const SfxBoolItem*>(aResult.getItem())->GetValue(); } return bRet; } @@ -266,11 +265,12 @@ void SfxSecurityPage_Impl::Reset_Impl() SfxViewShell* pViewSh = SfxViewShell::Current(); if (pViewSh) { - const SfxUInt16Item* pItem; - SfxDispatcher* pDisp = pViewSh->GetDispatcher(); - if (SfxItemState::DEFAULT <= pDisp->QueryState( SID_HTML_MODE, pItem )) + SfxPoolItemHolder aResult; + + if (SfxItemState::DEFAULT <= pViewSh->GetDispatcher()->QueryState(SID_HTML_MODE, aResult)) { - sal_uInt16 nMode = pItem->GetValue(); + const SfxUInt16Item* pItem(static_cast<const SfxUInt16Item*>(aResult.getItem())); + const sal_uInt16 nMode(pItem->GetValue()); bIsHTMLDoc = ( ( nMode & HTMLMODE_ON ) != 0 ); } } diff --git a/sfx2/source/dialog/templdlg.cxx b/sfx2/source/dialog/templdlg.cxx index db21ee720c2d..1a55cb24c7fa 100644 --- a/sfx2/source/dialog/templdlg.cxx +++ b/sfx2/source/dialog/templdlg.cxx @@ -43,6 +43,7 @@ #include <sfx2/objsh.hxx> #include <sfx2/tplpitem.hxx> #include <sfx2/sfxresid.hxx> +#include <svl/itemset.hxx> #include <sfx2/sfxsids.hrc> #include <sfx2/strings.hrc> @@ -512,19 +513,19 @@ bool SfxCommonTemplateDialog_Impl::Execute_Impl( DeletionWatcher aDeleted(*this); sal_uInt16 nModi = pModifier ? *pModifier : 0; - const SfxPoolItem* pItem = rDispatcher.Execute( + const SfxPoolItemHolder aResult(rDispatcher.Execute( nId, SfxCallMode::SYNCHRON | SfxCallMode::RECORD, - pItems, nModi ); + pItems, nModi)); // Dialog can be destroyed while in Execute() because started // subdialogs are not modal to it (#i97888#). - if ( !pItem || aDeleted ) + if ( nullptr == aResult.getItem() || aDeleted ) return false; if ((nId == SID_STYLE_NEW || SID_STYLE_EDIT == nId) && rStyleList.EnableExecute()) { - const SfxUInt16Item *pFilterItem = dynamic_cast< const SfxUInt16Item* >(pItem); + const SfxUInt16Item* pFilterItem(dynamic_cast<const SfxUInt16Item*>(aResult.getItem())); assert(pFilterItem); SfxStyleSearchBits nFilterFlags = static_cast<SfxStyleSearchBits>(pFilterItem->GetValue()) & ~SfxStyleSearchBits::UserDefined; if(nFilterFlags == SfxStyleSearchBits::Auto) // User Template? diff --git a/sfx2/source/dialog/versdlg.cxx b/sfx2/source/dialog/versdlg.cxx index b0904b38ab34..defa731b4fdd 100644 --- a/sfx2/source/dialog/versdlg.cxx +++ b/sfx2/source/dialog/versdlg.cxx @@ -297,9 +297,9 @@ IMPL_LINK_NOARG(SfxVersionDialog, SelectHdl_Impl, weld::TreeView&, void) m_xOpenButton->set_sensitive(bEnable); m_xViewButton->set_sensitive(bEnable); - const SfxPoolItem *pDummy=nullptr; - m_pViewFrame->GetDispatcher()->QueryState( SID_DOCUMENT_MERGE, pDummy ); - SfxItemState eState = m_pViewFrame->GetDispatcher()->QueryState( SID_DOCUMENT_COMPARE, pDummy ); + SfxPoolItemHolder aResult; + m_pViewFrame->GetDispatcher()->QueryState(SID_DOCUMENT_MERGE, aResult); + SfxItemState eState = m_pViewFrame->GetDispatcher()->QueryState(SID_DOCUMENT_COMPARE, aResult); m_xCompareButton->set_sensitive(bEnable && eState >= SfxItemState::DEFAULT); } diff --git a/sfx2/source/doc/objmisc.cxx b/sfx2/source/doc/objmisc.cxx index 5b7aa98df38e..234ae799caeb 100644 --- a/sfx2/source/doc/objmisc.cxx +++ b/sfx2/source/doc/objmisc.cxx @@ -484,8 +484,8 @@ bool SfxObjectShell::SwitchToShared( bool bShared, bool bSave ) if ( pViewFrame ) { // TODO/LATER: currently the application guards against the reentrance problem - const SfxPoolItem* pItem = pViewFrame->GetBindings().ExecuteSynchron( HasName() ? SID_SAVEDOC : SID_SAVEASDOC ); - const SfxBoolItem* pResult = dynamic_cast<const SfxBoolItem*>( pItem ); + const SfxPoolItemHolder aItem(pViewFrame->GetBindings().ExecuteSynchron( HasName() ? SID_SAVEDOC : SID_SAVEASDOC )); + const SfxBoolItem* pResult(dynamic_cast<const SfxBoolItem*>(aItem.getItem())); bResult = ( pResult && pResult->GetValue() ); if ( bResult ) aOrigURL = GetMedium()->GetURLObject().GetMainURL( INetURLObject::DecodeMechanism::NONE ); diff --git a/sfx2/source/doc/objserv.cxx b/sfx2/source/doc/objserv.cxx index 5372807fba67..fedbfb205d92 100644 --- a/sfx2/source/doc/objserv.cxx +++ b/sfx2/source/doc/objserv.cxx @@ -666,7 +666,8 @@ void SfxObjectShell::ExecFile_Impl(SfxRequest &rReq) SfxDocumentInfoItem aDocInfoItem( aURL, getDocProperties(), aCmisProperties, IsUseUserData(), IsUseThumbnailSave() ); - if ( !GetSlotState( SID_DOCTEMPLATE ) ) + const SfxPoolItemHolder aSlotState(GetSlotState(SID_DOCTEMPLATE)); + if (nullptr == aSlotState.getItem()) // templates not supported aDocInfoItem.SetTemplate(false); @@ -1067,12 +1068,14 @@ void SfxObjectShell::ExecFile_Impl(SfxRequest &rReq) SfxViewShell::Current()->SetStoringHelper(xHelper); QueryHiddenInformation(bIsPDFExport ? HiddenWarningFact::WhenCreatingPDF : HiddenWarningFact::WhenSaving); + SfxPoolItemHolder aItem; + if (SID_DIRECTEXPORTDOCASPDF == nId) + aItem = GetSlotState(SID_MAIL_PREPAREEXPORT); + const SfxBoolItem* pItem(dynamic_cast<const SfxBoolItem*>(aItem.getItem())); - const SfxBoolItem *pItem = nId != SID_DIRECTEXPORTDOCASPDF ? nullptr : - dynamic_cast<const SfxBoolItem*>( GetSlotState(SID_MAIL_PREPAREEXPORT) ); // Fetch value from the pool item early, because GUIStoreModel() can free the pool // item as part of spinning the main loop if a dialog is opened. - bool bMailPrepareExport = pItem && pItem->GetValue(); + const bool bMailPrepareExport(nullptr != pItem && pItem->GetValue()); if (bMailPrepareExport) { SfxRequest aRequest(SID_MAIL_PREPAREEXPORT, SfxCallMode::SYNCHRON, GetPool()); diff --git a/sfx2/source/doc/objxtor.cxx b/sfx2/source/doc/objxtor.cxx index 2fd5df242fcc..11b38ced10a0 100644 --- a/sfx2/source/doc/objxtor.cxx +++ b/sfx2/source/doc/objxtor.cxx @@ -568,30 +568,30 @@ bool SfxObjectShell::PrepareClose if ( RET_YES == nRet ) { // Save by each Dispatcher - const SfxPoolItem *pPoolItem; + SfxPoolItemHolder aPoolItem; if (IsReadOnly()) { SfxBoolItem aWarnItem( SID_FAIL_ON_WARNING, bUI ); const SfxPoolItem* ppArgs[] = { &aWarnItem, nullptr }; - pPoolItem = pFrame->GetBindings().ExecuteSynchron(SID_SAVEASDOC, ppArgs); + aPoolItem = pFrame->GetBindings().ExecuteSynchron(SID_SAVEASDOC, ppArgs); } else if (IsSaveVersionOnClose()) { SfxStringItem aItem( SID_DOCINFO_COMMENTS, SfxResId(STR_AUTOMATICVERSION) ); SfxBoolItem aWarnItem( SID_FAIL_ON_WARNING, bUI ); const SfxPoolItem* ppArgs[] = { &aItem, &aWarnItem, nullptr }; - pPoolItem = pFrame->GetBindings().ExecuteSynchron( SID_SAVEDOC, ppArgs ); + aPoolItem = pFrame->GetBindings().ExecuteSynchron( SID_SAVEDOC, ppArgs ); } else { SfxBoolItem aWarnItem( SID_FAIL_ON_WARNING, bUI ); const SfxPoolItem* ppArgs[] = { &aWarnItem, nullptr }; - pPoolItem = pFrame->GetBindings().ExecuteSynchron( SID_SAVEDOC, ppArgs ); + aPoolItem = pFrame->GetBindings().ExecuteSynchron( SID_SAVEDOC, ppArgs ); } - if ( !pPoolItem || pPoolItem->isVoidItem() ) + if ( nullptr == aPoolItem.getItem() || aPoolItem.getItem()->isVoidItem() ) return false; - if ( auto pBoolItem = dynamic_cast< const SfxBoolItem *>( pPoolItem ) ) + if ( auto pBoolItem = dynamic_cast< const SfxBoolItem *>( aPoolItem.getItem() ) ) if ( !pBoolItem->GetValue() ) return false; } diff --git a/sfx2/source/inc/itemdel.hxx b/sfx2/source/inc/itemdel.hxx deleted file mode 100644 index b8ea325010e4..000000000000 --- a/sfx2/source/inc/itemdel.hxx +++ /dev/null @@ -1,30 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ -#ifndef INCLUDED_SFX2_ITEMDEL_HXX -#define INCLUDED_SFX2_ITEMDEL_HXX - -#include <memory> - -class SfxPoolItem; - -void DeleteItemOnIdle(std::unique_ptr<SfxPoolItem> pItem); - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sfx2/source/view/frmload.cxx b/sfx2/source/view/frmload.cxx index 0fcf0b90baf2..7f58a397ccd3 100644 --- a/sfx2/source/view/frmload.cxx +++ b/sfx2/source/view/frmload.cxx @@ -301,9 +301,9 @@ OUString SfxFrameLoader_Impl::impl_askForFilter_nothrow( const Reference< XInter return sFilterName; } -bool lcl_getDispatchResult( const SfxPoolItem* _pResult ) +bool lcl_getDispatchResult(const SfxPoolItemHolder& rResult) { - if ( !_pResult ) + if (nullptr == rResult.getItem()) return false; // default must be set to true, because some return values @@ -312,7 +312,7 @@ bool lcl_getDispatchResult( const SfxPoolItem* _pResult ) // On the other side some special slots return a boolean state, // which can be set to FALSE. - const SfxBoolItem *pItem = dynamic_cast<const SfxBoolItem*>( _pResult ); + const SfxBoolItem* pItem(dynamic_cast<const SfxBoolItem*>(rResult.getItem())); if ( pItem ) bSuccess = pItem->GetValue(); @@ -326,7 +326,7 @@ bool SfxFrameLoader_Impl::impl_createNewDocWithSlotParam( const sal_uInt16 _nSlo aRequest.AppendItem( SfxUnoFrameItem( SID_FILLFRAME, i_rxFrame ) ); if ( i_bHidden ) aRequest.AppendItem( SfxBoolItem( SID_HIDDEN, true ) ); - return lcl_getDispatchResult( SfxGetpApp()->ExecuteSlot( aRequest ) ); + return lcl_getDispatchResult(SfxGetpApp()->ExecuteSlot(aRequest)); } diff --git a/sfx2/source/view/viewfrm.cxx b/sfx2/source/view/viewfrm.cxx index 57fbb91d5d66..fe0dc0adc7fc 100644 --- a/sfx2/source/view/viewfrm.cxx +++ b/sfx2/source/view/viewfrm.cxx @@ -1011,9 +1011,9 @@ void SfxViewFrame::ExecHistory_Impl( SfxRequest &rReq ) else if ( GetViewShell() ) { // The SW has its own undo in the View - const SfxPoolItem *pRet = GetViewShell()->ExecuteSlot( rReq ); - if ( pRet ) - bOK = static_cast<const SfxBoolItem*>(pRet)->GetValue(); + const SfxPoolItemHolder& rResult(GetViewShell()->ExecuteSlot(rReq)); + if (nullptr != rResult.getItem()) + bOK = static_cast<const SfxBoolItem*>(rResult.getItem())->GetValue(); } rReq.SetReturnValue( SfxBoolItem( rReq.GetSlot(), bOK ) ); @@ -2968,10 +2968,10 @@ void SfxViewFrame::AddDispatchMacroToBasic_Impl( const OUString& sMacro ) aReq.SetInternalArgs_Impl(aSet); aReq.AppendItem( SfxBoolItem(SID_RECORDMACRO,true) ); - const SfxPoolItem* pRet = SfxGetpApp()->ExecuteSlot( aReq ); + const SfxPoolItemHolder& rResult(SfxGetpApp()->ExecuteSlot(aReq)); OUString aScriptURL; - if ( pRet ) - aScriptURL = static_cast<const SfxStringItem*>(pRet)->GetValue(); + if (nullptr != rResult.getItem()) + aScriptURL = static_cast<const SfxStringItem*>(rResult.getItem())->GetValue(); if ( !aScriptURL.isEmpty() ) { // parse scriptURL @@ -3524,8 +3524,8 @@ void SfxViewFrame::ChildWindowState( SfxItemSet& rState ) } else if ( nSID == SID_HYPERLINK_DIALOG ) { - const SfxPoolItem* pDummy = nullptr; - SfxItemState eState = GetDispatcher()->QueryState( SID_HYPERLINK_SETLINK, pDummy ); + SfxPoolItemHolder aDummy; + SfxItemState eState = GetDispatcher()->QueryState(SID_HYPERLINK_SETLINK, aDummy); if ( SfxItemState::DISABLED == eState ) rState.DisableItem(nSID); else diff --git a/sfx2/source/view/viewfrm2.cxx b/sfx2/source/view/viewfrm2.cxx index e3cdb6b1a207..0af0c2c5bc1e 100644 --- a/sfx2/source/view/viewfrm2.cxx +++ b/sfx2/source/view/viewfrm2.cxx @@ -183,7 +183,7 @@ void SfxViewFrame::Exec_Impl(SfxRequest &rReq ) case SID_ACTIVATE: { MakeActive_Impl( true ); - rReq.SetReturnValue( SfxObjectItem( 0, this ) ); + rReq.SetReturnValue(SfxObjectItem(0, this)); break; } @@ -207,9 +207,10 @@ void SfxViewFrame::Exec_Impl(SfxRequest &rReq ) aReq.AppendItem( SfxFrameItem( SID_DOCFRAME, &GetFrame() ) ); aReq.AppendItem( SfxStringItem( SID_TARGETNAME, "_blank" ) ); SfxGetpApp()->ExecuteSlot( aReq ); - const SfxViewFrameItem* pItem = dynamic_cast<const SfxViewFrameItem*>( aReq.GetReturnValue() ); - if ( pItem ) - rReq.SetReturnValue( SfxFrameItem( 0, pItem->GetFrame() ) ); + + const SfxViewFrameItem* pItem(dynamic_cast<const SfxViewFrameItem*>(aReq.GetReturnValue().getItem())); + if (nullptr != pItem) + rReq.SetReturnValue(SfxFrameItem(0, pItem->GetFrame())); break; } @@ -252,7 +253,7 @@ void SfxViewFrame::Exec_Impl(SfxRequest &rReq ) } } - rReq.SetReturnValue( SfxBoolItem( rReq.GetSlot(), bClosed )); + rReq.SetReturnValue(SfxBoolItem(rReq.GetSlot(), bClosed)); } return; } diff --git a/starmath/source/SmElementsPanel.cxx b/starmath/source/SmElementsPanel.cxx index dec685787c3a..3abc02555578 100644 --- a/starmath/source/SmElementsPanel.cxx +++ b/starmath/source/SmElementsPanel.cxx @@ -23,6 +23,7 @@ #include <sfx2/dispatch.hxx> #include <sfx2/lokcomponenthelpers.hxx> #include <svl/stritem.hxx> +#include <svl/itemset.hxx> #include "SmElementsPanel.hxx" #include <starmath.hrc> diff --git a/starmath/source/edit.cxx b/starmath/source/edit.cxx index 77ab710fab69..bc1138a18d44 100644 --- a/starmath/source/edit.cxx +++ b/starmath/source/edit.cxx @@ -30,6 +30,7 @@ #include <sfx2/dispatch.hxx> #include <sfx2/sfxsids.hrc> #include <svl/stritem.hxx> +#include <svl/itemset.hxx> #include <sfx2/viewfrm.hxx> #include <osl/diagnose.h> #include <o3tl/string_view.hxx> diff --git a/svl/source/items/itemset.cxx b/svl/source/items/itemset.cxx index 102cf4d2bef8..b14cfa20383e 100644 --- a/svl/source/items/itemset.cxx +++ b/svl/source/items/itemset.cxx @@ -52,23 +52,49 @@ size_t getUsedSfxPoolItemHolderCount() { return nUsedSfxPoolItemHolderCount; } // fallback flag 'ITEM_CLASSIC_MODE' static bool g_bItemClassicMode(getenv("ITEM_CLASSIC_MODE")); -SfxPoolItemHolder::SfxPoolItemHolder(SfxItemPool& rPool, const SfxPoolItem* pItem) -: m_pPool(&rPool), - m_pItem(pItem) +// I thought about this constructor a while, but when there is no +// Item we need no cleanup at destruction (what we would need the +// Pool for), so it is OK and makes default construction easier +// when no Pool is needed. The other constructors guanantee that +// there *cannot* be a state with Item set and Pool not set. IF +// you change this class, ALWAYS ensure that this can not happen (!) +SfxPoolItemHolder::SfxPoolItemHolder() +: m_pPool(nullptr) +, m_pItem(nullptr) +#ifdef DBG_UTIL +, m_bDeleted(false) +#endif +{ +#ifdef DBG_UTIL + nAllocatedSfxPoolItemHolderCount++; + nUsedSfxPoolItemHolderCount++; +#endif +} + +SfxPoolItemHolder::SfxPoolItemHolder(SfxItemPool& rPool, const SfxPoolItem* pItem, bool bPassingOwnership) +: m_pPool(&rPool) +, m_pItem(pItem) +#ifdef DBG_UTIL +, m_bDeleted(false) +#endif { #ifdef DBG_UTIL nAllocatedSfxPoolItemHolderCount++; nUsedSfxPoolItemHolderCount++; #endif if (nullptr != m_pItem) - m_pItem = implCreateItemEntry(*m_pPool, m_pItem, m_pItem->Which(), false); + m_pItem = implCreateItemEntry(*m_pPool, m_pItem, m_pItem->Which(), bPassingOwnership); } SfxPoolItemHolder::SfxPoolItemHolder(const SfxPoolItemHolder& rHolder) -: m_pPool(rHolder.m_pPool), - m_pItem(rHolder.m_pItem) +: m_pPool(rHolder.m_pPool) +, m_pItem(rHolder.m_pItem) +#ifdef DBG_UTIL +, m_bDeleted(false) +#endif { #ifdef DBG_UTIL + assert(!rHolder.isDeleted() && "Destructed instance used (!)"); nAllocatedSfxPoolItemHolderCount++; nUsedSfxPoolItemHolderCount++; #endif @@ -79,14 +105,20 @@ SfxPoolItemHolder::SfxPoolItemHolder(const SfxPoolItemHolder& rHolder) SfxPoolItemHolder::~SfxPoolItemHolder() { #ifdef DBG_UTIL + assert(!isDeleted() && "Destructed instance used (!)"); nAllocatedSfxPoolItemHolderCount--; #endif if (nullptr != m_pItem) implCleanupItemEntry(*m_pPool, m_pItem); +#ifdef DBG_UTIL + m_bDeleted = true; +#endif } const SfxPoolItemHolder& SfxPoolItemHolder::operator=(const SfxPoolItemHolder& rHolder) { + assert(!isDeleted() && "Destructed instance used (!)"); + assert(!rHolder.isDeleted() && "Destructed instance used (!)"); if (this == &rHolder || *this == rHolder) return *this; @@ -104,6 +136,8 @@ const SfxPoolItemHolder& SfxPoolItemHolder::operator=(const SfxPoolItemHolder& r bool SfxPoolItemHolder::operator==(const SfxPoolItemHolder &rHolder) const { + assert(!isDeleted() && "Destructed instance used (!)"); + assert(!rHolder.isDeleted() && "Destructed instance used (!)"); return m_pPool == rHolder.m_pPool && areSfxPoolItemPtrsEqual(m_pItem, rHolder.m_pItem); } diff --git a/svl/source/items/poolitem.cxx b/svl/source/items/poolitem.cxx index bf86b4ab740e..ae7c97136c48 100644 --- a/svl/source/items/poolitem.cxx +++ b/svl/source/items/poolitem.cxx @@ -495,7 +495,6 @@ SfxPoolItem::SfxPoolItem(sal_uInt16 const nWhich) , m_nSerialNumber(nUsedSfxPoolItemCount) #endif , m_bIsVoidItem(false) - , m_bDeleteOnIdle(false) , m_bStaticDefault(false) , m_bPoolDefault(false) , m_bRegisteredAtPool(false) diff --git a/svx/source/dialog/_bmpmask.cxx b/svx/source/dialog/_bmpmask.cxx index 3e6a56a79f91..1385aea0c974 100644 --- a/svx/source/dialog/_bmpmask.cxx +++ b/svx/source/dialog/_bmpmask.cxx @@ -22,6 +22,7 @@ #include <vcl/virdev.hxx> #include <svtools/valueset.hxx> #include <svl/eitem.hxx> +#include <svl/itemset.hxx> #include <sfx2/dispatch.hxx> #include <svtools/colrdlg.hxx> diff --git a/svx/source/dialog/fontwork.cxx b/svx/source/dialog/fontwork.cxx index 15740a27037f..5f9b681b026b 100644 --- a/svx/source/dialog/fontwork.cxx +++ b/svx/source/dialog/fontwork.cxx @@ -37,6 +37,7 @@ #include <svx/svxids.hrc> #include <bitmaps.hlst> #include <svx/fontwork.hxx> +#include <svl/itemset.hxx> #define WIDTH_CHARS 10 diff --git a/svx/source/dialog/rubydialog.cxx b/svx/source/dialog/rubydialog.cxx index 0802c302b75a..83cfe3052c05 100644 --- a/svx/source/dialog/rubydialog.cxx +++ b/svx/source/dialog/rubydialog.cxx @@ -43,6 +43,7 @@ #include <vcl/event.hxx> #include <vcl/settings.hxx> #include <vcl/svapp.hxx> +#include <svl/itemset.hxx> using namespace css::uno; using namespace css::frame; diff --git a/svx/source/dialog/srchdlg.cxx b/svx/source/dialog/srchdlg.cxx index b1c87a6db7c8..f06822ceaf0b 100644 --- a/svx/source/dialog/srchdlg.cxx +++ b/svx/source/dialog/srchdlg.cxx @@ -424,14 +424,14 @@ void SvxSearchDialog::Construct_Impl() // Get attribute sets only once in constructor() const SfxPoolItem* ppArgs[] = { pSearchItem.get(), nullptr }; - const SvxSetItem* pSrchSetItem = - static_cast<const SvxSetItem*>( rBindings.GetDispatcher()->Execute( FID_SEARCH_SEARCHSET, SfxCallMode::SLOT, ppArgs ) ); + SfxPoolItemHolder aResult(rBindings.GetDispatcher()->Execute(FID_SEARCH_SEARCHSET, SfxCallMode::SLOT, ppArgs)); + const SvxSetItem* pSrchSetItem(static_cast<const SvxSetItem*>(aResult.getItem())); if ( pSrchSetItem ) InitAttrList_Impl( &pSrchSetItem->GetItemSet(), nullptr ); - const SvxSetItem* pReplSetItem = - static_cast<const SvxSetItem*>( rBindings.GetDispatcher()->Execute( FID_SEARCH_REPLACESET, SfxCallMode::SLOT, ppArgs ) ); + aResult = rBindings.GetDispatcher()->Execute(FID_SEARCH_REPLACESET, SfxCallMode::SLOT, ppArgs); + const SvxSetItem* pReplSetItem(static_cast<const SvxSetItem*>(aResult.getItem())); if ( pReplSetItem ) InitAttrList_Impl( nullptr, &pReplSetItem->GetItemSet() ); @@ -900,14 +900,14 @@ void SvxSearchDialog::Init_Impl( bool bSearchPattern ) { // Get attribute sets, if it not has been done already const SfxPoolItem* ppArgs[] = { pSearchItem.get(), nullptr }; - const SvxSetItem* pSrchSetItem = - static_cast<const SvxSetItem*>(rBindings.GetDispatcher()->Execute( FID_SEARCH_SEARCHSET, SfxCallMode::SLOT, ppArgs )); + SfxPoolItemHolder aResult(rBindings.GetDispatcher()->Execute(FID_SEARCH_SEARCHSET, SfxCallMode::SLOT, ppArgs)); + const SvxSetItem* pSrchSetItem(static_cast<const SvxSetItem*>(aResult.getItem())); if ( pSrchSetItem ) InitAttrList_Impl( &pSrchSetItem->GetItemSet(), nullptr ); - const SvxSetItem* pReplSetItem = - static_cast<const SvxSetItem*>( rBindings.GetDispatcher()->Execute( FID_SEARCH_REPLACESET, SfxCallMode::SLOT, ppArgs ) ); + aResult = rBindings.GetDispatcher()->Execute(FID_SEARCH_REPLACESET, SfxCallMode::SLOT, ppArgs); + const SvxSetItem* pReplSetItem(static_cast<const SvxSetItem*>(aResult.getItem())); if ( pReplSetItem ) InitAttrList_Impl( nullptr, &pReplSetItem->GetItemSet() ); diff --git a/svx/source/dialog/svxruler.cxx b/svx/source/dialog/svxruler.cxx index ffc34cd5bfb5..6323583fd271 100644 --- a/svx/source/dialog/svxruler.cxx +++ b/svx/source/dialog/svxruler.cxx @@ -43,6 +43,7 @@ #include <osl/diagnose.h> #include <rtl/math.hxx> #include <o3tl/string_view.hxx> +#include <svl/itemset.hxx> #include "rlrcitem.hxx" #include <memory> diff --git a/svx/source/gallery2/galctrl.cxx b/svx/source/gallery2/galctrl.cxx index 716a198ec87f..1c3ffbf0326b 100644 --- a/svx/source/gallery2/galctrl.cxx +++ b/svx/source/gallery2/galctrl.cxx @@ -34,6 +34,7 @@ #include <vcl/commandevent.hxx> #include <vcl/graphicfilter.hxx> #include <bitmaps.hlst> +#include <svl/itemset.hxx> GalleryPreview::GalleryPreview(GalleryBrowser2* pParent, std::unique_ptr<weld::ScrolledWindow> xScrolledWindow) : mxScrolledWindow(std::move(xScrolledWindow)) diff --git a/svx/source/sidebar/area/AreaPropertyPanel.cxx b/svx/source/sidebar/area/AreaPropertyPanel.cxx index fa634ee4499b..951028d61f32 100644 --- a/svx/source/sidebar/area/AreaPropertyPanel.cxx +++ b/svx/source/sidebar/area/AreaPropertyPanel.cxx @@ -23,6 +23,7 @@ #include <svx/xflftrit.hxx> #include <sfx2/dispatch.hxx> #include <sfx2/bindings.hxx> +#include <svl/itemset.hxx> using namespace css; @@ -90,9 +91,9 @@ void AreaPropertyPanel::setFillTransparence(const XFillTransparenceItem& rItem) void AreaPropertyPanel::setFillUseBackground(const XFillStyleItem* pStyleItem, const XFillUseSlideBackgroundItem& rItem) { - const SfxPoolItem* pItem = nullptr; + SfxPoolItemHolder aResult; auto pDispatcher = GetBindings()->GetDispatcher(); - auto state = pDispatcher->QueryState(SID_ATTR_FILL_USE_SLIDE_BACKGROUND, pItem); + auto state = pDispatcher->QueryState(SID_ATTR_FILL_USE_SLIDE_BACKGROUND, aResult); // FillUseSlideBackground is only available in Impress if (state == SfxItemState::DISABLED) { diff --git a/svx/source/sidebar/effect/EffectPropertyPanel.cxx b/svx/source/sidebar/effect/EffectPropertyPanel.cxx index 400dda997962..f6be6ddaff49 100644 --- a/svx/source/sidebar/effect/EffectPropertyPanel.cxx +++ b/svx/source/sidebar/effect/EffectPropertyPanel.cxx @@ -18,6 +18,7 @@ #include <svx/svddef.hxx> #include <svx/svxids.hrc> #include <svx/xcolit.hxx> +#include <svl/itemset.hxx> namespace svx::sidebar { diff --git a/svx/source/sidebar/graphic/GraphicPropertyPanel.cxx b/svx/source/sidebar/graphic/GraphicPropertyPanel.cxx index 5503649551e6..11a3130d466b 100644 --- a/svx/source/sidebar/graphic/GraphicPropertyPanel.cxx +++ b/svx/source/sidebar/graphic/GraphicPropertyPanel.cxx @@ -25,6 +25,7 @@ #include <sfx2/bindings.hxx> #include <sfx2/dispatch.hxx> #include <com/sun/star/lang/IllegalArgumentException.hpp> +#include <svl/itemset.hxx> using namespace css; using namespace css::uno; diff --git a/svx/source/sidebar/line/LinePropertyPanel.cxx b/svx/source/sidebar/line/LinePropertyPanel.cxx index 02dd597bd056..83a33b922888 100644 --- a/svx/source/sidebar/line/LinePropertyPanel.cxx +++ b/svx/source/sidebar/line/LinePropertyPanel.cxx @@ -26,6 +26,7 @@ #include <svx/xlncapit.hxx> #include <svx/xlinjoit.hxx> #include <com/sun/star/lang/IllegalArgumentException.hpp> +#include <svl/itemset.hxx> using namespace css; using namespace css::uno; diff --git a/svx/source/sidebar/media/MediaPlaybackPanel.cxx b/svx/source/sidebar/media/MediaPlaybackPanel.cxx index 4027e16ec730..53c9190b832e 100644 --- a/svx/source/sidebar/media/MediaPlaybackPanel.cxx +++ b/svx/source/sidebar/media/MediaPlaybackPanel.cxx @@ -21,6 +21,7 @@ #include <sfx2/sfxsids.hrc> #include <sfx2/dispatch.hxx> #include <avmedia/MediaControlBase.hxx> +#include <svl/itemset.hxx> #include <com/sun/star/lang/IllegalArgumentException.hpp> diff --git a/svx/source/sidebar/paragraph/ParaLineSpacingControl.cxx b/svx/source/sidebar/paragraph/ParaLineSpacingControl.cxx index 4c756a5b1224..bda7eb62e632 100644 --- a/svx/source/sidebar/paragraph/ParaLineSpacingControl.cxx +++ b/svx/source/sidebar/paragraph/ParaLineSpacingControl.cxx @@ -29,6 +29,7 @@ #include <svl/intitem.hxx> #include <svl/itempool.hxx> +#include <svl/itemset.hxx> #include <ParaLineSpacingPopup.hxx> @@ -84,10 +85,10 @@ ParaLineSpacingControl::ParaLineSpacingControl(SvxLineSpacingToolBoxControl* pCo mxLineDistAtMetricBox->connect_value_changed( aLink2 ); FieldUnit eUnit = FieldUnit::INCH; - const SfxUInt16Item* pItem = nullptr; - SfxViewFrame* pCurrent = SfxViewFrame::Current(); - if (pCurrent && pCurrent->GetBindings().GetDispatcher()->QueryState(SID_ATTR_METRIC, pItem) >= SfxItemState::DEFAULT) - eUnit = static_cast<FieldUnit>(pItem->GetValue()); + SfxPoolItemHolder aResult; + SfxViewFrame* pCurrent(SfxViewFrame::Current()); + if (pCurrent && pCurrent->GetBindings().GetDispatcher()->QueryState(SID_ATTR_METRIC, aResult) >= SfxItemState::DEFAULT) + eUnit = static_cast<FieldUnit>(static_cast<const SfxUInt16Item*>(aResult.getItem())->GetValue()); else eUnit = SfxModule::GetCurrentFieldUnit(); @@ -124,18 +125,18 @@ ParaLineSpacingControl::~ParaLineSpacingControl() void ParaLineSpacingControl::Initialize() { - const SvxLineSpacingItem* pItem(nullptr); + SfxPoolItemHolder aResult; SfxViewFrame* pCurrent = SfxViewFrame::Current(); const bool bItemStateSet(nullptr != pCurrent); const SfxItemState eState(bItemStateSet - ? pCurrent->GetBindings().GetDispatcher()->QueryState(SID_ATTR_PARA_LINESPACE, pItem) + ? pCurrent->GetBindings().GetDispatcher()->QueryState(SID_ATTR_PARA_LINESPACE, aResult) : SfxItemState::DEFAULT); mxLineDist->set_sensitive(true); if( bItemStateSet && (eState == SfxItemState::DEFAULT || eState == SfxItemState::SET) ) { - const SvxLineSpacingItem* currSPItem = pItem; + const SvxLineSpacingItem* currSPItem(static_cast<const SvxLineSpacingItem*>(aResult.getItem())); // It seems draw/impress and writer require different MapUnit values for fixed line spacing // metric values to be correctly calculated. MapUnit eUnit = MapUnit::Map100thMM; // works for draw/impress diff --git a/svx/source/sidebar/paragraph/ParaSpacingWindow.cxx b/svx/source/sidebar/paragraph/ParaSpacingWindow.cxx index f5968510e2ea..ac8749b3b332 100644 --- a/svx/source/sidebar/paragraph/ParaSpacingWindow.cxx +++ b/svx/source/sidebar/paragraph/ParaSpacingWindow.cxx @@ -24,6 +24,7 @@ #include <sfx2/app.hxx> #include <sfx2/viewfrm.hxx> #include <svl/itempool.hxx> +#include <svl/itemset.hxx> using namespace svx; -e ... etc. - the rest is truncated