summaryrefslogtreecommitdiff
path: root/sc/source/ui/condformat
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 /sc/source/ui/condformat
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>
Diffstat (limited to 'sc/source/ui/condformat')
-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
3 files changed, 148 insertions, 156 deletions
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: */