diff options
author | Michael Weghorn <m.weghorn@posteo.de> | 2024-09-20 14:03:00 +0200 |
---|---|---|
committer | Michael Weghorn <m.weghorn@posteo.de> | 2024-09-25 21:08:59 +0200 |
commit | 385bbbd6e1f602d066b00c0913aefa36e75ce5a6 (patch) | |
tree | 500379b431d67f0e8a3ac1d3aaf4ee168e4b95ef /include | |
parent | f61ecf25636d401f862c4de226c04237e1fb2f69 (diff) |
tdf#130857 Move VclBuilder::handleObject to WidgetBuilder base
Move `VclBuilder::handleObject` to the template base class
`WidgetBuilder` introduced in previous commit
Change-Id: I2d81cc6dd54d796b549357a4444b95627661c623
Author: OmkarAcharekar <omkaracharekar12@gmail.com>
Date: Fri Sep 20 13:33:01 2024 +0200
tdf#130857 refactor VclBuilder: Extract template base class
Add new virtual methods to that base class to override in the
subclasses. These are currently the ones that `VclBuilder`
already implements for `vcl::Window`.
More refactoring - in particular for those methods that currently
still do XML parsing themselves is planned for the future
once the relevant functionality will be implemented in
other subclasses. For now, those methods that do XML parsing
themseslves trigger an assert in the base class implementation
and remain unchanged in the `VclBuilder` implementation.
One aspect to be aware of is that `WidgetPtr` should explicitly
be initialized to `nullptr` if not assigned a different value:
While `VclPtr` that gets used for `VclBuilder` has a default ctor
that takes care of proper initialization, that's not the case for
the upcoming `QtBuilder` [1] that just uses `QObject*` for `WidgetPtr`.
[1] https://gerrit.libreoffice.org/c/core/+/161831
Change-Id: I5c1b7201c82ca2c0c2d7389642aee407ebea16ce
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/173737
Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
Tested-by: Jenkins
Diffstat (limited to 'include')
-rw-r--r-- | include/vcl/builder.hxx | 23 | ||||
-rw-r--r-- | include/vcl/widgetbuilder.hxx | 155 |
2 files changed, 162 insertions, 16 deletions
diff --git a/include/vcl/builder.hxx b/include/vcl/builder.hxx index 353d300015b3..3ad480eece64 100644 --- a/include/vcl/builder.hxx +++ b/include/vcl/builder.hxx @@ -189,8 +189,8 @@ private: void mungeModel(ComboBox &rTarget, const ListStore &rStore, sal_uInt16 nActiveId); void mungeModel(SvTabListBox &rTarget, const ListStore &rStore, sal_uInt16 nActiveId); - void insertComboBoxOrListBoxItems(vcl::Window *pWindow, VclBuilder::stringmap &rMap, - const std::vector<ComboBoxTextItem>& rItems); + void insertComboBoxOrListBoxItems(vcl::Window* pWindow, stringmap& rMap, + const std::vector<ComboBoxTextItem>& rItems) override; static void mungeTextBuffer(VclMultiLineEdit &rTarget, const TextBuffer &rTextBuffer); @@ -269,10 +269,9 @@ private: void tweakInsertedChild(vcl::Window *pParent, vcl::Window* pCurrentChild, std::string_view sType, std::string_view sInternalChild) override; - VclPtr<vcl::Window> insertObject(vcl::Window *pParent, - const OUString &rClass, const OUString &rID, - stringmap &rProps, stringmap &rPangoAttributes, - stringmap &rAtkProps); + VclPtr<vcl::Window> insertObject(vcl::Window* pParent, const OUString& rClass, + const OUString& rID, stringmap& rProps, + stringmap& rPangoAttributes, stringmap& rAtkProps) override; VclPtr<vcl::Window> makeObject(vcl::Window *pParent, const OUString &rClass, const OUString &rID, @@ -290,8 +289,6 @@ private: void extractButtonImage(const OUString &id, stringmap &rMap, bool bRadio); void extractMnemonicWidget(const OUString &id, stringmap &rMap); - VclPtr<vcl::Window> handleObject(vcl::Window *pParent, stringmap *pAtkProps, xmlreader::XmlReader &reader, bool bToolbarItem) override; - void applyPackingProperties(vcl::Window* pCurrent, vcl::Window* pParent, const stringmap& rPackingProperties) override; @@ -309,13 +306,15 @@ private: void handleTabChild(vcl::Window *pParent, xmlreader::XmlReader &reader) override; void handleMenu(xmlreader::XmlReader& reader, vcl::Window* pParent, const OUString& rID, - bool bMenuBar); + bool bMenuBar) override; // if bToolbarItem=true, pParent is the ToolBox that the item belongs to, since there's no widget for the item itself - void applyAtkProperties(vcl::Window *pWindow, const stringmap& rProperties, bool bToolbarItem); + void applyAtkProperties(vcl::Window* pWindow, const stringmap& rProperties, + bool bToolbarItem) override; - static void setPriority(vcl::Window* pWindow, int nPriority); - static void setContext(vcl::Window* pWindow, std::vector<vcl::EnumContext::Context>&& aContext); + void setPriority(vcl::Window* pWindow, int nPriority) override; + void setContext(vcl::Window* pWindow, + std::vector<vcl::EnumContext::Context>&& aContext) override; PackingData get_window_packing_data(const vcl::Window *pWindow) const; void set_window_packing_position(const vcl::Window *pWindow, sal_Int32 nPosition); diff --git a/include/vcl/widgetbuilder.hxx b/include/vcl/widgetbuilder.hxx index a12bff918c0a..da2370ad5845 100644 --- a/include/vcl/widgetbuilder.hxx +++ b/include/vcl/widgetbuilder.hxx @@ -9,8 +9,8 @@ #pragma once +#include <sal/log.hxx> #include <vcl/builderbase.hxx> - #include <xmlreader/span.hxx> #include <xmlreader/xmlreader.hxx> @@ -114,13 +114,159 @@ protected: } } + WidgetPtr handleObject(Widget* pParent, stringmap* pAtkProps, xmlreader::XmlReader& reader, + bool bToolbarItem) + { + OUString sClass; + OUString sID; + OUString sCustomProperty; + extractClassAndIdAndCustomProperty(reader, sClass, sID, sCustomProperty); + + if (sClass == "GtkListStore" || sClass == "GtkTreeStore") + { + handleListStore(reader, sID, sClass); + return nullptr; + } + else if (sClass == "GtkMenu") + { + handleMenu(reader, pParent, sID, false); + return nullptr; + } + else if (sClass == "GtkMenuBar") + { + handleMenu(reader, pParent, sID, true); + return nullptr; + } + else if (sClass == "GtkSizeGroup") + { + handleSizeGroup(reader); + return nullptr; + } + else if (sClass == "AtkObject") + { + assert((pParent || pAtkProps) && "must have one set"); + assert(!(pParent && pAtkProps) && "must not have both"); + auto aAtkProperties = handleAtkObject(reader); + if (pParent) + applyAtkProperties(pParent, aAtkProperties, bToolbarItem); + if (pAtkProps) + *pAtkProps = std::move(aAtkProperties); + return nullptr; + } + + int nLevel = 1; + + stringmap aProperties, aPangoAttributes; + stringmap aAtkAttributes; + std::vector<ComboBoxTextItem> aItems; + + if (!sCustomProperty.isEmpty()) + aProperties[u"customproperty"_ustr] = sCustomProperty; + + WidgetPtr pCurrentChild = nullptr; + while (true) + { + xmlreader::Span name; + int nsId; + xmlreader::XmlReader::Result res + = reader.nextItem(xmlreader::XmlReader::Text::NONE, &name, &nsId); + + if (res == xmlreader::XmlReader::Result::Done) + break; + + if (res == xmlreader::XmlReader::Result::Begin) + { + if (name == "child") + { + if (!pCurrentChild) + { + pCurrentChild = insertObject(pParent, sClass, sID, aProperties, + aPangoAttributes, aAtkAttributes); + } + handleChild(pCurrentChild, nullptr, reader, isToolbarItemClass(sClass)); + } + else if (name == "items") + aItems = handleItems(reader); + else if (name == "style") + { + int nPriority = 0; + std::vector<vcl::EnumContext::Context> aContext + = handleStyle(reader, nPriority); + if (nPriority != 0) + setPriority(pCurrentChild, nPriority); + if (!aContext.empty()) + setContext(pCurrentChild, std::move(aContext)); + } + else + { + ++nLevel; + if (name == "property") + collectProperty(reader, aProperties); + else if (name == "attribute") + collectPangoAttribute(reader, aPangoAttributes); + else if (name == "relation") + collectAtkRelationAttribute(reader, aAtkAttributes); + else if (name == "role") + collectAtkRoleAttribute(reader, aAtkAttributes); + else if (name == "action-widget") + handleActionWidget(reader); + } + } + + if (res == xmlreader::XmlReader::Result::End) + { + --nLevel; + } + + if (!nLevel) + break; + } + + if (sClass == "GtkAdjustment") + { + addAdjustment(sID, aProperties); + return nullptr; + } + else if (sClass == "GtkTextBuffer") + { + addTextBuffer(sID, aProperties); + return nullptr; + } + + if (!pCurrentChild) + { + pCurrentChild + = insertObject(pParent, sClass, sID, aProperties, aPangoAttributes, aAtkAttributes); + } + + if (!aItems.empty()) + insertComboBoxOrListBoxItems(pCurrentChild, aProperties, aItems); + + return pCurrentChild; + } + + virtual void applyAtkProperties(Widget* pWidget, const stringmap& rProperties, + bool bToolbarItem) + = 0; virtual void applyPackingProperties(Widget* pCurrentChild, Widget* pParent, const stringmap& rPackingProperties) = 0; + virtual void insertComboBoxOrListBoxItems(Widget* pWidget, stringmap& rMap, + const std::vector<ComboBoxTextItem>& rItems) + = 0; + + virtual WidgetPtr insertObject(Widget* pParent, const OUString& rClass, const OUString& rID, + stringmap& rProps, stringmap& rPangoAttributes, + stringmap& rAtkProps) + = 0; + virtual void tweakInsertedChild(Widget* pParent, Widget* pCurrentChild, std::string_view sType, std::string_view sInternalChild) = 0; + virtual void setPriority(Widget* pWidget, int nPriority) = 0; + virtual void setContext(Widget* pWidget, std::vector<vcl::EnumContext::Context>&& aContext) = 0; + // These methods are currently only implemented by VclBuilder and should be // refactored as described in the class documentation above (split into // parsing done in this class + overridable methods that don't need XmlReader @@ -128,13 +274,14 @@ protected: // // Until that's done, other subclasses can be used to handle only those .ui files // not using the corresponding features (attributes/objects in the .ui file). - virtual WidgetPtr handleObject(Widget* /*pParent*/, stringmap* /*pAtkProps*/, - xmlreader::XmlReader& /*reader*/, bool /*bToolbarItem*/) + virtual void handleMenu(xmlreader::XmlReader& /*reader*/, Widget* /*pParent*/, + const OUString& /*rID*/, bool /*bMenuBar*/) { assert(false && "Functionality not implemented by this subclass yet."); - return nullptr; } + virtual void handleTabChild(Widget* /*pParent*/, xmlreader::XmlReader& /*reader*/) + { assert(false && "Functionality not implemented by this subclass yet."); } |