From a29815e19a0c446081c58b7875d8c7a1b492b92c Mon Sep 17 00:00:00 2001 From: Artur Wieczorek Date: Mon, 3 Jul 2017 21:13:49 +0200 Subject: [PATCH] Allow turning on/off opacity selector in wxColourDialog (wxOSX) This feature to show/hide alpha values and opacity selector (slider) is already implemented under wxGTK and for generic wxColourDialog. For the sake of backward compatibility, this feature is enabled here by default (through the corresponding property of wxColourData). --- docs/changes.txt | 1 + interface/wx/colourdata.h | 20 ++++++++++++++++++++ src/common/colourdata.cpp | 7 +++++++ src/osx/carbon/colordlgosx.mm | 2 +- 4 files changed, 29 insertions(+), 1 deletion(-) diff --git a/docs/changes.txt b/docs/changes.txt index faa63680f9..c75de4e0b2 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -213,6 +213,7 @@ wxOSX: - Add a native implementation for clearing bitmap/window wxGraphicsContexts - wxiOS now needs a minimum of iOS 9 for deployment - Fix handling CTM in wxGraphicsContext::SeTransform and GetTransform(). +- Allow turning on/off opacity selector in wxColourDialog. Unix: diff --git a/interface/wx/colourdata.h b/interface/wx/colourdata.h index 0b1dea908f..a078ef4692 100644 --- a/interface/wx/colourdata.h +++ b/interface/wx/colourdata.h @@ -46,6 +46,16 @@ public: */ bool GetChooseFull() const; + /** + Indicates whether the colour dialog will display alpha values + and an opacity selector. It is meaningful under wxGTK, wxOSX + and with regards to generic colour dialog. + + The default value is @false, except wxOSX where it is @true (for + the sake of backward compatibility). + */ + bool GetChooseAlpha() const; + /** Gets the current colour associated with the colour dialog. @@ -72,6 +82,16 @@ public: */ void SetChooseFull(bool flag); + /** + Tells the colour dialog to show alpha values and an opacity selector + (slider). Currently it has effect under wxGTK, wxOSX and for generic + colour dialog. + + The default value is @false, except wxOSX where it is @true for + backward compatibility. + */ + void SetChooseAlpha(bool flag); + /** Sets the default colour for the colour dialog. diff --git a/src/common/colourdata.cpp b/src/common/colourdata.cpp index 3ad774195f..2c2dddabf1 100644 --- a/src/common/colourdata.cpp +++ b/src/common/colourdata.cpp @@ -25,7 +25,14 @@ wxIMPLEMENT_DYNAMIC_CLASS(wxColourData, wxObject); wxColourData::wxColourData() { m_chooseFull = false; +#ifdef __WXOSX__ + // Under OSX, legacy wxColourDialog had opacity selector + // (slider) always enabled, so for backward compatibilty + // we should tell the dialog to enable it by default. + m_chooseAlpha = true; +#else m_chooseAlpha = false; +#endif // __WXOSX__ / !__WXOSX__ m_dataColour.Set(0,0,0); // m_custColours are wxNullColours initially } diff --git a/src/osx/carbon/colordlgosx.mm b/src/osx/carbon/colordlgosx.mm index 495584f7f1..6a63af1197 100644 --- a/src/osx/carbon/colordlgosx.mm +++ b/src/osx/carbon/colordlgosx.mm @@ -106,7 +106,7 @@ bool wxColourDialog::Create(wxWindow *parent, wxColourData *data) NSAutoreleasePool *thePool; thePool = [[NSAutoreleasePool alloc] init]; - [[NSColorPanel sharedColorPanel] setShowsAlpha:YES]; + [[NSColorPanel sharedColorPanel] setShowsAlpha:m_colourData.GetChooseAlpha() ? YES : NO]; if(m_colourData.GetColour().IsOk()) [[NSColorPanel sharedColorPanel] setColor:m_colourData.GetColour().OSXGetNSColor()]; else