Supporters update.
[dcpomatic.git] / src / wx / content_widget.h
index c4ae4d591aaa5d97a472953d4e06626e0236019e..34755e4b5a7e1707b710f45487bc9cdf4934dfd3 100644 (file)
@@ -30,7 +30,6 @@
 #include <wx/wx.h>
 #include <wx/gbsizer.h>
 #include <wx/spinctrl.h>
-#include <boost/function.hpp>
 #include <vector>
 
 /** @class ContentWidget
@@ -43,7 +42,7 @@
  *  @param V Data type of state as used by the view.
  */
 template <class S, class T, typename U, typename V>
-class ContentWidget : public boost::noncopyable
+class ContentWidget
 {
 public:
        /** @param parent Parent window.
@@ -52,6 +51,7 @@ public:
         *  @param part Part of Content that the property is in (e.g. &Content::video)
         *  @param model_getter Function on the Content to get the value.
         *  @param model_setter Function on the Content to set the value.
+        *  @param view_changed Function called when the view has changed; useful for linking controls.
         *  @param view_to_model Function to convert a view value to a model value.
         *  @param model_to_view Function to convert a model value to a view value.
         */
@@ -59,11 +59,12 @@ public:
                wxWindow* parent,
                T* wrapped,
                int property,
-               boost::function<boost::shared_ptr<S> (Content*)> part,
-               boost::function<U (S*)> model_getter,
-               boost::function<void (S*, U)> model_setter,
-               boost::function<U (V)> view_to_model,
-               boost::function<V (U)> model_to_view
+               std::function<std::shared_ptr<S> (Content*)> part,
+               std::function<U (S*)> model_getter,
+               std::function<void (S*, U)> model_setter,
+               std::function<void ()> view_changed,
+               std::function<U (V)> view_to_model,
+               std::function<V (U)> model_to_view
                )
                : _wrapped (wrapped)
                , _sizer (0)
@@ -72,6 +73,7 @@ public:
                , _part (part)
                , _model_getter (model_getter)
                , _model_setter (model_setter)
+               , _view_changed (view_changed)
                , _view_to_model (view_to_model)
                , _model_to_view (model_to_view)
                , _ignore_model_changes (false)
@@ -81,13 +83,16 @@ public:
                _button->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&ContentWidget::button_clicked, this));
        }
 
+       ContentWidget (ContentWidget const&) = delete;
+       ContentWidget& operator= (ContentWidget const&) = delete;
+
        /** @return the widget that we are wrapping */
        T* wrapped () const
        {
                return _wrapped;
        }
 
-       typedef std::vector<boost::shared_ptr<Content> > List;
+       typedef std::vector<std::shared_ptr<Content> > List;
 
        /** Set the content that this control is working on (i.e. the selected content) */
        void set_content (List content)
@@ -105,17 +110,21 @@ public:
                update_from_model ();
 
                for (typename List::iterator i = _content.begin(); i != _content.end(); ++i) {
+#if BOOST_VERSION >= 106100
+                       _connections.push_back ((*i)->Change.connect (boost::bind (&ContentWidget::model_changed, this, boost::placeholders::_1, boost::placeholders::_3)));
+#else
                        _connections.push_back ((*i)->Change.connect (boost::bind (&ContentWidget::model_changed, this, _1, _3)));
+#endif
                }
        }
 
        /** Add this widget to a wxGridBagSizer */
-       void add (wxGridBagSizer* sizer, wxGBPosition position, wxGBSpan span = wxDefaultSpan)
+       void add (wxGridBagSizer* sizer, wxGBPosition position, wxGBSpan span = wxDefaultSpan, int flag = 0)
        {
                _sizer = sizer;
                _position = position;
                _span = span;
-               _sizer->Add (_wrapped, _position, _span);
+               _sizer->Add (_wrapped, _position, _span, flag);
        }
 
        /** Update the view from the model */
@@ -146,6 +155,9 @@ public:
                for (size_t i = 0; i < _content.size(); ++i) {
                        boost::bind (_model_setter, _part (_content[i].get()).get(), _view_to_model (wx_get (_wrapped))) ();
                }
