sc/source/ui/condformat/condformatdlg.cxx |   26 +++++++++++---------
 sc/source/ui/inc/condformatdlg.hxx        |    2 -
 sc/source/ui/inc/tabvwsh.hxx              |    7 +++--
 sc/source/ui/view/cellsh1.cxx             |   38 ++++++++++++++++--------------
 sc/source/ui/view/tabvwsh4.cxx            |    2 -
 sc/source/ui/view/tabvwshc.cxx            |   14 ++++-------
 6 files changed, 48 insertions(+), 41 deletions(-)

New commits:
commit 84e87079d158d9945493e6edd149b924ecbc518b
Author:     Armin Le Grand (Collabora) <armin.le.gr...@me.com>
AuthorDate: Wed Feb 26 11:45:06 2025 +0100
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Wed Feb 26 20:23:09 2025 +0100

    tdf#160252 ITEM fix ScCondFormatDlgItem usage (againII)
    
    Change-Id: Iac66fed14c6084d80c0b49badbaa1f8c6109f248
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/182218
    Tested-by: Jenkins
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>
    Reviewed-by: Armin Le Grand <armin.le.gr...@me.com>
    (cherry picked from commit 35c2320dcc2e0a492d5d85133081ed040578483d)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/182233
    Signed-off-by: Xisco Fauli <xiscofa...@libreoffice.org>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/182241

