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             |   46 +++++++++++++++++-------------
 sc/source/ui/view/tabvwsh4.cxx            |    2 -
 sc/source/ui/view/tabvwshc.cxx            |   14 +++------
 6 files changed, 54 insertions(+), 43 deletions(-)

New commits:
commit 35c2320dcc2e0a492d5d85133081ed040578483d
Author:     Armin Le Grand (Collabora) <armin.le.gr...@me.com>
AuthorDate: Wed Feb 26 11:45:06 2025 +0100
Commit:     Armin Le Grand <armin.le.gr...@me.com>
CommitDate: Wed Feb 26 15:40:40 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>

diff --git a/sc/source/ui/condformat/condformatdlg.cxx 
b/sc/source/ui/condformat/condformatdlg.cxx
index c38a8c7e06ea..3d0a2ddc0c72 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(pFormat, aRange, maPos, mpDlgItem->GetDialogType());
+    mxCondFormList->init(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 9edd0716d941..28a8626afe59 100644
--- a/sc/source/ui/inc/condformatdlg.hxx
+++ b/sc/source/ui/inc/condformatdlg.hxx
@@ -83,7 +83,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 5a562431f473..a1be44905351 100644
--- a/sc/source/ui/inc/tabvwsh.hxx
+++ b/sc/source/ui/inc/tabvwsh.hxx
@@ -198,7 +198,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;
@@ -470,8 +471,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 7b81aff93536..a090b612eaa9 100644
--- a/sc/source/ui/view/cellsh1.cxx
+++ b/sc/source/ui/view/cellsh1.cxx
@@ -202,10 +202,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();
@@ -2208,10 +2208,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;
                 }
 
@@ -2917,10 +2918,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)
@@ -2929,11 +2932,15 @@ 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)
+                    [this, pDlg, &rData, pTabViewShell, aPos](sal_Int32 nRet)
                     {
                         std::unique_ptr<ScConditionalFormatList> 
pCondFormatList
                             = pDlg->GetConditionalFormatList();
@@ -2945,12 +2952,14 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq )
                         else if (nRet == DLG_RET_ADD)
                         {
                             // Put the xml string parameter to initialize the
-                            // Conditional Format Dialog. ( add new )
-                            pTabViewShell->setScCondFormatDlgItem(
+                            // Conditional Format Dialog. ( add new ). Proivde
+                            // new DialogData
+                            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);
@@ -2960,12 +2969,14 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq )
                             ScConditionalFormat* pFormat = 
pDlg->GetCondFormatSelected();
                             sal_uInt32 nIndex = pFormat ? pFormat->GetKey() : 
sal_uInt32(-1);
                             // Put the xml string parameter to initialize the
-                            // Conditional Format Dialog. ( edit selected 
conditional format )
-                            pTabViewShell->setScCondFormatDlgItem(
+                            // Conditional Format Dialog. ( edit selected 
conditional format ).
+                            // Proivde new DialogData
+                            pTabViewShell->setScCondFormatDlgData(
                                 std::make_shared<ScCondFormatDlgData>(
                                     std::shared_ptr<ScConditionalFormatList>(
                                         pCondFormatList.release()),
                                     nIndex, true));
+
                             // Queue message to open Conditional Format Dialog
                             
GetViewData().GetDispatcher().Execute(SID_OPENDLG_CONDFRMT,
                                                                   
SfxCallMode::ASYNCHRON);
@@ -2973,9 +2984,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 46ed26d6b808..af8496c347b6 100644
--- a/sc/source/ui/view/tabvwsh4.cxx
+++ b/sc/source/ui/view/tabvwsh4.cxx
@@ -2040,7 +2040,7 @@ ScTabViewShell::ScTabViewShell( SfxViewFrame& rViewFrame,
     nCurRefDlgId(0),
     mbInSwitch(false),
     m_pDragData(new ScDragData),
-    m_pScCondFormatDlgItem()
+    m_pScCondFormatDlgData()
 {
     const ScAppOptions& rAppOpt = ScModule::get()->GetAppOptions();
 
diff --git a/sc/source/ui/view/tabvwshc.cxx b/sc/source/ui/view/tabvwshc.cxx
index 8fc9fb1276cf..8e1f6860d619 100644
--- a/sc/source/ui/view/tabvwshc.cxx
+++ b/sc/source/ui/view/tabvwshc.cxx
@@ -426,20 +426,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