include/vcl/weld.hxx             |   20 ++++++++++++++++++++
 vcl/inc/qt5/QtInstanceWidget.hxx |    3 +++
 vcl/qt5/QtInstanceWidget.cxx     |   12 ++++++++++++
 vcl/source/app/salvtables.cxx    |   24 ++++++++++++------------
 vcl/unx/gtk3/gtkinst.cxx         |   37 ++++++++++++++++---------------------
 5 files changed, 63 insertions(+), 33 deletions(-)

New commits:
commit 5776d98616a93b5e77326ddf205a239b2f8ca016
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Thu Dec 5 00:37:44 2024 +0100
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Thu Dec 5 09:28:05 2024 +0100

    tdf#130857 qt weld: Notify when receiving/losing focus
    
    In QtInstanceWidget, connect to the QApplication::focusChanged
    signal [1] and when either the old or the new focus widget
    is the one belonging to this QtInstanceWidget, notify
    about the lost/gained focus.
    
    With this in place, SvxSearchDialog::FocusHdl_Impl
    now gets called in a WIP branch where support for the
    "Find and Replace" dialog is declared when moving
    focus into one of the comboboxes in that dialog.
    
    [1] https://doc.qt.io/qt-6/qapplication.html#focusChanged
    
    Change-Id: I15190cf9b0d2e72d78a57f58da7ff2ebd1e7a6d9
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/177835
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>

diff --git a/vcl/inc/qt5/QtInstanceWidget.hxx b/vcl/inc/qt5/QtInstanceWidget.hxx
index a790ac81edf7..fc84a4adda59 100644
--- a/vcl/inc/qt5/QtInstanceWidget.hxx
+++ b/vcl/inc/qt5/QtInstanceWidget.hxx
@@ -181,6 +181,9 @@ public:
     virtual void draw(OutputDevice&, const Point&, const Size&) override;
 
     static void setHelpId(QWidget& rWidget, const OUString& rHelpId);
+
+private Q_SLOTS:
+    void applicationFocusChanged(QWidget* pOldFocus, QWidget* pNewFocus);
 };
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */
diff --git a/vcl/qt5/QtInstanceWidget.cxx b/vcl/qt5/QtInstanceWidget.cxx
index 0ecf4ffd6d14..29cb929cb80d 100644
--- a/vcl/qt5/QtInstanceWidget.cxx
+++ b/vcl/qt5/QtInstanceWidget.cxx
@@ -22,6 +22,8 @@ QtInstanceWidget::QtInstanceWidget(QWidget* pWidget)
     : m_pWidget(pWidget)
 {
     assert(pWidget);
+
+    connect(qApp, &QApplication::focusChanged, this, 
&QtInstanceWidget::applicationFocusChanged);
 }
 
 void QtInstanceWidget::set_sensitive(bool bSensitive)
@@ -577,4 +579,14 @@ void QtInstanceWidget::draw(OutputDevice&, const Point&, 
const Size&)
     assert(false && "Not implemented yet");
 }
 
