cui/source/dialogs/colorpicker.cxx           |   33 ++++++++++++-
 cui/util/cui.component                       |    4 +
 include/svtools/colrdlg.hxx                  |    9 +++
 include/svx/PaletteManager.hxx               |    3 +
 offapi/UnoApi_offapi.mk                      |    1 
 offapi/com/sun/star/cui/AsyncColorPicker.idl |   41 +++++++++++++++++
 sfx2/source/appl/appserv.cxx                 |    3 +
 svtools/source/dialogs/colrdlg.cxx           |   65 ++++++++++++++++++++++++++-
 svx/source/tbxctrls/PaletteManager.cxx       |   29 ++++++------
 9 files changed, 168 insertions(+), 20 deletions(-)

New commits:
commit 2d9c05d615c2bf8dc494f4eec1213d27c74d24ef
Author:     Szymon Kłos <szymon.k...@collabora.com>
AuthorDate: Mon Jul 26 11:59:39 2021 +0200
Commit:     Szymon Kłos <szymon.k...@collabora.com>
CommitDate: Mon Jul 26 13:26:31 2021 +0200

    online: keep sidebar opened
    
    when we switch mode in online keep sidebar in opened
    state. For example when switching from notebookbar
    to classic mode - sidebar is set to "Tabs" what makes
    sidebar hidden in online. The same happened when
    crash occured.
    
    Change-Id: I5d0d1dba4c89b5e380a0bf717fabf4337016894c
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/119496
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Szymon Kłos <szymon.k...@collabora.com>

diff --git a/sfx2/source/appl/appserv.cxx b/sfx2/source/appl/appserv.cxx
index 42cd0825e747..2e41b999cf70 100644
--- a/sfx2/source/appl/appserv.cxx
+++ b/sfx2/source/appl/appserv.cxx
@@ -933,6 +933,9 @@ void SfxApplication::MiscExec_Impl( SfxRequest& rReq )
                     // Sidebar
                     pViewFrame->ShowChildWindow( SID_SIDEBAR );
 
+                    if (comphelper::LibreOfficeKit::isActive())
+                        aSidebarMode = "Opened";
+
                     sfx2::sidebar::SidebarController* pSidebar =
                             
sfx2::sidebar::SidebarController::GetSidebarControllerForFrame( xFrame );
                     if ( pSidebar )
commit 3381abd0bb3b3664b63185d63c11b8fe11565880
Author:     Szymon Kłos <szymon.k...@collabora.com>
AuthorDate: Fri Jul 16 10:06:43 2021 +0200
Commit:     Szymon Kłos <szymon.k...@collabora.com>
CommitDate: Mon Jul 26 13:26:18 2021 +0200

    Make Custom Color Picker dialog async
    
    - now supports also XAsynchronousExecutableDialog
    - inherits from SfxDialogController to attach correct LOKNotifier
    
    Change-Id: Ic21db4057b8087d74a437b1c8ec95408ade5264d
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/119012
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Szymon Kłos <szymon.k...@collabora.com>

diff --git a/cui/source/dialogs/colorpicker.cxx 
b/cui/source/dialogs/colorpicker.cxx
index a341c193c890..0738fe7bd26f 100644
--- a/cui/source/dialogs/colorpicker.cxx
+++ b/cui/source/dialogs/colorpicker.cxx
@@ -19,6 +19,7 @@
 
 #include <com/sun/star/uno/XComponentContext.hpp>
 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
+#include <com/sun/star/ui/dialogs/XAsynchronousExecutableDialog.hpp>
 #include <com/sun/star/beans/XPropertyAccess.hpp>
 #include <com/sun/star/lang/XInitialization.hpp>
 #include <com/sun/star/lang/XServiceInfo.hpp>
@@ -31,6 +32,7 @@
 #include <vcl/svapp.hxx>
 #include <vcl/virdev.hxx>
 #include <vcl/weld.hxx>
+#include <sfx2/basedlgs.hxx>
 #include <svx/hexcolorcontrol.hxx>
 #include <basegfx/color/bcolortools.hxx>
 #include <cmath>
