include/vcl/builder.hxx          |    2 +-
 include/vcl/weld.hxx             |   25 ++++++++++++++-----------
 include/vcl/widgetbuilder.hxx    |   19 ++++++++++---------
 vcl/inc/qt5/QtBuilder.hxx        |    6 +++---
 vcl/inc/qt5/QtInstanceDialog.hxx |    2 ++
 vcl/inc/qt5/QtInstanceWindow.hxx |    1 -
 vcl/inc/salvtables.hxx           |    4 ++--
 vcl/qt5/QtBuilder.cxx            |    4 ++--
 vcl/qt5/QtInstanceDialog.cxx     |    5 +++++
 vcl/qt5/QtInstanceWindow.cxx     |    2 --
 vcl/source/app/salvtables.cxx    |   24 ++++++++++++------------
 vcl/source/window/builder.cxx    |    5 +++--
 vcl/unx/gtk3/gtkinst.cxx         |   24 ++++++++++++------------
 13 files changed, 66 insertions(+), 57 deletions(-)

New commits:
commit 7738a109699044ab4c370e4794234402b27b7677
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Sat Nov 23 23:46:36 2024 +0100
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Sun Nov 24 17:04:11 2024 +0100

    tdf#130857 weld: Move Window::set_centered_on_parent to Dialog
    
    weld::Window::set_centered_on_parent only ever gets
    called for weld::Dialog instances, so move it to the
    weld::Dialog subclass.
    
    For the Qt implementation, no longer trigger an assert because
    of the method being unimplemented (doing nothing), as QDialog
    opens centered on its parent toplevel by default.
    Quoting from the QDialog doc [1]:
    
    > Note that QDialog (and any other widget that has type Qt::Dialog) uses
    > the parent widget slightly differently from other classes in Qt. A
    > dialog is always a top-level widget, but if it has a parent, its default
    > location is centered on top of the parent's top-level widget (if it is
    > not top-level itself).
    
    (API for moving a QWidget to a different position like
    QWidget::move [2] exists, but would only work on X11/XWayland,
    not Wayland.)
    
    [1] https://doc.qt.io/qt-6/qdialog.html#details
    [2] https://doc.qt.io/qt-6/qwidget.html#pos-prop
    
    Change-Id: I14d41f91e5297c6e58cb4edb2ee98f19814d45cb
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/177192
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>

diff --git a/include/vcl/weld.hxx b/include/vcl/weld.hxx
index effe46665612..98495b7496ec 100644
--- a/include/vcl/weld.hxx
+++ b/include/vcl/weld.hxx
@@ -543,17 +543,7 @@ public:
     virtual Size get_size() const = 0;
     virtual Point get_position() const = 0;
     virtual AbsoluteScreenPixelRectangle get_monitor_workarea() const = 0;
-    // center window on is parent
-    //
-    // bTrackGeometryRequests set to true tries to ensure the window will end
-    // up still centered on its parent windows final size, taking into account
-    // that there may currently be pending geometry requests for the parent not
-    // yet processed by the underlying toolkit
-    //
-    // for e.g gtk this will means the window is always centered even when
-    // resized, calling set_centered_on_parent with false will turn this
-    // off again.
-    virtual void set_centered_on_parent(bool bTrackGeometryRequests) = 0;
+
     // returns whether the widget that has focus is within this Window
     // (its very possible to move this to weld::Container if that becomes
     // desirable)
@@ -617,6 +607,19 @@ private:
 public:
     virtual void set_modal(bool bModal) = 0;
     virtual bool get_modal() const = 0;
+
+    // center dialog on its parent
+    //
+    // bTrackGeometryRequests set to true tries to ensure the dialog will end
+    // up still centered on its parent windows final size, taking into account
+    // that there may currently be pending geometry requests for the parent not
+    // yet processed by the underlying toolkit
+    //
+    // for e.g gtk this will means the dialog is always centered even when
+    // resized, calling set_centered_on_parent with false will turn this
+    // off again.
+    virtual void set_centered_on_parent(bool bTrackGeometryRequests) = 0;
+
     virtual int run() = 0;
     // Run async without a controller
     // @param self - must point to this, to enforce that the dialog was 
