Hacky window-on-top fix for OS X.
[dcpomatic.git] / src / wx / timeline_dialog.cc
1 /*
2     Copyright (C) 2013-2016 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
6     DCP-o-matic is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     DCP-o-matic is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
18
19 */
20
21 #include <list>
22 #include <wx/graphics.h>
23 #include "lib/playlist.h"
24 #include "film_editor.h"
25 #include "timeline_dialog.h"
26 #include "wx_util.h"
27 #include "content_panel.h"
28 #include <iostream>
29
30 using std::list;
31 using std::cout;
32 using boost::shared_ptr;
33
34 TimelineDialog::TimelineDialog (ContentPanel* cp, shared_ptr<Film> film)
35         : wxDialog (
36                 cp->panel(),
37                 wxID_ANY,
38                 _("Timeline"),
39                 wxDefaultPosition,
40                 wxSize (640, 512),
41 #ifdef DCPOMATIC_OSX
42                 /* I can't get wxFRAME_FLOAT_ON_PARENT to work on OS X, and although wxSTAY_ON_TOP keeps
43                    the window above all others (and not just our own) it's better than nothing for now.
44                 */
45                 wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxFULL_REPAINT_ON_RESIZE | wxSTAY_ON_TOP
46 #else
47                 wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxFULL_REPAINT_ON_RESIZE | wxFRAME_FLOAT_ON_PARENT
48 #endif
49                 )
50         , _film (film)
51         , _timeline (this, cp, film)
52 {
53         wxBoxSizer* sizer = new wxBoxSizer (wxVERTICAL);
54
55         wxBoxSizer* controls = new wxBoxSizer (wxHORIZONTAL);
56         _snap = new wxCheckBox (this, wxID_ANY, _("Snap"));
57         controls->Add (_snap);
58         _sequence = new wxCheckBox (this, wxID_ANY, _("Keep video and subtitles in sequence"));
59         controls->Add (_sequence, 1, wxLEFT, 12);
60
61         sizer->Add (controls, 0, wxALL, 12);
62         sizer->Add (&_timeline, 1, wxEXPAND | wxALL, 12);
63
64 #ifdef DCPOMATIC_LINUX
65         wxSizer* buttons = CreateSeparatedButtonSizer (wxCLOSE);
66         if (buttons) {
67                 sizer->Add (buttons, wxSizerFlags().Expand().DoubleBorder());
68         }
69 #endif
70
71         SetSizer (sizer);
72         sizer->Layout ();
73         sizer->SetSizeHints (this);
74
75         _snap->SetValue (_timeline.snap ());
76         _snap->Bind (wxEVT_COMMAND_CHECKBOX_CLICKED, boost::bind (&TimelineDialog::snap_toggled, this));
77         film_changed (Film::SEQUENCE);
78         _sequence->Bind (wxEVT_COMMAND_CHECKBOX_CLICKED, boost::bind (&TimelineDialog::sequence_toggled, this));
79
80         _film_changed_connection = film->Changed.connect (bind (&TimelineDialog::film_changed, this, _1));
81 }
82
83 void
84 TimelineDialog::snap_toggled ()
85 {
86         _timeline.set_snap (_snap->GetValue ());
87 }
88
89 void
90 TimelineDialog::sequence_toggled ()
91 {
92         shared_ptr<Film> film = _film.lock ();
93         if (!film) {
94                 return;
95         }
96
97         film->set_sequence (_sequence->GetValue ());
98 }
99
100 void
101 TimelineDialog::film_changed (Film::Property p)
102 {
103         shared_ptr<Film> film = _film.lock ();
104         if (!film) {
105                 return;
106         }
107
108         if (p == Film::SEQUENCE) {
109                 _sequence->SetValue (film->sequence ());
110         }
111 }
112
113 void
114 TimelineDialog::set_selection (ContentList selection)
115 {
116         _timeline.set_selection (selection);
117 }