Supporters update.
[dcpomatic.git] / src / wx / dcpomatic_choice.cc
1 /*
2     Copyright (C) 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 "dcpomatic_choice.h"
23 #include "wx_util.h"
24
25
26 using std::string;
27 using boost::optional;
28
29
30 Choice::Choice(wxWindow* parent)
31         : wxChoice(parent, wxID_ANY)
32 {
33         /* This hack works around a problem where the height of the wxChoice would be
34          * too small on KDE.  This added empty string will be removed in the first
35          * call to add().
36          */
37         Append("");
38         set(0);
39 }
40
41
42 void
43 Choice::add(string const& entry)
44 {
45         add(std_to_wx(entry));
46 }
47
48
49 void
50 Choice::add(wxString const& entry)
51 {
52         if (_needs_clearing) {
53                 Clear();
54                 _needs_clearing = false;
55         }
56
57         Append(entry);
58 }
59
60
61 void
62 Choice::add(wxString const& entry, wxClientData* data)
63 {
64         if (_needs_clearing) {
65                 Clear();
66                 _needs_clearing = false;
67         }
68
69         Append(entry, data);
70 }
71
72
73 void
74 Choice::set(int index)
75 {
76         SetSelection(index);
77 }
78
79
80 optional<int>
81 Choice::get() const
82 {
83         auto const sel = GetSelection();
84         if (sel == wxNOT_FOUND) {
85                 return {};
86         }
87
88         return sel;
89 }
90