Exemplo n.º 1
0
            private void ForwardDelegateMethod(string selName, NSObject arg1)
            {
                var sel = new Selector(selName);

                if (_originalDelegate.RespondsToSelector(sel))
                {
                    void_objc_msgSend_IntPtr(
                        _originalDelegate.Handle,
                        sel.Handle,
                        arg1 != null ? arg1.Handle : IntPtr.Zero);
                }
            }
Exemplo n.º 2
0
        protected virtual void CheckNSObjectProtocol(NSObject obj)
        {
            // not documented to allow null, but commonly used this way. OTOH it's not clear what code answer this
            // (it might be different implementations) but we can make sure that Apple allows null with this test
            // ref: https://bugzilla.xamarin.com/show_bug.cgi?id=35924
            var kind_of_null = obj.IsKindOfClass(null);

            if (kind_of_null)
            {
                ReportError("{0} : IsKindOfClass(null) failed", instance_type_name);
            }
            var is_member_of_null = obj.IsMemberOfClass(null);

            if (is_member_of_null)
            {
                ReportError("{0} : IsMemberOfClass(null) failed", instance_type_name);
            }
            var respond_to_null = obj.RespondsToSelector(null);

            if (respond_to_null)
            {
                ReportError("{0} : RespondToSelector(null) failed", instance_type_name);
            }
            var conforms_to_null = obj.ConformsToProtocol(IntPtr.Zero);

            if (conforms_to_null)
            {
                ReportError("{0} : ConformsToProtocol(null) failed", instance_type_name);
            }
        }
Exemplo n.º 3
0
        internal static void DumpAccessibilityTree(NSObject obj = null, int indentLevel = 0)
        {
            if (obj == null)
            {
                obj = NSApplication.SharedApplication;
            }

            string desc = obj.Description;

            desc = desc.PadLeft(desc.Length + indentLevel, ' ');
            Console.WriteLine($"{desc}");

            if (!obj.RespondsToSelector(new Selector("accessibilityChildren")))
            {
                string notAccessible = "Not accessible";
                Console.WriteLine($"{notAccessible.PadLeft (notAccessible.Length + indentLevel + 2, ' ')}");
                return;
            }

            NSArray children = (NSArray)obj.PerformSelector(new Selector("accessibilityChildren"));

            if (children == null)
            {
                return;
            }

            for (nuint i = 0; i < children.Count; i++)
            {
                DumpAccessibilityTree(children.GetItem <NSObject> (i), indentLevel + 2);
            }
        }
Exemplo n.º 4
0
        public static bool AddMethod(this NSObject obj, Selector selector, Delegate imp)
        {
            if (obj.RespondsToSelector(selector))
            {
                return(false);
            }

            var classHandle = obj.Class.Handle;

            return(LibObjc.class_addMethod(classHandle, selector.Handle, imp, "v@:"));
        }
Exemplo n.º 5
0
        public override NSObject TargetForAction(Selector theAction, NSObject theTarget, NSObject sender)
        {
            if (theAction == null)
            {
                return(null);
            }

            if (theTarget != null && theTarget.RespondsToSelector(theAction))
            {
                return(theTarget);
            }

            return(base.TargetForAction(theAction, theTarget, sender));
        }
Exemplo n.º 6
0
        public void ChangeAttributes(NSObject sender)
        {
            var sel = new Selector("convertAttributes:");

            if (sender.RespondsToSelector(sel))
            {
                var ptr = MacApi.LibObjc.IntPtr_objc_msgSend_IntPtr(sender.Handle, sel.Handle, (SelectedAttributes ?? new NSDictionary()).Handle);
                if (ObjCRuntime.Runtime.GetNSObject(ptr) is NSDictionary attrs)
                {
                    SelectedAttributes = (NSMutableDictionary)attrs.MutableCopy();
                    NSFontManager.SharedFontManager.SetSelectedAttributes(attrs, false);
                }
            }
        }
