Skip to content

Commit

Permalink
[AppKit] Add some of the missing NSAccessibility bits (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
iain authored and chamons committed May 31, 2016
1 parent d23c146 commit f535df6
Show file tree
Hide file tree
Showing 2 changed files with 1,133 additions and 0 deletions.
145 changes: 145 additions & 0 deletions src/AppKit/NSAccessibility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,15 @@ public enum NSAccessibilityUnits : nint
Picas = 4
}

[Mac (10,9)]
[Native]
public enum NSAccessibilityPriorityLevel : nint
{
Low = 10,
Medium = 50,
High = 90
}

#if !COREBUILD
public partial class NSAccessibility
{
Expand All @@ -80,6 +89,142 @@ public static CGPoint GetPointInView (NSView parentView, CGPoint point)
{
return NSAccessibilityPointInView (parentView, point);
}

[Mac (10,7)]
[DllImport (Constants.AppKitLibrary)]
static extern void NSAccessibilityPostNotificationWithUserInfo (IntPtr element, IntPtr notification, IntPtr userInfo);

public static void PostNotification (NSObject element, NSString notification, NSDictionary userInfo)
{
if (element == null)
throw new ArgumentNullException ("element");

if (notification == null)
throw new ArgumentNullException ("notification");

IntPtr userInfoHandle;
if (userInfo == null)
userInfoHandle = IntPtr.Zero;
else
userInfoHandle = userInfo.Handle;

NSAccessibilityPostNotificationWithUserInfo (element.Handle, notification.Handle, userInfoHandle);
}

[DllImport (Constants.AppKitLibrary)]
static extern void NSAccessibilityPostNotification (IntPtr element, IntPtr notification);

public static void PostNotification (NSObject element, NSString notification)
{
if (element == null)
throw new ArgumentNullException ("element");

if (notification == null)
throw new ArgumentNullException ("notification");

NSAccessibilityPostNotification (element.Handle, notification.Handle);
}

[DllImport (Constants.AppKitLibrary)]
static extern IntPtr NSAccessibilityRoleDescription (IntPtr role, IntPtr subrole);

public static string GetRoleDescription (NSString role, NSString subrole)
{
if (role == null)
throw new ArgumentNullException ("role");

IntPtr subroleHandle;
if (subrole == null)
subroleHandle = IntPtr.Zero;
else
subroleHandle = subrole.Handle;

IntPtr handle = NSAccessibilityRoleDescription (role.Handle, subroleHandle);
return NSString.FromHandle (handle);
}

[DllImport (Constants.AppKitLibrary)]
static extern IntPtr NSAccessibilityRoleDescriptionForUIElement (IntPtr element);

public static string GetRoleDescription (NSObject element)
{
if (element == null)
throw new ArgumentNullException ("element");

IntPtr handle = NSAccessibilityRoleDescriptionForUIElement (element.Handle);
return NSString.FromHandle (handle);
}

[DllImport (Constants.AppKitLibrary)]
static extern IntPtr NSAccessibilityActionDescription (IntPtr action);

public static string GetActionDescription (NSString action)
{
if (action == null)
throw new ArgumentNullException ("action");

IntPtr handle = NSAccessibilityActionDescription (action.Handle);
return NSString.FromHandle (handle);
}

[DllImport (Constants.AppKitLibrary)]
static extern IntPtr NSAccessibilityUnignoredAncestor (IntPtr element);

public static NSObject GetUnignoredAncestor (NSObject element)
{
if (element == null)
throw new ArgumentNullException ("element");

var handle = NSAccessibilityUnignoredAncestor (element.Handle);
return Runtime.GetNSObject (handle);
}

[DllImport (Constants.AppKitLibrary)]
static extern IntPtr NSAccessibilityUnignoredDescendant (IntPtr element);

public static NSObject GetUnignoredDescendant (NSObject element)
{
if (element == null)
throw new ArgumentNullException ("element");

var handle = NSAccessibilityUnignoredDescendant (element.Handle);

return Runtime.GetNSObject (handle);
}

[DllImport (Constants.AppKitLibrary)]
static extern IntPtr NSAccessibilityUnignoredChildren (IntPtr originalChildren);

public static NSObject[] GetUnignoredChildren (NSArray originalChildren)
{
if (originalChildren == null)
throw new ArgumentNullException ("originalChildren");

var handle = NSAccessibilityUnignoredChildren (originalChildren.Handle);

return NSArray.ArrayFromHandle<NSObject> (handle);
}

[DllImport (Constants.AppKitLibrary)]
static extern IntPtr NSAccessibilityUnignoredChildrenForOnlyChild (IntPtr originalChild);

public static NSObject[] GetUnignoredChildren (NSObject originalChild)
{
if (originalChild == null)
throw new ArgumentNullException ("originalChild");

var handle = NSAccessibilityUnignoredChildrenForOnlyChild (originalChild.Handle);

return NSArray.ArrayFromHandle<NSObject> (handle);
}

[DllImport (Constants.AppKitLibrary)]
static extern bool NSAccessibilitySetMayContainProtectedContent (bool flag);

public static bool SetMayContainProtectedContent (bool flag)
{
return NSAccessibilitySetMayContainProtectedContent (flag);
}
}
#endif
}
Loading

0 comments on commit f535df6

Please sign in to comment.