+void QtInstanceWidget::applicationFocusChanged(QWidget* pOldFocus, QWidget* 
pNewFocus)
+{
+    SolarMutexGuard g;
+
+    if (pOldFocus == m_pWidget)
+        signal_focus_out();
+    else if (pNewFocus == m_pWidget)
+        signal_focus_in();
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */
commit 4a309551927898f97d1a9b2dce8050e021bbfd34
Author:     Michael Weghorn <m.wegh...@posteo.de>
AuthorDate: Thu Dec 5 00:29:05 2024 +0100
Commit:     Michael Weghorn <m.wegh...@posteo.de>
CommitDate: Thu Dec 5 09:27:57 2024 +0100

    weld: Add weld::Widget::signal_* methods to call handlers
    
    Similar to what already exists in most subclasses,
    add signal_<event_name> methods to call the handlers
    and use these in the subclasses instead of calling
    the handlers directly.
    
    Change-Id: I6b79ddd859b360e947d97ada57f1573a276d6177
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/177834
    Tested-by: Jenkins
    Reviewed-by: Michael Weghorn <m.wegh...@posteo.de>

diff --git a/include/vcl/weld.hxx b/include/vcl/weld.hxx
index 715beb742a4e..e55cf8a205f0 100644
--- a/include/vcl/weld.hxx
+++ b/include/vcl/weld.hxx
@@ -95,6 +95,26 @@ protected:
     Link<const MouseEvent&, bool> m_aMouseMotionHdl;
     Link<const MouseEvent&, bool> m_aMouseReleaseHdl;
 
+    void signal_focus_in() { m_aFocusInHdl.Call(*this); }
+    void signal_focus_out() { m_aFocusOutHdl.Call(*this); }
+    bool signal_mnemonic_activate() { return 
m_aMnemonicActivateHdl.Call(*this); }
+    void signal_style_updated() { m_aStyleUpdatedHdl.Call(*this); }
+    void signal_size_allocate(const Size& rSize) { 
m_aSizeAllocateHdl.Call(rSize); }
+    bool signal_key_press(const KeyEvent& rKeyEvent) { return 
m_aKeyPressHdl.Call(rKeyEvent); }
+    bool signal_key_release(const KeyEvent& rKeyEvent) { return 
m_aKeyReleaseHdl.Call(rKeyEvent); }
+    bool signal_mouse_press(const MouseEvent& rMouseEvent)
+    {
+        return m_aMousePressHdl.Call(rMouseEvent);
+    }
+    bool signal_mouse_motion(const MouseEvent& rMouseEvent)
+    {
+        return m_aMouseMotionHdl.Call(rMouseEvent);
+    }
+    bool signal_mouse_release(const MouseEvent& rMouseEvent)
+    {
+        return m_aMouseReleaseHdl.Call(rMouseEvent);
+    }
+
 public:
     virtual void set_sensitive(bool sensitive) = 0;
     virtual bool get_sensitive() const = 0;
diff --git a/vcl/source/app/salvtables.cxx b/vcl/source/app/salvtables.cxx
index 3b06cc0e05e6..8f0bb080accb 100644
--- a/vcl/source/app/salvtables.cxx
+++ b/vcl/source/app/salvtables.cxx
@@ -741,11 +741,11 @@ SystemWindow* SalInstanceWidget::getSystemWindow() { 
return m_xWidget->GetSystem
 void SalInstanceWidget::HandleEventListener(VclWindowEvent& rEvent)
 {
     if (rEvent.GetId() == VclEventId::WindowGetFocus)
-        m_aFocusInHdl.Call(*this);
+        signal_focus_in();
     else if (rEvent.GetId() == VclEventId::WindowLoseFocus)
-        m_aFocusOutHdl.Call(*this);
+        signal_focus_out();
     else if (rEvent.GetId() == VclEventId::WindowResize)
-        m_aSizeAllocateHdl.Call(m_xWidget->GetSizePixel());
+        signal_size_allocate(m_xWidget->GetSizePixel());
 }
 
 namespace
@@ -766,14 +766,14 @@ void 
SalInstanceWidget::HandleMouseEventListener(VclWindowEvent& rWinEvent)
         if (m_xWidget == rWinEvent.GetWindow())
         {
             const MouseEvent* pMouseEvent = static_cast<const 
MouseEvent*>(rWinEvent.GetData());
-            m_aMousePressHdl.Call(*pMouseEvent);
+            signal_mouse_press(*pMouseEvent);
         }
         else if (m_xWidget->ImplIsChild(rWinEvent.GetWindow()))
         {
             const MouseEvent* pMouseEvent = static_cast<const 
MouseEvent*>(rWinEvent.GetData());
             const MouseEvent aTransformedEvent(
                 TransformEvent(*pMouseEvent, m_xWidget, 
rWinEvent.GetWindow()));
-            m_aMousePressHdl.Call(aTransformedEvent);
+            signal_mouse_press(aTransformedEvent);
         }
     }
     else if (rWinEvent.GetId() == VclEventId::WindowMouseButtonUp)
@@ -781,14 +781,14 @@ void 
SalInstanceWidget::HandleMouseEventListener(VclWindowEvent& rWinEvent)
         if (m_xWidget == rWinEvent.GetWindow())
         {
             const MouseEvent* pMouseEvent = static_cast<const 
MouseEvent*>(rWinEvent.GetData());
-            m_aMouseReleaseHdl.Call(*pMouseEvent);
+            signal_mouse_release(*pMouseEvent);
         }
         else if (m_xWidget->ImplIsChild(rWinEvent.GetWindow()))
         {
             const MouseEvent* pMouseEvent = static_cast<const 
MouseEvent*>(rWinEvent.GetData());
             const MouseEvent aTransformedEvent(
                 TransformEvent(*pMouseEvent, m_xWidget, 
rWinEvent.GetWindow()));
-            m_aMouseReleaseHdl.Call(aTransformedEvent);
+            signal_mouse_release(aTransformedEvent);
         }
     }
     else if (rWinEvent.GetId() == VclEventId::WindowMouseMove)
