diff options
-rw-r--r-- | include/vcl/builder.hxx | 3 | ||||
-rw-r--r-- | vcl/source/app/salvtables.cxx | 37 | ||||
-rw-r--r-- | vcl/source/window/builder.cxx | 28 |
3 files changed, 47 insertions, 21 deletions
diff --git a/include/vcl/builder.hxx b/include/vcl/builder.hxx index 203b44e96871..d795b5cdc915 100644 --- a/include/vcl/builder.hxx +++ b/include/vcl/builder.hxx @@ -116,6 +116,9 @@ private: VclBuilder(const VclBuilder&) = delete; VclBuilder& operator=(const VclBuilder&) = delete; + // owner for ListBox/ComboBox UserData + std::vector<std::unique_ptr<OUString>> m_aUserData; + //If the toplevel window has any properties which need to be set on it, //but the toplevel is the owner of the builder, then its ctor //has not been completed during the building, so properties for it diff --git a/vcl/source/app/salvtables.cxx b/vcl/source/app/salvtables.cxx index c849343e02c7..d3d776278632 100644 --- a/vcl/source/app/salvtables.cxx +++ b/vcl/source/app/salvtables.cxx @@ -1752,6 +1752,8 @@ IMPL_LINK(SalInstanceEntry, CursorListener, VclWindowEvent&, rEvent, void) class SalInstanceTreeView : public SalInstanceContainer, public virtual weld::TreeView { private: + // owner for UserData + std::vector<std::unique_ptr<OUString>> m_aUserData; VclPtr<SvTreeListBox> m_xTreeView; DECL_LINK(SelectHdl, SvTreeListBox*, void); @@ -1769,7 +1771,14 @@ public: virtual void insert(int pos, const OUString& rStr, const OUString* pId, const OUString* pIconName, VirtualDevice* pImageSurface) override { auto nInsertPos = pos == -1 ? COMBOBOX_APPEND : pos; - void* pUserData = pId ? new OUString(*pId) : nullptr; + void* pUserData; + if (pId) + { + m_aUserData.emplace_back(o3tl::make_unique<OUString>(*pId)); + pUserData = m_aUserData.back().get(); + } + else + pUserData = nullptr; if (!pIconName && !pImageSurface) m_xTreeView->InsertEntry(rStr, nullptr, false, nInsertPos, pUserData); @@ -1829,6 +1838,7 @@ public: virtual void clear() override { m_xTreeView->Clear(); + m_aUserData.clear(); } virtual int n_children() const override @@ -2343,6 +2353,8 @@ template <class vcl_type> class SalInstanceComboBox : public SalInstanceContainer, public virtual weld::ComboBox { protected: + // owner for ListBox/ComboBox UserData + std::vector<std::unique_ptr<OUString>> m_aUserData; VclPtr<vcl_type> m_xComboBox; public: @@ -2449,12 +2461,8 @@ public: virtual void clear() override { - for (int i = 0; i < get_count(); ++i) - { - const OUString* pId = getEntryData(i); - delete pId; - } - return m_xComboBox->Clear(); + m_xComboBox->Clear(); + m_aUserData.clear(); } virtual void make_sorted() override @@ -2466,11 +2474,6 @@ public: { return m_xComboBox->IsInDropDown(); } - - virtual ~SalInstanceComboBox() override - { - clear(); - } }; class SalInstanceComboBoxWithoutEdit : public SalInstanceComboBox<ListBox> @@ -2506,7 +2509,10 @@ public: else nInsertedAt = m_xComboBox->InsertEntry(rStr, createImage(*pImageSurface), nInsertPos); if (pId) - m_xComboBox->SetEntryData(nInsertedAt, new OUString(*pId)); + { + m_aUserData.emplace_back(o3tl::make_unique<OUString>(*pId)); + m_xComboBox->SetEntryData(nInsertedAt, m_aUserData.back().get()); + } } virtual void insert_separator(int pos) override @@ -2609,7 +2615,10 @@ public: else nInsertedAt = m_xComboBox->InsertEntryWithImage(rStr, createImage(*pImageSurface), nInsertPos); if (pId) - m_xComboBox->SetEntryData(nInsertedAt, new OUString(*pId)); + { + m_aUserData.emplace_back(o3tl::make_unique<OUString>(*pId)); + m_xComboBox->SetEntryData(nInsertedAt, m_aUserData.back().get()); + } } virtual void insert_separator(int pos) override diff --git a/vcl/source/window/builder.cxx b/vcl/source/window/builder.cxx index 179bf1b21859..2406b7a56cc8 100644 --- a/vcl/source/window/builder.cxx +++ b/vcl/source/window/builder.cxx @@ -3323,7 +3323,9 @@ void VclBuilder::insertMenuObject(PopupMenu *pParent, PopupMenu *pSubMenu, const /// Insert items to a ComboBox or a ListBox. /// They have no common ancestor that would have 'InsertEntry()', so use a template. -template<typename T> static bool insertItems(vcl::Window *pWindow, VclBuilder::stringmap &rMap, const std::vector<ComboBoxTextItem> &rItems) +template<typename T> static bool insertItems(vcl::Window *pWindow, VclBuilder::stringmap &rMap, + std::vector<std::unique_ptr<OUString>>& rUserData, + const std::vector<ComboBoxTextItem> &rItems) { T *pContainer = dynamic_cast<T*>(pWindow); if (!pContainer) @@ -3334,7 +3336,10 @@ template<typename T> static bool insertItems(vcl::Window *pWindow, VclBuilder::s { sal_Int32 nPos = pContainer->InsertEntry(item.m_sItem); if (!item.m_sId.isEmpty()) - pContainer->SetEntryData(nPos, new OUString(OUString::fromUtf8(item.m_sId))); + { + rUserData.emplace_back(o3tl::make_unique<OUString>(OUString::fromUtf8(item.m_sId))); + pContainer->SetEntryData(nPos, rUserData.back().get()); + } } if (nActiveId < rItems.size()) pContainer->SelectEntryPos(nActiveId); @@ -3487,8 +3492,8 @@ VclPtr<vcl::Window> VclBuilder::handleObject(vcl::Window *pParent, xmlreader::Xm if (!aItems.empty()) { // try to fill-in the items - if (!insertItems<ComboBox>(pCurrentChild, aProperties, aItems)) - insertItems<ListBox>(pCurrentChild, aProperties, aItems); + if (!insertItems<ComboBox>(pCurrentChild, aProperties, m_aUserData, aItems)) + insertItems<ListBox>(pCurrentChild, aProperties, m_aUserData, aItems); } return pCurrentChild; @@ -3980,7 +3985,10 @@ void VclBuilder::mungeModel(ComboBox &rTarget, const ListStore &rStore, sal_uInt else { if (!rRow[1].isEmpty()) - rTarget.SetEntryData(nEntry, new OUString(rRow[1])); + { + m_aUserData.emplace_back(o3tl::make_unique<OUString>(rRow[1])); + rTarget.SetEntryData(nEntry, m_aUserData.back().get()); + } } } } @@ -4004,7 +4012,10 @@ void VclBuilder::mungeModel(ListBox &rTarget, const ListStore &rStore, sal_uInt1 else { if (!rRow[1].isEmpty()) - rTarget.SetEntryData(nEntry, new OUString(rRow[1])); + { + m_aUserData.emplace_back(o3tl::make_unique<OUString>(rRow[1])); + rTarget.SetEntryData(nEntry, m_aUserData.back().get()); + } } } } @@ -4028,7 +4039,10 @@ void VclBuilder::mungeModel(SvTreeListBox &rTarget, const ListStore &rStore, sal else { if (!rRow[1].isEmpty()) - pEntry->SetUserData(new OUString(rRow[1])); + { + m_aUserData.emplace_back(o3tl::make_unique<OUString>(rRow[1])); + pEntry->SetUserData(m_aUserData.back().get()); + } } } } |