X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Fwx%2Fwx_util.cc;h=a0beb8f72d0f4e7ac92b7be74e2b06ae52b756af;hb=60874f7b18adfc95493e94f6f8cd44773f7afe7b;hp=bc9b29c4f3d96c231aac9be58bb302576def733e;hpb=f425f2fbed0f85c62fdc70accff95c2e83503612;p=dcpomatic.git diff --git a/src/wx/wx_util.cc b/src/wx/wx_util.cc index bc9b29c4f..a0beb8f72 100644 --- a/src/wx/wx_util.cc +++ b/src/wx/wx_util.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2012-2020 Carl Hetherington + Copyright (C) 2012-2021 Carl Hetherington This file is part of DCP-o-matic. @@ -105,6 +105,7 @@ add_label_to_sizer (wxSizer* s, wxWindow* p, wxString t, bool left, int prop, in return m; } + wxStaticText * #ifdef __WXOSX__ add_label_to_sizer (wxSizer* s, wxStaticText* t, bool left, int prop, int flags) @@ -119,6 +120,7 @@ add_label_to_sizer (wxSizer* s, wxStaticText* t, bool, int prop, int flags) return t; } + wxStaticText * add_label_to_sizer (wxGridBagSizer* s, wxWindow* p, wxString t, bool left, wxGBPosition pos, wxGBSpan span) { @@ -131,6 +133,7 @@ add_label_to_sizer (wxGridBagSizer* s, wxWindow* p, wxString t, bool left, wxGBP return m; } + wxStaticText * #ifdef __WXOSX__ add_label_to_sizer (wxGridBagSizer* s, wxStaticText* t, bool left, wxGBPosition pos, wxGBSpan span) @@ -146,6 +149,7 @@ add_label_to_sizer (wxGridBagSizer* s, wxStaticText* t, bool, wxGBPosition pos, return t; } + /** Pop up an error dialogue box. * @param parent Parent. * @param m Message. @@ -164,6 +168,7 @@ error_dialog (wxWindow* parent, wxString m, optional e) d->Destroy (); } + /** Pop up an error dialogue box. * @param parent Parent. * @param m Message. @@ -176,11 +181,12 @@ message_dialog (wxWindow* parent, wxString m) d->Destroy (); } + /** @return true if the user answered "yes" */ bool confirm_dialog (wxWindow* parent, wxString m) { - wxMessageDialog* d = new wxMessageDialog (parent, m, _("DCP-o-matic"), wxYES_NO | wxICON_QUESTION); + auto d = new wxMessageDialog (parent, m, _("DCP-o-matic"), wxYES_NO | wxICON_QUESTION); int const r = d->ShowModal (); d->Destroy (); return r == wxID_YES; @@ -193,9 +199,10 @@ confirm_dialog (wxWindow* parent, wxString m) string wx_to_std (wxString s) { - return string (s.ToUTF8 ()); + return string (s.ToUTF8()); } + /** @param s STL string. * @return Corresponding wxWidgets string. */ @@ -205,12 +212,14 @@ std_to_wx (string s) return wxString (s.c_str(), wxConvUTF8); } + string string_client_data (wxClientData* o) { return wx_to_std (dynamic_cast(o)->GetData()); } + void checked_set (FilePickerCtrl* widget, boost::filesystem::path value) { @@ -225,6 +234,7 @@ checked_set (FilePickerCtrl* widget, boost::filesystem::path value) } } + void checked_set (wxDirPickerCtrl* widget, boost::filesystem::path value) { @@ -239,6 +249,7 @@ checked_set (wxDirPickerCtrl* widget, boost::filesystem::path value) } } + void checked_set (wxSpinCtrl* widget, int value) { @@ -247,6 +258,7 @@ checked_set (wxSpinCtrl* widget, int value) } } + void checked_set (wxSpinCtrlDouble* widget, double value) { @@ -256,6 +268,7 @@ checked_set (wxSpinCtrlDouble* widget, double value) } } + void checked_set (wxChoice* widget, int value) { @@ -264,6 +277,7 @@ checked_set (wxChoice* widget, int value) } } + void checked_set (wxChoice* widget, string value) { @@ -281,15 +295,16 @@ checked_set (wxChoice* widget, string value) } } + void checked_set (wxChoice* widget, vector > items) { - vector > current; + 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)) + make_pair( + wx_to_std(widget->GetString(i)), + string_client_data(widget->GetClientObject(i)) ) ); } @@ -304,6 +319,7 @@ checked_set (wxChoice* widget, vector > items) } } + void checked_set (wxTextCtrl* widget, string value) { @@ -312,6 +328,7 @@ checked_set (wxTextCtrl* widget, string value) } } + void checked_set (PasswordEntry* entry, string value) { @@ -320,6 +337,7 @@ checked_set (PasswordEntry* entry, string value) } } + void checked_set (wxTextCtrl* widget, wxString value) { @@ -328,6 +346,7 @@ checked_set (wxTextCtrl* widget, wxString value) } } + void checked_set (wxStaticText* widget, string value) { @@ -336,6 +355,7 @@ checked_set (wxStaticText* widget, string value) } } + void checked_set (wxStaticText* widget, wxString value) { @@ -344,6 +364,7 @@ checked_set (wxStaticText* widget, wxString value) } } + void checked_set (wxCheckBox* widget, bool value) { @@ -352,6 +373,7 @@ checked_set (wxCheckBox* widget, bool value) } } + void checked_set (wxRadioButton* widget, bool value) { @@ -360,6 +382,7 @@ checked_set (wxRadioButton* widget, bool value) } } + void dcpomatic_setup_i18n () { @@ -408,24 +431,28 @@ dcpomatic_setup_i18n () } } + int wx_get (wxSpinCtrl* w) { return w->GetValue (); } + int wx_get (wxChoice* w) { return w->GetSelection (); } + double wx_get (wxSpinCtrlDouble* w) { return w->GetValue (); } + /** @param s String of the form Context|String * @return translation, or String if no translation is available. */ @@ -444,6 +471,7 @@ context_translation (wxString s) return t; } + wxString time_to_timecode (DCPTime t, double fps) { @@ -458,23 +486,24 @@ time_to_timecode (DCPTime t, double fps) return wxString::Format (wxT("%02d:%02d:%02d.%02d"), h, m, s, f); } + void setup_audio_channels_choice (wxChoice* choice, int minimum) { - vector > items; + vector> items; for (int i = minimum; i <= 16; i += 2) { if (i == 2) { - items.push_back (make_pair (wx_to_std (_("2 - stereo")), locale_convert (i))); + items.push_back (make_pair(wx_to_std(_("2 - stereo")), locale_convert(i))); } else if (i == 4) { - items.push_back (make_pair (wx_to_std (_("4 - L/C/R/Lfe")), locale_convert (i))); + items.push_back (make_pair(wx_to_std(_("4 - L/C/R/Lfe")), locale_convert(i))); } else if (i == 6) { - items.push_back (make_pair (wx_to_std (_("6 - 5.1")), locale_convert (i))); + items.push_back (make_pair(wx_to_std(_("6 - 5.1")), locale_convert(i))); } else if (i == 8) { - items.push_back (make_pair (wx_to_std (_("8 - 5.1/HI/VI")), locale_convert (i))); + items.push_back (make_pair(wx_to_std(_("8 - 5.1/HI/VI")), locale_convert(i))); } else if (i == 12) { - items.push_back (make_pair (wx_to_std (_("12 - 7.1/HI/VI")), locale_convert (i))); + items.push_back (make_pair(wx_to_std(_("12 - 7.1/HI/VI")), locale_convert(i))); } else { - items.push_back (make_pair (locale_convert (i), locale_convert (i))); + items.push_back (make_pair(locale_convert (i), locale_convert(i))); } } @@ -489,11 +518,14 @@ maybe_show_splash () try { wxBitmap bitmap; if (bitmap.LoadFile(bitmap_path("splash"), wxBITMAP_TYPE_PNG)) { - wxMemoryDC dc(bitmap); - auto const version = wxString::Format("%s (%s)", dcpomatic_version, dcpomatic_git_commit); - auto screen_size = dc.GetSize(); - auto text_size = dc.GetTextExtent(version); - dc.DrawText(version, (screen_size.GetWidth() - text_size.GetWidth()) / 2, 236); + { + /* This wxMemoryDC must be destroyed before bitmap can be used elsewhere */ + wxMemoryDC dc(bitmap); + auto const version = wxString::Format("%s (%s)", dcpomatic_version, dcpomatic_git_commit); + auto screen_size = dc.GetSize(); + auto text_size = dc.GetTextExtent(version); + dc.DrawText(version, (screen_size.GetWidth() - text_size.GetWidth()) / 2, 236); + } #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); @@ -509,6 +541,7 @@ maybe_show_splash () return splash; } + double calculate_mark_interval (double mark_interval) { @@ -613,7 +646,7 @@ bitmap_path (string name) base = resources_path(); #endif - boost::filesystem::path p = base / String::compose("%1.png", name); + auto p = base / String::compose("%1.png", name); return std_to_wx (p.string()); } @@ -628,3 +661,15 @@ small_button_size (wxWindow* parent, wxString text) 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 +} +