+
+
+void
+ScreensPanel::checkbox_changed (wxTreeListEvent& ev)
+{
+ if (item_to_cinema(ev.GetItem())) {
+ /* Cinema: check/uncheck all children */
+ auto const checked = _targets->GetCheckedState(ev.GetItem());
+ for (auto child = _targets->GetFirstChild(ev.GetItem()); child.IsOk(); child = _targets->GetNextSibling(child)) {
+ _targets->CheckItem(child, checked);
+ }
+ } else {
+ /* Screen: set cinema to checked/unchecked/3state */
+ auto parent = _targets->GetItemParent(ev.GetItem());
+ DCPOMATIC_ASSERT (parent.IsOk());
+ int checked = 0;
+ int unchecked = 0;
+ for (auto child = _targets->GetFirstChild(parent); child.IsOk(); child = _targets->GetNextSibling(child)) {
+ if (_targets->GetCheckedState(child) == wxCHK_CHECKED) {
+ ++checked;
+ } else {
+ ++unchecked;
+ }
+ }
+ if (checked == 0) {
+ _targets->CheckItem(parent, wxCHK_UNCHECKED);
+ } else if (unchecked == 0) {
+ _targets->CheckItem(parent, wxCHK_CHECKED);
+ } else {
+ _targets->CheckItem(parent, wxCHK_UNDETERMINED);
+ }
+ }
+
+ ScreensChanged ();
+}
+
+
+shared_ptr<Cinema>
+ScreensPanel::item_to_cinema (wxTreeListItem item) const
+{
+ auto iter = _item_to_cinema.find (item);
+ if (iter == _item_to_cinema.end()) {
+ return {};
+ }
+
+ return iter->second;
+}
+
+
+shared_ptr<Screen>
+ScreensPanel::item_to_screen (wxTreeListItem item) const
+{
+ auto iter = _item_to_screen.find (item);
+ if (iter == _item_to_screen.end()) {
+ return {};
+ }
+
+ return iter->second;
+}
+
+
+ScreensPanel::Comparator::Comparator ()
+{
+ UErrorCode status = U_ZERO_ERROR;
+ _collator = ucol_open(nullptr, &status);
+ if (_collator) {
+ ucol_setAttribute(_collator, UCOL_NORMALIZATION_MODE, UCOL_ON, &status);
+ ucol_setAttribute(_collator, UCOL_STRENGTH, UCOL_PRIMARY, &status);
+ ucol_setAttribute(_collator, UCOL_ALTERNATE_HANDLING, UCOL_SHIFTED, &status);
+ }
+}
+
+ScreensPanel::Comparator::~Comparator ()
+{
+ if (_collator) {
+ ucol_close (_collator);
+ }
+}
+
+int
+ScreensPanel::Comparator::Compare (wxTreeListCtrl* tree_list, unsigned, wxTreeListItem a, wxTreeListItem b)
+{
+ auto utf8_a = wx_to_std(tree_list->GetItemText(a));
+ auto utf8_b = wx_to_std(tree_list->GetItemText(b));
+ if (_collator) {
+ UErrorCode error = U_ZERO_ERROR;
+ boost::scoped_array<uint16_t> utf16_a(new uint16_t[utf8_a.size() + 1]);
+ u_strFromUTF8(reinterpret_cast<UChar*>(utf16_a.get()), utf8_a.size() + 1, nullptr, utf8_a.c_str(), -1, &error);
+ boost::scoped_array<uint16_t> utf16_b(new uint16_t[utf8_b.size() + 1]);
+ u_strFromUTF8(reinterpret_cast<UChar*>(utf16_b.get()), utf8_b.size() + 1, nullptr, utf8_b.c_str(), -1, &error);
+ return ucol_strcoll(_collator, reinterpret_cast<UChar*>(utf16_a.get()), -1, reinterpret_cast<UChar*>(utf16_b.get()), -1);
+ } else {
+ return strcoll(utf8_a.c_str(), utf8_b.c_str());
+ }
+}