Merge master.
[dcpomatic.git] / src / wx / timeline.cc
1 /*
2     Copyright (C) 2013-2014 Carl Hetherington <cth@carlh.net>
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #include <list>
21 #include <wx/graphics.h>
22 #include <boost/weak_ptr.hpp>
23 #include "lib/film.h"
24 #include "lib/playlist.h"
25 #include "lib/image_content.h"
26 #include "film_editor.h"
27 #include "timeline.h"
28 #include "content_panel.h"
29 #include "wx_util.h"
30
31 using std::list;
32 using std::cout;
33 using std::max;
34 using boost::shared_ptr;
35 using boost::weak_ptr;
36 using boost::dynamic_pointer_cast;
37 using boost::bind;
38 using boost::optional;
39
40 /** @class View
41  *  @brief Parent class for components of the timeline (e.g. a piece of content or an axis).
42  */
43 class View : public boost::noncopyable
44 {
45 public:
46         View (Timeline& t)
47                 : _timeline (t)
48         {
49
50         }
51
52         virtual ~View () {}
53                 
54         void paint (wxGraphicsContext* g)
55         {
56                 _last_paint_bbox = bbox ();
57                 do_paint (g);
58         }
59         
60         void force_redraw ()
61         {
62                 _timeline.force_redraw (_last_paint_bbox);
63                 _timeline.force_redraw (bbox ());
64         }
65
66         virtual dcpomatic::Rect<int> bbox () const = 0;
67
68 protected:
69         virtual void do_paint (wxGraphicsContext *) = 0;
70         
71         int time_x (DCPTime t) const
72         {
73                 return _timeline.tracks_position().x + t.seconds() * _timeline.pixels_per_second().get_value_or (0);
74         }
75         
76         Timeline& _timeline;
77
78 private:
79         dcpomatic::Rect<int> _last_paint_bbox;
80 };
81
82
83 /** @class ContentView
84  *  @brief Parent class for views of pieces of content.
85  */
86 class ContentView : public View
87 {
88 public:
89         ContentView (Timeline& tl, shared_ptr<Content> c)
90                 : View (tl)
91                 , _content (c)
92                 , _selected (false)
93         {
94                 _content_connection = c->Changed.connect (bind (&ContentView::content_changed, this, _2, _3));
95         }
96
97         dcpomatic::Rect<int> bbox () const
98         {
99                 assert (_track);
100
101                 shared_ptr<const Film> film = _timeline.film ();
102                 shared_ptr<const Content> content = _content.lock ();
103                 if (!film || !content) {
104                         return dcpomatic::Rect<int> ();
105                 }
106                 
107                 return dcpomatic::Rect<int> (
108                         time_x (content->position ()) - 8,
109                         y_pos (_track.get()) - 8,
110                         content->length_after_trim().seconds() * _timeline.pixels_per_second().get_value_or(0) + 16,
111                         _timeline.track_height() + 16
112                         );
113         }
114
115         void set_selected (bool s) {
116                 _selected = s;
117                 force_redraw ();
118         }
119         
120         bool selected () const {
121                 return _selected;
122         }
123
124         shared_ptr<Content> content () const {
125                 return _content.lock ();
126         }
127
128         void set_track (int t) {
129                 _track = t;
130         }
131
132         void unset_track () {
133                 _track = boost::optional<int> ();
134         }
135
136         optional<int> track () const {
137                 return _track;
138         }
139
140         virtual wxString type () const = 0;
141         virtual wxColour background_colour () const = 0;
142         virtual wxColour foreground_colour () const = 0;
143         
144 private:
145
146         void do_paint (wxGraphicsContext* gc)
147         {
148                 assert (_track);
149
150                 shared_ptr<const Film> film = _timeline.film ();
151                 shared_ptr<const Content> cont = content ();
152                 if (!film || !cont) {
153                         return;
154                 }
155
156                 DCPTime const position = cont->position ();
157                 DCPTime const len = cont->length_after_trim ();
158
159                 wxColour selected (background_colour().Red() / 2, background_colour().Green() / 2, background_colour().Blue() / 2);
160
161                 gc->SetPen (*wxThePenList->FindOrCreatePen (foreground_colour(), 4, wxPENSTYLE_SOLID));
162                 if (_selected) {
163                         gc->SetBrush (*wxTheBrushList->FindOrCreateBrush (selected, wxBRUSHSTYLE_SOLID));
164                 } else {
165                         gc->SetBrush (*wxTheBrushList->FindOrCreateBrush (background_colour(), wxBRUSHSTYLE_SOLID));
166                 }
167
168                 wxGraphicsPath path = gc->CreatePath ();
169                 path.MoveToPoint    (time_x (position),       y_pos (_track.get()) + 4);
170                 path.AddLineToPoint (time_x (position + len), y_pos (_track.get()) + 4);
171                 path.AddLineToPoint (time_x (position + len), y_pos (_track.get() + 1) - 4);
172                 path.AddLineToPoint (time_x (position),       y_pos (_track.get() + 1) - 4);
173                 path.AddLineToPoint (time_x (position),       y_pos (_track.get()) + 4);
174                 gc->StrokePath (path);
175                 gc->FillPath (path);
176
177                 wxString name = wxString::Format (wxT ("%s [%s]"), std_to_wx (cont->summary()).data(), type().data());
178                 wxDouble name_width;
179                 wxDouble name_height;
180                 wxDouble name_descent;
181                 wxDouble name_leading;
182                 gc->GetTextExtent (name, &name_width, &name_height, &name_descent, &name_leading);
183                 
184                 gc->Clip (wxRegion (time_x (position), y_pos (_track.get()), len.seconds() * _timeline.pixels_per_second().get_value_or(0), _timeline.track_height()));
185                 gc->SetFont (gc->CreateFont (*wxNORMAL_FONT, foreground_colour ()));
186                 gc->DrawText (name, time_x (position) + 12, y_pos (_track.get() + 1) - name_height - 4);
187                 gc->ResetClip ();
188         }
189
190         int y_pos (int t) const
191         {
192                 return _timeline.tracks_position().y + t * _timeline.track_height();
193         }
194
195         void content_changed (int p, bool frequent)
196         {
197                 ensure_ui_thread ();
198                 
199                 if (p == ContentProperty::POSITION || p == ContentProperty::LENGTH) {
200                         force_redraw ();
201                 }
202
203                 if (!frequent) {
204                         _timeline.setup_pixels_per_second ();
205                         _timeline.Refresh ();
206                 }
207         }
208
209         boost::weak_ptr<Content> _content;
210         optional<int> _track;
211         bool _selected;
212
213         boost::signals2::scoped_connection _content_connection;
214 };
215
216 /** @class AudioContentView
217  *  @brief Timeline view for AudioContent.
218  */
219 class AudioContentView : public ContentView
220 {
221 public:
222         AudioContentView (Timeline& tl, shared_ptr<Content> c)
223                 : ContentView (tl, c)
224         {}
225         
226 private:
227         wxString type () const
228         {
229                 return _("audio");
230         }
231
232         wxColour background_colour () const
233         {
234                 return wxColour (149, 121, 232, 255);
235         }
236
237         wxColour foreground_colour () const
238         {
239                 return wxColour (0, 0, 0, 255);
240         }
241 };
242
243 /** @class AudioContentView
244  *  @brief Timeline view for VideoContent.
245  */
246 class VideoContentView : public ContentView
247 {
248 public:
249         VideoContentView (Timeline& tl, shared_ptr<Content> c)
250                 : ContentView (tl, c)
251         {}
252
253 private:        
254
255         wxString type () const
256         {
257                 if (dynamic_pointer_cast<ImageContent> (content ()) && content()->number_of_paths() == 1) {
258                         return _("still");
259                 } else {
260                         return _("video");
261                 }
262         }
263
264         wxColour background_colour () const
265         {
266                 return wxColour (242, 92, 120, 255);
267         }
268
269         wxColour foreground_colour () const
270         {
271                 return wxColour (0, 0, 0, 255);
272         }
273 };
274
275 /** @class AudioContentView
276  *  @brief Timeline view for SubtitleContent.
277  */
278 class SubtitleContentView : public ContentView
279 {
280 public:
281         SubtitleContentView (Timeline& tl, shared_ptr<SubtitleContent> c)
282                 : ContentView (tl, c)
283                 , _subtitle_content (c)
284         {}
285
286 private:
287         wxString type () const
288         {
289                 return _("subtitles");
290         }
291
292         wxColour background_colour () const
293         {
294                 shared_ptr<SubtitleContent> sc = _subtitle_content.lock ();
295                 if (!sc || !sc->use_subtitles ()) {
296                         return wxColour (210, 210, 210, 128);
297                 }
298                 
299                 return wxColour (163, 255, 154, 255);
300         }
301
302         wxColour foreground_colour () const
303         {
304                 shared_ptr<SubtitleContent> sc = _subtitle_content.lock ();
305                 if (!sc || !sc->use_subtitles ()) {
306                         return wxColour (180, 180, 180, 128);
307                 }
308
309                 return wxColour (0, 0, 0, 255);
310         }
311
312         boost::weak_ptr<SubtitleContent> _subtitle_content;
313 };
314
315 class TimeAxisView : public View
316 {
317 public:
318         TimeAxisView (Timeline& tl, int y)
319                 : View (tl)
320                 , _y (y)
321         {}
322         
323         dcpomatic::Rect<int> bbox () const
324         {
325                 return dcpomatic::Rect<int> (0, _y - 4, _timeline.width(), 24);
326         }
327
328         void set_y (int y)
329         {
330                 _y = y;
331                 force_redraw ();
332         }
333
334 private:        
335
336         void do_paint (wxGraphicsContext* gc)
337         {
338                 if (!_timeline.pixels_per_second()) {
339                         return;
340                 }
341
342                 double const pps = _timeline.pixels_per_second().get ();
343                 
344                 gc->SetPen (*wxThePenList->FindOrCreatePen (wxColour (0, 0, 0), 1, wxPENSTYLE_SOLID));
345                 
346                 double mark_interval = rint (128 / pps);
347                 if (mark_interval > 5) {
348                         mark_interval -= int (rint (mark_interval)) % 5;
349                 }
350                 if (mark_interval > 10) {
351                         mark_interval -= int (rint (mark_interval)) % 10;
352                 }
353                 if (mark_interval > 60) {
354                         mark_interval -= int (rint (mark_interval)) % 60;
355                 }
356                 if (mark_interval > 3600) {
357                         mark_interval -= int (rint (mark_interval)) % 3600;
358                 }
359                 
360                 if (mark_interval < 1) {
361                         mark_interval = 1;
362                 }
363
364                 wxGraphicsPath path = gc->CreatePath ();
365                 path.MoveToPoint (_timeline.x_offset(), _y);
366                 path.AddLineToPoint (_timeline.width(), _y);
367                 gc->StrokePath (path);
368
369                 gc->SetFont (gc->CreateFont (*wxNORMAL_FONT));
370                 
371                 /* Time in seconds */
372                 DCPTime t;
373                 while ((t.seconds() * pps) < _timeline.width()) {
374                         wxGraphicsPath path = gc->CreatePath ();
375                         path.MoveToPoint (time_x (t), _y - 4);
376                         path.AddLineToPoint (time_x (t), _y + 4);
377                         gc->StrokePath (path);
378
379                         double tc = t.seconds ();
380                         int const h = tc / 3600;
381                         tc -= h * 3600;
382                         int const m = tc / 60;
383                         tc -= m * 60;
384                         int const s = tc;
385                         
386                         wxString str = wxString::Format (wxT ("%02d:%02d:%02d"), h, m, s);
387                         wxDouble str_width;
388                         wxDouble str_height;
389                         wxDouble str_descent;
390                         wxDouble str_leading;
391                         gc->GetTextExtent (str, &str_width, &str_height, &str_descent, &str_leading);
392                         
393                         int const tx = _timeline.x_offset() + t.seconds() * pps;
394                         if ((tx + str_width) < _timeline.width()) {
395                                 gc->DrawText (str, time_x (t), _y + 16);
396                         }
397                         
398                         t += DCPTime::from_seconds (mark_interval);
399                 }
400         }
401
402 private:
403         int _y;
404 };
405
406
407 Timeline::Timeline (wxWindow* parent, ContentPanel* cp, shared_ptr<Film> film)
408         : wxPanel (parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxFULL_REPAINT_ON_RESIZE)
409         , _content_panel (cp)
410         , _film (film)
411         , _time_axis_view (new TimeAxisView (*this, 32))
412         , _tracks (0)
413         , _left_down (false)
414         , _down_view_position (0)
415         , _first_move (false)
416         , _menu (this)
417         , _snap (true)
418 {
419 #ifndef __WXOSX__
420         SetDoubleBuffered (true);
421 #endif  
422
423         Bind (wxEVT_PAINT,      boost::bind (&Timeline::paint,       this));
424         Bind (wxEVT_LEFT_DOWN,  boost::bind (&Timeline::left_down,   this, _1));
425         Bind (wxEVT_LEFT_UP,    boost::bind (&Timeline::left_up,     this, _1));
426         Bind (wxEVT_RIGHT_DOWN, boost::bind (&Timeline::right_down,  this, _1));
427         Bind (wxEVT_MOTION,     boost::bind (&Timeline::mouse_moved, this, _1));
428         Bind (wxEVT_SIZE,       boost::bind (&Timeline::resized,     this));
429
430         playlist_changed ();
431
432         SetMinSize (wxSize (640, tracks() * track_height() + 96));
433
434         _playlist_changed_connection = film->playlist()->Changed.connect (bind (&Timeline::playlist_changed, this));
435         _playlist_content_changed_connection = film->playlist()->ContentChanged.connect (bind (&Timeline::playlist_content_changed, this, _2));
436 }
437
438 void
439 Timeline::paint ()
440 {
441         wxPaintDC dc (this);
442
443         wxGraphicsContext* gc = wxGraphicsContext::Create (dc);
444         if (!gc) {
445                 return;
446         }
447
448         for (ViewList::iterator i = _views.begin(); i != _views.end(); ++i) {
449                 (*i)->paint (gc);
450         }
451
452         delete gc;
453 }
454
455 void
456 Timeline::playlist_changed ()
457 {
458         ensure_ui_thread ();
459         
460         shared_ptr<const Film> fl = _film.lock ();
461         if (!fl) {
462                 return;
463         }
464
465         _views.clear ();
466         _views.push_back (_time_axis_view);
467
468         ContentList content = fl->playlist()->content ();
469
470         for (ContentList::iterator i = content.begin(); i != content.end(); ++i) {
471                 if (dynamic_pointer_cast<VideoContent> (*i)) {
472                         _views.push_back (shared_ptr<View> (new VideoContentView (*this, *i)));
473                 }
474                 if (dynamic_pointer_cast<AudioContent> (*i)) {
475                         _views.push_back (shared_ptr<View> (new AudioContentView (*this, *i)));
476                 }
477
478                 shared_ptr<SubtitleContent> sc = dynamic_pointer_cast<SubtitleContent> (*i);
479                 if (sc && sc->has_subtitles ()) {
480                         _views.push_back (shared_ptr<View> (new SubtitleContentView (*this, sc)));
481                 }
482         }
483
484         assign_tracks ();
485         setup_pixels_per_second ();
486         Refresh ();
487 }
488
489 void
490 Timeline::playlist_content_changed (int property)
491 {
492         ensure_ui_thread ();
493
494         if (property == ContentProperty::POSITION) {
495                 assign_tracks ();
496                 setup_pixels_per_second ();
497                 Refresh ();
498         }
499 }
500
501 void
502 Timeline::assign_tracks ()
503 {
504         for (ViewList::iterator i = _views.begin(); i != _views.end(); ++i) {
505                 shared_ptr<ContentView> c = dynamic_pointer_cast<ContentView> (*i);
506                 if (c) {
507                         c->unset_track ();
508                 }
509         }
510
511         for (ViewList::iterator i = _views.begin(); i != _views.end(); ++i) {
512                 shared_ptr<ContentView> cv = dynamic_pointer_cast<ContentView> (*i);
513                 if (!cv) {
514                         continue;
515                 }
516
517                 shared_ptr<Content> content = cv->content();
518
519                 int t = 0;
520                 while (true) {
521                         ViewList::iterator j = _views.begin();
522                         while (j != _views.end()) {
523                                 shared_ptr<ContentView> test = dynamic_pointer_cast<ContentView> (*j);
524                                 if (!test) {
525                                         ++j;
526                                         continue;
527                                 }
528                                 
529                                 shared_ptr<Content> test_content = test->content();
530                                         
531                                 if (test && test->track() && test->track().get() == t) {
532                                         bool const no_overlap =
533                                                 (content->position() < test_content->position() && content->end() < test_content->position()) ||
534                                                 (content->position() > test_content->end()      && content->end() > test_content->end());
535                                         
536                                         if (!no_overlap) {
537                                                 /* we have an overlap on track `t' */
538                                                 ++t;
539                                                 break;
540                                         }
541                                 }
542                                 
543                                 ++j;
544                         }
545
546                         if (j == _views.end ()) {
547                                 /* no overlap on `t' */
548                                 break;
549                         }
550                 }
551
552                 cv->set_track (t);
553                 _tracks = max (_tracks, t + 1);
554         }
555
556         _time_axis_view->set_y (tracks() * track_height() + 32);
557 }
558
559 int
560 Timeline::tracks () const
561 {
562         return _tracks;
563 }
564
565 void
566 Timeline::setup_pixels_per_second ()
567 {
568         shared_ptr<const Film> film = _film.lock ();
569         if (!film || film->length() == DCPTime ()) {
570                 return;
571         }
572
573         _pixels_per_second = static_cast<double>(width() - x_offset() * 2) / film->length().seconds ();
574 }
575
576 shared_ptr<View>
577 Timeline::event_to_view (wxMouseEvent& ev)
578 {
579         ViewList::iterator i = _views.begin();
580         Position<int> const p (ev.GetX(), ev.GetY());
581         while (i != _views.end() && !(*i)->bbox().contains (p)) {
582                 ++i;
583         }
584
585         if (i == _views.end ()) {
586                 return shared_ptr<View> ();
587         }
588
589         return *i;
590 }
591
592 void
593 Timeline::left_down (wxMouseEvent& ev)
594 {
595         shared_ptr<View> view = event_to_view (ev);
596         shared_ptr<ContentView> content_view = dynamic_pointer_cast<ContentView> (view);
597
598         _down_view.reset ();
599
600         if (content_view) {
601                 _down_view = content_view;
602                 _down_view_position = content_view->content()->position ();
603         }
604
605         for (ViewList::iterator i = _views.begin(); i != _views.end(); ++i) {
606                 shared_ptr<ContentView> cv = dynamic_pointer_cast<ContentView> (*i);
607                 if (!cv) {
608                         continue;
609                 }
610                 
611                 if (!ev.ShiftDown ()) {
612                         cv->set_selected (view == *i);
613                 }
614                 
615                 if (view == *i) {
616                         _content_panel->set_selection (cv->content ());
617                 }
618         }
619
620         if (content_view && ev.ShiftDown ()) {
621                 content_view->set_selected (!content_view->selected ());
622         }
623
624         _left_down = true;
625         _down_point = ev.GetPosition ();
626         _first_move = false;
627
628         if (_down_view) {
629                 _down_view->content()->set_change_signals_frequent (true);
630         }
631 }
632
633 void
634 Timeline::left_up (wxMouseEvent& ev)
635 {
636         _left_down = false;
637
638         if (_down_view) {
639                 _down_view->content()->set_change_signals_frequent (false);
640         }
641
642         set_position_from_event (ev);
643 }
644
645 void
646 Timeline::mouse_moved (wxMouseEvent& ev)
647 {
648         if (!_left_down) {
649                 return;
650         }
651
652         set_position_from_event (ev);
653 }
654
655 void
656 Timeline::right_down (wxMouseEvent& ev)
657 {
658         shared_ptr<View> view = event_to_view (ev);
659         shared_ptr<ContentView> cv = dynamic_pointer_cast<ContentView> (view);
660         if (!cv) {
661                 return;
662         }
663
664         if (!cv->selected ()) {
665                 clear_selection ();
666                 cv->set_selected (true);
667         }
668
669         _menu.popup (_film, selected_content (), ev.GetPosition ());
670 }
671
672 void
673 Timeline::set_position_from_event (wxMouseEvent& ev)
674 {
675         if (!_pixels_per_second) {
676                 return;
677         }
678
679         double const pps = _pixels_per_second.get ();
680
681         wxPoint const p = ev.GetPosition();
682
683         if (!_first_move) {
684                 /* We haven't moved yet; in that case, we must move the mouse some reasonable distance
685                    before the drag is considered to have started.
686                 */
687                 int const dist = sqrt (pow (p.x - _down_point.x, 2) + pow (p.y - _down_point.y, 2));
688                 if (dist < 8) {
689                         return;
690                 }
691                 _first_move = true;
692         }
693
694         if (!_down_view) {
695                 return;
696         }
697         
698         DCPTime new_position = _down_view_position + DCPTime::from_seconds ((p.x - _down_point.x) / pps);
699         
700         if (_snap) {
701                 
702                 bool first = true;
703                 DCPTime nearest_distance = DCPTime::max ();
704                 DCPTime nearest_new_position = DCPTime::max ();
705                 
706                 /* Find the nearest content edge; this is inefficient */
707                 for (ViewList::iterator i = _views.begin(); i != _views.end(); ++i) {
708                         shared_ptr<ContentView> cv = dynamic_pointer_cast<ContentView> (*i);
709                         if (!cv || cv == _down_view) {
710                                 continue;
711                         }
712                         
713                         {
714                                 /* Snap starts to ends */
715                                 DCPTime const d = DCPTime (cv->content()->end() - new_position).abs ();
716                                 if (first || d < nearest_distance) {
717                                         nearest_distance = d;
718                                         nearest_new_position = cv->content()->end();
719                                 }
720                         }
721                         
722                         {
723                                 /* Snap ends to starts */
724                                 DCPTime const d = DCPTime (
725                                         cv->content()->position() - (new_position + _down_view->content()->length_after_trim())
726                                         ).abs ();
727                                 
728                                 if (d < nearest_distance) {
729                                         nearest_distance = d;
730                                         nearest_new_position = cv->content()->position() - _down_view->content()->length_after_trim ();
731                                 }
732                         }
733                         
734                         first = false;
735                 }
736                 
737                 if (!first) {
738                         /* Snap if it's close; `close' means within a proportion of the time on the timeline */
739                         if (nearest_distance < DCPTime::from_seconds ((width() / pps) / 32)) {
740                                 new_position = nearest_new_position;
741                         }
742                 }
743         }
744         
745         if (new_position < DCPTime ()) {
746                 new_position = DCPTime ();
747         }
748
749         _down_view->content()->set_position (new_position);
750         
751         shared_ptr<Film> film = _film.lock ();
752         assert (film);
753         film->set_sequence_video (false);
754 }
755
756 void
757 Timeline::force_redraw (dcpomatic::Rect<int> const & r)
758 {
759         RefreshRect (wxRect (r.x, r.y, r.width, r.height), false);
760 }
761
762 shared_ptr<const Film>
763 Timeline::film () const
764 {
765         return _film.lock ();
766 }
767
768 void
769 Timeline::resized ()
770 {
771         setup_pixels_per_second ();
772 }
773
774 void
775 Timeline::clear_selection ()
776 {
777         for (ViewList::iterator i = _views.begin(); i != _views.end(); ++i) {
778                 shared_ptr<ContentView> cv = dynamic_pointer_cast<ContentView> (*i);
779                 if (cv) {
780                         cv->set_selected (false);
781                 }
782         }
783 }
784
785 Timeline::ContentViewList
786 Timeline::selected_views () const
787 {
788         ContentViewList sel;
789         
790         for (ViewList::const_iterator i = _views.begin(); i != _views.end(); ++i) {
791                 shared_ptr<ContentView> cv = dynamic_pointer_cast<ContentView> (*i);
792                 if (cv && cv->selected()) {
793                         sel.push_back (cv);
794                 }
795         }
796
797         return sel;
798 }
799
800 ContentList
801 Timeline::selected_content () const
802 {
803         ContentList sel;
804         ContentViewList views = selected_views ();
805         
806         for (ContentViewList::const_iterator i = views.begin(); i != views.end(); ++i) {
807                 sel.push_back ((*i)->content ());
808         }
809
810         return sel;
811 }