Пример #1
0
 public MenuItem ItemWithTag(int tag)
 {
     return((MenuItem)Object.FromIntPtr((IntPtr)ObjCMessaging.objc_msgSend(
                                            NativeObject, "itemWithTag:",
                                            typeof(IntPtr),
                                            typeof(int), tag)));
 }
        public static Type TypeForIntPtr(IntPtr cls)
        {
            if (cls == IntPtr.Zero)
            {
                return(typeof(void));
            }

            string class_name = (string)ObjCMessaging.objc_msgSend((IntPtr)ObjCMessaging.objc_msgSend(cls, "className", typeof(IntPtr)), "cString", typeof(string));

            if (class_name.StartsWith("%"))
            {
                class_name = class_name.Substring(1);
            }

            Type type = TypeForClassname(class_name);

            IntPtr superclass = (IntPtr)ObjCMessaging.objc_msgSend(cls, "superclass", typeof(IntPtr));

            while (type == null)
            {
                class_name = (string)ObjCMessaging.objc_msgSend((IntPtr)ObjCMessaging.objc_msgSend(superclass, "className", typeof(IntPtr)), "cString", typeof(string));

                if (class_name == null || class_name == "")
                {
                    throw new InvalidOperationException("There is no managed type reflecting: " + (string)ObjCMessaging.objc_msgSend((IntPtr)ObjCMessaging.objc_msgSend(cls, "className", typeof(IntPtr)), "cString", typeof(string)));
                }

                type = TypeForClassname(class_name);

                superclass = (IntPtr)ObjCMessaging.objc_msgSend(superclass, "superclass", typeof(IntPtr));
            }

            return(type);
        }
Пример #3
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)));
 }
Пример #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)));
 }
Пример #5
0
        public static void LoadNib(string nibname)
        {
            Dictionary dict = new Dictionary("NSOwner", Application.SharedApplication);

            ObjCMessaging.objc_msgSend((IntPtr)ObjCClass.FromType(typeof(Bundle)).ToIntPtr(), "loadNibFile:externalNameTable:withZone:", typeof(bool), typeof(System.IntPtr), new Cocoa.String(nibname).NativeObject, typeof(System.IntPtr), dict.NativeObject, typeof(System.IntPtr), Application.SharedApplication.Zone);
            ObjCMessaging.objc_msgSend((IntPtr)ObjCClass.FromType(typeof(Bundle)).ToIntPtr(), "loadNibNamed:owner:", typeof(bool), typeof(System.IntPtr), new Cocoa.String(nibname).NativeObject, typeof(System.IntPtr), Application.SharedApplication.NativeObject);
        }
Пример #6
0
        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 void EndSheet(Cocoa.Window sheet, int returnCode)
 {
     if (sheet == null)
     {
         throw new ArgumentNullException("sheet");
     }
     ObjCMessaging.objc_msgSend(NativeObject, "endSheet:returnCode:", typeof(void), typeof(System.IntPtr), sheet.NativeObject, typeof(int), returnCode);
 }
Пример #8
0
 /// <summary>
 ///
 /// </summary>
 /// <param name"aPoint"></param>
 /// <oaran name="aView"></param>
 /// <return></return>
 public Point ConvertPointFromView(Point aPoint, View aView)
 {
     return((Point)ObjCMessaging.objc_msgSend(
                NativeObject, "convertPoint:fromView:",
                typeof(Point),                        // return value type
                typeof(Point), aPoint,                // 1st arg
                typeof(IntPtr), aView.NativeObject)); // 2nd arg
 }
 public bool DragColor(Color aColor, Event aEvent, View aView)
 {
     return((bool)ObjCMessaging.objc_msgSend(NativeObject, "dragColor:withEvent:fromView:",
                                             typeof(System.Boolean),               // return value
                                             typeof(IntPtr), aColor.NativeObject,  // dragColor:
                                             typeof(IntPtr), aEvent.NativeObject,  // withEvent:
                                             typeof(IntPtr), aView.NativeObject)); // fromView:
 }
Пример #10
0
        public override void TestVarargMarshaling(int iterations)
        {
            var instance = new Cocoa.String("some string to test");

            for (int i = 0; i < iterations; i++)
            {
                new Cocoa.String(( IntPtr )ObjCMessaging.objc_msgSend(instance.NativeObject, "stringByAppendingFormat:", typeof(IntPtr), typeof(IntPtr), new Cocoa.String(" %@ %@ %f %d %d").NativeObject, typeof(IntPtr), new Cocoa.String("some").NativeObject, typeof(IntPtr), new Cocoa.String("text").NativeObject, typeof(double), System.Math.PI, typeof(bool), true, typeof(int), 10)).ToString();
            }
        }
Пример #11
0
 public override string ToString()
 {
     /// This function used to be just cal NSString's cString, however this cause some downstream
     /// character encoding issues. Especially in the Event class. The fix for this was to
     /// tell this function to encode the string using UTF-8.
     /// Todd Schavey - [email protected]
     ///
     return((string)ObjCMessaging.objc_msgSend(NativeObject, "cStringUsingEncoding:", typeof(string), typeof(int), 4 /*NSUTF8StringEncoding*/));
 }
