Use RAII for modal pauses

This commit is contained in:
Ilari Liusvaara 2012-01-20 14:09:38 +02:00
parent aa06a54a06
commit a3ab2973f9
3 changed files with 35 additions and 46 deletions

View file

@ -534,6 +534,16 @@ struct platform
static void run_queues() throw(); static void run_queues() throw();
}; };
class modal_pause_holder
{
public:
modal_pause_holder();
~modal_pause_holder();
private:
modal_pause_holder(const modal_pause_holder&);
modal_pause_holder& operator=(const modal_pause_holder&);
};
template<typename T> template<typename T>
void functor_call_helper(void* args) void functor_call_helper(void* args)
{ {

View file

@ -563,4 +563,15 @@ void platform::screen_set_palette(unsigned rshift, unsigned gshift, unsigned bsh
trigger_repaint(); trigger_repaint();
} }
modal_pause_holder::modal_pause_holder()
{
platform::set_modal_pause(true);
}
modal_pause_holder::~modal_pause_holder()
{
platform::set_modal_pause(false);
}
volatile bool queue_synchronous_fn_warning; volatile bool queue_synchronous_fn_warning;

View file

@ -239,14 +239,13 @@ namespace
controller_autohold_menu::controller_autohold_menu(unsigned lid, enum devicetype_t dtype) controller_autohold_menu::controller_autohold_menu(unsigned lid, enum devicetype_t dtype)
{ {
platform::set_modal_pause(true); modal_pause_holder hld;
our_lid = lid; our_lid = lid;
for(unsigned i = 0; i < MAX_LOGICAL_BUTTONS; i++) { for(unsigned i = 0; i < MAX_LOGICAL_BUTTONS; i++) {
int id = wxID_AUTOHOLD_FIRST + MAX_LOGICAL_BUTTONS * lid + i; int id = wxID_AUTOHOLD_FIRST + MAX_LOGICAL_BUTTONS * lid + i;
entries[i] = AppendCheckItem(id, towxstring(get_logical_button_name(i))); entries[i] = AppendCheckItem(id, towxstring(get_logical_button_name(i)));
} }
change_type(); change_type();
platform::set_modal_pause(false);
} }
void controller_autohold_menu::change_type() void controller_autohold_menu::change_type()
@ -281,38 +280,30 @@ namespace
return; return;
} }
unsigned lidx = (x - wxID_AUTOHOLD_FIRST) % MAX_LOGICAL_BUTTONS; unsigned lidx = (x - wxID_AUTOHOLD_FIRST) % MAX_LOGICAL_BUTTONS;
platform::set_modal_pause(true); modal_pause_holder hld;
int pid = controls.lcid_to_pcid(our_lid); int pid = controls.lcid_to_pcid(our_lid);
if(pid < 0 || !entries[lidx]) { if(pid < 0 || !entries[lidx])
platform::set_modal_pause(false);
return; return;
}
int pidx = controls.button_id(pid, lidx); int pidx = controls.button_id(pid, lidx);
if(pidx < 0) { if(pidx < 0)
platform::set_modal_pause(false);
return; return;
}
//Autohold change on pid=pid, ctrlindx=idx, state //Autohold change on pid=pid, ctrlindx=idx, state
bool newstate = entries[lidx]->IsChecked(); bool newstate = entries[lidx]->IsChecked();
UI_change_autohold(pid, pidx, newstate); UI_change_autohold(pid, pidx, newstate);
platform::set_modal_pause(false);
} }
void controller_autohold_menu::update(unsigned pid, unsigned ctrlnum, bool newstate) void controller_autohold_menu::update(unsigned pid, unsigned ctrlnum, bool newstate)
{ {
platform::set_modal_pause(true); modal_pause_holder hld;
int pid2 = UI_controller_index_by_logical(our_lid); int pid2 = UI_controller_index_by_logical(our_lid);
if(pid2 < 0 || static_cast<unsigned>(pid) != pid2) { if(pid2 < 0 || static_cast<unsigned>(pid) != pid2)
platform::set_modal_pause(false);
return; return;
}
for(unsigned i = 0; i < MAX_LOGICAL_BUTTONS; i++) { for(unsigned i = 0; i < MAX_LOGICAL_BUTTONS; i++) {
int idx = UI_button_id(pid2, i); int idx = UI_button_id(pid2, i);
if(idx < 0 || static_cast<unsigned>(idx) != ctrlnum) if(idx < 0 || static_cast<unsigned>(idx) != ctrlnum)
continue; continue;
entries[i]->Check(newstate); entries[i]->Check(newstate);
} }
platform::set_modal_pause(false);
} }
@ -332,12 +323,11 @@ namespace
void autohold_menu::reconfigure() void autohold_menu::reconfigure()
{ {
platform::set_modal_pause(true); modal_pause_holder hld;
for(unsigned i = 0; i < MAXCONTROLLERS; i++) { for(unsigned i = 0; i < MAXCONTROLLERS; i++) {
menus[i]->change_type(); menus[i]->change_type();
entries[i]->Enable(!menus[i]->is_dummy()); entries[i]->Enable(!menus[i]->is_dummy());
} }
platform::set_modal_pause(false);
} }
void autohold_menu::on_select(wxCommandEvent& e) void autohold_menu::on_select(wxCommandEvent& e)
@ -608,11 +598,10 @@ void boot_emulator(loaded_rom& rom, moviefile& movie)
a->rom = &rom; a->rom = &rom;
a->initial = &movie; a->initial = &movie;
a->load_has_to_succeed = false; a->load_has_to_succeed = false;
platform::set_modal_pause(true); modal_pause_holder hld;
emulation_thread = &thread::create(emulator_main, a); emulation_thread = &thread::create(emulator_main, a);
main_window = new wxwin_mainwindow(); main_window = new wxwin_mainwindow();
main_window->Show(); main_window->Show();
platform::set_modal_pause(false);
} catch(std::bad_alloc& e) { } catch(std::bad_alloc& e) {
OOM_panic(); OOM_panic();
} }
@ -1055,7 +1044,7 @@ void wxwin_mainwindow::handle_menu_click(wxCommandEvent& e)
wxeditor_settings_display(this); wxeditor_settings_display(this);
return; return;
case wxID_EDIT_KEYBINDINGS: { case wxID_EDIT_KEYBINDINGS: {
platform::set_modal_pause(true); modal_pause_holder hld;
std::set<std::string> bind; std::set<std::string> bind;
runemufn([&bind]() { bind = keymapper::get_bindings(); }); runemufn([&bind]() { bind = keymapper::get_bindings(); });
std::vector<wxString> choices; std::vector<wxString> choices;
@ -1066,7 +1055,6 @@ void wxwin_mainwindow::handle_menu_click(wxCommandEvent& e)
wxT("Select binding"), choices.size(), &choices[0]); wxT("Select binding"), choices.size(), &choices[0]);
if(d->ShowModal() == wxID_CANCEL) { if(d->ShowModal() == wxID_CANCEL) {
d->Destroy(); d->Destroy();
platform::set_modal_pause(false);
return; return;
} }
std::string key = tostdstring(d->GetStringSelection()); std::string key = tostdstring(d->GetStringSelection());
@ -1075,7 +1063,6 @@ void wxwin_mainwindow::handle_menu_click(wxCommandEvent& e)
wxdialog_keyentry* d2 = new wxdialog_keyentry(this); wxdialog_keyentry* d2 = new wxdialog_keyentry(this);
if(d2->ShowModal() == wxID_CANCEL) { if(d2->ShowModal() == wxID_CANCEL) {
d2->Destroy(); d2->Destroy();
platform::set_modal_pause(false);
return; return;
} }
key = d2->getkey(); key = d2->getkey();
@ -1087,7 +1074,6 @@ void wxwin_mainwindow::handle_menu_click(wxCommandEvent& e)
wxT("Edit binding"), towxstring(old_command_value)); wxT("Edit binding"), towxstring(old_command_value));
if(d4->ShowModal() == wxID_CANCEL) { if(d4->ShowModal() == wxID_CANCEL) {
d4->Destroy(); d4->Destroy();
platform::set_modal_pause(false);
return; return;
} }
bool fault = false; bool fault = false;
@ -1106,11 +1092,10 @@ void wxwin_mainwindow::handle_menu_click(wxCommandEvent& e)
d3->Destroy(); d3->Destroy();
} }
d4->Destroy(); d4->Destroy();
platform::set_modal_pause(false);
return; return;
} }
case wxID_EDIT_ALIAS: { case wxID_EDIT_ALIAS: {
platform::set_modal_pause(true); modal_pause_holder hld;
std::set<std::string> bind; std::set<std::string> bind;
runemufn([&bind]() { bind = command::get_aliases(); }); runemufn([&bind]() { bind = command::get_aliases(); });
std::vector<wxString> choices; std::vector<wxString> choices;
@ -1121,7 +1106,6 @@ void wxwin_mainwindow::handle_menu_click(wxCommandEvent& e)
wxT("Select alias"), choices.size(), &choices[0]); wxT("Select alias"), choices.size(), &choices[0]);
if(d->ShowModal() == wxID_CANCEL) { if(d->ShowModal() == wxID_CANCEL) {
d->Destroy(); d->Destroy();
platform::set_modal_pause(false);
return; return;
} }
std::string alias = tostdstring(d->GetStringSelection()); std::string alias = tostdstring(d->GetStringSelection());
@ -1131,7 +1115,6 @@ void wxwin_mainwindow::handle_menu_click(wxCommandEvent& e)
wxT("Enter alias name")); wxT("Enter alias name"));
if(d2->ShowModal() == wxID_CANCEL) { if(d2->ShowModal() == wxID_CANCEL) {
d2->Destroy(); d2->Destroy();
platform::set_modal_pause(false);
return; return;
} }
alias = tostdstring(d2->GetValue()); alias = tostdstring(d2->GetValue());
@ -1141,7 +1124,6 @@ void wxwin_mainwindow::handle_menu_click(wxCommandEvent& e)
"alias name: ") + alias), wxT("Error"), wxOK | wxICON_EXCLAMATION); "alias name: ") + alias), wxT("Error"), wxOK | wxICON_EXCLAMATION);
d3->ShowModal(); d3->ShowModal();
d3->Destroy(); d3->Destroy();
platform::set_modal_pause(false);
return; return;
} }
} }
@ -1150,17 +1132,15 @@ void wxwin_mainwindow::handle_menu_click(wxCommandEvent& e)
wxT("Edit alias"), towxstring(old_alias_value), wxOK | wxCANCEL | wxCENTRE | wxTE_MULTILINE); wxT("Edit alias"), towxstring(old_alias_value), wxOK | wxCANCEL | wxCENTRE | wxTE_MULTILINE);
if(d4->ShowModal() == wxID_CANCEL) { if(d4->ShowModal() == wxID_CANCEL) {
d4->Destroy(); d4->Destroy();
platform::set_modal_pause(false);
return; return;
} }
std::string newcmd = tostdstring(d4->GetValue()); std::string newcmd = tostdstring(d4->GetValue());
runemufn([alias, newcmd]() { command::set_alias_for(alias, newcmd); }); runemufn([alias, newcmd]() { command::set_alias_for(alias, newcmd); });
d4->Destroy(); d4->Destroy();
platform::set_modal_pause(false);
return; return;
} }
case wxID_EDIT_JUKEBOX: { case wxID_EDIT_JUKEBOX: {
platform::set_modal_pause(true); modal_pause_holder hld;
std::string x; std::string x;
std::vector<std::string> new_jukebox; std::vector<std::string> new_jukebox;
runemufn([&x]() { runemufn([&x]() {
@ -1172,7 +1152,6 @@ void wxwin_mainwindow::handle_menu_click(wxCommandEvent& e)
wxT("Configure jukebox"), towxstring(x), wxOK | wxCANCEL | wxCENTRE | wxTE_MULTILINE); wxT("Configure jukebox"), towxstring(x), wxOK | wxCANCEL | wxCENTRE | wxTE_MULTILINE);
if(dialog->ShowModal() == wxID_CANCEL) { if(dialog->ShowModal() == wxID_CANCEL) {
dialog->Destroy(); dialog->Destroy();
platform::set_modal_pause(false);
return; return;
} }
x = tostdstring(dialog->GetValue()); x = tostdstring(dialog->GetValue());
@ -1194,11 +1173,10 @@ void wxwin_mainwindow::handle_menu_click(wxCommandEvent& e)
} }
runemufn([&new_jukebox]() { set_jukebox_names(new_jukebox); }); runemufn([&new_jukebox]() { set_jukebox_names(new_jukebox); });
notify_update_status(); notify_update_status();
platform::set_modal_pause(false);
return; return;
} }
case wxID_EDIT_MEMORYWATCH: { case wxID_EDIT_MEMORYWATCH: {
platform::set_modal_pause(true); modal_pause_holder hld;
std::set<std::string> bind; std::set<std::string> bind;
runemufn([&bind]() { bind = get_watches(); }); runemufn([&bind]() { bind = get_watches(); });
std::vector<wxString> choices; std::vector<wxString> choices;
@ -1209,7 +1187,6 @@ void wxwin_mainwindow::handle_menu_click(wxCommandEvent& e)
wxT("Select watch"), choices.size(), &choices[0]); wxT("Select watch"), choices.size(), &choices[0]);
if(d->ShowModal() == wxID_CANCEL) { if(d->ShowModal() == wxID_CANCEL) {
d->Destroy(); d->Destroy();
platform::set_modal_pause(false);
return; return;
} }
std::string watch = tostdstring(d->GetStringSelection()); std::string watch = tostdstring(d->GetStringSelection());
@ -1219,7 +1196,6 @@ void wxwin_mainwindow::handle_menu_click(wxCommandEvent& e)
wxT("Enter watch name")); wxT("Enter watch name"));
if(d2->ShowModal() == wxID_CANCEL) { if(d2->ShowModal() == wxID_CANCEL) {
d2->Destroy(); d2->Destroy();
platform::set_modal_pause(false);
return; return;
} }
watch = tostdstring(d2->GetValue()); watch = tostdstring(d2->GetValue());
@ -1230,17 +1206,15 @@ void wxwin_mainwindow::handle_menu_click(wxCommandEvent& e)
wxT("Edit watch"), towxstring(old_watch_value), wxOK | wxCANCEL | wxCENTRE); wxT("Edit watch"), towxstring(old_watch_value), wxOK | wxCANCEL | wxCENTRE);
if(d4->ShowModal() == wxID_CANCEL) { if(d4->ShowModal() == wxID_CANCEL) {
d4->Destroy(); d4->Destroy();
platform::set_modal_pause(false);
return; return;
} }
std::string newexpr = tostdstring(d4->GetValue()); std::string newexpr = tostdstring(d4->GetValue());
runemufn([watch, newexpr]() { set_watchexpr_for(watch, newexpr); }); runemufn([watch, newexpr]() { set_watchexpr_for(watch, newexpr); });
platform::set_modal_pause(false);
d4->Destroy(); d4->Destroy();
return; return;
} }
case wxID_SAVE_MEMORYWATCH: { case wxID_SAVE_MEMORYWATCH: {
platform::set_modal_pause(true); modal_pause_holder hld;
std::set<std::string> old_watches; std::set<std::string> old_watches;
runemufn([&old_watches]() { old_watches = get_watches(); }); runemufn([&old_watches]() { old_watches = get_watches(); });
std::string filename; std::string filename;
@ -1248,7 +1222,6 @@ void wxwin_mainwindow::handle_menu_click(wxCommandEvent& e)
wxFileDialog* d = new wxFileDialog(this, towxstring("Save watches to file"), wxT(".")); wxFileDialog* d = new wxFileDialog(this, towxstring("Save watches to file"), wxT("."));
if(d->ShowModal() == wxID_CANCEL) { if(d->ShowModal() == wxID_CANCEL) {
d->Destroy(); d->Destroy();
platform::set_modal_pause(false);
return; return;
} }
filename = tostdstring(d->GetPath()); filename = tostdstring(d->GetPath());
@ -1258,11 +1231,10 @@ void wxwin_mainwindow::handle_menu_click(wxCommandEvent& e)
for(auto i : old_watches) for(auto i : old_watches)
out << i << std::endl << get_watchexpr_for(i) << std::endl; out << i << std::endl << get_watchexpr_for(i) << std::endl;
out.close(); out.close();
platform::set_modal_pause(false);
return; return;
} }
case wxID_LOAD_MEMORYWATCH: { case wxID_LOAD_MEMORYWATCH: {
platform::set_modal_pause(true); modal_pause_holder hld;
std::set<std::string> old_watches; std::set<std::string> old_watches;
runemufn([&old_watches]() { old_watches = get_watches(); }); runemufn([&old_watches]() { old_watches = get_watches(); });
std::map<std::string, std::string> new_watches; std::map<std::string, std::string> new_watches;
@ -1271,7 +1243,6 @@ void wxwin_mainwindow::handle_menu_click(wxCommandEvent& e)
wxFileDialog* d = new wxFileDialog(this, towxstring("Choose memory watch file"), wxT(".")); wxFileDialog* d = new wxFileDialog(this, towxstring("Choose memory watch file"), wxT("."));
if(d->ShowModal() == wxID_CANCEL) { if(d->ShowModal() == wxID_CANCEL) {
d->Destroy(); d->Destroy();
platform::set_modal_pause(false);
return; return;
} }
filename = tostdstring(d->GetPath()); filename = tostdstring(d->GetPath());
@ -1286,7 +1257,6 @@ void wxwin_mainwindow::handle_menu_click(wxCommandEvent& e)
wxT("Select member"), files.size(), &files[0]); wxT("Select member"), files.size(), &files[0]);
if(d2->ShowModal() == wxID_CANCEL) { if(d2->ShowModal() == wxID_CANCEL) {
d2->Destroy(); d2->Destroy();
platform::set_modal_pause(false);
return; return;
} }
filename = filename + "/" + tostdstring(d2->GetStringSelection()); filename = filename + "/" + tostdstring(d2->GetStringSelection());
@ -1310,7 +1280,6 @@ void wxwin_mainwindow::handle_menu_click(wxCommandEvent& e)
"watch: ") + e.what()), wxT("Error"), wxOK | wxICON_EXCLAMATION); "watch: ") + e.what()), wxT("Error"), wxOK | wxICON_EXCLAMATION);
d3->ShowModal(); d3->ShowModal();
d3->Destroy(); d3->Destroy();
platform::set_modal_pause(false);
return; return;
} }
@ -1321,7 +1290,6 @@ void wxwin_mainwindow::handle_menu_click(wxCommandEvent& e)
if(!new_watches.count(i)) if(!new_watches.count(i))
set_watchexpr_for(i, ""); set_watchexpr_for(i, "");
}); });
platform::set_modal_pause(false);
return; return;
} }
case wxID_MEMORY_SEARCH: case wxID_MEMORY_SEARCH: