Kaydet (Commit) 64c16c94 authored tarafından Caolán McNamara's avatar Caolán McNamara

add model support to ComboBox like ListBox

Change-Id: I325650a8e95ea7eb426714f6ab8313dcec162e46
Reviewed-on: https://gerrit.libreoffice.org/60527
Tested-by: Jenkins
Reviewed-by: 's avatarCaolán McNamara <caolanm@redhat.com>
Tested-by: 's avatarCaolán McNamara <caolanm@redhat.com>
üst c6e9be6b
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include <com/sun/star/uno/XComponentContext.hpp> #include <com/sun/star/uno/XComponentContext.hpp>
class Button; class Button;
class ComboBox;
class ListBox; class ListBox;
class MessageDialog; class MessageDialog;
class NumericFormatter; class NumericFormatter;
...@@ -218,6 +219,7 @@ private: ...@@ -218,6 +219,7 @@ private:
const ListStore* get_model_by_name(const OString& sID) const; const ListStore* get_model_by_name(const OString& sID) const;
void mungeModel(ListBox &rTarget, const ListStore &rStore, sal_uInt16 nActiveId); void mungeModel(ListBox &rTarget, const ListStore &rStore, sal_uInt16 nActiveId);
void mungeModel(ComboBox &rTarget, const ListStore &rStore, sal_uInt16 nActiveId);
typedef stringmap TextBuffer; typedef stringmap TextBuffer;
const TextBuffer* get_buffer_by_name(const OString& sID) const; const TextBuffer* get_buffer_by_name(const OString& sID) const;
......
...@@ -483,12 +483,16 @@ VclBuilder::VclBuilder(vcl::Window *pParent, const OUString& sUIDir, const OUStr ...@@ -483,12 +483,16 @@ VclBuilder::VclBuilder(vcl::Window *pParent, const OUString& sUIDir, const OUStr
//Set ComboBox models when everything has been imported //Set ComboBox models when everything has been imported
for (auto const& elem : m_pParserState->m_aModelMaps) 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 // pStore may be empty
const ListStore *pStore = get_model_by_name(elem.m_sValue.toUtf8()); const ListStore *pStore = get_model_by_name(elem.m_sValue.toUtf8());
SAL_WARN_IF(!pTarget, "vcl", "missing elements of combobox"); SAL_WARN_IF(!pListBoxTarget && !pComboBoxTarget, "vcl", "missing elements of combobox");
if (pTarget && pStore) if (pListBoxTarget && pStore)
mungeModel(*pTarget, *pStore, elem.m_nActiveId); mungeModel(*pListBoxTarget, *pStore, elem.m_nActiveId);
else if (pComboBoxTarget && pStore)
mungeModel(*pComboBoxTarget, *pStore, elem.m_nActiveId);
} }
//Set TextView buffers when everything has been imported //Set TextView buffers when everything has been imported
...@@ -3913,6 +3917,30 @@ const VclBuilder::Adjustment *VclBuilder::get_adjustment_by_name(const OString& ...@@ -3913,6 +3917,30 @@ const VclBuilder::Adjustment *VclBuilder::get_adjustment_by_name(const OString&
return nullptr; 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) void VclBuilder::mungeModel(ListBox &rTarget, const ListStore &rStore, sal_uInt16 nActiveId)
{ {
for (auto const& entry : rStore.m_aEntries) for (auto const& entry : rStore.m_aEntries)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment