예제 #1
0
 internal ControlTarget(UIControl control, UIControlEvent controlEvent, Action <UIControl> callback)
 {
     _control      = control;
     _controlEvent = controlEvent;
     _callback     = callback;
     control.AddTarget(EventHandler, controlEvent);
 }
예제 #2
0
        public void AddTarget(EventHandler notification, UIControlEvent events)
        {
            var targets = allTargets.GetValue(this, k =>
            {
                MarkDirty();
                return(new Dictionary <EventHandler, Dictionary <UIControlEvent, UIControlEventProxy> > ());
            });

            Dictionary <UIControlEvent, UIControlEventProxy> t;

            if (!targets.TryGetValue(notification, out t))
            {
                t = new Dictionary <UIControlEvent, UIControlEventProxy> ();
                targets [notification] = t;
            }

            UIControlEventProxy ep;

            if (!t.TryGetValue(events, out ep))
            {
                ep         = new UIControlEventProxy(this, notification);
                t [events] = ep;
                AddTarget(ep, Selector.GetHandle(UIControlEventProxy.BridgeSelector), events);
            }
            else
            {
                ep.Counter++;
            }
        }
예제 #3
0
 private void widget_PerCentChanged(object sender, UIControlEvent e)
 {
     this.UpDateData(delegate
     {
         this._propertyItem.SetValue("PrePositionEnabled", e.IsCheck, null);
         this.isCheck = e.IsCheck;
         this.SetControl();
     });
 }
예제 #4
0
 private void widget_PerCentChanged(object sender, UIControlEvent e)
 {
     this.UpDateData((System.Action)(() =>
     {
         this._propertyItem.SetValue("PrePositionEnabled", (object)e.IsCheck, (object[])null);
         this.isCheck = e.IsCheck;
         this.SetControl();
     }));
 }
        public static IDisposable BindToTarget(this ICommand This, UIControl control, UIControlEvent events)
        {
            var ev = new EventHandler((o,e) => {
                if (!This.CanExecute(null)) return;
                This.Execute(null);
            });

            control.AddTarget(ev, events);
            return Disposable.Create(() => control.RemoveTarget(ev, events));
        }
예제 #6
0
파일: RxCocoa.cs 프로젝트: niilohlin/RxiOS
        /// <summary>
        /// Returns An <c>IOBservable<T></c> instance for T when the <c>UIControlEvent is generated</c>
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="rx"></param>
        /// <param name="controlEvent"></param>
        /// <returns>An <c>IOBservable</c> instance for <c>T</c> when the <c>UIControlEvent</c> is generated</returns>
        public static ControlEvent <T> ControlEvent <T>(this Reactive <T> rx, UIControlEvent controlEvent) where T : UIControl
        {
            var source = Observable.Create <T>(observer =>
            {
                if (rx.Parent == null)
                {
                    observer.OnCompleted();
                    return(Disposable.Empty);
                }
                var controltarget = new ControlTarget(rx.Parent, controlEvent, uiControl => observer.OnNext(rx.Parent));
                return(Disposable.Create(() => controltarget.Dispose()));
            }); //.TakeUntil(self.deallocated?);

            return(new ControlEvent <T>(source));
        }
예제 #7
0
        public void RemoveTarget(EventHandler notification, UIControlEvent events)
        {
#if XAMCORE_2_0
            Dictionary <EventHandler, Dictionary <UIControlEvent, UIControlEventProxy> > targets;

            if (allTargets == null)
            {
                return;
            }

            if (!allTargets.TryGetValue(this, out targets))
            {
                return;
            }
#else
            if (targets == null)
            {
                return;
            }
#endif

            Dictionary <UIControlEvent, UIControlEventProxy> t;
            if (!targets.TryGetValue(notification, out t))
            {
                return;
            }

            UIControlEventProxy ep;
            if (!t.TryGetValue(events, out ep))
            {
                return;
            }

            ep.Counter--;
            if (ep.Counter > 1)
            {
                return;
            }

            RemoveTarget(ep, Selector.GetHandle(UIControlEventProxy.BridgeSelector), events);
            t.Remove(events);
            ep.Dispose();
            if (t.Count == 0)
            {
                targets.Remove(notification);
            }
        }
        public static IDisposable BindToTarget(this ICommand This, UIControl control, UIControlEvent events)
        {
            var ev = new EventHandler((o,e) => {
                if (!This.CanExecute(null)) return;
                This.Execute(null);
            });

            var cech = new EventHandler((o, e) => {
                var canExecute = This.CanExecute(null);
                control.Enabled = canExecute;
            });

            This.CanExecuteChanged += cech;
            control.AddTarget(ev, events);

            control.Enabled = This.CanExecute(null);

            return Disposable.Create(() => {
                control.RemoveTarget(ev, events);
                This.CanExecuteChanged -= cech;
            });
        }