created/held by a shared_ptr
diff --git a/vcl/inc/qt5/QtInstanceDialog.hxx b/vcl/inc/qt5/QtInstanceDialog.hxx
index 5c8a6d0981ab..9395a9a1fe48 100644
--- a/vcl/inc/qt5/QtInstanceDialog.hxx
+++ b/vcl/inc/qt5/QtInstanceDialog.hxx
@@ -52,6 +52,8 @@ public:
 
     virtual bool get_modal() const override;
 
+    virtual void set_centered_on_parent(bool bTrackGeometryRequests) override;
+
     virtual weld::Button* weld_widget_for_response(int) override;
 
     virtual void set_default_response(int) override;
diff --git a/vcl/inc/qt5/QtInstanceWindow.hxx b/vcl/inc/qt5/QtInstanceWindow.hxx
index 9b73b39694d7..b92b830c7b9b 100644
--- a/vcl/inc/qt5/QtInstanceWindow.hxx
+++ b/vcl/inc/qt5/QtInstanceWindow.hxx
@@ -25,7 +25,6 @@ public:
     virtual Size get_size() const override;
     virtual Point get_position() const override;
     virtual AbsoluteScreenPixelRectangle get_monitor_workarea() const override;
-    virtual void set_centered_on_parent(bool) override;
 
     virtual bool has_toplevel_focus() const override;
     virtual void present() override;
diff --git a/vcl/inc/salvtables.hxx b/vcl/inc/salvtables.hxx
index 196be2c4193a..3af166383832 100644
--- a/vcl/inc/salvtables.hxx
+++ b/vcl/inc/salvtables.hxx
@@ -483,8 +483,6 @@ public:
 
     virtual AbsoluteScreenPixelRectangle get_monitor_workarea() const override;
 
-    virtual void set_centered_on_parent(bool /*bTrackGeometryRequests*/) 
override;
-
     virtual bool get_resizable() const override;
 
     virtual bool has_toplevel_focus() const override;
@@ -551,6 +549,8 @@ public:
 
     virtual bool get_modal() const override;
 
+    virtual void set_centered_on_parent(bool /*bTrackGeometryRequests*/) 
override;
+
     virtual weld::Button* weld_widget_for_response(int nResponse) override;
 
     virtual void set_default_response(int nResponse) override;
diff --git a/vcl/qt5/QtInstanceDialog.cxx b/vcl/qt5/QtInstanceDialog.cxx
index c1be1db313c0..61de5aa8b153 100644
--- a/vcl/qt5/QtInstanceDialog.cxx
+++ b/vcl/qt5/QtInstanceDialog.cxx
@@ -139,6 +139,11 @@ bool QtInstanceDialog::get_modal() const
     return m_pDialog->isModal();
 }
 
+void QtInstanceDialog::set_centered_on_parent(bool)
+{
+    // QDialog is centered on parent toplevel by default
+}
+
 weld::Button* QtInstanceDialog::weld_widget_for_response(int)
 {
     assert(false && "Not implemented yet");
diff --git a/vcl/qt5/QtInstanceWindow.cxx b/vcl/qt5/QtInstanceWindow.cxx
index 8cc9573a6be5..262fe299a0c9 100644
--- a/vcl/qt5/QtInstanceWindow.cxx
+++ b/vcl/qt5/QtInstanceWindow.cxx
@@ -80,8 +80,6 @@ AbsoluteScreenPixelRectangle 
QtInstanceWindow::get_monitor_workarea() const
     return AbsoluteScreenPixelRectangle();
 }
 