Пример #12
0
 /// <summary>
 /// Instanciates an instance of Font with a specify font name and size.
 /// </summary>
 /// <param name="aFontName">
 /// A fully specified family-face name, such as Helvetica-BoldOblique or Times-Roman.
 /// </param>
 /// <param name="aFontSize">
 /// Used to scale the font. If you use a fontSize of 0.0, this method uses the default User Font size
 /// </param>
 public Font(string aFontName, float aFontSize)
 {
     NativeObject = (IntPtr)ObjCMessaging.objc_msgSendSuper(NativeObject,
                                                            "initWithName:size:",
                                                            typeof(IntPtr),
                                                            typeof(IntPtr), new Cocoa.String(aFontName).NativeObject, /// Name
                                                            typeof(float), aFontSize                                  /// Size
                                                            );
 }
Пример #13
0
 public View(Rect frame) : base()
 {
     if (this.GetType().IsSubclassOf(typeof(View)))
     {
         NativeObject = (IntPtr)ObjCMessaging.objc_msgSendSuper(NativeObject, "initWithFrame:", typeof(IntPtr), typeof(Rect), frame);
     }
     else
     {
         throw new ArgumentException("initWithFrame: directly on NSView is unsupported");
     }
 }
Пример #14
0
        public void RegisterDragTypes(string [] types)
        {
            MutableArray array = new MutableArray();

            foreach (string t in types)
            {
                array.Add(new Cocoa.String(t));
            }

            ObjCMessaging.objc_msgSend(NativeObject, "registerForDraggedTypes:", typeof(void), typeof(IntPtr), array.NativeObject);
        }
Пример #15
0
 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)));
 }
Пример #16
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);
        }
Пример #17
0
        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));
        }
Пример #18
0
        public void BeginSheet(string directory, string filename, Cocoa.Window docWindow, SavePanelHandler modalDelegate, System.IntPtr contextInfo)
        {
            if (modalDelegate == null)
            {
                throw new ArgumentNullException("modalDelegate");
            }
            Cocoa.Object target   = (Cocoa.Object)modalDelegate.Target;
            MethodInfo   method   = modalDelegate.Method;
            string       selector = method.Name;

            foreach (ExportAttribute export_attribute in Attribute.GetCustomAttributes(method, typeof(ExportAttribute)))
            {
                if (export_attribute.Selector != null)
                {
                    selector = export_attribute.Selector;
                }
            }
            ObjCMessaging.objc_msgSend(NativeObject, "beginSheetForDirectory:file:modalForWindow:modalDelegate:didEndSelector:contextInfo:", typeof(void), typeof(System.IntPtr), (directory == null) ? IntPtr.Zero : new Cocoa.String(directory).NativeObject, typeof(System.IntPtr), (filename == null) ? IntPtr.Zero : new Cocoa.String(filename).NativeObject, typeof(System.IntPtr), (docWindow == null) ? IntPtr.Zero : docWindow.NativeObject, typeof(System.IntPtr), target.NativeObject, typeof(System.IntPtr), ObjCMethods.sel_getUid(selector), typeof(System.IntPtr), contextInfo);
        }
Пример #19
0
 public void Close()
 {
     ObjCMessaging.objc_msgSend(NativeObject, "close", typeof(void));
 }
Пример #20
0
 public void Open()
 {
     ObjCMessaging.objc_msgSend(NativeObject, "open", typeof(void));
 }
 public void RunApplication()
 {
     ObjCMessaging.objc_msgSend(NativeObject, "run", typeof(void));
 }
 public int RunModalSession(IntPtr modalsession)
 {
     return((int)ObjCMessaging.objc_msgSend(NativeObject, "runModalSession:", typeof(int), typeof(IntPtr), modalsession));
 }
 public void EndModalSession(IntPtr modalsession)
 {
     ObjCMessaging.objc_msgSend(NativeObject, "endModalSession:", typeof(void), typeof(IntPtr), modalsession);
 }
 public IntPtr ModalSessionForWindow(Window window)
 {
     return((IntPtr)ObjCMessaging.objc_msgSend(NativeObject, "beginModalSessionForWindow:", typeof(IntPtr), typeof(IntPtr), window.NativeObject));
 }
 public void SetAppleMenu(Menu menu)
 {
     ObjCMessaging.objc_msgSend(NativeObject, "setAppleMenu:", typeof(void), typeof(IntPtr), menu.NativeObject);
 }
 public void Add(Object o)
 {
     ObjCMessaging.objc_msgSend(NativeObject, "addObject:", typeof(void), typeof(IntPtr), o.NativeObject);
 }
Пример #27
0
 public FileWrapper(string path) : base()
 {
     NativeObject = (IntPtr)ObjCMessaging.objc_msgSend(NativeObject, "initWithPath:", typeof(IntPtr), typeof(IntPtr), new Cocoa.String(path).NativeObject);
 }
Пример #28
0
 public int RunModal(string directory, string filename)
 {
     return((int)ObjCMessaging.objc_msgSend(NativeObject, "runModalForDirectory:file:", typeof(System.Int32), typeof(System.IntPtr), (directory == null) ? IntPtr.Zero : new Cocoa.String(directory).NativeObject, typeof(System.IntPtr), (filename == null) ? IntPtr.Zero : new Cocoa.String(filename).NativeObject));
 }
Пример #29
0
 public void Stop()
 {
     ObjCMessaging.objc_msgSend(NativeObject, "invalidate", typeof(void));
 }
Пример #30
0
 public int RunModal()
 {
     return((int)ObjCMessaging.objc_msgSend(NativeObject, "runModal", typeof(System.Int32)));
 }