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/QtInstanceMenuButton.hxx |   37 ++++++++++++++++++++
 vcl/inc/qt6/QtInstanceMenuButton.hxx |   12 ++++++
 vcl/qt5/QtBuilder.cxx                |    2 -
 vcl/qt5/QtInstanceBuilder.cxx        |    9 +++--
 vcl/qt5/QtInstanceMenuButton.cxx     |   62 +++++++++++++++++++++++++++++++++++
 vcl/qt6/QtInstanceMenuButton.cxx     |   12 ++++++
 11 files changed, 135 insertions(+), 5 deletions(-)

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

    tdf#130857 qt weld: Introduce QtInstanceMenuButton
    
    Add new QtInstanceMenuButton class as the native Qt
    weld::MenuButton implementation.
    
    The actual logic of the class methods still needs to
    be implemented, they all just trigger an assert when
    called right now.
    
    Create a QToolButton for "GtkMenuButton" objects in .ui files.
    
    Let QtInstanceBuilder::weld_menu_button create an instance
    of that new class and pass the button in the ctor.
    
    Change-Id: Ie5ba0bad8e351554323e8f4ec1281b2c5ae8fbc3
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/178963
    Reviewed-by: Michael Weghorn <[email protected]>
    Tested-by: Jenkins

diff --git a/vcl/CustomTarget_qt5_moc.mk b/vcl/CustomTarget_qt5_moc.mk
index 17c91545cdb0..115dd8f48579 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/QtInstanceMenuButton.moc \
        $(gb_CustomTarget_workdir)/vcl/qt5/QtInstanceMessageDialog.moc \
        $(gb_CustomTarget_workdir)/vcl/qt5/QtInstanceNotebook.moc \
        $(gb_CustomTarget_workdir)/vcl/qt5/QtInstanceProgressBar.moc \
diff --git a/vcl/CustomTarget_qt6_moc.mk b/vcl/CustomTarget_qt6_moc.mk
index 214a17952bc4..990da773f31f 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/QtInstanceMenuButton.moc \
        $(gb_CustomTarget_workdir)/vcl/qt6/QtInstanceMessageDialog.moc \
        $(gb_CustomTarget_workdir)/vcl/qt6/QtInstanceNotebook.moc \
        $(gb_CustomTarget_workdir)/vcl/qt6/QtInstanceProgressBar.moc \
diff --git a/vcl/Library_vclplug_qt5.mk b/vcl/Library_vclplug_qt5.mk
index b260c4fae083..79f61aa7eb89 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/QtInstanceMenuButton \
     vcl/qt5/QtInstanceMessageDialog \
     vcl/qt5/QtInstanceNotebook \
     vcl/qt5/QtInstanceProgressBar \
diff --git a/vcl/Library_vclplug_qt6.mk b/vcl/Library_vclplug_qt6.mk
index 56bab58a2918..027c47b0b47a 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/QtInstanceMenuButton \
     vcl/qt6/QtInstanceMessageDialog \
     vcl/qt6/QtInstanceNotebook \
     vcl/qt6/QtInstanceProgressBar \
diff --git a/vcl/inc/qt5/QtInstanceBuilder.hxx 
b/vcl/inc/qt5/QtInstanceBuilder.hxx
index 4cf1a59a6b55..a94e074f29fa 100644
--- a/vcl/inc/qt5/QtInstanceBuilder.hxx
+++ b/vcl/inc/qt5/QtInstanceBuilder.hxx
@@ -43,7 +43,7 @@ public:
     weld_scrolled_window(const OUString& rId, bool bUserManagedScrolling = 
false) override;
     virtual std::unique_ptr<weld::Notebook> weld_notebook(const OUString& rId) 
override;
     virtual std::unique_ptr<weld::Button> weld_button(const OUString& rId) 
