Fix some spelling mistakes (mostly in comments).
[dcpomatic.git] / src / wx / content_panel.cc
index db29ed74a1fee6d2bcaf37c9de725b19fc1de5c0..f51d5ed48da7cd955b9afe8470305be26ab7d7b8 100644 (file)
@@ -36,6 +36,8 @@
 #include "lib/content_factory.h"
 #include "lib/cross.h"
 #include "lib/dcp_content.h"
+#include "lib/dcp_subtitle_content.h"
+#include "lib/dcp_subtitle_decoder.h"
 #include "lib/dcpomatic_log.h"
 #include "lib/ffmpeg_content.h"
 #include "lib/image_content.h"
 #include "lib/string_text_file_content.h"
 #include "lib/text_content.h"
 #include "lib/video_content.h"
+#include <dcp/warnings.h>
+LIBDCP_DISABLE_WARNINGS
 #include <wx/display.h>
 #include <wx/listctrl.h>
 #include <wx/notebook.h>
 #include <wx/wx.h>
+LIBDCP_ENABLE_WARNINGS
 #include <boost/filesystem.hpp>
 
 
@@ -82,7 +87,7 @@ ContentPanel::ContentPanel (wxNotebook* n, shared_ptr<Film> film, weak_ptr<FilmV
        _splitter = new LimitedSplitter (n);
        _top_panel = new wxPanel (_splitter);
 
-       _menu = new ContentMenu (_splitter);
+       _menu = new ContentMenu (_splitter, _film_viewer);
 
        {
                auto s = new wxBoxSizer (wxHORIZONTAL);
@@ -297,20 +302,27 @@ ContentPanel::check_selection ()
        }
 
        optional<DCPTime> go_to;
-       for (auto i: selected()) {
-               DCPTime p;
-               p = i->position();
-               if (dynamic_pointer_cast<StringTextFileContent>(i) && i->paths_valid()) {
-                       /* Rather special case; if we select a text subtitle file jump to its
-                          first subtitle.
-                       */
-                       StringTextFile ts (dynamic_pointer_cast<StringTextFileContent>(i));
-                       if (ts.first()) {
-                               p += DCPTime(ts.first().get(), _film->active_frame_rate_change(i->position()));
+       for (auto content: selected()) {
+               if (content->paths_valid()) {
+                       auto position = content->position();
+                       if (auto text_content = dynamic_pointer_cast<StringTextFileContent>(content)) {
+                               /* Rather special case; if we select a text subtitle file jump to its
+                                  first subtitle.
+                               */
+                               StringTextFile ts(text_content);
+                               if (auto first = ts.first()) {
+                                       position += DCPTime(first.get(), _film->active_frame_rate_change(content->position()));
+                               }
+                       } else if (auto dcp_content = dynamic_pointer_cast<DCPSubtitleContent>(content)) {
+                               /* Do the same for DCP subtitles */
+                               DCPSubtitleDecoder ts(_film, dcp_content);
+                               if (auto first = ts.first()) {
+                                       position += DCPTime(first.get(), _film->active_frame_rate_change(content->position()));
+                               }
+                       }
+                       if (!go_to || position < go_to.get()) {
+                               go_to = position;
                        }
-               }
-               if (!go_to || p < go_to.get()) {
-                       go_to = p;
                }
        }
 
@@ -471,7 +483,7 @@ ContentPanel::add_folder_clicked ()
                return;
        }
 
-       list<shared_ptr<Content> > content;
+       vector<shared_ptr<Content>> content;
 
        try {
                content = content_factory (path);
@@ -538,7 +550,7 @@ bool
 ContentPanel::remove_clicked (bool hotkey)
 {
        /* If the method was called because Delete was pressed check that our notebook page
-          is visible and that the content list is focussed.
+          is visible and that the content list is focused.
        */
        if (hotkey && (_parent->GetCurrentPage() != _splitter || !_content->HasFocus())) {
                return true;
@@ -665,11 +677,7 @@ ContentPanel::set_selection (weak_ptr<Content> wc)
 {
        auto content = _film->content ();
        for (size_t i = 0; i < content.size(); ++i) {
-               if (content[i] == wc.lock ()) {
-                       _content->SetItemState (i, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
-               } else {
-                       _content->SetItemState (i, 0, wxLIST_STATE_SELECTED);
-               }
+               set_selected_state(i, content[i] == wc.lock());
        }
 }
 
@@ -681,11 +689,7 @@ ContentPanel::set_selection (ContentList cl)
 
        auto content = _film->content ();
        for (size_t i = 0; i < content.size(); ++i) {
-               if (find(cl.begin(), cl.end(), content[i]) != cl.end()) {
-                       _content->SetItemState (i, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
-               } else {
-                       _content->SetItemState (i, 0, wxLIST_STATE_SELECTED);
-               }
+               set_selected_state(i, find(cl.begin(), cl.end(), content[i]) != cl.end());
        }
 
        _no_check_selection = false;
@@ -771,7 +775,7 @@ ContentPanel::setup ()
                _content->InsertItem (item);
 
                if (i.get() == selected_content) {
-                       _content->SetItemState (t, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
+                       set_selected_state(t, true);
                }
 
                if (!valid || needs_kdm || needs_assets) {
@@ -781,7 +785,7 @@ ContentPanel::setup ()
 
        if (!selected_content && !content.empty ()) {
                /* Select the item of content if none was selected before */
-               _content->SetItemState (0, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED);
+               set_selected_state(0, true);
        }
 
        setup_sensitivity ();
@@ -849,6 +853,14 @@ ContentPanel::panels () const
 }
 
 
+void
+ContentPanel::set_selected_state(int item, bool state)
+{
+       _content->SetItemState(item, state ? wxLIST_STATE_SELECTED : 0, wxLIST_STATE_SELECTED);
+       _content->SetItemState(item, state ? wxLIST_STATE_FOCUSED : 0, wxLIST_STATE_FOCUSED);
+}
+
+
 LimitedSplitter::LimitedSplitter (wxWindow* parent)
        : wxSplitterWindow (parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSP_NOBORDER | wxSP_3DSASH | wxSP_LIVE_UPDATE)
        , _first_shown (false)