FromIntPtr() public static method

public static FromIntPtr ( IntPtr from ) : Object
from System.IntPtr
return Object
Esempio n. 1
0
 public MenuItem ItemWithTag(int tag)
 {
     return((MenuItem)Object.FromIntPtr((IntPtr)ObjCMessaging.objc_msgSend(
                                            NativeObject, "itemWithTag:",
                                            typeof(IntPtr),
                                            typeof(int), tag)));
 }
Esempio n. 2
0
 public MenuItem ItemWithTitle(string title)
 {
     return((MenuItem)Object.FromIntPtr((IntPtr)ObjCMessaging.objc_msgSend(
                                            NativeObject, "itemWithTitle:",
                                            typeof(IntPtr),
                                            typeof(IntPtr), new Cocoa.String(title).NativeObject)));
 }
Esempio n. 3
0
        private static object [] ArgumentsFromNative(object [] arguments, MethodInfo method)
        {
            object []        new_arguments = new object [arguments.Length];
            ParameterInfo [] parameters    = method.GetParameters();

            if (new_arguments.Length != parameters.Length)
            {
                throw new ArgumentException("The number of provided arguments does not match the expected count for the method");
            }
            for (int i = 0; i < arguments.Length; i++)
            {
                if (parameters [i].ParameterType.IsSubclassOf(typeof(Object)) || parameters [i].ParameterType == typeof(Object))
                {
                    if (arguments [i].GetType() != typeof(IntPtr))
                    {
                        throw new ArgumentException("Argument mismatch.  Attempted to convert a " + arguments  [i].GetType() + " to a " + parameters [i].ParameterType);
                    }

                    new_arguments [i] = Object.FromIntPtr((IntPtr)arguments [i]);
                }
                else
                {
                    new_arguments [i] = Convert.ChangeType(arguments [i], parameters [i].ParameterType);
                }
            }

            return(new_arguments);
        }
Esempio n. 4
0
 public MenuItem AddItem(string title, string action, string keyEquivalent)
 {
     return((MenuItem)Object.FromIntPtr((IntPtr)ObjCMessaging.objc_msgSend(NativeObject, "addItemWithTitle:action:keyEquivalent:", typeof(IntPtr),
                                                                           typeof(IntPtr), new Cocoa.String(title).NativeObject,
                                                                           typeof(IntPtr), ObjCMethods.sel_getUid(action),
                                                                           typeof(IntPtr), new Cocoa.String(keyEquivalent).NativeObject)));
 }
Esempio n. 5
0
        public static IntPtr Dispatch(IntPtr objc_class_ptr, IntPtr objc_selector, object [] arguments)
        {
            Object     target       = Object.FromIntPtr(objc_class_ptr);
            string     selector     = Marshal.PtrToStringAuto(objc_selector);
            MethodInfo method       = MethodInfoFromSelector(selector, target.GetType());
            IntPtr     return_value = IntPtr.Zero;

            arguments = ArgumentsFromNative(arguments, method);

            target.ImportMembers();

            try {
                return_value = ReturnToNative(method.Invoke(target, arguments));
            } catch (ArgumentException) {
                Console.WriteLine("Dispatch.Invoke caused an argument exception:");
                ParameterInfo [] parameters = method.GetParameters();
                for (int i = 0; i < parameters.Length; i++)
                {
                    Console.WriteLine("\t{0} {1} {2}", (arguments [i] != null ? arguments [i].GetType().ToString() : "null"), ((arguments [i] != null ? arguments [i].GetType() : typeof(void)) == parameters [i].ParameterType ? "==" : "!="), parameters [i].ParameterType.ToString());
                }
            }
            target.ExportMembers();

            return(return_value);
        }
        public static Alert AlertWithMessage(string messageTitle, string defaultButtonTitle, string alternateButtonTitle, string otherButtonTitle, string informativeText)
        {
            // Documentation indicates that nil values can be passed but they actually generate runtime errors.
            if (messageTitle == null)
            {
                messageTitle = "";
            }
            if ((defaultButtonTitle == null) || (defaultButtonTitle.Length == 0))
            {
                defaultButtonTitle = "OK";
            }
            if (alternateButtonTitle == null)
            {
                alternateButtonTitle = "";
            }
            if (otherButtonTitle == null)
            {
                otherButtonTitle = "";
            }
            if (informativeText == null)
            {
                informativeText = "";
            }

            return((Alert)Object.FromIntPtr((IntPtr)ObjCMessaging.objc_msgSend(ObjCClass.FromType(typeof(Alert)).ToIntPtr(), "alertWithMessageText:defaultButton:alternateButton:otherButton:informativeTextWithFormat:", typeof(System.IntPtr), typeof(System.IntPtr), new Cocoa.String(messageTitle).NativeObject, typeof(System.IntPtr), new Cocoa.String(defaultButtonTitle).NativeObject, typeof(System.IntPtr), new Cocoa.String(alternateButtonTitle).NativeObject, typeof(System.IntPtr), new Cocoa.String(otherButtonTitle).NativeObject, typeof(System.IntPtr), new Cocoa.String(informativeText).NativeObject)));
        }
 public Cocoa.Button AddButtonWithTitle(string buttonTitle)
 {
     if (buttonTitle == null)
     {
         throw new ArgumentNullException("buttonTitle");
     }
     if (buttonTitle.Length == 0)
     {
         throw new ArgumentException("buttonTitle: The buttonTitle parameter must be a non-empty string.");
     }
     return((Cocoa.Button)Object.FromIntPtr((IntPtr)ObjCMessaging.objc_msgSend(NativeObject, "addButtonWithTitle:", typeof(System.IntPtr), typeof(System.IntPtr), new Cocoa.String(buttonTitle).NativeObject)));
 }
