X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Fwx%2Fcontent_widget.h;h=744d0a7a28b312d96d867b08cbfb10c5b5d6e59b;hb=73407f943ba25e2a0df2c98b3a9a938132876e9f;hp=b4d06286e46972de23b863460ec8aebceba57653;hpb=e491397c0028a80ac4a48a92007f783746553c1a;p=dcpomatic.git diff --git a/src/wx/content_widget.h b/src/wx/content_widget.h index b4d06286e..744d0a7a2 100644 --- a/src/wx/content_widget.h +++ b/src/wx/content_widget.h @@ -1,19 +1,20 @@ /* - Copyright (C) 2013-2014 Carl Hetherington + Copyright (C) 2013-2016 Carl Hetherington - This program is free software; you can redistribute it and/or modify + This file is part of DCP-o-matic. + + DCP-o-matic is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. - This program is distributed in the hope that it will be useful, + DCP-o-matic is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with DCP-o-matic. If not, see . */ @@ -21,27 +22,28 @@ * @brief ContentWidget class. */ -#ifndef DCPOMATIC_MULTIPLE_WIDGET_H -#define DCPOMATIC_MULTIPLE_WIDGET_H +#ifndef DCPOMATIC_CONTENT_WIDGET_H +#define DCPOMATIC_CONTENT_WIDGET_H -#include +#include "wx_util.h" +#include "lib/content.h" #include #include #include #include -#include "wx_util.h" +#include /** @class ContentWidget * @brief A widget which represents some Content state and which can be used * when multiple pieces of content are selected. * - * @param S Type containing the content being represented (e.g. VideoContent) + * @param S Type of ContentPart being manipulated (e.g. VideoContent) * @param T Type of the widget (e.g. wxSpinCtrl) * @param U Data type of state as used by the model. * @param V Data type of state as used by the view. */ template -class ContentWidget +class ContentWidget : public boost::noncopyable { public: /** @param parent Parent window. @@ -54,6 +56,7 @@ public: wxWindow* parent, T* wrapped, int property, + boost::function (Content*)> part, boost::function model_getter, boost::function model_setter, boost::function view_to_model, @@ -63,6 +66,7 @@ public: , _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) @@ -80,7 +84,7 @@ public: 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) @@ -90,7 +94,7 @@ public: } _connections.clear (); - + _content = content; _wrapped->Enable (!_content.empty ()); @@ -120,8 +124,8 @@ public: } typename List::iterator i = _content.begin (); - U const v = boost::bind (_model_getter, _content.front().get())(); - while (i != _content.end() && boost::bind (_model_getter, i->get())() == v) { + U const v = boost::bind (_model_getter, _part(_content.front().get()).get())(); + while (i != _content.end() && boost::bind (_model_getter, _part(i->get()).get())() == v) { ++i; } @@ -137,13 +141,13 @@ public: { _ignore_model_changes = true; for (size_t i = 0; i < _content.size(); ++i) { - boost::bind (_model_setter, _content[i].get(), _view_to_model (wx_get (_wrapped))) (); + boost::bind (_model_setter, _part (_content[i].get()).get(), _view_to_model (wx_get (_wrapped))) (); } _ignore_model_changes = false; } - + private: - + void set_single () { if (_wrapped->IsShown ()) { @@ -162,7 +166,7 @@ private: if (_button->IsShown ()) { return; } - + _wrapped->Hide (); _sizer->Detach (_wrapped); _button->Show (); @@ -172,9 +176,9 @@ private: void button_clicked () { - U const v = boost::bind (_model_getter, _content.front().get())(); + 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, i->get(), v) (); + boost::bind (_model_setter, _part(i->get()).get(), v) (); } } @@ -184,7 +188,7 @@ private: update_from_model (); } } - + T* _wrapped; wxGridBagSizer* _sizer; wxGBPosition _position; @@ -192,6 +196,7 @@ private: wxButton* _button; List _content; int _property; + boost::function (Content *)> _part; boost::function _model_getter; boost::function _model_setter; boost::function _view_to_model; @@ -214,6 +219,7 @@ public: wxWindow* parent, wxSpinCtrl* wrapped, int property, + boost::function (Content *)> part, boost::function getter, boost::function setter ) @@ -221,6 +227,7 @@ public: parent, wrapped, property, + part, getter, setter, &caster, &caster @@ -238,6 +245,7 @@ public: wxWindow* parent, wxSpinCtrlDouble* wrapped, int property, + boost::function (Content *)> part, boost::function getter, boost::function setter ) @@ -245,6 +253,7 @@ public: parent, wrapped, property, + part, getter, setter, &caster, &caster @@ -262,6 +271,7 @@ public: wxWindow* parent, wxChoice* wrapped, int property, + boost::function (Content *)> part, boost::function getter, boost::function setter, boost::function view_to_model, @@ -271,6 +281,7 @@ public: parent, wrapped, property, + part, getter, setter, view_to_model,