Files
odfstudio/vcl/source/components/ColorPicker.cxx
T
Michael Weghorn 9d6ade1f3b [API CHANGE] Reintroduce com.sun.star.ui.dialogs.ColorPicker
Bring back the com.sun.star.ui.dialogs.ColorPicker service
previously dropped in

    commit 5ba0ccb296
    Author: Michael Weghorn <m.weghorn@posteo.de>
    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 0905c23676
        Author: Michael Weghorn <m.weghorn@posteo.de>
        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 dae9472b27
    Author: Michael Weghorn <m.weghorn@posteo.de>
    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 <stephan.bergmann@collabora.com>
2025-11-18 20:29:00 +01:00

126 lines
4.0 KiB
C++

/* -*- 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: */