Fix some coverity-reported stuff.
[dcpomatic.git] / src / wx / timeline.cc
index 1f0aee4e8528be86bf5020a760532ed98be85882..4e306c4998a526081e4629f79c03ba5d4fcaa63d 100644 (file)
@@ -75,6 +75,8 @@ private:
        dcpomatic::Rect<int> _last_paint_bbox;
 };
 
+
+/** Parent class for views of pieces of content */
 class ContentView : public View
 {
 public:
@@ -160,7 +162,7 @@ private:
                gc->StrokePath (path);
                gc->FillPath (path);
 
-               wxString name = wxString::Format (wxT ("%s [%s]"), std_to_wx (cont->path().filename().string()).data(), type().data());
+               wxString name = wxString::Format (wxT ("%s [%s]"), std_to_wx (cont->path_summary()).data(), type().data());
                wxDouble name_width;
                wxDouble name_height;
                wxDouble name_descent;
@@ -323,6 +325,7 @@ private:
        int _y;
 };
 
+
 Timeline::Timeline (wxWindow* parent, FilmEditor* ed, shared_ptr<Film> film)
        : wxPanel (parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxFULL_REPAINT_ON_RESIZE)
        , _film_editor (ed)
@@ -333,7 +336,7 @@ Timeline::Timeline (wxWindow* parent, FilmEditor* ed, shared_ptr<Film> film)
        , _left_down (false)
        , _down_view_position (0)
        , _first_move (false)
-       , _menu (film, this)
+       , _menu (this)
        , _snap (true)
 {
 #ifndef __WXOSX__
@@ -471,7 +474,7 @@ void
 Timeline::setup_pixels_per_time_unit ()
 {
        shared_ptr<const Film> film = _film.lock ();
-       if (!film) {
+       if (!film || film->length() == 0) {
                return;
        }
 
@@ -571,7 +574,7 @@ Timeline::right_down (wxMouseEvent& ev)
                cv->set_selected (true);
        }
 
-       _menu.popup (selected_content (), ev.GetPosition ());
+       _menu.popup (_film, selected_content (), ev.GetPosition ());
 }
 
 void
@@ -590,61 +593,63 @@ Timeline::set_position_from_event (wxMouseEvent& ev)
                _first_move = true;
        }
 
-       if (_down_view) {
-               Time new_position = _down_view_position + (p.x - _down_point.x) / _pixels_per_time_unit;
+       if (!_down_view) {
+               return;
+       }
+       
+       Time new_position = _down_view_position + (p.x - _down_point.x) / _pixels_per_time_unit;
+       
+       if (_snap) {
                
-               if (_snap) {
-
-                       bool first = true;
-                       Time nearest_distance = TIME_MAX;
-                       Time nearest_new_position = TIME_MAX;
+               bool first = true;
+               Time nearest_distance = TIME_MAX;
+               Time nearest_new_position = TIME_MAX;
+               
+               /* Find the nearest content edge; this is inefficient */
+               for (ViewList::iterator i = _views.begin(); i != _views.end(); ++i) {
+                       shared_ptr<ContentView> cv = dynamic_pointer_cast<ContentView> (*i);
+                       if (!cv || cv == _down_view) {
+                               continue;
+                       }
                        
-                       /* Find the nearest content edge; this is inefficient */
-                       for (ViewList::iterator i = _views.begin(); i != _views.end(); ++i) {
-                               shared_ptr<ContentView> cv = dynamic_pointer_cast<ContentView> (*i);
-                               if (!cv || cv == _down_view) {
-                                       continue;
-                               }
-
-                               {
-                                       /* Snap starts to ends */
-                                       Time const d = abs (cv->content()->end() - new_position);
-                                       if (first || d < nearest_distance) {
-                                               nearest_distance = d;
-                                               nearest_new_position = cv->content()->end();
-                                       }
-                               }
-
-                               {
-                                       /* Snap ends to starts */
-                                       Time const d = abs (cv->content()->position() - (new_position + _down_view->content()->length_after_trim()));
-                                       if (d < nearest_distance) {
-                                               nearest_distance = d;
-                                               nearest_new_position = cv->content()->position() - _down_view->content()->length_after_trim ();
-                                       }
+                       {
+                               /* Snap starts to ends */
+                               Time const d = abs (cv->content()->end() - new_position);
+                               if (first || d < nearest_distance) {
+                                       nearest_distance = d;
+                                       nearest_new_position = cv->content()->end();
                                }
-
-                               first = false;
                        }
-
-                       if (!first) {
-                               /* Snap if it's close; `close' means within a proportion of the time on the timeline */
-                               if (nearest_distance < (width() / pixels_per_time_unit()) / 32) {
-                                       new_position = nearest_new_position;
+                       
+                       {
+                               /* Snap ends to starts */
+                               Time const d = abs (cv->content()->position() - (new_position + _down_view->content()->length_after_trim()));
+                               if (d < nearest_distance) {
+                                       nearest_distance = d;
+                                       nearest_new_position = cv->content()->position() - _down_view->content()->length_after_trim ();
                                }
                        }
+                       
+                       first = false;
                }
                
-               if (new_position < 0) {
-                       new_position = 0;
+               if (!first) {
+                       /* Snap if it's close; `close' means within a proportion of the time on the timeline */
+                       if (nearest_distance < (width() / pixels_per_time_unit()) / 32) {
+                               new_position = nearest_new_position;
+                       }
                }
+       }
        
-               _down_view->content()->set_position (new_position);
-
-               shared_ptr<Film> film = _film.lock ();
-               assert (film);
-               film->set_sequence_video (false);
+       if (new_position < 0) {
+               new_position = 0;
        }
+       
+       _down_view->content()->set_position (new_position);
+       
+       shared_ptr<Film> film = _film.lock ();
+       assert (film);
+       film->set_sequence_video (false);
 }
 
 void