sfx2/source/control/dispatch.cxx |   20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

New commits:
commit af58fe4a99a8fef39e337a49bc915819d78e1ccd
Author:     Stephan Bergmann <stephan.bergm...@allotropia.de>
AuthorDate: Thu Apr 17 10:34:14 2025 +0200
Commit:     Stephan Bergmann <stephan.bergm...@allotropia.de>
CommitDate: Thu Apr 17 13:56:29 2025 +0200

    Hack to keep popup menus alive long enough for Emscripten Qt5
    
    This fixes <https://github.com/allotropia/zetajs/issues/12> "Is it possible 
to
    make context menu work?"
    
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/184315
    Reviewed-by: Stephan Bergmann <stephan.bergm...@allotropia.de>
    Tested-by: Jenkins
    (cherry picked from commit 39bd06ad1e404b37eb70b58ee76fc52184dd4b21)
    Conflicts:
            sfx2/source/control/dispatch.cxx
    
    Change-Id: Ib89b638dd94210bae13017554c30c3172e299102
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/184320
    Tested-by: Stephan Bergmann <stephan.bergm...@allotropia.de>
    Reviewed-by: Stephan Bergmann <stephan.bergm...@allotropia.de>

diff --git a/sfx2/source/control/dispatch.cxx b/sfx2/source/control/dispatch.cxx
index bedad9a6241a..c4281bbd6ea6 100644
--- a/sfx2/source/control/dispatch.cxx
+++ b/sfx2/source/control/dispatch.cxx
@@ -40,6 +40,7 @@
 #include <comphelper/lok.hxx>
 #include <comphelper/processfactory.hxx>
 #include <comphelper/propertyvalue.hxx>
+#include <config_vclplug.h>
 #include <rtl/strbuf.hxx>
 #include <sal/log.hxx>
 #include <sfx2/app.hxx>
@@ -1852,6 +1853,23 @@ void SfxDispatcher::ExecutePopup( const OUString& 
rResName, vcl::Window* pWin, c
     css::uno::Reference< css::frame::XPopupMenuController > xPopupController(
         xContext->getServiceManager()->createInstanceWithArgumentsAndContext(
         "com.sun.star.comp.framework.ResourceMenuController", aArgs, xContext 
), css::uno::UNO_QUERY );
+#if defined EMSCRIPTEN && ENABLE_QT5
+    // At least under Emscripten with Qt5, the QMenu::exec underlying the 
below call to
+    // xPopupMenu->execute returns immediately, without going into a new event 
loop, and we need to
+    // keep the underlying QMenu instance alive via the static 
lastPopupController chain here, until
+    // the next popup menu is opened (there can only ever be a single popup 
menu open, so it
+    // suffices to have a single static lastPopupController instance):
+    static css::uno::Reference<css::frame::XPopupMenuController> 
lastPopupController;
+    if (lastPopupController.is()) {
+        if (css::uno::Reference<css::lang::XComponent> component(
+                lastPopupController, css::uno::UNO_QUERY);
+            component.is())
+        {
+            component->dispose();
+        }
+        lastPopupController = xPopupController;
+    }
+#endif
 
     rtl::Reference< VCLXPopupMenu > xPopupMenu = new VCLXPopupMenu();
 
@@ -1888,9 +1906,11 @@ void SfxDispatcher::ExecutePopup( const OUString& 
rResName, vcl::Window* pWin, c
         }
     }
 
+#if !(defined EMSCRIPTEN && ENABLE_QT5)
     css::uno::Reference< css::lang::XComponent > xComponent( xPopupController, 
css::uno::UNO_QUERY );
     if ( xComponent.is() )
         xComponent->dispose();
+#endif
 }
 
 /** With this method the SfxDispatcher can be locked and released. A locked

Reply via email to