vcl/CustomTarget_qt5_moc.mk       |    1 
 vcl/CustomTarget_qt6_moc.mk       |    1 
 vcl/Library_vclplug_qt5.mk        |    1 
 vcl/Library_vclplug_qt6.mk        |    1 
 vcl/inc/qt5/QtInstanceBuilder.hxx |    2 
 vcl/inc/qt5/QtInstanceMenu.hxx    |   53 ++++++++++++++++++++
 vcl/inc/qt6/QtInstanceMenu.hxx    |   12 ++++
 vcl/qt5/QtInstanceBuilder.cxx     |    8 +--
 vcl/qt5/QtInstanceMenu.cxx        |   97 ++++++++++++++++++++++++++++++++++++++
 vcl/qt6/QtInstanceMenu.cxx        |   12 ++++
 10 files changed, 184 insertions(+), 4 deletions(-)

New commits:
commit b8ca64234f2b35b0d984999f36414bb20cf192b7
Author:     Michael Weghorn <[email protected]>
AuthorDate: Fri Dec 20 21:34:46 2024 +0100
Commit:     Michael Weghorn <[email protected]>
CommitDate: Sat Dec 21 09:29:21 2024 +0100

    tdf#130857 qt weld: Introduce QtInstanceMenu
    
    Introduce QtInstanceMenu as the native Qt implementation
    for weld::Menu.
    
    This mostly adds the basic structure.
    For all methods except QtInstanceMenu::clear,
    the actual logic still needs to be implemented.
    
    Change-Id: I983f2cd3976eee50f55b2ac702578833dbad3d39
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/178964
    Reviewed-by: Michael Weghorn <[email protected]>
    Tested-by: Jenkins

diff --git a/vcl/CustomTarget_qt5_moc.mk b/vcl/CustomTarget_qt5_moc.mk
index 115dd8f48579..47fa70642760 100644
--- a/vcl/CustomTarget_qt5_moc.mk
+++ b/vcl/CustomTarget_qt5_moc.mk
@@ -29,6 +29,7 @@ $(call gb_CustomTarget_get_target,vcl/qt5) : \
        $(gb_CustomTarget_workdir)/vcl/qt5/QtInstanceLabel.moc \
        $(gb_CustomTarget_workdir)/vcl/qt5/QtInstanceLevelBar.moc \
        $(gb_CustomTarget_workdir)/vcl/qt5/QtInstanceLinkButton.moc \
+       $(gb_CustomTarget_workdir)/vcl/qt5/QtInstanceMenu.moc \
        $(gb_CustomTarget_workdir)/vcl/qt5/QtInstanceMenuButton.moc \
        $(gb_CustomTarget_workdir)/vcl/qt5/QtInstanceMessageDialog.moc \
        $(gb_CustomTarget_workdir)/vcl/qt5/QtInstanceNotebook.moc \
diff --git a/vcl/CustomTarget_qt6_moc.mk b/vcl/CustomTarget_qt6_moc.mk
index 990da773f31f..36828b2d00b4 100644
--- a/vcl/CustomTarget_qt6_moc.mk
+++ b/vcl/CustomTarget_qt6_moc.mk
@@ -29,6 +29,7 @@ $(call gb_CustomTarget_get_target,vcl/qt6) : \
        $(gb_CustomTarget_workdir)/vcl/qt6/QtInstanceLabel.moc \
        $(gb_CustomTarget_workdir)/vcl/qt6/QtInstanceLevelBar.moc \
        $(gb_CustomTarget_workdir)/vcl/qt6/QtInstanceLinkButton.moc \
+       $(gb_CustomTarget_workdir)/vcl/qt6/QtInstanceMenu.moc \
        $(gb_CustomTarget_workdir)/vcl/qt6/QtInstanceMenuButton.moc \
        $(gb_CustomTarget_workdir)/vcl/qt6/QtInstanceMessageDialog.moc \
        $(gb_CustomTarget_workdir)/vcl/qt6/QtInstanceNotebook.moc \