예제 #9
0
    /// <summary>
    /// Binds the <see cref="ICommand"/> to target <see cref="UIControl"/>.
    /// </summary>
    /// <param name="item">The command to bind to.</param>
    /// <param name="control">The control.</param>
    /// <param name="events">The events.</param>
    /// <returns>A disposable.</returns>
    public static IDisposable BindToTarget(this ICommand item, UIControl control, UIControlEvent events)
    {
        if (item is null)
        {
            throw new ArgumentNullException(nameof(item));
        }

        if (control is null)
        {
            throw new ArgumentNullException(nameof(control));
        }

        var ev = new EventHandler((o, e) =>
        {
            if (!item.CanExecute(null))
            {
                return;
            }

            item.Execute(null);
        });

        var cech = new EventHandler((o, e) =>
        {
            control.Enabled = item.CanExecute(null);
        });

        item.CanExecuteChanged += cech;
        control.AddTarget(ev, events);

        control.Enabled = item.CanExecute(null);

        return(Disposable.Create(() =>
        {
            control.RemoveTarget(ev, events);
            item.CanExecuteChanged -= cech;
        }));
    }
예제 #10
0
        void handleControl(UIView view, UIControlEvent controlEvent)
        {
            var control = view as UIControl;

            if (control != null)
            {
                var targets = control.AllTargets;
                foreach (var target in targets)
                {
                    var actions = control.GetActions(target, controlEvent);
                    if ((actions != null)
                        )
                    {
                        foreach (var action in actions)
                        {
                            var selectorString = action;
                            var selector       = new ObjCRuntime.Selector(selectorString);
                            control.SendAction(selector, target, null);
                        }
                    }
                }
            }
        }
        public static IDisposable BindToTarget(this ICommand This, UIControl control, UIControlEvent events)
        {
            var ev = new EventHandler((o, e) => {
                if (!This.CanExecute(null))
                {
                    return;
                }
                This.Execute(null);
            });

            var cech = new EventHandler((o, e) => {
                var canExecute  = This.CanExecute(null);
                control.Enabled = canExecute;
            });

            This.CanExecuteChanged += cech;
            control.AddTarget(ev, events);

            control.Enabled = This.CanExecute(null);

            return(Disposable.Create(() => {
                control.RemoveTarget(ev, events);
                This.CanExecuteChanged -= cech;
            }));
        }
예제 #12
0
        /// <summary>
        /// Creates an Observable for a UIControl Event.
        /// </summary>
        /// <returns>An observable.</returns>
        /// <param name="sender">The sender.</param>
        /// <param name="expression">The expression.</param>
        /// <param name="evt">The control event to listen for.</param>
        protected static IObservable <IObservedChange <object, object> > ObservableFromUIControlEvent(NSObject sender, Expression expression, UIControlEvent evt)
        {
            return(Observable.Create <IObservedChange <object, object> >(subj =>
            {
                var control = (UIControl)sender;

                EventHandler handler = (s, e) => subj.OnNext(new ObservedChange <object, object>(sender, expression));

                control.AddTarget(handler, evt);

                return Disposable.Create(() => control.RemoveTarget(handler, evt));
            }));
        }
        public static IDisposable BindToTarget(this ICommand This, UIControl control, UIControlEvent events)
        {
            var ev = new EventHandler((o, e) => {
                if (!This.CanExecute(null))
                {
                    return;
                }
                This.Execute(null);
            });

            control.AddTarget(ev, events);
            return(Disposable.Create(() => control.RemoveTarget(ev, events)));
        }
