Example #1
0
        public override bool MakeFirstResponder(NSResponder aResponder)
        {
            var prevFirstResponder = FirstResponder;

            if (base.MakeFirstResponder(aResponder) && IsKeyWindow && prevFirstResponder != FirstResponder)
            {
                var prev = XplatUICocoa.GetHandle(prevFirstResponder);
                var next = XplatUICocoa.GetHandle(aResponder);

                if (prev != IntPtr.Zero)
                {
                    driver.SendMessage(prev, Msg.WM_KILLFOCUS, next, IntPtr.Zero);
                }
                if (next != IntPtr.Zero && FirstResponder == aResponder)
                {
                    driver.SendMessage(next, Msg.WM_SETFOCUS, prev, IntPtr.Zero);
                }

                // If the newly focused control is not a MWF control's view, then it must be some embedded native control. Try
                // to update the ActiveControl chain in Form to match it using similar approach as in Control.WmSetFocus.
                var wrapperControl = Control.FromChildHandle(next);
                if (wrapperControl != null && wrapperControl.Handle != next)
                {
                    wrapperControl.Select(wrapperControl);
                }

                return(true);
            }

            return(false);
        }
        public void WindowDidUpdate(NSNotification notification)
        {
            if (this.View != null &&
                this.View.Window != null &&
                this.View.Window.FirstResponder != null)
            {
                NSTextField tv = ApiUtils.GetFirstResponderTextField(this.View.Window);

                if (tv != null)
                {
                    if (m_prevResponder != tv &&
                        ApiUtils.IsTextFieldFirstResponder(this.View.Window, textFieldComputerName) &&
                        textFieldComputerName.StringValue.IsEqualToString(NSString.Empty) &&
                        !textFieldDisplayName.StringValue.IsEqualToString(NSString.Empty))
                    {
                        textFieldComputerName.StringValue = textFieldDisplayName.StringValue;
                    }

                    m_prevResponder = tv;
                }
                else
                {
                    m_prevResponder = this.View.Window.FirstResponder;
                }
            }
        }
Example #3
0
        public override bool MakeFirstResponder(NSResponder aResponder)
        {
            var ok   = base.MakeFirstResponder(aResponder);
            var next = FirstResponder;

            if (ok)
            {
                var c = XplatUICocoa.GetHandle(next);
                if (prevFocus != c && !(next is MonoWindow))
                {
                    if (prevFocus != IntPtr.Zero)
                    {
                        driver.SendMessage(prevFocus, Msg.WM_KILLFOCUS, c, IntPtr.Zero);
                    }

                    // If sending WM_SETFOCUS causes another immediate change of focus, we need to have prevFocus updated
                    var oldPrefFocus = prevFocus;
                    prevFocus = c;

                    if (c != IntPtr.Zero)
                    {
                        driver.SendMessage(c, Msg.WM_SETFOCUS, oldPrefFocus, IntPtr.Zero);
                    }
                }
                else
                {
                    prevFocus = c;
                }
            }
            return(ok);
        }
        public void WindowDidUpdate(NSNotification notification)
        {
            if (View != null &&
                View.Window != null &&
                View.Window.FirstResponder != null)
            {
                NSTextField tv = ApiUtils.GetFirstResponderTextField(View.Window);

                if (tv != null)
                {
                    if (m_prevResponder != tv &&
                        ApiUtils.IsTextFieldFirstResponder(View.Window, textFieldComputerName) &&
                        NSString.IsNullOrEmpty(textFieldComputerName.StringValue) &&
                        !NSString.IsNullOrEmpty(textFieldDisplayName.StringValue))
                    {
                        textFieldComputerName.StringValue = textFieldDisplayName.StringValue;
                    }

                    m_prevResponder = tv;
                }
                else
                {
                    m_prevResponder = View.Window.FirstResponder;
                }
            }
        }
