From 2097b5aaa59ee5f13a654b0a22d1f9c3687c985f Mon Sep 17 00:00:00 2001 From: Rafael Kitover Date: Thu, 28 Mar 2019 21:45:06 +0000 Subject: [PATCH] wx 2.8 compat fixes, centos support, cmake fixes Add support for RHEL/centos to installdeps. There is no SFML package. Add some string compatibility stuff so that everything builds on wx 2.8 unicode builds. TODO: add travis slaves for 2.8, with and without unicode Disable the game frame spacer code on 2.8 because it does not work (the frame does not expand.) cmake improvements: - set ENABLE_LTO=OFF for Debug builds by default - set ENABLE_LINK=OFF if SFML cannot be found and continue - use better logic for finding wx utilities wx-config and wxrc Signed-off-by: Rafael Kitover Closes #395 Closes #297 --- CMakeLists.txt | 21 +++-- README.md | 4 +- installdeps | 190 +++++++++++++++++++++++++++++++++++++++++- src/wx/CMakeLists.txt | 75 ++++++++++++++--- src/wx/cmdevents.cpp | 36 ++++---- src/wx/guiinit.cpp | 59 +++++++------ src/wx/openal.cpp | 2 +- src/wx/opts.cpp | 48 +++++------ src/wx/panel.cpp | 51 +++++++----- src/wx/sys.cpp | 22 ++--- src/wx/viewers.cpp | 2 +- src/wx/viewsupt.h | 2 +- src/wx/wxvbam.cpp | 56 ++++++------- 13 files changed, 413 insertions(+), 155 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d3748420..ff7fb9ac 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -116,8 +116,9 @@ option(ENABLE_FFMPEG "Enable ffmpeg A/V recording" ${FFMPEG_DEFAULT}) set(LTO_DEFAULT ON) -if(WIN32 AND CMAKE_COMPILER_IS_GNUCXX AND AMD64) - # lto produces buggy binaries for 64 bit win32 +# lto produces buggy binaries for 64 bit win32 +# and we generally don't want it when debugging because it makes linking slow +if((WIN32 AND CMAKE_COMPILER_IS_GNUCXX AND AMD64) OR CMAKE_BUILD_TYPE MATCHES Debug) set(LTO_DEFAULT OFF) endif() @@ -168,7 +169,7 @@ endif() include_directories(${CMAKE_BINARY_DIR}) configure_file("${CMAKE_SOURCE_DIR}/src/version.h.in" "${CMAKE_BINARY_DIR}/version.h" @ONLY) -if(CMAKE_BUILD_TYPE STREQUAL "Debug") +if(CMAKE_BUILD_TYPE MATCHES Debug) add_definitions(-DDEBUG) else() add_definitions(-DNDEBUG) @@ -196,7 +197,11 @@ endif() # Look for some dependencies using CMake scripts find_package(ZLIB REQUIRED) + +set(OpenGL_GL_PREFERENCE GLVND) + find_package(OpenGL REQUIRED) + find_package(PNG REQUIRED) if(EXISTS /etc/redhat-release) @@ -220,7 +225,13 @@ if(ENABLE_LINK) if(WIN32 AND ((NOT (MINGW AND MSYS)) OR CMAKE_TOOLCHAIN_FILE MATCHES mxe) AND NOT CMAKE_TOOLCHAIN_FILE MATCHES vcpkg) set(SFML_STATIC_LIBRARIES TRUE) endif() - find_package(SFML 2 COMPONENTS network system REQUIRED) + + find_package(SFML 2 COMPONENTS network system) + + if(NOT SFML_FOUND) + message(WARNING "SFML not found, LINK will be disabled") + set(ENABLE_LINK NO) + endif() endif() # set the standard libraries all ports use @@ -479,7 +490,7 @@ if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID STREQUAL Clang) set(MY_C_FLAGS ${MY_C_FLAGS} -static-libgcc -static-libstdc++) endif() - if(CMAKE_BUILD_TYPE STREQUAL Debug) + if(CMAKE_BUILD_TYPE MATCHES Debug) set(MY_C_FLAGS ${MY_C_FLAGS} ${MY_C_DBG_FLAGS} -Wall -Wextra) else() set(MY_C_FLAGS ${MY_C_FLAGS} ${MY_C_OPT_FLAGS} -Wno-error) diff --git a/README.md b/README.md index 17a6c440..83467a4c 100644 --- a/README.md +++ b/README.md @@ -60,8 +60,8 @@ cmake .. make -j`nproc` ``` -`./installdeps` is supported on MSys2, Linux (Debian/Ubuntu, Fedora, Arch or -Solus) and Mac OS X (homebrew, macports or fink.) +`./installdeps` is supported on MSys2, Linux (Debian/Ubuntu, Fedora, Arch, +Solus and RHEL/CentOS) and Mac OS X (homebrew, macports or fink.) The Ninja cmake generator is also now supported, including on msys2 and Visual Studio. diff --git a/installdeps b/installdeps index 7ce1e9ad..af0b9361 100755 --- a/installdeps +++ b/installdeps @@ -155,6 +155,8 @@ linux_installdeps() { debian_installdeps elif [ -f /etc/fedora-release ]; then fedora_installdeps + elif [ -f /etc/redhat-release ] || [ -f /etc/centos-release ]; then + rhel_installdeps elif [ -f /etc/arch-release ]; then archlinux_installdeps elif [ -f /etc/solus-release ]; then @@ -407,7 +409,7 @@ fedora_installdeps() { fi # non-multiarch packages first - check sudo dnf -y --nogpgcheck --best --allowerasing install gcc gcc-c++ make cmake ccache git nasm redhat-rpm-config pkgconfig ccache + check sudo dnf -y --nogpgcheck --best --allowerasing install gcc gcc-c++ make cmake ccache git nasm redhat-rpm-config pkgconfig ccache ninja-build # try to install multiarch libgcc, glibc-devel and pkgconfig if available if [ -n "$amd64" ]; then @@ -427,7 +429,7 @@ fedora_installdeps() { # this is sometimes necessary for rawhide set -- --exclude='glibc32*' fi - for pkg in zlib-devel mesa-libGL-devel ffmpeg-devel gettext-devel libpng-devel SDL2-devel SFML-devel openal-soft-devel wxGTK3-devel gtk2-devel gtk3-devel; do + for pkg in zlib-devel mesa-libGL-devel ffmpeg-devel gettext-devel libpng-devel SDL2-devel SFML-devel openal-soft-devel wxGTK3-devel gtk3-devel; do case $pkg in *ffmpeg*) [ -n "$no_ffmpeg" ] && continue @@ -535,6 +537,190 @@ fedora_installdeps() { build_instructions } +rhel_installdeps() { + rhel=1 + ffmpeg=ffmpeg-devel + no_ffmpeg= + rpms_installed= + + check_cross + installing + + warning= + + rhel_release=$(rpm -E %rhel) + tries=3 + curdir=$(pwd) + + # this source is necessary for mingw packages on rhel, and may be for other things in the future + check sudo yum -y install epel-release + + # make sure rpmfusion is installed for ffmpeg + while [ $tries -gt 0 ]; do + mkdir -p "${tmp}/fusion" + cd "${tmp}/fusion" + if ! curl -fLO https://download1.rpmfusion.org/free/el/rpmfusion-free-release-${rhel_release}.noarch.rpm; then + rhel_release=$((rhel_release - 1)) + tries=$((tries - 1)) + continue + fi + if ! curl -fLO https://download1.rpmfusion.org/nonfree/el/rpmfusion-nonfree-release-${rhel_release}.noarch.rpm; then + tries=0 + break + fi + # check if already installed + if rpm -q rpmfusion-free-release-${rhel_release} >/dev/null 2>&1 && rpm -q rpmfusion-nonfree-release-${rhel_release} >/dev/null 2>&1; then + info_msg 'rpmfusion already installed, good' + break + fi + # otherwise try to install + if ! sudo rpm --nodeps -Uvh ./rpmfusion-*.rpm; then + tries=0 + break + fi + break + done + cd "$curdir" + if [ $tries -eq 0 ]; then + warning 'installing rpmfusion repos failed, continuing without ffmpeg' + no_ffmpeg=1 + cmake_flags="$cmake_flags -DENABLE_FFMPEG=NO" + fi + + # non-multiarch packages first + CMAKE=cmake3 + check sudo yum -y install gcc gcc-c++ make cmake3 ccache git nasm redhat-rpm-config pkgconfig ccache ninja-build + + # try to install multiarch libgcc, glibc-devel and pkgconfig if available + if [ -n "$amd64" ]; then + for pkg in pkgconfig libgcc glibc-devel; do + if [ "$target" = m32 ]; then + sudo yum -y install "$pkg".i686 + else + sudo yum -y install "$pkg".x86_64 + fi + done + fi + + set -- + if [ -z "$target" -o "$target" = m32 ]; then + # try to install both 64 bit and 32 bit versions on 64 bit hosts (see below) + if [ -n "$amd64" ]; then + # this is sometimes necessary for rawhide + set -- --exclude='glibc32*' + fi + + warning='RHEL does not currently have SFML packages, LINK support will be disabled' + cmake_flags="$cmake_flags -DENABLE_LINK=NO" + + for pkg in zlib-devel mesa-libGL-devel ffmpeg-devel gettext-devel libpng-devel SDL2-devel openal-soft-devel wxGTK3-devel gtk3-devel wxGTK-devel; do + case $pkg in + *ffmpeg*) + [ -n "$no_ffmpeg" ] && continue + ;; + esac + + if [ -n "$amd64" ]; then + if [ "$target" = m32 ]; then + set -- "$@" "${pkg}.i686" + else + set -- "$@" "${pkg}.x86_64" + fi + else + set -- "$@" "$pkg" + fi + done + + # redhat has a bug where all necessary -devel packages are not pulled in for 32 bit direct -devel deps + # this hack adds them to the list + if [ -n "$amd64" -a "$target" = m32 ]; then + info_msg 'Calculating dependencies, this will take a while..' + curdeps= + newdeps=$@ + while [ "$curdeps" != "$newdeps" ]; do + curdeps=$newdeps + set -- $(echo "$@" $(repoquery --deplist "$@" 2>/dev/null | sed -n 's/\.x86_64$/.i686/; s/^ *provider: *\([^ ]*-devel-.*\)$/\1/p' | sort -u) | sed 's/ */\n/g' | sort -u) + newdeps=$@ + printf '%s' . + done + + echo + info_msg 'Done' + + ## install the RPMs with rpm --force get around file conflicts + + host_rpms=$(echo "$@" | sed 's/\.i686//g') + + # first update the host arch versions to reduce chances of conflicts + check sudo yum -y install $host_rpms + + oldcwd=$PWD + mkdir "$tmp/rpms" + cd "$tmp/rpms" + + check sudo yum -y download "$@" + + # first try installing with yum to pull in deps + check sudo yum -y --skip-broken install *.rpm + + # follow up with rpm --force to ignore conflicts + check sudo rpm -Uvh --force *.rpm + + rm -f *.rpm + + # reinstall the host rpms to make sure any overwritten files are the host version + check sudo yum -y download $host_rpms + + check sudo yum -y --skip-broken install *.rpm + + check sudo rpm -Uvh --force *.rpm + + cd "$oldcwd" + rm -rf "$tmp/rpms" + + ffmpeg=ffmpeg-devel.i686 + + rpms_installed=1 + fi + else # mingw build + set -- "$@" pkgconfig + case "$target" in + mingw-w64-i686) + target=mingw32 + cmake_flags="$cmake_flags -DCMAKE_TOOLCHAIN_FILE=../cmake/Toolchain-cross-MinGW-w64-i686.cmake -DENABLE_LINK=NO" + ;; + mingw-w64-x86_64) + target=mingw64 + cmake_flags="$cmake_flags -DCMAKE_TOOLCHAIN_FILE=../cmake/Toolchain-cross-MinGW-w64-x86_64.cmake -DENABLE_LINK=NO" + ;; + *) + error 'unknown cross target (this should not happen)' + ;; + esac + # install static deps + for pkg in zlib gettext libpng SDL2 wxWidgets; do + set -- "$@" "${target}-${pkg}-static" + done + # install deps that are not available as static + for pkg in openal-soft; do + set -- "$@" "${target}-${pkg}" + done + + warning='SFML is required for LINK support, RHEL/EPEL does not currently have a MinGW SFML package, if you want LINK support you will need to install it manually' + fi + + [ -z "$rpms_installed" ] && check sudo yum -y install "$@" + + if ! rpm -q $ffmpeg >/dev/null 2>&1; then + warning 'ffmpeg failed to install (probably due to conflicts)' + cmake_flags="$cmake_flags -DENABLE_FFMPEG=NO" + fi + + [ -n "$warning" ] && warning "$warning" + + build_instructions +} + suse_installdeps() { suse=1 check_cross diff --git a/src/wx/CMakeLists.txt b/src/wx/CMakeLists.txt index b9637c55..50785037 100644 --- a/src/wx/CMakeLists.txt +++ b/src/wx/CMakeLists.txt @@ -68,7 +68,7 @@ endif() if(WIN32 AND CMAKE_TOOLCHAIN_FILE MATCHES vcpkg AND (X86_32 OR AMD64)) # set up wxwidgets stuff add_definitions(-D_UNICODE -DUNICODE -DWXUSINGDLL -DwxUSE_GUI=1 -D__WXMSW__) - if("${CMAKE_BUILD_TYPE}" MATCHES "Debug") + if(CMAKE_BUILD_TYPE MATCHES Debug) add_definitions(-D_DEBUG) include_directories(${_VCPKG_INSTALLED_DIR}/${WINARCH}-windows/debug/lib/mswud) include_directories(${_VCPKG_INSTALLED_DIR}/${WINARCH}-windows/include) @@ -117,7 +117,7 @@ if(WIN32 AND CMAKE_TOOLCHAIN_FILE MATCHES vcpkg AND (X86_32 OR AMD64)) file(COPY ${_VCPKG_ROOT_DIR}/installed/${WINARCH}-windows/bin/SDL2.dll DESTINATION ${CMAKE_BINARY_DIR}) endif() else() - if(CMAKE_BUILD_TYPE STREQUAL "Debug") + if(CMAKE_BUILD_TYPE MATCHES Debug) set(wxWidgets_USE_DEBUG ON) # noop if wx is compiled with --disable-debug, like in Mac Homebrew atm endif() @@ -156,12 +156,42 @@ else() set(wxWidgets_USE_UNICODE ON) + function(find_wx_util var util) + foreach(conf_suffix gtk4 gtk3 "") + foreach(major_version 4 3 2 "") + foreach(minor_version RANGE 0 101) + unset(suffix) + if(conf_suffix) + set(suffix "-${conf_suffix}") + endif() + if(major_version) + set(suffix "${suffix}-${major_version}") + endif() + if(NOT minor_version EQUAL 101) + set(suffix "${suffix}.${minor_version}") + endif() + + find_program(${var} NAMES "${util}${suffix}") + + if(${${var}}) + return() + endif() + endforeach() + endforeach() + endforeach() + endfunction() + # Check for gtk4 then gtk3 packages first, some dists like arch rename the # wx-config utility for these packages to e.g. wx-config-gtk3 # - # Do not do the check if the WX_CONFIG env var is set. - if(NOT WIN32 AND NOT APPLE AND "$ENV{WX_CONFIG}" STREQUAL "") - find_program(wxWidgets_CONFIG_EXECUTABLE NAMES wx-config-gtk4 wx-config-gtk3 wx-config) + # Do not do the check if the WX_CONFIG env var is set or the cmake variable + # is set + if(NOT wxWidgets_CONFIG_EXECUTABLE) + if(DEFINED ENV{WX_CONFIG}) + separate_arguments(wxWidgets_CONFIG_EXECUTABLE UNIX_COMMAND $ENV{WX_CONFIG}) + else() + find_wx_util(wxWidgets_CONFIG_EXECUTABLE wx-config) + endif() endif() # adv is for wxAboutBox @@ -180,7 +210,7 @@ else() include_directories(${wxWidgets_INCLUDE_DIRS}) - if(CMAKE_BUILD_TYPE STREQUAL "Debug") + if(CMAKE_BUILD_TYPE MATCHES Debug) # tell wx to enable debug mode if possible, if the cmake module did not do it for us execute_process(COMMAND "${wxWidgets_CONFIG_EXECUTABLE} --debug=yes" RESULT_VARIABLE WX_CONFIG_DEBUG OUTPUT_QUIET ERROR_QUIET) @@ -257,13 +287,19 @@ int WINAPI DetourMessageBoxA(HWND hWnd, LPCSTR lpText, LPCSTR lpCaption, UINT uT class MyApp : public wxAppConsole { public: virtual bool OnInit(); + // this is necessary for 2.8 to make the class non-abstract + virtual int OnRun() { return 0; } }; bool MyApp::OnInit() { exit(0); } +#if wxCHECK_VERSION(2, 9, 0) wxIMPLEMENT_APP_NO_MAIN(MyApp); +#else +IMPLEMENT_APP_NO_MAIN(MyApp); +#endif int main(int argc, char** argv) { @@ -518,8 +554,27 @@ include(HostCompile) host_compile(${CMAKE_CURRENT_SOURCE_DIR}/bin2c.c ${BIN2C}) if(WXRC) - separate_arguments(WXRC UNIX_COMMAND "${WXRC}") -else() + separate_arguments(WXRC UNIX_COMMAND ${WXRC}) +elseif(DEFINED ENV{WXRC}) + separate_arguments(WXRC UNIX_COMMAND $ENV{WXRC}) +elseif(wxWidgets_CONFIG_EXECUTABLE) + execute_process( + COMMAND ${wxWidgets_CONFIG_EXECUTABLE} --utility=wxrc + OUTPUT_VARIABLE WXRC + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + # check if the path from wx-config is good + if(NOT EXISTS ${WXRC}) + unset(WXRC) + endif() +endif() + +if(NOT WXRC) + find_wx_util(WXRC wxrc) +endif() + +if(NOT WXRC) + message(WARNING "could not find your wxrc executable") set(WXRC wxrc) endif() @@ -723,7 +778,7 @@ endif() if(CMAKE_COMPILER_IS_GNUCXX) if(WIN32) # Build a console app in debug mode on Windows - if(CMAKE_BUILD_TYPE STREQUAL Debug) + if(CMAKE_BUILD_TYPE MATCHES Debug) set(CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE} -Wl,--subsystem,console") else() set(CMAKE_CXX_LINK_EXECUTABLE "${CMAKE_CXX_LINK_EXECUTABLE} -Wl,--subsystem,windows") @@ -767,7 +822,7 @@ if(APPLE) # bundle dylibs and relink them for releasing .app # also install translations into the .app # but only in Release mode - if(NOT CMAKE_BUILD_TYPE STREQUAL "Debug") + if(NOT CMAKE_BUILD_TYPE MATCHES Debug) add_custom_command( TARGET visualboyadvance-m POST_BUILD COMMAND ${CMAKE_SOURCE_DIR}/tools/osx/third_party_libs_tool ./visualboyadvance-m.app diff --git a/src/wx/cmdevents.cpp b/src/wx/cmdevents.cpp index 416962a1..fa75dd98 100644 --- a/src/wx/cmdevents.cpp +++ b/src/wx/cmdevents.cpp @@ -527,7 +527,7 @@ EVT_HANDLER_MASK(RomInformation, "ROM information...", CMDEN_GB | CMDEN_GBA) } while (0) #define setblabs(id, b, ts) \ do { \ - s.Printf(wxT("%02x (%s)"), (unsigned int)b, ts); \ + s.Printf(wxT("%02x (%s)"), (unsigned int)b, ts.c_str()); \ setlab(id); \ } while (0) #define setlabs(id, ts, l) \ @@ -865,9 +865,9 @@ EVT_HANDLER_MASK(ImportBatteryFile, "Import battery file...", CMDEN_GB | CMDEN_G wxString msg; if (panel->emusys->emuReadBattery(fn.mb_fn_str())) - msg.Printf(_("Loaded battery %s"), fn.mb_str()); + msg.Printf(_("Loaded battery %s"), fn.c_str()); else - msg.Printf(_("Error loading battery %s"), fn.mb_str()); + msg.Printf(_("Error loading battery %s"), fn.c_str()); systemScreenMessage(msg); } @@ -903,7 +903,7 @@ EVT_HANDLER_MASK(ImportGamesharkCodeFile, "Import GameShark code file...", CMDEN wxFFile f(fn, wxT("rb")); if (!f.IsOpened()) { - wxLogError(_("Cannot open file %s"), fn.mb_str()); + wxLogError(_("Cannot open file %s"), fn.c_str()); return; } @@ -913,7 +913,7 @@ EVT_HANDLER_MASK(ImportGamesharkCodeFile, "Import GameShark code file...", CMDEN char buf[14]; if (f.Read(&len, sizeof(len)) != sizeof(len) || wxUINT32_SWAP_ON_BE(len) != 14 || f.Read(buf, 14) != 14 || memcmp(buf, "SharkPortCODES", 14)) { - wxLogError(_("Unsupported code file %s"), fn.mb_str()); + wxLogError(_("Unsupported code file %s"), fn.c_str()); return; } @@ -983,9 +983,9 @@ EVT_HANDLER_MASK(ImportGamesharkCodeFile, "Import GameShark code file...", CMDEN } if (res) - msg.Printf(_("Loaded code file %s"), fn.mb_str()); + msg.Printf(_("Loaded code file %s"), fn.c_str()); else - msg.Printf(_("Error loading code file %s"), fn.mb_str()); + msg.Printf(_("Error loading code file %s"), fn.c_str()); systemScreenMessage(msg); } @@ -1031,9 +1031,9 @@ EVT_HANDLER_MASK(ImportGamesharkActionReplaySnapshot, } if (res) - msg.Printf(_("Loaded snapshot file %s"), fn.mb_str()); + msg.Printf(_("Loaded snapshot file %s"), fn.c_str()); else - msg.Printf(_("Error loading snapshot file %s"), fn.mb_str()); + msg.Printf(_("Error loading snapshot file %s"), fn.c_str()); systemScreenMessage(msg); } @@ -1056,9 +1056,9 @@ EVT_HANDLER_MASK(ExportBatteryFile, "Export battery file...", CMDEN_GB | CMDEN_G wxString msg; if (panel->emusys->emuWriteBattery(fn.mb_fn_str())) - msg.Printf(_("Wrote battery %s"), fn.mb_str()); + msg.Printf(_("Wrote battery %s"), fn.c_str()); else - msg.Printf(_("Error writing battery %s"), fn.mb_str()); + msg.Printf(_("Error writing battery %s"), fn.c_str()); systemScreenMessage(msg); } @@ -1097,11 +1097,11 @@ EVT_HANDLER_MASK(ExportGamesharkSnapshot, "Export GameShark snapshot...", CMDEN_ // FIXME: this will fail on big-endian machines if file format is // little-endian // fix in GBA.cpp - if (CPUWriteGSASnapshot(fn.mb_str(), tit->GetValue().mb_str(), - dsc->GetValue().mb_str(), n->GetValue().mb_str())) - msg.Printf(_("Saved snapshot file %s"), fn.mb_str()); + if (CPUWriteGSASnapshot(fn.utf8_str(), tit->GetValue().utf8_str(), + dsc->GetValue().utf8_str(), n->GetValue().utf8_str())) + msg.Printf(_("Saved snapshot file %s"), fn.c_str()); else - msg.Printf(_("Error saving snapshot file %s"), fn.mb_str()); + msg.Printf(_("Error saving snapshot file %s"), fn.c_str()); systemScreenMessage(msg); } @@ -1141,7 +1141,7 @@ EVT_HANDLER_MASK(ScreenCapture, "Screen capture...", CMDEN_GB | CMDEN_GBA) panel->emusys->emuWriteBMP(fn.mb_fn_str()); wxString msg; - msg.Printf(_("Wrote snapshot %s"), fn.mb_str()); + msg.Printf(_("Wrote snapshot %s"), fn.c_str()); systemScreenMessage(msg); } @@ -1937,7 +1937,7 @@ void MainFrame::GDBBreak() if (!debugOpenPty()) return; - msg.Printf(_("Waiting for connection at %s"), debugGetSlavePty().mb_str()); + msg.Printf(_("Waiting for connection at %s"), debugGetSlavePty().c_str()); } else #endif { @@ -2242,7 +2242,7 @@ EVT_HANDLER(GameBoyAdvanceConfigure, "Game Boy Advance options...") vba_over.append(wxTextFile::GetEOL()); fn.Mkdir(0777, wxPATH_MKDIR_FULL); wxTempFileOutputStream fos(fn.GetFullPath()); - fos.Write(vba_over.mb_str(), vba_over.size()); + fos.Write(vba_over.c_str(), vba_over.size()); fos.Commit(); } } diff --git a/src/wx/guiinit.cpp b/src/wx/guiinit.cpp index e958385f..6018ddc8 100644 --- a/src/wx/guiinit.cpp +++ b/src/wx/guiinit.cpp @@ -17,7 +17,6 @@ #include #include #include -#include #include #include #include @@ -88,7 +87,7 @@ public: return; if (!server) { - bool valid = SetLinkServerHost(gopts.link_host.mb_str()); + bool valid = SetLinkServerHost(gopts.link_host.c_str()); if (!valid) { wxMessageBox(_("You must enter a valid host name"), @@ -111,10 +110,10 @@ public: char host[length]; GetLinkServerHost(host, length); title.Printf(_("Waiting for clients...")); - connmsg.Printf(_("Server IP address is: %s\n"), wxString(host, wxConvLibc).mb_str()); + connmsg.Printf(_("Server IP address is: %s\n"), wxString(host, wxConvLibc).c_str()); } else { title.Printf(_("Waiting for connection...")); - connmsg.Printf(_("Connecting to %s\n"), gopts.link_host.mb_str()); + connmsg.Printf(_("Connecting to %s\n"), gopts.link_host.c_str()); } // Init link @@ -436,9 +435,9 @@ public: if (isgb) { if (!ce_type) - gbAddGsCheat(tok.mb_str(), ce_desc.mb_str()); + gbAddGsCheat(tok.utf8_str(), ce_desc.utf8_str()); else - gbAddGgCheat(tok.mb_str(), ce_desc.mb_str()); + gbAddGgCheat(tok.utf8_str(), ce_desc.utf8_str()); } else { // Flashcart CHT format if (tok.Contains(wxT("="))) { @@ -446,16 +445,16 @@ public: } // Generic Code else if (tok.Contains(wxT(":"))) - cheatsAddCheatCode(tok.mb_str(), ce_desc.mb_str()); + cheatsAddCheatCode(tok.utf8_str(), ce_desc.utf8_str()); // following determination of type by lengths is // same used by win32 and gtk code // and like win32/gtk code, user-chosen fmt is ignored else if (tok.size() == 12) { tok = tok.substr(0, 8) + wxT(' ') + tok.substr(8); - cheatsAddCBACode(tok.mb_str(), ce_desc.mb_str()); + cheatsAddCBACode(tok.utf8_str(), ce_desc.utf8_str()); } else if (tok.size() == 16) // not sure why 1-tok is !v3 and 2-tok is v3.. - cheatsAddGSACode(tok.mb_str(), ce_desc.mb_str(), false); + cheatsAddGSACode(tok.utf8_str(), ce_desc.utf8_str(), false); // CBA codes are assumed to be N+4, and anything else // is assumed to be GSA v3 (although I assume the // actual formats should be 8+4 and 8+8) @@ -463,18 +462,18 @@ public: if (!tk.HasMoreTokens()) { // throw an error appropriate to chosen type if (ce_type == 1) // GSA - cheatsAddGSACode(tok.mb_str(), ce_desc.mb_str(), false); + cheatsAddGSACode(tok.utf8_str(), ce_desc.utf8_str(), false); else - cheatsAddCBACode(tok.mb_str(), ce_desc.mb_str()); + cheatsAddCBACode(tok.utf8_str(), ce_desc.utf8_str()); } else { wxString tok2 = tk.GetNextToken(); if (tok2.size() == 4) { tok += wxT(' ') + tok2; - cheatsAddCBACode(tok.mb_str(), ce_desc.mb_str()); + cheatsAddCBACode(tok.utf8_str(), ce_desc.utf8_str()); } else { tok += tok2; - cheatsAddGSACode(tok.mb_str(), ce_desc.mb_str(), true); + cheatsAddGSACode(tok.utf8_str(), ce_desc.utf8_str(), true); } } } @@ -624,7 +623,7 @@ public: } else if (ce_desc != odesc) { *dirty = true; char* p = isgb ? gbCheatList[id].cheatDesc : cheatsList[id].desc; - strncpy(p, ce_desc.mb_str(), sizeof(cheatsList[0].desc)); + strncpy(p, ce_desc.utf8_str(), sizeof(cheatsList[0].desc)); p[sizeof(cheatsList[0].desc) - 1] = 0; item1.SetId(id); item1.SetText(wxString(p, wxConvUTF8)); @@ -674,7 +673,7 @@ void CheatList_t::ParseChtLine(wxString desc, wxString tok) wxString cheat_value; uint32_t address = 0; uint32_t value = 0; - sscanf(cheat_addr.mb_str(), "%8x", &address); + sscanf(cheat_addr.utf8_str(), "%8x", &address); if (address < 0x40000) address += 0x2000000; @@ -685,11 +684,11 @@ void CheatList_t::ParseChtLine(wxString desc, wxString tok) while (value_tk.HasMoreTokens()) { wxString value_token = value_tk.GetNextToken(); - sscanf(value_token.mb_str(), "%2x", &value); + sscanf(value_token.utf8_str(), "%2x", &value); cheat_line.Printf(wxT("%08X"), address); cheat_value.Printf(wxT("%02X"), value); cheat_line = cheat_line + wxT(":") + cheat_value; - cheatsAddCheatCode(cheat_line.mb_str(), cheat_desc.mb_str()); + cheatsAddCheatCode(cheat_line.utf8_str(), cheat_desc.utf8_str()); address++; } } @@ -1070,7 +1069,7 @@ public: for (int i = 0; i < (1 << size); i++) { addr_s.Printf(wxT("%02X%02X%02X%02X"), bank, val & 0xff, addr & 0xff, addr >> 8); - gbAddGsCheat(addr_s.mb_str(), ca_desc.mb_str()); + gbAddGsCheat(addr_s.utf8_str(), ca_desc.utf8_str()); val >>= 8; addr++; } @@ -1092,7 +1091,7 @@ public: } addr_s.append(s); - cheatsAddCheatCode(addr_s.mb_str(), ca_desc.mb_str()); + cheatsAddCheatCode(addr_s.utf8_str(), ca_desc.utf8_str()); } } @@ -1572,7 +1571,7 @@ public: if (newapi == lastapi) return; - gopts.audio_dev = ""; + gopts.audio_dev = wxT(""); FillDev(newapi); } } sound_config_handler; @@ -1812,7 +1811,7 @@ public: // to put the plugins... it depends on where program was // installed, and of course OS wxString msg; - msg.Printf(_("No usable rpi plugins found in %s"), plpath.mb_str()); + msg.Printf(_("No usable rpi plugins found in %s"), plpath.c_str()); systemScreenMessage(msg); ch->Hide(); txt->Hide(); @@ -2357,7 +2356,7 @@ void CheckThrowXRCError(T pointer, const wxString& name) std::string errormessage = "Unable to load a \""; errormessage += typeid(pointer).name(); errormessage += "\" from the builtin xrc file: "; - errormessage += name.mb_str(); + errormessage += name.utf8_str(); throw std::runtime_error(errormessage); } } @@ -2760,9 +2759,9 @@ bool MainFrame::BindControls() if (a->GetFlags() == e->GetFlags() && a->GetKeyCode() == e->GetKeyCode()) { if (e->GetMenuItem()) { wxLogInfo(_("Duplicate menu accelerator: %s for %s and %s; keeping first"), - wxKeyTextCtrl::ToString(a->GetFlags(), a->GetKeyCode()).mb_str(), - e->GetMenuItem()->GetItemLabelText().mb_str(), - mi->GetItemLabelText().mb_str()); + wxKeyTextCtrl::ToString(a->GetFlags(), a->GetKeyCode()).c_str(), + e->GetMenuItem()->GetItemLabelText().c_str(), + mi->GetItemLabelText().c_str()); delete a; a = 0; } else { @@ -2774,9 +2773,9 @@ bool MainFrame::BindControls() break; wxLogInfo(_("Menu accelerator %s for %s overrides default for %s ; keeping menu"), - wxKeyTextCtrl::ToString(a->GetFlags(), a->GetKeyCode()).mb_str(), - mi->GetItemLabelText().mb_str(), - cmdtab[cmd].cmd); + wxKeyTextCtrl::ToString(a->GetFlags(), a->GetKeyCode()).c_str(), + mi->GetItemLabelText().c_str(), + cmdtab[cmd].cmd.c_str()); } sys_accels.erase(e); @@ -2880,7 +2879,7 @@ bool MainFrame::BindControls() for (int i = 0; i < checkable_mi.size(); i++) if (!checkable_mi[i].boolopt && !checkable_mi[i].intopt) { wxLogError(_("Invalid menu item %s; removing"), - checkable_mi[i].mi->GetItemLabelText().mb_str()); + checkable_mi[i].mi->GetItemLabelText().c_str()); checkable_mi[i].mi->GetMenu()->Remove(checkable_mi[i].mi); checkable_mi[i].mi = NULL; } @@ -3784,7 +3783,7 @@ bool MainFrame::BindControls() bool isv = !gopts.link_host.empty(); if (isv) { - isv = SetLinkServerHost(gopts.link_host.mb_str()); + isv = SetLinkServerHost(gopts.link_host.c_str()); } if (!isv) { diff --git a/src/wx/openal.cpp b/src/wx/openal.cpp index c3a4393a..7f4245ad 100644 --- a/src/wx/openal.cpp +++ b/src/wx/openal.cpp @@ -148,7 +148,7 @@ bool OpenAL::init(long sampleRate) assert(initialized == false); if (!gopts.audio_dev.empty()) { - device = alcOpenDevice(gopts.audio_dev.mb_str()); + device = alcOpenDevice(gopts.audio_dev.utf8_str()); } else { device = alcOpenDevice(NULL); } diff --git a/src/wx/opts.cpp b/src/wx/opts.cpp index 5ea9d72f..f1df598a 100644 --- a/src/wx/opts.cpp +++ b/src/wx/opts.cpp @@ -374,7 +374,7 @@ void load_opts() for (cont = cfg->GetFirstEntry(s, grp_idx); cont; cont = cfg->GetNextEntry(s, grp_idx)) { - //wxLogWarning(_("Invalid option %s present; removing if possible"), s.mb_str()); + //wxLogWarning(_("Invalid option %s present; removing if possible"), s.c_str()); item_del.push_back(s); } @@ -412,7 +412,7 @@ void load_opts() for (cont = cfg->GetFirstGroup(e, key_idx); cont; cont = cfg->GetNextGroup(e, key_idx)) { s.append(e); - //wxLogWarning(_("Invalid option group %s present; removing if possible"), s.mb_str()); + //wxLogWarning(_("Invalid option group %s present; removing if possible"), s.c_str()); grp_del.push_back(s); s.resize(poff2); } @@ -427,7 +427,7 @@ void load_opts() if (i == NUM_KEYS) { s.append(e); - //wxLogWarning(_("Invalid option %s present; removing if possible"), s.mb_str()); + //wxLogWarning(_("Invalid option %s present; removing if possible"), s.c_str()); item_del.push_back(s); s.resize(poff2); } @@ -439,7 +439,7 @@ void load_opts() } else { s.append(wxT('/')); s.append(e); - //wxLogWarning(_("Invalid option group %s present; removing if possible"), s.mb_str()); + //wxLogWarning(_("Invalid option group %s present; removing if possible"), s.c_str()); grp_del.push_back(s); s.resize(poff); } @@ -454,7 +454,7 @@ void load_opts() if (!std::binary_search(&cmdtab[0], &cmdtab[ncmds], dummy, cmditem_lt)) { s.append(wxT('/')); s.append(e); - //wxLogWarning(_("Invalid option %s present; removing if possible"), s.mb_str()); + //wxLogWarning(_("Invalid option %s present; removing if possible"), s.c_str()); item_del.push_back(s); s.resize(poff); } @@ -465,7 +465,7 @@ void load_opts() wxString opt_name(dummy.opt); if (!std::binary_search(&opts[0], &opts[num_opts], dummy, opt_lt) && opt_name != wxT("General/LastUpdated") && opt_name != wxT("General/LastUpdatedFileName")) { - //wxLogWarning(_("Invalid option %s present; removing if possible"), s.mb_str()); + //wxLogWarning(_("Invalid option %s present; removing if possible"), s.c_str()); item_del.push_back(s); } @@ -510,9 +510,9 @@ void load_opts() // technically, the translation for this string could incorproate // the equals sign if necessary instead of doing it this way wxLogWarning(_("Invalid value %s for option %s; valid values are %s%s%s"), - s, opt.opt, ev, + s.c_str(), opt.opt.c_str(), ev.c_str(), isx ? wxT(" = ") : wxT(""), - isx ? evx : wxT("")); + isx ? evx.c_str() : wxT("")); // write first option cfg->Write(opt.opt, enum_opts[0]); } else @@ -526,14 +526,14 @@ void load_opts() cfg->Read(opt.opt, &opt.curint, *opt.intopt); if (opt.curint < opt.min || opt.curint > opt.max) { - wxLogWarning(_("Invalid value %d for option %s; valid values are %d - %d"), opt.curint, opt.opt, opt.min, opt.max); + wxLogWarning(_("Invalid value %d for option %s; valid values are %d - %d"), opt.curint, opt.opt.c_str(), opt.min, opt.max); } else *opt.intopt = opt.curint; } else if (opt.doubleopt) { cfg->Read(opt.opt, &opt.curdouble, *opt.doubleopt); if (opt.curdouble < opt.min || opt.curdouble > opt.max) { - wxLogWarning(_("Invalid value %f for option %s; valid values are %f - %f"), opt.curdouble, opt.opt, opt.min, opt.max); + wxLogWarning(_("Invalid value %f for option %s; valid values are %f - %f"), opt.curdouble, opt.opt.c_str(), opt.min, opt.max); } else *opt.doubleopt = opt.curdouble; } else if (opt.uintopt) { @@ -542,7 +542,7 @@ void load_opts() opt.curuint = val; if (opt.curuint < opt.min || opt.curuint > opt.max) { - wxLogWarning(_("Invalid value %f for option %s; valid values are %f - %f"), opt.curuint, opt.opt, opt.min, opt.max); + wxLogWarning(_("Invalid value %f for option %s; valid values are %f - %f"), opt.curuint, opt.opt.c_str(), opt.min, opt.max); } else *opt.uintopt = opt.curuint; } else if (opt.boolopt) { @@ -594,14 +594,14 @@ void load_opts() for (int i = 0; i < 4; i++) { for (int j = 0; j < NUM_KEYS; j++) { wxString optname; - optname.Printf(wxT("Joypad/%d/%s"), i + 1, joynames[j]); + optname.Printf(wxT("Joypad/%d/%s"), i + 1, joynames[j].c_str()); bool gotit = cfg->Read(optname, &s); if (gotit) { gopts.joykey_bindings[i][j] = wxJoyKeyTextCtrl::FromString(s); if (s.size() && !gopts.joykey_bindings[i][j].size()) - wxLogWarning(_("Invalid key binding %s for %s"), s.mb_str(), optname.mb_str()); + wxLogWarning(_("Invalid key binding %s for %s"), s.c_str(), optname.c_str()); } else { s = wxJoyKeyTextCtrl::ToString(gopts.joykey_bindings[i][j]); cfg->Write(optname, s); @@ -622,7 +622,7 @@ void load_opts() wxAcceleratorEntry_v val = wxKeyTextCtrl::FromString(s); if (!val.size()) - wxLogWarning(_("Invalid key binding %s for %s"), s.mb_str(), kbopt.mb_str()); + wxLogWarning(_("Invalid key binding %s for %s"), s.c_str(), kbopt.c_str()); else { for (int j = 0; j < val.size(); j++) val[j].Set(val[j].GetFlags(), val[j].GetKeyCode(), @@ -670,7 +670,7 @@ void update_opts() cfg->Write(opt.opt, (opt.curdouble = *opt.doubleopt)); } else if (opt.uintopt) { if (*opt.uintopt != opt.curuint) - cfg->Write(opt.opt, (opt.curuint = *opt.uintopt)); + cfg->Write(opt.opt, (long)(opt.curuint = *opt.uintopt)); } else if (opt.boolopt) { if (*opt.boolopt != opt.curbool) cfg->Write(opt.opt, (opt.curbool = *opt.boolopt)); @@ -708,7 +708,7 @@ void update_opts() for (int j = 0; j < NUM_KEYS; j++) { wxString s, o; wxString optname; - optname.Printf(wxT("Joypad/%d/%s"), i + 1, joynames[j]); + optname.Printf(wxT("Joypad/%d/%s"), i + 1, joynames[j].c_str()); s = wxJoyKeyTextCtrl::ToString(gopts.joykey_bindings[i][j]); cfg->Read(optname, &o); @@ -786,7 +786,7 @@ bool opt_set(const wxString& name, const wxString& val) else if (opt->boolopt) { if (!(val == wxT('0') || val == wxT('1'))) wxLogWarning(_("Invalid flag option %s - %s ignored"), - name, val); + name.c_str(), val.c_str()); else *opt->boolopt = val == wxT('1'); } else if (!opt->enumvals.empty()) { @@ -803,9 +803,9 @@ bool opt_set(const wxString& name, const wxString& val) // technically, the translation for this string could incorproate // the equals sign if necessary instead of doing it this way wxLogWarning(_("Invalid value %s for option %s; valid values are %s%s%s"), - s, opt->opt, opt->enumvals, + s.c_str(), opt->opt.c_str(), opt->enumvals.c_str(), isx ? wxT(" = ") : wxT(""), - isx ? evx : wxT("")); + isx ? evx.c_str() : wxT("")); } else { *opt->intopt = found_pos; } @@ -814,7 +814,7 @@ bool opt_set(const wxString& name, const wxString& val) long ival; if (!s.ToLong(&ival) || ival < opt->min || ival > opt->max) - wxLogWarning(_("Invalid value %d for option %s; valid values are %d - %d"), ival, name, opt->min, opt->max); + wxLogWarning(_("Invalid value %d for option %s; valid values are %d - %d"), ival, name.c_str(), opt->min, opt->max); else *opt->intopt = ival; } else if (opt->doubleopt) { @@ -822,7 +822,7 @@ bool opt_set(const wxString& name, const wxString& val) double dval; if (!s.ToDouble(&dval) || dval < opt->min || dval > opt->max) - wxLogWarning(_("Invalid value %f for option %s; valid values are %f - %f"), dval, name, opt->min, opt->max); + wxLogWarning(_("Invalid value %f for option %s; valid values are %f - %f"), dval, name.c_str(), opt->min, opt->max); else *opt->doubleopt = dval; } else if (opt->uintopt) { @@ -830,7 +830,7 @@ bool opt_set(const wxString& name, const wxString& val) unsigned long uival; if (!s.ToULong(&uival) || uival < opt->min || uival > opt->max) - wxLogWarning(_("Invalid value %f for option %s; valid values are %f - %f"), uival, name, opt->min, opt->max); + wxLogWarning(_("Invalid value %f for option %s; valid values are %f - %f"), uival, name.c_str(), opt->min, opt->max); else *opt->uintopt = (uint32_t)uival; } else { @@ -899,7 +899,7 @@ bool opt_set(const wxString& name, const wxString& val) cmd->cmd_id); if (!aval.size()) - wxLogWarning(_("Invalid key binding %s for %s"), val, name); + wxLogWarning(_("Invalid key binding %s for %s"), val.c_str(), name.c_str()); else gopts.accels.insert(gopts.accels.end(), aval.begin(), aval.end()); } @@ -925,7 +925,7 @@ bool opt_set(const wxString& name, const wxString& val) auto b = wxJoyKeyTextCtrl::FromString(val); if (!b.size()) - wxLogWarning(_("Invalid key binding %s for %s"), val, name); + wxLogWarning(_("Invalid key binding %s for %s"), val.c_str(), name.c_str()); else gopts.joykey_bindings[jno][kno] = b; } diff --git a/src/wx/panel.cpp b/src/wx/panel.cpp index 40d49b27..b48ff07c 100644 --- a/src/wx/panel.cpp +++ b/src/wx/panel.cpp @@ -83,7 +83,7 @@ void GameArea::LoadGame(const wxString& name) if (t == IMAGE_UNKNOWN) { wxString s; - s.Printf(_("%s is not a valid ROM file"), name.mb_str()); + s.Printf(_("%s is not a valid ROM file"), name.c_str()); wxMessageDialog dlg(GetParent(), s, _("Problem loading file"), wxOK | wxICON_ERROR); dlg.ShowModal(); return; @@ -140,7 +140,7 @@ void GameArea::LoadGame(const wxString& name) if (t == IMAGE_GB) { if (!gbLoadRom(fn)) { wxString s; - s.Printf(_("Unable to load Game Boy ROM %s"), name.mb_str()); + s.Printf(_("Unable to load Game Boy ROM %s"), name.c_str()); wxMessageDialog dlg(GetParent(), s, _("Problem loading file"), wxOK | wxICON_ERROR); dlg.ShowModal(); return; @@ -192,7 +192,7 @@ void GameArea::LoadGame(const wxString& name) gbCPUInit(fn, use_bios); if (use_bios && !useBios) { - wxLogError(_("Could not load BIOS %s"), (gbCgbMode ? gopts.gbc_bios : gopts.gb_bios).mb_str()); + wxLogError(_("Could not load BIOS %s"), (gbCgbMode ? gopts.gbc_bios : gopts.gb_bios).c_str()); // could clear use flag & file name now, but better to force // user to do it } @@ -215,7 +215,7 @@ void GameArea::LoadGame(const wxString& name) { if (!(rom_size = CPULoadRom(fn))) { wxString s; - s.Printf(_("Unable to load Game Boy Advance ROM %s"), name.mb_str()); + s.Printf(_("Unable to load Game Boy Advance ROM %s"), name.c_str()); wxMessageDialog dlg(GetParent(), s, _("Problem loading file"), wxOK | wxICON_ERROR); dlg.ShowModal(); return; @@ -285,7 +285,7 @@ void GameArea::LoadGame(const wxString& name) CPUInit(gopts.gba_bios.mb_fn_str(), useBiosFileGBA); if (useBiosFileGBA && !useBios) { - wxLogError(_("Could not load BIOS %s"), gopts.gba_bios.mb_str()); + wxLogError(_("Could not load BIOS %s"), gopts.gba_bios.c_str()); // could clear use flag & file name now, but better to force // user to do it } @@ -354,7 +354,7 @@ void GameArea::LoadGame(const wxString& name) if (emusys->emuReadBattery(fnb.data())) { wxString msg; - msg.Printf(_("Loaded battery %s"), bat.GetFullPath().mb_str()); + msg.Printf(_("Loaded battery %s"), bat.GetFullPath().c_str()); systemScreenMessage(msg); if (cpuSaveType == 0 && ovSaveType == 0 && t == IMAGE_GBA) { @@ -572,7 +572,7 @@ bool GameArea::LoadState() bool GameArea::LoadState(int slot) { wxString fname; - fname.Printf(SAVESLOT_FMT, game_name().mb_str(), slot); + fname.Printf(SAVESLOT_FMT, game_name().c_str(), slot); return LoadState(wxFileName(statedir, fname)); } @@ -606,7 +606,7 @@ bool GameArea::LoadState(const wxFileName& fname) wxString msg; msg.Printf(ret ? _("Loaded state %s") : _("Error loading state %s"), - fname.GetFullPath().mb_str()); + fname.GetFullPath().c_str()); systemScreenMessage(msg); return ret; } @@ -619,7 +619,7 @@ bool GameArea::SaveState() bool GameArea::SaveState(int slot) { wxString fname; - fname.Printf(SAVESLOT_FMT, game_name().mb_str(), slot); + fname.Printf(SAVESLOT_FMT, game_name().c_str(), slot); return SaveState(wxFileName(statedir, fname)); } @@ -630,7 +630,7 @@ bool GameArea::SaveState(const wxFileName& fname) wxGetApp().frame->update_state_ts(true); wxString msg; msg.Printf(ret ? _("Saved state %s") : _("Error saving state %s"), - fname.GetFullPath().mb_str()); + fname.GetFullPath().c_str()); systemScreenMessage(msg); return ret; } @@ -660,7 +660,7 @@ void GameArea::SaveBattery() // of course some games just write battery way too often for such // a thing to be useful if (!emusys->emuWriteBattery(fnb.data())) - wxLogError(_("Error writing battery %s"), fn); + wxLogError(_("Error writing battery %s"), fn.c_str()); systemSaveUpdateCounter = SYSTEM_SAVE_NOT_UPDATED; } @@ -1018,7 +1018,6 @@ void GameArea::OnIdle(wxIdleEvent& event) // set userdata so we know it's the panel and not the frame being resized // the userdata is freed on disconnect/destruction - w->Connect(wxEVT_SIZE, wxSizeEventHandler(GameArea::OnSize), new wxObject, this); this->Connect(wxEVT_SIZE, wxSizeEventHandler(GameArea::OnSize), NULL, this); w->SetBackgroundStyle(wxBG_STYLE_CUSTOM); @@ -1032,19 +1031,29 @@ void GameArea::OnIdle(wxIdleEvent& event) AdjustMinSize(); AdjustSize(false); + unsigned frame_priority = 0; + // add spacers on top and bottom to center panel vertically + // but not on 2.8 which does not handle this correctly +#if wxCHECK_VERSION(2, 9, 0) GetSizer()->Add(0, 0, 1, wxEXPAND); +#else + frame_priority = 1; +#endif // On windows with the vcpkg version of wxWidgets which is 3.1.2, the // wxEXPAND flag throws an XRC error, but everything works fine without it. // On GTK however, the flag is necessary. #if defined(__WXMSW__) - GetSizer()->Add(w, 0, gopts.retain_aspect ? (wxSHAPED | wxALIGN_CENTER_HORIZONTAL) : wxEXPAND); + GetSizer()->Add(w, frame_priority, gopts.retain_aspect ? (wxSHAPED | wxALIGN_CENTER_HORIZONTAL) : wxEXPAND); #else - GetSizer()->Add(w, 0, gopts.retain_aspect ? (wxSHAPED | wxALIGN_CENTER_HORIZONTAL | wxEXPAND) : wxEXPAND); + GetSizer()->Add(w, frame_priority, gopts.retain_aspect ? (wxSHAPED | wxALIGN_CENTER_HORIZONTAL | wxEXPAND) : wxEXPAND); #endif +#if wxCHECK_VERSION(2, 9, 0) GetSizer()->Add(0, 0, 1, wxEXPAND); +#endif + Layout(); if (pointer_blanked) @@ -1280,10 +1289,8 @@ void GameArea::EraseBackground(wxEraseEvent& ev) void GameArea::OnSize(wxSizeEvent& ev) { - if (!ev.GetEventUserData()) { // is frame - draw_black_background(this); - Layout(); - } + draw_black_background(this); + Layout(); // panel may resize if (panel) @@ -1812,7 +1819,7 @@ void DrawingPanelBase::DrawArea(uint8_t** data) if (panel->osdstat.size()) drawText(todraw + outstride * (systemColorDepth != 24), outstride, - 10, 20, panel->osdstat.mb_str(), showSpeedTransparent); + 10, 20, panel->osdstat.utf8_str(), showSpeedTransparent); if (!disableStatusMessages && !panel->osdtext.empty()) { if (systemGetClock() - panel->osdtime < OSD_TIME) { @@ -1820,7 +1827,7 @@ void DrawingPanelBase::DrawArea(uint8_t** data) int linelen = std::ceil(width * scale - 20) / 8; int nlines = (message.size() + linelen - 1) / linelen; int cury = height - 14 - nlines * 10; - char* buf = strdup(message.mb_str()); + char* buf = strdup(message.utf8_str()); char* ptr = buf; while (nlines > 1) { @@ -2323,7 +2330,7 @@ void GameArea::StartVidRecording(const wxString& fname) if ((ret = vid_rec.Record(fnb.data(), basic_width, basic_height, systemColorDepth)) != MRET_OK) - wxLogError(_("Unable to begin recording to %s (%s)"), fname.mb_str(), + wxLogError(_("Unable to begin recording to %s (%s)"), fname.c_str(), media_err(ret)); else { MainFrame* mf = wxGetApp().frame; @@ -2354,7 +2361,7 @@ void GameArea::StartSoundRecording(const wxString& fname) MediaRet ret; if ((ret = snd_rec.Record(fnb.data())) != MRET_OK) - wxLogError(_("Unable to begin recording to %s (%s)"), fname.mb_str(), + wxLogError(_("Unable to begin recording to %s (%s)"), fname.c_str(), media_err(ret)); else { MainFrame* mf = wxGetApp().frame; diff --git a/src/wx/sys.cpp b/src/wx/sys.cpp index 271adeb7..8b2765d5 100644 --- a/src/wx/sys.cpp +++ b/src/wx/sys.cpp @@ -44,7 +44,7 @@ void systemMessage(int id, const char* fmt, ...) va_list args; // auto-conversion of wxCharBuffer to const char * seems broken // so save underlying wxCharBuffer (or create one of none is used) - wxCharBuffer _fmt(wxString(wxGetTranslation(wxString(fmt, wxConvLibc))).mb_str()); + wxCharBuffer _fmt(wxString(wxGetTranslation(wxString(fmt, wxConvLibc))).utf8_str()); if (!buf) { buf = (char*)malloc(buflen); @@ -71,7 +71,7 @@ void systemMessage(int id, const char* fmt, ...) exit(1); } - wxLogError(wxT("%s"), wxString(buf, wxConvLibc).mb_str()); + wxLogError(wxT("%s"), wxString(buf, wxConvLibc).c_str()); } static int frames = 0; @@ -129,7 +129,7 @@ void systemStartGameRecording(const wxString& fname) uint32_t version = 1; if (!game_file.Open(fn, wxT("wb")) || game_file.Write(&version, sizeof(version)) != sizeof(version)) { - wxLogError(_("Cannot open output file %s"), fname.mb_str()); + wxLogError(_("Cannot open output file %s"), fname.c_str()); return; } @@ -190,7 +190,7 @@ void systemStartGamePlayback(const wxString& fname) uint32_t version; if (!game_file.Open(fn, wxT("rb")) || game_file.Read(&version, sizeof(version)) != sizeof(version) || wxUINT32_SWAP_ON_BE(version) != 1) { - wxLogError(_("Cannot open recording file %s"), fname.mb_str()); + wxLogError(_("Cannot open recording file %s"), fname.c_str()); return; } @@ -415,7 +415,7 @@ void systemScreenCapture(int num) do { wxString bfn; - bfn.Printf(wxT("%s%02d"), panel->game_name().mb_str(), + bfn.Printf(wxT("%s%02d"), panel->game_name().c_str(), num++); if (captureFormat == 0) @@ -434,7 +434,7 @@ void systemScreenCapture(int num) panel->emusys->emuWriteBMP(fn.GetFullPath().mb_fn_str()); wxString msg; - msg.Printf(_("Wrote snapshot %s"), fn.GetFullPath().mb_str()); + msg.Printf(_("Wrote snapshot %s"), fn.GetFullPath().c_str()); systemScreenMessage(msg); } @@ -805,7 +805,7 @@ void PrintDialog::DoSave(wxCommandEvent&) if (scimg.SaveFile(of)) { wxString msg; - msg.Printf(_("Wrote printer output to %s"), of.mb_str()); + msg.Printf(_("Wrote printer output to %s"), of.c_str()); systemScreenMessage(msg); wxButton* cb = wxStaticCast(dlg->FindWindow(wxID_CANCEL), wxButton); @@ -963,7 +963,7 @@ void systemGbPrint(uint8_t* data, int len, int pages, int feed, int pal, int con do { wxString bfn; - bfn.Printf(wxT("%s-print%02d"), panel->game_name().mb_str(), + bfn.Printf(wxT("%s-print%02d"), panel->game_name().c_str(), num++); if (captureFormat == 0) @@ -986,7 +986,7 @@ void systemGbPrint(uint8_t* data, int len, int pages, int feed, int pal, int con if (ret) { wxString msg; - msg.Printf(_("Wrote printer output to %s"), of.mb_str()); + msg.Printf(_("Wrote printer output to %s"), of.c_str()); systemScreenMessage(msg); } @@ -1174,7 +1174,7 @@ bool debugOpenPty() if ((pty_master = posix_openpt(O_RDWR | O_NOCTTY)) < 0 || grantpt(pty_master) < 0 || unlockpt(pty_master) < 0 || !(slave_name = ptsname(pty_master))) { wxLogError(_("Error opening pseudo tty: %s"), wxString(strerror(errno), wxConvLibc) - .mb_str()); + .c_str()); if (pty_master >= 0) { close(pty_master); @@ -1311,7 +1311,7 @@ void log(const char* defaultMsg, ...) if (out == NULL) { // FIXME: this should be an option wxFileName trace_log(wxGetApp().GetConfigurationPath(), wxT("trace.log")); - out = fopen(trace_log.GetFullPath().mb_str(), "w"); + out = fopen(trace_log.GetFullPath().utf8_str(), "w"); if (!out) return; diff --git a/src/wx/viewers.cpp b/src/wx/viewers.cpp index b476439d..1b6c8c56 100644 --- a/src/wx/viewers.cpp +++ b/src/wx/viewers.cpp @@ -686,7 +686,7 @@ public: wxFileName fn(memsave_fn); if (!fn.IsFileReadable()) { - wxLogError(wxT("Can't open file %s"), memsave_fn.mb_str()); + wxLogError(wxT("Can't open file %s"), memsave_fn.c_str()); return; } diff --git a/src/wx/viewsupt.h b/src/wx/viewsupt.h index 1a69c943..ad06f0de 100644 --- a/src/wx/viewsupt.h +++ b/src/wx/viewsupt.h @@ -58,7 +58,7 @@ protected: // on errors, abort program #define baddialog() \ do { \ - wxLogError(_("Unable to load dialog %s from resources"), dname); \ + wxLogError(_("Unable to load dialog %s from resources"), dname.c_str()); \ wxGetApp().frame->Close(true); \ return; \ } while (0) diff --git a/src/wx/wxvbam.cpp b/src/wx/wxvbam.cpp index 850bf0f6..fe375653 100644 --- a/src/wx/wxvbam.cpp +++ b/src/wx/wxvbam.cpp @@ -60,14 +60,14 @@ static void get_config_path(wxPathList& path, bool exists = true) static bool debug_dumped = false; if (!debug_dumped) { - wxLogDebug(wxT("GetUserLocalDataDir(): %s"), stdp.GetUserLocalDataDir().mb_str()); - wxLogDebug(wxT("GetUserDataDir(): %s"), stdp.GetUserDataDir().mb_str()); - wxLogDebug(wxT("GetLocalizedResourcesDir(wxGetApp().locale.GetCanonicalName()): %s"), stdp.GetLocalizedResourcesDir(wxGetApp().locale.GetCanonicalName()).mb_str()); - wxLogDebug(wxT("GetResourcesDir(): %s"), stdp.GetResourcesDir().mb_str()); - wxLogDebug(wxT("GetDataDir(): %s"), stdp.GetDataDir().mb_str()); - wxLogDebug(wxT("GetLocalDataDir(): %s"), stdp.GetLocalDataDir().mb_str()); - wxLogDebug(wxT("plugins_dir: %s"), wxGetApp().GetPluginsDir().mb_str()); - wxLogDebug(wxT("XdgConfigDir: %s"), get_xdg_user_config_home() + current_app_name); + wxLogDebug(wxT("GetUserLocalDataDir(): %s"), stdp.GetUserLocalDataDir().c_str()); + wxLogDebug(wxT("GetUserDataDir(): %s"), stdp.GetUserDataDir().c_str()); + wxLogDebug(wxT("GetLocalizedResourcesDir(wxGetApp().locale.GetCanonicalName()): %s"), stdp.GetLocalizedResourcesDir(wxGetApp().locale.GetCanonicalName()).c_str()); + wxLogDebug(wxT("GetResourcesDir(): %s"), stdp.GetResourcesDir().c_str()); + wxLogDebug(wxT("GetDataDir(): %s"), stdp.GetDataDir().c_str()); + wxLogDebug(wxT("GetLocalDataDir(): %s"), stdp.GetLocalDataDir().c_str()); + wxLogDebug(wxT("plugins_dir: %s"), wxGetApp().GetPluginsDir().c_str()); + wxLogDebug(wxT("XdgConfigDir: %s"), (wxString(get_xdg_user_config_home().c_str(), wxConvLibc) + current_app_name).c_str()); debug_dumped = true; } @@ -76,8 +76,8 @@ static void get_config_path(wxPathList& path, bool exists = true) #if defined(__WXGTK__) // XDG spec manual support // ${XDG_CONFIG_HOME:-$HOME/.config}/`appname` - wxString old_config = wxString(getenv("HOME")) + FILE_SEP + ".vbam"; - wxString new_config(get_xdg_user_config_home()); + wxString old_config = wxString(getenv("HOME"), wxConvLibc) + wxT(FILE_SEP) + wxT(".vbam"); + wxString new_config(get_xdg_user_config_home().c_str(), wxConvLibc); if (!wxDirExists(old_config) && wxIsWritable(new_config)) { wxFileName new_path(new_config, wxEmptyString); @@ -120,7 +120,7 @@ const wxString wxvbamApp::GetPluginsDir() wxString wxvbamApp::GetConfigurationPath() { - wxString config("vbam.ini"); + wxString config(wxT("vbam.ini")); // first check if config files exists in reverse order // (from system paths to more local paths.) if (data_path.empty()) { @@ -247,17 +247,17 @@ bool wxvbamApp::OnInit() // this needs to be in a subdir to support other config as well // but subdir flag behaves differently 2.8 vs. 2.9. Oh well. // NOTE: this does not support XDG (freedesktop.org) paths - wxString confname("vbam.ini"); + wxString confname(wxT("vbam.ini")); wxFileName vbamconf(GetConfigurationPath(), confname); // /MIGRATION // migrate from 'vbam.{cfg,conf}' to 'vbam.ini' to manage a single config // file for all platforms. #if !defined(__WXMSW__) && !defined(__APPLE__) - wxString oldConf(GetConfigurationPath() + FILE_SEP + "vbam.conf"); + wxString oldConf(GetConfigurationPath() + wxT(FILE_SEP) + wxT("vbam.conf")); #else - wxString oldConf(GetConfigurationPath() + FILE_SEP + "vbam.cfg"); + wxString oldConf(GetConfigurationPath() + wxT(FILE_SEP) + wxT("vbam.cfg")); #endif - wxString newConf(GetConfigurationPath() + FILE_SEP + "vbam.ini"); + wxString newConf(GetConfigurationPath() + wxT(FILE_SEP) + wxT("vbam.ini")); if (wxFileExists(oldConf)) { wxRenameFile(oldConf, newConf, false); @@ -533,7 +533,7 @@ bool wxvbamApp::OnCmdLineParsed(wxCmdLineParser& cl) "To override, remove all but changed root node(s). " "First found root node of correct name in any .xrc or " ".xrs files in following search path overrides built-in:"), - s.mb_str()); + s.c_str()); tack_full_path(lm); wxLogMessage(lm); console_mode = true; @@ -560,7 +560,7 @@ bool wxvbamApp::OnCmdLineParsed(wxCmdLineParser& cl) wxString lm; lm.Printf(_("Wrote built-in override file to %s\n" "To override, delete all but changed section. First found section is used from search path:"), - s.mb_str()); + s.c_str()); wxString oi = wxFileName::GetPathSeparator(); oi += wxT("vba-over.ini"); tack_full_path(lm, oi); @@ -580,17 +580,17 @@ bool wxvbamApp::OnCmdLineParsed(wxCmdLineParser& cl) "For flag options, true and false are specified as 1 and 0, respectively.\n\n")); for (int i = 0; i < num_opts; i++) { - wxPrintf(wxT("%s (%s"), opts[i].opt, - opts[i].boolopt ? wxT("flag") : opts[i].stropt ? wxT("string") : !opts[i].enumvals.empty() ? opts[i].enumvals : (wxString)(opts[i].intopt ? wxT("int") : opts[i].doubleopt ? wxT("decimal") : wxT("string"))); + wxPrintf(wxT("%s (%s"), opts[i].opt.c_str(), + opts[i].boolopt ? wxT("flag") : opts[i].stropt ? wxT("string") : !opts[i].enumvals.empty() ? opts[i].enumvals.c_str() : (opts[i].intopt ? wxT("int") : opts[i].doubleopt ? wxT("decimal") : wxT("string"))); if (!opts[i].enumvals.empty()) { const wxString evx = wxGetTranslation(opts[i].enumvals); if (wxStrcmp(evx, opts[i].enumvals)) - wxPrintf(wxT(" = %s"), evx); + wxPrintf(wxT(" = %s"), evx.c_str()); } - wxPrintf(wxT(")\n\t%s\n\n"), opts[i].desc); + wxPrintf(wxT(")\n\t%s\n\n"), opts[i].desc.c_str()); if (!opts[i].enumvals.empty()) opts[i].enumvals = wxGetTranslation(opts[i].enumvals); @@ -599,7 +599,7 @@ bool wxvbamApp::OnCmdLineParsed(wxCmdLineParser& cl) wxPrintf(_("The commands available for the Keyboard/* option are:\n\n")); for (int i = 0; i < ncmds; i++) - wxPrintf(wxT("%s (%s)\n"), cmdtab[i].cmd, cmdtab[i].name); + wxPrintf(wxT("%s (%s)\n"), cmdtab[i].cmd.c_str(), cmdtab[i].name.c_str()); console_mode = true; return true; @@ -631,11 +631,11 @@ bool wxvbamApp::OnCmdLineParsed(wxCmdLineParser& cl) } else { if (!complained) { wxFprintf(stderr, _("Bad configuration option or multiple ROM files given:\n")); - wxFprintf(stderr, wxT("%s\n"), pending_load.mb_str()); + wxFprintf(stderr, wxT("%s\n"), pending_load.c_str()); complained = true; } - wxFprintf(stderr, wxT("%s\n"), p); + wxFprintf(stderr, wxT("%s\n"), p.c_str()); } } } @@ -649,12 +649,12 @@ bool wxvbamApp::OnCmdLineParsed(wxCmdLineParser& cl) wxString wxvbamApp::GetConfigDir() { - return GetAbsolutePath(get_xdg_user_config_home() + DOT_DIR); + return GetAbsolutePath(wxString((get_xdg_user_config_home() + DOT_DIR).c_str(), wxConvLibc)); } wxString wxvbamApp::GetDataDir() { - return GetAbsolutePath(get_xdg_user_data_home() + DOT_DIR); + return GetAbsolutePath(wxString((get_xdg_user_data_home() + DOT_DIR).c_str(), wxConvLibc)); } wxvbamApp::~wxvbamApp() { @@ -796,7 +796,7 @@ wxString MainFrame::GetGamePath(wxString path) if (!wxIsWritable(game_path)) { - game_path = wxGetApp().GetAbsolutePath(get_xdg_user_data_home() + DOT_DIR); + game_path = wxGetApp().GetAbsolutePath(wxString((get_xdg_user_data_home() + DOT_DIR).c_str(), wxConvLibc)); wxFileName::Mkdir(game_path, 0777, wxPATH_MKDIR_FULL); } @@ -865,7 +865,7 @@ void MainFrame::update_state_ts(bool force) if (panel->game_type() != IMAGE_UNKNOWN) { wxString fn; - fn.Printf(SAVESLOT_FMT, panel->game_name().mb_str(), i + 1); + fn.Printf(SAVESLOT_FMT, panel->game_name().c_str(), i + 1); wxFileName fp(panel->state_dir(), fn); wxDateTime ts; // = wxInvalidDateTime