diff --git a/sc/source/ui/condformat/condformatdlg.cxx 
b/sc/source/ui/condformat/condformatdlg.cxx
index 8c608597cab0..7aa7b018fa15 100644
--- a/sc/source/ui/condformat/condformatdlg.cxx
+++ b/sc/source/ui/condformat/condformatdlg.cxx
@@ -429,7 +429,7 @@ ScCondFormatDlg::ScCondFormatDlg(SfxBindings* pB, 
SfxChildWindow* pCW,
     , mpViewData(pViewData)
     // previous version based on SfxPoolItem used SfxPoolItem::Clone here, so 
make a copy
     // using copy constructor
-    , mpDlgItem(std::make_shared<ScCondFormatDlgData>(*rItem))
+    , mpDlgData(std::make_shared<ScCondFormatDlgData>(*rItem))
     , mpLastEdit(nullptr)
     , mxBtnOk(m_xBuilder->weld_button(u"ok"_ustr))
     , mxBtnAdd(m_xBuilder->weld_button(u"add"_ustr))
@@ -447,12 +447,12 @@ ScCondFormatDlg::ScCondFormatDlg(SfxBindings* pB, 
SfxChildWindow* pCW,
     mxRbRange->SetReferences(this, mxEdRange.get());
 
     ScConditionalFormat* pFormat = nullptr;
-    mnKey = mpDlgItem->GetIndex();
-    if (mpDlgItem->IsManaged() && mpDlgItem->GetConditionalFormatList())
+    mnKey = mpDlgData->GetIndex();
+    if (mpDlgData->IsManaged() && mpDlgData->GetConditionalFormatList())
     {
-        pFormat = mpDlgItem->GetConditionalFormatList()->GetFormat(mnKey);
+        pFormat = mpDlgData->GetConditionalFormatList()->GetFormat(mnKey);
     }
-    else if (!mpDlgItem->IsManaged())
+    else if (!mpDlgData->IsManaged())
     {
         ScDocument& rDoc = mpViewData->GetDocument();
         pFormat = rDoc.GetCondFormList(mpViewData->GetTabNo())->GetFormat ( 
mnKey );
@@ -476,7 +476,7 @@ ScCondFormatDlg::ScCondFormatDlg(SfxBindings* pB, 
SfxChildWindow* pCW,
     }
     maPos = aRange.GetTopLeftCorner();
 
-    mxCondFormList->init(mpViewData->GetDocument(), pFormat, aRange, maPos, 
mpDlgItem->GetDialogType());
+    mxCondFormList->init(mpViewData->GetDocument(), pFormat, aRange, maPos, 
mpDlgData->GetDialogType());
 
     mxBtnOk->connect_clicked(LINK(this, ScCondFormatDlg, BtnPressedHdl ) );
     mxBtnAdd->connect_clicked( LINK( mxCondFormList.get(), ScCondFormatList, 
AddBtnHdl ) );
@@ -615,7 +615,7 @@ void ScCondFormatDlg::OkPressed()
 {
     std::unique_ptr<ScConditionalFormat> pFormat = GetConditionalFormat();
 
-    if (!mpDlgItem->IsManaged())
+    if (!mpDlgData->IsManaged())
     {
         if(pFormat)
         {
@@ -629,7 +629,7 @@ void ScCondFormatDlg::OkPressed()
     }
     else
     {
-        ScConditionalFormatList* pList = mpDlgItem->GetConditionalFormatList();
+        ScConditionalFormatList* pList = mpDlgData->GetConditionalFormatList();
         sal_uInt32 nKey = mnKey;
         if (mnKey == 0)
         {
@@ -643,8 +643,10 @@ void ScCondFormatDlg::OkPressed()
             pList->InsertNew(std::move(pFormat));
         }
 
-        mpViewData->GetViewShell()->setScCondFormatDlgItem(mpDlgItem);
+        // provide needed DialogData
+        mpViewData->GetViewShell()->setScCondFormatDlgData(mpDlgData);
         SetDispatcherLock( false );
+
         // Queue message to open Conditional Format Manager Dialog
         GetBindings().GetDispatcher()->Execute( SID_OPENDLG_CONDFRMT_MANAGER,
                                             SfxCallMode::ASYNCHRON );
@@ -656,10 +658,12 @@ void ScCondFormatDlg::OkPressed()
 //
 void ScCondFormatDlg::CancelPressed()
 {
-    if ( mpDlgItem->IsManaged() )
+    if ( mpDlgData->IsManaged() )
     {
-        mpViewData->GetViewShell()->setScCondFormatDlgItem(mpDlgItem);
+        // provide needed DialogData
+        mpViewData->GetViewShell()->setScCondFormatDlgData(mpDlgData);
         SetDispatcherLock( false );
+
         // Queue message to open Conditional Format Manager Dialog
         GetBindings().GetDispatcher()->Execute( SID_OPENDLG_CONDFRMT_MANAGER,
                                             SfxCallMode::ASYNCHRON );
diff --git a/sc/source/ui/inc/condformatdlg.hxx 
b/sc/source/ui/inc/condformatdlg.hxx
index 4b2b4cfb4c11..403b13035826 100644
--- a/sc/source/ui/inc/condformatdlg.hxx
+++ b/sc/source/ui/inc/condformatdlg.hxx
@@ -82,7 +82,7 @@ private:
     ScAddress maPos;
     ScViewData* mpViewData;
 
-    std::shared_ptr<ScCondFormatDlgData> mpDlgItem;
+    std::shared_ptr<ScCondFormatDlgData> mpDlgData;
 
     OUString msBaseTitle;
 
diff --git a/sc/source/ui/inc/tabvwsh.hxx b/sc/source/ui/inc/tabvwsh.hxx
index a3c0d728f90f..56d42a00d0cb 100644
--- a/sc/source/ui/inc/tabvwsh.hxx
+++ b/sc/source/ui/inc/tabvwsh.hxx
@@ -196,7 +196,8 @@ private:
     OUString   maScope;
 
     std::unique_ptr<ScDragData> m_pDragData;
-    std::shared_ptr<ScCondFormatDlgData> m_pScCondFormatDlgItem;
+    // temporary data for exchange in the used multi-dialog structure
+    std::shared_ptr<ScCondFormatDlgData> m_pScCondFormatDlgData;
 
     // Chart insert wizard's mark to make sure it undoes the correct thing in 
LOK case
     UndoStackMark m_InsertWizardUndoMark = MARK_INVALID;
@@ -460,8 +461,8 @@ public:
     void SetMoveKeepEdit(bool value) { bMoveKeepEdit = value; };
     bool GetMoveKeepEdit() { return bMoveKeepEdit; };
 
-    void setScCondFormatDlgItem(const std::shared_ptr<ScCondFormatDlgData>& 
rItem) { m_pScCondFormatDlgItem = rItem; }
-    const std::shared_ptr<ScCondFormatDlgData>& getScCondFormatDlgItem() const 
{ return m_pScCondFormatDlgItem; }
+    void setScCondFormatDlgData(const std::shared_ptr<ScCondFormatDlgData>& 
rItem) { m_pScCondFormatDlgData = rItem; }
+    const std::shared_ptr<ScCondFormatDlgData>& getScCondFormatDlgData() const 
{ return m_pScCondFormatDlgData; }
 
     void SetInsertWizardUndoMark();
 
diff --git a/sc/source/ui/view/cellsh1.cxx b/sc/source/ui/view/cellsh1.cxx
index 2d3fdab0e19f..8a1fedc84314 100644
--- a/sc/source/ui/view/cellsh1.cxx
+++ b/sc/source/ui/view/cellsh1.cxx
@@ -200,10 +200,10 @@ void HandleConditionalFormat(sal_uInt32 nIndex, bool 
bCondFormatDlg, bool bConta
     if (bCondFormatDlg || !bContainsCondFormat)
     {
         // Put the xml string parameter to initialize the
-        // Conditional Format Dialog.
-        std::shared_ptr<ScCondFormatDlgData> 
pDlgItem(std::make_shared<ScCondFormatDlgData>(nullptr, nIndex, false));
-        pDlgItem->SetDialogType(eType);
-        pTabViewShell->setScCondFormatDlgItem(pDlgItem);
+        // Conditional Format Dialog. Set the initial DialogData.
+        std::shared_ptr<ScCondFormatDlgData> 
pDlgData(std::make_shared<ScCondFormatDlgData>(nullptr, nIndex, false));
+        pDlgData->SetDialogType(eType);
+        pTabViewShell->setScCondFormatDlgData(pDlgData);
 
         sal_uInt16 nId = ScCondFormatDlgWrapper::GetChildWindowId();
         SfxViewFrame& rViewFrm = pTabViewShell->GetViewFrame();
@@ -2190,10 +2190,11 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq )
                 sal_uInt32  nIndex      = sal_uInt32(-1);
                 bool        bManaged    = false;
 
-                const std::shared_ptr<ScCondFormatDlgData>& 
rDlgItem(pTabViewShell->getScCondFormatDlgItem());
-                if (rDlgItem)
+                // get the current DialogData
+                const std::shared_ptr<ScCondFormatDlgData>& 
rDlgData(pTabViewShell->getScCondFormatDlgData());
+                if (rDlgData)
                 {
-                    nIndex = rDlgItem->GetIndex();
+                    nIndex = rDlgData->GetIndex();
                     bManaged = true;
                 }
 
@@ -2904,10 +2905,12 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq )
                 ScAddress aPos(rData.GetCurX(), rData.GetCurY(), 
rData.GetTabNo());
 
                 ScConditionalFormatList* pList = nullptr;
-                const std::shared_ptr<ScCondFormatDlgData>& 
rDlgItem(pTabViewShell->getScCondFormatDlgItem());
-                if (rDlgItem)
+
+                // get the current DialogData
+                const std::shared_ptr<ScCondFormatDlgData>& 
rDlgData(pTabViewShell->getScCondFormatDlgData());
+                if (rDlgData)
                 {
-                    pList = rDlgItem->GetConditionalFormatList();
+                    pList = rDlgData->GetConditionalFormatList();
                 }
 
                 if (!pList)
@@ -2916,10 +2919,14 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq )
                 VclPtr<AbstractScCondFormatManagerDlg> 
pDlg(pFact->CreateScCondFormatMgrDlg(
                     pTabViewShell->GetFrameWeld(), rDoc, pList));
 
-                if (rDlgItem)
+                if (rDlgData)
+                {
                     pDlg->SetModified();
+                    // reset the current DialogData, will be reset when needed 
below
+                    pTabViewShell->setScCondFormatDlgData(nullptr);
+                }
 
-                pDlg->StartExecuteAsync([this, pDlg, &rData, pTabViewShell, 
rDlgItem, aPos](sal_Int32 nRet){
+                pDlg->StartExecuteAsync([this, pDlg, &rData, pTabViewShell, 
aPos](sal_Int32 nRet){
                     std::unique_ptr<ScConditionalFormatList> pCondFormatList = 
pDlg->GetConditionalFormatList();
                     if(nRet == RET_OK && pDlg->CondFormatsChanged())
                     {
@@ -2929,7 +2936,7 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq )
                     {
                         // Put the xml string parameter to initialize the
                         // Conditional Format Dialog. ( add new )
-                        
pTabViewShell->setScCondFormatDlgItem(std::make_shared<ScCondFormatDlgData>(
+                        
pTabViewShell->setScCondFormatDlgData(std::make_shared<ScCondFormatDlgData>(
                             
std::shared_ptr<ScConditionalFormatList>(pCondFormatList.release()), -1, true));
                         // Queue message to open Conditional Format Dialog
                         GetViewData().GetDispatcher().Execute( 
SID_OPENDLG_CONDFRMT, SfxCallMode::ASYNCHRON );
@@ -2940,7 +2947,7 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq )
                         sal_Int32 nIndex = pFormat ? pFormat->GetKey() : -1;
                         // Put the xml string parameter to initialize the
                         // Conditional Format Dialog. ( edit selected 
conditional format )
-                        
pTabViewShell->setScCondFormatDlgItem(std::make_shared<ScCondFormatDlgData>(
+                        
pTabViewShell->setScCondFormatDlgData(std::make_shared<ScCondFormatDlgData>(
                                     
std::shared_ptr<ScConditionalFormatList>(pCondFormatList.release()), nIndex, 
true));
 
                         // Queue message to open Conditional Format Dialog
@@ -2949,9 +2956,6 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq )
                     else
                         pCondFormatList.reset();
 
-                    if (rDlgItem)
-                        pTabViewShell->setScCondFormatDlgItem(nullptr);
-
                     pDlg->disposeOnce();
                 });
             }
diff --git a/sc/source/ui/view/tabvwsh4.cxx b/sc/source/ui/view/tabvwsh4.cxx
index a61bbf4ae242..91a160237bd6 100644
--- a/sc/source/ui/view/tabvwsh4.cxx
+++ b/sc/source/ui/view/tabvwsh4.cxx
@@ -1800,7 +1800,7 @@ ScTabViewShell::ScTabViewShell( SfxViewFrame& rViewFrame,
     nCurRefDlgId(0),
     mbInSwitch(false),
     m_pDragData(new ScDragData),
-    m_pScCondFormatDlgItem()
+    m_pScCondFormatDlgData()
 {
     const ScAppOptions& rAppOpt = SC_MOD()->GetAppOptions();
 
diff --git a/sc/source/ui/view/tabvwshc.cxx b/sc/source/ui/view/tabvwshc.cxx
index 7904290b6d5b..886a0c5a03ce 100644
--- a/sc/source/ui/view/tabvwshc.cxx
+++ b/sc/source/ui/view/tabvwshc.cxx
@@ -425,20 +425,18 @@ std::shared_ptr<SfxModelessDialogController> 
ScTabViewShell::CreateRefDialogCont
         }
         case WID_CONDFRMT_REF:
         {
-            // Get the pool item stored by Conditional Format Manager Dialog.
-            const std::shared_ptr<ScCondFormatDlgData>& 
rDlgItem(getScCondFormatDlgItem());
+            // Get the DialogData stored by Conditional Format Manager Dialog.
+            const std::shared_ptr<ScCondFormatDlgData>& 
rDlgData(getScCondFormatDlgData());
 
-            if (rDlgItem)
+            if (rDlgData)
             {
                 ScViewData& rViewData = GetViewData();
                 rViewData.SetRefTabNo( rViewData.GetTabNo() );
 
-                xResult = std::make_shared<ScCondFormatDlg>(pB, pCW, pParent, 
&rViewData, rDlgItem);
+                xResult = std::make_shared<ScCondFormatDlg>(pB, pCW, pParent, 
&rViewData, rDlgData);
 
-                // Remove the pool item stored by Conditional Format Manager 
Dialog.
-                // tdf#160252 still needed *after* change to 
ScCondFormatDlgData due to
-                // UnitTest UITest_conditional_format
-                setScCondFormatDlgItem(nullptr);
+                // Remove the DialogData stored by Conditional Format Manager 
Dialog.
+                setScCondFormatDlgData(nullptr);
             }
 
             break;

Reply via email to