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