+               if (_view_changed) {
+                       _view_changed ();
+               }
                _ignore_model_changes = false;
        }
 
@@ -185,14 +197,14 @@ private:
        void button_clicked ()
        {
                U const v = boost::bind (_model_getter, _part(_content.front().get()).get())();
-               for (typename List::iterator i = _content.begin (); i != _content.end(); ++i) {
-                       boost::bind (_model_setter, _part(i->get()).get(), v) ();
+               for (auto const& i: _content) {
+                       boost::bind (_model_setter, _part(i.get()).get(), v)();
                }
        }
 
        void model_changed (ChangeType type, int property)
        {
-               if (type == CHANGE_TYPE_DONE && property == _property && !_ignore_model_changes) {
+               if (type == ChangeType::DONE && property == _property && !_ignore_model_changes) {
                        update_from_model ();
                }
        }
@@ -204,11 +216,12 @@ private:
        wxButton* _button;
        List _content;
        int _property;
-       boost::function<boost::shared_ptr<S> (Content *)> _part;
-       boost::function<U (S*)> _model_getter;
-       boost::function<void (S*, U)> _model_setter;
-       boost::function<U (V)> _view_to_model;
-       boost::function<V (U)> _model_to_view;
+       std::function<std::shared_ptr<S> (Content *)> _part;
+       std::function<U (S*)> _model_getter;
+       std::function<void (S*, U)> _model_setter;
+       std::function<void ()> _view_changed;
+       std::function<U (V)> _view_to_model;
+       std::function<V (U)> _model_to_view;
        std::list<boost::signals2::connection> _connections;
        bool _ignore_model_changes;
 };
@@ -227,9 +240,10 @@ public:
                wxWindow* parent,
                wxSpinCtrl* wrapped,
                int property,
-               boost::function<boost::shared_ptr<S> (Content *)> part,
-               boost::function<int (S*)> getter,
-               boost::function<void (S*, int)> setter
+               std::function<std::shared_ptr<S> (Content *)> part,
+               std::function<int (S*)> getter,
+               std::function<void (S*, int)> setter,
+               std::function<void ()> view_changed = std::function<void ()>()
                )
                : ContentWidget<S, wxSpinCtrl, int, int> (
                        parent,
@@ -237,6 +251,7 @@ public:
                        property,
                        part,
                        getter, setter,
+                       view_changed,
                        &caster<int, int>,
                        &caster<int, int>
                        )
@@ -253,9 +268,10 @@ public:
                wxWindow* parent,
                wxSpinCtrlDouble* wrapped,
                int property,
-               boost::function<boost::shared_ptr<S> (Content *)> part,
-               boost::function<double (S*)> getter,
-               boost::function<void (S*, double)> setter
+               std::function<std::shared_ptr<S> (Content *)> part,
+               std::function<double (S*)> getter,
+               std::function<void (S*, double)> setter,
+               std::function<void ()> view_changed = std::function<void ()>()
                )
                : ContentWidget<S, wxSpinCtrlDouble, double, double> (
                        parent,
@@ -263,6 +279,7 @@ public:
                        property,
                        part,
                        getter, setter,
+                       view_changed,
                        &caster<double, double>,
                        &caster<double, double>
                        )
@@ -279,11 +296,12 @@ public:
                wxWindow* parent,
                wxChoice* wrapped,
                int property,
-               boost::function<boost::shared_ptr<S> (Content *)> part,
-               boost::function<U (S*)> getter,
-               boost::function<void (S*, U)> setter,
-               boost::function<U (int)> view_to_model,
-               boost::function<int (U)> model_to_view
+               std::function<std::shared_ptr<S> (Content *)> part,
+               std::function<U (S*)> getter,
+               std::function<void (S*, U)> setter,
+               std::function<U (int)> view_to_model,
+               std::function<int (U)> model_to_view,
+               std::function<void ()> view_changed = std::function<void()>()
                )
                : ContentWidget<S, wxChoice, U, int> (
                        parent,
@@ -292,6 +310,7 @@ public:
                        part,
                        getter,
                        setter,
+                       view_changed,
                        view_to_model,
                        model_to_view
                        )