offapi/UnoApi_offapi.mk | 1 offapi/com/sun/star/cui/ColorPicker.idl | 35 ++++++++ solenv/bin/native-code.py | 1 vcl/Library_vcl.mk | 1 vcl/source/components/ColorPicker.cxx | 125 ++++++++++++++++++++++++++++++++ vcl/vcl.common.component | 4 + 6 files changed, 167 insertions(+)
New commits: commit 9d6ade1f3b8e4ee59ae7bbe7fda440152af60221 Author: Michael Weghorn <[email protected]> AuthorDate: Tue Nov 18 17:06:04 2025 +0100 Commit: Stephan Bergmann <[email protected]> CommitDate: Tue Nov 18 20:29:00 2025 +0100 [API CHANGE] Reintroduce com.sun.star.ui.dialogs.ColorPicker Bring back the com.sun.star.ui.dialogs.ColorPicker service previously dropped in commit 5ba0ccb2964da46d32ade0c87baf2d407cb52a8a Author: Michael Weghorn <[email protected]> Date: Mon Jun 16 08:01:55 2025 +0200 [API CHANGE] Drop ColorPicker, AsynchronousColorPicker The unpublished com::sun::star::cui::ColorPicker and com::sun::star::cui::AsynchronousColorPicker UNO services were previously used to be able to use ColorPickerDialog (implemented in cui) from svtools. That's no longer the case since commit 0905c23676fe34a5346683ee46568e4d1c58806a Author: Michael Weghorn <[email protected]> Date: Fri Jun 13 18:27:09 2025 +0200 Stop using UNO abstraction for color picker , so drop the now unused services and the ColorPicker class that implemented them. While the service was unpublished and undocumented, it was still used in practice by third party code, see for example the macro in [1] and further discussion in Gerrit change [2]. Therefore bring back the service, but with a new implementation in vcl that no longer uses the ColorPickerDialog implemented in cui directly, but instead uses the weld::ColorChooserDialog abstraction introduced in commit dae9472b27914807ec08062e8293a091e90cffb6 Author: Michael Weghorn <[email protected]> Date: Fri Jul 25 14:26:06 2025 +0200 tdf#167669 weld: Introduce weld::ColorChooserDialog which supports the use of the native platform/toolkit color dialogs (currently implemented for GTK and Qt), see tdf#167669. Don't reintroduce evaluation of the "Mode" parameter to set a vcl::ColorPickerMode because that seems unused by third-party code according to a quick Google search. This makes the macro from [1] work again, and results in the native GTK and Qt color pickers being used for the case of the gtk3/qt6 VCL plugins on Linux. [1] https://forum.openoffice.org/en/forum/viewtopic.php?f=21&t=99268 [2] https://gerrit.libreoffice.org/c/core/+/186538/comments/3af0d3d8_8b843d4e Change-Id: Ic0f2ce2b289f37bf1fb32192d0f3b3deb99121ce Reviewed-on: https://gerrit.libreoffice.org/c/core/+/194172 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <[email protected]> diff --git a/offapi/UnoApi_offapi.mk b/offapi/UnoApi_offapi.mk index 2fb6e2284c9d..97d776847092 100644 --- a/offapi/UnoApi_offapi.mk +++ b/offapi/UnoApi_offapi.mk @@ -99,6 +99,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,\ + ColorPicker \ GetCreateDialogFactoryService \ )) $(eval $(call gb_UnoApi_add_idlfiles_nohdl,offapi,com/sun/star/datatransfer,\ diff --git a/offapi/com/sun/star/cui/ColorPicker.idl b/offapi/com/sun/star/cui/ColorPicker.idl new file mode 100644 index 000000000000..4490b7cd08d3 --- /dev/null +++ b/offapi/com/sun/star/cui/ColorPicker.idl @@ -0,0 +1,35 @@ +/* -*- 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 . + */ + + +module com { module sun { module star { module cui { + +/** + @since LibreOffice 4.1 + */ +service ColorPicker : com::sun::star::ui::dialogs::XExecutableDialog +{ + createWithParent([in] com::sun::star::awt::XWindow Parent); +}; + + +}; }; }; }; + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/solenv/bin/native-code.py b/solenv/bin/native-code.py index c9d041209653..a5ce23de55ca 100755 --- a/solenv/bin/native-code.py +++ b/solenv/bin/native-code.py @@ -114,6 +114,7 @@ core_constructor_list = [ # cppcanvas/source/uno/mtfrenderer.component "com_sun_star_comp_rendering_MtfRenderer_get_implementation", # cui/util/cui.component + ("com_sun_star_cui_ColorPicker_get_implementation", "#if !ENABLE_FUZZERS"), ("com_sun_star_cui_GetCreateDialogFactoryService", "#if !ENABLE_FUZZERS"), # dbaccess/util/dba.component "com_sun_star_comp_dba_DataAccessDescriptorFactory", diff --git a/vcl/Library_vcl.mk b/vcl/Library_vcl.mk index 14088046ee62..00f64eb8e2e1 100644 --- a/vcl/Library_vcl.mk +++ b/vcl/Library_vcl.mk @@ -472,6 +472,7 @@ $(eval $(call gb_Library_add_exception_objects,vcl,\ vcl/source/app/watchdog \ vcl/source/app/weldutils \ vcl/source/app/winscheduler \ + vcl/source/components/ColorPicker \ vcl/source/components/dtranscomp \ vcl/source/components/fontident \ vcl/source/filter/bmp/BmpReader \ diff --git a/vcl/source/components/ColorPicker.cxx b/vcl/source/components/ColorPicker.cxx new file mode 100644 index 000000000000..3308001d1776 --- /dev/null +++ b/vcl/source/components/ColorPicker.cxx @@ -0,0 +1,125 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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/. + */ + +#include <salinst.hxx> +#include <svdata.hxx> + +#include <com/sun/star/awt/XWindow.hpp> +#include <com/sun/star/beans/XPropertyAccess.hpp> +#include <com/sun/star/lang/XInitialization.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/ui/dialogs/XExecutableDialog.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> +#include <comphelper/compbase.hxx> +#include <comphelper/propertyvalue.hxx> +#include <cppuhelper/supportsservice.hxx> +#include <tools/color.hxx> +#include <vcl/svapp.hxx> +#include <vcl/weld.hxx> + +namespace +{ +class ColorPicker : public comphelper::WeakComponentImplHelper< + css::lang::XServiceInfo, css::ui::dialogs::XExecutableDialog, + css::lang::XInitialization, css::beans::XPropertyAccess> +{ +public: + explicit ColorPicker(); + + // XInitialization + virtual void SAL_CALL initialize(const css::uno::Sequence<css::uno::Any>& rArguments) override; + + // XServiceInfo + virtual OUString SAL_CALL getImplementationName() override; + virtual sal_Bool SAL_CALL supportsService(const OUString& rServiceName) override; + virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override; + + // XPropertyAccess + virtual css::uno::Sequence<css::beans::PropertyValue> SAL_CALL getPropertyValues() override; + virtual void SAL_CALL + setPropertyValues(const css::uno::Sequence<css::beans::PropertyValue>& rProperties) override; + + // XExecutableDialog + virtual void SAL_CALL setTitle(const OUString& rTitle) override; + virtual sal_Int16 SAL_CALL execute() override; + +private: + Color m_aColor; + css::uno::Reference<css::awt::XWindow> m_xParent; +}; + +constexpr OUString COLOR_PROPERTY_NAME = u"Color"_ustr; + +ColorPicker::ColorPicker() + : m_aColor(COL_BLACK) +{ +} + +void SAL_CALL ColorPicker::initialize(const css::uno::Sequence<css::uno::Any>& rArguments) +{ + if (rArguments.getLength() == 1) + { + rArguments[0] >>= m_xParent; + } +} + +OUString SAL_CALL ColorPicker::getImplementationName() +{ + return u"com.sun.star.cui.ColorPicker"_ustr; +} + +sal_Bool SAL_CALL ColorPicker::supportsService(const OUString& rServiceName) +{ + return cppu::supportsService(this, rServiceName); +} + +css::uno::Sequence<OUString> SAL_CALL ColorPicker::getSupportedServiceNames() +{ + return { u"com.sun.star.ui.dialogs.ColorPicker"_ustr }; +} + +css::uno::Sequence<css::beans::PropertyValue> SAL_CALL ColorPicker::getPropertyValues() +{ + css::uno::Sequence<css::beans::PropertyValue> aProps{ comphelper::makePropertyValue( + COLOR_PROPERTY_NAME, m_aColor) }; + return aProps; +} + +void SAL_CALL +ColorPicker::setPropertyValues(const css::uno::Sequence<css::beans::PropertyValue>& rProperties) +{ + for (const css::beans::PropertyValue& rProp : rProperties) + { + if (rProp.Name == COLOR_PROPERTY_NAME) + rProp.Value >>= m_aColor; + } +} + +void SAL_CALL ColorPicker::setTitle(const OUString&) {} + +sal_Int16 SAL_CALL ColorPicker::execute() +{ + std::unique_ptr<weld::ColorChooserDialog> pColorChooserDialog + = ImplGetSVData()->mpDefInst->CreateColorChooserDialog(Application::GetFrameWeld(m_xParent), + vcl::ColorPickerMode::Select); + const int nRet = pColorChooserDialog->run(); + if (nRet == RET_OK) + m_aColor = pColorChooserDialog->get_color(); + return nRet; +} + +extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* +com_sun_star_cui_ColorPicker_get_implementation(css::uno::XComponentContext*, + const css::uno::Sequence<css::uno::Any>&) +{ + return cppu::acquire(new ColorPicker); +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/vcl/vcl.common.component b/vcl/vcl.common.component index a7bdb6e4472f..574a422c64f7 100644 --- a/vcl/vcl.common.component +++ b/vcl/vcl.common.component @@ -27,6 +27,10 @@ constructor="com_sun_star_comp_graphic_GraphicProvider_get_implementation"> <service name="com.sun.star.graphic.GraphicProvider"/> </implementation> + <implementation name="com.sun.star.cui.ColorPicker" + constructor="com_sun_star_cui_ColorPicker_get_implementation"> + <service name="com.sun.star.ui.dialogs.ColorPicker"/> + </implementation> <implementation name="com.sun.star.datatransfer.clipboard.AquaClipboard" constructor="vcl_SystemClipboard_get_implementation"> <service name="com.sun.star.datatransfer.clipboard.SystemClipboard"/>
