summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarkus Mohrhard <markus.mohrhard@googlemail.com>2016-09-18 16:14:35 +0200
committerMarkus Mohrhard <markus.mohrhard@googlemail.com>2016-09-19 10:10:09 +0000
commit5b8c22379e2eae74f7ed78326ab89483db5c6624 (patch)
tree60cbfdd24bca243b4a911ff1dab298ef91590b5b
parent96646c351e20fa6699fa368457a05ee70f76f103 (diff)
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. Change-Id: I9802be11cd15c2d2d877e55c91d836735fe0e0ff Reviewed-on: https://gerrit.libreoffice.org/28995 Reviewed-by: Markus Mohrhard <markus.mohrhard@googlemail.com> Tested-by: Markus Mohrhard <markus.mohrhard@googlemail.com>
-rw-r--r--sc/Library_sc.mk1
-rw-r--r--sc/inc/scabstdlg.hxx4
-rw-r--r--sc/inc/scitems.hxx3
-rw-r--r--sc/source/ui/app/msgpool.cxx4
-rw-r--r--sc/source/ui/attrdlg/scdlgfact.cxx7
-rw-r--r--sc/source/ui/attrdlg/scdlgfact.hxx4
-rw-r--r--sc/source/ui/condformat/condformatdlg.cxx214
-rw-r--r--sc/source/ui/condformat/condformatdlgitem.cxx77
-rw-r--r--sc/source/ui/condformat/condformatmgr.cxx13
-rw-r--r--sc/source/ui/inc/condformatdlg.hxx33
-rw-r--r--sc/source/ui/inc/condformatdlgitem.hxx68
-rw-r--r--sc/source/ui/inc/condformatmgr.hxx3
-rw-r--r--sc/source/ui/inc/msgpool.hxx2
-rw-r--r--sc/source/ui/view/cellsh1.cxx74
-rw-r--r--sc/source/ui/view/tabvwshc.cxx47
15 files changed, 299 insertions, 255 deletions
diff --git a/sc/Library_sc.mk b/sc/Library_sc.mk
index fd20f7604f7c..bf75fb1ea369 100644
--- a/sc/Library_sc.mk
+++ b/sc/Library_sc.mk
@@ -388,6 +388,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/scabstdlg.hxx b/sc/inc/scabstdlg.hxx
index b601d5fe11fd..bf939b9c2956 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 4e7adb1905dc..6664e91742d5 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/ui/app/msgpool.cxx b/sc/source/ui/app/msgpool.cxx
index 9eac708dd647..5509647270b1 100644
--- a/sc/source/ui/app/msgpool.cxx
+++ b/sc/source/ui/app/msgpool.cxx
@@ -53,7 +53,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 +68,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 91258f78754e..e2bd4072ff6c 100644
--- a/sc/source/ui/attrdlg/scdlgfact.cxx
+++ b/sc/source/ui/attrdlg/scdlgfact.cxx
@@ -422,11 +422,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 7cae7f24203a..c03bea9f9dc3 100644
--- a/sc/source/ui/attrdlg/scdlgfact.hxx
+++ b/sc/source/ui/attrdlg/scdlgfact.hxx
@@ -145,7 +145,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 d75bb340aff9..130f2670451d 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 000000000000..a4ef079c75de
--- /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 a8c0ecc69bbc..9128941d5573 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 d6a0a9352b88..34c6f3fc2297 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() override;
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 000000000000..d974b2c10213
--- /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 aad167e7f400..f436ca81e7e2 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 009f7c8e832c..83f3c591b10f 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 c31db963100e..af92bf76aa84 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"
@@ -1934,20 +1935,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;
}
}
@@ -2070,12 +2069,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();
@@ -2424,7 +2420,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();
@@ -2437,44 +2433,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));
+
+ 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 e84893b2f062..0b35e92745b6 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 );
}