override;
-    virtual std::unique_ptr<weld::MenuButton> weld_menu_button(const 
OUString&) override;
+    virtual std::unique_ptr<weld::MenuButton> weld_menu_button(const OUString& 
rId) override;
     virtual std::unique_ptr<weld::MenuToggleButton>
     weld_menu_toggle_button(const OUString&) override;
     virtual std::unique_ptr<weld::LinkButton> weld_link_button(const OUString& 
rId) override;
diff --git a/vcl/inc/qt5/QtInstanceMenuButton.hxx 
b/vcl/inc/qt5/QtInstanceMenuButton.hxx
new file mode 100644
index 000000000000..097811945392
--- /dev/null
+++ b/vcl/inc/qt5/QtInstanceMenuButton.hxx
@@ -0,0 +1,37 @@
+/* -*- 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 "QtInstanceToggleButton.hxx"
+
+class QtInstanceMenuButton : public QtInstanceToggleButton, public virtual 
weld::MenuButton
+{
+    Q_OBJECT
+
+public:
+    QtInstanceMenuButton(QAbstractButton* pButton);
+
+    virtual void insert_item(int pos, const OUString& rId, const OUString& 
rStr,
+                             const OUString* pIconName, VirtualDevice* 
pImageSurface,
+                             TriState eCheckRadioFalse) override;
+
+    virtual void insert_separator(int pos, const OUString& rId) override;
+    virtual void remove_item(const OUString& rId) override;
+    virtual void clear() override;
+    virtual void set_item_sensitive(const OUString& rIdent, bool bSensitive) 
override;
+    virtual void set_item_active(const OUString& rIdent, bool bActive) 
override;
+    virtual void set_item_label(const OUString& rIdent, const OUString& 
rLabel) override;
+    virtual OUString get_item_label(const OUString& rIdent) const override;
+    virtual void set_item_visible(const OUString& rIdent, bool bVisible) 
override;
+
+    virtual void set_popover(weld::Widget* pPopover) override;
+};
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */
diff --git a/vcl/inc/qt6/QtInstanceMenuButton.hxx 
b/vcl/inc/qt6/QtInstanceMenuButton.hxx
new file mode 100644
index 000000000000..0468723ead93
--- /dev/null
+++ b/vcl/inc/qt6/QtInstanceMenuButton.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/QtInstanceMenuButton.hxx"
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */
diff --git a/vcl/qt5/QtBuilder.cxx b/vcl/qt5/QtBuilder.cxx
index 8d37ea196caf..b03bd8a9646c 100644
--- a/vcl/qt5/QtBuilder.cxx
+++ b/vcl/qt5/QtBuilder.cxx
@@ -316,7 +316,7 @@ QObject* QtBuilder::makeObject(QObject* pParent, 
std::u16string_view sName, std:
     {
         pObject = new QPlainTextEdit(pParentWidget);
     }
-    else if (sName == u"GtkToggleButton")
+    else if (sName == u"GtkToggleButton" || sName == u"GtkMenuButton")
     {
         pObject = new QToolButton(pParentWidget);
     }
diff --git a/vcl/qt5/QtInstanceBuilder.cxx b/vcl/qt5/QtInstanceBuilder.cxx
index f6c92169a09d..43e023fdebf0 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 <QtInstanceMenuButton.hxx>
 #include <QtInstanceMessageDialog.hxx>
 #include <QtInstanceNotebook.hxx>
 #include <QtInstanceProgressBar.hxx>
@@ -204,10 +205,12 @@ std::unique_ptr<weld::Button> 
QtInstanceBuilder::weld_button(const OUString& rId
     return xRet;
 }
 
-std::unique_ptr<weld::MenuButton> QtInstanceBuilder::weld_menu_button(const 
OUString&)
+std::unique_ptr<weld::MenuButton> QtInstanceBuilder::weld_menu_button(const 
OUString& rId)
 {
-    assert(false && "Not implemented yet");
-    return nullptr;
+    QAbstractButton* pButton = m_xBuilder->get<QAbstractButton>(rId);
+    std::unique_ptr<weld::MenuButton> xRet(pButton ? 
std::make_unique<QtInstanceMenuButton>(pButton)
+                                                   : nullptr);
+    return xRet;
 }
 
 std::unique_ptr<weld::MenuToggleButton> 
QtInstanceBuilder::weld_menu_toggle_button(const OUString&)
diff --git a/vcl/qt5/QtInstanceMenuButton.cxx b/vcl/qt5/QtInstanceMenuButton.cxx
new file mode 100644
index 000000000000..cde0312183e3
--- /dev/null
+++ b/vcl/qt5/QtInstanceMenuButton.cxx
@@ -0,0 +1,62 @@
+/* -*- 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 <QtInstanceMenuButton.hxx>
+#include <QtInstanceMenuButton.moc>
+
+QtInstanceMenuButton::QtInstanceMenuButton(QAbstractButton* pButton)
+    : QtInstanceToggleButton(pButton)
+{
+    assert(pButton);
+}
+
+void QtInstanceMenuButton::insert_item(int, const OUString&, const OUString&, 
const OUString*,
+                                       VirtualDevice*, TriState)
+{
+    assert(false && "Not implemented yet");
+}
+
+void QtInstanceMenuButton::insert_separator(int, const OUString&)
+{
+    assert(false && "Not implemented yet");
+}
+
+void QtInstanceMenuButton::remove_item(const OUString&) { assert(false && "Not 
implemented yet"); }
+
+void QtInstanceMenuButton::clear() { assert(false && "Not implemented yet"); }
+
+void QtInstanceMenuButton::set_item_sensitive(const OUString&, bool)
+{
+    assert(false && "Not implemented yet");
+}
+
+void QtInstanceMenuButton::set_item_active(const OUString&, bool)
+{
+    assert(false && "Not implemented yet");
+}
+
+void QtInstanceMenuButton::set_item_label(const OUString&, const OUString&)
+{
+    assert(false && "Not implemented yet");
+}
+
+OUString QtInstanceMenuButton::get_item_label(const OUString&) const
+{
+    assert(false && "Not implemented yet");
+    return OUString();
+}
+
+void QtInstanceMenuButton::set_item_visible(const OUString&, bool)
+{
+    assert(false && "Not implemented yet");
+}
+
+void QtInstanceMenuButton::set_popover(weld::Widget*) { assert(false && "Not 
implemented yet"); }
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */
diff --git a/vcl/qt6/QtInstanceMenuButton.cxx b/vcl/qt6/QtInstanceMenuButton.cxx
new file mode 100644
index 000000000000..785d7069e43d
--- /dev/null
+++ b/vcl/qt6/QtInstanceMenuButton.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/QtInstanceMenuButton.cxx"
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */

Reply via email to