From a8e30a77bdd434ea2cdd81407f4ea75664fdce93 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Sat, 22 Mar 2014 13:44:30 +0000 Subject: [PATCH] Another attempt to fix glitches in the colour conversion dialog on OS X. Reported-by: Adam Colt --- ChangeLog | 5 ++++ src/wx/colour_conversion_editor.cc | 29 +++++++++++++++++++--- src/wx/colour_conversion_editor.h | 5 ++++ src/wx/content_colour_conversion_dialog.cc | 11 +++++--- 4 files changed, 43 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 418149a18..f44c24870 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2014-03-22 Carl Hetherington + + * Another attempt to fix colour conversion dialog strange behaviour + on OS X. + 2014-03-18 Carl Hetherington * Version 1.66.3 released. diff --git a/src/wx/colour_conversion_editor.cc b/src/wx/colour_conversion_editor.cc index a4ec23411..6617b66d6 100644 --- a/src/wx/colour_conversion_editor.cc +++ b/src/wx/colour_conversion_editor.cc @@ -93,20 +93,20 @@ ColourConversionEditor::ColourConversionEditor (wxWindow* parent) _output_gamma->SetDigits (2); _output_gamma->SetIncrement (0.1); - _input_gamma->Bind (wxEVT_COMMAND_SPINCTRLDOUBLE_UPDATED, boost::bind (&ColourConversionEditor::changed, this)); + _input_gamma->Bind (wxEVT_COMMAND_SPINCTRLDOUBLE_UPDATED, boost::bind (&ColourConversionEditor::changed, this, _input_gamma)); _input_gamma_linearised->Bind (wxEVT_COMMAND_CHECKBOX_CLICKED, boost::bind (&ColourConversionEditor::changed, this)); for (int i = 0; i < 3; ++i) { for (int j = 0; j < 3; ++j) { _matrix[i][j]->Bind (wxEVT_COMMAND_TEXT_UPDATED, boost::bind (&ColourConversionEditor::changed, this)); } } - _output_gamma->Bind (wxEVT_COMMAND_SPINCTRLDOUBLE_UPDATED, boost::bind (&ColourConversionEditor::changed, this)); + _output_gamma->Bind (wxEVT_COMMAND_SPINCTRLDOUBLE_UPDATED, boost::bind (&ColourConversionEditor::changed, this, _output_gamma)); } void ColourConversionEditor::set (ColourConversion conversion) { - _input_gamma->SetValue (conversion.input_gamma); + set_spin_ctrl (_input_gamma, conversion.input_gamma); _input_gamma_linearised->SetValue (conversion.input_gamma_linearised); for (int i = 0; i < 3; ++i) { for (int j = 0; j < 3; ++j) { @@ -117,7 +117,7 @@ ColourConversionEditor::set (ColourConversion conversion) _matrix[i][j]->SetValue (std_to_wx (s.str ())); } } - _output_gamma->SetValue (conversion.output_gamma); + set_spin_ctrl (_output_gamma, conversion.output_gamma); } ColourConversion @@ -150,3 +150,24 @@ ColourConversionEditor::changed () Changed (); } +void +ColourConversionEditor::changed (wxSpinCtrlDouble* sc) +{ + /* On OS X, it seems that in some cases when a wxSpinCtrlDouble loses focus + it emits an erroneous changed signal, which messes things up. + Check for that here. + */ + if (fabs (_last_spin_ctrl_value[sc] - sc->GetValue()) < 1e-3) { + return; + } + + Changed (); +} + +void +ColourConversionEditor::set_spin_ctrl (wxSpinCtrlDouble* control, double value) +{ + _last_spin_ctrl_value[control] = value; + control->SetValue (value); +} + diff --git a/src/wx/colour_conversion_editor.h b/src/wx/colour_conversion_editor.h index 8567cac22..ed22104e2 100644 --- a/src/wx/colour_conversion_editor.h +++ b/src/wx/colour_conversion_editor.h @@ -38,6 +38,11 @@ public: private: void changed (); + void changed (wxSpinCtrlDouble *); + + void set_spin_ctrl (wxSpinCtrlDouble *, double); + + std::map _last_spin_ctrl_value; wxSpinCtrlDouble* _input_gamma; wxCheckBox* _input_gamma_linearised; diff --git a/src/wx/content_colour_conversion_dialog.cc b/src/wx/content_colour_conversion_dialog.cc index d8e768bcd..3fa8e120a 100644 --- a/src/wx/content_colour_conversion_dialog.cc +++ b/src/wx/content_colour_conversion_dialog.cc @@ -20,6 +20,7 @@ #include #include "lib/colour_conversion.h" #include "lib/config.h" +#include "lib/util.h" #include "wx_util.h" #include "content_colour_conversion_dialog.h" #include "colour_conversion_editor.h" @@ -78,7 +79,7 @@ ContentColourConversionDialog::set (ColourConversion c) _setting = true; _editor->set (c); _setting = false; - + check_for_preset (); } @@ -93,7 +94,11 @@ ContentColourConversionDialog::check_for_preset () _preset_check->SetValue (preset); _preset_choice->Enable (preset); - _preset_choice->SetSelection (preset.get_value_or (-1)); + if (preset) { + _preset_choice->SetSelection (preset.get ()); + } else { + _preset_choice->SetSelection (-1); + } } void @@ -112,7 +117,7 @@ void ContentColourConversionDialog::preset_choice_changed () { vector presets = Config::instance()->colour_conversions (); - int const s = _preset_choice->GetSelection(); + int const s = _preset_choice->GetCurrentSelection(); if (s != -1) { set (presets[s].conversion); } -- 2.30.2