diff options
author | Caolán McNamara <caolanm@redhat.com> | 2019-02-12 11:11:24 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2019-02-12 18:32:07 +0100 |
commit | 5c8ff0eab1ac8199efd966a0fcb3352cdb8deaf6 (patch) | |
tree | 88bef19509020cd172b2ed051c27d9d038a6fc45 | |
parent | 66cab03733f4fc91a2ebd37a799d940f5e787166 (diff) |
weld ScNamePasteDlg
Change-Id: I197a917458fdd75b08f888deac1926dc363202d5
Reviewed-on: https://gerrit.libreoffice.org/67735
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
-rw-r--r-- | include/vcl/weld.hxx | 13 | ||||
-rw-r--r-- | sc/inc/scabstdlg.hxx | 2 | ||||
-rw-r--r-- | sc/source/ui/attrdlg/scdlgfact.cxx | 13 | ||||
-rw-r--r-- | sc/source/ui/attrdlg/scdlgfact.hxx | 10 | ||||
-rw-r--r-- | sc/source/ui/inc/namemgrtable.hxx | 36 | ||||
-rw-r--r-- | sc/source/ui/inc/namepast.hxx | 20 | ||||
-rw-r--r-- | sc/source/ui/namedlg/namemgrtable.cxx | 115 | ||||
-rw-r--r-- | sc/source/ui/namedlg/namepast.cxx | 60 | ||||
-rw-r--r-- | sc/source/ui/view/cellsh1.cxx | 2 | ||||
-rw-r--r-- | sc/source/ui/view/editsh.cxx | 2 | ||||
-rw-r--r-- | sc/uiconfig/scalc/ui/insertname.ui | 85 | ||||
-rw-r--r-- | vcl/source/app/salvtables.cxx | 47 | ||||
-rw-r--r-- | vcl/unx/gtk3/gtk3gtkinst.cxx | 113 |
13 files changed, 431 insertions, 87 deletions
diff --git a/include/vcl/weld.hxx b/include/vcl/weld.hxx index bdd80ac3c635..8e6f3a71b2b6 100644 --- a/include/vcl/weld.hxx +++ b/include/vcl/weld.hxx @@ -462,6 +462,7 @@ protected: Link<const std::pair<int, int>&, void> m_aRadioToggleHdl; // if handler returns false, the expansion of the row is refused Link<TreeIter&, bool> m_aExpandingHdl; + Link<TreeView&, void> m_aVisibleRangeChangedHdl; std::vector<int> m_aRadioIndexes; @@ -472,6 +473,8 @@ protected: { return !m_aExpandingHdl.IsSet() || m_aExpandingHdl.Call(rIter); } + void signal_visible_range_changed() { m_aVisibleRangeChangedHdl.Call(*this); } + // arg is pair<row,col> void signal_toggled(const std::pair<int, int>& rRowCol) { m_aRadioToggleHdl.Call(rRowCol); } @@ -593,15 +596,23 @@ public: virtual bool get_row_expanded(const TreeIter& rIter) const = 0; virtual void expand_row(TreeIter& rIter) = 0; virtual void collapse_row(TreeIter& rIter) = 0; - virtual OUString get_text(const TreeIter& rIter) const = 0; + virtual void set_text(TreeIter& rIter, const OUString& rStr, int col = -1) = 0; + virtual OUString get_text(const TreeIter& rIter, int col = -1) const = 0; virtual OUString get_id(const TreeIter& rIter) const = 0; virtual void scroll_to_row(const TreeIter& rIter) = 0; virtual bool is_selected(const TreeIter& rIter) const = 0; virtual void selected_foreach(const std::function<void(TreeIter&)>& func) = 0; + virtual void visible_foreach(const std::function<void(TreeIter&)>& func) = 0; void connect_expanding(const Link<TreeIter&, bool>& rLink) { m_aExpandingHdl = rLink; } + virtual void connect_visible_range_changed(const Link<TreeView&, void>& rLink) + { + assert(!m_aVisibleRangeChangedHdl.IsSet() || !rLink.IsSet()); + m_aVisibleRangeChangedHdl = rLink; + } + //all of them void select_all() { unselect(-1); } void unselect_all() { select(-1); } diff --git a/sc/inc/scabstdlg.hxx b/sc/inc/scabstdlg.hxx index 8c1153fcabc1..f272b1a31ced 100644 --- a/sc/inc/scabstdlg.hxx +++ b/sc/inc/scabstdlg.hxx @@ -466,7 +466,7 @@ public: virtual VclPtr<AbstractScNameCreateDlg> CreateScNameCreateDlg(weld::Window * pParent, CreateNameFlags nFlags) = 0; - virtual VclPtr<AbstractScNamePasteDlg> CreateScNamePasteDlg ( vcl::Window * pParent, ScDocShell* pShell ) = 0; + virtual VclPtr<AbstractScNamePasteDlg> CreateScNamePasteDlg(weld::Window * pParent, ScDocShell* pShell) = 0; virtual VclPtr<AbstractScPivotFilterDlg> CreateScPivotFilterDlg(vcl::Window* pParent, const SfxItemSet& rArgSet, sal_uInt16 nSourceTab) = 0; diff --git a/sc/source/ui/attrdlg/scdlgfact.cxx b/sc/source/ui/attrdlg/scdlgfact.cxx index 12599e6f6ca4..fa64f1848b80 100644 --- a/sc/source/ui/attrdlg/scdlgfact.cxx +++ b/sc/source/ui/attrdlg/scdlgfact.cxx @@ -160,7 +160,11 @@ short AbstractScNameCreateDlg_Impl::Execute() return m_xDlg->run(); } -IMPL_ABSTDLG_BASE(AbstractScNamePasteDlg_Impl); +short AbstractScNamePasteDlg_Impl::Execute() +{ + return m_xDlg->run(); +} + IMPL_ABSTDLG_BASE(AbstractScPivotFilterDlg_Impl); IMPL_ABSTDLG_BASE(AbstractScDPFunctionDlg_Impl); IMPL_ABSTDLG_BASE(AbstractScDPSubtotalDlg_Impl); @@ -580,7 +584,7 @@ CreateNameFlags AbstractScNameCreateDlg_Impl::GetFlags() const std::vector<OUString> AbstractScNamePasteDlg_Impl::GetSelectedNames() const { - return pDlg->GetSelectedNames(); + return m_xDlg->GetSelectedNames(); } const ScQueryItem& AbstractScPivotFilterDlg_Impl::GetOutputItem() @@ -879,10 +883,9 @@ VclPtr<AbstractScNameCreateDlg> ScAbstractDialogFactory_Impl::CreateScNameCreate return VclPtr<AbstractScNameCreateDlg_Impl>::Create(std::make_unique<ScNameCreateDlg>(pParent, nFlags)); } -VclPtr<AbstractScNamePasteDlg> ScAbstractDialogFactory_Impl::CreateScNamePasteDlg ( vcl::Window * pParent, ScDocShell* pShell ) +VclPtr<AbstractScNamePasteDlg> ScAbstractDialogFactory_Impl::CreateScNamePasteDlg(weld::Window * pParent, ScDocShell* pShell) { - VclPtr<ScNamePasteDlg> pDlg = VclPtr<ScNamePasteDlg>::Create( pParent, pShell ); - return VclPtr<AbstractScNamePasteDlg_Impl>::Create( pDlg ); + return VclPtr<AbstractScNamePasteDlg_Impl>::Create(std::make_unique<ScNamePasteDlg>(pParent, pShell)); } VclPtr<AbstractScPivotFilterDlg> ScAbstractDialogFactory_Impl::CreateScPivotFilterDlg(vcl::Window* pParent, diff --git a/sc/source/ui/attrdlg/scdlgfact.hxx b/sc/source/ui/attrdlg/scdlgfact.hxx index 1519074fa28e..1d1b8ce4fa2e 100644 --- a/sc/source/ui/attrdlg/scdlgfact.hxx +++ b/sc/source/ui/attrdlg/scdlgfact.hxx @@ -374,7 +374,13 @@ public: class AbstractScNamePasteDlg_Impl : public AbstractScNamePasteDlg { - DECL_ABSTDLG_BASE( AbstractScNamePasteDlg_Impl, ScNamePasteDlg ) + std::unique_ptr<ScNamePasteDlg> m_xDlg; +public: + explicit AbstractScNamePasteDlg_Impl(std::unique_ptr<ScNamePasteDlg> p) + : m_xDlg(std::move(p)) + { + } + virtual short Execute() override; virtual std::vector<OUString> GetSelectedNames() const override; }; @@ -627,7 +633,7 @@ public: virtual VclPtr<AbstractScNameCreateDlg> CreateScNameCreateDlg(weld::Window * pParent, CreateNameFlags nFlags) override; - virtual VclPtr<AbstractScNamePasteDlg> CreateScNamePasteDlg ( vcl::Window * pParent, ScDocShell* pShell ) override; + virtual VclPtr<AbstractScNamePasteDlg> CreateScNamePasteDlg(weld::Window * pParent, ScDocShell* pShell) override; virtual VclPtr<AbstractScPivotFilterDlg> CreateScPivotFilterDlg(vcl::Window* pParent, const SfxItemSet& rArgSet, sal_uInt16 nSourceTab) override; diff --git a/sc/source/ui/inc/namemgrtable.hxx b/sc/source/ui/inc/namemgrtable.hxx index adf2175428e9..4bf8b879c840 100644 --- a/sc/source/ui/inc/namemgrtable.hxx +++ b/sc/source/ui/inc/namemgrtable.hxx @@ -86,6 +86,42 @@ public: DECL_LINK( HeaderEndDragHdl, HeaderBar*, void); }; +class SC_DLLPUBLIC RangeManagerTable +{ +private: + std::unique_ptr<weld::TreeView> m_xTreeView; + + OUString const maGlobalString; + + // should be const because we should not modify it here + const std::map<OUString, std::unique_ptr<ScRangeName>>& m_RangeMap; + // for performance, save which entries already have the formula entry + // otherwise opening the dialog with a lot of range names is extremely slow because + // we would calculate all formula strings during opening + std::map<OUString, bool> maCalculatedFormulaEntries; + const ScAddress maPos; + + int m_nId; + + void GetLine(ScRangeNameLine& aLine, weld::TreeIter& rEntry); + void Init(); + void CheckForFormulaString(); + const ScRangeData* findRangeData(const ScRangeNameLine& rLine); + + DECL_LINK(SizeAllocHdl, const Size&, void); + DECL_LINK(VisRowsScrolledHdl, weld::TreeView&, void); + +public: + RangeManagerTable(std::unique_ptr<weld::TreeView>, + const std::map<OUString, std::unique_ptr<ScRangeName>>& rTabRangeNames, + const ScAddress& rPos); + + int n_children() const { return m_xTreeView->n_children(); } + + void addEntry(const ScRangeNameLine& rLine, bool bSetCurEntry); + std::vector<ScRangeNameLine> GetSelectedEntries(); +}; + #endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/inc/namepast.hxx b/sc/source/ui/inc/namepast.hxx index bf07a076d68d..8cec55594351 100644 --- a/sc/source/ui/inc/namepast.hxx +++ b/sc/source/ui/inc/namepast.hxx @@ -20,10 +20,8 @@ #ifndef INCLUDED_SC_SOURCE_UI_INC_NAMEPAST_HXX #define INCLUDED_SC_SOURCE_UI_INC_NAMEPAST_HXX -#include <vcl/dialog.hxx> -#include <vcl/button.hxx> +#include <vcl/weld.hxx> #include "namemgrtable.hxx" - #include <memory> #include <vector> #include <map> @@ -31,25 +29,23 @@ class ScRangeName; class ScDocShell; -class ScNamePasteDlg : public ModalDialog +class ScNamePasteDlg : public weld::GenericDialogController { - DECL_LINK( ButtonHdl, Button *, void ); + DECL_LINK(ButtonHdl, weld::Button&, void); private: - VclPtr<PushButton> m_pBtnPasteAll; - VclPtr<PushButton> m_pBtnPaste; - VclPtr<PushButton> m_pBtnClose; - - VclPtr<ScRangeManagerTable> mpTable; + std::unique_ptr<weld::Button> m_xBtnPasteAll; + std::unique_ptr<weld::Button> m_xBtnPaste; + std::unique_ptr<weld::Button> m_xBtnClose; + std::unique_ptr<RangeManagerTable> m_xTable; std::vector<OUString> maSelectedNames; std::map<OUString, std::unique_ptr<ScRangeName>> m_RangeMap; public: - ScNamePasteDlg( vcl::Window * pParent, ScDocShell* pShell ); + ScNamePasteDlg(weld::Window * pParent, ScDocShell* pShell); virtual ~ScNamePasteDlg() override; - virtual void dispose() override; const std::vector<OUString>& GetSelectedNames() const; }; diff --git a/sc/source/ui/namedlg/namemgrtable.cxx b/sc/source/ui/namedlg/namemgrtable.cxx index 5655a6a1d1a2..8f93788269c3 100644 --- a/sc/source/ui/namedlg/namemgrtable.cxx +++ b/sc/source/ui/namedlg/namemgrtable.cxx @@ -306,4 +306,119 @@ IMPL_LINK_NOARG(ScRangeManagerTable, ScrollHdl, SvTreeListBox*, void) CheckForFormulaString(); } +RangeManagerTable::RangeManagerTable(std::unique_ptr<weld::TreeView> xTreeView, + const std::map<OUString, std::unique_ptr<ScRangeName>>& rRangeMap, + const ScAddress& rPos) + : m_xTreeView(std::move(xTreeView)) + , maGlobalString( ScResId(STR_GLOBAL_SCOPE)) + , m_RangeMap(rRangeMap) + , maPos( rPos ) + , m_nId(0) +{ + auto nColWidth = m_xTreeView->get_size_request().Width() / 7; + std::vector<int> aWidths; + aWidths.push_back(nColWidth * 2); + aWidths.push_back(nColWidth * 3); + m_xTreeView->set_column_fixed_widths(aWidths); + + Init(); + m_xTreeView->set_selection_mode(SelectionMode::Multiple); + m_xTreeView->connect_size_allocate(LINK(this, RangeManagerTable, SizeAllocHdl)); + m_xTreeView->connect_visible_range_changed(LINK(this, RangeManagerTable, VisRowsScrolledHdl)); +} + +IMPL_LINK_NOARG(RangeManagerTable, VisRowsScrolledHdl, weld::TreeView&, void) +{ + CheckForFormulaString(); +} + +const ScRangeData* RangeManagerTable::findRangeData(const ScRangeNameLine& rLine) +{ + const ScRangeName* pRangeName; + if (rLine.aScope == maGlobalString) + pRangeName = m_RangeMap.find(OUString(STR_GLOBAL_RANGE_NAME))->second.get(); + else + pRangeName = m_RangeMap.find(rLine.aScope)->second.get(); + + return pRangeName->findByUpperName(ScGlobal::pCharClass->uppercase(rLine.aName)); +} + +void RangeManagerTable::CheckForFormulaString() +{ + m_xTreeView->visible_foreach([this](weld::TreeIter& rEntry){ + OUString sId(m_xTreeView->get_id(rEntry)); + std::map<OUString, bool>::const_iterator itr = maCalculatedFormulaEntries.find(sId); + if (itr == maCalculatedFormulaEntries.end() || !itr->second) + { + ScRangeNameLine aLine; + GetLine(aLine, rEntry); + const ScRangeData* pData = findRangeData( aLine ); + OUString aFormulaString; + pData->GetSymbol(aFormulaString, maPos); + m_xTreeView->set_text(rEntry, aFormulaString, 1); + maCalculatedFormulaEntries.insert( std::pair<OUString, bool>(sId, true) ); + } + }); +} + +IMPL_LINK_NOARG(RangeManagerTable, SizeAllocHdl, const Size&, void) +{ + CheckForFormulaString(); +} + +void RangeManagerTable::addEntry(const ScRangeNameLine& rLine, bool bSetCurEntry) +{ + int nRow = m_xTreeView->n_children(); + m_xTreeView->insert(nullptr, -1, nullptr, nullptr, nullptr, nullptr, nullptr, false); + m_xTreeView->set_text(nRow, rLine.aName, 0); + m_xTreeView->set_text(nRow, rLine.aExpression, 1); + m_xTreeView->set_text(nRow, rLine.aScope, 2); + // just unique to track which one has been cached by maCalculatedFormulaEntries + m_xTreeView->set_id(nRow, OUString::number(m_nId++)); + if (bSetCurEntry) + m_xTreeView->set_cursor(nRow); +} + +void RangeManagerTable::GetLine(ScRangeNameLine& rLine, weld::TreeIter& rEntry) +{ + rLine.aName = m_xTreeView->get_text(rEntry, 0); + rLine.aExpression = m_xTreeView->get_text(rEntry, 1); + rLine.aScope = m_xTreeView->get_text(rEntry, 2); +} + +void RangeManagerTable::Init() +{ + m_xTreeView->freeze(); + m_xTreeView->clear(); + for (auto const& itr : m_RangeMap) + { + const ScRangeName *const pLocalRangeName = itr.second.get(); + ScRangeNameLine aLine; + if (itr.first == STR_GLOBAL_RANGE_NAME) + aLine.aScope = maGlobalString; + else + aLine.aScope = itr.first; + for (const auto& rEntry : *pLocalRangeName) + { + if (!rEntry.second->HasType(ScRangeData::Type::Database)) + { + aLine.aName = rEntry.second->GetName(); + addEntry(aLine, false); + } + } + } + m_xTreeView->thaw(); +} + +std::vector<ScRangeNameLine> RangeManagerTable::GetSelectedEntries() +{ + std::vector<ScRangeNameLine> aSelectedEntries; + m_xTreeView->selected_foreach([this, &aSelectedEntries](weld::TreeIter& rEntry){ + ScRangeNameLine aLine; + GetLine(aLine, rEntry); + aSelectedEntries.push_back(aLine); + }); + return aSelectedEntries; +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/namedlg/namepast.cxx b/sc/source/ui/namedlg/namepast.cxx index ddfae23d479b..2e259ed4364d 100644 --- a/sc/source/ui/namedlg/namepast.cxx +++ b/sc/source/ui/namedlg/namepast.cxx @@ -25,13 +25,12 @@ #include <viewdata.hxx> #include <scui_def.hxx> -ScNamePasteDlg::ScNamePasteDlg( vcl::Window * pParent, ScDocShell* pShell ) - : ModalDialog( pParent, "InsertNameDialog", "modules/scalc/ui/insertname.ui" ) +ScNamePasteDlg::ScNamePasteDlg(weld::Window * pParent, ScDocShell* pShell) + : GenericDialogController(pParent, "modules/scalc/ui/insertname.ui", "InsertNameDialog") + , m_xBtnPasteAll(m_xBuilder->weld_button("pasteall")) + , m_xBtnPaste(m_xBuilder->weld_button("paste")) + , m_xBtnClose(m_xBuilder->weld_button("close")) { - get(m_pBtnPasteAll, "pasteall"); - get(m_pBtnPaste, "paste"); - get(m_pBtnClose, "close"); - ScDocument& rDoc = pShell->GetDocument(); std::map<OUString, ScRangeName*> aCopyMap; rDoc.GetRangeNameMap(aCopyMap); @@ -42,56 +41,45 @@ ScNamePasteDlg::ScNamePasteDlg( vcl::Window * pParent, ScDocShell* pShell ) ScViewData* pViewData = ScDocShell::GetViewData(); ScAddress aPos(pViewData->GetCurX(), pViewData->GetCurY(), pViewData->GetTabNo()); - SvSimpleTableContainer *pContainer = get<SvSimpleTableContainer>("ctrl"); - Size aControlSize(210, 0); - aControlSize = LogicToPixel(aControlSize, MapMode(MapUnit::MapAppFont)); - pContainer->set_width_request(aControlSize.Width()); - pContainer->set_height_request(10 * GetTextHeight()); - mpTable = VclPtr<ScRangeManagerTable>::Create(*pContainer, m_RangeMap, aPos); - m_pBtnPaste->SetClickHdl( LINK( this, ScNamePasteDlg, ButtonHdl) ); - m_pBtnPasteAll->SetClickHdl( LINK( this, ScNamePasteDlg, ButtonHdl)); - m_pBtnClose->SetClickHdl( LINK( this, ScNamePasteDlg, ButtonHdl)); + std::unique_ptr<weld::TreeView> xTreeView(m_xBuilder->weld_tree_view("ctrl")); + xTreeView->set_size_request(xTreeView->get_approximate_digit_width() * 75, + xTreeView->get_height_rows(10)); + m_xTable.reset(new RangeManagerTable(std::move(xTreeView), m_RangeMap, aPos)); + + m_xBtnPaste->connect_clicked( LINK( this, ScNamePasteDlg, ButtonHdl) ); + m_xBtnPasteAll->connect_clicked( LINK( this, ScNamePasteDlg, ButtonHdl)); + m_xBtnClose->connect_clicked( LINK( this, ScNamePasteDlg, ButtonHdl)); - if (!mpTable->GetEntryCount()) + if (!m_xTable->n_children()) { - m_pBtnPaste->Disable(); - m_pBtnPasteAll->Disable(); + m_xBtnPaste->set_sensitive(false); + m_xBtnPasteAll->set_sensitive(false); } } ScNamePasteDlg::~ScNamePasteDlg() { - disposeOnce(); -} - -void ScNamePasteDlg::dispose() -{ - mpTable.disposeAndClear(); - m_pBtnPasteAll.clear(); - m_pBtnPaste.clear(); - m_pBtnClose.clear(); - ModalDialog::dispose(); } -IMPL_LINK( ScNamePasteDlg, ButtonHdl, Button *, pButton, void ) +IMPL_LINK(ScNamePasteDlg, ButtonHdl, weld::Button&, rButton, void) { - if( pButton == m_pBtnPasteAll ) + if (&rButton == m_xBtnPasteAll.get()) { - EndDialog( BTN_PASTE_LIST ); + m_xDialog->response(BTN_PASTE_LIST); } - else if( pButton == m_pBtnPaste ) + else if (&rButton == m_xBtnPaste.get()) { - std::vector<ScRangeNameLine> aSelectedLines = mpTable->GetSelectedEntries(); + std::vector<ScRangeNameLine> aSelectedLines = m_xTable->GetSelectedEntries(); for (const auto& rLine : aSelectedLines) { maSelectedNames.push_back(rLine.aName); } - EndDialog( BTN_PASTE_NAME ); + m_xDialog->response(BTN_PASTE_NAME); } - else if( pButton == m_pBtnClose ) + else if (&rButton == m_xBtnClose.get()) { - EndDialog( BTN_PASTE_CLOSE ); + m_xDialog->response(BTN_PASTE_CLOSE); } } diff --git a/sc/source/ui/view/cellsh1.cxx b/sc/source/ui/view/cellsh1.cxx index 1e5e24b958d7..0694c87e40e2 100644 --- a/sc/source/ui/view/cellsh1.cxx +++ b/sc/source/ui/view/cellsh1.cxx @@ -2156,7 +2156,7 @@ void ScCellShell::ExecuteEdit( SfxRequest& rReq ) { ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create(); - ScopedVclPtr<AbstractScNamePasteDlg> pDlg(pFact->CreateScNamePasteDlg( pTabViewShell->GetDialogParent(), GetViewData()->GetDocShell() )); + ScopedVclPtr<AbstractScNamePasteDlg> pDlg(pFact->CreateScNamePasteDlg(pTabViewShell->GetFrameWeld(), GetViewData()->GetDocShell())); switch( pDlg->Execute() ) { case BTN_PASTE_LIST: diff --git a/sc/source/ui/view/editsh.cxx b/sc/source/ui/view/editsh.cxx index b06f3f7605a2..d815cb19090d 100644 --- a/sc/source/ui/view/editsh.cxx +++ b/sc/source/ui/view/editsh.cxx @@ -462,7 +462,7 @@ void ScEditShell::Execute( SfxRequest& rReq ) { ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create(); - ScopedVclPtr<AbstractScNamePasteDlg> pDlg(pFact->CreateScNamePasteDlg( pViewData->GetDialogParent(), pViewData->GetDocShell() )); + ScopedVclPtr<AbstractScNamePasteDlg> pDlg(pFact->CreateScNamePasteDlg(pViewData->GetFrameWeld(), pViewData->GetDocShell())); short nRet = pDlg->Execute(); // pDlg is needed below diff --git a/sc/uiconfig/scalc/ui/insertname.ui b/sc/uiconfig/scalc/ui/insertname.ui index c1d9bb94453f..a07490a4bf44 100644 --- a/sc/uiconfig/scalc/ui/insertname.ui +++ b/sc/uiconfig/scalc/ui/insertname.ui @@ -1,13 +1,30 @@ <?xml version="1.0" encoding="UTF-8"?> -<!-- Generated with glade 3.18.3 --> +<!-- Generated with glade 3.22.1 --> <interface domain="sc"> <requires lib="gtk+" version="3.18"/> + <object class="GtkTreeStore" id="liststore3"> + <columns> + <!-- column-name text --> + <column type="gchararray"/> + <!-- column-name text2 --> + <column type="gchararray"/> + <!-- column-name text3 --> + <column type="gchararray"/> + <!-- column-name id --> + <column type="gchararray"/> + </columns> + </object> <object class="GtkDialog" id="InsertNameDialog"> <property name="can_focus">False</property> <property name="border_width">6</property> <property name="title" translatable="yes" context="insertname|InsertNameDialog">Paste Names</property> - <property name="resizable">False</property> + <property name="modal">True</property> + <property name="default_width">0</property> + <property name="default_height">0</property> <property name="type_hint">dialog</property> + <child> + <placeholder/> + </child> <child internal-child="vbox"> <object class="GtkBox" id="dialog-vbox1"> <property name="can_focus">False</property> @@ -87,11 +104,67 @@ </packing> </child> <child> - <object class="svtlo-SvSimpleTableContainer" id="ctrl"> + <object class="GtkScrolledWindow"> <property name="visible">True</property> - <property name="can_focus">False</property> + <property name="can_focus">True</property> <property name="hexpand">True</property> <property name="vexpand">True</property> + <property name="shadow_type">in</property> + <child> + <object class="GtkTreeView" id="ctrl"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="receives_default">True</property> + <property name="hexpand">True</property> + <property name="vexpand">True</property> + <property name="model">liststore3</property> + <property name="search_column">0</property> + <property name="headers_visible">True</property> + <property name="show_expanders">False</property> + <child internal-child="selection"> + <object class="GtkTreeSelection" id="Macro Library List-selection2"/> + </child> + <child> + <object class="GtkTreeViewColumn" id="treeviewcolumn3"> + <property name="resizable">True</property> + <property name="spacing">6</property> + <property name="title" translatable="yes" context="insertname|STR_HEADER_NAME">Name</property> + <child> + <object class="GtkCellRendererText" id="cellrenderer1"/> + <attributes> + <attribute name="text">0</attribute> + </attributes> + </child> + </object> + </child> + <child> + <object class="GtkTreeViewColumn" id="treeviewcolumn4"> + <property name="resizable">True</property> + <property name="spacing">6</property> + <property name="title" translatable="yes" context="insertname|STR_HEADER_RANGE_OR_EXPR">Range or formula expression</property> + <child> + <object class="GtkCellRendererText" id="cellrenderer2"/> + <attributes> + <attribute name="text">1</attribute> + </attributes> + </child> + </object> + </child> + <child> + <object class="GtkTreeViewColumn" id="treeviewcolumn5"> + <property name="resizable">True</property> + <property name="spacing">6</property> + <property name="title" translatable="yes" context="insertname|STR_HEADER_SCOPE">Scope</property> + <child> + <object class="GtkCellRendererText" id="cellrenderer3"/> + <attributes> + <attribute name="text">2</attribute> + </attributes> + </child> + </object> + </child> + </object> + </child> </object> <packing> <property name="expand">False</property> @@ -103,8 +176,8 @@ </child> <action-widgets> <action-widget response="-11">help</action-widget> - <action-widget response="0">pasteall</action-widget> - <action-widget response="0">paste</action-widget> + <action-widget response="102">pasteall</action-widget> + <action-widget response="101">paste</action-widget> <action-widget response="-7">close</action-widget> </action-widgets> </object> diff --git a/vcl/source/app/salvtables.cxx b/vcl/source/app/salvtables.cxx index c92411a3bd2a..988900ee51e2 100644 --- a/vcl/source/app/salvtables.cxx +++ b/vcl/source/app/salvtables.cxx @@ -1994,6 +1994,7 @@ private: DECL_LINK(EndDragHdl, HeaderBar*, void); DECL_LINK(HeaderBarClickedHdl, HeaderBar*, void); DECL_LINK(ToggleHdl, SvLBoxButtonData*, void); + DECL_LINK(VisibleRangeChangedHdl, SvTreeListBox*, void); public: SalInstanceTreeView(SvTabListBox* pTreeView, bool bTakeOwnership) : SalInstanceContainer(pTreeView, bTakeOwnership) @@ -2259,9 +2260,8 @@ public: return static_cast<SvLBoxString&>(rItem).GetText(); } - virtual void set_text(int pos, const OUString& rText, int col) override + void set_text(SvTreeListEntry* pEntry, const OUString& rText, int col) { - SvTreeListEntry* pEntry = m_xTreeView->GetEntry(nullptr, pos); if (col == -1) { m_xTreeView->SetEntryText(pEntry, rText); @@ -2290,6 +2290,12 @@ public: m_xTreeView->ModelHasEntryInvalidated(pEntry); } + virtual void set_text(int pos, const OUString& rText, int col) override + { + SvTreeListEntry* pEntry = m_xTreeView->GetEntry(nullptr, pos); + set_text(pEntry, rText, col); + } + virtual bool get_toggle(int pos, int col) const override { SvTreeListEntry* pEntry = m_xTreeView->GetEntry(nullptr, pos); @@ -2513,10 +2519,20 @@ public: m_xTreeView->Collapse(rVclIter.iter); } - virtual OUString get_text(const weld::TreeIter& rIter) const override + virtual OUString get_text(const weld::TreeIter& rIter, int col) const override { const SalInstanceTreeIter& rVclIter = static_cast<const SalInstanceTreeIter&>(rIter); - return SvTabListBox::GetEntryText(rVclIter.iter, 0); + + if (col == -1) + col = 0xffff; + + return SvTabListBox::GetEntryText(rVclIter.iter, col); + } + + virtual void set_text(weld::TreeIter& rIter, const OUString& rText, int col) override + { + SalInstanceTreeIter& rVclIter = static_cast<SalInstanceTreeIter&>(rIter); + set_text(rVclIter.iter, rText, col); } virtual OUString get_id(const weld::TreeIter& rIter) const override @@ -2552,6 +2568,23 @@ public: } } + virtual void visible_foreach(const std::function<void(weld::TreeIter&)>& func) override + { + SalInstanceTreeIter aVclIter(nullptr); + aVclIter.iter = m_xTreeView->GetFirstEntryInView(); + while (aVclIter.iter) + { + func(aVclIter); + aVclIter.iter = m_xTreeView->GetNextEntryInView(aVclIter.iter); + } + } + + virtual void connect_visible_range_changed(const Link<weld::TreeView&, void>& rLink) override + { + weld::TreeView::connect_visible_range_changed(rLink); + m_xTreeView->SetScrolledHdl(LINK(this, SalInstanceTreeView, VisibleRangeChangedHdl)); + } + virtual bool is_selected(const weld::TreeIter& rIter) const override { const SalInstanceTreeIter& rVclIter = static_cast<const SalInstanceTreeIter&>(rIter); @@ -2619,9 +2652,15 @@ public: m_xTreeView->SetExpandingHdl(Link<SvTreeListBox*, bool>()); m_xTreeView->SetDoubleClickHdl(Link<SvTreeListBox*, bool>()); m_xTreeView->SetSelectHdl(Link<SvTreeListBox*, void>()); + m_xTreeView->SetScrolledHdl(Link<SvTreeListBox*, void>()); } }; +IMPL_LINK_NOARG(SalInstanceTreeView, VisibleRangeChangedHdl, SvTreeListBox*, void) +{ + signal_visible_range_changed(); +} + IMPL_LINK(SalInstanceTreeView, ToggleHdl, SvLBoxButtonData*, pData, void) { SvTreeListEntry* pEntry = pData->GetActEntry(); diff --git a/vcl/unx/gtk3/gtk3gtkinst.cxx b/vcl/unx/gtk3/gtk3gtkinst.cxx index ca1315f3101b..1e5abddfd398 100644 --- a/vcl/unx/gtk3/gtk3gtkinst.cxx +++ b/vcl/unx/gtk3/gtk3gtkinst.cxx @@ -5066,6 +5066,7 @@ private: gulong m_nChangedSignalId; gulong m_nRowActivatedSignalId; gulong m_nTestExpandRowSignalId; + gulong m_nVAdjustmentChangedSignalId; GtkSortType m_eSortType; DECL_LINK(async_signal_changed, void*, void); @@ -5131,18 +5132,23 @@ private: } } + OUString get(const GtkTreeIter& iter, int col) const + { + GtkTreeModel *pModel = GTK_TREE_MODEL(m_pTreeStore); + gchar* pStr; + gtk_tree_model_get(pModel, const_cast<GtkTreeIter*>(&iter), col, &pStr, -1); + OUString sRet(pStr, pStr ? strlen(pStr) : 0, RTL_TEXTENCODING_UTF8); + g_free(pStr); + return sRet; + } + OUString get(int pos, int col) const { OUString sRet; GtkTreeModel *pModel = GTK_TREE_MODEL(m_pTreeStore); GtkTreeIter iter; if (gtk_tree_model_iter_nth_child(pModel, &iter, nullptr, pos)) - { - gchar* pStr; - gtk_tree_model_get(pModel, &iter, col, &pStr, -1); - sRet = OUString(pStr, pStr ? strlen(pStr) : 0, RTL_TEXTENCODING_UTF8); - g_free(pStr); - } + sRet = get(iter, col); return sRet; } @@ -5158,14 +5164,19 @@ private: return bRet; } + void set(GtkTreeIter& iter, int col, const OUString& rText) + { + OString aStr(OUStringToOString(rText, RTL_TEXTENCODING_UTF8)); + gtk_tree_store_set(m_pTreeStore, &iter, col, aStr.getStr(), -1); + } + void set(int pos, int col, const OUString& rText) { GtkTreeModel *pModel = GTK_TREE_MODEL(m_pTreeStore); GtkTreeIter iter; if (gtk_tree_model_iter_nth_child(pModel, &iter, nullptr, pos)) { - OString aStr(OUStringToOString(rText, RTL_TEXTENCODING_UTF8)); - gtk_tree_store_set(m_pTreeStore, &iter, col, aStr.getStr(), -1); + set(iter, col, rText); } } @@ -5197,7 +5208,7 @@ private: if (gtk_tree_model_iter_children(pModel, &tmp, &iter)) { aIter.iter = tmp; - if (get_text(aIter) == "<dummy>") + if (get_text(aIter, -1) == "<dummy>") { gtk_tree_store_remove(m_pTreeStore, &tmp); bPlaceHolder = true; @@ -5265,6 +5276,12 @@ private: pThis->signal_column_clicked(pColumn); } + static void signalVAdjustmentChanged(GtkAdjustment*, gpointer widget) + { + GtkInstanceTreeView* pThis = static_cast<GtkInstanceTreeView*>(widget); + pThis->signal_visible_range_changed(); + } + public: GtkInstanceTreeView(GtkTreeView* pTreeView, bool bTakeOwnership) : GtkInstanceContainer(GTK_CONTAINER(pTreeView), bTakeOwnership) @@ -5278,6 +5295,7 @@ public: G_CALLBACK(signalChanged), this)) , m_nRowActivatedSignalId(g_signal_connect(pTreeView, "row-activated", G_CALLBACK(signalRowActivated), this)) , m_nTestExpandRowSignalId(g_signal_connect(pTreeView, "test-expand-row", G_CALLBACK(signalTestExpandRow), this)) + , m_nVAdjustmentChangedSignalId(0) , m_eSortType(GTK_SORT_ASCENDING) { m_pColumns = gtk_tree_view_get_columns(m_pTreeView); @@ -5547,6 +5565,41 @@ public: g_list_free_full(pList, reinterpret_cast<GDestroyNotify>(gtk_tree_path_free)); } + virtual void visible_foreach(const std::function<void(weld::TreeIter&)>& func) override + { + GtkTreePath* start_path; + GtkTreePath* end_path; + + if (gtk_tree_view_get_visible_range(m_pTreeView, &start_path, &end_path)) + { + GtkInstanceTreeIter aGtkIter(nullptr); + GtkTreeModel *pModel = GTK_TREE_MODEL(m_pTreeStore); + gtk_tree_model_get_iter(pModel, &aGtkIter.iter, start_path); + + do + { + func(aGtkIter); + GtkTreePath* path = gtk_tree_model_get_path(pModel, &aGtkIter.iter); + bool bContinue = gtk_tree_path_compare(path, end_path) != 0; + gtk_tree_path_free(path); + if (!bContinue) + break; + if (!iter_next(aGtkIter)) + break; + } while(true); + + gtk_tree_path_free(start_path); + gtk_tree_path_free(end_path); + } + } + + virtual void connect_visible_range_changed(const Link<weld::TreeView&, void>& rLink) override + { + weld::TreeView::connect_visible_range_changed(rLink); + GtkAdjustment* pVAdjustment = gtk_scrollable_get_vadjustment(GTK_SCROLLABLE(m_pTreeView)); + m_nVAdjustmentChangedSignalId = g_signal_connect(pVAdjustment, "value-changed", G_CALLBACK(signalVAdjustmentChanged), this); + } + virtual bool is_selected(const weld::TreeIter& rIter) const override { const GtkInstanceTreeIter& rGtkIter = static_cast<const GtkInstanceTreeIter&>(rIter); @@ -5563,7 +5616,7 @@ public: virtual void set_text(int pos, const OUString& rText, int col) override { if (col == -1) - return set(pos, m_nTextCol, rText); + col = m_nTextCol; return set(pos, col, rText); } @@ -5701,7 +5754,7 @@ public: if (ret) { //on-demand dummy entry doesn't count - return get_text(rGtkIter) != "<dummy>"; + return get_text(rGtkIter, -1) != "<dummy>"; } return ret; } @@ -5804,15 +5857,20 @@ public: gtk_tree_path_free(path); } - virtual OUString get_text(const weld::TreeIter& rIter) const override + virtual OUString get_text(const weld::TreeIter& rIter, int col) const override { const GtkInstanceTreeIter& rGtkIter = static_cast<const GtkInstanceTreeIter&>(rIter); - GtkTreeModel *pModel = GTK_TREE_MODEL(m_pTreeStore); - gchar* pStr; - gtk_tree_model_get(pModel, const_cast<GtkTreeIter*>(&rGtkIter.iter), m_nTextCol, &pStr, -1); - OUString sRet(pStr, pStr ? strlen(pStr) : 0, RTL_TEXTENCODING_UTF8); - g_free(pStr); - return sRet; + if (col == -1) + col = m_nTextCol; + return get(rGtkIter.iter, col); + } + + virtual void set_text(weld::TreeIter& rIter, const OUString& rText, int col) override + { + GtkInstanceTreeIter& rGtkIter = static_cast<GtkInstanceTreeIter&>(rIter); + if (col == -1) + col = m_nTextCol; + set(rGtkIter.iter, col, rText); } virtual OUString get_id(const weld::TreeIter& rIter) const override @@ -5900,6 +5958,19 @@ public: gtk_widget_set_size_request(m_pWidget, nWidth, nHeight); } + virtual Size get_size_request() const override + { + GtkWidget* pParent = gtk_widget_get_parent(m_pWidget); + if (GTK_IS_SCROLLED_WINDOW(pParent)) + { + return Size(gtk_scrolled_window_get_min_content_width(GTK_SCROLLED_WINDOW(pParent)), + gtk_scrolled_window_get_min_content_height(GTK_SCROLLED_WINDOW(pParent))); + } + int nWidth, nHeight; + gtk_widget_get_size_request(m_pWidget, &nWidth, &nHeight); + return Size(nWidth, nHeight); + } + virtual Size get_preferred_size() const override { GtkWidget* pParent = gtk_widget_get_parent(m_pWidget); @@ -5970,6 +6041,12 @@ public: virtual ~GtkInstanceTreeView() override { + if (m_nVAdjustmentChangedSignalId) + { + GtkAdjustment* pVAdjustment = gtk_scrollable_get_vadjustment(GTK_SCROLLABLE(m_pTreeView)); + g_signal_handler_disconnect(pVAdjustment, m_nVAdjustmentChangedSignalId); + } + g_signal_handler_disconnect(m_pTreeView, m_nTestExpandRowSignalId); g_signal_handler_disconnect(m_pTreeView, m_nRowActivatedSignalId); g_signal_handler_disconnect(gtk_tree_view_get_selection(m_pTreeView), m_nChangedSignalId); |