Also keep maps the other way around.
[dcpomatic.git] / src / wx / screens_panel.h
1 /*
2     Copyright (C) 2015-2022 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
22 #include "lib/warnings.h"
23 DCPOMATIC_DISABLE_WARNINGS
24 #include <wx/wx.h>
25 DCPOMATIC_ENABLE_WARNINGS
26 #include <wx/srchctrl.h>
27 #include <wx/treelist.h>
28 #include <boost/signals2.hpp>
29 #include <list>
30 #include <map>
31
32
33 namespace dcpomatic {
34         class Screen;
35 }
36
37
38 class Cinema;
39 class UCollator;
40
41
42 class ScreensPanel : public wxPanel
43 {
44 public:
45         explicit ScreensPanel (wxWindow* parent);
46         ~ScreensPanel ();
47
48         std::vector<std::shared_ptr<dcpomatic::Screen>> screens () const;
49         void setup_sensitivity ();
50
51         boost::signals2::signal<void ()> ScreensChanged;
52
53 private:
54         void add_cinemas ();
55         boost::optional<wxTreeListItem> add_cinema (std::shared_ptr<Cinema>);
56         boost::optional<wxTreeListItem> add_screen (std::shared_ptr<Cinema>, std::shared_ptr<dcpomatic::Screen>);
57         void add_cinema_clicked ();
58         void edit_cinema_clicked ();
59         void remove_cinema_clicked ();
60         void add_screen_clicked ();
61         void edit_screen_clicked ();
62         void remove_screen_clicked ();
63         void selection_changed_shim (wxTreeListEvent &);
64         void selection_changed ();
65         void search_changed ();
66         void checkbox_changed (wxTreeListEvent& ev);
67         boost::optional<std::pair<wxTreeListItem, std::shared_ptr<Cinema>>> cinema_for_operation () const;
68
69         typedef std::vector<std::pair<wxTreeListItem, std::shared_ptr<Cinema>>> Cinemas;
70         typedef std::vector<std::pair<wxTreeListItem, std::shared_ptr<dcpomatic::Screen>>> Screens;
71
72         std::shared_ptr<Cinema> item_to_cinema (wxTreeListItem item) const;
73         std::shared_ptr<dcpomatic::Screen> item_to_screen (wxTreeListItem item) const;
74         boost::optional<wxTreeListItem> cinema_to_item (std::shared_ptr<Cinema> cinema) const;
75         boost::optional<wxTreeListItem> screen_to_item (std::shared_ptr<dcpomatic::Screen> screen) const;
76
77         wxSearchCtrl* _search;
78         wxTreeListCtrl* _targets;
79         wxButton* _add_cinema;
80         wxButton* _edit_cinema;
81         wxButton* _remove_cinema;
82         wxButton* _add_screen;
83         wxButton* _edit_screen;
84         wxButton* _remove_screen;
85
86         Cinemas _cinemas;
87         Screens _screens;
88         Cinemas _selected_cinemas;
89         Screens _selected_screens;
90
91         std::map<wxTreeListItem, std::shared_ptr<Cinema>> _item_to_cinema;
92         std::map<wxTreeListItem, std::shared_ptr<dcpomatic::Screen>> _item_to_screen;
93         std::map<std::shared_ptr<Cinema>, wxTreeListItem> _cinema_to_item;
94         std::map<std::shared_ptr<dcpomatic::Screen>, wxTreeListItem> _screen_to_item;
95
96         bool _ignore_selection_change;
97
98         class Comparator : public wxTreeListItemComparator
99         {
100         public:
101                 Comparator ();
102                 ~Comparator ();
103
104                 int Compare (wxTreeListCtrl* tree_list, unsigned, wxTreeListItem a, wxTreeListItem b) override;
105
106         private:
107                 UCollator* _collator;
108         };
109
110         Comparator _comparator;
111 };