diff options
author | Szymon Kłos <szymon.klos@collabora.com> | 2021-07-16 10:06:43 +0200 |
---|---|---|
committer | Szymon Kłos <szymon.klos@collabora.com> | 2021-08-19 10:02:15 +0200 |
commit | f54ccf09a5073b6e544c976da68de0c9fc0bdf6c (patch) | |
tree | 63f5c2db742cb8c53cb8763e15e535c578d58ac6 | |
parent | abd08d042fb397fbf97b93d8ca1a6426c1b304e6 (diff) |
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 <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Szymon Kłos <szymon.klos@collabora.com>
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/120670
Tested-by: Jenkins
-rw-r--r-- | cui/source/dialogs/colorpicker.cxx | 33 | ||||
-rw-r--r-- | cui/util/cui.component | 4 | ||||
-rw-r--r-- | include/svtools/colrdlg.hxx | 9 | ||||
-rw-r--r-- | include/svx/PaletteManager.hxx | 3 | ||||
-rw-r--r-- | offapi/UnoApi_offapi.mk | 1 | ||||
-rw-r--r-- | offapi/com/sun/star/cui/AsyncColorPicker.idl | 41 | ||||
-rw-r--r-- | svtools/source/dialogs/colrdlg.cxx | 65 | ||||
-rw-r--r-- | svx/source/tbxctrls/PaletteManager.cxx | 29 |
8 files changed, 165 insertions, 20 deletions
diff --git a/cui/source/dialogs/colorpicker.cxx b/cui/source/dialogs/colorpicker.cxx index 3f1bb0e8c53d..1ecaa887e206 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 0de6196f54b4..72591fdbbbf8 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 dbd7bd143ce9..d913ef87c2e9 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; +const OUStringLiteral sColor = u"Color"; SvColorDialog::SvColorDialog() : meMode(svtools::ColorPickerMode::Select) @@ -58,7 +62,6 @@ short SvColorDialog::Execute(weld::Window* pParent) short ret = 0; try { - static const OUStringLiteral sColor( u"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 ); + } + 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 4084dffc993c..7bb067952438 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) |