[vlc-devel] [PATCH] macosx: Add CoreUIHelpers

Marvin Scholz epirat07 at gmail.com
Sat Sep 24 13:13:04 CEST 2016


This adds necessary CoreUI helper functions to allow easy CoreUI
rendering for some components like Segmented Controls, where we need to
use buttons and not a real segmented control but make them look like
segmented controls.
---
 .../package/macosx/vlc.xcodeproj/project.pbxproj   |  6 ++
 modules/gui/macosx/CompatibilityFixes.h            |  2 +
 modules/gui/macosx/CoreUIHelpers.h                 | 26 +++++++++
 modules/gui/macosx/CoreUIHelpers.m                 | 64 ++++++++++++++++++++++
 modules/gui/macosx/Makefile.am                     |  2 +
 5 files changed, 100 insertions(+)
 create mode 100644 modules/gui/macosx/CoreUIHelpers.h
 create mode 100644 modules/gui/macosx/CoreUIHelpers.m

diff --git a/extras/package/macosx/vlc.xcodeproj/project.pbxproj b/extras/package/macosx/vlc.xcodeproj/project.pbxproj
index e890ea7..a276479 100644
--- a/extras/package/macosx/vlc.xcodeproj/project.pbxproj
+++ b/extras/package/macosx/vlc.xcodeproj/project.pbxproj
@@ -474,6 +474,7 @@
 		6B3F8D2F1CE58E0E002A4998 /* VLCPreviousTemplate.pdf in Resources */ = {isa = PBXBuildFile; fileRef = 6B3F8D2B1CE58E0E002A4998 /* VLCPreviousTemplate.pdf */; };
 		6B3F8D311CE5CC21002A4998 /* VLCStatusBarIcon.pdf in Resources */ = {isa = PBXBuildFile; fileRef = 6B3F8D301CE5CC21002A4998 /* VLCStatusBarIcon.pdf */; };
 		6B3F8D331CE5CD57002A4998 /* VLCShuffleTemplate.pdf in Resources */ = {isa = PBXBuildFile; fileRef = 6B3F8D321CE5CD57002A4998 /* VLCShuffleTemplate.pdf */; };
+		6B78BCEF1D957765004B7191 /* CoreUIHelpers.m in Sources */ = {isa = PBXBuildFile; fileRef = 6B78BCED1D957765004B7191 /* CoreUIHelpers.m */; };
 		6B846FE41CF5D88C00112E54 /* VLCHUDButtonCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 6B846FDD1CF5D88C00112E54 /* VLCHUDButtonCell.m */; };
 		6B846FE51CF5D88C00112E54 /* VLCHUDCheckboxCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 6B846FDF1CF5D88C00112E54 /* VLCHUDCheckboxCell.m */; };
 		6B846FE61CF5D88C00112E54 /* VLCHUDRadiobuttonCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 6B846FE11CF5D88C00112E54 /* VLCHUDRadiobuttonCell.m */; };
