diff options
author | Caolán McNamara <caolanm@redhat.com> | 2018-09-15 15:00:26 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2018-09-15 21:33:59 +0200 |
commit | 64c16c94b7fba876077c32e27cea76bd0a87ed1f (patch) | |
tree | af5514545f670e539bb0085e0b435c3aacec5288 /vcl | |
parent | c6e9be6bd817f7bae78fb95966019ad02947d47a (diff) |
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 <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/source/window/builder.cxx | 36 |
1 files changed, 32 insertions, 4 deletions
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) |