-void QtInstanceWindow::set_centered_on_parent(bool) { assert(false && "Not 
implemented yet"); }
-
 bool QtInstanceWindow::has_toplevel_focus() const
 {
     SolarMutexGuard g;
diff --git a/vcl/source/app/salvtables.cxx b/vcl/source/app/salvtables.cxx
index 77d856b60a66..bf562ce7c687 100644
--- a/vcl/source/app/salvtables.cxx
+++ b/vcl/source/app/salvtables.cxx
@@ -1627,18 +1627,6 @@ AbsoluteScreenPixelRectangle 
SalInstanceWindow::get_monitor_workarea() const
     return m_xWindow->GetDesktopRectPixel();
 }
 
-void SalInstanceWindow::set_centered_on_parent(bool /*bTrackGeometryRequests*/)
-{
-    if (vcl::Window* pParent = m_xWidget->GetParent())
-    {
-        Size aParentGeometry(pParent->GetSizePixel());
-        Size aGeometry(m_xWidget->get_preferred_size());
-        auto nX = (aParentGeometry.Width() - aGeometry.Width()) / 2;
-        auto nY = (aParentGeometry.Height() - aGeometry.Height()) / 2;
-        m_xWidget->SetPosPixel(Point(nX, nY));
-    }
-}
-
 bool SalInstanceWindow::get_resizable() const { return m_xWindow->GetStyle() & 
WB_SIZEABLE; }
 
 bool SalInstanceWindow::has_toplevel_focus() const { return 
m_xWindow->HasChildPathFocus(); }
@@ -1936,6 +1924,18 @@ void SalInstanceDialog::set_modal(bool bModal)
 
 bool SalInstanceDialog::get_modal() const { return 
m_xDialog->IsModalInputMode(); }
 
+void SalInstanceDialog::set_centered_on_parent(bool /*bTrackGeometryRequests*/)
+{
+    if (vcl::Window* pParent = m_xWidget->GetParent())
+    {
+        Size aParentGeometry(pParent->GetSizePixel());
+        Size aGeometry(m_xWidget->get_preferred_size());
+        auto nX = (aParentGeometry.Width() - aGeometry.Width()) / 2;
+        auto nY = (aParentGeometry.Height() - aGeometry.Height()) / 2;
+        m_xWidget->SetPosPixel(Point(nX, nY));
+    }
+}
+
 void SalInstanceDialog::set_default_response(int nResponse)
 {
     m_xDialog->set_default_response(nResponse);
diff --git a/vcl/unx/gtk3/gtkinst.cxx b/vcl/unx/gtk3/gtkinst.cxx
index f7c220273417..91a12bc3b9bf 100644
--- a/vcl/unx/gtk3/gtkinst.cxx
+++ b/vcl/unx/gtk3/gtkinst.cxx
@@ -6421,18 +6421,6 @@ public:
         return ::get_monitor_workarea(GTK_WIDGET(m_pWindow));
     }
 
-    virtual void set_centered_on_parent(bool bTrackGeometryRequests) override
-    {
-#if !GTK_CHECK_VERSION(4, 0, 0)
-        if (bTrackGeometryRequests)
-            gtk_window_set_position(m_pWindow, GTK_WIN_POS_CENTER_ALWAYS);
-        else
-            gtk_window_set_position(m_pWindow, GTK_WIN_POS_CENTER_ON_PARENT);
-#else
-        (void)bTrackGeometryRequests;
-#endif
-    }
-
     virtual bool get_resizable() const override
     {
         return gtk_window_get_resizable(m_pWindow);
@@ -7163,6 +7151,18 @@ public:
         return gtk_window_get_modal(m_pDialog);
     }
 
+    virtual void set_centered_on_parent(bool bTrackGeometryRequests) override
+    {
+#if !GTK_CHECK_VERSION(4, 0, 0)
+        if (bTrackGeometryRequests)
+            gtk_window_set_position(m_pDialog, GTK_WIN_POS_CENTER_ALWAYS);
+        else
+            gtk_window_set_position(m_pDialog, GTK_WIN_POS_CENTER_ON_PARENT);
+#else
+        (void)bTrackGeometryRequests;
+#endif
+    }
+
     virtual void response(int nResponse) override;
 
     virtual void add_button(const OUString& rText, int nResponse, const 
OUString& rHelpId) override
commit a18672dd3ef382436b0aa2449bded50c18e35705
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Sat Nov 23 20:54:47 2024 +0100
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Sun Nov 24 17:04:01 2024 +0100

    tdf#130857 Pass child type to WidgetBuilder::insertObject
    
    In WidgetBuilder::handleChild, pass the child type
    not only to WidgetBuilder::tweakInsertedChild, but
    also to WidgetBuilder::handleObject (add a new param
    for that) and from there down into the virtual
    WidgetBuilder::insertObject, so it can be evaluated
    by subclasses when creating new widgets.
    
    While it is not used yet, an upcoming commit will
    make use of it in QtBuilder, in order to distinguish
    between the two "GtkExpander" children: the label and
    the actual content child.
    
    As described in the "GtkExpander as GtkBuildable" doc [1]:
    
    > The GtkExpander implementation of the GtkBuildable interface supports
    > placing a child in the label position by specifying “label” as the
    > “type” attribute of a <child> element. A normal content child can be
    > specified without specifying a <child> type attribute.
    
    [1] https://docs.gtk.org/gtk3/class.Expander.html
    
    Change-Id: I3e308a6642d72b55d0ccc597dac716b236c22d61
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/177191
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>

diff --git a/include/vcl/builder.hxx b/include/vcl/builder.hxx
index 9f062448d97f..254b4e52d328 100644
--- a/include/vcl/builder.hxx
+++ b/include/vcl/builder.hxx
@@ -242,7 +242,7 @@ private:
                             std::string_view sType, std::string_view 
sInternalChild) override;
 
     VclPtr<vcl::Window> insertObject(vcl::Window* pParent, const OUString& 
rClass,
-                                     const OUString& rID, stringmap& rProps,
+                                     std::string_view sType, const OUString& 
rID, stringmap& rProps,
                                      stringmap& rPangoAttributes, stringmap& 
rAtkProps) override;
 
     VclPtr<vcl::Window> makeObject(vcl::Window *pParent,
diff --git a/include/vcl/widgetbuilder.hxx b/include/vcl/widgetbuilder.hxx
index 8e8a729fb57a..22641cb5d552 100644
--- a/include/vcl/widgetbuilder.hxx
+++ b/include/vcl/widgetbuilder.hxx
@@ -124,8 +124,8 @@ protected:
             {
                 if (name == "object" || name == "placeholder")
                 {
-                    pCurrentChild
-                        = handleObject(pParent, pAtkProps, reader, 
sInternalChild, bToolbarItem);
+                    pCurrentChild = handleObject(pParent, pAtkProps, reader, 
sType, sInternalChild,
+                                                 bToolbarItem);
 
                     bool bObjectInserted = pCurrentChild && pParent != 
pCurrentChild;
                     if (bObjectInserted)
@@ -161,7 +161,8 @@ protected:
     }
 
     WidgetPtr handleObject(Widget* pParent, stringmap* pAtkProps, 
xmlreader::XmlReader& reader,
-                           std::string_view sInternalChild, bool bToolbarItem)
+                           std::string_view sType, std::string_view 
sInternalChild,
+                           bool bToolbarItem)
     {
         OUString sClass;
         OUString sID;
@@ -226,7 +227,7 @@ protected:
                 {
                     if (!pCurrentChild)
                     {
-                        pCurrentChild = insertObject(pParent, sClass, sID, 
aProperties,
+                        pCurrentChild = insertObject(pParent, sClass, sType, 
sID, aProperties,
                                                      aPangoAttributes, 
aAtkAttributes);
                     }
                     handleChild(pCurrentChild, nullptr, reader, 
isToolbarItemClass(sClass));
@@ -281,8 +282,8 @@ protected:
 
         if (!pCurrentChild)
         {
-            pCurrentChild
-                = insertObject(pParent, sClass, sID, aProperties, 
aPangoAttributes, aAtkAttributes);
+            pCurrentChild = insertObject(pParent, sClass, sType, sID, 
aProperties, aPangoAttributes,
+                                         aAtkAttributes);
         }
 
         if (!aItems.empty())
@@ -535,9 +536,9 @@ protected:
                                               const 
std::vector<ComboBoxTextItem>& rItems)
         = 0;
 
-    virtual WidgetPtr insertObject(Widget* pParent, const OUString& rClass, 
const OUString& rID,
-                                   stringmap& rProps, stringmap& 
rPangoAttributes,
-                                   stringmap& rAtkProps)
+    virtual WidgetPtr insertObject(Widget* pParent, const OUString& rClass, 
std::string_view sType,
+                                   const OUString& rID, stringmap& rProps,
+                                   stringmap& rPangoAttributes, stringmap& 
rAtkProps)
         = 0;
 
     virtual void tweakInsertedChild(Widget* pParent, Widget* pCurrentChild, 
std::string_view sType,
diff --git a/vcl/inc/qt5/QtBuilder.hxx b/vcl/inc/qt5/QtBuilder.hxx
index dd31c9999c42..7415b399eb57 100644
--- a/vcl/inc/qt5/QtBuilder.hxx
+++ b/vcl/inc/qt5/QtBuilder.hxx
@@ -61,9 +61,9 @@ public:
     virtual void insertComboBoxOrListBoxItems(QObject* pObject, stringmap& 
rMap,
                                               const 
std::vector<ComboBoxTextItem>& rItems) override;
 
-    virtual QObject* insertObject(QObject* pParent, const OUString& rClass, 
const OUString& rID,
-                                  stringmap& rProps, stringmap& 
rPangoAttributes,
-                                  stringmap& rAtkProps) override;
+    virtual QObject* insertObject(QObject* pParent, const OUString& rClass, 
std::string_view sType,
+                                  const OUString& rID, stringmap& rProps,
+                                  stringmap& rPangoAttributes, stringmap& 
rAtkProps) override;
 
     void tweakInsertedChild(QObject* pParent, QObject* pCurrentChild, 
std::string_view sType,
                             std::string_view sInternalChild) override;
diff --git a/vcl/qt5/QtBuilder.cxx b/vcl/qt5/QtBuilder.cxx
index d73800d02d0d..36efe978551f 100644
--- a/vcl/qt5/QtBuilder.cxx
+++ b/vcl/qt5/QtBuilder.cxx
@@ -83,8 +83,8 @@ void QtBuilder::insertComboBoxOrListBoxItems(QObject* 
pObject, stringmap& rMap,
     assert(false && "list boxes are not supported yet");
 }
 
-QObject* QtBuilder::insertObject(QObject* pParent, const OUString& rClass, 
const OUString& rID,
-                                 stringmap& rProps, stringmap&, stringmap&)
+QObject* QtBuilder::insertObject(QObject* pParent, const OUString& rClass, 
std::string_view,
+                                 const OUString& rID, stringmap& rProps, 
stringmap&, stringmap&)
 {
     QObject* pCurrentChild = nullptr;
 
diff --git a/vcl/source/window/builder.cxx b/vcl/source/window/builder.cxx
index 0a06c388fb67..e22ebf320e15 100644
--- a/vcl/source/window/builder.cxx
+++ b/vcl/source/window/builder.cxx
@@ -2411,8 +2411,9 @@ namespace BuilderUtils
     }
 }
 
-VclPtr<vcl::Window> VclBuilder::insertObject(vcl::Window *pParent, const 
OUString &rClass,
-    const OUString &rID, stringmap &rProps, stringmap &rPango, stringmap &rAtk)
+VclPtr<vcl::Window> VclBuilder::insertObject(vcl::Window* pParent, const 
OUString& rClass,
+                                             std::string_view, const OUString& 
rID,
+                                             stringmap& rProps, stringmap& 
rPango, stringmap& rAtk)
 {
     VclPtr<vcl::Window> pCurrentChild;
 

Reply via email to