X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Fwx%2Fcontent_widget.h;h=302436e55385f5f0e75eb4844f8b253c5791f168;hb=HEAD;hp=c4ae4d591aaa5d97a472953d4e06626e0236019e;hpb=8796ee8654dfbf98290bfaaca1388e50ab962b40;p=dcpomatic.git diff --git a/src/wx/content_widget.h b/src/wx/content_widget.h index c4ae4d591..302436e55 100644 --- a/src/wx/content_widget.h +++ b/src/wx/content_widget.h @@ -18,21 +18,27 @@ */ + /** @file src/wx/content_widget.h * @brief ContentWidget class. */ + #ifndef DCPOMATIC_CONTENT_WIDGET_H #define DCPOMATIC_CONTENT_WIDGET_H + #include "wx_util.h" #include "lib/content.h" -#include +#include +LIBDCP_DISABLE_WARNINGS #include #include -#include +#include +LIBDCP_ENABLE_WARNINGS #include + /** @class ContentWidget * @brief A widget which represents some Content state and which can be used * when multiple pieces of content are selected. @@ -43,7 +49,7 @@ * @param V Data type of state as used by the view. */ template -class ContentWidget : public boost::noncopyable +class ContentWidget { public: /** @param parent Parent window. @@ -52,6 +58,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,21 +66,23 @@ public: wxWindow* parent, T* wrapped, int property, - boost::function (Content*)> part, - boost::function model_getter, - boost::function model_setter, - boost::function view_to_model, - boost::function model_to_view + std::function (Content*)> part, + std::function model_getter, + std::function model_setter, + std::function view_changed, + std::function view_to_model, + std::function model_to_view ) : _wrapped (wrapped) , _sizer (0) , _button (new wxButton (parent, wxID_ANY, _("Multiple values"))) , _property (property) - , _part (part) - , _model_getter (model_getter) - , _model_setter (model_setter) - , _view_to_model (view_to_model) - , _model_to_view (model_to_view) + , _part(std::move(part)) + , _model_getter(std::move(model_getter)) + , _model_setter(std::move(model_setter)) + , _view_changed(std::move(view_changed)) + , _view_to_model(std::move(view_to_model)) + , _model_to_view(std::move(model_to_view)) , _ignore_model_changes (false) { _button->SetToolTip (_("Click the button to set all selected content to the same value.")); @@ -81,13 +90,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 > List; + typedef std::vector > List; /** Set the content that this control is working on (i.e. the selected content) */ void set_content (List content) @@ -105,17 +117,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 +162,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 +204,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 +223,12 @@ private: wxButton* _button; List _content; int _property; - boost::function (Content *)> _part; - boost::function _model_getter; - boost::function _model_setter; - boost::function _view_to_model; - boost::function _model_to_view; + std::function (Content *)> _part; + std::function _model_getter; + std::function _model_setter; + std::function _view_changed; + std::function _view_to_model; + std::function _model_to_view; std::list _connections; bool _ignore_model_changes; }; @@ -227,9 +247,10 @@ public: wxWindow* parent, wxSpinCtrl* wrapped, int property, - boost::function (Content *)> part, - boost::function getter, - boost::function setter + std::function (Content *)> part, + std::function getter, + std::function setter, + std::function view_changed = std::function() ) : ContentWidget ( parent, @@ -237,6 +258,7 @@ public: property, part, getter, setter, + view_changed, &caster, &caster ) @@ -253,9 +275,10 @@ public: wxWindow* parent, wxSpinCtrlDouble* wrapped, int property, - boost::function (Content *)> part, - boost::function getter, - boost::function setter + std::function (Content *)> part, + std::function getter, + std::function setter, + std::function view_changed = std::function() ) : ContentWidget ( parent, @@ -263,6 +286,7 @@ public: property, part, getter, setter, + view_changed, &caster, &caster ) @@ -279,11 +303,12 @@ public: wxWindow* parent, wxChoice* wrapped, int property, - boost::function (Content *)> part, - boost::function getter, - boost::function setter, - boost::function view_to_model, - boost::function model_to_view + std::function (Content *)> part, + std::function getter, + std::function setter, + std::function view_to_model, + std::function model_to_view, + std::function view_changed = std::function() ) : ContentWidget ( parent, @@ -292,6 +317,7 @@ public: part, getter, setter, + view_changed, view_to_model, model_to_view )