Esempio n. 8
0
        public MenuItem AddItem(string title, ActionHandler action, string keyEquivalent)
        {
            MenuItem item = (MenuItem)Object.FromIntPtr((IntPtr)ObjCMessaging.objc_msgSend(
                                                            NativeObject, "addItemWithTitle:action:keyEquivalent:",
                                                            typeof(IntPtr),
                                                            typeof(IntPtr), new Cocoa.String(title).NativeObject,
                                                            typeof(IntPtr), IntPtr.Zero,
                                                            typeof(IntPtr), new Cocoa.String(keyEquivalent).NativeObject));

            if (action != null)
            {
                item.Click += action;
            }
            return(item);
        }
        public object [] ToArray()
        {
            ArrayList list = new ArrayList();
            Type      t    = null;

            for (int i = 0; i < (int)ObjCMessaging.objc_msgSend(NativeObject, "count", typeof(int)); i++)
            {
                list.Add(Object.FromIntPtr((IntPtr)ObjCMessaging.objc_msgSend(NativeObject, "objectAtIndex:", typeof(IntPtr), typeof(int), i)));
                if (t == null)
                {
                    t = list [0].GetType();
                }
            }
            return((object [])list.ToArray(t));
        }
 public StatusItem StatusItemWithLength(double length)
 {
     return((StatusItem)Object.FromIntPtr((IntPtr)ObjCMessaging.objc_msgSend(NativeObject, "statusItemWithLength:", typeof(System.IntPtr), typeof(System.Double), length)));
 }
Esempio n. 11
0
 public Color ToRGB()
 {
     return((Color)Object.FromIntPtr((IntPtr)ObjCMessaging.objc_msgSend(NativeObject, "colorUsingColorSpaceName:", typeof(IntPtr), typeof(IntPtr), new Cocoa.String("NSDeviceRGBColorSpace").NativeObject)));
 }
 public void ImportMembers()
 {
     foreach (FieldInfo field in this.GetType().GetFields(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance))
     {
         ConnectAttribute attr = (ConnectAttribute)Attribute.GetCustomAttribute(field, typeof(ConnectAttribute));
         if (attr != null)
         {
             string name         = (attr.Name != null ? attr.Name : field.Name);
             IntPtr native_value = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(IntPtr)));
             ObjCMethods.object_getInstanceVariable(this.NativeObject, name, native_value);
             field.SetValue(this, field.FieldType.IsPrimitive ? Marshal.PtrToStructure(native_value, field.FieldType) : Object.FromIntPtr(Marshal.ReadIntPtr(native_value)));
             Marshal.FreeHGlobal(native_value);
         }
     }
 }
Esempio n. 13
0
 public Cocoa.Object ItemAtRow(int row)
 {
     return((Cocoa.Object)Object.FromIntPtr((IntPtr)ObjCMessaging.objc_msgSend(NativeObject, "itemAtRow:", typeof(IntPtr), typeof(int), row)));
 }
Esempio n. 14
0
 public string [] ListForType(string type)
 {
     return((string [])((Array)Object.FromIntPtr((IntPtr)ObjCMessaging.objc_msgSend(NativeObject, "propertyListForType:", typeof(IntPtr), typeof(IntPtr), new Cocoa.String(type).NativeObject))).ToArray());
 }
 public string ItemTitleAtIndex(int index)
 {
     return(Object.FromIntPtr((IntPtr)ObjCMessaging.objc_msgSend(NativeObject, "itemTitleAtIndex:", typeof(System.IntPtr), typeof(System.Int32), index)).ToString());
 }
Esempio n. 16
0
 public static Color FromHueSaturationBrightnessAlpha(float hue, float saturation, float brightness, float alpha)
 {
     return((Color)Object.FromIntPtr((IntPtr)ObjCMessaging.objc_msgSend((IntPtr)ObjCClass.FromType(typeof(Color)).ToIntPtr(), "colorWithDeviceHue:saturation:brightness:alpha:", typeof(IntPtr), typeof(float), hue, typeof(float), saturation, typeof(float), brightness, typeof(float), alpha)));
 }
Esempio n. 17
0
 public static Bundle BundleWithPath(string path)
 {
     return((Bundle)Object.FromIntPtr((IntPtr)ObjCMessaging.objc_msgSend((IntPtr)ObjCClass.FromType(typeof(Bundle)).ToIntPtr(), "bundleWithPath:", typeof(IntPtr), typeof(IntPtr), new Cocoa.String(path).NativeObject)));
 }