X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Fwx%2Fwx_util.cc;h=7a41f66e7cfa226c1bccb139f7fb88b3dc141082;hb=ac9f0b8c968f5bffc60a49ffb71a7c7a248f4e32;hp=1a34e5fa808bc992d1bd14bb55368848f0080862;hpb=39fb8198febde1937019db1c300ec363aab5aa56;p=dcpomatic.git diff --git a/src/wx/wx_util.cc b/src/wx/wx_util.cc index 1a34e5fa8..7a41f66e7 100644 --- a/src/wx/wx_util.cc +++ b/src/wx/wx_util.cc @@ -25,8 +25,11 @@ #include "file_picker_ctrl.h" +#include "language_tag_widget.h" #include "password_entry.h" +#include "region_subtag_widget.h" #include "static_text.h" +#include "wx_ptr.h" #include "wx_util.h" #include "lib/config.h" #include "lib/cross.h" @@ -34,15 +37,15 @@ #include "lib/job_manager.h" #include "lib/util.h" #include "lib/version.h" -#include "lib/warnings.h" #include -DCPOMATIC_DISABLE_WARNINGS +#include +LIBDCP_DISABLE_WARNINGS #include #include #include #include #include -DCPOMATIC_ENABLE_WARNINGS +LIBDCP_ENABLE_WARNINGS #include @@ -86,7 +89,7 @@ setup_osx_flags (wxSizer* s, bool left, int& flags) #endif -/** Add a wxStaticText to a wxSizer, aligning it at vertical centre. +/** Add a wxStaticText to a wxSizer. * @param s Sizer to add to. * @param p Parent window for the wxStaticText. * @param t Text for the wxStaticText. @@ -101,7 +104,7 @@ add_label_to_sizer (wxSizer* s, wxWindow* p, wxString t, bool left, int prop, in setup_osx_flags (s, left, flags); #endif auto m = create_label (p, t, left); - s->Add (m, prop, flags, 6); + s->Add (m, prop, flags, DCPOMATIC_SIZER_GAP); return m; } @@ -116,20 +119,20 @@ add_label_to_sizer (wxSizer* s, wxStaticText* t, bool, int prop, int flags) #ifdef __WXOSX__ setup_osx_flags (s, left, flags); #endif - s->Add (t, prop, flags, 6); + s->Add (t, prop, flags, DCPOMATIC_SIZER_GAP); return t; } wxStaticText * -add_label_to_sizer (wxGridBagSizer* s, wxWindow* p, wxString t, bool left, wxGBPosition pos, wxGBSpan span) +add_label_to_sizer(wxGridBagSizer* s, wxWindow* p, wxString t, bool left, wxGBPosition pos, wxGBSpan span, bool indent) { - int flags = wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT; + int flags = wxALIGN_CENTER_VERTICAL | wxLEFT; #ifdef __WXOSX__ setup_osx_flags (s, left, flags); #endif auto m = create_label (p, t, left); - s->Add (m, pos, span, flags); + s->Add(m, pos, span, flags, indent ? DCPOMATIC_SIZER_X_GAP : 0); return m; } @@ -158,14 +161,13 @@ add_label_to_sizer (wxGridBagSizer* s, wxStaticText* t, bool, wxGBPosition pos, void error_dialog (wxWindow* parent, wxString m, optional e) { - auto d = new wxMessageDialog (parent, m, _("DCP-o-matic"), wxOK | wxICON_ERROR); + auto d = make_wx(parent, m, _("DCP-o-matic"), wxOK | wxICON_ERROR); if (e) { wxString em = *e; em[0] = wxToupper (em[0]); d->SetExtendedMessage (em); } d->ShowModal (); - d->Destroy (); } @@ -176,9 +178,8 @@ error_dialog (wxWindow* parent, wxString m, optional e) void message_dialog (wxWindow* parent, wxString m) { - auto d = new wxMessageDialog (parent, m, _("DCP-o-matic"), wxOK | wxICON_INFORMATION); + auto d = make_wx(parent, m, _("DCP-o-matic"), wxOK | wxICON_INFORMATION); d->ShowModal (); - d->Destroy (); } @@ -186,10 +187,8 @@ message_dialog (wxWindow* parent, wxString m) bool confirm_dialog (wxWindow* parent, wxString m) { - auto d = new wxMessageDialog (parent, m, _("DCP-o-matic"), wxYES_NO | wxICON_QUESTION); - int const r = d->ShowModal (); - d->Destroy (); - return r == wxID_YES; + auto d = make_wx(parent, m, _("DCP-o-matic"), wxYES_NO | wxICON_QUESTION); + return d->ShowModal() == wxID_YES; } @@ -297,14 +296,14 @@ checked_set (wxChoice* widget, string value) void -checked_set (wxChoice* widget, vector > items) +checked_set (wxChoice* widget, vector> items) { vector> current; for (unsigned int i = 0; i < widget->GetCount(); ++i) { current.push_back ( make_pair( wx_to_std(widget->GetString(i)), - string_client_data(widget->GetClientObject(i)) + widget->GetClientData() ? string_client_data(widget->GetClientObject(i)) : "" ) ); } @@ -383,6 +382,33 @@ checked_set (wxRadioButton* widget, bool value) } +void +checked_set(LanguageTagWidget* widget, dcp::LanguageTag value) +{ + if (widget->get() != value) { + widget->set(value); + } +} + + +void +checked_set(LanguageTagWidget* widget, optional value) +{ + if (widget->get() != value) { + widget->set(value); + } +} + + +void +checked_set(RegionSubtagWidget* widget, optional value) +{ + if (widget->get() != value) { + widget->set(value); + } +} + + void dcpomatic_setup_i18n () { @@ -511,13 +537,14 @@ setup_audio_channels_choice (wxChoice* choice, int minimum) } -wxSplashScreen * +wx_ptr maybe_show_splash () { - wxSplashScreen* splash = nullptr; + wx_ptr splash; + try { wxBitmap bitmap; - if (bitmap.LoadFile(bitmap_path("splash"), wxBITMAP_TYPE_PNG)) { + if (bitmap.LoadFile(bitmap_path("splash.png"), wxBITMAP_TYPE_PNG)) { { /* This wxMemoryDC must be destroyed before bitmap can be used elsewhere */ wxMemoryDC dc(bitmap); @@ -528,9 +555,9 @@ maybe_show_splash () } #ifdef DCPOMATIC_WINDOWS /* Having wxSTAY_ON_TOP means error dialogues hide behind the splash screen on Windows, no matter what I try */ - splash = new wxSplashScreen (bitmap, wxSPLASH_CENTRE_ON_SCREEN | wxSPLASH_NO_TIMEOUT, 0, 0, -1, wxDefaultPosition, wxDefaultSize, wxBORDER_SIMPLE | wxFRAME_NO_TASKBAR); + splash.reset(bitmap, wxSPLASH_CENTRE_ON_SCREEN | wxSPLASH_NO_TIMEOUT, 0, nullptr, -1, wxDefaultPosition, wxDefaultSize, wxBORDER_SIMPLE | wxFRAME_NO_TASKBAR); #else - splash = new wxSplashScreen (bitmap, wxSPLASH_CENTRE_ON_SCREEN | wxSPLASH_NO_TIMEOUT, 0, 0, -1); + splash.reset(bitmap, wxSPLASH_CENTRE_ON_SCREEN | wxSPLASH_NO_TIMEOUT, 0, nullptr, -1); #endif wxYield (); } @@ -646,18 +673,89 @@ bitmap_path (string name) base = resources_path(); #endif - auto p = base / String::compose("%1.png", name); + auto p = base / name; return std_to_wx (p.string()); } +wxString +icon_path(string name) +{ + return gui_is_dark() ? bitmap_path(String::compose("%1_white.png", name)) : bitmap_path(String::compose("%1_black.png", name)); +} + + wxSize small_button_size (wxWindow* parent, wxString text) { wxClientDC dc (parent); auto size = dc.GetTextExtent (text); size.SetHeight (-1); - size.IncBy (24, 0); + size.IncBy (32, 0); return size; } + +bool +gui_is_dark () +{ +#if defined(DCPOMATIC_OSX) && wxCHECK_VERSION(3, 1, 0) + auto appearance = wxSystemSettings::GetAppearance(); + return appearance.IsDark(); +#else + return false; +#endif +} + + +#if wxCHECK_VERSION(3,1,0) +double +dpi_scale_factor (wxWindow* window) +{ + return window->GetDPIScaleFactor(); +} +#else +double +dpi_scale_factor (wxWindow*) +{ + return 1; +} +#endif + + + +int +search_ctrl_height () +{ +#ifdef __WXGTK3__ + return 30; +#else + return -1; +#endif +} + + +void +report_config_load_failure(wxWindow* parent, Config::LoadFailure what) +{ + switch (what) { + case Config::LoadFailure::CONFIG: + message_dialog(parent, _("The existing configuration failed to load. Default values will be used instead. These may take a short time to create.")); + break; + case Config::LoadFailure::CINEMAS: + message_dialog( + parent, + _(wxString::Format("The cinemas list for creating KDMs (cinemas.xml) failed to load. Please check the numbered backup files in %s", + std_to_wx(Config::instance()->cinemas_file().parent_path().string()))) + ); + break; + case Config::LoadFailure::DKDM_RECIPIENTS: + message_dialog( + parent, + _(wxString::Format("The recipients list for creating DKDMs (dkdm_recipients.xml) failed to load. Please check the numbered backup files in %s", + std_to_wx(Config::instance()->dkdm_recipients_file().parent_path().string()))) + ); + break; + } +} +