[Libreoffice-commits] core.git: Branch 'distro/collabora/co-2021' - include/vcl vcl/inc vcl/jsdialog vcl/source

Szymon KÅ‚os (via logerrit) logerrit at kemper.freedesktop.org
Mon Jun 28 08:12:34 UTC 2021


 include/vcl/menubtn.hxx              |    2 +
 vcl/inc/jsdialog/enabled.hxx         |    1 
 vcl/inc/jsdialog/jsdialogbuilder.hxx |   18 +++++++++-
 vcl/jsdialog/enabled.cxx             |   10 +++++
 vcl/jsdialog/executor.cxx            |   20 +++++++++++
 vcl/jsdialog/jsdialogbuilder.cxx     |   59 ++++++++++++++++++++++++++++++++++-
 vcl/source/control/menubtn.cxx       |   18 ++++++++++
 vcl/source/window/builder.cxx        |    4 +-
 8 files changed, 128 insertions(+), 4 deletions(-)

New commits:
commit dcbecb4b7bc3e0ec2d64f003d732d0ac0c9d7903
Author:     Szymon Kłos <szymon.klos at collabora.com>
AuthorDate: Tue Jun 15 13:10:00 2021 +0200
Commit:     Szymon Kłos <szymon.klos at collabora.com>
CommitDate: Mon Jun 28 10:11:57 2021 +0200

    jsdialog: dump and activate popup windows
    
    Change-Id: I4eb49a81d12ac37f50c6595eeec6d472fdbe6d82
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/117251
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
    Reviewed-by: Szymon Kłos <szymon.klos at collabora.com>

diff --git a/include/vcl/menubtn.hxx b/include/vcl/menubtn.hxx
index f32270161b8d..8e7c259221c5 100644
--- a/include/vcl/menubtn.hxx
+++ b/include/vcl/menubtn.hxx
@@ -89,6 +89,8 @@ public:
 
     void SetCurItemId();
 
+    void DumpAsPropertyTree(tools::JsonWriter& rJsonWriter) override;
+
 };
 
 #endif // INCLUDED_VCL_MENUBTN_HXX
diff --git a/vcl/inc/jsdialog/enabled.hxx b/vcl/inc/jsdialog/enabled.hxx
index 1b2ec56ce84e..fec96f1f34a6 100644
--- a/vcl/inc/jsdialog/enabled.hxx
+++ b/vcl/inc/jsdialog/enabled.hxx
@@ -14,6 +14,7 @@
 namespace jsdialog
 {
 bool isBuilderEnabled(const OUString& rUIFile, bool bMobile);
+bool isBuilderEnabledForPopup(const OUString& rUIFile);
 bool isBuilderEnabledForSidebar(const OUString& rUIFile);
 bool isInterimBuilderEnabledForNotebookbar(const OUString& rUIFile);
 }
diff --git a/vcl/inc/jsdialog/jsdialogbuilder.hxx b/vcl/inc/jsdialog/jsdialogbuilder.hxx
index 7594edbdc1ed..4e6324a15fcb 100644
--- a/vcl/inc/jsdialog/jsdialogbuilder.hxx
+++ b/vcl/inc/jsdialog/jsdialogbuilder.hxx
@@ -194,6 +194,8 @@ class JSInstanceBuilder : public SalInstanceBuilder, public JSDialogSender
     std::string m_sTypeOfJSON;
     bool m_bHasTopLevelDialog;
     bool m_bIsNotebookbar;
+    /// When LOKNotifier is set by jsdialogs code we need to release it
+    VclPtr<vcl::Window> m_aWindowToRelease;
 
     friend VCL_DLLPUBLIC bool jsdialog::ExecuteAction(sal_uInt64 nWindowId, const OString& rWidget,
                                                       StringMap& rData);
@@ -205,8 +207,9 @@ class JSInstanceBuilder : public SalInstanceBuilder, public JSDialogSender
     void RememberWidget(const OString& id, weld::Widget* pWidget);
     static weld::Widget* FindWeldWidgetsMap(sal_uInt64 nWindowId, const OString& rWidget);
 
-    /// used for dialogs
-    JSInstanceBuilder(weld::Widget* pParent, const OUString& rUIRoot, const OUString& rUIFile);
+    /// used for dialogs or popups
+    JSInstanceBuilder(weld::Widget* pParent, const OUString& rUIRoot, const OUString& rUIFile,
+                      bool bPopup = false);
     /// used for sidebar panels
     JSInstanceBuilder(weld::Widget* pParent, const OUString& rUIRoot, const OUString& rUIFile,
                       sal_uInt64 nLOKWindowId);
