sc/Library_sc.mk                              |    1 
 sc/inc/conditio.hxx                           |    2 
 sc/inc/scabstdlg.hxx                          |    4 
 sc/inc/scitems.hxx                            |    3 
 sc/source/core/data/conditio.cxx              |   12 +
 sc/source/core/data/table1.cxx                |    9 -
 sc/source/ui/app/msgpool.cxx                  |    7 
 sc/source/ui/attrdlg/scdlgfact.cxx            |    7 
 sc/source/ui/attrdlg/scdlgfact.hxx            |    4 
 sc/source/ui/condformat/condformatdlg.cxx     |  214 +++++++-------------------
 sc/source/ui/condformat/condformatdlgitem.cxx |   77 +++++++++
 sc/source/ui/condformat/condformatmgr.cxx     |   13 +
 sc/source/ui/inc/condformatdlg.hxx            |   33 ----
 sc/source/ui/inc/condformatdlgitem.hxx        |   68 ++++++++
 sc/source/ui/inc/condformatmgr.hxx            |    3 
 sc/source/ui/inc/msgpool.hxx                  |    2 
 sc/source/ui/view/cellsh1.cxx                 |   74 +++++---
 sc/source/ui/view/tabvwshc.cxx                |   47 +----
 18 files changed, 316 insertions(+), 264 deletions(-)

New commits:
commit 98b580b302267fb7c781e94ef6d175d696e9e848
Author: Markus Mohrhard <markus.mohrh...@googlemail.com>
Date:   Sun Sep 18 16:07:22 2016 +0200

    tdf#96453, tdf#100793 rework transfer of data between cond format dlgs
    
    extract the code to get the max key id to own method
    
    Change-Id: I56bd53e03a7ea97b15895528ec02a09a73d877b6
    Reviewed-on: https://gerrit.libreoffice.org/28994
    Tested-by: Jenkins <c...@libreoffice.org>
    Reviewed-by: Markus Mohrhard <markus.mohrh...@googlemail.com>
    (cherry picked from commit 046f3aa2d9285da7661c4d9f59c0baf406227553)
    
    tdf#96453, tdf#100793 rework transfer of data between cond format dlgs
    
    The xml based transfer of information was a bad idea from the start. It
    can obviously not transport the temporary conditional format information
    from the manager dialog. Therefore the whole handling here was
    completely broken and deleted formats came back, changed formats were
    not saved and added formats got applied directly to the document.
    
    Now the document fornat list and the one from the manager are indepedent
    again and as long as the manager has not been closed with ok nothing is
    written to the document.
    
    Reviewed-on: https://gerrit.libreoffice.org/28995
    Reviewed-by: Markus Mohrhard <markus.mohrh...@googlemail.com>
    Tested-by: Markus Mohrhard <markus.mohrh...@googlemail.com>
    (cherry picked from commit 5b8c22379e2eae74f7ed78326ab89483db5c6624)
    
    Conflicts:
        sc/source/ui/inc/condformatdlg.hxx
        sc/source/ui/view/cellsh1.cxx
    
    Change-Id: I9802be11cd15c2d2d877e55c91d836735fe0e0ff
    
    adapt aMsgItemInfo to 5b8c22379
    
    Change-Id: If5fd822f3f90b204d2661cf7b4446cb925ee6f3b
    Reviewed-on: https://gerrit.libreoffice.org/29191
    Tested-by: Jenkins <c...@libreoffice.org>
    Reviewed-by: Eike Rathke <er...@redhat.com>
    Tested-by: Eike Rathke <er...@redhat.com>

diff --git a/sc/Library_sc.mk b/sc/Library_sc.mk
index bd767cb..0ef50c3 100644
--- a/sc/Library_sc.mk
+++ b/sc/Library_sc.mk
@@ -387,6 +387,7 @@ $(eval $(call gb_Library_add_exception_objects,sc,\
     sc/source/ui/cctrl/tbzoomsliderctrl \
     sc/source/ui/condformat/condformatdlg \
     sc/source/ui/condformat/condformatdlgentry \
+    sc/source/ui/condformat/condformatdlgitem \
     sc/source/ui/condformat/condformathelper \
     sc/source/ui/condformat/colorformat \
     sc/source/ui/dbgui/asciiopt \
diff --git a/sc/inc/conditio.hxx b/sc/inc/conditio.hxx
index f214320..104fe42 100644
--- a/sc/inc/conditio.hxx
+++ b/sc/inc/conditio.hxx
@@ -523,6 +523,8 @@ public:
 
     void startRendering();
     void endRendering();
+
+    sal_uInt32 getMaxKey() const;
 };
 
 #endif
diff --git a/sc/inc/scabstdlg.hxx b/sc/inc/scabstdlg.hxx
index 8c6c6c5..4f946f7 100644
--- a/sc/inc/scabstdlg.hxx
+++ b/sc/inc/scabstdlg.hxx
@@ -79,7 +79,9 @@ class AbstractScCondFormatManagerDlg : public 
VclAbstractDialog
 public:
     virtual ScConditionalFormatList* GetConditionalFormatList() = 0;
 
-    virtual bool CondFormatsChanged() = 0;
+    virtual bool CondFormatsChanged() const = 0;
+
+    virtual void SetModified() = 0;
 
     virtual ScConditionalFormat* GetCondFormatSelected() = 0;
 };
diff --git a/sc/inc/scitems.hxx b/sc/inc/scitems.hxx
index 4e7adb1..6664e91 100644
--- a/sc/inc/scitems.hxx
+++ b/sc/inc/scitems.hxx
@@ -41,8 +41,9 @@
 #define SCITEM_SOLVEDATA            1107
 #define SCITEM_USERLIST             1108
 #define SCITEM_PRINTWARN            1109
+#define SCITEM_CONDFORMATDLGDATA    1110
 
-#define MSGPOOL_END                 1109
+#define MSGPOOL_END                 1110
 
 // Item-IDs for attributes:
 
