Support subs and tidy up a few things.
[dcpomatic.git] / src / wx / screens_panel.h
1 /*
2     Copyright (C) 2015-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 "lib/warnings.h"
22 DCPOMATIC_DISABLE_WARNINGS
23 #include <wx/wx.h>
24 DCPOMATIC_ENABLE_WARNINGS
25 #include <wx/srchctrl.h>
26 #include <wx/treectrl.h>
27 #include <boost/signals2.hpp>
28 #include <list>
29 #include <map>
30
31 namespace dcpomatic {
32         class Screen;
33 }
34
35
36 class Cinema;
37
38
39 /** Shim around wxTreeCtrl so we can use strcoll() to compare things */
40 class TreeCtrl : public wxTreeCtrl
41 {
42 public:
43         wxDECLARE_DYNAMIC_CLASS (TreeCtrl);
44
45         TreeCtrl () {}
46
47         TreeCtrl (wxWindow* parent)
48                 : wxTreeCtrl (parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTR_HIDE_ROOT | wxTR_MULTIPLE | wxTR_HAS_BUTTONS | wxTR_LINES_AT_ROOT)
49         {}
50
51         virtual ~TreeCtrl () {}
52
53 private:
54         int OnCompareItems (wxTreeItemId const& a, wxTreeItemId const& b);
55 };
56
57
58 class ScreensPanel : public wxPanel
59 {
60 public:
61         explicit ScreensPanel (wxWindow* parent);
62         ~ScreensPanel ();
63
64         std::list<std::shared_ptr<dcpomatic::Screen>> screens () const;
65         void setup_sensitivity ();
66
67         boost::signals2::signal<void ()> ScreensChanged;
68
69 private:
70         void add_cinemas ();
71         boost::optional<wxTreeItemId> add_cinema (std::shared_ptr<Cinema>);
72         boost::optional<wxTreeItemId> add_screen (std::shared_ptr<Cinema>, std::shared_ptr<dcpomatic::Screen>);
73         void add_cinema_clicked ();
74         void edit_cinema_clicked ();
75         void remove_cinema_clicked ();
76         void add_screen_clicked ();
77         void edit_screen_clicked ();
78         void remove_screen_clicked ();
79         void selection_changed_shim (wxTreeEvent &);
80         void selection_changed ();
81         void search_changed ();
82
83         wxSearchCtrl* _search;
84         TreeCtrl* _targets;
85         wxButton* _add_cinema;
86         wxButton* _edit_cinema;
87         wxButton* _remove_cinema;
88         wxButton* _add_screen;
89         wxButton* _edit_screen;
90         wxButton* _remove_screen;
91         wxTreeItemId _root;
92
93         typedef std::map<wxTreeItemId, std::shared_ptr<Cinema>> CinemaMap;
94         typedef std::map<wxTreeItemId, std::shared_ptr<dcpomatic::Screen>> ScreenMap;
95
96         CinemaMap _cinemas;
97         ScreenMap _screens;
98         CinemaMap _selected_cinemas;
99         ScreenMap _selected_screens;
100
101         bool _ignore_selection_change;
102 };