Exemplo n.º 7
0
        public override bool SendAction(Selector theAction, NSObject theTarget, NSObject sender)
        {
            if (theAction == null)
            {
                return(false);
            }

            if (base.SendAction(theAction, theTarget, sender))
            {
                return(true);
            }

            // FIXME
            // The following code should not be necessary, it should have been done by base. What am I missing?
            // It's here to make autocompletion work properly:
            // Without this, double clicking a word in a completion list of a text field (initial wizard) does not work.

            if (theAction.Name == "tableAction:")             // Prevent crashes when used with certain other selectors.
            {
                if (theTarget != null && theTarget.RespondsToSelector(theAction))
                {
                    try
                    {
                        var signature  = theTarget.GetMethodSignature(theAction);
                        var invocation = signature.ToInvocation();
                        invocation.Selector = theAction;
                        if (signature.NumberOfArguments > 2)
                        {
                            invocation.SetArgument(sender, 2);
                        }
                        invocation.Invoke(theTarget);
                        return(true);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine($"Exception in invocation of '{theAction.Name}':{e}");
                    }
                }
            }
            return(false);
        }
Exemplo n.º 8
0
        public override void Connect()
        {
            string sel = "connectWithOptions:";

            RoyalRDSConnection rdpData = Data as RoyalRDSConnection;

            rdpData.BeginTemporaryMode();
            bool autologon = rdpData.CredentialAutologon;

            NSString hostname = rdpData.URI.ResolveTokensApi(rdpData).NS();
            int      port     = rdpData.RDPPort;

            rdpData.EndTemporaryMode();

            NSString username = NSString.Empty;
            //NSString domain = NSString.Empty;
            NSString password = NSString.Empty;

            rdpData.BeginTemporaryMode();
            CredentialInfo effectiveCred = rdpData.GetEffectiveCredential();

            rdpData.EndTemporaryMode();

            if (autologon && effectiveCred != null)
            {
                string usernameStr = effectiveCred.Username;
                string passwordStr = effectiveCred.Password;

                username = usernameStr.NS();
                password = passwordStr.NS();
            }

            int screenWidth  = 0;
            int screenHeight = 0;

            if (rdpData.DesktopWidth == 0 && rdpData.DesktopHeight == 0)
            {
                screenWidth  = (int)TabViewItem.View.CastTo <NSView>().Frame.Width;
                screenHeight = (int)TabViewItem.View.CastTo <NSView>().Frame.Height;
            }
            else
            {
                rdpData.BeginTemporaryMode();
                screenWidth  = rdpData.DesktopWidth;
                screenHeight = rdpData.DesktopHeight;
                rdpData.EndTemporaryMode();
            }

            // TODO: Screen Width should actually be a multitude of 4, not 8, but 8 seems to work just fine with rdesktop
            if (screenWidth % 8 != 0)
            {
                screenWidth = (screenWidth / 8) * 8;
            }

            m_screenWidth  = screenWidth;
            m_screenHeight = screenHeight;

            CordRdpOptions options = new CordRdpOptions();

            rdpData.BeginTemporaryMode();
            options.Hostname = hostname;
            options.Port     = port;
            options.Username = username;
            //options.Domain = domain;
            options.Password         = password;
            options.ConnectToConsole = rdpData.ConnectToAdministerOrConsole;
            options.SmartSize        = false;      //rdpData.SmartSizing;
            options.ScreenWidth      = screenWidth;
            options.ScreenHeight     = screenHeight;
            options.ColorDepth       = rdpData.ColorDepth;
            options.AllowWallpaper   = rdpData.AllowWallpaper;
            options.AllowAnimations  = rdpData.AllowMenuAnimations;
            options.FontSmoothing    = rdpData.AllowFontSmoothing;
            options.ShowWindowContentsWhileDragging = rdpData.AllowFullWindowDrag;
            options.ShowThemes           = rdpData.AllowThemes;
            options.RedirectPrinters     = rdpData.RedirectPrinters;
            options.RedirectDiskDrives   = rdpData.RedirectDrives;
            options.AudioRedirectionMode = rdpData.AudioRedirectionMode;
            rdpData.EndTemporaryMode();

            if (m_nativeController.RespondsToSelector(sel))
            {
                m_nativeController.SendMessage(sel, options);
            }

            options.Release();
        }
Exemplo n.º 9
0
 public static bool IsSwfControl(this NSObject obj)
 {
     return(obj.RespondsToSelector(swfMarkSel));
 }