@@ -230,6 +233,8 @@ public:
     static JSInstanceBuilder* CreateSidebarBuilder(weld::Widget* pParent, const OUString& rUIRoot,
                                                    const OUString& rUIFile,
                                                    sal_uInt64 nLOKWindowId = 0);
+    static JSInstanceBuilder* CreatePopupBuilder(weld::Widget* pParent, const OUString& rUIRoot,
+                                                 const OUString& rUIFile);
 
     virtual ~JSInstanceBuilder() override;
     virtual std::unique_ptr<weld::MessageDialog> weld_message_dialog(const OString& id) override;
@@ -254,6 +259,7 @@ public:
     virtual std::unique_ptr<weld::RadioButton> weld_radio_button(const OString& id) override;
     virtual std::unique_ptr<weld::Frame> weld_frame(const OString& id) override;
     virtual std::unique_ptr<weld::MenuButton> weld_menu_button(const OString& id) override;
+    virtual std::unique_ptr<weld::Popover> weld_popover(const OString& id) override;
 
     static weld::MessageDialog* CreateMessageDialog(weld::Widget* pParent,
                                                     VclMessageType eMessageType,
@@ -626,6 +632,14 @@ public:
     virtual void set_label(const OUString& rText) override;
     virtual void set_image(VirtualDevice* pDevice) override;
     virtual void set_image(const css::uno::Reference<css::graphic::XGraphic>& rImage) override;
+    virtual void set_active(bool active) override;
+};
+
+class JSPopover : public JSWidget<SalInstancePopover, DockingWindow>
+{
+public:
+    JSPopover(JSDialogSender* pSender, DockingWindow* pPopover, SalInstanceBuilder* pBuilder,
+              bool bTakeOwnership);
 };
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/vcl/jsdialog/enabled.cxx b/vcl/jsdialog/enabled.cxx
index da0174c81a8f..92f29674d00e 100644
--- a/vcl/jsdialog/enabled.cxx
+++ b/vcl/jsdialog/enabled.cxx
@@ -13,6 +13,7 @@ namespace jsdialog
 {
 bool isBuilderEnabled(const OUString& rUIFile, bool bMobile)
 {
+    // mobile only dialogs
     if (bMobile)
     {
         if (rUIFile == "modules/swriter/ui/wordcount-mobile.ui"
@@ -28,6 +29,7 @@ bool isBuilderEnabled(const OUString& rUIFile, bool bMobile)
         }
     }
 
+    // dialogs
     if (rUIFile == "modules/scalc/ui/pivottablelayoutdialog.ui"
         || rUIFile == "modules/scalc/ui/selectsource.ui"
         || rUIFile == "modules/scalc/ui/managenamesdialog.ui"
@@ -58,6 +60,14 @@ bool isBuilderEnabled(const OUString& rUIFile, bool bMobile)
     return false;
 }
 
+bool isBuilderEnabledForPopup(const OUString& rUIFile)
+{
+    if (rUIFile == "svx/ui/colorwindow.ui")
+        return true;
+
+    return false;
+}
+
 bool isBuilderEnabledForSidebar(const OUString& rUIFile)
 {
     if (rUIFile == "sfx/ui/panel.ui" || rUIFile == "svx/ui/sidebartextpanel.ui"
diff --git a/vcl/jsdialog/executor.cxx b/vcl/jsdialog/executor.cxx
index d5d22d984891..9cce1546c77f 100644
--- a/vcl/jsdialog/executor.cxx
+++ b/vcl/jsdialog/executor.cxx
@@ -124,6 +124,26 @@ bool ExecuteAction(sal_uInt64 nWindowId, const OString& rWidget, StringMap& rDat
                 }
             }
         }
+        else if (sControlType == "menubutton")
+        {
+            auto pButton = dynamic_cast<weld::MenuButton*>(pWidget);
+            if (pButton)
+            {
+                if (sAction == "toggle")
+                {
+                    if (pButton->get_active())
+                        pButton->set_active(false);
+                    else
+                        pButton->set_active(true);
+
+                    BaseJSWidget* pMenuButton = dynamic_cast<BaseJSWidget*>(pButton);
+                    if (pMenuButton)
+                        pMenuButton->sendUpdate(true);
+
+                    return true;
+                }
+            }
+        }
         else if (sControlType == "checkbox")
         {
             auto pCheckButton = dynamic_cast<weld::CheckButton*>(pWidget);
diff --git a/vcl/jsdialog/jsdialogbuilder.cxx b/vcl/jsdialog/jsdialogbuilder.cxx
index 87efbc466f72..5fb8ea82539e 100644
--- a/vcl/jsdialog/jsdialogbuilder.cxx
+++ b/vcl/jsdialog/jsdialogbuilder.cxx
@@ -384,7 +384,7 @@ void JSDropTarget::fire_dragEnter(const css::datatransfer::dnd::DropTargetDragEn
 
 // used for dialogs
 JSInstanceBuilder::JSInstanceBuilder(weld::Widget* pParent, const OUString& rUIRoot,
-                                     const OUString& rUIFile)
+                                     const OUString& rUIFile, bool bPopup)
     : SalInstanceBuilder(extract_sal_widget(pParent), rUIRoot, rUIFile)
     , m_nWindowId(0)
     , m_aParentDialog(nullptr)
@@ -392,7 +392,12 @@ JSInstanceBuilder::JSInstanceBuilder(weld::Widget* pParent, const OUString& rUIR
     , m_sTypeOfJSON("dialog")
     , m_bHasTopLevelDialog(false)
     , m_bIsNotebookbar(false)
+    , m_aWindowToRelease(nullptr)
 {
+    // when it is a popup we initialize sender in weld_popover
+    if (bPopup)
+        return;
+
     vcl::Window* pRoot = m_xBuilder->get_widget_root();
 
     if (pRoot && pRoot->GetParent())
@@ -416,6 +421,7 @@ JSInstanceBuilder::JSInstanceBuilder(weld::Widget* pParent, const OUString& rUIR
     , m_sTypeOfJSON("sidebar")
     , m_bHasTopLevelDialog(false)
     , m_bIsNotebookbar(false)
+    , m_aWindowToRelease(nullptr)
 {
     vcl::Window* pRoot = m_xBuilder->get_widget_root();
 
@@ -453,6 +459,7 @@ JSInstanceBuilder::JSInstanceBuilder(vcl::Window* pParent, const OUString& rUIRo
     , m_sTypeOfJSON("notebookbar")
     , m_bHasTopLevelDialog(false)
     , m_bIsNotebookbar(false)
+    , m_aWindowToRelease(nullptr)
 {
     vcl::Window* pRoot = m_xBuilder->get_widget_root();
     if (pRoot && pRoot->GetParent())
@@ -481,6 +488,7 @@ JSInstanceBuilder::JSInstanceBuilder(vcl::Window* pParent, const OUString& rUIRo
     , m_sTypeOfJSON("autofilter")
     , m_bHasTopLevelDialog(false)
     , m_bIsNotebookbar(false)
+    , m_aWindowToRelease(nullptr)
 {
     vcl::Window* pRoot = m_xBuilder->get_widget_root();
     m_aContentWindow = pParent;
@@ -524,8 +532,21 @@ JSInstanceBuilder* JSInstanceBuilder::CreateSidebarBuilder(weld::Widget* pParent
     return new JSInstanceBuilder(pParent, rUIRoot, rUIFile, nLOKWindowId);
 }
 
+JSInstanceBuilder* JSInstanceBuilder::CreatePopupBuilder(weld::Widget* pParent,
+                                                         const OUString& rUIRoot,
+                                                         const OUString& rUIFile)
+{
+    return new JSInstanceBuilder(pParent, rUIRoot, rUIFile, true);
+}
+
 JSInstanceBuilder::~JSInstanceBuilder()
 {
+    if (m_aWindowToRelease)
+    {
+        m_aWindowToRelease->ReleaseLOKNotifier();
+        m_aWindowToRelease.clear();
+    }
+
     if (m_nWindowId && (m_bHasTopLevelDialog || m_bIsNotebookbar))
     {
         GetLOKWeldWidgetsMap().erase(m_nWindowId);
@@ -885,6 +906,30 @@ std::unique_ptr<weld::MenuButton> JSInstanceBuilder::weld_menu_button(const OStr
     return pWeldWidget;
 }
 
+std::unique_ptr<weld::Popover> JSInstanceBuilder::weld_popover(const OString& id)
+{
+    DockingWindow* pDockingWindow = m_xBuilder->get<DockingWindow>(id);
+    std::unique_ptr<weld::Popover> pRet(
+        pDockingWindow ? new JSPopover(this, pDockingWindow, this, false) : nullptr);
+    if (pDockingWindow)
+    {
+        assert(!m_aOwnedToplevel && "only one toplevel per .ui allowed");
+        m_aOwnedToplevel.set(pDockingWindow);
+        m_xBuilder->drop_ownership(pDockingWindow);
+
+        if (VclPtr<vcl::Window> pWin = pDockingWindow->GetParentWithLOKNotifier())
+        {
+            pDockingWindow->SetLOKNotifier(pWin->GetLOKNotifier());
+            m_aParentDialog = pDockingWindow;
+            m_aWindowToRelease = pDockingWindow;
+            m_nWindowId = m_aParentDialog->GetLOKWindowId();
+            InsertWindowToMap(m_nWindowId);
+            initializeSender(GetNotifierWindow(), GetContentWindow(), GetTypeOfJSON());
+        }
+    }
+    return pRet;
+}
+
 weld::MessageDialog* JSInstanceBuilder::CreateMessageDialog(weld::Widget* pParent,
                                                             VclMessageType eMessageType,
                                                             VclButtonsType eButtonType,
@@ -1445,4 +1490,16 @@ void JSMenuButton::set_image(const css::uno::Reference<css::graphic::XGraphic>&
     sendUpdate();
 }
 
+void JSMenuButton::set_active(bool active)
+{
+    SalInstanceMenuButton::set_active(active);
+    sendUpdate();
+}
+
+JSPopover::JSPopover(JSDialogSender* pSender, DockingWindow* pDockingWindow,
+                     SalInstanceBuilder* pBuilder, bool bTakeOwnership)
+    : JSWidget<SalInstancePopover, DockingWindow>(pSender, pDockingWindow, pBuilder, bTakeOwnership)
+{
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/vcl/source/control/menubtn.cxx b/vcl/source/control/menubtn.cxx
index a3c1cda1ce8b..a6e809e558fe 100644
--- a/vcl/source/control/menubtn.cxx
+++ b/vcl/source/control/menubtn.cxx
@@ -28,6 +28,7 @@
 #include <vcl/uitest/logger.hxx>
 #include <vcl/uitest/eventdescription.hxx>
 #include <menutogglebutton.hxx>
+#include <tools/json_writer.hxx>
 
 namespace
 {
@@ -264,6 +265,23 @@ void MenuButton::SetCurItemId(){
     msCurItemIdent = mpMenu->GetCurItemIdent();
 }
 
+void MenuButton::DumpAsPropertyTree(tools::JsonWriter& rJsonWriter)
+{
+    Button::DumpAsPropertyTree(rJsonWriter);
+    if (mpFloatingWindow)
+    {
+        auto aPopup = rJsonWriter.startNode("popup");
+        if (InPopupMode())
+            mpFloatingWindow->DumpAsPropertyTree(rJsonWriter);
+        else
+            rJsonWriter.put("action", "close");
+
+        VclPtr<vcl::Window> pParentWithNotifier = mpFloatingWindow->GetParentWithLOKNotifier();
+        if (pParentWithNotifier)
+            rJsonWriter.put("id", pParentWithNotifier->GetLOKWindowId());
+    }
+}
+
 //class MenuToggleButton ----------------------------------------------------
 
 MenuToggleButton::MenuToggleButton( vcl::Window* pParent, WinBits nWinBits )
diff --git a/vcl/source/window/builder.cxx b/vcl/source/window/builder.cxx
index 25db6aacc40d..11d8073d6320 100644
--- a/vcl/source/window/builder.cxx
+++ b/vcl/source/window/builder.cxx
@@ -170,7 +170,9 @@ weld::Builder* Application::CreateBuilder(weld::Widget* pParent, const OUString
     {
         if (jsdialog::isBuilderEnabledForSidebar(rUIFile))
             return JSInstanceBuilder::CreateSidebarBuilder(pParent, AllSettings::GetUIRootDir(), rUIFile, nLOKWindowId);
-        if (jsdialog::isBuilderEnabled(rUIFile, bMobile))
+        else if (jsdialog::isBuilderEnabledForPopup(rUIFile))
+            return JSInstanceBuilder::CreatePopupBuilder(pParent, AllSettings::GetUIRootDir(), rUIFile);
+        else if (jsdialog::isBuilderEnabled(rUIFile, bMobile))
             return JSInstanceBuilder::CreateDialogBuilder(pParent, AllSettings::GetUIRootDir(), rUIFile);
     }
 


More information about the Libreoffice-commits mailing list