@@ -796,14 +796,14 @@ void 
SalInstanceWidget::HandleMouseEventListener(VclWindowEvent& rWinEvent)
         if (m_xWidget == rWinEvent.GetWindow())
         {
             const MouseEvent* pMouseEvent = static_cast<const 
MouseEvent*>(rWinEvent.GetData());
-            m_aMouseMotionHdl.Call(*pMouseEvent);
+            signal_mouse_motion(*pMouseEvent);
         }
         else if (m_xWidget->ImplIsChild(rWinEvent.GetWindow()))
         {
             const MouseEvent* pMouseEvent = static_cast<const 
MouseEvent*>(rWinEvent.GetData());
             const MouseEvent aTransformedEvent(
                 TransformEvent(*pMouseEvent, m_xWidget, 
rWinEvent.GetWindow()));
-            m_aMouseMotionHdl.Call(aTransformedEvent);
+            signal_mouse_motion(aTransformedEvent);
         }
     }
 }
@@ -816,12 +816,12 @@ bool 
SalInstanceWidget::HandleKeyEventListener(VclWindowEvent& rEvent)
     if (rEvent.GetId() == VclEventId::WindowKeyInput)
     {
         const KeyEvent* pKeyEvent = static_cast<const 
KeyEvent*>(rEvent.GetData());
-        return m_aKeyPressHdl.Call(*pKeyEvent);
+        return signal_key_press(*pKeyEvent);
     }
     else if (rEvent.GetId() == VclEventId::WindowKeyUp)
     {
         const KeyEvent* pKeyEvent = static_cast<const 
KeyEvent*>(rEvent.GetData());
-        return m_aKeyReleaseHdl.Call(*pKeyEvent);
+        return signal_key_release(*pKeyEvent);
     }
     return false;
 }
@@ -843,7 +843,7 @@ IMPL_LINK(SalInstanceWidget, MouseEventListener, 
VclWindowEvent&, rEvent, void)
 
 IMPL_LINK_NOARG(SalInstanceWidget, MnemonicActivateHdl, vcl::Window&, bool)
 {
-    return m_aMnemonicActivateHdl.Call(*this);
+    return signal_mnemonic_activate();
 }
 
 namespace
diff --git a/vcl/unx/gtk3/gtkinst.cxx b/vcl/unx/gtk3/gtkinst.cxx
index f1ca1030e300..c837bd6dbb54 100644
--- a/vcl/unx/gtk3/gtkinst.cxx
+++ b/vcl/unx/gtk3/gtkinst.cxx
@@ -2588,7 +2588,7 @@ protected:
         if (pTopLevel && g_object_get_data(G_OBJECT(pTopLevel), 
"g-lo-BlockFocusChange"))
             return;
 
-        m_aFocusInHdl.Call(*this);
+        weld::Widget::signal_focus_in();
     }
 
     static gboolean signalMnemonicActivate(GtkWidget*, gboolean, gpointer 
widget)
@@ -2598,11 +2598,6 @@ protected:
         return pThis->signal_mnemonic_activate();
     }
 
-    bool signal_mnemonic_activate()
-    {
-        return m_aMnemonicActivateHdl.Call(*this);
-    }
-
 #if GTK_CHECK_VERSION(4, 0, 0)
     static void signalFocusOut(GtkEventControllerFocus*, gpointer widget)
     {
@@ -2638,7 +2633,7 @@ protected:
         if (pTopLevel && g_object_get_data(G_OBJECT(pTopLevel), 
"g-lo-BlockFocusChange"))
             return;
 
-        m_aFocusOutHdl.Call(*this);
+        weld::Widget::signal_focus_out();
     }
 
     virtual void ensureMouseEventWidget()
@@ -2990,10 +2985,10 @@ private:
         sal_uInt16 nCode = m_nLastMouseButton | (nModCode & (KEY_SHIFT | 
KEY_MOD1 | KEY_MOD2));
         MouseEvent aMEvt(aPos, n_press, 
ImplGetMouseButtonMode(m_nLastMouseButton, nModCode), nCode, nCode);
 
-        if (nEventType == SalEvent::MouseButtonDown && 
m_aMousePressHdl.Call(aMEvt))
+        if (nEventType == SalEvent::MouseButtonDown && 
signal_mouse_press(aMEvt))
             gtk_gesture_set_state(GTK_GESTURE(pGesture), 
GTK_EVENT_SEQUENCE_CLAIMED);
 
