[foundation] Use more generated code for NSRunLoopMode and add helper API

Use the features for the enum generator support to update NSRunLoopMode:

* remove manual convertion from enum values/NSString
* remove manual code using NSRunLoopMode, in favor of [Wrap]
* add, using [Wrap], easier overloads for using NSRunLoopMode
This commit is contained in:
Sebastien Pouliot 2016-09-15 13:27:03 -04:00
Родитель eaf2ef6688
Коммит 9bb9b438bc
6 изменённых файлов: 162 добавлений и 120 удалений

Просмотреть файл

@ -1,26 +0,0 @@
//
// CADisplayLink: Support for CADisplayLink
//
// Authors:
// Timothy Risi.
//
// Copyright 2014 Xamarin Inc
//
#if !MONOMAC
using System;
using XamCore.Foundation;
using XamCore.ObjCRuntime;
using XamCore.CoreGraphics;
using XamCore.CoreFoundation;
using XamCore.CoreText;
namespace XamCore.CoreAnimation {
public partial class CADisplayLink {
public void AddToRunLoop (NSRunLoop runloop, NSRunLoopMode mode)
{
AddToRunLoop (runloop, NSRunLoop.FromEnum (mode));
}
}
}
#endif

Просмотреть файл

@ -1,12 +1,9 @@
// FIXME: EnumDesktop.cs should be merged into this file.
#if !MONOMAC
using XamCore.ObjCRuntime;
namespace XamCore.Foundation {
// Utility enum, ObjC uses NSString
[NoMac]
[iOS (7,0)]
public enum NSDocumentType {
Unknown = -1,
@ -17,11 +14,39 @@ namespace XamCore.Foundation {
}
// Utility enum, ObjC uses NSString
[NoMac]
[iOS (7,0)]
public enum NSDocumentViewMode {
Normal,
PageLayout
}
public enum NSRunLoopMode {
[DefaultEnumValue]
[Field ("NSDefaultRunLoopMode")]
Default,
[Field ("NSRunLoopCommonModes")]
Common,
#if MONOMAC
[Field ("NSConnectionReplyMode")]
ConnectionReply = 2,
[Field ("NSModalPanelRunLoopMode", "AppKit")]
ModalPanel,
[Field ("NSEventTrackingRunLoopMode", "AppKit")]
EventTracking,
#elif !WATCH
// iOS-specific Enums start in 100 to avoid conflicting with future extensions to MonoMac
[Field ("UITrackingRunLoopMode", "UIKit")]
UITracking = 100,
#endif
// If it is not part of these enumerations
[Field (null)]
Other = 1000
}
}
#endif // !MONOMAC

Просмотреть файл

@ -23,24 +23,9 @@ using System;
using System.Runtime.InteropServices;
namespace XamCore.Foundation {
// This is a C# utility enum without a corresponding native enum, it can stay as 'int'.
public enum NSRunLoopMode {
Default,
Common,
#if MONOMAC
ConnectionReply = 2,
ModalPanel,
EventTracking,
#elif !WATCH
// iOS-specific Enums start in 100 to avoid conflicting with future extensions to MonoMac
UITracking = 100,
#endif
// If it is not part of these enumerations
Other = 1000
}
public partial class NSRunLoop {
#if !XAMCORE_2_0
static NSString GetRealMode (string mode)
{
if (mode == NSDefaultRunLoopMode)
@ -55,56 +40,18 @@ namespace XamCore.Foundation {
return new NSString (mode);
}
internal static NSString FromEnum (NSRunLoopMode mode)
{
switch (mode){
case NSRunLoopMode.Common:
return NSRunLoopCommonModes;
#if MONOMAC
case NSRunLoopMode.ConnectionReply:
return NSRunLoopConnectionReplyMode;
case NSRunLoopMode.ModalPanel:
return NSRunLoopModalPanelMode;
case NSRunLoopMode.EventTracking:
return NSRunLoopEventTracking;
#elif !WATCH
case NSRunLoopMode.UITracking:
return UITrackingRunLoopMode;
#endif
default:
case NSRunLoopMode.Default:
return NSDefaultRunLoopMode;
}
}
#if !XAMCORE_2_0
[Advice ("Use AddTimer (NSTimer, NSRunLoopMode)")]
public void AddTimer (NSTimer timer, string forMode)
{
AddTimer (timer, GetRealMode (forMode));
}
#endif
public void AddTimer (NSTimer timer, NSRunLoopMode forMode)
{
AddTimer (timer, FromEnum (forMode));
}
#if !XAMCORE_2_0
[Advice ("Use LimitDateForMode (NSRunLoopMode) instead")]
public NSDate LimitDateForMode (string mode)
{
return LimitDateForMode (GetRealMode (mode));
}
#endif
public NSDate LimitDateForMode (NSRunLoopMode mode)
{
return LimitDateForMode (FromEnum (mode));
}
#if !XAMCORE_2_0
[Advice ("Use AcceptInputForMode (NSRunLoopMode, NSDate)")]
public void AcceptInputForMode (string mode, NSDate limitDate)
{
@ -112,11 +59,6 @@ namespace XamCore.Foundation {
}
#endif
public void AcceptInputForMode (NSRunLoopMode mode, NSDate limitDate)
{
AcceptInputForMode (FromEnum (mode), limitDate);
}
public void Stop ()
{
GetCFRunLoop ().Stop ();
@ -126,33 +68,20 @@ namespace XamCore.Foundation {
{
GetCFRunLoop ().WakeUp ();
}
}
public bool RunUntil (NSRunLoopMode mode, NSDate limitDate)
static public partial class NSRunLoopModeExtensions {
// this is a less common pattern so it's not automatically generated
public static NSString[] GetConstants (this NSRunLoopMode[] self)
{
return RunUntil (FromEnum (mode), limitDate);
}
public NSRunLoopMode CurrentRunLoopMode {
get {
var mode = CurrentMode;
if (mode == NSDefaultRunLoopMode)
return NSRunLoopMode.Default;
if (mode == NSRunLoopCommonModes)
return NSRunLoopMode.Common;
#if MONOMAC
if (mode == NSRunLoopConnectionReplyMode)
return NSRunLoopMode.ConnectionReply;
if (mode == NSRunLoopModalPanelMode)
return NSRunLoopMode.ModalPanel;
if (mode == NSRunLoopEventTracking)
return NSRunLoopMode.EventTracking;
#elif !WATCH
if (mode == UITrackingRunLoopMode)
return NSRunLoopMode.UITracking;
#endif
return NSRunLoopMode.Other;
}
if (self == null)
throw new ArgumentNullException (nameof (self));
var array = new NSString [self.Length];
for (int n = 0; n < self.Length; n++)
array [n] = self [n].GetConstant ();
return array;
}
}
}

Просмотреть файл

@ -150,10 +150,16 @@ namespace XamCore.CoreAnimation {
[Export ("addToRunLoop:forMode:")]
void AddToRunLoop (NSRunLoop runloop, [NullAllowed] NSString mode);
[Wrap ("AddToRunLoop (runloop, mode.GetConstant ())")]
void AddToRunLoop (NSRunLoop runloop, NSRunLoopMode mode);
[Export ("removeFromRunLoop:forMode:")]
void RemoveFromRunLoop (NSRunLoop runloop, [NullAllowed] NSString mode);
[Wrap ("RemoveFromRunLoop (runloop, mode.GetConstant ())")]
void RemoveFromRunLoop (NSRunLoop runloop, NSRunLoopMode mode);
[Export ("invalidate")]
void Invalidate ();

Просмотреть файл

@ -1914,25 +1914,37 @@ namespace XamCore.Foundation
[Export ("readInBackgroundAndNotifyForModes:")]
void ReadInBackground (NSString [] notifyRunLoopModes);
[Wrap ("ReadInBackground (notifyRunLoopModes.GetConstants ())")]
void ReadInBackground (NSRunLoopMode [] notifyRunLoopModes);
[Export ("readInBackgroundAndNotify")]
void ReadInBackground ();
[Export ("readToEndOfFileInBackgroundAndNotifyForModes:")]
void ReadToEndOfFileInBackground (NSString [] notifyRunLoopModes);
[Wrap ("ReadToEndOfFileInBackground (notifyRunLoopModes.GetConstants ())")]
void ReadToEndOfFileInBackground (NSRunLoopMode [] notifyRunLoopModes);
[Export ("readToEndOfFileInBackgroundAndNotify")]
void ReadToEndOfFileInBackground ();
[Export ("acceptConnectionInBackgroundAndNotifyForModes:")]
void AcceptConnectionInBackground (NSString [] notifyRunLoopModes);
[Wrap ("AcceptConnectionInBackground (notifyRunLoopModes.GetConstants ())")]
void AcceptConnectionInBackground (NSRunLoopMode [] notifyRunLoopModes);
[Export ("acceptConnectionInBackgroundAndNotify")]
void AcceptConnectionInBackground ();
[Export ("waitForDataInBackgroundAndNotifyForModes:")]
void WaitForDataInBackground (NSString [] notifyRunLoopModes);
[Wrap ("WaitForDataInBackground (notifyRunLoopModes.GetConstants ())")]
void WaitForDataInBackground (NSRunLoopMode [] notifyRunLoopModes);
[Export ("waitForDataInBackgroundAndNotify")]
void WaitForDataInBackground ();
@ -3797,18 +3809,30 @@ namespace XamCore.Foundation
[Export ("currentMode")]
NSString CurrentMode { get; }
[Wrap ("NSRunLoopModeExtensions.GetValue (CurrentMode)")]
NSRunLoopMode CurrentRunLoopMode { get; }
[Export ("getCFRunLoop")]
CFRunLoop GetCFRunLoop ();
[Export ("addTimer:forMode:")]
void AddTimer (NSTimer timer, NSString forMode);
[Wrap ("AddTimer (timer, forMode.GetConstant ())")]
void AddTimer (NSTimer timer, NSRunLoopMode forMode);
[Export ("limitDateForMode:")]
NSDate LimitDateForMode (NSString mode);
[Wrap ("LimitDateForMode (mode.GetConstant ())")]
NSDate LimitDateForMode (NSRunLoopMode mode);
[Export ("acceptInputForMode:beforeDate:")]
void AcceptInputForMode (NSString mode, NSDate limitDate);
[Wrap ("AcceptInputForMode (mode.GetConstant (), limitDate)")]
void AcceptInputForMode (NSRunLoopMode mode, NSDate limitDate);
[Export ("run")]
void Run ();
@ -3818,6 +3842,9 @@ namespace XamCore.Foundation
[Export ("runMode:beforeDate:")]
bool RunUntil (NSString runLoopMode, NSDate limitdate);
[Wrap ("RunUntil (runLoopMode.GetConstant (), limitDate)")]
bool RunUntil (NSRunLoopMode runLoopMode, NSDate limitDate);
[Watch (3,0)][TV (10,0)][Mac (10,12)][iOS (10,0)]
[Export ("performBlock:")]
void Perform (Action block);
@ -3826,6 +3853,11 @@ namespace XamCore.Foundation
[Export ("performInModes:block:")]
void Perform (NSString[] modes, Action block);
[Watch (3,0)][TV (10,0)][Mac (10,12)][iOS (10,0)]
[Wrap ("Perform (modes.GetConstants (), block)")]
void Perform (NSRunLoopMode[] modes, Action block);
#if !XAMCORE_4_0
[Field ("NSDefaultRunLoopMode")]
NSString NSDefaultRunLoopMode { get; }
@ -3847,6 +3879,7 @@ namespace XamCore.Foundation
[NoMac][NoWatch]
[Field ("UITrackingRunLoopMode", "UIKit")]
NSString UITrackingRunLoopMode { get; }
#endif
}
[BaseType (typeof (NSObject))]
@ -5464,10 +5497,16 @@ namespace XamCore.Foundation
[Export ("scheduleInRunLoop:forMode:")]
void Schedule (NSRunLoop aRunLoop, NSString forMode);
[Wrap ("Schedule (aRunLoop, forMode.GetConstant ())")]
void Schedule (NSRunLoop aRunLoop, NSRunLoopMode forMode);
[Export ("unscheduleFromRunLoop:forMode:")]
void Unschedule (NSRunLoop aRunLoop, NSString forMode);
[Wrap ("Unschedule (aRunLoop, forMode.GetConstant ())")]
void Unschedule (NSRunLoop aRunLoop, NSRunLoopMode forMode);
#if !MONOMAC
[Since (5,0)]
[Export ("originalRequest")]
@ -6254,8 +6293,17 @@ namespace XamCore.Foundation
[Export ("levelsOfUndo")]
nint LevelsOfUndo { get; set; }
#if XAMCORE_4_0
[Internal]
[Export ("runLoopModes")]
NSString [] _RunLoopModes { get; set; }
[Wrap ("RunLoopModes.GetConstants ()")]
NSRunLoop [] RunLoopModes { get; set; }
#else
[Export ("runLoopModes")]
string [] RunLoopModes { get; set; }
#endif
[Export ("undo")]
void Undo ();
@ -6718,12 +6766,25 @@ namespace XamCore.Foundation
[Export ("setProperty:forKey:"), Internal]
bool SetPropertyForKey ([NullAllowed] NSObject property, NSString key);
#if XAMCORE_4_0
[Export ("scheduleInRunLoop:forMode:")]
void Schedule (NSRunLoop aRunLoop, NSString mode);
[Export ("removeFromRunLoop:forMode:")]
void Unschedule (NSRunLoop aRunLoop, NSString mode);
#else
[Export ("scheduleInRunLoop:forMode:")]
void Schedule (NSRunLoop aRunLoop, string mode);
[Export ("removeFromRunLoop:forMode:")]
void Unschedule (NSRunLoop aRunLoop, string mode);
#endif
[Wrap ("Schedule (aRunLoop, mode.GetConstant ())")]
void Schedule (NSRunLoop aRunLoop, NSRunLoopMode mode);
[Wrap ("Unschedule (aRunLoop, mode.GetConstant ())")]
void Unschedule (NSRunLoop aRunLoop, NSRunLoopMode mode);
[Export ("streamStatus")]
NSStreamStatus Status { get; }
@ -8802,12 +8863,26 @@ namespace XamCore.Foundation
[Protocolize]
NSNetServiceDelegate Delegate { get; set; }
#if XAMCORE_4_0
[Export ("scheduleInRunLoop:forMode:")]
void Schedule (NSRunLoop aRunLoop, NSString forMode);
// For consistency with other APIs (NSUrlConnection) we call this Unschedule
[Export ("removeFromRunLoop:forMode:")]
void Unschedule (NSRunLoop aRunLoop, NSString forMode);
#else
[Export ("scheduleInRunLoop:forMode:")]
void Schedule (NSRunLoop aRunLoop, string forMode);
// For consistency with other APIs (NSUrlConnection) we call this Unschedule
[Export ("removeFromRunLoop:forMode:")]
void Unschedule (NSRunLoop aRunLoop, string forMode);
#endif
[Wrap ("Schedule (aRunLoop, forMode.GetConstant ())")]
void Schedule (NSRunLoop aRunLoop, NSRunLoopMode forMode);
[Wrap ("Unschedule (aRunLoop, forMode.GetConstant ())")]
void Unschedule (NSRunLoop aRunLoop, NSRunLoopMode forMode);
[Export ("domain", ArgumentSemantic.Copy)]
string Domain { get; }
@ -8917,12 +8992,27 @@ namespace XamCore.Foundation
[Protocolize]
NSNetServiceBrowserDelegate Delegate { get; set; }
#if XAMCORE_4_0
[Export ("scheduleInRunLoop:forMode:")]
void Schedule (NSRunLoop aRunLoop, NSString forMode);
// For consistency with other APIs (NSUrlConnection) we call this Unschedule
[Export ("removeFromRunLoop:forMode:")]
void Unschedule (NSRunLoop aRunLoop, NSString forMode);
#else
[Export ("scheduleInRunLoop:forMode:")]
void Schedule (NSRunLoop aRunLoop, string forMode);
// For consistency with other APIs (NSUrlConnection) we call this Unschedule
[Export ("removeFromRunLoop:forMode:")]
void Unschedule (NSRunLoop aRunLoop, string forMode);
#endif
[Wrap ("Schedule (aRunLoop, forMode.GetConstant ())")]
void Schedule (NSRunLoop aRunLoop, NSRunLoopMode forMode);
[Wrap ("Schedule (aRunLoop, forMode.GetConstant ())")]
void Unschedule (NSRunLoop aRunLoop, NSRunLoopMode forMode);
[Export ("searchForBrowsableDomains")]
void SearchForBrowsableDomains ();
@ -9104,7 +9194,14 @@ namespace XamCore.Foundation
void EnqueueNotification (NSNotification notification, NSPostingStyle postingStyle);
[Export ("enqueueNotification:postingStyle:coalesceMask:forModes:")]
#if !XAMCORE_4_0
void EnqueueNotification (NSNotification notification, NSPostingStyle postingStyle, NSNotificationCoalescing coalesceMask, string [] modes);
#else
void EnqueueNotification (NSNotification notification, NSPostingStyle postingStyle, NSNotificationCoalescing coalesceMask, NSString [] modes);
[Wrap ("EnqueueNotification (notification, postingStyle, coalesceMask, modes.GetConstants ())")]
void EnqueueNotification (NSNotification notification, NSPostingStyle postingStyle, NSNotificationCoalescing coalesceMask, NSRunLoopMode [] modes);
#endif
[Export ("dequeueNotificationsMatching:coalesceMask:")]
void DequeueNotificationsMatchingcoalesceMask (NSNotification notification, NSNotificationCoalescing coalesceMask);
@ -9993,9 +10090,15 @@ namespace XamCore.Foundation
[Export ("scheduleInRunLoop:forMode:")]
void ScheduleInRunLoop (NSRunLoop runLoop, NSString runLoopMode);
[Wrap ("ScheduleInRunLoop (runLoop, runLoopMode.GetConstant ())")]
void ScheduleInRunLoop (NSRunLoop runLoop, NSRunLoopMode runLoopMode);
[Export ("removeFromRunLoop:forMode:")]
void RemoveFromRunLoop (NSRunLoop runLoop, NSString runLoopMode);
[Wrap ("RemoveFromRunLoop (runLoop, runLoopMode.GetConstant ())")]
void RemoveFromRunLoop (NSRunLoop runLoop, NSRunLoopMode runLoopMode);
// Disable warning for NSMutableArray
#pragma warning disable 618
[Export ("sendBeforeDate:components:from:reserved:")]
@ -10064,10 +10167,14 @@ namespace XamCore.Foundation
[Override]
void RemoveFromRunLoop (NSRunLoop runLoop, NSString mode);
// note: wrap'ed version using NSRunLoopMode will call the override
[Export ("scheduleInRunLoop:forMode:")]
[Override]
void ScheduleInRunLoop (NSRunLoop runLoop, NSString mode);
// note: wrap'ed version using NSRunLoopMode will call the override
[Export ("delegate", ArgumentSemantic.Assign), NullAllowed]
[Override]
NSObject WeakDelegate { get; set; }

Просмотреть файл

@ -313,7 +313,6 @@ COREANIMATION_CORE_SOURCES = \
COREANIMATION_SOURCES = \
CoreAnimation/CABasicAnimation.cs \
CoreAnimation/CADefs.cs \
CoreAnimation/CADisplayLink.cs \
CoreAnimation/CALayer.cs \
CoreAnimation/CAKeyFrameAnimation.cs \
CoreAnimation/CALayerDelegate.cs \
@ -591,6 +590,9 @@ FINDERSYNC_CORE_SOURCES = \
# Foundation
FOUNDATION_API_SOURCES = \
Foundation/Enums.cs \
FOUNDATION_CORE_SOURCES = \
Foundation/AdviceAttribute.cs \
Foundation/ConnectAttribute.cs \
@ -615,7 +617,6 @@ FOUNDATION_CORE_SOURCES = \
Foundation/PreserveAttribute.cs \
Foundation/ProtocolAttribute.cs \
Foundation/RegisterAttribute.cs \
Foundation/Enums.cs \
Foundation/NSObject.iOS.cs \
Foundation/NSAttributedString.iOS.cs \
Foundation/EnumDesktop.cs \