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