vcl/Library_vclplug_qt5.mk         |    1 
 vcl/Library_vclplug_qt6.mk         |    1 
 vcl/inc/qt5/QtInstanceBuilder.hxx  |    2 
 vcl/inc/qt5/QtInstanceComboBox.hxx |   84 ++++++++++++
 vcl/inc/qt6/QtInstanceComboBox.hxx |   12 +
 vcl/qt5/QtBuilder.cxx              |    5 
 vcl/qt5/QtInstanceBuilder.cxx      |    9 -
 vcl/qt5/QtInstanceComboBox.cxx     |  240 +++++++++++++++++++++++++++++++++++++
 vcl/qt6/QtInstanceComboBox.cxx     |   12 +
 9 files changed, 362 insertions(+), 4 deletions(-)

New commits:
commit 4bdcb6169130a7cf40a1324527b41b643c811a78
Author:     Michael Weghorn <[email protected]>
AuthorDate: Tue Oct 22 18:19:45 2024 +0200
Commit:     Michael Weghorn <[email protected]>
CommitDate: Wed Oct 23 18:37:57 2024 +0200

    tdf#130857 qt weld: Add initial combobox handling
    
    * Add new class QtInstanceComboBox as a weld::ComboBox
      implementation using a native QComboBox. Implement
      some of the most important and straightforward methods
      and trigger an assert for all others for now.
    
    * In QtBuilder::makeObject, handle the "GtkComboBoxText"
      case and create a QComboBox for that.
    
    * Implement QtInstanceBuilder::weld_combo_box
      to return a QtInstanceComboBox instance.
    
    Change-Id: I2ac2d0f55a948ea2f090c81096484e22899ddcbc
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/175443
    Reviewed-by: Michael Weghorn <[email protected]>
    Tested-by: Jenkins