diff --git a/sc/source/core/data/conditio.cxx b/sc/source/core/data/conditio.cxx
index 684498c..7fd1ef5 100644
--- a/sc/source/core/data/conditio.cxx
+++ b/sc/source/core/data/conditio.cxx
@@ -2290,4 +2290,16 @@ void ScConditionalFormatList::clear()
     m_ConditionalFormats.clear();
 }
 
+sal_uInt32 ScConditionalFormatList::getMaxKey() const
+{
+    sal_uInt32 nMax = 0;
+    for (const auto& aEntry : m_ConditionalFormats)
+    {
+        if (aEntry->GetKey() > nMax)
+            nMax = aEntry->GetKey();
+    }
+
+    return nMax;
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/core/data/table1.cxx b/sc/source/core/data/table1.cxx
index 277f6c1..5679f2a 100644
--- a/sc/source/core/data/table1.cxx
+++ b/sc/source/core/data/table1.cxx
@@ -2106,14 +2106,7 @@ sal_uLong ScTable::AddCondFormat( ScConditionalFormat* 
pNew )
     if(!mpCondFormatList)
         mpCondFormatList.reset(new ScConditionalFormatList());
 
-    sal_uLong nMax = 0;
-    for(ScConditionalFormatList::const_iterator itr = 
mpCondFormatList->begin();
-            itr != mpCondFormatList->end(); ++itr)
-    {
-        sal_uLong nKey = (*itr)->GetKey();
-        if(nKey > nMax)
-            nMax = nKey;
-    }
+    sal_uInt32 nMax = mpCondFormatList->getMaxKey();
 
     pNew->SetKey(nMax+1);
     mpCondFormatList->InsertNew(pNew);
diff --git a/sc/source/ui/app/msgpool.cxx b/sc/source/ui/app/msgpool.cxx
index caa8aaa..e309c41 100644
--- a/sc/source/ui/app/msgpool.cxx
+++ b/sc/source/ui/app/msgpool.cxx
@@ -35,7 +35,8 @@ static SfxItemInfo const aMsgItemInfos[] =
     { SID_PIVOT_TABLE,           true },   // SCITEM_PIVOTDATA
     { SID_SOLVE,                 true },   // SCITEM_SOLVEDATA
     { SID_SCUSERLISTS,           true },   // SCITEM_USERLIST
-    { SID_PRINTER_NOTFOUND_WARN, true }    // SCITEM_PRINTWARN
+    { SID_PRINTER_NOTFOUND_WARN, true },   // SCITEM_PRINTWARN
+    { 0,                         false }  // SCITEM_CONDFORMATDLGDATA
 };
 
 ScMessagePool::ScMessagePool()
@@ -53,7 +54,8 @@ ScMessagePool::ScMessagePool()
     aGlobalSolveItem        ( ScSolveItem           ( SCITEM_SOLVEDATA, 
nullptr ) ),
     aGlobalUserListItem     ( ScUserListItem        ( SCITEM_USERLIST ) ),
 
-    aPrintWarnItem          ( SfxBoolItem           ( SCITEM_PRINTWARN, false 
) )
+    aPrintWarnItem          ( SfxBoolItem           ( SCITEM_PRINTWARN, false 
) ),
+    aCondFormatDlgItem      ( ScCondFormatDlgItem   ( nullptr, -1, false ) )
 {
     ppPoolDefaults = new SfxPoolItem*[MSGPOOL_END - MSGPOOL_START + 1];
 
@@ -67,6 +69,7 @@ ScMessagePool::ScMessagePool()
     ppPoolDefaults[SCITEM_SOLVEDATA         - MSGPOOL_START] = 
&aGlobalSolveItem;
     ppPoolDefaults[SCITEM_USERLIST          - MSGPOOL_START] = 
&aGlobalUserListItem;
     ppPoolDefaults[SCITEM_PRINTWARN         - MSGPOOL_START] = &aPrintWarnItem;
+    ppPoolDefaults[SCITEM_CONDFORMATDLGDATA - MSGPOOL_START] = 
&aCondFormatDlgItem;
 
     SetDefaults( ppPoolDefaults );
 
diff --git a/sc/source/ui/attrdlg/scdlgfact.cxx 
b/sc/source/ui/attrdlg/scdlgfact.cxx
index 5b26fec..6bf050d 100644
--- a/sc/source/ui/attrdlg/scdlgfact.cxx
+++ b/sc/source/ui/attrdlg/scdlgfact.cxx
@@ -423,11 +423,16 @@ ScConditionalFormatList* 
AbstractScCondFormatManagerDlg_Impl::GetConditionalForm
     return pDlg->GetConditionalFormatList();
 }
 
-bool AbstractScCondFormatManagerDlg_Impl::CondFormatsChanged()
+bool AbstractScCondFormatManagerDlg_Impl::CondFormatsChanged() const
 {
     return pDlg->CondFormatsChanged();
 }
 
+void AbstractScCondFormatManagerDlg_Impl::SetModified()
+{
+    return pDlg->SetModified();
+}
+
 ScConditionalFormat* 
AbstractScCondFormatManagerDlg_Impl::GetCondFormatSelected()
 {
     return pDlg->GetCondFormatSelected();
diff --git a/sc/source/ui/attrdlg/scdlgfact.hxx 
b/sc/source/ui/attrdlg/scdlgfact.hxx
index d2d3626..ea9ea53 100644
--- a/sc/source/ui/attrdlg/scdlgfact.hxx
+++ b/sc/source/ui/attrdlg/scdlgfact.hxx
@@ -130,7 +130,9 @@ class AbstractScCondFormatManagerDlg_Impl : public 
AbstractScCondFormatManagerDl
 
     virtual ScConditionalFormatList* GetConditionalFormatList() override;
 
-    virtual bool CondFormatsChanged() override;
+    virtual bool CondFormatsChanged() const override;
+
+    virtual void SetModified() override;
 
     virtual ScConditionalFormat* GetCondFormatSelected() override;
 };
