LibreOffice Module cui (master) 1
colorpicker.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#include <com/sun/star/uno/XComponentContext.hpp>
21#include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
22#include <com/sun/star/ui/dialogs/XAsynchronousExecutableDialog.hpp>
23#include <com/sun/star/beans/XPropertyAccess.hpp>
24#include <com/sun/star/lang/XInitialization.hpp>
25#include <com/sun/star/lang/XServiceInfo.hpp>
26#include <com/sun/star/awt/XWindow.hpp>
27
32#include <vcl/customweld.hxx>
33#include <vcl/event.hxx>
34#include <vcl/svapp.hxx>
35#include <vcl/virdev.hxx>
36#include <vcl/weld.hxx>
37#include <sfx2/basedlgs.hxx>
40#include <cmath>
42
43using namespace ::com::sun::star::uno;
44using namespace ::com::sun::star::lang;
45using namespace ::com::sun::star::ui::dialogs;
46using namespace ::com::sun::star::beans;
47using namespace ::basegfx;
48
49namespace {
50
51enum class UpdateFlags
52{
53 NONE = 0x00,
54 RGB = 0x01,
55 CMYK = 0x02,
56 HSB = 0x04,
57 ColorChooser = 0x08,
58 ColorSlider = 0x10,
59 Hex = 0x20,
60 All = 0x3f,
61};
62
63}
64
65namespace o3tl {
66 template<> struct typed_flags<UpdateFlags> : is_typed_flags<UpdateFlags, 0x3f> {};
67}
68
69
70namespace cui
71{
72
73namespace {
74
75enum class ColorComponent {
76 Red,
77 Green,
78 Blue,
79 Hue,
80 Saturation,
81 Brightness,
82 Cyan,
83 Yellow,
84 Magenta,
85 Key,
86};
87
88}
89
90// color space conversion helpers
91
92static void RGBtoHSV( double dR, double dG, double dB, double& dH, double& dS, double& dV )
93{
94 BColor result = basegfx::utils::rgb2hsv( BColor( dR, dG, dB ) );
95
96 dH = result.getX();
97 dS = result.getY();
98 dV = result.getZ();
99}
100
101static void HSVtoRGB(double dH, double dS, double dV, double& dR, double& dG, double& dB )
102{
103 BColor result = basegfx::utils::hsv2rgb( BColor( dH, dS, dV ) );
104
105 dR = result.getRed();
106 dG = result.getGreen();
107 dB = result.getBlue();
108}
109
110// CMYK values from 0 to 1
111static void CMYKtoRGB( double fCyan, double fMagenta, double fYellow, double fKey, double& dR, double& dG, double& dB )
112{
113 fCyan = (fCyan * ( 1.0 - fKey )) + fKey;
114 fMagenta = (fMagenta * ( 1.0 - fKey )) + fKey;
115 fYellow = (fYellow * ( 1.0 - fKey )) + fKey;
116
117 dR = std::clamp( 1.0 - fCyan, 0.0, 1.0 );
118 dG = std::clamp( 1.0 - fMagenta, 0.0, 1.0 );
119 dB = std::clamp( 1.0 - fYellow, 0.0, 1.0 );
120}
121
122// CMY results from 0 to 1
123static void RGBtoCMYK( double dR, double dG, double dB, double& fCyan, double& fMagenta, double& fYellow, double& fKey )
124{
125 fCyan = 1 - dR;
126 fMagenta = 1 - dG;
127 fYellow = 1 - dB;
128
129 //CMYK and CMY values from 0 to 1
130 fKey = 1.0;
131 if( fCyan < fKey ) fKey = fCyan;
132 if( fMagenta < fKey ) fKey = fMagenta;
133 if( fYellow < fKey ) fKey = fYellow;
134
135 if( fKey >= 1.0 )
136 {
137 //Black
138 fCyan = 0.0;
139 fMagenta = 0.0;
140 fYellow = 0.0;
141 }
142 else
143 {
144 fCyan = ( fCyan - fKey ) / ( 1.0 - fKey );
145 fMagenta = ( fMagenta - fKey ) / ( 1.0 - fKey );
146 fYellow = ( fYellow - fKey ) / ( 1.0 - fKey );
147 }
148}
149
150namespace {
151
152class ColorPreviewControl : public weld::CustomWidgetController
153{
154private:
156
157 virtual void Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle&) override;
158public:
159 ColorPreviewControl()
160 {
161 }
162
163 virtual void SetDrawingArea(weld::DrawingArea* pDrawingArea) override
164 {
165 CustomWidgetController::SetDrawingArea(pDrawingArea);
166 pDrawingArea->set_size_request(pDrawingArea->get_approximate_digit_width() * 10,
167 pDrawingArea->get_text_height() * 2);
168 }
169
170 void SetColor(const Color& rCol)
171 {
172 if (rCol != m_aColor)
173 {
174 m_aColor = rCol;
175 Invalidate();
176 }
177 }
178};
179
180}
181
182void ColorPreviewControl::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle&)
183{
184 rRenderContext.SetFillColor(m_aColor);
185 rRenderContext.SetLineColor(m_aColor);
186 rRenderContext.DrawRect(tools::Rectangle(Point(0, 0), GetOutputSizePixel()));
187}
188
189namespace {
190
191enum ColorMode { HUE, SATURATION, BRIGHTNESS, RED, GREEN, BLUE };
192
193}
194
195const ColorMode DefaultMode = HUE;
196
197namespace {
198
199class ColorFieldControl : public weld::CustomWidgetController
200{
201public:
202 ColorFieldControl()
204 , mdX( -1.0 )
205 , mdY( -1.0 )
206 , mbMouseCaptured(false)
207 {
208 }
209
210 virtual void SetDrawingArea(weld::DrawingArea* pDrawingArea) override
211 {
212 CustomWidgetController::SetDrawingArea(pDrawingArea);
213 pDrawingArea->set_size_request(pDrawingArea->get_approximate_digit_width() * 40,
214 pDrawingArea->get_text_height() * 10);
215 }
216
217 virtual ~ColorFieldControl() override
218 {
220 }
221
222 virtual void Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect) override;
223 virtual void Resize() override;
224 virtual bool MouseButtonDown(const MouseEvent& rMEvt) override;
225 virtual bool MouseMove(const MouseEvent& rMEvt) override;
226 virtual bool MouseButtonUp(const MouseEvent& rMEvt) override;
227
228 void UpdateBitmap();
229 void ShowPosition( const Point& rPos, bool bUpdate );
230 void UpdatePosition();
231 void Modify();
232
233 void SetValues(Color aColor, ColorMode eMode, double x, double y);
234 double GetX() const { return mdX;}
235 double GetY() const { return mdY;}
236
237 void SetModifyHdl(const Link<ColorFieldControl&,void>& rLink) { maModifyHdl = rLink; }
238
239private:
240 ColorMode meMode;
242 double mdX;
243 double mdY;
248 std::vector<sal_uInt8> maRGB_Horiz;
249 std::vector<sal_uInt16> maGrad_Horiz;
250 std::vector<sal_uInt16> maPercent_Horiz;
251 std::vector<sal_uInt8> maRGB_Vert;
252 std::vector<sal_uInt16> maPercent_Vert;
253};
254
255}
256
257void ColorFieldControl::UpdateBitmap()
258{
259 const Size aSize(GetOutputSizePixel());
260
261 if (mxBitmap && mxBitmap->GetOutputSizePixel() != aSize)
263
264 const sal_Int32 nWidth = aSize.Width();
265 const sal_Int32 nHeight = aSize.Height();
266
267 if (nWidth == 0 || nHeight == 0)
268 return;
269
270 if (!mxBitmap)
271 {
273 mxBitmap->SetOutputSizePixel(aSize);
274
275 maRGB_Horiz.resize( nWidth );
276 maGrad_Horiz.resize( nWidth );
277 maPercent_Horiz.resize( nWidth );
278
279 sal_uInt8* pRGB = maRGB_Horiz.data();
280 sal_uInt16* pGrad = maGrad_Horiz.data();
281 sal_uInt16* pPercent = maPercent_Horiz.data();
282
283 for( sal_Int32 x = 0; x < nWidth; x++ )
284 {
285 *pRGB++ = static_cast<sal_uInt8>((x * 256) / nWidth);
286 *pGrad++ = static_cast<sal_uInt16>((x * 359) / nWidth);
287 *pPercent++ = static_cast<sal_uInt16>((x * 100) / nWidth);
288 }
289
290 maRGB_Vert.resize(nHeight);
291 maPercent_Vert.resize(nHeight);
292
293 pRGB = maRGB_Vert.data();
294 pPercent = maPercent_Vert.data();
295
296 sal_Int32 y = nHeight;
297 while (y--)
298 {
299 *pRGB++ = static_cast<sal_uInt8>((y * 256) / nHeight);
300 *pPercent++ = static_cast<sal_uInt16>((y * 100) / nHeight);
301 }
302 }
303
304 sal_uInt8* pRGB_Horiz = maRGB_Horiz.data();
305 sal_uInt16* pGrad_Horiz = maGrad_Horiz.data();
306 sal_uInt16* pPercent_Horiz = maPercent_Horiz.data();
307 sal_uInt8* pRGB_Vert = maRGB_Vert.data();
308 sal_uInt16* pPercent_Vert = maPercent_Vert.data();
309
310 Color aBitmapColor(maColor);
311
312 sal_uInt16 nHue, nSat, nBri;
313 maColor.RGBtoHSB(nHue, nSat, nBri);
314
315 // this has been unlooped for performance reason, please do not merge back!
316
317 sal_uInt16 y = nHeight,x;
318
319 switch(meMode)
320 {
321 case HUE:
322 while (y--)
323 {
324 nBri = pPercent_Vert[y];
325 x = nWidth;
326 while (x--)
327 {
328 nSat = pPercent_Horiz[x];
329 mxBitmap->DrawPixel(Point(x,y), Color::HSBtoRGB(nHue, nSat, nBri));
330 }
331 }
332 break;
333 case SATURATION:
334 while (y--)
335 {
336 nBri = pPercent_Vert[y];
337 x = nWidth;
338 while (x--)
339 {
340 nHue = pGrad_Horiz[x];
341 mxBitmap->DrawPixel(Point(x,y), Color::HSBtoRGB(nHue, nSat, nBri));
342 }
343 }
344 break;
345 case BRIGHTNESS:
346 while (y--)
347 {
348 nSat = pPercent_Vert[y];
349 x = nWidth;
350 while (x--)
351 {
352 nHue = pGrad_Horiz[x];
353 mxBitmap->DrawPixel(Point(x,y), Color::HSBtoRGB(nHue, nSat, nBri));
354 }
355 }
356 break;
357 case RED:
358 while (y--)
359 {
360 aBitmapColor.SetGreen(pRGB_Vert[y]);
361 x = nWidth;
362 while (x--)
363 {
364 aBitmapColor.SetBlue(pRGB_Horiz[x]);
365 mxBitmap->DrawPixel(Point(x,y), aBitmapColor);
366 }
367 }
368 break;
369 case GREEN:
370 while (y--)
371 {
372 aBitmapColor.SetRed(pRGB_Vert[y]);
373 x = nWidth;
374 while (x--)
375 {
376 aBitmapColor.SetBlue(pRGB_Horiz[x]);
377 mxBitmap->DrawPixel(Point(x,y), aBitmapColor);
378 }
379 }
380 break;
381 case BLUE:
382 while (y--)
383 {
384 aBitmapColor.SetGreen(pRGB_Vert[y]);
385 x = nWidth;
386 while (x--)
387 {
388 aBitmapColor.SetRed(pRGB_Horiz[x]);
389 mxBitmap->DrawPixel(Point(x,y), aBitmapColor);
390 }
391 }
392 break;
393 }
394}
395
396void ColorFieldControl::ShowPosition( const Point& rPos, bool bUpdate )
397{
398 if (!mxBitmap)
399 {
400 UpdateBitmap();
401 Invalidate();
402 }
403
404 if (!mxBitmap)
405 return;
406
407 const Size aSize(mxBitmap->GetOutputSizePixel());
408
409 tools::Long nX = rPos.X();
410 tools::Long nY = rPos.Y();
411 if (nX < 0)
412 nX = 0;
413 else if (nX >= aSize.Width())
414 nX = aSize.Width() - 1;
415
416 if (nY < 0)
417 nY = 0;
418 else if (nY >= aSize.Height())
419 nY = aSize.Height() - 1;
420
421 Point aPos = maPosition;
422 maPosition.setX( nX - 5 );
423 maPosition.setY( nY - 5 );
424 Invalidate(tools::Rectangle(aPos, Size(11, 11)));
425 Invalidate(tools::Rectangle(maPosition, Size(11, 11)));
426
427 if (bUpdate)
428 {
429 mdX = double(nX) / double(aSize.Width() - 1.0);
430 mdY = double(aSize.Height() - 1.0 - nY) / double(aSize.Height() - 1.0);
431
432 maColor = mxBitmap->GetPixel(Point(nX, nY));
433 }
434}
435
436bool ColorFieldControl::MouseButtonDown(const MouseEvent& rMEvt)
437{
438 CaptureMouse();
439 mbMouseCaptured = true;
440 ShowPosition(rMEvt.GetPosPixel(), true);
441 Modify();
442 return true;
443}
444
445bool ColorFieldControl::MouseMove(const MouseEvent& rMEvt)
446{
447 if (mbMouseCaptured)
448 {
449 ShowPosition(rMEvt.GetPosPixel(), true);
450 Modify();
451 }
452 return true;
453}
454
455bool ColorFieldControl::MouseButtonUp(const MouseEvent&)
456{
457 ReleaseMouse();
458 mbMouseCaptured = false;
459 return true;
460}
461
462void ColorFieldControl::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle&)
463{
464 if (!mxBitmap)
465 UpdateBitmap();
466
467 if (mxBitmap)
468 {
469 Size aSize(GetOutputSizePixel());
470 rRenderContext.DrawOutDev(Point(0, 0), aSize, Point(0, 0), aSize, *mxBitmap);
471 }
472
473 // draw circle around current color
474 if (maColor.IsDark())
475 rRenderContext.SetLineColor( COL_WHITE );
476 else
477 rRenderContext.SetLineColor( COL_BLACK );
478
479 rRenderContext.SetFillColor();
480
481 rRenderContext.DrawEllipse(::tools::Rectangle(maPosition, Size(11, 11)));
482}
483
484void ColorFieldControl::Resize()
485{
486 CustomWidgetController::Resize();
487 UpdateBitmap();
488 UpdatePosition();
489}
490
491void ColorFieldControl::Modify()
492{
493 maModifyHdl.Call( *this );
494}
495
496void ColorFieldControl::SetValues( Color aColor, ColorMode eMode, double x, double y )
497{
498 bool bUpdateBitmap = (maColor!= aColor) || (meMode != eMode);
499 if( !(bUpdateBitmap || (mdX != x) || (mdY != y)) )
500 return;
501
502 maColor = aColor;
503 meMode = eMode;
504 mdX = x;
505 mdY = y;
506
507 if (bUpdateBitmap)
508 UpdateBitmap();
509 UpdatePosition();
510 if (bUpdateBitmap)
511 Invalidate();
512}
513
514void ColorFieldControl::UpdatePosition()
515{
516 Size aSize(GetOutputSizePixel());
517 ShowPosition(Point(static_cast<tools::Long>(mdX * aSize.Width()), static_cast<tools::Long>((1.0 - mdY) * aSize.Height())), false);
518}
519
520namespace {
521
522class ColorSliderControl : public weld::CustomWidgetController
523{
524public:
525 ColorSliderControl();
526 virtual ~ColorSliderControl() override;
527
528 virtual void SetDrawingArea(weld::DrawingArea* pDrawingArea) override;
529
530 virtual bool MouseButtonDown(const MouseEvent& rMEvt) override;
531 virtual bool MouseMove(const MouseEvent& rMEvt) override;
532 virtual bool MouseButtonUp(const MouseEvent& rMEvt) override;
533 virtual void Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle&) override;
534 virtual void Resize() override;
535
536 void UpdateBitmap();
537 void ChangePosition( tools::Long nY );
538 void Modify();
539
540 void SetValue( const Color& rColor, ColorMode eMode, double dValue );
541 double GetValue() const { return mdValue; }
542
543 void SetModifyHdl( const Link<ColorSliderControl&,void>& rLink ) { maModifyHdl = rLink; }
544
545 sal_Int16 GetLevel() const { return mnLevel; }
546
547private:
550 ColorMode meMode;
552 sal_Int16 mnLevel;
553 double mdValue;
554};
555
556}
557
558ColorSliderControl::ColorSliderControl()
560 , mnLevel( 0 )
561 , mdValue( -1.0 )
562{
563}
564
565void ColorSliderControl::SetDrawingArea(weld::DrawingArea* pDrawingArea)
566{
567 CustomWidgetController::SetDrawingArea(pDrawingArea);
568 pDrawingArea->set_size_request(pDrawingArea->get_approximate_digit_width() * 3, -1);
569}
570
571ColorSliderControl::~ColorSliderControl()
572{
574}
575
576void ColorSliderControl::UpdateBitmap()
577{
578 Size aSize(1, GetOutputSizePixel().Height());
579
580 if (mxBitmap && mxBitmap->GetOutputSizePixel() != aSize)
582
583 if (!mxBitmap)
584 {
586 mxBitmap->SetOutputSizePixel(aSize);
587 }
588
589 const tools::Long nY = aSize.Height() - 1;
590
591 Color aBitmapColor(maColor);
592
593 sal_uInt16 nHue, nSat, nBri;
594 maColor.RGBtoHSB(nHue, nSat, nBri);
595
596 // this has been unlooped for performance reason, please do not merge back!
597
598 switch (meMode)
599 {
600 case HUE:
601 nSat = 100;
602 nBri = 100;
603 for (tools::Long y = 0; y <= nY; y++)
604 {
605 nHue = static_cast<sal_uInt16>((359 * y) / nY);
606 mxBitmap->DrawPixel(Point(0, nY - y), Color::HSBtoRGB(nHue, nSat, nBri));
607 }
608 break;
609
610 case SATURATION:
611 nBri = std::max(sal_uInt16(32), nBri);
612 for (tools::Long y = 0; y <= nY; y++)
613 {
614 nSat = static_cast<sal_uInt16>((100 * y) / nY);
615 mxBitmap->DrawPixel(Point(0, nY - y), Color::HSBtoRGB(nHue, nSat, nBri));
616 }
617 break;
618
619 case BRIGHTNESS:
620 for (tools::Long y = 0; y <= nY; y++)
621 {
622 nBri = static_cast<sal_uInt16>((100 * y) / nY);
623 mxBitmap->DrawPixel(Point(0, nY - y), Color::HSBtoRGB(nHue, nSat, nBri));
624 }
625 break;
626
627 case RED:
628 for (tools::Long y = 0; y <= nY; y++)
629 {
630 aBitmapColor.SetRed(sal_uInt8((tools::Long(255) * y) / nY));
631 mxBitmap->DrawPixel(Point(0, nY - y), aBitmapColor);
632 }
633 break;
634
635 case GREEN:
636 for (tools::Long y = 0; y <= nY; y++)
637 {
638 aBitmapColor.SetGreen(sal_uInt8((tools::Long(255) * y) / nY));
639 mxBitmap->DrawPixel(Point(0, nY - y), aBitmapColor);
640 }
641 break;
642
643 case BLUE:
644 for (tools::Long y = 0; y <= nY; y++)
645 {
646 aBitmapColor.SetBlue(sal_uInt8((tools::Long(255) * y) / nY));
647 mxBitmap->DrawPixel(Point(0, nY - y), aBitmapColor);
648 }
649 break;
650 }
651}
652
653void ColorSliderControl::ChangePosition(tools::Long nY)
654{
655 const tools::Long nHeight = GetOutputSizePixel().Height() - 1;
656
657 if (nY < 0)
658 nY = 0;
659 else if (nY > nHeight)
660 nY = nHeight;
661
662 mnLevel = nY;
663 mdValue = double(nHeight - nY) / double(nHeight);
664}
665
666bool ColorSliderControl::MouseButtonDown(const MouseEvent& rMEvt)
667{
668 CaptureMouse();
669 ChangePosition(rMEvt.GetPosPixel().Y());
670 Modify();
671 return true;
672}
673
674bool ColorSliderControl::MouseMove(const MouseEvent& rMEvt)
675{
676 if (IsMouseCaptured())
677 {
678 ChangePosition(rMEvt.GetPosPixel().Y());
679 Modify();
680 }
681 return true;
682}
683
684bool ColorSliderControl::MouseButtonUp(const MouseEvent&)
685{
686 ReleaseMouse();
687 return true;
688}
689
690void ColorSliderControl::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle&)
691{
692 if (!mxBitmap)
693 UpdateBitmap();
694
695 const Size aSize(GetOutputSizePixel());
696
697 Point aPos;
698 int x = aSize.Width();
699 while (x--)
700 {
701 rRenderContext.DrawOutDev(aPos, aSize, Point(0,0), aSize, *mxBitmap);
702 aPos.AdjustX(1);
703 }
704}
705
706void ColorSliderControl::Resize()
707{
708 CustomWidgetController::Resize();
709 UpdateBitmap();
710}
711
712void ColorSliderControl::Modify()
713{
714 maModifyHdl.Call(*this);
715}
716
717void ColorSliderControl::SetValue(const Color& rColor, ColorMode eMode, double dValue)
718{
719 bool bUpdateBitmap = (rColor != maColor) || (eMode != meMode);
720 if( bUpdateBitmap || (mdValue != dValue))
721 {
722 maColor = rColor;
723 mdValue = dValue;
724 mnLevel = static_cast<sal_Int16>((1.0-dValue) * GetOutputSizePixel().Height());
725 meMode = eMode;
726 if (bUpdateBitmap)
727 UpdateBitmap();
728 Invalidate();
729 }
730}
731
732namespace {
733
734class ColorPickerDialog : public SfxDialogController
735{
736private:
737 ColorFieldControl m_aColorField;
738 ColorSliderControl m_aColorSlider;
739 ColorPreviewControl m_aColorPreview;
740 ColorPreviewControl m_aColorPrevious;
741
742 std::unique_ptr<weld::CustomWeld> m_xColorField;
743 std::unique_ptr<weld::CustomWeld> m_xColorSlider;
744 std::unique_ptr<weld::CustomWeld> m_xColorPreview;
745 std::unique_ptr<weld::CustomWeld> m_xColorPrevious;
746
747 std::unique_ptr<weld::Widget> m_xFISliderLeft;
748 std::unique_ptr<weld::Widget> m_xFISliderRight;
749 std::unique_ptr<weld::RadioButton> m_xRBRed;
750 std::unique_ptr<weld::RadioButton> m_xRBGreen;
751 std::unique_ptr<weld::RadioButton> m_xRBBlue;
752 std::unique_ptr<weld::RadioButton> m_xRBHue;
753 std::unique_ptr<weld::RadioButton> m_xRBSaturation;
754 std::unique_ptr<weld::RadioButton> m_xRBBrightness;
755
756 std::unique_ptr<weld::SpinButton> m_xMFRed;
757 std::unique_ptr<weld::SpinButton> m_xMFGreen;
758 std::unique_ptr<weld::SpinButton> m_xMFBlue;
759 std::unique_ptr<weld::HexColorControl> m_xEDHex;
760
761 std::unique_ptr<weld::MetricSpinButton> m_xMFHue;
762 std::unique_ptr<weld::MetricSpinButton> m_xMFSaturation;
763 std::unique_ptr<weld::MetricSpinButton> m_xMFBrightness;
764
765 std::unique_ptr<weld::MetricSpinButton> m_xMFCyan;
766 std::unique_ptr<weld::MetricSpinButton> m_xMFMagenta;
767 std::unique_ptr<weld::MetricSpinButton> m_xMFYellow;
768 std::unique_ptr<weld::MetricSpinButton> m_xMFKey;
769
770public:
771 ColorPickerDialog(weld::Window* pParent, Color nColor, sal_Int16 nMode);
772
773 void update_color(UpdateFlags n = UpdateFlags::All);
774
775 DECL_LINK(ColorFieldControlModifydl, ColorFieldControl&, void);
776 DECL_LINK(ColorSliderControlModifyHdl, ColorSliderControl&, void);
777 DECL_LINK(ColorModifyMetricHdl, weld::MetricSpinButton&, void);
778 DECL_LINK(ColorModifySpinHdl, weld::SpinButton&, void);
779 DECL_LINK(ColorModifyEditHdl, weld::Entry&, void);
780 DECL_LINK(ModeModifyHdl, weld::Toggleable&, void);
781
782 Color GetColor() const;
783
784 void setColorComponent(ColorComponent nComp, double dValue);
785
786private:
787 ColorMode meMode;
788
790 double mdHue, mdSat, mdBri;
792};
793
794}
795
796ColorPickerDialog::ColorPickerDialog(weld::Window* pParent, Color nColor, sal_Int16 nDialogMode)
797 : SfxDialogController(pParent, "cui/ui/colorpickerdialog.ui", "ColorPicker")
798 , m_xColorField(new weld::CustomWeld(*m_xBuilder, "colorField", m_aColorField))
799 , m_xColorSlider(new weld::CustomWeld(*m_xBuilder, "colorSlider", m_aColorSlider))
800 , m_xColorPreview(new weld::CustomWeld(*m_xBuilder, "preview", m_aColorPreview))
801 , m_xColorPrevious(new weld::CustomWeld(*m_xBuilder, "previous", m_aColorPrevious))
802 , m_xFISliderLeft(m_xBuilder->weld_widget("leftImage"))
803 , m_xFISliderRight(m_xBuilder->weld_widget("rightImage"))
804 , m_xRBRed(m_xBuilder->weld_radio_button("redRadiobutton"))
805 , m_xRBGreen(m_xBuilder->weld_radio_button("greenRadiobutton"))
806 , m_xRBBlue(m_xBuilder->weld_radio_button("blueRadiobutton"))
807 , m_xRBHue(m_xBuilder->weld_radio_button("hueRadiobutton"))
808 , m_xRBSaturation(m_xBuilder->weld_radio_button("satRadiobutton"))
809 , m_xRBBrightness(m_xBuilder->weld_radio_button("brightRadiobutton"))
810 , m_xMFRed(m_xBuilder->weld_spin_button("redSpinbutton"))
811 , m_xMFGreen(m_xBuilder->weld_spin_button("greenSpinbutton"))
812 , m_xMFBlue(m_xBuilder->weld_spin_button("blueSpinbutton"))
813 , m_xEDHex(new weld::HexColorControl(m_xBuilder->weld_entry("hexEntry")))
814 , m_xMFHue(m_xBuilder->weld_metric_spin_button("hueSpinbutton", FieldUnit::DEGREE))
815 , m_xMFSaturation(m_xBuilder->weld_metric_spin_button("satSpinbutton", FieldUnit::PERCENT))
816 , m_xMFBrightness(m_xBuilder->weld_metric_spin_button("brightSpinbutton", FieldUnit::PERCENT))
817 , m_xMFCyan(m_xBuilder->weld_metric_spin_button("cyanSpinbutton", FieldUnit::PERCENT))
818 , m_xMFMagenta(m_xBuilder->weld_metric_spin_button("magSpinbutton", FieldUnit::PERCENT))
819 , m_xMFYellow(m_xBuilder->weld_metric_spin_button("yellowSpinbutton", FieldUnit::PERCENT))
820 , m_xMFKey(m_xBuilder->weld_metric_spin_button("keySpinbutton", FieldUnit::PERCENT))
822{
823 m_aColorField.SetModifyHdl( LINK( this, ColorPickerDialog, ColorFieldControlModifydl ) );
824 m_aColorSlider.SetModifyHdl( LINK( this, ColorPickerDialog, ColorSliderControlModifyHdl ) );
825
826 int nMargin = (m_xFISliderLeft->get_preferred_size().Height() + 1) / 2;
827 m_xColorSlider->set_margin_top(nMargin);
828 m_xColorSlider->set_margin_bottom(nMargin);
829
830 Link<weld::MetricSpinButton&,void> aLink3( LINK( this, ColorPickerDialog, ColorModifyMetricHdl ) );
831 m_xMFCyan->connect_value_changed( aLink3 );
832 m_xMFMagenta->connect_value_changed( aLink3 );
833 m_xMFYellow->connect_value_changed( aLink3 );
834 m_xMFKey->connect_value_changed( aLink3 );
835
836 m_xMFHue->connect_value_changed( aLink3 );
837 m_xMFSaturation->connect_value_changed( aLink3 );
838 m_xMFBrightness->connect_value_changed( aLink3 );
839
840 Link<weld::SpinButton&,void> aLink4(LINK(this, ColorPickerDialog, ColorModifySpinHdl));
841 m_xMFRed->connect_value_changed(aLink4);
842 m_xMFGreen->connect_value_changed(aLink4);
843 m_xMFBlue->connect_value_changed(aLink4);
844
845 m_xEDHex->connect_changed(LINK(this, ColorPickerDialog, ColorModifyEditHdl));
846
847 Link<weld::Toggleable&,void> aLink2 = LINK( this, ColorPickerDialog, ModeModifyHdl );
848 m_xRBRed->connect_toggled( aLink2 );
849 m_xRBGreen->connect_toggled( aLink2 );
850 m_xRBBlue->connect_toggled( aLink2 );
851 m_xRBHue->connect_toggled( aLink2 );
852 m_xRBSaturation->connect_toggled( aLink2 );
853 m_xRBBrightness->connect_toggled( aLink2 );
854
855 Color aColor(nColor);
856
857 // modify
858 if (nDialogMode == 2)
859 {
860 m_aColorPrevious.SetColor(aColor);
861 m_xColorPrevious->show();
862 }
863
864 mdRed = static_cast<double>(aColor.GetRed()) / 255.0;
865 mdGreen = static_cast<double>(aColor.GetGreen()) / 255.0;
866 mdBlue = static_cast<double>(aColor.GetBlue()) / 255.0;
867
870
871 update_color();
872}
873
874static int toInt( double dValue, double dRange )
875{
876 return static_cast< int >( std::floor((dValue * dRange) + 0.5 ) );
877}
878
879Color ColorPickerDialog::GetColor() const
880{
881 return Color( toInt(mdRed,255.0), toInt(mdGreen,255.0), toInt(mdBlue,255.0) );
882}
883
884void ColorPickerDialog::update_color( UpdateFlags n )
885{
886 sal_uInt8 nRed = toInt(mdRed,255.0);
887 sal_uInt8 nGreen = toInt(mdGreen,255.0);
888 sal_uInt8 nBlue = toInt(mdBlue,255.0);
889
890 Color aColor(nRed, nGreen, nBlue);
891
892 if (n & UpdateFlags::RGB) // update RGB
893 {
894 m_xMFRed->set_value(nRed);
895 m_xMFGreen->set_value(nGreen);
896 m_xMFBlue->set_value(nBlue);
897 }
898
899 if (n & UpdateFlags::CMYK) // update CMYK
900 {
901 m_xMFCyan->set_value(toInt(mdCyan, 100.0), FieldUnit::PERCENT);
902 m_xMFMagenta->set_value(toInt(mdMagenta, 100.0), FieldUnit::PERCENT);
903 m_xMFYellow->set_value(toInt(mdYellow, 100.0), FieldUnit::PERCENT);
904 m_xMFKey->set_value(toInt(mdKey, 100.0), FieldUnit::PERCENT);
905 }
906
907 if (n & UpdateFlags::HSB ) // update HSB
908 {
909 m_xMFHue->set_value(toInt(mdHue, 1.0), FieldUnit::DEGREE);
910 m_xMFSaturation->set_value(toInt( mdSat, 100.0), FieldUnit::PERCENT);
911 m_xMFBrightness->set_value(toInt( mdBri, 100.0), FieldUnit::PERCENT);
912 }
913
914 if (n & UpdateFlags::ColorChooser ) // update Color Chooser 1
915 {
916 switch( meMode )
917 {
918 case HUE:
919 m_aColorField.SetValues(aColor, meMode, mdSat, mdBri);
920 break;
921 case SATURATION:
922 m_aColorField.SetValues(aColor, meMode, mdHue / 360.0, mdBri);
923 break;
924 case BRIGHTNESS:
925 m_aColorField.SetValues(aColor, meMode, mdHue / 360.0, mdSat);
926 break;
927 case RED:
928 m_aColorField.SetValues(aColor, meMode, mdBlue, mdGreen);
929 break;
930 case GREEN:
931 m_aColorField.SetValues(aColor, meMode, mdBlue, mdRed);
932 break;
933 case BLUE:
934 m_aColorField.SetValues(aColor, meMode, mdRed, mdGreen);
935 break;
936 }
937 }
938
939 if (n & UpdateFlags::ColorSlider) // update Color Chooser 2
940 {
941 switch (meMode)
942 {
943 case HUE:
944 m_aColorSlider.SetValue(aColor, meMode, mdHue / 360.0);
945 break;
946 case SATURATION:
947 m_aColorSlider.SetValue(aColor, meMode, mdSat);
948 break;
949 case BRIGHTNESS:
950 m_aColorSlider.SetValue(aColor, meMode, mdBri);
951 break;
952 case RED:
953 m_aColorSlider.SetValue(aColor, meMode, mdRed);
954 break;
955 case GREEN:
956 m_aColorSlider.SetValue(aColor, meMode, mdGreen);
957 break;
958 case BLUE:
959 m_aColorSlider.SetValue(aColor, meMode, mdBlue);
960 break;
961 }
962 }
963
964 if (n & UpdateFlags::Hex) // update hex
965 {
966 m_xFISliderLeft->set_margin_top(m_aColorSlider.GetLevel());
967 m_xFISliderRight->set_margin_top(m_aColorSlider.GetLevel());
968 m_xEDHex->SetColor(aColor);
969 }
970 m_aColorPreview.SetColor(aColor);
971}
972
973IMPL_LINK_NOARG(ColorPickerDialog, ColorFieldControlModifydl, ColorFieldControl&, void)
974{
975 double x = m_aColorField.GetX();
976 double y = m_aColorField.GetY();
977
978 switch( meMode )
979 {
980 case HUE:
981 mdSat = x;
982 setColorComponent( ColorComponent::Brightness, y );
983 break;
984 case SATURATION:
985 mdHue = x * 360.0;
986 setColorComponent( ColorComponent::Brightness, y );
987 break;
988 case BRIGHTNESS:
989 mdHue = x * 360.0;
990 setColorComponent( ColorComponent::Saturation, y );
991 break;
992 case RED:
993 mdBlue = x;
994 setColorComponent( ColorComponent::Green, y );
995 break;
996 case GREEN:
997 mdBlue = x;
998 setColorComponent( ColorComponent::Red, y );
999 break;
1000 case BLUE:
1001 mdRed = x;
1002 setColorComponent( ColorComponent::Green, y );
1003 break;
1004 }
1005
1006 update_color(UpdateFlags::All & ~UpdateFlags::ColorChooser);
1007}
1008
1009IMPL_LINK_NOARG(ColorPickerDialog, ColorSliderControlModifyHdl, ColorSliderControl&, void)
1010{
1011 double dValue = m_aColorSlider.GetValue();
1012 switch (meMode)
1013 {
1014 case HUE:
1015 setColorComponent( ColorComponent::Hue, dValue * 360.0 );
1016 break;
1017 case SATURATION:
1018 setColorComponent( ColorComponent::Saturation, dValue );
1019 break;
1020 case BRIGHTNESS:
1021 setColorComponent( ColorComponent::Brightness, dValue );
1022 break;
1023 case RED:
1024 setColorComponent( ColorComponent::Red, dValue );
1025 break;
1026 case GREEN:
1027 setColorComponent( ColorComponent::Green, dValue );
1028 break;
1029 case BLUE:
1030 setColorComponent( ColorComponent::Blue, dValue );
1031 break;
1032 }
1033
1034 update_color(UpdateFlags::All & ~UpdateFlags::ColorSlider);
1035}
1036
1037IMPL_LINK(ColorPickerDialog, ColorModifyMetricHdl, weld::MetricSpinButton&, rEdit, void)
1038{
1039 UpdateFlags n = UpdateFlags::NONE;
1040
1041 if (&rEdit == m_xMFHue.get())
1042 {
1043 setColorComponent( ColorComponent::Hue, static_cast<double>(m_xMFHue->get_value(FieldUnit::DEGREE)) );
1044 n = UpdateFlags::All & ~UpdateFlags::HSB;
1045 }
1046 else if (&rEdit == m_xMFSaturation.get())
1047 {
1048 setColorComponent( ColorComponent::Saturation, static_cast<double>(m_xMFSaturation->get_value(FieldUnit::PERCENT)) / 100.0 );
1049 n = UpdateFlags::All & ~UpdateFlags::HSB;
1050 }
1051 else if (&rEdit == m_xMFBrightness.get())
1052 {
1053 setColorComponent( ColorComponent::Brightness, static_cast<double>(m_xMFBrightness->get_value(FieldUnit::PERCENT)) / 100.0 );
1054 n = UpdateFlags::All & ~UpdateFlags::HSB;
1055 }
1056 else if (&rEdit == m_xMFCyan.get())
1057 {
1058 setColorComponent( ColorComponent::Cyan, static_cast<double>(m_xMFCyan->get_value(FieldUnit::PERCENT)) / 100.0 );
1059 n = UpdateFlags::All & ~UpdateFlags::CMYK;
1060 }
1061 else if (&rEdit == m_xMFMagenta.get())
1062 {
1063 setColorComponent( ColorComponent::Magenta, static_cast<double>(m_xMFMagenta->get_value(FieldUnit::PERCENT)) / 100.0 );
1064 n = UpdateFlags::All & ~UpdateFlags::CMYK;
1065 }
1066 else if (&rEdit == m_xMFYellow.get())
1067 {
1068 setColorComponent( ColorComponent::Yellow, static_cast<double>(m_xMFYellow->get_value(FieldUnit::PERCENT)) / 100.0 );
1069 n = UpdateFlags::All & ~UpdateFlags::CMYK;
1070 }
1071 else if (&rEdit == m_xMFKey.get())
1072 {
1073 setColorComponent( ColorComponent::Key, static_cast<double>(m_xMFKey->get_value(FieldUnit::PERCENT)) / 100.0 );
1074 n = UpdateFlags::All & ~UpdateFlags::CMYK;
1075 }
1076
1077 if (n != UpdateFlags::NONE)
1078 update_color(n);
1079}
1080
1081IMPL_LINK_NOARG(ColorPickerDialog, ColorModifyEditHdl, weld::Entry&, void)
1082{
1083 UpdateFlags n = UpdateFlags::NONE;
1084
1085 Color aColor = m_xEDHex->GetColor();
1086
1087 if (aColor != COL_AUTO && aColor != GetColor())
1088 {
1089 mdRed = static_cast<double>(aColor.GetRed()) / 255.0;
1090 mdGreen = static_cast<double>(aColor.GetGreen()) / 255.0;
1091 mdBlue = static_cast<double>(aColor.GetBlue()) / 255.0;
1092
1095 n = UpdateFlags::All & ~UpdateFlags::Hex;
1096 }
1097
1098 if (n != UpdateFlags::NONE)
1099 update_color(n);
1100}
1101
1102IMPL_LINK(ColorPickerDialog, ColorModifySpinHdl, weld::SpinButton&, rEdit, void)
1103{
1104 UpdateFlags n = UpdateFlags::NONE;
1105
1106 if (&rEdit == m_xMFRed.get())
1107 {
1108 setColorComponent( ColorComponent::Red, static_cast<double>(m_xMFRed->get_value()) / 255.0 );
1109 n = UpdateFlags::All & ~UpdateFlags::RGB;
1110 }
1111 else if (&rEdit == m_xMFGreen.get())
1112 {
1113 setColorComponent( ColorComponent::Green, static_cast<double>(m_xMFGreen->get_value()) / 255.0 );
1114 n = UpdateFlags::All & ~UpdateFlags::RGB;
1115 }
1116 else if (&rEdit == m_xMFBlue.get())
1117 {
1118 setColorComponent( ColorComponent::Blue, static_cast<double>(m_xMFBlue->get_value()) / 255.0 );
1119 n = UpdateFlags::All & ~UpdateFlags::RGB;
1120 }
1121
1122 if (n != UpdateFlags::NONE)
1123 update_color(n);
1124}
1125
1126
1127IMPL_LINK_NOARG(ColorPickerDialog, ModeModifyHdl, weld::Toggleable&, void)
1128{
1129 ColorMode eMode = HUE;
1130
1131 if (m_xRBRed->get_active())
1132 {
1133 eMode = RED;
1134 }
1135 else if (m_xRBGreen->get_active())
1136 {
1137 eMode = GREEN;
1138 }
1139 else if (m_xRBBlue->get_active())
1140 {
1141 eMode = BLUE;
1142 }
1143 else if (m_xRBSaturation->get_active())
1144 {
1145 eMode = SATURATION;
1146 }
1147 else if (m_xRBBrightness->get_active())
1148 {
1149 eMode = BRIGHTNESS;
1150 }
1151
1152 if (meMode != eMode)
1153 {
1154 meMode = eMode;
1155 update_color(UpdateFlags::ColorChooser | UpdateFlags::ColorSlider);
1156 }
1157}
1158
1159void ColorPickerDialog::setColorComponent( ColorComponent nComp, double dValue )
1160{
1161 switch( nComp )
1162 {
1163 case ColorComponent::Red:
1164 mdRed = dValue;
1165 break;
1166 case ColorComponent::Green:
1167 mdGreen = dValue;
1168 break;
1169 case ColorComponent::Blue:
1170 mdBlue = dValue;
1171 break;
1172 case ColorComponent::Hue:
1173 mdHue = dValue;
1174 break;
1175 case ColorComponent::Saturation:
1176 mdSat = dValue;
1177 break;
1178 case ColorComponent::Brightness:
1179 mdBri = dValue;
1180 break;
1181 case ColorComponent::Cyan:
1182 mdCyan = dValue;
1183 break;
1184 case ColorComponent::Yellow:
1185 mdYellow = dValue;
1186 break;
1187 case ColorComponent::Magenta:
1188 mdMagenta = dValue;
1189 break;
1190 case ColorComponent::Key:
1191 mdKey = dValue;
1192 break;
1193 }
1194
1195 if (nComp == ColorComponent::Red || nComp == ColorComponent::Green || nComp == ColorComponent::Blue)
1196 {
1199 }
1200 else if (nComp == ColorComponent::Hue || nComp == ColorComponent::Saturation || nComp == ColorComponent::Brightness)
1201 {
1204 }
1205 else
1206 {
1209 }
1210}
1211
1212typedef ::cppu::WeakComponentImplHelper< XServiceInfo, XExecutableDialog, XAsynchronousExecutableDialog, XInitialization, XPropertyAccess > ColorPickerBase;
1213
1214namespace {
1215
1216class ColorPicker : protected ::cppu::BaseMutex, // Struct for right initialization of mutex member! Must be first of baseclasses.
1217 public ColorPickerBase
1218{
1219public:
1220 explicit ColorPicker();
1221
1222 // XInitialization
1223 virtual void SAL_CALL initialize( const Sequence< Any >& aArguments ) override;
1224
1225 // XInitialization
1226 virtual OUString SAL_CALL getImplementationName( ) override;
1227 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
1228 virtual Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override;
1229
1230 // XPropertyAccess
1231 virtual Sequence< PropertyValue > SAL_CALL getPropertyValues( ) override;
1232 virtual void SAL_CALL setPropertyValues( const Sequence< PropertyValue >& aProps ) override;
1233
1234 // XExecutableDialog
1235 virtual void SAL_CALL setTitle( const OUString& aTitle ) override;
1236 virtual sal_Int16 SAL_CALL execute( ) override;
1237
1238 // XAsynchronousExecutableDialog
1239 virtual void SAL_CALL setDialogTitle( const OUString& aTitle ) override;
1240 virtual void SAL_CALL startExecuteModal( const css::uno::Reference< css::ui::dialogs::XDialogClosedListener >& xListener ) override;
1241
1242private:
1244 sal_Int16 mnMode;
1245 Reference<css::awt::XWindow> mxParent;
1246};
1247
1248}
1249
1250extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
1252 css::uno::XComponentContext*, css::uno::Sequence<css::uno::Any> const&)
1253{
1254 return cppu::acquire( new ColorPicker );
1255}
1256
1257
1258constexpr OUStringLiteral gsColorKey( u"Color" );
1259constexpr OUStringLiteral gsModeKey( u"Mode" );
1260
1261ColorPicker::ColorPicker()
1263 , mnColor( 0 )
1264 , mnMode( 0 )
1265{
1266}
1267
1268// XInitialization
1269void SAL_CALL ColorPicker::initialize( const Sequence< Any >& aArguments )
1270{
1271 if( aArguments.getLength() == 1 )
1272 {
1273 aArguments[0] >>= mxParent;
1274 }
1275}
1276
1277// XInitialization
1278OUString SAL_CALL ColorPicker::getImplementationName( )
1279{
1280 return "com.sun.star.cui.ColorPicker";
1281}
1282
1283sal_Bool SAL_CALL ColorPicker::supportsService( const OUString& sServiceName )
1284{
1285 return cppu::supportsService(this, sServiceName);
1286}
1287
1288Sequence< OUString > SAL_CALL ColorPicker::getSupportedServiceNames( )
1289{
1290 return { "com.sun.star.ui.dialogs.ColorPicker",
1291 "com.sun.star.ui.dialogs.AsynchronousColorPicker" };
1292}
1293
1294// XPropertyAccess
1295Sequence< PropertyValue > SAL_CALL ColorPicker::getPropertyValues( )
1296{
1297 Sequence< PropertyValue > props{ comphelper::makePropertyValue(gsColorKey, mnColor) };
1298 return props;
1299}
1300
1301void SAL_CALL ColorPicker::setPropertyValues( const Sequence< PropertyValue >& aProps )
1302{
1303 for ( const PropertyValue& rProp : aProps )
1304 {
1305 if( rProp.Name == gsColorKey )
1306 {
1307 rProp.Value >>= mnColor;
1308 }
1309 else if( rProp.Name == gsModeKey )
1310 {
1311 rProp.Value >>= mnMode;
1312 }
1313 }
1314}
1315
1316// XExecutableDialog
1317void SAL_CALL ColorPicker::setTitle( const OUString& )
1318{
1319}
1320
1321sal_Int16 SAL_CALL ColorPicker::execute()
1322{
1323 std::unique_ptr<ColorPickerDialog> xDlg(new ColorPickerDialog(Application::GetFrameWeld(mxParent), mnColor, mnMode));
1324 sal_Int16 ret = xDlg->run();
1325 if (ret)
1326 mnColor = xDlg->GetColor();
1327 return ret;
1328}
1329
1330// XAsynchronousExecutableDialog
1331void SAL_CALL ColorPicker::setDialogTitle( const OUString& )
1332{
1333}
1334
1335void SAL_CALL ColorPicker::startExecuteModal( const css::uno::Reference< css::ui::dialogs::XDialogClosedListener >& xListener )
1336{
1337 std::shared_ptr<ColorPickerDialog> xDlg = std::make_shared<ColorPickerDialog>(Application::GetFrameWeld(mxParent), mnColor, mnMode);
1338 weld::DialogController::runAsync(xDlg, [this, xDlg, xListener] (sal_Int32 nResult) {
1339 if (nResult)
1340 mnColor = xDlg->GetColor();
1341
1342 sal_Int16 nRet = static_cast<sal_Int16>(nResult);
1343 css::ui::dialogs::DialogClosedEvent aEvent( *this, nRet );
1344 xListener->dialogClosed( aEvent );
1345 });
1346}
1347
1348}
1349
1350/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
struct _ADOKey Key
AnyEventRef aEvent
static weld::Window * GetFrameWeld(const css::uno::Reference< css::awt::XWindow > &rWindow)
sal_uInt8 GetBlue() const
void RGBtoHSB(sal_uInt16 &nHue, sal_uInt16 &nSaturation, sal_uInt16 &nBrightness) const
bool IsDark() const
static Color HSBtoRGB(sal_uInt16 nHue, sal_uInt16 nSaturation, sal_uInt16 nBrightness)
sal_uInt8 GetRed() const
sal_uInt8 GetGreen() const
const Point & GetPosPixel() const
void DrawEllipse(const tools::Rectangle &rRect)
void DrawRect(const tools::Rectangle &rRect)
void SetLineColor()
void SetFillColor()
SAL_DLLPRIVATE void DrawOutDev(const Point &, const Size &, const Point &, const Size &, const Printer &)=delete
constexpr tools::Long Height() const
constexpr tools::Long Width() const
void disposeAndClear()
static VclPtr< reference_type > Create(Arg &&... arg)
static bool runAsync(const std::shared_ptr< DialogController > &rController, const std::function< void(sal_Int32)> &)
virtual int get_text_height() const=0
virtual void set_size_request(int nWidth, int nHeight)=0
virtual float get_approximate_digit_width() const=0
constexpr ::Color COL_AUTO(ColorTransparency, 0xFF, 0xFF, 0xFF, 0xFF)
double mdValue
std::unique_ptr< weld::CustomWeld > m_xColorSlider
std::vector< sal_uInt8 > maRGB_Horiz
double mdBlue
std::unique_ptr< weld::Widget > m_xFISliderLeft
double mdRed
Point maPosition
std::unique_ptr< weld::CustomWeld > m_xColorPrevious
Color maColor
std::unique_ptr< weld::RadioButton > m_xRBGreen
std::unique_ptr< weld::SpinButton > m_xMFGreen
double mdX
double mdMagenta
std::unique_ptr< weld::SpinButton > m_xMFBlue
ColorMode meMode
Color m_aColor
bool mbMouseCaptured
sal_Int16 mnMode
std::unique_ptr< weld::MetricSpinButton > m_xMFYellow
double mdY
std::unique_ptr< weld::RadioButton > m_xRBBrightness
std::unique_ptr< weld::SpinButton > m_xMFRed
std::unique_ptr< weld::MetricSpinButton > m_xMFBrightness
std::unique_ptr< weld::MetricSpinButton > m_xMFCyan
std::vector< sal_uInt16 > maPercent_Horiz
ColorFieldControl m_aColorField
std::unique_ptr< weld::RadioButton > m_xRBRed
std::unique_ptr< weld::MetricSpinButton > m_xMFHue
Color mnColor
std::unique_ptr< weld::HexColorControl > m_xEDHex
std::unique_ptr< weld::MetricSpinButton > m_xMFKey
std::unique_ptr< weld::CustomWeld > m_xColorField
std::vector< sal_uInt16 > maPercent_Vert
std::unique_ptr< weld::CustomWeld > m_xColorPreview
ColorPreviewControl m_aColorPreview
double mdHue
double mdSat
std::unique_ptr< weld::RadioButton > m_xRBSaturation
std::unique_ptr< weld::RadioButton > m_xRBBlue
ColorSliderControl m_aColorSlider
ColorPreviewControl m_aColorPrevious
double mdGreen
Link< ColorFieldControl &, void > maModifyHdl
std::unique_ptr< weld::RadioButton > m_xRBHue
std::vector< sal_uInt8 > maRGB_Vert
std::unique_ptr< weld::Widget > m_xFISliderRight
Reference< css::awt::XWindow > mxParent
VclPtr< VirtualDevice > mxBitmap
std::unique_ptr< weld::MetricSpinButton > m_xMFMagenta
double mdCyan
double mdYellow
std::unique_ptr< weld::MetricSpinButton > m_xMFSaturation
std::vector< sal_uInt16 > maGrad_Horiz
double mdKey
double mdBri
sal_Int16 mnLevel
DECL_LINK(CheckNameHdl, SvxNameDialog &, bool)
virtual void SetValue(tools::Long nNew) override
virtual tools::Long GetValue() const override
float y
float x
FieldUnit
std::mutex m_aMutex
Sequence< PropertyValue > aArguments
Mode eMode
sal_Int64 n
NONE
BColor hsv2rgb(const BColor &rHSVColor)
BColor rgb2hsv(const BColor &rRGBColor)
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
css::uno::Sequence< OUString > getSupportedServiceNames()
OUString getImplementationName()
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_cui_ColorPicker_get_implementation(css::uno::XComponentContext *, css::uno::Sequence< css::uno::Any > const &)
static void HSVtoRGB(double dH, double dS, double dV, double &dR, double &dG, double &dB)
::cppu::WeakComponentImplHelper< XServiceInfo, XExecutableDialog, XAsynchronousExecutableDialog, XInitialization, XPropertyAccess > ColorPickerBase
constexpr OUStringLiteral gsModeKey(u"Mode")
IMPL_LINK(ColorPickerDialog, ColorModifySpinHdl, weld::SpinButton &, rEdit, void)
static void CMYKtoRGB(double fCyan, double fMagenta, double fYellow, double fKey, double &dR, double &dG, double &dB)
static void RGBtoCMYK(double dR, double dG, double dB, double &fCyan, double &fMagenta, double &fYellow, double &fKey)
static int toInt(double dValue, double dRange)
static void RGBtoHSV(double dR, double dG, double dB, double &dH, double &dS, double &dV)
Definition: colorpicker.cxx:92
constexpr OUStringLiteral gsColorKey(u"Color")
const ColorMode DefaultMode
IMPL_LINK_NOARG(ColorPickerDialog, ModeModifyHdl, weld::Toggleable &, void)
dictionary props
long Long
@ MouseButtonDown
unsigned char sal_uInt8
unsigned char sal_Bool
Any result
constexpr OUStringLiteral PERCENT(u"Percent")
UpdateFlags