@@ -727,7 +729,7 @@ void ColorSliderControl::SetValue(const Color& rColor, 
ColorMode eMode, double d
 
 namespace {
 
-class ColorPickerDialog : public weld::GenericDialogController
+class ColorPickerDialog : public SfxDialogController
 {
 private:
     ColorFieldControl m_aColorField;
@@ -790,7 +792,7 @@ private:
 }
 
 ColorPickerDialog::ColorPickerDialog(weld::Window* pParent, Color nColor, 
sal_Int16 nDialogMode)
-    : GenericDialogController(pParent, "cui/ui/colorpickerdialog.ui", 
"ColorPicker")
+    : SfxDialogController(pParent, "cui/ui/colorpickerdialog.ui", 
"ColorPicker")
     , m_xColorField(new weld::CustomWeld(*m_xBuilder, "colorField", 
m_aColorField))
     , m_xColorSlider(new weld::CustomWeld(*m_xBuilder, "colorSlider", 
m_aColorSlider))
     , m_xColorPreview(new weld::CustomWeld(*m_xBuilder, "preview", 
m_aColorPreview))
@@ -1205,7 +1207,7 @@ void ColorPickerDialog::setColorComponent( ColorComponent 
nComp, double dValue )
     }
 }
 
-typedef ::cppu::WeakComponentImplHelper< XServiceInfo, XExecutableDialog, 
XInitialization, XPropertyAccess > ColorPickerBase;
+typedef ::cppu::WeakComponentImplHelper< XServiceInfo, XExecutableDialog, 
XAsynchronousExecutableDialog, XInitialization, XPropertyAccess > 
ColorPickerBase;
 
 namespace {
 
@@ -1231,6 +1233,10 @@ public:
     virtual void SAL_CALL setTitle( const OUString& aTitle ) override;
     virtual sal_Int16 SAL_CALL execute(  ) override;
 
+    // XAsynchronousExecutableDialog
+    virtual void SAL_CALL setDialogTitle( const OUString& aTitle ) override;
+    virtual void SAL_CALL startExecuteModal( const css::uno::Reference< 
css::ui::dialogs::XDialogClosedListener >& xListener ) override;
+
 private:
     Color mnColor;
     sal_Int16 mnMode;
@@ -1279,7 +1285,8 @@ sal_Bool SAL_CALL ColorPicker::supportsService( const 
OUString& sServiceName )
 
 Sequence< OUString > SAL_CALL ColorPicker::getSupportedServiceNames(  )
 {
-    return { "com.sun.star.ui.dialogs.ColorPicker" };
+    return { "com.sun.star.ui.dialogs.ColorPicker",
+             "com.sun.star.ui.dialogs.AsyncColorPicker" };
 }
 
 // XPropertyAccess
@@ -1320,6 +1327,24 @@ sal_Int16 SAL_CALL ColorPicker::execute()
     return ret;
 }
 
+// XAsynchronousExecutableDialog
+void SAL_CALL ColorPicker::setDialogTitle( const OUString& )
+{
+}
+
+void SAL_CALL ColorPicker::startExecuteModal( const css::uno::Reference< 
css::ui::dialogs::XDialogClosedListener >& xListener )
+{
+    std::shared_ptr<ColorPickerDialog> xDlg = 
std::make_shared<ColorPickerDialog>(Application::GetFrameWeld(mxParent), 
mnColor, mnMode);
+    weld::DialogController::runAsync(xDlg, [this, xDlg, xListener] (sal_Int32 
nResult) {
+        if (nResult)
+            mnColor = xDlg->GetColor();
+
+        sal_Int16 nRet = static_cast<sal_Int16>(nResult);
+        css::ui::dialogs::DialogClosedEvent aEvent( *this, nRet );
+        xListener->dialogClosed( aEvent );
+    });
+}
+
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/cui/util/cui.component b/cui/util/cui.component
index 37023b4e1fa1..ae88b06d84bf 100644
--- a/cui/util/cui.component
+++ b/cui/util/cui.component
@@ -23,4 +23,8 @@
     constructor="com_sun_star_cui_ColorPicker_get_implementation">
     <service name="com.sun.star.ui.dialogs.ColorPicker"/>
   </implementation>