예제 #14
0
        /// <summary>
        /// Creates an Observable for a UIControl Event
        /// </summary>
        /// <returns>An observable</returns>
        /// <param name="sender">The sender</param>
        /// <param name="propertyName">The property name </param>
        /// <param name="evt">The control event to listen for</param>
        protected static IObservable <IObservedChange <object, object> > ObservableFromUIControlEvent(NSObject sender, string propertyName, UIControlEvent evt)
        {
            return(Observable.Create <IObservedChange <object, object> >(subj =>
            {
                var control = (UIControl)sender;

                EventHandler handler = (s, e) =>
                {
                    subj.OnNext(new ObservedChange <object, object>()
                    {
                        Sender = sender, PropertyName = propertyName
                    });
                };

                control.AddTarget(handler, evt);

                return Disposable.Create(() =>
                {
                    control.RemoveTarget(handler, evt);
                });
            }));
        }
예제 #15
0
        private void widget_SQuardValueChanged(object sender, UIControlEvent e)
        {
            this.UpDateData(delegate
            {
                NodeObject nodeObject = this._propertyItem.Instance as NodeObject;
                string name           = e.Name;
                switch (name)
                {
                case "comboBox_modeType_Changed":
                    if (this.sizeTypeObject != null)
                    {
                        this.sizeTypeObject.IsCustomSize = !e.IsCheck;
                        this.SetControl();
                    }
                    break;

                case "preSizeEnabled_Clicked":
                    nodeObject.PreSizeEnable = e.IsCheck;
                    this.SetControl();
                    break;

                case "rectSize_PointX":
                    if (nodeObject.PreSizeEnable)
                    {
                        PointF preSize     = nodeObject.PreSize;
                        preSize.X          = (float)e.UIValue / 100f;
                        nodeObject.PreSize = preSize;
                    }
                    else
                    {
                        nodeObject.Size = new PointF((float)((int)e.UIValue), nodeObject.Size.Y);
                    }
                    break;

                case "rectSize_PointY":
                    if (nodeObject.PreSizeEnable)
                    {
                        PointF preSize2    = nodeObject.PreSize;
                        preSize2.Y         = (float)e.UIValue / 100f;
                        nodeObject.PreSize = preSize2;
                    }
                    else
                    {
                        nodeObject.Size = new PointF(nodeObject.Size.X, (float)((int)e.UIValue));
                    }
                    break;

                case "scale9Enabled_Clicked":
                    if (this.scale9 != null)
                    {
                        this.scale9.Scale9Enable = e.IsCheck;
                        this.SetControl();
                    }
                    break;

                case "Left":
                    if (this.scale9 != null)
                    {
                        this.scale9.LeftEage = (int)e.UIValue;
                    }
                    break;

                case "Right":
                    if (this.scale9 != null)
                    {
                        this.scale9.RightEage = (int)e.UIValue;
                    }
                    break;

                case "Bottom":
                    if (this.scale9 != null)
                    {
                        this.scale9.BottomEage = (int)e.UIValue;
                    }
                    break;

                case "Top":
                    if (this.scale9 != null)
                    {
                        this.scale9.TopEage = (int)e.UIValue;
                    }
                    break;
                }
            });
        }
        /// <summary>
        /// Creates an Observable for a UIControl Event
        /// </summary>
        /// <returns>An observable</returns>
        /// <param name="sender">The sender</param>
        /// <param name="propertyName">The property name </param>
        /// <param name="evt">The control event to listen for</param>
        protected static IObservable<IObservedChange<object, object>> ObservableFromUIControlEvent(NSObject sender, Expression expression, UIControlEvent evt)
        {
            return Observable.Create<IObservedChange<object, object>>(subj =>
            {
                var control = (UIControl) sender;

                EventHandler handler = (s,e)=>
                {
                    subj.OnNext(new ObservedChange<object, object>(sender, expression));
                };

                control.AddTarget(handler, evt);

                return Disposable.Create(() =>
                {
                    control.RemoveTarget(handler, evt);
                });
            });
        }
