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