+  <implementation name="com.sun.star.cui.AsyncColorPicker"
+    constructor="com_sun_star_cui_ColorPicker_get_implementation">
+    <service name="com.sun.star.ui.dialogs.AsyncColorPicker"/>
+  </implementation>
 </component>
diff --git a/include/svtools/colrdlg.hxx b/include/svtools/colrdlg.hxx
index ce644d63a865..fabdbcd1177e 100644
--- a/include/svtools/colrdlg.hxx
+++ b/include/svtools/colrdlg.hxx
@@ -21,6 +21,10 @@
 
 #include <svtools/svtdllapi.h>
 #include <tools/color.hxx>
+#include <tools/link.hxx>
+#include <com/sun/star/ui/dialogs/XAsynchronousExecutableDialog.hpp>
+
+#include <functional>
 
 namespace weld { class Window; }
 
@@ -43,10 +47,15 @@ public:
     void            SetMode( svtools::ColorPickerMode eMode );
 
     short           Execute(weld::Window* pParent);
+    void            ExecuteAsync(weld::Window* pParent, const 
std::function<void(sal_Int32)>& func);
 
 private:
     Color               maColor;
     svtools::ColorPickerMode meMode;
+    ::com::sun::star::uno::Reference< 
::com::sun::star::ui::dialogs::XAsynchronousExecutableDialog > mxDialog;
+    std::function<void(sal_Int32)> m_aResultFunc;
+
+    DECL_LINK( DialogClosedHdl, css::ui::dialogs::DialogClosedEvent*, void );
 };
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/svx/PaletteManager.hxx b/include/svx/PaletteManager.hxx
index 5d22e1d1f42d..179c2fb4a924 100644
--- a/include/svx/PaletteManager.hxx
+++ b/include/svx/PaletteManager.hxx
@@ -22,6 +22,7 @@
 #include <svx/Palette.hxx>
 #include <rtl/ustring.hxx>
 #include <svx/xtable.hxx>
+#include <svtools/colrdlg.hxx>
 
 #include <deque>
 #include <vector>
@@ -47,6 +48,8 @@ class SVXCORE_DLLPUBLIC PaletteManager
 
     ColorSelectFunction maColorSelectFunction;
     css::uno::Reference < css::uno::XComponentContext > m_context;
+
+    std::unique_ptr<SvColorDialog> m_pColorDlg;
 public:
     PaletteManager();
     ~PaletteManager();