diff --git a/sc/source/ui/condformat/condformatdlg.cxx 
b/sc/source/ui/condformat/condformatdlg.cxx
index 8f0d621..c5f4870 100644
--- a/sc/source/ui/condformat/condformatdlg.cxx
+++ b/sc/source/ui/condformat/condformatdlg.cxx
@@ -33,6 +33,7 @@
 #include "docsh.hxx"
 #include "docfunc.hxx"
 #include "condformatdlgentry.hxx"
+#include "condformatdlgitem.hxx"
 
 #include "globstr.hrc"
 
@@ -412,19 +413,14 @@ IMPL_LINK_NOARG_TYPED( ScCondFormatList, ScrollHdl, 
ScrollBar*, void )
     DoScroll(mpScrollBar->GetDelta());
 }
 
-// Conditional Format Dialog
-//
 ScCondFormatDlg::ScCondFormatDlg(SfxBindings* pB, SfxChildWindow* pCW,
     vcl::Window* pParent, ScViewData* pViewData,
-    const ScConditionalFormat* pFormat, const ScRangeList& rRange,
-    const ScAddress& rPos, condformat::dialog::ScCondFormatDialogType eType,
-    bool bManaged)
+    const ScCondFormatDlgItem* pItem)
         : ScAnyRefDlg(pB, pCW, pParent, "ConditionalFormatDialog",
                         "modules/scalc/ui/conditionalformatdialog.ui")
-    , mbManaged(bManaged)
-    , maPos(rPos)
     , mpViewData(pViewData)
     , mpLastEdit(nullptr)
