include/sfx2/filedlghelper.hxx       |    8 +++++---
 sfx2/source/appl/appopen.cxx         |    4 ++--
 sfx2/source/dialog/filedlghelper.cxx |   18 +++++++++---------
 sfx2/source/dialog/filedlgimpl.hxx   |    2 +-
 sfx2/source/doc/guisaveas.cxx        |    6 +++---
 5 files changed, 20 insertions(+), 18 deletions(-)

New commits:
commit 5021a10f75870e7fa8f34e58512fd7c027debc68
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Thu Jul 1 10:29:22 2021 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Thu Jul 1 15:00:16 2021 +0200

    sfx2::FileDialogHelper allocate SfxItemSet on stack
    
    and pass around the explicit sub-type, instead of doing static_cast in
    various places
    
    Change-Id: I28ba8fd6f5c9e2a1ffbf5ec091bcf0ebdd1d18b1
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/118210
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/include/sfx2/filedlghelper.hxx b/include/sfx2/filedlghelper.hxx
index 356beb49c4ff..4985b7bf045e 100644
--- a/include/sfx2/filedlghelper.hxx
+++ b/include/sfx2/filedlghelper.hxx
@@ -32,6 +32,7 @@
 #include <o3tl/typed_flags_set.hxx>
 
 #include <memory>
+#include <optional>
 #include <vector>
 
 namespace com::sun::star::ui::dialogs
@@ -49,6 +50,7 @@ namespace weld { class Window; }
 class Graphic;
 class SfxFilter;
 class SfxItemSet;