diff --git a/offapi/UnoApi_offapi.mk b/offapi/UnoApi_offapi.mk
index 8d6e21d00a9b..a8844748309e 100644
--- a/offapi/UnoApi_offapi.mk
+++ b/offapi/UnoApi_offapi.mk
@@ -100,6 +100,7 @@ $(eval $(call 
gb_UnoApi_add_idlfiles_nohdl,offapi,com/sun/star/configuration,\
     theDefaultProvider \
 ))
 $(eval $(call gb_UnoApi_add_idlfiles_nohdl,offapi,com/sun/star/cui,\
+    AsyncColorPicker \
     ColorPicker \
 ))
 $(eval $(call gb_UnoApi_add_idlfiles_nohdl,offapi,com/sun/star/datatransfer,\
diff --git a/offapi/com/sun/star/cui/AsyncColorPicker.idl 
b/offapi/com/sun/star/cui/AsyncColorPicker.idl
new file mode 100644
index 000000000000..a4f8c28d9b3e
--- /dev/null
+++ b/offapi/com/sun/star/cui/AsyncColorPicker.idl
@@ -0,0 +1,41 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ *   Licensed to the Apache Software Foundation (ASF) under one or more
+ *   contributor license agreements. See the NOTICE file distributed
+ *   with this work for additional information regarding copyright
+ *   ownership. The ASF licenses this file to you under the Apache
+ *   License, Version 2.0 (the "License"); you may not use this file
+ *   except in compliance with the License. You may obtain a copy of
+ *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+#ifndef __com_sun_star_cui_AsyncColorPicker_idl__
+#define __com_sun_star_cui_AsyncColorPicker_idl__
+
+#include <com/sun/star/ui/dialogs/XAsynchronousExecutableDialog.idl>
+#include <com/sun/star/awt/XWindow.idl>
+
+
+module com { module sun { module star { module cui {
+
+/**
+    @since LibreOffice 7.2
+ */
+service AsyncColorPicker : 
com::sun::star::ui::dialogs::XAsynchronousExecutableDialog
+{
+    createWithParent([in] com::sun::star::awt::XWindow Parent);
+};
+
+}; }; }; };
+
+#endif
+
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svtools/source/dialogs/colrdlg.cxx 
b/svtools/source/dialogs/colrdlg.cxx
index ea448ffd86e2..549e6b1c291e 100644
--- a/svtools/source/dialogs/colrdlg.cxx
+++ b/svtools/source/dialogs/colrdlg.cxx
@@ -20,12 +20,15 @@
 
 #include <com/sun/star/awt/XWindow.hpp>
 #include <com/sun/star/beans/XPropertyAccess.hpp>
+#include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp>
 #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
+#include <com/sun/star/cui/AsyncColorPicker.hpp>
 #include <com/sun/star/cui/ColorPicker.hpp>
 
 #include <comphelper/processfactory.hxx>
 
 #include <svtools/colrdlg.hxx>
+#include <svtools/dialogclosedlistener.hxx>
 #include <vcl/weld.hxx>
 #include <osl/diagnose.h>
 
@@ -34,6 +37,7 @@ using namespace ::com::sun::star::lang;
 using namespace ::com::sun::star::beans;
 using namespace ::com::sun::star::ui::dialogs;
 
+constexpr char sColor[] = "Color";
 
 SvColorDialog::SvColorDialog()
     : meMode(svtools::ColorPickerMode::Select)
@@ -58,7 +62,6 @@ short SvColorDialog::Execute(weld::Window* pParent)
     short ret = 0;
     try
     {
-        const OUString sColor( "Color" );
         Reference< XComponentContext > xContext( 
::comphelper::getProcessComponentContext() );
 
         Reference<css::awt::XWindow> xParent;
@@ -69,7 +72,7 @@ short SvColorDialog::Execute(weld::Window* pParent)
         Reference< XPropertyAccess > xPropertyAccess( xDialog, UNO_QUERY_THROW 
);
 
         Sequence< PropertyValue > props( 2 );
-        props[0].Name = sColor;
+        props[0].Name = OUString( sColor );
         props[0].Value <<= maColor;
         props[1].Name = "Mode";
         props[1].Value <<= static_cast<sal_Int16>(meMode);
@@ -98,4 +101,62 @@ short SvColorDialog::Execute(weld::Window* pParent)
     return ret;
 }
 
+void SvColorDialog::ExecuteAsync(weld::Window* pParent, const 
std::function<void(sal_Int32)>& func)
+{
+    m_aResultFunc = func;
+
+    try
+    {
+        Reference< XComponentContext > xContext( 
::comphelper::getProcessComponentContext() );
+
+        Reference<css::awt::XWindow> xParent;
+        if (pParent)
+            xParent = pParent->GetXWindow();
+
+        mxDialog = css::cui::AsyncColorPicker::createWithParent(xContext, 
xParent);
+        Reference< XPropertyAccess > xPropertyAccess( mxDialog, 
UNO_QUERY_THROW );
+
+        Sequence< PropertyValue > props( 2 );
+        props[0].Name = OUString( sColor );
+        props[0].Value <<= maColor;
+        props[1].Name = "Mode";
+        props[1].Value <<= static_cast<sal_Int16>(meMode);
+
+        xPropertyAccess->setPropertyValues( props );
+
+        rtl::Reference< ::svt::DialogClosedListener > pListener = new 
::svt::DialogClosedListener();
+        pListener->SetDialogClosedLink( LINK( this, SvColorDialog, 
DialogClosedHdl ) );
+
+        mxDialog->startExecuteModal( pListener.get() );
+    }
+    catch(Exception&)
+    {
+        OSL_ASSERT(false);
+    }
+}
+
+IMPL_LINK( SvColorDialog, DialogClosedHdl, 
css::ui::dialogs::DialogClosedEvent*, pEvent, void )
+{
+    sal_Int32 nResult = 0;
+    sal_Int16 nDialogRet = pEvent->DialogResult;
+    if( nDialogRet == ExecutableDialogResults::OK )
+    {
+        nResult = RET_OK;
+
+        Reference< XPropertyAccess > xPropertyAccess( mxDialog, 
UNO_QUERY_THROW );
+        Sequence< PropertyValue > props = xPropertyAccess->getPropertyValues();
+
+        for( const auto& rProp : std::as_const(props) )
+        {
+            if( rProp.Name == sColor )
+            {
+                rProp.Value >>= maColor;
+            }
+        }
+    }
+
+    m_aResultFunc(nResult);
+    mxDialog.clear();
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svx/source/tbxctrls/PaletteManager.cxx 
b/svx/source/tbxctrls/PaletteManager.cxx
index f3630cc492aa..a440c7fe28b8 100644
--- a/svx/source/tbxctrls/PaletteManager.cxx
+++ b/svx/source/tbxctrls/PaletteManager.cxx
@@ -28,7 +28,6 @@
 #include <svx/svxids.hrc>
 #include <svx/dialmgr.hxx>
 #include <tbxcolorupdate.hxx>
-#include <svtools/colrdlg.hxx>
 #include <vcl/svapp.hxx>
 #include <vcl/settings.hxx>
 #include <stack>
@@ -301,19 +300,21 @@ void PaletteManager::PopupColorPicker(weld::Window* 
pParent, const OUString& aCo
 {
     // The calling object goes away during aColorDlg.Execute(), so we must 
copy this
     OUString aCommandCopy = aCommand;
-    SvColorDialog aColorDlg;
-    aColorDlg.SetColor(rInitialColor);
-    aColorDlg.SetMode(svtools::ColorPickerMode::Modify);
-    if (aColorDlg.Execute(pParent) == RET_OK)
-    {
-        Color aLastColor = aColorDlg.GetColor();
-        OUString sColorName = "#" + 
aLastColor.AsRGBHexString().toAsciiUpperCase();
-        NamedColor aNamedColor = std::make_pair(aLastColor, sColorName);
-        if (mpBtnUpdater)
-            mpBtnUpdater->Update(aNamedColor);
-        AddRecentColor(aLastColor, sColorName);
-        maColorSelectFunction(aCommandCopy, aNamedColor);
-    }
+    m_pColorDlg = std::make_unique<SvColorDialog>();
+    m_pColorDlg->SetColor(rInitialColor);
+    m_pColorDlg->SetMode(svtools::ColorPickerMode::Modify);
+    m_pColorDlg->ExecuteAsync(pParent, [this, aCommandCopy] (sal_Int32 
nResult) {
+        if (nResult == RET_OK)
+        {
+            Color aLastColor = m_pColorDlg->GetColor();
+            OUString sColorName = "#" + 
aLastColor.AsRGBHexString().toAsciiUpperCase();
+            NamedColor aNamedColor = std::make_pair(aLastColor, sColorName);
+            if (mpBtnUpdater)
+                mpBtnUpdater->Update(aNamedColor);
+            AddRecentColor(aLastColor, sColorName);
+            maColorSelectFunction(aCommandCopy, aNamedColor);
+        }
+    });
 }
 
 void PaletteManager::DispatchColorCommand(const OUString& aCommand, const 
NamedColor& rColor)
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to