diff options
author | Caolán McNamara <caolanm@redhat.com> | 2019-05-11 19:51:21 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2019-05-11 22:19:28 +0200 |
commit | b8061f41373cc90823c93cf9f025647c93496293 (patch) | |
tree | 5ffa8954183ec0fe07270381bc67bfc11699ed3d /sc/source/ui | |
parent | 28e9dcca1f2f0e1bd91e779bf772bcb4a9d8a9f4 (diff) |
weld ScCondFormatManagerDlg
Change-Id: Iccf2657f2c8fe98b4e975936fb75d56fc9523b5a
Reviewed-on: https://gerrit.libreoffice.org/72162
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'sc/source/ui')
-rw-r--r-- | sc/source/ui/attrdlg/scdlgfact.cxx | 23 | ||||
-rw-r--r-- | sc/source/ui/attrdlg/scdlgfact.hxx | 15 | ||||
-rw-r--r-- | sc/source/ui/condformat/condformatmgr.cxx | 173 | ||||
-rw-r--r-- | sc/source/ui/inc/condformatmgr.hxx | 41 | ||||
-rw-r--r-- | sc/source/ui/view/cellsh1.cxx | 5 |
5 files changed, 114 insertions, 143 deletions
diff --git a/sc/source/ui/attrdlg/scdlgfact.cxx b/sc/source/ui/attrdlg/scdlgfact.cxx index 057935500c69..a2b4e4c2b02f 100644 --- a/sc/source/ui/attrdlg/scdlgfact.cxx +++ b/sc/source/ui/attrdlg/scdlgfact.cxx @@ -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) diff --git a/sc/source/ui/attrdlg/scdlgfact.hxx b/sc/source/ui/attrdlg/scdlgfact.hxx index 14d6b5317467..dcf1566d60c9 100644 --- a/sc/source/ui/attrdlg/scdlgfact.hxx +++ b/sc/source/ui/attrdlg/scdlgfact.hxx @@ -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; diff --git a/sc/source/ui/condformat/condformatmgr.cxx b/sc/source/ui/condformat/condformatmgr.cxx index 057ef9a963a7..1ac76ac319b1 100644 --- a/sc/source/ui/condformat/condformatmgr.cxx +++ b/sc/source/ui/condformat/condformatmgr.cxx @@ -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: */ diff --git a/sc/source/ui/inc/condformatmgr.hxx b/sc/source/ui/inc/condformatmgr.hxx index 1d3cbf101e75..94bbf346cb1d 100644 --- a/sc/source/ui/inc/condformatmgr.hxx +++ b/sc/source/ui/inc/condformatmgr.hxx @@ -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 diff --git a/sc/source/ui/view/cellsh1.cxx b/sc/source/ui/view/cellsh1.cxx index 7dc9a5e456ef..791716a66faf 100644 --- a/sc/source/ui/view/cellsh1.cxx +++ b/sc/source/ui/view/cellsh1.cxx @@ -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; |