macOS: Add swapoutOverride function to CompatibilityFixes
authorMarvin Scholz <epirat07@gmail.com>
Wed, 21 Jun 2017 00:09:39 +0000 (02:09 +0200)
committerMarvin Scholz <epirat07@gmail.com>
Thu, 22 Jun 2017 21:46:58 +0000 (23:46 +0200)
This adds a swaputOverride function, which swaps out the implementation
of a overridden method of a Class with its base implementation from the
superclass.

extras/package/macosx/VLC.xcodeproj/project.pbxproj
modules/gui/macosx/CompatibilityFixes.h
modules/gui/macosx/CompatibilityFixes.m [new file with mode: 0644]
modules/gui/macosx/Makefile.am

index d2055f1..fa93372 100644 (file)
@@ -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 */; };
                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>"; };
                                DCE7BD0708A5724D007B10AE /* VLCBookmarksWindowController.h */,
                                DCE7BD0608A5724D007B10AE /* VLCBookmarksWindowController.m */,
                                CCB0BB3013FAC9F40095BD0A /* CompatibilityFixes.h */,
+                               6B6FFF6F1EF9EC350001CEB1 /* CompatibilityFixes.m */,
                                E0382C00160BA09E0031D7FF /* VLCControlsBarCommon.h */,
                                E0382C01160BA09E0031D7FF /* VLCControlsBarCommon.m */,
                                7D5678EE1D5BA397002698F3 /* VLCMainWindowControlsBar.h */,
                                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 */,
index f98679c..0a0a51c 100644 (file)
@@ -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 (file)
index 0000000..6dcbe2c
--- /dev/null
@@ -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);
+}
index bdbe0c4..579bf4f 100644 (file)
@@ -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 \