diff --git a/vcl/Library_vclplug_qt5.mk b/vcl/Library_vclplug_qt5.mk
index 79f61aa7eb89..30c2fa8bf45a 100644
--- a/vcl/Library_vclplug_qt5.mk
+++ b/vcl/Library_vclplug_qt5.mk
@@ -115,6 +115,7 @@ $(eval $(call gb_Library_add_exception_objects,vclplug_qt5,\
     vcl/qt5/QtInstanceLabel \
     vcl/qt5/QtInstanceLevelBar \
     vcl/qt5/QtInstanceLinkButton \
+    vcl/qt5/QtInstanceMenu \
     vcl/qt5/QtInstanceMenuButton \
     vcl/qt5/QtInstanceMessageDialog \
     vcl/qt5/QtInstanceNotebook \
diff --git a/vcl/Library_vclplug_qt6.mk b/vcl/Library_vclplug_qt6.mk
index 027c47b0b47a..43100fa3d585 100644
--- a/vcl/Library_vclplug_qt6.mk
+++ b/vcl/Library_vclplug_qt6.mk
@@ -114,6 +114,7 @@ $(eval $(call gb_Library_add_exception_objects,vclplug_qt6,\
     vcl/qt6/QtInstanceLabel \
     vcl/qt6/QtInstanceLevelBar \
     vcl/qt6/QtInstanceLinkButton \
+    vcl/qt6/QtInstanceMenu \
     vcl/qt6/QtInstanceMenuButton \
     vcl/qt6/QtInstanceMessageDialog \
     vcl/qt6/QtInstanceNotebook \
diff --git a/vcl/inc/qt5/QtInstanceBuilder.hxx 
b/vcl/inc/qt5/QtInstanceBuilder.hxx
index a94e074f29fa..484df49bc50b 100644
--- a/vcl/inc/qt5/QtInstanceBuilder.hxx
+++ b/vcl/inc/qt5/QtInstanceBuilder.hxx
@@ -74,7 +74,7 @@ public:
     weld_drawing_area(const OUString&, const a11yref& rA11yImpl = nullptr,
                       FactoryFunction pUITestFactoryFunction = nullptr,
                       void* pUserData = nullptr) override;
-    virtual std::unique_ptr<weld::Menu> weld_menu(const OUString&) override;
+    virtual std::unique_ptr<weld::Menu> weld_menu(const OUString& rId) 
override;
     virtual std::unique_ptr<weld::Popover> weld_popover(const OUString&) 
override;
     virtual std::unique_ptr<weld::Toolbar> weld_toolbar(const OUString&) 
override;
     virtual std::unique_ptr<weld::Scrollbar> weld_scrollbar(const OUString&) 
override;
diff --git a/vcl/inc/qt5/QtInstanceMenu.hxx b/vcl/inc/qt5/QtInstanceMenu.hxx
new file mode 100644
index 000000000000..3133351cf005
--- /dev/null
+++ b/vcl/inc/qt5/QtInstanceMenu.hxx
@@ -0,0 +1,53 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; 
fill-column: 100 -*- */
+/*
+ * 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/.
+ */
+
+#pragma once
+
+#include <QtWidgets/QMenu>
+
+#include <vcl/weld.hxx>
+
+class QtInstanceMenu : public QObject, public virtual weld::Menu
+{
+    Q_OBJECT
+
+    QMenu* m_pMenu;
+
+public:
+    QtInstanceMenu(QMenu* pMenu);
+
+    virtual OUString popup_at_rect(weld::Widget* pParent, const 
tools::Rectangle& rRect,
+                                   weld::Placement ePlace = 
weld::Placement::Under) override;
+
+    virtual void set_sensitive(const OUString& rIdent, bool bSensitive) 
override;
+    virtual bool get_sensitive(const OUString& rIdent) const override;
+    virtual void set_label(const OUString& rIdent, const OUString& rLabel) 
override;
+    virtual OUString get_label(const OUString& rIdent) const override;
+    virtual void set_active(const OUString& rIdent, bool bActive) override;
+    virtual bool get_active(const OUString& rIdent) const override;
+    virtual void set_visible(const OUString& rIdent, bool bVisible) override;
+
+    virtual void insert(int pos, const OUString& rId, const OUString& rStr,
+                        const OUString* pIconName, VirtualDevice* 
pImageSurface,
+                        const css::uno::Reference<css::graphic::XGraphic>& 
rImage,
+                        TriState eCheckRadioFalse) override;
+
+    virtual void set_item_help_id(const OUString& rIdent, const OUString& 
rHelpId) override;
+    virtual void remove(const OUString& rId) override;
+
+    virtual void clear() override;
+
+    virtual void insert_separator(int pos, const OUString& rId) override;
+
+    virtual int n_children() const override;
+
+    virtual OUString get_id(int pos) const override;
+};
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */
diff --git a/vcl/inc/qt6/QtInstanceMenu.hxx b/vcl/inc/qt6/QtInstanceMenu.hxx
new file mode 100644
index 000000000000..9fc95fb09529
--- /dev/null
+++ b/vcl/inc/qt6/QtInstanceMenu.hxx
@@ -0,0 +1,12 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; 
fill-column: 100 -*- */
+/*
+ * 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/.
+ */
+
+#include "../qt5/QtInstanceMenu.hxx"
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */
diff --git a/vcl/qt5/QtInstanceBuilder.cxx b/vcl/qt5/QtInstanceBuilder.cxx
index 43e023fdebf0..899acaa7e75d 100644
--- a/vcl/qt5/QtInstanceBuilder.cxx
+++ b/vcl/qt5/QtInstanceBuilder.cxx
@@ -24,6 +24,7 @@
 #include <QtInstanceLevelBar.hxx>
 #include <QtInstanceLinkButton.hxx>
 #include <QtInstanceIconView.hxx>
+#include <QtInstanceMenu.hxx>
 #include <QtInstanceMenuButton.hxx>
 #include <QtInstanceMessageDialog.hxx>
 #include <QtInstanceNotebook.hxx>
@@ -387,10 +388,11 @@ QtInstanceBuilder::weld_drawing_area(const OUString& rId, 
const a11yref&, Factor
     return xRet;
 }
 
-std::unique_ptr<weld::Menu> QtInstanceBuilder::weld_menu(const OUString&)
+std::unique_ptr<weld::Menu> QtInstanceBuilder::weld_menu(const OUString& rId)
 {
-    assert(false && "Not implemented yet");
-    return nullptr;
+    QMenu* pMenu = m_xBuilder->get<QMenu>(rId);
+    std::unique_ptr<weld::Menu> xRet(pMenu ? 
std::make_unique<QtInstanceMenu>(pMenu) : nullptr);
+    return xRet;
 }
 
 std::unique_ptr<weld::Popover> QtInstanceBuilder::weld_popover(const OUString&)
diff --git a/vcl/qt5/QtInstanceMenu.cxx b/vcl/qt5/QtInstanceMenu.cxx
new file mode 100644
index 000000000000..c998342aab1d
--- /dev/null
+++ b/vcl/qt5/QtInstanceMenu.cxx
@@ -0,0 +1,97 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; 
fill-column: 100 -*- */
+/*
+ * 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/.
+ */
+
+#include <QtInstanceMenu.hxx>
+#include <QtInstanceMenu.moc>
+
+#include <QtInstance.hxx>
+
+#include <vcl/svapp.hxx>
+
+QtInstanceMenu::QtInstanceMenu(QMenu* pMenu)
+    : m_pMenu(pMenu)
+{
+    assert(m_pMenu);
+}
+
+OUString QtInstanceMenu::popup_at_rect(weld::Widget*, const tools::Rectangle&, 
weld::Placement)
+{
+    assert(false && "Not implemented yet");
+    return OUString();
+}
+
+void QtInstanceMenu::set_sensitive(const OUString&, bool)
+{
+    assert(false && "Not implemented yet");
+}
+
+bool QtInstanceMenu::get_sensitive(const OUString&) const
+{
+    assert(false && "Not implemented yet");
+    return false;
+}
+
+void QtInstanceMenu::set_label(const OUString&, const OUString&)
+{
+    assert(false && "Not implemented yet");
+}
+
+OUString QtInstanceMenu::get_label(const OUString&) const
+{
+    assert(false && "Not implemented yet");
+    return OUString();
+}
+
+void QtInstanceMenu::set_active(const OUString&, bool) { assert(false && "Not 
implemented yet"); }
+
+bool QtInstanceMenu::get_active(const OUString&) const
+{
+    assert(false && "Not implemented yet");
+    return false;
+}
+
+void QtInstanceMenu::set_visible(const OUString&, bool) { assert(false && "Not 
implemented yet"); }
+
+void QtInstanceMenu::insert(int, const OUString&, const OUString&, const 
OUString*, VirtualDevice*,
+                            const 
css::uno::Reference<css::graphic::XGraphic>&, TriState)
+{
+    assert(false && "Not implemented yet");
+}
+
+void QtInstanceMenu::set_item_help_id(const OUString&, const OUString&)
+{
+    assert(false && "Not implemented yet");
+}
+
+void QtInstanceMenu::remove(const OUString&) { assert(false && "Not 
implemented yet"); }
+
+void QtInstanceMenu::clear()
+{
+    SolarMutexGuard g;
+    GetQtInstance().RunInMainThread([&] { m_pMenu->clear(); });
+}
+
+void QtInstanceMenu::insert_separator(int, const OUString&)
+{
+    assert(false && "Not implemented yet");
+}
+
+int QtInstanceMenu::n_children() const
+{
+    assert(false && "Not implemented yet");
+    return 0;
+}
+
+OUString QtInstanceMenu::get_id(int) const
+{
+    assert(false && "Not implemented yet");
+    return OUString();
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */
diff --git a/vcl/qt6/QtInstanceMenu.cxx b/vcl/qt6/QtInstanceMenu.cxx
new file mode 100644
index 000000000000..e1d3b148ccc2
--- /dev/null
+++ b/vcl/qt6/QtInstanceMenu.cxx
@@ -0,0 +1,12 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; 
fill-column: 100 -*- */
+/*
+ * 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/.
+ */
+
+#include "../qt5/QtInstanceMenu.cxx"
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */

Reply via email to