Fix number of compile errors and warnings with GCC 14
[lsnes.git] / include / platform / wxwidgets / platform.hpp
blob81853e5d870108c7431ef72c5333d9c8228c2818
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);
65 std::string tostdstring(const wxString& str);
66 wxString towxstring(const std::u32string& str);
67 std::u32string tou32string(const wxString& str);
68 std::string pick_archive_member(wxWindow* parent, const std::string& filename);
69 void boot_emulator(emulator_instance& inst, loaded_rom& rom, moviefile& movie, bool fscreen);
70 void handle_wx_keyboard(emulator_instance& inst, wxKeyEvent& e, bool polarity);
71 void handle_wx_mouse(emulator_instance& inst, wxMouseEvent& e);
72 std::string map_keycode_to_key(int kcode);
73 void initialize_wx_keyboard(emulator_instance& inst);
74 void deinitialize_wx_keyboard(emulator_instance& inst);
75 void initialize_wx_mouse(emulator_instance& inst);
76 void deinitialize_wx_mouse(emulator_instance& inst);
77 void signal_program_exit();
78 void signal_resize_needed();
79 void _runuifun_async(runuifun_once_ctx* octx, void (*fn)(void*), void* arg);
80 void show_projectwindow(wxWindow* modwin, emulator_instance& inst);
81 void signal_core_change();
82 void do_save_configuration();
84 std::vector<interface_action_paramval> prompt_action_params(wxWindow* parent, const std::string& label,
85 const std::list<interface_action_param>& params);
88 //Editor dialogs.
89 void wxeditor_authors_display(wxWindow* parent, emulator_instance& inst);
90 void wxeditor_hotkeys_display(wxWindow* parent);
91 void wxeditor_memorywatches_display(wxWindow* parent, emulator_instance& inst);
92 void wxeditor_subtitles_display(wxWindow* parent, emulator_instance& inst);
93 std::string wxeditor_keyselect(wxWindow* parent, bool clearable);
94 void show_wxeditor_voicesub(wxWindow* parent, emulator_instance& inst);
95 void open_rom_select_window();
96 void open_new_project_window(wxWindow* parent, emulator_instance& inst);
97 void show_conflictwindow(wxWindow* parent);
98 void open_vumeter_window(wxWindow* parent, emulator_instance& inst);
99 void wxeditor_movie_display(wxWindow* parent, emulator_instance& inst);
100 void wxeditor_movie_update(emulator_instance& inst);
101 void wxeditor_autohold_display(wxWindow* parent, emulator_instance& inst);
102 void wxeditor_tasinput_display(wxWindow* parent, emulator_instance& inst);
103 void wxeditor_macro_display(wxWindow* parent, emulator_instance& inst);
104 void wxeditor_hexedit_display(wxWindow* parent, emulator_instance& inst);
105 void wxeditor_multitrack_display(wxWindow* parent, emulator_instance& inst);
106 bool wxeditor_plugin_manager_display(wxWindow* parent);
107 void wxeditor_tracelog_display(wxWindow* parent, emulator_instance& inst, int cpuid, const std::string& cpuname);
108 void wxeditor_disassembler_display(wxWindow* parent, emulator_instance& inst);
109 void wxeditor_plugin_manager_notify_fail(const std::string& libname);
111 //Auxillary windows.
112 void wxwindow_memorysearch_display(emulator_instance& inst);
113 void wxwindow_memorysearch_update(emulator_instance& inst);
114 void wxeditor_hexeditor_update(emulator_instance& inst);
115 class memory_search;
116 memory_search* wxwindow_memorysearch_active(emulator_instance& inst);
117 bool wxeditor_hexeditor_available(emulator_instance& inst);
118 bool wxeditor_hexeditor_jumpto(emulator_instance& inst, uint64_t addr);
119 void wxwindow_tasinput_update(emulator_instance& inst);
121 template<typename T> void runuifun(T fn) {
122 _runuifun_async(nullptr, functor_call_helper2<T>, new T(fn));
124 template<typename T> void runuifun(runuifun_once_ctx& octx, T fn)
126 _runuifun_async(&octx, functor_call_helper2<T>, new T(fn));
129 //Thrown by various dialog functions if canceled.
130 class canceled_exception : public std::runtime_error
132 public:
133 canceled_exception();
136 //Prompt for stuff. These all can throw canceled_exception.
137 std::string pick_file_member(wxWindow* parent, const std::string& title, const std::string& startdir);
138 unsigned pick_among_index(wxWindow* parent, const std::string& title, const std::string& prompt,
139 const std::vector<std::string>& choices, unsigned defaultchoice = 0);
140 std::string pick_among(wxWindow* parent, const std::string& title, const std::string& prompt,
141 const std::vector<std::string>& choices, unsigned defaultchoice = 0);
142 std::string pick_text(wxWindow* parent, const std::string& title, const std::string& prompt,
143 const std::string& dflt = "", bool multiline = false);
144 //Show message box with OK button.
145 void show_message_ok(wxWindow* parent, const std::string& title, const std::string& text, int icon);
147 //Run function and show errors. Returns true on error.
149 bool run_show_error(wxWindow* parent, const std::string& title, const std::string& text, std::function<void()> fn);
150 void show_exception(wxWindow* parent, const std::string& title, const std::string& text, std::exception& e);
151 void show_exception_any(wxWindow* parent, const std::string& title, const std::string& text, std::exception& e);
153 //Some important windows (if open).
154 extern wxwin_messages* msg_window;
155 extern wxwin_mainwindow* main_window;
156 extern std::string our_rom_name;
157 extern bool wxwidgets_exiting;
159 //Some important settings.
160 extern std::map<std::string, std::string> core_selections;
163 #endif