From 5944d7999cb1e79f350fe639b44418d503d4001b Mon Sep 17 00:00:00 2001
From: sepro <4618135+seproDev@users.noreply.github.com>
Date: Mon, 24 Jul 2023 20:35:38 +0200
Subject: [PATCH] Add option to build on wxWidgets master

---
 .github/workflows/ci.yml          | 19 ++++++++++++++++++
 meson.build                       | 18 ++++++++++++++---
 src/dialog_colorpicker.cpp        |  4 ++--
 src/dialog_translation.cpp        |  7 ++++++-
 src/subs_edit_ctrl.cpp            | 33 ++++++++++++++++++++-----------
 subprojects/wxWidgets-master.wrap |  6 ++++++
 subprojects/wxWidgets.wrap        |  3 ++-
 7 files changed, 72 insertions(+), 18 deletions(-)
 create mode 100644 subprojects/wxWidgets-master.wrap

diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index e742075c0..35ed3e294 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -33,6 +33,25 @@ jobs:
               -Dfribidi:tests=false
               -Dfribidi:docs=false
               -Dlibass:fontconfig=disabled
+          - name: Windows MSVC Release (wx master)
+            os: windows-latest
+            msvc: true
+            buildtype: release
+            args: >-
+              -Ddefault_library=static 
+              --force-fallback-for=zlib,harfbuzz,freetype2,fribidi,libpng 
+              -Dfreetype2:harfbuzz=disabled 
+              -Dharfbuzz:freetype=disabled 
+              -Dharfbuzz:cairo=disabled 
+              -Dharfbuzz:glib=disabled 
+              -Dharfbuzz:gobject=disabled
+              -Dharfbuzz:tests=disabled
+              -Dharfbuzz:docs=disabled
+              -Dharfbuzz:icu=disabled
+              -Dfribidi:tests=false
+              -Dfribidi:docs=false
+              -Dlibass:fontconfig=disabled
+              -Dwx_version='3.3.0'
           #- {
           #  name: Windows MinGW,
           #  os: windows-latest,
diff --git a/meson.build b/meson.build
index 1448c971a..3f2c3b05e 100644
--- a/meson.build
+++ b/meson.build
@@ -8,6 +8,7 @@ cmake = import('cmake')
 
 if host_machine.system() == 'windows'
     add_project_arguments('-DNOMINMAX', '-D_WIN32_WINNT=0x0601', language: 'cpp')
+    add_project_arguments('-DUNICODE', language: 'cpp')
 
     if not get_option('csri').disabled()
         add_global_arguments('-DCSRI_NO_EXPORT', language: 'c')
@@ -134,16 +135,21 @@ else
     opt_var = cmake.subproject_options()
     opt_var.add_cmake_defines({
         'wxBUILD_INSTALL': false,
-        'wxBUILD_PRECOMP': false,       # otherwise breaks project generation w/ meson
+        'wxBUILD_PRECOMP': 'OFF',       # otherwise breaks project generation w/ meson
         'wxBUILD_SHARED': build_shared,
 
         'wxUSE_WEBVIEW': false,         # breaks build on linux
+        'wxUSE_REGEX': 'builtin',
         'CMAKE_BUILD_TYPE': build_type,
         'wxUSE_IMAGE': true,
         'wxBUILD_MONOLITHIC': true      # otherwise breaks project generation w/ meson
     })
 
-    wx = cmake.subproject('wxWidgets', options: opt_var)
+    if get_option('wx_version').version_compare('>=3.3.0')
+        wx = cmake.subproject('wxWidgets-master', options: opt_var)
+    else
+        wx = cmake.subproject('wxWidgets', options: opt_var)
+    endif
 
     deps += [
         wx.dependency('wxmono'),
@@ -151,6 +157,12 @@ else
         wx.dependency('wxscintilla')
     ]
 
