Ejemplo n.º 1
0
        static bool ValidateSystemUserInterfaceItem(IntPtr sender, IntPtr sel, IntPtr item)
        {
            var actionHandle = Messaging.IntPtr_objc_msgSend(item, selGetAction);

            var control = Runtime.GetNSObject(sender);
            var handler = GetHandler(control) as MacView <TControl, TWidget, TCallback>;

            if (handler != null)
            {
                Command command;
                if (handler.systemActions != null && actionHandle != IntPtr.Zero && handler.systemActions.TryGetValue(actionHandle, out command))
                {
                    if (command != null)
                    {
                        return(command.Enabled);
                    }
                }
            }
            var objClass = ObjCExtensions.object_getClass(sender);

            if (objClass == IntPtr.Zero)
            {
                return(false);
            }

            var superClass = ObjCExtensions.class_getSuperclass(objClass);

            return
                (superClass != IntPtr.Zero &&
                 ObjCExtensions.ClassInstancesRespondToSelector(superClass, sel) &&
                 Messaging.bool_objc_msgSendSuper_IntPtr(control.SuperHandle, sel, item));
        }
Ejemplo n.º 2
0
        public bool HasMethod(IntPtr selector, object control)
        {
            var type        = control.GetType();
            var classHandle = Class.GetHandle(type);

            return(ObjCExtensions.GetMethod(classHandle, selector) != IntPtr.Zero);
        }
Ejemplo n.º 3
0
 public void AddMethod(IntPtr selector, Delegate action, string arguments, object control)
 {
     var type = control.GetType();
     #if OSX
     if (!typeof(IMacControl).IsAssignableFrom(type))
         throw new EtoException(string.Format("Control '{0}' does not inherit from IMacControl", type));
     #endif
     var classHandle = Class.GetHandle(type);
     ObjCExtensions.AddMethod(classHandle, selector, action, arguments);
 }
Ejemplo n.º 4
0
        public void AddMethod(IntPtr selector, Delegate action, string arguments, object control)
        {
            var type = control.GetType();

                        #if OSX
            if (!typeof(IMacControl).IsAssignableFrom(type))
            {
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, "Control '{0}' does not inherit from IMacControl", type));
            }
            if (((IMacControl)control).WeakHandler?.Target == null)
            {
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, "Control '{0}' has a null handler", type));
            }
                        #endif
            var classHandle = Class.GetHandle(type);
            ObjCExtensions.AddMethod(classHandle, selector, action, arguments);
        }
Ejemplo n.º 5
0
        public bool EnsureTextInputImplemented(NSView view = null)
        {
            view = view ?? TextInputControl;

            // determine whether we need to call InterpretKeyEvents ourselves or if it is already handled by the super class (e.g. NSTextView)
            // for NSTextField (TextBox, etc), we handle the TextInput event via MacFieldEditor
            TextInputImplemented = !ObjCExtensions.ClassConformsToProtocol(view.GetSuperclass(), MacViewTextInput.NSTextInputClientProtocol_Handle);

            // if it already conforms to the protocol, add the insertText:replacementRange method only
            if (view.ConformsToProtocol(MacViewTextInput.NSTextInputClientProtocol_Handle))
            {
                AddMethod(MacView.selInsertTextReplacementRange, MacView.TriggerTextInput_Delegate, EtoEnvironment.Is64BitProcess ? "v@:@{NSRange=QQ}" : "v@:@{NSRange=II}");
                return(false);
            }

            // Debug.WriteLine($"Adding TextInputClient to {view.GetType()}, Widget: {Widget.GetType()}");

            // add the NSTextInputClient protocol to the class
            var cls = Class.GetHandle(view.GetType());

            ObjCExtensions.ClassAddProtocol(cls, MacViewTextInput.NSTextInputClientProtocol_Handle);

            // add required methods for the NSTextInputClient protocol
            AddMethod(MacViewTextInput.HasMarkedText_Selector, MacViewTextInput.HasMarkedText_Delegate, "B@:", view);
            AddMethod(MacViewTextInput.MarkedRange_Selector, MacViewTextInput.MarkedRange_Delegate, "{NSRange=QQ}@:", view);
            AddMethod(MacViewTextInput.SelectedRange_Selector, MacViewTextInput.SelectedRange_Delegate, "{NSRange=QQ}@:", view);
            AddMethod(MacViewTextInput.SetMarkedText_Selector, MacViewTextInput.SetMarkedText_Delegate, "v@:@{NSRange=QQ}{NSRange=QQ}", view);
            AddMethod(MacViewTextInput.UnmarkText_Selector, MacViewTextInput.UnmarkText_Delegate, "v@:", view);
            AddMethod(MacViewTextInput.ValidAttributesForMarkedText_Selector, MacViewTextInput.ValidAttributesForMarkedText_Delegate, "@@:", view);
            AddMethod(MacViewTextInput.AttributedStringForProposedRange_Selector, MacViewTextInput.AttributedStringForProposedRange_Delegate, "@@:{NSRange=QQ}^{NSRange=QQ}", view);
            AddMethod(MacViewTextInput.CharacterIndexForPoint_Selector, MacViewTextInput.CharacterIndexForPoint_Delegate, "Q@:{CGPoint=gg}", view);
            AddMethod(MacViewTextInput.FirstRectForCharacterRange_Selector, MacViewTextInput.FirstRectForCharacterRange_Delegate, "{CGRect=gggg}@:{NSRange=QQ}^{NSRange=QQ}", view);
            AddMethod(MacViewTextInput.DoCommandBySelector_Selector, MacViewTextInput.DoCommandBySelector_Delegate, "v@:#", view);

            AddMethod(MacView.selInsertTextReplacementRange, MacView.TriggerTextInput_Delegate, "v@:@{NSRange=QQ}", view);
            return(true);
        }
Ejemplo n.º 6
0
 static MacLabel()
 {
     supportsSingleLine = ObjCExtensions.ClassInstancesRespondToSelector(Class.GetHandle("NSTextFieldCell"), Selector.GetHandle("setUsesSingleLineMode:"));
 }