diff --git a/vcl/Library_vclplug_qt5.mk b/vcl/Library_vclplug_qt5.mk
index 767eab5e4024..b80fefe7947c 100644
--- a/vcl/Library_vclplug_qt5.mk
+++ b/vcl/Library_vclplug_qt5.mk
@@ -99,6 +99,7 @@ $(eval $(call gb_Library_add_exception_objects,vclplug_qt5,\
     vcl/qt5/QtInstanceButton \
     vcl/qt5/QtInstanceCheckButton \
     vcl/qt5/QtInstanceContainer \
+    vcl/qt5/QtInstanceComboBox \
     vcl/qt5/QtInstanceDialog \
     vcl/qt5/QtInstanceEntry \
     vcl/qt5/QtInstanceMessageDialog \
diff --git a/vcl/Library_vclplug_qt6.mk b/vcl/Library_vclplug_qt6.mk
index 01e0ae5a2a9d..89628d93fd93 100644
--- a/vcl/Library_vclplug_qt6.mk
+++ b/vcl/Library_vclplug_qt6.mk
@@ -97,6 +97,7 @@ $(eval $(call gb_Library_add_exception_objects,vclplug_qt6,\
     vcl/qt6/QtInstanceBuilder \
     vcl/qt6/QtInstanceButton \
     vcl/qt6/QtInstanceCheckButton \
+    vcl/qt6/QtInstanceComboBox \
     vcl/qt6/QtInstanceContainer \
     vcl/qt6/QtInstanceDialog \
     vcl/qt6/QtInstanceEntry \
diff --git a/vcl/inc/qt5/QtInstanceBuilder.hxx 
b/vcl/inc/qt5/QtInstanceBuilder.hxx
index d0332b7601be..4a5fc1d0d02a 100644
--- a/vcl/inc/qt5/QtInstanceBuilder.hxx
+++ b/vcl/inc/qt5/QtInstanceBuilder.hxx
@@ -61,7 +61,7 @@ public:
                                                                             
FieldUnit) override;
     virtual std::unique_ptr<weld::FormattedSpinButton>
     weld_formatted_spin_button(const OUString&) override;
-    virtual std::unique_ptr<weld::ComboBox> weld_combo_box(const OUString&) 
override;
+    virtual std::unique_ptr<weld::ComboBox> weld_combo_box(const OUString& 
rId) override;
     virtual std::unique_ptr<weld::EntryTreeView>
     weld_entry_tree_view(const OUString&, const OUString&, const OUString&) 
override;
     virtual std::unique_ptr<weld::TreeView> weld_tree_view(const OUString&) 
override;
diff --git a/vcl/inc/qt5/QtInstanceComboBox.hxx 
b/vcl/inc/qt5/QtInstanceComboBox.hxx
new file mode 100644
index 000000000000..cc5bd2523eb3
--- /dev/null
+++ b/vcl/inc/qt5/QtInstanceComboBox.hxx
@@ -0,0 +1,84 @@
+/* -*- 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/.
+ */
+
+#pragma once
+
+#include "QtInstanceWidget.hxx"
+
+#include <QtWidgets/QComboBox>
+
+class QtInstanceComboBox : public QtInstanceWidget, public virtual 
weld::ComboBox
+{
+    QComboBox* m_pComboBox;
+
+public:
+    QtInstanceComboBox(QComboBox* pComboBox);
+
+    virtual void insert(int nPos, const OUString& rStr, const OUString* pId,
+                        const OUString* pIconName, VirtualDevice* 
pImageSurface) override;
+    virtual void insert_vector(const std::vector<weld::ComboBoxEntry>& rItems,
+                               bool bKeepExisting) override;
+
+    virtual void insert_separator(int pos, const OUString& rId) override;
+
+    virtual int get_count() const override;
+    virtual void make_sorted() override;
+    virtual void clear() override;
+
+    virtual int get_active() const override;
+    virtual void set_active(int nPos) override;
+    virtual void remove(int nPos) override;
+
+    virtual OUString get_active_text() const override;
+    virtual OUString get_text(int nPos) const override;
+    virtual int find_text(const OUString& rStr) const override;
+
+    virtual OUString get_active_id() const override;
+    virtual void set_active_id(const OUString& rStr) override;
+    virtual OUString get_id(int pos) const override;
+    virtual void set_id(int row, const OUString& rId) override;
+    virtual int find_id(const OUString& rId) const override;
+
+    virtual bool changed_by_direct_pick() const override;
+
+    virtual bool has_entry() const override;
+    virtual void set_entry_message_type(weld::EntryMessageType eType) override;
+    virtual void set_entry_text(const OUString& rStr) override;
+    virtual void set_entry_width_chars(int nChars) override;
+    virtual void set_entry_max_length(int nChars) override;
+    virtual void select_entry_region(int nStartPos, int nEndPos) override;
+    virtual bool get_entry_selection_bounds(int& rStartPos, int& rEndPos) 
override;
+    virtual void set_entry_completion(bool bEnable, bool bCaseSensitive = 
false) override;
+    virtual void set_entry_placeholder_text(const OUString& rText) override;
+    virtual void set_entry_editable(bool bEditable) override;
+    virtual void cut_entry_clipboard() override;
+    virtual void copy_entry_clipboard() override;
+    virtual void paste_entry_clipboard() override;
+
+    virtual void set_font(const vcl::Font& rFont) override;
+
+    virtual void set_entry_font(const vcl::Font& rFont) override;
+    virtual vcl::Font get_entry_font() override;
+
+    virtual bool get_popup_shown() const override;
+
+    virtual void set_custom_renderer(bool bOn) override;
+    virtual VclPtr<VirtualDevice> create_render_virtual_device() const 
override;
+    virtual void set_item_menu(const OUString& rIdent, weld::Menu* pMenu) 
override;
+    virtual int get_menu_button_width() const override;
+
+    virtual int get_max_mru_count() const override;
+    virtual void set_max_mru_count(int nCount) override;
+    virtual OUString get_mru_entries() const override;
+    virtual void set_mru_entries(const OUString& rEntries) override;
+
+    virtual void set_max_drop_down_rows(int nRows) override;
+};
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/inc/qt6/QtInstanceComboBox.hxx 
b/vcl/inc/qt6/QtInstanceComboBox.hxx
new file mode 100644
index 000000000000..019af7c2522b
--- /dev/null
+++ b/vcl/inc/qt6/QtInstanceComboBox.hxx
@@ -0,0 +1,12 @@
+/* -*- 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/.
+ */
+
+#include "../qt5/QtInstanceComboBox.hxx"
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/qt5/QtBuilder.cxx b/vcl/qt5/QtBuilder.cxx
index bc1241d8bd56..47b013035613 100644
--- a/vcl/qt5/QtBuilder.cxx
+++ b/vcl/qt5/QtBuilder.cxx
@@ -15,6 +15,7 @@
 #include <rtl/ustrbuf.hxx>
 
 #include <QtWidgets/QCheckBox>
+#include <QtWidgets/QComboBox>
 #include <QtWidgets/QDialog>
 #include <QtWidgets/QDialogButtonBox>
 #include <QtWidgets/QGroupBox>
@@ -143,6 +144,10 @@ QObject* QtBuilder::makeObject(QObject* pParent, 
std::u16string_view sName, cons
     {
         pObject = new QCheckBox(pParentWidget);
     }
+    else if (sName == u"GtkComboBoxText")
+    {
+        pObject = new QComboBox(pParentWidget);
+    }
     else if (sName == u"GtkDialog")
     {
         pObject = new QDialog(pParentWidget);
diff --git a/vcl/qt5/QtInstanceBuilder.cxx b/vcl/qt5/QtInstanceBuilder.cxx
index 83ef9656670d..4b8c9fe2ea87 100644
--- a/vcl/qt5/QtInstanceBuilder.cxx
+++ b/vcl/qt5/QtInstanceBuilder.cxx
@@ -13,6 +13,7 @@
 
 #include <QtBuilder.hxx>
 #include <QtInstanceCheckButton.hxx>
+#include <QtInstanceComboBox.hxx>
 #include <QtInstanceEntry.hxx>
 #include <QtInstanceLabel.hxx>
 #include <QtInstanceMessageDialog.hxx>
@@ -230,10 +231,12 @@ QtInstanceBuilder::weld_formatted_spin_button(const 
OUString&)
     return nullptr;
 }
 
-std::unique_ptr<weld::ComboBox> QtInstanceBuilder::weld_combo_box(const 
OUString&)
+std::unique_ptr<weld::ComboBox> QtInstanceBuilder::weld_combo_box(const 
OUString& rId)
 {
-    assert(false && "Not implemented yet");
-    return nullptr;
+    QComboBox* pComboBox = m_xBuilder->get<QComboBox>(rId);
+    std::unique_ptr<weld::ComboBox> xRet(pComboBox ? 
std::make_unique<QtInstanceComboBox>(pComboBox)
+                                                   : nullptr);
+    return xRet;
 }
 
 std::unique_ptr<weld::EntryTreeView>
diff --git a/vcl/qt5/QtInstanceComboBox.cxx b/vcl/qt5/QtInstanceComboBox.cxx
new file mode 100644
index 000000000000..c1146cb35621
--- /dev/null
+++ b/vcl/qt5/QtInstanceComboBox.cxx
@@ -0,0 +1,240 @@
+/* -*- 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/.
+ */
+
+#include <QtInstanceComboBox.hxx>
+
+QtInstanceComboBox::QtInstanceComboBox(QComboBox* pComboBox)
+    : QtInstanceWidget(pComboBox)
+    , m_pComboBox(pComboBox)
+{
+    assert(pComboBox);
+}
+
+void QtInstanceComboBox::insert(int nPos, const OUString& rStr, const 
OUString* pId,
+                                const OUString* pIconName, VirtualDevice* 
pImageSurface)
+{
+    if (pId || pIconName || !pImageSurface)
+        assert(false && "Handling for these not implemented yet");
+
+    SolarMutexGuard g;
+    GetQtInstance().RunInMainThread([&] { m_pComboBox->insertItem(nPos, 
toQString(rStr)); });
+}
+
+void QtInstanceComboBox::insert_vector(const 
std::vector<weld::ComboBoxEntry>&, bool)
+{
+    assert(false && "Not implemented yet");
+}
+
+void QtInstanceComboBox::insert_separator(int, const OUString&)
+{
+    assert(false && "Not implemented yet");
+}
+
+int QtInstanceComboBox::get_count() const
+{
+    SolarMutexGuard g;
+    int nCount;
+    GetQtInstance().RunInMainThread([&] { nCount = m_pComboBox->count(); });
+    return nCount;
+}
+
+void QtInstanceComboBox::make_sorted() { assert(false && "Not implemented 
yet"); }
+
+void QtInstanceComboBox::clear()
+{
+    SolarMutexGuard g;
+    GetQtInstance().RunInMainThread([&] { m_pComboBox->clear(); });
+}
+
+int QtInstanceComboBox::get_active() const
+{
+    SolarMutexGuard g;
+    int nCurrentIndex;
+    GetQtInstance().RunInMainThread([&] { nCurrentIndex = 
m_pComboBox->currentIndex(); });
+    return nCurrentIndex;
+}
+
+void QtInstanceComboBox::set_active(int nPos)
+{
+    SolarMutexGuard g;
+    GetQtInstance().RunInMainThread([&] { m_pComboBox->setCurrentIndex(nPos); 
});
+}
+
+void QtInstanceComboBox::remove(int nPos)
+{
+    SolarMutexGuard g;
+    GetQtInstance().RunInMainThread([&] { m_pComboBox->removeItem(nPos); });
+}
+
+OUString QtInstanceComboBox::get_active_text() const
+{
+    SolarMutexGuard g;
+    OUString sCurrentText;
+    GetQtInstance().RunInMainThread([&] { sCurrentText = 
toOUString(m_pComboBox->currentText()); });
+    return sCurrentText;
+}
+
+OUString QtInstanceComboBox::get_text(int nPos) const
+{
+    SolarMutexGuard g;
+    OUString sItemText;
+    GetQtInstance().RunInMainThread([&] { sItemText = 
toOUString(m_pComboBox->itemText(nPos)); });
+    return sItemText;
+}
+
+int QtInstanceComboBox::find_text(const OUString& rStr) const
+{
+    SolarMutexGuard g;
+    int nIndex;
+    GetQtInstance().RunInMainThread([&] { nIndex = 
m_pComboBox->findText(toQString(rStr)); });
+    return nIndex;
+}
+
+OUString QtInstanceComboBox::get_active_id() const
+{
+    assert(false && "Not implemented yet");
+    return OUString();
+}
+
+void QtInstanceComboBox::set_active_id(const OUString&) { assert(false && "Not 
implemented yet"); }
+
+OUString QtInstanceComboBox::get_id(int) const
+{
+    assert(false && "Not implemented yet");
+    return OUString();
+}
+
+void QtInstanceComboBox::set_id(int, const OUString&) { assert(false && "Not 
implemented yet"); }
+
+int QtInstanceComboBox::find_id(const OUString&) const
+{
+    assert(false && "Not implemented yet");
+    return -1;
+}
+
+bool QtInstanceComboBox::changed_by_direct_pick() const
+{
+    assert(false && "Not implemented yet");
+    return false;
+}
+
+bool QtInstanceComboBox::has_entry() const
+{
+    SolarMutexGuard g;
+    bool bEditable;
+    GetQtInstance().RunInMainThread([&] { bEditable = 
m_pComboBox->isEditable(); });
+    return bEditable;
+}
+
+void QtInstanceComboBox::set_entry_message_type(weld::EntryMessageType)
+{
+    assert(false && "Not implemented yet");
+}
+
+void QtInstanceComboBox::set_entry_text(const OUString& rStr)
+{
+    SolarMutexGuard g;
+    GetQtInstance().RunInMainThread([&] { 
m_pComboBox->setEditText(toQString(rStr)); });
+}
+
+void QtInstanceComboBox::set_entry_width_chars(int) { assert(false && "Not 
implemented yet"); }
+
+void QtInstanceComboBox::set_entry_max_length(int) { assert(false && "Not 
implemented yet"); }
+
+void QtInstanceComboBox::select_entry_region(int, int) { assert(false && "Not 
implemented yet"); }
+
+bool QtInstanceComboBox::get_entry_selection_bounds(int&, int&)
+{
+    assert(false && "Not implemented yet");
+    return false;
+}
+
+void QtInstanceComboBox::set_entry_completion(bool, bool)
+{
+    assert(false && "Not implemented yet");
+}
+
+void QtInstanceComboBox::set_entry_placeholder_text(const OUString& rText)
+{
+    SolarMutexGuard g;
+    GetQtInstance().RunInMainThread([&] { 
m_pComboBox->setEditText(toQString(rText)); });
+}
+
+void QtInstanceComboBox::set_entry_editable(bool bEditable)
+{
+    SolarMutexGuard g;
+    GetQtInstance().RunInMainThread([&] { m_pComboBox->setEditable(bEditable); 
});
+}
+
+void QtInstanceComboBox::cut_entry_clipboard() { assert(false && "Not 
implemented yet"); }
+
+void QtInstanceComboBox::copy_entry_clipboard() { assert(false && "Not 
implemented yet"); }
+
+void QtInstanceComboBox::paste_entry_clipboard() { assert(false && "Not 
implemented yet"); }
+
+void QtInstanceComboBox::set_font(const vcl::Font&) { assert(false && "Not 
implemented yet"); }
+
+void QtInstanceComboBox::set_entry_font(const vcl::Font&)
+{
+    assert(false && "Not implemented yet");
+}
+
+vcl::Font QtInstanceComboBox::get_entry_font()
+{
+    assert(false && "Not implemented yet");
+    return vcl::Font();
+}
+
+bool QtInstanceComboBox::get_popup_shown() const
+{
+    assert(false && "Not implemented yet");
+    return false;
+}
+
+void QtInstanceComboBox::set_custom_renderer(bool) { assert(false && "Not 
implemented yet"); }
+
+VclPtr<VirtualDevice> QtInstanceComboBox::create_render_virtual_device() const
+{
+    assert(false && "Not implemented yet");
+    return nullptr;
+}
+
+void QtInstanceComboBox::set_item_menu(const OUString&, weld::Menu*)
+{
+    assert(false && "Not implemented yet");
+}
+
+int QtInstanceComboBox::get_menu_button_width() const
+{
+    assert(false && "Not implemented yet");
+    return -1;
+}
+
+int QtInstanceComboBox::get_max_mru_count() const
+{
+    assert(false && "Not implemented yet");
+    return -1;
+}
+
+void QtInstanceComboBox::set_max_mru_count(int) { assert(false && "Not 
implemented yet"); }
+
+OUString QtInstanceComboBox::get_mru_entries() const
+{
+    assert(false && "Not implemented yet");
+    return OUString();
+}
+
+void QtInstanceComboBox::set_mru_entries(const OUString&)
+{
+    assert(false && "Not implemented yet");
+}
+
+void QtInstanceComboBox::set_max_drop_down_rows(int) { assert(false && "Not 
implemented yet"); }
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/qt6/QtInstanceComboBox.cxx b/vcl/qt6/QtInstanceComboBox.cxx
new file mode 100644
index 000000000000..05a6f06c2cb6
--- /dev/null
+++ b/vcl/qt6/QtInstanceComboBox.cxx
@@ -0,0 +1,12 @@
+/* -*- 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/.
+ */
+
+#include "../qt5/QtInstanceComboBox.cxx"
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Reply via email to