+    if get_option('wx_version').version_compare('>=3.3.0')
+        deps += [
+            wx.dependency('wxlexilla')
+        ]
+    endif
+
     if host_machine.system() == 'windows' or host_machine.system() == 'darwin'
         deps += [
             wx.dependency('wxpng'),
@@ -242,7 +254,7 @@ if host_machine.system() == 'windows' and not get_option('directsound').disabled
 endif
 
 if host_machine.system() == 'darwin'
-    frameworks_dep = dependency('appleframeworks', modules : ['CoreText', 'CoreFoundation', 'AppKit', 'Carbon', 'IOKit'])
+    frameworks_dep = dependency('appleframeworks', modules : ['CoreText', 'CoreFoundation', 'AppKit', 'Carbon', 'IOKit', 'QuartzCore'])
     deps += frameworks_dep
 endif
 
diff --git a/src/dialog_colorpicker.cpp b/src/dialog_colorpicker.cpp
index 510d2a6ce..d7bba83b9 100644
--- a/src/dialog_colorpicker.cpp
+++ b/src/dialog_colorpicker.cpp
@@ -398,8 +398,8 @@ void ColorPickerScreenDropper::DropFromScreenXY(int x, int y) {
 	CGGetDisplaysWithPoint(CGPointMake(x, y), 1, &display_id, &display_count);
 
 	agi::scoped_holder<CGImageRef> img(CGDisplayCreateImageForRect(display_id, CGRectMake(x - resx / 2, y - resy / 2, resx, resy)), CGImageRelease);
-	NSUInteger width = CGImageGetWidth(img);
-	NSUInteger height = CGImageGetHeight(img);
+	size_t width = CGImageGetWidth(img);
+	size_t height = CGImageGetHeight(img);
 	std::vector<uint8_t> imgdata(height * width * 4);
 
 	agi::scoped_holder<CGColorSpaceRef> colorspace(CGColorSpaceCreateDeviceRGB(), CGColorSpaceRelease);
diff --git a/src/dialog_translation.cpp b/src/dialog_translation.cpp
index b47d01b4c..e23c70eaf 100644
--- a/src/dialog_translation.cpp
+++ b/src/dialog_translation.cpp
@@ -51,6 +51,11 @@
 #include <wx/stattext.h>
 #include <wx/stc/stc.h>
 
+// Define macros for wxWidgets 3.1
+#ifndef wxSTC_KEYMOD_SHIFT
+#define wxSTC_KEYMOD_SHIFT wxSTC_SCMOD_SHIFT
+#endif
+
 static void add_hotkey(wxSizer *sizer, wxWindow *parent, const char *command, wxString const& text) {
 	sizer->Add(new wxStaticText(parent, -1, text));
 	sizer->Add(new wxStaticText(parent, -1, to_wx(hotkey::get_hotkey_str_first("Translation Assistant", command))));
@@ -97,7 +102,7 @@ DialogTranslation::DialogTranslation(agi::Context *c)
 		translated_text->SetMarginWidth(1, 0);
 		translated_text->SetFocus();
 		translated_text->Bind(wxEVT_CHAR_HOOK, &DialogTranslation::OnKeyDown, this);
-		translated_text->CmdKeyAssign(wxSTC_KEY_RETURN, wxSTC_SCMOD_SHIFT, wxSTC_CMD_NEWLINE);
+		translated_text->CmdKeyAssign(wxSTC_KEY_RETURN, wxSTC_KEYMOD_SHIFT, wxSTC_CMD_NEWLINE);
 
 		wxSizer *translated_box = new wxStaticBoxSizer(wxVERTICAL, this, _("Translation"));
 		translated_box->Add(translated_text, 1, wxEXPAND, 0);
diff --git a/src/subs_edit_ctrl.cpp b/src/subs_edit_ctrl.cpp
index 9d1fc6a01..dab71585b 100644
--- a/src/subs_edit_ctrl.cpp
+++ b/src/subs_edit_ctrl.cpp
@@ -56,6 +56,17 @@
 #include <wx/menu.h>
 #include <wx/settings.h>
 
+// Define macros for wxWidgets 3.1
+#ifndef wxSTC_KEYMOD_CTRL
+#define wxSTC_KEYMOD_CTRL wxSTC_SCMOD_CTRL
+#endif
+#ifndef wxSTC_KEYMOD_SHIFT
+#define wxSTC_KEYMOD_SHIFT wxSTC_SCMOD_SHIFT
+#endif
+#ifndef wxSTC_KEYMOD_NORM
+#define wxSTC_KEYMOD_NORM wxSTC_SCMOD_NORM
+#endif
+
 // Maximum number of languages (locales)
 // It should be above 100 (at least 242) and probably not more than 1000
 #define LANGS_MAX 1000
@@ -94,17 +105,17 @@ SubsTextEditCtrl::SubsTextEditCtrl(wxWindow* parent, wxSize wsize, long style, a
 	SetStyles();
 
 	// Set hotkeys
-	CmdKeyClear(wxSTC_KEY_RETURN,wxSTC_SCMOD_CTRL);
-	CmdKeyClear(wxSTC_KEY_RETURN,wxSTC_SCMOD_SHIFT);
-	CmdKeyClear(wxSTC_KEY_RETURN,wxSTC_SCMOD_NORM);
-	CmdKeyClear(wxSTC_KEY_TAB,wxSTC_SCMOD_NORM);
-	CmdKeyClear(wxSTC_KEY_TAB,wxSTC_SCMOD_SHIFT);
-	CmdKeyClear('D',wxSTC_SCMOD_CTRL);
-	CmdKeyClear('L',wxSTC_SCMOD_CTRL);
-	CmdKeyClear('L',wxSTC_SCMOD_CTRL | wxSTC_SCMOD_SHIFT);
-	CmdKeyClear('T',wxSTC_SCMOD_CTRL);
-	CmdKeyClear('T',wxSTC_SCMOD_CTRL | wxSTC_SCMOD_SHIFT);
-	CmdKeyClear('U',wxSTC_SCMOD_CTRL);
+	CmdKeyClear(wxSTC_KEY_RETURN,wxSTC_KEYMOD_CTRL);
+	CmdKeyClear(wxSTC_KEY_RETURN,wxSTC_KEYMOD_SHIFT);
+	CmdKeyClear(wxSTC_KEY_RETURN,wxSTC_KEYMOD_NORM);
+	CmdKeyClear(wxSTC_KEY_TAB,wxSTC_KEYMOD_NORM);
+	CmdKeyClear(wxSTC_KEY_TAB,wxSTC_KEYMOD_SHIFT);
+	CmdKeyClear('D',wxSTC_KEYMOD_CTRL);
+	CmdKeyClear('L',wxSTC_KEYMOD_CTRL);
+	CmdKeyClear('L',wxSTC_KEYMOD_CTRL | wxSTC_KEYMOD_SHIFT);
+	CmdKeyClear('T',wxSTC_KEYMOD_CTRL);
+	CmdKeyClear('T',wxSTC_KEYMOD_CTRL | wxSTC_KEYMOD_SHIFT);
+	CmdKeyClear('U',wxSTC_KEYMOD_CTRL);
 
 	using std::bind;
 
diff --git a/subprojects/wxWidgets-master.wrap b/subprojects/wxWidgets-master.wrap
new file mode 100644
index 000000000..bbde46e78
--- /dev/null
+++ b/subprojects/wxWidgets-master.wrap
@@ -0,0 +1,6 @@
+[wrap-git]
+directory = wxWidgets-master
+url = https://github.com/wxWidgets/wxWidgets.git
+revision = master
+clone-recursive = true
+depth = 1
diff --git a/subprojects/wxWidgets.wrap b/subprojects/wxWidgets.wrap
index 949a03927..310179b05 100644
--- a/subprojects/wxWidgets.wrap
+++ b/subprojects/wxWidgets.wrap
@@ -1,5 +1,6 @@
 [wrap-git]
 directory = wxWidgets
 url = https://github.com/wxWidgets/wxWidgets.git
-revision = v3.1.4
+revision = v3.1.7
 clone-recursive = true
+depth = 1