@@ -1282,6 +1283,8 @@
 		6B3F8D2B1CE58E0E002A4998 /* VLCPreviousTemplate.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; name = VLCPreviousTemplate.pdf; path = Resources/vlcmenubaricon/VLCPreviousTemplate.pdf; sourceTree = "<group>"; };
 		6B3F8D301CE5CC21002A4998 /* VLCStatusBarIcon.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; name = VLCStatusBarIcon.pdf; path = Resources/vlcmenubaricon/VLCStatusBarIcon.pdf; sourceTree = "<group>"; };
 		6B3F8D321CE5CD57002A4998 /* VLCShuffleTemplate.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; name = VLCShuffleTemplate.pdf; path = Resources/vlcmenubaricon/VLCShuffleTemplate.pdf; sourceTree = "<group>"; };
+		6B78BCED1D957765004B7191 /* CoreUIHelpers.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CoreUIHelpers.m; path = ../../../modules/gui/macosx/CoreUIHelpers.m; sourceTree = "<group>"; };
+		6B78BCEE1D957765004B7191 /* CoreUIHelpers.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CoreUIHelpers.h; path = ../../../modules/gui/macosx/CoreUIHelpers.h; sourceTree = "<group>"; };
 		6B846FDC1CF5D88C00112E54 /* VLCHUDButtonCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = VLCHUDButtonCell.h; path = ../../../modules/gui/macosx/VLCHUDButtonCell.h; sourceTree = "<group>"; };
 		6B846FDD1CF5D88C00112E54 /* VLCHUDButtonCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = VLCHUDButtonCell.m; path = ../../../modules/gui/macosx/VLCHUDButtonCell.m; sourceTree = "<group>"; };
 		6B846FDE1CF5D88C00112E54 /* VLCHUDCheckboxCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = VLCHUDCheckboxCell.h; path = ../../../modules/gui/macosx/VLCHUDCheckboxCell.h; sourceTree = "<group>"; };
@@ -1975,6 +1978,8 @@
 				1CD3667A1B7A242E0054E39F /* VLCTimeSelectionPanelController.m */,
 				6BBBB8AF1D10A96B001BD9BA /* Renderers */,
 				6B846FE81CF5D89500112E54 /* HUD UI Classes */,
+				6B78BCEE1D957765004B7191 /* CoreUIHelpers.h */,
+				6B78BCED1D957765004B7191 /* CoreUIHelpers.m */,
 				5CCED71414C0D4A90057F8D1 /* VLCUIWidgets.h */,
 				5CCED71514C0D4A90057F8D1 /* VLCUIWidgets.m */,
 				E0C2583E161B593D00185AAD /* VLCVoutWindowController.h */,
@@ -4009,6 +4014,7 @@
 				1CCB5F6E1A62A724004C3E90 /* VLCEyeTvController.h in Sources */,
 				1CCB5F6F1A62A724004C3E90 /* VLCEyeTvController.m in Sources */,
 				1CCB5F701A62A724004C3E90 /* VLCFSPanel.h in Sources */,
+				6B78BCEF1D957765004B7191 /* CoreUIHelpers.m in Sources */,
 				7D5678ED1D5BA1DC002698F3 /* VLCApplication.m in Sources */,
 				1CCB5F711A62A724004C3E90 /* VLCFSPanel.m in Sources */,
 				1CCB5F721A62A724004C3E90 /* VLCMain.h in Sources */,
diff --git a/modules/gui/macosx/CompatibilityFixes.h b/modules/gui/macosx/CompatibilityFixes.h
index 4a35c1c..0c3e669 100644
--- a/modules/gui/macosx/CompatibilityFixes.h
+++ b/modules/gui/macosx/CompatibilityFixes.h
@@ -32,6 +32,8 @@
 #define OSX_EL_CAPITAN (NSAppKitVersionNumber >= 1404 && NSAppKitVersionNumber < 1485)
 #define OSX_SIERRA (NSAppKitVersionNumber >= 1485)
 
+#define OSX_YOSEMITE_OR_HIGHER (NSAppKitVersionNumber >= 1334)
+
 // Sierra only APIs
 #ifndef MAC_OS_X_VERSION_10_12
 
