include/vcl/builder.hxx | 2 ++ vcl/source/window/builder.cxx | 36 ++++++++++++++++++++++++++++++++---- 2 files changed, 34 insertions(+), 4 deletions(-)
New commits: commit 64c16c94b7fba876077c32e27cea76bd0a87ed1f Author: Caolán McNamara <caol...@redhat.com> AuthorDate: Sat Sep 15 15:00:26 2018 +0100 Commit: Caolán McNamara <caol...@redhat.com> CommitDate: Sat Sep 15 21:33:59 2018 +0200 add model support to ComboBox like ListBox Change-Id: I325650a8e95ea7eb426714f6ab8313dcec162e46 Reviewed-on: https://gerrit.libreoffice.org/60527 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caol...@redhat.com> Tested-by: Caolán McNamara <caol...@redhat.com> diff --git a/include/vcl/builder.hxx b/include/vcl/builder.hxx index 0ae018a601dc..534789b12cb2 100644 --- a/include/vcl/builder.hxx +++ b/include/vcl/builder.hxx @@ -35,6 +35,7 @@ #include <com/sun/star/uno/XComponentContext.hpp> class Button; +class ComboBox; class ListBox; class MessageDialog; class NumericFormatter; @@ -218,6 +219,7 @@ private: const ListStore* get_model_by_name(const OString& sID) const; void mungeModel(ListBox &rTarget, const ListStore &rStore, sal_uInt16 nActiveId); + void mungeModel(ComboBox &rTarget, const ListStore &rStore, sal_uInt16 nActiveId); typedef stringmap TextBuffer; const TextBuffer* get_buffer_by_name(const OString& sID) const; diff --git a/vcl/source/window/builder.cxx b/vcl/source/window/builder.cxx index b22ef476c36e..9b1a1d322916 100644 --- a/vcl/source/window/builder.cxx +++ b/vcl/source/window/builder.cxx @@ -483,12 +483,16 @@ VclBuilder::VclBuilder(vcl::Window *pParent, const OUString& sUIDir, const OUStr //Set ComboBox models when everything has been imported for (auto const& elem : m_pParserState->m_aModelMaps) { - ListBox *pTarget = get<ListBox>(elem.m_sID); + vcl::Window* pTarget = get<vcl::Window>(elem.m_sID); + ListBox *pListBoxTarget = dynamic_cast<ListBox*>(pTarget); + ComboBox *pComboBoxTarget = dynamic_cast<ComboBox*>(pTarget); // pStore may be empty const ListStore *pStore = get_model_by_name(elem.m_sValue.toUtf8()); - SAL_WARN_IF(!pTarget, "vcl", "missing elements of combobox"); - if (pTarget && pStore) - mungeModel(*pTarget, *pStore, elem.m_nActiveId); + SAL_WARN_IF(!pListBoxTarget && !pComboBoxTarget, "vcl", "missing elements of combobox"); + if (pListBoxTarget && pStore) + mungeModel(*pListBoxTarget, *pStore, elem.m_nActiveId); + else if (pComboBoxTarget && pStore) + mungeModel(*pComboBoxTarget, *pStore, elem.m_nActiveId); } //Set TextView buffers when everything has been imported @@ -3913,6 +3917,30 @@ const VclBuilder::Adjustment *VclBuilder::get_adjustment_by_name(const OString& return nullptr; } +void VclBuilder::mungeModel(ComboBox &rTarget, const ListStore &rStore, sal_uInt16 nActiveId) +{ + for (auto const& entry : rStore.m_aEntries) + { + const ListStore::row &rRow = entry; + sal_uInt16 nEntry = rTarget.InsertEntry(rRow[0]); + if (rRow.size() > 1) + { + if (m_bLegacy) + { + sal_IntPtr nValue = rRow[1].toInt32(); + rTarget.SetEntryData(nEntry, reinterpret_cast<void*>(nValue)); + } + else + { + if (!rRow[1].isEmpty()) + rTarget.SetEntryData(nEntry, new OUString(rRow[1])); + } + } + } + if (nActiveId < rStore.m_aEntries.size()) + rTarget.SelectEntryPos(nActiveId); +} + void VclBuilder::mungeModel(ListBox &rTarget, const ListStore &rStore, sal_uInt16 nActiveId) { for (auto const& entry : rStore.m_aEntries) _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits