49a3ca5c3364b04323762afe4eb6a5e8037bf2ea
[dcpomatic.git] / src / wx / wx_util.cc
1 /*
2     Copyright (C) 2012-2021 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 /** @file src/wx/wx_util.cc
23  *  @brief Some utility functions and classes.
24  */
25
26
27 #include "file_picker_ctrl.h"
28 #include "language_tag_widget.h"
29 #include "password_entry.h"
30 #include "region_subtag_widget.h"
31 #include "static_text.h"
32 #include "wx_ptr.h"
33 #include "wx_util.h"
34 #include "wx_variant.h"
35 #include "lib/config.h"
36 #include "lib/cross.h"
37 #include "lib/job.h"
38 #include "lib/job_manager.h"
39 #include "lib/util.h"
40 #include "lib/version.h"
41 #include <dcp/locale_convert.h>
42 #include <dcp/warnings.h>
43 LIBDCP_DISABLE_WARNINGS
44 #include <wx/filepicker.h>
45 #include <wx/progdlg.h>
46 #include <wx/sizer.h>
47 #include <wx/spinctrl.h>
48 #include <wx/splash.h>
49 LIBDCP_ENABLE_WARNINGS
50 #include <boost/thread.hpp>
51
52
53 using std::string;
54 using std::vector;
55 using std::pair;
56 using std::shared_ptr;
57 using boost::optional;
58 using dcp::locale_convert;
59 using namespace dcpomatic;
60
61
62 wxStaticText *
63 #ifdef __WXOSX__
64 create_label (wxWindow* p, wxString t, bool left)
65 #else
66 create_label (wxWindow* p, wxString t, bool)
67 #endif
68 {
69 #ifdef __WXOSX__
70         if (left) {
71                 t += wxT (":");
72         }
73 #endif
74         return new StaticText (p, t);
75 }
76
77
78 #ifdef __WXOSX__
79 static
80 void
81 setup_osx_flags (wxSizer* s, bool left, int& flags)
82 {
83         if (left) {
84                 auto box = dynamic_cast<wxBoxSizer*>(s);
85                 if (!box || box->GetOrientation() != wxHORIZONTAL) {
86                         flags |= wxALIGN_RIGHT;
87                 }
88         }
89 }
90 #endif
91
92
93 /** Add a wxStaticText to a wxSizer.
94  *  @param s Sizer to add to.
95  *  @param p Parent window for the wxStaticText.
96  *  @param t Text for the wxStaticText.
97  *  @param left true if this label is a `left label'; ie the sort
98  *  of label which should be right-aligned on OS X.
99  *  @param prop Proportion to pass when calling Add() on the wxSizer.
100  */
101 wxStaticText *
102 add_label_to_sizer (wxSizer* s, wxWindow* p, wxString t, bool left, int prop, int flags)
103 {
104 #ifdef __WXOSX__
105         setup_osx_flags (s, left, flags);
106 #endif
107         auto m = create_label (p, t, left);
108         s->Add (m, prop, flags, DCPOMATIC_SIZER_GAP);
109         return m;
110 }
111
112
113 wxStaticText *
114 #ifdef __WXOSX__
115 add_label_to_sizer (wxSizer* s, wxStaticText* t, bool left, int prop, int flags)
116 #else
117 add_label_to_sizer (wxSizer* s, wxStaticText* t, bool, int prop, int flags)
118 #endif
119 {
120 #ifdef __WXOSX__
121         setup_osx_flags (s, left, flags);
122 #endif
123         s->Add (t, prop, flags, DCPOMATIC_SIZER_GAP);
124         return t;
125 }
126
127
128 wxStaticText *
129 add_label_to_sizer(wxGridBagSizer* s, wxWindow* p, wxString t, bool left, wxGBPosition pos, wxGBSpan span, bool indent)
130 {
131         int flags = wxALIGN_CENTER_VERTICAL | wxLEFT;
132 #ifdef __WXOSX__
133         setup_osx_flags (s, left, flags);
134 #endif
135         auto m = create_label (p, t, left);
136         s->Add(m, pos, span, flags, indent ? DCPOMATIC_SIZER_X_GAP : 0);
137         return m;
138 }
139
140
141 wxStaticText *
142 #ifdef __WXOSX__
143 add_label_to_sizer (wxGridBagSizer* s, wxStaticText* t, bool left, wxGBPosition pos, wxGBSpan span)
144 #else
145 add_label_to_sizer (wxGridBagSizer* s, wxStaticText* t, bool, wxGBPosition pos, wxGBSpan span)
146 #endif
147 {
148         int flags = wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT;
149 #ifdef __WXOSX__
150         setup_osx_flags (s, left, flags);
151 #endif
152         s->Add (t, pos, span, flags);
153         return t;
154 }
155
156
157 /** Pop up an error dialogue box.
158  *  @param parent Parent.
159  *  @param m Message.
160  *  @param e Extended message.
161  */
162 void
163 error_dialog (wxWindow* parent, wxString m, optional<wxString> e)
164 {
165         auto d = make_wx<wxMessageDialog>(parent, m, variant::wx::dcpomatic(), wxOK | wxICON_ERROR);
166         if (e) {
167                 wxString em = *e;
168                 em[0] = wxToupper (em[0]);
169                 d->SetExtendedMessage (em);
170         }
171         d->ShowModal ();
172 }
173
174
175 /** Pop up an error dialogue box.
176  *  @param parent Parent.
177  *  @param m Message.
178  */
179 void
180 message_dialog (wxWindow* parent, wxString m)
181 {
182         auto d = make_wx<wxMessageDialog>(parent, m, variant::wx::dcpomatic(), wxOK | wxICON_INFORMATION);
183         d->ShowModal ();
184 }
185
186
187 /** @return true if the user answered "yes" */
188 bool
189 confirm_dialog (wxWindow* parent, wxString m)
190 {
191         auto d = make_wx<wxMessageDialog>(parent, m, variant::wx::dcpomatic(), wxYES_NO | wxICON_QUESTION);
192         return d->ShowModal() == wxID_YES;
193 }
194
195
196 /** @param s wxWidgets string.
197  *  @return Corresponding STL string.
198  */
199 string
200 wx_to_std (wxString s)
201 {
202         return string (s.ToUTF8());
203 }
204
205
206 /** @param s STL string.
207  *  @return Corresponding wxWidgets string.
208  */
209 wxString
210 std_to_wx (string s)
211 {
212         return wxString (s.c_str(), wxConvUTF8);
213 }
214
215
216 string
217 string_client_data (wxClientData* o)
218 {
219         return wx_to_std (dynamic_cast<wxStringClientData*>(o)->GetData());
220 }
221
222
223 void
224 checked_set (FilePickerCtrl* widget, boost::filesystem::path value)
225 {
226         if (widget->path() != value) {
227                 if (value.empty()) {
228                         /* Hack to make wxWidgets clear the control when we are passed
229                            an empty value.
230                         */
231                         value = " ";
232                 }
233                 widget->set_path(value);
234         }
235 }
236
237
238 void
239 checked_set (wxDirPickerCtrl* widget, boost::filesystem::path value)
240 {
241         if (widget->GetPath() != std_to_wx (value.string())) {
242                 if (value.empty()) {
243                         /* Hack to make wxWidgets clear the control when we are passed
244                            an empty value.
245                         */
246                         value = " ";
247                 }
248                 widget->SetPath (std_to_wx (value.string()));
249         }
250 }
251
252
253 void
254 checked_set (wxSpinCtrl* widget, int value)
255 {
256         if (widget->GetValue() != value) {
257                 widget->SetValue (value);
258         }
259 }
260
261
262 void
263 checked_set (wxSpinCtrlDouble* widget, double value)
264 {
265         /* XXX: completely arbitrary epsilon */
266         if (fabs (widget->GetValue() - value) > 1e-16) {
267                 widget->SetValue (value);
268         }
269 }
270
271
272 void
273 checked_set (wxChoice* widget, int value)
274 {
275         if (widget->GetSelection() != value) {
276                 widget->SetSelection (value);
277         }
278 }
279
280
281 void
282 checked_set (wxChoice* widget, string value)
283 {
284         wxClientData* o = nullptr;
285         if (widget->GetSelection() != -1) {
286                 o = widget->GetClientObject (widget->GetSelection ());
287         }
288
289         if (!o || string_client_data(o) != value) {
290                 for (unsigned int i = 0; i < widget->GetCount(); ++i) {
291                         if (string_client_data (widget->GetClientObject (i)) == value) {
292                                 widget->SetSelection (i);
293                         }
294                 }
295         }
296 }
297
298
299 void
300 checked_set (wxChoice* widget, vector<pair<string, string>> items)
301 {
302        vector<pair<string, string>> current;
303        for (unsigned int i = 0; i < widget->GetCount(); ++i) {
304                current.push_back (
305                        make_pair(
306                                wx_to_std(widget->GetString(i)),
307                                widget->GetClientData() ? string_client_data(widget->GetClientObject(i)) : ""
308                                )
309                        );
310        }
311
312        if (current == items) {
313                return;
314        }
315
316        widget->Clear ();
317        for (auto i: items) {
318                widget->Append (std_to_wx(i.first), new wxStringClientData(std_to_wx(i.second)));
319        }
320 }
321
322
323 void
324 checked_set (wxTextCtrl* widget, string value)
325 {
326         if (widget->GetValue() != std_to_wx (value)) {
327                 widget->ChangeValue (std_to_wx (value));
328         }
329 }
330
331
332 void
333 checked_set (PasswordEntry* entry, string value)
334 {
335         if (entry->get() != value) {
336                 entry->set(value);
337         }
338 }
339
340
341 void
342 checked_set (wxTextCtrl* widget, wxString value)
343 {
344         if (widget->GetValue() != value) {
345                 widget->ChangeValue (value);
346         }
347 }
348
349
350 void
351 checked_set (wxStaticText* widget, string value)
352 {
353         if (widget->GetLabel() != std_to_wx (value)) {
354                 widget->SetLabel (std_to_wx (value));
355         }
356 }
357
358
359 void
360 checked_set (wxStaticText* widget, wxString value)
361 {
362         if (widget->GetLabel() != value) {
363                 widget->SetLabel (value);
364         }
365 }
366
367
368 void
369 checked_set (wxCheckBox* widget, bool value)
370 {
371         if (widget->GetValue() != value) {
372                 widget->SetValue (value);
373         }
374 }
375
376
377 void
378 checked_set (wxRadioButton* widget, bool value)
379 {
380         if (widget->GetValue() != value) {
381                 widget->SetValue (value);
382         }
383 }
384
385
386 void
387 checked_set(LanguageTagWidget* widget, dcp::LanguageTag value)
388 {
389         if (widget->get() != value) {
390                 widget->set(value);
391         }
392 }
393
394
395 void
396 checked_set(LanguageTagWidget* widget, optional<dcp::LanguageTag> value)
397 {
398         if (widget->get() != value) {
399                 widget->set(value);
400         }
401 }
402
403
404 void
405 checked_set(RegionSubtagWidget* widget, optional<dcp::LanguageTag::RegionSubtag> value)
406 {
407         if (widget->get() != value) {
408                 widget->set(value);
409         }
410 }
411
412
413 #ifdef DCPOMATIC_OSX
414
415 void
416 dcpomatic_setup_i18n()
417 {
418         wxLog::EnableLogging();
419
420         auto get_locale_value = [](CFLocaleKey key) {
421                 CFLocaleRef cflocale = CFLocaleCopyCurrent();
422                 auto value = (CFStringRef) CFLocaleGetValue(cflocale, key);
423                 char buffer[64];
424                 CFStringGetCString(value, buffer, sizeof(buffer), kCFStringEncodingUTF8);
425                 CFRelease(cflocale);
426                 return string(buffer);
427         };
428
429         auto translations = new wxTranslations();
430
431         auto config_lang = Config::instance()->language();
432         if (config_lang && !config_lang->empty()) {
433                 translations->SetLanguage(std_to_wx(*config_lang));
434         } else {
435                 /* We want to use the user's preferred language.  It seems that if we use the wxWidgets default we will get the
436                  * language for the locale, which may not be what we want (e.g. for a machine in Germany, configured for DE locale,
437                  * but with the preferred language set to English).
438                  *
439                  * Instead, the the language code from macOS then get the corresponding canonical language string with region,
440                  * which wxTranslations::SetLanguage will accept.
441                  */
442                 auto const language_code = get_locale_value(kCFLocaleLanguageCode);
443                 /* Ideally this would be wxUILocale (as wxLocale is deprecated) but we want to keep this building
444                  * with the old wxWidgets we use for the older macOS builds.
445                  */
446                 auto const info = wxLocale::FindLanguageInfo(std_to_wx(language_code));
447                 if (info) {
448 #if wxCHECK_VERSION(3, 1, 6)
449                         translations->SetLanguage(info->GetCanonicalWithRegion());
450 #else
451                         translations->SetLanguage(info->CanonicalName);
452 #endif
453                 }
454         }
455
456 #ifdef DCPOMATIC_DEBUG
457         wxFileTranslationsLoader::AddCatalogLookupPathPrefix(wxT("build/src/wx/mo"));
458         wxFileTranslationsLoader::AddCatalogLookupPathPrefix(wxT("build/src/tools/mo"));
459 #endif
460
461         translations->AddStdCatalog();
462         translations->AddCatalog(wxT("libdcpomatic2-wx"));
463         translations->AddCatalog(wxT("dcpomatic2"));
464
465         wxTranslations::Set(translations);
466
467         dcpomatic_setup_gettext_i18n(config_lang.get_value_or(""));
468 }
469
470 #else
471
472 void
473 dcpomatic_setup_i18n ()
474 {
475         int language = wxLANGUAGE_DEFAULT;
476
477         auto config_lang = Config::instance()->language ();
478         if (config_lang && !config_lang->empty ()) {
479                 auto const li = wxLocale::FindLanguageInfo (std_to_wx (config_lang.get ()));
480                 if (li) {
481                         language = li->Language;
482                 }
483         }
484
485         wxLocale* locale = nullptr;
486         if (wxLocale::IsAvailable (language)) {
487                 locale = new wxLocale (language, wxLOCALE_LOAD_DEFAULT);
488
489 #ifdef DCPOMATIC_WINDOWS
490                 locale->AddCatalogLookupPathPrefix (std_to_wx (mo_path().string()));
491 #endif
492
493 #ifdef DCPOMATIC_LINUX
494                 locale->AddCatalogLookupPathPrefix (LINUX_LOCALE_PREFIX);
495
496                 /* We have to include the wxWidgets .mo in our distribution,
497                    so we rename it to avoid clashes with any other installation
498                    of wxWidgets.
499                 */
500                 locale->AddCatalog (wxT ("dcpomatic2-wxstd"));
501
502                 /* Fedora 29 (at least) installs wxstd3.mo instead of wxstd.mo */
503                 locale->AddCatalog (wxT ("wxstd3"));
504 #endif
505
506                 locale->AddCatalog(wxT("wxstd"));
507                 locale->AddCatalog(wxT("libdcpomatic2-wx"));
508                 locale->AddCatalog(wxT("dcpomatic2"));
509
510                 if (!locale->IsOk()) {
511                         delete locale;
512                         locale = new wxLocale (wxLANGUAGE_ENGLISH);
513                 }
514         }
515
516         if (locale) {
517                 dcpomatic_setup_gettext_i18n (wx_to_std (locale->GetCanonicalName ()));
518         }
519 }
520
521 #endif
522
523
524 int
525 wx_get (wxSpinCtrl* w)
526 {
527         return w->GetValue ();
528 }
529
530
531 int
532 wx_get (wxChoice* w)
533 {
534         return w->GetSelection ();
535 }
536
537
538 double
539 wx_get (wxSpinCtrlDouble* w)
540 {
541         return w->GetValue ();
542 }
543
544
545 /** @param s String of the form Context|String
546  *  @return translation, or String if no translation is available.
547  */
548 wxString
549 context_translation (wxString s)
550 {
551         auto t = wxGetTranslation (s);
552         if (t == s) {
553                 /* No translation; strip the context */
554                 int c = t.Find (wxT ("|"));
555                 if (c != wxNOT_FOUND) {
556                         t = t.Mid (c + 1);
557                 }
558         }
559
560         return t;
561 }
562
563
564 wxString
565 time_to_timecode (DCPTime t, double fps)
566 {
567         auto w = t.seconds ();
568         int const h = (w / 3600);
569         w -= h * 3600;
570         int const m = (w / 60);
571         w -= m * 60;
572         int const s = floor (w);
573         w -= s;
574         int const f = lrint (w * fps);
575         return wxString::Format (wxT("%02d:%02d:%02d.%02d"), h, m, s, f);
576 }
577
578
579 void
580 setup_audio_channels_choice (wxChoice* choice, int minimum)
581 {
582         vector<pair<string, string>> items;
583         for (int i = minimum; i <= 16; i += 2) {
584                 if (i == 2) {
585                         items.push_back (make_pair(wx_to_std(_("2 - stereo")), locale_convert<string>(i)));
586                 } else if (i == 4) {
587                         items.push_back (make_pair(wx_to_std(_("4 - L/C/R/Lfe")), locale_convert<string>(i)));
588                 } else if (i == 6) {
589                         items.push_back (make_pair(wx_to_std(_("6 - 5.1")), locale_convert<string>(i)));
590                 } else if (i == 8) {
591                         items.push_back (make_pair(wx_to_std(_("8 - 5.1/HI/VI")), locale_convert<string>(i)));
592                 } else if (i == 12) {
593                         items.push_back (make_pair(wx_to_std(_("12 - 7.1/HI/VI")), locale_convert<string>(i)));
594                 } else {
595                         items.push_back (make_pair(locale_convert<string> (i), locale_convert<string>(i)));
596                 }
597         }
598
599         checked_set (choice, items);
600 }
601
602
603 wxSplashScreen*
604 maybe_show_splash ()
605 {
606         wxSplashScreen* splash = nullptr;
607
608         try {
609                 wxBitmap bitmap;
610                 if (bitmap.LoadFile(bitmap_path("splash.png"), wxBITMAP_TYPE_PNG)) {
611                         {
612                                 /* This wxMemoryDC must be destroyed before bitmap can be used elsewhere */
613                                 wxMemoryDC dc(bitmap);
614                                 auto const version = wxString::Format("%s (%s)", dcpomatic_version, dcpomatic_git_commit);
615                                 auto screen_size = dc.GetSize();
616                                 auto text_size = dc.GetTextExtent(version);
617                                 dc.DrawText(version, (screen_size.GetWidth() - text_size.GetWidth()) / 2, 236);
618                         }
619 #ifdef DCPOMATIC_WINDOWS
620                         /* Having wxSTAY_ON_TOP means error dialogues hide behind the splash screen on Windows, no matter what I try */
621                         splash = new wxSplashScreen(bitmap, wxSPLASH_CENTRE_ON_SCREEN | wxSPLASH_NO_TIMEOUT, 0, nullptr, -1, wxDefaultPosition, wxDefaultSize, wxBORDER_SIMPLE | wxFRAME_NO_TASKBAR);
622 #else
623                         splash = new wxSplashScreen(bitmap, wxSPLASH_CENTRE_ON_SCREEN | wxSPLASH_NO_TIMEOUT, 0, nullptr, -1);
624 #endif
625                         wxYield ();
626                 }
627         } catch (boost::filesystem::filesystem_error& e) {
628                 /* Maybe we couldn't find the splash image; never mind */
629         }
630
631         return splash;
632 }
633
634
635 double
636 calculate_mark_interval (double mark_interval)
637 {
638         if (mark_interval > 5) {
639                 mark_interval -= lrint (mark_interval) % 5;
640         }
641         if (mark_interval > 10) {
642                 mark_interval -= lrint (mark_interval) % 10;
643         }
644         if (mark_interval > 60) {
645                 mark_interval -= lrint (mark_interval) % 60;
646         }
647         if (mark_interval > 3600) {
648                 mark_interval -= lrint (mark_interval) % 3600;
649         }
650
651         if (mark_interval < 1) {
652                 mark_interval = 1;
653         }
654
655         return mark_interval;
656 }
657
658
659 /** @return false if the task was cancelled */
660 bool
661 display_progress (wxString title, wxString task)
662 {
663         auto jm = JobManager::instance ();
664
665         wxProgressDialog progress (title, task, 100, 0, wxPD_CAN_ABORT);
666
667         bool ok = true;
668
669         while (jm->work_to_do()) {
670                 dcpomatic_sleep_seconds (1);
671                 if (!progress.Pulse()) {
672                         /* user pressed cancel */
673                         for (auto i: jm->get()) {
674                                 i->cancel();
675                         }
676                         ok = false;
677                         break;
678                 }
679         }
680
681         return ok;
682 }
683
684
685 int
686 get_offsets (vector<Offset>& offsets)
687 {
688         offsets.push_back (Offset(_("UTC-11"),  -11,  0));
689         offsets.push_back (Offset(_("UTC-10"),  -10,  0));
690         offsets.push_back (Offset(_("UTC-9"),    -9,  0));
691         offsets.push_back (Offset(_("UTC-8"),    -8,  0));
692         offsets.push_back (Offset(_("UTC-7"),    -7,  0));
693         offsets.push_back (Offset(_("UTC-6"),    -6,  0));
694         offsets.push_back (Offset(_("UTC-5"),    -5,  0));
695         offsets.push_back (Offset(_("UTC-4:30"), -4, 30));
696         offsets.push_back (Offset(_("UTC-4"),    -4,  0));
697         offsets.push_back (Offset(_("UTC-3:30"), -3, 30));
698         offsets.push_back (Offset(_("UTC-3"),    -3,  0));
699         offsets.push_back (Offset(_("UTC-2"),    -2,  0));
700         offsets.push_back (Offset(_("UTC-1"),    -1,  0));
701         int utc = offsets.size();
702         offsets.push_back (Offset(_("UTC")  ,     0,  0));
703         offsets.push_back (Offset(_("UTC+1"),     1,  0));
704         offsets.push_back (Offset(_("UTC+2"),     2,  0));
705         offsets.push_back (Offset(_("UTC+3"),     3,  0));
706         offsets.push_back (Offset(_("UTC+4"),     4,  0));
707         offsets.push_back (Offset(_("UTC+5"),     5,  0));
708         offsets.push_back (Offset(_("UTC+5:30"),  5, 30));
709         offsets.push_back (Offset(_("UTC+6"),     6,  0));
710         offsets.push_back (Offset(_("UTC+7"),     7,  0));
711         offsets.push_back (Offset(_("UTC+8"),     8,  0));
712         offsets.push_back (Offset(_("UTC+9"),     9,  0));
713         offsets.push_back (Offset(_("UTC+9:30"),  9, 30));
714         offsets.push_back (Offset(_("UTC+10"),   10,  0));
715         offsets.push_back (Offset(_("UTC+11"),   11,  0));
716         offsets.push_back (Offset(_("UTC+12"),   12,  0));
717
718         return utc;
719 }
720
721
722 wxString
723 bitmap_path (string name)
724 {
725         boost::filesystem::path base;
726
727 #ifdef DCPOMATIC_DEBUG
728         /* Hack to allow Linux and OS X to find icons when running from the source tree */
729         char* path = getenv ("DCPOMATIC_GRAPHICS");
730         if (path) {
731                 base = path;
732         } else {
733                 base = resources_path();
734         }
735
736         if (!boost::filesystem::exists(base / name)) {
737                 base = path / boost::filesystem::path("osx/preferences");
738         }
739 #else
740         base = resources_path();
741 #endif
742
743         auto p = base / name;
744         return std_to_wx (p.string());
745 }
746
747
748 wxString
749 icon_path(string name)
750 {
751         return gui_is_dark() ? bitmap_path(String::compose("%1_white.png", name)) : bitmap_path(String::compose("%1_black.png", name));
752 }
753
754
755 wxSize
756 small_button_size (wxWindow* parent, wxString text)
757 {
758         wxClientDC dc (parent);
759         auto size = dc.GetTextExtent (text);
760         size.SetHeight (-1);
761         size.IncBy (32, 0);
762         return size;
763 }
764
765
766 bool
767 gui_is_dark ()
768 {
769 #if defined(DCPOMATIC_OSX) && wxCHECK_VERSION(3, 1, 0)
770         auto appearance = wxSystemSettings::GetAppearance();
771         return appearance.IsDark();
772 #else
773         return false;
774 #endif
775 }
776
777
778 #if wxCHECK_VERSION(3,1,0)
779 double
780 dpi_scale_factor (wxWindow* window)
781 {
782         return window->GetDPIScaleFactor();
783 }
784 #else
785 double
786 dpi_scale_factor (wxWindow*)
787 {
788         return 1;
789 }
790 #endif
791
792
793
794 int
795 search_ctrl_height ()
796 {
797 #ifdef __WXGTK3__
798         return 30;
799 #else
800         return -1;
801 #endif
802 }
803
804
805 void
806 report_config_load_failure(wxWindow* parent, Config::LoadFailure what)
807 {
808         switch (what) {
809         case Config::LoadFailure::CONFIG:
810                 message_dialog(parent, _("The existing configuration failed to load.  Default values will be used instead.  These may take a short time to create."));
811                 break;
812         case Config::LoadFailure::CINEMAS:
813                 message_dialog(
814                         parent,
815                         _(wxString::Format("The cinemas list for creating KDMs (cinemas.xml) failed to load.  Please check the numbered backup files in %s",
816                                            std_to_wx(Config::instance()->cinemas_file().parent_path().string())))
817                         );
818                 break;
819         case Config::LoadFailure::DKDM_RECIPIENTS:
820                 message_dialog(
821                         parent,
822                         _(wxString::Format("The recipients list for creating DKDMs (dkdm_recipients.xml) failed to load.  Please check the numbered backup files in %s",
823                                            std_to_wx(Config::instance()->dkdm_recipients_file().parent_path().string())))
824                         );
825                 break;
826         }
827 }
828