diff --git a/modules/gui/macosx/CoreUIHelpers.h b/modules/gui/macosx/CoreUIHelpers.h
new file mode 100644
index 0000000..ca1cc3d
--- /dev/null
+++ b/modules/gui/macosx/CoreUIHelpers.h
@@ -0,0 +1,26 @@
+/*****************************************************************************
+ * CoreUIHelpers.h: Helper functions for CoreUI usage
+ *****************************************************************************
+ * Copyright (C) 2016 VLC authors and VideoLAN
+ * $Id$
+ *
+ * Authors: 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 <Cocoa/Cocoa.h>
+
+int VLCCoreUIDraw(CGRect rect, CGContextRef context, CFDictionaryRef options);
diff --git a/modules/gui/macosx/CoreUIHelpers.m b/modules/gui/macosx/CoreUIHelpers.m
new file mode 100644
index 0000000..032b6c0
--- /dev/null
+++ b/modules/gui/macosx/CoreUIHelpers.m
@@ -0,0 +1,64 @@
+/*****************************************************************************
+ * CoreUIHelpers.m: Helper functions for CoreUI usage
+ *****************************************************************************
+ * Copyright (C) 2016 VLC authors and VideoLAN
+ * $Id$
+ *
+ * Authors: 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 "CoreUIHelpers.h"
+#import "CompatibilityFixes.h"
+
+/* Declare necessary private CoreUI types and functions */
+typedef CFTypeRef CUIRendererRef;
+int CUIDraw(CUIRendererRef r, CGRect rect, CGContextRef ctx, CFDictionaryRef options, CFDictionaryRef* result);
+
+
+/* On 10.9 and higher, there is NSAppearance which can be used
+ * to do Core UI drawing.
+ */
+#ifdef MAC_OS_X_VERSION_10_9
+ at interface NSAppearance (Private)
+- (int)_drawInRect:(struct CGRect)rect context:(struct CGContext *)ctx options:(CFDictionaryRef)opt;
+ at end
+#endif
+
+/* On 10.8 and lower we need a CUIRendererRef which is provided
+ * by a private NSWindow method.
+ */
+ at interface NSWindow(Private)
++ (CUIRendererRef)coreUIRenderer;
+ at end
+
+
+int VLCCoreUIDraw(CGRect rect, CGContextRef context, CFDictionaryRef options)
+{
+#ifdef MAC_OS_X_VERSION_10_9
+    if (OSX_YOSEMITE_OR_HIGHER) {
+        NSAppearance *appearance = [NSAppearance currentAppearance];
+        if ([NSAppearance respondsToSelector:@selector(_drawInRect:context:options:)]) {
+            return [appearance _drawInRect:rect context:context options:options];
+        }
+        return -1;
+    }
+#endif
+
+    /* CoreUI rendering without NSAppearance */
+    CUIRendererRef renderer = [NSWindow respondsToSelector:@selector(coreUIRenderer)] ? [NSWindow coreUIRenderer] : nil;
+    return CUIDraw(renderer, rect, context, options, NULL);
+}
diff --git a/modules/gui/macosx/Makefile.am b/modules/gui/macosx/Makefile.am
index d8c3678..19b014b 100644
--- a/modules/gui/macosx/Makefile.am
+++ b/modules/gui/macosx/Makefile.am
@@ -5,6 +5,7 @@ guidir = $(pluginsdir)/gui
 
 libmacosx_plugin_la_OBJCFLAGS = $(AM_OBJCFLAGS) -fobjc-exceptions -fobjc-arc -F${CONTRIB_DIR}
 libmacosx_plugin_la_LDFLAGS = $(AM_LDFLAGS) -rpath '$(guidir)' \
+	-Wl,-framework,CoreUI -F/System/Library/PrivateFrameworks/ \
 	-Wl,-framework,Cocoa -Wl,-framework,Carbon -Wl,-framework,CoreServices \
 	-Wl,-framework,AVFoundation -Wl,-framework,CoreMedia -Wl,-framework,IOKit \
 	-Wl,-framework,AddressBook -Wl,-framework,WebKit -Wl,-framework,CoreAudio \
@@ -88,4 +89,5 @@ libmacosx_plugin_la_SOURCES = \
 	VLCRendererDialog.h VLCRendererDialog.m \
 	VLCResumeDialogController.h VLCResumeDialogController.m \
 	VLCTrackSynchronizationWindowController.h VLCTrackSynchronizationWindowController.m \
+	CoreUIHelpers.h CoreUIHelpers.m \
 	VLCVideoEffectsWindowController.h VLCVideoEffectsWindowController.m
-- 
2.8.4 (Apple Git-73)



More information about the vlc-devel mailing list