[vlc-commits] macOS: Add swapoutOverride function to CompatibilityFixes

Marvin Scholz git at videolan.org
Thu Jun 22 23:57:19 CEST 2017


vlc | branch: master | Marvin Scholz <epirat07 at gmail.com> | Wed Jun 21 02:09:39 2017 +0200| [0ee9a18be9c6a1bff5591e4c0d0678f3eaaca398] | committer: Marvin Scholz

macOS: Add swapoutOverride function to CompatibilityFixes

This adds a swaputOverride function, which swaps out the implementation
of a overridden method of a Class with its base implementation from the
superclass.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=0ee9a18be9c6a1bff5591e4c0d0678f3eaaca398
---

 .../package/macosx/VLC.xcodeproj/project.pbxproj   |  4 ++
 modules/gui/macosx/CompatibilityFixes.h            |  6 ++-
 modules/gui/macosx/CompatibilityFixes.m            | 45 ++++++++++++++++++++++
 modules/gui/macosx/Makefile.am                     |  2 +-
 4 files changed, 55 insertions(+), 2 deletions(-)

diff --git a/extras/package/macosx/VLC.xcodeproj/project.pbxproj b/extras/package/macosx/VLC.xcodeproj/project.pbxproj
index d2055f1c04..fa93372303 100644
--- a/extras/package/macosx/VLC.xcodeproj/project.pbxproj
+++ b/extras/package/macosx/VLC.xcodeproj/project.pbxproj
@@ -76,6 +76,7 @@
 		6B4D50961E7A7D16004479B5 /* NSSound+VLCAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 6B4D50951E7A7D16004479B5 /* NSSound+VLCAdditions.m */; };
 		6B4D50A71E7AB52C004479B5 /* NSScreen+VLCAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 6B4D50A61E7AB52C004479B5 /* NSScreen+VLCAdditions.m */; };
 		6B5978C51EFBFBF2003D9C80 /* VLCPopUpButtonCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 6B5978C41EFBFBF2003D9C80 /* VLCPopUpButtonCell.m */; };
+		6B6FFF701EF9EC350001CEB1 /* CompatibilityFixes.m in Sources */ = {isa = PBXBuildFile; fileRef = 6B6FFF6F1EF9EC350001CEB1 /* CompatibilityFixes.m */; };
 		6B8166291EBFC34300C26F1B /* VLCDefaultValueSlider.m in Sources */ = {isa = PBXBuildFile; fileRef = 6B6A499B1DFD9B23009128AC /* VLCDefaultValueSlider.m */; };
 		6B81662A1EBFC34300C26F1B /* VLCDefaultValueSliderCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 6B6A499D1DFD9B23009128AC /* VLCDefaultValueSliderCell.m */; };
 		6B81662B1EBFC35D00C26F1B /* VLCVoutWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = E0C2583F161B593D00185AAD /* VLCVoutWindowController.m */; };
@@ -135,6 +136,7 @@
 		6B6A499B1DFD9B23009128AC /* VLCDefaultValueSlider.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VLCDefaultValueSlider.m; sourceTree = "<group>"; };
 		6B6A499C1DFD9B23009128AC /* VLCDefaultValueSliderCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VLCDefaultValueSliderCell.h; sourceTree = "<group>"; };
 		6B6A499D1DFD9B23009128AC /* VLCDefaultValueSliderCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VLCDefaultValueSliderCell.m; sourceTree = "<group>"; };
+		6B6FFF6F1EF9EC350001CEB1 /* CompatibilityFixes.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CompatibilityFixes.m; sourceTree = "<group>"; };
 		6B8223FE1E4D2A8F00833BE1 /* About.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = About.xib; sourceTree = "<group>"; };
 		6B8223FF1E4D2A9000833BE1 /* AddonManager.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = AddonManager.xib; sourceTree = "<group>"; };
 		6B8224001E4D2A9000833BE1 /* AudioEffects.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = AudioEffects.xib; sourceTree = "<group>"; };
@@ -884,6 +886,7 @@
 				DCE7BD0708A5724D007B10AE /* VLCBookmarksWindowController.h */,
 				DCE7BD0608A5724D007B10AE /* VLCBookmarksWindowController.m */,
 				CCB0BB3013FAC9F40095BD0A /* CompatibilityFixes.h */,
+				6B6FFF6F1EF9EC350001CEB1 /* CompatibilityFixes.m */,
 				E0382C00160BA09E0031D7FF /* VLCControlsBarCommon.h */,
 				E0382C01160BA09E0031D7FF /* VLCControlsBarCommon.m */,
 				7D5678EE1D5BA397002698F3 /* VLCMainWindowControlsBar.h */,