예제 #17
0
        public void RemoveTarget(EventHandler notification, UIControlEvent events)
        {
            #if XAMCORE_2_0
            Dictionary<EventHandler, Dictionary<UIControlEvent, UIControlEventProxy>> targets;

            if (allTargets == null)
                return;

            if (!allTargets.TryGetValue (this, out targets))
                return;
            #else
            if (targets == null)
                return;
            #endif

            Dictionary<UIControlEvent, UIControlEventProxy> t;
            if (!targets.TryGetValue (notification, out t))
                return;

            UIControlEventProxy ep;
            if (!t.TryGetValue (events, out ep))
                return;

            ep.Counter--;
            if (ep.Counter > 1)
                return;

            RemoveTarget (ep, Selector.GetHandle (UIControlEventProxy.BridgeSelector), events);
            t.Remove (events);
            ep.Dispose ();
            if (t.Count == 0)
                targets.Remove (notification);
        }
예제 #18
0
        public void AddTarget(EventHandler notification, UIControlEvent events)
        {
            #if XAMCORE_2_0
            var targets = allTargets.GetValue (this, k =>
            {
                MarkDirty ();
                return new Dictionary<EventHandler, Dictionary<UIControlEvent, UIControlEventProxy>> ();
            });
            #else
            if (targets == null) {
                targets = new Dictionary<EventHandler, Dictionary<UIControlEvent, UIControlEventProxy>> ();
                MarkDirty ();
            }
            #endif

            Dictionary<UIControlEvent, UIControlEventProxy> t;
            if (!targets.TryGetValue (notification, out t)) {
                t = new Dictionary<UIControlEvent, UIControlEventProxy> ();
                targets [notification] = t;
            }

            UIControlEventProxy ep;

            if (!t.TryGetValue (events, out ep)) {
                ep = new UIControlEventProxy (this, notification);
                t [events] = ep;
                AddTarget (ep, Selector.GetHandle (UIControlEventProxy.BridgeSelector), events);
            } else {
                ep.Counter++;
            }
        }
예제 #19
0
        private void widget_SQuardValueChanged(object sender, UIControlEvent e)
        {
            this.UpDateData((System.Action)(() =>
            {
                NodeObject instance = this._propertyItem.Instance as NodeObject;
                switch (e.Name)
                {
                case "comboBox_modeType_Changed":
                    if (this.sizeTypeObject == null)
                    {
                        break;
                    }
                    this.sizeTypeObject.IsCustomSize = !e.IsCheck;
                    this.SetControl();
                    break;

                case "preSizeEnabled_Clicked":
                    instance.PreSizeEnable = e.IsCheck;
                    this.SetControl();
                    break;

                case "rectSize_PointX":
                    if (instance.PreSizeEnable)
                    {
                        PointF preSize   = instance.PreSize;
                        preSize.X        = (float)e.UIValue / 100f;
                        instance.PreSize = preSize;
                        break;
                    }
                    instance.Size = new PointF((float)(int)e.UIValue, instance.Size.Y);
                    break;

                case "rectSize_PointY":
                    if (instance.PreSizeEnable)
                    {
                        PointF preSize   = instance.PreSize;
                        preSize.Y        = (float)e.UIValue / 100f;
                        instance.PreSize = preSize;
                        break;
                    }
                    instance.Size = new PointF(instance.Size.X, (float)(int)e.UIValue);
                    break;

                case "scale9Enabled_Clicked":
                    if (this.scale9 == null)
                    {
                        break;
                    }
                    this.scale9.Scale9Enable = e.IsCheck;
                    this.SetControl();
                    break;

                case "Left":
                    if (this.scale9 == null)
                    {
                        break;
                    }
                    this.scale9.LeftEage = (int)e.UIValue;
                    break;

                case "Right":
                    if (this.scale9 == null)
                    {
                        break;
                    }
                    this.scale9.RightEage = (int)e.UIValue;
                    break;

                case "Bottom":
                    if (this.scale9 == null)
                    {
                        break;
                    }
                    this.scale9.BottomEage = (int)e.UIValue;
                    break;

                case "Top":
                    if (this.scale9 == null)
                    {
                        break;
                    }
                    this.scale9.TopEage = (int)e.UIValue;
                    break;
                }
            }));
        }