+class SfxAllItemSet;
 
 enum class FileDialogFlags {
     NONE              = 0x00,
@@ -222,10 +224,10 @@ public:
    DECL_LINK( ExecuteSystemFilePicker, void*, void );
 
    ErrCode                  Execute( std::vector<OUString>& rpURLList,
-                                     std::unique_ptr<SfxItemSet>& rpSet,
+                                     std::optional<SfxAllItemSet>& rpSet,
                                      OUString&         rFilter,
                                      const OUString&   rDirPath );
-   ErrCode                  Execute( std::unique_ptr<SfxItemSet>& rpSet,
+   ErrCode                  Execute( std::optional<SfxAllItemSet>& rpSet,
                                      OUString&         rFilter );
 };
 
@@ -239,7 +241,7 @@ ErrCode FileOpenDialog_Impl( weld::Window* pParent,
                              FileDialogFlags nFlags,
                              std::vector<OUString>& rpURLList,
                              OUString& rFilter,
-                             std::unique_ptr<SfxItemSet>& rpSet,
+                             std::optional<SfxAllItemSet>& rpSet,
                              const OUString* pPath,
                              sal_Int16 nDialog,
                              const OUString& rStandardDir,
diff --git a/sfx2/source/appl/appopen.cxx b/sfx2/source/appl/appopen.cxx
index 08431c29eaaa..f26b88a1b06c 100644
--- a/sfx2/source/appl/appopen.cxx
+++ b/sfx2/source/appl/appopen.cxx
@@ -608,7 +608,7 @@ void SfxApplication::OpenDocExec_Impl( SfxRequest& rReq )
         // get FileName from dialog
         std::vector<OUString> aURLList;
         OUString aFilter;
-        std::unique_ptr<SfxItemSet> pSet;
+        std::optional<SfxAllItemSet> pSet;
         OUString aPath;
         const SfxStringItem* pFolderNameItem = 
rReq.GetArg<SfxStringItem>(SID_PATH);
         if ( pFolderNameItem )
@@ -662,7 +662,7 @@ void SfxApplication::OpenDocExec_Impl( SfxRequest& rReq )
             return;
         }
 
-        rReq.SetArgs( *static_cast<SfxAllItemSet*>(pSet.get()) );
+        rReq.SetArgs( *pSet );
         if ( !aFilter.isEmpty() )
             rReq.AppendItem( SfxStringItem( SID_FILTER_NAME, aFilter ) );
         rReq.AppendItem( SfxStringItem( SID_TARGETNAME, "_default" ) );
diff --git a/sfx2/source/dialog/filedlghelper.cxx 
b/sfx2/source/dialog/filedlghelper.cxx
index 939863816142..c388b909a3a4 100644
--- a/sfx2/source/dialog/filedlghelper.cxx
+++ b/sfx2/source/dialog/filedlghelper.cxx
@@ -1395,7 +1395,7 @@ void FileDialogHelper_Impl::implGetAndCacheFiles(const 
uno::Reference< XInterfac
 }
 
 ErrCode FileDialogHelper_Impl::execute( std::vector<OUString>& rpURLList,
-                                        std::unique_ptr<SfxItemSet>& rpSet,
+                                        std::optional<SfxAllItemSet>& rpSet,
                                         OUString&       rFilter )
 {
     // rFilter is a pure output parameter, it shouldn't be used for anything 
else
@@ -1411,15 +1411,15 @@ ErrCode FileDialogHelper_Impl::execute( 
std::vector<OUString>& rpURLList,
         // check password checkbox if the document had password before
         if( mbHasPassword )
         {
-            const SfxBoolItem* pPassItem = 
SfxItemSet::GetItem<SfxBoolItem>(rpSet.get(), SID_PASSWORDINTERACTION, false);
+            const SfxBoolItem* pPassItem = 
SfxItemSet::GetItem<SfxBoolItem>(&*rpSet, SID_PASSWORDINTERACTION, false);
             mbPwdCheckBoxState = ( pPassItem != nullptr && 
pPassItem->GetValue() );
 
             // in case the document has password to modify, the dialog should 
be shown
-            const SfxUnoAnyItem* pPassToModifyItem = 
SfxItemSet::GetItem<SfxUnoAnyItem>(rpSet.get(), SID_MODIFYPASSWORDINFO, false);
+            const SfxUnoAnyItem* pPassToModifyItem = 
SfxItemSet::GetItem<SfxUnoAnyItem>(&*rpSet, SID_MODIFYPASSWORDINFO, false);
             mbPwdCheckBoxState |= ( pPassToModifyItem && 
pPassToModifyItem->GetValue().hasValue() );
         }
 
-        const SfxBoolItem* pSelectItem = 
SfxItemSet::GetItem<SfxBoolItem>(rpSet.get(), SID_SELECTION, false);
+        const SfxBoolItem* pSelectItem = 
SfxItemSet::GetItem<SfxBoolItem>(&*rpSet, SID_SELECTION, false);
         if ( pSelectItem )
             mbSelection = pSelectItem->GetValue();
         else
@@ -1455,7 +1455,7 @@ ErrCode FileDialogHelper_Impl::execute( 
std::vector<OUString>& rpURLList,
     {
         // create an itemset if there is no
         if( !rpSet )
-            rpSet.reset(new SfxAllItemSet( SfxGetpApp()->GetPool() ));
+            rpSet.emplace( SfxGetpApp()->GetPool() );
 
         // the item should remain only if it was set by the dialog
         rpSet->ClearItem( SID_SELECTION );
@@ -1531,7 +1531,7 @@ ErrCode FileDialogHelper_Impl::execute( 
std::vector<OUString>& rpURLList,
                 {
                     // ask for a password
                     OUString aDocName(rpURLList[0]);
-                    ErrCode errCode = RequestPassword(pCurrentFilter, 
aDocName, rpSet.get(), GetFrameInterface());
+                    ErrCode errCode = RequestPassword(pCurrentFilter, 
aDocName, &*rpSet, GetFrameInterface());
                     if (errCode != ERRCODE_NONE)
                         return errCode;
                 }
@@ -2383,7 +2383,7 @@ IMPL_LINK_NOARG(FileDialogHelper, 
ExecuteSystemFilePicker, void*, void)
 
 // rDirPath has to be a directory
 ErrCode FileDialogHelper::Execute( std::vector<OUString>& rpURLList,
-                                   std::unique_ptr<SfxItemSet>& rpSet,
+                                   std::optional<SfxAllItemSet>& rpSet,
                                    OUString&       rFilter,
                                    const OUString& rDirPath )
 {
@@ -2397,7 +2397,7 @@ ErrCode FileDialogHelper::Execute()
     return mpImpl->execute();
 }
 
-ErrCode FileDialogHelper::Execute( std::unique_ptr<SfxItemSet>& rpSet,
+ErrCode FileDialogHelper::Execute( std::optional<SfxAllItemSet>& rpSet,
                                    OUString&       rFilter )
 {
     ErrCode nRet;
@@ -2645,7 +2645,7 @@ ErrCode FileOpenDialog_Impl( weld::Window* pParent,
                              FileDialogFlags nFlags,
                              std::vector<OUString>& rpURLList,
                              OUString& rFilter,
-                             std::unique_ptr<SfxItemSet>& rpSet,
+                             std::optional<SfxAllItemSet>& rpSet,
                              const OUString* pPath,
                              sal_Int16 nDialog,
                              const OUString& rStandardDir,
diff --git a/sfx2/source/dialog/filedlgimpl.hxx 
b/sfx2/source/dialog/filedlgimpl.hxx
index e5e02e209748..f8a75f049f76 100644
--- a/sfx2/source/dialog/filedlgimpl.hxx
+++ b/sfx2/source/dialog/filedlgimpl.hxx
@@ -176,7 +176,7 @@ namespace sfx2
         virtual                 ~FileDialogHelper_Impl() override;
 
         ErrCode                 execute( std::vector<OUString>& rpURLList,
-                                         std::unique_ptr<SfxItemSet>& rpSet,
+                                         std::optional<SfxAllItemSet>& rpSet,
                                          OUString&       rFilter );
         ErrCode                 execute();
 
diff --git a/sfx2/source/doc/guisaveas.cxx b/sfx2/source/doc/guisaveas.cxx
index e2a2209e7b38..84a4edd83b42 100644
--- a/sfx2/source/doc/guisaveas.cxx
+++ b/sfx2/source/doc/guisaveas.cxx
@@ -966,10 +966,10 @@ bool ModelData_Impl::OutputFileDialog( sal_Int16 
nStoreMode,
 
     // generate SidSet from MediaDescriptor and provide it into FileDialog
     // than merge changed SidSet back
-    std::unique_ptr<SfxItemSet> pDialogParams(new SfxAllItemSet( 
SfxGetpApp()->GetPool() ));
+    std::optional<SfxAllItemSet> pDialogParams( SfxGetpApp()->GetPool() );
     TransformParameters( nSlotID,
                          GetMediaDescr().getAsConstPropertyValueList(),
-                         static_cast<SfxAllItemSet&>(*pDialogParams) );
+                         *pDialogParams );
 
     const SfxPoolItem* pItem = nullptr;
     if ( bPreselectPassword && pDialogParams->GetItemState( 
SID_ENCRYPTIONDATA, true, &pItem ) != SfxItemState::SET )
@@ -990,7 +990,7 @@ bool ModelData_Impl::OutputFileDialog( sal_Int16 nStoreMode,
 
     // the following two arguments can not be converted in MediaDescriptor,
     // so they should be removed from the ItemSet after retrieving
-    const SfxBoolItem* pRecommendReadOnly = 
SfxItemSet::GetItem<SfxBoolItem>(pDialogParams.get(), SID_RECOMMENDREADONLY, 
false);
+    const SfxBoolItem* pRecommendReadOnly = 
SfxItemSet::GetItem<SfxBoolItem>(&*pDialogParams, SID_RECOMMENDREADONLY, false);
     m_bRecommendReadOnly = ( pRecommendReadOnly && 
pRecommendReadOnly->GetValue() );
     pDialogParams->ClearItem( SID_RECOMMENDREADONLY );
 
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to