Kaydet (Commit) b8061f41 authored tarafından Caolán McNamara's avatar Caolán McNamara

weld ScCondFormatManagerDlg

Change-Id: Iccf2657f2c8fe98b4e975936fb75d56fc9523b5a
Reviewed-on: https://gerrit.libreoffice.org/72162
Tested-by: Jenkins
Reviewed-by: 's avatarCaolán McNamara <caolanm@redhat.com>
Tested-by: 's avatarCaolán McNamara <caolanm@redhat.com>
üst 28e9dcca
......@@ -423,7 +423,6 @@
#define STR_UNDO_INSERT_CURRENT_TIME NC_("STR_UNDO_INSERT_CURRENT_TIME", "Insert Current Time")
#define STR_MANAGE_NAMES NC_("STR_MANAGE_NAMES", "Manage Names...")
#define STR_HEADER_NAME NC_("STR_HEADER_NAME", "Name")
#define STR_HEADER_RANGE_OR_EXPR NC_("STR_HEADER_RANGE_OR_EXPR", "Range or formula expression")
#define STR_HEADER_SCOPE NC_("STR_HEADER_SCOPE", "Scope")
#define STR_MULTI_SELECT NC_("STR_MULTI_SELECT", "(multiple)")
#define STR_GLOBAL_SCOPE NC_("STR_GLOBAL_SCOPE", "Document (Global)")
......@@ -431,8 +430,6 @@
#define STR_ERR_NAME_INVALID NC_("STR_ERR_NAME_INVALID", "Invalid name. Only use letters, numbers and underscore.")
#define STR_UNSAVED_EXT_REF NC_("STR_UNSAVED_EXT_REF", "This Document contains external references to unsaved documents.\n\nDo you want to continue?")
#define STR_CLOSE_WITH_UNSAVED_REFS NC_("STR_CLOSE_WITH_UNSAVED_REFS", "This Document is referenced by another document and not yet saved. Closing it without saving will result in data loss.")
#define STR_HEADER_RANGE NC_("STR_HEADER_RANGE", "Range")
#define STR_HEADER_COND NC_("STR_HEADER_COND", "First Condition")
#define STR_COND_CONDITION NC_("STR_COND_CONDITION", "Cell value is")
#define STR_COND_COLORSCALE NC_("STR_COND_COLORSCALE", "ColorScale")
#define STR_COND_DATABAR NC_("STR_COND_DATABAR", "DataBar")
......
......@@ -410,7 +410,7 @@ public:
virtual VclPtr<AbstractScSortWarningDlg> CreateScSortWarningDlg(weld::Window* pParent, const OUString& rExtendText, const OUString& rCurrentText ) = 0;
virtual VclPtr<AbstractScCondFormatManagerDlg> CreateScCondFormatMgrDlg(vcl::Window* pParent, ScDocument* pDoc, const ScConditionalFormatList* pFormatList ) = 0;
virtual VclPtr<AbstractScCondFormatManagerDlg> CreateScCondFormatMgrDlg(weld::Window* pParent, ScDocument* pDoc, const ScConditionalFormatList* pFormatList ) = 0;
virtual VclPtr<AbstractScDataPilotDatabaseDlg> CreateScDataPilotDatabaseDlg(weld::Window* pParent) = 0;
......
......@@ -82,7 +82,15 @@ short AbstractScColRowLabelDlg_Impl::Execute()
return m_xDlg->run();
}
IMPL_ABSTDLG_BASE(AbstractScCondFormatManagerDlg_Impl);
short AbstractScCondFormatManagerDlg_Impl::Execute()
{
return m_xDlg->run();
}
bool AbstractScCondFormatManagerDlg_Impl::StartExecuteAsync(VclAbstractDialog::AsyncContext &rCtx)
{
return weld::DialogController::runAsync(m_xDlg, rCtx.maEndDialogFn);
}
short AbstractScDataPilotDatabaseDlg_Impl::Execute()
{
......@@ -510,22 +518,22 @@ sal_uLong AbstractScLinkedAreaDlg_Impl::GetRefresh()
std::unique_ptr<ScConditionalFormatList> AbstractScCondFormatManagerDlg_Impl::GetConditionalFormatList()
{
return pDlg->GetConditionalFormatList();
return m_xDlg->GetConditionalFormatList();
}
bool AbstractScCondFormatManagerDlg_Impl::CondFormatsChanged() const
{
return pDlg->CondFormatsChanged();
return m_xDlg->CondFormatsChanged();
}
void AbstractScCondFormatManagerDlg_Impl::SetModified()
{
return pDlg->SetModified();
return m_xDlg->SetModified();
}
ScConditionalFormat* AbstractScCondFormatManagerDlg_Impl::GetCondFormatSelected()
{
return pDlg->GetCondFormatSelected();
return m_xDlg->GetCondFormatSelected();
}
int AbstractScMetricInputDlg_Impl::GetInputValue() const
......@@ -761,10 +769,9 @@ VclPtr<AbstractScSortWarningDlg> ScAbstractDialogFactory_Impl::CreateScSortWarni
return VclPtr<AbstractScSortWarningDlg_Impl>::Create(std::make_unique<ScSortWarningDlg>(pParent, rExtendText, rCurrentText));
}
VclPtr<AbstractScCondFormatManagerDlg> ScAbstractDialogFactory_Impl::CreateScCondFormatMgrDlg(vcl::Window* pParent, ScDocument* pDoc, const ScConditionalFormatList* pFormatList )
VclPtr<AbstractScCondFormatManagerDlg> ScAbstractDialogFactory_Impl::CreateScCondFormatMgrDlg(weld::Window* pParent, ScDocument* pDoc, const ScConditionalFormatList* pFormatList )
{
VclPtr<ScCondFormatManagerDlg> pDlg = VclPtr<ScCondFormatManagerDlg>::Create( pParent, pDoc, pFormatList );
return VclPtr<AbstractScCondFormatManagerDlg_Impl>::Create( pDlg );
return VclPtr<AbstractScCondFormatManagerDlg_Impl>::Create(std::make_unique<ScCondFormatManagerDlg>(pParent, pDoc, pFormatList));
}
VclPtr<AbstractScDataPilotDatabaseDlg> ScAbstractDialogFactory_Impl::CreateScDataPilotDatabaseDlg(weld::Window* pParent)
......
......@@ -131,14 +131,17 @@ public:
class AbstractScCondFormatManagerDlg_Impl : public AbstractScCondFormatManagerDlg
{
DECL_ABSTDLG_BASE(AbstractScCondFormatManagerDlg_Impl, ScCondFormatManagerDlg)
std::shared_ptr<ScCondFormatManagerDlg> m_xDlg;
public:
explicit AbstractScCondFormatManagerDlg_Impl(std::unique_ptr<ScCondFormatManagerDlg> p)
: m_xDlg(std::move(p))
{
}
virtual short Execute() override;
virtual bool StartExecuteAsync(VclAbstractDialog::AsyncContext &rCtx) override;
virtual std::unique_ptr<ScConditionalFormatList> GetConditionalFormatList() override;
virtual bool CondFormatsChanged() const override;
virtual void SetModified() override;
virtual ScConditionalFormat* GetCondFormatSelected() override;
};
......@@ -597,7 +600,7 @@ public:
virtual VclPtr<AbstractScSortWarningDlg> CreateScSortWarningDlg(weld::Window* pParent, const OUString& rExtendText, const OUString& rCurrentText ) override;
virtual VclPtr<AbstractScCondFormatManagerDlg> CreateScCondFormatMgrDlg(vcl::Window* pParent, ScDocument* pDoc, const ScConditionalFormatList* pFormatList ) override;
virtual VclPtr<AbstractScCondFormatManagerDlg> CreateScCondFormatMgrDlg(weld::Window* pParent, ScDocument* pDoc, const ScConditionalFormatList* pFormatList ) override;
virtual VclPtr<AbstractScDataPilotDatabaseDlg> CreateScDataPilotDatabaseDlg(weld::Window* pParent) override;
......
......@@ -15,194 +15,155 @@
#include <document.hxx>
#include <conditio.hxx>
ScCondFormatManagerWindow::ScCondFormatManagerWindow(SvSimpleTableContainer& rParent,
ScCondFormatManagerWindow::ScCondFormatManagerWindow(weld::TreeView& rTreeView,
ScDocument* pDoc, ScConditionalFormatList* pFormatList)
: SvSimpleTable(rParent, WB_HSCROLL | WB_SORT | WB_TABSTOP)
: mrTreeView(rTreeView)
, mpDoc(pDoc)
, mpFormatList(pFormatList)
{
OUString aConditionStr(ScResId(STR_HEADER_COND));
OUString aRangeStr(ScResId(STR_HEADER_RANGE));
OUStringBuffer sHeader;
sHeader.append(aRangeStr).append("\t").append(aConditionStr);
InsertHeaderEntry(sHeader.makeStringAndClear(), HEADERBAR_APPEND, HeaderBarItemBits::LEFT);
mrTreeView.set_size_request(mrTreeView.get_approximate_digit_width() * 70,
mrTreeView.get_height_rows(20));
setColSizes();
Init();
Show();
SetSelectionMode(SelectionMode::Multiple);
}
OUString ScCondFormatManagerWindow::createEntryString(const ScConditionalFormat& rFormat)
{
const ScRangeList& aRange = rFormat.GetRange();
OUString aStr;
aRange.Format(aStr, ScRefFlags::VALID, mpDoc, mpDoc->GetAddressConvention());
aStr += "\t";
aStr += ScCondFormatHelper::GetExpression(rFormat, aRange.GetTopLeftCorner());
return aStr;
mrTreeView.set_selection_mode(SelectionMode::Multiple);
mrTreeView.make_sorted();
}
void ScCondFormatManagerWindow::Init()
{
SetUpdateMode(false);
mrTreeView.freeze();
if (mpFormatList)
{
int nRow = 0;
OUString sRangeStr;
for(const auto& rItem : *mpFormatList)
{
SvTreeListEntry* pEntry = InsertEntryToColumn( createEntryString(*rItem) );
maMapLBoxEntryToCondIndex.insert(std::pair<SvTreeListEntry*,sal_Int32>(pEntry, rItem->GetKey()));
const ScRangeList& aRange = rItem->GetRange();
aRange.Format(sRangeStr, ScRefFlags::VALID, mpDoc, mpDoc->GetAddressConvention());
mrTreeView.append(OUString::number(rItem->GetKey()), sRangeStr);
mrTreeView.set_text(nRow, ScCondFormatHelper::GetExpression(*rItem, aRange.GetTopLeftCorner()), 1);
++nRow;
}
}
SetUpdateMode(true);
mrTreeView.thaw();
if (mpFormatList && !mpFormatList->empty())
SelectRow(0);
}
void ScCondFormatManagerWindow::Resize()
{
SvSimpleTable::Resize();
if (GetParentDialog()->isCalculatingInitialLayoutSize())
setColSizes();
mrTreeView.select(0);
}
void ScCondFormatManagerWindow::DeleteSelection()
{
if(GetSelectionCount())
auto aSelectedRows = mrTreeView.get_selected_rows();
std::sort(aSelectedRows.begin(), aSelectedRows.end());
for (auto it = aSelectedRows.rbegin(); it != aSelectedRows.rend(); ++it)
{
for(SvTreeListEntry* pEntry = FirstSelected(); pEntry != nullptr; pEntry = NextSelected(pEntry))
{
sal_Int32 nIndex = maMapLBoxEntryToCondIndex.find(pEntry)->second;
mpFormatList->erase(nIndex);
}
RemoveSelection();
sal_Int32 nIndex = mrTreeView.get_id(*it).toInt32();
mpFormatList->erase(nIndex);
mrTreeView.remove(*it);
}
}
ScConditionalFormat* ScCondFormatManagerWindow::GetSelection()
{
SvTreeListEntry* pEntry = FirstSelected();
if(!pEntry)
int nEntry = mrTreeView.get_selected_index();
if (nEntry == -1)
return nullptr;
sal_Int32 nIndex = maMapLBoxEntryToCondIndex.find(pEntry)->second;
sal_Int32 nIndex = mrTreeView.get_id(nEntry).toInt32();
return mpFormatList->GetFormat(nIndex);
}
void ScCondFormatManagerWindow::setColSizes()
{
HeaderBar &rBar = GetTheHeaderBar();
if (rBar.GetItemCount() < 2)
return;
long aStaticTabs[]= { 0, 0 };
aStaticTabs[1] = rBar.GetSizePixel().Width() / 2;
SvSimpleTable::SetTabs(SAL_N_ELEMENTS(aStaticTabs), aStaticTabs, MapUnit::MapPixel);
}
ScCondFormatManagerDlg::ScCondFormatManagerDlg(vcl::Window* pParent, ScDocument* pDoc, const ScConditionalFormatList* pFormatList):
ModalDialog(pParent, "CondFormatManager", "modules/scalc/ui/condformatmanager.ui"),
mpFormatList( pFormatList ? new ScConditionalFormatList(*pFormatList) : nullptr),
mbModified(false)
{
SvSimpleTableContainer *pContainer = get<SvSimpleTableContainer>("CONTAINER");
Size aSize(LogicToPixel(Size(290, 220), MapMode(MapUnit::MapAppFont)));
pContainer->set_width_request(aSize.Width());
pContainer->set_height_request(aSize.Height());
m_pCtrlManager = VclPtr<ScCondFormatManagerWindow>::Create(*pContainer, pDoc, mpFormatList.get());
get(m_pBtnAdd, "add");
get(m_pBtnRemove, "remove");
get(m_pBtnEdit, "edit");
m_pBtnRemove->SetClickHdl(LINK(this, ScCondFormatManagerDlg, RemoveBtnHdl));
m_pBtnEdit->SetClickHdl(LINK(this, ScCondFormatManagerDlg, EditBtnClickHdl));
m_pBtnAdd->SetClickHdl(LINK(this, ScCondFormatManagerDlg, AddBtnHdl));
m_pCtrlManager->SetDoubleClickHdl(LINK(this, ScCondFormatManagerDlg, EditBtnHdl));
UpdateButtonSensitivity();
std::vector<int> aWidths;
aWidths.push_back(mrTreeView.get_size_request().Width() / 2);
mrTreeView.set_column_fixed_widths(aWidths);
}
ScCondFormatManagerDlg::~ScCondFormatManagerDlg()
ScCondFormatManagerDlg::ScCondFormatManagerDlg(weld::Window* pParent, ScDocument* pDoc, const ScConditionalFormatList* pFormatList)
: GenericDialogController(pParent, "modules/scalc/ui/condformatmanager.ui", "CondFormatManager")
, m_bModified(false)
, m_xFormatList( pFormatList ? new ScConditionalFormatList(*pFormatList) : nullptr)
, m_xBtnAdd(m_xBuilder->weld_button("add"))
, m_xBtnRemove(m_xBuilder->weld_button("remove"))
, m_xBtnEdit(m_xBuilder->weld_button("edit"))
, m_xTreeView(m_xBuilder->weld_tree_view("CONTAINER"))
, m_xCtrlManager(new ScCondFormatManagerWindow(*m_xTreeView, pDoc, m_xFormatList.get()))
{
disposeOnce();
m_xBtnRemove->connect_clicked(LINK(this, ScCondFormatManagerDlg, RemoveBtnHdl));
m_xBtnEdit->connect_clicked(LINK(this, ScCondFormatManagerDlg, EditBtnClickHdl));
m_xBtnAdd->connect_clicked(LINK(this, ScCondFormatManagerDlg, AddBtnHdl));
m_xTreeView->connect_row_activated(LINK(this, ScCondFormatManagerDlg, EditBtnHdl));
UpdateButtonSensitivity();
}
void ScCondFormatManagerDlg::dispose()
ScCondFormatManagerDlg::~ScCondFormatManagerDlg()
{
mpFormatList.reset();
m_pBtnAdd.clear();
m_pBtnRemove.clear();
m_pBtnEdit.clear();
m_pCtrlManager.disposeAndClear();
ModalDialog::dispose();
}
std::unique_ptr<ScConditionalFormatList> ScCondFormatManagerDlg::GetConditionalFormatList()
{
return std::move(mpFormatList);
return std::move(m_xFormatList);
}
void ScCondFormatManagerDlg::UpdateButtonSensitivity()
{
OUString aNewSensitivity = mpFormatList->empty() ? OUString("false") : OUString("true");
m_pBtnRemove->set_property("sensitive", aNewSensitivity);
m_pBtnEdit->set_property("sensitive", aNewSensitivity);
bool bNewSensitivity = !m_xFormatList->empty();
m_xBtnRemove->set_sensitive(bNewSensitivity);
m_xBtnEdit->set_sensitive(bNewSensitivity);
}
// Get the current conditional format selected.
//
ScConditionalFormat* ScCondFormatManagerDlg::GetCondFormatSelected()
{
return m_pCtrlManager->GetSelection();
return m_xCtrlManager->GetSelection();
}
IMPL_LINK_NOARG(ScCondFormatManagerDlg, RemoveBtnHdl, Button*, void)
IMPL_LINK_NOARG(ScCondFormatManagerDlg, RemoveBtnHdl, weld::Button&, void)
{
m_pCtrlManager->DeleteSelection();
mbModified = true;
m_xCtrlManager->DeleteSelection();
m_bModified = true;
UpdateButtonSensitivity();
}
IMPL_LINK_NOARG(ScCondFormatManagerDlg, EditBtnClickHdl, Button*, void)
IMPL_LINK_NOARG(ScCondFormatManagerDlg, EditBtnClickHdl, weld::Button&, void)
{
mbModified = true;
EditBtnHdl(nullptr);
// EditBtnHdl() might call EndDialog which will blow us away
if (!IsDisposed())
UpdateButtonSensitivity();
EditBtnHdl(*m_xTreeView);
}
IMPL_LINK_NOARG(ScCondFormatManagerDlg, EditBtnHdl, SvTreeListBox*, bool)
IMPL_LINK_NOARG(ScCondFormatManagerDlg, EditBtnHdl, weld::TreeView&, void)
{
ScConditionalFormat* pFormat = m_pCtrlManager->GetSelection();
ScConditionalFormat* pFormat = m_xCtrlManager->GetSelection();
if(!pFormat)
return false;
if (!pFormat)
return;
mbModified = true;
EndDialog( DLG_RET_EDIT );
m_bModified = true;
m_xDialog->response( DLG_RET_EDIT );
return false;
return;
}
IMPL_LINK_NOARG(ScCondFormatManagerDlg, AddBtnHdl, Button*, void)
IMPL_LINK_NOARG(ScCondFormatManagerDlg, AddBtnHdl, weld::Button&, void)
{
mbModified = true;
EndDialog( DLG_RET_ADD );
m_bModified = true;
m_xDialog->response( DLG_RET_ADD );
}
void ScCondFormatManagerDlg::SetModified()
{
mbModified = true;
m_bModified = true;
UpdateButtonSensitivity();
}
bool ScCondFormatManagerDlg::CondFormatsChanged() const
{
return mbModified;
return m_bModified;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -10,9 +10,7 @@
#ifndef INCLUDED_SC_SOURCE_UI_INC_CONDFORMATMGR_HXX
#define INCLUDED_SC_SOURCE_UI_INC_CONDFORMATMGR_HXX
#include <vcl/dialog.hxx>
#include <vcl/button.hxx>
#include <svtools/simptabl.hxx>
#include <vcl/weld.hxx>
#include <map>
......@@ -20,31 +18,28 @@ class ScDocument;
class ScConditionalFormat;
class ScConditionalFormatList;
class ScCondFormatManagerWindow : public SvSimpleTable
class ScCondFormatManagerWindow
{
private:
void Init();
OUString createEntryString(const ScConditionalFormat& rFormat);
void setColSizes();
weld::TreeView& mrTreeView;
ScDocument* const mpDoc;
ScConditionalFormatList* mpFormatList;
std::map<SvTreeListEntry*, sal_Int32> maMapLBoxEntryToCondIndex;
public:
ScCondFormatManagerWindow(SvSimpleTableContainer& rParent, ScDocument* pDoc, ScConditionalFormatList* pFormatList);
ScCondFormatManagerWindow(weld::TreeView& rTreeView, ScDocument* pDoc, ScConditionalFormatList* pFormatList);
void DeleteSelection();
ScConditionalFormat* GetSelection();
virtual void Resize() override;
};
class ScCondFormatManagerDlg : public ModalDialog
class ScCondFormatManagerDlg : public weld::GenericDialogController
{
public:
ScCondFormatManagerDlg(vcl::Window* pParent, ScDocument* pDoc, const ScConditionalFormatList* pFormatList);
ScCondFormatManagerDlg(weld::Window* pParent, ScDocument* pDoc, const ScConditionalFormatList* pFormatList);
virtual ~ScCondFormatManagerDlg() override;
virtual void dispose() override;
std::unique_ptr<ScConditionalFormatList> GetConditionalFormatList();
......@@ -54,19 +49,21 @@ public:
ScConditionalFormat* GetCondFormatSelected();
private:
VclPtr<PushButton> m_pBtnAdd;
VclPtr<PushButton> m_pBtnRemove;
VclPtr<PushButton> m_pBtnEdit;
std::unique_ptr<ScConditionalFormatList> mpFormatList;
VclPtr<ScCondFormatManagerWindow> m_pCtrlManager;
void UpdateButtonSensitivity();
bool m_bModified;
std::unique_ptr<ScConditionalFormatList> m_xFormatList;
std::unique_ptr<weld::Button> m_xBtnAdd;
std::unique_ptr<weld::Button> m_xBtnRemove;
std::unique_ptr<weld::Button> m_xBtnEdit;
std::unique_ptr<weld::TreeView> m_xTreeView;
std::unique_ptr<ScCondFormatManagerWindow> m_xCtrlManager;
DECL_LINK(RemoveBtnHdl, Button*, void);
DECL_LINK(EditBtnClickHdl, Button*, void);
DECL_LINK(AddBtnHdl, Button*, void);
DECL_LINK(EditBtnHdl, SvTreeListBox*, bool);
void UpdateButtonSensitivity();
bool mbModified;
DECL_LINK(RemoveBtnHdl, weld::Button&, void);
DECL_LINK(EditBtnClickHdl, weld::Button&, void);
DECL_LINK(AddBtnHdl, weld::Button&, void);
DECL_LINK(EditBtnHdl, weld::TreeView&, void);
};
#endif
......
......@@ -2541,8 +2541,9 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq )
if (!pList)
pList = pDoc->GetCondFormList( aPos.Tab() );
vcl::Window* pWin = pTabViewShell->GetDialogParent();
VclPtr<AbstractScCondFormatManagerDlg> pDlg(pFact->CreateScCondFormatMgrDlg(
pTabViewShell->GetDialogParent(), pDoc, pList));
pWin ? pWin->GetFrameWeld() : nullptr, pDoc, pList));
if (pDlgItem)
pDlg->SetModified();
......@@ -2579,6 +2580,8 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq )
if (pDlgItem)
pTabViewShell->GetPool().Remove(*pDlgItem);
pDlg->disposeOnce();
});
}
break;
......
......@@ -140,10 +140,6 @@
<child>
<placeholder/>
</child>
<style>
<class name="notebook"/>
<class name="stack"/>
</style>
</object>
</child>
</object>
......
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