+    , mpDlgItem(static_cast<ScCondFormatDlgItem*>(pItem->Clone()))
 {
     get(mpBtnOk, "ok");
     get(mpBtnAdd, "add");
@@ -438,10 +434,39 @@ ScCondFormatDlg::ScCondFormatDlg(SfxBindings* pB, 
SfxChildWindow* pCW,
     get(mpRbRange, "rbassign");
     mpRbRange->SetReferences(this, mpEdRange);
 
-    maKey = pFormat ? pFormat->GetKey() : 0;
+    ScConditionalFormat* pFormat = nullptr;
+    mnKey = mpDlgItem->GetIndex();
+    if (mpDlgItem->IsManaged() && mpDlgItem->GetConditionalFormatList())
+    {
+        pFormat = mpDlgItem->GetConditionalFormatList()->GetFormat(mnKey);
+    }
+    else if (!mpDlgItem->IsManaged())
+    {
+        ScDocument* pDoc = mpViewData->GetDocument();
+        pFormat = pDoc->GetCondFormList(mpViewData->GetTabNo())->GetFormat ( 
mnKey );
+    }
+
+    ScRangeList aRange;
+    if (pFormat)
+    {
+        aRange = pFormat->GetRange();
+    }
+    else
+    {
+        // this is for adding a new entry
+        mpViewData->GetMarkData().FillRangeListWithMarks(&aRange, false);
+        if(aRange.empty())
+        {
+            ScAddress aPos(mpViewData->GetCurX(), mpViewData->GetCurY(), 
mpViewData->GetTabNo());
+            ScRange* pRange = new ScRange(aPos);
+            aRange.push_back(pRange);
+        }
+        mnKey = 0;
+    }
+    maPos = aRange.GetTopLeftCorner();
 
     get(mpCondFormList, "list");
-    mpCondFormList->init(mpViewData->GetDocument(), this, pFormat, rRange, 
rPos, eType);
+    mpCondFormList->init(mpViewData->GetDocument(), this, pFormat, aRange, 
maPos, mpDlgItem->GetDialogType());
 
     mpBtnOk->SetClickHdl(LINK(this, ScCondFormatDlg, BtnPressedHdl ) );
     mpBtnAdd->SetClickHdl( LINK( mpCondFormList, ScCondFormatList, AddBtnHdl ) 
);
@@ -451,7 +476,7 @@ ScCondFormatDlg::ScCondFormatDlg(SfxBindings* pB, 
SfxChildWindow* pCW,
     mpEdRange->SetGetFocusHdl( LINK( this, ScCondFormatDlg, RangeGetFocusHdl ) 
);
 
     OUString aRangeString;
-    rRange.Format(aRangeString, ScRefFlags::VALID, pViewData->GetDocument(),
+    aRange.Format(aRangeString, ScRefFlags::VALID, pViewData->GetDocument(),
                     pViewData->GetDocument()->GetAddressConvention());
     mpEdRange->SetText(aRangeString);
 
@@ -589,15 +614,29 @@ void ScCondFormatDlg::OkPressed()
 {
     ScConditionalFormat* pFormat = GetConditionalFormat();
 
-    if(pFormat)
-        mpViewData->GetDocShell()->GetDocFunc().ReplaceConditionalFormat(maKey,
-            pFormat, maPos.Tab(), pFormat->GetRange());
+    if (!mpDlgItem->IsManaged())
+    {
+        if(pFormat)
+            
mpViewData->GetDocShell()->GetDocFunc().ReplaceConditionalFormat(mnKey,
+                    pFormat, maPos.Tab(), pFormat->GetRange());
+        else
+            
mpViewData->GetDocShell()->GetDocFunc().ReplaceConditionalFormat(mnKey,
+                    nullptr, maPos.Tab(), ScRangeList());
+    }
     else
-        mpViewData->GetDocShell()->GetDocFunc().ReplaceConditionalFormat(maKey,
-            nullptr, maPos.Tab(), ScRangeList());
-
-    if ( mbManaged )
     {
+        ScConditionalFormatList* pList = mpDlgItem->GetConditionalFormatList();
+        sal_uInt32 nKey = mnKey;
+        if (mnKey == 0)
+        {
+            nKey = pList->getMaxKey() + 1;
+        }
+
+        pFormat->SetKey(nKey);
+        pList->erase(nKey);
+        pList->InsertNew(pFormat);
+        mpViewData->GetViewShell()->GetPool().Put(*mpDlgItem);
+
         SetDispatcherLock( false );
         // Queue message to open Conditional Format Manager Dialog
         GetBindings().GetDispatcher()->Execute( SID_OPENDLG_CONDFRMT_MANAGER,
@@ -610,8 +649,9 @@ void ScCondFormatDlg::OkPressed()
 //
 void ScCondFormatDlg::CancelPressed()
 {
-    if ( mbManaged )
+    if ( mpDlgItem->IsManaged() )
     {
+        mpViewData->GetViewShell()->GetPool().Put(*mpDlgItem);
         SetDispatcherLock( false );
         // Queue message to open Conditional Format Manager Dialog
         GetBindings().GetDispatcher()->Execute( SID_OPENDLG_CONDFRMT_MANAGER,
@@ -620,142 +660,6 @@ void ScCondFormatDlg::CancelPressed()
     Close();
 }
 
-// Parse xml string parameters used to initialize the Conditional Format Dialog
-// when it is created.
-//
-bool ScCondFormatDlg::ParseXmlString(const OUString&    sXMLString,
-                                     sal_uInt32&        nIndex,
-                                     sal_uInt8&         nType,
-                                     bool&              bManaged)
-{
-    bool bRetVal = false;
-    OString sTagName;
-    OUString sTagValue;
-
-    xmlNodePtr      pXmlRoot  = nullptr;
-    xmlNodePtr      pXmlNode  = nullptr;
-
-    OString sOString = OUStringToOString( sXMLString, RTL_TEXTENCODING_UTF8 );
-    xmlDocPtr pXmlDoc = xmlParseMemory(sOString.getStr(), 
sOString.getLength());
-
-    if( pXmlDoc )
-    {
-        bRetVal = true;
-        pXmlRoot = xmlDocGetRootElement( pXmlDoc );
-        pXmlNode = pXmlRoot->children;
-
-        while (pXmlNode != nullptr && bRetVal)
-        {
-            sTagName  = OUStringToOString("Index", RTL_TEXTENCODING_UTF8);
-            if (xmlStrcmp(pXmlNode->name, reinterpret_cast<xmlChar const 
*>(sTagName.getStr())) == 0)
-            {
-                if (pXmlNode->children != nullptr && pXmlNode->children->type 
== XML_TEXT_NODE)
-                {
-                    sTagValue = 
OUString(reinterpret_cast<char*>(pXmlNode->children->content),
-                                     
strlen(reinterpret_cast<char*>(pXmlNode->children->content)),
-                                     RTL_TEXTENCODING_UTF8);
-                    nIndex   = sTagValue.toUInt32();
-                    pXmlNode = pXmlNode->next;
-                    continue;
-                }
-            }
-
-            sTagName  = OUStringToOString("Type", RTL_TEXTENCODING_UTF8);
-            if (xmlStrcmp(pXmlNode->name, reinterpret_cast<xmlChar const 
*>(sTagName.getStr())) == 0)
-            {
-                if (pXmlNode->children != nullptr && pXmlNode->children->type 
== XML_TEXT_NODE)
-                {
-                    sTagValue = 
OUString(reinterpret_cast<char*>(pXmlNode->children->content),
-                                     
strlen(reinterpret_cast<char*>(pXmlNode->children->content)),
-                                     RTL_TEXTENCODING_UTF8);
-                    nType    = sTagValue.toUInt32();
-                    pXmlNode = pXmlNode->next;
-                    continue;
-                }
-            }
-
-            sTagName  = OUStringToOString("Managed", RTL_TEXTENCODING_UTF8);
-            if (xmlStrcmp(pXmlNode->name, reinterpret_cast<xmlChar const 
*>(sTagName.getStr())) == 0)
-            {
-                if (pXmlNode->children != nullptr && pXmlNode->children->type 
== XML_TEXT_NODE)
-                {
-                    sTagValue = 
OUString(reinterpret_cast<char*>(pXmlNode->children->content),
-                                     
strlen(reinterpret_cast<char*>(pXmlNode->children->content)),
-                                     RTL_TEXTENCODING_UTF8);
-                    bManaged = sTagValue.toBoolean();
-                    pXmlNode = pXmlNode->next;
-                    continue;
-                }
-            }
-            bRetVal = false;
-        }
-    }
-
-    xmlFreeDoc(pXmlDoc);
-    return bRetVal;
-}
-
-// Generate xml string parameters used to initialize the Conditional Format 
Dialog
-// when it is created.
-//
-OUString ScCondFormatDlg::GenerateXmlString(sal_uInt32 nIndex, sal_uInt8 
nType, bool bManaged)
-{
-    OUString sReturn;
-
-    OString sTagName;
-    OString sTagValue;
-
-    xmlNodePtr      pXmlRoot  = nullptr;
-    xmlNodePtr      pXmlNode  = nullptr;
-
-    xmlChar*        pBuffer   = nullptr;
-    const xmlChar*  pTagName  = nullptr;
-    const xmlChar*  pTagValue = nullptr;
-
-    xmlDocPtr pXmlDoc = xmlNewDoc(reinterpret_cast<const xmlChar*>("1.0"));
-
-    sTagName = OUStringToOString("ScCondFormatDlg", RTL_TEXTENCODING_UTF8);
-    pTagName = reinterpret_cast<const xmlChar*>(sTagName.getStr());
-    pXmlRoot = xmlNewDocNode(pXmlDoc, nullptr, pTagName, nullptr);
-
-    xmlDocSetRootElement(pXmlDoc, pXmlRoot);
-
-    sTagName  = OUStringToOString("Index", RTL_TEXTENCODING_UTF8);
-    sTagValue = OUStringToOString(OUString::number(nIndex), 
RTL_TEXTENCODING_UTF8);
-    pTagName  = reinterpret_cast<const xmlChar*>(sTagName.getStr());
-    pTagValue = reinterpret_cast<const xmlChar*>(sTagValue.getStr());
-    pXmlNode  = xmlNewDocNode(pXmlDoc, nullptr, pTagName, pTagValue);
-
-    xmlAddChild(pXmlRoot, pXmlNode);
-
-    sTagName  = OUStringToOString("Type", RTL_TEXTENCODING_UTF8);
-    sTagValue = OUStringToOString(OUString::number(nType), 
RTL_TEXTENCODING_UTF8);
-    pTagName  = reinterpret_cast<const xmlChar*>(sTagName.getStr());
-    pTagValue = reinterpret_cast<const xmlChar*>(sTagValue.getStr());
-    pXmlNode  = xmlNewDocNode(pXmlDoc, nullptr, pTagName, pTagValue);
-
-    xmlAddChild(pXmlRoot, pXmlNode);
-
-    sTagName  = OUStringToOString("Managed", RTL_TEXTENCODING_UTF8);
-    sTagValue = OUStringToOString(OUString::boolean(bManaged), 
RTL_TEXTENCODING_UTF8);
-    pTagName  = reinterpret_cast<const xmlChar*>(sTagName.getStr());
-    pTagValue = reinterpret_cast<const xmlChar*>(sTagValue.getStr());
-    pXmlNode  = xmlNewDocNode(pXmlDoc, nullptr, pTagName, pTagValue);
-
-    xmlAddChild(pXmlRoot, pXmlNode);
-
-    int nSize = 0;
-    xmlDocDumpMemory(pXmlDoc, &pBuffer, &nSize);
-
-    sReturn = OUString(reinterpret_cast<char const *>(pBuffer), nSize, 
RTL_TEXTENCODING_UTF8);
-
-    xmlFree(pBuffer);
-    xmlFreeDoc(pXmlDoc);
-
-    return sReturn;
-}
-
-
 IMPL_LINK_TYPED( ScCondFormatDlg, EdRangeModifyHdl, Edit&, rEdit, void )
 {
     OUString aRangeStr = rEdit.GetText();
@@ -775,8 +679,6 @@ IMPL_LINK_TYPED( ScCondFormatDlg, RangeGetFocusHdl, 
Control&, rControl, void )
     mpLastEdit = static_cast<formula::RefEdit*>(&rControl);
 }
 
-// Conditional Format Dialog button click event handler.
-//
 IMPL_LINK_TYPED( ScCondFormatDlg, BtnPressedHdl, Button*, pBtn, void)
 {
     if (pBtn == mpBtnOk)
diff --git a/sc/source/ui/condformat/condformatdlgitem.cxx 
b/sc/source/ui/condformat/condformatdlgitem.cxx
new file mode 100644
index 0000000..a4ef079
--- /dev/null
+++ b/sc/source/ui/condformat/condformatdlgitem.cxx
@@ -0,0 +1,77 @@
+/* -*- 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/.
+ */
+
+
+#include "scitems.hxx"
+#include "condformatdlgitem.hxx"
+
+ScCondFormatDlgItem::ScCondFormatDlgItem():
+    SfxPoolItem(SCITEM_CONDFORMATDLGDATA),
+    mpCondFormats(),
+    mnItem(-1),
+    meDialogType(condformat::dialog::CONDITION),
+    mbManaged(false)
+{
+}
+
+ScCondFormatDlgItem::ScCondFormatDlgItem(std::shared_ptr<ScConditionalFormatList>
 pCondFormats,
+        sal_Int32 nItem, bool bManaged):
+    SfxPoolItem(SCITEM_CONDFORMATDLGDATA),
+    mpCondFormats(pCondFormats),
+    mnItem(nItem),
+    meDialogType(condformat::dialog::CONDITION),
+    mbManaged(bManaged)
+{
+}
+
+ScCondFormatDlgItem::~ScCondFormatDlgItem()
+{
+}
+
+bool ScCondFormatDlgItem::operator==(const SfxPoolItem& /*rItem*/) const
+{
+    return false;
+}
+
+SfxPoolItem* ScCondFormatDlgItem::Clone(SfxItemPool* /*pPool*/) const
+{
+    return new ScCondFormatDlgItem(*this);
+}
+
+SfxPoolItem* ScCondFormatDlgItem::Create(SvStream& /*rStrm*/, sal_uInt16 
/*nVer*/) const
+{
+    return nullptr;
+}
+
+bool ScCondFormatDlgItem::IsManaged() const
+{
+    return mbManaged;
+}
+
+condformat::dialog::ScCondFormatDialogType 
ScCondFormatDlgItem::GetDialogType() const
+{
+    return meDialogType;
+}
+
+sal_Int32 ScCondFormatDlgItem::GetIndex() const
+{
+    return mnItem;
+}
+
+ScConditionalFormatList* ScCondFormatDlgItem::GetConditionalFormatList()
+{
+    return mpCondFormats.get();
+}
+
+void 
ScCondFormatDlgItem::SetDialogType(condformat::dialog::ScCondFormatDialogType 
eType)
+{
+    meDialogType = eType;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/condformat/condformatmgr.cxx 
b/sc/source/ui/condformat/condformatmgr.cxx
index 69ad5a2..e310a64 100644
--- a/sc/source/ui/condformat/condformatmgr.cxx
+++ b/sc/source/ui/condformat/condformatmgr.cxx
@@ -161,6 +161,7 @@ IMPL_LINK_NOARG_TYPED(ScCondFormatManagerDlg, RemoveBtnHdl, 
Button*, void)
 
 IMPL_LINK_NOARG_TYPED(ScCondFormatManagerDlg, EditBtnClickHdl, Button*, void)
 {
+    mbModified = true;
     EditBtnHdl(nullptr);
 }
 IMPL_LINK_NOARG_TYPED(ScCondFormatManagerDlg, EditBtnHdl, SvTreeListBox*, bool)
@@ -170,6 +171,7 @@ IMPL_LINK_NOARG_TYPED(ScCondFormatManagerDlg, EditBtnHdl, 
SvTreeListBox*, bool)
     if(!pFormat)
         return false;
 
+    mbModified = true;
     EndDialog( DLG_RET_EDIT );
 
     return false;
@@ -177,7 +179,18 @@ IMPL_LINK_NOARG_TYPED(ScCondFormatManagerDlg, EditBtnHdl, 
SvTreeListBox*, bool)
 
 IMPL_LINK_NOARG_TYPED(ScCondFormatManagerDlg, AddBtnHdl, Button*, void)
 {
+    mbModified = true;
     EndDialog( DLG_RET_ADD );
 }
 
+void ScCondFormatManagerDlg::SetModified()
+{
+    mbModified = true;
+}
+
+bool ScCondFormatManagerDlg::CondFormatsChanged() const
+{
+    return mbModified;
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/inc/condformatdlg.hxx 
b/sc/source/ui/inc/condformatdlg.hxx
index 212b204..42b39a8 100644
--- a/sc/source/ui/inc/condformatdlg.hxx
+++ b/sc/source/ui/inc/condformatdlg.hxx
@@ -22,9 +22,12 @@
 #include "rangelst.hxx"
 #include "condformathelper.hxx"
 #include "viewdata.hxx"
+#include "condformatdlgitem.hxx"
 
 #include "anyrefdg.hxx"
 
+#include <memory>
+
 #define DLG_RET_ADD         8
 #define DLG_RET_EDIT        16
 
@@ -35,24 +38,6 @@ class ScConditionalFormat;
 struct ScDataBarFormatData;
 class ScCondFrmtEntry;
 
-namespace condformat {
-
-namespace dialog {
-
-enum ScCondFormatDialogType
-{
-    NONE,
-    CONDITION,
-    COLORSCALE,
-    DATABAR,
-    ICONSET,
-    DATE
-};
-
-}
-
-}
-
 class ScCondFormatDlg;
 
 class ScCondFormatList : public Control
@@ -108,14 +93,15 @@ private:
     VclPtr<formula::RefButton> mpRbRange;
 
     VclPtr<ScCondFormatList> mpCondFormList;
-    sal_Int32 maKey;
+    sal_Int32 mnKey;
 
-    bool mbManaged;
     ScAddress maPos;
     ScViewData* mpViewData;
 
     VclPtr<formula::RefEdit> mpLastEdit;
 
+    std::shared_ptr<ScCondFormatDlgItem> mpDlgItem;
+
     OUString msBaseTitle;
     void updateTitle();
 
@@ -128,17 +114,12 @@ protected:
 
 public:
     SC_DLLPUBLIC ScCondFormatDlg(SfxBindings* pB, SfxChildWindow* pCW, 
vcl::Window* pWindow,
-                                 ScViewData* pViewData, const 
ScConditionalFormat* pFormat,
-                                 const ScRangeList& rRange, const ScAddress& 
rPos,
-                                 condformat::dialog::ScCondFormatDialogType 
eType, bool bManaged);
+                                 ScViewData* pViewData, const 
ScCondFormatDlgItem* pDlgItem);
     virtual ~ScCondFormatDlg();
     virtual void dispose() override;
 
     SC_DLLPUBLIC ScConditionalFormat* GetConditionalFormat() const;
 
-    static OUString GenerateXmlString(sal_uInt32 nIndex, sal_uInt8 nType, bool 
bManaged);
-    static bool ParseXmlString(const OUString& sXMLString, sal_uInt32& nIndex,
-                               sal_uInt8& nType, bool& bManaged);
     virtual void SetReference(const ScRange&, ScDocument*) override;
     virtual bool IsRefInputMode() const override;
     virtual void SetActive() override;
diff --git a/sc/source/ui/inc/condformatdlgitem.hxx 
b/sc/source/ui/inc/condformatdlgitem.hxx
new file mode 100644
index 0000000..d974b2c
--- /dev/null
+++ b/sc/source/ui/inc/condformatdlgitem.hxx
@@ -0,0 +1,68 @@
+/* -*- 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/.
+ */
+
+#ifndef INCLUDED_SC_SOURCE_UI_INC_CONDFORMATDLGITEM_HXX
+#define INCLUDED_SC_SOURCE_UI_INC_CONDFORMATDLGITEM_HXX
+
+#include <svl/poolitem.hxx>
+
+#include <memory>
+
+namespace condformat {
+
+namespace dialog {
+
+enum ScCondFormatDialogType
+{
+    NONE,
+    CONDITION,
+    COLORSCALE,
+    DATABAR,
+    ICONSET,
+    DATE
+};
+
+}
+
+}
+
+class ScConditionalFormatList;
+
+class ScCondFormatDlgItem : public SfxPoolItem
+{
+public:
+
+    ScCondFormatDlgItem();
+    ScCondFormatDlgItem(std::shared_ptr<ScConditionalFormatList> pCondFormats, 
sal_Int32 nItem, bool bManaged);
+
+    virtual ~ScCondFormatDlgItem() override;
+
+    virtual bool operator==(const SfxPoolItem&) const override;
+    virtual SfxPoolItem* Clone(SfxItemPool* pPool = nullptr) const override;
+    virtual SfxPoolItem* Create(SvStream& rStream, sal_uInt16 nVer) const 
override;
+
+    bool IsManaged() const;
+    condformat::dialog::ScCondFormatDialogType GetDialogType() const;
+    sal_Int32 GetIndex() const;
+
+    void SetDialogType(condformat::dialog::ScCondFormatDialogType eType);
+
+    ScConditionalFormatList* GetConditionalFormatList();
+
+private:
+
+    std::shared_ptr<ScConditionalFormatList> mpCondFormats;
+    sal_Int32 mnItem;
+    condformat::dialog::ScCondFormatDialogType meDialogType;
+    bool mbManaged;
+};
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/ui/inc/condformatmgr.hxx 
b/sc/source/ui/inc/condformatmgr.hxx
index 013f716..983d53d 100644
--- a/sc/source/ui/inc/condformatmgr.hxx
+++ b/sc/source/ui/inc/condformatmgr.hxx
@@ -53,7 +53,8 @@ public:
 
     ScConditionalFormatList* GetConditionalFormatList();
 
-    bool CondFormatsChanged() { return mbModified;}
+    bool CondFormatsChanged() const;
+    void SetModified();
 
     ScConditionalFormat* GetCondFormatSelected();
 
diff --git a/sc/source/ui/inc/msgpool.hxx b/sc/source/ui/inc/msgpool.hxx
index 1985aa0..581bf1c 100644
--- a/sc/source/ui/inc/msgpool.hxx
+++ b/sc/source/ui/inc/msgpool.hxx
@@ -28,6 +28,7 @@
 #include <svl/eitem.hxx>
 
 #include "uiitems.hxx"
+#include "condformatdlgitem.hxx"
 
 class ScDocumentPool;
 
@@ -44,6 +45,7 @@ class ScMessagePool: public SfxItemPool
     ScUserListItem      aGlobalUserListItem;
 
     SfxBoolItem         aPrintWarnItem;
+    ScCondFormatDlgItem aCondFormatDlgItem;
 
     SfxPoolItem**   ppPoolDefaults;
     ScDocumentPool* pDocPool;
diff --git a/sc/source/ui/view/cellsh1.cxx b/sc/source/ui/view/cellsh1.cxx
index 10a3430..c16d042 100644
--- a/sc/source/ui/view/cellsh1.cxx
+++ b/sc/source/ui/view/cellsh1.cxx
@@ -77,6 +77,7 @@
 #include "docpool.hxx"
 #include "condformatdlg.hxx"
 #include "attrib.hxx"
+#include "condformatdlgitem.hxx"
 
 #include "globstr.hrc"
 #include "scui_def.hxx"
@@ -1935,20 +1936,18 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq )
         case SID_OPENDLG_CONDDATE:
             {
                 sal_uInt32  nIndex      = sal_uInt32(-1);
-                sal_uInt8   nType       = 0;
                 bool        bManaged    = false;
 
-                // Get the pool item stored it by Conditional Format Manager 
Dialog.
-                sal_uInt32 nItems(pTabViewShell->GetPool().GetItemCount2( 
SCITEM_STRING ));
+                // Get the pool item stored by Conditional Format Manager 
Dialog.
+                sal_uInt32 nItems(pTabViewShell->GetPool().GetItemCount2( 
SCITEM_CONDFORMATDLGDATA ));
                 for( sal_uInt32 nIter = 0; nIter < nItems; ++nIter )
                 {
-                    const SfxPoolItem* pItem = 
pTabViewShell->GetPool().GetItem2( SCITEM_STRING, nIter );
+                    const SfxPoolItem* pItem = 
pTabViewShell->GetPool().GetItem2( SCITEM_CONDFORMATDLGDATA, nIter );
                     if( pItem != nullptr )
                     {
-                        if ( ScCondFormatDlg::ParseXmlString(
-                                static_cast<const 
SfxStringItem*>(pItem)->GetValue(),
-                                nIndex, nType, bManaged))
-                            break;
+                        const ScCondFormatDlgItem* pDlgItem = 
static_cast<const ScCondFormatDlgItem*>(pItem);
+                        nIndex = pDlgItem->GetIndex();
+                        break;
                     }
                 }
 
@@ -2071,12 +2070,9 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq )
                 {
                     // Put the xml string parameter to initialize the
                     // Conditional Format Dialog.
-                    pTabViewShell->GetPool().Put( SfxStringItem( SCITEM_STRING,
-                                                      
ScCondFormatDlg::GenerateXmlString(
-                                                        pCondFormat ? 
pCondFormat->GetKey() : sal_uInt32(-1),
-                                                        sal_uInt8(eType),
-                                                        false
-                                                      ) ) );
+                    ScCondFormatDlgItem aDlgItem(nullptr, nIndex, false);
+                    aDlgItem.SetDialogType(eType);
+                    pTabViewShell->GetPool().Put(aDlgItem);
 
                     sal_uInt16      nId      = 
ScCondFormatDlgWrapper::GetChildWindowId();
                     SfxViewFrame*   pViewFrm = pTabViewShell->GetViewFrame();
@@ -2425,7 +2421,7 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq )
         case SID_OPENDLG_CONDFRMT_MANAGER:
             {
                 ScAbstractDialogFactory* pFact = 
ScAbstractDialogFactory::Create();
-                OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
+                assert(pFact);
 
                 ScViewData* pData = GetViewData();
                 ScDocument* pDoc = pData->GetDocument();
@@ -2438,44 +2434,62 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq )
 
                 ScAddress aPos(pData->GetCurX(), pData->GetCurY(), 
pData->GetTabNo());
 
-                ScConditionalFormatList* pList = pDoc->GetCondFormList( 
aPos.Tab() );
+                ScConditionalFormatList* pList = nullptr;
+
+                sal_uInt32 nItems(pTabViewShell->GetPool().GetItemCount2( 
SCITEM_CONDFORMATDLGDATA ));
+                const ScCondFormatDlgItem* pDlgItem = nullptr;
+                for( sal_uInt32 nIter = 0; nIter < nItems; ++nIter )
+                {
+                    const SfxPoolItem* pItem = 
pTabViewShell->GetPool().GetItem2( SCITEM_CONDFORMATDLGDATA, nIter );
+                    if( pItem != nullptr )
+                    {
+                        pDlgItem= static_cast<const 
ScCondFormatDlgItem*>(pItem);
+                        pList = 
const_cast<ScCondFormatDlgItem*>(pDlgItem)->GetConditionalFormatList();
+                        break;
+                    }
+                }
+
+                if (!pList)
+                    pList = pDoc->GetCondFormList( aPos.Tab() );
+
                 std::unique_ptr<AbstractScCondFormatManagerDlg> 
pDlg(pFact->CreateScCondFormatMgrDlg(
                     pTabViewShell->GetDialogParent(), pDoc, pList, 
RID_SCDLG_COND_FORMAT_MANAGER));
+
+                if (pDlgItem)
+                    pDlg->SetModified();
+
                 short nRet = pDlg->Execute();
+                ScConditionalFormatList* pCondFormatList = 
pDlg->GetConditionalFormatList();
                 if(nRet == RET_OK && pDlg->CondFormatsChanged())
                 {
-                    ScConditionalFormatList* pCondFormatList = 
pDlg->GetConditionalFormatList();
                     
pData->GetDocShell()->GetDocFunc().SetConditionalFormatList(pCondFormatList, 
aPos.Tab());
                 }
                 else if(nRet == DLG_RET_ADD)
                 {
                     // Put the xml string parameter to initialize the
                     // Conditional Format Dialog. ( add new )
-                    pTabViewShell->GetPool().Put( SfxStringItem( SCITEM_STRING,
-                                                      
ScCondFormatDlg::GenerateXmlString(
-                                                        sal_uInt32(-1),
-                                                        
sal_uInt8(condformat::dialog::ScCondFormatDialogType::CONDITION),
-                                                        true
-                                                      ) ) );
-
+                    pTabViewShell->GetPool().Put(ScCondFormatDlgItem(
+                                
std::shared_ptr<ScConditionalFormatList>(pCondFormatList), -1, true));
                     // Queue message to open Conditional Format Dialog
                     GetViewData()->GetDispatcher().Execute( 
SID_OPENDLG_CONDFRMT, SfxCallMode::ASYNCHRON );
                 }
                 else if (nRet == DLG_RET_EDIT)
                 {
                     ScConditionalFormat* pFormat = 
pDlg->GetCondFormatSelected();
+                    sal_Int32 nIndex = pFormat ? pFormat->GetKey() : -1;
                     // Put the xml string parameter to initialize the
                     // Conditional Format Dialog. ( edit selected conditional 
format )
-                    pTabViewShell->GetPool().Put( SfxStringItem( SCITEM_STRING,
-                                                      
ScCondFormatDlg::GenerateXmlString(
-                                                        pFormat ? 
pFormat->GetKey() : sal_uInt32(-1),
-                                                        
sal_uInt8(condformat::dialog::ScCondFormatDialogType::CONDITION),
-                                                        true
-                                                      ) ) );
+                    pTabViewShell->GetPool().Put(ScCondFormatDlgItem(
+                                
std::shared_ptr<ScConditionalFormatList>(pCondFormatList), nIndex, true));
 
                     // Queue message to open Conditional Format Dialog
                     GetViewData()->GetDispatcher().Execute( 
SID_OPENDLG_CONDFRMT, SfxCallMode::ASYNCHRON );
                 }
+                else
+                    delete pCondFormatList;
+
+                if (pDlgItem)
+                    pTabViewShell->GetPool().Remove(*pDlgItem);
             }
             break;
 
diff --git a/sc/source/ui/view/tabvwshc.cxx b/sc/source/ui/view/tabvwshc.cxx
index bfe6d8e..5b4b073 100644
--- a/sc/source/ui/view/tabvwshc.cxx
+++ b/sc/source/ui/view/tabvwshc.cxx
@@ -57,6 +57,7 @@
 #include "reffact.hxx"
 #include "condformatdlg.hxx"
 #include "xmlsourcedlg.hxx"
+#include "condformatdlgitem.hxx"
 
 #include "RandomNumberGeneratorDialog.hxx"
 #include "SamplingDialog.hxx"
@@ -467,55 +468,27 @@ VclPtr<SfxModelessDialog> ScTabViewShell::CreateRefDialog(
 
         case WID_CONDFRMT_REF:
         {
-            sal_uInt32  nIndex      = sal_uInt32(-1);
-            sal_uInt8   nType       = 0;
-            bool        bManaged    = false;
             bool        bFound      = false;
-
-            ScRangeList aRangeList;
-            ScConditionalFormat* pCondFormat;
-            condformat::dialog::ScCondFormatDialogType aDialogType;
-
-            // Get the pool item stored it by Conditional Format Manager 
Dialog.
+            const ScCondFormatDlgItem* pDlgItem = nullptr;
+            // Get the pool item stored by Conditional Format Manager Dialog.
             const SfxPoolItem* pItem = nullptr;
-            sal_uInt32 nItems(GetPool().GetItemCount2( SCITEM_STRING ));
+            sal_uInt32 nItems(GetPool().GetItemCount2( 
SCITEM_CONDFORMATDLGDATA ));
             for( sal_uInt32 nIter = 0; nIter < nItems; ++nIter )
             {
-                if( nullptr != (pItem = GetPool().GetItem2( SCITEM_STRING, 
nIter ) ) )
+                if( nullptr != (pItem = GetPool().GetItem2( 
SCITEM_CONDFORMATDLGDATA, nIter ) ) )
                 {
-                    if ( ScCondFormatDlg::ParseXmlString(
-                            static_cast<const 
SfxStringItem*>(pItem)->GetValue(),
-                            nIndex, nType, bManaged))
-                    {
-                        bFound = true;
-                        break;
-                    }
+                    pDlgItem = static_cast<const ScCondFormatDlgItem*>(pItem);
+                    bFound = true;
+                    break;
                 }
             }
 
             ScViewData& rViewData = GetViewData();
             rViewData.SetRefTabNo( rViewData.GetTabNo() );
 
-            aDialogType = static_cast< 
condformat::dialog::ScCondFormatDialogType > ( nType );
-            pCondFormat = 
pDoc->GetCondFormList(rViewData.GetTabNo())->GetFormat ( nIndex );
-
-            if ( pCondFormat )
-                aRangeList = pCondFormat->GetRange();
-            else
-            {
-                rViewData.GetMarkData().FillRangeListWithMarks(&aRangeList, 
false);
-                ScAddress aPos(rViewData.GetCurX(), rViewData.GetCurY(), 
rViewData.GetTabNo());
-                if(aRangeList.empty())
-                {
-                    ScRange* pRange = new ScRange(aPos);
-                    aRangeList.push_back(pRange);
-                }
-            }
-
-            pResult = VclPtr<ScCondFormatDlg>::Create( pB, pCW, pParent, 
&rViewData, pCondFormat, aRangeList,
-                aRangeList.GetTopLeftCorner(), aDialogType, bManaged );
+            pResult = VclPtr<ScCondFormatDlg>::Create( pB, pCW, pParent, 
&rViewData, pDlgItem );
 
-            // Remove the pool item stored it by Conditional Format Manager 
Dialog.
+            // Remove the pool item stored by Conditional Format Manager 
Dialog.
             if ( bFound && pItem )
                 GetPool().Remove( *pItem );
         }
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to