-        if (nEventType == SalEvent::MouseButtonUp && 
m_aMouseReleaseHdl.Call(aMEvt))
+        if (nEventType == SalEvent::MouseButtonUp && 
signal_mouse_release(aMEvt))
             gtk_gesture_set_state(GTK_GESTURE(pGesture), 
GTK_EVENT_SEQUENCE_CLAIMED);
     }
 
@@ -3096,12 +3091,12 @@ private:
         {
             if (!m_aMousePressHdl.IsSet())
                 return false;
-            return m_aMousePressHdl.Call(aMEvt);
+            return signal_mouse_press(aMEvt);
         }
 
         if (!m_aMouseReleaseHdl.IsSet())
             return false;
-        return m_aMouseReleaseHdl.Call(aMEvt);
+        return signal_mouse_release(aMEvt);
     }
 #endif
 
@@ -3116,7 +3111,7 @@ private:
         sal_uInt32 nModCode = GtkSalFrame::GetMouseModCode(nState);
         MouseEvent aMEvt(aPos, 0, ImplGetMouseMoveMode(nModCode), nModCode, 
nModCode);
 
-        return m_aMouseMotionHdl.Call(aMEvt);
+        return signal_mouse_motion(aMEvt);
     }
 
 #if GTK_CHECK_VERSION(4, 0, 0)
@@ -3178,7 +3173,7 @@ private:
         eModifiers = eModifiers | eMouseEventModifiers;
         MouseEvent aMEvt(aPos, 0, eModifiers, nModCode, nModCode);
 
-        m_aMouseMotionHdl.Call(aMEvt);
+        signal_mouse_motion(aMEvt);
         return false;
     }
 
@@ -4100,7 +4095,7 @@ public:
 
     virtual void signal_size_allocate(guint nWidth, guint nHeight)
     {
-        m_aSizeAllocateHdl.Call(Size(nWidth, nHeight));
+        weld::Widget::signal_size_allocate(Size(nWidth, nHeight));
     }
 
 #if GTK_CHECK_VERSION(4, 0, 0)
@@ -4109,7 +4104,7 @@ public:
         if (m_aKeyPressHdl.IsSet())
         {
             SolarMutexGuard aGuard;
-            return m_aKeyPressHdl.Call(CreateKeyEvent(keyval, keycode, state, 
0));
+            return weld::Widget::signal_key_press(CreateKeyEvent(keyval, 
keycode, state, 0));
         }
         return false;
     }
@@ -4119,7 +4114,7 @@ public:
         if (m_aKeyReleaseHdl.IsSet())
         {
             SolarMutexGuard aGuard;
-            return m_aKeyReleaseHdl.Call(CreateKeyEvent(keyval, keycode, 
state, 0));
+            return weld::Widget::signal_key_release(CreateKeyEvent(keyval, 
keycode, state, 0));
         }
         return false;
     }
@@ -4130,7 +4125,7 @@ public:
         if (m_aKeyPressHdl.IsSet())
         {
             SolarMutexGuard aGuard;
-            return m_aKeyPressHdl.Call(GtkToVcl(*pEvent));
+            return weld::Widget::signal_key_press(GtkToVcl(*pEvent));
         }
         return false;
     }
@@ -4140,7 +4135,7 @@ public:
         if (m_aKeyReleaseHdl.IsSet())
         {
             SolarMutexGuard aGuard;
-            return m_aKeyReleaseHdl.Call(GtkToVcl(*pEvent));
+            return weld::Widget::signal_key_release(GtkToVcl(*pEvent));
         }
         return false;
     }
@@ -4611,7 +4606,7 @@ IMPL_LINK(GtkInstanceWidget, SettingsChangedHdl, 
VclWindowEvent&, rEvent, void)
 
     DataChangedEvent* pData = static_cast<DataChangedEvent*>(rEvent.GetData());
     if (pData->GetType() == DataChangedEventType::SETTINGS)
-        m_aStyleUpdatedHdl.Call(*this);
+        signal_style_updated();
 }
 
 #if !GTK_CHECK_VERSION(4, 0, 0)
@@ -19056,8 +19051,8 @@ public:
     virtual void click(const Point& rPos) override
     {
         MouseEvent aEvent(rPos);
-        m_aMousePressHdl.Call(aEvent);
-        m_aMouseReleaseHdl.Call(aEvent);
+        signal_mouse_press(aEvent);
+        signal_mouse_release(aEvent);
     }
 };
 

Reply via email to