tdf#167669 gtk: Use native GtkColorChooserDialog
Following
Change-Id: I29380607cdf3abe739a245aeb25526f643dfa537
Author: Michael Weghorn <m.weghorn@posteo.de>
Date: Fri Jul 25 14:26:06 2025 +0200
tdf#167669 weld: Introduce weld::ColorChooserDialog
, switch the GTK implementation to use a native
GtkColorChooserDialog [1] for the weld::ColorChooserDialog
implementation instead of using LibreOffice's custom
GtkColorChooserDialog.
Set GtkColorChooserDialog::show-editor [2] to true in
order to not show a set of preselected colors on start,
but show the more advanced control (that can otherwise be
opened by clicking the "+" button) right away.
This one is more similar to the LO one, and e.g. the
"Font Color" popup in the Writer Formatting toolbar already
provides a set of predefined colors to select from, so
not showing another set when clicking the "Custom Color"
button seems reasonable.
Besides providing a more uniform experience across applications,
using the native GtkColorChooserDialog also provides a color
picker to select a color from a pixel on screen, which the
custom LO implementation doesn't have.
In the ColorDialog ctor, explicitly set the dialog to modal.
This is already the case for the custom dialog used so far
(and still used by anything except gtk3/gtk4 after this commit)
as defined in the .ui file (cui/uiconfig/ui/colorpickerdialog.ui),
but it's not the case for GtkColorChooserDialog by default.
[1] https://docs.gtk.org/gtk3/class.ColorChooserDialog.html
[2] https://docs.gtk.org/gtk3/property.ColorChooserDialog.show-editor.html
Change-Id: If5bfb453b55c905ffe332707e2fb261a48664c31
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/188344
Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
Tested-by: Jenkins
This commit is contained in:
@@ -135,4 +135,6 @@
|
||||
#define RID_STR_ACC_SCROLLBAR_NAME_HORIZONTAL NC_("RID_STR_ACC_SCROLLBAR_NAME_HORIZONTAL", "Horizontal scroll bar")
|
||||
#define RID_STR_ACC_PANEL_DESCRIPTION NC_("RID_STR_ACC_PANEL_DESCRIPTION", "Please press enter to go into child control for more operations")
|
||||
|
||||
#define RID_STR_PICK_COLOR NC_("RID_STR_PICK_COLOR", "Pick a Color")
|
||||
|
||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
||||
|
||||
@@ -29,6 +29,7 @@ ColorDialog::ColorDialog(weld::Window* pParent, vcl::ColorPickerMode eMode)
|
||||
std::unique_ptr<weld::ColorChooserDialog> pDialog
|
||||
= GetSalInstance()->CreateColorChooserDialog(pParent, eMode);
|
||||
assert(pDialog);
|
||||
pDialog->set_modal(true);
|
||||
m_pColorChooserDialogController
|
||||
= std::make_shared<ColorChooserDialogController>(std::move(pDialog));
|
||||
}
|
||||
|
||||
+27
-14
@@ -4489,6 +4489,11 @@ namespace
|
||||
return aColor;
|
||||
}
|
||||
|
||||
Color toVclColor(const GdkRGBA& rColor)
|
||||
{
|
||||
return Color(rColor.red * 255, rColor.green * 255, rColor.blue * 255);
|
||||
}
|
||||
|
||||
OUString get_label(GtkLabel* pLabel)
|
||||
{
|
||||
const gchar* pStr = gtk_label_get_label(pLabel);
|
||||
@@ -7957,23 +7962,32 @@ public:
|
||||
class GtkInstanceColorChooserDialog : public GtkInstanceDialog,
|
||||
public virtual weld::ColorChooserDialog
|
||||
{
|
||||
ScopedVclPtr<AbstractColorPickerDialog> m_pAbstractColorPickerDialog;
|
||||
GtkColorChooserDialog* m_pColorChooserDialog;
|
||||
|
||||
public:
|
||||
GtkInstanceColorChooserDialog(AbstractColorPickerDialog* pColorDialog)
|
||||
: GtkInstanceDialog(
|
||||
dynamic_cast<GtkInstanceDialog*>(pColorDialog->GetDialog())->getWindow(), nullptr,
|
||||
false)
|
||||
, m_pAbstractColorPickerDialog(pColorDialog)
|
||||
GtkInstanceColorChooserDialog(GtkColorChooserDialog* pColorChooserDialog)
|
||||
: GtkInstanceDialog(GTK_WINDOW(pColorChooserDialog), nullptr, true)
|
||||
, m_pColorChooserDialog(pColorChooserDialog)
|
||||
{
|
||||
assert(m_pColorChooserDialog);
|
||||
gtk_color_chooser_set_use_alpha(GTK_COLOR_CHOOSER(m_pColorChooserDialog), false);
|
||||
|
||||
// directly show the advanced color editor
|
||||
g_object_set(G_OBJECT(m_pColorChooserDialog), "show-editor", true, nullptr);
|
||||
}
|
||||
|
||||
virtual void set_color(const Color& rColor) override
|
||||
{
|
||||
m_pAbstractColorPickerDialog->SetColor(rColor);
|
||||
GdkRGBA aColor = toGdkColor(rColor);
|
||||
gtk_color_chooser_set_rgba(GTK_COLOR_CHOOSER(m_pColorChooserDialog), &aColor);
|
||||
}
|
||||
|
||||
virtual Color get_color() const override { return m_pAbstractColorPickerDialog->GetColor(); }
|
||||
virtual Color get_color() const override
|
||||
{
|
||||
GdkRGBA aColor;
|
||||
gtk_color_chooser_get_rgba(GTK_COLOR_CHOOSER(m_pColorChooserDialog), &aColor);
|
||||
return toVclColor(aColor);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -25160,13 +25174,12 @@ weld::MessageDialog* GtkInstance::CreateMessageDialog(weld::Widget* pParent, Vcl
|
||||
}
|
||||
|
||||
std::unique_ptr<weld::ColorChooserDialog>
|
||||
GtkInstance::CreateColorChooserDialog(weld::Window* pParent, vcl::ColorPickerMode eMode)
|
||||
GtkInstance::CreateColorChooserDialog(weld::Window* pParent, vcl::ColorPickerMode)
|
||||
{
|
||||
VclAbstractDialogFactory* pFact = VclAbstractDialogFactory::Create();
|
||||
assert(pFact);
|
||||
VclPtr<AbstractColorPickerDialog> pDialog
|
||||
= pFact->CreateColorPickerDialog(pParent, COL_BLACK, eMode);
|
||||
assert(pDialog);
|
||||
GtkInstanceWindow* pWindow = dynamic_cast<GtkInstanceWindow*>(pParent);
|
||||
GtkWindow* pGtkParent = pWindow ? pWindow->getWindow() : nullptr;
|
||||
GtkColorChooserDialog* pDialog = GTK_COLOR_CHOOSER_DIALOG(
|
||||
gtk_color_chooser_dialog_new(VclResId(RID_STR_PICK_COLOR).toUtf8().getStr(), pGtkParent));
|
||||
return std::make_unique<GtkInstanceColorChooserDialog>(pDialog);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user