Example #5
0
        /// <summary>
        /// Gets a Boolean value indicating of the given command is allowed to execute.
        /// </summary>
        /// <param name="command">The command of interest.</param>
        /// <returns><c>true</c> if the command should be allowed to execute, <c>false</c> otherwise.</returns>
        protected override bool HandleCanExecuteChangedForCommand(VisualRelayCommand command)
        {
            var context = Context;

            if (command.UniqueId == CancelRomsImportCommand.UniqueId)
            {
                context = ProgressIndicatorViewModel;
            }
            var canExecute = command.CanExecute(context);

            if (command.UniqueId == RemoveRomsCommand.UniqueId)
            {
                if (canExecute)
                {
                    NSResponder firstResponder = null;
                    if ((NSApplication.SharedApplication != null) && (NSApplication.SharedApplication.MainWindow != null))
                    {
                        firstResponder = NSApplication.SharedApplication.MainWindow.FirstResponder;
                        canExecute     = firstResponder is NSTableView;
                        if (canExecute)
                        {
                            canExecute = (RomListView != null) && (RomListView.FindChild <NSTableView>() == firstResponder);
                        }
                        command.MenuItem.NativeMenuItem.KeyEquivalent             = canExecute ? RemoveRomsCommand.KeyboardShortcutKey : string.Empty;
                        command.MenuItem.NativeMenuItem.KeyEquivalentModifierMask = (NSEventModifierMask)(canExecute ? RemoveRomsCommand.KeyboardShortcutModifiers : OSModifierKeys.None);
                    }
                }
            }
            return(canExecute);
        }
Example #6
0
 public ModalDialogContext()
 {
     keyWindow = NSApplication.SharedApplication.KeyWindow;
     if (keyWindow != null)
     {
         firstResponder = keyWindow.FirstResponder;
     }
 }
Example #7
0
 void TickHandleAction(NSTimer obj)
 {
     if (window.FirstResponder != responder)
     {
         responder = (AppKit.NSResponder)window.FirstResponder;
         Changed?.Invoke(this, responder);
     }
 }
Example #8
0
        public virtual bool EmbeddedControlDoCommandBySelector(NSResponder target, Selector selector)
        {
            // This method allows you to choose which [menu] commands should be processed by embedded native control itself,
            // and which commands should be handled in the form of WM_KEYDOWN/WM_KEYUP message pair by it's WinForms parent control.

            // By default, the parent control performs all commands (copy:, paste:, etc..).
            return((snatchCommands ? this : target).TryToPerformwith(selector, this));
        }
Example #9
0
 /// <summary>
 /// Ensures that an event handler is invoked on main the thread.
 /// </summary>
 /// <param name="instance">Typically a NSController or NSView that must handle an event from a ViewModel.</param>
 /// <param name="sender">Sender of the orginal event.</param>
 /// <param name="args">Event data.</param>
 /// <param name="handler">The event handler to ensure is executed on the main thread.</param>
 /// <typeparam name="TEventArgs">The data type of the event handler's data.</typeparam>
 public static void HandleEventOnMainThread <TEventArgs>(this NSResponder instance, object sender, TEventArgs args, System.Action <object, TEventArgs> handler) where TEventArgs : System.EventArgs
 {
     if (!OSDispatcher.IsMainThread)
     {
         instance.InvokeOnMainThread(() => handler(sender, args));
         return;
     }
     handler(sender, args);
 }
            public override bool ValidateProposedFirstResponder(NSResponder responder, NSEvent forEvent)
            {
                if (responder is PropertyButton)
                {
                    return(true);
                }

                return(base.ValidateProposedFirstResponder(responder, forEvent));
            }
Example #11
0
 public override bool MakeFirstResponder(NSResponder aResponder)
 {
     if (aResponder is NSView view)
     {
         context.ChangeFocusedView(new MacViewWrapper(view));
         RefreshBar(view);
     }
     return(base.MakeFirstResponder(aResponder));
 }
        // See first paragraph under "How the Field Editor Works"
        // https://developer.apple.com/library/archive/documentation/TextFonts/Conceptual/CocoaTextArchitecture/TextEditing/TextEditing.html#//apple_ref/doc/uid/TP40009459-CH3-SW29
        static NSResponder ResolveResponder(NSResponder responder)
        {
            if (responder is NSText text && text.FieldEditor)
            {
                return((text.WeakDelegate as NSResponder) ?? responder);
            }

            return(responder);
        }
Example #13
0
        private static bool GetInheritedValue(this NSResponder visual, string property, out object propertyValue)
        {
            bool gotValue = false;

            propertyValue = null;
            var         window = visual as NSWindow;
            var         view   = visual as NSView;
            NSResponder root   = window;

            if (root == null)
            {
                if (view != null)
                {
                    root = view.Window;
                }
                if (root == null)
                {
                    root = INTV.Shared.Utility.SingleInstanceApplication.Current;
                }
            }
            while ((visual != null) && !gotValue)
            {
                var properties = AttachedProperties.GetEntry(visual);
                if (properties != null)
                {
                    gotValue = properties.TryGetValue(property, out propertyValue);
                }
                if (!gotValue)
                {
                    if (view != null)
                    {
                        window = view.Window;
                        visual = view.Superview;
                        view   = visual as NSView;
                        if (view == null)
                        {
                            visual = window;
                        }
                        if (visual == null)
                        {
                            visual = INTV.Shared.Utility.SingleInstanceApplication.Current;
                        }
                    }
                    else if (window != null)
                    {
                        visual = INTV.Shared.Utility.SingleInstanceApplication.Current;
                        window = null;
                    }
                    else
                    {
                        visual = null;
                    }
                }
            }
            return(gotValue);
        }
