Add <functional> to files that use std::function
[lsnes.git] / include / platform / wxwidgets / platform.hpp
blob2f07d5ea008d885df2ccc806fe1c1bc8be17937f
1 #ifndef _plat_wxwidgets__platform__hpp__included__
2 #define _plat_wxwidgets__platform__hpp__included__
4 #include <wx/wx.h>
5 #include <wx/event.h>
6 #include <wx/control.h>
7 #include <wx/combobox.h>
9 #include "core/queue.hpp"
10 #include "core/moviefile.hpp"
11 #include "core/window.hpp"
12 #include "library/threads.hpp"
14 #include <functional>
15 #include <cstdlib>
16 #include <cstdint>
17 #include <cstddef>
19 #include <wx/string.h>
20 #include <wx/event.h>
22 void _check_ui_thread(const char* file, int line);
23 #define CHECK_UI_THREAD _check_ui_thread( __FILE__ , __LINE__ )
25 struct runuifun_once_ctx
27 runuifun_once_ctx()
29 flag = false;
31 bool set_flag()
33 threads::alock h(m);
34 if(flag) return false;
35 flag = true;
36 return true;
38 void clear_flag()
40 threads::alock h(m);
41 flag = false;
43 private:
44 threads::lock m;
45 bool flag;
48 class wxwin_mainwindow;
49 class wxwin_messages;
50 class wxwin_status;
51 class wxWindow;
52 class wxKeyEvent;
53 class emulator_instance;
55 //Scaling
56 extern double video_scale_factor;
57 extern int scaling_flags;
58 extern bool arcorrect_enabled;
59 extern bool hflip_enabled;
60 extern bool vflip_enabled;
61 extern bool rotate_enabled;
62 extern int wx_escape_count;
64 wxString towxstring(const std::string& str) throw(std::bad_alloc);
65 std::string tostdstring(const wxString& str) throw(std::bad_alloc);
66 wxString towxstring(const std::u32string& str) throw(std::bad_alloc);
67 std::u32string tou32string(const wxString& str) throw(std::bad_alloc);
68 void bring_app_foreground();
69 std::string pick_archive_member(wxWindow* parent, const std::string& filename) throw(std::bad_alloc);
70 void boot_emulator(emulator_instance& inst, loaded_rom& rom, moviefile& movie, bool fscreen);
71 void handle_wx_keyboard(emulator_instance& inst, wxKeyEvent& e, bool polarity);
72 void handle_wx_mouse(emulator_instance& inst, wxMouseEvent& e);
73 std::string map_keycode_to_key(int kcode);
74 void initialize_wx_keyboard(emulator_instance& inst);
75 void deinitialize_wx_keyboard(emulator_instance& inst);
76 void initialize_wx_mouse(emulator_instance& inst);
77 void deinitialize_wx_mouse(emulator_instance& inst);
78 void signal_program_exit();
79 void signal_resize_needed();
80 void _runuifun_async(runuifun_once_ctx* octx, void (*fn)(void*), void* arg);
81 void show_projectwindow(wxWindow* modwin, emulator_instance& inst);
82 void signal_core_change();
83 void do_save_configuration();
85 std::vector<interface_action_paramval> prompt_action_params(wxWindow* parent, const std::string& label,
86 const std::list<interface_action_param>& params);
89 //Editor dialogs.
90 void wxeditor_authors_display(wxWindow* parent, emulator_instance& inst);
91 void wxeditor_hotkeys_display(wxWindow* parent);
92 void wxeditor_memorywatches_display(wxWindow* parent, emulator_instance& inst);
93 void wxeditor_subtitles_display(wxWindow* parent, emulator_instance& inst);
94 std::string wxeditor_keyselect(wxWindow* parent, bool clearable);
95 void show_wxeditor_voicesub(wxWindow* parent, emulator_instance& inst);
96 void open_rom_select_window();
97 void open_new_project_window(wxWindow* parent, emulator_instance& inst);
98 void show_conflictwindow(wxWindow* parent);
99 void open_vumeter_window(wxWindow* parent, emulator_instance& inst);
100 void wxeditor_movie_display(wxWindow* parent, emulator_instance& inst);
101 void wxeditor_movie_update(emulator_instance& inst);
102 void wxeditor_autohold_display(wxWindow* parent, emulator_instance& inst);
103 void wxeditor_tasinput_display(wxWindow* parent, emulator_instance& inst);
104 void wxeditor_macro_display(wxWindow* parent, emulator_instance& inst);
105 void wxeditor_hexedit_display(wxWindow* parent, emulator_instance& inst);
106 void wxeditor_multitrack_display(wxWindow* parent, emulator_instance& inst);
107 bool wxeditor_plugin_manager_display(wxWindow* parent);
108 void wxeditor_tracelog_display(wxWindow* parent, emulator_instance& inst, int cpuid, const std::string& cpuname);
109 void wxeditor_disassembler_display(wxWindow* parent, emulator_instance& inst);
110 void wxeditor_plugin_manager_notify_fail(const std::string& libname);
112 //Auxillary windows.
113 void wxwindow_memorysearch_display(emulator_instance& inst);
114 void wxwindow_memorysearch_update(emulator_instance& inst);
115 void wxeditor_hexeditor_update(emulator_instance& inst);
116 class memory_search;
117 memory_search* wxwindow_memorysearch_active(emulator_instance& inst);
118 bool wxeditor_hexeditor_available(emulator_instance& inst);
119 bool wxeditor_hexeditor_jumpto(emulator_instance& inst, uint64_t addr);
120 void wxwindow_tasinput_update(emulator_instance& inst);
122 template<typename T> void runuifun(T fn) {
123 _runuifun_async(nullptr, functor_call_helper2<T>, new T(fn));
125 template<typename T> void runuifun(runuifun_once_ctx& octx, T fn)
127 _runuifun_async(&octx, functor_call_helper2<T>, new T(fn));
130 //Thrown by various dialog functions if canceled.
131 class canceled_exception : public std::runtime_error
133 public:
134 canceled_exception();
137 //Prompt for stuff. These all can throw canceled_exception.
138 std::string pick_file_member(wxWindow* parent, const std::string& title, const std::string& startdir);
139 unsigned pick_among_index(wxWindow* parent, const std::string& title, const std::string& prompt,
140 const std::vector<std::string>& choices, unsigned defaultchoice = 0);
141 std::string pick_among(wxWindow* parent, const std::string& title, const std::string& prompt,
142 const std::vector<std::string>& choices, unsigned defaultchoice = 0);
143 std::string pick_text(wxWindow* parent, const std::string& title, const std::string& prompt,
144 const std::string& dflt = "", bool multiline = false);
145 //Show message box with OK button.
146 void show_message_ok(wxWindow* parent, const std::string& title, const std::string& text, int icon);
148 //Run function and show errors. Returns true on error.
150 bool run_show_error(wxWindow* parent, const std::string& title, const std::string& text, std::function<void()> fn);
151 void show_exception(wxWindow* parent, const std::string& title, const std::string& text, std::exception& e);
152 void show_exception_any(wxWindow* parent, const std::string& title, const std::string& text, std::exception& e);
154 //Some important windows (if open).
155 extern wxwin_messages* msg_window;
156 extern wxwin_mainwindow* main_window;
157 extern std::string our_rom_name;
158 extern bool wxwidgets_exiting;
160 //Some important settings.
161 extern std::map<std::string, std::string> core_selections;
164 #endif