d588620e70bf15da29cc242e4ae8d86977e8f36a from master; fix hang if you cancel a paused...
[dcpomatic.git] / src / wx / wx_util.cc
index 0119799d26aaa3d0c8ff17dde466169877d6fd78..9c13cfbcb69e741cbff7f8d8e42c8804bf62494e 100644 (file)
@@ -179,6 +179,29 @@ checked_set (wxChoice* widget, string value)
        }
 }
 
+void
+checked_set (wxChoice* widget, vector<pair<string, string> > items)
+{
+       vector<pair<string, string> > 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))
+                               )
+                       );
+       }
+
+       if (current == items) {
+               return;
+       }
+
+       widget->Clear ();
+       for (vector<pair<string, string> >::const_iterator i = items.begin(); i != items.end(); ++i) {
+               widget->Append (std_to_wx (i->first), new wxStringClientData (std_to_wx (i->second)));
+       }
+}
+
 void
 checked_set (wxTextCtrl* widget, string value)
 {
@@ -187,6 +210,14 @@ checked_set (wxTextCtrl* widget, string value)
        }
 }
 
+void
+checked_set (wxTextCtrl* widget, wxString value)
+{
+       if (widget->GetValue() != value) {
+               widget->ChangeValue (value);
+       }
+}
+
 void
 checked_set (wxStaticText* widget, string value)
 {
@@ -195,6 +226,14 @@ checked_set (wxStaticText* widget, string value)
        }
 }
 
+void
+checked_set (wxStaticText* widget, wxString value)
+{
+       if (widget->GetLabel() != value) {
+               widget->SetLabel (value);
+       }
+}
+
 void
 checked_set (wxCheckBox* widget, bool value)
 {
@@ -232,11 +271,9 @@ dcpomatic_setup_i18n ()
                locale->AddCatalogLookupPathPrefix (std_to_wx (mo_path().string()));
 #endif         
 
-#ifdef DCPOMATIC_POSIX
-               locale->AddCatalogLookupPathPrefix (POSIX_LOCALE_PREFIX);
-#endif
-
 #ifdef DCPOMATIC_LINUX
+               locale->AddCatalogLookupPathPrefix (LINUX_LOCALE_PREFIX);
+
                /* We have to include the wxWidgets .mo in our distribution,
                   so we rename it to avoid clashes with any other installation
                   of wxWidgets.
@@ -293,3 +330,17 @@ context_translation (wxString s)
 
        return t;
 }
+
+wxString
+time_to_timecode (DCPTime t, float fps)
+{
+       double w = t.seconds ();
+       int const h = (w / 3600);
+       w -= h * 3600;
+       int const m = (w / 60);
+       w -= m * 60;
+       int const s = floor (w);
+       w -= s;
+       int const f = rint (w * fps);
+       return wxString::Format (wxT("%02d:%02d:%02d.%02d"), h, m, s, f);
+}