Example #14
0
        public override bool MakeFirstResponder(NSResponder aResponder)
        {
            var result = base.MakeFirstResponder(aResponder);

            if (result)
            {
                var notification = NSNotification.FromName(CustomWindowNotifications.WindowMakeFirstResponder, aResponder);
                NSNotificationCenter.DefaultCenter.PostNotification(notification);
            }
            return(result);
        }
Example #15
0
            public bool ValidateProposedFirstResponder(NSResponder responder, NSEvent forEvent)
            {
                if (responder is PropertyButton)
                {
                    return(true);
                }

                bool baseRet = bool_objc_msgSendSuper_IntPtr_IntPtr(this.SuperHandle, selValidateProposedFirstResponder_ForEvent_Handle, responder.Handle, forEvent == null ? IntPtr.Zero : forEvent.Handle);

                return(true);
            }
Example #16
0
        NSViewController GetViewController()
        {
            NSResponder r = this;

            while (r != null)
            {
                var c = r as NSViewController;
                if (c != null)
                {
                    return(c);
                }
                r = r.NextResponder;
            }
            return(null);
        }
Example #17
0
            public override void Validate()
            {
                NSResponder responder = NSApplication.SharedApplication.KeyWindow;

                while (responder != null)
                {
                    if (responder.RespondsToSelector(Action))
                    {
                        Enabled = true;
                        return;
                    }

                    responder = responder.NextResponder;
                }

                Enabled = false;
            }
        public override void ObserveValue(NSString keyPath, NSObject ofObject, NSDictionary change, IntPtr context)
        {
            var window = ofObject as NSWindow;

            if (window != null && keyPath == key)
            {
                var firstResponder = change [ChangeNewKey] as NSResponder;
                if (firstResponder != null && !(firstResponder is NSWindow) && (!(firstResponder is NSView view) || view.Window == window))
                {
                    this.prevFirstResponder = ResolveResponder(firstResponder);
                }
            }
            else
            {
                base.ObserveValue(keyPath, ofObject, change, context);
            }
        }
Example #19
0
        /// <summary>If the standard PerformKeyEquivalent doesn't work, then use this
        /// to try to execute the given command directly. Used as a workaround.</summary>
        /// <param name="responder">The recipient of the event.</param>
        /// <param name="theEvent">The event to handle</param>
        /// <param name="command">The command.</param>
        /// <param name="context">Data context for the command.</param>
        /// <returns><c>true</c> if the command using the delete key was executed, otherwise <c>false</c>.</returns>
        /// <remarks>This is to work around an as-yet unsuccessfully diagnosed problem with the
        /// 'delete' key shortcut that arises when cancelling cell edits in the NSOutlineView / NSTableView.
        /// It seems that other shortcuts aside from delete will work. It may be that when the
        /// field editor becomes active, the cancel isn't being processed properly, or the
        /// re-enabling of keyboard shortcuts isn't happening in the right order, or something
        /// about the editor itself and its temporary requisition of the delete key is at play here.
        /// Blather aside, this will explicitly check for the backspace / delete key and treat
        /// it as if it were a command shortcut.</remarks>
        public static bool PerformKeyEquivalentForDelete(this NSResponder responder, NSEvent theEvent, VisualRelayCommand command, object context)
        {
            var didIt = false;

            if (theEvent.Window.FirstResponder == responder)
            {
                var isDeleteOrBackspace = (theEvent.Characters == NSBackspaceCharacterString) || (theEvent.Characters == NSDeleteCharacterString);
                var deleteCommandUsesBackspaceOrDelete = (command.KeyboardShortcutKey == NSBackspaceCharacterString) || (command.KeyboardShortcutKey == NSDeleteCharacterString);
                if (isDeleteOrBackspace && deleteCommandUsesBackspaceOrDelete)
                {
                    didIt = command.CanExecute(context);
                    if (didIt)
                    {
                        command.Execute(context);
                    }
                }
            }
            return(didIt);
        }
        /// <summary>
        /// Gets a Boolean value indicating of the given command is allowed to execute.
        /// </summary>
        /// <param name="command">The command of interest.</param>
        /// <returns><c>true</c> if the command should be allowed to execute, <c>false</c> otherwise.</returns>
        protected override bool HandleCanExecuteChangedForCommand(VisualRelayCommand command)
        {
            var canExecute = base.HandleCanExecuteChangedForCommand(command);

            if (canExecute && (command.UniqueId == DeleteItemsCommand.UniqueId))
            {
                NSResponder firstResponder = null;
                if ((NSApplication.SharedApplication != null) && (NSApplication.SharedApplication.MainWindow != null))
                {
                    firstResponder = NSApplication.SharedApplication.MainWindow.FirstResponder;
                    canExecute     = firstResponder is NSOutlineView;
                    if (canExecute)
                    {
                        canExecute = (MenuLayoutView != null) && (MenuLayoutView.FindChild <NSOutlineView>() == firstResponder);
                    }
                    command.MenuItem.NativeMenuItem.KeyEquivalent             = canExecute ? DeleteItemsCommand.KeyboardShortcutKey : string.Empty;
                    command.MenuItem.NativeMenuItem.KeyEquivalentModifierMask = (NSEventModifierMask)(canExecute ? DeleteItemsCommand.KeyboardShortcutModifiers : OSModifierKeys.None);
                }
            }
            return(canExecute);
        }
