Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AppKit] Add some of the missing NSAccessibility bits #79

Merged
merged 1 commit into from
May 31, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe you need to check against null ptr here too. element and notification can be null and you will get a NRE.


[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