[Libreoffice-commits] core.git: include/vcl vcl/inc vcl/source vcl/unx

Caolán McNamara (via logerrit) logerrit at kemper.freedesktop.org
Tue Mar 16 20:39:11 UTC 2021


 include/vcl/weld.hxx          |    2 ++
 vcl/inc/salvtables.hxx        |    1 +
 vcl/source/app/salvtables.cxx |    9 +++++++++
 vcl/unx/gtk3/gtk3gtkinst.cxx  |   34 ++++++++++++++++++++++++++++++----
 4 files changed, 42 insertions(+), 4 deletions(-)

New commits:
commit 5aef0085cadb03c5c6b64747cf0ea76657a3a2ca
Author:     Caolán McNamara <caolanm at redhat.com>
AuthorDate: Tue Mar 16 12:56:42 2021 +0000
Commit:     Caolán McNamara <caolanm at redhat.com>
CommitDate: Tue Mar 16 21:38:23 2021 +0100

    enable grabbing focus to an unspecified container child
    
    Change-Id: I269f76a3e71832ef2e8961952d9362838bd49cfc
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/112577
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/include/vcl/weld.hxx b/include/vcl/weld.hxx
index 1fc18c85fb65..46ae951f3b94 100644
--- a/include/vcl/weld.hxx
+++ b/include/vcl/weld.hxx
@@ -346,6 +346,8 @@ public:
     {
         m_aContainerFocusChangedHdl = rLink;
     }
+    // causes a child of the container to have the keyboard focus
+    virtual void child_grab_focus() = 0;
 };
 
 class VCL_DLLPUBLIC Box : virtual public Container
diff --git a/vcl/inc/salvtables.hxx b/vcl/inc/salvtables.hxx
index efec58258868..88bda40618b6 100644
--- a/vcl/inc/salvtables.hxx
+++ b/vcl/inc/salvtables.hxx
@@ -419,6 +419,7 @@ public:
                          bool bTakeOwnership);
     virtual void HandleEventListener(VclWindowEvent& rEvent) override;
     virtual void connect_container_focus_changed(const Link<Container&, void>& rLink) override;
+    virtual void child_grab_focus() override;
     virtual void move(weld::Widget* pWidget, weld::Container* pNewParent) override;
     virtual void recursively_unset_default_buttons() override;
     virtual css::uno::Reference<css::awt::XWindow> CreateChildFrame() override;
diff --git a/vcl/source/app/salvtables.cxx b/vcl/source/app/salvtables.cxx
index 2a0009446132..7d309a7ebe13 100644
--- a/vcl/source/app/salvtables.cxx
+++ b/vcl/source/app/salvtables.cxx
@@ -1189,6 +1189,15 @@ void SalInstanceContainer::move(weld::Widget* pWidget, weld::Container* pNewPare
         pVclWidget->getWidget()->SetParentToDefaultWindow();
 }
 
+void SalInstanceContainer::child_grab_focus()
+{
+    disable_notify_events();
+    m_xContainer->GrabFocus();
+    if (vcl::Window* pFirstChild = m_xContainer->ImplGetDlgWindow(0, GetDlgWindowType::First))
+        pFirstChild->ImplControlFocus();
+    enable_notify_events();
+}
+
 void SalInstanceContainer::recursively_unset_default_buttons()
 {
     implResetDefault(m_xContainer.get());
diff --git a/vcl/unx/gtk3/gtk3gtkinst.cxx b/vcl/unx/gtk3/gtk3gtkinst.cxx
index d15ee5d5a7e8..fc958c780f18 100644
--- a/vcl/unx/gtk3/gtk3gtkinst.cxx
+++ b/vcl/unx/gtk3/gtk3gtkinst.cxx
@@ -3817,6 +3817,27 @@ public:
 
     GtkContainer* getContainer() { return m_pContainer; }
 
+    virtual void child_grab_focus() override
+    {
+        disable_notify_events();
+        gtk_widget_grab_focus(m_pWidget);
+        bool bHasFocusChild = gtk_container_get_focus_child(m_pContainer);
+        if (!bHasFocusChild)
+        {
+            GList* pChildren = gtk_container_get_children(m_pContainer);
+            for (GList* pChild = g_list_first(pChildren); pChild; pChild = g_list_next(pChild))
+            {
+                gtk_container_set_focus_child(m_pContainer, static_cast<GtkWidget*>(pChild->data));
+                bHasFocusChild = true;
+                break;
+            }
+            g_list_free(pChildren);
+        }
+        if (bHasFocusChild)
+            gtk_widget_child_focus(gtk_container_get_focus_child(GTK_CONTAINER(m_pWidget)), GTK_DIR_TAB_FORWARD);
+        enable_notify_events();
+    }
+
     virtual void move(weld::Widget* pWidget, weld::Container* pNewParent) override
     {
         GtkInstanceWidget* pGtkWidget = dynamic_cast<GtkInstanceWidget*>(pWidget);
@@ -8897,12 +8918,17 @@ public:
     {
         disable_notify_events();
         gtk_widget_grab_focus(m_pWidget);
-        if (!gtk_container_get_focus_child(GTK_CONTAINER(m_pWidget)))
+        bool bHasFocusChild = gtk_container_get_focus_child(GTK_CONTAINER(m_pWidget));
+        if (!bHasFocusChild)
         {
-            GtkToolItem* pItem = gtk_toolbar_get_nth_item(m_pToolbar, 0);
-            gtk_container_set_focus_child(GTK_CONTAINER(m_pWidget), GTK_WIDGET(pItem));
+            if (GtkToolItem* pItem = gtk_toolbar_get_nth_item(m_pToolbar, 0))
+            {
+                gtk_container_set_focus_child(GTK_CONTAINER(m_pWidget), GTK_WIDGET(pItem));
+                bHasFocusChild = true;
+            }
         }
-        gtk_widget_child_focus(gtk_container_get_focus_child(GTK_CONTAINER(m_pWidget)), GTK_DIR_TAB_FORWARD);
+        if (bHasFocusChild)
+            gtk_widget_child_focus(gtk_container_get_focus_child(GTK_CONTAINER(m_pWidget)), GTK_DIR_TAB_FORWARD);
         enable_notify_events();
     }
 


More information about the Libreoffice-commits mailing list