@@ -1931,6 +1934,7 @@
 				1C3113DB1E508C6900D4DD76 /* VLCStringUtility.m in Sources */,
 				6B4D50A71E7AB52C004479B5 /* NSScreen+VLCAdditions.m in Sources */,
 				1C3113DD1E508C6900D4DD76 /* VLCTrackSynchronizationWindowController.m in Sources */,
+				6B6FFF701EF9EC350001CEB1 /* CompatibilityFixes.m in Sources */,
 				1C3113DF1E508C6900D4DD76 /* VLCVideoEffectsWindowController.m in Sources */,
 				1C3113E11E508C6900D4DD76 /* VLCVoutView.m in Sources */,
 				1C3113E31E508C6900D4DD76 /* VLCPlaylist.m in Sources */,
diff --git a/modules/gui/macosx/CompatibilityFixes.h b/modules/gui/macosx/CompatibilityFixes.h
index f98679c18d..0a0a51cb7b 100644
--- a/modules/gui/macosx/CompatibilityFixes.h
+++ b/modules/gui/macosx/CompatibilityFixes.h
@@ -1,10 +1,11 @@
 /*****************************************************************************
  * CompatibilityFixes.h: MacOS X interface module
  *****************************************************************************
- * Copyright (C) 2011-2012 VLC authors and VideoLAN
+ * Copyright (C) 2011-2017 VLC authors and VideoLAN
  * $Id$
  *
  * Authors: Felix Paul Kühne <fkuehne -at- videolan -dot- org>
+ *          Marvin Scholz <epirat07 -at- gmail -dot- com>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -52,3 +53,6 @@ typedef NS_OPTIONS(NSUInteger, NSStatusItemBehavior) {
 typedef NSUInteger NSWindowStyleMask;
 
 #endif
+
+void swapoutOverride(Class cls, SEL selector);
+
diff --git a/modules/gui/macosx/CompatibilityFixes.m b/modules/gui/macosx/CompatibilityFixes.m
new file mode 100644
index 0000000000..6dcbe2cb3d
--- /dev/null
+++ b/modules/gui/macosx/CompatibilityFixes.m
@@ -0,0 +1,45 @@
+/*****************************************************************************
+ * CompatibilityFixes.h: MacOS X interface module
+ *****************************************************************************
+ * Copyright (C) 2011-2017 VLC authors and VideoLAN
+ * $Id$
+ *
+ * Authors: Felix Paul Kühne <fkuehne -at- videolan -dot- org>
+ *          Marvin Scholz <epirat07 -at- gmail -dot- com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#import "CompatibilityFixes.h"
+#import <objc/runtime.h>
+
+/**
+ Swaps out the implementation of the method at @c selector in Class @c cls
+ with the implementation of that method from the superclass.
+ 
+ @param cls         The class which this selector belongs to
+ @param selector    The selector of whom to swap the implementation
+ 
+ @note  The @c cls must be a subclass of another class and both
+        must implement the @c selector for this function to work as expected!
+ */
+void swapoutOverride(Class cls, SEL selector)
+{
+    Method subclassMeth = class_getInstanceMethod(cls, selector);
+    IMP baseImp = class_getMethodImplementation([cls superclass], selector);
+
+    if (subclassMeth && baseImp)
+        method_setImplementation(subclassMeth, baseImp);
+}
diff --git a/modules/gui/macosx/Makefile.am b/modules/gui/macosx/Makefile.am
index bdbe0c4e57..579bf4fd7b 100644
--- a/modules/gui/macosx/Makefile.am
+++ b/modules/gui/macosx/Makefile.am
@@ -19,7 +19,7 @@ libmacosx_plugin_la_SOURCES = \
 	gui/macosx/VLCAddonsWindowController.h gui/macosx/VLCAddonsWindowController.m \
 	gui/macosx/applescript.h gui/macosx/applescript.m \
 	gui/macosx/AppleRemote.h gui/macosx/AppleRemote.m \
-	gui/macosx/CompatibilityFixes.h \
+	gui/macosx/CompatibilityFixes.h gui/macosx/CompatibilityFixes.m \
 	gui/macosx/VLCControlsBarCommon.m gui/macosx/VLCControlsBarCommon.h \
 	gui/macosx/VLCDocumentController.m gui/macosx/VLCDocumentController.h \
 	gui/macosx/VLCMainWindowControlsBar.m gui/macosx/VLCMainWindowControlsBar.h \



More information about the vlc-commits mailing list