diff options
author | Caolán McNamara <caolanm@redhat.com> | 2018-04-06 16:06:49 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2018-09-09 15:01:06 +0200 |
commit | 854d8c418904bbb9370ca6ee0aad6bde5deb426e (patch) | |
tree | 5031d234c155d3b8d67056b30d1b1af994a3c75b /vcl | |
parent | f2ea65c92330ef0e36725a351f7b39027023f4bf (diff) |
weld SfxNewStyleDlg
set some parents and replace VclComboBoxText with an entry and a treeview
Change-Id: Ied75176355f23c986eac4d5de8654472a15dbbbf
Reviewed-on: https://gerrit.libreoffice.org/52517
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/source/app/salvtables.cxx | 56 | ||||
-rw-r--r-- | vcl/source/window/builder.cxx | 50 | ||||
-rw-r--r-- | vcl/unx/gtk3/gtk3gtkinst.cxx | 5 |
3 files changed, 111 insertions, 0 deletions
diff --git a/vcl/source/app/salvtables.cxx b/vcl/source/app/salvtables.cxx index dfac4c9f9aca..f32c36af335d 100644 --- a/vcl/source/app/salvtables.cxx +++ b/vcl/source/app/salvtables.cxx @@ -1472,6 +1472,11 @@ public: weld::Entry::connect_cursor_position(rLink); } + void SetAutocompleteHdl(const Link<Edit&,void>& rLink) + { + m_xEntry->SetAutocompleteHdl(rLink); + } + virtual ~SalInstanceEntry() override { if (m_aCursorPositionHdl.IsSet()) @@ -2308,6 +2313,51 @@ IMPL_LINK_NOARG(SalInstanceComboBoxTextWithEdit, EntryActivateHdl, Edit&, void) m_aEntryActivateHdl.Call(*this); } +class SalInstanceEntryTreeView : public weld::EntryTreeView +{ +private: + DECL_LINK(AutocompleteHdl, Edit&, void); + SalInstanceEntry* m_pEntry; +public: + SalInstanceEntryTreeView(std::unique_ptr<weld::Entry> xEntry, std::unique_ptr<weld::TreeView> xTreeView) + : EntryTreeView(std::move(xEntry), std::move(xTreeView)) + , m_pEntry(dynamic_cast<SalInstanceEntry*>(m_xEntry.get())) + { + assert(m_pEntry); + m_pEntry->SetAutocompleteHdl(LINK(this, SalInstanceEntryTreeView, AutocompleteHdl)); + } + ~SalInstanceEntryTreeView() + { + m_pEntry->SetAutocompleteHdl(Link<Edit&, void>()); + } +}; + +IMPL_LINK(SalInstanceEntryTreeView, AutocompleteHdl, Edit&, rEdit, void) +{ + Selection aSel = rEdit.GetSelection(); + + OUString aFullText = rEdit.GetText(); + OUString aStartText = aFullText.copy(0, static_cast<sal_Int32>(aSel.Max())); + + int nPos = -1; + int nCount = m_xTreeView->n_children(); + for (int i = 0; i < nCount; ++i) + { + if (m_xTreeView->get_text(i).startsWithIgnoreAsciiCase(aStartText)) + { + nPos = i; + break; + } + } + + if (nPos != -1) + { + OUString aText = m_xTreeView->get_text(nPos); + Selection aSelection(aText.getLength(), aStartText.getLength()); + rEdit.SetText(aText, aSelection); + } +} + class SalInstanceBuilder : public weld::Builder { private: @@ -2462,6 +2512,12 @@ public: return pListBox ? o3tl::make_unique<SalInstanceComboBoxTextWithoutEdit>(pListBox, bTakeOwnership) : nullptr; } + virtual std::unique_ptr<weld::EntryTreeView> weld_entry_tree_view(const OString& entryid, const OString& treeviewid, bool bTakeOwnership) override + { + return o3tl::make_unique<SalInstanceEntryTreeView>(weld_entry(entryid, bTakeOwnership), + weld_tree_view(treeviewid, bTakeOwnership)); + } + virtual std::unique_ptr<weld::TreeView> weld_tree_view(const OString &id, bool bTakeOwnership) override { ListBox* pTreeView = m_xBuilder->get<ListBox>(id); diff --git a/vcl/source/window/builder.cxx b/vcl/source/window/builder.cxx index 6fd77952f24f..2ca29761b473 100644 --- a/vcl/source/window/builder.cxx +++ b/vcl/source/window/builder.cxx @@ -332,6 +332,56 @@ namespace weld const LocaleDataWrapper& rLocaleData = aSysLocale.GetLocaleData(); return TimeFormatter::FormatTime(ConvertValue(nValue), m_eFormat, TimeFormat::Hour24, true, rLocaleData); } + + EntryTreeView::EntryTreeView(std::unique_ptr<Entry> xEntry, std::unique_ptr<TreeView> xTreeView) + : m_xEntry(std::move(xEntry)) + , m_xTreeView(std::move(xTreeView)) + { + m_xTreeView->connect_changed(LINK(this, EntryTreeView, ClickHdl)); + m_xEntry->connect_changed(LINK(this, EntryTreeView, ModifyHdl)); + } + + IMPL_LINK(EntryTreeView, ClickHdl, weld::TreeView&, rView, void) + { + m_xEntry->set_text(rView.get_selected_text()); + } + + void EntryTreeView::EntryModifyHdl(weld::Entry& rBox) + { + OUString sText(rBox.get_text()); + int nExists = m_xTreeView->find_text(sText); + if (nExists != -1) + { + m_xTreeView->select(nExists); + return; + } + + m_xTreeView->select(-1); + if (sText.isEmpty()) + return; + + int nCount = m_xTreeView->n_children(); + for (int i = 0; i < nCount; ++i) + { + if (m_xTreeView->get_text(i).startsWith(sText)) + { + m_xTreeView->select(i); + break; + } + } + } + + IMPL_LINK(EntryTreeView, ModifyHdl, weld::Entry&, rBox, void) + { + EntryModifyHdl(rBox); + m_aChangeHdl.Call(rBox); + } + + void EntryTreeView::set_size_request_by_digits_rows(int nDigits, int nRows) + { + m_xTreeView->set_size_request(m_xTreeView->get_approximate_digit_width() * nDigits, + m_xTreeView->get_height_rows(nRows)); + } } VclBuilder::VclBuilder(vcl::Window *pParent, const OUString& sUIDir, const OUString& sUIFile, const OString& sID, diff --git a/vcl/unx/gtk3/gtk3gtkinst.cxx b/vcl/unx/gtk3/gtk3gtkinst.cxx index 3d8a8a03b8f0..34d7d75ca954 100644 --- a/vcl/unx/gtk3/gtk3gtkinst.cxx +++ b/vcl/unx/gtk3/gtk3gtkinst.cxx @@ -5352,6 +5352,11 @@ public: return o3tl::make_unique<GtkInstanceTreeView>(pTreeView, bTakeOwnership); } + virtual std::unique_ptr<weld::EntryTreeView> weld_entry_tree_view(const OString& entryid, const OString& treeviewid, bool bTakeOwnership) override + { + return o3tl::make_unique<weld::EntryTreeView>(weld_entry(entryid, bTakeOwnership), weld_tree_view(treeviewid, bTakeOwnership)); + } + virtual std::unique_ptr<weld::Label> weld_label(const OString &id, bool bTakeOwnership) override { GtkLabel* pLabel = GTK_LABEL(gtk_builder_get_object(m_pBuilder, id.getStr())); |