vcl/unx/gtk3/gtkinst.cxx | 19 +++++++++++++++++++ vcl/unx/gtk4/convert3to4.cxx | 42 +++++++++++++++++++++++++++++++++--------- 2 files changed, 52 insertions(+), 9 deletions(-)
New commits: commit b9959364cbdbf8a17d977717522e57187f82730f Author: Caolán McNamara <[email protected]> AuthorDate: Fri Jun 4 15:52:29 2021 +0100 Commit: Caolán McNamara <[email protected]> CommitDate: Fri Jun 4 21:00:07 2021 +0200 gtk4: experiment with GtkPicture for all our theme resources math, format, spacing for an example where GtkPicture is wanted writer, format, columns for an example where GtkImage is wanted Change-Id: Ib7acfc242d93e8b3f23687e7e5483aedd5cc4a45 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/116727 Tested-by: Jenkins Reviewed-by: Caolán McNamara <[email protected]> diff --git a/vcl/unx/gtk3/gtkinst.cxx b/vcl/unx/gtk3/gtkinst.cxx index 5b225ac558b3..64e6376f9700 100644 --- a/vcl/unx/gtk3/gtkinst.cxx +++ b/vcl/unx/gtk3/gtkinst.cxx @@ -21082,6 +21082,25 @@ private: } } } +#if GTK_CHECK_VERSION(4, 0, 0) + else if (GTK_IS_PICTURE(pWidget)) + { + GtkPicture* pPicture = GTK_PICTURE(pWidget); + if (GFile* icon_file = gtk_picture_get_file(pPicture)) + { + char* icon_name = g_file_get_uri(icon_file); + OUString aIconName(icon_name, strlen(icon_name), RTL_TEXTENCODING_UTF8); + g_free(icon_name); + assert(aIconName.startsWith("private:///graphicrepository/")); + aIconName.startsWith("private:///graphicrepository/", &aIconName); + if (GdkPixbuf* pixbuf = load_icon_by_name_theme_lang(aIconName, m_aIconTheme, m_aUILang)) + { + gtk_picture_set_pixbuf(GTK_PICTURE(pWidget), pixbuf); + g_object_unref(pixbuf); + } + } + } +#endif #if !GTK_CHECK_VERSION(4, 0, 0) else if (GTK_IS_TOOL_BUTTON(pWidget)) { diff --git a/vcl/unx/gtk4/convert3to4.cxx b/vcl/unx/gtk4/convert3to4.cxx index 33a3c4d5adc5..2d009791d60e 100644 --- a/vcl/unx/gtk4/convert3to4.cxx +++ b/vcl/unx/gtk4/convert3to4.cxx @@ -255,21 +255,28 @@ struct ConvertResult { bool m_bChildCanFocus; bool m_bHasVisible; - bool m_bHasIconName; + bool m_bHasSymbolicIconName; bool m_bAlwaysShowImage; css::uno::Reference<css::xml::dom::XNode> m_xPropertyLabel; - ConvertResult(bool bChildCanFocus, bool bHasVisible, bool bHasIconName, bool bAlwaysShowImage, + ConvertResult(bool bChildCanFocus, bool bHasVisible, bool bHasSymbolicIconName, + bool bAlwaysShowImage, const css::uno::Reference<css::xml::dom::XNode>& rPropertyLabel) : m_bChildCanFocus(bChildCanFocus) , m_bHasVisible(bHasVisible) - , m_bHasIconName(bHasIconName) + , m_bHasSymbolicIconName(bHasSymbolicIconName) , m_bAlwaysShowImage(bAlwaysShowImage) , m_xPropertyLabel(rPropertyLabel) { } }; +bool IsAllowedBuiltInIcon(std::u16string_view iconName) +{ + // limit the named icons to those known by VclBuilder + return VclBuilder::mapStockToSymbol(iconName) != SymbolType::DONTKNOW; +} + ConvertResult Convert3To4(const css::uno::Reference<css::xml::dom::XNode>& xNode) { css::uno::Reference<css::xml::dom::XNodeList> xNodeList = xNode->getChildNodes(); @@ -281,7 +288,7 @@ ConvertResult Convert3To4(const css::uno::Reference<css::xml::dom::XNode>& xNode OUString sBorderWidth; bool bChildCanFocus = false; bool bHasVisible = false; - bool bHasIconName = false; + bool bHasSymbolicIconName = false; bool bAlwaysShowImage = false; css::uno::Reference<css::xml::dom::XNode> xPropertyLabel; css::uno::Reference<css::xml::dom::XNode> xCantFocus; @@ -363,7 +370,22 @@ ConvertResult Convert3To4(const css::uno::Reference<css::xml::dom::XNode>& xNode bHasVisible = true; if (sName == "icon-name") - bHasIconName = true; + { + OUString sIconName(xChild->getFirstChild()->getNodeValue()); + bHasSymbolicIconName = IsAllowedBuiltInIcon(sIconName); + if (!bHasSymbolicIconName) + { + auto xDoc = xChild->getOwnerDocument(); + // private:graphicrepository/ would be turned by gio (?) into private:///graphicrepository/ + // so use private:///graphicrepository/ here. At the moment we just want this to be transported + // as-is to postprocess_widget. Though it might be nice to register a protocol handler with gio + // to avoid us doing the load in that second pass. + auto xUri + = CreateProperty(xDoc, "file", "private:///graphicrepository/" + sIconName); + xChild->getParentNode()->insertBefore(xUri, xChild); + xRemoveList.push_back(xChild); + } + } if (sName == "events") xRemoveList.push_back(xChild); @@ -419,6 +441,8 @@ ConvertResult Convert3To4(const css::uno::Reference<css::xml::dom::XNode>& xNode SAL_WARN("vcl.gtk", "what should we do with an icon-size of: " << xChild->getFirstChild()->getNodeValue()); } + else if (GetParentObjectType(xChild) == "GtkPicture") + xRemoveList.push_back(xChild); } if (sName == "truncate-multiline") @@ -726,7 +750,7 @@ ConvertResult Convert3To4(const css::uno::Reference<css::xml::dom::XNode>& xNode auto xNextChild = xChild->getNextSibling(); - bool bChildHasIconName = false; + bool bChildHasSymbolicIconName = false; bool bChildHasVisible = false; bool bChildAlwaysShowImage = false; css::uno::Reference<css::xml::dom::XNode> xChildPropertyLabel; @@ -742,7 +766,7 @@ ConvertResult Convert3To4(const css::uno::Reference<css::xml::dom::XNode>& xNode if (xChild->getNodeName() == "object") { bChildHasVisible = aChildRes.m_bHasVisible; - bChildHasIconName = aChildRes.m_bHasIconName; + bChildHasSymbolicIconName = aChildRes.m_bHasSymbolicIconName; bChildAlwaysShowImage = aChildRes.m_bAlwaysShowImage; xChildPropertyLabel = aChildRes.m_xPropertyLabel; } @@ -921,7 +945,7 @@ ConvertResult Convert3To4(const css::uno::Reference<css::xml::dom::XNode>& xNode { xClass->setNodeValue("GtkCheckButton"); } - else if (sClass == "GtkImage" && !bChildHasIconName) + else if (sClass == "GtkImage" && !bChildHasSymbolicIconName) { xClass->setNodeValue("GtkPicture"); } @@ -1017,7 +1041,7 @@ ConvertResult Convert3To4(const css::uno::Reference<css::xml::dom::XNode>& xNode for (auto& xRemove : xRemoveList) xNode->removeChild(xRemove); - return ConvertResult(bChildCanFocus, bHasVisible, bHasIconName, bAlwaysShowImage, + return ConvertResult(bChildCanFocus, bHasVisible, bHasSymbolicIconName, bAlwaysShowImage, xPropertyLabel); } } _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
