Use a vector<pair<...>> to store screens and cinemas instead of a map.
[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
40
41 class ScreensPanel : public wxPanel
42 {
43 public:
44         explicit ScreensPanel (wxWindow* parent);
45         ~ScreensPanel ();
46
47         std::vector<std::shared_ptr<dcpomatic::Screen>> screens () const;
48         void setup_sensitivity ();
49
50         boost::signals2::signal<void ()> ScreensChanged;
51
52 private:
53         void add_cinemas ();
54         boost::optional<wxTreeListItem> add_cinema (std::shared_ptr<Cinema>);
55         boost::optional<wxTreeListItem> add_screen (std::shared_ptr<Cinema>, std::shared_ptr<dcpomatic::Screen>);
56         void add_cinema_clicked ();
57         void edit_cinema_clicked ();
58         void remove_cinema_clicked ();
59         void add_screen_clicked ();
60         void edit_screen_clicked ();
61         void remove_screen_clicked ();
62         void selection_changed_shim (wxTreeListEvent &);
63         void selection_changed ();
64         void search_changed ();
65         void checkbox_changed (wxTreeListEvent& ev);
66         boost::optional<std::pair<wxTreeListItem, std::shared_ptr<Cinema>>> cinema_for_operation () const;
67
68         typedef std::vector<std::pair<wxTreeListItem, std::shared_ptr<Cinema>>> Cinemas;
69         typedef std::vector<std::pair<wxTreeListItem, std::shared_ptr<dcpomatic::Screen>>> Screens;
70
71         Cinemas::iterator cinema_by_tree_list_item (wxTreeListItem item);
72         Screens::const_iterator screen_by_tree_list_item (wxTreeListItem item) const;
73
74         wxSearchCtrl* _search;
75         wxTreeListCtrl* _targets;
76         wxButton* _add_cinema;
77         wxButton* _edit_cinema;
78         wxButton* _remove_cinema;
79         wxButton* _add_screen;
80         wxButton* _edit_screen;
81         wxButton* _remove_screen;
82
83         Cinemas _cinemas;
84         Screens _screens;
85         Cinemas _selected_cinemas;
86         Screens _selected_screens;
87
88         bool _ignore_selection_change;
89
90         class Comparator : public wxTreeListItemComparator
91         {
92         public:
93                 int Compare (wxTreeListCtrl* tree_list, unsigned, wxTreeListItem a, wxTreeListItem b) override
94                 {
95                         return strcoll(wx_to_std(tree_list->GetItemText(a)).c_str(), wx_to_std(tree_list->GetItemText(b)).c_str());
96                 }
97         };
98
99         Comparator _comparator;
100 };