include/vcl/builder.hxx | 9 ++++++-- vcl/source/window/builder.cxx | 46 ++++++++++++++++++++++-------------------- 2 files changed, 32 insertions(+), 23 deletions(-)
New commits: commit 6c50f685c527f3fa67d7cd9b4842d7e9735e42a1 Author: Michael Weghorn <m.wegh...@posteo.de> AuthorDate: Mon Aug 12 11:33:16 2024 +0200 Commit: Michael Weghorn <m.wegh...@posteo.de> CommitDate: Tue Aug 13 07:16:49 2024 +0200 tdf#130857 Drop VclBuilder::m_pStringReplace Just use a local variable and call the `Translate::GetReadStringHook` getter directly in the currently 2 places using it. (Those will be further consolidated to use a helper method in upcoming commits.) Change-Id: I787a4794e6fd727e19bad12d5f61df66f41964c9 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/171763 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.wegh...@posteo.de> diff --git a/include/vcl/builder.hxx b/include/vcl/builder.hxx index 78b4bb6a3f18..52f43870f52c 100644 --- a/include/vcl/builder.hxx +++ b/include/vcl/builder.hxx @@ -298,7 +298,6 @@ private: OUString m_sID; OUString m_sHelpRoot; - ResHookProc m_pStringReplace; VclPtr<vcl::Window> m_pParent; bool m_bToplevelHasDeferredInit; bool m_bToplevelHasDeferredProperties; diff --git a/vcl/source/window/builder.cxx b/vcl/source/window/builder.cxx index c5c480eceaae..0b5b6979f80f 100644 --- a/vcl/source/window/builder.cxx +++ b/vcl/source/window/builder.cxx @@ -459,7 +459,6 @@ VclBuilder::VclBuilder(vcl::Window* pParent, const OUString& sUIDir, const OUStr : new NotebookBarAddonsItem{}) , m_sID(std::move(sID)) , m_sHelpRoot(sUIFile) - , m_pStringReplace(Translate::GetReadStringHook()) , m_pParent(pParent) , m_bToplevelParentFound(false) , m_pParserState(new ParserState) @@ -3195,8 +3194,8 @@ std::vector<ComboBoxTextItem> VclBuilder::handleItems(xmlreader::XmlReader &read else sFinalValue = OUString::fromUtf8(sValue); - if (m_pStringReplace) - sFinalValue = (*m_pStringReplace)(sFinalValue); + if (ResHookProc pStringReplace = Translate::GetReadStringHook()) + sFinalValue = (*pStringReplace)(sFinalValue); aItems.emplace_back(sFinalValue, sId); } @@ -4004,8 +4003,8 @@ void VclBuilder::collectProperty(xmlreader::XmlReader &reader, stringmap &rMap) if (!sProperty.isEmpty()) { sProperty = sProperty.replace('_', '-'); - if (m_pStringReplace) - sFinalValue = (*m_pStringReplace)(sFinalValue); + if (ResHookProc pStringReplace = Translate::GetReadStringHook()) + sFinalValue = (*pStringReplace)(sFinalValue); rMap[sProperty] = sFinalValue; } } commit bfca3583e0df069b9e18ec1d7ca988276cc91f3f Author: Michael Weghorn <m.wegh...@posteo.de> AuthorDate: Mon Aug 12 10:26:57 2024 +0200 Commit: Michael Weghorn <m.wegh...@posteo.de> CommitDate: Tue Aug 13 07:16:38 2024 +0200 tdf#130857 VclBuilder: Move m_bLegacy to base class ... and introduce a protected getter instead of accessing the member directly. Change-Id: I105cb10b015887ee14bba0c519f03e9ba8b4c3c1 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/171750 Reviewed-by: Michael Weghorn <m.wegh...@posteo.de> Tested-by: Jenkins diff --git a/include/vcl/builder.hxx b/include/vcl/builder.hxx index 300e806e04ab..78b4bb6a3f18 100644 --- a/include/vcl/builder.hxx +++ b/include/vcl/builder.hxx @@ -71,6 +71,8 @@ public: typedef std::map<OUString, std::pair<OUString, OUString>> accelmap; protected: + BuilderBase(bool bLegacy); + static void collectPangoAttribute(xmlreader::XmlReader& reader, stringmap& rMap); static void collectAtkRelationAttribute(xmlreader::XmlReader& reader, stringmap& rMap); static void collectAtkRoleAttribute(xmlreader::XmlReader& reader, stringmap& rMap); @@ -78,6 +80,11 @@ protected: static bool isToolbarItemClass(std::u16string_view sClass); static std::vector<vcl::EnumContext::Context> handleStyle(xmlreader::XmlReader &reader, int &nPriority); static OUString getStyleClass(xmlreader::XmlReader &reader); + + bool isLegacy() { return m_bLegacy; } + +private: + bool m_bLegacy; }; /// Creates a hierarchy of vcl::Windows (widgets) from a .ui file for dialogs, sidebar, etc. @@ -296,7 +303,6 @@ private: bool m_bToplevelHasDeferredInit; bool m_bToplevelHasDeferredProperties; bool m_bToplevelParentFound; - bool m_bLegacy; std::unique_ptr<ParserState> m_pParserState; vcl::Window *get_by_name(std::u16string_view sID); diff --git a/vcl/source/window/builder.cxx b/vcl/source/window/builder.cxx index 442988294a05..c5c480eceaae 100644 --- a/vcl/source/window/builder.cxx +++ b/vcl/source/window/builder.cxx @@ -445,10 +445,16 @@ namespace weld } } +BuilderBase::BuilderBase(bool bLegacy) + : m_bLegacy(bLegacy) +{ +} + VclBuilder::VclBuilder(vcl::Window* pParent, const OUString& sUIDir, const OUString& sUIFile, OUString sID, css::uno::Reference<css::frame::XFrame> xFrame, bool bLegacy, const NotebookBarAddonsItem* pNotebookBarAddonsItem) - : m_pNotebookBarAddonsItem(pNotebookBarAddonsItem + : BuilderBase(bLegacy) + , m_pNotebookBarAddonsItem(pNotebookBarAddonsItem ? new NotebookBarAddonsItem(*pNotebookBarAddonsItem) : new NotebookBarAddonsItem{}) , m_sID(std::move(sID)) @@ -456,7 +462,6 @@ VclBuilder::VclBuilder(vcl::Window* pParent, const OUString& sUIDir, const OUStr , m_pStringReplace(Translate::GetReadStringHook()) , m_pParent(pParent) , m_bToplevelParentFound(false) - , m_bLegacy(bLegacy) , m_pParserState(new ParserState) , m_xFrame(std::move(xFrame)) { @@ -535,7 +540,7 @@ VclBuilder::VclBuilder(vcl::Window* pParent, const OUString& sUIDir, const OUStr SAL_WARN_IF(!pOne || !pOther, "vcl", "missing member of radiobutton group"); if (pOne && pOther) { - if (m_bLegacy) + if (isLegacy()) pOne->group(*pOther); else { @@ -1732,7 +1737,7 @@ VclPtr<vcl::Window> VclBuilder::makeObject(vcl::Window *pParent, const OUString m_pParserState->m_aExpanderWidgets.push_back(pExpander); xWindow = pExpander; } - else if (name == "GtkButton" || (!m_bLegacy && name == "GtkToggleButton")) + else if (name == "GtkButton" || (!isLegacy() && name == "GtkToggleButton")) { VclPtr<Button> xButton; OUString sMenu = BuilderUtils::extractCustomProperty(rMap); @@ -1740,7 +1745,7 @@ VclPtr<vcl::Window> VclBuilder::makeObject(vcl::Window *pParent, const OUString xButton = extractStockAndBuildPushButton(pParent, rMap, name == "GtkToggleButton"); else { - assert(m_bLegacy && "use GtkMenuButton"); + assert(isLegacy() && "use GtkMenuButton"); xButton = extractStockAndBuildMenuButton(pParent, rMap); m_pParserState->m_aButtonMenuMaps.emplace_back(id, sMenu); } @@ -1775,7 +1780,7 @@ VclPtr<vcl::Window> VclBuilder::makeObject(vcl::Window *pParent, const OUString setupFromActionName(xButton, rMap, m_xFrame); xWindow = xButton; } - else if (name == "GtkToggleButton" && m_bLegacy) + else if (name == "GtkToggleButton" && isLegacy()) { VclPtr<Button> xButton; OUString sMenu = BuilderUtils::extractCustomProperty(rMap); @@ -1905,7 +1910,7 @@ VclPtr<vcl::Window> VclBuilder::makeObject(vcl::Window *pParent, const OUString } else if (name == "GtkTreeView") { - if (!m_bLegacy) + if (!isLegacy()) { assert(rMap.find(u"model"_ustr) != rMap.end() && "GtkTreeView must have a model"); } @@ -1918,7 +1923,7 @@ VclPtr<vcl::Window> VclBuilder::makeObject(vcl::Window *pParent, const OUString // everything over to SvHeaderTabListBox/SvTabListBox extractModel(id, rMap); WinBits nWinStyle = WB_CLIPCHILDREN|WB_LEFT|WB_VCENTER|WB_3DLOOK; - if (m_bLegacy) + if (isLegacy()) { OUString sBorder = BuilderUtils::extractCustomProperty(rMap); if (!sBorder.isEmpty()) @@ -1930,7 +1935,7 @@ VclPtr<vcl::Window> VclBuilder::makeObject(vcl::Window *pParent, const OUString } //ListBox/SvHeaderTabListBox manages its own scrolling, vcl::Window *pRealParent = prepareWidgetOwnScrolling(pParent, nWinStyle); - if (m_bLegacy) + if (isLegacy()) { xWindow = VclPtr<ListBox>::Create(pRealParent, nWinStyle | WB_SIMPLEMODE); xWindowForPackingProps = xWindow; @@ -1977,7 +1982,7 @@ VclPtr<vcl::Window> VclBuilder::makeObject(vcl::Window *pParent, const OUString } else if (name == "GtkTreeViewColumn") { - if (!m_bLegacy) + if (!isLegacy()) { SvHeaderTabListBox* pTreeView = dynamic_cast<SvHeaderTabListBox*>(pParent); if (HeaderBar* pHeaderBar = pTreeView ? pTreeView->GetHeaderBar() : nullptr) @@ -2144,7 +2149,7 @@ VclPtr<vcl::Window> VclBuilder::makeObject(vcl::Window *pParent, const OUString { nItemId = ToolBoxItemId(pToolBox->GetItemCount() + 1); //TODO: ImplToolItems::size_type -> sal_uInt16! - if (aCommand.isEmpty() && !m_bLegacy) + if (aCommand.isEmpty() && !isLegacy()) aCommand = id; pToolBox->InsertItem(nItemId, extractLabel(rMap), aCommand, nBits); } @@ -3320,7 +3325,7 @@ void VclBuilder::handleMenuObject(Menu *pParent, xmlreader::XmlReader &reader) { name = reader.getAttributeValue(false); sID = OUString(name.begin, name.length, RTL_TEXTENCODING_UTF8); - if (m_bLegacy) + if (isLegacy()) { sal_Int32 nDelim = sID.indexOf(':'); if (nDelim != -1) @@ -3605,7 +3610,7 @@ VclPtr<vcl::Window> VclBuilder::handleObject(vcl::Window *pParent, stringmap *pA { name = reader.getAttributeValue(false); sID = OUString(name.begin, name.length, RTL_TEXTENCODING_UTF8); - if (m_bLegacy) + if (isLegacy()) { sal_Int32 nDelim = sID.indexOf(':'); if (nDelim != -1) @@ -4234,7 +4239,7 @@ void VclBuilder::mungeModel(ComboBox &rTarget, const ListStore &rStore, sal_uInt sal_uInt16 nEntry = rTarget.InsertEntry(rRow[0]); if (rRow.size() > 1) { - if (m_bLegacy) + if (isLegacy()) { sal_IntPtr nValue = rRow[1].toInt32(); rTarget.SetEntryData(nEntry, reinterpret_cast<void*>(nValue)); @@ -4261,7 +4266,7 @@ void VclBuilder::mungeModel(ListBox &rTarget, const ListStore &rStore, sal_uInt1 sal_uInt16 nEntry = rTarget.InsertEntry(rRow[0]); if (rRow.size() > 1) { - if (m_bLegacy) + if (isLegacy()) { sal_IntPtr nValue = rRow[1].toInt32(); rTarget.SetEntryData(nEntry, reinterpret_cast<void*>(nValue)); @@ -4288,7 +4293,7 @@ void VclBuilder::mungeModel(SvTabListBox& rTarget, const ListStore &rStore, sal_ auto pEntry = rTarget.InsertEntry(rRow[0]); if (rRow.size() > 1) { - if (m_bLegacy) + if (isLegacy()) { sal_IntPtr nValue = rRow[1].toInt32(); pEntry->SetUserData(reinterpret_cast<void*>(nValue));