X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Fwx%2Fwx_util.cc;h=048f87908e8c72770e973f0450a36767c1b747f3;hb=b666a794a130386bc01ede2143ef40bd6973eb32;hp=27a4554ca61d5534994cbd6f794c1f289a44060c;hpb=b1e4b53ed5b674bb3b65390eba4c04873a8b9ec7;p=dcpomatic.git diff --git a/src/wx/wx_util.cc b/src/wx/wx_util.cc index 27a4554ca..048f87908 100644 --- a/src/wx/wx_util.cc +++ b/src/wx/wx_util.cc @@ -105,7 +105,7 @@ confirm_dialog (wxWindow* parent, wxString m) string wx_to_std (wxString s) { - return string (s.mb_str ()); + return string (s.ToUTF8 ()); } /** @param s STL string. @@ -123,7 +123,7 @@ int const ThreadedStaticText::_update_event_id = 10000; * @param initial Initial text for the wxStaticText while the computation is being run. * @param fn Function which works out what the wxStaticText content should be and returns it. */ -ThreadedStaticText::ThreadedStaticText (wxWindow* parent, wxString initial, function fn) +ThreadedStaticText::ThreadedStaticText (wxWindow* parent, wxString initial, boost::function fn) : wxStaticText (parent, wxID_ANY, initial) { Bind (wxEVT_COMMAND_TEXT_UPDATED, boost::bind (&ThreadedStaticText::thread_finished, this, _1), _update_event_id); @@ -139,12 +139,19 @@ ThreadedStaticText::~ThreadedStaticText () /** Run our thread and post the result to the GUI thread via AddPendingEvent */ void -ThreadedStaticText::run (function fn) +ThreadedStaticText::run (boost::function fn) +try { wxCommandEvent ev (wxEVT_COMMAND_TEXT_UPDATED, _update_event_id); ev.SetString (std_to_wx (fn ())); GetEventHandler()->AddPendingEvent (ev); } +catch (...) +{ + /* Ignore exceptions; marginally better than the program quitting, but + only marginally. + */ +} /** Called in the GUI thread when our worker thread has finished */ void @@ -289,3 +296,11 @@ wx_get (wxChoice* w) { return w->GetSelection (); } + +void +run_gui_loop () +{ + while (wxTheApp->Pending ()) { + wxTheApp->Dispatch (); + } +}