Example #21
0
        void RefreshDebugData(NSResponder firstResponder)
        {
            view = firstResponder as NSView;
            if (view != null)
            {
                debugOverlayWindow.AlignWith(view);
            }

            nextKeyView = view?.NextValidKeyView as NSView;
            if (nextKeyView != null)
            {
                debugNextOverlayWindow.AlignWith(nextKeyView);
            }

            previousKeyView = view?.PreviousValidKeyView as NSView;
            if (previousKeyView != null)
            {
                debugPreviousOverlayWindow.AlignWith(previousKeyView);
            }

            RefreshStatusWindow();
        }
Example #22
0
 public virtual bool EmbeddedControlDoCommandBySelector(NSResponder target, Selector selector)
 {
     return(eventResponder.EmbeddedControlDoCommandBySelector(target, selector));
 }
Example #23
0
 public override void UIMakeFirstResponder(WebView sender, NSResponder newResponder);
Example #24
0
 public override bool ValidateProposedFirstResponder(NSResponder responder, NSEvent forEvent)
 {
     return(true);
 }
Example #25
0
 public bool validateProposedFirstResponder(NSResponder responder, NSEvent ev)
 {
     return(true);
 }
Example #26
0
            public override bool ValidateProposedFirstResponder(NSResponder responder, NSEvent forEvent)
            {
                var valid = base.ValidateProposedFirstResponder(responder, forEvent);

                return(Handler?.ValidateProposedFirstResponder(responder, forEvent, valid) ?? valid);
            }
Example #27
0
 private void DoDump(NSResponder o, ref int indent)
 {
     if (NSObject.IsNullOrNil(o))
     {
         DoDump1(NSApplication.sharedApplication(), ref indent);
     }
     else
     {
         DoDump(o.nextResponder(), ref indent);
         DoDump1(o, ref indent);
     }
 }
Example #28
0
        private void DoDump1(NSResponder o, ref int indent)
        {
            Console.Write("{0}{1}", new string(' ', 3*indent), o);

            List<string> extras = new List<string>();
            if (o == NSApplication.sharedApplication().keyWindow())
                extras.Add("key");
            if (o == NSApplication.sharedApplication().mainWindow())
                extras.Add("main");
            if (o.respondsToSelector("isVisible"))
                if ((sbyte) o.Call("isVisible") == 0)
                    extras.Add("hidden");

            if (extras.Count > 0)
                Console.Write(" [{0}]", string.Join(", ", extras.ToArray()));

            Console.WriteLine();

            if (o.respondsToSelector("delegate"))
            {
                NSObject d = (NSObject) o.Call("delegate");
                if (!NSObject.IsNullOrNil(d))
                {
                    Console.WriteLine("{0}{1}", new string(' ', 3*indent), d);
                }
            }
            ++indent;
        }
Example #29
0
 public static bool MakeFirstResponder(NSResponder aResponder)
 {
     return(true);
 }
Example #30
0
 /// <summary>
 /// Creates an OSVisual from a platform-specific object.
 /// </summary>
 /// <param name="responder">The OS-specific object to place into the abstraction..</param>
 /// <returns>The abstraction.</returns>
 public static OSVisual FromObject(NSResponder responder)
 {
     return(new OSVisual(responder));
 }
Example #31
0
 /// <summary>
 /// Initializes a new instance of the <see cref="INTV.Shared.View.OSVisual"/> struct.
 /// </summary>
 /// <param name="responder">A responder.</param>
 public OSVisual(NSResponder responder)
 {
     _visual = responder;
 }