Kaydet (Commit) 5b8c2237 authored tarafından Markus Mohrhard's avatar Markus Mohrhard

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/28995Reviewed-by: 's avatarMarkus Mohrhard <markus.mohrhard@googlemail.com>
Tested-by: 's avatarMarkus Mohrhard <markus.mohrhard@googlemail.com>
üst 96646c35
......@@ -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 \
......
......@@ -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;
};
......
......@@ -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:
......
......@@ -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 );
......
......@@ -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();
......
......@@ -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;
};
......
/* -*- 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: */
......@@ -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: */
......@@ -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;
......
/* -*- 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: */
......@@ -53,7 +53,8 @@ public:
ScConditionalFormatList* GetConditionalFormatList();
bool CondFormatsChanged() { return mbModified;}
bool CondFormatsChanged() const;
void SetModified();
ScConditionalFormat* GetCondFormatSelected();
......
......@@ -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;
......
......@@ -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;
......
......@@ -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 );
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment