/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
/* Template class for a Builder to create a hierarchy of widgets from a .ui file * for dialogs, sidebar, etc. * * This class parses the .ui file and calls overridable methods * so subclasses can create the widgets of a specific toolkit. * * The VclBuilder subclass is the implementation using LibreOffice's own VCL toolkit * and the QtBuilder subclass uses native Qt widgets.
*/ template <typename Widget, typename WidgetPtr, typename MenuClass, typename MenuPtr> class WidgetBuilder : public BuilderBase
{ protected: struct MenuAndId
{
OUString m_sID;
MenuPtr m_pMenu;
MenuAndId(OUString sId, MenuClass* pMenu)
: m_sID(std::move(sId))
, m_pMenu(pMenu)
{
}
};
public: //sID may not exist
MenuClass* get_menu(std::u16string_view sID)
{ for (autoconst& menu : m_aMenus)
{ if (menu.m_sID == sID) return menu.m_pMenu;
}
// Set Mnemonic widgets when everything has been imported for (const MnemonicWidgetMap& rMnemonic : getMnemonicWidgetMaps())
{
setMnemonicWidget(rMnemonic.m_sID, rMnemonic.m_sValue);
}
// Set radiobutton groups when everything has been imported for (const RadioButtonGroupMap& rGroup : getRadioButtonGroupMaps())
setRadioButtonGroup(rGroup.m_sID, rGroup.m_sValue);
}
// either pParent or pAtkProps must be set, pParent for a child of a widget, pAtkProps for // collecting the atk info for a GtkMenuItem or tab child void handleChild(Widget* pParent, stringmap* pAtkProps, xmlreader::XmlReader& reader, bool bToolbarItem = false)
{
xmlreader::Span name; int nsId;
OString sType, sInternalChild;
while (reader.nextAttribute(&nsId, &name))
{ if (name == "type")
{
name = reader.getAttributeValue(false);
sType = OString(name.begin, name.length);
} elseif (name == "internal-child")
{
name = reader.getAttributeValue(false);
sInternalChild = OString(name.begin, name.length);
}
}
if (sType == "tab")
{
handleTabChild(pParent, reader); return;
}
WidgetPtr pCurrentChild = nullptr; int nLevel = 1; while (true)
{
xmlreader::XmlReader::Result res
= reader.nextItem(xmlreader::XmlReader::Text::NONE, &name, &nsId);
if (res == xmlreader::XmlReader::Result::Begin)
{ if (name == "object" || name == "placeholder")
{
pCurrentChild = handleObject(pParent, pAtkProps, reader, sType, sInternalChild,
bToolbarItem);
if (!sCustomProperty.isEmpty())
aProperties[u"customproperty"_ustr] = sCustomProperty;
// Internal-children default in glade to not having their visible bits set // even though they are visible (generally anyway) if (!sInternalChild.empty())
aProperties[u"visible"_ustr] = "True";
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;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.