Another attempt to fix glitches in the colour conversion dialog
authorCarl Hetherington <cth@carlh.net>
Sat, 22 Mar 2014 13:44:30 +0000 (13:44 +0000)
committerCarl Hetherington <cth@carlh.net>
Sat, 22 Mar 2014 13:44:30 +0000 (13:44 +0000)
on OS X.

Reported-by: Adam Colt
ChangeLog
src/wx/colour_conversion_editor.cc
src/wx/colour_conversion_editor.h
src/wx/content_colour_conversion_dialog.cc

index 418149a183aef3f12c7979e49399bd3c1be4794b..f44c248704192eeecfeb4966e899c49df879d50e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2014-03-22  Carl Hetherington  <cth@carlh.net>
+
+       * Another attempt to fix colour conversion dialog strange behaviour
+       on OS X.
+
 2014-03-18  Carl Hetherington  <cth@carlh.net>
 
        * Version 1.66.3 released.
index a4ec2341126788fca6321c583824032914e5e00f..6617b66d6ca44dbae258041628898663dda3c979 100644 (file)
@@ -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);
+}
+
index 8567cac22250a9a85d83e9ea1b903be7aaa81563..ed22104e2addef25309d8bd635f5792b8f9f7fef 100644 (file)
@@ -38,6 +38,11 @@ public:
 
 private:
        void changed ();
+       void changed (wxSpinCtrlDouble *);
+
+       void set_spin_ctrl (wxSpinCtrlDouble *, double);
+
+       std::map<wxSpinCtrlDouble*, double> _last_spin_ctrl_value;
        
        wxSpinCtrlDouble* _input_gamma;
        wxCheckBox* _input_gamma_linearised;
index d8e768bcd6d16b069ab273ae0eb414a5e8d3bce1..3fa8e120a8cff1d41284529cf4cc38d2aa52989c 100644 (file)
@@ -20,6 +20,7 @@
 #include <wx/statline.h>
 #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<PresetColourConversion> presets = Config::instance()->colour_conversions ();
-       int const s = _preset_choice->GetSelection();
+       int const s = _preset_choice->GetCurrentSelection();
        if (s != -1) {
                set (presets[s].conversion);
        }